1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted
872 \begin_inset Marginal
875 \begin_layout Standard
900 will push a as an int and as a char resp.
903 \begin_layout Itemize
908 \begin_layout Standard
917 -regextend has been removed.
920 \begin_layout Itemize
925 \begin_layout Standard
934 -noregparms has been removed.
937 \begin_layout Itemize
942 \begin_layout Standard
951 -stack-after-data has been removed.
954 \begin_layout Itemize
956 \begin_inset LatexCommand \index{bit}
961 \begin_inset LatexCommand \index{sbit}
966 \begin_inset LatexCommand \index{\_\_sbit}
970 types now consistently behave like the C99 _Bool type with respect to type
972 \begin_inset LatexCommand \index{type conversion}
977 \begin_inset LatexCommand \index{type promotion}
982 The most common incompatibility resulting from this change is related to
984 \begin_inset LatexCommand \index{Bit toggling}
999 \begin_inset LatexCommand \index{\~\/ Operator}
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1007 \begin_layout Standard
1020 b = !b; /* toggles b */
1024 In previous versions, both forms would have toggled the bit.
1027 \begin_layout Standard
1030 <pending: more incompatibilities?>
1033 \begin_layout Section
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039 a desire to compute.
1040 The preferred method of installation is to compile SDCC from source using
1042 For Windows some pre-compiled binary distributions are available for your
1044 You should have some experience with command line tools and compiler use.
1047 \begin_layout Section
1051 \begin_layout Standard
1052 The SDCC home page at
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1057 is a great place to find distribution sets.
1058 You can also find links to the user mailing lists that offer help or discuss
1059 SDCC with other SDCC users.
1060 Web links to other SDCC related sites can also be found here.
1061 This document can be found in the DOC directory of the source package as
1062 a text or HTML file.
1063 A pdf version of this document is available at
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1069 Some of the other tools (simulator and assembler) included with SDCC contain
1070 their own documentation and can be found in the source distribution.
1071 If you want the latest unreleased software, the complete source package
1072 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1076 \begin_layout Section
1077 Wishes for the future
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082 Here are some I can think of:
1087 \begin_layout Standard
1090 char KernelFunction3(char p) at 0x340;
1095 \begin_layout Standard
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1109 If you can think of some more, please see the section
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1114 about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1120 \begin_inset LatexCommand \index{Feature request}
1129 \begin_layout Chapter
1131 \begin_inset LatexCommand \index{Installation}
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1150 More detailed instructions follow below.
1153 \begin_layout Section
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1165 The defaults can be overridden by:
1169 \labelwidthstring 00.00.0000
1174 \begin_layout Standard
1183 -prefix see table below
1187 \labelwidthstring 00.00.0000
1192 \begin_layout Standard
1201 -exec_prefix see table below
1205 \labelwidthstring 00.00.0000
1210 \begin_layout Standard
1219 -bindir see table below
1223 \labelwidthstring 00.00.0000
1228 \begin_layout Standard
1237 -datadir see table below
1241 \labelwidthstring 00.00.0000
1246 \begin_layout Standard
1255 -datarootdir see table below
1261 \labelwidthstring 00.00.0000
1264 docdir environment variable, see table below
1268 \labelwidthstring 00.00.0000
1271 include_dir_suffix environment variable, see table below
1275 \labelwidthstring 00.00.0000
1278 lib_dir_suffix environment variable, see table below
1282 \labelwidthstring 00.00.0000
1285 sdccconf_h_dir_separator environment variable, either / or
1290 This character will only be used in sdccconf.h; don't forget it's a C-header,
1291 therefore a double-backslash is needed there.
1297 \labelwidthstring 00.00.0000
1302 \begin_layout Standard
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1315 \labelwidthstring 00.00.0000
1320 \begin_layout Standard
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1333 \labelwidthstring 00.00.0000
1338 \begin_layout Standard
1347 -disable-z80-port Excludes the z80 port
1351 \labelwidthstring 00.00.0000
1356 \begin_layout Standard
1365 -disable-avr-port Excludes the AVR port
1369 \labelwidthstring 00.00.0000
1374 \begin_layout Standard
1383 -disable-ds390-port Excludes the DS390 port
1387 \labelwidthstring 00.00.0000
1392 \begin_layout Standard
1401 -disable-hc08-port Excludes the HC08 port
1405 \labelwidthstring 00.00.0000
1410 \begin_layout Standard
1419 -disable-pic-port Excludes the PIC14 port
1423 \labelwidthstring 00.00.0000
1428 \begin_layout Standard
1437 -disable-pic16-port Excludes the PIC16 port
1441 \labelwidthstring 00.00.0000
1446 \begin_layout Standard
1455 -disable-xa51-port Excludes the XA51 port
1459 \labelwidthstring 00.00.0000
1464 \begin_layout Standard
1473 -disable-ucsim Disables configuring and building of ucsim
1477 \labelwidthstring 00.00.0000
1482 \begin_layout Standard
1491 -disable-device-lib Disables automatically building device libraries
1495 \labelwidthstring 00.00.0000
1500 \begin_layout Standard
1509 -disable-packihx Disables building packihx
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -enable-libgc Use the Bohem memory allocator.
1548 Lower runtime footprint.
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553 the tools and their arguments can be influenced.
1554 Please see `configure -
1558 \begin_layout Standard
1567 -help' and the man/info pages of `configure' for details.
1572 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574 SDCC_LIB_NAME are defined by `configure' too.
1575 At the moment it's not possible to change the default settings (it was
1576 simply never required).
1580 These configure options are compiled into the binaries,
1581 and can only be changed by rerunning 'configure' and recompiling SDCC.
1582 The configure options are written in
1586 to distinguish them from run time environment variables (see section search
1592 \begin_inset Quotes sld
1596 \begin_inset Quotes srd
1599 are used by the SDCC team to build the official Win32 binaries.
1600 The SDCC team uses Mingw32 to build the official Windows binaries, because
1604 \begin_layout Enumerate
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1630 \begin_layout Standard
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 \begin_layout Standard
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_layout Standard
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1660 \begin_layout Standard
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_layout Standard
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_layout Standard
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1691 \begin_layout Standard
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1704 \begin_layout Standard
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1715 \begin_layout Standard
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 \begin_layout Standard
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_layout Standard
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 \begin_layout Standard
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1780 \begin_layout Standard
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 \begin_layout Standard
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_layout Standard
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 \begin_layout Standard
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1839 \begin_layout Standard
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1876 \begin_layout Standard
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_layout Standard
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_layout Standard
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1924 \begin_layout Standard
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1935 \begin_layout Standard
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1944 \begin_layout Standard
1960 \begin_layout Standard
1962 'configure' also computes relative paths.
1963 This is needed for full relocatability of a binary package and to complete
1964 search paths (see section search paths below):
1969 \begin_layout Standard
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 \begin_layout Standard
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_layout Standard
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 \begin_layout Standard
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2052 \begin_layout Standard
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2061 \begin_layout Standard
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2072 \begin_layout Standard
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 \begin_layout Standard
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2092 \begin_layout Standard
2108 \begin_layout Standard
2113 \begin_layout LyX-Code
2120 \begin_layout Standard
2130 \begin_inset Quotes srd
2134 \begin_inset Quotes srd
2141 \begin_layout Standard
2151 \begin_inset Quotes srd
2155 \begin_inset Quotes srd
2164 \begin_layout Standard
2177 \begin_layout Standard
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2194 \begin_layout LyX-Code
2200 \begin_inset Quotes srd
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2208 \begin_inset Quotes srd
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2220 \begin_inset Quotes srd
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2232 \begin_inset Quotes srd
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2247 \begin_layout Standard
2257 \begin_inset Quotes srd
2261 \begin_inset Quotes srd
2272 \begin_layout Standard
2282 \begin_inset Quotes srd
2286 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2300 \begin_inset Quotes srd
2308 \begin_inset Quotes srd
2312 \begin_inset Quotes srd
2320 \begin_inset Quotes srd
2324 \begin_inset Quotes srd
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2344 \begin_inset Quotes srd
2355 \begin_layout Standard
2372 \begin_layout Standard
2381 -host=i586-mingw32msvc
2389 \begin_layout Standard
2398 -build=unknown-unknown-linux-gnu
2401 \begin_layout Standard
2403 \begin_inset Quotes sld
2407 \begin_inset Quotes srd
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2414 \begin_layout LyX-Code
2423 \begin_layout Standard
2433 \begin_inset Quotes srd
2437 \begin_inset Quotes srd
2448 \begin_layout Standard
2458 \begin_inset Quotes srd
2462 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2476 \begin_inset Quotes srd
2484 \begin_inset Quotes srd
2488 \begin_inset Quotes srd
2496 \begin_inset Quotes srd
2500 \begin_inset Quotes srd
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2520 \begin_inset Quotes srd
2528 \begin_inset Quotes srd
2532 \begin_inset Quotes srd
2540 \begin_inset Quotes srd
2544 \begin_inset Quotes srd
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2556 \begin_layout Standard
2565 -C' turns on caching, which gives a little bit extra speed.
2566 However if options are changed, it can be necessary to delete the config.cache
2570 \begin_layout Section
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2577 \begin_inset LatexCommand \index{Install paths}
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2591 \begin_layout Standard
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2604 \begin_layout Standard
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 \begin_layout Standard
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_layout Standard
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2637 \begin_layout Standard
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_layout Standard
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_layout Standard
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_layout Standard
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2679 \begin_layout Standard
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 \begin_layout Standard
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2703 \begin_layout Standard
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2723 \begin_layout Standard
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_layout Standard
2750 $DATADIR/$LIB_DIR_SUFFIX
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2767 \begin_layout Standard
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_layout Standard
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_layout Standard
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_layout Standard
2832 *compiler, preprocessor, assembler, and linker
2838 is auto-appended by the compiler, e.g.
2839 small, large, z80, ds390 etc
2842 \begin_layout Standard
2844 The install paths can still be changed during `make install' with e.g.:
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2873 \begin_layout Section
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2880 \begin_inset LatexCommand \index{Search path}
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2893 , see section above).
2894 Further search paths are determined by environment variables during runtime.
2897 The paths searched when running the compiler are as follows (the first
2903 Binary files (preprocessor, assembler and linker)
2908 \begin_layout Standard
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2920 \begin_layout Standard
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_layout Standard
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2938 \begin_layout Standard
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2949 \begin_layout Standard
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2969 \begin_layout Standard
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2991 \begin_layout Standard
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3000 \begin_layout Standard
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_layout Standard
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3020 \begin_layout Standard
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3029 \begin_layout Standard
3045 \begin_layout Standard
3053 \begin_layout Standard
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_layout Standard
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3074 \begin_layout Standard
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3083 \begin_layout Standard
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3099 \begin_layout Standard
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3121 \begin_layout Standard
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3138 \begin_layout Standard
3143 \begin_layout Standard
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3162 \begin_layout Standard
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 \begin_layout Standard
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3191 \begin_layout Standard
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_layout Standard
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3219 \begin_layout Standard
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3232 \begin_layout Standard
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3251 \begin_layout Standard
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3302 \begin_layout Standard
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3317 \begin_layout Standard
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3345 \begin_layout Standard
3361 \begin_layout Standard
3367 \begin_layout Standard
3376 -nostdinc disables the last two search paths.
3386 \begin_layout Standard
3387 With the exception of
3388 \begin_inset Quotes sld
3395 \begin_layout Standard
3405 \begin_inset Quotes srd
3412 is auto-appended by the compiler (e.g.
3413 small, large, z80, ds390 etc.).
3419 \begin_layout Standard
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_layout Standard
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3440 \begin_layout Standard
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3449 \begin_layout Standard
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3460 \begin_layout Standard
3465 \begin_layout Standard
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3482 \begin_layout Standard
3487 \begin_layout Standard
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3504 \begin_layout Standard
3509 \begin_layout Standard
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3528 \begin_layout Standard
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3554 \begin_layout Standard
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_layout Standard
3578 $LIB_DIR_SUFFIX/<model>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3586 \begin_layout Standard
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3601 \begin_layout Standard
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3620 \begin_layout Standard
3631 $LIB_DIR_SUFFIX/<model>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3639 \begin_layout Standard
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3693 \begin_layout Standard
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3751 \begin_layout Standard
3756 $LIB_DIR_SUFFIX/<model>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3777 \begin_layout Standard
3793 \begin_layout Standard
3794 \begin_inset Note Note
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799 the HTML output (last line)!
3807 \begin_layout Standard
3815 \begin_layout Standard
3824 -nostdlib disables the last two search paths.
3827 \begin_layout Section
3829 \begin_inset LatexCommand \index{Building SDCC}
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3845 \begin_layout Enumerate
3848 Download the source package
3850 either from the SDCC Subversion repository or from snapshot builds
3852 , it will be named something like sdcc
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3870 \begin_layout Enumerate
3873 Bring up a command line terminal, such as xterm.
3876 \begin_layout Enumerate
3879 Unpack the file using a command like:
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3889 , this will create a sub-directory called sdcc with all of the sources.
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type:
3901 \begin_layout Enumerate
3911 This configures the package for compilation on your system.
3914 \begin_layout Enumerate
3928 All of the source packages will compile, this can take a while.
3931 \begin_layout Enumerate
3945 This copies the binary executables, the include files, the libraries and
3946 the documentation to the install directories.
3947 Proceed with section
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3964 On Mac OS X 10.2.x it was reported, that the
3965 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966 Fortunately there's also gcc 2.9.x installed, which works fine.
3967 This compiler can be selected by running 'configure' with:
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3974 \begin_layout Subsection
3975 Cross compiling SDCC on Linux for Windows
3978 \begin_layout Standard
3979 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3980 See section 'Configure Options'.
3983 \begin_layout Subsection
3984 Building SDCC using Cygwin and Mingw32
3987 \begin_layout Standard
3988 For building and installing a Cygwin executable follow the instructions
3994 \begin_inset Quotes sld
3998 \begin_inset Quotes srd
4001 Win32-binary can be built, which will not need the Cygwin-DLL.
4002 For the necessary 'configure' options see section 'configure options' or
4003 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4008 Cygwin on Windows download setup.exe from
4009 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4015 \begin_inset Quotes sld
4018 default text file type
4019 \begin_inset Quotes srd
4023 \begin_inset Quotes sld
4027 \begin_inset Quotes srd
4030 and download/install at least the following packages.
4031 Some packages are selected by default, others will be automatically selected
4032 because of dependencies with the manually selected packages.
4033 Never deselect these packages!
4036 \begin_layout Itemize
4040 \begin_layout Itemize
4044 \begin_layout Itemize
4045 gcc ; version 3.x is fine, no need to use the old 2.9x
4048 \begin_layout Itemize
4049 binutils ; selected with gcc
4052 \begin_layout Itemize
4056 \begin_layout Itemize
4057 rxvt ; a nice console, which makes life much easier under windoze (see below)
4060 \begin_layout Itemize
4061 man ; not really needed for building SDCC, but you'll miss it sooner or
4065 \begin_layout Itemize
4066 less ; not really needed for building SDCC, but you'll miss it sooner or
4070 \begin_layout Itemize
4071 svn ; only if you use Subversion access
4074 \begin_layout Standard
4075 If you want to develop something you'll need:
4078 \begin_layout Itemize
4079 python ; for the regression tests
4082 \begin_layout Itemize
4083 gdb ; the gnu debugger, together with the nice GUI
4084 \begin_inset Quotes sld
4088 \begin_inset Quotes srd
4094 \begin_layout Itemize
4095 openssh ; to access the CF or commit changes
4098 \begin_layout Itemize
4099 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4100 use autoconf-stable!
4103 \begin_layout Standard
4104 rxvt is a nice console with history.
4105 Replace in your cygwin.bat the line
4108 \begin_layout LyX-Code
4113 \begin_layout Standard
4125 \begin_layout Standard
4129 \begin_layout LyX-Code
4130 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4133 \begin_layout LyX-Code
4134 -bg black -fg white -geometry 100x65 -e bash -
4138 \begin_layout Standard
4150 \begin_layout Standard
4151 Text selected with the mouse is automatically copied to the clipboard, pasting
4152 works with shift-insert.
4156 The other good tip is to make sure you have no //c/-styl
4157 e paths anywhere, use /cygdrive/c/ instead.
4158 Using // invokes a network lookup which is very slow.
4160 \begin_inset Quotes sld
4164 \begin_inset Quotes srd
4167 is too long, you can change it with e.g.
4170 \begin_layout LyX-Code
4174 \begin_layout Standard
4175 SDCC sources use the unix line ending LF.
4176 Life is much easier, if you store the source tree on a drive which is mounted
4178 And use an editor which can handle LF-only line endings.
4179 Make sure not to commit files with windows line endings.
4180 The tabulator spacing
4181 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4185 used in the project is 8.
4186 Although a tabulator spacing of 8 is a sensible choice for programmers
4187 (it's a power of 2 and allows to display 8/16 bit signed variables without
4188 loosing columns) the plan is to move towards using only spaces in the source.
4191 \begin_layout Subsection
4192 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4195 \begin_layout Standard
4198 Download the source package
4200 either from the SDCC Subversion repository or from the
4201 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4207 , it will be named something like sdcc
4211 -yyyymmdd-rrrr.tar.bz2.
4214 SDCC is distributed with all the projects, workspaces, and files you need
4215 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4216 The workspace name is 'sdcc.dsw'.
4217 Please note that as it is now, all the executables are created in a folder
4221 Once built you need to copy the executables from sdcc
4225 bin before running SDCC.
4230 WARNING: Visual studio is very picky with line terminations; it expects
4231 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4232 When using the Subversion repository it's easiest to configure the svn
4233 client to convert automatically for you.
4234 If however you are getting a message such as "This makefile was not generated
4235 by Developer Studio etc.
4237 \begin_inset Quotes srd
4240 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4241 need to convert the Unix style line endings to DOS style line endings.
4242 To do so you can use the
4243 \begin_inset Quotes sld
4247 \begin_inset Quotes srd
4250 utility freely available on the internet.
4251 Doug Hawkins reported in the sdcc-user list that this works:
4259 SDCC> unix2dos sdcc.dsw
4265 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4269 In order to build SDCC with MSVC
4270 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4271 One good place to get them is
4272 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4280 Download the file UnxUtils
4281 \begin_inset LatexCommand \index{UnxUtils}
4286 Now you have to install the utilities and setup MSVC so it can locate the
4288 Here there are two alternatives (choose one!):
4291 \begin_layout Enumerate
4296 a) Extract UnxUtils.zip to your C:
4298 hard disk PRESERVING the original paths, otherwise bison won't work.
4299 (If you are using WinZip make certain that 'Use folder names' is selected)
4304 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4305 'Show directories for:' select 'Executable files', and in the directories
4306 window add a new path: 'C:
4316 (As a side effect, you get a bunch of Unix utilities that
4317 could be useful, such as diff and patch.)
4320 \begin_layout Enumerate
4325 This one avoids extracting a bunch of files you may not
4326 use, but requires some extra work:
4330 a) Create a directory were to put the
4331 tools needed, or use a directory already present.
4338 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4339 gawk.exe to such directory WITHOUT preserving the original paths.
4340 (If you are using WinZip make certain that 'Use folder names' is not selected)
4345 ) Rename bison.exe to '_bison.exe'.
4349 d) Create a batch file 'bison.bat' in 'C:
4353 ' and add these lines:
4373 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4377 Steps 'c' and 'd' are needed
4378 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4379 reside in some weird Unix directory, '/usr/local/share/' I think.
4380 So it is necessary to tell bison where those files are located if they
4381 are not in such directory.
4382 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4387 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4388 in 'Show directories for:' select 'Executable files', and in the directories
4389 window add a new path: 'c:
4392 Note that you can use any other path instead of 'c:
4394 util', even the path where the Visual C++ tools are, probably: 'C:
4398 Microsoft Visual Studio
4403 So you don't have to execute step 'e' :)
4406 \begin_layout Standard
4408 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4409 the executables from sdcc
4413 bin, and you can compile using SDCC.
4416 \begin_layout Subsection
4417 Building SDCC Using Borland
4420 \begin_layout Enumerate
4421 From the sdcc directory, run the command "make -f Makefile.bcc".
4422 This should regenerate all the .exe files in the bin directory except for
4426 \begin_layout Enumerate
4427 If you modify any source files and need to rebuild, be aware that the dependenci
4428 es may not be correctly calculated.
4429 The safest option is to delete all .obj files and run the build again.
4430 From a Cygwin BASH prompt, this can easily be done with the command (be
4431 sure you are in the sdcc directory):
4441 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4443 ) -print -exec rm {}
4452 or on Windows NT/2000/XP from the command prompt with the command:
4459 del /s *.obj *.lib *.rul
4462 from the sdcc directory.
4465 \begin_layout Subsection
4466 Windows Install Using a ZIP Package
4469 \begin_layout Enumerate
4470 Download the binary zip package from
4471 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4475 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4476 This should unpack to a group of sub-directories.
4477 An example directory structure after unpacking the mingw32 package is:
4482 bin for the executables, c:
4490 lib for the include and libraries.
4493 \begin_layout Enumerate
4494 Adjust your environment variable PATH to include the location of the bin
4495 directory or start sdcc using the full path.
4498 \begin_layout Subsection
4499 Windows Install Using the Setup Program
4500 \begin_inset LatexCommand \label{sub:Windows-Install}
4507 \begin_layout Standard
4508 Download the setup program
4510 sdcc-x.y.z-setup.exe
4512 for an official release from
4515 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4519 or a setup program for one of the snapshots
4521 sdcc-yyyymmdd-xxxx-setup.exe
4524 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4529 A windows typical installer will guide you through the installation process.
4532 \begin_layout Subsection
4534 \begin_inset LatexCommand \index{VPATH}
4541 \begin_layout Standard
4542 SDCC supports the VPATH feature provided by configure and make.
4543 It allows to separate the source and build trees.
4547 \begin_layout Standard
4574 \begin_layout Standard
4577 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4578 # extract source to directory sdcc
4581 \begin_layout Standard
4584 mkdir sdcc.build\InsetSpace ~
4593 # put output in sdcc.build
4596 \begin_layout Standard
4602 \begin_layout Standard
4605 ../sdcc/configure\InsetSpace ~
4613 # configure is doing all the magic!
4616 \begin_layout Standard
4622 \begin_layout Standard
4628 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4629 It automagically computes the variables srcdir, top_srcdir and top_buildir
4635 the generated files will be in ~/sdcc.build, while the source files stay
4638 This is not only usefull for building different binaries, e.g.
4639 when cross compiling.
4640 It also gives you a much better overview in the source tree when all the
4641 generated files are not scattered between the source files.
4642 And the best thing is: if you want to change a file you can leave the original
4643 file untouched in the source directory.
4644 Simply copy it to the build directory, edit it, enter `make clean', `rm
4645 Makefile.dep' and `make'.
4650 will do the rest for you!
4653 \begin_layout Section
4654 Building the Documentation
4657 \begin_layout Standard
4662 \begin_layout Standard
4671 -enable-doc to the configure arguments to build the documentation together
4672 with all the other stuff.
4673 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4674 dvips and makeindex) to get the job done.
4675 Another possibility is to change to the doc directory and to type
4679 \begin_inset Quotes srd
4683 \begin_inset Quotes srd
4690 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4693 \begin_inset LatexCommand \url{http://www.lyx.org}
4697 as editor is straightforward.
4698 Prebuilt documentation in html and pdf format is available from
4699 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4706 \begin_layout Section
4707 Reading the Documentation
4708 \begin_inset LatexCommand \index{Documentation}
4715 \begin_layout Standard
4716 Currently reading the document in pdf format is recommended, as for unknown
4717 reason the hyperlinks are working there whereas in the html version they
4722 \begin_layout Standard
4723 If you should know why please drop us a note
4731 You'll find the pdf version
4732 \begin_inset LatexCommand \index{PDF version of this document}
4737 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4745 \begin_inset LatexCommand \index{HTML version of this document}
4750 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4756 This documentation is in some aspects different from a commercial documentation:
4760 \begin_layout Itemize
4761 It tries to document SDCC for several processor architectures in one document
4762 (commercially these probably would be separate documents/products).
4764 \begin_inset LatexCommand \index{Status of documentation}
4768 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4770 Z80, PIC14, PIC16 and HC08.
4773 \begin_layout Itemize
4774 There are many references pointing away from this documentation.
4775 Don't let this distract you.
4777 was a reference like
4778 \begin_inset LatexCommand \url{http://www.opencores.org}
4782 together with a statement
4783 \begin_inset Quotes sld
4786 some processors which are targetted by SDCC can be implemented in a
4803 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4808 \begin_inset Quotes srd
4812 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4817 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4822 \begin_inset Quotes sld
4825 have you ever heard of an open source compiler that compiles a subset of
4827 \begin_inset Quotes srd
4830 we expect you to have a quick look there and come back.
4831 If you read this you are on the right track.
4834 \begin_layout Itemize
4835 Some sections attribute more space to problems, restrictions and warnings
4836 than to the solution.
4839 \begin_layout Itemize
4840 The installation section and the section about the debugger is intimidating.
4843 \begin_layout Itemize
4844 There are still lots of typos and there are more different writing styles
4848 \begin_layout Section
4849 Testing the SDCC Compiler
4850 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4857 \begin_layout Standard
4858 The first thing you should do after installing your SDCC compiler is to
4867 \begin_layout Standard
4877 \begin_inset LatexCommand \index{version}
4884 at the prompt, and the program should run and output its version like:
4889 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4893 \begin_layout Standard
4894 If it doesn't run, or gives a message about not finding sdcc program, then
4895 you need to check over your installation.
4896 Make sure that the sdcc bin directory is in your executable search path
4897 defined by the PATH environment setting (
4902 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4909 Install trouble-shooting for suggestions
4912 Make sure that the sdcc program is in the bin folder, if not perhaps something
4913 did not install correctly.
4921 is commonly installed as described in section
4922 \begin_inset Quotes sld
4925 Install and search paths
4926 \begin_inset Quotes srd
4935 Make sure the compiler works on a very simple example.
4936 Type in the following test.c program using your favorite
4961 \begin_layout Standard
4964 Compile this using the following command:
4973 If all goes well, the compiler will generate a test.asm and test.rel file.
4974 Congratulations, you've just compiled your first program with SDCC.
4975 We used the -c option to tell SDCC not to link the generated code, just
4976 to keep things simple for this step.
4984 The next step is to try it with the linker.
4994 If all goes well the compiler will link with the libraries and produce
4995 a test.ihx output file.
5000 (no test.ihx, and the linker generates warnings), then the problem is most
5009 usr/local/share/sdcc/lib directory
5016 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5023 Install trouble-shooting for suggestions).
5031 The final test is to ensure
5039 header files and libraries.
5040 Edit test.c and change it to the following:
5058 strcpy(str1, "testing");
5063 \begin_layout Standard
5066 Compile this by typing
5073 This should generate a test.ihx output file, and it should give no warnings
5074 such as not finding the string.h file.
5075 If it cannot find the string.h file, then the problem is that
5079 cannot find the /usr/local/share/sdcc/include directory
5086 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5093 Install trouble-shooting section for suggestions).
5102 \begin_layout Standard
5114 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5118 to find exactly where SDCC is looking for the include and lib files.
5121 \begin_layout Section
5122 Install Trouble-shooting
5123 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5128 \begin_inset LatexCommand \index{Install trouble-shooting}
5135 \begin_layout Subsection
5136 If SDCC does not build correctly
5139 \begin_layout Standard
5140 A thing to try is starting from scratch by unpacking the .tgz source package
5141 again in an empty directory.
5149 ./configure 2>&1 | tee configure.log
5163 make 2>&1 | tee make.log
5170 If anything goes wrong, you can review the log files to locate the problem.
5171 Or a relevant part of this can be attached to an email that could be helpful
5172 when requesting help from the mailing list.
5175 \begin_layout Subsection
5177 \begin_inset Quotes sld
5181 \begin_inset Quotes srd
5187 \begin_layout Standard
5189 \begin_inset Quotes sld
5193 \begin_inset Quotes srd
5196 command is a script that analyzes your system and performs some configuration
5197 to ensure the source package compiles on your system.
5198 It will take a few minutes to run, and will compile a few tests to determine
5199 what compiler features are installed.
5202 \begin_layout Subsection
5204 \begin_inset Quotes sld
5208 \begin_inset Quotes srd
5214 \begin_layout Standard
5215 This runs the GNU make tool, which automatically compiles all the source
5216 packages into the final installed binary executables.
5219 \begin_layout Subsection
5221 \begin_inset Quotes sld
5225 \begin_inset Quotes erd
5231 \begin_layout Standard
5232 This will install the compiler, other executables libraries and include
5233 files into the appropriate directories.
5235 \begin_inset LatexCommand \ref{sub:Install-paths}
5241 \begin_inset LatexCommand \ref{sub:Search-Paths}
5246 about install and search paths.
5248 On most systems you will need super-user privilege
5252 \begin_layout Section
5256 \begin_layout Standard
5257 SDCC is not just a compiler, but a collection of tools by various developers.
5258 These include linkers, assemblers, simulators and other components.
5259 Here is a summary of some of the components.
5260 Note that the included simulator and assembler have separate documentation
5261 which you can find in the source package in their respective directories.
5262 As SDCC grows to include support for other processors, other packages from
5263 various developers are included and may have their own sets of documentation.
5268 might want to look at the files which are installed in <installdir>.
5269 At the time of this writing, we find the following programs for gcc-builds:
5274 In <installdir>/bin:
5277 \begin_layout Itemize
5278 sdcc - The compiler.
5281 \begin_layout Itemize
5282 sdcpp - The C preprocessor.
5285 \begin_layout Itemize
5286 asx8051 - The assembler for 8051 type processors.
5289 \begin_layout Itemize
5294 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5297 \begin_layout Itemize
5298 aslink -The linker for 8051 type processors.
5301 \begin_layout Itemize
5306 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5309 \begin_layout Itemize
5310 s51 - The ucSim 8051 simulator.
5313 \begin_layout Itemize
5314 sdcdb - The source debugger.
5317 \begin_layout Itemize
5318 packihx - A tool to pack (compress) Intel hex files.
5321 \begin_layout Standard
5322 In <installdir>/share/sdcc/include
5325 \begin_layout Itemize
5329 \begin_layout Standard
5330 In <installdir>/share/sdcc/lib
5333 \begin_layout Itemize
5334 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5338 \begin_layout Standard
5339 In <installdir>/share/sdcc/doc
5342 \begin_layout Itemize
5346 \begin_layout Standard
5347 As development for other processors proceeds, this list will expand to include
5348 executables to support processors like AVR, PIC, etc.
5351 \begin_layout Subsection
5355 \begin_layout Standard
5356 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5357 the assembler and linkage editor.
5360 \begin_layout Subsection
5361 sdcpp - The C-Preprocessor
5364 \begin_layout Standard
5366 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5370 is a modified version of the GNU cpp
5371 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5376 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5381 The C preprocessor is used to pull in #include sources, process #ifdef
5382 statements, #defines and so on.
5385 \begin_layout Subsection
5394 - The Assemblers and Linkage Editors
5397 \begin_layout Standard
5398 This is retargettable assembler & linkage editor, it was developed by Alan
5400 John Hartman created the version for 8051, and I (Sandeep) have made some
5401 enhancements and bug fixes for it to work properly with SDCC.
5404 \begin_layout Subsection
5408 \begin_layout Standard
5410 \begin_inset LatexCommand \index{s51}
5414 is a free open source simulator developed by Daniel Drotos.
5415 The simulator is built as part of the build process.
5416 For more information visit Daniel's web site at:
5417 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5422 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5426 \begin_layout Subsection
5427 sdcdb - Source Level Debugger
5430 \begin_layout Standard
5432 \begin_inset LatexCommand \index{SDCDB (debugger)}
5436 is the companion source level debugger.
5437 More about SDCDB in section
5438 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5443 The current version of the debugger uses Daniel's Simulator S51
5444 \begin_inset LatexCommand \index{s51}
5448 , but can be easily changed to use other simulators.
5451 \begin_layout Chapter
5455 \begin_layout Section
5459 \begin_layout Subsection
5460 Single Source File Projects
5463 \begin_layout Standard
5464 For single source file 8051 projects the process is very simple.
5465 Compile your programs with the following command
5468 "sdcc sourcefile.c".
5472 This will compile, assemble and link your source file.
5473 Output files are as follows:
5476 \begin_layout Itemize
5478 \begin_inset LatexCommand \index{<file>.asm}
5483 \begin_inset LatexCommand \index{Assembler source}
5487 file created by the compiler
5490 \begin_layout Itemize
5492 \begin_inset LatexCommand \index{<file>.lst}
5497 \begin_inset LatexCommand \index{Assembler listing}
5501 file created by the Assembler
5504 \begin_layout Itemize
5506 \begin_inset LatexCommand \index{<file>.rst}
5511 \begin_inset LatexCommand \index{Assembler listing}
5515 file updated with linkedit information, created by linkage editor
5518 \begin_layout Itemize
5520 \begin_inset LatexCommand \index{<file>.sym}
5525 \begin_inset LatexCommand \index{Symbol listing}
5529 for the sourcefile, created by the assembler
5532 \begin_layout Itemize
5534 \begin_inset LatexCommand \index{<file>.rel}
5539 \begin_inset LatexCommand \index{<file>.o}
5544 \begin_inset LatexCommand \index{Object file}
5548 created by the assembler, input to Linkage editor
5551 \begin_layout Itemize
5553 \begin_inset LatexCommand \index{<file>.map}
5558 \begin_inset LatexCommand \index{Memory map}
5562 for the load module, created by the Linker
5565 \begin_layout Itemize
5567 \begin_inset LatexCommand \index{<file>.mem}
5571 - A file with a summary of the memory usage
5574 \begin_layout Itemize
5576 \begin_inset LatexCommand \index{<file>.ihx}
5580 - The load module in Intel hex format
5581 \begin_inset LatexCommand \index{Intel hex format}
5585 (you can select the Motorola S19 format
5586 \begin_inset LatexCommand \index{Motorola S19 format}
5594 \begin_layout Standard
5604 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5609 If you need another format you might want to use
5616 \begin_inset LatexCommand \index{objdump (tool)}
5627 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5632 \begin_inset Note Note
5635 \begin_layout Standard
5642 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5647 Both formats are documented in the documentation of srecord
5648 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5655 \begin_layout Itemize
5657 \begin_inset LatexCommand \index{<file>.adb}
5661 - An intermediate file containing debug information needed to create the
5666 \begin_layout Standard
5676 \begin_inset LatexCommand \index{-\/-debug}
5683 \begin_layout Itemize
5685 \begin_inset LatexCommand \index{<file>.cdb}
5689 - An optional file (with -
5693 \begin_layout Standard
5702 -debug) containing debug information.
5703 The format is documented in cdbfileformat.pdf
5706 \begin_layout Itemize
5709 \begin_inset LatexCommand \index{<file> (no extension)}
5713 An optional AOMF or AOMF51
5714 \begin_inset LatexCommand \index{AOMF, AOMF51}
5719 \begin_inset LatexCommand \label{OMF file}
5723 file containing debug information (generated with option -
5727 \begin_layout Standard
5753 ormat is a subformat of the OMF51 format and is commonly used by third party
5755 \begin_inset LatexCommand \index{Debugger}
5759 , simulators, emulators).
5762 \begin_layout Itemize
5764 \begin_inset LatexCommand \index{<file>.dump*}
5768 - Dump file to debug the compiler it self (generated with option -
5772 \begin_layout Standard
5781 -dumpall) (see section
5782 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5788 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5794 \begin_inset Quotes sld
5797 Anatomy of the compiler
5798 \begin_inset Quotes srd
5804 \begin_layout Subsection
5805 Postprocessing the Intel Hex
5806 \begin_inset LatexCommand \index{Intel hex format}
5811 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5818 \begin_layout Standard
5819 In most cases this won't be needed but the Intel Hex file
5820 \begin_inset LatexCommand \index{<file>.ihx}
5824 which is generated by SDCC might include lines of varying length and the
5825 addresses within the file are not guaranteed to be strictly ascending.
5826 If your toolchain or a bootloader does not like this you can use the tool
5832 \begin_inset LatexCommand \index{packihx (tool)}
5836 which is part of the SDCC distribution:
5843 packihx sourcefile.ihx >sourcefile.hex
5850 The separately available
5855 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5859 package additionally allows to set undefined locations to a predefined
5860 value, to insert checksums
5861 \begin_inset LatexCommand \index{checksum}
5865 of various flavours (crc, add, xor) and to perform other manipulations
5866 (convert, split, crop, offset, ...).
5874 srec_cat\InsetSpace ~
5876 sourcefile.ihx -intel\InsetSpace ~
5878 -o sourcefile.hex -intel
5885 An example for a more complex command line
5889 \begin_layout Standard
5890 the command backfills
5891 \begin_inset LatexCommand \index{backfill unused memory}
5895 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5897 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5898 will be interpreted as an
5906 (where an emergency routine could sit).
5919 srec_cat\InsetSpace ~
5920 sourcefile.ihx -intel\InsetSpace ~
5922 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5923 -little-endian-checksum-nega
5924 tive 0xfffe 0x02 0x02\InsetSpace ~
5926 -o sourcefile.hex -intel
5935 The srecord package is available at
5936 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5943 \begin_layout Subsection
5944 Projects with Multiple Source Files
5947 \begin_layout Standard
5948 SDCC can compile only ONE file at a time.
5949 Let us for example assume that you have a project containing the following
5954 foo1.c (contains some functions)
5956 foo2.c (contains some more functions)
5959 n.c (contains more functions and the function main)
5967 The first two files will need to be compiled separately with the commands:
5999 Then compile the source file containing the
6004 \begin_inset LatexCommand \index{Linker}
6008 the files together with the following command:
6016 foomain.c\InsetSpace ~
6017 foo1.rel\InsetSpace ~
6022 \begin_inset LatexCommand \index{<file>.rel}
6034 can be separately compiled as well:
6045 sdcc foomain.rel foo1.rel foo2.rel
6052 The file containing the
6067 file specified in the command line, since the linkage editor processes
6068 file in the order they are presented to it.
6069 The linker is invoked from SDCC using a script file with extension .lnk
6070 \begin_inset LatexCommand \index{<file>.lnk}
6075 You can view this file to troubleshoot linking problems such as those arising
6076 from missing libraries.
6079 \begin_layout Subsection
6080 Projects with Additional Libraries
6081 \begin_inset LatexCommand \index{Libraries}
6088 \begin_layout Standard
6089 Some reusable routines may be compiled into a library, see the documentation
6090 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6094 \begin_inset LatexCommand \index{<file>.lib}
6101 Libraries created in this manner can be included in the command line.
6102 Make sure you include the -L <library-path> option to tell the linker where
6103 to look for these files if they are not in the current directory.
6104 Here is an example, assuming you have the source file
6116 (if that is not the same as your current project):
6123 sdcc foomain.c foolib.lib -L mylib
6134 must be an absolute path name.
6138 The most efficient way to use libraries is
6139 to keep separate modules in separate source files.
6140 The lib file now should name all the modules.rel
6141 \begin_inset LatexCommand \index{<file>.rel}
6146 For an example see the standard library file
6150 in the directory <installdir>/share/lib/small.
6153 \begin_layout Subsection
6154 Using sdcclib to Create and Manage Libraries
6155 \begin_inset LatexCommand \index{sdcclib}
6162 \begin_layout Standard
6163 Alternatively, instead of having a .rel file for each entry on the library
6164 file as described in the preceding section, sdcclib can be used to embed
6165 all the modules belonging to such library in the library file itself.
6166 This results in a larger library file, but it greatly reduces the number
6167 of disk files accessed by the linker.
6168 Additionally, the packed library file contains an index of all include
6169 modules and symbols that significantly speeds up the linking process.
6170 To display a list of options supported by sdcclib type:
6175 \begin_layout Standard
6180 \begin_inset LatexCommand \index{sdcclib}
6191 To create a new library file, start by compiling all the required modules.
6197 \begin_layout Standard
6204 \begin_layout Standard
6211 \begin_layout Standard
6218 \begin_layout Standard
6225 \begin_layout Standard
6234 \begin_layout Standard
6235 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6237 The next step is to add the .rel files to the library file:
6242 \begin_layout Standard
6246 sdcclib libint.lib _divsint.rel
6249 \begin_inset LatexCommand \index{sdcclib}
6256 \begin_layout Standard
6260 sdcclib libint.lib _divuint.rel
6263 \begin_layout Standard
6267 sdcclib libint.lib _modsint.rel
6270 \begin_layout Standard
6274 sdcclib libint.lib _moduint.rel
6277 \begin_layout Standard
6281 sdcclib libint.lib _mulint.rel
6289 \begin_layout Standard
6298 \begin_layout Standard
6302 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6310 \begin_layout Standard
6311 If the file already exists in the library, it will be replaced.
6312 If a list of .rel files is available, you can tell sdcclib to add those
6314 For example, if the file 'myliblist.txt' contains
6322 \begin_layout Standard
6329 \begin_layout Standard
6336 \begin_layout Standard
6343 \begin_layout Standard
6350 \begin_layout Standard
6362 \begin_layout Standard
6371 \begin_layout Standard
6375 sdcclib -l libint.lib myliblist.txt
6383 \begin_layout Standard
6384 Additionally, you can instruct sdcclib to compiles the files before adding
6385 them to the library.
6386 This is achieved using the environment variables SDCCLIB_CC
6387 \begin_inset LatexCommand \index{SDCCLIB_CC}
6392 \begin_inset LatexCommand \index{SDCCLIB_AS}
6405 \begin_layout Standard
6409 set SDCCLIB_CC=sdcc -c
6412 \begin_layout Standard
6416 sdcclib -l libint.lib myliblist.txt
6424 \begin_layout Standard
6425 To see what modules and symbols are included in the library, options -s
6426 and -m are available.
6434 sdcclib -s libint.lib
6437 \begin_inset LatexCommand \index{sdcclib}
6449 \begin_layout Standard
6455 \begin_layout Standard
6461 \begin_layout Standard
6469 \begin_layout Standard
6475 \begin_layout Standard
6481 \begin_layout Standard
6487 \begin_layout Standard
6493 \begin_layout Standard
6501 \begin_layout Standard
6507 \begin_layout Standard
6513 \begin_layout Standard
6521 \begin_layout Standard
6527 \begin_layout Standard
6533 \begin_layout Standard
6539 \begin_layout Standard
6547 \begin_layout Standard
6553 \begin_layout Standard
6564 \begin_layout Standard
6565 If the source files are compiled using -
6569 \begin_layout Standard
6579 \begin_inset LatexCommand \index{-\/-debug}
6583 , the corresponding debug information file .adb will be include in the library
6585 The library files created with sdcclib are plain text files, so they can
6586 be viewed with a text editor.
6587 It is not recomended to modify a library file created with sdcclib using
6588 a text editor, as there are file indexes numbers located accross the file
6589 used by the linker to quickly locate the required module to link.
6590 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6591 it can be safely deleted, since all the information required for linking
6592 is embedded in the library file itself.
6593 Library files created using sdcclib are used as described in the preceding
6595 \begin_inset VSpace bigskip
6601 \begin_layout Section
6602 Command Line Options
6603 \begin_inset LatexCommand \index{Command Line Options}
6608 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6615 \begin_layout Subsection
6616 Processor Selection Options
6617 \begin_inset LatexCommand \index{Options processor selection}
6622 \begin_inset LatexCommand \index{Processor selection options}
6630 \labelwidthstring 00.00.0000
6634 \begin_inset LatexCommand \index{-mmcs51}
6640 Generate code for the Intel MCS51
6641 \begin_inset LatexCommand \index{MCS51}
6645 family of processors.
6646 This is the default processor target.
6650 \labelwidthstring 00.00.0000
6654 \begin_inset LatexCommand \index{-mds390}
6660 Generate code for the Dallas DS80C390
6661 \begin_inset LatexCommand \index{DS80C390}
6669 \labelwidthstring 00.00.0000
6673 \begin_inset LatexCommand \index{-mds400}
6679 Generate code for the Dallas DS80C400
6680 \begin_inset LatexCommand \index{DS80C400}
6688 \labelwidthstring 00.00.0000
6692 \begin_inset LatexCommand \index{-mhc08}
6698 Generate code for the Freescale/Motorola HC08
6699 \begin_inset LatexCommand \index{HC08}
6703 family of processors.
6707 \labelwidthstring 00.00.0000
6711 \begin_inset LatexCommand \index{-mz80}
6717 Generate code for the Zilog Z80
6718 \begin_inset LatexCommand \index{Z80}
6722 family of processors.
6726 \labelwidthstring 00.00.0000
6730 \begin_inset LatexCommand \index{-mgbz80}
6736 Generate code for the GameBoy Z80
6737 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6741 processor (Not actively maintained).
6745 \labelwidthstring 00.00.0000
6749 \begin_inset LatexCommand \index{-mavr}
6755 Generate code for the Atmel AVR
6756 \begin_inset LatexCommand \index{AVR}
6760 processor (Not maintained, not complete).
6761 AVR users should probably have a look at winavr
6762 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6767 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6771 , which is based on AVR-port of the gcc compiler.
6774 \begin_layout Standard
6775 \begin_inset Note Note
6778 \begin_layout Standard
6779 I think it is fair to direct users there for now.
6780 Open source is also about avoiding unnecessary work .
6781 But I didn't find the 'official' link.
6790 \labelwidthstring 00.00.0000
6794 \begin_inset LatexCommand \index{-mpic14}
6800 Generate code for the Microchip PIC 14
6801 \begin_inset LatexCommand \index{PIC14}
6805 -bit processors (p16f84 and variants.
6806 In development, not complete).
6809 \begin_layout Standard
6810 \begin_inset Note Note
6813 \begin_layout Standard
6814 p16f627 p16f628 p16f84 p16f873 p16f877?
6823 \labelwidthstring 00.00.0000
6827 \begin_inset LatexCommand \index{-mpic16}
6833 Generate code for the Microchip PIC 16
6834 \begin_inset LatexCommand \index{PIC16}
6838 -bit processors (p18f452 and variants.
6839 In development, not complete).
6843 \labelwidthstring 00.00.0000
6848 Generate code for the Toshiba TLCS-900H
6849 \begin_inset LatexCommand \index{TLCS-900H}
6853 processor (Not maintained, not complete).
6857 \labelwidthstring 00.00.0000
6861 \begin_inset LatexCommand \index{-mxa51}
6867 Generate code for the Phillips XA51
6868 \begin_inset LatexCommand \index{XA51}
6872 processor (Not maintained, not complete).
6875 \begin_layout Standard
6876 \begin_inset VSpace bigskip
6882 \begin_layout Subsection
6883 Preprocessor Options
6884 \begin_inset LatexCommand \index{Options preprocessor}
6889 \begin_inset LatexCommand \index{Preprocessor options}
6894 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6902 \labelwidthstring 00.00.0000
6906 \begin_inset LatexCommand \index{-I<path>}
6912 The additional location where the preprocessor will look for <..h> or
6913 \begin_inset Quotes eld
6917 \begin_inset Quotes erd
6924 \labelwidthstring 00.00.0000
6928 \begin_inset LatexCommand \index{-D<macro[=value]>}
6934 Command line definition of macros.
6935 Passed to the preprocessor.
6939 \labelwidthstring 00.00.0000
6943 \begin_inset LatexCommand \index{-M}
6949 Tell the preprocessor to output a rule suitable for make describing the
6950 dependencies of each object file.
6951 For each source file, the preprocessor outputs one make-rule whose target
6952 is the object file name for that source file and whose dependencies are
6953 all the files `#include'd in it.
6954 This rule may be a single line or may be continued with `
6956 '-newline if it is long.
6957 The list of rules is printed on standard output instead of the preprocessed
6960 \begin_inset LatexCommand \index{-E}
6968 \labelwidthstring 00.00.0000
6972 \begin_inset LatexCommand \index{-C}
6978 Tell the preprocessor not to discard comments.
6979 Used with the `-E' option.
6983 \labelwidthstring 00.00.0000
6987 \begin_inset LatexCommand \index{-MM}
6998 Like `-M' but the output mentions only the user header files included with
7000 \begin_inset Quotes eld
7004 System header files included with `#include <file>' are omitted.
7008 \labelwidthstring 00.00.0000
7012 \begin_inset LatexCommand \index{-Aquestion(answer)}
7018 Assert the answer answer for question, in case it is tested with a preprocessor
7019 conditional such as `#if #question(answer)'.
7020 `-A-' disables the standard assertions that normally describe the target
7025 \labelwidthstring 00.00.0000
7029 \begin_inset LatexCommand \index{-Umacro}
7035 Undefine macro macro.
7036 `-U' options are evaluated after all `-D' options, but before any `-include'
7037 and `-imacros' options.
7041 \labelwidthstring 00.00.0000
7045 \begin_inset LatexCommand \index{-dM}
7051 Tell the preprocessor to output only a list of the macro definitions that
7052 are in effect at the end of preprocessing.
7053 Used with the `-E' option.
7057 \labelwidthstring 00.00.0000
7061 \begin_inset LatexCommand \index{-dD}
7067 Tell the preprocessor to pass all macro definitions into the output, in
7068 their proper sequence in the rest of the output.
7072 \labelwidthstring 00.00.0000
7076 \begin_inset LatexCommand \index{-dN}
7087 Like `-dD' except that the macro arguments and contents are omitted.
7088 Only `#define name' is included in the output.
7092 \labelwidthstring 00.00.0000
7095 -pedantic-parse-number
7096 \begin_inset LatexCommand \index{pedantic}
7101 \begin_inset LatexCommand \index{-pedantic-parse-number}
7109 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7117 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7118 and the macro LO_B(3) gets expanded.
7119 See also #pragma pedantic_parse_number
7120 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7125 \begin_inset LatexCommand \ref{sec:Pragmas}
7131 Note: this functionality is not in conformance with C99 standard!
7135 \labelwidthstring 00.00.0000
7139 preprocessorOption[,preprocessorOption]
7142 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7147 Pass the preprocessorOption to the preprocessor
7152 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7157 SDCC uses an adapted version of the preprocessor
7161 of the GNU Compiler Collection
7162 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7171 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7175 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7180 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7187 \begin_layout Standard
7188 \begin_inset VSpace bigskip
7194 \begin_layout Subsection
7196 \begin_inset LatexCommand \index{Options linker}
7201 \begin_inset LatexCommand \index{Linker options}
7209 \labelwidthstring 00.00.0000
7219 \begin_layout Standard
7231 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7236 \begin_inset LatexCommand \index{-L -\/-lib-path}
7243 <absolute path to additional libraries> This option is passed to the linkage
7244 editor's additional libraries
7245 \begin_inset LatexCommand \index{Libraries}
7250 The path name must be absolute.
7251 Additional library files may be specified in the command line.
7252 See section Compiling programs for more details.
7256 \labelwidthstring 00.00.0000
7263 \begin_layout Standard
7275 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7280 <Value> The start location of the external ram
7281 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7285 , default value is 0.
7286 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7290 \begin_layout Standard
7299 -xram-loc 0x8000 or -
7303 \begin_layout Standard
7316 \labelwidthstring 00.00.0000
7323 \begin_layout Standard
7335 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7340 <Value> The start location of the code
7341 \begin_inset LatexCommand \index{code}
7345 segment, default value 0.
7346 Note when this option is used the interrupt vector table
7347 \begin_inset LatexCommand \index{interrupt vector table}
7351 is also relocated to the given address.
7352 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7356 \begin_layout Standard
7365 -code-loc 0x8000 or -
7369 \begin_layout Standard
7382 \labelwidthstring 00.00.0000
7389 \begin_layout Standard
7401 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7406 <Value> By default the stack
7407 \begin_inset LatexCommand \index{stack}
7411 is placed after the data segment.
7412 Using this option the stack can be placed anywhere in the internal memory
7414 The value entered can be in Hexadecimal or Decimal format, e.g.
7419 \begin_layout Standard
7428 -stack-loc 0x20 or -
7432 \begin_layout Standard
7442 Since the sp register is incremented before a push or call, the initial
7443 sp will be set to one byte prior the provided value.
7444 The provided value should not overlap any other memory areas such as used
7445 register banks or the data segment and with enough space for the current
7453 \begin_layout Standard
7466 \begin_inset LatexCommand \index{-\/-pack-iram}
7470 option (which is now a default setting) will override this setting, so
7471 you should also specify the
7477 \begin_layout Standard
7490 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7494 option if you need to manually place the stack.
7498 \labelwidthstring 00.00.0000
7505 \begin_layout Standard
7517 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7522 <Value> By default the external stack
7523 \begin_inset LatexCommand \index{xstack}
7527 is placed after the pdata
7528 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7533 Using this option the xstack can be placed anywhere in the external memory
7535 The value entered can be in Hexadecimal or Decimal format, e.g.
7540 \begin_layout Standard
7549 -xstack-loc 0x8000 or -
7553 \begin_layout Standard
7563 The provided value should not overlap any other memory areas such as the
7564 pdata or xdata segment and with enough space for the current application.
7568 \labelwidthstring 00.00.0000
7575 \begin_layout Standard
7587 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7592 <Value> The start location of the internal ram data
7593 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7598 The value entered can be in Hexadecimal or Decimal format, eg.
7603 \begin_layout Standard
7616 \begin_layout Standard
7626 (By default, the start location of the internal ram data segment is set
7627 as low as possible in memory, taking into account the used register banks
7628 and the bit segment at address 0x20.
7629 For example if register banks 0 and 1 are used without bit variables, the
7630 data segment will be set, if -
7634 \begin_layout Standard
7643 -data-loc is not used, to location 0x10.)
7647 \labelwidthstring 00.00.0000
7654 \begin_layout Standard
7666 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7671 <Value> The start location of the indirectly addressable internal ram
7672 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7676 of the 8051, default value is 0x80.
7677 The value entered can be in Hexadecimal or Decimal format, eg.
7682 \begin_layout Standard
7691 -idata-loc 0x88 or -
7695 \begin_layout Standard
7708 \labelwidthstring 00.00.0000
7715 \begin_layout Standard
7727 <Value> The start location of the bit
7728 \begin_inset LatexCommand \index{bit}
7732 addressable internal ram of the 8051.
7738 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7743 \labelwidthstring 00.00.0000
7750 \begin_layout Standard
7760 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7769 The linker output (final object code) is in Intel Hex format.
7770 \begin_inset LatexCommand \index{Intel hex format}
7774 This is the default option.
7775 The format itself is documented in the documentation of srecord
7776 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7784 \labelwidthstring 00.00.0000
7791 \begin_layout Standard
7801 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7810 The linker output (final object code) is in Motorola S19 format
7811 \begin_inset LatexCommand \index{Motorola S19 format}
7816 The format itself is documented in the documentation of srecord.
7820 \labelwidthstring 00.00.0000
7827 \begin_layout Standard
7837 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7842 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7851 The linker output (final object code) is in ELF format
7852 \begin_inset LatexCommand \index{ELF format}
7857 (Currently only supported for the HC08
7858 \begin_inset LatexCommand \index{HC08}
7866 \labelwidthstring 00.00.0000
7870 linkOption[,linkOption]
7873 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7878 Pass the linkOption to the linker.
7879 If a bootloader is used an option like
7880 \begin_inset Quotes sld
7885 \begin_inset Quotes srd
7888 would be typical to set the start of the code segment.
7889 See also #pragma constseg and #pragma codeseg in section
7890 \begin_inset LatexCommand \ref{sec:Pragmas}
7895 File sdcc/as/doc/asxhtm.html has more on linker options.
7898 \begin_layout Standard
7899 \begin_inset VSpace bigskip
7905 \begin_layout Subsection
7907 \begin_inset LatexCommand \index{Options MCS51}
7912 \begin_inset LatexCommand \index{MCS51 options}
7920 \labelwidthstring 00.00.0000
7927 \begin_layout Standard
7937 \begin_inset LatexCommand \index{-\/-model-small}
7948 Generate code for Small Model programs, see section Memory Models for more
7950 This is the default model.
7954 \labelwidthstring 00.00.0000
7961 \begin_layout Standard
7971 \begin_inset LatexCommand \index{-\/-model-medium}
7977 Generate code for Medium model programs, see section Memory Models for
7979 If this option is used all source files in the project have to be compiled
7981 It must also be used when invoking the linker.
7985 \labelwidthstring 00.00.0000
7992 \begin_layout Standard
8002 \begin_inset LatexCommand \index{-\/-model-large}
8008 Generate code for Large model programs, see section Memory Models for more
8010 If this option is used all source files in the project have to be compiled
8012 It must also be used when invoking the linker.
8016 \labelwidthstring 00.00.0000
8023 \begin_layout Standard
8033 \begin_inset LatexCommand \index{-\/-xstack}
8039 Uses a pseudo stack in the pdata
8040 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8044 area (usually the first 256 bytes in the external ram) for allocating variables
8045 and passing parameters.
8047 \begin_inset LatexCommand \ref{sub:External-Stack}
8052 External Stack for more details.
8056 \labelwidthstring 00.00.0000
8063 \begin_layout Standard
8076 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8080 Causes the linker to check if the internal ram usage is within limits of
8085 \labelwidthstring 00.00.0000
8092 \begin_layout Standard
8105 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8109 Causes the linker to check if the external ram usage is within limits of
8114 \labelwidthstring 00.00.0000
8121 \begin_layout Standard
8134 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8138 Causes the linker to check if the code memory usage is within limits of
8143 \labelwidthstring 00.00.0000
8150 \begin_layout Standard
8163 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8167 Causes the linker to check if there is at minimum <Value> bytes for stack.
8171 \labelwidthstring 00.00.0000
8178 \begin_layout Standard
8191 \begin_inset LatexCommand \index{-\/-pack-iram}
8195 Causes the linker to use unused register banks for data variables and pack
8196 data, idata and stack together.
8197 This is the default now.
8201 \labelwidthstring 00.00.0000
8208 \begin_layout Standard
8221 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8225 Causes the linker to use old style for allocating memory areas.
8229 \labelwidthstring 00.00.0000
8236 \begin_layout Standard
8249 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8253 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8255 Only use this option if your code is in the same 2k block of memory.
8256 You may need to use this option for some 8051 derivatives which lack the
8257 lcall/ljmp instructions..
8260 \begin_layout Standard
8261 \begin_inset VSpace bigskip
8267 \begin_layout Subsection
8268 DS390 / DS400 Options
8269 \begin_inset LatexCommand \index{Options DS390}
8274 \begin_inset LatexCommand \index{DS390}
8282 \labelwidthstring 00.00.0000
8289 \begin_layout Standard
8301 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8311 Generate 24-bit flat mode code.
8312 This is the one and only that the ds390 code generator supports right now
8313 and is default when using
8318 See section Memory Models for more details.
8322 \labelwidthstring 00.00.0000
8329 \begin_layout Standard
8339 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8345 disable interrupts during ESP:SP updates.
8349 \labelwidthstring 00.00.0000
8356 \begin_layout Standard
8368 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8372 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8373 This is the one and only that the ds390 code generator supports right now
8374 and is default when using
8379 In this mode, the stack is located in the lower 1K of the internal RAM,
8380 which is mapped to 0x400000.
8381 Note that the support is incomplete, since it still uses a single byte
8382 as the stack pointer.
8383 This means that only the lower 256 bytes of the potential 1K stack space
8384 will actually be used.
8385 However, this does allow you to reclaim the precious 256 bytes of low RAM
8386 for use for the DATA and IDATA segments.
8387 The compiler will not generate any code to put the processor into 10 bit
8389 It is important to ensure that the processor is in this mode before calling
8390 any re-entrant functions compiled with this option.
8391 In principle, this should work with the
8397 \begin_layout Standard
8407 \begin_inset LatexCommand \index{-\/-stack-auto}
8413 option, but that has not been tested.
8414 It is incompatible with the
8420 \begin_layout Standard
8430 \begin_inset LatexCommand \index{-\/-xstack}
8437 It also only makes sense if the processor is in 24 bit contiguous addressing
8444 \begin_layout Standard
8453 -model-flat24 option
8458 \begin_inset Note Note
8462 \labelwidthstring 00.00.0000
8469 \begin_layout Standard
8478 -stack-8-bit - switches off the 10-bit mode
8487 \labelwidthstring 00.00.0000
8494 \begin_layout Standard
8504 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8510 insert call to function __stack_probe at each function prologue.
8514 \labelwidthstring 00.00.0000
8521 \begin_layout Standard
8531 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8537 <nnnn> LibraryID used in -mTININative.
8542 \labelwidthstring 00.00.0000
8549 \begin_layout Standard
8559 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8565 generate code for DS390 Arithmetic Accelerator.
8569 \begin_layout Standard
8570 \begin_inset VSpace bigskip
8576 \begin_layout Subsection
8578 \begin_inset LatexCommand \index{Options Z80}
8583 \begin_inset LatexCommand \index{Z80}
8591 \labelwidthstring 00.00.0000
8598 \begin_layout Standard
8610 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8620 Force a called function to always save BC.
8624 \labelwidthstring 00.00.0000
8631 \begin_layout Standard
8643 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8647 When linking, skip the standard crt0.o object file.
8648 You must provide your own crt0.o for your system when linking.
8652 \labelwidthstring 00.00.0000
8659 \begin_layout Standard
8671 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8675 Determinate PORT I/O mode (<Value> is z80 or z180).
8679 \labelwidthstring 00.00.0000
8686 \begin_layout Standard
8698 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8702 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8706 \labelwidthstring 00.00.0000
8713 \begin_layout Standard
8726 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8730 Use <Value> for the code segment name.
8734 \labelwidthstring 00.00.0000
8741 \begin_layout Standard
8754 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8758 Use <Value> for the const segment name.
8762 \labelwidthstring 00.00.0000
8763 \begin_inset VSpace bigskip
8769 \begin_layout Subsection
8771 \begin_inset LatexCommand \index{Options GBZ80}
8776 \begin_inset LatexCommand \index{GBZ80}
8784 \labelwidthstring 00.00.0000
8791 \begin_layout Standard
8803 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8813 Force a called function to always save BC.
8817 \labelwidthstring 00.00.0000
8824 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8828 Use code bank <Num>.
8832 \labelwidthstring 00.00.0000
8839 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8843 Use data bank <Num>.
8847 \labelwidthstring 00.00.0000
8854 \begin_layout Standard
8867 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8871 Use <Value> for the code segment name.
8875 \labelwidthstring 00.00.0000
8882 \begin_layout Standard
8895 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8899 Use <Value> for the const segment name.
8902 \begin_layout Standard
8903 \begin_inset VSpace bigskip
8909 \begin_layout Subsection
8910 Optimization Options
8911 \begin_inset LatexCommand \index{Options optimization}
8916 \begin_inset LatexCommand \index{Optimization options}
8924 \labelwidthstring 00.00.0000
8931 \begin_layout Standard
8941 \begin_inset LatexCommand \index{-\/-nogcse}
8947 Will not do global subexpression elimination, this option may be used when
8948 the compiler creates undesirably large stack/data spaces to store compiler
8958 \begin_inset LatexCommand \index{sloc (spill location)}
8963 A warning message will be generated when this happens and the compiler
8964 will indicate the number of extra bytes it allocated.
8965 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8967 \begin_inset LatexCommand \index{\#pragma nogcse}
8971 can be used to turn off global subexpression elimination
8972 \begin_inset LatexCommand \index{Subexpression elimination}
8976 for a given function only.
8980 \labelwidthstring 00.00.0000
8987 \begin_layout Standard
8997 \begin_inset LatexCommand \index{-\/-noinvariant}
9003 Will not do loop invariant optimizations, this may be turned off for reasons
9004 explained for the previous option.
9005 For more details of loop optimizations performed see Loop Invariants in
9007 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9012 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9014 \begin_inset LatexCommand \index{\#pragma noinvariant}
9018 can be used to turn off invariant optimizations for a given function only.
9022 \labelwidthstring 00.00.0000
9029 \begin_layout Standard
9039 \begin_inset LatexCommand \index{-\/-noinduction}
9045 Will not do loop induction optimizations, see section strength reduction
9047 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9049 \begin_inset LatexCommand \index{\#pragma noinduction}
9053 can be used to turn off induction optimizations for a given function only.
9057 \labelwidthstring 00.00.0000
9064 \begin_layout Standard
9074 \begin_inset LatexCommand \index{-\/-nojtbound}
9085 Will not generate boundary condition check when switch statements
9086 \begin_inset LatexCommand \index{switch statement}
9090 are implemented using jump-tables.
9092 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9097 Switch Statements for more details.
9098 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9100 \begin_inset LatexCommand \index{\#pragma nojtbound}
9104 can be used to turn off boundary checking for jump tables for a given function
9109 \labelwidthstring 00.00.0000
9116 \begin_layout Standard
9126 \begin_inset LatexCommand \index{-\/-noloopreverse}
9135 Will not do loop reversal
9136 \begin_inset LatexCommand \index{Loop reversing}
9144 \labelwidthstring 00.00.0000
9149 \begin_layout Standard
9163 \begin_inset LatexCommand \index{-\/-nolabelopt }
9167 Will not optimize labels (makes the dumpfiles more readable).
9171 \labelwidthstring 00.00.0000
9178 \begin_layout Standard
9188 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9194 Will not memcpy initialized data from code space into xdata space.
9195 This saves a few bytes in code space if you don't have initialized data
9196 \begin_inset LatexCommand \index{Variable initialization}
9204 \labelwidthstring 00.00.0000
9211 \begin_layout Standard
9221 \begin_inset LatexCommand \index{-\/-nooverlay}
9227 The compiler will not overlay parameters and local variables of any function,
9228 see section Parameters and local variables for more details.
9232 \labelwidthstring 00.00.0000
9239 \begin_layout Standard
9249 \begin_inset LatexCommand \index{-\/-no-peep}
9255 Disable peep-hole optimization with built-in rules.
9259 \labelwidthstring 00.00.0000
9266 \begin_layout Standard
9278 \begin_inset LatexCommand \index{-\/-peep-file}
9283 <filename> This option can be used to use additional rules to be used by
9284 the peep hole optimizer.
9286 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9291 Peep Hole optimizations for details on how to write these rules.
9295 \labelwidthstring 00.00.0000
9302 \begin_layout Standard
9312 \begin_inset LatexCommand \index{-\/-peep-asm}
9318 Pass the inline assembler code through the peep hole optimizer.
9319 This can cause unexpected changes to inline assembler code, please go through
9320 the peephole optimizer
9321 \begin_inset LatexCommand \index{Peephole optimizer}
9325 rules defined in the source file tree '<target>/peeph.def' before using
9330 \labelwidthstring 00.00.0000
9337 \begin_layout Standard
9347 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9353 The compiler will optimize code generation towards fast code, possibly
9354 at the expense of code size.
9358 \labelwidthstring 00.00.0000
9365 \begin_layout Standard
9375 \begin_inset LatexCommand \index{-\/-opt-code-size}
9381 The compiler will optimize code generation towards compact code, possibly
9382 at the expense of code speed.
9385 \begin_layout Standard
9386 \begin_inset VSpace bigskip
9392 \begin_layout Subsection
9394 \begin_inset LatexCommand \index{Options other}
9402 \labelwidthstring 00.00.0000
9410 \begin_layout Standard
9420 \begin_inset LatexCommand \index{-\/-compile-only}
9425 \begin_inset LatexCommand \index{-c -\/-compile-only}
9431 will compile and assemble the source, but will not call the linkage editor.
9435 \labelwidthstring 00.00.0000
9444 \begin_layout Standard
9456 \begin_inset LatexCommand \index{-\/-c1mode}
9462 reads the preprocessed source from standard input and compiles it.
9463 The file name for the assembler output must be specified using the -o option.
9467 \labelwidthstring 00.00.0000
9471 \begin_inset LatexCommand \index{-E}
9477 Run only the C preprocessor.
9478 Preprocess all the C source files specified and output the results to standard
9483 \labelwidthstring 00.00.0000
9488 \begin_inset LatexCommand \index{-o <path/file>}
9494 The output path where everything will be placed or the file name used for
9495 all generated output files.
9496 If the parameter is a path, it must have a trailing slash (or backslash
9497 for the Windows binaries) to be recognized as a path.
9502 Note for Windows users: if the path contains spaces, it should be surrounded
9504 The trailing backslash should be doubled in order to prevent escaping the
9505 final quote, for example:
9508 \begin_inset Quotes sld
9522 \begin_inset Quotes srd
9527 or put after the final quote, for example:
9530 \begin_inset Quotes sld
9540 \begin_inset Quotes srd
9548 The path using slashes for directory delimiters can be used too, for example:
9552 \begin_inset Quotes sld
9555 F:/Projects/test3/output 1/
9556 \begin_inset Quotes srd
9565 \labelwidthstring 00.00.0000
9572 \begin_layout Standard
9582 \begin_inset LatexCommand \index{-\/-stack-auto}
9593 All functions in the source file will be compiled as
9598 \begin_inset LatexCommand \index{reentrant}
9603 the parameters and local variables will be allocated on the stack
9604 \begin_inset LatexCommand \index{stack}
9610 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9614 Parameters and Local Variables for more details.
9615 If this option is used all source files in the project should be compiled
9617 It automatically implies -
9623 \begin_layout Standard
9634 -int-long-reent and -
9640 \begin_layout Standard
9656 \labelwidthstring 00.00.0000
9663 \begin_layout Standard
9673 \begin_inset LatexCommand \index{-\/-callee-saves}
9678 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9682 function1[,function2][,function3]....
9685 The compiler by default uses a caller saves convention for register saving
9686 across function calls, however this can cause unnecessary register pushing
9687 and popping when calling small functions from larger functions.
9688 This option can be used to switch the register saving convention for the
9689 function names specified.
9690 The compiler will not save registers when calling these functions, no extra
9691 code will be generated at the entry and exit (function prologue
9694 \begin_inset LatexCommand \index{function prologue}
9703 \begin_inset LatexCommand \index{function epilogue}
9709 ) for these functions to save and restore the registers used by these functions,
9710 this can SUBSTANTIALLY reduce code and improve run time performance of
9712 In the future the compiler (with inter procedural analysis) will be able
9713 to determine the appropriate scheme to use for each function call.
9714 DO NOT use this option for built-in functions such as _mulint..., if this
9715 option is used for a library function the appropriate library function
9716 needs to be recompiled with the same option.
9717 If the project consists of multiple source files then all the source file
9718 should be compiled with the same -
9722 \begin_layout Standard
9731 -callee-saves option string.
9732 Also see #pragma\InsetSpace ~
9734 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9739 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9747 \labelwidthstring 00.00.0000
9754 \begin_layout Standard
9764 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9778 \begin_layout Standard
9787 -callee-saves will be applied to all functions by default.
9791 \labelwidthstring 00.00.0000
9798 \begin_layout Standard
9808 \begin_inset LatexCommand \index{-\/-debug}
9817 When this option is used the compiler will generate debug information.
9818 The debug information collected in a file with .cdb extension can be used
9820 For more information see documentation for SDCDB.
9821 Another file with no extension contains debug information in AOMF or AOMF51
9822 \begin_inset LatexCommand \index{AOMF, AOMF51}
9826 format which is commonly used by third party tools.
9830 \labelwidthstring 00.00.0000
9834 \begin_inset LatexCommand \index{-S}
9845 Stop after the stage of compilation proper; do not assemble.
9846 The output is an assembler code file for the input file specified.
9850 \labelwidthstring 00.00.0000
9857 \begin_layout Standard
9867 \begin_inset LatexCommand \index{-\/-int-long-reent}
9873 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9874 Note by default these libraries are compiled as non-reentrant.
9875 See section Installation for more details.
9879 \labelwidthstring 00.00.0000
9886 \begin_layout Standard
9896 \begin_inset LatexCommand \index{-\/-cyclomatic}
9905 This option will cause the compiler to generate an information message for
9906 each function in the source file.
9907 The message contains some
9911 information about the function.
9912 The number of edges and nodes the compiler detected in the control flow
9913 graph of the function, and most importantly the
9915 cyclomatic complexity
9916 \begin_inset LatexCommand \index{Cyclomatic complexity}
9922 see section on Cyclomatic Complexity for more details.
9926 \labelwidthstring 00.00.0000
9933 \begin_layout Standard
9943 \begin_inset LatexCommand \index{-\/-float-reent}
9949 Floating point library is compiled as reentrant
9950 \begin_inset LatexCommand \index{reentrant}
9955 See section Installation for more details.
9959 \labelwidthstring 00.00.0000
9966 \begin_layout Standard
9976 \begin_inset LatexCommand \index{-\/-funsigned-char}
9982 The default signedness for every type is
9987 In some embedded environments the default signedness of
9996 To set the signess for characters to unsigned, use the option -
10002 \begin_layout Standard
10014 If this option is set and no signedness keyword (unsigned/signed) is given,
10015 a char will be signed.
10016 All other types are unaffected.
10020 \labelwidthstring 00.00.0000
10027 \begin_layout Standard
10037 \begin_inset LatexCommand \index{-\/-main-return}
10043 This option can be used if the code generated is called by a monitor program
10044 or if the main routine includes an endless loop.
10045 This option results in slightly smaller code and saves two bytes of stack
10047 The return from the 'main'
10048 \begin_inset LatexCommand \index{main return}
10052 function will return to the function calling main.
10053 The default setting is to lock up i.e.
10062 \labelwidthstring 00.00.0000
10069 \begin_layout Standard
10079 \begin_inset LatexCommand \index{-\/-nostdinc}
10085 This will prevent the compiler from passing on the default include path
10086 to the preprocessor.
10090 \labelwidthstring 00.00.0000
10097 \begin_layout Standard
10107 \begin_inset LatexCommand \index{-\/-nostdlib}
10113 This will prevent the compiler from passing on the default library
10114 \begin_inset LatexCommand \index{Libraries}
10118 path to the linker.
10122 \labelwidthstring 00.00.0000
10129 \begin_layout Standard
10139 \begin_inset LatexCommand \index{-\/-verbose}
10145 Shows the various actions the compiler is performing.
10149 \labelwidthstring 00.00.0000
10153 \begin_inset LatexCommand \index{-V}
10159 Shows the actual commands the compiler is executing.
10163 \labelwidthstring 00.00.0000
10170 \begin_layout Standard
10180 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10186 Hides your ugly and inefficient c-code from the asm file, so you can always
10187 blame the compiler :)
10191 \labelwidthstring 00.00.0000
10198 \begin_layout Standard
10208 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10214 Include code generator and peep-hole comments in the generated asm files.
10218 \labelwidthstring 00.00.0000
10225 \begin_layout Standard
10235 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10241 Don't include peep-hole comments in the generated asm files even if -
10247 \begin_layout Standard
10258 -fverbose-asm option is specified.
10262 \labelwidthstring 00.00.0000
10269 \begin_layout Standard
10279 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10285 Include i-codes in the asm file.
10286 Sounds like noise but is most helpful for debugging the compiler itself.
10290 \labelwidthstring 00.00.0000
10297 \begin_layout Standard
10307 \begin_inset LatexCommand \index{pedantic}
10312 \begin_inset LatexCommand \index{-\/-less-pedantic}
10319 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10323 Disable some of the more pedantic warnings
10324 \begin_inset LatexCommand \index{Warnings}
10329 For more details, see the less_pedantic pragma
10330 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10338 \labelwidthstring 00.00.0000
10345 \begin_layout Standard
10354 -disable-warning\InsetSpace ~
10356 \begin_inset LatexCommand \index{-\/-disable-warning}
10362 Disable specific warning with number <nnnn>.
10366 \labelwidthstring 00.00.0000
10373 \begin_layout Standard
10383 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10389 Display the directories in the compiler's search path
10393 \labelwidthstring 00.00.0000
10400 \begin_layout Standard
10410 \begin_inset LatexCommand \index{-\/-vc}
10416 Display errors and warnings using MSVC style, so you can use SDCC with
10417 the visual studio IDE
10418 \begin_inset LatexCommand \index{IDE}
10423 With SDCC both offering a GCC-like (the default) and a MSVC-like
10424 \begin_inset LatexCommand \index{MSVC output style}
10428 output style, integration into most programming editors should be straightforwa
10433 \labelwidthstring 00.00.0000
10440 \begin_layout Standard
10450 \begin_inset LatexCommand \index{-\/-use-stdout}
10456 Send errors and warnings to stdout instead of stderr.
10460 \labelwidthstring 00.00.0000
10464 asmOption[,asmOption]
10467 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10472 Pass the asmOption to the assembler
10473 \begin_inset LatexCommand \index{Options assembler}
10478 \begin_inset LatexCommand \index{Assembler options}
10483 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10487 \labelwidthstring 00.00.0000
10494 \begin_layout Standard
10504 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10510 Generally follow the C89 standard, but allow SDCC features that conflict
10511 with the standard (default).
10515 \labelwidthstring 00.00.0000
10522 \begin_layout Standard
10532 \begin_inset LatexCommand \index{-\/-std-c89}
10538 Follow the C89 standard and disable SDCC features that conflict with the
10543 \labelwidthstring 00.00.0000
10550 \begin_layout Standard
10560 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10566 Generally follow the C99 standard, but allow SDCC features that conflict
10567 with the standard (incomplete support).
10571 \labelwidthstring 00.00.0000
10578 \begin_layout Standard
10588 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10594 Follow the C99 standard and disable SDCC features that conflict with the
10595 standard (incomplete support).
10599 \labelwidthstring 00.00.0000
10606 \begin_layout Standard
10618 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10623 <Name> The name to be used for the code
10624 \begin_inset LatexCommand \index{code}
10628 segment, default CSEG.
10629 This is useful if you need to tell the compiler to put the code in a special
10630 segment so you can later on tell the linker to put this segment in a special
10632 Can be used for instance when using bank switching to put the code in a
10637 \labelwidthstring 00.00.0000
10644 \begin_layout Standard
10656 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10661 <Name> The name to be used for the const
10662 \begin_inset LatexCommand \index{const}
10666 segment, default CONST.
10667 This is useful if you need to tell the compiler to put the const data in
10668 a special segment so you can later on tell the linker to put this segment
10669 in a special place in memory.
10670 Can be used for instance when using bank switching to put the const data
10675 \labelwidthstring 00.00.0000
10682 \begin_layout Standard
10691 -fdollars-in-identifiers
10692 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10698 Permit '$' as an identifier character.
10702 \labelwidthstring 00.00.0000
10709 \begin_layout Standard
10721 \begin_inset LatexCommand \index{-\/-more-pedantic}
10726 \begin_inset LatexCommand \index{pedantic}
10736 a SDCC compiler option but if you want
10740 warnings you can use a separate tool dedicated to syntax checking like
10742 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10747 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10752 \begin_inset LatexCommand \url{http://www.splint.org}
10757 To make your source files parseable by splint you will have to include
10763 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10767 in your source file and add brackets around extended keywords (like
10770 \begin_inset Quotes sld
10783 \begin_inset Quotes srd
10791 \begin_inset Quotes sld
10794 __interrupt\InsetSpace ~
10796 \begin_inset Quotes srd
10804 Splint has an excellent on line manual at
10805 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10809 and it's capabilities go beyond pure syntax checking.
10810 You'll need to tell splint the location of SDCC's include files so a typical
10811 command line could look like this:
10815 splint\InsetSpace ~
10817 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10823 \labelwidthstring 00.00.0000
10830 \begin_layout Standard
10842 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10847 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10851 Treat short as 8-bit (for backward compatibility with older versions of
10852 compiler - see section
10853 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10860 \begin_layout Standard
10861 \begin_inset VSpace bigskip
10867 \begin_layout Subsection
10868 Intermediate Dump Options
10869 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10874 \begin_inset LatexCommand \index{Options intermediate dump}
10879 \begin_inset LatexCommand \index{Intermediate dump options}
10886 \begin_layout Standard
10887 The following options are provided for the purpose of retargetting and debugging
10889 They provide a means to dump the intermediate code (iCode
10890 \begin_inset LatexCommand \index{iCode}
10894 ) generated by the compiler in human readable form at various stages of
10895 the compilation process.
10896 More on iCodes see chapter
10897 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10902 \begin_inset Quotes srd
10905 The anatomy of the compiler
10906 \begin_inset Quotes srd
10913 \labelwidthstring 00.00.0000
10920 \begin_layout Standard
10930 \begin_inset LatexCommand \index{-\/-dumpraw}
10936 This option will cause the compiler to dump the intermediate code into
10939 <source filename>.dumpraw
10941 just after the intermediate code has been generated for a function, i.e.
10942 before any optimizations are done.
10944 \begin_inset LatexCommand \index{Basic blocks}
10948 at this stage ordered in the depth first number, so they may not be in
10949 sequence of execution.
10953 \labelwidthstring 00.00.0000
10960 \begin_layout Standard
10970 \begin_inset LatexCommand \index{-\/-dumpgcse}
10976 Will create a dump of iCodes, after global subexpression elimination
10977 \begin_inset LatexCommand \index{Global subexpression elimination}
10981 , into a file named
10983 <source filename>.dumpgcse.
10987 \labelwidthstring 00.00.0000
10994 \begin_layout Standard
11004 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11010 Will create a dump of iCodes, after deadcode elimination
11011 \begin_inset LatexCommand \index{Dead-code elimination}
11015 , into a file named
11017 <source filename>.dumpdeadcode.
11021 \labelwidthstring 00.00.0000
11028 \begin_layout Standard
11038 \begin_inset LatexCommand \index{-\/-dumploop}
11047 Will create a dump of iCodes, after loop optimizations
11048 \begin_inset LatexCommand \index{Loop optimization}
11052 , into a file named
11054 <source filename>.dumploop.
11058 \labelwidthstring 00.00.0000
11065 \begin_layout Standard
11075 \begin_inset LatexCommand \index{-\/-dumprange}
11084 Will create a dump of iCodes, after live range analysis
11085 \begin_inset LatexCommand \index{Live range analysis}
11089 , into a file named
11091 <source filename>.dumprange.
11095 \labelwidthstring 00.00.0000
11102 \begin_layout Standard
11112 \begin_inset LatexCommand \index{-\/-dumlrange}
11118 Will dump the life ranges
11119 \begin_inset LatexCommand \index{Live range analysis}
11127 \labelwidthstring 00.00.0000
11134 \begin_layout Standard
11144 \begin_inset LatexCommand \index{-\/-dumpregassign}
11153 Will create a dump of iCodes, after register assignment
11154 \begin_inset LatexCommand \index{Register assignment}
11158 , into a file named
11160 <source filename>.dumprassgn.
11164 \labelwidthstring 00.00.0000
11171 \begin_layout Standard
11181 \begin_inset LatexCommand \index{-\/-dumplrange}
11187 Will create a dump of the live ranges of iTemp's
11191 \labelwidthstring 00.00.0000
11198 \begin_layout Standard
11208 \begin_inset LatexCommand \index{-\/-dumpall}
11219 Will cause all the above mentioned dumps to be created.
11222 \begin_layout Standard
11223 \begin_inset VSpace bigskip
11229 \begin_layout Subsection
11230 Redirecting output on Windows Shells
11233 \begin_layout Standard
11234 By default SDCC writes its error messages to
11235 \begin_inset Quotes sld
11239 \begin_inset Quotes srd
11243 To force all messages to
11244 \begin_inset Quotes sld
11248 \begin_inset Quotes srd
11260 \begin_layout Standard
11275 \begin_inset LatexCommand \index{-\/-use-stdout}
11280 Additionally, if you happen to have visual studio installed in your windows
11281 machine, you can use it to compile your sources using a custom build and
11288 \begin_layout Standard
11300 \begin_inset LatexCommand \index{-\/-vc}
11305 Something like this should work:
11324 \begin_layout Standard
11343 \begin_layout Standard
11355 -model-large -c $(InputPath)
11358 \begin_inset VSpace bigskip
11364 \begin_layout Section
11365 Environment variables
11366 \begin_inset LatexCommand \index{Environment variables}
11373 \begin_layout Standard
11374 SDCC recognizes the following environment variables:
11378 \labelwidthstring 00.00.0000
11382 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11388 SDCC installs a signal handler
11389 \begin_inset LatexCommand \index{signal handler}
11393 to be able to delete temporary files after an user break (^C) or an exception.
11394 If this environment variable is set, SDCC won't install the signal handler
11395 in order to be able to debug SDCC.
11399 \labelwidthstring 00.00.0000
11405 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11411 Path, where temporary files will be created.
11412 The order of the variables is the search order.
11413 In a standard *nix environment these variables are not set, and there's
11414 no need to set them.
11415 On Windows it's recommended to set one of them.
11419 \labelwidthstring 00.00.0000
11423 \begin_inset LatexCommand \index{SDCC\_HOME}
11430 \begin_inset LatexCommand \ref{sub:Install-paths}
11436 \begin_inset Quotes sld
11440 \begin_inset Quotes srd
11447 \labelwidthstring 00.00.0000
11451 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11458 \begin_inset LatexCommand \ref{sub:Search-Paths}
11464 \begin_inset Quotes sld
11468 \begin_inset Quotes srd
11475 \labelwidthstring 00.00.0000
11479 \begin_inset LatexCommand \index{SDCC\_LIB}
11486 \begin_inset LatexCommand \ref{sub:Search-Paths}
11492 \begin_inset Quotes sld
11496 \begin_inset Quotes srd
11502 \begin_layout Standard
11503 There are some more environment variables recognized by SDCC, but these
11504 are solely used for debugging purposes.
11505 They can change or disappear very quickly, and will never be documented.
11506 \begin_inset VSpace bigskip
11512 \begin_layout Section
11513 Storage Class Language Extensions
11516 \begin_layout Subsection
11517 MCS51/DS390 Storage Class
11518 \begin_inset LatexCommand \index{Storage class}
11522 Language Extensions
11525 \begin_layout Standard
11526 In addition to the ANSI storage classes SDCC allows the following MCS51
11527 specific storage classes:
11530 \begin_layout Subsubsection
11532 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11537 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11542 \begin_inset LatexCommand \index{near (storage class)}
11547 \begin_inset LatexCommand \index{\_\_near (storage class)}
11554 \begin_layout Standard
11559 storage class for the Small Memory model (
11567 or the more ANSI-C compliant forms
11575 can be used synonymously).
11576 Variables declared with this storage class will be allocated in the directly
11577 addressable portion of the internal RAM of a 8051, e.g.:
11580 \begin_layout Verse
11583 __data unsigned char test_data;
11586 \begin_layout Standard
11587 Writing 0x01 to this variable generates the assembly code:
11590 \begin_layout Verse
11593 75*00 01\InsetSpace ~
11601 \begin_layout Subsubsection
11603 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11608 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11613 \begin_inset LatexCommand \index{far (storage class)}
11618 \begin_inset LatexCommand \index{\_\_far (storage class)}
11625 \begin_layout Standard
11626 Variables declared with this storage class will be placed in the external
11632 storage class for the Large Memory model, e.g.:
11635 \begin_layout Verse
11638 __xdata unsigned char test_xdata;
11641 \begin_layout Standard
11642 Writing 0x01 to this variable generates the assembly code:
11645 \begin_layout Verse
11648 90s00r00\InsetSpace ~
11679 \begin_layout Subsubsection
11681 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11686 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11693 \begin_layout Standard
11694 Variables declared with this storage class will be allocated into the indirectly
11695 addressable portion of the internal ram of a 8051, e.g.:
11698 \begin_layout Verse
11701 __idata unsigned char test_idata;
11704 \begin_layout Standard
11705 Writing 0x01 to this variable generates the assembly code:
11708 \begin_layout Verse
11735 \begin_layout Standard
11736 Please note, the first 128 byte of idata physically access the same RAM
11737 as the data memory.
11738 The original 8051 had 128 byte idata memory, nowadays most devices have
11739 256 byte idata memory.
11741 \begin_inset LatexCommand \index{stack}
11745 is located in idata memory.
11748 \begin_layout Subsubsection
11750 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11755 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11762 \begin_layout Standard
11763 Paged xdata access is just as straightforward as using the other addressing
11765 It is typically located at the start of xdata and has a maximum size of
11767 The following example writes 0x01 to the pdata variable.
11768 Please note, pdata access physically accesses xdata memory.
11769 The high byte of the address is determined by port P2
11770 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11774 (or in case of some 8051 variants by a separate Special Function Register,
11776 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11785 storage class for the Medium Memory model, e.g.:
11788 \begin_layout Verse
11791 __pdata unsigned char test_pdata;
11794 \begin_layout Standard
11795 Writing 0x01 to this variable generates the assembly code:
11798 \begin_layout Verse
11807 mov r0,#_test_pdata
11829 \begin_layout Standard
11834 \begin_layout Standard
11844 \begin_inset LatexCommand \index{-\/-xstack}
11848 option is used the pdata memory area is followed by the xstack memory area
11849 and the sum of their sizes is limited to 256 bytes.
11852 \begin_layout Subsubsection
11854 \begin_inset LatexCommand \index{code}
11859 \begin_inset LatexCommand \index{\_\_code}
11866 \begin_layout Standard
11867 'Variables' declared with this storage class will be placed in the code
11871 \begin_layout Verse
11874 __code unsigned char test_code;
11877 \begin_layout Standard
11878 Read access to this variable generates the assembly code:
11881 \begin_layout Verse
11884 90s00r6F\InsetSpace ~
11887 mov dptr,#_test_code
11912 \begin_layout Standard
11917 indexed arrays of characters in code memory can be accessed efficiently:
11920 \begin_layout Verse
11923 __code char test_array[] = {'c','h','e','a','p'};
11926 \begin_layout Standard
11927 Read access to this array using an 8-bit unsigned index generates the assembly
11931 \begin_layout Verse
11943 \begin_layout Verse
11946 90s00r41\InsetSpace ~
11949 mov dptr,#_test_array
11952 \begin_layout Verse
11967 \begin_layout Subsubsection
11969 \begin_inset LatexCommand \index{bit}
11974 \begin_inset LatexCommand \index{\_\_bit}
11981 \begin_layout Standard
11982 This is a data-type and a storage class specifier.
11983 When a variable is declared as a bit, it is allocated into the bit addressable
11984 memory of 8051, e.g.:
11987 \begin_layout Verse
11993 \begin_layout Standard
11994 Writing 1 to this variable generates the assembly code:
11997 \begin_layout Verse
12011 \begin_layout Standard
12012 The bit addressable memory consists of 128 bits which are located from 0x20
12013 to 0x2f in data memory.
12016 Apart from this 8051 specific storage class most architectures support
12018 \begin_inset LatexCommand \index{bitfields}
12026 \begin_layout Standard
12027 Not really meant as examples, but nevertheless showing what bitfields are
12028 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12034 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12035 signed modifier are implemented as unsigned.
12038 \begin_layout Subsubsection
12040 \begin_inset LatexCommand \index{sfr}
12045 \begin_inset LatexCommand \index{\_\_sfr}
12050 \begin_inset LatexCommand \index{sfr16}
12055 \begin_inset LatexCommand \index{\_\_sfr16}
12060 \begin_inset LatexCommand \index{sfr32}
12065 \begin_inset LatexCommand \index{\_\_sfr32}
12070 \begin_inset LatexCommand \index{\_\_sbit}
12075 \begin_inset LatexCommand \index{sbit}
12082 \begin_layout Standard
12083 Like the bit keyword,
12085 sfr / sfr16 / sfr32 / sbit
12087 signify both a data-type and storage class, they are used to describe the
12108 variables of a 8051, eg:
12111 \begin_layout Verse
12115 \begin_inset LatexCommand \index{at}
12120 \begin_inset LatexCommand \index{\_\_at}
12124 (0x80) P0;\InsetSpace ~
12125 /* special function register P0 at location 0x80 */
12130 special function register combination for timer 0
12134 with the high byte at
12135 location 0x8C and the low byte at location 0x8A */
12137 __sfr16 __at (0x8C8A)
12143 \begin_inset LatexCommand \index{at}
12148 \begin_inset LatexCommand \index{\_\_at}
12152 (0xd7) CY;\InsetSpace ~
12154 \begin_inset LatexCommand \index{Flags}
12159 \begin_inset LatexCommand \index{Carry flag}
12166 \begin_layout Standard
12167 Special function registers which are located on an address dividable by
12168 8 are bit-addressable, an
12172 addresses a specific bit within these sfr.
12174 16 Bit and 32 bit special function
12175 register combinations which require a certain access order are better not
12185 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12186 this is not guaranteed.
12191 \begin_layout Standard
12192 Please note, if you use a header file which was written for another compiler
12193 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12199 Specifically the syntax
12202 sfr P0 = 0x80;\InsetSpace ~
12209 by SDCC to an assignment of 0x80 to a variable called P0
12212 \begin_inset Marginal
12215 \begin_layout Standard
12227 Nevertheless it is possible to write header files
12228 \begin_inset LatexCommand \index{Header files}
12233 \begin_inset LatexCommand \index{Include files}
12237 which can be shared among different compilers (see section
12238 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12246 \begin_layout Subsubsection
12248 \begin_inset LatexCommand \index{Pointer}
12252 to MCS51/DS390 specific memory spaces
12255 \begin_layout Standard
12256 SDCC allows (via language extensions) pointers to explicitly point to any
12257 of the memory spaces
12258 \begin_inset LatexCommand \index{Memory model}
12263 In addition to the explicit pointers, the compiler uses (by default) generic
12264 pointers which can be used to point to any of the memory spaces.
12269 declaration examples:
12272 \begin_layout Verse
12275 /* pointer physically in internal ram pointing to object in external ram
12278 __xdata unsigned char * __data p;
12282 /* pointer physically in external ram
12283 pointing to object in internal ram */
12285 __data unsigned char * __xdata p;
12290 pointer physically in code rom pointing to data in xdata space */
12293 unsigned char * __code p;
12297 /* pointer physically in code space pointing to
12298 data in code space */
12300 __code unsigned char * __code p;
12305 physically located in xdata space */
12307 unsigned char * __xdata p;
12312 pointer physically located in default memory space */
12319 the following is a function pointer
12320 \begin_inset LatexCommand \index{function pointer}
12324 physically located in data space */
12326 char (* __data fp)(void);
12329 \begin_layout Standard
12330 Well you get the idea.
12335 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12348 The highest order byte of the
12352 pointers contains the data space information.
12353 Assembler support routines are called whenever data is stored or retrieved
12359 These are useful for developing reusable library
12360 \begin_inset LatexCommand \index{Libraries}
12365 Explicitly specifying the pointer
12366 \begin_inset LatexCommand \index{pointer}
12370 type will generate the most efficient code.
12373 \begin_layout Subsubsection
12374 Notes on MCS51 memory
12375 \begin_inset LatexCommand \index{MCS51 memory}
12382 \begin_layout Standard
12383 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12384 RAM memory which is structured as follows:
12388 - Bytes 00-1F - 32 bytes to hold
12389 up to 4 banks of the registers R0 to R7,
12391 - Bytes 20-2F - 16 bytes to hold
12393 \begin_inset LatexCommand \index{bit}
12399 - Bytes 30-7F - 80 bytes for general purpose use.
12404 \begin_layout Standard
12405 Additionally some members of the MCS51 family may have up to 128 bytes of
12406 additional, indirectly addressable, internal RAM memory (
12411 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12416 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12421 Furthermore, some chips may have some built in external memory (
12426 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12431 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12435 ) which should not be confused with the internal, directly addressable RAM
12441 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12446 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12451 Sometimes this built in
12455 memory has to be activated before using it (you can probably find this
12456 information on the datasheet of the microcontroller your are using, see
12458 \begin_inset LatexCommand \ref{sub:Startup-Code}
12466 \begin_layout Standard
12467 Normally SDCC will only use the first bank
12468 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12472 of registers (register bank 0), but it is possible to specify that other
12473 banks of registers (keyword
12480 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12485 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12491 ) should be used for example in interrupt
12492 \begin_inset LatexCommand \index{interrupt}
12497 \begin_inset LatexCommand \index{\_\_interrupt}
12502 By default, the compiler will place the stack after the last byte of allocated
12503 memory for variables.
12504 For example, if the first 2 banks of registers are used, and only four
12509 variables, it will position the base of the internal stack at address 20
12511 This implies that as the stack
12512 \begin_inset LatexCommand \index{stack}
12516 grows, it will use up the remaining register banks, and the 16 bytes used
12517 by the 128 bit variables, and 80 bytes for general purpose use.
12518 If any bit variables are used, the data variables will be placed in unused
12519 register banks and after the byte holding the last bit variable.
12520 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12525 variables will be placed starting from address 0x10 to 0x20 and continue
12531 \begin_layout Standard
12541 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12545 to specify the start address of the
12553 \begin_layout Standard
12563 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12567 to specify the size of the total internal RAM (
12581 \begin_layout Standard
12582 By default the 8051 linker will place the stack after the last byte of (i)data
12588 \begin_layout Standard
12598 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12602 allows you to specify the start of the stack, i.e.
12603 you could start it after any data in the general purpose area.
12604 If your microcontroller has additional indirectly addressable internal
12609 ) you can place the stack on it.
12610 You may also need to use -
12614 \begin_layout Standard
12624 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12628 to set the start address of the external RAM (
12636 \begin_layout Standard
12646 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12650 to specify its size.
12651 Same goes for the code memory, using -
12655 \begin_layout Standard
12665 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12673 \begin_layout Standard
12683 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12688 If in doubt, don't specify any options and see if the resulting memory
12689 layout is appropriate, then you can adjust it.
12692 \begin_layout Standard
12693 The linker generates two files with memory allocation information.
12694 The first, with extension .map
12695 \begin_inset LatexCommand \index{<file>.map}
12699 shows all the variables and segments.
12700 The second with extension .mem
12701 \begin_inset LatexCommand \index{<file>.mem}
12705 shows the final memory layout.
12706 The linker will complain either if memory segments overlap, there is not
12707 enough memory, or there is not enough space for stack.
12708 If you get any linking warnings and/or errors related to stack or segments
12709 allocation, take a look at either the .map or .mem files to find out what
12711 The .mem file may even suggest a solution to the problem.
12712 \begin_inset VSpace bigskip
12718 \begin_layout Subsection
12719 Z80/Z180 Storage Class
12720 \begin_inset LatexCommand \index{Z80!Storage class}
12724 Language Extensions
12727 \begin_layout Subsubsection
12729 \begin_inset LatexCommand \index{sfr}
12734 \begin_inset LatexCommand \index{\_\_sfr}
12738 (in/out to 8-bit addresses)
12741 \begin_layout Standard
12743 \begin_inset LatexCommand \index{Z80}
12747 family has separate address spaces for memory and
12757 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12762 \begin_inset LatexCommand \index{Z80!I/O memory}
12767 \begin_inset LatexCommand \index{Z180!I/O memory}
12771 is accessed with special instructions, e.g.:
12774 \begin_layout Verse
12777 sfr at 0x78 IoPort;\InsetSpace ~
12779 /* define a var in I/O space at 78h called IoPort */
12783 \begin_layout Standard
12784 Writing 0x01 to this variable generates the assembly code:
12787 \begin_layout Verse
12807 \begin_layout Subsubsection
12809 \begin_inset LatexCommand \index{sfr}
12814 \begin_inset LatexCommand \index{\_\_sfr}
12818 (in/out to 16-bit addresses)
12821 \begin_layout Standard
12826 is used to support 16 bit addresses in I/O memory e.g.:
12829 \begin_layout Verse
12833 \begin_inset LatexCommand \index{at}
12838 \begin_inset LatexCommand \index{\_\_at}
12845 \begin_layout Standard
12846 Writing 0x01 to this variable generates the assembly code:
12849 \begin_layout Verse
12852 01 23 01\InsetSpace ~
12874 \begin_layout Subsubsection
12876 \begin_inset LatexCommand \index{sfr}
12881 \begin_inset LatexCommand \index{\_\_sfr}
12885 (in0/out0 to 8 bit addresses on Z180
12886 \begin_inset LatexCommand \index{Z180}
12891 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12898 \begin_layout Standard
12899 The compiler option -
12903 \begin_layout Standard
12913 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12917 =180 (80) and a compiler #pragma\InsetSpace ~
12919 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12923 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12933 If you include the file z180.h this will be set automatically.
12934 \begin_inset VSpace bigskip
12940 \begin_layout Subsection
12942 \begin_inset LatexCommand \index{HC08!Storage class}
12946 Language Extensions
12949 \begin_layout Subsubsection
12951 \begin_inset LatexCommand \index{data (hc08 storage class)}
12956 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12963 \begin_layout Standard
12964 The data storage class declares a variable that resides in the first 256
12965 bytes of memory (the direct page).
12967 \begin_inset LatexCommand \index{HC08}
12971 is most efficient at accessing variables (especially pointers) stored here.
12974 \begin_layout Subsubsection
12976 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12981 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12988 \begin_layout Standard
12989 The xdata storage class declares a variable that can reside anywhere in
12991 This is the default if no storage class is specified.
12993 \begin_inset VSpace bigskip
12999 \begin_layout Section
13000 Absolute Addressing
13001 \begin_inset LatexCommand \index{Absolute addressing}
13008 \begin_layout Standard
13009 Data items can be assigned an absolute address with the
13012 \begin_inset LatexCommand \index{at}
13017 \begin_inset LatexCommand \index{\_\_at}
13023 keyword, in addition to a storage class, e.g.:
13026 \begin_layout Verse
13030 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13035 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13040 \begin_inset LatexCommand \index{at}
13045 \begin_inset LatexCommand \index{\_\_at}
13049 0x7ffe unsigned int chksum;
13052 \begin_layout Standard
13053 or, better conforming to ISO/IEC 9899 C:
13056 \begin_layout Verse
13059 __xdata __at (0x7ffe) unsigned int chksum;
13062 \begin_layout Standard
13063 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13064 of the external ram.
13069 reserve any space for variables declared in this way
13070 \begin_inset Marginal
13073 \begin_layout Standard
13082 (they are implemented with an equate in the assembler).
13083 Thus it is left to the programmer to make sure there are no overlaps with
13084 other variables that are declared without the absolute address.
13085 The assembler listing file (.lst
13086 \begin_inset LatexCommand \index{<file>.lst}
13090 ) and the linker output files (.rst
13091 \begin_inset LatexCommand \index{<file>.rst}
13096 \begin_inset LatexCommand \index{<file>.map}
13100 ) are good places to look for such overlaps.
13103 \begin_layout Standard
13104 If however you provide an initializer
13105 \begin_inset LatexCommand \index{Variable initialization}
13109 actual memory allocation will take place and overlaps will be detected
13114 \begin_layout Verse
13117 __code __at (0x7ff0) char Id[5] =
13118 \begin_inset Quotes sld
13122 \begin_inset Quotes srd
13128 \begin_layout Standard
13129 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13133 \begin_layout Standard
13134 In case of memory mapped I/O devices the keyword
13138 has to be used to tell the compiler that accesses might not be removed:
13141 \begin_layout Verse
13145 \begin_inset LatexCommand \index{volatile}
13150 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13155 \begin_inset LatexCommand \index{at}
13159 (0x8000) unsigned char PORTA_8255;
13162 \begin_layout Standard
13163 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13168 \begin_inset LatexCommand \index{Aligned array}
13175 starts at a block (256 byte) boundary
13176 \begin_inset LatexCommand \index{block boundary}
13181 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13187 Absolute addresses can be specified for variables in all
13188 storage classes, e.g.:
13191 \begin_layout Verse
13195 \begin_inset LatexCommand \index{bit}
13200 \begin_inset LatexCommand \index{at}
13207 \begin_layout Standard
13208 The above example will allocate the variable at offset 0x02 in the bit-addressab
13210 There is no real advantage to assigning absolute addresses to variables
13211 in this manner, unless you want strict control over all the variables allocated.
13212 One possible use would be to write hardware portable code.
13213 For example, if you have a routine that uses one or more of the microcontroller
13214 I/O pins, and such pins are different for two different hardwares, you
13215 can declare the I/O pins in your routine using:
13218 \begin_layout Verse
13222 \begin_inset LatexCommand \index{volatile}
13226 __bit MOSI;\InsetSpace ~
13230 /* master out, slave in */
13232 extern volatile __bit MISO;\InsetSpace ~
13239 extern volatile __bit MCLK;\InsetSpace ~
13248 Output of a byte on a 3-wire serial bus.
13253 If needed adapt polarity of clock,
13254 polarity of data and bit order
13259 unsigned char spi_io(unsigned char out_byte)
13284 MOSI = out_byte & 0x80;
13315 /* _asm nop _endasm; */\InsetSpace ~
13323 /* for slow peripherals */
13375 \begin_layout Standard
13376 Then, someplace in the code for the first hardware you would use
13379 \begin_layout Verse
13383 \begin_inset LatexCommand \index{at}
13388 \begin_inset LatexCommand \index{\_\_at}
13392 (0x80) MOSI;\InsetSpace ~
13396 /* I/O port 0, bit 0 */
13398 __bit __at (0x81) MISO;\InsetSpace ~
13405 __bit __at (0x82) MCLK;\InsetSpace ~
13409 /* I/O port 0, bit 2 */
13412 \begin_layout Standard
13413 Similarly, for the second hardware you would use
13416 \begin_layout Verse
13419 __bit __at (0x83) MOSI;\InsetSpace ~
13423 /* I/O port 0, bit 3 */
13425 __bit __at (0x91) MISO;\InsetSpace ~
13430 I/O port 1, bit 1 */
13433 \begin_inset LatexCommand \index{bit}
13437 __at (0x92) MCLK;\InsetSpace ~
13441 /* I/O port 1, bit 2 */
13444 \begin_layout Standard
13445 and you can use the same hardware dependent routine without changes, as
13446 for example in a library.
13447 This is somehow similar to sbit, but only one absolute address has to be
13448 specified in the whole project.
13449 \begin_inset VSpace bigskip
13455 \begin_layout Section
13457 \begin_inset LatexCommand \index{Parameters}
13462 \begin_inset LatexCommand \index{function parameter}
13467 \begin_inset LatexCommand \index{local variables}
13472 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13479 \begin_layout Standard
13480 Automatic (local) variables and parameters to functions can either be placed
13481 on the stack or in data-space.
13482 The default action of the compiler is to place these variables in the internal
13483 RAM (for small model) or external RAM (for medium or large model).
13484 This in fact makes them similar to
13487 \begin_inset LatexCommand \index{static}
13493 so by default functions are non-reentrant
13494 \begin_inset LatexCommand \index{reentrant}
13503 They can be placed on the stack
13504 \begin_inset LatexCommand \index{stack}
13514 \begin_layout Standard
13524 \begin_inset LatexCommand \index{-\/-stack-auto}
13532 #pragma\InsetSpace ~
13536 \begin_inset LatexCommand \index{\#pragma stackauto}
13543 \begin_inset LatexCommand \index{reentrant}
13549 keyword in the function declaration, e.g.:
13552 \begin_layout Verse
13555 unsigned char foo(char i) __reentrant
13569 \begin_layout Standard
13570 Since stack space on 8051 is limited, the
13580 \begin_layout Standard
13591 option should be used sparingly.
13592 Note that the reentrant keyword just means that the parameters & local
13593 variables will be allocated to the stack, it
13597 mean that the function is register bank
13598 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13607 \begin_inset LatexCommand \index{local variables}
13611 can be assigned storage classes and absolute
13612 \begin_inset LatexCommand \index{Absolute addressing}
13619 \begin_layout Verse
13622 unsigned char foo()
13630 __xdata unsigned char i;
13643 \begin_inset LatexCommand \index{at}
13647 (0x31) unsigned char j;
13659 \begin_layout Standard
13660 In the above example the variable
13664 will be allocated in the external ram,
13668 in bit addressable space and
13679 \begin_layout Standard
13690 or when a function is declared as
13694 this should only be done for static variables.
13697 \begin_layout Standard
13699 \begin_inset LatexCommand \index{function parameter}
13703 however are not allowed any storage class
13704 \begin_inset LatexCommand \index{Storage class}
13708 , (storage classes for parameters will be ignored), their allocation is
13709 governed by the memory model in use, and the reentrancy options.
13712 \begin_layout Standard
13713 It is however allowed to use bit parameters in reentrant functions and also
13714 non-static local bit variables are supported.
13715 Efficient use is limited to 8 semi-bitregisters in bit space.
13716 They are pushed and popped to stack
13717 \begin_inset LatexCommand \index{stack}
13721 as a single byte just like the normal registers.
13724 \begin_layout Section
13726 \begin_inset LatexCommand \label{sub:Overlaying}
13731 \begin_inset LatexCommand \index{Overlaying}
13738 \begin_layout Standard
13740 \begin_inset LatexCommand \index{reentrant}
13744 functions SDCC will try to reduce internal ram space usage by overlaying
13745 parameters and local variables of a function (if possible).
13746 Parameters and local variables
13747 \begin_inset LatexCommand \index{local variables}
13751 of a function will be allocated to an overlayable segment if the function
13754 no other function calls and the function is non-reentrant and the memory
13756 \begin_inset LatexCommand \index{Memory model}
13763 If an explicit storage class
13764 \begin_inset LatexCommand \index{Storage class}
13768 is specified for a local variable, it will NOT be overlayed.
13771 \begin_layout Standard
13772 Note that the compiler (not the linkage editor) makes the decision for overlayin
13774 Functions that are called from an interrupt service routine
13775 \begin_inset Marginal
13778 \begin_layout Standard
13786 should be preceded by a #pragma\InsetSpace ~
13788 \begin_inset LatexCommand \index{\#pragma nooverlay}
13792 if they are not reentrant.
13795 \begin_layout Standard
13796 Also note that the compiler does not do any processing of inline assembler
13797 code, so the compiler might incorrectly assign local variables and parameters
13798 of a function into the overlay segment if the inline assembler code calls
13799 other c-functions that might use the overlay.
13800 In that case the #pragma\InsetSpace ~
13801 nooverlay should be used.
13804 \begin_layout Standard
13805 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13807 \begin_inset LatexCommand \index{Multiplication}
13812 \begin_inset LatexCommand \index{Division}
13816 will NOT be overlayed since these are implemented using external functions,
13820 \begin_layout Verse
13826 \begin_inset LatexCommand \index{\#pragma nooverlay}
13832 void set_error(unsigned char errcd)
13849 some_isr () __interrupt
13850 \begin_inset LatexCommand \index{interrupt}
13880 \begin_layout Standard
13881 In the above example the parameter
13889 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13891 not present, this could cause unpredictable runtime behavior when called
13892 from an interrupt service routine.
13893 The #pragma\InsetSpace ~
13894 nooverlay ensures that the parameters and local variables for
13895 the function are NOT overlayed.
13896 \begin_inset VSpace bigskip
13902 \begin_layout Section
13903 Interrupt Service Routines
13904 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13911 \begin_layout Subsection
13912 General Information
13915 \begin_layout Standard
13928 outines to be coded in C, with some extended keywords.
13931 \begin_layout Verse
13934 void timer_isr (void) __interrupt (1) __using (1)
13948 \begin_layout Standard
13949 The optional number following the
13952 \begin_inset LatexCommand \index{interrupt}
13957 \begin_inset LatexCommand \index{\_\_interrupt}
13963 keyword is the interrupt number this routine will service.
13964 When present, the compiler will insert a call to this routine in the interrupt
13966 \begin_inset LatexCommand \index{interrupt vector table}
13970 for the interrupt number specified.
13971 If you have multiple source files in your project, interrupt service routines
13972 can be present in any of them, but a prototype of the isr MUST be present
13973 or included in the file that contains the function
13978 The optional (8051 specific) keyword
13981 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13986 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13992 can be used to tell the compiler to use the specified register bank when
13993 generating code for this function.
13996 Interrupt service routines open the door for some very interesting bugs:
13999 \begin_layout Subsubsection
14000 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14004 Common interrupt pitfall: variable not declared
14009 \begin_layout Standard
14010 If an interrupt service routine changes variables which are accessed by
14011 other functions these variables have to be declared
14016 \begin_inset LatexCommand \index{volatile}
14022 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14029 \begin_layout Subsubsection
14030 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14034 Common interrupt pitfall:
14039 \begin_layout Standard
14040 If the access to these variables is not
14043 \begin_inset LatexCommand \index{atomic}
14050 the processor needs more than one instruction for the access and could
14051 be interrupted while accessing the variable) the interrupt must be disabled
14052 during the access to avoid inconsistent data.
14055 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14056 and should be protected by disabling interrupts.
14057 You're not automatically on the safe side if you use 8 bit variables though.
14058 We need an example here: f.e.
14059 on the 8051 the harmless looking
14060 \begin_inset Quotes srd
14070 \begin_inset Quotes sld
14079 \begin_inset Quotes srd
14089 \begin_inset Quotes sld
14092 from within an interrupt routine might get lost if the interrupt occurs
14095 \begin_inset Quotes sld
14100 counter\InsetSpace ~
14105 \begin_inset Quotes srd
14108 is not atomic on the 8051 even if
14112 is located in data memory.
14114 Bugs like these are hard to reproduce and can
14115 cause a lot of trouble.
14119 \begin_layout Subsubsection
14120 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14124 Common interrupt pitfall:
14129 \begin_layout Standard
14130 The return address and the registers used in the interrupt service routine
14131 are saved on the stack
14132 \begin_inset LatexCommand \index{stack}
14136 so there must be sufficient stack space.
14137 If there isn't variables or registers (or even the return address itself)
14144 \begin_inset LatexCommand \index{stack overflow}
14148 is most likely to happen if the interrupt occurs during the
14149 \begin_inset Quotes sld
14153 \begin_inset Quotes srd
14156 subroutine when the stack is already in use for f.e.
14157 many return addresses.
14160 \begin_layout Subsubsection
14161 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14165 Common interrupt pitfall:
14167 use of non-reentrant functions
14170 \begin_layout Standard
14171 A special note here, int (16 bit) and long (32 bit) integer division
14172 \begin_inset LatexCommand \index{Division}
14177 \begin_inset LatexCommand \index{Multiplication}
14182 \begin_inset LatexCommand \index{Modulus}
14187 \begin_inset LatexCommand \index{Floating point support}
14191 operations are implemented using external support routines.
14192 If an interrupt service routine needs to do any of these operations then
14193 the support routines (as mentioned in a following section) will have to
14194 be recompiled using the
14200 \begin_layout Standard
14210 \begin_inset LatexCommand \index{-\/-stack-auto}
14216 option and the source file will need to be compiled using the
14222 \begin_layout Standard
14234 \begin_inset LatexCommand \index{-\/-int-long-reent}
14241 Note, the type promotion
14242 \begin_inset LatexCommand \index{type promotion}
14246 required by ANSI C can cause 16 bit routines to be used
14247 \begin_inset Marginal
14250 \begin_layout Standard
14259 without the programmer being aware of it.
14263 (unsigned char)(tail-1)
14265 within the if clause in section
14266 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14273 \begin_layout Standard
14274 Calling other functions from an interrupt service routine is not recommended,
14275 avoid it if possible.
14276 Note that when some function is called from an interrupt service routine
14277 it should be preceded by a #pragma\InsetSpace ~
14279 \begin_inset LatexCommand \index{\#pragma nooverlay}
14283 if it is not reentrant.
14284 Furthermore nonreentrant functions should not be called from the main program
14285 while the interrupt service routine might be active.
14286 They also must not be called from low priority interrupt service routines
14287 while a high priority interrupt service routine might be active.
14288 You could use semaphores or make the function
14292 if all parameters are passed in registers.
14295 \begin_inset LatexCommand \ref{sub:Overlaying}
14300 about Overlaying and section
14301 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14306 about Functions using private register banks.
14307 \begin_inset VSpace bigskip
14313 \begin_layout Subsection
14314 MCS51/DS390 Interrupt Service Routines
14317 \begin_layout Standard
14319 \begin_inset LatexCommand \index{interrupt}
14323 numbers and the corresponding address & descriptions for the Standard 8051/8052
14325 SDCC will automatically adjust the
14326 \begin_inset LatexCommand \index{interrupt vector table}
14330 to the maximum interrupt number specified.
14335 \begin_layout Standard
14337 \begin_inset Tabular
14338 <lyxtabular version="3" rows="9" columns="3">
14340 <column alignment="center" valignment="top" leftline="true" width="0in">
14341 <column alignment="left" valignment="top" leftline="true" width="0in">
14342 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14343 <row topline="true" bottomline="true">
14344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14347 \begin_layout Standard
14353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14356 \begin_layout Standard
14362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14365 \begin_layout Standard
14372 <row topline="true">
14373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14376 \begin_layout Standard
14382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14385 \begin_layout Standard
14391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14394 \begin_layout Standard
14401 <row topline="true">
14402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14405 \begin_layout Standard
14411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14414 \begin_layout Standard
14420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14423 \begin_layout Standard
14430 <row topline="true">
14431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14434 \begin_layout Standard
14440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14443 \begin_layout Standard
14449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14452 \begin_layout Standard
14459 <row topline="true">
14460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14463 \begin_layout Standard
14469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14472 \begin_layout Standard
14478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14481 \begin_layout Standard
14488 <row topline="true">
14489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14492 \begin_layout Standard
14498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14501 \begin_layout Standard
14507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14510 \begin_layout Standard
14517 <row topline="true">
14518 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14521 \begin_layout Standard
14527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14530 \begin_layout Standard
14536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14539 \begin_layout Standard
14546 <row topline="true">
14547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14550 \begin_layout Standard
14556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14559 \begin_layout Standard
14565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14568 \begin_layout Standard
14575 <row topline="true" bottomline="true">
14576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14579 \begin_layout Standard
14585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14588 \begin_layout Standard
14594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14597 \begin_layout Standard
14613 \begin_layout Standard
14614 If the interrupt service routine is defined without
14617 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14622 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14628 a register bank or with register bank 0 (
14632 0), the compiler will save the registers used by itself on the stack upon
14633 entry and restore them at exit, however if such an interrupt service routine
14634 calls another function then the entire register bank will be saved on the
14636 This scheme may be advantageous for small interrupt service routines which
14637 have low register usage.
14640 \begin_layout Standard
14641 If the interrupt service routine is defined to be using a specific register
14646 & psw are saved and restored, if such an interrupt service routine calls
14647 another function (using another register bank) then the entire register
14648 bank of the called function will be saved on the stack
14649 \begin_inset LatexCommand \index{stack}
14654 This scheme is recommended for larger interrupt service routines.
14655 \begin_inset VSpace bigskip
14661 \begin_layout Subsection
14663 \begin_inset LatexCommand \index{HC08}
14667 Interrupt Service Routines
14670 \begin_layout Standard
14671 Since the number of interrupts
14672 \begin_inset LatexCommand \index{HC08!interrupt}
14676 available is chip specific and the interrupt vector table always ends at
14677 the last byte of memory, the interrupt numbers corresponds to the interrupt
14678 vectors in reverse order of address.
14679 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14680 2 will use the interrupt vector at 0xfffa, and so on.
14681 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14682 this way; instead see section
14683 \begin_inset LatexCommand \ref{sub:Startup-Code}
14687 for details on customizing startup.
14688 \begin_inset VSpace bigskip
14694 \begin_layout Subsection
14695 Z80 Interrupt Service Routines
14698 \begin_layout Standard
14700 \begin_inset LatexCommand \index{Z80}
14704 uses several different methods for determining the correct interrupt
14705 \begin_inset LatexCommand \index{Z80!interrupt}
14709 vector depending on the hardware implementation.
14710 Therefore, SDCC ignores the optional interrupt number and does not attempt
14711 to generate an interrupt vector table.
14714 \begin_layout Standard
14715 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14716 instruction to return from the interrupt.
14717 To write an interrupt handler for the non-maskable interrupt, which needs
14718 a RETN instruction instead, add the
14725 \begin_layout Verse
14728 void nmi_isr (void) critical interrupt
14742 \begin_layout Standard
14743 However if you need to create a non-interruptable interrupt service routine
14744 you would also require the
14749 To distinguish between this and an nmi_isr you must provide an interrupt
14751 \begin_inset VSpace bigskip
14757 \begin_layout Section
14758 Enabling and Disabling Interrupts
14761 \begin_layout Subsection
14762 Critical Functions and Critical Statements
14765 \begin_layout Standard
14766 A special keyword may be associated with a block or a function declaring
14772 SDCC will generate code to disable all interrupts
14773 \begin_inset LatexCommand \index{interrupt}
14777 upon entry to a critical function and restore the interrupt enable to the
14778 previous state before returning.
14779 Nesting critical functions will need one additional byte on the stack
14780 \begin_inset LatexCommand \index{stack}
14787 \begin_layout Verse
14790 int foo () __critical
14791 \begin_inset LatexCommand \index{critical}
14796 \begin_inset LatexCommand \index{\_\_critical}
14821 \begin_layout Standard
14822 The critical attribute maybe used with other attributes like
14832 may also be used to disable interrupts more locally:
14835 \begin_layout Verse
14841 \begin_layout Standard
14842 More than one statement could have been included in the block.
14845 \begin_layout Subsection
14846 Enabling and Disabling Interrupts directly
14849 \begin_layout Standard
14851 \begin_inset LatexCommand \index{interrupt}
14855 can also be disabled and enabled directly (8051):
14858 \begin_layout Verse
14861 EA = 0;\InsetSpace ~
14887 \begin_layout Verse
14923 \begin_layout Verse
14926 EA = 1;\InsetSpace ~
14955 \begin_layout Verse
14994 \begin_layout Standard
14995 On other architectures which have seperate opcodes for enabling and disabling
14996 interrupts you might want to make use of defines with inline assembly
14997 \begin_inset LatexCommand \index{Assembler routines}
15002 \begin_inset LatexCommand \index{HC08!interrupt}
15009 \begin_layout Verse
15013 \begin_inset LatexCommand \index{\_asm}
15022 \begin_inset LatexCommand \index{\_endasm}
15029 \begin_layout Verse
15032 #define SEI _asm\InsetSpace ~
15039 \begin_layout Verse
15045 \begin_layout Standard
15046 Note: it is sometimes sufficient to disable only a specific interrupt source
15048 a timer or serial interrupt by manipulating an
15051 \begin_inset LatexCommand \index{interrupt mask}
15061 \begin_layout Standard
15062 Usually the time during which interrupts are disabled should be kept as
15064 This minimizes both
15069 \begin_inset LatexCommand \index{interrupt latency}
15073 (the time between the occurrence of the interrupt and the execution of
15074 the first code in the interrupt routine) and
15079 \begin_inset LatexCommand \index{interrupt jitter}
15083 (the difference between the shortest and the longest interrupt latency).
15084 These really are something different, f.e.
15085 a serial interrupt has to be served before its buffer overruns so it cares
15086 for the maximum interrupt latency, whereas it does not care about jitter.
15087 On a loudspeaker driven via a digital to analog converter which is fed
15088 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15089 a much smaller jitter will be very audible.
15092 \begin_layout Standard
15093 You can reenable interrupts within an interrupt routine and on some architecture
15094 s you can make use of two (or more) levels of
15096 interrupt priorities
15099 \begin_inset LatexCommand \index{interrupt priority}
15104 On some architectures which don't support interrupt priorities these can
15105 be implemented by manipulating the interrupt mask and reenabling interrupts
15106 within the interrupt routine.
15107 Check there is sufficient space on the stack
15108 \begin_inset LatexCommand \index{stack}
15112 and don't add complexity unless you have to.
15116 \begin_layout Subsection
15118 \begin_inset LatexCommand \index{semaphore}
15122 locking (mcs51/ds390)
15125 \begin_layout Standard
15126 Some architectures (mcs51/ds390) have an atomic
15127 \begin_inset LatexCommand \index{atomic}
15140 These type of instructions are typically used in preemptive multitasking
15141 systems, where a routine f.e.
15142 claims the use of a data structure ('acquires a lock
15143 \begin_inset LatexCommand \index{lock}
15147 on it'), makes some modifications and then releases the lock when the data
15148 structure is consistent again.
15149 The instruction may also be used if interrupt and non-interrupt code have
15150 to compete for a resource.
15151 With the atomic bit test and clear instruction interrupts
15152 \begin_inset LatexCommand \index{interrupt}
15156 don't have to be disabled for the locking operation.
15160 \begin_layout Standard
15161 SDCC generates this instruction if the source follows this pattern:
15164 \begin_layout Verse
15168 \begin_inset LatexCommand \index{volatile}
15172 bit resource_is_free;
15176 if (resource_is_free)
15186 resource_is_free=0;
15199 resource_is_free=1;
15206 \begin_layout Standard
15207 Note, mcs51 and ds390 support only an atomic
15208 \begin_inset LatexCommand \index{atomic}
15216 instruction (as opposed to atomic bit test and
15221 \begin_layout Section
15222 Functions using private register banks
15223 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15230 \begin_layout Standard
15231 Some architectures have support for quickly changing register sets.
15232 SDCC supports this feature with the
15235 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15240 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15246 attribute (which tells the compiler to use a register bank
15247 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15251 other than the default bank zero).
15252 It should only be applied to
15255 \begin_inset LatexCommand \index{interrupt}
15261 functions (see footnote below).
15262 This will in most circumstances make the generated ISR code more efficient
15263 since it will not have to save registers on the stack.
15266 \begin_layout Standard
15271 attribute will have no effect on the generated code for a
15275 function (but may occasionally be useful anyway
15279 \begin_layout Standard
15280 possible exception: if a function is called ONLY from 'interrupt' functions
15281 using a particular bank, it can be declared with the same 'using' attribute
15282 as the calling 'interrupt' functions.
15283 For instance, if you have several ISRs using bank one, and all of them
15284 call memcpy(), it might make sense to create a specialized version of memcpy()
15285 'using 1', since this would prevent the ISR from having to save bank zero
15286 to the stack on entry and switch to bank zero before calling the function
15295 (pending: Note, nowadays the
15299 attribute has an effect on
15303 the generated code for a
15314 \begin_layout Standard
15319 function using a non-zero bank will assume that it can trash that register
15320 bank, and will not save it.
15321 Since high-priority interrupts
15322 \begin_inset LatexCommand \index{interrupts}
15327 \begin_inset LatexCommand \index{interrupt priority}
15331 can interrupt low-priority ones on the 8051 and friends, this means that
15332 if a high-priority ISR
15336 a particular bank occurs while processing a low-priority ISR
15340 the same bank, terrible and bad things can happen.
15341 To prevent this, no single register bank should be
15345 by both a high priority and a low priority ISR.
15346 This is probably most easily done by having all high priority ISRs use
15347 one bank and all low priority ISRs use another.
15348 If you have an ISR which can change priority at runtime, you're on your
15349 own: I suggest using the default bank zero and taking the small performance
15353 \begin_layout Standard
15354 It is most efficient if your ISR calls no other functions.
15355 If your ISR must call other functions, it is most efficient if those functions
15356 use the same bank as the ISR (see note 1 below); the next best is if the
15357 called functions use bank zero.
15358 It is very inefficient to call a function using a different, non-zero bank
15361 \begin_inset VSpace bigskip
15367 \begin_layout Section
15369 \begin_inset LatexCommand \label{sub:Startup-Code}
15374 \begin_inset LatexCommand \index{Startup code}
15381 \begin_layout Subsection
15382 MCS51/DS390 Startup Code
15385 \begin_layout Standard
15386 The compiler triggers the linker to link certain initialization modules
15387 from the runtime library
15388 \begin_inset LatexCommand \index{Runtime library}
15392 called crt<something>.
15393 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15394 GSINIT5) is not linked unless the -
15400 \begin_layout Standard
15411 -xstack option is used.
15412 These modules are highly entangled by the use of special segments/areas,
15413 but a common layout is shown below:
15416 \begin_layout Verse
15424 \begin_layout Verse
15448 ljmp __sdcc_gsinit_startup
15451 \begin_layout Verse
15459 \begin_layout Verse
15471 .area GSINIT0 (CODE)
15473 __sdcc_gsinit_startup::
15483 mov sp,#__start__stack - 1
15486 \begin_layout Verse
15494 \begin_layout Verse
15506 .area GSINIT1 (CODE)
15508 __sdcc_init_xstack::
15510 ; Need to initialize in GSINIT1 in
15511 case the user's __sdcc_external_startup uses the xstack.
15521 mov __XPAGE,#(__start__x
15532 mov _spx,#__start__xstack
15535 \begin_layout Verse
15543 \begin_layout Verse
15555 .area GSINIT2 (CODE)
15565 lcall __sdcc_external_startup
15585 jz __sdcc_init_data
15596 __sdcc_program_startup
15601 \begin_layout Verse
15609 \begin_layout Verse
15621 .area GSINIT3 (CODE)
15674 mov r2,#((l_XINIT+255) >> 8)
15705 __XPAGE,#(s_XISEG >> 8)
15707 00001$:\InsetSpace ~
15771 00002$:\InsetSpace ~
15798 \begin_layout Verse
15806 \begin_layout Verse
15818 .area GSINIT4 (CODE)
15820 __mcs51_genRAMCLEAR::
15842 00004$:\InsetSpace ~
15856 ; _mcs51_genRAMCLEAR() end
15859 \begin_layout Verse
15867 \begin_layout Verse
15879 .area GSINIT4 (CODE)
15881 __mcs51_genXRAMCLEAR::
15932 mov __XPAGE,#(s_PSEG >> 8)
15944 00005$:\InsetSpace ~
15998 orl a,#(l_XSEG >> 8)
16041 00007$:\InsetSpace ~
16078 \begin_layout Verse
16086 \begin_layout Verse
16098 .area GSINIT5 (CODE)
16100 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16103 ; and __mcs51_genRAMCLEAR modifies _spx.
16113 mov __XPAGE,#(__start__x
16124 mov _spx,#__start__xstack
16127 \begin_layout Verse
16132 (application modules)
16135 \begin_layout Verse
16147 .area GSINIT (CODE)
16150 \begin_layout Verse
16158 \begin_layout Verse
16170 .area GSFINAL (CODE)
16180 ljmp __sdcc_program_startup
16182 ;---------------------------------
16183 -----------------------
16187 ;--------------------------------------------------
16210 __sdcc_program_startup:
16223 return from main will lock up
16236 \begin_layout Standard
16237 One of these modules (crtstart.asm) contains a call to the C routine
16239 _sdcc_external_startup()
16240 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16249 at the start of the CODE area.
16250 This routine is also in the runtime library
16251 \begin_inset LatexCommand \index{Runtime library}
16255 and returns 0 by default.
16256 If this routine returns a non-zero value, the static & global variable
16257 initialization will be skipped and the function main will be invoked.
16258 Otherwise static & global variables will be initialized before the function
16262 _sdcc_external_startup()
16264 routine to your program to override the default if you need to setup hardware
16265 or perform some other critical operation prior to static & global variable
16267 \begin_inset LatexCommand \index{Variable initialization}
16272 On some mcs51 variants xdata
16273 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16277 memory has to be explicitly enabled before it can be accessed or if the
16279 \begin_inset LatexCommand \index{watchdog}
16283 needs to be disabled, this is the place to do it.
16284 The startup code clears all internal data memory, 256 bytes by default,
16285 but from 0 to n-1 if
16291 \begin_layout Standard
16301 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16308 (recommended for Chipcon CC1010).
16311 \begin_layout Standard
16312 See also the compiler options
16318 \begin_layout Standard
16334 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16344 \begin_layout Standard
16356 \begin_inset LatexCommand \index{-\/-main-return}
16361 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16365 about MCS51-variants.
16366 \begin_inset VSpace bigskip
16372 \begin_layout Subsection
16376 \begin_layout Standard
16378 \begin_inset LatexCommand \index{HC08}
16382 startup code follows the same scheme as the MCS51 startup code.
16383 \begin_inset VSpace bigskip
16389 \begin_layout Subsection
16393 \begin_layout Standard
16395 \begin_inset LatexCommand \index{Z80}
16399 the startup code is inserted by linking with crt0.o which is generated from
16400 sdcc/device/lib/z80/crt0.s.
16401 If you need a different startup code you can use the compiler option
16410 \begin_layout Standard
16425 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16429 and provide your own crt0.o.
16431 \begin_inset VSpace bigskip
16437 \begin_layout Section
16438 Inline Assembler Code
16439 \begin_inset LatexCommand \index{Assembler routines}
16446 \begin_layout Subsection
16447 A Step by Step Introduction
16448 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16455 \begin_layout Standard
16456 Starting from a small snippet of c-code this example shows for the MCS51
16457 how to use inline assembly, access variables, a function parameter and
16458 an array in xdata memory.
16459 The example uses an MCS51 here but is easily adapted for other architectures.
16460 This is a buffer routine which should be optimized:
16463 \begin_layout Verse
16467 unsigned char __far
16468 \begin_inset LatexCommand \index{far (storage class)}
16473 \begin_inset LatexCommand \index{\_\_far (storage class)}
16478 \begin_inset LatexCommand \index{at}
16483 \begin_inset LatexCommand \index{\_\_at}
16487 (0x7f00) buf[0x100];
16488 \begin_inset LatexCommand \index{Aligned array}
16494 unsigned char head, tail;\InsetSpace ~
16512 \begin_inset LatexCommand \index{interrupt}
16564 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16576 void to_buffer( unsigned char c )
16584 if( head != (unsigned char)(tail-1)
16591 \begin_inset LatexCommand \index{promotion to signed int}
16596 \begin_inset LatexCommand \index{type promotion}
16601 \begin_inset Marginal
16604 \begin_layout Standard
16623 buf[ head++ ] = c;\InsetSpace ~
16639 /* access to a 256 byte aligned array */
16644 \begin_layout Standard
16645 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16646 then a corresponding buffer.asm file is generated.
16647 We define a new function
16651 in file buffer.c in which we cut and paste the generated code, removing
16652 unwanted comments and some ':'.
16654 \begin_inset Quotes sld
16662 \begin_inset Quotes srd
16666 \begin_inset Quotes sld
16674 \begin_inset Quotes srd
16681 \begin_layout Standard
16682 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16683 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16685 The latter is also used in the library functions.
16690 to the beginning and the end of the function body:
16693 \begin_layout Verse
16697 /* With a cut and paste from the .asm file, we have something to start with.
16703 function is not yet OK! (registers aren't saved) */
16705 void to_buffer_asm(
16715 \begin_inset LatexCommand \index{\_asm}
16720 \begin_inset LatexCommand \index{\_\_asm}
16734 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16740 \begin_inset LatexCommand \index{promotion to signed int}
16745 \begin_inset LatexCommand \index{type promotion}
16798 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16799 \begin_inset LatexCommand \index{Aligned array}
16865 \begin_inset LatexCommand \index{\_endasm}
16870 \begin_inset LatexCommand \index{\_\_endasm}
16879 \begin_layout Standard
16880 The new file buffer.c should compile with only one warning about the unreferenced
16881 function argument 'c'.
16882 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16883 (1) and finally have:
16886 \begin_layout Verse
16890 unsigned char __far __at(0x7f00) buf[0x100];
16892 unsigned char head, tail;
16903 void to_buffer( unsigned char c )
16912 head != (unsigned char)(tail-1) )
16941 c; // to avoid warning: unreferenced function argument
16948 \begin_inset LatexCommand \index{\_asm}
16953 \begin_inset LatexCommand \index{\_\_asm}
16967 ; save used registers here.
16978 ; If we were still using r2,r3 we would have to push them here.
16981 ; if( head != (unsigned char)(tail-1) )
17025 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17061 a,dpl \InsetSpace ~
17068 ; dpl holds lower byte of function argument
17080 dpl,_head \InsetSpace ~
17083 ; buf is 0x100 byte aligned so head can be used directly
17126 ; we could do an ANL _head,#0x0f here to use a
17127 smaller buffer (see above)
17139 ; restore used registers here
17146 \begin_inset LatexCommand \index{\_endasm}
17151 \begin_inset LatexCommand \index{\_\_endasm}
17162 \begin_layout Standard
17163 The inline assembler code can contain any valid code understood by the assembler
17164 , this includes any assembler directives and comment lines.
17165 The assembler does not like some characters like ':' or ''' in comments.
17166 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17167 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17172 \begin_inset LatexCommand \index{Assembler documentation}
17177 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17185 \begin_layout Standard
17186 The compiler does not do any validation of the code within the
17189 \begin_inset LatexCommand \index{\_asm}
17194 \begin_inset LatexCommand \index{\_\_asm}
17202 \begin_inset LatexCommand \index{\_endasm}
17207 \begin_inset LatexCommand \index{\_\_endasm}
17216 Specifically it will not know which registers are used and thus register
17218 \begin_inset LatexCommand \index{push/pop}
17222 has to be done manually.
17226 \begin_layout Standard
17227 It is recommended that each assembly instruction (including labels) be placed
17228 in a separate line (as the example shows).
17233 \begin_layout Standard
17245 \begin_inset LatexCommand \index{-\/-peep-asm}
17251 command line option is used, the inline assembler code will be passed through
17252 the peephole optimizer
17253 \begin_inset LatexCommand \index{Peephole optimizer}
17258 There are only a few (if any) cases where this option makes sense, it might
17259 cause some unexpected changes in the inline assembler code.
17260 Please go through the peephole optimizer rules defined in file
17264 before using this option.
17267 \begin_layout Subsection
17269 \begin_inset LatexCommand \label{sub:Naked-Functions}
17274 \begin_inset LatexCommand \index{Naked functions}
17281 \begin_layout Standard
17282 A special keyword may be associated with a function declaring it as
17285 \begin_inset LatexCommand \index{\_naked}
17290 \begin_inset LatexCommand \index{\_\_naked}
17301 function modifier attribute prevents the compiler from generating prologue
17302 \begin_inset LatexCommand \index{function prologue}
17307 \begin_inset LatexCommand \index{function epilogue}
17311 code for that function.
17312 This means that the user is entirely responsible for such things as saving
17313 any registers that may need to be preserved, selecting the proper register
17314 bank, generating the
17318 instruction at the end, etc.
17319 Practically, this means that the contents of the function must be written
17320 in inline assembler.
17321 This is particularly useful for interrupt functions, which can have a large
17322 (and often unnecessary) prologue/epilogue.
17323 For example, compare the code generated by these two functions:
17326 \begin_layout Verse
17330 \begin_inset LatexCommand \index{volatile}
17334 data unsigned char counter;
17338 void simpleInterrupt(void) __interrupt
17339 \begin_inset LatexCommand \index{interrupt}
17344 \begin_inset LatexCommand \index{\_\_interrupt}
17362 void nakedInterrupt(void) __interrupt (2) __naked
17371 \begin_inset LatexCommand \index{\_asm}
17376 \begin_inset LatexCommand \index{\_\_asm}
17393 _counter ; does not change flags, no need to save psw
17406 include ret or reti in _naked function.
17413 \begin_inset LatexCommand \index{\_endasm}
17418 \begin_inset LatexCommand \index{\_\_endasm}
17427 \begin_layout Standard
17428 For an 8051 target, the generated simpleInterrupt looks like:
17431 \begin_layout Verse
17438 example, recent versions of SDCC generate
17444 code for simpleInterrupt() and nakedInterrupt()!
17585 \begin_layout Standard
17586 whereas nakedInterrupt looks like:
17589 \begin_layout Verse
17602 _counter ; does not change flags, no need to save psw
17621 MUST explicitly include ret or reti in _naked function
17624 \begin_layout Standard
17625 The related directive #pragma exclude
17626 \begin_inset LatexCommand \index{\#pragma exclude}
17630 allows a more fine grained control over pushing & popping
17631 \begin_inset LatexCommand \index{push/pop}
17638 \begin_layout Standard
17639 While there is nothing preventing you from writing C code inside a
17643 function, there are many ways to shoot yourself in the foot doing this,
17644 and it is recommended that you stick to inline assembler.
17647 \begin_layout Subsection
17648 Use of Labels within Inline Assembler
17651 \begin_layout Standard
17652 SDCC allows the use of in-line assembler with a few restrictions regarding
17654 All labels defined within inline assembler code have to be of the form
17659 where nnnnn is a number less than 100 (which implies a limit of utmost
17660 100 inline assembler labels
17671 \begin_layout Standard
17672 This is a slightly more stringent rule than absolutely necessary, but stays
17673 always on the safe side.
17674 Labels in the form of nnnnn$ are local labels in the assembler, locality
17675 of which is confined within two labels of the standard form.
17676 The compiler uses the same form for labels within a function (but starting
17677 from nnnnn=00100); and places always a standard label at the beginning
17678 of a function, thus limiting the locality of labels within the scope of
17680 So, if the inline assembler part would be embedded into C-code, an improperly
17681 placed non-local label in the assembler would break up the reference space
17682 for labels created by the compiler for the C-code, leading to an assembling
17686 \begin_layout Standard
17687 The numeric part of local labels does not need to have 5 digits (although
17688 this is the form of labels output by the compiler), any valid integer will
17690 Please refer to the assemblers documentation for further details.
17698 \begin_layout Verse
17702 \begin_inset LatexCommand \index{\_asm}
17707 \begin_inset LatexCommand \index{\_\_asm}
17737 \begin_inset LatexCommand \index{\_endasm}
17742 \begin_inset LatexCommand \index{\_\_endasm}
17749 \begin_layout Standard
17750 Inline assembler code cannot reference any C-labels, however it can reference
17752 \begin_inset LatexCommand \index{Labels}
17756 defined by the inline assembler, e.g.:
17759 \begin_layout Verse
17782 ; some assembler code
17803 /* some more c code */
17805 clabel:\InsetSpace ~
17807 /* inline assembler cannot reference this
17812 \begin_layout Standard
17817 is translated by the compiler into a local label, so the locality of labels
17818 within the function is not broken.
17835 0003$: ;label (can be referenced by inline assembler only)
17842 \begin_inset LatexCommand \index{\_endasm}
17847 \begin_inset LatexCommand \index{\_\_endasm}
17857 /* some more c code */
17862 \begin_layout Standard
17863 In other words inline assembly code can access labels defined in inline
17864 assembly within the scope of the function.
17865 The same goes the other way, i.e.
17866 labels defines in inline assembly can not be accessed by C statements.
17869 \begin_layout Section
17870 Interfacing with Assembler Code
17871 \begin_inset LatexCommand \index{Assembler routines}
17878 \begin_layout Subsection
17879 Global Registers used for Parameter Passing
17880 \begin_inset LatexCommand \index{Parameter passing}
17887 \begin_layout Standard
17888 The compiler always uses the global registers
17891 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17896 \begin_inset LatexCommand \index{DPTR}
17901 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17910 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17916 to pass the first (non-bit) parameter to a function, and also to pass the
17918 \begin_inset LatexCommand \index{return value}
17922 of function; according to the following scheme: one byte return value in
17927 , two byte value in
17936 three byte values (generic pointers) in
17948 , and four byte values in
17966 \begin_inset LatexCommand \index{generic pointer}
17970 contain type of accessed memory in
17991 \begin_inset Note Note
17994 \begin_layout Standard
17995 This might not be the case of certain memory models (medium???)
18003 \begin_layout Standard
18004 The second parameter onwards is either allocated on the stack (for reentrant
18009 \begin_layout Standard
18018 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18021 \begin_layout Standard
18022 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18023 space for reentrant functions or allocated directly in bit memory otherwise.
18026 \begin_layout Standard
18027 Functions (with two or more parameters or bit parameters) that are called
18028 through function pointers
18029 \begin_inset LatexCommand \index{function pointers}
18033 must therefor be reentrant so the compiler knows how to pass the parameters.
18036 \begin_layout Subsection
18040 \begin_layout Standard
18041 Unless the called function is declared as
18046 \begin_inset LatexCommand \index{naked}
18054 \begin_layout Standard
18064 \begin_inset LatexCommand \index{-\/-callee-saves}
18072 \begin_layout Standard
18081 -all-callee-saves command line option or the corresponding callee_saves
18082 pragma are used, the caller will save the registers (
18086 ) around the call, so the called function can destroy they content freely.
18089 \begin_layout Standard
18090 If the called function is not declared as
18094 , the caller will swap register banks around the call, if caller and callee
18095 use different register banks (having them defined by the
18103 \begin_layout Standard
18104 The called function can also use
18120 observing that they are used for parameter/return value passing.
18123 \begin_layout Subsection
18124 Assembler Routine (non-reentrant)
18127 \begin_layout Standard
18128 In the following example
18129 \begin_inset LatexCommand \index{reentrant}
18134 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18138 the function c_func calls an assembler routine asm_func, which takes two
18140 \begin_inset LatexCommand \index{function parameter}
18147 \begin_layout Verse
18150 extern int asm_func(unsigned char, unsigned char);
18154 int c_func (unsigned char
18155 i, unsigned char j)
18163 return asm_func(i,j);
18177 return c_func(10,9);
18182 \begin_layout Standard
18183 The corresponding assembler function is:
18186 \begin_layout Verse
18189 .globl _asm_func_PARM_2
18291 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18308 \begin_layout Standard
18309 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18310 the parameter number starting from 1, and counting from the left.
18311 The first parameter is passed in
18327 according to the description above.
18328 The variable name for the second parameter will be _<function_name>_PARM_2.
18333 ble the assembler routine with the following command:
18340 asx8051 -losg asmfunc.asm
18347 Then compile and link the assembler routine to the C source file with the
18355 sdcc cfunc.c asmfunc.rel
18358 \begin_layout Subsection
18359 Assembler Routine (reentrant)
18362 \begin_layout Standard
18364 \begin_inset LatexCommand \index{reentrant}
18369 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18373 the second parameter
18374 \begin_inset LatexCommand \index{function parameter}
18378 onwards will be passed on the stack, the parameters are pushed from right
18380 before the call the second leftmost parameter will be on the top of the
18381 stack (the leftmost parameter is passed in registers).
18382 Here is an example:
18385 \begin_layout Verse
18388 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18393 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18402 return asm_func(i,j,k);
18416 return c_func(10,9,8);
18421 \begin_layout Standard
18422 The corresponding (unoptimized) assembler routine is:
18425 \begin_layout Verse
18445 _bp,sp\InsetSpace ~
18451 ;stack contains: _bp, return
18452 address, second parameter, third parameter
18476 a,#0xfd\InsetSpace ~
18482 pointer to the second parameter
18506 a,#0xfc\InsetSpace ~
18512 to the rightmost parameter
18553 result (= sum of all three parameters)
18568 ;return value goes into dptr
18602 \begin_layout Standard
18603 The compiling and linking procedure remains the same, however note the extra
18604 entry & exit linkage required for the assembler code, _bp is the stack
18605 frame pointer and is used to compute the offset into the stack for parameters
18606 and local variables.
18607 \begin_inset VSpace bigskip
18613 \begin_layout Section
18615 \begin_inset LatexCommand \index{int (16 bit)}
18620 \begin_inset LatexCommand \index{long (32 bit)}
18627 \begin_layout Standard
18628 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18629 multiplication and modulus operations are implemented by support routines.
18630 These support routines are all developed in ANSI-C to facilitate porting
18631 to other MCUs, although some model specific assembler optimizations are
18633 The following files contain the described routines, all of them can be
18634 found in <installdir>/share/sdcc/lib.
18639 \begin_layout Standard
18641 \begin_inset Tabular
18642 <lyxtabular version="3" rows="11" columns="2">
18644 <column alignment="left" valignment="top" leftline="true" width="0">
18645 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18646 <row topline="true" bottomline="true">
18647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18650 \begin_layout Standard
18658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18661 \begin_layout Standard
18670 <row topline="true">
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18674 \begin_layout Standard
18680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18683 \begin_layout Standard
18684 16 bit multiplication
18690 <row topline="true">
18691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18694 \begin_layout Standard
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18703 \begin_layout Standard
18704 signed 16 bit division (calls _divuint)
18710 <row topline="true">
18711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18714 \begin_layout Standard
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18723 \begin_layout Standard
18724 unsigned 16 bit division
18730 <row topline="true">
18731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18734 \begin_layout Standard
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18743 \begin_layout Standard
18744 signed 16 bit modulus (calls _moduint)
18750 <row topline="true">
18751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18754 \begin_layout Standard
18760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18763 \begin_layout Standard
18764 unsigned 16 bit modulus
18770 <row topline="true">
18771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18774 \begin_layout Standard
18780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18783 \begin_layout Standard
18784 32 bit multiplication
18790 <row topline="true">
18791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18794 \begin_layout Standard
18800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18803 \begin_layout Standard
18804 signed 32 division (calls _divulong)
18810 <row topline="true">
18811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18814 \begin_layout Standard
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18823 \begin_layout Standard
18824 unsigned 32 division
18830 <row topline="true">
18831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18834 \begin_layout Standard
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18843 \begin_layout Standard
18844 signed 32 bit modulus (calls _modulong)
18850 <row topline="true" bottomline="true">
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18854 \begin_layout Standard
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18863 \begin_layout Standard
18864 unsigned 32 bit modulus
18879 \begin_layout Standard
18880 Since they are compiled as
18885 \begin_inset LatexCommand \index{reentrant}
18890 \begin_inset LatexCommand \index{interrupt}
18894 service routines should not do any of the above operations.
18895 If this is unavoidable then the above routines will need to be compiled
18902 \begin_layout Standard
18912 \begin_inset LatexCommand \index{-\/-stack-auto}
18918 option, after which the source program will have to be compiled with
18924 \begin_layout Standard
18934 \begin_inset LatexCommand \index{-\/-int-long-reent}
18941 Notice that you don't have to call these routines directly.
18942 The compiler will use them automatically every time an integer operation
18946 \begin_layout Section
18947 Floating Point Support
18948 \begin_inset LatexCommand \index{Floating point support}
18955 \begin_layout Standard
18956 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18957 The floating point support routines are derived from gcc's floatlib.c and
18958 consist of the following routines:
18963 \begin_layout Standard
18967 \begin_inset Tabular
18968 <lyxtabular version="3" rows="17" columns="2">
18970 <column alignment="left" valignment="top" leftline="true" width="0">
18971 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18972 <row topline="true" bottomline="true">
18973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18976 \begin_layout Standard
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18994 \begin_layout Standard
19001 <row topline="true">
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19005 \begin_layout Standard
19020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19023 \begin_layout Standard
19033 add floating point numbers
19039 <row topline="true">
19040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19043 \begin_layout Standard
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19061 \begin_layout Standard
19071 subtract floating point numbers
19077 <row topline="true">
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19081 \begin_layout Standard
19096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19099 \begin_layout Standard
19109 divide floating point numbers
19115 <row topline="true">
19116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19119 \begin_layout Standard
19134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19137 \begin_layout Standard
19147 multiply floating point numbers
19153 <row topline="true">
19154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19157 \begin_layout Standard
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19175 \begin_layout Standard
19185 convert floating point to unsigned char
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19195 \begin_layout Standard
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19213 \begin_layout Standard
19223 convert floating point to signed char
19229 <row topline="true">
19230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19233 \begin_layout Standard
19248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19251 \begin_layout Standard
19261 convert floating point to unsigned int
19267 <row topline="true">
19268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19271 \begin_layout Standard
19286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19289 \begin_layout Standard
19299 convert floating point to signed int
19305 <row topline="true">
19306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19309 \begin_layout Standard
19332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19335 \begin_layout Standard
19345 convert floating point to unsigned long
19351 <row topline="true">
19352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19355 \begin_layout Standard
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19373 \begin_layout Standard
19383 convert floating point to signed long
19389 <row topline="true">
19390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19393 \begin_layout Standard
19408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19411 \begin_layout Standard
19421 convert unsigned char to floating point
19427 <row topline="true">
19428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19431 \begin_layout Standard
19446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19449 \begin_layout Standard
19459 convert char to floating point number
19465 <row topline="true">
19466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19469 \begin_layout Standard
19484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19487 \begin_layout Standard
19497 convert unsigned int to floating point
19503 <row topline="true">
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19507 \begin_layout Standard
19522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19525 \begin_layout Standard
19535 convert int to floating point numbers
19541 <row topline="true">
19542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19545 \begin_layout Standard
19560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19563 \begin_layout Standard
19573 convert unsigned long to floating point number
19579 <row topline="true" bottomline="true">
19580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19583 \begin_layout Standard
19598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19601 \begin_layout Standard
19611 convert long to floating point number
19626 \begin_layout Standard
19627 These support routines are developed in ANSI-C so there is room for space
19628 and speed improvement
19632 \begin_layout Standard
19633 These floating point routines (
19637 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19644 Note if all these routines are used simultaneously the data space might
19646 For serious floating point usage the large model might be needed.
19647 Also notice that you don't have to call this routines directly.
19648 The compiler will use them automatically every time a floating point operation
19650 \begin_inset VSpace bigskip
19656 \begin_layout Section
19658 \begin_inset LatexCommand \index{Libraries}
19665 \begin_layout Standard
19668 <pending: this is messy and incomplete - a little more information is in
19669 sdcc/doc/libdoc.txt
19674 \begin_layout Subsection
19675 Compiler support routines (_gptrget, _mulint etc.)
19678 \begin_layout Subsection
19679 Stdclib functions (puts, printf, strcat etc.)
19682 \begin_layout Subsubsection
19686 \begin_layout Paragraph
19687 getchar(), putchar()
19690 \begin_layout Standard
19691 \begin_inset LatexCommand \index{<stdio.h>}
19695 As usual on embedded systems you have to provide your own
19698 \begin_inset LatexCommand \index{getchar()}
19707 \begin_inset LatexCommand \index{putchar()}
19714 SDCC does not know whether the system connects to a serial line with or
19715 without handshake, LCD, keyboard or other device.
19729 You'll find examples for serial routines f.e.
19730 in sdcc/device/lib.
19731 For the mcs51 this minimalistic polling
19735 routine might be a start:
19738 \begin_layout Verse
19741 void putchar (char c) {
19747 while (!TI)\InsetSpace ~
19750 /* assumes UART is initialized */
19778 \begin_layout Paragraph
19782 \begin_layout Standard
19786 \begin_inset LatexCommand \index{printf()}
19796 does not support float (except on ds390).
19797 To enable this recompile it with the option
19803 \begin_layout Standard
19813 \begin_inset LatexCommand \index{USE\_FLOATS}
19819 on the command line.
19826 \begin_layout Standard
19836 \begin_inset LatexCommand \index{-\/-model-large}
19842 for the mcs51 port, since this uses a lot of memory.
19845 \begin_layout Standard
19846 If you're short on code memory you might want to use
19849 \begin_inset LatexCommand \index{printf\_small()}
19864 For the mcs51 there additionally are assembly versions
19867 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19873 (subset of printf using less than 270 bytes) and
19876 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19885 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19891 (floating-point aware version of printf_fast) which should fit the requirements
19892 of many embedded systems (printf_fast() can be customized by unsetting
19897 support long variables and field widths).
19898 Be sure to use only one of these printf options within a project.
19903 \begin_layout Standard
19904 Feature matrix of different
19911 \begin_layout Standard
19912 \begin_inset Tabular
19913 <lyxtabular version="3" rows="14" columns="7">
19914 <features islongtable="true">
19915 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19916 <column alignment="center" valignment="top" leftline="true" width="0">
19917 <column alignment="center" valignment="top" leftline="true" width="12col%">
19918 <column alignment="center" valignment="top" leftline="true" width="10col%">
19919 <column alignment="center" valignment="top" leftline="true" width="0">
19920 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19921 <column alignment="center" valignment="top" rightline="true" width="0">
19922 <row topline="true" bottomline="true" endhead="true">
19923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19926 \begin_layout Standard
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19938 \begin_layout Standard
19940 \begin_inset LatexCommand \index{printf}
19949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19952 \begin_layout Standard
19960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19963 \begin_layout Standard
19969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19972 \begin_layout Standard
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19981 \begin_layout Standard
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19990 \begin_layout Standard
19997 <row topline="true" endhead="true">
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20001 \begin_layout Standard
20007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20010 \begin_layout Standard
20018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20021 \begin_layout Standard
20029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20032 \begin_layout Standard
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20043 \begin_layout Standard
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20054 \begin_layout Standard
20062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20065 \begin_layout Standard
20074 <row topline="true" endhead="true">
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20078 \begin_layout Standard
20079 \begin_inset Quotes sld
20083 \begin_inset Quotes srd
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20098 \begin_layout Standard
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20107 \begin_layout Standard
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20116 \begin_layout Standard
20122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20125 \begin_layout Standard
20131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20134 \begin_layout Standard
20140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20143 \begin_layout Standard
20150 <row topline="true" endhead="true">
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20154 \begin_layout Standard
20158 \begin_layout Standard
20164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20167 \begin_layout Standard
20173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20176 \begin_layout Standard
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20185 \begin_layout Standard
20186 0.45k / 0.47k (+ _ltoa)
20191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20194 \begin_layout Standard
20200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20203 \begin_layout Standard
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20212 \begin_layout Standard
20219 <row topline="true">
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_layout Standard
20229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20232 \begin_layout Standard
20242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20245 \begin_layout Standard
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20295 \begin_layout Standard
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20337 \begin_layout Standard
20343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20346 \begin_layout Standard
20352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20355 \begin_layout Standard
20362 <row topline="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20366 \begin_layout Standard
20367 long (32 bit) support
20372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20375 \begin_layout Standard
20381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_layout Standard
20390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20393 \begin_layout Standard
20399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20402 \begin_layout Standard
20408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20411 \begin_layout Standard
20426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20429 \begin_layout Standard
20436 <row topline="true">
20437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_layout Standard
20441 byte arguments on stack
20446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20449 \begin_layout Standard
20455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20458 \begin_layout Standard
20464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20467 \begin_layout Standard
20473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20476 \begin_layout Standard
20482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20485 \begin_layout Standard
20491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20494 \begin_layout Standard
20501 <row topline="true">
20502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20505 \begin_layout Standard
20507 \begin_inset LatexCommand \index{Floating point support}
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" usebox="none">
20528 \begin_layout Standard
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20537 \begin_layout Standard
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20546 \begin_layout Standard
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20555 \begin_layout Standard
20560 \begin_layout Standard
20561 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20574 \begin_layout Standard
20581 <row topline="true">
20582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20585 \begin_layout Standard
20586 float formats %e %g
20591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20594 \begin_layout Standard
20600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20603 \begin_layout Standard
20609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20612 \begin_layout Standard
20618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20621 \begin_layout Standard
20627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20630 \begin_layout Standard
20636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20639 \begin_layout Standard
20646 <row topline="true" bottomline="true">
20647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20650 \begin_layout Standard
20656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20659 \begin_layout Standard
20665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20668 \begin_layout Standard
20674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20677 \begin_layout Standard
20683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20686 \begin_layout Standard
20692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20695 \begin_layout Standard
20701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20704 \begin_layout Standard
20711 <row bottomline="true">
20712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20715 \begin_layout Standard
20720 \begin_layout Standard
20721 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20725 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20733 \begin_layout Standard
20739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20742 \begin_layout Standard
20748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20751 \begin_layout Standard
20757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20760 \begin_layout Standard
20766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20769 \begin_layout Standard
20775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20778 \begin_layout Standard
20784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20787 \begin_layout Standard
20794 <row bottomline="true">
20795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20798 \begin_layout Standard
20803 \begin_layout Standard
20804 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20813 \begin_layout Standard
20819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20822 \begin_layout Standard
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20831 \begin_layout Standard
20837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20840 \begin_layout Standard
20846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20849 \begin_layout Standard
20855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20858 \begin_layout Standard
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20867 \begin_layout Standard
20872 \begin_layout Standard
20873 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20884 <row bottomline="true">
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20888 \begin_layout Standard
20893 \begin_layout Standard
20894 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20903 \begin_layout Standard
20909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20912 \begin_layout Standard
20918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20921 \begin_layout Standard
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20930 \begin_layout Standard
20936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20939 \begin_layout Standard
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20948 \begin_layout Standard
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20957 \begin_layout Standard
20964 <row bottomline="true">
20965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20968 \begin_layout Standard
20973 \begin_layout Standard
20974 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20983 \begin_layout Standard
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20992 \begin_layout Standard
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21001 \begin_layout Standard
21007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21010 \begin_layout Standard
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21019 \begin_layout Standard
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21028 \begin_layout Standard
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21037 \begin_layout Standard
21051 \begin_layout Subsubsection
21053 \begin_inset LatexCommand \index{malloc.h}
21060 \begin_layout Standard
21061 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21062 using dynamic memory allocation
21063 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21068 \begin_inset LatexCommand \index{heap (malloc)}
21072 space of 1024 bytes is provided for malloc to allocate memory from.
21073 If you need a different heap size you need to recompile _heap.c with the
21074 required size defined in HEAP_SIZE.
21075 It is recommended to make a copy of this file into your project directory
21076 and compile it there with:
21079 \begin_layout Verse
21082 sdcc -c _heap.c -D HEAD_SIZE=2048
21085 \begin_layout Standard
21086 And then link it with:
21089 \begin_layout Verse
21092 sdcc main.rel _heap.rel
21095 \begin_layout Subsection
21096 Math functions (sinf, powf, sqrtf etc.)
21099 \begin_layout Subsubsection
21103 \begin_layout Standard
21104 See definitions in file <math.h>.
21107 \begin_layout Subsection
21111 \begin_layout Standard
21113 \begin_inset LatexCommand \index{Libraries}
21117 included in SDCC should have a license at least as liberal as the GNU Lesser
21118 General Public License
21119 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21130 \begin_layout Standard
21131 \begin_inset Note Note
21134 \begin_layout Standard
21135 license statements for the libraries are missing.
21136 sdcc/device/lib/ser_ir.c
21139 \begin_layout Standard
21141 come with a GPL (as opposed to LGPL) License - this will not be liberal
21142 enough for many embedded programmers.
21150 \begin_layout Standard
21151 If you have ported some library or want to share experience about some code
21153 falls into any of these categories Busses (I
21154 \begin_inset Formula $^{\textrm{2}}$
21157 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21158 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21159 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21160 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21165 would certainly like to hear about it.
21168 \begin_layout Standard
21169 Programmers coding for embedded systems are not especially famous for being
21170 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21171 e these references are very valuable.
21172 Let's help to create a climate where information is shared.
21173 \begin_inset VSpace bigskip
21179 \begin_layout Section
21183 \begin_layout Subsection
21184 MCS51 Memory Models
21185 \begin_inset LatexCommand \index{Memory model}
21190 \begin_inset LatexCommand \index{MCS51 memory model}
21197 \begin_layout Subsubsection
21198 Small, Medium and Large
21201 \begin_layout Standard
21202 SDCC allows three memory models for MCS51 code,
21211 Modules compiled with different memory models should
21215 be combined together or the results would be unpredictable.
21216 The library routines supplied with the compiler are compiled as small,
21218 The compiled library modules are contained in separate directories as small,
21219 medium and large so that you can link to the appropriate set.
21222 \begin_layout Standard
21223 When the medium or large model is used all variables declared without a
21224 storage class will be allocated into the external ram, this includes all
21225 parameters and local variables (for non-reentrant
21226 \begin_inset LatexCommand \index{reentrant}
21231 When the small model is used variables without storage class are allocated
21232 in the internal ram.
21235 \begin_layout Standard
21236 Judicious usage of the processor specific storage classes
21237 \begin_inset LatexCommand \index{Storage class}
21241 and the 'reentrant' function type will yield much more efficient code,
21242 than using the large model.
21243 Several optimizations are disabled when the program is compiled using the
21244 large model, it is therefore recommended that the small model be used unless
21245 absolutely required.
21248 \begin_layout Subsubsection
21250 \begin_inset LatexCommand \label{sub:External-Stack}
21255 \begin_inset LatexCommand \index{stack}
21260 \begin_inset LatexCommand \index{External stack (mcs51)}
21267 \begin_layout Standard
21268 The external stack (-
21272 \begin_layout Standard
21282 \begin_inset LatexCommand \index{-\/-xstack}
21286 ) is located in pdata
21287 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21291 memory (usually at the start of the external ram segment) and uses all
21292 unused space in pdata (max.
21298 \begin_layout Standard
21307 -xstack option is used to compile the program, the parameters and local
21309 \begin_inset LatexCommand \index{local variables}
21313 of all reentrant functions are allocated in this area.
21314 This option is provided for programs with large stack space requirements.
21315 When used with the -
21319 \begin_layout Standard
21329 \begin_inset LatexCommand \index{-\/-stack-auto}
21333 option, all parameters and local variables are allocated on the external
21334 stack (note: support libraries will need to be recompiled with the same
21336 There is a predefined target in the library makefile).
21339 \begin_layout Standard
21340 The compiler outputs the higher order address byte of the external ram segment
21342 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21347 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21351 ), therefore when using the External Stack option, this port
21355 be used by the application program.
21358 \begin_layout Subsection
21360 \begin_inset LatexCommand \index{Memory model}
21365 \begin_inset LatexCommand \index{DS390 memory model}
21372 \begin_layout Standard
21373 The only model supported is Flat 24
21374 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21379 This generates code for the 24 bit contiguous addressing mode of the Dallas
21381 In this mode, up to four meg of external RAM or code space can be directly
21383 See the data sheets at www.dalsemi.com for further information on this part.
21388 that the compiler does not generate any code to place the processor into
21389 24 bitmode (although
21393 in the ds390 libraries will do that for you).
21399 \begin_inset LatexCommand \index{Tinibios (DS390)}
21403 , the boot loader or similar code must ensure that the processor is in 24
21404 bit contiguous addressing mode before calling the SDCC startup code.
21415 \begin_layout Standard
21426 option, variables will by default be placed into the XDATA segment.
21431 Segments may be placed anywhere in the 4 meg address space using the usual
21436 \begin_layout Standard
21446 Note that if any segments are located above 64K, the -r flag must be passed
21447 to the linker to generate the proper segment relocations, and the Intel
21448 HEX output format must be used.
21449 The -r flag can be passed to the linker by using the option
21453 on the SDCC command line.
21454 However, currently the linker can not handle code segments > 64k.
21457 \begin_layout Section
21459 \begin_inset LatexCommand \label{sec:Pragmas}
21464 \begin_inset LatexCommand \index{Pragmas}
21471 \begin_layout Standard
21472 Pragmas are used to turn on and/or off certain compiler options.
21473 Some of them are closely related to corresponding command-line options
21475 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21481 Pragmas should be placed before and/or after a function, placing pragmas
21482 inside a function body could have unpredictable results.
21487 following #pragma directives:
21490 \begin_layout Itemize
21496 \begin_inset LatexCommand \index{\#pragma save}
21500 - this will save most current options to the save/restore stack.
21501 See #pragma\InsetSpace ~
21505 \begin_layout Itemize
21511 \begin_inset LatexCommand \index{\#pragma restore}
21515 - will restore saved options from the last save.
21516 saves & restores can be nested.
21517 SDCC uses a save/restore stack: save pushes current options to the stack,
21518 restore pulls current options from the stack.
21519 See #pragma\InsetSpace ~
21525 \begin_layout Itemize
21531 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21536 \begin_inset LatexCommand \index{function prologue}
21540 function1[,function2[,function3...]]
21541 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21545 - The compiler by default uses a caller saves convention for register saving
21546 across function calls, however this can cause unnecessary register pushing
21548 \begin_inset LatexCommand \index{push/pop}
21552 when calling small functions from larger functions.
21553 This option can be used to switch off the register saving convention for
21554 the function names specified.
21555 The compiler will not save registers when calling these functions, extra
21556 code need to be manually inserted at the entry and exit for these functions
21557 to save and restore the registers used by these functions, this can SUBSTANTIAL
21558 LY reduce code and improve run time performance of the generated code.
21559 In the future the compiler (with inter procedural analysis) may be able
21560 to determine the appropriate scheme to use for each function call.
21565 \begin_layout Standard
21574 -callee-saves command line option is used (see page
21575 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21579 ), the function names specified in #pragma\InsetSpace ~
21581 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21585 is appended to the list of functions specified in the command line.
21588 \begin_layout Itemize
21594 \begin_inset LatexCommand \index{\#pragma exclude}
21598 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21599 of pairs of push/pop
21600 \begin_inset LatexCommand \index{push/pop}
21609 \begin_inset LatexCommand \index{interrupt}
21622 The directive should be placed immediately before the ISR function definition
21623 and it affects ALL ISR functions following it.
21624 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21625 exclude\InsetSpace ~
21627 \begin_inset LatexCommand \index{\#pragma exclude}
21632 See also the related keyword _naked
21633 \begin_inset LatexCommand \index{\_naked}
21638 \begin_inset LatexCommand \index{\_\_naked}
21645 \begin_layout Itemize
21651 \begin_inset LatexCommand \index{pedantic}
21656 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21661 \begin_inset LatexCommand \label{ite:less_pedantic}
21665 - the compiler will not warn you anymore for obvious mistakes, you're on
21667 See also the command line option -
21671 \begin_layout Standard
21681 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21688 More specifically, the following warnings will be disabled:
21690 comparison is always [true/false] due to limited range of data type
21694 overflow in implicit constant conversion
21696 (158); [the (in)famous]
21698 conditional flow changed by optimizer: so said EVELYN the modified DOG
21702 function '[function name]' must return value
21707 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21708 level) are disabled, too, namely:
21711 \begin_inset Note Note
21714 \begin_layout Standard
21715 dunno what comes here - this warning appears to be unused altogether
21724 [left/right] shifting more than size of object changed to zero
21732 integer overflow in expression
21736 unmatched #pragma save and #pragma restore
21740 comparison of 'signed char' with 'unsigned char' requires promotion to int
21744 ISO C90 does not support flexible array members
21748 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21752 \begin_inset Note Note
21755 \begin_layout Standard
21756 appears to be always blank - what was supposed to be here?
21765 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21766 complexity [number]
21771 \begin_layout Itemize
21777 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21781 - the compiler will not warn you anymore about warning number <nnnn>.
21784 \begin_layout Itemize
21790 \begin_inset LatexCommand \index{\#pragma nogcse}
21794 - will stop global common subexpression elimination.
21797 \begin_layout Itemize
21803 \begin_inset LatexCommand \index{\#pragma noinduction}
21807 - will stop loop induction optimizations.
21810 \begin_layout Itemize
21816 \begin_inset LatexCommand \index{\#pragma noinvariant}
21820 - will not do loop invariant optimizations.
21821 For more details see Loop Invariants in section
21822 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21829 \begin_layout Itemize
21835 \begin_inset LatexCommand \index{\#pragma noiv}
21839 - Do not generate interrupt
21840 \begin_inset LatexCommand \index{interrupt}
21845 \begin_inset LatexCommand \index{interrupt vector table}
21849 entries for all ISR functions defined after the pragma.
21850 This is useful in cases where the interrupt vector table must be defined
21851 manually, or when there is a secondary, manually defined interrupt vector
21853 for the autovector feature of the Cypress EZ-USB FX2).
21854 More elegantly this can be achieved by obmitting the optional interrupt
21855 number after the interrupt keyword, see section
21856 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21864 \begin_layout Itemize
21870 \begin_inset LatexCommand \index{\#pragma nojtbound}
21874 - will not generate code for boundary value checking, when switch statements
21875 are turned into jump-tables (dangerous).
21876 For more details see section
21877 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21884 \begin_layout Itemize
21890 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21894 - Will not do loop reversal optimization
21897 \begin_layout Itemize
21903 \begin_inset LatexCommand \index{\#pragma nooverlay}
21907 - the compiler will not overlay the parameters and local variables of a
21911 \begin_layout Itemize
21917 \begin_inset LatexCommand \index{\#pragma stackauto}
21925 \begin_layout Standard
21935 \begin_inset LatexCommand \index{-\/-stack-auto}
21940 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21944 Parameters and Local Variables.
21947 \begin_layout Itemize
21953 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21957 - The compiler will optimize code generation towards fast code, possibly
21958 at the expense of code size.
21959 Currently this has little effect.
21962 \begin_layout Itemize
21968 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21972 - The compiler will optimize code generation towards compact code, possibly
21973 at the expense of code speed.
21974 Currently this has little effect.
21977 \begin_layout Itemize
21983 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21987 - The compiler will attempt to generate code that is both compact and fast,
21988 as long as meeting one goal is not a detriment to the other (this is the
21993 \begin_layout Itemize
21999 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22003 - Generally follow the C89 standard, but allow SDCC features that conflict
22004 with the standard (default).
22007 \begin_layout Itemize
22013 \begin_inset LatexCommand \index{\#pragma std\_c89}
22017 - Follow the C89 standard and disable SDCC features that conflict with the
22021 \begin_layout Itemize
22027 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22031 - Generally follow the C99 standard, but allow SDCC features that conflict
22032 with the standard (incomplete support).
22035 \begin_layout Itemize
22041 \begin_inset LatexCommand \index{\#pragma std\_c99}
22045 - Follow the C99 standard and disable SDCC features that conflict with the
22046 standard (incomplete support).
22049 \begin_layout Itemize
22055 \begin_inset LatexCommand \index{\#pragma codeseg}
22059 - Use this name (max.
22060 8 characters) for the code segment.
22065 \begin_layout Standard
22077 \begin_layout Itemize
22083 \begin_inset LatexCommand \index{\#pragma constseg}
22087 - Use this name (max.
22088 8 characters) for the const segment.
22093 \begin_layout Standard
22105 \begin_layout Standard
22106 The preprocessor SDCPP
22107 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22111 supports the following #pragma directives:
22114 \begin_layout Itemize
22117 pedantic_parse_number
22120 \begin_inset LatexCommand \index{pedantic}
22125 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22130 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22134 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22135 properly and the macro LO_B(3) gets expanded.
22141 \begin_layout Standard
22150 -pedantic-parse-number command line option
22151 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22158 Below is an example on how to use this pragma.
22161 Note: this functionality is not in conformance with standard!
22164 \begin_layout Verse
22167 #pragma pedantic_parse_number +
22168 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22176 #define LO_B(x) ((x) & 0xff)
22180 unsigned char foo(void)
22187 unsigned char c=0xfe-LO_B(3)
22202 \begin_layout Itemize
22208 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22212 (+ | -) - switch _asm _endasm block preprocessing on / off.
22214 You use this prama to define multilines of assembly code.
22215 This will prevent the preprocessor from changing the formating required
22217 Below is an example on how to use this pragma.
22220 \begin_layout Verse
22223 #pragma preproc_asm -
22224 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22230 #define MYDELAY _asm
22235 nop ;my assembly comment...
22249 #pragma preproc_asm
22280 \begin_layout Itemize
22286 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22290 (+ | -) - Allow "naked" hash in macro definition, for example:
22294 #define DIR_LO(x) #(x & 0xff)
22299 Below is an example on how to use this pragma.
22302 \begin_layout Verse
22305 #pragma preproc_asm +
22307 #pragma sdcc_hash +
22308 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22323 mov R6_B3, #(x & 0xff)
22330 mov R7_B3, #((x >> 8) & 0xff)
22354 \begin_layout Standard
22355 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22356 ons which might cause the compiler to generate extra stack and/or data space
22357 to store compiler generated temporary variables.
22358 This usually happens in large functions.
22359 Pragma directives should be used as shown in the following example, they
22360 are used to control options and optimizations for a given function.
22364 \begin_layout Verse
22368 \begin_inset LatexCommand \index{\#pragma save}
22379 /* save the current settings */
22382 \begin_inset LatexCommand \index{\#pragma nogcse}
22391 /* turnoff global subexpression elimination */
22393 #pragma noinduction
22394 \begin_inset LatexCommand \index{\#pragma noinduction}
22398 /* turn off induction optimizations */
22421 \begin_inset LatexCommand \index{\#pragma restore}
22425 /* turn the optimizations back on */
22428 \begin_layout Standard
22429 The compiler will generate a warning message when extra space is allocated.
22430 It is strongly recommended that the save and restore pragmas be used when
22431 changing options for a function.
22440 \begin_layout Section
22441 Defines Created by the Compiler
22444 \begin_layout Standard
22445 The compiler creates the following #defines
22446 \begin_inset LatexCommand \index{\#defines}
22451 \begin_inset LatexCommand \index{Defines created by the compiler}
22460 \begin_layout Standard
22461 \begin_inset Tabular
22462 <lyxtabular version="3" rows="11" columns="2">
22464 <column alignment="left" valignment="top" leftline="true" width="3in">
22465 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22466 <row topline="true" bottomline="true">
22467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22470 \begin_layout Standard
22478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22481 \begin_layout Standard
22490 <row topline="true">
22491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22494 \begin_layout Standard
22496 \begin_inset LatexCommand \index{SDCC}
22505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22508 \begin_layout Standard
22510 Since version 2.5.6 the version number as an int (ex.
22517 <row topline="true">
22518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22521 \begin_layout Standard
22523 \begin_inset LatexCommand \index{SDCC\_mcs51}
22528 \begin_inset LatexCommand \index{SDCC\_ds390}
22533 \begin_inset LatexCommand \index{SDCC\_z80}
22542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22545 \begin_layout Standard
22546 depending on the model used (e.g.: -mds390)
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{\_\_mcs51}
22563 \begin_inset LatexCommand \index{\_\_ds390}
22568 \begin_inset LatexCommand \index{\_\_hc08}
22573 \begin_inset LatexCommand \index{\_\_z80}
22582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22585 \begin_layout Standard
22586 depending on the model used (e.g.
22593 <row topline="true">
22594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22597 \begin_layout Standard
22599 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22611 \begin_layout Standard
22618 \begin_layout Standard
22635 <row topline="true">
22636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22639 \begin_layout Standard
22641 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22653 \begin_layout Standard
22660 \begin_layout Standard
22677 <row topline="true">
22678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22681 \begin_layout Standard
22683 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22695 \begin_layout Standard
22702 \begin_layout Standard
22719 <row topline="true">
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22723 \begin_layout Standard
22725 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22737 \begin_layout Standard
22744 \begin_layout Standard
22761 <row topline="true">
22762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22765 \begin_layout Standard
22767 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22779 \begin_layout Standard
22786 \begin_layout Standard
22803 <row topline="true">
22804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22807 \begin_layout Standard
22809 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22821 \begin_layout Standard
22832 <row topline="true" bottomline="true">
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22836 \begin_layout Standard
22838 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22850 \begin_layout Standard
22868 \begin_layout Chapter
22869 Notes on supported Processors
22872 \begin_layout Section
22874 \begin_inset LatexCommand \label{sub:MCS51-variants}
22879 \begin_inset LatexCommand \index{MCS51 variants}
22886 \begin_layout Standard
22887 MCS51 processors are available from many vendors and come in many different
22889 While they might differ considerably in respect to Special Function Registers
22890 the core MCS51 is usually not modified or is kept compatible.
22894 \begin_layout Subsection
22895 pdata access by SFR
22898 \begin_layout Standard
22899 With the upcome of devices with internal xdata and flash memory devices
22901 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22905 as dedicated I/O port is becoming more popular.
22906 Switching the high byte for pdata
22907 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22911 access which was formerly done by port P2 is then achieved by a Special
22913 \begin_inset LatexCommand \index{sfr}
22918 In well-established MCS51 tradition the address of this
22922 is where the chip designers decided to put it.
22923 Needless to say that they didn't agree on a common name either.
22924 So that the startup code can correctly initialize xdata variables, you
22925 should define an sfr with the name _XPAGE
22928 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22934 at the appropriate location if the default, port P2, is not used for this.
22938 \begin_layout Verse
22941 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22945 \begin_layout Verse
22948 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22953 \begin_layout Verse
22956 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22960 \begin_layout Verse
22963 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22967 \begin_layout Verse
22970 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22974 \begin_layout Standard
22975 For more exotic implementations further customizations may be needed.
22977 \begin_inset LatexCommand \ref{sub:Startup-Code}
22981 for other possibilities.
22984 \begin_layout Subsection
22985 Other Features available by SFR
22988 \begin_layout Standard
22989 Some MCS51 variants offer features like Double DPTR
22990 \begin_inset LatexCommand \index{DPTR}
22994 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22995 These are currently not used for the MCS51 port.
22996 If you absolutely need them you can fall back to inline assembly or submit
22998 \begin_inset VSpace bigskip
23004 \begin_layout Section
23008 \begin_layout Standard
23010 \begin_inset LatexCommand \index{DS80C400}
23015 \begin_inset LatexCommand \index{DS400}
23019 microcontroller has a rich set of peripherals.
23020 In its built-in ROM library it includes functions to access some of the
23021 features, among them is a TCP stack with IP4 and IP6 support.
23022 Library headers (currently in beta status) and other files are provided
23026 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23032 \begin_inset VSpace bigskip
23038 \begin_layout Section
23039 The Z80 and gbz80 port
23042 \begin_layout Standard
23043 SDCC can target both the Zilog Z80
23044 \begin_inset LatexCommand \index{Z80}
23048 and the Nintendo Gameboy's Z80-like gbz80
23049 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23054 The Z80 port is passed through the same
23057 \begin_inset LatexCommand \index{Regression test}
23064 \begin_inset LatexCommand \ref{sec:Quality-control}
23068 ) as the MCS51 and DS390 ports, so floating point support, support for long
23069 variables and bitfield support is fine.
23070 See mailing lists and forums about interrupt routines.
23073 \begin_layout Standard
23074 As always, the code is the authoritative reference - see z80/ralloc.c and
23077 \begin_inset LatexCommand \index{Z80!stack}
23081 frame is similar to that generated by the IAR Z80 compiler.
23082 IX is used as the base pointer, HL and IY are used as a temporary registers,
23083 and BC and DE are available for holding variables.
23085 \begin_inset LatexCommand \index{Z80!return value}
23089 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23091 The gbz80 port use the same set of registers for the return values, but
23092 in a different order of significance: E (one byte), DE (two bytes), or
23094 \begin_inset VSpace bigskip
23100 \begin_layout Section
23104 \begin_layout Standard
23105 The port to the Freescale/Motorola HC08
23106 \begin_inset LatexCommand \index{HC08}
23110 family has been added in October 2003, and is still undergoing some basic
23112 The code generator is complete, but the register allocation is still quite
23114 Some of the SDCC's standard C library functions have embedded non-HC08
23115 inline assembly and so are not yet usable.
23118 \begin_layout Standard
23119 The HC08 port passes the regression test suite (see section
23120 \begin_inset LatexCommand \ref{sec:Quality-control}
23125 \begin_inset VSpace bigskip
23133 \begin_layout Section
23135 \begin_inset LatexCommand \index{PIC14}
23142 \begin_layout Standard
23143 The PIC14 port adds support for Microchip
23144 \begin_inset LatexCommand \index{Microchip}
23149 \begin_inset Formula $^{\text{TM}}$
23153 \begin_inset LatexCommand \index{PIC14}
23158 \begin_inset Formula $^{\text{TM}}$
23161 MCUs with 14 bit wide instructions.
23162 This port is not yet mature and still lacks many features.
23163 However, it can work for simple code.
23166 \begin_layout Standard
23167 Currently supported devices include:
23170 \begin_layout Standard
23171 12F: 629, 635, 675, 683
23174 \begin_layout Standard
23178 \begin_layout Standard
23182 \begin_layout Standard
23183 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23186 \begin_layout Standard
23187 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23191 \begin_layout Standard
23195 \begin_layout Standard
23196 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23200 \begin_layout Standard
23201 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23204 \begin_layout Standard
23205 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23209 \begin_layout Standard
23210 16F: 913, 914, 916, 917
23213 \begin_layout Standard
23214 An up-to-date list of currently supported devices can be obtained via
23216 sdcc -mpic14 -phelp foo.c
23218 (foo.c must exist...).
23221 \begin_layout Subsection
23223 \begin_inset LatexCommand \index{code page (pic14)}
23228 \begin_inset LatexCommand \index{Memory bank (pic14)}
23235 \begin_layout Standard
23236 The linker organizes allocation for the code page and RAM banks.
23237 It does not have intimate knowledge of the code flow.
23238 It will put all the code section of a single .asm file into a single code
23240 In order to make use of multiple code pages, separate asm files must be
23242 The compiler assigns all
23246 functions of a single .c file into the same code page.
23250 To get the best results,
23251 follow these guidelines:
23254 \begin_layout Enumerate
23255 Make local functions static, as non static functions require code page selection
23258 Due to the way sdcc handles functions, place called functions prior
23259 to calling functions in the file wherever possible: Otherwise sdcc will
23260 insert unneccessary pagesel directives around the call, believing that
23261 the called function is externally defined.
23264 \begin_layout Enumerate
23265 For devices that have multiple code pages it is more efficient to use the
23266 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23267 but only 2 files for the 16F874.
23268 This way the linker can put the code for each file into different code
23269 pages and there will be less page selection overhead.
23272 \begin_layout Enumerate
23273 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23274 instruction set), use `unsigned char' wherever possible instead of `int'.
23277 \begin_layout Subsection
23278 Adding New Devices to the Port
23281 \begin_layout Standard
23282 Adding support for a new 14
23286 \begin_layout Standard
23295 bit PIC MCU requires the following steps:
23298 \begin_layout Enumerate
23299 Create a new device description.
23301 Each device is described in two files: pic16f*.h
23303 These files primarily define SFRs, structs to access their bits, and symbolic
23304 configuration options.
23305 Both files can be generated from gputils' .inc files using the perl script
23308 support/scripts/inc2h.pl
23311 This file also contains further instructions on how to proceed.
23314 \begin_layout Enumerate
23315 Copy the .h file into SDCC's include path and either add the .c file to your
23316 project or copy it to
23318 device/lib/pic/libdev
23321 Afterwards, rebuild and install the libraries.
23324 \begin_layout Enumerate
23325 Edit pic14devices.txt in SDCC's include path (
23327 device/include/pic/
23329 in the source tree or
23331 /usr/local/share/sdcc/include/pic
23333 after installation).
23335 You need to add a device specification here to make
23336 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23338 Probably you can copy and modify an existing entry.
23339 The file format is documented at the top of the file.
23342 \begin_layout Subsection
23346 \begin_layout Standard
23347 For the interrupt function, use the keyword `__interrupt'
23348 \begin_inset LatexCommand \index{PIC14!interrupt}
23352 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23353 there to avoid a syntax error - it ought to be fixed).
23357 \begin_layout Verse
23360 void Intr(void) __interrupt 0
23366 T0IF = 0; /* Clear timer interrupt */
23371 \begin_layout Subsection
23372 Linking and Assembling
23375 \begin_layout Standard
23376 For assembling you can use either GPUTILS'
23377 \begin_inset LatexCommand \index{gputils (pic tools)}
23381 gpasm.exe or MPLAB's mpasmwin.exe.
23382 GPUTILS are available from
23383 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23388 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23389 If you use MPLAB and an interrupt function then the linker script file
23390 vectors section will need to be enlarged to link with mplink.
23401 \begin_layout Verse
23414 sdcc -V -mpic14 -p16f877 -c $<
23418 $(PRJ).hex: $(OBJS)
23428 gplink -m -s $(PRJ).lkr
23429 -o $(PRJ).hex $(OBJS) libsdcc.lib
23432 \begin_layout Standard
23440 \begin_layout Verse
23453 sdcc -S -V -mpic14 -p16f877 $<
23463 mpasmwin /q /o $*.asm
23467 $(PRJ).hex: $(OBJS)
23478 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23481 \begin_layout Standard
23482 Please note that indentations within a
23486 have to be done with a tabulator character.
23489 \begin_layout Subsection
23490 Command-Line Options
23493 \begin_layout Standard
23494 Besides the switches common to all SDCC backends, the PIC14 port accepts
23495 the following options (for an updated list see sdcc -
23499 \begin_layout Standard
23511 \begin_layout Description
23516 \begin_layout Standard
23526 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23530 emit debug info in assembly output
23533 \begin_layout Description
23538 \begin_layout Standard
23548 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23552 disable (slightly faulty) optimization on pCode
23555 \begin_layout Description
23560 \begin_layout Standard
23570 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23574 sets the lowest address of the argument passing stack (defaults to a suitably
23575 large shared databank to reduce BANKSEL overhead)
23578 \begin_layout Description
23583 \begin_layout Standard
23593 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23597 sets the size if the argument passing stack (default: 16, minimum: 4)
23600 \begin_layout Subsection
23601 Environment Variables
23604 \begin_layout Standard
23605 The PIC14 port recognizes the following environment variables:
23608 \begin_layout Description
23609 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23610 register (the ones called r0xNNNN) in a section of its own.
23611 By default (if this variable is unset), sdcc tries to cluster registers
23612 in sections in order to reduce the BANKSEL overhead when accessing them.
23615 \begin_layout Subsection
23619 \begin_layout Standard
23620 The PIC14 library currently only contains support routines required by the
23621 compiler to implement multiplication, division, and floating point support.
23622 No libc-like replacement is available at the moment, though many of the
23623 common sdcc library sources (in
23627 ) should also compile with the PIC14 port.
23630 \begin_layout Subsubsection
23631 error: missing definition for symbol ``__gptrget1''
23634 \begin_layout Standard
23635 The PIC14 port uses library routines to provide more complex operations
23636 like multiplication, division/modulus and (generic) pointer dereferencing.
23637 In order to add these routines to your project, you must link with PIC14's
23643 For single source file projects this is done automatically, more complex
23648 to the linker's arguments.
23649 Make sure you also add an include path for the library (using the -I switch
23653 \begin_layout Subsubsection
23654 Processor mismatch in file ``XXX''.
23657 \begin_layout Standard
23658 This warning can usually be ignored due to the very good compatibility amongst
23663 \begin_layout Standard
23673 \begin_inset LatexCommand \index{PIC14}
23680 \begin_layout Standard
23681 You might also consider recompiling the library for your specific device
23682 by changing the ARCH=p16f877 (default target) entry in
23684 device/lib/pic/Makefile.in
23688 device/lib/pic/Makefile
23690 to reflect your device.
23691 This might even improve performance for smaller devices as unneccesary
23692 BANKSELs might be removed.
23695 \begin_layout Subsection
23699 \begin_layout Subsubsection
23703 \begin_layout Standard
23704 Functions with variable argument lists (like printf) are not yet supported.
23705 Similarly, taking the argument of the first argument passed into a function
23706 does not work: It is currently passed in WREG and has no address...
23709 \begin_layout Subsubsection
23710 Regression tests fail
23713 \begin_layout Standard
23714 Though the small subset of regression tests in src/regression passes, SDCC
23715 regression test suite does not, indicating that there are still major bugs
23717 However, many smaller projects have successfully used SDCC in the past...
23720 \begin_layout Standard
23728 \begin_layout Section
23730 \begin_inset LatexCommand \index{PIC16}
23737 \begin_layout Standard
23738 The PIC16 port adds support for Microchip
23739 \begin_inset LatexCommand \index{Microchip}
23744 \begin_inset Formula $^{\text{TM}}$
23748 \begin_inset LatexCommand \index{PIC}
23753 \begin_inset Formula $^{\text{TM}}$
23756 MCUs with 16 bit wide instructions.
23757 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23758 ; devices supported by the port include:
23761 \begin_layout Standard
23762 18F: 242, 248, 252, 258, 442, 448, 452, 458
23765 \begin_layout Standard
23769 \begin_layout Standard
23770 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23774 \begin_layout Standard
23775 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23779 \begin_layout Standard
23780 18F: 6520, 6620, 6680, 6720
23783 \begin_layout Standard
23784 18F: 8520, 8620, 8680, 8720
23787 \begin_layout Subsection
23791 \begin_layout Standard
23792 PIC16 port supports the standard command line arguments as supposed, with
23793 the exception of certain cases that will be mentioned in the following
23797 \begin_layout Description
23802 \begin_layout Standard
23812 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23820 \begin_layout Standard
23832 \begin_layout Description
23837 \begin_layout Standard
23846 -fommit-frame-pointer
23847 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23851 Frame pointer will be omitted when the function uses no local variables.
23854 \begin_layout Subsection
23855 Port Specific Options
23856 \begin_inset LatexCommand \index{Options PIC16}
23863 \begin_layout Standard
23864 The port specific options appear after the global options in the sdcc -
23868 \begin_layout Standard
23880 \begin_layout Subsubsection
23881 Code Generation Options
23884 \begin_layout Standard
23885 These options influence the generated assembler code.
23888 \begin_layout Description
23893 \begin_layout Standard
23902 -pstack-model=[model] Used in conjuction with the command above.
23903 Defines the stack model to be used, valid stack models are:
23908 \labelwidthstring 00.00.0000
23913 Selects small stack model.
23914 8 bit stack and frame pointers.
23915 Supports 256 bytes stack size.
23919 \labelwidthstring 00.00.0000
23924 Selects large stack model.
23925 16 bit stack and frame pointers.
23926 Supports 65536 bytes stack size.
23930 \begin_layout Description
23935 \begin_layout Standard
23944 -pno-banksel Do not generate BANKSEL assembler directives.
23947 \begin_layout Description
23952 \begin_layout Standard
23961 -extended Enable extended instruction set/literal offset addressing mode.
23965 \begin_layout Subsubsection
23966 Optimization Options
23969 \begin_layout Description
23974 \begin_layout Standard
23983 -obanksel=n Set optimization level for inserting BANKSELs.
23990 \labelwidthstring 00.00.0000
23995 \labelwidthstring 00.00.0000
23996 1 checks previous used register and if it is the same then does not emit
23997 BANKSEL, accounts only for labels.
24001 \labelwidthstring 00.00.0000
24002 2 tries to check the location of (even different) symbols and removes BANKSELs
24003 if they are in the same bank.
24008 Important: There might be problems if the linker script has data sections
24009 across bank borders!
24013 \begin_layout Description
24018 \begin_layout Standard
24027 -denable-peeps Force the usage of peepholes.
24031 \begin_layout Description
24036 \begin_layout Standard
24045 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24048 \begin_layout Description
24053 \begin_layout Standard
24062 -optimize-cmp Try to optimize some compares.
24065 \begin_layout Description
24070 \begin_layout Standard
24079 -optimize-df Analyze the dataflow of the generated code and improve it.
24082 \begin_layout Subsubsection
24086 \begin_layout Description
24091 \begin_layout Standard
24100 -asm= Sets the full path and name of an external assembler to call.
24103 \begin_layout Description
24108 \begin_layout Standard
24118 \begin_inset LatexCommand \index{PIC16!MPLAB}
24122 compatibility option.
24123 Currently only suppresses special gpasm directives.
24126 \begin_layout Subsubsection
24130 \begin_layout Description
24135 \begin_layout Standard
24144 -link= Sets the full path and name of an external linker to call.
24147 \begin_layout Description
24152 \begin_layout Standard
24161 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24162 unitialized data variables with [kword].
24163 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24166 \begin_layout Description
24171 \begin_layout Standard
24180 -ivt-loc=n Place the interrupt vector table at address
24185 Useful for bootloaders.
24188 \begin_layout Description
24193 \begin_layout Standard
24202 -nodefaultlibs Do not link default libraries when linking.
24205 \begin_layout Description
24210 \begin_layout Standard
24219 -use-crt= Use a custom run-time module instead of the defaults.
24222 \begin_layout Description
24227 \begin_layout Standard
24236 -no-crt Don't link the default run-time modules
24239 \begin_layout Subsubsection
24243 \begin_layout Standard
24244 Debugging options enable extra debugging information in the output files.
24247 \begin_layout Description
24252 \begin_layout Standard
24261 -debug-xtra Similar to -
24265 \begin_layout Standard
24275 \begin_inset LatexCommand \index{-\/-debug}
24279 , but dumps more information.
24282 \begin_layout Description
24287 \begin_layout Standard
24296 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24298 <source> is the name of the file being compiled.
24301 \begin_layout Description
24306 \begin_layout Standard
24315 -pcode-verbose Enable pcode debugging information in translation.
24318 \begin_layout Description
24323 \begin_layout Standard
24332 -calltree Dump call tree in .calltree file.
24335 \begin_layout Description
24340 \begin_layout Standard
24349 -gstack Trace push/pops for stack pointer overflow.
24352 \begin_layout Subsection
24353 Enviroment Variables
24356 \begin_layout Standard
24357 There is a number of enviromental variables that can be used when running
24358 SDCC to enable certain optimizations or force a specific program behaviour.
24359 these variables are primarily for debugging purposes so they can be enabled/dis
24363 \begin_layout Standard
24364 Currently there is only two such variables available:
24367 \begin_layout Description
24368 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24369 bitfields is optimized by directly loading FSR0 with the address of the
24370 bitfield structure.
24371 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24373 This step saves data ram and code space for functions that make heavy use
24375 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24380 \begin_layout Description
24381 NO_REG_OPT Do not perform pCode registers optimization.
24382 This should be used for debugging purposes.
24383 If bugs in the pcode optimizer are found, users can benefit from temporarily
24384 disabling the optimizer until the bug is fixed.
24387 \begin_layout Subsection
24388 Preprocessor Macros
24391 \begin_layout Standard
24393 \begin_inset LatexCommand \index{PIC16}
24397 port defines the following preprocessor macros while translating a source.
24400 \begin_layout Standard
24402 \begin_inset Tabular
24403 <lyxtabular version="3" rows="6" columns="2">
24405 <column alignment="center" valignment="top" leftline="true" width="0">
24406 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24407 <row topline="true" bottomline="true">
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24411 \begin_layout Standard
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24420 \begin_layout Standard
24427 <row topline="true">
24428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24431 \begin_layout Standard
24437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24440 \begin_layout Standard
24441 Port identification
24447 <row topline="true">
24448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24451 \begin_layout Standard
24456 \begin_layout Standard
24470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24473 \begin_layout Standard
24474 Port identification (same as above)
24480 <row topline="true">
24481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24484 \begin_layout Standard
24490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24493 \begin_layout Standard
24494 MCU Identification.
24499 is the microcontrol identification number, i.e.
24506 <row topline="true">
24507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24510 \begin_layout Standard
24515 \begin_layout Standard
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24532 \begin_layout Standard
24533 MCU Identification (same as above)
24539 <row topline="true" bottomline="true">
24540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24543 \begin_layout Standard
24549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24552 \begin_layout Standard
24553 nnn = SMALL or LARGE respectively according to the stack model used
24566 \begin_layout Standard
24567 In addition the following macros are defined when calling assembler:
24570 \begin_layout Standard
24572 \begin_inset Tabular
24573 <lyxtabular version="3" rows="4" columns="2">
24575 <column alignment="center" valignment="top" leftline="true" width="0">
24576 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24577 <row topline="true" bottomline="true">
24578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24581 \begin_layout Standard
24587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24590 \begin_layout Standard
24597 <row topline="true">
24598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24601 \begin_layout Standard
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24610 \begin_layout Standard
24611 MCU Identification.
24616 is the microcontrol identification number, i.e.
24623 <row topline="true">
24624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24627 \begin_layout Standard
24633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24636 \begin_layout Standard
24637 nnn = SMALL or LARGE respectively according to the memory model used for
24644 <row topline="true" bottomline="true">
24645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24648 \begin_layout Standard
24654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24657 \begin_layout Standard
24658 nnn = SMALL or LARGE respectively according to the stack model used
24671 \begin_layout Subsection
24675 \begin_layout Standard
24677 \begin_inset LatexCommand \index{PIC16}
24681 port uses the following directories for searching header files and libraries.
24684 \begin_layout Standard
24686 \begin_inset Tabular
24687 <lyxtabular version="3" rows="3" columns="4">
24689 <column alignment="center" valignment="top" leftline="true" width="0">
24690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24691 <column alignment="center" valignment="top" width="0">
24692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24693 <row topline="true" bottomline="true">
24694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24697 \begin_layout Standard
24703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24706 \begin_layout Standard
24712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24715 \begin_layout Standard
24721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24724 \begin_layout Standard
24731 <row topline="true">
24732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24735 \begin_layout Standard
24736 PREFIX/sdcc/include/pic16
24741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24744 \begin_layout Standard
24745 PIC16 specific headers
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24753 \begin_layout Standard
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24762 \begin_layout Standard
24769 <row topline="true" bottomline="true">
24770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24773 \begin_layout Standard
24774 PREFIX/sdcc/lib/pic16
24779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24782 \begin_layout Standard
24783 PIC16 specific libraries
24788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24791 \begin_layout Standard
24797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24800 \begin_layout Standard
24814 \begin_layout Subsection
24816 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24823 \begin_layout Standard
24825 \begin_inset LatexCommand \index{PIC16}
24829 port currently supports the following pragmas:
24832 \begin_layout Description
24834 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24838 This forces the code generator to initialize the stack & frame pointers
24839 at a specific address.
24840 This is an ad hoc solution for cases where no STACK directive is available
24841 in the linker script or gplink is not instructed to create a stack section.
24844 stack pragma should be used only once in a project.
24845 Multiple pragmas may result in indeterminate behaviour of the program.
24849 \begin_layout Standard
24850 The old format (ie.
24851 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24852 cross page boundaries (or even exceed the available data RAM) and crash
24854 Make sure that stack does not cross page boundaries when using the SMALL
24862 The format is as follows:
24867 \begin_layout LyX-Code
24868 #pragma stack bottom_address [stack_size]
24873 \begin_layout Standard
24878 is the lower bound of the stack section.
24879 The stack pointer initially will point at address (bottom_address+stack_size-1).
24882 \begin_layout LyX-Code
24886 \begin_layout LyX-Code
24890 \begin_layout LyX-Code
24891 /* initializes stack of 100 bytes at RAM address 0x200 */
24894 \begin_layout LyX-Code
24895 #pragma stack 0x200 100
24898 \begin_layout Standard
24899 If the stack_size field is omitted then a stack is created with the default
24901 This size might be enough for most programs, but its not enough for operations
24902 with deep function nesting or excessive stack usage.
24905 \begin_layout Description
24907 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24911 Force a function to a static FLASH address.
24914 \begin_layout LyX-Code
24918 \begin_layout LyX-Code
24922 \begin_layout LyX-Code
24923 /* place function test_func at 0x4000 */
24926 \begin_layout LyX-Code
24927 #pragma code test_func 0x4000
24930 \begin_layout LyX-Code
24934 \begin_layout Description
24935 library instructs the linker to use a library module.
24940 \begin_layout LyX-Code
24941 #pragma library module_name
24944 \begin_layout Standard
24949 can be any library or object file (including its path).
24950 Note that there are four reserved keywords which have special meaning.
24954 \begin_layout Standard
24956 \begin_inset Tabular
24957 <lyxtabular version="3" rows="6" columns="3">
24959 <column alignment="center" valignment="top" leftline="true" width="0">
24960 <column alignment="block" valignment="top" leftline="true" width="20page%">
24961 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24962 <row topline="true" bottomline="true">
24963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24966 \begin_layout Standard
24972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24975 \begin_layout Standard
24981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24984 \begin_layout Standard
24991 <row topline="true">
24992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24995 \begin_layout Standard
25003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25006 \begin_layout Standard
25007 ignore all library pragmas
25012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25015 \begin_layout Standard
25024 <row topline="true">
25025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25028 \begin_layout Standard
25036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25039 \begin_layout Standard
25045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25048 \begin_layout Standard
25059 <row topline="true">
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25063 \begin_layout Standard
25071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25074 \begin_layout Standard
25075 link the Math libarary
25080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25083 \begin_layout Standard
25094 <row topline="true">
25095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25098 \begin_layout Standard
25106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25109 \begin_layout Standard
25110 link the I/O library
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25118 \begin_layout Standard
25129 <row topline="true" bottomline="true">
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25133 \begin_layout Standard
25141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25144 \begin_layout Standard
25145 link the debug library
25150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25153 \begin_layout Standard
25170 * is the device number, i.e.
25171 452 for PIC18F452 MCU.
25174 \begin_layout Standard
25175 This feature allows for linking with specific libraries withoug having to
25176 explicit name them in the command line.
25181 keyword will reject all modules specified by the library pragma.
25184 \begin_layout Description
25185 udata The pragma udata instructs the compiler to emit code so that linker
25186 will place a variable at a specific memory bank.
25189 \begin_layout LyX-Code
25193 \begin_layout LyX-Code
25197 \begin_layout LyX-Code
25198 /* places variable foo at bank2 */
25201 \begin_layout LyX-Code
25202 #pragma udata bank2 foo
25205 \begin_layout LyX-Code
25209 \begin_layout Standard
25210 In order for this pragma to work extra SECTION directives should be added
25211 in the .lkr script.
25212 In the following example a sample .lkr file is shown:
25215 \begin_layout LyX-Code
25219 \begin_layout LyX-Code
25220 // Sample linker script for the PIC18F452 processor
25223 \begin_layout LyX-Code
25227 \begin_layout LyX-Code
25228 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25231 \begin_layout LyX-Code
25232 CODEPAGE NAME=page START=0x2A END=0x7FFF
25235 \begin_layout LyX-Code
25236 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25239 \begin_layout LyX-Code
25240 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25243 \begin_layout LyX-Code
25244 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25247 \begin_layout LyX-Code
25248 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25251 \begin_layout LyX-Code
25252 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25255 \begin_layout LyX-Code
25259 \begin_layout LyX-Code
25260 DATABANK NAME=gpr0 START=0x80 END=0xFF
25263 \begin_layout LyX-Code
25264 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25267 \begin_layout LyX-Code
25268 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25271 \begin_layout LyX-Code
25272 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25275 \begin_layout LyX-Code
25276 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25279 \begin_layout LyX-Code
25280 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25283 \begin_layout LyX-Code
25284 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25287 \begin_layout LyX-Code
25291 \begin_layout LyX-Code
25292 SECTION NAME=CONFIG ROM=config
25295 \begin_layout LyX-Code
25299 \begin_layout LyX-Code
25300 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25303 \begin_layout LyX-Code
25304 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25307 \begin_layout LyX-Code
25308 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25311 \begin_layout LyX-Code
25312 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25315 \begin_layout LyX-Code
25316 SECTION NAME=bank4 RAM=gpr4
25319 \begin_layout LyX-Code
25320 SECTION NAME=bank5 RAM=gpr5
25323 \begin_layout Standard
25324 The linker will recognise the section name set in the pragma statement and
25325 will position the variable at the memory bank set with the RAM field at
25326 the SECTION line in the linker script file.
25329 \begin_layout Subsection
25331 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25338 \begin_layout Standard
25339 There is one main header file
25340 \begin_inset LatexCommand \index{PIC16!Header files}
25344 that can be included to the source files using the pic16
25345 \begin_inset LatexCommand \index{PIC16}
25355 This header file contains the definitions for the processor special registers,
25356 so it is necessary if the source accesses them.
25357 It can be included by adding the following line in the beginning of the
25361 \begin_layout LyX-Code
25362 #include <pic18fregs.h>
25365 \begin_layout Standard
25366 The specific microcontroller is selected within the pic18fregs.h automatically,
25367 so the same source can be used with a variety of devices.
25370 \begin_layout Subsection
25374 \begin_layout Standard
25376 \begin_inset LatexCommand \index{PIC16!Libraries}
25381 \begin_inset LatexCommand \index{PIC16}
25385 port depends on are the microcontroller device libraries which contain
25386 the symbol definitions for the microcontroller special function registers.
25387 These libraries have the format pic18fxxxx.lib, where
25391 is the microcontroller identification number.
25392 The specific library is selected automatically by the compiler at link
25393 stage according to the selected device.
25396 \begin_layout Standard
25397 Libraries are created with gplib which is part of the gputils package
25398 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25405 \begin_layout Subsubsection*
25406 Building the libraries
25409 \begin_layout Standard
25410 Before using SDCC/pic16 there are some libraries that need to be compiled.
25411 This process is not done automatically by SDCC since not all users use
25412 SDCC for pic16 projects.
25413 So each user should compile the libraries separately.
25416 \begin_layout Standard
25417 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25420 \begin_layout LyX-Code
25421 cd device/lib/pic16
25424 \begin_layout LyX-Code
25428 \begin_layout LyX-Code
25432 \begin_layout LyX-Code
25436 \begin_layout LyX-Code
25440 \begin_layout LyX-Code
25441 su -c 'make install' # install the libraries, you need the root password
25444 \begin_layout Standard
25445 If you need to install the headers too, do:
25448 \begin_layout LyX-Code
25452 \begin_layout LyX-Code
25453 su -c 'make install' # install the headers, you need the root password
25456 \begin_layout Standard
25457 There exist a special target to build the I/O libraries.
25458 This target is not automatically build because it will build the I/O library
25464 This way building will take quite a lot of time.
25465 Users are advised to edit the
25467 device/lib/pic16/pics.build
25469 file and then execute:
25472 \begin_layout LyX-Code
25476 \begin_layout Subsection
25477 Adding New Devices to the Port
25480 \begin_layout Standard
25481 Adding support for a new 16
25485 \begin_layout Standard
25494 bit PIC MCU requires the following steps:
25497 \begin_layout Enumerate
25498 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25502 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25506 \begin_layout Enumerate
25509 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25512 \begin_layout Enumerate
25515 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25518 \begin_layout Enumerate
25521 /path/to/sdcc/device/lib/pics.all
25529 Note: No 18f prefix here!
25532 \begin_layout Enumerate
25535 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25539 Add your DEVICE if it does not compile in
25554 \begin_layout Enumerate
25557 /path/to/sdcc/device/include/pic16/pic18fregs.h
25560 The file format is self-explanatory, just add
25564 #elif defined(picDEVICE)
25566 # include <picDEVICE.h>
25570 at the right place (keep it sorted).
25573 \begin_layout Enumerate
25576 /path/to/sdcc/src/pic16/devices.inc
25579 Copy and modify an existing entry and insert it at the correct place (keep
25581 The file is hardly documented, look at the entries for the 18f2221...
25584 \begin_layout Enumerate
25585 Recompile SDCC, including the pic16 libraries.
25588 \begin_layout Subsection
25592 \begin_layout Standard
25593 The following memory models are supported by the PIC16 port:
25596 \begin_layout Itemize
25600 \begin_layout Itemize
25604 \begin_layout Standard
25605 Memory model affects the default size of pointers within the source.
25606 The sizes are shown in the next table:
25609 \begin_layout Standard
25611 \begin_inset Tabular
25612 <lyxtabular version="3" rows="3" columns="3">
25614 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25615 <column alignment="center" valignment="top" leftline="true" width="0">
25616 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25617 <row topline="true" bottomline="true">
25618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25621 \begin_layout Standard
25622 Pointer sizes according to memory model
25627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25630 \begin_layout Standard
25636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25639 \begin_layout Standard
25646 <row topline="true" bottomline="true">
25647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25650 \begin_layout Standard
25656 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25659 \begin_layout Standard
25665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25668 \begin_layout Standard
25675 <row topline="true" bottomline="true">
25676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25679 \begin_layout Standard
25685 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25688 \begin_layout Standard
25694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25697 \begin_layout Standard
25711 \begin_layout Standard
25712 It is advisable that all sources within a project are compiled with the
25714 If one wants to override the default memory model, this can be done by
25715 declaring a pointer as
25724 Far selects large memory model's pointers, while near selects small memory
25728 \begin_layout Standard
25729 The standard device libraries (see
25730 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25734 ) contain no reference to pointers, so they can be used with both memory
25738 \begin_layout Subsection
25742 \begin_layout Standard
25744 \begin_inset LatexCommand \index{PIC16!stack}
25748 implementation for the PIC16 port uses two indirect registers, FSR1 and
25752 \begin_layout Description
25753 FSR1 is assigned as stack pointer
25756 \begin_layout Description
25757 FSR2 is assigned as frame pointer
25760 \begin_layout Standard
25761 The following stack models are supported by the PIC16 port
25764 \begin_layout Itemize
25772 \begin_layout Itemize
25780 \begin_layout Standard
25785 model means that only the FSRxL byte is used to access stack and frame,
25792 uses both FSRxL and FSRxH registers.
25793 The following table shows the stack/frame pointers sizes according to stack
25794 model and the maximum space they can address:
25797 \begin_layout Standard
25799 \begin_inset Tabular
25800 <lyxtabular version="3" rows="3" columns="3">
25802 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25803 <column alignment="center" valignment="top" leftline="true" width="0">
25804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25805 <row topline="true" bottomline="true">
25806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25809 \begin_layout Standard
25810 Stack & Frame pointer sizes according to stack model
25815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25818 \begin_layout Standard
25824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25827 \begin_layout Standard
25834 <row topline="true">
25835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25838 \begin_layout Standard
25844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25847 \begin_layout Standard
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25856 \begin_layout Standard
25863 <row topline="true" bottomline="true">
25864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25867 \begin_layout Standard
25873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25876 \begin_layout Standard
25882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25885 \begin_layout Standard
25899 \begin_layout Standard
25904 stack model is currently not working properly throughout the code generator.
25905 So its use is not advised.
25906 Also there are some other points that need special care:
25911 \begin_layout Enumerate
25912 Do not create stack sections with size more than one physical bank (that
25916 \begin_layout Enumerate
25917 Stack sections should no cross physical bank limits (i.e.
25918 #pragma stack 0x50 0x100)
25921 \begin_layout Standard
25922 These limitations are caused by the fact that only FSRxL is modified when
25923 using SMALL stack model, so no more than 256 bytes of stack can be used.
25924 This problem will disappear after LARGE model is fully implemented.
25927 \begin_layout Subsection
25931 \begin_layout Standard
25932 In addition to the standard SDCC function keywords, PIC16
25933 \begin_inset LatexCommand \index{PIC16}
25937 port makes available two more:
25940 \begin_layout Description
25942 \begin_inset LatexCommand \index{PIC16!wparam}
25946 Use the WREG to pass one byte of the first function argument.
25947 This improves speed but you may not use this for functions with arguments
25948 that are called via function pointers, otherwise the first byte of the
25949 first parameter will get lost.
25953 \begin_layout LyX-Code
25954 void func_wparam(int a) wparam
25957 \begin_layout LyX-Code
25961 \begin_layout LyX-Code
25962 /* WREG hold the lower part of a */
25965 \begin_layout LyX-Code
25966 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25970 \begin_layout LyX-Code
25974 \begin_layout LyX-Code
25978 \begin_layout Description
25980 \begin_inset LatexCommand \index{PIC16!shadowregs}
25984 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25985 hardware shadow registers which hold the values of WREG, STATUS and BSR
25987 This can be done by adding the keyword
25995 keyword in the function's header.
25998 \begin_layout LyX-Code
25999 void isr_shadow(void) shadowregs interrupt 1
26002 \begin_layout LyX-Code
26006 \begin_layout LyX-Code
26010 \begin_layout LyX-Code
26014 \begin_layout Standard
26019 instructs the code generator not to store/restore WREG, STATUS, BSR when
26020 entering/exiting the ISR.
26023 \begin_layout Subsection
26024 Function return values
26027 \begin_layout Standard
26028 Return values from functions are placed to the appropriate registers following
26029 a modified Microchip policy optimized for SDCC.
26030 The following table shows these registers:
26033 \begin_layout Standard
26035 \begin_inset Tabular
26036 <lyxtabular version="3" rows="6" columns="2">
26038 <column alignment="center" valignment="top" leftline="true" width="0">
26039 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26040 <row topline="true" bottomline="true">
26041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26044 \begin_layout Standard
26050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26053 \begin_layout Standard
26054 destination register
26060 <row topline="true">
26061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26064 \begin_layout Standard
26070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26073 \begin_layout Standard
26080 <row topline="true">
26081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26084 \begin_layout Standard
26090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26093 \begin_layout Standard
26100 <row topline="true">
26101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26104 \begin_layout Standard
26110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26113 \begin_layout Standard
26120 <row topline="true">
26121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26124 \begin_layout Standard
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26133 \begin_layout Standard
26134 FSR0L:PRODH:PRODL:WREG
26140 <row topline="true" bottomline="true">
26141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26144 \begin_layout Standard
26150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26153 \begin_layout Standard
26154 on stack, FSR0 points to the beginning
26167 \begin_layout Subsection
26171 \begin_layout Standard
26173 \begin_inset LatexCommand \index{PIC16!interrupt}
26177 service routine (ISR) is declared using the
26184 \begin_layout LyX-Code
26185 void isr(void) interrupt
26190 \begin_layout LyX-Code
26194 \begin_layout LyX-Code
26198 \begin_layout LyX-Code
26202 \begin_layout Standard
26207 is the interrupt number, which for PIC18F devices can be:
26210 \begin_layout Standard
26212 \begin_inset Tabular
26213 <lyxtabular version="3" rows="4" columns="3">
26215 <column alignment="center" valignment="top" leftline="true" width="0">
26216 <column alignment="center" valignment="top" leftline="true" width="0">
26217 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26218 <row topline="true" bottomline="true">
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26222 \begin_layout Standard
26230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26233 \begin_layout Standard
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26242 \begin_layout Standard
26243 Interrupt Vector Address
26249 <row topline="true">
26250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26253 \begin_layout Standard
26259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26262 \begin_layout Standard
26268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26271 \begin_layout Standard
26278 <row topline="true">
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 \begin_layout Standard
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26300 \begin_layout Standard
26310 HIGH priority interrupts
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26318 \begin_layout Standard
26325 <row topline="true" bottomline="true">
26326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26329 \begin_layout Standard
26335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26338 \begin_layout Standard
26339 LOW priority interrupts
26344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26347 \begin_layout Standard
26361 \begin_layout Standard
26362 When generating assembly code for ISR the code generator places a
26368 Interrupt Vector Address
26370 which points at the genetated ISR.
26371 This single GOTO instruction is part of an automatically generated
26373 interrupt entry point
26376 The actuall ISR code is placed as normally would in the code space.
26377 Upon interrupt request, the GOTO instruction is executed which jumps to
26379 When declaring interrupt functions as _naked this GOTO instruction is
26384 The whole interrupt functions is therefore placed at the Interrupt Vector
26385 Address of the specific interrupt.
26386 This is not a problem for the LOW priority interrupts, but it is a problem
26387 for the RESET and the HIGH priority interrupts because code may be written
26388 at the next interrupt's vector address and cause undeterminate program
26389 behaviour if that interrupt is raised.
26393 \begin_layout Standard
26394 This is not a problem when
26397 \begin_layout Enumerate
26398 this is a HIGH interrupt ISR and LOW interrupts are
26405 \begin_layout Enumerate
26406 when the ISR is small enough not to reach the next interrupt's vector address.
26414 \begin_layout Standard
26420 This way a function is generated similar to an ISR, but it is not assigned
26424 \begin_layout Standard
26425 When entering an interrupt, currently the PIC16
26426 \begin_inset LatexCommand \index{PIC16}
26430 port automatically saves the following registers:
26433 \begin_layout Itemize
26437 \begin_layout Itemize
26441 \begin_layout Itemize
26445 \begin_layout Itemize
26446 PROD (PRODL and PRODH)
26449 \begin_layout Itemize
26450 FSR0 (FSR0L and FSR0H)
26453 \begin_layout Standard
26454 These registers are restored upon return from the interrupt routine.
26458 \begin_layout Standard
26459 NOTE that when the _naked attribute is specified for an interrupt routine,
26460 then NO registers are stored or restored.
26468 \begin_layout Subsection
26472 \begin_layout Standard
26473 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26474 There are 3 types of generic pointers currently implemented data, code
26475 and eeprom pointers.
26476 They are differentiated by the value of the 7th and 6th bits of the upper
26480 \begin_layout Standard
26482 \begin_inset Tabular
26483 <lyxtabular version="3" rows="5" columns="5">
26485 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26486 <column alignment="center" valignment="top" width="0">
26487 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26488 <column alignment="center" valignment="top" width="0">
26489 <column alignment="left" valignment="top" rightline="true" width="0">
26490 <row topline="true" bottomline="true">
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26494 \begin_layout Standard
26500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26503 \begin_layout Standard
26509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26512 \begin_layout Standard
26518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26521 \begin_layout Standard
26522 rest of the pointer
26527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26530 \begin_layout Standard
26537 <row topline="true" bottomline="true">
26538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26541 \begin_layout Standard
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26550 \begin_layout Standard
26556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26559 \begin_layout Standard
26565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26568 \begin_layout Standard
26573 uuuuuu uuuuxxxx xxxxxxxx
26578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26581 \begin_layout Standard
26582 a 12-bit data pointer in data RAM memory
26588 <row bottomline="true">
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26592 \begin_layout Standard
26598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26601 \begin_layout Standard
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26610 \begin_layout Standard
26616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26619 \begin_layout Standard
26624 uxxxxx xxxxxxxx xxxxxxxx
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26632 \begin_layout Standard
26633 a 21-bit code pointer in FLASH memory
26639 <row bottomline="true">
26640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26643 \begin_layout Standard
26649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26652 \begin_layout Standard
26658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26661 \begin_layout Standard
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26670 \begin_layout Standard
26675 uuuuuu uuuuuuxx xxxxxxxx
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26683 \begin_layout Standard
26684 a 10-bit eeprom pointer in EEPROM memory
26690 <row bottomline="true">
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26694 \begin_layout Standard
26700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26703 \begin_layout Standard
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26712 \begin_layout Standard
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26721 \begin_layout Standard
26726 xxxxxx xxxxxxxx xxxxxxxx
26731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26734 \begin_layout Standard
26735 unimplemented pointer type
26748 \begin_layout Standard
26749 Generic pointer are read and written with a set of library functions which
26750 read/write 1, 2, 3, 4 bytes.
26753 \begin_layout Subsection
26757 \begin_layout Subsubsection
26758 Standard I/O Streams
26761 \begin_layout Standard
26766 the type FILE is defined as:
26769 \begin_layout LyX-Code
26770 typedef char * FILE;
26773 \begin_layout Standard
26774 This type is the stream type implemented I/O in the PIC18F devices.
26775 Also the standard input and output streams are declared in stdio.h:
26778 \begin_layout LyX-Code
26779 extern FILE * stdin;
26782 \begin_layout LyX-Code
26783 extern FILE * stdout;
26786 \begin_layout Standard
26787 The FILE type is actually a generic pointer which defines one more type
26788 of generic pointers, the
26793 This new type has the format:
26796 \begin_layout Standard
26798 \begin_inset Tabular
26799 <lyxtabular version="3" rows="2" columns="7">
26801 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26802 <column alignment="center" valignment="top" width="0">
26803 <column alignment="center" valignment="top" leftline="true" width="0">
26804 <column alignment="center" valignment="top" leftline="true" width="0">
26805 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26806 <column alignment="center" valignment="top" width="0">
26807 <column alignment="left" valignment="top" rightline="true" width="0">
26808 <row topline="true" bottomline="true">
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26812 \begin_layout Standard
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26821 \begin_layout Standard
26827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26830 \begin_layout Standard
26836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26839 \begin_layout Standard
26845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26848 \begin_layout Standard
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26857 \begin_layout Standard
26858 rest of the pointer
26863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26866 \begin_layout Standard
26873 <row topline="true" bottomline="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
26892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26895 \begin_layout Standard
26901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26904 \begin_layout Standard
26910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26913 \begin_layout Standard
26919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26922 \begin_layout Standard
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26935 \begin_layout Standard
26936 upper byte high nubble is 0x2n, the rest are zeroes
26949 \begin_layout Standard
26950 Currently implemented there are 3 types of streams defined:
26953 \begin_layout Standard
26955 \begin_inset Tabular
26956 <lyxtabular version="3" rows="4" columns="4">
26958 <column alignment="center" valignment="top" leftline="true" width="0">
26959 <column alignment="center" valignment="top" leftline="true" width="0">
26960 <column alignment="center" valignment="top" leftline="true" width="0">
26961 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26962 <row topline="true" bottomline="true">
26963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26966 \begin_layout Standard
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26975 \begin_layout Standard
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26984 \begin_layout Standard
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_layout Standard
27000 <row topline="true">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27004 \begin_layout Standard
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_layout Standard
27021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27024 \begin_layout Standard
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27033 \begin_layout Standard
27034 Writes/Reads characters via the USART peripheral
27040 <row topline="true">
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27044 \begin_layout Standard
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27053 \begin_layout Standard
27061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27064 \begin_layout Standard
27070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27073 \begin_layout Standard
27074 Writes/Reads characters via the MSSP peripheral
27080 <row topline="true" bottomline="true">
27081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27084 \begin_layout Standard
27090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27093 \begin_layout Standard
27101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27104 \begin_layout Standard
27110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27113 \begin_layout Standard
27114 Writes/Reads characters via used defined functions
27127 \begin_layout Standard
27128 The stream identifiers are declared as macros in the stdio.h header.
27131 \begin_layout Standard
27132 In the libc library there exist the functions that are used to write to
27133 each of the above streams.
27137 \begin_layout Description
27142 \begin_layout Standard
27151 _stream_usart_putchar writes a character at the USART stream
27154 \begin_layout Description
27159 \begin_layout Standard
27168 _stream_mssp_putchar writes a character at the MSSP stream
27171 \begin_layout Description
27172 putchar dummy function.
27173 This writes a character to a user specified manner.
27176 \begin_layout Standard
27177 In order to increase performance
27181 is declared in stdio.h as having its parameter in WREG (it has the wparam
27183 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27184 in a user-friendly way.
27189 is the name of the variable that holds the character to print.
27190 An example follows:
27193 \begin_layout LyX-Code
27194 #include <pic18fregs.h>
27203 \begin_layout LyX-Code
27207 \begin_layout LyX-Code
27208 PORTA = c; /* dump character c to PORTA */
27211 \begin_layout LyX-Code
27219 \begin_layout LyX-Code
27223 \begin_layout LyX-Code
27224 stdout = STREAM_USER; /* this is not necessary, since stdout points
27227 \begin_layout LyX-Code
27228 * by default to STREAM_USER */
27231 \begin_layout LyX-Code
27233 \begin_inset Quotes sld
27236 This is a printf test
27239 \begin_inset Quotes srd
27245 \begin_layout LyX-Code
27249 \begin_layout LyX-Code
27253 \begin_layout Subsubsection
27257 \begin_layout Standard
27258 PIC16 contains an implementation of the printf-family of functions.
27259 There exist the following functions:
27262 \begin_layout LyX-Code
27263 extern unsigned int sprintf(char *buf, char *fmt, ...);
27266 \begin_layout LyX-Code
27267 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27270 \begin_layout LyX-Code
27274 \begin_layout LyX-Code
27275 extern unsigned int printf(char *fmt, ...);
27278 \begin_layout LyX-Code
27279 extern unsigned int vprintf(char *fmt, va_lista ap);
27282 \begin_layout LyX-Code
27286 \begin_layout LyX-Code
27287 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27290 \begin_layout LyX-Code
27291 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27294 \begin_layout Standard
27295 For sprintf and vsprintf
27299 should normally be a data pointer where the resulting string will be placed.
27300 No range checking is done so the user should allocate the necessery buffer.
27301 For fprintf and vfprintf
27305 should be a stream pointer (i.e.
27306 stdout, STREAM_MSSP, etc...).
27309 \begin_layout Subsubsection
27313 \begin_layout Standard
27314 The PIC18F family of microcontrollers supports a number of interrupt sources.
27315 A list of these interrupts is shown in the following table:
27318 \begin_layout Standard
27320 \begin_inset Tabular
27321 <lyxtabular version="3" rows="11" columns="4">
27323 <column alignment="left" valignment="top" leftline="true" width="0">
27324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27325 <column alignment="left" valignment="top" leftline="true" width="0">
27326 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27327 <row topline="true" bottomline="true">
27328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27331 \begin_layout Standard
27337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27340 \begin_layout Standard
27346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27349 \begin_layout Standard
27355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27358 \begin_layout Standard
27365 <row topline="true">
27366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27369 \begin_layout Standard
27375 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27378 \begin_layout Standard
27379 PORTB change interrupt
27384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27387 \begin_layout Standard
27393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27396 \begin_layout Standard
27397 EEPROM/FLASH write complete interrupt
27403 <row topline="true">
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27407 \begin_layout Standard
27413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27416 \begin_layout Standard
27417 INT0 external interrupt
27422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27425 \begin_layout Standard
27431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27434 \begin_layout Standard
27435 Bus collision interrupt
27441 <row topline="true">
27442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27445 \begin_layout Standard
27451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27454 \begin_layout Standard
27455 INT1 external interrupt
27460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27463 \begin_layout Standard
27469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27472 \begin_layout Standard
27473 Low voltage detect interrupt
27479 <row topline="true">
27480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27483 \begin_layout Standard
27489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27492 \begin_layout Standard
27493 INT2 external interrupt
27498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27501 \begin_layout Standard
27507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27510 \begin_layout Standard
27511 Parallel slave port interrupt
27517 <row topline="true">
27518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27521 \begin_layout Standard
27527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27530 \begin_layout Standard
27531 CCP1 module interrupt
27536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27539 \begin_layout Standard
27545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27548 \begin_layout Standard
27549 AD convertion complete interrupt
27555 <row topline="true">
27556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27559 \begin_layout Standard
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27568 \begin_layout Standard
27569 CCP2 module interrupt
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27577 \begin_layout Standard
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27586 \begin_layout Standard
27587 USART receive interrupt
27593 <row topline="true">
27594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27597 \begin_layout Standard
27603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27606 \begin_layout Standard
27607 TMR0 overflow interrupt
27612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27615 \begin_layout Standard
27621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27624 \begin_layout Standard
27625 USART transmit interrupt
27631 <row topline="true">
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27635 \begin_layout Standard
27641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27644 \begin_layout Standard
27645 TMR1 overflow interrupt
27650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27653 \begin_layout Standard
27659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27662 \begin_layout Standard
27663 SSP receive/transmit interrupt
27669 <row topline="true">
27670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27673 \begin_layout Standard
27679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27682 \begin_layout Standard
27683 TMR2 matches PR2 interrupt
27688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27691 \begin_layout Standard
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27700 \begin_layout Standard
27707 <row topline="true" bottomline="true">
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27711 \begin_layout Standard
27717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27720 \begin_layout Standard
27721 TMR3 overflow interrupt
27726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27729 \begin_layout Standard
27735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27738 \begin_layout Standard
27752 \begin_layout Standard
27753 The prototypes for these names are defined in the header file
27760 \begin_layout Standard
27761 In order to simplify signal handling, a number of macros is provided:
27765 \labelwidthstring 00.00.0000
27766 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27767 high priority interrupts.
27772 is the function name to use.
27776 \labelwidthstring 00.00.0000
27777 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27778 low priority interrupt.
27783 is the function name to use.
27787 \labelwidthstring 00.00.0000
27788 DEF_HANDLER(sig,handler) define a handler for signal
27794 \labelwidthstring 00.00.0000
27795 END_DEF end the declaration of the dispatch table.
27798 \begin_layout Standard
27799 Additionally there are two more macros to simplify the declaration of the
27804 \labelwidthstring 00.00.0000
27807 SIGHANDLER(handler)
27809 this declares the function prototype for the
27817 \labelwidthstring 00.00.0000
27818 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27821 \begin_layout Standard
27822 An example of using the macros above is shown below:
27825 \begin_layout LyX-Code
27826 #include <pic18fregs.h>
27829 \begin_layout LyX-Code
27830 #include <signal.h>
27834 DEF_INTHIGH(high_int)
27837 \begin_layout LyX-Code
27838 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27841 \begin_layout LyX-Code
27842 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27845 \begin_layout LyX-Code
27850 SIGHANDLER(_tmr0_handler)
27853 \begin_layout LyX-Code
27857 \begin_layout LyX-Code
27858 /* action to be taken when timer 0 overflows */
27861 \begin_layout LyX-Code
27866 SIGHANDLERNAKED(_bcol_handler)
27869 \begin_layout LyX-Code
27873 \begin_layout LyX-Code
27877 \begin_layout LyX-Code
27878 /* action to be taken when bus collision occurs */
27881 \begin_layout LyX-Code
27885 \begin_layout LyX-Code
27889 \begin_layout LyX-Code
27893 \begin_layout Standard
27898 Special care should be taken when using the above scheme:
27901 \begin_layout Itemize
27902 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27905 \begin_layout Itemize
27906 when declaring SIGHANDLERNAKED handler never forget to use
27910 for proper returning.
27913 \begin_layout Subsection
27917 \begin_layout Standard
27918 Here you can find some general tips for compiling programs with SDCC/pic16.
27921 \begin_layout Subsubsection
27925 \begin_layout Standard
27927 \begin_inset LatexCommand \index{PIC16!stack}
27931 size (that is 64 bytes) probably is enough for many programs.
27932 One must take care that when there are many levels of function nesting,
27933 or there is excessive usage of stack, its size should be extended.
27934 An example of such a case is the printf/sprintf family of functions.
27935 If you encounter problems like not being able to print integers, then you
27936 need to set the stack size around the maximum (256 for small stack model).
27937 The following diagram shows what happens when calling printf to print an
27941 \begin_layout LyX-Code
27942 printf () --> ltoa () --> ultoa () --> divschar ()
27945 \begin_layout Standard
27946 It is should be understood that stack is easily consumed when calling complicate
27948 Using command line arguments like -
27952 \begin_layout Standard
27961 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27963 Other ways to reduce stack usage may exist.
27966 \begin_layout Subsection
27970 \begin_layout Standard
27971 The PIC16 Port currently does not pass SDCC's regression test
27972 \begin_inset LatexCommand \index{Regression test (PIC16)}
27977 \begin_inset LatexCommand \ref{sec:Quality-control}
27981 ) and thus the snapshot build regression tests for the PIC16 target are
27982 currently disabled for all hosts
27987 \begin_layout Chapter
27991 \begin_layout Standard
27992 There are several approaches to debugging your code.
27993 This chapter is meant to show your options and to give detail on some of
27998 When writing your code:
28001 \begin_layout Itemize
28002 write your code with debugging in mind (avoid duplicating code, put conceptually
28003 similar variables into structs, use structured code, have strategic points
28004 within your code where all variables are consistent, ...)
28007 \begin_layout Itemize
28008 run a syntax-checking tool like splint
28009 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28014 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28022 \begin_layout Standard
28032 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28039 \begin_layout Itemize
28040 for the high level code use a C-compiler (like f.e.
28041 GCC) to compile run and debug the code on your host.
28046 \begin_layout Standard
28056 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28060 ) on how to handle syntax extensions like __xdata, __at(), ...
28064 \begin_layout Itemize
28065 use another C-compiler to compile code for your target.
28066 Always an option but not recommended:) And not very likely to help you.
28067 If you seriously consider walking this path you should at least occasionally
28068 check portability of your code.
28069 Most commercial compiler vendors will offer an evaluation version so you
28070 can test compile your code or snippets of your code.
28073 \begin_layout Standard
28074 Debugging on a simulator:
28077 \begin_layout Itemize
28078 there is a separate section about SDCDB (section
28079 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28086 \begin_layout Itemize
28087 or (8051 specific) use a freeware/commercial simulator which interfaces
28089 \begin_inset LatexCommand \index{AOMF, AOMF51}
28094 \begin_inset LatexCommand \ref{OMF file}
28098 ) optionally generated by SDCC.
28101 \begin_layout Standard
28102 Debugging On-target:
28105 \begin_layout Itemize
28106 use a MCU port pin to serially output debug data to the RS232 port of your
28108 You'll probably want some level shifting device typically involving a MAX232
28110 If the hardware serial port of the MCU is not available search for 'Software
28111 UART' in your favourite search machine.
28114 \begin_layout Itemize
28115 use an on-target monitor.
28116 In this context a monitor is a small program which usually accepts commands
28117 via a serial line and allows to set program counter, to single step through
28118 a program and read/write memory locations.
28119 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28121 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28128 \begin_layout Itemize
28129 toggle MCU port pins at strategic points within your code and use an oscilloscop
28133 digital oscilloscope
28136 \begin_inset LatexCommand \index{Oscilloscope}
28140 with deep trace memory is really helpful especially if you have to debug
28141 a realtime application.
28142 If you need to monitor more pins than your oscilloscope provides you can
28143 sometimes get away with a small R-2R network.
28144 On a single channel oscilloscope you could f.e.
28145 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28147 \begin_inset Formula $\Omega$
28150 resistor and the other one by a 5\InsetSpace ~
28152 \begin_inset Formula $\Omega$
28155 resistor to the oscilloscope probe (check output drive capability of the
28156 pins you want to monitor).
28157 If you need to monitor many more pins a
28164 \begin_layout Itemize
28178 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28183 Usually very expensive.
28184 And very nice to have too.
28185 And usually locks you (for years...) to the devices the ICE can emulate.
28189 \begin_layout Itemize
28190 use a remote debugger.
28191 In most 8-bit systems the symbol information is not available on the target,
28192 and a complete debugger is too bulky for the target system.
28193 Therefore usually a debugger on the host system connects to an on-target
28194 debugging stub which accepts only primitive commands.
28197 Terms to enter into your favourite search engine could be 'remote debugging',
28198 'gdb stub' or 'inferior debugger'.
28202 \begin_layout Itemize
28203 use an on target hardware debugger.
28204 Some of the more modern MCUs include hardware support for setting break
28205 points and monitoring/changing variables by using dedicated hardware pins.
28206 This facility doesn't require additional code to run on the target and
28211 doesn't affect runtime behaviour until a breakpoint is hit.
28212 For the mcs51 most hardware debuggers use the AOMF
28213 \begin_inset LatexCommand \index{AOMF, AOMF51}
28218 \begin_inset LatexCommand \ref{OMF file}
28226 \begin_layout Standard
28230 \begin_layout Itemize
28231 if you are not familiar with any of the following terms you're likely to
28232 run into problems rather sooner than later:
28249 As an embedded programmer you
28253 to know them so why not look them up
28257 you have problems?)
28260 \begin_layout Itemize
28261 tell someone else about your problem (actually this is a surprisingly effective
28262 means to hunt down the bug even if the listener is not familiar with your
28264 As 'failure to communicate' is probably one of the job-induced deformations
28265 of an embedded programmer this is highly encouraged.
28268 \begin_layout Section
28269 Debugging with SDCDB
28270 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28275 \begin_inset LatexCommand \index{SDCDB (debugger)}
28282 \begin_layout Standard
28283 SDCC is distributed with a source level debugger
28284 \begin_inset LatexCommand \index{Debugger}
28289 The debugger uses a command line interface, the command repertoire of the
28290 debugger has been kept as close to gdb
28291 \begin_inset LatexCommand \index{gdb}
28295 (the GNU debugger) as possible.
28296 The configuration and build process is part of the standard compiler installati
28297 on, which also builds and installs the debugger in the target directory
28298 specified during configuration.
28299 The debugger allows you debug BOTH at the C source and at the ASM source
28303 \begin_layout Subsection
28304 Compiling for Debugging
28307 \begin_layout Standard
28312 \begin_layout Standard
28322 \begin_inset LatexCommand \index{-\/-debug}
28326 option must be specified for all files for which debug information is to
28328 The compiler generates a .adb file for each of these files.
28329 The linker creates the .cdb
28330 \begin_inset LatexCommand \index{<file>.cdb}
28335 \begin_inset LatexCommand \index{<file>.adb}
28339 files and the address information.
28340 This .cdb is used by the debugger.
28343 \begin_layout Subsection
28344 How the Debugger Works
28347 \begin_layout Standard
28352 \begin_layout Standard
28361 -debug option is specified the compiler generates extra symbol information
28362 some of which are put into the assembler source and some are put into the
28364 Then the linker creates the .cdb file from the individual .adb files with
28365 the address information for the symbols.
28366 The debugger reads the symbolic information generated by the compiler &
28367 the address information generated by the linker.
28368 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28369 execution is controlled by the debugger.
28370 When a command is issued for the debugger, it translates it into appropriate
28371 commands for the simulator.
28372 (Currently SDCDM only connects to the simulator but
28377 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28381 is an effort to connect directly to the hardware.)
28384 \begin_layout Subsection
28385 Starting the Debugger SDCDB
28388 \begin_layout Standard
28389 The debugger can be started using the following command line.
28390 (Assume the file you are debugging has the file name foo).
28404 The debugger will look for the following files.
28407 \begin_layout Itemize
28408 foo.c - the source file.
28411 \begin_layout Itemize
28412 foo.cdb - the debugger symbol information file.
28415 \begin_layout Itemize
28416 foo.ihx - the Intel hex format
28417 \begin_inset LatexCommand \index{Intel hex format}
28424 \begin_layout Subsection
28425 SDCDB Command Line Options
28428 \begin_layout Itemize
28433 \begin_layout Standard
28442 -directory=<source file directory> this option can used to specify the directory
28444 The debugger will look into the directory list specified for source, cdb
28446 The items in the directory list must be separated by ':', e.g.
28447 if the source files can be in the directories /home/src1 and /home/src2,
28452 \begin_layout Standard
28461 -directory option should be -
28465 \begin_layout Standard
28474 -directory=/home/src1:/home/src2.
28475 Note there can be no spaces in the option.
28479 \begin_layout Itemize
28480 -cd <directory> - change to the <directory>.
28483 \begin_layout Itemize
28484 -fullname - used by GUI front ends.
28487 \begin_layout Itemize
28488 -cpu <cpu-type> - this argument is passed to the simulator please see the
28489 simulator docs for details.
28492 \begin_layout Itemize
28493 -X <Clock frequency > this options is passed to the simulator please see
28494 the simulator docs for details.
28497 \begin_layout Itemize
28498 -s <serial port file> passed to simulator see the simulator docs for details.
28501 \begin_layout Itemize
28502 -S <serial in,out> passed to simulator see the simulator docs for details.
28505 \begin_layout Itemize
28506 -k <port number> passed to simulator see the simulator docs for details.
28509 \begin_layout Subsection
28510 SDCDB Debugger Commands
28513 \begin_layout Standard
28514 As mentioned earlier the command interface for the debugger has been deliberatel
28515 y kept as close the GNU debugger gdb, as possible.
28516 This will help the integration with existing graphical user interfaces
28517 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28518 If you use a graphical user interface for the debugger you can skip this
28522 \begin_layout Subsubsection*
28523 break [line | file:line | function | file:function]
28526 \begin_layout Standard
28527 Set breakpoint at specified line or function:
28536 sdcdb>break foo.c:100
28538 sdcdb>break funcfoo
28540 sdcdb>break foo.c:funcfoo
28543 \begin_layout Subsubsection*
28544 clear [line | file:line | function | file:function ]
28547 \begin_layout Standard
28548 Clear breakpoint at specified line or function:
28557 sdcdb>clear foo.c:100
28559 sdcdb>clear funcfoo
28561 sdcdb>clear foo.c:funcfoo
28564 \begin_layout Subsubsection*
28568 \begin_layout Standard
28569 Continue program being debugged, after breakpoint.
28572 \begin_layout Subsubsection*
28576 \begin_layout Standard
28577 Execute till the end of the current function.
28580 \begin_layout Subsubsection*
28584 \begin_layout Standard
28585 Delete breakpoint number 'n'.
28586 If used without any option clear ALL user defined break points.
28589 \begin_layout Subsubsection*
28590 info [break | stack | frame | registers ]
28593 \begin_layout Itemize
28594 info break - list all breakpoints
28597 \begin_layout Itemize
28598 info stack - show the function call stack.
28601 \begin_layout Itemize
28602 info frame - show information about the current execution frame.
28605 \begin_layout Itemize
28606 info registers - show content of all registers.
28609 \begin_layout Subsubsection*
28613 \begin_layout Standard
28614 Step program until it reaches a different source line.
28615 Note: pressing <return> repeats the last command.
28618 \begin_layout Subsubsection*
28622 \begin_layout Standard
28623 Step program, proceeding through subroutine calls.
28626 \begin_layout Subsubsection*
28630 \begin_layout Standard
28631 Start debugged program.
28634 \begin_layout Subsubsection*
28638 \begin_layout Standard
28639 Print type information of the variable.
28642 \begin_layout Subsubsection*
28646 \begin_layout Standard
28647 print value of variable.
28650 \begin_layout Subsubsection*
28654 \begin_layout Standard
28655 load the given file name.
28656 Note this is an alternate method of loading file for debugging.
28659 \begin_layout Subsubsection*
28663 \begin_layout Standard
28664 print information about current frame.
28667 \begin_layout Subsubsection*
28671 \begin_layout Standard
28672 Toggle between C source & assembly source.
28675 \begin_layout Subsubsection*
28676 ! simulator command
28679 \begin_layout Standard
28680 Send the string following '!' to the simulator, the simulator response is
28682 Note the debugger does not interpret the command being sent to the simulator,
28683 so if a command like 'go' is sent the debugger can loose its execution
28684 context and may display incorrect values.
28687 \begin_layout Subsubsection*
28691 \begin_layout Standard
28694 My name is Bobby Brown"
28697 \begin_layout Subsection
28698 Interfacing SDCDB with DDD
28701 \begin_layout Standard
28702 \begin_inset Note Note
28705 \begin_layout Standard
28706 The screenshot was converted from png to eps with:
28707 \begin_inset Quotes sld
28710 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28711 \begin_inset Quotes srd
28714 which produces a pretty compact eps file which is free from compression
28718 \begin_layout Standard
28719 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28720 as this broke the build system on Sourceforge (pdf-file was broken.
28721 pdflatex does not accept eps files).
28729 \begin_layout Standard
28745 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28751 shows a screenshot of a debugging session with DDD
28752 \begin_inset LatexCommand \index{DDD (debugger)}
28756 (Unix only) on a simulated 8032.
28757 The debugging session might not run as smoothly as the screenshot suggests.
28758 The debugger allows setting of breakpoints, displaying and changing variables,
28759 single stepping through C and assembler code.
28762 The source was compiled with
28776 \begin_layout Standard
28788 -debug ddd_example.c
28801 and DDD was invoked with
28808 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28811 \begin_layout Standard
28812 \begin_inset Note Note
28815 \begin_layout Standard
28816 Check that the double quotes or an apostroph within the command line survive
28817 the LyX tool chain.
28818 Previously the apostrophs got slanted in the PDF output so a cut and paste
28827 \begin_layout Subsection
28828 Interfacing SDCDB with XEmacs
28829 \begin_inset LatexCommand \index{XEmacs}
28834 \begin_inset LatexCommand \index{Emacs}
28841 \begin_layout Standard
28842 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28843 sdcdb.el and sdcdbsrc.el.
28844 These two files can be found in the $(prefix)/bin directory after the installat
28846 These files need to be loaded into XEmacs for the interface to work.
28847 This can be done at XEmacs startup time by inserting the following into
28848 your '.xemacs' file (which can be found in your HOME directory):
28854 (load-file sdcdbsrc.el)
28860 .xemacs is a lisp file so the () around the command is REQUIRED.
28861 The files can also be loaded dynamically while XEmacs is running, set the
28862 environment variable 'EMACSLOADPATH' to the installation bin directory
28863 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28864 To start the interface enter the following command:
28878 You will prompted to enter the file name to be debugged.
28883 The command line options that are passed to the simulator directly are
28884 bound to default values in the file sdcdbsrc.el.
28885 The variables are listed below, these values maybe changed as required.
28888 \begin_layout Itemize
28889 sdcdbsrc-cpu-type '51
28892 \begin_layout Itemize
28893 sdcdbsrc-frequency '11059200
28896 \begin_layout Itemize
28897 sdcdbsrc-serial nil
28900 \begin_layout Standard
28901 The following is a list of key mapping for the debugger interface.
28904 \begin_layout Standard
28927 binding\InsetSpace ~
28965 -------\InsetSpace ~
29036 sdcdb-back-from-src\InsetSpace ~
29065 rom-src\InsetSpace ~
29075 SDCDB continue command
29093 sdcdb-step-from-src\InsetSpace ~
29122 hatis-c-sexp\InsetSpace ~
29132 SDCDB ptypecommand for data at
29199 sdcdbsrc-delete\InsetSpace ~
29214 B Delete all breakpoints if no arg
29263 given or delete arg (C-u arg x)
29282 -frame\InsetSpace ~
29297 SDCDB Display current frame if no arg,
29346 given or display frame arg
29414 sdcdbsrc-goto-sdcdb\InsetSpace ~
29424 Goto the SDCDB output buffer
29443 t-c-sexp\InsetSpace ~
29454 SDCDB print command for data at
29521 sdcdbsrc-goto-sdcdb\InsetSpace ~
29532 o the SDCDB output buffer
29550 sdcdbsrc-mode\InsetSpace ~
29566 Toggles Sdcdbsrc mode (turns it
29582 sdcdb-finish-from-src\InsetSpace ~
29590 SDCDB finish command
29624 Set break for line with point
29639 sdcdbsrc-mode\InsetSpace ~
29655 Toggle Sdcdbsrc mode
29671 dbsrc-srcmode\InsetSpace ~
29695 \begin_layout Chapter
29699 \begin_layout Standard
29700 Here are a few guidelines that will help the compiler generate more efficient
29701 code, some of the tips are specific to this compiler others are generally
29702 good programming practice.
29705 \begin_layout Itemize
29706 Use the smallest data type to represent your data-value.
29707 If it is known in advance that the value is going to be less than 256 then
29708 use an 'unsigned char' instead of a 'short' or 'int'.
29709 Please note, that ANSI C requires both signed and unsigned chars to be
29710 promoted to 'signed int'
29711 \begin_inset LatexCommand \index{promotion to signed int}
29716 \begin_inset Marginal
29719 \begin_layout Standard
29728 before doing any operation.
29730 \begin_inset LatexCommand \index{type promotion}
29735 \begin_inset LatexCommand \label{type promotion}
29739 can be omitted, if the result is the same.
29740 The effect of the promotion rules together with the sign-extension is often
29745 \begin_layout Verse
29748 unsigned char uc = 0xfe;
29750 if (uc * uc < 0) /* this is true! */
29763 \begin_layout Standard
29770 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29778 \begin_layout Verse
29781 (unsigned char) -12 / (signed char) -3 = ...
29784 \begin_layout Standard
29785 No, the result is not 4:
29788 \begin_layout Verse
29791 (int) (unsigned char) -12 / (int) (signed char) -3 =
29793 (int) (unsigned char)
29794 0xf4 / (int) (signed char) 0xfd =
29796 (int) 0x00f4 / (int) 0xfffd =
29801 (int) 244 / (int) -3 =
29803 (int) -81 = (int) 0xffaf;
29806 \begin_layout Standard
29807 Don't complain, that gcc gives you a different result.
29808 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29809 Therefore the results are different.
29812 \begin_inset Quotes sld
29816 \begin_inset Quotes srd
29822 \begin_layout Quote
29825 If well-defined overflow characteristics are important and negative values
29826 are not, or if you want to steer clear of sign-extension problems when
29827 manipulating bits or bytes, use one of the corresponding unsigned types.
29828 (Beware when mixing signed and unsigned values in expressions, though.)
29831 character types (especially unsigned char) can be used as "tiny" integers,
29832 doing so is sometimes more trouble than it's worth, due to unpredictable
29833 sign extension and increased code size.
29837 \begin_layout Itemize
29838 Use unsigned when it is known in advance that the value is not going to
29840 This helps especially if you are doing division or multiplication, bit-shifting
29841 or are using an array index.
29844 \begin_layout Itemize
29845 NEVER jump into a LOOP.
29848 \begin_layout Itemize
29849 Declare the variables to be local
29850 \begin_inset LatexCommand \index{local variables}
29854 whenever possible, especially loop control variables (induction).
29857 \begin_layout Itemize
29858 Have a look at the assembly listing to get a
29859 \begin_inset Quotes sld
29863 \begin_inset Quotes srd
29866 for the code generation.
29869 \begin_layout Section
29870 Porting code from or to other compilers
29871 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29878 \begin_layout Itemize
29879 check whether endianness of the compilers differs and adapt where needed.
29882 \begin_layout Itemize
29883 check the device specific header files
29884 \begin_inset LatexCommand \index{Header files}
29889 \begin_inset LatexCommand \index{Include files}
29893 for compiler specific syntax.
29894 Eventually include the file <compiler.h
29895 \begin_inset LatexCommand \index{compiler.h (include file)}
29900 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29904 to allow using common header files.
29907 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29914 \begin_layout Itemize
29915 check whether the startup code contains the correct initialization (watchdog,
29919 \begin_layout Itemize
29920 check whether the sizes of short, int, long match.
29923 \begin_layout Itemize
29924 check if some 16 or 32 bit hardware registers require a specific addressing
29925 order (least significant or most significant byte first) and adapt if needed
29934 relate to time and not to lower/upper memory location here, so this is
29939 the same as endianness).
29942 \begin_layout Itemize
29943 check whether the keyword
29947 is used where needed.
29948 The compilers might differ in their optimization characteristics (as different
29949 versions of the same compiler might also use more clever optimizations
29950 this is good idea anyway).
29952 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29959 \begin_layout Itemize
29960 check that the compilers are not told to supress warnings.
29963 \begin_layout Itemize
29964 check and convert compiler specific extensions (interrupts, memory areas,
29968 \begin_layout Itemize
29969 check for differences in type promotion.
29970 Especially check for math operations on
29979 For the sake of C99 compatibility SDCC will probably promote these to
29983 more often than other compilers.
29984 Eventually insert explicit casts to
29993 Also check that the ~\InsetSpace ~
29995 \begin_inset LatexCommand \index{\~\/ Operator}
30002 \begin_inset LatexCommand \index{bit}
30008 variables, use the !\InsetSpace ~
30011 \begin_inset LatexCommand \ref{type promotion}
30016 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30023 \begin_layout Itemize
30024 check the assembly code generated for interrupt routines (f.e.
30025 for calls to possibly non-reentrant library functions).
30028 \begin_layout Itemize
30029 check whether timing loops result in proper timing (or preferably consider
30030 a rewrite of the code with timer based delays instead).
30033 \begin_layout Itemize
30034 check for differences in printf parameters (some compilers push (va_arg
30035 \begin_inset LatexCommand \index{vararg, va\_arg}
30039 ) char variables as
30043 others push them as
30049 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30056 \begin_layout Itemize
30057 check the resulting memory map
30058 \begin_inset LatexCommand \index{Memory map}
30063 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30064 ly idata, pdata, xdata).
30065 Eventually check if unexpected library functions are included.
30068 \begin_layout Section
30070 \begin_inset LatexCommand \index{Tools}
30074 included in the distribution
30077 \begin_layout Standard
30079 \begin_inset Tabular
30080 <lyxtabular version="3" rows="12" columns="3">
30082 <column alignment="left" valignment="top" leftline="true" width="0pt">
30083 <column alignment="left" valignment="top" leftline="true" width="0pt">
30084 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30085 <row topline="true" bottomline="true">
30086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30089 \begin_layout Standard
30097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30100 \begin_layout Standard
30108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30111 \begin_layout Standard
30120 <row topline="true">
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30124 \begin_layout Standard
30126 \begin_inset LatexCommand \index{uCsim}
30135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30138 \begin_layout Standard
30139 Simulator for various architectures
30144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30147 \begin_layout Standard
30154 <row topline="true">
30155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30158 \begin_layout Standard
30164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30167 \begin_layout Standard
30169 \begin_inset LatexCommand \index{Header files}
30174 \begin_inset LatexCommand \index{Include files}
30183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30186 \begin_layout Standard
30187 sdcc/support/scripts
30193 <row topline="true">
30194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30197 \begin_layout Standard
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30206 \begin_layout Standard
30207 header file conversion
30212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30215 \begin_layout Standard
30216 sdcc/support/scripts
30222 <row topline="true">
30223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30226 \begin_layout Standard
30232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30235 \begin_layout Standard
30241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30244 \begin_layout Standard
30260 <row topline="true">
30261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30264 \begin_layout Standard
30270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30273 \begin_layout Standard
30279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30282 \begin_layout Standard
30298 <row topline="true">
30299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30302 \begin_layout Standard
30308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30311 \begin_layout Standard
30317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30320 \begin_layout Standard
30336 <row topline="true">
30337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30340 \begin_layout Standard
30346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30349 \begin_layout Standard
30355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30358 \begin_layout Standard
30374 <row topline="true">
30375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30378 \begin_layout Standard
30384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30387 \begin_layout Standard
30393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30396 \begin_layout Standard
30412 <row topline="true">
30413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30416 \begin_layout Standard
30422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30425 \begin_layout Standard
30431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30434 \begin_layout Standard
30450 <row topline="true">
30451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30454 \begin_layout Standard
30460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30463 \begin_layout Standard
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30472 \begin_layout Standard
30488 <row topline="true" bottomline="true">
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30492 \begin_layout Standard
30498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30501 \begin_layout Standard
30503 \begin_inset LatexCommand \index{packihx (tool)}
30512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30515 \begin_layout Standard
30540 \begin_layout Section
30542 \begin_inset LatexCommand \index{Documentation}
30546 included in the distribution
30549 \begin_layout Standard
30551 \begin_inset Tabular
30552 <lyxtabular version="3" rows="10" columns="2">
30554 <column alignment="block" valignment="top" leftline="true" width="40col%">
30555 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30556 <row topline="true" bottomline="true" endhead="true">
30557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30560 \begin_layout Standard
30568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30571 \begin_layout Standard
30574 Filename / Where to get
30580 <row topline="true">
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30584 \begin_layout Standard
30585 SDCC Compiler User Guide
30590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30593 \begin_layout Standard
30594 You're reading it right now
30606 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30616 <row topline="true">
30617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30620 \begin_layout Standard
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30629 \begin_layout Standard
30642 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30652 <row topline="true">
30653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30656 \begin_layout Standard
30658 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30663 \begin_inset LatexCommand \index{Assembler documentation}
30670 \begin_inset LatexCommand \index{aslink}
30675 \begin_inset LatexCommand \index{Linker documentation}
30684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30687 \begin_layout Standard
30688 sdcc/as/doc/asxhtm.html
30700 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30710 <row topline="true">
30711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30714 \begin_layout Standard
30715 SDCC regression test
30716 \begin_inset LatexCommand \index{Regression test}
30725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30728 \begin_layout Standard
30729 sdcc/doc/test_suite_spec.pdf
30741 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30751 <row topline="true">
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30755 \begin_layout Standard
30761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30764 \begin_layout Standard
30777 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30787 <row topline="true">
30788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30791 \begin_layout Standard
30792 Notes on debugging with SDCDB
30793 \begin_inset LatexCommand \index{SDCDB (debugger)}
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30805 \begin_layout Standard
30806 sdcc/debugger/README
30818 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30828 <row topline="true">
30829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30832 \begin_layout Standard
30834 \begin_inset LatexCommand \index{uCsim}
30838 Software simulator for microcontrollers
30843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30846 \begin_layout Standard
30876 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30886 <row topline="true">
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30890 \begin_layout Standard
30891 Temporary notes on the pic16
30892 \begin_inset LatexCommand \index{PIC16}
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30904 \begin_layout Standard
30905 sdcc/src/pic16/NOTES
30917 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30927 <row topline="true" bottomline="true">
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30931 \begin_layout Standard
30932 SDCC internal documentation (debugging file format)
30937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30940 \begin_layout Standard
30970 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30989 \begin_layout Section
30990 Related open source tools
30991 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30996 \begin_inset LatexCommand \index{Related tools}
31003 \begin_layout Standard
31005 \begin_inset Tabular
31006 <lyxtabular version="3" rows="14" columns="3">
31008 <column alignment="left" valignment="top" leftline="true" width="0pt">
31009 <column alignment="block" valignment="top" leftline="true" width="30line%">
31010 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31011 <row topline="true" bottomline="true">
31012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31015 \begin_layout Standard
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31026 \begin_layout Standard
31034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31037 \begin_layout Standard
31046 <row topline="true">
31047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31050 \begin_layout Standard
31052 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31064 \begin_layout Standard
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31073 \begin_layout Standard
31074 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31084 <row topline="true">
31085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31088 \begin_layout Standard
31090 \begin_inset LatexCommand \index{gputils (pic tools)}
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31102 \begin_layout Standard
31108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31111 \begin_layout Standard
31112 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31122 <row topline="true">
31123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31126 \begin_layout Standard
31132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31135 \begin_layout Standard
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31144 \begin_layout Standard
31145 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31155 <row topline="true">
31156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31159 \begin_layout Standard
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31168 \begin_layout Standard
31169 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31178 \begin_layout Standard
31179 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31189 <row topline="true">
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31193 \begin_layout Standard
31195 \begin_inset LatexCommand \index{indent (source formatting tool)}
31204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31207 \begin_layout Standard
31208 Formats C source - Master of the white spaces
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31216 \begin_layout Standard
31217 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31227 <row topline="true">
31228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31231 \begin_layout Standard
31233 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31245 \begin_layout Standard
31246 Object file conversion, checksumming, ...
31251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31254 \begin_layout Standard
31255 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31265 <row topline="true">
31266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31269 \begin_layout Standard
31271 \begin_inset LatexCommand \index{objdump (tool)}
31280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31283 \begin_layout Standard
31284 Object file conversion, ...
31289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31292 \begin_layout Standard
31293 Part of binutils (should be there anyway)
31299 <row topline="true">
31300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31303 \begin_layout Standard
31309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31312 \begin_layout Standard
31313 8051 monitor (hex up-/download, single step, disassemble)
31318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31321 \begin_layout Standard
31322 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31332 <row topline="true">
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31336 \begin_layout Standard
31338 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31350 \begin_layout Standard
31351 Source code documentation system
31356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31359 \begin_layout Standard
31360 \begin_inset LatexCommand \url{http://www.doxygen.org}
31370 <row topline="true">
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31374 \begin_layout Standard
31380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31383 \begin_layout Standard
31384 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31392 \begin_layout Standard
31393 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31403 <row topline="true">
31404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31407 \begin_layout Standard
31413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31416 \begin_layout Standard
31417 8051 monitor (hex up-/download, single step, disassemble)
31422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31425 \begin_layout Standard
31426 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31436 <row topline="true">
31437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31440 \begin_layout Standard
31442 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31454 \begin_layout Standard
31455 Statically checks c sources (see
31456 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31468 \begin_layout Standard
31469 \begin_inset LatexCommand \url{http://www.splint.org}
31479 <row topline="true" bottomline="true">
31480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31483 \begin_layout Standard
31485 \begin_inset LatexCommand \index{DDD (debugger)}
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31497 \begin_layout Standard
31498 Debugger, serves nicely as GUI to SDCDB
31499 \begin_inset LatexCommand \index{SDCDB (debugger)}
31508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31511 \begin_layout Standard
31512 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31531 \begin_layout Section
31532 Related documentation / recommended reading
31535 \begin_layout Standard
31537 \begin_inset Tabular
31538 <lyxtabular version="3" rows="7" columns="3">
31540 <column alignment="left" valignment="top" leftline="true" width="0pt">
31541 <column alignment="left" valignment="top" leftline="true" width="0">
31542 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31543 <row topline="true" bottomline="true">
31544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31547 \begin_layout Standard
31555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31558 \begin_layout Standard
31566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31569 \begin_layout Standard
31578 <row topline="true">
31579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31582 \begin_layout Standard
31597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31600 \begin_layout Standard
31602 \begin_inset LatexCommand \index{C Reference card}
31611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31614 \begin_layout Standard
31615 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31625 <row topline="true">
31626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31629 \begin_layout Standard
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31638 \begin_layout Standard
31640 \begin_inset LatexCommand \index{C FAQ}
31649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31652 \begin_layout Standard
31653 \begin_inset LatexCommand \url{http://www.c-faq.com}
31663 <row topline="true">
31664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31667 \begin_layout Standard
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31676 \begin_layout Standard
31677 \begin_inset Quotes sld
31681 \begin_inset Quotes srd
31689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31692 \begin_layout Standard
31695 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31705 <row topline="true">
31706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31709 \begin_layout Standard
31715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31718 \begin_layout Standard
31719 \begin_inset Quotes sld
31722 Extensions for Embedded C
31723 \begin_inset Quotes srd
31731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31734 \begin_layout Standard
31737 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31747 <row topline="true">
31748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31751 \begin_layout Standard
31757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31760 \begin_layout Standard
31761 Latest datasheet of target CPU
31766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31769 \begin_layout Standard
31776 <row topline="true" bottomline="true">
31777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31780 \begin_layout Standard
31786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31789 \begin_layout Standard
31790 Revision history of datasheet
31795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31798 \begin_layout Standard
31814 \begin_layout Section
31815 Application notes specifically for SDCC
31818 \begin_layout Standard
31819 SDCC makes no claims about the completeness of this list and about up-to-datenes
31820 s or correctness of the application notes
31821 \begin_inset LatexCommand \index{Application notes}
31828 \begin_layout Standard
31832 \begin_inset Tabular
31833 <lyxtabular version="3" rows="7" columns="3">
31835 <column alignment="block" valignment="top" leftline="true" width="17col%">
31836 <column alignment="block" valignment="top" leftline="true" width="27col%">
31837 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31838 <row topline="true" bottomline="true">
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31842 \begin_layout Standard
31851 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31854 \begin_layout Standard
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31866 \begin_layout Standard
31876 <row topline="true">
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31880 \begin_layout Standard
31888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31891 \begin_layout Standard
31894 Using the SDCC Compiler for the DS80C400
31895 \begin_inset LatexCommand \index{DS80C400}
31904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31907 \begin_layout Standard
31910 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31920 <row topline="true">
31921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31924 \begin_layout Standard
31932 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31935 \begin_layout Standard
31938 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31939 \begin_inset LatexCommand \index{DS89C4x0}
31943 Family of Microcontrollers
31948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31951 \begin_layout Standard
31954 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31964 <row topline="true">
31965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31968 \begin_layout Standard
31971 Silicon Laboratories / Cygnal
31976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31979 \begin_layout Standard
31982 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31983 \begin_inset LatexCommand \index{IDE}
31992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31995 \begin_layout Standard
31998 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32008 <row topline="true">
32009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32012 \begin_layout Standard
32015 Ramtron / Goal Semiconductor
32020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32023 \begin_layout Standard
32026 Interfacing SDCC to Syn and Textpad
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32034 \begin_layout Standard
32037 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32047 <row topline="true">
32048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32051 \begin_layout Standard
32054 Ramtron / Goal Semiconductor
32059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32062 \begin_layout Standard
32065 Installing and Configuring SDCC and Crimson Editor
32070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32073 \begin_layout Standard
32076 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32086 <row topline="true" bottomline="true">
32087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32090 \begin_layout Standard
32098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32101 \begin_layout Standard
32104 MSC12xx Programming with SDCC
32109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32112 \begin_layout Standard
32115 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32132 \begin_layout Section
32136 \begin_layout Standard
32137 Some questions answered, some pointers given - it might be time to in turn
32145 \begin_layout Itemize
32146 can you solve your project with the selected microcontroller? Would you
32147 find out early or rather late that your target is too small/slow/whatever?
32148 Can you switch to a slightly better device if it doesn't fit?
32151 \begin_layout Itemize
32152 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32153 and/or another programming language be more adequate? Would an operating
32154 system on the target device help?
32157 \begin_layout Itemize
32158 if you solved the problem, will the marketing department be happy?
32161 \begin_layout Itemize
32162 if the marketing department is happy, will customers be happy?
32165 \begin_layout Itemize
32166 if you're the project manager, marketing department and maybe even the customer
32167 in one person, have you tried to see the project from the outside?
32170 \begin_layout Itemize
32171 is the project done if you think it is done? Or is just that other interface/pro
32172 tocol/feature/configuration/option missing? How about website, manual(s),
32173 internationali(z|s)ation, packaging, labels, 2nd source for components,
32174 electromagnetic compatability/interference, documentation for production,
32175 production test software, update mechanism, patent issues?
32178 \begin_layout Itemize
32179 is your project adequately positioned in that magic triangle: fame, fortune,
32183 \begin_layout Standard
32184 Maybe not all answers to these questions are known and some answers may
32189 , nevertheless knowing these questions may help you to avoid burnout
32193 \begin_layout Standard
32194 burnout is bad for electronic devices, programmers and motorcycle tyres
32200 Chances are you didn't want to hear some of them...
32203 \begin_layout Chapter
32205 \begin_inset LatexCommand \index{Support}
32212 \begin_layout Standard
32213 SDCC has grown to be a large project.
32214 The compiler alone (without the preprocessor, assembler and linker) is
32215 well over 150,000 lines of code (blank stripped).
32216 The open source nature of this project is a key to its continued growth
32218 You gain the benefit and support of many active software developers and
32220 Is SDCC perfect? No, that's why we need your help.
32221 The developers take pride in fixing reported bugs.
32222 You can help by reporting the bugs and helping other SDCC users.
32223 There are lots of ways to contribute, and we encourage you to take part
32224 in making SDCC a great software package.
32228 \begin_layout Standard
32229 The SDCC project is hosted on the SDCC sourceforge site at
32230 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32235 You'll find the complete set of mailing lists
32236 \begin_inset LatexCommand \index{Mailing list(s)}
32240 , forums, bug reporting system, patch submission
32241 \begin_inset LatexCommand \index{Patch submission}
32246 \begin_inset LatexCommand \index{download}
32250 area and Subversion code repository
32251 \begin_inset LatexCommand \index{Subversion code repository}
32258 \begin_layout Section
32260 \begin_inset LatexCommand \index{Bug reporting}
32265 \begin_inset LatexCommand \index{Reporting bugs}
32272 \begin_layout Standard
32273 The recommended way of reporting bugs is using the infrastructure of the
32275 You can follow the status of bug reports there and have an overview about
32279 \begin_layout Standard
32280 Bug reports are automatically forwarded to the developer mailing list and
32281 will be fixed ASAP.
32282 When reporting a bug, it is very useful to include a small test program
32283 (the smaller the better) which reproduces the problem.
32284 If you can isolate the problem by looking at the generated assembly code,
32285 this can be very helpful.
32286 Compiling your program with the -
32290 \begin_layout Standard
32300 \begin_inset LatexCommand \index{-\/-dumpall}
32304 option can sometimes be useful in locating optimization problems.
32305 When reporting a bug please make sure you:
32308 \begin_layout Enumerate
32309 Attach the code you are compiling with SDCC.
32313 \begin_layout Enumerate
32314 Specify the exact command you use to run SDCC, or attach your Makefile.
32318 \begin_layout Enumerate
32319 Specify the SDCC version (type "
32325 "), your platform, and operating system.
32329 \begin_layout Enumerate
32330 Provide an exact copy of any error message or incorrect output.
32334 \begin_layout Enumerate
32335 Put something meaningful in the subject of your message.
32338 \begin_layout Standard
32339 Please attempt to include these 5 important parts, as applicable, in all
32340 requests for support or when reporting any problems or bugs with SDCC.
32341 Though this will make your message lengthy, it will greatly improve your
32342 chance that SDCC users and developers will be able to help you.
32343 Some SDCC developers are frustrated by bug reports without code provided
32344 that they can use to reproduce and ultimately fix the problem, so please
32345 be sure to provide sample code if you are reporting a bug!
32348 \begin_layout Standard
32349 Please have a short check that you are using a recent version of SDCC and
32350 the bug is not yet known.
32351 This is the link for reporting bugs:
32352 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32357 With SDCC on average having more than 200 downloads
32358 \begin_inset LatexCommand \index{download}
32362 on sourceforge per day
32366 \begin_layout Standard
32367 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32368 between 2002 and 2005.
32369 This does not include other methods of distribution.
32374 there must be some users.
32375 So it's not exactly easy to find a new bug.
32376 If you find one we need it:
32378 reporting bugs is good
32383 \begin_layout Section
32384 Requesting Features
32385 \begin_inset LatexCommand \label{sub:Requesting-Features}
32390 \begin_inset LatexCommand \index{Feature request}
32395 \begin_inset LatexCommand \index{Requesting features}
32402 \begin_layout Standard
32403 Like bug reports feature requests are forwarded to the developer mailing
32405 This is the link for requesting features:
32406 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32413 \begin_layout Section
32417 \begin_layout Standard
32418 Like bug reports contributed patches are forwarded to the developer mailing
32420 This is the link for submitting patches
32421 \begin_inset LatexCommand \index{Patch submission}
32426 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32433 \begin_layout Standard
32434 You need to specify some parameters to the
32438 command for the patches to be useful.
32439 If you modified more than one file a patch created f.e.
32444 \begin_inset Quotes sld
32447 diff -Naur unmodified_directory modified_directory >my_changes.patch
32448 \begin_inset Quotes srd
32454 will be fine, otherwise
32458 \begin_inset Quotes sld
32461 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32462 \begin_inset Quotes srd
32472 \begin_layout Section
32476 \begin_layout Standard
32477 These links should take you directly to the
32478 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32486 \begin_layout Standard
32487 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32488 automated messages (mid 2003)
32494 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32499 \begin_inset LatexCommand \index{Mailing list(s)}
32503 and forums are archived and searchable so if you are lucky someone already
32504 had a similar problem.
32505 While mails to the lists themselves are delivered promptly their web front
32506 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32507 if you're seriously using SDCC please consider subscribing to the lists.
32510 \begin_layout Section
32514 \begin_layout Standard
32515 You can follow the status of the Subversion version
32516 \begin_inset LatexCommand \index{version}
32520 of SDCC by watching the Changelog
32521 \begin_inset LatexCommand \index{Changelog}
32525 in the Subversion repository
32528 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32535 \begin_layout Section
32536 Subversion Source Code Repository
32539 \begin_layout Standard
32549 \begin_layout Standard
32563 or the filenames of the snapshot versions of SDCC include date and its
32565 \begin_inset LatexCommand \index{Subversion code repository}
32570 Subversion allows to download the source of recent or previous versions
32572 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32576 (by number or by date).
32577 An on-line source code browser and detailled instructions are also available
32579 SDCC versions starting from 1999 up to now are available (currently the
32580 versions prior to the conversion from cvs
32581 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32585 to Subversion (April 2006) are either by accessible by Subversion or by
32589 \begin_layout Section
32591 \begin_inset LatexCommand \index{Release policy}
32598 \begin_layout Standard
32599 Historically there often were long delays between official releases and
32600 the sourceforge download area tends to get not updated at all.
32601 Excuses in the past might have referred to problems with live range analysis,
32602 but as this was fixed a while ago, the current problem is that another
32603 excuse has to be found.
32604 Kidding aside, we have to get better there! On the other hand there are
32605 daily snapshots available at
32606 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32610 , and you can always build the very last version (hopefully with many bugs
32611 fixed, and features added) from the source code available at
32612 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32618 \begin_inset LatexCommand \index{wiki}
32623 \begin_inset LatexCommand \index{SDCC Wiki}
32628 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32632 also holds some information about past and future releases.
32635 \begin_layout Section
32637 \begin_inset LatexCommand \index{Examples}
32644 \begin_layout Standard
32645 You'll find some small examples in the directory
32647 sdcc/device/examples/.
32650 More examples and libraries are available at
32652 The SDCC Open Knowledge Resource
32653 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32660 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32667 \begin_layout Standard
32668 \begin_inset Note Note
32671 \begin_layout Standard
32672 I did insert a reference to Paul's web site here although it seems rather
32673 dedicated to a specific 8032 board (I think it's okay because it f.e.
32674 shows LCD/Harddisc interface and has a free 8051 monitor.
32675 Independent 8032 board vendors face hard competition of heavily subsidized
32676 development boards anyway).
32679 \begin_layout Standard
32680 Maybe we should include some links to real world applications.
32681 Preferably pointer to pointers (one for each architecture) so this stays
32690 \begin_layout Section
32692 \begin_inset LatexCommand \label{sec:Quality-control}
32697 \begin_inset LatexCommand \index{Quality control}
32704 \begin_layout Standard
32705 The compiler is passed through snaphot build compile and build checks.
32711 \begin_inset LatexCommand \index{Regression test}
32715 check that SDCC itself compiles flawlessly on several host platforms (i386,
32716 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32717 the quality of the code generated by SDCC by running the code for several
32718 target platforms through simulators.
32719 The regression test suite comprises more than 100 files which expand to
32720 more than 500 test cases which include more than 4500 tests.
32721 The results of these tests are published daily on SDCC's snapshot page
32722 (click on the red or green symbols on the right side of
32723 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32730 \begin_layout Standard
32731 There is a separate document
32734 \begin_inset LatexCommand \index{Test suite}
32741 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32745 about the regression test suite.
32748 \begin_layout Standard
32749 You'll find the test code in the directory
32751 sdcc/support/regression
32754 You can run these tests manually by running
32758 in this directory (or f.e.
32763 \begin_inset Quotes sld
32767 \begin_inset Quotes srd
32773 if you don't want to run the complete tests).
32774 The test code might also be interesting if you want to look for examples
32775 \begin_inset LatexCommand \index{Examples}
32779 checking corner cases of SDCC or if you plan to submit patches
32780 \begin_inset LatexCommand \index{Patch submission}
32787 \begin_layout Standard
32788 The PIC14 port uses a different set of regression tests
32789 \begin_inset LatexCommand \index{Regression test (PIC14)}
32793 , you'll find them in the directory
32795 sdcc/src/regression
32800 \begin_layout Section
32801 Use of SDCC in Education
32804 \begin_layout Standard
32813 \begin_layout Standard
32814 the phrase "use in education" might evoke the association "
32818 fit for use in education".
32819 This connotation is not intended but nevertheless risked as the licensing
32820 of SDCC makes it difficult to offer educational discounts
32826 If your rationales are to:
32829 \begin_layout Enumerate
32830 give students a chance to understand the
32834 steps of code generation
32837 \begin_layout Enumerate
32838 have a curriculum that can be extended for years.
32839 Then you could use an fpga board as target and your curriculum will seamlessly
32840 extend from logic synthesis (
32841 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32846 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32850 ), over assembly programming, to C to FPGA compilers (
32851 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32858 \begin_layout Enumerate
32859 be able to insert excursions about skills like using a revision control
32860 system, submitting/applying patches, using a type-setting (as opposed to
32861 word-processing) engine LyX/LaTeX, using
32862 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32867 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32871 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32872 Source Software, CPU simulation, compiler regression tests
32873 \begin_inset LatexCommand \index{Regression test}
32880 And if there should be a shortage of ideas then you can always point students
32881 to the ever-growing feature request list
32882 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32889 \begin_layout Enumerate
32890 not tie students to a specific host platform and instead allow them to use
32895 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32897 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32904 \begin_layout Enumerate
32905 not encourage students to use illegal copies of educational software
32908 \begin_layout Enumerate
32909 be immune to licensing/availability/price changes of the chosen tool chain
32912 \begin_layout Enumerate
32913 be able to change to a new target platform without having to adopt a new
32917 \begin_layout Enumerate
32918 have complete control over and insight into the tool chain
32921 \begin_layout Enumerate
32922 make your students aware about the pros and cons of open source software
32926 \begin_layout Enumerate
32927 give back to the public as you are probably at least partially publically
32931 \begin_layout Enumerate
32932 give students a chance to publically prove their skills and to possibly
32933 see a world wide impact
32936 \begin_layout Standard
32937 then SDCC is probably among the first choices.
32938 Well, probably SDCC might be the only choice.
32943 \begin_layout Chapter
32944 SDCC Technical Data
32947 \begin_layout Section
32949 \begin_inset LatexCommand \index{Optimizations}
32956 \begin_layout Standard
32957 SDCC performs a host of standard optimizations in addition to some MCU specific
32962 \begin_layout Subsection
32963 Sub-expression Elimination
32964 \begin_inset LatexCommand \index{Subexpression elimination}
32971 \begin_layout Standard
32972 The compiler does local and
32991 \begin_layout Verse
32999 \begin_layout Standard
33000 will be translated to
33003 \begin_layout Verse
33013 \begin_layout Standard
33014 Some subexpressions are not as obvious as the above example, e.g.:
33017 \begin_layout Verse
33025 \begin_layout Standard
33026 In this case the address arithmetic a->b[i] will be computed only once;
33027 the equivalent code in C would be.
33030 \begin_layout Verse
33040 \begin_layout Standard
33041 The compiler will try to keep these temporary variables in registers.
33044 \begin_layout Subsection
33045 Dead-Code Elimination
33046 \begin_inset LatexCommand \index{Dead-code elimination}
33053 \begin_layout Verse
33068 i = 1; \InsetSpace ~
33077 global = 1;\InsetSpace ~
33091 global = 3;\InsetSpace ~
33097 \begin_layout Standard
33101 \begin_layout Verse
33117 \begin_layout Subsection
33119 \begin_inset LatexCommand \index{Copy propagation}
33126 \begin_layout Verse
33150 \begin_layout Standard
33154 \begin_layout Verse
33178 \begin_layout Standard
33179 Note: the dead stores created by this copy propagation will be eliminated
33180 by dead-code elimination.
33183 \begin_layout Subsection
33185 \begin_inset LatexCommand \index{Loop optimization}
33190 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33197 \begin_layout Standard
33198 Two types of loop optimizations are done by SDCC
33206 of loop induction variables.
33207 In addition to the strength reduction the optimizer marks the induction
33208 variables and the register allocator tries to keep the induction variables
33209 in registers for the duration of the loop.
33210 Because of this preference of the register allocator
33211 \begin_inset LatexCommand \index{Register allocation}
33215 , loop induction optimization causes an increase in register pressure, which
33216 may cause unwanted spilling of other temporary variables into the stack
33217 \begin_inset LatexCommand \index{stack}
33222 The compiler will generate a warning message when it is forced to allocate
33223 extra space either on the stack or data space.
33224 If this extra space allocation is undesirable then induction optimization
33225 can be eliminated either for the entire source file (with -
33229 \begin_layout Standard
33238 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33240 \begin_inset LatexCommand \index{\#pragma noinduction}
33251 \begin_layout Verse
33254 for (i = 0 ; i < 100 ; i ++)
33263 \begin_layout Standard
33267 \begin_layout Verse
33272 for (i = 0; i < 100; i++)
33281 \begin_layout Standard
33282 As mentioned previously some loop invariants are not as apparent, all static
33283 address computations are also moved out of the loop.
33288 \begin_inset LatexCommand \index{Strength reduction}
33292 , this optimization substitutes an expression by a cheaper expression:
33295 \begin_layout Verse
33298 for (i=0;i < 100; i++)
33307 \begin_layout Standard
33311 \begin_layout Verse
33318 for (i=0;i< 100;i++) {
33324 ar[itemp1] = itemp2;
33342 \begin_layout Standard
33343 The more expensive multiplication
33344 \begin_inset LatexCommand \index{Multiplication}
33348 is changed to a less expensive addition.
33351 \begin_layout Subsection
33353 \begin_inset LatexCommand \index{Loop reversing}
33360 \begin_layout Standard
33361 This optimization is done to reduce the overhead of checking loop boundaries
33362 for every iteration.
33363 Some simple loops can be reversed and implemented using a
33364 \begin_inset Quotes eld
33367 decrement and jump if not zero
33368 \begin_inset Quotes erd
33372 SDCC checks for the following criterion to determine if a loop is reversible
33373 (note: more sophisticated compilers use data-dependency analysis to make
33374 this determination, SDCC uses a more simple minded analysis).
33377 \begin_layout Itemize
33378 The 'for' loop is of the form
33384 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33394 \begin_layout Itemize
33395 The <for body> does not contain
33396 \begin_inset Quotes eld
33400 \begin_inset Quotes erd
33404 \begin_inset Quotes erd
33410 \begin_layout Itemize
33411 All goto's are contained within the loop.
33414 \begin_layout Itemize
33415 No function calls within the loop.
33418 \begin_layout Itemize
33419 The loop control variable <sym> is not assigned any value within the loop
33422 \begin_layout Itemize
33423 The loop control variable does NOT participate in any arithmetic operation
33427 \begin_layout Itemize
33428 There are NO switch statements in the loop.
33431 \begin_layout Subsection
33432 Algebraic Simplifications
33435 \begin_layout Standard
33436 SDCC does numerous algebraic simplifications, the following is a small sub-set
33437 of these optimizations.
33440 \begin_layout Verse
33443 i = j + 0;\InsetSpace ~
33447 /* changed to: */\InsetSpace ~
33453 i /= 2;\InsetSpace ~
33460 /* changed to: */\InsetSpace ~
33467 = j - j;\InsetSpace ~
33471 /* changed to: */\InsetSpace ~
33477 i = j / 1;\InsetSpace ~
33481 /* changed to: */\InsetSpace ~
33488 \begin_layout Standard
33489 Note the subexpressions
33490 \begin_inset LatexCommand \index{Subexpression}
33494 given above are generally introduced by macro expansions or as a result
33495 of copy/constant propagation.
33498 \begin_layout Subsection
33499 'switch' Statements
33500 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33505 \begin_inset LatexCommand \index{switch statement}
33512 \begin_layout Standard
33513 SDCC can optimize switch statements to jump tables
33514 \begin_inset LatexCommand \index{jump tables}
33519 It makes the decision based on an estimate of the generated code size.
33520 SDCC is quite liberal in the requirements for jump table generation:
33523 \begin_layout Itemize
33524 The labels need not be in order, and the starting number need not be one
33525 or zero, the case labels are in numerical sequence or not too many case
33526 labels are missing.
33530 \begin_layout Verse
33533 switch(i) {\InsetSpace ~
33564 case 4: ...\InsetSpace ~
33596 case 5: ...\InsetSpace ~
33628 case 3: ...\InsetSpace ~
33659 case 6: ...\InsetSpace ~
33691 case 7: ...\InsetSpace ~
33723 case 8: ...\InsetSpace ~
33755 case 9: ...\InsetSpace ~
33787 case 10: ...\InsetSpace ~
33818 case 11: ...\InsetSpace ~
33885 \begin_layout Standard
33886 Both the above switch statements will be implemented using a jump-table.
33887 The example to the right side is slightly more efficient as the check for
33888 the lower boundary of the jump-table is not needed.
33892 \begin_layout Itemize
33893 The number of case labels is not larger than supported by the target architectur
33897 \begin_layout Itemize
33898 If the case labels are not in numerical sequence ('gaps' between cases)
33899 SDCC checks whether a jump table with additionally inserted dummy cases
33900 is still attractive.
33904 \begin_layout Itemize
33905 If the starting number is not zero and a check for the lower boundary of
33906 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33911 \begin_layout Standard
33912 Switch statements which have large gaps in the numeric sequence or those
33913 that have too many case labels can be split into more than one switch statement
33914 for efficient code generation, e.g.:
33917 \begin_layout Verse
33995 \begin_layout Standard
33996 If the above switch statement is broken down into two switch statements
33999 \begin_layout Verse
34042 \begin_layout Standard
34046 \begin_layout Verse
34089 \begin_layout Standard
34090 then both the switch statements will be implemented using jump-tables whereas
34091 the unmodified switch statement will not be.
34094 \begin_layout Standard
34095 \begin_inset Note Note
34098 \begin_layout Standard
34099 There might be reasons which SDCC cannot know about to either favour or
34100 not favour jump tables.
34101 If the target system has to be as quick for the last switch case as for
34102 the first (pro jump table), or if the switch argument is known to be zero
34103 in the majority of the cases (contra jump table).
34111 \begin_layout Standard
34112 The pragma nojtbound
34113 \begin_inset LatexCommand \index{\#pragma nojtbound}
34117 can be used to turn off checking the
34130 It has no effect if a default label is supplied.
34131 Use of this pragma is dangerous: if the switch
34132 \begin_inset LatexCommand \index{switch statement}
34136 argument is not matched by a case statement the processor will happily
34140 \begin_layout Subsection
34141 Bit-shifting Operations
34142 \begin_inset LatexCommand \index{Bit shifting}
34149 \begin_layout Standard
34150 Bit shifting is one of the most frequently used operation in embedded programmin
34152 SDCC tries to implement bit-shift operations in the most efficient way
34156 \begin_layout Verse
34169 \begin_layout Standard
34170 generates the following code:
34173 \begin_layout Verse
34188 \begin_layout Standard
34189 In general SDCC will never setup a loop if the shift count is known.
34193 \begin_layout Verse
34206 \begin_layout Standard
34210 \begin_layout Verse
34234 \begin_layout Subsection
34236 \begin_inset LatexCommand \index{Bit rotation}
34243 \begin_layout Standard
34244 A special case of the bit-shift operation is bit rotation
34245 \begin_inset LatexCommand \index{rotating bits}
34249 , SDCC recognizes the following expression to be a left bit-rotation:
34252 \begin_layout Verse
34260 char i;\InsetSpace ~
34271 /* unsigned is needed for rotation */
34276 i = ((i << 1) | (i >> 7));
34285 \begin_layout Standard
34286 will generate the following code:
34289 \begin_layout Verse
34306 \begin_layout Standard
34307 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34308 ns of this case will also be recognized as bit-rotation, i.e.:
34311 \begin_layout Verse
34314 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34317 \begin_layout Subsection
34318 Nibble and Byte Swapping
34321 \begin_layout Standard
34322 Other special cases of the bit-shift operations are nibble or byte swapping
34323 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34327 , SDCC recognizes the following expressions:
34330 \begin_layout Verse
34351 i = ((i << 4) | (i >> 4));
34357 j = ((j << 8) | (j >> 8));
34360 \begin_layout Standard
34361 and generates a swap instruction for the nibble swapping
34362 \begin_inset LatexCommand \index{Nibble swapping}
34366 or move instructions for the byte swapping
34367 \begin_inset LatexCommand \index{Byte swapping}
34373 \begin_inset Quotes sld
34377 \begin_inset Quotes srd
34380 example can be used to convert from little to big-endian or vice versa.
34381 If you want to change the endianness of a
34385 integer you have to cast to
34392 \begin_layout Standard
34393 Note that SDCC stores numbers in little-endian
34397 \begin_layout Standard
34398 Usually 8-bit processors don't care much about endianness.
34399 This is not the case for the standard 8051 which only has an instruction
34405 \begin_inset LatexCommand \index{DPTR}
34413 so little-endian is the more efficient byte order.
34419 \begin_inset LatexCommand \index{little-endian}
34424 \begin_inset LatexCommand \index{Endianness}
34429 lowest order first).
34432 \begin_layout Subsection
34434 \begin_inset LatexCommand \index{Highest Order Bit}
34439 \begin_inset LatexCommand \index{Any Order Bit}
34446 \begin_layout Standard
34447 It is frequently required to obtain the highest order bit of an integral
34448 type (long, int, short or char types).
34449 Also obtaining any other order bit is not uncommon.
34450 SDCC recognizes the following expressions to yield the highest order bit
34451 and generates optimized code for it, e.g.:
34454 \begin_layout Verse
34465 unsigned char hob1, aob1;
34469 bit hob2, hob3, aob2,
34479 hob1 = (gint >> 15) & 1;
34483 hob2 = (gint >> 15) & 1;
34487 hob3 = gint & 0x8000;
34492 aob1 = (gint >> 9) & 1;
34496 aob2 = (gint >> 8) & 1;
34500 aob3 = gint & 0x0800;
34510 \begin_layout Standard
34511 will generate the following code:
34514 \begin_layout Verse
34545 000A E5*01\InsetSpace ~
34572 000C 23\InsetSpace ~
34603 000D 54 01\InsetSpace ~
34631 000F F5*02\InsetSpace ~
34686 0011 E5*01\InsetSpace ~
34714 0013 33\InsetSpace ~
34744 0014 92*00\InsetSpace ~
34800 0016 E5*01\InsetSpace ~
34827 0018 33\InsetSpace ~
34857 0019 92*01\InsetSpace ~
34913 001B E5*01\InsetSpace ~
34972 001E 54 01\InsetSpace ~
34999 0020 F5*03\InsetSpace ~
35055 0022 E5*01\InsetSpace ~
35082 0024 13\InsetSpace ~
35112 0025 92*02\InsetSpace ~
35168 0027 E5*01\InsetSpace ~
35223 002B 92*03\InsetSpace ~
35251 \begin_layout Standard
35252 Other variations of these cases however will
35257 They are standard C expressions, so I heartily recommend these be the only
35258 way to get the highest order bit, (it is portable).
35259 Of course it will be recognized even if it is embedded in other expressions,
35263 \begin_layout Verse
35266 xyz = gint + ((gint >> 15) & 1);
35269 \begin_layout Standard
35270 will still be recognized.
35273 \begin_layout Subsection
35275 \begin_inset LatexCommand \index{Higher Order Byte}
35279 / Higher Order Word
35280 \begin_inset LatexCommand \index{Higher Order Word}
35287 \begin_layout Standard
35288 It is also frequently required to obtain a higher order byte or word of
35289 a larger integral type (long, int or short types).
35290 SDCC recognizes the following expressions to yield the higher order byte
35291 or word and generates optimized code for it, e.g.:
35294 \begin_layout Verse
35299 unsigned long int glong;
35307 unsigned char hob1,
35312 unsigned int how1, how2;
35321 hob1 = (gint >> 8) & 0xFF;
35325 hob2 = glong >> 24;
35329 how1 = (glong >> 16) & 0xFFFF;
35344 \begin_layout Standard
35345 will generate the following code:
35348 \begin_layout Verse
35379 0037 85*01*06\InsetSpace ~
35401 _foo_hob1_1_1,(_gint + 1)
35432 003A 85*05*07\InsetSpace ~
35454 _foo_hob2_1_1,(_glong + 3)
35484 003D 85*04*08\InsetSpace ~
35507 _foo_how1_1_1,(_glong + 2)
35509 0040 85*05*09\InsetSpace ~
35534 0043 85*03*0A\InsetSpace ~
35556 _foo_how2_1_1,(_glong + 1)
35558 0046 85*04*0B\InsetSpace ~
35581 (_foo_how2_1_1 + 1),(_glong + 2)
35584 \begin_layout Standard
35585 Again, variations of these cases may
35590 They are standard C expressions, so I heartily recommend these be the only
35591 way to get the higher order byte/word, (it is portable).
35592 Of course it will be recognized even if it is embedded in other expressions,
35596 \begin_layout Verse
35599 xyz = gint + ((gint >> 8) & 0xFF);
35602 \begin_layout Standard
35603 will still be recognized.
35606 \begin_layout Subsection
35608 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35613 \begin_inset LatexCommand \index{Peephole optimizer}
35620 \begin_layout Standard
35621 The compiler uses a rule based, pattern matching and re-writing mechanism
35622 for peep-hole optimization.
35627 a peep-hole optimizer by Christopher W.
35628 Fraser (cwfraser\InsetSpace ~
35631 A default set of rules are compiled into the compiler, additional rules
35632 may be added with the
35638 \begin_layout Standard
35648 \begin_inset LatexCommand \index{-\/-peep-file}
35655 The rule language is best illustrated with examples.
35658 \begin_layout Verse
35680 \begin_layout Standard
35681 The above rule will change the following assembly
35682 \begin_inset LatexCommand \index{Assembler routines}
35689 \begin_layout Verse
35697 \begin_layout Standard
35701 \begin_layout Verse
35707 \begin_layout Standard
35708 Note: All occurrences of a
35712 (pattern variable) must denote the same string.
35713 With the above rule, the assembly sequence:
35716 \begin_layout Verse
35724 \begin_layout Standard
35725 will remain unmodified.
35729 Other special case optimizations may be added by the
35736 \begin_layout Standard
35749 some variants of the 8051 MCU
35750 \begin_inset LatexCommand \index{MCS51 variants}
35763 The following two rules will change all
35780 \begin_layout Verse
35783 replace { lcall %1 } by { acall %1 }
35785 replace { ljmp %1 } by { ajmp %1 }
35788 \begin_layout Standard
35789 (NOTE: from version 2.7.3 on, you can use option -
35795 \begin_layout Standard
35807 \begin_inset LatexCommand \index{-\/-acall-ajmp}
35811 , which also takes care of aligning the interrupt vectors properly.)
35816 \begin_layout Standard
35819 inline-assembler code
35821 is also passed through the peep hole optimizer, thus the peephole optimizer
35822 can also be used as an assembly level macro expander.
35823 The rules themselves are MCU dependent whereas the rule language infra-structur
35824 e is MCU independent.
35825 Peephole optimization rules for other MCU can be easily programmed using
35830 The syntax for a rule is as follows:
35833 \begin_layout Verse
35836 rule := replace [ restart ] '{' <assembly sequence> '
35874 <assembly sequence> '
35892 '}' [if <functionName> ] '
35897 \begin_layout Standard
35898 <assembly sequence> := assembly instruction (each instruction including
35899 labels must be on a separate line).
35903 The optimizer will apply to the rules
35904 one by one from the top in the sequence of their appearance, it will terminate
35905 when all rules are exhausted.
35906 If the 'restart' option is specified, then the optimizer will start matching
35907 the rules again from the top, this option for a rule is expensive (performance)
35908 , it is intended to be used in situations where a transformation will trigger
35909 the same rule again.
35910 An example of this (not a good one, it has side effects) is the following
35914 \begin_layout Verse
35934 \begin_layout Standard
35935 Note that the replace pattern cannot be a blank, but can be a comment line.
35936 Without the 'restart' option only the innermost 'pop' 'push' pair would
35937 be eliminated, i.e.:
35940 \begin_layout Verse
35952 \begin_layout Standard
35956 \begin_layout Verse
35966 \begin_layout Standard
35971 the restart option the rule will be applied again to the resulting code
35972 and then all the pop-push pairs will be eliminated to yield:
35975 \begin_layout Verse
35983 \begin_layout Standard
35984 A conditional function can be attached to a rule.
35985 Attaching rules are somewhat more involved, let me illustrate this with
35989 \begin_layout Verse
36013 \begin_layout Standard
36014 The optimizer does a look-up of a function name table defined in function
36019 in the source file SDCCpeeph.c, with the name
36024 If it finds a corresponding entry the function is called.
36025 Note there can be no parameters specified for these functions, in this
36030 is crucial, since the function
36034 expects to find the label in that particular variable (the hash table containin
36035 g the variable bindings is passed as a parameter).
36036 If you want to code more such functions, take a close look at the function
36037 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36038 Currently implemented are
36040 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36041 24bitMode, portIsDS390, 24bitModeAndPortDS390
36050 \begin_layout Standard
36051 I know this whole thing is a little kludgey, but maybe some day we will
36052 have some better means.
36053 If you are looking at this file, you will see the default rules that are
36054 compiled into the compiler, you can add your own rules in the default set
36055 there if you get tired of specifying the -
36059 \begin_layout Standard
36071 \begin_layout Section
36073 \begin_inset LatexCommand \index{ANSI-compliance}
36078 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36085 \begin_layout Standard
36086 The latest publically available version of the standard
36088 ISO/IEC 9899 - Programming languages - C
36090 should be available at:
36091 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36100 \begin_layout Standard
36101 Deviations from the compliance:
36104 \begin_layout Itemize
36105 functions are not reentrant
36106 \begin_inset LatexCommand \index{reentrant}
36110 unless explicitly declared as such or the
36116 \begin_layout Standard
36126 \begin_inset LatexCommand \index{-\/-stack-auto}
36132 command line option is specified.
36135 \begin_layout Itemize
36137 \begin_inset LatexCommand \index{struct}
36142 \begin_inset LatexCommand \index{union}
36146 cannot be assigned values directly, cannot be passed as function parameters
36147 or assigned to each other and cannot be a return value
36148 \begin_inset LatexCommand \index{return value}
36152 from a function, e.g.:
36156 \begin_layout Verse
36179 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36198 s parms) /* invalid in SDCC although allowed in ANSI */
36220 return rets; /* is invalid in SDCC although allowed in ANSI */
36226 \begin_layout Itemize
36227 initialization of structure arrays must be fully braced.
36231 \begin_layout Verse
36234 struct s { char x } a[] = {1, 2};\InsetSpace ~
36239 /* invalid in SDCC */
36242 } a[] = {{1}, {2}}; /* OK */
36246 \begin_layout Itemize
36248 \begin_inset LatexCommand \index{long long (not supported)}
36253 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36260 \begin_layout Itemize
36262 \begin_inset LatexCommand \index{double (not supported)}
36266 ' precision floating point
36267 \begin_inset LatexCommand \index{Floating point support}
36274 \begin_layout Itemize
36276 \begin_inset LatexCommand \index{K\&R style}
36280 function declarations are NOT allowed.
36284 \begin_layout Verse
36287 foo(i,j) /* this old style of function declarations */
36289 int i,j; /* is valid
36290 in ANSI but not valid in SDCC */
36305 \begin_layout Itemize
36306 Most enhancements in C99 are not supported, e.g.:
36310 \begin_layout Verse
36317 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36321 \begin_layout Itemize
36322 But some have been added recently in SDCC 2.7.0.
36323 They must be considered alpha quality however.
36327 \begin_layout Verse
36332 \begin_inset LatexCommand \index{inline (not supported)}
36338 int increment (int a) { return a+1; } /* inlines the increment without
36339 function call overhead */
36344 \begin_inset LatexCommand \index{inline (not supported)}
36350 p; /* accepted but ignored */
36354 \begin_layout Itemize
36355 Certain words that are valid identifiers in the standard may be reserved
36356 words in SDCC unless the
36362 \begin_layout Standard
36372 \begin_inset LatexCommand \index{-\/-std-c89}
36380 \begin_layout Standard
36390 \begin_inset LatexCommand \index{-\/-std-c99}
36396 command line options are used.
36397 These may include (depending on the selected processor): 'at', 'banked',
36398 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36399 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36400 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36402 Compliant equivalents of these keywords are always available in a form
36403 that begin with two underscores
36404 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36409 '__data' instead of 'data'.
36412 \begin_layout Section
36413 Cyclomatic Complexity
36414 \begin_inset LatexCommand \index{Cyclomatic complexity}
36421 \begin_layout Standard
36422 Cyclomatic complexity of a function is defined as the number of independent
36423 paths the program can take during execution of the function.
36424 This is an important number since it defines the number test cases you
36425 have to generate to validate the function.
36426 The accepted industry standard for complexity number is 10, if the cyclomatic
36427 complexity reported by SDCC exceeds 10 you should think about simplification
36428 of the function logic.
36429 Note that the complexity level is not related to the number of lines of
36430 code in a function.
36431 Large functions can have low complexity, and small functions can have large
36437 SDCC uses the following formula to compute the complexity:
36442 \begin_layout Standard
36443 complexity = (number of edges in control flow graph) - (number of nodes
36444 in control flow graph) + 2;
36448 Having said that the industry standard is 10,
36449 you should be aware that in some cases it be may unavoidable to have a
36450 complexity level of less than 10.
36451 For example if you have switch statement with more than 10 case labels,
36452 each case label adds one to the complexity level.
36453 The complexity level is by no means an absolute measure of the algorithmic
36454 complexity of the function, it does however provide a good starting point
36455 for which functions you might look at for further optimization.
36458 \begin_layout Section
36459 Retargetting for other Processors
36462 \begin_layout Standard
36463 The issues for retargetting the compiler are far too numerous to be covered
36465 What follows is a brief description of each of the seven phases of the
36466 compiler and its MCU dependency.
36469 \begin_layout Itemize
36470 Parsing the source and building the annotated parse tree.
36471 This phase is largely MCU independent (except for the language extensions).
36472 Syntax & semantic checks are also done in this phase, along with some initial
36473 optimizations like back patching labels and the pattern matching optimizations
36474 like bit-rotation etc.
36477 \begin_layout Itemize
36478 The second phase involves generating an intermediate code which can be easy
36479 manipulated during the later phases.
36480 This phase is entirely MCU independent.
36481 The intermediate code generation assumes the target machine has unlimited
36482 number of registers, and designates them with the name iTemp.
36483 The compiler can be made to dump a human readable form of the code generated
36488 \begin_layout Standard
36500 \begin_layout Itemize
36501 This phase does the bulk of the standard optimizations and is also MCU independe
36503 This phase can be broken down into several sub-phases:
36507 Break down intermediate
36508 code (iCode) into basic blocks.
36510 Do control flow & data flow analysis on the
36513 Do local common subexpression elimination, then global subexpressio
36516 Dead code elimination
36520 If loop optimizations
36521 caused any changes then do 'global subexpression elimination' and 'dead
36522 code elimination' again.
36525 \begin_layout Itemize
36526 This phase determines the live-ranges; by live range I mean those iTemp
36527 variables defined by the compiler that still survive after all the optimization
36529 Live range analysis
36530 \begin_inset LatexCommand \index{Live range analysis}
36534 is essential for register allocation, since these computation determines
36535 which of these iTemps will be assigned to registers, and for how long.
36538 \begin_layout Itemize
36539 Phase five is register allocation.
36540 There are two parts to this process.
36544 The first part I call 'register packing'
36545 (for lack of a better term).
36546 In this case several MCU specific expression folding is done to reduce
36551 The second part is more MCU independent and deals with
36552 allocating registers to the remaining live ranges.
36553 A lot of MCU specific code does creep into this phase because of the limited
36554 number of index registers available in the 8051.
36557 \begin_layout Itemize
36558 The Code generation phase is (unhappily), entirely MCU dependent and very
36559 little (if any at all) of this code can be reused for other MCU.
36560 However the scheme for allocating a homogenized assembler operand for each
36561 iCode operand may be reused.
36564 \begin_layout Itemize
36565 As mentioned in the optimization section the peep-hole optimizer is rule
36566 based system, which can reprogrammed for other MCUs.
36569 \begin_layout Standard
36570 More information is available on SDCC Wiki
36571 \begin_inset LatexCommand \index{wiki}
36576 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36580 ) and in the thread
36581 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36588 \begin_layout Chapter
36590 \begin_inset LatexCommand \index{Compiler internals}
36597 \begin_layout Section
36598 The anatomy of the compiler
36599 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36606 \begin_layout Standard
36609 This is an excerpt from an article published in Circuit Cellar Magazine
36615 It's a little outdated (the compiler is much more efficient now and user/develo
36616 per friendly), but pretty well exposes the guts of it all.
36622 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36623 It is fairly easy to retarget for other 8-bit MCU.
36624 Here we take a look at some of the internals of the compiler.
36628 \begin_layout Paragraph*
36630 \begin_inset LatexCommand \index{Parsing}
36637 \begin_layout Standard
36638 Parsing the input source file and creating an AST (Annotated Syntax Tree
36639 \begin_inset LatexCommand \index{Annotated syntax tree}
36644 This phase also involves propagating types (annotating each node of the
36645 parse tree with type information) and semantic analysis.
36646 There are some MCU specific parsing rules.
36647 For example the storage classes, the extended storage classes are MCU specific
36648 while there may be a xdata storage class for 8051 there is no such storage
36649 class for z80 or Atmel AVR.
36650 SDCC allows MCU specific storage class extensions, i.e.
36651 xdata will be treated as a storage class specifier when parsing 8051 C
36652 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36656 \begin_layout Paragraph*
36658 \begin_inset LatexCommand \index{iCode}
36665 \begin_layout Standard
36666 Intermediate code generation.
36667 In this phase the AST is broken down into three-operand form (iCode).
36668 These three operand forms are represented as doubly linked lists.
36669 ICode is the term given to the intermediate form generated by the compiler.
36670 ICode example section shows some examples of iCode generated for some simple
36671 C source functions.
36674 \begin_layout Paragraph*
36676 \begin_inset LatexCommand \index{Optimizations}
36683 \begin_layout Standard
36684 Bulk of the target independent optimizations is performed in this phase.
36685 The optimizations include constant propagation, common sub-expression eliminati
36686 on, loop invariant code movement, strength reduction of loop induction variables
36687 and dead-code elimination.
36690 \begin_layout Paragraph*
36691 Live range analysis
36692 \begin_inset LatexCommand \index{Live range analysis}
36699 \begin_layout Standard
36700 During intermediate code generation phase, the compiler assumes the target
36701 machine has infinite number of registers and generates a lot of temporary
36703 The live range computation determines the lifetime of each of these compiler-ge
36704 nerated temporaries.
36705 A picture speaks a thousand words.
36706 ICode example sections show the live range annotations for each of the
36708 It is important to note here, each iCode is assigned a number in the order
36709 of its execution in the function.
36710 The live ranges are computed in terms of these numbers.
36711 The from number is the number of the iCode which first defines the operand
36712 and the to number signifies the iCode which uses this operand last.
36715 \begin_layout Paragraph*
36716 Register Allocation
36717 \begin_inset LatexCommand \index{Register allocation}
36724 \begin_layout Standard
36725 The register allocation determines the type and number of registers needed
36727 In most MCUs only a few registers can be used for indirect addressing.
36728 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36729 address the internal ram and DPTR to indirectly address the external ram.
36730 The compiler will try to allocate the appropriate register to pointer variables
36732 ICode example section shows the operands annotated with the registers assigned
36734 The compiler will try to keep operands in registers as much as possible;
36735 there are several schemes the compiler uses to do achieve this.
36736 When the compiler runs out of registers the compiler will check to see
36737 if there are any live operands which is not used or defined in the current
36738 basic block being processed, if there are any found then it will push that
36739 operand and use the registers in this block, the operand will then be popped
36740 at the end of the basic block.
36744 \begin_layout Standard
36745 There are other MCU specific considerations in this phase.
36746 Some MCUs have an accumulator; very short-lived operands could be assigned
36747 to the accumulator instead of a general-purpose register.
36750 \begin_layout Paragraph*
36754 \begin_layout Standard
36755 Figure II gives a table of iCode
36756 \begin_inset LatexCommand \index{iCode}
36760 operations supported by the compiler.
36761 The code generation involves translating these operations into corresponding
36762 assembly code for the processor.
36763 This sounds overly simple but that is the essence of code generation.
36764 Some of the iCode operations are generated on a MCU specific manner for
36765 example, the z80 port does not use registers to pass parameters so the
36766 SEND and RECV iCode operations will not be generated, and it also does
36767 not support JUMPTABLES.
36773 \begin_layout Standard
36777 \begin_inset Tabular
36778 <lyxtabular version="3" rows="39" columns="4">
36779 <features islongtable="true" headBottomDL="true">
36780 <column alignment="block" valignment="top" leftline="true" width="13col%">
36781 <column alignment="left" valignment="top" leftline="true" width="13col%">
36782 <column alignment="block" valignment="top" leftline="true" width="22col%">
36783 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36784 <row topline="true" bottomline="true" endhead="true">
36785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36788 \begin_layout Standard
36794 \begin_inset LatexCommand \index{iCode}
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36806 \begin_layout Standard
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36817 \begin_layout Standard
36825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36828 \begin_layout Standard
36837 <row topline="true">
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36841 \begin_layout Standard
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36852 \begin_layout Standard
36855 IC_LEFT() IC_RESULT()
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36863 \begin_layout Standard
36871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36874 \begin_layout Standard
36877 IC_RESULT = ! IC_LEFT;
36883 <row topline="true">
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36887 \begin_layout Standard
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36898 \begin_layout Standard
36901 IC_LEFT() IC_RESULT()
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36909 \begin_layout Standard
36912 Bitwise complement of
36917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36920 \begin_layout Standard
36923 IC_RESULT = ~IC_LEFT;
36929 <row topline="true">
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 IC_LEFT() IC_RESULT()
36952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36955 \begin_layout Standard
36958 Rotate right with carry
36963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36966 \begin_layout Standard
36969 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36975 <row topline="true">
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 IC_LEFT() IC_RESULT()
36998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37001 \begin_layout Standard
37004 Rotate left with carry
37009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37012 \begin_layout Standard
37015 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37021 <row topline="true">
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37025 \begin_layout Standard
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37036 \begin_layout Standard
37039 IC_LEFT() IC_RESULT()
37044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37047 \begin_layout Standard
37050 Get the highest order bit of IC_LEFT
37055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37058 \begin_layout Standard
37061 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37067 <row topline="true">
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37071 \begin_layout Standard
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37082 \begin_layout Standard
37085 IC_LEFT() IC_RESULT()
37090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37093 \begin_layout Standard
37101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37104 \begin_layout Standard
37107 IC_RESULT = - IC_LEFT;
37113 <row topline="true">
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
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37139 \begin_layout Standard
37142 Push the operand into stack
37147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37150 \begin_layout Standard
37159 <row topline="true">
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" usebox="none">
37185 \begin_layout Standard
37188 Pop the operand from the stack
37193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37196 \begin_layout Standard
37205 <row topline="true">
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
37223 IC_LEFT() IC_RESULT()
37228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37231 \begin_layout Standard
37234 Call the function represented by IC_LEFT
37239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37242 \begin_layout Standard
37245 IC_RESULT = IC_LEFT();
37251 <row topline="true">
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37255 \begin_layout Standard
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37266 \begin_layout Standard
37269 IC_LEFT() IC_RESULT()
37274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37277 \begin_layout Standard
37280 Call via function pointer
37285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37288 \begin_layout Standard
37291 IC_RESULT = (*IC_LEFT)();
37297 <row topline="true">
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37301 \begin_layout Standard
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" usebox="none">
37323 \begin_layout Standard
37326 Return the value in operand IC_LEFT
37331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37334 \begin_layout Standard
37343 <row topline="true">
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37347 \begin_layout Standard
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" usebox="none">
37369 \begin_layout Standard
37377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37380 \begin_layout Standard
37389 <row topline="true">
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37393 \begin_layout Standard
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" usebox="none">
37415 \begin_layout Standard
37423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37426 \begin_layout Standard
37435 <row topline="true">
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37439 \begin_layout Standard
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37450 \begin_layout Standard
37453 IC_LEFT() IC_RIGHT() IC_RESULT()
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37461 \begin_layout Standard
37469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37472 \begin_layout Standard
37475 IC_RESULT = IC_LEFT + IC_RIGHT
37481 <row topline="true">
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37485 \begin_layout Standard
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37496 \begin_layout Standard
37499 IC_LEFT() IC_RIGHT() IC_RESULT()
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37507 \begin_layout Standard
37515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37518 \begin_layout Standard
37521 IC_RESULT = IC_LEFT - IC_RIGHT
37527 <row topline="true">
37528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37531 \begin_layout Standard
37539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37542 \begin_layout Standard
37545 IC_LEFT() IC_RIGHT() IC_RESULT()
37550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37553 \begin_layout Standard
37561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37564 \begin_layout Standard
37567 IC_RESULT = IC_LEFT * IC_RIGHT;
37573 <row topline="true">
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37577 \begin_layout Standard
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37588 \begin_layout Standard
37591 IC_LEFT() IC_RIGHT() IC_RESULT()
37596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37599 \begin_layout Standard
37607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37610 \begin_layout Standard
37613 IC_RESULT = IC_LEFT / IC_RIGHT;
37619 <row topline="true">
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37623 \begin_layout Standard
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37634 \begin_layout Standard
37637 IC_LEFT() IC_RIGHT() IC_RESULT()
37642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37645 \begin_layout Standard
37653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37656 \begin_layout Standard
37659 IC_RESULT = IC_LEFT % IC_RIGHT;
37665 <row topline="true">
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37669 \begin_layout Standard
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37680 \begin_layout Standard
37683 IC_LEFT() IC_RIGHT() IC_RESULT()
37688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37691 \begin_layout Standard
37699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37702 \begin_layout Standard
37705 IC_RESULT = IC_LEFT < IC_RIGHT;
37711 <row topline="true">
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37715 \begin_layout Standard
37723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37726 \begin_layout Standard
37729 IC_LEFT() IC_RIGHT() IC_RESULT()
37734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37737 \begin_layout Standard
37745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37748 \begin_layout Standard
37751 IC_RESULT = IC_LEFT > IC_RIGHT;
37757 <row topline="true">
37758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37761 \begin_layout Standard
37769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37772 \begin_layout Standard
37775 IC_LEFT() IC_RIGHT() IC_RESULT()
37780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37783 \begin_layout Standard
37791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37794 \begin_layout Standard
37797 IC_RESULT = IC_LEFT == IC_RIGHT;
37803 <row topline="true">
37804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37807 \begin_layout Standard
37815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37818 \begin_layout Standard
37821 IC_LEFT() IC_RIGHT() IC_RESULT()
37826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37829 \begin_layout Standard
37832 Logical and operation
37837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37840 \begin_layout Standard
37843 IC_RESULT = IC_LEFT && IC_RIGHT;
37849 <row topline="true">
37850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37853 \begin_layout Standard
37861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37864 \begin_layout Standard
37867 IC_LEFT() IC_RIGHT() IC_RESULT()
37872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37875 \begin_layout Standard
37878 Logical or operation
37883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37886 \begin_layout Standard
37889 IC_RESULT = IC_LEFT || IC_RIGHT;
37895 <row topline="true">
37896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37899 \begin_layout Standard
37907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37910 \begin_layout Standard
37913 IC_LEFT() IC_RIGHT() IC_RESULT()
37918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37921 \begin_layout Standard
37929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37932 \begin_layout Standard
37935 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37941 <row topline="true">
37942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37945 \begin_layout Standard
37953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37956 \begin_layout Standard
37959 IC_LEFT() IC_RIGHT() IC_RESULT()
37964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37967 \begin_layout Standard
37975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37978 \begin_layout Standard
37981 IC_RESULT = IC_LEFT | IC_RIGHT;
37987 <row topline="true">
37988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37991 \begin_layout Standard
37999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38002 \begin_layout Standard
38005 IC_LEFT() IC_RIGHT() IC_RESULT()
38010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38013 \begin_layout Standard
38021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38024 \begin_layout Standard
38027 IC_RESULT = IC_LEFT & IC_RIGHT;
38033 <row topline="true">
38034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38037 \begin_layout Standard
38045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38048 \begin_layout Standard
38051 IC_LEFT() IC_RIGHT() IC_RESULT()
38056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38059 \begin_layout Standard
38067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38070 \begin_layout Standard
38073 IC_RESULT = IC_LEFT << IC_RIGHT
38079 <row topline="true">
38080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38083 \begin_layout Standard
38091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38094 \begin_layout Standard
38097 IC_LEFT() IC_RIGHT() IC_RESULT()
38102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38105 \begin_layout Standard
38113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38116 \begin_layout Standard
38119 IC_RESULT = IC_LEFT >> IC_RIGHT
38125 <row topline="true">
38126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38129 \begin_layout Standard
38139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38142 \begin_layout Standard
38145 IC_LEFT() IC_RESULT()
38150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38153 \begin_layout Standard
38161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38164 \begin_layout Standard
38167 IC_RESULT = (*IC_LEFT);
38173 <row topline="true">
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38177 \begin_layout Standard
38185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38188 \begin_layout Standard
38191 IC_RIGHT() IC_RESULT()
38196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38199 \begin_layout Standard
38207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38210 \begin_layout Standard
38213 (*IC_RESULT) = IC_RIGHT;
38219 <row topline="true">
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38223 \begin_layout Standard
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38234 \begin_layout Standard
38237 IC_RIGHT() IC_RESULT()
38242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38245 \begin_layout Standard
38253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38256 \begin_layout Standard
38259 IC_RESULT = IC_RIGHT;
38265 <row topline="true">
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38269 \begin_layout Standard
38277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38280 \begin_layout Standard
38283 IC_COND IC_TRUE IC_LABEL
38288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38291 \begin_layout Standard
38295 If true label is present then jump to true label if condition is true else
38296 jump to false label if condition is false
38301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38304 \begin_layout Standard
38307 if (IC_COND) goto IC_TRUE;
38313 If (!IC_COND) goto IC_FALSE;
38319 <row topline="true">
38320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38323 \begin_layout Standard
38331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38334 \begin_layout Standard
38337 IC_LEFT() IC_RESULT()
38342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38345 \begin_layout Standard
38353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38356 \begin_layout Standard
38359 IC_RESULT = &IC_LEFT();
38365 <row topline="true">
38366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38369 \begin_layout Standard
38377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38380 \begin_layout Standard
38383 IC_JTCOND IC_JTLABELS
38388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38391 \begin_layout Standard
38394 Jump to list of labels depending on the value of JTCOND
38399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38402 \begin_layout Standard
38411 <row topline="true">
38412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38415 \begin_layout Standard
38423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38426 \begin_layout Standard
38429 IC_RIGHT() IC_LEFT() IC_RESULT()
38434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38437 \begin_layout Standard
38445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38448 \begin_layout Standard
38451 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38457 <row topline="true">
38458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38461 \begin_layout Standard
38469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38472 \begin_layout Standard
38480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38483 \begin_layout Standard
38486 This is used for passing parameters in registers;
38488 move IC_LEFT to the next
38489 available parameter register.
38494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38497 \begin_layout Standard
38506 <row topline="true">
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38510 \begin_layout Standard
38518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38521 \begin_layout Standard
38529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38532 \begin_layout Standard
38535 This is used for receiving parameters passed in registers;
38538 in the next parameter register to IC_RESULT
38543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38546 \begin_layout Standard
38555 <row topline="true" bottomline="true">
38556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38559 \begin_layout Standard
38563 (some more have been added)
38568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38571 \begin_layout Standard
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38580 \begin_layout Standard
38586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38589 \begin_layout Standard
38613 \begin_layout Standard
38614 \begin_inset Note Note
38617 \begin_layout Standard
38618 In the original article Figure II was announced to be downloadable on
38623 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38631 \begin_layout Paragraph*
38633 \begin_inset LatexCommand \index{iCode}
38640 \begin_layout Standard
38641 This section shows some details of iCode.
38642 The example C code does not do anything useful; it is used as an example
38643 to illustrate the intermediate code generated by the compiler.
38646 \begin_layout Verse
38656 /* This function does nothing useful.
38663 for the purpose of explaining iCode */
38666 short function (data
38675 short i=10; \InsetSpace ~
38677 /* dead initialization eliminated */
38683 /* dead initialization eliminated */
38711 /* compiler detects i,j to be induction
38716 for (i = 0, j = 10 ; i < 10 ; i++, j
38722 \begin_layout Standard
38745 mul += i * 3; \InsetSpace ~
38747 /* this multiplication remains */
38754 j * 3;\InsetSpace ~
38756 /* this multiplication changed to addition */
38770 \begin_layout Standard
38771 In addition to the operands each iCode contains information about the filename
38772 and line it corresponds to in the source file.
38773 The first field in the listing should be interpreted as follows:
38778 Filename(linenumber: iCode Execution sequence number : ICode hash table
38779 key : loop depth of the iCode).
38784 Then follows the human readable form of the ICode operation.
38785 Each operand of this triplet form can be of three basic types a) compiler
38786 generated temporary b) user defined variable c) a constant value.
38787 Note that local variables and parameters are replaced by compiler generated
38790 \begin_inset LatexCommand \index{Live range analysis}
38794 are computed only for temporaries (i.e.
38795 live ranges are not computed for global variables).
38797 \begin_inset LatexCommand \index{Register allocation}
38801 are allocated for temporaries only.
38802 Operands are formatted in the following manner:
38807 Operand Name [lr live-from : live-to ] { type information } [ registers
38813 As mentioned earlier the live ranges are computed in terms of the execution
38814 sequence number of the iCodes, for example
38816 the iTemp0 is live from (i.e.
38817 first defined in iCode with execution sequence number 3, and is last used
38818 in the iCode with sequence number 5).
38819 For induction variables such as iTemp21 the live range computation extends
38820 the lifetime from the start to the end of the loop.
38822 The register allocator
38823 used the live range information to allocate registers, the same registers
38824 may be used for different temporaries if their live ranges do not overlap,
38825 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38826 ranges do not overlap.
38827 In addition the allocator also takes into consideration the type and usage
38828 of a temporary, for example itemp6 is a pointer to near space and is used
38829 as to fetch data from (i.e.
38830 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38831 Some short lived temporaries are allocated to special registers which have
38832 meaning to the code generator e.g.
38833 iTemp13 is allocated to a pseudo register CC which tells the back end that
38834 the temporary is used only for a conditional jump the code generation makes
38835 use of this information to optimize a compare and jump ICode.
38839 \begin_inset LatexCommand \index{Loop optimization}
38843 performed by the compiler.
38844 It can detect induction variables iTemp21(i) and iTemp23(j).
38845 Also note the compiler does selective strength reduction
38846 \begin_inset LatexCommand \index{Strength reduction}
38851 the multiplication of an induction variable in line 18 (gint = j * 3) is
38852 changed to addition, a new temporary iTemp17 is allocated and assigned
38853 a initial value, a constant 3 is then added for each iteration of the loop.
38854 The compiler does not change the multiplication
38855 \begin_inset LatexCommand \index{Multiplication}
38859 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38862 Note the dead code elimination
38863 \begin_inset LatexCommand \index{Dead-code elimination}
38867 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38873 \begin_layout Standard
38876 Sample.c (5:1:0:0) _entry($9) :
38879 \begin_layout Standard
38882 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38885 \begin_layout Standard
38888 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38891 \begin_layout Standard
38894 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38897 \begin_layout Standard
38900 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38904 \begin_layout Standard
38907 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38910 \begin_layout Standard
38913 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38917 \begin_layout Standard
38920 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38923 \begin_layout Standard
38926 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38930 \begin_layout Standard
38933 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38937 \begin_layout Standard
38940 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38944 \begin_layout Standard
38947 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38951 \begin_layout Standard
38954 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38955 * int}[r0] + 0x2 {short}
38958 \begin_layout Standard
38961 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38964 \begin_layout Standard
38967 Sample.c(11:17:21:0)_whilebreak_0($3) :
38970 \begin_layout Standard
38973 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38976 \begin_layout Standard
38979 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38982 \begin_layout Standard
38985 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38988 \begin_layout Standard
38991 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38994 \begin_layout Standard
38997 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39000 \begin_layout Standard
39003 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39006 \begin_layout Standard
39009 Sample.c(15:24:26:1)_forcond_0($4) :
39012 \begin_layout Standard
39015 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39019 \begin_layout Standard
39022 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39025 \begin_layout Standard
39028 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39029 + ITemp21 [lr21:38]{short}[r4]
39032 \begin_layout Standard
39035 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39039 \begin_layout Standard
39042 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39043 + iTemp15 [lr29:30]{short}[r1]
39046 \begin_layout Standard
39049 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39053 \begin_layout Standard
39056 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39060 \begin_layout Standard
39063 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39067 \begin_layout Standard
39070 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39074 \begin_layout Standard
39077 Sample.c(19:38:47:1) goto _forcond_0($4)
39080 \begin_layout Standard
39083 Sample.c(19:39:48:0)_forbreak_0($7) :
39086 \begin_layout Standard
39089 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39090 + ITemp11 [lr19:40]{short}[r3]
39093 \begin_layout Standard
39096 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39099 \begin_layout Standard
39102 Sample.c(20:42:51:0)_return($8) :
39105 \begin_layout Standard
39108 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39114 Finally the code generated for this function:
39119 \begin_layout Standard
39125 \begin_layout Standard
39131 \begin_layout Standard
39139 \begin_layout Standard
39145 \begin_layout Standard
39153 \begin_layout Standard
39159 \begin_layout Standard
39162 ; ----------------------------------------------
39165 \begin_layout Standard
39168 ; function function
39171 \begin_layout Standard
39174 ; ----------------------------------------------
39177 \begin_layout Standard
39183 \begin_layout Standard
39186 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39189 \begin_layout Standard
39197 \begin_layout Standard
39200 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39203 \begin_layout Standard
39211 \begin_layout Standard
39214 ;_whilecontinue_0($1) :
39217 \begin_layout Standard
39223 \begin_layout Standard
39226 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39229 \begin_layout Standard
39232 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39235 \begin_layout Standard
39243 \begin_layout Standard
39251 \begin_layout Standard
39259 \begin_layout Standard
39267 \begin_layout Standard
39275 \begin_layout Standard
39283 \begin_layout Standard
39291 \begin_layout Standard
39297 \begin_layout Standard
39300 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39303 \begin_layout Standard
39311 \begin_layout Standard
39319 \begin_layout Standard
39322 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39325 \begin_layout Standard
39333 \begin_layout Standard
39341 \begin_layout Standard
39349 \begin_layout Standard
39357 \begin_layout Standard
39365 \begin_layout Standard
39373 \begin_layout Standard
39376 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39379 \begin_layout Standard
39387 \begin_layout Standard
39395 \begin_layout Standard
39403 \begin_layout Standard
39411 \begin_layout Standard
39419 \begin_layout Standard
39422 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39425 \begin_layout Standard
39433 \begin_layout Standard
39441 \begin_layout Standard
39449 \begin_layout Standard
39452 ; iTemp6 [lr5:16]{_near * int}[r0] =
39455 \begin_layout Standard
39458 ; iTemp6 [lr5:16]{_near * int}[r0] +
39461 \begin_layout Standard
39467 \begin_layout Standard
39475 \begin_layout Standard
39478 ; goto _whilecontinue_0($1)
39481 \begin_layout Standard
39489 \begin_layout Standard
39492 ; _whilebreak_0($3) :
39495 \begin_layout Standard
39501 \begin_layout Standard
39504 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39507 \begin_layout Standard
39515 \begin_layout Standard
39518 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39521 \begin_layout Standard
39529 \begin_layout Standard
39532 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39535 \begin_layout Standard
39543 \begin_layout Standard
39546 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39549 \begin_layout Standard
39557 \begin_layout Standard
39565 \begin_layout Standard
39568 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39571 \begin_layout Standard
39579 \begin_layout Standard
39587 \begin_layout Standard
39593 \begin_layout Standard
39599 \begin_layout Standard
39602 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39605 \begin_layout Standard
39608 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39611 \begin_layout Standard
39619 \begin_layout Standard
39627 \begin_layout Standard
39635 \begin_layout Standard
39643 \begin_layout Standard
39651 \begin_layout Standard
39657 \begin_layout Standard
39660 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39663 \begin_layout Standard
39666 ; iTemp21 [lr21:38]{short}[r4]
39669 \begin_layout Standard
39677 \begin_layout Standard
39685 \begin_layout Standard
39693 \begin_layout Standard
39696 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39699 \begin_layout Standard
39707 \begin_layout Standard
39715 \begin_layout Standard
39723 \begin_layout Standard
39731 \begin_layout Standard
39734 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39737 \begin_layout Standard
39740 ; iTemp15 [lr29:30]{short}[r1]
39743 \begin_layout Standard
39751 \begin_layout Standard
39759 \begin_layout Standard
39762 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39765 \begin_layout Standard
39773 \begin_layout Standard
39781 \begin_layout Standard
39789 \begin_layout Standard
39797 \begin_layout Standard
39805 \begin_layout Standard
39813 \begin_layout Standard
39816 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39819 \begin_layout Standard
39827 \begin_layout Standard
39835 \begin_layout Standard
39843 \begin_layout Standard
39851 \begin_layout Standard
39859 \begin_layout Standard
39867 \begin_layout Standard
39870 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39873 \begin_layout Standard
39881 \begin_layout Standard
39884 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39887 \begin_layout Standard
39895 \begin_layout Standard
39900 cjne r5,#0xff,00104$
39903 \begin_layout Standard
39911 \begin_layout Standard
39914 ; goto _forcond_0($4)
39917 \begin_layout Standard
39925 \begin_layout Standard
39928 ; _forbreak_0($7) :
39931 \begin_layout Standard
39937 \begin_layout Standard
39940 ; ret iTemp24 [lr40:41]{short}
39943 \begin_layout Standard
39951 \begin_layout Standard
39959 \begin_layout Standard
39967 \begin_layout Standard
39973 \begin_layout Standard
39979 \begin_layout Standard
39989 \begin_layout Section
39990 A few words about basic block successors, predecessors and dominators
39993 \begin_layout Standard
39994 Successors are basic blocks
39995 \begin_inset LatexCommand \index{Basic blocks}
39999 that might execute after this basic block.
40001 Predecessors are basic blocks
40002 that might execute before reaching this basic block.
40004 Dominators are basic
40005 blocks that WILL execute before reaching this basic block.
40010 \begin_layout Standard
40014 \begin_layout Standard
40018 \begin_layout Standard
40026 \begin_layout Standard
40030 \begin_layout Standard
40038 \begin_layout Standard
40044 \begin_layout Standard
40045 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40048 \begin_layout Standard
40049 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40052 \begin_layout Standard
40053 c) domVect of [BB4] = BB1 ...
40054 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40058 \begin_layout Chapter
40062 \begin_layout Standard
40063 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40073 Thanks to all the other volunteer developers who have helped with coding,
40074 testing, web-page creation, distribution sets, etc.
40075 You know who you are :-)
40083 Thanks to Sourceforge
40084 \begin_inset LatexCommand \url{http://www.sf.net}
40088 which has hosted the project since 1999 and donates significant download
40097 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40098 cycles and bandwidth for snapshot builds.
40103 \begin_layout Standard
40104 This document was initially written by Sandeep Dutta
40107 \begin_layout Standard
40108 All product names mentioned herein may be trademarks
40109 \begin_inset LatexCommand \index{Trademarks}
40113 of their respective companies.
40117 \begin_layout Section*
40121 \begin_layout Standard
40122 To avoid confusion, the installation and building options for SDCC itself
40123 (chapter 2) are not part of the index.
40126 \begin_layout Standard
40127 \begin_inset LatexCommand \printindex{}