1 #LyX 1.4.5 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 Standard
3975 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
3977 Run 'configure' with:
3980 \begin_layout LyX-Code
3986 \begin_layout LyX-Code
3987 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
3993 \begin_layout LyX-Code
3994 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4000 \begin_layout LyX-Code
4001 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4004 \begin_layout Subsection
4005 Cross compiling SDCC on Linux for Windows
4008 \begin_layout Standard
4009 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4010 See section 'Configure Options'.
4013 \begin_layout Subsection
4014 Building SDCC using Cygwin and Mingw32
4017 \begin_layout Standard
4018 For building and installing a Cygwin executable follow the instructions
4024 \begin_inset Quotes sld
4028 \begin_inset Quotes srd
4031 Win32-binary can be built, which will not need the Cygwin-DLL.
4032 For the necessary 'configure' options see section 'configure options' or
4033 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4038 Cygwin on Windows download setup.exe from
4039 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4045 \begin_inset Quotes sld
4048 default text file type
4049 \begin_inset Quotes srd
4053 \begin_inset Quotes sld
4057 \begin_inset Quotes srd
4060 and download/install at least the following packages.
4061 Some packages are selected by default, others will be automatically selected
4062 because of dependencies with the manually selected packages.
4063 Never deselect these packages!
4066 \begin_layout Itemize
4070 \begin_layout Itemize
4074 \begin_layout Itemize
4075 gcc ; version 3.x is fine, no need to use the old 2.9x
4078 \begin_layout Itemize
4079 binutils ; selected with gcc
4082 \begin_layout Itemize
4086 \begin_layout Itemize
4087 rxvt ; a nice console, which makes life much easier under windoze (see below)
4090 \begin_layout Itemize
4091 man ; not really needed for building SDCC, but you'll miss it sooner or
4095 \begin_layout Itemize
4096 less ; not really needed for building SDCC, but you'll miss it sooner or
4100 \begin_layout Itemize
4101 svn ; only if you use Subversion access
4104 \begin_layout Standard
4105 If you want to develop something you'll need:
4108 \begin_layout Itemize
4109 python ; for the regression tests
4112 \begin_layout Itemize
4113 gdb ; the gnu debugger, together with the nice GUI
4114 \begin_inset Quotes sld
4118 \begin_inset Quotes srd
4124 \begin_layout Itemize
4125 openssh ; to access the CF or commit changes
4128 \begin_layout Itemize
4129 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4130 use autoconf-stable!
4133 \begin_layout Standard
4134 rxvt is a nice console with history.
4135 Replace in your cygwin.bat the line
4138 \begin_layout LyX-Code
4143 \begin_layout Standard
4155 \begin_layout Standard
4159 \begin_layout LyX-Code
4160 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4163 \begin_layout LyX-Code
4164 -bg black -fg white -geometry 100x65 -e bash -
4168 \begin_layout Standard
4180 \begin_layout Standard
4181 Text selected with the mouse is automatically copied to the clipboard, pasting
4182 works with shift-insert.
4186 The other good tip is to make sure you have no //c/-styl
4187 e paths anywhere, use /cygdrive/c/ instead.
4188 Using // invokes a network lookup which is very slow.
4190 \begin_inset Quotes sld
4194 \begin_inset Quotes srd
4197 is too long, you can change it with e.g.
4200 \begin_layout LyX-Code
4204 \begin_layout Standard
4205 SDCC sources use the unix line ending LF.
4206 Life is much easier, if you store the source tree on a drive which is mounted
4208 And use an editor which can handle LF-only line endings.
4209 Make sure not to commit files with windows line endings.
4210 The tabulator spacing
4211 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4215 used in the project is 8.
4216 Although a tabulator spacing of 8 is a sensible choice for programmers
4217 (it's a power of 2 and allows to display 8/16 bit signed variables without
4218 loosing columns) the plan is to move towards using only spaces in the source.
4221 \begin_layout Subsection
4222 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4225 \begin_layout Standard
4228 Download the source package
4230 either from the SDCC Subversion repository or from the
4231 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4237 , it will be named something like sdcc
4241 -yyyymmdd-rrrr.tar.bz2.
4244 SDCC is distributed with all the projects, workspaces, and files you need
4245 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4246 The workspace name is 'sdcc.dsw'.
4247 Please note that as it is now, all the executables are created in a folder
4251 Once built you need to copy the executables from sdcc
4255 bin before running SDCC.
4260 WARNING: Visual studio is very picky with line terminations; it expects
4261 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4262 When using the Subversion repository it's easiest to configure the svn
4263 client to convert automatically for you.
4264 If however you are getting a message such as "This makefile was not generated
4265 by Developer Studio etc.
4267 \begin_inset Quotes srd
4270 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4271 need to convert the Unix style line endings to DOS style line endings.
4272 To do so you can use the
4273 \begin_inset Quotes sld
4277 \begin_inset Quotes srd
4280 utility freely available on the internet.
4281 Doug Hawkins reported in the sdcc-user list that this works:
4289 SDCC> unix2dos sdcc.dsw
4295 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4299 In order to build SDCC with MSVC
4300 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4301 One good place to get them is
4302 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4310 Download the file UnxUtils
4311 \begin_inset LatexCommand \index{UnxUtils}
4316 Now you have to install the utilities and setup MSVC so it can locate the
4318 Here there are two alternatives (choose one!):
4321 \begin_layout Enumerate
4326 a) Extract UnxUtils.zip to your C:
4328 hard disk PRESERVING the original paths, otherwise bison won't work.
4329 (If you are using WinZip make certain that 'Use folder names' is selected)
4334 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4335 'Show directories for:' select 'Executable files', and in the directories
4336 window add a new path: 'C:
4346 (As a side effect, you get a bunch of Unix utilities that
4347 could be useful, such as diff and patch.)
4350 \begin_layout Enumerate
4355 This one avoids extracting a bunch of files you may not
4356 use, but requires some extra work:
4360 a) Create a directory were to put the
4361 tools needed, or use a directory already present.
4368 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4369 gawk.exe to such directory WITHOUT preserving the original paths.
4370 (If you are using WinZip make certain that 'Use folder names' is not selected)
4375 ) Rename bison.exe to '_bison.exe'.
4379 d) Create a batch file 'bison.bat' in 'C:
4383 ' and add these lines:
4403 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4407 Steps 'c' and 'd' are needed
4408 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4409 reside in some weird Unix directory, '/usr/local/share/' I think.
4410 So it is necessary to tell bison where those files are located if they
4411 are not in such directory.
4412 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4417 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4418 in 'Show directories for:' select 'Executable files', and in the directories
4419 window add a new path: 'c:
4422 Note that you can use any other path instead of 'c:
4424 util', even the path where the Visual C++ tools are, probably: 'C:
4428 Microsoft Visual Studio
4433 So you don't have to execute step 'e' :)
4436 \begin_layout Standard
4438 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4439 the executables from sdcc
4443 bin, and you can compile using SDCC.
4446 \begin_layout Subsection
4447 Building SDCC Using Borland
4450 \begin_layout Enumerate
4451 From the sdcc directory, run the command "make -f Makefile.bcc".
4452 This should regenerate all the .exe files in the bin directory except for
4456 \begin_layout Enumerate
4457 If you modify any source files and need to rebuild, be aware that the dependenci
4458 es may not be correctly calculated.
4459 The safest option is to delete all .obj files and run the build again.
4460 From a Cygwin BASH prompt, this can easily be done with the command (be
4461 sure you are in the sdcc directory):
4471 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4473 ) -print -exec rm {}
4482 or on Windows NT/2000/XP from the command prompt with the command:
4489 del /s *.obj *.lib *.rul
4492 from the sdcc directory.
4495 \begin_layout Subsection
4496 Windows Install Using a ZIP Package
4499 \begin_layout Enumerate
4500 Download the binary zip package from
4501 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4505 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4506 This should unpack to a group of sub-directories.
4507 An example directory structure after unpacking the mingw32 package is:
4512 bin for the executables, c:
4520 lib for the include and libraries.
4523 \begin_layout Enumerate
4524 Adjust your environment variable PATH to include the location of the bin
4525 directory or start sdcc using the full path.
4528 \begin_layout Subsection
4529 Windows Install Using the Setup Program
4530 \begin_inset LatexCommand \label{sub:Windows-Install}
4537 \begin_layout Standard
4538 Download the setup program
4540 sdcc-x.y.z-setup.exe
4542 for an official release from
4545 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4549 or a setup program for one of the snapshots
4551 sdcc-yyyymmdd-xxxx-setup.exe
4554 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4559 A windows typical installer will guide you through the installation process.
4562 \begin_layout Subsection
4564 \begin_inset LatexCommand \index{VPATH}
4571 \begin_layout Standard
4572 SDCC supports the VPATH feature provided by configure and make.
4573 It allows to separate the source and build trees.
4577 \begin_layout Standard
4604 \begin_layout Standard
4607 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4608 # extract source to directory sdcc
4611 \begin_layout Standard
4614 mkdir sdcc.build\InsetSpace ~
4623 # put output in sdcc.build
4626 \begin_layout Standard
4632 \begin_layout Standard
4635 ../sdcc/configure\InsetSpace ~
4643 # configure is doing all the magic!
4646 \begin_layout Standard
4652 \begin_layout Standard
4658 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4659 It automagically computes the variables srcdir, top_srcdir and top_buildir
4665 the generated files will be in ~/sdcc.build, while the source files stay
4668 This is not only usefull for building different binaries, e.g.
4669 when cross compiling.
4670 It also gives you a much better overview in the source tree when all the
4671 generated files are not scattered between the source files.
4672 And the best thing is: if you want to change a file you can leave the original
4673 file untouched in the source directory.
4674 Simply copy it to the build directory, edit it, enter `make clean', `rm
4675 Makefile.dep' and `make'.
4680 will do the rest for you!
4683 \begin_layout Section
4684 Building the Documentation
4687 \begin_layout Standard
4692 \begin_layout Standard
4701 -enable-doc to the configure arguments to build the documentation together
4702 with all the other stuff.
4703 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4704 dvips and makeindex) to get the job done.
4705 Another possibility is to change to the doc directory and to type
4709 \begin_inset Quotes srd
4713 \begin_inset Quotes srd
4720 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4723 \begin_inset LatexCommand \url{http://www.lyx.org}
4727 as editor is straightforward.
4728 Prebuilt documentation in html and pdf format is available from
4729 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4736 \begin_layout Section
4737 Reading the Documentation
4738 \begin_inset LatexCommand \index{Documentation}
4745 \begin_layout Standard
4746 Currently reading the document in pdf format is recommended, as for unknown
4747 reason the hyperlinks are working there whereas in the html version they
4752 \begin_layout Standard
4753 If you should know why please drop us a note
4761 You'll find the pdf version
4762 \begin_inset LatexCommand \index{PDF version of this document}
4767 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4775 \begin_inset LatexCommand \index{HTML version of this document}
4780 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4786 This documentation is in some aspects different from a commercial documentation:
4790 \begin_layout Itemize
4791 It tries to document SDCC for several processor architectures in one document
4792 (commercially these probably would be separate documents/products).
4794 \begin_inset LatexCommand \index{Status of documentation}
4798 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4800 Z80, PIC14, PIC16 and HC08.
4803 \begin_layout Itemize
4804 There are many references pointing away from this documentation.
4805 Don't let this distract you.
4807 was a reference like
4808 \begin_inset LatexCommand \url{http://www.opencores.org}
4812 together with a statement
4813 \begin_inset Quotes sld
4816 some processors which are targetted by SDCC can be implemented in a
4833 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4838 \begin_inset Quotes srd
4842 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4847 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4852 \begin_inset Quotes sld
4855 have you ever heard of an open source compiler that compiles a subset of
4857 \begin_inset Quotes srd
4860 we expect you to have a quick look there and come back.
4861 If you read this you are on the right track.
4864 \begin_layout Itemize
4865 Some sections attribute more space to problems, restrictions and warnings
4866 than to the solution.
4869 \begin_layout Itemize
4870 The installation section and the section about the debugger is intimidating.
4873 \begin_layout Itemize
4874 There are still lots of typos and there are more different writing styles
4878 \begin_layout Section
4879 Testing the SDCC Compiler
4880 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4887 \begin_layout Standard
4888 The first thing you should do after installing your SDCC compiler is to
4897 \begin_layout Standard
4907 \begin_inset LatexCommand \index{version}
4914 at the prompt, and the program should run and output its version like:
4919 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4923 \begin_layout Standard
4924 If it doesn't run, or gives a message about not finding sdcc program, then
4925 you need to check over your installation.
4926 Make sure that the sdcc bin directory is in your executable search path
4927 defined by the PATH environment setting (
4932 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4939 Install trouble-shooting for suggestions
4942 Make sure that the sdcc program is in the bin folder, if not perhaps something
4943 did not install correctly.
4951 is commonly installed as described in section
4952 \begin_inset Quotes sld
4955 Install and search paths
4956 \begin_inset Quotes srd
4965 Make sure the compiler works on a very simple example.
4966 Type in the following test.c program using your favorite
4991 \begin_layout Standard
4994 Compile this using the following command:
5003 If all goes well, the compiler will generate a test.asm and test.rel file.
5004 Congratulations, you've just compiled your first program with SDCC.
5005 We used the -c option to tell SDCC not to link the generated code, just
5006 to keep things simple for this step.
5014 The next step is to try it with the linker.
5024 If all goes well the compiler will link with the libraries and produce
5025 a test.ihx output file.
5030 (no test.ihx, and the linker generates warnings), then the problem is most
5039 usr/local/share/sdcc/lib directory
5046 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5053 Install trouble-shooting for suggestions).
5061 The final test is to ensure
5069 header files and libraries.
5070 Edit test.c and change it to the following:
5088 strcpy(str1, "testing");
5093 \begin_layout Standard
5096 Compile this by typing
5103 This should generate a test.ihx output file, and it should give no warnings
5104 such as not finding the string.h file.
5105 If it cannot find the string.h file, then the problem is that
5109 cannot find the /usr/local/share/sdcc/include directory
5116 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5123 Install trouble-shooting section for suggestions).
5132 \begin_layout Standard
5144 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5148 to find exactly where SDCC is looking for the include and lib files.
5151 \begin_layout Section
5152 Install Trouble-shooting
5153 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5158 \begin_inset LatexCommand \index{Install trouble-shooting}
5165 \begin_layout Subsection
5166 If SDCC does not build correctly
5169 \begin_layout Standard
5170 A thing to try is starting from scratch by unpacking the .tgz source package
5171 again in an empty directory.
5179 ./configure 2>&1 | tee configure.log
5193 make 2>&1 | tee make.log
5200 If anything goes wrong, you can review the log files to locate the problem.
5201 Or a relevant part of this can be attached to an email that could be helpful
5202 when requesting help from the mailing list.
5205 \begin_layout Subsection
5207 \begin_inset Quotes sld
5211 \begin_inset Quotes srd
5217 \begin_layout Standard
5219 \begin_inset Quotes sld
5223 \begin_inset Quotes srd
5226 command is a script that analyzes your system and performs some configuration
5227 to ensure the source package compiles on your system.
5228 It will take a few minutes to run, and will compile a few tests to determine
5229 what compiler features are installed.
5232 \begin_layout Subsection
5234 \begin_inset Quotes sld
5238 \begin_inset Quotes srd
5244 \begin_layout Standard
5245 This runs the GNU make tool, which automatically compiles all the source
5246 packages into the final installed binary executables.
5249 \begin_layout Subsection
5251 \begin_inset Quotes sld
5255 \begin_inset Quotes erd
5261 \begin_layout Standard
5262 This will install the compiler, other executables libraries and include
5263 files into the appropriate directories.
5265 \begin_inset LatexCommand \ref{sub:Install-paths}
5271 \begin_inset LatexCommand \ref{sub:Search-Paths}
5276 about install and search paths.
5278 On most systems you will need super-user privilege
5282 \begin_layout Section
5286 \begin_layout Standard
5287 SDCC is not just a compiler, but a collection of tools by various developers.
5288 These include linkers, assemblers, simulators and other components.
5289 Here is a summary of some of the components.
5290 Note that the included simulator and assembler have separate documentation
5291 which you can find in the source package in their respective directories.
5292 As SDCC grows to include support for other processors, other packages from
5293 various developers are included and may have their own sets of documentation.
5298 might want to look at the files which are installed in <installdir>.
5299 At the time of this writing, we find the following programs for gcc-builds:
5304 In <installdir>/bin:
5307 \begin_layout Itemize
5308 sdcc - The compiler.
5311 \begin_layout Itemize
5312 sdcpp - The C preprocessor.
5315 \begin_layout Itemize
5316 asx8051 - The assembler for 8051 type processors.
5319 \begin_layout Itemize
5324 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5327 \begin_layout Itemize
5328 aslink -The linker for 8051 type processors.
5331 \begin_layout Itemize
5336 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5339 \begin_layout Itemize
5340 s51 - The ucSim 8051 simulator.
5343 \begin_layout Itemize
5344 sdcdb - The source debugger.
5347 \begin_layout Itemize
5348 packihx - A tool to pack (compress) Intel hex files.
5351 \begin_layout Standard
5352 In <installdir>/share/sdcc/include
5355 \begin_layout Itemize
5359 \begin_layout Standard
5360 In <installdir>/share/sdcc/lib
5363 \begin_layout Itemize
5364 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5368 \begin_layout Standard
5369 In <installdir>/share/sdcc/doc
5372 \begin_layout Itemize
5376 \begin_layout Standard
5377 As development for other processors proceeds, this list will expand to include
5378 executables to support processors like AVR, PIC, etc.
5381 \begin_layout Subsection
5385 \begin_layout Standard
5386 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5387 the assembler and linkage editor.
5390 \begin_layout Subsection
5391 sdcpp - The C-Preprocessor
5394 \begin_layout Standard
5396 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5400 is a modified version of the GNU cpp
5401 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5406 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5411 The C preprocessor is used to pull in #include sources, process #ifdef
5412 statements, #defines and so on.
5415 \begin_layout Subsection
5424 - The Assemblers and Linkage Editors
5427 \begin_layout Standard
5428 This is retargettable assembler & linkage editor, it was developed by Alan
5430 John Hartman created the version for 8051, and I (Sandeep) have made some
5431 enhancements and bug fixes for it to work properly with SDCC.
5434 \begin_layout Subsection
5438 \begin_layout Standard
5440 \begin_inset LatexCommand \index{s51}
5444 is a free open source simulator developed by Daniel Drotos.
5445 The simulator is built as part of the build process.
5446 For more information visit Daniel's web site at:
5447 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5452 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5456 \begin_layout Subsection
5457 sdcdb - Source Level Debugger
5460 \begin_layout Standard
5462 \begin_inset LatexCommand \index{SDCDB (debugger)}
5466 is the companion source level debugger.
5467 More about SDCDB in section
5468 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5473 The current version of the debugger uses Daniel's Simulator S51
5474 \begin_inset LatexCommand \index{s51}
5478 , but can be easily changed to use other simulators.
5481 \begin_layout Chapter
5485 \begin_layout Section
5489 \begin_layout Subsection
5490 Single Source File Projects
5493 \begin_layout Standard
5494 For single source file 8051 projects the process is very simple.
5495 Compile your programs with the following command
5498 "sdcc sourcefile.c".
5502 This will compile, assemble and link your source file.
5503 Output files are as follows:
5506 \begin_layout Itemize
5508 \begin_inset LatexCommand \index{<file>.asm}
5513 \begin_inset LatexCommand \index{Assembler source}
5517 file created by the compiler
5520 \begin_layout Itemize
5522 \begin_inset LatexCommand \index{<file>.lst}
5527 \begin_inset LatexCommand \index{Assembler listing}
5531 file created by the Assembler
5534 \begin_layout Itemize
5536 \begin_inset LatexCommand \index{<file>.rst}
5541 \begin_inset LatexCommand \index{Assembler listing}
5545 file updated with linkedit information, created by linkage editor
5548 \begin_layout Itemize
5550 \begin_inset LatexCommand \index{<file>.sym}
5555 \begin_inset LatexCommand \index{Symbol listing}
5559 for the sourcefile, created by the assembler
5562 \begin_layout Itemize
5564 \begin_inset LatexCommand \index{<file>.rel}
5569 \begin_inset LatexCommand \index{<file>.o}
5574 \begin_inset LatexCommand \index{Object file}
5578 created by the assembler, input to Linkage editor
5581 \begin_layout Itemize
5583 \begin_inset LatexCommand \index{<file>.map}
5588 \begin_inset LatexCommand \index{Memory map}
5592 for the load module, created by the Linker
5595 \begin_layout Itemize
5597 \begin_inset LatexCommand \index{<file>.mem}
5601 - A file with a summary of the memory usage
5604 \begin_layout Itemize
5606 \begin_inset LatexCommand \index{<file>.ihx}
5610 - The load module in Intel hex format
5611 \begin_inset LatexCommand \index{Intel hex format}
5615 (you can select the Motorola S19 format
5616 \begin_inset LatexCommand \index{Motorola S19 format}
5624 \begin_layout Standard
5634 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5639 If you need another format you might want to use
5646 \begin_inset LatexCommand \index{objdump (tool)}
5657 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5662 \begin_inset Note Note
5665 \begin_layout Standard
5672 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5677 Both formats are documented in the documentation of srecord
5678 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5685 \begin_layout Itemize
5687 \begin_inset LatexCommand \index{<file>.adb}
5691 - An intermediate file containing debug information needed to create the
5696 \begin_layout Standard
5706 \begin_inset LatexCommand \index{-\/-debug}
5713 \begin_layout Itemize
5715 \begin_inset LatexCommand \index{<file>.cdb}
5719 - An optional file (with -
5723 \begin_layout Standard
5732 -debug) containing debug information.
5733 The format is documented in cdbfileformat.pdf
5736 \begin_layout Itemize
5739 \begin_inset LatexCommand \index{<file> (no extension)}
5743 An optional AOMF or AOMF51
5744 \begin_inset LatexCommand \index{AOMF, AOMF51}
5749 \begin_inset LatexCommand \label{OMF file}
5753 file containing debug information (generated with option -
5757 \begin_layout Standard
5783 ormat is a subformat of the OMF51 format and is commonly used by third party
5785 \begin_inset LatexCommand \index{Debugger}
5789 , simulators, emulators).
5792 \begin_layout Itemize
5794 \begin_inset LatexCommand \index{<file>.dump*}
5798 - Dump file to debug the compiler it self (generated with option -
5802 \begin_layout Standard
5811 -dumpall) (see section
5812 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5818 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5824 \begin_inset Quotes sld
5827 Anatomy of the compiler
5828 \begin_inset Quotes srd
5834 \begin_layout Subsection
5835 Postprocessing the Intel Hex
5836 \begin_inset LatexCommand \index{Intel hex format}
5841 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5848 \begin_layout Standard
5849 In most cases this won't be needed but the Intel Hex file
5850 \begin_inset LatexCommand \index{<file>.ihx}
5854 which is generated by SDCC might include lines of varying length and the
5855 addresses within the file are not guaranteed to be strictly ascending.
5856 If your toolchain or a bootloader does not like this you can use the tool
5862 \begin_inset LatexCommand \index{packihx (tool)}
5866 which is part of the SDCC distribution:
5873 packihx sourcefile.ihx >sourcefile.hex
5880 The separately available
5885 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5889 package additionally allows to set undefined locations to a predefined
5890 value, to insert checksums
5891 \begin_inset LatexCommand \index{checksum}
5895 of various flavours (crc, add, xor) and to perform other manipulations
5896 (convert, split, crop, offset, ...).
5904 srec_cat\InsetSpace ~
5906 sourcefile.ihx -intel\InsetSpace ~
5908 -o sourcefile.hex -intel
5915 An example for a more complex command line
5919 \begin_layout Standard
5920 the command backfills
5921 \begin_inset LatexCommand \index{backfill unused memory}
5925 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5927 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5928 will be interpreted as an
5936 (where an emergency routine could sit).
5949 srec_cat\InsetSpace ~
5950 sourcefile.ihx -intel\InsetSpace ~
5952 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5953 -little-endian-checksum-nega
5954 tive 0xfffe 0x02 0x02\InsetSpace ~
5956 -o sourcefile.hex -intel
5965 The srecord package is available at
5966 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5973 \begin_layout Subsection
5974 Projects with Multiple Source Files
5977 \begin_layout Standard
5978 SDCC can compile only ONE file at a time.
5979 Let us for example assume that you have a project containing the following
5984 foo1.c (contains some functions)
5986 foo2.c (contains some more functions)
5989 n.c (contains more functions and the function main)
5997 The first two files will need to be compiled separately with the commands:
6029 Then compile the source file containing the
6034 \begin_inset LatexCommand \index{Linker}
6038 the files together with the following command:
6046 foomain.c\InsetSpace ~
6047 foo1.rel\InsetSpace ~
6052 \begin_inset LatexCommand \index{<file>.rel}
6064 can be separately compiled as well:
6075 sdcc foomain.rel foo1.rel foo2.rel
6082 The file containing the
6097 file specified in the command line, since the linkage editor processes
6098 file in the order they are presented to it.
6099 The linker is invoked from SDCC using a script file with extension .lnk
6100 \begin_inset LatexCommand \index{<file>.lnk}
6105 You can view this file to troubleshoot linking problems such as those arising
6106 from missing libraries.
6109 \begin_layout Subsection
6110 Projects with Additional Libraries
6111 \begin_inset LatexCommand \index{Libraries}
6118 \begin_layout Standard
6119 Some reusable routines may be compiled into a library, see the documentation
6120 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6124 \begin_inset LatexCommand \index{<file>.lib}
6131 Libraries created in this manner can be included in the command line.
6132 Make sure you include the -L <library-path> option to tell the linker where
6133 to look for these files if they are not in the current directory.
6134 Here is an example, assuming you have the source file
6146 (if that is not the same as your current project):
6153 sdcc foomain.c foolib.lib -L mylib
6164 must be an absolute path name.
6168 The most efficient way to use libraries is
6169 to keep separate modules in separate source files.
6170 The lib file now should name all the modules.rel
6171 \begin_inset LatexCommand \index{<file>.rel}
6176 For an example see the standard library file
6180 in the directory <installdir>/share/lib/small.
6183 \begin_layout Subsection
6184 Using sdcclib to Create and Manage Libraries
6185 \begin_inset LatexCommand \index{sdcclib}
6192 \begin_layout Standard
6193 Alternatively, instead of having a .rel file for each entry on the library
6194 file as described in the preceding section, sdcclib can be used to embed
6195 all the modules belonging to such library in the library file itself.
6196 This results in a larger library file, but it greatly reduces the number
6197 of disk files accessed by the linker.
6198 Additionally, the packed library file contains an index of all include
6199 modules and symbols that significantly speeds up the linking process.
6200 To display a list of options supported by sdcclib type:
6205 \begin_layout Standard
6210 \begin_inset LatexCommand \index{sdcclib}
6221 To create a new library file, start by compiling all the required modules.
6227 \begin_layout Standard
6234 \begin_layout Standard
6241 \begin_layout Standard
6248 \begin_layout Standard
6255 \begin_layout Standard
6264 \begin_layout Standard
6265 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6267 The next step is to add the .rel files to the library file:
6272 \begin_layout Standard
6276 sdcclib libint.lib _divsint.rel
6279 \begin_inset LatexCommand \index{sdcclib}
6286 \begin_layout Standard
6290 sdcclib libint.lib _divuint.rel
6293 \begin_layout Standard
6297 sdcclib libint.lib _modsint.rel
6300 \begin_layout Standard
6304 sdcclib libint.lib _moduint.rel
6307 \begin_layout Standard
6311 sdcclib libint.lib _mulint.rel
6319 \begin_layout Standard
6328 \begin_layout Standard
6332 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6340 \begin_layout Standard
6341 If the file already exists in the library, it will be replaced.
6342 If a list of .rel files is available, you can tell sdcclib to add those
6344 For example, if the file 'myliblist.txt' contains
6352 \begin_layout Standard
6359 \begin_layout Standard
6366 \begin_layout Standard
6373 \begin_layout Standard
6380 \begin_layout Standard
6392 \begin_layout Standard
6401 \begin_layout Standard
6405 sdcclib -l libint.lib myliblist.txt
6413 \begin_layout Standard
6414 Additionally, you can instruct sdcclib to compiles the files before adding
6415 them to the library.
6416 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6425 \begin_layout Standard
6429 set SDCCLIB_CC=sdcc -c
6432 \begin_layout Standard
6436 sdcclib -l libint.lib myliblist.txt
6444 \begin_layout Standard
6445 To see what modules and symbols are included in the library, options -s
6446 and -m are available.
6454 sdcclib -s libint.lib
6457 \begin_inset LatexCommand \index{sdcclib}
6469 \begin_layout Standard
6475 \begin_layout Standard
6481 \begin_layout Standard
6489 \begin_layout Standard
6495 \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
6541 \begin_layout Standard
6547 \begin_layout Standard
6553 \begin_layout Standard
6559 \begin_layout Standard
6567 \begin_layout Standard
6573 \begin_layout Standard
6584 \begin_layout Standard
6585 If the source files are compiled using -
6589 \begin_layout Standard
6599 \begin_inset LatexCommand \index{-\/-debug}
6603 , the corresponding debug information file .adb will be include in the library
6605 The library files created with sdcclib are plain text files, so they can
6606 be viewed with a text editor.
6607 It is not recomended to modify a library file created with sdcclib using
6608 a text editor, as there are file indexes numbers located accross the file
6609 used by the linker to quickly locate the required module to link.
6610 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6611 it can be safely deleted, since all the information required for linking
6612 is embedded in the library file itself.
6613 Library files created using sdcclib are used as described in the preceding
6615 \begin_inset VSpace bigskip
6621 \begin_layout Section
6622 Command Line Options
6623 \begin_inset LatexCommand \index{Command Line Options}
6628 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6635 \begin_layout Subsection
6636 Processor Selection Options
6637 \begin_inset LatexCommand \index{Options processor selection}
6642 \begin_inset LatexCommand \index{Processor selection options}
6650 \labelwidthstring 00.00.0000
6654 \begin_inset LatexCommand \index{-mmcs51}
6660 Generate code for the Intel MCS51
6661 \begin_inset LatexCommand \index{MCS51}
6665 family of processors.
6666 This is the default processor target.
6670 \labelwidthstring 00.00.0000
6674 \begin_inset LatexCommand \index{-mds390}
6680 Generate code for the Dallas DS80C390
6681 \begin_inset LatexCommand \index{DS80C390}
6689 \labelwidthstring 00.00.0000
6693 \begin_inset LatexCommand \index{-mds400}
6699 Generate code for the Dallas DS80C400
6700 \begin_inset LatexCommand \index{DS80C400}
6708 \labelwidthstring 00.00.0000
6712 \begin_inset LatexCommand \index{-mhc08}
6718 Generate code for the Freescale/Motorola HC08
6719 \begin_inset LatexCommand \index{HC08}
6723 family of processors.
6727 \labelwidthstring 00.00.0000
6731 \begin_inset LatexCommand \index{-mz80}
6737 Generate code for the Zilog Z80
6738 \begin_inset LatexCommand \index{Z80}
6742 family of processors.
6746 \labelwidthstring 00.00.0000
6750 \begin_inset LatexCommand \index{-mgbz80}
6756 Generate code for the GameBoy Z80
6757 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6761 processor (Not actively maintained).
6765 \labelwidthstring 00.00.0000
6769 \begin_inset LatexCommand \index{-mavr}
6775 Generate code for the Atmel AVR
6776 \begin_inset LatexCommand \index{AVR}
6780 processor (Not maintained, not complete).
6781 AVR users should probably have a look at winavr
6782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6787 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6791 , which is based on AVR-port of the gcc compiler.
6794 \begin_layout Standard
6795 \begin_inset Note Note
6798 \begin_layout Standard
6799 I think it is fair to direct users there for now.
6800 Open source is also about avoiding unnecessary work .
6801 But I didn't find the 'official' link.
6810 \labelwidthstring 00.00.0000
6814 \begin_inset LatexCommand \index{-mpic14}
6820 Generate code for the Microchip PIC 14
6821 \begin_inset LatexCommand \index{PIC14}
6825 -bit processors (p16f84 and variants.
6826 In development, not complete).
6829 \begin_layout Standard
6830 \begin_inset Note Note
6833 \begin_layout Standard
6834 p16f627 p16f628 p16f84 p16f873 p16f877?
6843 \labelwidthstring 00.00.0000
6847 \begin_inset LatexCommand \index{-mpic16}
6853 Generate code for the Microchip PIC 16
6854 \begin_inset LatexCommand \index{PIC16}
6858 -bit processors (p18f452 and variants.
6859 In development, not complete).
6863 \labelwidthstring 00.00.0000
6868 Generate code for the Toshiba TLCS-900H
6869 \begin_inset LatexCommand \index{TLCS-900H}
6873 processor (Not maintained, not complete).
6877 \labelwidthstring 00.00.0000
6881 \begin_inset LatexCommand \index{-mxa51}
6887 Generate code for the Phillips XA51
6888 \begin_inset LatexCommand \index{XA51}
6892 processor (Not maintained, not complete).
6895 \begin_layout Standard
6896 \begin_inset VSpace bigskip
6902 \begin_layout Subsection
6903 Preprocessor Options
6904 \begin_inset LatexCommand \index{Options preprocessor}
6909 \begin_inset LatexCommand \index{Preprocessor options}
6914 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6922 \labelwidthstring 00.00.0000
6926 \begin_inset LatexCommand \index{-I<path>}
6932 The additional location where the preprocessor will look for <..h> or
6933 \begin_inset Quotes eld
6937 \begin_inset Quotes erd
6944 \labelwidthstring 00.00.0000
6948 \begin_inset LatexCommand \index{-D<macro[=value]>}
6954 Command line definition of macros.
6955 Passed to the preprocessor.
6959 \labelwidthstring 00.00.0000
6963 \begin_inset LatexCommand \index{-M}
6969 Tell the preprocessor to output a rule suitable for make describing the
6970 dependencies of each object file.
6971 For each source file, the preprocessor outputs one make-rule whose target
6972 is the object file name for that source file and whose dependencies are
6973 all the files `#include'd in it.
6974 This rule may be a single line or may be continued with `
6976 '-newline if it is long.
6977 The list of rules is printed on standard output instead of the preprocessed
6980 \begin_inset LatexCommand \index{-E}
6988 \labelwidthstring 00.00.0000
6992 \begin_inset LatexCommand \index{-C}
6998 Tell the preprocessor not to discard comments.
6999 Used with the `-E' option.
7003 \labelwidthstring 00.00.0000
7007 \begin_inset LatexCommand \index{-MM}
7018 Like `-M' but the output mentions only the user header files included with
7020 \begin_inset Quotes eld
7024 System header files included with `#include <file>' are omitted.
7028 \labelwidthstring 00.00.0000
7032 \begin_inset LatexCommand \index{-Aquestion(answer)}
7038 Assert the answer answer for question, in case it is tested with a preprocessor
7039 conditional such as `#if #question(answer)'.
7040 `-A-' disables the standard assertions that normally describe the target
7045 \labelwidthstring 00.00.0000
7049 \begin_inset LatexCommand \index{-Umacro}
7055 Undefine macro macro.
7056 `-U' options are evaluated after all `-D' options, but before any `-include'
7057 and `-imacros' options.
7061 \labelwidthstring 00.00.0000
7065 \begin_inset LatexCommand \index{-dM}
7071 Tell the preprocessor to output only a list of the macro definitions that
7072 are in effect at the end of preprocessing.
7073 Used with the `-E' option.
7077 \labelwidthstring 00.00.0000
7081 \begin_inset LatexCommand \index{-dD}
7087 Tell the preprocessor to pass all macro definitions into the output, in
7088 their proper sequence in the rest of the output.
7092 \labelwidthstring 00.00.0000
7096 \begin_inset LatexCommand \index{-dN}
7107 Like `-dD' except that the macro arguments and contents are omitted.
7108 Only `#define name' is included in the output.
7112 \labelwidthstring 00.00.0000
7115 -pedantic-parse-number
7116 \begin_inset LatexCommand \index{pedantic}
7121 \begin_inset LatexCommand \index{-pedantic-parse-number}
7129 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7137 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7138 and the macro LO_B(3) gets expanded.
7139 See also #pragma pedantic_parse_number
7140 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7145 \begin_inset LatexCommand \ref{sec:Pragmas}
7151 Note: this functionality is not in conformance with C99 standard!
7155 \labelwidthstring 00.00.0000
7159 preprocessorOption[,preprocessorOption]
7162 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7167 Pass the preprocessorOption to the preprocessor
7172 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7177 SDCC uses an adapted version of the preprocessor
7181 of the GNU Compiler Collection
7182 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7191 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7195 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7200 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7207 \begin_layout Standard
7208 \begin_inset VSpace bigskip
7214 \begin_layout Subsection
7216 \begin_inset LatexCommand \index{Options linker}
7221 \begin_inset LatexCommand \index{Linker options}
7229 \labelwidthstring 00.00.0000
7239 \begin_layout Standard
7251 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7256 \begin_inset LatexCommand \index{-L -\/-lib-path}
7263 <absolute path to additional libraries> This option is passed to the linkage
7264 editor's additional libraries
7265 \begin_inset LatexCommand \index{Libraries}
7270 The path name must be absolute.
7271 Additional library files may be specified in the command line.
7272 See section Compiling programs for more details.
7276 \labelwidthstring 00.00.0000
7283 \begin_layout Standard
7295 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7300 <Value> The start location of the external ram
7301 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7305 , default value is 0.
7306 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7310 \begin_layout Standard
7319 -xram-loc 0x8000 or -
7323 \begin_layout Standard
7336 \labelwidthstring 00.00.0000
7343 \begin_layout Standard
7355 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7360 <Value> The start location of the code
7361 \begin_inset LatexCommand \index{code}
7365 segment, default value 0.
7366 Note when this option is used the interrupt vector table
7367 \begin_inset LatexCommand \index{interrupt vector table}
7371 is also relocated to the given address.
7372 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7376 \begin_layout Standard
7385 -code-loc 0x8000 or -
7389 \begin_layout Standard
7402 \labelwidthstring 00.00.0000
7409 \begin_layout Standard
7421 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7426 <Value> By default the stack
7427 \begin_inset LatexCommand \index{stack}
7431 is placed after the data segment.
7432 Using this option the stack can be placed anywhere in the internal memory
7434 The value entered can be in Hexadecimal or Decimal format, e.g.
7439 \begin_layout Standard
7448 -stack-loc 0x20 or -
7452 \begin_layout Standard
7462 Since the sp register is incremented before a push or call, the initial
7463 sp will be set to one byte prior the provided value.
7464 The provided value should not overlap any other memory areas such as used
7465 register banks or the data segment and with enough space for the current
7473 \begin_layout Standard
7486 \begin_inset LatexCommand \index{-\/-pack-iram}
7490 option (which is now a default setting) will override this setting, so
7491 you should also specify the
7497 \begin_layout Standard
7510 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7514 option if you need to manually place the stack.
7518 \labelwidthstring 00.00.0000
7525 \begin_layout Standard
7537 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7542 <Value> By default the external stack
7543 \begin_inset LatexCommand \index{xstack}
7547 is placed after the pdata
7548 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7553 Using this option the xstack can be placed anywhere in the external memory
7555 The value entered can be in Hexadecimal or Decimal format, e.g.
7560 \begin_layout Standard
7569 -xstack-loc 0x8000 or -
7573 \begin_layout Standard
7583 The provided value should not overlap any other memory areas such as the
7584 pdata or xdata segment and with enough space for the current application.
7588 \labelwidthstring 00.00.0000
7595 \begin_layout Standard
7607 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7612 <Value> The start location of the internal ram data
7613 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7618 The value entered can be in Hexadecimal or Decimal format, eg.
7623 \begin_layout Standard
7636 \begin_layout Standard
7646 (By default, the start location of the internal ram data segment is set
7647 as low as possible in memory, taking into account the used register banks
7648 and the bit segment at address 0x20.
7649 For example if register banks 0 and 1 are used without bit variables, the
7650 data segment will be set, if -
7654 \begin_layout Standard
7663 -data-loc is not used, to location 0x10.)
7667 \labelwidthstring 00.00.0000
7674 \begin_layout Standard
7686 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7691 <Value> The start location of the indirectly addressable internal ram
7692 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7696 of the 8051, default value is 0x80.
7697 The value entered can be in Hexadecimal or Decimal format, eg.
7702 \begin_layout Standard
7711 -idata-loc 0x88 or -
7715 \begin_layout Standard
7728 \labelwidthstring 00.00.0000
7735 \begin_layout Standard
7747 <Value> The start location of the bit
7748 \begin_inset LatexCommand \index{bit}
7752 addressable internal ram of the 8051.
7758 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7763 \labelwidthstring 00.00.0000
7770 \begin_layout Standard
7780 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7789 The linker output (final object code) is in Intel Hex format.
7790 \begin_inset LatexCommand \index{Intel hex format}
7794 This is the default option.
7795 The format itself is documented in the documentation of srecord
7796 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7804 \labelwidthstring 00.00.0000
7811 \begin_layout Standard
7821 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7830 The linker output (final object code) is in Motorola S19 format
7831 \begin_inset LatexCommand \index{Motorola S19 format}
7836 The format itself is documented in the documentation of srecord.
7840 \labelwidthstring 00.00.0000
7847 \begin_layout Standard
7857 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7862 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7871 The linker output (final object code) is in ELF format
7872 \begin_inset LatexCommand \index{ELF format}
7877 (Currently only supported for the HC08
7878 \begin_inset LatexCommand \index{HC08}
7886 \labelwidthstring 00.00.0000
7890 linkOption[,linkOption]
7893 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7898 Pass the linkOption to the linker.
7899 If a bootloader is used an option like
7900 \begin_inset Quotes sld
7905 \begin_inset Quotes srd
7908 would be typical to set the start of the code segment.
7909 See also #pragma constseg and #pragma codeseg in section
7910 \begin_inset LatexCommand \ref{sec:Pragmas}
7915 File sdcc/as/doc/asxhtm.html has more on linker options.
7918 \begin_layout Standard
7919 \begin_inset VSpace bigskip
7925 \begin_layout Subsection
7927 \begin_inset LatexCommand \index{Options MCS51}
7932 \begin_inset LatexCommand \index{MCS51 options}
7940 \labelwidthstring 00.00.0000
7947 \begin_layout Standard
7957 \begin_inset LatexCommand \index{-\/-model-small}
7968 Generate code for Small Model programs, see section Memory Models for more
7970 This is the default model.
7974 \labelwidthstring 00.00.0000
7981 \begin_layout Standard
7991 \begin_inset LatexCommand \index{-\/-model-medium}
7997 Generate code for Medium model programs, see section Memory Models for
7999 If this option is used all source files in the project have to be compiled
8001 It must also be used when invoking the linker.
8005 \labelwidthstring 00.00.0000
8012 \begin_layout Standard
8022 \begin_inset LatexCommand \index{-\/-model-large}
8028 Generate code for Large model programs, see section Memory Models for more
8030 If this option is used all source files in the project have to be compiled
8032 It must also be used when invoking the linker.
8036 \labelwidthstring 00.00.0000
8043 \begin_layout Standard
8053 \begin_inset LatexCommand \index{-\/-xstack}
8059 Uses a pseudo stack in the pdata
8060 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8064 area (usually the first 256 bytes in the external ram) for allocating variables
8065 and passing parameters.
8067 \begin_inset LatexCommand \ref{sub:External-Stack}
8072 External Stack for more details.
8076 \labelwidthstring 00.00.0000
8083 \begin_layout Standard
8096 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8100 Causes the linker to check if the internal ram usage is within limits of
8105 \labelwidthstring 00.00.0000
8112 \begin_layout Standard
8125 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8129 Causes the linker to check if the external ram usage is within limits of
8134 \labelwidthstring 00.00.0000
8141 \begin_layout Standard
8154 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8158 Causes the linker to check if the code memory usage is within limits of
8163 \labelwidthstring 00.00.0000
8170 \begin_layout Standard
8183 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8187 Causes the linker to check if there is at minimum <Value> bytes for stack.
8191 \labelwidthstring 00.00.0000
8198 \begin_layout Standard
8211 \begin_inset LatexCommand \index{-\/-pack-iram}
8215 Causes the linker to use unused register banks for data variables and pack
8216 data, idata and stack together.
8217 This is the default now.
8221 \labelwidthstring 00.00.0000
8228 \begin_layout Standard
8241 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8245 Causes the linker to use old style for allocating memory areas.
8249 \labelwidthstring 00.00.0000
8256 \begin_layout Standard
8269 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8273 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8275 Only use this option if your code is in the same 2k block of memory.
8276 You may need to use this option for some 8051 derivatives which lack the
8277 lcall/ljmp instructions..
8280 \begin_layout Standard
8281 \begin_inset VSpace bigskip
8287 \begin_layout Subsection
8288 DS390 / DS400 Options
8289 \begin_inset LatexCommand \index{Options DS390}
8294 \begin_inset LatexCommand \index{DS390}
8302 \labelwidthstring 00.00.0000
8309 \begin_layout Standard
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8331 Generate 24-bit flat mode code.
8332 This is the one and only that the ds390 code generator supports right now
8333 and is default when using
8338 See section Memory Models for more details.
8342 \labelwidthstring 00.00.0000
8349 \begin_layout Standard
8359 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8365 disable interrupts during ESP:SP updates.
8369 \labelwidthstring 00.00.0000
8376 \begin_layout Standard
8388 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8392 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8393 This is the one and only that the ds390 code generator supports right now
8394 and is default when using
8399 In this mode, the stack is located in the lower 1K of the internal RAM,
8400 which is mapped to 0x400000.
8401 Note that the support is incomplete, since it still uses a single byte
8402 as the stack pointer.
8403 This means that only the lower 256 bytes of the potential 1K stack space
8404 will actually be used.
8405 However, this does allow you to reclaim the precious 256 bytes of low RAM
8406 for use for the DATA and IDATA segments.
8407 The compiler will not generate any code to put the processor into 10 bit
8409 It is important to ensure that the processor is in this mode before calling
8410 any re-entrant functions compiled with this option.
8411 In principle, this should work with the
8417 \begin_layout Standard
8427 \begin_inset LatexCommand \index{-\/-stack-auto}
8433 option, but that has not been tested.
8434 It is incompatible with the
8440 \begin_layout Standard
8450 \begin_inset LatexCommand \index{-\/-xstack}
8457 It also only makes sense if the processor is in 24 bit contiguous addressing
8464 \begin_layout Standard
8473 -model-flat24 option
8478 \begin_inset Note Note
8482 \labelwidthstring 00.00.0000
8489 \begin_layout Standard
8498 -stack-8-bit - switches off the 10-bit mode
8507 \labelwidthstring 00.00.0000
8514 \begin_layout Standard
8524 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8530 insert call to function __stack_probe at each function prologue.
8534 \labelwidthstring 00.00.0000
8541 \begin_layout Standard
8551 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8557 <nnnn> LibraryID used in -mTININative.
8562 \labelwidthstring 00.00.0000
8569 \begin_layout Standard
8579 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8585 generate code for DS390 Arithmetic Accelerator.
8589 \begin_layout Standard
8590 \begin_inset VSpace bigskip
8596 \begin_layout Subsection
8598 \begin_inset LatexCommand \index{Options Z80}
8603 \begin_inset LatexCommand \index{Z80}
8611 \labelwidthstring 00.00.0000
8618 \begin_layout Standard
8630 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8640 Force a called function to always save BC.
8644 \labelwidthstring 00.00.0000
8651 \begin_layout Standard
8663 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8667 When linking, skip the standard crt0.o object file.
8668 You must provide your own crt0.o for your system when linking.
8672 \labelwidthstring 00.00.0000
8679 \begin_layout Standard
8691 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8695 Determinate PORT I/O mode (<Value> is z80 or z180).
8699 \labelwidthstring 00.00.0000
8706 \begin_layout Standard
8718 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8722 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8726 \labelwidthstring 00.00.0000
8733 \begin_layout Standard
8746 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8750 Use <Value> for the code segment name.
8754 \labelwidthstring 00.00.0000
8761 \begin_layout Standard
8774 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8778 Use <Value> for the const segment name.
8782 \labelwidthstring 00.00.0000
8783 \begin_inset VSpace bigskip
8789 \begin_layout Subsection
8791 \begin_inset LatexCommand \index{Options GBZ80}
8796 \begin_inset LatexCommand \index{GBZ80}
8804 \labelwidthstring 00.00.0000
8811 \begin_layout Standard
8823 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8833 Force a called function to always save BC.
8837 \labelwidthstring 00.00.0000
8844 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8848 Use code bank <Num>.
8852 \labelwidthstring 00.00.0000
8859 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8863 Use data bank <Num>.
8867 \labelwidthstring 00.00.0000
8874 \begin_layout Standard
8887 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8891 Use <Value> for the code segment name.
8895 \labelwidthstring 00.00.0000
8902 \begin_layout Standard
8915 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8919 Use <Value> for the const segment name.
8922 \begin_layout Standard
8923 \begin_inset VSpace bigskip
8929 \begin_layout Subsection
8930 Optimization Options
8931 \begin_inset LatexCommand \index{Options optimization}
8936 \begin_inset LatexCommand \index{Optimization options}
8944 \labelwidthstring 00.00.0000
8951 \begin_layout Standard
8961 \begin_inset LatexCommand \index{-\/-nogcse}
8967 Will not do global subexpression elimination, this option may be used when
8968 the compiler creates undesirably large stack/data spaces to store compiler
8978 \begin_inset LatexCommand \index{sloc (spill location)}
8983 A warning message will be generated when this happens and the compiler
8984 will indicate the number of extra bytes it allocated.
8985 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8987 \begin_inset LatexCommand \index{\#pragma nogcse}
8991 can be used to turn off global subexpression elimination
8992 \begin_inset LatexCommand \index{Subexpression elimination}
8996 for a given function only.
9000 \labelwidthstring 00.00.0000
9007 \begin_layout Standard
9017 \begin_inset LatexCommand \index{-\/-noinvariant}
9023 Will not do loop invariant optimizations, this may be turned off for reasons
9024 explained for the previous option.
9025 For more details of loop optimizations performed see Loop Invariants in
9027 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9032 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9034 \begin_inset LatexCommand \index{\#pragma noinvariant}
9038 can be used to turn off invariant optimizations for a given function only.
9042 \labelwidthstring 00.00.0000
9049 \begin_layout Standard
9059 \begin_inset LatexCommand \index{-\/-noinduction}
9065 Will not do loop induction optimizations, see section strength reduction
9067 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9069 \begin_inset LatexCommand \index{\#pragma noinduction}
9073 can be used to turn off induction optimizations for a given function only.
9077 \labelwidthstring 00.00.0000
9084 \begin_layout Standard
9094 \begin_inset LatexCommand \index{-\/-nojtbound}
9105 Will not generate boundary condition check when switch statements
9106 \begin_inset LatexCommand \index{switch statement}
9110 are implemented using jump-tables.
9112 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9117 Switch Statements for more details.
9118 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9120 \begin_inset LatexCommand \index{\#pragma nojtbound}
9124 can be used to turn off boundary checking for jump tables for a given function
9129 \labelwidthstring 00.00.0000
9136 \begin_layout Standard
9146 \begin_inset LatexCommand \index{-\/-noloopreverse}
9155 Will not do loop reversal
9156 \begin_inset LatexCommand \index{Loop reversing}
9164 \labelwidthstring 00.00.0000
9169 \begin_layout Standard
9183 \begin_inset LatexCommand \index{-\/-nolabelopt }
9187 Will not optimize labels (makes the dumpfiles more readable).
9191 \labelwidthstring 00.00.0000
9198 \begin_layout Standard
9208 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9214 Will not memcpy initialized data from code space into xdata space.
9215 This saves a few bytes in code space if you don't have initialized data
9216 \begin_inset LatexCommand \index{Variable initialization}
9224 \labelwidthstring 00.00.0000
9231 \begin_layout Standard
9241 \begin_inset LatexCommand \index{-\/-nooverlay}
9247 The compiler will not overlay parameters and local variables of any function,
9248 see section Parameters and local variables for more details.
9252 \labelwidthstring 00.00.0000
9259 \begin_layout Standard
9269 \begin_inset LatexCommand \index{-\/-no-peep}
9275 Disable peep-hole optimization with built-in rules.
9279 \labelwidthstring 00.00.0000
9286 \begin_layout Standard
9298 \begin_inset LatexCommand \index{-\/-peep-file}
9303 <filename> This option can be used to use additional rules to be used by
9304 the peep hole optimizer.
9306 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9311 Peep Hole optimizations for details on how to write these rules.
9315 \labelwidthstring 00.00.0000
9322 \begin_layout Standard
9332 \begin_inset LatexCommand \index{-\/-peep-asm}
9338 Pass the inline assembler code through the peep hole optimizer.
9339 This can cause unexpected changes to inline assembler code, please go through
9340 the peephole optimizer
9341 \begin_inset LatexCommand \index{Peephole optimizer}
9345 rules defined in the source file tree '<target>/peeph.def' before using
9350 \labelwidthstring 00.00.0000
9357 \begin_layout Standard
9367 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9373 The compiler will optimize code generation towards fast code, possibly
9374 at the expense of code size.
9378 \labelwidthstring 00.00.0000
9385 \begin_layout Standard
9395 \begin_inset LatexCommand \index{-\/-opt-code-size}
9401 The compiler will optimize code generation towards compact code, possibly
9402 at the expense of code speed.
9405 \begin_layout Standard
9406 \begin_inset VSpace bigskip
9412 \begin_layout Subsection
9414 \begin_inset LatexCommand \index{Options other}
9422 \labelwidthstring 00.00.0000
9430 \begin_layout Standard
9440 \begin_inset LatexCommand \index{-\/-compile-only}
9445 \begin_inset LatexCommand \index{-c -\/-compile-only}
9451 will compile and assemble the source, but will not call the linkage editor.
9455 \labelwidthstring 00.00.0000
9464 \begin_layout Standard
9476 \begin_inset LatexCommand \index{-\/-c1mode}
9482 reads the preprocessed source from standard input and compiles it.
9483 The file name for the assembler output must be specified using the -o option.
9487 \labelwidthstring 00.00.0000
9491 \begin_inset LatexCommand \index{-E}
9497 Run only the C preprocessor.
9498 Preprocess all the C source files specified and output the results to standard
9503 \labelwidthstring 00.00.0000
9508 \begin_inset LatexCommand \index{-o <path/file>}
9514 The output path where everything will be placed or the file name used for
9515 all generated output files.
9516 If the parameter is a path, it must have a trailing slash (or backslash
9517 for the Windows binaries) to be recognized as a path.
9522 Note for Windows users: if the path contains spaces, it should be surrounded
9524 The trailing backslash should be doubled in order to prevent escaping the
9525 final quote, for example:
9528 \begin_inset Quotes sld
9542 \begin_inset Quotes srd
9547 or put after the final quote, for example:
9550 \begin_inset Quotes sld
9560 \begin_inset Quotes srd
9568 The path using slashes for directory delimiters can be used too, for example:
9572 \begin_inset Quotes sld
9575 F:/Projects/test3/output 1/
9576 \begin_inset Quotes srd
9585 \labelwidthstring 00.00.0000
9592 \begin_layout Standard
9602 \begin_inset LatexCommand \index{-\/-stack-auto}
9613 All functions in the source file will be compiled as
9618 \begin_inset LatexCommand \index{reentrant}
9623 the parameters and local variables will be allocated on the stack
9624 \begin_inset LatexCommand \index{stack}
9630 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9634 Parameters and Local Variables for more details.
9635 If this option is used all source files in the project should be compiled
9637 It automatically implies -
9643 \begin_layout Standard
9654 -int-long-reent and -
9660 \begin_layout Standard
9676 \labelwidthstring 00.00.0000
9683 \begin_layout Standard
9693 \begin_inset LatexCommand \index{-\/-callee-saves}
9698 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9702 function1[,function2][,function3]....
9705 The compiler by default uses a caller saves convention for register saving
9706 across function calls, however this can cause unnecessary register pushing
9707 and popping when calling small functions from larger functions.
9708 This option can be used to switch the register saving convention for the
9709 function names specified.
9710 The compiler will not save registers when calling these functions, no extra
9711 code will be generated at the entry and exit (function prologue
9714 \begin_inset LatexCommand \index{function prologue}
9723 \begin_inset LatexCommand \index{function epilogue}
9729 ) for these functions to save and restore the registers used by these functions,
9730 this can SUBSTANTIALLY reduce code and improve run time performance of
9732 In the future the compiler (with inter procedural analysis) will be able
9733 to determine the appropriate scheme to use for each function call.
9734 DO NOT use this option for built-in functions such as _mulint..., if this
9735 option is used for a library function the appropriate library function
9736 needs to be recompiled with the same option.
9737 If the project consists of multiple source files then all the source file
9738 should be compiled with the same -
9742 \begin_layout Standard
9751 -callee-saves option string.
9752 Also see #pragma\InsetSpace ~
9754 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9759 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9767 \labelwidthstring 00.00.0000
9774 \begin_layout Standard
9784 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9798 \begin_layout Standard
9807 -callee-saves will be applied to all functions by default.
9811 \labelwidthstring 00.00.0000
9818 \begin_layout Standard
9828 \begin_inset LatexCommand \index{-\/-debug}
9837 When this option is used the compiler will generate debug information.
9838 The debug information collected in a file with .cdb extension can be used
9840 For more information see documentation for SDCDB.
9841 Another file with no extension contains debug information in AOMF or AOMF51
9842 \begin_inset LatexCommand \index{AOMF, AOMF51}
9846 format which is commonly used by third party tools.
9850 \labelwidthstring 00.00.0000
9854 \begin_inset LatexCommand \index{-S}
9865 Stop after the stage of compilation proper; do not assemble.
9866 The output is an assembler code file for the input file specified.
9870 \labelwidthstring 00.00.0000
9877 \begin_layout Standard
9887 \begin_inset LatexCommand \index{-\/-int-long-reent}
9893 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9894 Note by default these libraries are compiled as non-reentrant.
9895 See section Installation for more details.
9899 \labelwidthstring 00.00.0000
9906 \begin_layout Standard
9916 \begin_inset LatexCommand \index{-\/-cyclomatic}
9925 This option will cause the compiler to generate an information message for
9926 each function in the source file.
9927 The message contains some
9931 information about the function.
9932 The number of edges and nodes the compiler detected in the control flow
9933 graph of the function, and most importantly the
9935 cyclomatic complexity
9936 \begin_inset LatexCommand \index{Cyclomatic complexity}
9942 see section on Cyclomatic Complexity for more details.
9946 \labelwidthstring 00.00.0000
9953 \begin_layout Standard
9963 \begin_inset LatexCommand \index{-\/-float-reent}
9969 Floating point library is compiled as reentrant
9970 \begin_inset LatexCommand \index{reentrant}
9975 See section Installation for more details.
9979 \labelwidthstring 00.00.0000
9986 \begin_layout Standard
9996 \begin_inset LatexCommand \index{-\/-funsigned-char}
10002 The default signedness for every type is
10007 In some embedded environments the default signedness of
10016 To set the signess for characters to unsigned, use the option -
10022 \begin_layout Standard
10034 If this option is set and no signedness keyword (unsigned/signed) is given,
10035 a char will be signed.
10036 All other types are unaffected.
10040 \labelwidthstring 00.00.0000
10047 \begin_layout Standard
10057 \begin_inset LatexCommand \index{-\/-main-return}
10063 This option can be used if the code generated is called by a monitor program
10064 or if the main routine includes an endless loop.
10065 This option results in slightly smaller code and saves two bytes of stack
10067 The return from the 'main'
10068 \begin_inset LatexCommand \index{main return}
10072 function will return to the function calling main.
10073 The default setting is to lock up i.e.
10082 \labelwidthstring 00.00.0000
10089 \begin_layout Standard
10099 \begin_inset LatexCommand \index{-\/-nostdinc}
10105 This will prevent the compiler from passing on the default include path
10106 to the preprocessor.
10110 \labelwidthstring 00.00.0000
10117 \begin_layout Standard
10127 \begin_inset LatexCommand \index{-\/-nostdlib}
10133 This will prevent the compiler from passing on the default library
10134 \begin_inset LatexCommand \index{Libraries}
10138 path to the linker.
10142 \labelwidthstring 00.00.0000
10149 \begin_layout Standard
10159 \begin_inset LatexCommand \index{-\/-verbose}
10165 Shows the various actions the compiler is performing.
10169 \labelwidthstring 00.00.0000
10173 \begin_inset LatexCommand \index{-V}
10179 Shows the actual commands the compiler is executing.
10183 \labelwidthstring 00.00.0000
10190 \begin_layout Standard
10200 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10206 Hides your ugly and inefficient c-code from the asm file, so you can always
10207 blame the compiler :)
10211 \labelwidthstring 00.00.0000
10218 \begin_layout Standard
10228 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10234 Include code generator and peep-hole comments in the generated asm files.
10238 \labelwidthstring 00.00.0000
10245 \begin_layout Standard
10255 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10261 Don't include peep-hole comments in the generated asm files even if -
10267 \begin_layout Standard
10278 -fverbose-asm option is specified.
10282 \labelwidthstring 00.00.0000
10289 \begin_layout Standard
10299 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10305 Include i-codes in the asm file.
10306 Sounds like noise but is most helpful for debugging the compiler itself.
10310 \labelwidthstring 00.00.0000
10317 \begin_layout Standard
10327 \begin_inset LatexCommand \index{pedantic}
10332 \begin_inset LatexCommand \index{-\/-less-pedantic}
10339 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10343 Disable some of the more pedantic warnings
10344 \begin_inset LatexCommand \index{Warnings}
10349 For more details, see the less_pedantic pragma
10350 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10358 \labelwidthstring 00.00.0000
10365 \begin_layout Standard
10374 -disable-warning\InsetSpace ~
10376 \begin_inset LatexCommand \index{-\/-disable-warning}
10382 Disable specific warning with number <nnnn>.
10386 \labelwidthstring 00.00.0000
10393 \begin_layout Standard
10403 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10409 Display the directories in the compiler's search path
10413 \labelwidthstring 00.00.0000
10420 \begin_layout Standard
10430 \begin_inset LatexCommand \index{-\/-vc}
10436 Display errors and warnings using MSVC style, so you can use SDCC with
10437 the visual studio IDE
10438 \begin_inset LatexCommand \index{IDE}
10443 With SDCC both offering a GCC-like (the default) and a MSVC-like
10444 \begin_inset LatexCommand \index{MSVC output style}
10448 output style, integration into most programming editors should be straightforwa
10453 \labelwidthstring 00.00.0000
10460 \begin_layout Standard
10470 \begin_inset LatexCommand \index{-\/-use-stdout}
10476 Send errors and warnings to stdout instead of stderr.
10480 \labelwidthstring 00.00.0000
10484 asmOption[,asmOption]
10487 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10492 Pass the asmOption to the assembler
10493 \begin_inset LatexCommand \index{Options assembler}
10498 \begin_inset LatexCommand \index{Assembler options}
10503 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10507 \labelwidthstring 00.00.0000
10514 \begin_layout Standard
10524 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10530 Generally follow the C89 standard, but allow SDCC features that conflict
10531 with the standard (default).
10535 \labelwidthstring 00.00.0000
10542 \begin_layout Standard
10552 \begin_inset LatexCommand \index{-\/-std-c89}
10558 Follow the C89 standard and disable SDCC features that conflict with the
10563 \labelwidthstring 00.00.0000
10570 \begin_layout Standard
10580 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10586 Generally follow the C99 standard, but allow SDCC features that conflict
10587 with the standard (incomplete support).
10591 \labelwidthstring 00.00.0000
10598 \begin_layout Standard
10608 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10614 Follow the C99 standard and disable SDCC features that conflict with the
10615 standard (incomplete support).
10619 \labelwidthstring 00.00.0000
10626 \begin_layout Standard
10638 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10643 <Name> The name to be used for the code
10644 \begin_inset LatexCommand \index{code}
10648 segment, default CSEG.
10649 This is useful if you need to tell the compiler to put the code in a special
10650 segment so you can later on tell the linker to put this segment in a special
10652 Can be used for instance when using bank switching to put the code in a
10657 \labelwidthstring 00.00.0000
10664 \begin_layout Standard
10676 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10681 <Name> The name to be used for the const
10682 \begin_inset LatexCommand \index{const}
10686 segment, default CONST.
10687 This is useful if you need to tell the compiler to put the const data in
10688 a special segment so you can later on tell the linker to put this segment
10689 in a special place in memory.
10690 Can be used for instance when using bank switching to put the const data
10695 \labelwidthstring 00.00.0000
10702 \begin_layout Standard
10711 -fdollars-in-identifiers
10712 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10718 Permit '$' as an identifier character.
10722 \labelwidthstring 00.00.0000
10729 \begin_layout Standard
10741 \begin_inset LatexCommand \index{-\/-more-pedantic}
10746 \begin_inset LatexCommand \index{pedantic}
10756 a SDCC compiler option but if you want
10760 warnings you can use a separate tool dedicated to syntax checking like
10762 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10767 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10772 \begin_inset LatexCommand \url{http://www.splint.org}
10777 To make your source files parseable by splint you will have to include
10783 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10787 in your source file and add brackets around extended keywords (like
10790 \begin_inset Quotes sld
10803 \begin_inset Quotes srd
10811 \begin_inset Quotes sld
10814 __interrupt\InsetSpace ~
10816 \begin_inset Quotes srd
10824 Splint has an excellent on line manual at
10825 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10829 and it's capabilities go beyond pure syntax checking.
10830 You'll need to tell splint the location of SDCC's include files so a typical
10831 command line could look like this:
10835 splint\InsetSpace ~
10837 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10843 \labelwidthstring 00.00.0000
10850 \begin_layout Standard
10862 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10867 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10871 Treat short as 8-bit (for backward compatibility with older versions of
10872 compiler - see section
10873 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10880 \begin_layout Standard
10881 \begin_inset VSpace bigskip
10887 \begin_layout Subsection
10888 Intermediate Dump Options
10889 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10894 \begin_inset LatexCommand \index{Options intermediate dump}
10899 \begin_inset LatexCommand \index{Intermediate dump options}
10906 \begin_layout Standard
10907 The following options are provided for the purpose of retargetting and debugging
10909 They provide a means to dump the intermediate code (iCode
10910 \begin_inset LatexCommand \index{iCode}
10914 ) generated by the compiler in human readable form at various stages of
10915 the compilation process.
10916 More on iCodes see chapter
10917 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10922 \begin_inset Quotes srd
10925 The anatomy of the compiler
10926 \begin_inset Quotes srd
10933 \labelwidthstring 00.00.0000
10940 \begin_layout Standard
10950 \begin_inset LatexCommand \index{-\/-dumpraw}
10956 This option will cause the compiler to dump the intermediate code into
10959 <source filename>.dumpraw
10961 just after the intermediate code has been generated for a function, i.e.
10962 before any optimizations are done.
10964 \begin_inset LatexCommand \index{Basic blocks}
10968 at this stage ordered in the depth first number, so they may not be in
10969 sequence of execution.
10973 \labelwidthstring 00.00.0000
10980 \begin_layout Standard
10990 \begin_inset LatexCommand \index{-\/-dumpgcse}
10996 Will create a dump of iCodes, after global subexpression elimination
10997 \begin_inset LatexCommand \index{Global subexpression elimination}
11001 , into a file named
11003 <source filename>.dumpgcse.
11007 \labelwidthstring 00.00.0000
11014 \begin_layout Standard
11024 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11030 Will create a dump of iCodes, after deadcode elimination
11031 \begin_inset LatexCommand \index{Dead-code elimination}
11035 , into a file named
11037 <source filename>.dumpdeadcode.
11041 \labelwidthstring 00.00.0000
11048 \begin_layout Standard
11058 \begin_inset LatexCommand \index{-\/-dumploop}
11067 Will create a dump of iCodes, after loop optimizations
11068 \begin_inset LatexCommand \index{Loop optimization}
11072 , into a file named
11074 <source filename>.dumploop.
11078 \labelwidthstring 00.00.0000
11085 \begin_layout Standard
11095 \begin_inset LatexCommand \index{-\/-dumprange}
11104 Will create a dump of iCodes, after live range analysis
11105 \begin_inset LatexCommand \index{Live range analysis}
11109 , into a file named
11111 <source filename>.dumprange.
11115 \labelwidthstring 00.00.0000
11122 \begin_layout Standard
11132 \begin_inset LatexCommand \index{-\/-dumlrange}
11138 Will dump the life ranges
11139 \begin_inset LatexCommand \index{Live range analysis}
11147 \labelwidthstring 00.00.0000
11154 \begin_layout Standard
11164 \begin_inset LatexCommand \index{-\/-dumpregassign}
11173 Will create a dump of iCodes, after register assignment
11174 \begin_inset LatexCommand \index{Register assignment}
11178 , into a file named
11180 <source filename>.dumprassgn.
11184 \labelwidthstring 00.00.0000
11191 \begin_layout Standard
11201 \begin_inset LatexCommand \index{-\/-dumplrange}
11207 Will create a dump of the live ranges of iTemp's
11211 \labelwidthstring 00.00.0000
11218 \begin_layout Standard
11228 \begin_inset LatexCommand \index{-\/-dumpall}
11239 Will cause all the above mentioned dumps to be created.
11242 \begin_layout Standard
11243 \begin_inset VSpace bigskip
11249 \begin_layout Subsection
11250 Redirecting output on Windows Shells
11253 \begin_layout Standard
11254 By default SDCC writes its error messages to
11255 \begin_inset Quotes sld
11259 \begin_inset Quotes srd
11263 To force all messages to
11264 \begin_inset Quotes sld
11268 \begin_inset Quotes srd
11280 \begin_layout Standard
11295 \begin_inset LatexCommand \index{-\/-use-stdout}
11300 Additionally, if you happen to have visual studio installed in your windows
11301 machine, you can use it to compile your sources using a custom build and
11308 \begin_layout Standard
11320 \begin_inset LatexCommand \index{-\/-vc}
11325 Something like this should work:
11344 \begin_layout Standard
11363 \begin_layout Standard
11375 -model-large -c $(InputPath)
11378 \begin_inset VSpace bigskip
11384 \begin_layout Section
11385 Environment variables
11386 \begin_inset LatexCommand \index{Environment variables}
11393 \begin_layout Standard
11394 SDCC recognizes the following environment variables:
11398 \labelwidthstring 00.00.0000
11402 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11408 SDCC installs a signal handler
11409 \begin_inset LatexCommand \index{signal handler}
11413 to be able to delete temporary files after an user break (^C) or an exception.
11414 If this environment variable is set, SDCC won't install the signal handler
11415 in order to be able to debug SDCC.
11419 \labelwidthstring 00.00.0000
11425 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11431 Path, where temporary files will be created.
11432 The order of the variables is the search order.
11433 In a standard *nix environment these variables are not set, and there's
11434 no need to set them.
11435 On Windows it's recommended to set one of them.
11439 \labelwidthstring 00.00.0000
11443 \begin_inset LatexCommand \index{SDCC\_HOME}
11450 \begin_inset LatexCommand \ref{sub:Install-paths}
11456 \begin_inset Quotes sld
11460 \begin_inset Quotes srd
11467 \labelwidthstring 00.00.0000
11471 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11478 \begin_inset LatexCommand \ref{sub:Search-Paths}
11484 \begin_inset Quotes sld
11488 \begin_inset Quotes srd
11495 \labelwidthstring 00.00.0000
11499 \begin_inset LatexCommand \index{SDCC\_LIB}
11506 \begin_inset LatexCommand \ref{sub:Search-Paths}
11512 \begin_inset Quotes sld
11516 \begin_inset Quotes srd
11522 \begin_layout Standard
11523 There are some more environment variables recognized by SDCC, but these
11524 are solely used for debugging purposes.
11525 They can change or disappear very quickly, and will never be documented.
11526 \begin_inset VSpace bigskip
11532 \begin_layout Section
11533 Storage Class Language Extensions
11536 \begin_layout Subsection
11537 MCS51/DS390 Storage Class
11538 \begin_inset LatexCommand \index{Storage class}
11542 Language Extensions
11545 \begin_layout Standard
11546 In addition to the ANSI storage classes SDCC allows the following MCS51
11547 specific storage classes:
11550 \begin_layout Subsubsection
11552 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11557 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11562 \begin_inset LatexCommand \index{near (storage class)}
11567 \begin_inset LatexCommand \index{\_\_near (storage class)}
11574 \begin_layout Standard
11579 storage class for the Small Memory model (
11587 or the more ANSI-C compliant forms
11595 can be used synonymously).
11596 Variables declared with this storage class will be allocated in the directly
11597 addressable portion of the internal RAM of a 8051, e.g.:
11600 \begin_layout Verse
11603 __data unsigned char test_data;
11606 \begin_layout Standard
11607 Writing 0x01 to this variable generates the assembly code:
11610 \begin_layout Verse
11613 75*00 01\InsetSpace ~
11621 \begin_layout Subsubsection
11623 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11628 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11633 \begin_inset LatexCommand \index{far (storage class)}
11638 \begin_inset LatexCommand \index{\_\_far (storage class)}
11645 \begin_layout Standard
11646 Variables declared with this storage class will be placed in the external
11652 storage class for the Large Memory model, e.g.:
11655 \begin_layout Verse
11658 __xdata unsigned char test_xdata;
11661 \begin_layout Standard
11662 Writing 0x01 to this variable generates the assembly code:
11665 \begin_layout Verse
11668 90s00r00\InsetSpace ~
11699 \begin_layout Subsubsection
11701 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11706 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11713 \begin_layout Standard
11714 Variables declared with this storage class will be allocated into the indirectly
11715 addressable portion of the internal ram of a 8051, e.g.:
11718 \begin_layout Verse
11721 __idata unsigned char test_idata;
11724 \begin_layout Standard
11725 Writing 0x01 to this variable generates the assembly code:
11728 \begin_layout Verse
11755 \begin_layout Standard
11756 Please note, the first 128 byte of idata physically access the same RAM
11757 as the data memory.
11758 The original 8051 had 128 byte idata memory, nowadays most devices have
11759 256 byte idata memory.
11761 \begin_inset LatexCommand \index{stack}
11765 is located in idata memory.
11768 \begin_layout Subsubsection
11770 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11775 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11782 \begin_layout Standard
11783 Paged xdata access is just as straightforward as using the other addressing
11785 It is typically located at the start of xdata and has a maximum size of
11787 The following example writes 0x01 to the pdata variable.
11788 Please note, pdata access physically accesses xdata memory.
11789 The high byte of the address is determined by port P2
11790 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11794 (or in case of some 8051 variants by a separate Special Function Register,
11796 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11805 storage class for the Medium Memory model, e.g.:
11808 \begin_layout Verse
11811 __pdata unsigned char test_pdata;
11814 \begin_layout Standard
11815 Writing 0x01 to this variable generates the assembly code:
11818 \begin_layout Verse
11827 mov r0,#_test_pdata
11849 \begin_layout Standard
11854 \begin_layout Standard
11864 \begin_inset LatexCommand \index{-\/-xstack}
11868 option is used the pdata memory area is followed by the xstack memory area
11869 and the sum of their sizes is limited to 256 bytes.
11872 \begin_layout Subsubsection
11874 \begin_inset LatexCommand \index{code}
11879 \begin_inset LatexCommand \index{\_\_code}
11886 \begin_layout Standard
11887 'Variables' declared with this storage class will be placed in the code
11891 \begin_layout Verse
11894 __code unsigned char test_code;
11897 \begin_layout Standard
11898 Read access to this variable generates the assembly code:
11901 \begin_layout Verse
11904 90s00r6F\InsetSpace ~
11907 mov dptr,#_test_code
11932 \begin_layout Standard
11937 indexed arrays of characters in code memory can be accessed efficiently:
11940 \begin_layout Verse
11943 __code char test_array[] = {'c','h','e','a','p'};
11946 \begin_layout Standard
11947 Read access to this array using an 8-bit unsigned index generates the assembly
11951 \begin_layout Verse
11963 \begin_layout Verse
11966 90s00r41\InsetSpace ~
11969 mov dptr,#_test_array
11972 \begin_layout Verse
11987 \begin_layout Subsubsection
11989 \begin_inset LatexCommand \index{bit}
11994 \begin_inset LatexCommand \index{\_\_bit}
12001 \begin_layout Standard
12002 This is a data-type and a storage class specifier.
12003 When a variable is declared as a bit, it is allocated into the bit addressable
12004 memory of 8051, e.g.:
12007 \begin_layout Verse
12013 \begin_layout Standard
12014 Writing 1 to this variable generates the assembly code:
12017 \begin_layout Verse
12031 \begin_layout Standard
12032 The bit addressable memory consists of 128 bits which are located from 0x20
12033 to 0x2f in data memory.
12036 Apart from this 8051 specific storage class most architectures support
12038 \begin_inset LatexCommand \index{bitfields}
12046 \begin_layout Standard
12047 Not really meant as examples, but nevertheless showing what bitfields are
12048 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12054 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12055 signed modifier are implemented as unsigned.
12058 \begin_layout Subsubsection
12060 \begin_inset LatexCommand \index{sfr}
12065 \begin_inset LatexCommand \index{\_\_sfr}
12070 \begin_inset LatexCommand \index{sfr16}
12075 \begin_inset LatexCommand \index{\_\_sfr16}
12080 \begin_inset LatexCommand \index{sfr32}
12085 \begin_inset LatexCommand \index{\_\_sfr32}
12090 \begin_inset LatexCommand \index{\_\_sbit}
12095 \begin_inset LatexCommand \index{sbit}
12102 \begin_layout Standard
12103 Like the bit keyword,
12105 sfr / sfr16 / sfr32 / sbit
12107 signify both a data-type and storage class, they are used to describe the
12128 variables of a 8051, eg:
12131 \begin_layout Verse
12135 \begin_inset LatexCommand \index{at}
12140 \begin_inset LatexCommand \index{\_\_at}
12144 (0x80) P0;\InsetSpace ~
12145 /* special function register P0 at location 0x80 */
12150 special function register combination for timer 0
12154 with the high byte at
12155 location 0x8C and the low byte at location 0x8A */
12157 __sfr16 __at (0x8C8A)
12163 \begin_inset LatexCommand \index{at}
12168 \begin_inset LatexCommand \index{\_\_at}
12172 (0xd7) CY;\InsetSpace ~
12174 \begin_inset LatexCommand \index{Flags}
12179 \begin_inset LatexCommand \index{Carry flag}
12186 \begin_layout Standard
12187 Special function registers which are located on an address dividable by
12188 8 are bit-addressable, an
12192 addresses a specific bit within these sfr.
12194 16 Bit and 32 bit special function
12195 register combinations which require a certain access order are better not
12205 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12206 this is not guaranteed.
12211 \begin_layout Standard
12212 Please note, if you use a header file which was written for another compiler
12213 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12219 Specifically the syntax
12222 sfr P0 = 0x80;\InsetSpace ~
12229 by SDCC to an assignment of 0x80 to a variable called P0
12232 \begin_inset Marginal
12235 \begin_layout Standard
12247 Nevertheless it is possible to write header files
12248 \begin_inset LatexCommand \index{Header files}
12253 \begin_inset LatexCommand \index{Include files}
12257 which can be shared among different compilers (see section
12258 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12266 \begin_layout Subsubsection
12268 \begin_inset LatexCommand \index{Pointer}
12272 to MCS51/DS390 specific memory spaces
12275 \begin_layout Standard
12276 SDCC allows (via language extensions) pointers to explicitly point to any
12277 of the memory spaces
12278 \begin_inset LatexCommand \index{Memory model}
12283 In addition to the explicit pointers, the compiler uses (by default) generic
12284 pointers which can be used to point to any of the memory spaces.
12289 declaration examples:
12292 \begin_layout Verse
12295 /* pointer physically in internal ram pointing to object in external ram
12298 __xdata unsigned char * __data p;
12302 /* pointer physically in external ram
12303 pointing to object in internal ram */
12305 __data unsigned char * __xdata p;
12310 pointer physically in code rom pointing to data in xdata space */
12313 unsigned char * __code p;
12317 /* pointer physically in code space pointing to
12318 data in code space */
12320 __code unsigned char * __code p;
12325 physically located in xdata space */
12327 unsigned char * __xdata p;
12332 pointer physically located in default memory space */
12339 the following is a function pointer
12340 \begin_inset LatexCommand \index{function pointer}
12344 physically located in data space */
12346 char (* __data fp)(void);
12349 \begin_layout Standard
12350 Well you get the idea.
12355 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12368 The highest order byte of the
12372 pointers contains the data space information.
12373 Assembler support routines are called whenever data is stored or retrieved
12379 These are useful for developing reusable library
12380 \begin_inset LatexCommand \index{Libraries}
12385 Explicitly specifying the pointer
12386 \begin_inset LatexCommand \index{pointer}
12390 type will generate the most efficient code.
12393 \begin_layout Subsubsection
12394 Notes on MCS51 memory
12395 \begin_inset LatexCommand \index{MCS51 memory}
12402 \begin_layout Standard
12403 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12404 RAM memory which is structured as follows:
12408 - Bytes 00-1F - 32 bytes to hold
12409 up to 4 banks of the registers R0 to R7,
12411 - Bytes 20-2F - 16 bytes to hold
12413 \begin_inset LatexCommand \index{bit}
12419 - Bytes 30-7F - 80 bytes for general purpose use.
12424 \begin_layout Standard
12425 Additionally some members of the MCS51 family may have up to 128 bytes of
12426 additional, indirectly addressable, internal RAM memory (
12431 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12436 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12441 Furthermore, some chips may have some built in external memory (
12446 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12451 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12455 ) which should not be confused with the internal, directly addressable RAM
12461 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12466 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12471 Sometimes this built in
12475 memory has to be activated before using it (you can probably find this
12476 information on the datasheet of the microcontroller your are using, see
12478 \begin_inset LatexCommand \ref{sub:Startup-Code}
12486 \begin_layout Standard
12487 Normally SDCC will only use the first bank
12488 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12492 of registers (register bank 0), but it is possible to specify that other
12493 banks of registers (keyword
12500 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12505 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12511 ) should be used for example in interrupt
12512 \begin_inset LatexCommand \index{interrupt}
12517 \begin_inset LatexCommand \index{\_\_interrupt}
12522 By default, the compiler will place the stack after the last byte of allocated
12523 memory for variables.
12524 For example, if the first 2 banks of registers are used, and only four
12529 variables, it will position the base of the internal stack at address 20
12531 This implies that as the stack
12532 \begin_inset LatexCommand \index{stack}
12536 grows, it will use up the remaining register banks, and the 16 bytes used
12537 by the 128 bit variables, and 80 bytes for general purpose use.
12538 If any bit variables are used, the data variables will be placed in unused
12539 register banks and after the byte holding the last bit variable.
12540 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12545 variables will be placed starting from address 0x10 to 0x20 and continue
12551 \begin_layout Standard
12561 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12565 to specify the start address of the
12573 \begin_layout Standard
12583 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12587 to specify the size of the total internal RAM (
12601 \begin_layout Standard
12602 By default the 8051 linker will place the stack after the last byte of (i)data
12608 \begin_layout Standard
12618 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12622 allows you to specify the start of the stack, i.e.
12623 you could start it after any data in the general purpose area.
12624 If your microcontroller has additional indirectly addressable internal
12629 ) you can place the stack on it.
12630 You may also need to use -
12634 \begin_layout Standard
12644 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12648 to set the start address of the external RAM (
12656 \begin_layout Standard
12666 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12670 to specify its size.
12671 Same goes for the code memory, using -
12675 \begin_layout Standard
12685 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12693 \begin_layout Standard
12703 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12708 If in doubt, don't specify any options and see if the resulting memory
12709 layout is appropriate, then you can adjust it.
12712 \begin_layout Standard
12713 The linker generates two files with memory allocation information.
12714 The first, with extension .map
12715 \begin_inset LatexCommand \index{<file>.map}
12719 shows all the variables and segments.
12720 The second with extension .mem
12721 \begin_inset LatexCommand \index{<file>.mem}
12725 shows the final memory layout.
12726 The linker will complain either if memory segments overlap, there is not
12727 enough memory, or there is not enough space for stack.
12728 If you get any linking warnings and/or errors related to stack or segments
12729 allocation, take a look at either the .map or .mem files to find out what
12731 The .mem file may even suggest a solution to the problem.
12732 \begin_inset VSpace bigskip
12738 \begin_layout Subsection
12739 Z80/Z180 Storage Class
12740 \begin_inset LatexCommand \index{Z80!Storage class}
12744 Language Extensions
12747 \begin_layout Subsubsection
12749 \begin_inset LatexCommand \index{sfr}
12754 \begin_inset LatexCommand \index{\_\_sfr}
12758 (in/out to 8-bit addresses)
12761 \begin_layout Standard
12763 \begin_inset LatexCommand \index{Z80}
12767 family has separate address spaces for memory and
12777 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12782 \begin_inset LatexCommand \index{Z80!I/O memory}
12787 \begin_inset LatexCommand \index{Z180!I/O memory}
12791 is accessed with special instructions, e.g.:
12794 \begin_layout Verse
12797 sfr at 0x78 IoPort;\InsetSpace ~
12799 /* define a var in I/O space at 78h called IoPort */
12803 \begin_layout Standard
12804 Writing 0x01 to this variable generates the assembly code:
12807 \begin_layout Verse
12827 \begin_layout Subsubsection
12829 \begin_inset LatexCommand \index{sfr}
12834 \begin_inset LatexCommand \index{\_\_sfr}
12838 (in/out to 16-bit addresses)
12841 \begin_layout Standard
12846 is used to support 16 bit addresses in I/O memory e.g.:
12849 \begin_layout Verse
12853 \begin_inset LatexCommand \index{at}
12858 \begin_inset LatexCommand \index{\_\_at}
12865 \begin_layout Standard
12866 Writing 0x01 to this variable generates the assembly code:
12869 \begin_layout Verse
12872 01 23 01\InsetSpace ~
12894 \begin_layout Subsubsection
12896 \begin_inset LatexCommand \index{sfr}
12901 \begin_inset LatexCommand \index{\_\_sfr}
12905 (in0/out0 to 8 bit addresses on Z180
12906 \begin_inset LatexCommand \index{Z180}
12911 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12918 \begin_layout Standard
12919 The compiler option -
12923 \begin_layout Standard
12933 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12937 =180 (80) and a compiler #pragma\InsetSpace ~
12939 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12943 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12953 If you include the file z180.h this will be set automatically.
12954 \begin_inset VSpace bigskip
12960 \begin_layout Subsection
12962 \begin_inset LatexCommand \index{HC08!Storage class}
12966 Language Extensions
12969 \begin_layout Subsubsection
12971 \begin_inset LatexCommand \index{data (hc08 storage class)}
12976 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12983 \begin_layout Standard
12984 The data storage class declares a variable that resides in the first 256
12985 bytes of memory (the direct page).
12987 \begin_inset LatexCommand \index{HC08}
12991 is most efficient at accessing variables (especially pointers) stored here.
12994 \begin_layout Subsubsection
12996 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13001 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13008 \begin_layout Standard
13009 The xdata storage class declares a variable that can reside anywhere in
13011 This is the default if no storage class is specified.
13013 \begin_inset VSpace bigskip
13019 \begin_layout Section
13020 Absolute Addressing
13021 \begin_inset LatexCommand \index{Absolute addressing}
13028 \begin_layout Standard
13029 Data items can be assigned an absolute address with the
13032 \begin_inset LatexCommand \index{at}
13037 \begin_inset LatexCommand \index{\_\_at}
13043 keyword, in addition to a storage class, e.g.:
13046 \begin_layout Verse
13050 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13055 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13060 \begin_inset LatexCommand \index{at}
13065 \begin_inset LatexCommand \index{\_\_at}
13069 0x7ffe unsigned int chksum;
13072 \begin_layout Standard
13073 or, better conforming to ISO/IEC 9899 C:
13076 \begin_layout Verse
13079 __xdata __at (0x7ffe) unsigned int chksum;
13082 \begin_layout Standard
13083 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13084 of the external ram.
13089 reserve any space for variables declared in this way
13090 \begin_inset Marginal
13093 \begin_layout Standard
13102 (they are implemented with an equate in the assembler).
13103 Thus it is left to the programmer to make sure there are no overlaps with
13104 other variables that are declared without the absolute address.
13105 The assembler listing file (.lst
13106 \begin_inset LatexCommand \index{<file>.lst}
13110 ) and the linker output files (.rst
13111 \begin_inset LatexCommand \index{<file>.rst}
13116 \begin_inset LatexCommand \index{<file>.map}
13120 ) are good places to look for such overlaps.
13123 \begin_layout Standard
13124 If however you provide an initializer
13125 \begin_inset LatexCommand \index{Variable initialization}
13129 actual memory allocation will take place and overlaps will be detected
13134 \begin_layout Verse
13137 __code __at (0x7ff0) char Id[5] =
13138 \begin_inset Quotes sld
13142 \begin_inset Quotes srd
13148 \begin_layout Standard
13149 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13153 \begin_layout Standard
13154 In case of memory mapped I/O devices the keyword
13158 has to be used to tell the compiler that accesses might not be removed:
13161 \begin_layout Verse
13165 \begin_inset LatexCommand \index{volatile}
13170 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13175 \begin_inset LatexCommand \index{at}
13179 (0x8000) unsigned char PORTA_8255;
13182 \begin_layout Standard
13183 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13188 \begin_inset LatexCommand \index{Aligned array}
13195 starts at a block (256 byte) boundary
13196 \begin_inset LatexCommand \index{block boundary}
13201 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13207 Absolute addresses can be specified for variables in all
13208 storage classes, e.g.:
13211 \begin_layout Verse
13215 \begin_inset LatexCommand \index{bit}
13220 \begin_inset LatexCommand \index{at}
13227 \begin_layout Standard
13228 The above example will allocate the variable at offset 0x02 in the bit-addressab
13230 There is no real advantage to assigning absolute addresses to variables
13231 in this manner, unless you want strict control over all the variables allocated.
13232 One possible use would be to write hardware portable code.
13233 For example, if you have a routine that uses one or more of the microcontroller
13234 I/O pins, and such pins are different for two different hardwares, you
13235 can declare the I/O pins in your routine using:
13238 \begin_layout Verse
13242 \begin_inset LatexCommand \index{volatile}
13246 __bit MOSI;\InsetSpace ~
13250 /* master out, slave in */
13252 extern volatile __bit MISO;\InsetSpace ~
13259 extern volatile __bit MCLK;\InsetSpace ~
13268 Output of a byte on a 3-wire serial bus.
13273 If needed adapt polarity of clock,
13274 polarity of data and bit order
13279 unsigned char spi_io(unsigned char out_byte)
13304 MOSI = out_byte & 0x80;
13335 /* _asm nop _endasm; */\InsetSpace ~
13343 /* for slow peripherals */
13395 \begin_layout Standard
13396 Then, someplace in the code for the first hardware you would use
13399 \begin_layout Verse
13403 \begin_inset LatexCommand \index{at}
13408 \begin_inset LatexCommand \index{\_\_at}
13412 (0x80) MOSI;\InsetSpace ~
13416 /* I/O port 0, bit 0 */
13418 __bit __at (0x81) MISO;\InsetSpace ~
13425 __bit __at (0x82) MCLK;\InsetSpace ~
13429 /* I/O port 0, bit 2 */
13432 \begin_layout Standard
13433 Similarly, for the second hardware you would use
13436 \begin_layout Verse
13439 __bit __at (0x83) MOSI;\InsetSpace ~
13443 /* I/O port 0, bit 3 */
13445 __bit __at (0x91) MISO;\InsetSpace ~
13450 I/O port 1, bit 1 */
13453 \begin_inset LatexCommand \index{bit}
13457 __at (0x92) MCLK;\InsetSpace ~
13461 /* I/O port 1, bit 2 */
13464 \begin_layout Standard
13465 and you can use the same hardware dependent routine without changes, as
13466 for example in a library.
13467 This is somehow similar to sbit, but only one absolute address has to be
13468 specified in the whole project.
13469 \begin_inset VSpace bigskip
13475 \begin_layout Section
13477 \begin_inset LatexCommand \index{Parameters}
13482 \begin_inset LatexCommand \index{function parameter}
13487 \begin_inset LatexCommand \index{local variables}
13492 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13499 \begin_layout Standard
13500 Automatic (local) variables and parameters to functions can either be placed
13501 on the stack or in data-space.
13502 The default action of the compiler is to place these variables in the internal
13503 RAM (for small model) or external RAM (for medium or large model).
13504 This in fact makes them similar to
13507 \begin_inset LatexCommand \index{static}
13513 so by default functions are non-reentrant
13514 \begin_inset LatexCommand \index{reentrant}
13523 They can be placed on the stack
13524 \begin_inset LatexCommand \index{stack}
13534 \begin_layout Standard
13544 \begin_inset LatexCommand \index{-\/-stack-auto}
13552 #pragma\InsetSpace ~
13556 \begin_inset LatexCommand \index{\#pragma stackauto}
13563 \begin_inset LatexCommand \index{reentrant}
13569 keyword in the function declaration, e.g.:
13572 \begin_layout Verse
13575 unsigned char foo(char i) __reentrant
13589 \begin_layout Standard
13590 Since stack space on 8051 is limited, the
13600 \begin_layout Standard
13611 option should be used sparingly.
13612 Note that the reentrant keyword just means that the parameters & local
13613 variables will be allocated to the stack, it
13617 mean that the function is register bank
13618 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13627 \begin_inset LatexCommand \index{local variables}
13631 can be assigned storage classes and absolute
13632 \begin_inset LatexCommand \index{Absolute addressing}
13639 \begin_layout Verse
13642 unsigned char foo()
13650 __xdata unsigned char i;
13663 \begin_inset LatexCommand \index{at}
13667 (0x31) unsigned char j;
13679 \begin_layout Standard
13680 In the above example the variable
13684 will be allocated in the external ram,
13688 in bit addressable space and
13699 \begin_layout Standard
13710 or when a function is declared as
13714 this should only be done for static variables.
13717 \begin_layout Standard
13719 \begin_inset LatexCommand \index{function parameter}
13723 however are not allowed any storage class
13724 \begin_inset LatexCommand \index{Storage class}
13728 , (storage classes for parameters will be ignored), their allocation is
13729 governed by the memory model in use, and the reentrancy options.
13732 \begin_layout Standard
13733 It is however allowed to use bit parameters in reentrant functions and also
13734 non-static local bit variables are supported.
13735 Efficient use is limited to 8 semi-bitregisters in bit space.
13736 They are pushed and popped to stack
13737 \begin_inset LatexCommand \index{stack}
13741 as a single byte just like the normal registers.
13744 \begin_layout Section
13746 \begin_inset LatexCommand \label{sub:Overlaying}
13751 \begin_inset LatexCommand \index{Overlaying}
13758 \begin_layout Standard
13760 \begin_inset LatexCommand \index{reentrant}
13764 functions SDCC will try to reduce internal ram space usage by overlaying
13765 parameters and local variables of a function (if possible).
13766 Parameters and local variables
13767 \begin_inset LatexCommand \index{local variables}
13771 of a function will be allocated to an overlayable segment if the function
13774 no other function calls and the function is non-reentrant and the memory
13776 \begin_inset LatexCommand \index{Memory model}
13783 If an explicit storage class
13784 \begin_inset LatexCommand \index{Storage class}
13788 is specified for a local variable, it will NOT be overlayed.
13791 \begin_layout Standard
13792 Note that the compiler (not the linkage editor) makes the decision for overlayin
13794 Functions that are called from an interrupt service routine
13795 \begin_inset Marginal
13798 \begin_layout Standard
13806 should be preceded by a #pragma\InsetSpace ~
13808 \begin_inset LatexCommand \index{\#pragma nooverlay}
13812 if they are not reentrant.
13815 \begin_layout Standard
13816 Also note that the compiler does not do any processing of inline assembler
13817 code, so the compiler might incorrectly assign local variables and parameters
13818 of a function into the overlay segment if the inline assembler code calls
13819 other c-functions that might use the overlay.
13820 In that case the #pragma\InsetSpace ~
13821 nooverlay should be used.
13824 \begin_layout Standard
13825 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13827 \begin_inset LatexCommand \index{Multiplication}
13832 \begin_inset LatexCommand \index{Division}
13836 will NOT be overlayed since these are implemented using external functions,
13840 \begin_layout Verse
13846 \begin_inset LatexCommand \index{\#pragma nooverlay}
13852 void set_error(unsigned char errcd)
13869 some_isr () __interrupt
13870 \begin_inset LatexCommand \index{interrupt}
13900 \begin_layout Standard
13901 In the above example the parameter
13909 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13911 not present, this could cause unpredictable runtime behavior when called
13912 from an interrupt service routine.
13913 The #pragma\InsetSpace ~
13914 nooverlay ensures that the parameters and local variables for
13915 the function are NOT overlayed.
13916 \begin_inset VSpace bigskip
13922 \begin_layout Section
13923 Interrupt Service Routines
13924 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13931 \begin_layout Subsection
13932 General Information
13935 \begin_layout Standard
13948 outines to be coded in C, with some extended keywords.
13951 \begin_layout Verse
13954 void timer_isr (void) __interrupt (1) __using (1)
13968 \begin_layout Standard
13969 The optional number following the
13972 \begin_inset LatexCommand \index{interrupt}
13977 \begin_inset LatexCommand \index{\_\_interrupt}
13983 keyword is the interrupt number this routine will service.
13984 When present, the compiler will insert a call to this routine in the interrupt
13986 \begin_inset LatexCommand \index{interrupt vector table}
13990 for the interrupt number specified.
13991 If you have multiple source files in your project, interrupt service routines
13992 can be present in any of them, but a prototype of the isr MUST be present
13993 or included in the file that contains the function
13998 The optional (8051 specific) keyword
14001 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14006 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14012 can be used to tell the compiler to use the specified register bank when
14013 generating code for this function.
14016 Interrupt service routines open the door for some very interesting bugs:
14019 \begin_layout Subsubsection
14020 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14024 Common interrupt pitfall: variable not declared
14029 \begin_layout Standard
14030 If an interrupt service routine changes variables which are accessed by
14031 other functions these variables have to be declared
14036 \begin_inset LatexCommand \index{volatile}
14042 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14049 \begin_layout Subsubsection
14050 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14054 Common interrupt pitfall:
14059 \begin_layout Standard
14060 If the access to these variables is not
14063 \begin_inset LatexCommand \index{atomic}
14070 the processor needs more than one instruction for the access and could
14071 be interrupted while accessing the variable) the interrupt must be disabled
14072 during the access to avoid inconsistent data.
14075 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14076 and should be protected by disabling interrupts.
14077 You're not automatically on the safe side if you use 8 bit variables though.
14078 We need an example here: f.e.
14079 on the 8051 the harmless looking
14080 \begin_inset Quotes srd
14090 \begin_inset Quotes sld
14099 \begin_inset Quotes srd
14109 \begin_inset Quotes sld
14112 from within an interrupt routine might get lost if the interrupt occurs
14115 \begin_inset Quotes sld
14120 counter\InsetSpace ~
14125 \begin_inset Quotes srd
14128 is not atomic on the 8051 even if
14132 is located in data memory.
14134 Bugs like these are hard to reproduce and can
14135 cause a lot of trouble.
14139 \begin_layout Subsubsection
14140 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14144 Common interrupt pitfall:
14149 \begin_layout Standard
14150 The return address and the registers used in the interrupt service routine
14151 are saved on the stack
14152 \begin_inset LatexCommand \index{stack}
14156 so there must be sufficient stack space.
14157 If there isn't variables or registers (or even the return address itself)
14164 \begin_inset LatexCommand \index{stack overflow}
14168 is most likely to happen if the interrupt occurs during the
14169 \begin_inset Quotes sld
14173 \begin_inset Quotes srd
14176 subroutine when the stack is already in use for f.e.
14177 many return addresses.
14180 \begin_layout Subsubsection
14181 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14185 Common interrupt pitfall:
14187 use of non-reentrant functions
14190 \begin_layout Standard
14191 A special note here, int (16 bit) and long (32 bit) integer division
14192 \begin_inset LatexCommand \index{Division}
14197 \begin_inset LatexCommand \index{Multiplication}
14202 \begin_inset LatexCommand \index{Modulus}
14207 \begin_inset LatexCommand \index{Floating point support}
14211 operations are implemented using external support routines.
14212 If an interrupt service routine needs to do any of these operations then
14213 the support routines (as mentioned in a following section) will have to
14214 be recompiled using the
14220 \begin_layout Standard
14230 \begin_inset LatexCommand \index{-\/-stack-auto}
14236 option and the source file will need to be compiled using the
14242 \begin_layout Standard
14254 \begin_inset LatexCommand \index{-\/-int-long-reent}
14261 Note, the type promotion
14262 \begin_inset LatexCommand \index{type promotion}
14266 required by ANSI C can cause 16 bit routines to be used
14267 \begin_inset Marginal
14270 \begin_layout Standard
14279 without the programmer being aware of it.
14283 (unsigned char)(tail-1)
14285 within the if clause in section
14286 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14293 \begin_layout Standard
14294 Calling other functions from an interrupt service routine is not recommended,
14295 avoid it if possible.
14296 Note that when some function is called from an interrupt service routine
14297 it should be preceded by a #pragma\InsetSpace ~
14299 \begin_inset LatexCommand \index{\#pragma nooverlay}
14303 if it is not reentrant.
14304 Furthermore nonreentrant functions should not be called from the main program
14305 while the interrupt service routine might be active.
14306 They also must not be called from low priority interrupt service routines
14307 while a high priority interrupt service routine might be active.
14308 You could use semaphores or make the function
14312 if all parameters are passed in registers.
14315 \begin_inset LatexCommand \ref{sub:Overlaying}
14320 about Overlaying and section
14321 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14326 about Functions using private register banks.
14327 \begin_inset VSpace bigskip
14333 \begin_layout Subsection
14334 MCS51/DS390 Interrupt Service Routines
14337 \begin_layout Standard
14339 \begin_inset LatexCommand \index{interrupt}
14343 numbers and the corresponding address & descriptions for the Standard 8051/8052
14345 SDCC will automatically adjust the
14346 \begin_inset LatexCommand \index{interrupt vector table}
14350 to the maximum interrupt number specified.
14355 \begin_layout Standard
14357 \begin_inset Tabular
14358 <lyxtabular version="3" rows="9" columns="3">
14360 <column alignment="center" valignment="top" leftline="true" width="0in">
14361 <column alignment="left" valignment="top" leftline="true" width="0in">
14362 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14363 <row topline="true" bottomline="true">
14364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14367 \begin_layout Standard
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" rightline="true" usebox="none">
14385 \begin_layout Standard
14392 <row topline="true">
14393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14396 \begin_layout Standard
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" rightline="true" usebox="none">
14414 \begin_layout Standard
14421 <row topline="true">
14422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14425 \begin_layout Standard
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" rightline="true" usebox="none">
14443 \begin_layout Standard
14450 <row topline="true">
14451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14454 \begin_layout Standard
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" rightline="true" usebox="none">
14472 \begin_layout Standard
14479 <row topline="true">
14480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14483 \begin_layout Standard
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" rightline="true" usebox="none">
14501 \begin_layout Standard
14508 <row topline="true">
14509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14512 \begin_layout Standard
14518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14521 \begin_layout Standard
14527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14530 \begin_layout Standard
14537 <row topline="true">
14538 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14541 \begin_layout Standard
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" rightline="true" usebox="none">
14559 \begin_layout Standard
14566 <row topline="true">
14567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14570 \begin_layout Standard
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" rightline="true" usebox="none">
14588 \begin_layout Standard
14595 <row topline="true" bottomline="true">
14596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14599 \begin_layout Standard
14605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14608 \begin_layout Standard
14614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14617 \begin_layout Standard
14633 \begin_layout Standard
14634 If the interrupt service routine is defined without
14637 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14642 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14648 a register bank or with register bank 0 (
14652 0), the compiler will save the registers used by itself on the stack upon
14653 entry and restore them at exit, however if such an interrupt service routine
14654 calls another function then the entire register bank will be saved on the
14656 This scheme may be advantageous for small interrupt service routines which
14657 have low register usage.
14660 \begin_layout Standard
14661 If the interrupt service routine is defined to be using a specific register
14666 & psw are saved and restored, if such an interrupt service routine calls
14667 another function (using another register bank) then the entire register
14668 bank of the called function will be saved on the stack
14669 \begin_inset LatexCommand \index{stack}
14674 This scheme is recommended for larger interrupt service routines.
14675 \begin_inset VSpace bigskip
14681 \begin_layout Subsection
14683 \begin_inset LatexCommand \index{HC08}
14687 Interrupt Service Routines
14690 \begin_layout Standard
14691 Since the number of interrupts
14692 \begin_inset LatexCommand \index{HC08!interrupt}
14696 available is chip specific and the interrupt vector table always ends at
14697 the last byte of memory, the interrupt numbers corresponds to the interrupt
14698 vectors in reverse order of address.
14699 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14700 2 will use the interrupt vector at 0xfffa, and so on.
14701 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14702 this way; instead see section
14703 \begin_inset LatexCommand \ref{sub:Startup-Code}
14707 for details on customizing startup.
14708 \begin_inset VSpace bigskip
14714 \begin_layout Subsection
14715 Z80 Interrupt Service Routines
14718 \begin_layout Standard
14720 \begin_inset LatexCommand \index{Z80}
14724 uses several different methods for determining the correct interrupt
14725 \begin_inset LatexCommand \index{Z80!interrupt}
14729 vector depending on the hardware implementation.
14730 Therefore, SDCC ignores the optional interrupt number and does not attempt
14731 to generate an interrupt vector table.
14734 \begin_layout Standard
14735 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14736 instruction to return from the interrupt.
14737 To write an interrupt handler for the non-maskable interrupt, which needs
14738 a RETN instruction instead, add the
14745 \begin_layout Verse
14748 void nmi_isr (void) critical interrupt
14762 \begin_layout Standard
14763 However if you need to create a non-interruptable interrupt service routine
14764 you would also require the
14769 To distinguish between this and an nmi_isr you must provide an interrupt
14771 \begin_inset VSpace bigskip
14777 \begin_layout Section
14778 Enabling and Disabling Interrupts
14781 \begin_layout Subsection
14782 Critical Functions and Critical Statements
14785 \begin_layout Standard
14786 A special keyword may be associated with a block or a function declaring
14792 SDCC will generate code to disable all interrupts
14793 \begin_inset LatexCommand \index{interrupt}
14797 upon entry to a critical function and restore the interrupt enable to the
14798 previous state before returning.
14799 Nesting critical functions will need one additional byte on the stack
14800 \begin_inset LatexCommand \index{stack}
14807 \begin_layout Verse
14810 int foo () __critical
14811 \begin_inset LatexCommand \index{critical}
14816 \begin_inset LatexCommand \index{\_\_critical}
14841 \begin_layout Standard
14842 The critical attribute maybe used with other attributes like
14852 may also be used to disable interrupts more locally:
14855 \begin_layout Verse
14861 \begin_layout Standard
14862 More than one statement could have been included in the block.
14865 \begin_layout Subsection
14866 Enabling and Disabling Interrupts directly
14869 \begin_layout Standard
14871 \begin_inset LatexCommand \index{interrupt}
14875 can also be disabled and enabled directly (8051):
14878 \begin_layout Verse
14881 EA = 0;\InsetSpace ~
14907 \begin_layout Verse
14943 \begin_layout Verse
14946 EA = 1;\InsetSpace ~
14975 \begin_layout Verse
15014 \begin_layout Standard
15015 On other architectures which have seperate opcodes for enabling and disabling
15016 interrupts you might want to make use of defines with inline assembly
15017 \begin_inset LatexCommand \index{Assembler routines}
15022 \begin_inset LatexCommand \index{HC08!interrupt}
15029 \begin_layout Verse
15033 \begin_inset LatexCommand \index{\_asm}
15042 \begin_inset LatexCommand \index{\_endasm}
15049 \begin_layout Verse
15052 #define SEI _asm\InsetSpace ~
15059 \begin_layout Verse
15065 \begin_layout Standard
15066 Note: it is sometimes sufficient to disable only a specific interrupt source
15068 a timer or serial interrupt by manipulating an
15071 \begin_inset LatexCommand \index{interrupt mask}
15081 \begin_layout Standard
15082 Usually the time during which interrupts are disabled should be kept as
15084 This minimizes both
15089 \begin_inset LatexCommand \index{interrupt latency}
15093 (the time between the occurrence of the interrupt and the execution of
15094 the first code in the interrupt routine) and
15099 \begin_inset LatexCommand \index{interrupt jitter}
15103 (the difference between the shortest and the longest interrupt latency).
15104 These really are something different, f.e.
15105 a serial interrupt has to be served before its buffer overruns so it cares
15106 for the maximum interrupt latency, whereas it does not care about jitter.
15107 On a loudspeaker driven via a digital to analog converter which is fed
15108 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15109 a much smaller jitter will be very audible.
15112 \begin_layout Standard
15113 You can reenable interrupts within an interrupt routine and on some architecture
15114 s you can make use of two (or more) levels of
15116 interrupt priorities
15119 \begin_inset LatexCommand \index{interrupt priority}
15124 On some architectures which don't support interrupt priorities these can
15125 be implemented by manipulating the interrupt mask and reenabling interrupts
15126 within the interrupt routine.
15127 Check there is sufficient space on the stack
15128 \begin_inset LatexCommand \index{stack}
15132 and don't add complexity unless you have to.
15136 \begin_layout Subsection
15138 \begin_inset LatexCommand \index{semaphore}
15142 locking (mcs51/ds390)
15145 \begin_layout Standard
15146 Some architectures (mcs51/ds390) have an atomic
15147 \begin_inset LatexCommand \index{atomic}
15160 These type of instructions are typically used in preemptive multitasking
15161 systems, where a routine f.e.
15162 claims the use of a data structure ('acquires a lock
15163 \begin_inset LatexCommand \index{lock}
15167 on it'), makes some modifications and then releases the lock when the data
15168 structure is consistent again.
15169 The instruction may also be used if interrupt and non-interrupt code have
15170 to compete for a resource.
15171 With the atomic bit test and clear instruction interrupts
15172 \begin_inset LatexCommand \index{interrupt}
15176 don't have to be disabled for the locking operation.
15180 \begin_layout Standard
15181 SDCC generates this instruction if the source follows this pattern:
15184 \begin_layout Verse
15188 \begin_inset LatexCommand \index{volatile}
15192 bit resource_is_free;
15196 if (resource_is_free)
15206 resource_is_free=0;
15219 resource_is_free=1;
15226 \begin_layout Standard
15227 Note, mcs51 and ds390 support only an atomic
15228 \begin_inset LatexCommand \index{atomic}
15236 instruction (as opposed to atomic bit test and
15241 \begin_layout Section
15242 Functions using private register banks
15243 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15250 \begin_layout Standard
15251 Some architectures have support for quickly changing register sets.
15252 SDCC supports this feature with the
15255 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15260 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15266 attribute (which tells the compiler to use a register bank
15267 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15271 other than the default bank zero).
15272 It should only be applied to
15275 \begin_inset LatexCommand \index{interrupt}
15281 functions (see footnote below).
15282 This will in most circumstances make the generated ISR code more efficient
15283 since it will not have to save registers on the stack.
15286 \begin_layout Standard
15291 attribute will have no effect on the generated code for a
15295 function (but may occasionally be useful anyway
15299 \begin_layout Standard
15300 possible exception: if a function is called ONLY from 'interrupt' functions
15301 using a particular bank, it can be declared with the same 'using' attribute
15302 as the calling 'interrupt' functions.
15303 For instance, if you have several ISRs using bank one, and all of them
15304 call memcpy(), it might make sense to create a specialized version of memcpy()
15305 'using 1', since this would prevent the ISR from having to save bank zero
15306 to the stack on entry and switch to bank zero before calling the function
15315 (pending: Note, nowadays the
15319 attribute has an effect on
15323 the generated code for a
15334 \begin_layout Standard
15339 function using a non-zero bank will assume that it can trash that register
15340 bank, and will not save it.
15341 Since high-priority interrupts
15342 \begin_inset LatexCommand \index{interrupts}
15347 \begin_inset LatexCommand \index{interrupt priority}
15351 can interrupt low-priority ones on the 8051 and friends, this means that
15352 if a high-priority ISR
15356 a particular bank occurs while processing a low-priority ISR
15360 the same bank, terrible and bad things can happen.
15361 To prevent this, no single register bank should be
15365 by both a high priority and a low priority ISR.
15366 This is probably most easily done by having all high priority ISRs use
15367 one bank and all low priority ISRs use another.
15368 If you have an ISR which can change priority at runtime, you're on your
15369 own: I suggest using the default bank zero and taking the small performance
15373 \begin_layout Standard
15374 It is most efficient if your ISR calls no other functions.
15375 If your ISR must call other functions, it is most efficient if those functions
15376 use the same bank as the ISR (see note 1 below); the next best is if the
15377 called functions use bank zero.
15378 It is very inefficient to call a function using a different, non-zero bank
15381 \begin_inset VSpace bigskip
15387 \begin_layout Section
15389 \begin_inset LatexCommand \label{sub:Startup-Code}
15394 \begin_inset LatexCommand \index{Startup code}
15401 \begin_layout Subsection
15402 MCS51/DS390 Startup Code
15405 \begin_layout Standard
15406 The compiler triggers the linker to link certain initialization modules
15407 from the runtime library
15408 \begin_inset LatexCommand \index{Runtime library}
15412 called crt<something>.
15413 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15414 GSINIT5) is not linked unless the -
15420 \begin_layout Standard
15431 -xstack option is used.
15432 These modules are highly entangled by the use of special segments/areas,
15433 but a common layout is shown below:
15436 \begin_layout Verse
15444 \begin_layout Verse
15468 ljmp __sdcc_gsinit_startup
15471 \begin_layout Verse
15479 \begin_layout Verse
15491 .area GSINIT0 (CODE)
15493 __sdcc_gsinit_startup::
15503 mov sp,#__start__stack - 1
15506 \begin_layout Verse
15514 \begin_layout Verse
15526 .area GSINIT1 (CODE)
15528 __sdcc_init_xstack::
15530 ; Need to initialize in GSINIT1 in
15531 case the user's __sdcc_external_startup uses the xstack.
15541 mov __XPAGE,#(__start__x
15552 mov _spx,#__start__xstack
15555 \begin_layout Verse
15563 \begin_layout Verse
15575 .area GSINIT2 (CODE)
15585 lcall __sdcc_external_startup
15605 jz __sdcc_init_data
15616 __sdcc_program_startup
15621 \begin_layout Verse
15629 \begin_layout Verse
15641 .area GSINIT3 (CODE)
15694 mov r2,#((l_XINIT+255) >> 8)
15725 __XPAGE,#(s_XISEG >> 8)
15727 00001$:\InsetSpace ~
15791 00002$:\InsetSpace ~
15818 \begin_layout Verse
15826 \begin_layout Verse
15838 .area GSINIT4 (CODE)
15840 __mcs51_genRAMCLEAR::
15862 00004$:\InsetSpace ~
15876 ; _mcs51_genRAMCLEAR() end
15879 \begin_layout Verse
15887 \begin_layout Verse
15899 .area GSINIT4 (CODE)
15901 __mcs51_genXRAMCLEAR::
15962 mov __XPAGE,#(s_PSEG >> 8)
15974 00005$:\InsetSpace ~
16049 mov r1,#((l_XSEG + 255) >> 8)
16071 00007$:\InsetSpace ~
16108 \begin_layout Verse
16116 \begin_layout Verse
16128 .area GSINIT5 (CODE)
16130 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16133 ; and __mcs51_genRAMCLEAR modifies _spx.
16143 mov __XPAGE,#(__start__x
16154 mov _spx,#__start__xstack
16157 \begin_layout Verse
16162 (application modules)
16165 \begin_layout Verse
16177 .area GSINIT (CODE)
16180 \begin_layout Verse
16188 \begin_layout Verse
16200 .area GSFINAL (CODE)
16210 ljmp __sdcc_program_startup
16212 ;---------------------------------
16213 -----------------------
16217 ;--------------------------------------------------
16240 __sdcc_program_startup:
16253 return from main will lock up
16266 \begin_layout Standard
16267 One of these modules (crtstart.asm) contains a call to the C routine
16269 _sdcc_external_startup()
16270 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16279 at the start of the CODE area.
16280 This routine is also in the runtime library
16281 \begin_inset LatexCommand \index{Runtime library}
16285 and returns 0 by default.
16286 If this routine returns a non-zero value, the static & global variable
16287 initialization will be skipped and the function main will be invoked.
16288 Otherwise static & global variables will be initialized before the function
16292 _sdcc_external_startup()
16294 routine to your program to override the default if you need to setup hardware
16295 or perform some other critical operation prior to static & global variable
16297 \begin_inset LatexCommand \index{Variable initialization}
16302 On some mcs51 variants xdata
16303 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16307 memory has to be explicitly enabled before it can be accessed or if the
16309 \begin_inset LatexCommand \index{watchdog}
16313 needs to be disabled, this is the place to do it.
16314 The startup code clears all internal data memory, 256 bytes by default,
16315 but from 0 to n-1 if
16321 \begin_layout Standard
16331 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16338 (recommended for Chipcon CC1010).
16341 \begin_layout Standard
16342 See also the compiler options
16348 \begin_layout Standard
16364 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16374 \begin_layout Standard
16386 \begin_inset LatexCommand \index{-\/-main-return}
16391 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16395 about MCS51-variants.
16400 \begin_layout Standard
16401 While these initialization modules are meant as generic startup code there
16402 might be the need for customization.
16403 Let's assume the return value of
16405 _sdcc_external_startup()
16411 should not be checked (or
16413 _sdcc_external_startup()
16415 should not be called at all).
16416 The recommended way would be to copy
16422 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16426 ) into the source directory, adapt it there, then assemble it with
16432 \begin_layout Standard
16433 \begin_inset Quotes sld
16437 \begin_inset Quotes srd
16440 are the assembler options used in
16441 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16452 and when linking your project explicitely specify
16457 As a bonus a listing of the relocated object file
16464 \begin_layout Standard
16465 \begin_inset VSpace bigskip
16471 \begin_layout Subsection
16475 \begin_layout Standard
16477 \begin_inset LatexCommand \index{HC08}
16481 startup code follows the same scheme as the MCS51 startup code.
16482 \begin_inset VSpace bigskip
16488 \begin_layout Subsection
16492 \begin_layout Standard
16494 \begin_inset LatexCommand \index{Z80}
16498 the startup code is inserted by linking with crt0.o which is generated from
16499 sdcc/device/lib/z80/crt0.s.
16500 If you need a different startup code you can use the compiler option
16509 \begin_layout Standard
16524 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16528 and provide your own crt0.o.
16530 \begin_inset VSpace bigskip
16536 \begin_layout Section
16537 Inline Assembler Code
16538 \begin_inset LatexCommand \index{Assembler routines}
16545 \begin_layout Subsection
16546 A Step by Step Introduction
16547 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16554 \begin_layout Standard
16555 Starting from a small snippet of c-code this example shows for the MCS51
16556 how to use inline assembly, access variables, a function parameter and
16557 an array in xdata memory.
16558 The example uses an MCS51 here but is easily adapted for other architectures.
16559 This is a buffer routine which should be optimized:
16562 \begin_layout Verse
16566 unsigned char __far
16567 \begin_inset LatexCommand \index{far (storage class)}
16572 \begin_inset LatexCommand \index{\_\_far (storage class)}
16577 \begin_inset LatexCommand \index{at}
16582 \begin_inset LatexCommand \index{\_\_at}
16586 (0x7f00) buf[0x100];
16587 \begin_inset LatexCommand \index{Aligned array}
16593 unsigned char head, tail;\InsetSpace ~
16611 \begin_inset LatexCommand \index{interrupt}
16663 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16675 void to_buffer( unsigned char c )
16683 if( head != (unsigned char)(tail-1)
16690 \begin_inset LatexCommand \index{promotion to signed int}
16695 \begin_inset LatexCommand \index{type promotion}
16700 \begin_inset Marginal
16703 \begin_layout Standard
16722 buf[ head++ ] = c;\InsetSpace ~
16738 /* access to a 256 byte aligned array */
16743 \begin_layout Standard
16744 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16745 then a corresponding buffer.asm file is generated.
16746 We define a new function
16750 in file buffer.c in which we cut and paste the generated code, removing
16751 unwanted comments and some ':'.
16753 \begin_inset Quotes sld
16761 \begin_inset Quotes srd
16765 \begin_inset Quotes sld
16773 \begin_inset Quotes srd
16780 \begin_layout Standard
16781 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16782 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16784 The latter is also used in the library functions.
16789 to the beginning and the end of the function body:
16792 \begin_layout Verse
16796 /* With a cut and paste from the .asm file, we have something to start with.
16802 function is not yet OK! (registers aren't saved) */
16804 void to_buffer_asm(
16814 \begin_inset LatexCommand \index{\_asm}
16819 \begin_inset LatexCommand \index{\_\_asm}
16833 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16839 \begin_inset LatexCommand \index{promotion to signed int}
16844 \begin_inset LatexCommand \index{type promotion}
16897 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16898 \begin_inset LatexCommand \index{Aligned array}
16964 \begin_inset LatexCommand \index{\_endasm}
16969 \begin_inset LatexCommand \index{\_\_endasm}
16978 \begin_layout Standard
16979 The new file buffer.c should compile with only one warning about the unreferenced
16980 function argument 'c'.
16981 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16982 (1) and finally have:
16985 \begin_layout Verse
16989 unsigned char __far __at(0x7f00) buf[0x100];
16991 unsigned char head, tail;
17002 void to_buffer( unsigned char c )
17011 head != (unsigned char)(tail-1) )
17040 c; // to avoid warning: unreferenced function argument
17047 \begin_inset LatexCommand \index{\_asm}
17052 \begin_inset LatexCommand \index{\_\_asm}
17066 ; save used registers here.
17077 ; If we were still using r2,r3 we would have to push them here.
17080 ; if( head != (unsigned char)(tail-1) )
17124 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17160 a,dpl \InsetSpace ~
17167 ; dpl holds lower byte of function argument
17179 dpl,_head \InsetSpace ~
17182 ; buf is 0x100 byte aligned so head can be used directly
17225 ; we could do an ANL _head,#0x0f here to use a
17226 smaller buffer (see above)
17238 ; restore used registers here
17245 \begin_inset LatexCommand \index{\_endasm}
17250 \begin_inset LatexCommand \index{\_\_endasm}
17261 \begin_layout Standard
17262 The inline assembler code can contain any valid code understood by the assembler
17263 , this includes any assembler directives and comment lines.
17264 The assembler does not like some characters like ':' or ''' in comments.
17265 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17266 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17271 \begin_inset LatexCommand \index{Assembler documentation}
17276 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17284 \begin_layout Standard
17285 The compiler does not do any validation of the code within the
17288 \begin_inset LatexCommand \index{\_asm}
17293 \begin_inset LatexCommand \index{\_\_asm}
17301 \begin_inset LatexCommand \index{\_endasm}
17306 \begin_inset LatexCommand \index{\_\_endasm}
17315 Specifically it will not know which registers are used and thus register
17317 \begin_inset LatexCommand \index{push/pop}
17321 has to be done manually.
17325 \begin_layout Standard
17326 It is recommended that each assembly instruction (including labels) be placed
17327 in a separate line (as the example shows).
17332 \begin_layout Standard
17344 \begin_inset LatexCommand \index{-\/-peep-asm}
17350 command line option is used, the inline assembler code will be passed through
17351 the peephole optimizer
17352 \begin_inset LatexCommand \index{Peephole optimizer}
17357 There are only a few (if any) cases where this option makes sense, it might
17358 cause some unexpected changes in the inline assembler code.
17359 Please go through the peephole optimizer rules defined in file
17363 before using this option.
17366 \begin_layout Subsection
17368 \begin_inset LatexCommand \label{sub:Naked-Functions}
17373 \begin_inset LatexCommand \index{Naked functions}
17380 \begin_layout Standard
17381 A special keyword may be associated with a function declaring it as
17384 \begin_inset LatexCommand \index{\_naked}
17389 \begin_inset LatexCommand \index{\_\_naked}
17400 function modifier attribute prevents the compiler from generating prologue
17401 \begin_inset LatexCommand \index{function prologue}
17406 \begin_inset LatexCommand \index{function epilogue}
17410 code for that function.
17411 This means that the user is entirely responsible for such things as saving
17412 any registers that may need to be preserved, selecting the proper register
17413 bank, generating the
17417 instruction at the end, etc.
17418 Practically, this means that the contents of the function must be written
17419 in inline assembler.
17420 This is particularly useful for interrupt functions, which can have a large
17421 (and often unnecessary) prologue/epilogue.
17422 For example, compare the code generated by these two functions:
17425 \begin_layout Verse
17429 \begin_inset LatexCommand \index{volatile}
17433 data unsigned char counter;
17437 void simpleInterrupt(void) __interrupt
17438 \begin_inset LatexCommand \index{interrupt}
17443 \begin_inset LatexCommand \index{\_\_interrupt}
17461 void nakedInterrupt(void) __interrupt (2) __naked
17470 \begin_inset LatexCommand \index{\_asm}
17475 \begin_inset LatexCommand \index{\_\_asm}
17492 _counter ; does not change flags, no need to save psw
17505 include ret or reti in _naked function.
17512 \begin_inset LatexCommand \index{\_endasm}
17517 \begin_inset LatexCommand \index{\_\_endasm}
17526 \begin_layout Standard
17527 For an 8051 target, the generated simpleInterrupt looks like:
17530 \begin_layout Verse
17537 example, recent versions of SDCC generate
17543 code for simpleInterrupt() and nakedInterrupt()!
17684 \begin_layout Standard
17685 whereas nakedInterrupt looks like:
17688 \begin_layout Verse
17701 _counter ; does not change flags, no need to save psw
17720 MUST explicitly include ret or reti in _naked function
17723 \begin_layout Standard
17724 The related directive #pragma exclude
17725 \begin_inset LatexCommand \index{\#pragma exclude}
17729 allows a more fine grained control over pushing & popping
17730 \begin_inset LatexCommand \index{push/pop}
17737 \begin_layout Standard
17738 While there is nothing preventing you from writing C code inside a
17742 function, there are many ways to shoot yourself in the foot doing this,
17743 and it is recommended that you stick to inline assembler.
17746 \begin_layout Subsection
17747 Use of Labels within Inline Assembler
17750 \begin_layout Standard
17751 SDCC allows the use of in-line assembler with a few restrictions regarding
17753 All labels defined within inline assembler code have to be of the form
17758 where nnnnn is a number less than 100 (which implies a limit of utmost
17759 100 inline assembler labels
17770 \begin_layout Standard
17771 This is a slightly more stringent rule than absolutely necessary, but stays
17772 always on the safe side.
17773 Labels in the form of nnnnn$ are local labels in the assembler, locality
17774 of which is confined within two labels of the standard form.
17775 The compiler uses the same form for labels within a function (but starting
17776 from nnnnn=00100); and places always a standard label at the beginning
17777 of a function, thus limiting the locality of labels within the scope of
17779 So, if the inline assembler part would be embedded into C-code, an improperly
17780 placed non-local label in the assembler would break up the reference space
17781 for labels created by the compiler for the C-code, leading to an assembling
17785 \begin_layout Standard
17786 The numeric part of local labels does not need to have 5 digits (although
17787 this is the form of labels output by the compiler), any valid integer will
17789 Please refer to the assemblers documentation for further details.
17797 \begin_layout Verse
17801 \begin_inset LatexCommand \index{\_asm}
17806 \begin_inset LatexCommand \index{\_\_asm}
17836 \begin_inset LatexCommand \index{\_endasm}
17841 \begin_inset LatexCommand \index{\_\_endasm}
17848 \begin_layout Standard
17849 Inline assembler code cannot reference any C-labels, however it can reference
17851 \begin_inset LatexCommand \index{Labels}
17855 defined by the inline assembler, e.g.:
17858 \begin_layout Verse
17881 ; some assembler code
17902 /* some more c code */
17904 clabel:\InsetSpace ~
17906 /* inline assembler cannot reference this
17911 \begin_layout Standard
17916 is translated by the compiler into a local label, so the locality of labels
17917 within the function is not broken.
17934 0003$: ;label (can be referenced by inline assembler only)
17941 \begin_inset LatexCommand \index{\_endasm}
17946 \begin_inset LatexCommand \index{\_\_endasm}
17956 /* some more c code */
17961 \begin_layout Standard
17962 In other words inline assembly code can access labels defined in inline
17963 assembly within the scope of the function.
17964 The same goes the other way, i.e.
17965 labels defines in inline assembly can not be accessed by C statements.
17968 \begin_layout Section
17969 Interfacing with Assembler Code
17970 \begin_inset LatexCommand \index{Assembler routines}
17977 \begin_layout Subsection
17978 Global Registers used for Parameter Passing
17979 \begin_inset LatexCommand \index{Parameter passing}
17986 \begin_layout Standard
17987 The compiler always uses the global registers
17990 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17995 \begin_inset LatexCommand \index{DPTR}
18000 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18009 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18015 to pass the first (non-bit) parameter to a function, and also to pass the
18017 \begin_inset LatexCommand \index{return value}
18021 of function; according to the following scheme: one byte return value in
18026 , two byte value in
18035 three byte values (generic pointers) in
18047 , and four byte values in
18065 \begin_inset LatexCommand \index{generic pointer}
18069 contain type of accessed memory in
18090 \begin_inset Note Note
18093 \begin_layout Standard
18094 This might not be the case of certain memory models (medium???)
18102 \begin_layout Standard
18103 The second parameter onwards is either allocated on the stack (for reentrant
18108 \begin_layout Standard
18117 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18120 \begin_layout Standard
18121 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18122 space for reentrant functions or allocated directly in bit memory otherwise.
18125 \begin_layout Standard
18126 Functions (with two or more parameters or bit parameters) that are called
18127 through function pointers
18128 \begin_inset LatexCommand \index{function pointers}
18132 must therefor be reentrant so the compiler knows how to pass the parameters.
18135 \begin_layout Subsection
18139 \begin_layout Standard
18140 Unless the called function is declared as
18145 \begin_inset LatexCommand \index{naked}
18153 \begin_layout Standard
18163 \begin_inset LatexCommand \index{-\/-callee-saves}
18171 \begin_layout Standard
18180 -all-callee-saves command line option or the corresponding callee_saves
18181 pragma are used, the caller will save the registers (
18185 ) around the call, so the called function can destroy they content freely.
18188 \begin_layout Standard
18189 If the called function is not declared as
18193 , the caller will swap register banks around the call, if caller and callee
18194 use different register banks (having them defined by the
18202 \begin_layout Standard
18203 The called function can also use
18219 observing that they are used for parameter/return value passing.
18222 \begin_layout Subsection
18223 Assembler Routine (non-reentrant)
18226 \begin_layout Standard
18227 In the following example
18228 \begin_inset LatexCommand \index{reentrant}
18233 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18237 the function c_func calls an assembler routine asm_func, which takes two
18239 \begin_inset LatexCommand \index{function parameter}
18246 \begin_layout Verse
18249 extern int asm_func(unsigned char, unsigned char);
18253 int c_func (unsigned char
18254 i, unsigned char j)
18262 return asm_func(i,j);
18276 return c_func(10,9);
18281 \begin_layout Standard
18282 The corresponding assembler function is:
18285 \begin_layout Verse
18288 .globl _asm_func_PARM_2
18390 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18407 \begin_layout Standard
18408 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18409 the parameter number starting from 1, and counting from the left.
18410 The first parameter is passed in
18426 according to the description above.
18427 The variable name for the second parameter will be _<function_name>_PARM_2.
18432 ble the assembler routine with the following command:
18439 asx8051 -losg asmfunc.asm
18446 Then compile and link the assembler routine to the C source file with the
18454 sdcc cfunc.c asmfunc.rel
18457 \begin_layout Subsection
18458 Assembler Routine (reentrant)
18461 \begin_layout Standard
18463 \begin_inset LatexCommand \index{reentrant}
18468 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18472 the second parameter
18473 \begin_inset LatexCommand \index{function parameter}
18477 onwards will be passed on the stack, the parameters are pushed from right
18479 before the call the second leftmost parameter will be on the top of the
18480 stack (the leftmost parameter is passed in registers).
18481 Here is an example:
18484 \begin_layout Verse
18487 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18492 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18501 return asm_func(i,j,k);
18515 return c_func(10,9,8);
18520 \begin_layout Standard
18521 The corresponding (unoptimized) assembler routine is:
18524 \begin_layout Verse
18544 _bp,sp\InsetSpace ~
18550 ;stack contains: _bp, return
18551 address, second parameter, third parameter
18575 a,#0xfd\InsetSpace ~
18581 pointer to the second parameter
18605 a,#0xfc\InsetSpace ~
18611 to the rightmost parameter
18652 result (= sum of all three parameters)
18667 ;return value goes into dptr
18701 \begin_layout Standard
18702 The compiling and linking procedure remains the same, however note the extra
18703 entry & exit linkage required for the assembler code, _bp is the stack
18704 frame pointer and is used to compute the offset into the stack for parameters
18705 and local variables.
18706 \begin_inset VSpace bigskip
18712 \begin_layout Section
18714 \begin_inset LatexCommand \index{int (16 bit)}
18719 \begin_inset LatexCommand \index{long (32 bit)}
18726 \begin_layout Standard
18727 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18728 multiplication and modulus operations are implemented by support routines.
18729 These support routines are all developed in ANSI-C to facilitate porting
18730 to other MCUs, although some model specific assembler optimizations are
18732 The following files contain the described routines, all of them can be
18733 found in <installdir>/share/sdcc/lib.
18738 \begin_layout Standard
18740 \begin_inset Tabular
18741 <lyxtabular version="3" rows="11" columns="2">
18743 <column alignment="left" valignment="top" leftline="true" width="0">
18744 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18745 <row topline="true" bottomline="true">
18746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18749 \begin_layout Standard
18757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18760 \begin_layout Standard
18769 <row topline="true">
18770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18773 \begin_layout Standard
18779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18782 \begin_layout Standard
18783 16 bit multiplication
18789 <row topline="true">
18790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18793 \begin_layout Standard
18799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18802 \begin_layout Standard
18803 signed 16 bit division (calls _divuint)
18809 <row topline="true">
18810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18813 \begin_layout Standard
18819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18822 \begin_layout Standard
18823 unsigned 16 bit division
18829 <row topline="true">
18830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18833 \begin_layout Standard
18839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18842 \begin_layout Standard
18843 signed 16 bit modulus (calls _moduint)
18849 <row topline="true">
18850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18853 \begin_layout Standard
18859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18862 \begin_layout Standard
18863 unsigned 16 bit modulus
18869 <row topline="true">
18870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18873 \begin_layout Standard
18879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18882 \begin_layout Standard
18883 32 bit multiplication
18889 <row topline="true">
18890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18893 \begin_layout Standard
18899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18902 \begin_layout Standard
18903 signed 32 division (calls _divulong)
18909 <row topline="true">
18910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18913 \begin_layout Standard
18919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18922 \begin_layout Standard
18923 unsigned 32 division
18929 <row topline="true">
18930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18933 \begin_layout Standard
18939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18942 \begin_layout Standard
18943 signed 32 bit modulus (calls _modulong)
18949 <row topline="true" bottomline="true">
18950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18953 \begin_layout Standard
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18962 \begin_layout Standard
18963 unsigned 32 bit modulus
18978 \begin_layout Standard
18979 Since they are compiled as
18984 \begin_inset LatexCommand \index{reentrant}
18989 \begin_inset LatexCommand \index{interrupt}
18993 service routines should not do any of the above operations.
18994 If this is unavoidable then the above routines will need to be compiled
19001 \begin_layout Standard
19011 \begin_inset LatexCommand \index{-\/-stack-auto}
19017 option, after which the source program will have to be compiled with
19023 \begin_layout Standard
19033 \begin_inset LatexCommand \index{-\/-int-long-reent}
19040 Notice that you don't have to call these routines directly.
19041 The compiler will use them automatically every time an integer operation
19045 \begin_layout Section
19046 Floating Point Support
19047 \begin_inset LatexCommand \index{Floating point support}
19054 \begin_layout Standard
19055 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19056 The floating point support routines are derived from gcc's floatlib.c and
19057 consist of the following routines:
19062 \begin_layout Standard
19066 \begin_inset Tabular
19067 <lyxtabular version="3" rows="17" columns="2">
19069 <column alignment="left" valignment="top" leftline="true" width="0">
19070 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19071 <row topline="true" bottomline="true">
19072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19075 \begin_layout Standard
19090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19093 \begin_layout Standard
19100 <row topline="true">
19101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19104 \begin_layout Standard
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19122 \begin_layout Standard
19132 add floating point numbers
19138 <row topline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19142 \begin_layout Standard
19157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19160 \begin_layout Standard
19170 subtract floating point numbers
19176 <row topline="true">
19177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19180 \begin_layout Standard
19195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19198 \begin_layout Standard
19208 divide floating point numbers
19214 <row topline="true">
19215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19218 \begin_layout Standard
19233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19236 \begin_layout Standard
19246 multiply floating point numbers
19252 <row topline="true">
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19256 \begin_layout Standard
19271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19274 \begin_layout Standard
19284 convert floating point to unsigned char
19290 <row topline="true">
19291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19294 \begin_layout Standard
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19312 \begin_layout Standard
19322 convert floating point to signed char
19328 <row topline="true">
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19332 \begin_layout Standard
19347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19350 \begin_layout Standard
19360 convert floating point to unsigned int
19366 <row topline="true">
19367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19370 \begin_layout Standard
19385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19388 \begin_layout Standard
19398 convert floating point to signed int
19404 <row topline="true">
19405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19408 \begin_layout Standard
19431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19434 \begin_layout Standard
19444 convert floating point to unsigned long
19450 <row topline="true">
19451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19454 \begin_layout Standard
19469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19472 \begin_layout Standard
19482 convert floating point to signed long
19488 <row topline="true">
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19492 \begin_layout Standard
19507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19510 \begin_layout Standard
19520 convert unsigned char to floating point
19526 <row topline="true">
19527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19530 \begin_layout Standard
19545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19548 \begin_layout Standard
19558 convert char to floating point number
19564 <row topline="true">
19565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19568 \begin_layout Standard
19583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19586 \begin_layout Standard
19596 convert unsigned int to floating point
19602 <row topline="true">
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19606 \begin_layout Standard
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19624 \begin_layout Standard
19634 convert int to floating point numbers
19640 <row topline="true">
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19644 \begin_layout Standard
19659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19662 \begin_layout Standard
19672 convert unsigned long to floating point number
19678 <row topline="true" bottomline="true">
19679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19682 \begin_layout Standard
19697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19700 \begin_layout Standard
19710 convert long to floating point number
19725 \begin_layout Standard
19726 These support routines are developed in ANSI-C so there is room for space
19727 and speed improvement
19731 \begin_layout Standard
19732 These floating point routines (
19736 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19743 Note if all these routines are used simultaneously the data space might
19745 For serious floating point usage the large model might be needed.
19746 Also notice that you don't have to call this routines directly.
19747 The compiler will use them automatically every time a floating point operation
19749 \begin_inset VSpace bigskip
19755 \begin_layout Section
19757 \begin_inset LatexCommand \index{Libraries}
19764 \begin_layout Standard
19767 <pending: this is messy and incomplete - a little more information is in
19768 sdcc/doc/libdoc.txt
19773 \begin_layout Subsection
19774 Compiler support routines (_gptrget, _mulint etc.)
19777 \begin_layout Subsection
19778 Stdclib functions (puts, printf, strcat etc.)
19781 \begin_layout Subsubsection
19785 \begin_layout Paragraph
19786 getchar(), putchar()
19789 \begin_layout Standard
19790 \begin_inset LatexCommand \index{<stdio.h>}
19794 As usual on embedded systems you have to provide your own
19797 \begin_inset LatexCommand \index{getchar()}
19806 \begin_inset LatexCommand \index{putchar()}
19813 SDCC does not know whether the system connects to a serial line with or
19814 without handshake, LCD, keyboard or other device.
19828 You'll find examples for serial routines f.e.
19829 in sdcc/device/lib.
19830 For the mcs51 this minimalistic polling
19834 routine might be a start:
19837 \begin_layout Verse
19840 void putchar (char c) {
19846 while (!TI)\InsetSpace ~
19849 /* assumes UART is initialized */
19877 \begin_layout Paragraph
19881 \begin_layout Standard
19885 \begin_inset LatexCommand \index{printf()}
19895 does not support float (except on ds390).
19896 To enable this recompile it with the option
19902 \begin_layout Standard
19912 \begin_inset LatexCommand \index{USE\_FLOATS}
19918 on the command line.
19925 \begin_layout Standard
19935 \begin_inset LatexCommand \index{-\/-model-large}
19941 for the mcs51 port, since this uses a lot of memory.
19944 \begin_layout Standard
19945 If you're short on code memory you might want to use
19948 \begin_inset LatexCommand \index{printf\_small()}
19963 For the mcs51 there additionally are assembly versions
19966 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19972 (subset of printf using less than 270 bytes) and
19975 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19984 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19990 (floating-point aware version of printf_fast) which should fit the requirements
19991 of many embedded systems (printf_fast() can be customized by unsetting
19996 support long variables and field widths).
19997 Be sure to use only one of these printf options within a project.
20002 \begin_layout Standard
20003 Feature matrix of different
20010 \begin_layout Standard
20011 \begin_inset Tabular
20012 <lyxtabular version="3" rows="14" columns="7">
20013 <features islongtable="true">
20014 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20015 <column alignment="center" valignment="top" leftline="true" width="0">
20016 <column alignment="center" valignment="top" leftline="true" width="12col%">
20017 <column alignment="center" valignment="top" leftline="true" width="10col%">
20018 <column alignment="center" valignment="top" leftline="true" width="0">
20019 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20020 <column alignment="center" valignment="top" rightline="true" width="0">
20021 <row topline="true" bottomline="true" endhead="true">
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20025 \begin_layout Standard
20034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20037 \begin_layout Standard
20039 \begin_inset LatexCommand \index{printf}
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20051 \begin_layout Standard
20059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20062 \begin_layout Standard
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20071 \begin_layout Standard
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20080 \begin_layout Standard
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20089 \begin_layout Standard
20096 <row topline="true" endhead="true">
20097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20100 \begin_layout Standard
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_layout Standard
20117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20120 \begin_layout Standard
20128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20131 \begin_layout Standard
20139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20142 \begin_layout Standard
20150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20153 \begin_layout Standard
20161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20164 \begin_layout Standard
20173 <row topline="true" endhead="true">
20174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 \begin_layout Standard
20178 \begin_inset Quotes sld
20182 \begin_inset Quotes srd
20188 \begin_layout Standard
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20197 \begin_layout Standard
20203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20206 \begin_layout Standard
20212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20215 \begin_layout Standard
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_layout Standard
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20233 \begin_layout Standard
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20242 \begin_layout Standard
20249 <row topline="true" endhead="true">
20250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20253 \begin_layout Standard
20257 \begin_layout Standard
20263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20266 \begin_layout Standard
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20275 \begin_layout Standard
20281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20284 \begin_layout Standard
20285 0.45k / 0.47k (+ _ltoa)
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20293 \begin_layout Standard
20299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20302 \begin_layout Standard
20308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20311 \begin_layout Standard
20318 <row topline="true">
20319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20322 \begin_layout Standard
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 \begin_layout Standard
20341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20344 \begin_layout Standard
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_layout Standard
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20436 \begin_layout Standard
20442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20445 \begin_layout Standard
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20454 \begin_layout Standard
20461 <row topline="true">
20462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20465 \begin_layout Standard
20466 long (32 bit) support
20471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20474 \begin_layout Standard
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20483 \begin_layout Standard
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_layout Standard
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20501 \begin_layout Standard
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20510 \begin_layout Standard
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20528 \begin_layout Standard
20535 <row topline="true">
20536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20539 \begin_layout Standard
20540 byte arguments on stack
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20548 \begin_layout Standard
20554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20557 \begin_layout Standard
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20566 \begin_layout Standard
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20575 \begin_layout Standard
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20584 \begin_layout Standard
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20593 \begin_layout Standard
20600 <row topline="true">
20601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20604 \begin_layout Standard
20606 \begin_inset LatexCommand \index{Floating point support}
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20618 \begin_layout Standard
20624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20627 \begin_layout Standard
20633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20636 \begin_layout Standard
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20645 \begin_layout Standard
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20654 \begin_layout Standard
20659 \begin_layout Standard
20660 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20673 \begin_layout Standard
20680 <row topline="true">
20681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20684 \begin_layout Standard
20685 float formats %e %g
20690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20693 \begin_layout Standard
20699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20702 \begin_layout Standard
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20711 \begin_layout Standard
20717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20720 \begin_layout Standard
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20729 \begin_layout Standard
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20738 \begin_layout Standard
20745 <row topline="true" bottomline="true">
20746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20749 \begin_layout Standard
20755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20758 \begin_layout Standard
20764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20767 \begin_layout Standard
20773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20776 \begin_layout Standard
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20785 \begin_layout Standard
20791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20794 \begin_layout Standard
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20803 \begin_layout Standard
20810 <row bottomline="true">
20811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20814 \begin_layout Standard
20819 \begin_layout Standard
20820 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20824 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20832 \begin_layout Standard
20838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20841 \begin_layout Standard
20847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20850 \begin_layout Standard
20856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20859 \begin_layout Standard
20865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20868 \begin_layout Standard
20874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20877 \begin_layout Standard
20883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20886 \begin_layout Standard
20893 <row bottomline="true">
20894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20897 \begin_layout Standard
20902 \begin_layout Standard
20903 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
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" usebox="none">
20957 \begin_layout Standard
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20966 \begin_layout Standard
20971 \begin_layout Standard
20972 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20983 <row bottomline="true">
20984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20987 \begin_layout Standard
20992 \begin_layout Standard
20993 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21002 \begin_layout Standard
21008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21011 \begin_layout Standard
21017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21020 \begin_layout Standard
21026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21029 \begin_layout Standard
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 \begin_layout Standard
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21047 \begin_layout Standard
21053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21056 \begin_layout Standard
21063 <row bottomline="true">
21064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21067 \begin_layout Standard
21072 \begin_layout Standard
21073 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21082 \begin_layout Standard
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21091 \begin_layout Standard
21097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21100 \begin_layout Standard
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21109 \begin_layout Standard
21115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21118 \begin_layout Standard
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21127 \begin_layout Standard
21133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21136 \begin_layout Standard
21150 \begin_layout Subsubsection
21152 \begin_inset LatexCommand \index{malloc.h}
21159 \begin_layout Standard
21160 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21161 using dynamic memory allocation
21162 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21167 \begin_inset LatexCommand \index{heap (malloc)}
21171 space of 1024 bytes is provided for malloc to allocate memory from.
21172 If you need a different heap size you need to recompile _heap.c with the
21173 required size defined in HEAP_SIZE.
21174 It is recommended to make a copy of this file into your project directory
21175 and compile it there with:
21178 \begin_layout Verse
21181 sdcc -c _heap.c -D HEAD_SIZE=2048
21184 \begin_layout Standard
21185 And then link it with:
21188 \begin_layout Verse
21191 sdcc main.rel _heap.rel
21194 \begin_layout Subsection
21195 Math functions (sinf, powf, sqrtf etc.)
21198 \begin_layout Subsubsection
21202 \begin_layout Standard
21203 See definitions in file <math.h>.
21206 \begin_layout Subsection
21210 \begin_layout Standard
21212 \begin_inset LatexCommand \index{Libraries}
21216 included in SDCC should have a license at least as liberal as the GNU Lesser
21217 General Public License
21218 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21229 \begin_layout Standard
21230 \begin_inset Note Note
21233 \begin_layout Standard
21234 license statements for the libraries are missing.
21235 sdcc/device/lib/ser_ir.c
21238 \begin_layout Standard
21240 come with a GPL (as opposed to LGPL) License - this will not be liberal
21241 enough for many embedded programmers.
21249 \begin_layout Standard
21250 If you have ported some library or want to share experience about some code
21252 falls into any of these categories Busses (I
21253 \begin_inset Formula $^{\textrm{2}}$
21256 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21257 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21258 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21259 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21264 would certainly like to hear about it.
21267 \begin_layout Standard
21268 Programmers coding for embedded systems are not especially famous for being
21269 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21270 e these references are very valuable.
21271 Let's help to create a climate where information is shared.
21272 \begin_inset VSpace bigskip
21278 \begin_layout Section
21282 \begin_layout Subsection
21283 MCS51 Memory Models
21284 \begin_inset LatexCommand \index{Memory model}
21289 \begin_inset LatexCommand \index{MCS51 memory model}
21296 \begin_layout Subsubsection
21297 Small, Medium and Large
21300 \begin_layout Standard
21301 SDCC allows three memory models for MCS51 code,
21310 Modules compiled with different memory models should
21314 be combined together or the results would be unpredictable.
21315 The library routines supplied with the compiler are compiled as small,
21317 The compiled library modules are contained in separate directories as small,
21318 medium and large so that you can link to the appropriate set.
21321 \begin_layout Standard
21322 When the medium or large model is used all variables declared without a
21323 storage class will be allocated into the external ram, this includes all
21324 parameters and local variables (for non-reentrant
21325 \begin_inset LatexCommand \index{reentrant}
21330 When the small model is used variables without storage class are allocated
21331 in the internal ram.
21334 \begin_layout Standard
21335 Judicious usage of the processor specific storage classes
21336 \begin_inset LatexCommand \index{Storage class}
21340 and the 'reentrant' function type will yield much more efficient code,
21341 than using the large model.
21342 Several optimizations are disabled when the program is compiled using the
21343 large model, it is therefore recommended that the small model be used unless
21344 absolutely required.
21347 \begin_layout Subsubsection
21349 \begin_inset LatexCommand \label{sub:External-Stack}
21354 \begin_inset LatexCommand \index{stack}
21359 \begin_inset LatexCommand \index{External stack (mcs51)}
21366 \begin_layout Standard
21367 The external stack (-
21371 \begin_layout Standard
21381 \begin_inset LatexCommand \index{-\/-xstack}
21385 ) is located in pdata
21386 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21390 memory (usually at the start of the external ram segment) and uses all
21391 unused space in pdata (max.
21397 \begin_layout Standard
21406 -xstack option is used to compile the program, the parameters and local
21408 \begin_inset LatexCommand \index{local variables}
21412 of all reentrant functions are allocated in this area.
21413 This option is provided for programs with large stack space requirements.
21414 When used with the -
21418 \begin_layout Standard
21428 \begin_inset LatexCommand \index{-\/-stack-auto}
21432 option, all parameters and local variables are allocated on the external
21433 stack (note: support libraries will need to be recompiled with the same
21435 There is a predefined target in the library makefile).
21438 \begin_layout Standard
21439 The compiler outputs the higher order address byte of the external ram segment
21441 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21446 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21450 ), therefore when using the External Stack option, this port
21454 be used by the application program.
21457 \begin_layout Subsection
21459 \begin_inset LatexCommand \index{Memory model}
21464 \begin_inset LatexCommand \index{DS390 memory model}
21471 \begin_layout Standard
21472 The only model supported is Flat 24
21473 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21478 This generates code for the 24 bit contiguous addressing mode of the Dallas
21480 In this mode, up to four meg of external RAM or code space can be directly
21482 See the data sheets at www.dalsemi.com for further information on this part.
21487 that the compiler does not generate any code to place the processor into
21488 24 bitmode (although
21492 in the ds390 libraries will do that for you).
21498 \begin_inset LatexCommand \index{Tinibios (DS390)}
21502 , the boot loader or similar code must ensure that the processor is in 24
21503 bit contiguous addressing mode before calling the SDCC startup code.
21514 \begin_layout Standard
21525 option, variables will by default be placed into the XDATA segment.
21530 Segments may be placed anywhere in the 4 meg address space using the usual
21535 \begin_layout Standard
21545 Note that if any segments are located above 64K, the -r flag must be passed
21546 to the linker to generate the proper segment relocations, and the Intel
21547 HEX output format must be used.
21548 The -r flag can be passed to the linker by using the option
21552 on the SDCC command line.
21553 However, currently the linker can not handle code segments > 64k.
21556 \begin_layout Section
21558 \begin_inset LatexCommand \label{sec:Pragmas}
21563 \begin_inset LatexCommand \index{Pragmas}
21570 \begin_layout Standard
21571 Pragmas are used to turn on and/or off certain compiler options.
21572 Some of them are closely related to corresponding command-line options
21574 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21580 Pragmas should be placed before and/or after a function, placing pragmas
21581 inside a function body could have unpredictable results.
21586 following #pragma directives:
21589 \begin_layout Itemize
21595 \begin_inset LatexCommand \index{\#pragma save}
21599 - this will save most current options to the save/restore stack.
21600 See #pragma\InsetSpace ~
21604 \begin_layout Itemize
21610 \begin_inset LatexCommand \index{\#pragma restore}
21614 - will restore saved options from the last save.
21615 saves & restores can be nested.
21616 SDCC uses a save/restore stack: save pushes current options to the stack,
21617 restore pulls current options from the stack.
21618 See #pragma\InsetSpace ~
21624 \begin_layout Itemize
21630 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21635 \begin_inset LatexCommand \index{function prologue}
21639 function1[,function2[,function3...]]
21640 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21644 - The compiler by default uses a caller saves convention for register saving
21645 across function calls, however this can cause unnecessary register pushing
21647 \begin_inset LatexCommand \index{push/pop}
21651 when calling small functions from larger functions.
21652 This option can be used to switch off the register saving convention for
21653 the function names specified.
21654 The compiler will not save registers when calling these functions, extra
21655 code need to be manually inserted at the entry and exit for these functions
21656 to save and restore the registers used by these functions, this can SUBSTANTIAL
21657 LY reduce code and improve run time performance of the generated code.
21658 In the future the compiler (with inter procedural analysis) may be able
21659 to determine the appropriate scheme to use for each function call.
21664 \begin_layout Standard
21673 -callee-saves command line option is used (see page
21674 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21678 ), the function names specified in #pragma\InsetSpace ~
21680 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21684 is appended to the list of functions specified in the command line.
21687 \begin_layout Itemize
21693 \begin_inset LatexCommand \index{\#pragma exclude}
21697 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21698 of pairs of push/pop
21699 \begin_inset LatexCommand \index{push/pop}
21708 \begin_inset LatexCommand \index{interrupt}
21721 The directive should be placed immediately before the ISR function definition
21722 and it affects ALL ISR functions following it.
21723 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21724 exclude\InsetSpace ~
21726 \begin_inset LatexCommand \index{\#pragma exclude}
21731 See also the related keyword _naked
21732 \begin_inset LatexCommand \index{\_naked}
21737 \begin_inset LatexCommand \index{\_\_naked}
21744 \begin_layout Itemize
21750 \begin_inset LatexCommand \index{pedantic}
21755 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21760 \begin_inset LatexCommand \label{ite:less_pedantic}
21764 - the compiler will not warn you anymore for obvious mistakes, you're on
21766 See also the command line option -
21770 \begin_layout Standard
21780 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21787 More specifically, the following warnings will be disabled:
21789 comparison is always [true/false] due to limited range of data type
21793 overflow in implicit constant conversion
21795 (158); [the (in)famous]
21797 conditional flow changed by optimizer: so said EVELYN the modified DOG
21801 function '[function name]' must return value
21806 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21807 level) are disabled, too, namely:
21810 \begin_inset Note Note
21813 \begin_layout Standard
21814 dunno what comes here - this warning appears to be unused altogether
21823 [left/right] shifting more than size of object changed to zero
21831 integer overflow in expression
21835 unmatched #pragma save and #pragma restore
21839 comparison of 'signed char' with 'unsigned char' requires promotion to int
21843 ISO C90 does not support flexible array members
21847 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21851 \begin_inset Note Note
21854 \begin_layout Standard
21855 appears to be always blank - what was supposed to be here?
21864 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21865 complexity [number]
21870 \begin_layout Itemize
21876 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21880 - the compiler will not warn you anymore about warning number <nnnn>.
21883 \begin_layout Itemize
21889 \begin_inset LatexCommand \index{\#pragma nogcse}
21893 - will stop global common subexpression elimination.
21896 \begin_layout Itemize
21902 \begin_inset LatexCommand \index{\#pragma noinduction}
21906 - will stop loop induction optimizations.
21909 \begin_layout Itemize
21915 \begin_inset LatexCommand \index{\#pragma noinvariant}
21919 - will not do loop invariant optimizations.
21920 For more details see Loop Invariants in section
21921 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21928 \begin_layout Itemize
21934 \begin_inset LatexCommand \index{\#pragma noiv}
21938 - Do not generate interrupt
21939 \begin_inset LatexCommand \index{interrupt}
21944 \begin_inset LatexCommand \index{interrupt vector table}
21948 entries for all ISR functions defined after the pragma.
21949 This is useful in cases where the interrupt vector table must be defined
21950 manually, or when there is a secondary, manually defined interrupt vector
21952 for the autovector feature of the Cypress EZ-USB FX2).
21953 More elegantly this can be achieved by obmitting the optional interrupt
21954 number after the interrupt keyword, see section
21955 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21963 \begin_layout Itemize
21969 \begin_inset LatexCommand \index{\#pragma nojtbound}
21973 - will not generate code for boundary value checking, when switch statements
21974 are turned into jump-tables (dangerous).
21975 For more details see section
21976 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21983 \begin_layout Itemize
21989 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21993 - Will not do loop reversal optimization
21996 \begin_layout Itemize
22002 \begin_inset LatexCommand \index{\#pragma nooverlay}
22006 - the compiler will not overlay the parameters and local variables of a
22010 \begin_layout Itemize
22016 \begin_inset LatexCommand \index{\#pragma stackauto}
22024 \begin_layout Standard
22034 \begin_inset LatexCommand \index{-\/-stack-auto}
22039 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22043 Parameters and Local Variables.
22046 \begin_layout Itemize
22052 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22056 - The compiler will optimize code generation towards fast code, possibly
22057 at the expense of code size.
22058 Currently this has little effect.
22061 \begin_layout Itemize
22067 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22071 - The compiler will optimize code generation towards compact code, possibly
22072 at the expense of code speed.
22073 Currently this has little effect.
22076 \begin_layout Itemize
22082 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22086 - The compiler will attempt to generate code that is both compact and fast,
22087 as long as meeting one goal is not a detriment to the other (this is the
22092 \begin_layout Itemize
22098 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22102 - Generally follow the C89 standard, but allow SDCC features that conflict
22103 with the standard (default).
22106 \begin_layout Itemize
22112 \begin_inset LatexCommand \index{\#pragma std\_c89}
22116 - Follow the C89 standard and disable SDCC features that conflict with the
22120 \begin_layout Itemize
22126 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22130 - Generally follow the C99 standard, but allow SDCC features that conflict
22131 with the standard (incomplete support).
22134 \begin_layout Itemize
22140 \begin_inset LatexCommand \index{\#pragma std\_c99}
22144 - Follow the C99 standard and disable SDCC features that conflict with the
22145 standard (incomplete support).
22148 \begin_layout Itemize
22154 \begin_inset LatexCommand \index{\#pragma codeseg}
22158 - Use this name (max.
22159 8 characters) for the code segment.
22164 \begin_layout Standard
22176 \begin_layout Itemize
22182 \begin_inset LatexCommand \index{\#pragma constseg}
22186 - Use this name (max.
22187 8 characters) for the const segment.
22192 \begin_layout Standard
22204 \begin_layout Standard
22205 The preprocessor SDCPP
22206 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22210 supports the following #pragma directives:
22213 \begin_layout Itemize
22216 pedantic_parse_number
22219 \begin_inset LatexCommand \index{pedantic}
22224 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22229 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22233 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22234 properly and the macro LO_B(3) gets expanded.
22240 \begin_layout Standard
22249 -pedantic-parse-number command line option
22250 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22257 Below is an example on how to use this pragma.
22260 Note: this functionality is not in conformance with standard!
22263 \begin_layout Verse
22266 #pragma pedantic_parse_number +
22267 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22275 #define LO_B(x) ((x) & 0xff)
22279 unsigned char foo(void)
22286 unsigned char c=0xfe-LO_B(3)
22301 \begin_layout Itemize
22307 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22311 (+ | -) - switch _asm _endasm block preprocessing on / off.
22313 You use this prama to define multilines of assembly code.
22314 This will prevent the preprocessor from changing the formating required
22316 Below is an example on how to use this pragma.
22319 \begin_layout Verse
22322 #pragma preproc_asm -
22323 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22329 #define MYDELAY _asm
22334 nop ;my assembly comment...
22348 #pragma preproc_asm
22379 \begin_layout Itemize
22385 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22389 (+ | -) - Allow "naked" hash in macro definition, for example:
22393 #define DIR_LO(x) #(x & 0xff)
22398 Below is an example on how to use this pragma.
22401 \begin_layout Verse
22404 #pragma preproc_asm +
22406 #pragma sdcc_hash +
22407 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22422 mov R6_B3, #(x & 0xff)
22429 mov R7_B3, #((x >> 8) & 0xff)
22453 \begin_layout Standard
22454 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22455 ons which might cause the compiler to generate extra stack and/or data space
22456 to store compiler generated temporary variables.
22457 This usually happens in large functions.
22458 Pragma directives should be used as shown in the following example, they
22459 are used to control options and optimizations for a given function.
22463 \begin_layout Verse
22467 \begin_inset LatexCommand \index{\#pragma save}
22478 /* save the current settings */
22481 \begin_inset LatexCommand \index{\#pragma nogcse}
22490 /* turnoff global subexpression elimination */
22492 #pragma noinduction
22493 \begin_inset LatexCommand \index{\#pragma noinduction}
22497 /* turn off induction optimizations */
22520 \begin_inset LatexCommand \index{\#pragma restore}
22524 /* turn the optimizations back on */
22527 \begin_layout Standard
22528 The compiler will generate a warning message when extra space is allocated.
22529 It is strongly recommended that the save and restore pragmas be used when
22530 changing options for a function.
22539 \begin_layout Section
22540 Defines Created by the Compiler
22543 \begin_layout Standard
22544 The compiler creates the following #defines
22545 \begin_inset LatexCommand \index{\#defines}
22550 \begin_inset LatexCommand \index{Defines created by the compiler}
22559 \begin_layout Standard
22560 \begin_inset Tabular
22561 <lyxtabular version="3" rows="11" columns="2">
22563 <column alignment="left" valignment="top" leftline="true" width="3in">
22564 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22565 <row topline="true" bottomline="true">
22566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22569 \begin_layout Standard
22577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22580 \begin_layout Standard
22589 <row topline="true">
22590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22593 \begin_layout Standard
22595 \begin_inset LatexCommand \index{SDCC}
22604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22607 \begin_layout Standard
22609 Since version 2.5.6 the version number as an int (ex.
22616 <row topline="true">
22617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22620 \begin_layout Standard
22622 \begin_inset LatexCommand \index{SDCC\_mcs51}
22627 \begin_inset LatexCommand \index{SDCC\_ds390}
22632 \begin_inset LatexCommand \index{SDCC\_z80}
22641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22644 \begin_layout Standard
22645 depending on the model used (e.g.: -mds390)
22651 <row topline="true">
22652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22655 \begin_layout Standard
22657 \begin_inset LatexCommand \index{\_\_mcs51}
22662 \begin_inset LatexCommand \index{\_\_ds390}
22667 \begin_inset LatexCommand \index{\_\_hc08}
22672 \begin_inset LatexCommand \index{\_\_z80}
22681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22684 \begin_layout Standard
22685 depending on the model used (e.g.
22692 <row topline="true">
22693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22696 \begin_layout Standard
22698 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22710 \begin_layout Standard
22717 \begin_layout Standard
22734 <row topline="true">
22735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22738 \begin_layout Standard
22740 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22752 \begin_layout Standard
22759 \begin_layout Standard
22776 <row topline="true">
22777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22780 \begin_layout Standard
22782 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22794 \begin_layout Standard
22801 \begin_layout Standard
22818 <row topline="true">
22819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22822 \begin_layout Standard
22824 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22836 \begin_layout Standard
22843 \begin_layout Standard
22860 <row topline="true">
22861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22864 \begin_layout Standard
22866 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22878 \begin_layout Standard
22885 \begin_layout Standard
22902 <row topline="true">
22903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22906 \begin_layout Standard
22908 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22920 \begin_layout Standard
22931 <row topline="true" bottomline="true">
22932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22935 \begin_layout Standard
22937 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22949 \begin_layout Standard
22967 \begin_layout Chapter
22968 Notes on supported Processors
22971 \begin_layout Section
22973 \begin_inset LatexCommand \label{sub:MCS51-variants}
22978 \begin_inset LatexCommand \index{MCS51 variants}
22985 \begin_layout Standard
22986 MCS51 processors are available from many vendors and come in many different
22988 While they might differ considerably in respect to Special Function Registers
22989 the core MCS51 is usually not modified or is kept compatible.
22993 \begin_layout Subsection
22994 pdata access by SFR
22997 \begin_layout Standard
22998 With the upcome of devices with internal xdata and flash memory devices
23000 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23004 as dedicated I/O port is becoming more popular.
23005 Switching the high byte for pdata
23006 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23010 access which was formerly done by port P2 is then achieved by a Special
23012 \begin_inset LatexCommand \index{sfr}
23017 In well-established MCS51 tradition the address of this
23021 is where the chip designers decided to put it.
23022 Needless to say that they didn't agree on a common name either.
23023 So that the startup code can correctly initialize xdata variables, you
23024 should define an sfr with the name _XPAGE
23027 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23033 at the appropriate location if the default, port P2, is not used for this.
23037 \begin_layout Verse
23040 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23044 \begin_layout Verse
23047 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23052 \begin_layout Verse
23055 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23059 \begin_layout Verse
23062 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23066 \begin_layout Verse
23069 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23073 \begin_layout Standard
23074 For more exotic implementations further customizations may be needed.
23076 \begin_inset LatexCommand \ref{sub:Startup-Code}
23080 for other possibilities.
23083 \begin_layout Subsection
23084 Other Features available by SFR
23087 \begin_layout Standard
23088 Some MCS51 variants offer features like Double DPTR
23089 \begin_inset LatexCommand \index{DPTR}
23093 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23094 These are currently not used for the MCS51 port.
23095 If you absolutely need them you can fall back to inline assembly or submit
23097 \begin_inset VSpace bigskip
23103 \begin_layout Section
23107 \begin_layout Standard
23109 \begin_inset LatexCommand \index{DS80C400}
23114 \begin_inset LatexCommand \index{DS400}
23118 microcontroller has a rich set of peripherals.
23119 In its built-in ROM library it includes functions to access some of the
23120 features, among them is a TCP stack with IP4 and IP6 support.
23121 Library headers (currently in beta status) and other files are provided
23125 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23131 \begin_inset VSpace bigskip
23137 \begin_layout Section
23138 The Z80 and gbz80 port
23141 \begin_layout Standard
23142 SDCC can target both the Zilog Z80
23143 \begin_inset LatexCommand \index{Z80}
23147 and the Nintendo Gameboy's Z80-like gbz80
23148 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23153 The Z80 port is passed through the same
23156 \begin_inset LatexCommand \index{Regression test}
23163 \begin_inset LatexCommand \ref{sec:Quality-control}
23167 ) as the MCS51 and DS390 ports, so floating point support, support for long
23168 variables and bitfield support is fine.
23169 See mailing lists and forums about interrupt routines.
23172 \begin_layout Standard
23173 As always, the code is the authoritative reference - see z80/ralloc.c and
23176 \begin_inset LatexCommand \index{Z80!stack}
23180 frame is similar to that generated by the IAR Z80 compiler.
23181 IX is used as the base pointer, HL and IY are used as a temporary registers,
23182 and BC and DE are available for holding variables.
23184 \begin_inset LatexCommand \index{Z80!return value}
23188 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23190 The gbz80 port use the same set of registers for the return values, but
23191 in a different order of significance: E (one byte), DE (two bytes), or
23193 \begin_inset VSpace bigskip
23199 \begin_layout Section
23203 \begin_layout Standard
23204 The port to the Freescale/Motorola HC08
23205 \begin_inset LatexCommand \index{HC08}
23209 family has been added in October 2003, and is still undergoing some basic
23211 The code generator is complete, but the register allocation is still quite
23213 Some of the SDCC's standard C library functions have embedded non-HC08
23214 inline assembly and so are not yet usable.
23217 \begin_layout Standard
23218 The HC08 port passes the regression test suite (see section
23219 \begin_inset LatexCommand \ref{sec:Quality-control}
23224 \begin_inset VSpace bigskip
23232 \begin_layout Section
23234 \begin_inset LatexCommand \index{PIC14}
23241 \begin_layout Standard
23242 The PIC14 port adds support for Microchip
23243 \begin_inset LatexCommand \index{Microchip}
23248 \begin_inset Formula $^{\text{TM}}$
23252 \begin_inset LatexCommand \index{PIC14}
23257 \begin_inset Formula $^{\text{TM}}$
23260 MCUs with 14 bit wide instructions.
23261 This port is not yet mature and still lacks many features.
23262 However, it can work for simple code.
23265 \begin_layout Standard
23266 Currently supported devices include:
23269 \begin_layout Standard
23270 12F: 629, 635, 675, 683
23273 \begin_layout Standard
23277 \begin_layout Standard
23281 \begin_layout Standard
23282 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23285 \begin_layout Standard
23286 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23290 \begin_layout Standard
23294 \begin_layout Standard
23295 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23299 \begin_layout Standard
23300 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23303 \begin_layout Standard
23304 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23308 \begin_layout Standard
23309 16F: 913, 914, 916, 917
23312 \begin_layout Standard
23313 An up-to-date list of currently supported devices can be obtained via
23315 sdcc -mpic14 -phelp foo.c
23317 (foo.c must exist...).
23320 \begin_layout Subsection
23322 \begin_inset LatexCommand \index{code page (pic14)}
23327 \begin_inset LatexCommand \index{Memory bank (pic14)}
23334 \begin_layout Standard
23335 The linker organizes allocation for the code page and RAM banks.
23336 It does not have intimate knowledge of the code flow.
23337 It will put all the code section of a single .asm file into a single code
23339 In order to make use of multiple code pages, separate asm files must be
23341 The compiler assigns all
23345 functions of a single .c file into the same code page.
23349 To get the best results,
23350 follow these guidelines:
23353 \begin_layout Enumerate
23354 Make local functions static, as non static functions require code page selection
23357 Due to the way sdcc handles functions, place called functions prior
23358 to calling functions in the file wherever possible: Otherwise sdcc will
23359 insert unneccessary pagesel directives around the call, believing that
23360 the called function is externally defined.
23363 \begin_layout Enumerate
23364 For devices that have multiple code pages it is more efficient to use the
23365 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23366 but only 2 files for the 16F874.
23367 This way the linker can put the code for each file into different code
23368 pages and there will be less page selection overhead.
23371 \begin_layout Enumerate
23372 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23373 instruction set), use `unsigned char' wherever possible instead of `int'.
23376 \begin_layout Subsection
23377 Adding New Devices to the Port
23380 \begin_layout Standard
23381 Adding support for a new 14
23385 \begin_layout Standard
23394 bit PIC MCU requires the following steps:
23397 \begin_layout Enumerate
23398 Create a new device description.
23400 Each device is described in two files: pic16f*.h
23402 These files primarily define SFRs, structs to access their bits, and symbolic
23403 configuration options.
23404 Both files can be generated from gputils' .inc files using the perl script
23407 support/scripts/inc2h.pl
23410 This file also contains further instructions on how to proceed.
23413 \begin_layout Enumerate
23414 Copy the .h file into SDCC's include path and either add the .c file to your
23415 project or copy it to
23417 device/lib/pic/libdev
23420 Afterwards, rebuild and install the libraries.
23423 \begin_layout Enumerate
23424 Edit pic14devices.txt in SDCC's include path (
23426 device/include/pic/
23428 in the source tree or
23430 /usr/local/share/sdcc/include/pic
23432 after installation).
23434 You need to add a device specification here to make
23435 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23437 Probably you can copy and modify an existing entry.
23438 The file format is documented at the top of the file.
23441 \begin_layout Subsection
23445 \begin_layout Standard
23446 For the interrupt function, use the keyword `__interrupt'
23447 \begin_inset LatexCommand \index{PIC14!interrupt}
23451 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23452 there to avoid a syntax error - it ought to be fixed).
23456 \begin_layout Verse
23459 void Intr(void) __interrupt 0
23465 T0IF = 0; /* Clear timer interrupt */
23470 \begin_layout Subsection
23471 Linking and Assembling
23474 \begin_layout Standard
23475 For assembling you can use either GPUTILS'
23476 \begin_inset LatexCommand \index{gputils (pic tools)}
23480 gpasm.exe or MPLAB's mpasmwin.exe.
23481 GPUTILS are available from
23482 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23487 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23488 If you use MPLAB and an interrupt function then the linker script file
23489 vectors section will need to be enlarged to link with mplink.
23500 \begin_layout Verse
23513 sdcc -V -mpic14 -p16f877 -c $<
23517 $(PRJ).hex: $(OBJS)
23527 gplink -m -s $(PRJ).lkr
23528 -o $(PRJ).hex $(OBJS) libsdcc.lib
23531 \begin_layout Standard
23539 \begin_layout Verse
23552 sdcc -S -V -mpic14 -p16f877 $<
23562 mpasmwin /q /o $*.asm
23566 $(PRJ).hex: $(OBJS)
23577 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23580 \begin_layout Standard
23581 Please note that indentations within a
23585 have to be done with a tabulator character.
23588 \begin_layout Subsection
23589 Command-Line Options
23592 \begin_layout Standard
23593 Besides the switches common to all SDCC backends, the PIC14 port accepts
23594 the following options (for an updated list see sdcc -
23598 \begin_layout Standard
23610 \begin_layout Description
23615 \begin_layout Standard
23625 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23629 emit debug info in assembly output
23632 \begin_layout Description
23637 \begin_layout Standard
23647 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23651 disable (slightly faulty) optimization on pCode
23654 \begin_layout Description
23659 \begin_layout Standard
23669 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23673 sets the lowest address of the argument passing stack (defaults to a suitably
23674 large shared databank to reduce BANKSEL overhead)
23677 \begin_layout Description
23682 \begin_layout Standard
23692 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23696 sets the size if the argument passing stack (default: 16, minimum: 4)
23699 \begin_layout Subsection
23700 Environment Variables
23703 \begin_layout Standard
23704 The PIC14 port recognizes the following environment variables:
23707 \begin_layout Description
23708 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23709 register (the ones called r0xNNNN) in a section of its own.
23710 By default (if this variable is unset), sdcc tries to cluster registers
23711 in sections in order to reduce the BANKSEL overhead when accessing them.
23714 \begin_layout Subsection
23718 \begin_layout Standard
23719 The PIC14 library currently only contains support routines required by the
23720 compiler to implement multiplication, division, and floating point support.
23721 No libc-like replacement is available at the moment, though many of the
23722 common sdcc library sources (in
23726 ) should also compile with the PIC14 port.
23729 \begin_layout Subsubsection
23730 error: missing definition for symbol ``__gptrget1''
23733 \begin_layout Standard
23734 The PIC14 port uses library routines to provide more complex operations
23735 like multiplication, division/modulus and (generic) pointer dereferencing.
23736 In order to add these routines to your project, you must link with PIC14's
23742 For single source file projects this is done automatically, more complex
23747 to the linker's arguments.
23748 Make sure you also add an include path for the library (using the -I switch
23752 \begin_layout Subsubsection
23753 Processor mismatch in file ``XXX''.
23756 \begin_layout Standard
23757 This warning can usually be ignored due to the very good compatibility amongst
23762 \begin_layout Standard
23772 \begin_inset LatexCommand \index{PIC14}
23779 \begin_layout Standard
23780 You might also consider recompiling the library for your specific device
23781 by changing the ARCH=p16f877 (default target) entry in
23783 device/lib/pic/Makefile.in
23787 device/lib/pic/Makefile
23789 to reflect your device.
23790 This might even improve performance for smaller devices as unneccesary
23791 BANKSELs might be removed.
23794 \begin_layout Subsection
23798 \begin_layout Subsubsection
23802 \begin_layout Standard
23803 Functions with variable argument lists (like printf) are not yet supported.
23804 Similarly, taking the argument of the first argument passed into a function
23805 does not work: It is currently passed in WREG and has no address...
23808 \begin_layout Subsubsection
23809 Regression tests fail
23812 \begin_layout Standard
23813 Though the small subset of regression tests in src/regression passes, SDCC
23814 regression test suite does not, indicating that there are still major bugs
23816 However, many smaller projects have successfully used SDCC in the past...
23819 \begin_layout Standard
23827 \begin_layout Section
23829 \begin_inset LatexCommand \index{PIC16}
23836 \begin_layout Standard
23837 The PIC16 port adds support for Microchip
23838 \begin_inset LatexCommand \index{Microchip}
23843 \begin_inset Formula $^{\text{TM}}$
23847 \begin_inset LatexCommand \index{PIC}
23852 \begin_inset Formula $^{\text{TM}}$
23855 MCUs with 16 bit wide instructions.
23856 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23857 ; devices supported by the port include:
23860 \begin_layout Standard
23861 18F: 242, 248, 252, 258, 442, 448, 452, 458
23864 \begin_layout Standard
23868 \begin_layout Standard
23869 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23873 \begin_layout Standard
23874 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23878 \begin_layout Standard
23879 18F: 6520, 6620, 6680, 6720
23882 \begin_layout Standard
23883 18F: 8520, 8620, 8680, 8720
23886 \begin_layout Subsection
23890 \begin_layout Standard
23891 PIC16 port supports the standard command line arguments as supposed, with
23892 the exception of certain cases that will be mentioned in the following
23896 \begin_layout Description
23901 \begin_layout Standard
23911 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23919 \begin_layout Standard
23931 \begin_layout Description
23936 \begin_layout Standard
23945 -fommit-frame-pointer
23946 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23950 Frame pointer will be omitted when the function uses no local variables.
23953 \begin_layout Subsection
23954 Port Specific Options
23955 \begin_inset LatexCommand \index{Options PIC16}
23962 \begin_layout Standard
23963 The port specific options appear after the global options in the sdcc -
23967 \begin_layout Standard
23979 \begin_layout Subsubsection
23980 Code Generation Options
23983 \begin_layout Standard
23984 These options influence the generated assembler code.
23987 \begin_layout Description
23992 \begin_layout Standard
24001 -pstack-model=[model] Used in conjuction with the command above.
24002 Defines the stack model to be used, valid stack models are:
24007 \labelwidthstring 00.00.0000
24012 Selects small stack model.
24013 8 bit stack and frame pointers.
24014 Supports 256 bytes stack size.
24018 \labelwidthstring 00.00.0000
24023 Selects large stack model.
24024 16 bit stack and frame pointers.
24025 Supports 65536 bytes stack size.
24029 \begin_layout Description
24034 \begin_layout Standard
24043 -pno-banksel Do not generate BANKSEL assembler directives.
24046 \begin_layout Description
24051 \begin_layout Standard
24060 -extended Enable extended instruction set/literal offset addressing mode.
24064 \begin_layout Subsubsection
24065 Optimization Options
24068 \begin_layout Description
24073 \begin_layout Standard
24082 -obanksel=n Set optimization level for inserting BANKSELs.
24089 \labelwidthstring 00.00.0000
24094 \labelwidthstring 00.00.0000
24095 1 checks previous used register and if it is the same then does not emit
24096 BANKSEL, accounts only for labels.
24100 \labelwidthstring 00.00.0000
24101 2 tries to check the location of (even different) symbols and removes BANKSELs
24102 if they are in the same bank.
24107 Important: There might be problems if the linker script has data sections
24108 across bank borders!
24112 \begin_layout Description
24117 \begin_layout Standard
24126 -denable-peeps Force the usage of peepholes.
24130 \begin_layout Description
24135 \begin_layout Standard
24144 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24147 \begin_layout Description
24152 \begin_layout Standard
24161 -optimize-cmp Try to optimize some compares.
24164 \begin_layout Description
24169 \begin_layout Standard
24178 -optimize-df Analyze the dataflow of the generated code and improve it.
24181 \begin_layout Subsubsection
24185 \begin_layout Description
24190 \begin_layout Standard
24199 -asm= Sets the full path and name of an external assembler to call.
24202 \begin_layout Description
24207 \begin_layout Standard
24217 \begin_inset LatexCommand \index{PIC16!MPLAB}
24221 compatibility option.
24222 Currently only suppresses special gpasm directives.
24225 \begin_layout Subsubsection
24229 \begin_layout Description
24234 \begin_layout Standard
24243 -link= Sets the full path and name of an external linker to call.
24246 \begin_layout Description
24251 \begin_layout Standard
24260 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24261 unitialized data variables with [kword].
24262 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24265 \begin_layout Description
24270 \begin_layout Standard
24279 -ivt-loc=n Place the interrupt vector table at address
24284 Useful for bootloaders.
24287 \begin_layout Description
24292 \begin_layout Standard
24301 -nodefaultlibs Do not link default libraries when linking.
24304 \begin_layout Description
24309 \begin_layout Standard
24318 -use-crt= Use a custom run-time module instead of the defaults.
24321 \begin_layout Description
24326 \begin_layout Standard
24335 -no-crt Don't link the default run-time modules
24338 \begin_layout Subsubsection
24342 \begin_layout Standard
24343 Debugging options enable extra debugging information in the output files.
24346 \begin_layout Description
24351 \begin_layout Standard
24360 -debug-xtra Similar to -
24364 \begin_layout Standard
24374 \begin_inset LatexCommand \index{-\/-debug}
24378 , but dumps more information.
24381 \begin_layout Description
24386 \begin_layout Standard
24395 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24397 <source> is the name of the file being compiled.
24400 \begin_layout Description
24405 \begin_layout Standard
24414 -pcode-verbose Enable pcode debugging information in translation.
24417 \begin_layout Description
24422 \begin_layout Standard
24431 -calltree Dump call tree in .calltree file.
24434 \begin_layout Description
24439 \begin_layout Standard
24448 -gstack Trace push/pops for stack pointer overflow.
24451 \begin_layout Subsection
24452 Enviroment Variables
24455 \begin_layout Standard
24456 There is a number of enviromental variables that can be used when running
24457 SDCC to enable certain optimizations or force a specific program behaviour.
24458 these variables are primarily for debugging purposes so they can be enabled/dis
24462 \begin_layout Standard
24463 Currently there is only two such variables available:
24466 \begin_layout Description
24467 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24468 bitfields is optimized by directly loading FSR0 with the address of the
24469 bitfield structure.
24470 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24472 This step saves data ram and code space for functions that make heavy use
24474 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24479 \begin_layout Description
24480 NO_REG_OPT Do not perform pCode registers optimization.
24481 This should be used for debugging purposes.
24482 If bugs in the pcode optimizer are found, users can benefit from temporarily
24483 disabling the optimizer until the bug is fixed.
24486 \begin_layout Subsection
24487 Preprocessor Macros
24490 \begin_layout Standard
24492 \begin_inset LatexCommand \index{PIC16}
24496 port defines the following preprocessor macros while translating a source.
24499 \begin_layout Standard
24501 \begin_inset Tabular
24502 <lyxtabular version="3" rows="6" columns="2">
24504 <column alignment="center" valignment="top" leftline="true" width="0">
24505 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24506 <row topline="true" bottomline="true">
24507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24510 \begin_layout Standard
24516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24519 \begin_layout Standard
24526 <row topline="true">
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24530 \begin_layout Standard
24536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24539 \begin_layout Standard
24540 Port identification
24546 <row topline="true">
24547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24550 \begin_layout Standard
24555 \begin_layout Standard
24569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24572 \begin_layout Standard
24573 Port identification (same as above)
24579 <row topline="true">
24580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24583 \begin_layout Standard
24589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24592 \begin_layout Standard
24593 MCU Identification.
24598 is the microcontrol identification number, i.e.
24605 <row topline="true">
24606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24609 \begin_layout Standard
24614 \begin_layout Standard
24628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24631 \begin_layout Standard
24632 MCU Identification (same as above)
24638 <row topline="true" bottomline="true">
24639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24642 \begin_layout Standard
24648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24651 \begin_layout Standard
24652 nnn = SMALL or LARGE respectively according to the stack model used
24665 \begin_layout Standard
24666 In addition the following macros are defined when calling assembler:
24669 \begin_layout Standard
24671 \begin_inset Tabular
24672 <lyxtabular version="3" rows="4" columns="2">
24674 <column alignment="center" valignment="top" leftline="true" width="0">
24675 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24676 <row topline="true" bottomline="true">
24677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24680 \begin_layout Standard
24686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24689 \begin_layout Standard
24696 <row topline="true">
24697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24700 \begin_layout Standard
24706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24709 \begin_layout Standard
24710 MCU Identification.
24715 is the microcontrol identification number, i.e.
24722 <row topline="true">
24723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24726 \begin_layout Standard
24732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24735 \begin_layout Standard
24736 nnn = SMALL or LARGE respectively according to the memory model used for
24743 <row topline="true" bottomline="true">
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24747 \begin_layout Standard
24753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24756 \begin_layout Standard
24757 nnn = SMALL or LARGE respectively according to the stack model used
24770 \begin_layout Subsection
24774 \begin_layout Standard
24776 \begin_inset LatexCommand \index{PIC16}
24780 port uses the following directories for searching header files and libraries.
24783 \begin_layout Standard
24785 \begin_inset Tabular
24786 <lyxtabular version="3" rows="3" columns="4">
24788 <column alignment="center" valignment="top" leftline="true" width="0">
24789 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24790 <column alignment="center" valignment="top" width="0">
24791 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24792 <row topline="true" bottomline="true">
24793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24796 \begin_layout Standard
24802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24805 \begin_layout Standard
24811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24814 \begin_layout Standard
24820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24823 \begin_layout Standard
24830 <row topline="true">
24831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24834 \begin_layout Standard
24835 PREFIX/sdcc/include/pic16
24840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24843 \begin_layout Standard
24844 PIC16 specific headers
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24852 \begin_layout Standard
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24861 \begin_layout Standard
24868 <row topline="true" bottomline="true">
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24872 \begin_layout Standard
24873 PREFIX/sdcc/lib/pic16
24878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24881 \begin_layout Standard
24882 PIC16 specific libraries
24887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24890 \begin_layout Standard
24896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24899 \begin_layout Standard
24913 \begin_layout Subsection
24915 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24922 \begin_layout Standard
24924 \begin_inset LatexCommand \index{PIC16}
24928 port currently supports the following pragmas:
24931 \begin_layout Description
24933 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24937 This forces the code generator to initialize the stack & frame pointers
24938 at a specific address.
24939 This is an ad hoc solution for cases where no STACK directive is available
24940 in the linker script or gplink is not instructed to create a stack section.
24943 stack pragma should be used only once in a project.
24944 Multiple pragmas may result in indeterminate behaviour of the program.
24948 \begin_layout Standard
24949 The old format (ie.
24950 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24951 cross page boundaries (or even exceed the available data RAM) and crash
24953 Make sure that stack does not cross page boundaries when using the SMALL
24961 The format is as follows:
24966 \begin_layout LyX-Code
24967 #pragma stack bottom_address [stack_size]
24972 \begin_layout Standard
24977 is the lower bound of the stack section.
24978 The stack pointer initially will point at address (bottom_address+stack_size-1).
24981 \begin_layout LyX-Code
24985 \begin_layout LyX-Code
24989 \begin_layout LyX-Code
24990 /* initializes stack of 100 bytes at RAM address 0x200 */
24993 \begin_layout LyX-Code
24994 #pragma stack 0x200 100
24997 \begin_layout Standard
24998 If the stack_size field is omitted then a stack is created with the default
25000 This size might be enough for most programs, but its not enough for operations
25001 with deep function nesting or excessive stack usage.
25004 \begin_layout Description
25006 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25010 Force a function to a static FLASH address.
25013 \begin_layout LyX-Code
25017 \begin_layout LyX-Code
25021 \begin_layout LyX-Code
25022 /* place function test_func at 0x4000 */
25025 \begin_layout LyX-Code
25026 #pragma code test_func 0x4000
25029 \begin_layout LyX-Code
25033 \begin_layout Description
25034 library instructs the linker to use a library module.
25039 \begin_layout LyX-Code
25040 #pragma library module_name
25043 \begin_layout Standard
25048 can be any library or object file (including its path).
25049 Note that there are four reserved keywords which have special meaning.
25053 \begin_layout Standard
25055 \begin_inset Tabular
25056 <lyxtabular version="3" rows="6" columns="3">
25058 <column alignment="center" valignment="top" leftline="true" width="0">
25059 <column alignment="block" valignment="top" leftline="true" width="20page%">
25060 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25061 <row topline="true" bottomline="true">
25062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25065 \begin_layout Standard
25071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25074 \begin_layout Standard
25080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25083 \begin_layout Standard
25090 <row topline="true">
25091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25094 \begin_layout Standard
25102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25105 \begin_layout Standard
25106 ignore all library pragmas
25111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25114 \begin_layout Standard
25123 <row topline="true">
25124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25127 \begin_layout Standard
25135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25138 \begin_layout Standard
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25147 \begin_layout Standard
25158 <row topline="true">
25159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25162 \begin_layout Standard
25170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25173 \begin_layout Standard
25174 link the Math libarary
25179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25182 \begin_layout Standard
25193 <row topline="true">
25194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25197 \begin_layout Standard
25205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25208 \begin_layout Standard
25209 link the I/O library
25214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25217 \begin_layout Standard
25228 <row topline="true" bottomline="true">
25229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25232 \begin_layout Standard
25240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25243 \begin_layout Standard
25244 link the debug library
25249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25252 \begin_layout Standard
25269 * is the device number, i.e.
25270 452 for PIC18F452 MCU.
25273 \begin_layout Standard
25274 This feature allows for linking with specific libraries withoug having to
25275 explicit name them in the command line.
25280 keyword will reject all modules specified by the library pragma.
25283 \begin_layout Description
25284 udata The pragma udata instructs the compiler to emit code so that linker
25285 will place a variable at a specific memory bank.
25288 \begin_layout LyX-Code
25292 \begin_layout LyX-Code
25296 \begin_layout LyX-Code
25297 /* places variable foo at bank2 */
25300 \begin_layout LyX-Code
25301 #pragma udata bank2 foo
25304 \begin_layout LyX-Code
25308 \begin_layout Standard
25309 In order for this pragma to work extra SECTION directives should be added
25310 in the .lkr script.
25311 In the following example a sample .lkr file is shown:
25314 \begin_layout LyX-Code
25318 \begin_layout LyX-Code
25319 // Sample linker script for the PIC18F452 processor
25322 \begin_layout LyX-Code
25326 \begin_layout LyX-Code
25327 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25330 \begin_layout LyX-Code
25331 CODEPAGE NAME=page START=0x2A END=0x7FFF
25334 \begin_layout LyX-Code
25335 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25338 \begin_layout LyX-Code
25339 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25342 \begin_layout LyX-Code
25343 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25346 \begin_layout LyX-Code
25347 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25350 \begin_layout LyX-Code
25351 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25354 \begin_layout LyX-Code
25358 \begin_layout LyX-Code
25359 DATABANK NAME=gpr0 START=0x80 END=0xFF
25362 \begin_layout LyX-Code
25363 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25366 \begin_layout LyX-Code
25367 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25370 \begin_layout LyX-Code
25371 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25374 \begin_layout LyX-Code
25375 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25378 \begin_layout LyX-Code
25379 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25382 \begin_layout LyX-Code
25383 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25386 \begin_layout LyX-Code
25390 \begin_layout LyX-Code
25391 SECTION NAME=CONFIG ROM=config
25394 \begin_layout LyX-Code
25398 \begin_layout LyX-Code
25399 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25402 \begin_layout LyX-Code
25403 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25406 \begin_layout LyX-Code
25407 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25410 \begin_layout LyX-Code
25411 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25414 \begin_layout LyX-Code
25415 SECTION NAME=bank4 RAM=gpr4
25418 \begin_layout LyX-Code
25419 SECTION NAME=bank5 RAM=gpr5
25422 \begin_layout Standard
25423 The linker will recognise the section name set in the pragma statement and
25424 will position the variable at the memory bank set with the RAM field at
25425 the SECTION line in the linker script file.
25428 \begin_layout Subsection
25430 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25437 \begin_layout Standard
25438 There is one main header file
25439 \begin_inset LatexCommand \index{PIC16!Header files}
25443 that can be included to the source files using the pic16
25444 \begin_inset LatexCommand \index{PIC16}
25454 This header file contains the definitions for the processor special registers,
25455 so it is necessary if the source accesses them.
25456 It can be included by adding the following line in the beginning of the
25460 \begin_layout LyX-Code
25461 #include <pic18fregs.h>
25464 \begin_layout Standard
25465 The specific microcontroller is selected within the pic18fregs.h automatically,
25466 so the same source can be used with a variety of devices.
25469 \begin_layout Subsection
25473 \begin_layout Standard
25475 \begin_inset LatexCommand \index{PIC16!Libraries}
25480 \begin_inset LatexCommand \index{PIC16}
25484 port depends on are the microcontroller device libraries which contain
25485 the symbol definitions for the microcontroller special function registers.
25486 These libraries have the format pic18fxxxx.lib, where
25490 is the microcontroller identification number.
25491 The specific library is selected automatically by the compiler at link
25492 stage according to the selected device.
25495 \begin_layout Standard
25496 Libraries are created with gplib which is part of the gputils package
25497 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25504 \begin_layout Subsubsection*
25505 Building the libraries
25508 \begin_layout Standard
25509 Before using SDCC/pic16 there are some libraries that need to be compiled.
25510 This process is not done automatically by SDCC since not all users use
25511 SDCC for pic16 projects.
25512 So each user should compile the libraries separately.
25515 \begin_layout Standard
25516 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25519 \begin_layout LyX-Code
25520 cd device/lib/pic16
25523 \begin_layout LyX-Code
25527 \begin_layout LyX-Code
25531 \begin_layout LyX-Code
25535 \begin_layout LyX-Code
25539 \begin_layout LyX-Code
25540 su -c 'make install' # install the libraries, you need the root password
25543 \begin_layout Standard
25544 If you need to install the headers too, do:
25547 \begin_layout LyX-Code
25551 \begin_layout LyX-Code
25552 su -c 'make install' # install the headers, you need the root password
25555 \begin_layout Standard
25556 There exist a special target to build the I/O libraries.
25557 This target is not automatically build because it will build the I/O library
25563 This way building will take quite a lot of time.
25564 Users are advised to edit the
25566 device/lib/pic16/pics.build
25568 file and then execute:
25571 \begin_layout LyX-Code
25575 \begin_layout Subsection
25576 Adding New Devices to the Port
25579 \begin_layout Standard
25580 Adding support for a new 16
25584 \begin_layout Standard
25593 bit PIC MCU requires the following steps:
25596 \begin_layout Enumerate
25597 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25601 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25605 \begin_layout Enumerate
25608 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25611 \begin_layout Enumerate
25614 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25617 \begin_layout Enumerate
25620 /path/to/sdcc/device/lib/pics.all
25628 Note: No 18f prefix here!
25631 \begin_layout Enumerate
25634 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25638 Add your DEVICE if it does not compile in
25653 \begin_layout Enumerate
25656 /path/to/sdcc/device/include/pic16/pic18fregs.h
25659 The file format is self-explanatory, just add
25663 #elif defined(picDEVICE)
25665 # include <picDEVICE.h>
25669 at the right place (keep it sorted).
25672 \begin_layout Enumerate
25675 /path/to/sdcc/src/pic16/devices.inc
25678 Copy and modify an existing entry and insert it at the correct place (keep
25680 The file is hardly documented, look at the entries for the 18f2221...
25683 \begin_layout Enumerate
25684 Recompile SDCC, including the pic16 libraries.
25687 \begin_layout Subsection
25691 \begin_layout Standard
25692 The following memory models are supported by the PIC16 port:
25695 \begin_layout Itemize
25699 \begin_layout Itemize
25703 \begin_layout Standard
25704 Memory model affects the default size of pointers within the source.
25705 The sizes are shown in the next table:
25708 \begin_layout Standard
25710 \begin_inset Tabular
25711 <lyxtabular version="3" rows="3" columns="3">
25713 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25714 <column alignment="center" valignment="top" leftline="true" width="0">
25715 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25716 <row topline="true" bottomline="true">
25717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25720 \begin_layout Standard
25721 Pointer sizes according to memory model
25726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25729 \begin_layout Standard
25735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25738 \begin_layout Standard
25745 <row topline="true" bottomline="true">
25746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25749 \begin_layout Standard
25755 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25758 \begin_layout Standard
25764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25767 \begin_layout Standard
25774 <row topline="true" bottomline="true">
25775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25778 \begin_layout Standard
25784 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25787 \begin_layout Standard
25793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25796 \begin_layout Standard
25810 \begin_layout Standard
25811 It is advisable that all sources within a project are compiled with the
25813 If one wants to override the default memory model, this can be done by
25814 declaring a pointer as
25823 Far selects large memory model's pointers, while near selects small memory
25827 \begin_layout Standard
25828 The standard device libraries (see
25829 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25833 ) contain no reference to pointers, so they can be used with both memory
25837 \begin_layout Subsection
25841 \begin_layout Standard
25843 \begin_inset LatexCommand \index{PIC16!stack}
25847 implementation for the PIC16 port uses two indirect registers, FSR1 and
25851 \begin_layout Description
25852 FSR1 is assigned as stack pointer
25855 \begin_layout Description
25856 FSR2 is assigned as frame pointer
25859 \begin_layout Standard
25860 The following stack models are supported by the PIC16 port
25863 \begin_layout Itemize
25871 \begin_layout Itemize
25879 \begin_layout Standard
25884 model means that only the FSRxL byte is used to access stack and frame,
25891 uses both FSRxL and FSRxH registers.
25892 The following table shows the stack/frame pointers sizes according to stack
25893 model and the maximum space they can address:
25896 \begin_layout Standard
25898 \begin_inset Tabular
25899 <lyxtabular version="3" rows="3" columns="3">
25901 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25902 <column alignment="center" valignment="top" leftline="true" width="0">
25903 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25904 <row topline="true" bottomline="true">
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25908 \begin_layout Standard
25909 Stack & Frame pointer sizes according to stack model
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25917 \begin_layout Standard
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25926 \begin_layout Standard
25933 <row topline="true">
25934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25937 \begin_layout Standard
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25946 \begin_layout Standard
25952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25955 \begin_layout Standard
25962 <row topline="true" bottomline="true">
25963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25966 \begin_layout Standard
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25975 \begin_layout Standard
25981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25984 \begin_layout Standard
25998 \begin_layout Standard
26003 stack model is currently not working properly throughout the code generator.
26004 So its use is not advised.
26005 Also there are some other points that need special care:
26010 \begin_layout Enumerate
26011 Do not create stack sections with size more than one physical bank (that
26015 \begin_layout Enumerate
26016 Stack sections should no cross physical bank limits (i.e.
26017 #pragma stack 0x50 0x100)
26020 \begin_layout Standard
26021 These limitations are caused by the fact that only FSRxL is modified when
26022 using SMALL stack model, so no more than 256 bytes of stack can be used.
26023 This problem will disappear after LARGE model is fully implemented.
26026 \begin_layout Subsection
26030 \begin_layout Standard
26031 In addition to the standard SDCC function keywords, PIC16
26032 \begin_inset LatexCommand \index{PIC16}
26036 port makes available two more:
26039 \begin_layout Description
26041 \begin_inset LatexCommand \index{PIC16!wparam}
26045 Use the WREG to pass one byte of the first function argument.
26046 This improves speed but you may not use this for functions with arguments
26047 that are called via function pointers, otherwise the first byte of the
26048 first parameter will get lost.
26052 \begin_layout LyX-Code
26053 void func_wparam(int a) wparam
26056 \begin_layout LyX-Code
26060 \begin_layout LyX-Code
26061 /* WREG hold the lower part of a */
26064 \begin_layout LyX-Code
26065 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26069 \begin_layout LyX-Code
26073 \begin_layout LyX-Code
26077 \begin_layout Description
26079 \begin_inset LatexCommand \index{PIC16!shadowregs}
26083 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26084 hardware shadow registers which hold the values of WREG, STATUS and BSR
26086 This can be done by adding the keyword
26094 keyword in the function's header.
26097 \begin_layout LyX-Code
26098 void isr_shadow(void) shadowregs interrupt 1
26101 \begin_layout LyX-Code
26105 \begin_layout LyX-Code
26109 \begin_layout LyX-Code
26113 \begin_layout Standard
26118 instructs the code generator not to store/restore WREG, STATUS, BSR when
26119 entering/exiting the ISR.
26122 \begin_layout Subsection
26123 Function return values
26126 \begin_layout Standard
26127 Return values from functions are placed to the appropriate registers following
26128 a modified Microchip policy optimized for SDCC.
26129 The following table shows these registers:
26132 \begin_layout Standard
26134 \begin_inset Tabular
26135 <lyxtabular version="3" rows="6" columns="2">
26137 <column alignment="center" valignment="top" leftline="true" width="0">
26138 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26139 <row topline="true" bottomline="true">
26140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26143 \begin_layout Standard
26149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26152 \begin_layout Standard
26153 destination register
26159 <row topline="true">
26160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26163 \begin_layout Standard
26169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26172 \begin_layout Standard
26179 <row topline="true">
26180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26183 \begin_layout Standard
26189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26192 \begin_layout Standard
26199 <row topline="true">
26200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26203 \begin_layout Standard
26209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26212 \begin_layout Standard
26219 <row topline="true">
26220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26223 \begin_layout Standard
26229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26232 \begin_layout Standard
26233 FSR0L:PRODH:PRODL:WREG
26239 <row topline="true" bottomline="true">
26240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26243 \begin_layout Standard
26249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26252 \begin_layout Standard
26253 on stack, FSR0 points to the beginning
26266 \begin_layout Subsection
26270 \begin_layout Standard
26272 \begin_inset LatexCommand \index{PIC16!interrupt}
26276 service routine (ISR) is declared using the
26283 \begin_layout LyX-Code
26284 void isr(void) interrupt
26289 \begin_layout LyX-Code
26293 \begin_layout LyX-Code
26297 \begin_layout LyX-Code
26301 \begin_layout Standard
26306 is the interrupt number, which for PIC18F devices can be:
26309 \begin_layout Standard
26311 \begin_inset Tabular
26312 <lyxtabular version="3" rows="4" columns="3">
26314 <column alignment="center" valignment="top" leftline="true" width="0">
26315 <column alignment="center" valignment="top" leftline="true" width="0">
26316 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26317 <row topline="true" bottomline="true">
26318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26321 \begin_layout Standard
26329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26332 \begin_layout Standard
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26341 \begin_layout Standard
26342 Interrupt Vector Address
26348 <row topline="true">
26349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26352 \begin_layout Standard
26358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26361 \begin_layout Standard
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26370 \begin_layout Standard
26377 <row topline="true">
26378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26381 \begin_layout Standard
26396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26399 \begin_layout Standard
26409 HIGH priority interrupts
26414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26417 \begin_layout Standard
26424 <row topline="true" bottomline="true">
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26428 \begin_layout Standard
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26437 \begin_layout Standard
26438 LOW priority interrupts
26443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26446 \begin_layout Standard
26460 \begin_layout Standard
26461 When generating assembly code for ISR the code generator places a
26467 Interrupt Vector Address
26469 which points at the genetated ISR.
26470 This single GOTO instruction is part of an automatically generated
26472 interrupt entry point
26475 The actuall ISR code is placed as normally would in the code space.
26476 Upon interrupt request, the GOTO instruction is executed which jumps to
26478 When declaring interrupt functions as _naked this GOTO instruction is
26483 The whole interrupt functions is therefore placed at the Interrupt Vector
26484 Address of the specific interrupt.
26485 This is not a problem for the LOW priority interrupts, but it is a problem
26486 for the RESET and the HIGH priority interrupts because code may be written
26487 at the next interrupt's vector address and cause undeterminate program
26488 behaviour if that interrupt is raised.
26492 \begin_layout Standard
26493 This is not a problem when
26496 \begin_layout Enumerate
26497 this is a HIGH interrupt ISR and LOW interrupts are
26504 \begin_layout Enumerate
26505 when the ISR is small enough not to reach the next interrupt's vector address.
26513 \begin_layout Standard
26519 This way a function is generated similar to an ISR, but it is not assigned
26523 \begin_layout Standard
26524 When entering an interrupt, currently the PIC16
26525 \begin_inset LatexCommand \index{PIC16}
26529 port automatically saves the following registers:
26532 \begin_layout Itemize
26536 \begin_layout Itemize
26540 \begin_layout Itemize
26544 \begin_layout Itemize
26545 PROD (PRODL and PRODH)
26548 \begin_layout Itemize
26549 FSR0 (FSR0L and FSR0H)
26552 \begin_layout Standard
26553 These registers are restored upon return from the interrupt routine.
26557 \begin_layout Standard
26558 NOTE that when the _naked attribute is specified for an interrupt routine,
26559 then NO registers are stored or restored.
26567 \begin_layout Subsection
26571 \begin_layout Standard
26572 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26573 There are 3 types of generic pointers currently implemented data, code
26574 and eeprom pointers.
26575 They are differentiated by the value of the 7th and 6th bits of the upper
26579 \begin_layout Standard
26581 \begin_inset Tabular
26582 <lyxtabular version="3" rows="5" columns="5">
26584 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26585 <column alignment="center" valignment="top" width="0">
26586 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26587 <column alignment="center" valignment="top" width="0">
26588 <column alignment="left" valignment="top" rightline="true" width="0">
26589 <row topline="true" bottomline="true">
26590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26593 \begin_layout Standard
26599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26602 \begin_layout Standard
26608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26611 \begin_layout Standard
26617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26620 \begin_layout Standard
26621 rest of the pointer
26626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26629 \begin_layout Standard
26636 <row topline="true" bottomline="true">
26637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26640 \begin_layout Standard
26646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26649 \begin_layout Standard
26655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26658 \begin_layout Standard
26664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26667 \begin_layout Standard
26672 uuuuuu uuuuxxxx xxxxxxxx
26677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26680 \begin_layout Standard
26681 a 12-bit data pointer in data RAM memory
26687 <row bottomline="true">
26688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26691 \begin_layout Standard
26697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26700 \begin_layout Standard
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26709 \begin_layout Standard
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_layout Standard
26723 uxxxxx xxxxxxxx xxxxxxxx
26728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26731 \begin_layout Standard
26732 a 21-bit code pointer in FLASH memory
26738 <row bottomline="true">
26739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26742 \begin_layout Standard
26748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26751 \begin_layout Standard
26757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26760 \begin_layout Standard
26766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26769 \begin_layout Standard
26774 uuuuuu uuuuuuxx xxxxxxxx
26779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26782 \begin_layout Standard
26783 a 10-bit eeprom pointer in EEPROM memory
26789 <row bottomline="true">
26790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26793 \begin_layout Standard
26799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26802 \begin_layout Standard
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26811 \begin_layout Standard
26817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26820 \begin_layout Standard
26825 xxxxxx xxxxxxxx xxxxxxxx
26830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26833 \begin_layout Standard
26834 unimplemented pointer type
26847 \begin_layout Standard
26848 Generic pointer are read and written with a set of library functions which
26849 read/write 1, 2, 3, 4 bytes.
26852 \begin_layout Subsection
26856 \begin_layout Subsubsection
26857 Standard I/O Streams
26860 \begin_layout Standard
26865 the type FILE is defined as:
26868 \begin_layout LyX-Code
26869 typedef char * FILE;
26872 \begin_layout Standard
26873 This type is the stream type implemented I/O in the PIC18F devices.
26874 Also the standard input and output streams are declared in stdio.h:
26877 \begin_layout LyX-Code
26878 extern FILE * stdin;
26881 \begin_layout LyX-Code
26882 extern FILE * stdout;
26885 \begin_layout Standard
26886 The FILE type is actually a generic pointer which defines one more type
26887 of generic pointers, the
26892 This new type has the format:
26895 \begin_layout Standard
26897 \begin_inset Tabular
26898 <lyxtabular version="3" rows="2" columns="7">
26900 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26901 <column alignment="center" valignment="top" width="0">
26902 <column alignment="center" valignment="top" leftline="true" width="0">
26903 <column alignment="center" valignment="top" leftline="true" width="0">
26904 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26905 <column alignment="center" valignment="top" width="0">
26906 <column alignment="left" valignment="top" rightline="true" width="0">
26907 <row topline="true" bottomline="true">
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26911 \begin_layout Standard
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26920 \begin_layout Standard
26926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26929 \begin_layout Standard
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26938 \begin_layout Standard
26944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26947 \begin_layout Standard
26953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26956 \begin_layout Standard
26957 rest of the pointer
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26965 \begin_layout Standard
26972 <row topline="true" bottomline="true">
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26976 \begin_layout Standard
26982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26985 \begin_layout Standard
26991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26994 \begin_layout Standard
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27003 \begin_layout Standard
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27012 \begin_layout Standard
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_layout Standard
27031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27034 \begin_layout Standard
27035 upper byte high nubble is 0x2n, the rest are zeroes
27048 \begin_layout Standard
27049 Currently implemented there are 3 types of streams defined:
27052 \begin_layout Standard
27054 \begin_inset Tabular
27055 <lyxtabular version="3" rows="4" columns="4">
27057 <column alignment="center" valignment="top" leftline="true" width="0">
27058 <column alignment="center" valignment="top" leftline="true" width="0">
27059 <column alignment="center" valignment="top" leftline="true" width="0">
27060 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27061 <row topline="true" bottomline="true">
27062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27065 \begin_layout Standard
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27074 \begin_layout Standard
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27083 \begin_layout Standard
27089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27092 \begin_layout Standard
27099 <row topline="true">
27100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27103 \begin_layout Standard
27109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27112 \begin_layout Standard
27120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27123 \begin_layout Standard
27129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27132 \begin_layout Standard
27133 Writes/Reads characters via the USART peripheral
27139 <row topline="true">
27140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27143 \begin_layout Standard
27149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27152 \begin_layout Standard
27160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27163 \begin_layout Standard
27169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27172 \begin_layout Standard
27173 Writes/Reads characters via the MSSP peripheral
27179 <row topline="true" bottomline="true">
27180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27183 \begin_layout Standard
27189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27192 \begin_layout Standard
27200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27203 \begin_layout Standard
27209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27212 \begin_layout Standard
27213 Writes/Reads characters via used defined functions
27226 \begin_layout Standard
27227 The stream identifiers are declared as macros in the stdio.h header.
27230 \begin_layout Standard
27231 In the libc library there exist the functions that are used to write to
27232 each of the above streams.
27236 \begin_layout Description
27241 \begin_layout Standard
27250 _stream_usart_putchar writes a character at the USART stream
27253 \begin_layout Description
27258 \begin_layout Standard
27267 _stream_mssp_putchar writes a character at the MSSP stream
27270 \begin_layout Description
27271 putchar dummy function.
27272 This writes a character to a user specified manner.
27275 \begin_layout Standard
27276 In order to increase performance
27280 is declared in stdio.h as having its parameter in WREG (it has the wparam
27282 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27283 in a user-friendly way.
27288 is the name of the variable that holds the character to print.
27289 An example follows:
27292 \begin_layout LyX-Code
27293 #include <pic18fregs.h>
27302 \begin_layout LyX-Code
27306 \begin_layout LyX-Code
27307 PORTA = c; /* dump character c to PORTA */
27310 \begin_layout LyX-Code
27318 \begin_layout LyX-Code
27322 \begin_layout LyX-Code
27323 stdout = STREAM_USER; /* this is not necessary, since stdout points
27326 \begin_layout LyX-Code
27327 * by default to STREAM_USER */
27330 \begin_layout LyX-Code
27332 \begin_inset Quotes sld
27335 This is a printf test
27338 \begin_inset Quotes srd
27344 \begin_layout LyX-Code
27348 \begin_layout LyX-Code
27352 \begin_layout Subsubsection
27356 \begin_layout Standard
27357 PIC16 contains an implementation of the printf-family of functions.
27358 There exist the following functions:
27361 \begin_layout LyX-Code
27362 extern unsigned int sprintf(char *buf, char *fmt, ...);
27365 \begin_layout LyX-Code
27366 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27369 \begin_layout LyX-Code
27373 \begin_layout LyX-Code
27374 extern unsigned int printf(char *fmt, ...);
27377 \begin_layout LyX-Code
27378 extern unsigned int vprintf(char *fmt, va_lista ap);
27381 \begin_layout LyX-Code
27385 \begin_layout LyX-Code
27386 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27389 \begin_layout LyX-Code
27390 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27393 \begin_layout Standard
27394 For sprintf and vsprintf
27398 should normally be a data pointer where the resulting string will be placed.
27399 No range checking is done so the user should allocate the necessery buffer.
27400 For fprintf and vfprintf
27404 should be a stream pointer (i.e.
27405 stdout, STREAM_MSSP, etc...).
27408 \begin_layout Subsubsection
27412 \begin_layout Standard
27413 The PIC18F family of microcontrollers supports a number of interrupt sources.
27414 A list of these interrupts is shown in the following table:
27417 \begin_layout Standard
27419 \begin_inset Tabular
27420 <lyxtabular version="3" rows="11" columns="4">
27422 <column alignment="left" valignment="top" leftline="true" width="0">
27423 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27424 <column alignment="left" valignment="top" leftline="true" width="0">
27425 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27426 <row topline="true" bottomline="true">
27427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27430 \begin_layout Standard
27436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27439 \begin_layout Standard
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27448 \begin_layout Standard
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27457 \begin_layout Standard
27464 <row topline="true">
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27468 \begin_layout Standard
27474 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27477 \begin_layout Standard
27478 PORTB change interrupt
27483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27486 \begin_layout Standard
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27495 \begin_layout Standard
27496 EEPROM/FLASH write complete interrupt
27502 <row topline="true">
27503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27506 \begin_layout Standard
27512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27515 \begin_layout Standard
27516 INT0 external interrupt
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27524 \begin_layout Standard
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27533 \begin_layout Standard
27534 Bus collision interrupt
27540 <row topline="true">
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27544 \begin_layout Standard
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27553 \begin_layout Standard
27554 INT1 external interrupt
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27562 \begin_layout Standard
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27571 \begin_layout Standard
27572 Low voltage detect interrupt
27578 <row topline="true">
27579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27582 \begin_layout Standard
27588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27591 \begin_layout Standard
27592 INT2 external interrupt
27597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27600 \begin_layout Standard
27606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27609 \begin_layout Standard
27610 Parallel slave port interrupt
27616 <row topline="true">
27617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27620 \begin_layout Standard
27626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27629 \begin_layout Standard
27630 CCP1 module interrupt
27635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27638 \begin_layout Standard
27644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27647 \begin_layout Standard
27648 AD convertion complete interrupt
27654 <row topline="true">
27655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27658 \begin_layout Standard
27664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27667 \begin_layout Standard
27668 CCP2 module interrupt
27673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27676 \begin_layout Standard
27682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27685 \begin_layout Standard
27686 USART receive interrupt
27692 <row topline="true">
27693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27696 \begin_layout Standard
27702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27705 \begin_layout Standard
27706 TMR0 overflow interrupt
27711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27714 \begin_layout Standard
27720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27723 \begin_layout Standard
27724 USART transmit interrupt
27730 <row topline="true">
27731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27734 \begin_layout Standard
27740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27743 \begin_layout Standard
27744 TMR1 overflow interrupt
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27752 \begin_layout Standard
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27761 \begin_layout Standard
27762 SSP receive/transmit interrupt
27768 <row topline="true">
27769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27772 \begin_layout Standard
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27781 \begin_layout Standard
27782 TMR2 matches PR2 interrupt
27787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27790 \begin_layout Standard
27796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27799 \begin_layout Standard
27806 <row topline="true" bottomline="true">
27807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27810 \begin_layout Standard
27816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27819 \begin_layout Standard
27820 TMR3 overflow interrupt
27825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27828 \begin_layout Standard
27834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27837 \begin_layout Standard
27851 \begin_layout Standard
27852 The prototypes for these names are defined in the header file
27859 \begin_layout Standard
27860 In order to simplify signal handling, a number of macros is provided:
27864 \labelwidthstring 00.00.0000
27865 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27866 high priority interrupts.
27871 is the function name to use.
27875 \labelwidthstring 00.00.0000
27876 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27877 low priority interrupt.
27882 is the function name to use.
27886 \labelwidthstring 00.00.0000
27887 DEF_HANDLER(sig,handler) define a handler for signal
27893 \labelwidthstring 00.00.0000
27894 END_DEF end the declaration of the dispatch table.
27897 \begin_layout Standard
27898 Additionally there are two more macros to simplify the declaration of the
27903 \labelwidthstring 00.00.0000
27906 SIGHANDLER(handler)
27908 this declares the function prototype for the
27916 \labelwidthstring 00.00.0000
27917 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27920 \begin_layout Standard
27921 An example of using the macros above is shown below:
27924 \begin_layout LyX-Code
27925 #include <pic18fregs.h>
27928 \begin_layout LyX-Code
27929 #include <signal.h>
27933 DEF_INTHIGH(high_int)
27936 \begin_layout LyX-Code
27937 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27940 \begin_layout LyX-Code
27941 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27944 \begin_layout LyX-Code
27949 SIGHANDLER(_tmr0_handler)
27952 \begin_layout LyX-Code
27956 \begin_layout LyX-Code
27957 /* action to be taken when timer 0 overflows */
27960 \begin_layout LyX-Code
27965 SIGHANDLERNAKED(_bcol_handler)
27968 \begin_layout LyX-Code
27972 \begin_layout LyX-Code
27976 \begin_layout LyX-Code
27977 /* action to be taken when bus collision occurs */
27980 \begin_layout LyX-Code
27984 \begin_layout LyX-Code
27988 \begin_layout LyX-Code
27992 \begin_layout Standard
27997 Special care should be taken when using the above scheme:
28000 \begin_layout Itemize
28001 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28004 \begin_layout Itemize
28005 when declaring SIGHANDLERNAKED handler never forget to use
28009 for proper returning.
28012 \begin_layout Subsection
28016 \begin_layout Standard
28017 Here you can find some general tips for compiling programs with SDCC/pic16.
28020 \begin_layout Subsubsection
28024 \begin_layout Standard
28026 \begin_inset LatexCommand \index{PIC16!stack}
28030 size (that is 64 bytes) probably is enough for many programs.
28031 One must take care that when there are many levels of function nesting,
28032 or there is excessive usage of stack, its size should be extended.
28033 An example of such a case is the printf/sprintf family of functions.
28034 If you encounter problems like not being able to print integers, then you
28035 need to set the stack size around the maximum (256 for small stack model).
28036 The following diagram shows what happens when calling printf to print an
28040 \begin_layout LyX-Code
28041 printf () --> ltoa () --> ultoa () --> divschar ()
28044 \begin_layout Standard
28045 It is should be understood that stack is easily consumed when calling complicate
28047 Using command line arguments like -
28051 \begin_layout Standard
28060 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28062 Other ways to reduce stack usage may exist.
28065 \begin_layout Subsection
28069 \begin_layout Standard
28070 The PIC16 Port currently does not pass SDCC's regression test
28071 \begin_inset LatexCommand \index{Regression test (PIC16)}
28076 \begin_inset LatexCommand \ref{sec:Quality-control}
28080 ) and thus the snapshot build regression tests for the PIC16 target are
28081 currently disabled for all hosts
28086 \begin_layout Chapter
28090 \begin_layout Standard
28091 There are several approaches to debugging your code.
28092 This chapter is meant to show your options and to give detail on some of
28097 When writing your code:
28100 \begin_layout Itemize
28101 write your code with debugging in mind (avoid duplicating code, put conceptually
28102 similar variables into structs, use structured code, have strategic points
28103 within your code where all variables are consistent, ...)
28106 \begin_layout Itemize
28107 run a syntax-checking tool like splint
28108 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28113 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28121 \begin_layout Standard
28131 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28138 \begin_layout Itemize
28139 for the high level code use a C-compiler (like f.e.
28140 GCC) to compile run and debug the code on your host.
28145 \begin_layout Standard
28155 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28159 ) on how to handle syntax extensions like __xdata, __at(), ...
28163 \begin_layout Itemize
28164 use another C-compiler to compile code for your target.
28165 Always an option but not recommended:) And not very likely to help you.
28166 If you seriously consider walking this path you should at least occasionally
28167 check portability of your code.
28168 Most commercial compiler vendors will offer an evaluation version so you
28169 can test compile your code or snippets of your code.
28172 \begin_layout Standard
28173 Debugging on a simulator:
28176 \begin_layout Itemize
28177 there is a separate section about SDCDB (section
28178 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28185 \begin_layout Itemize
28186 or (8051 specific) use a freeware/commercial simulator which interfaces
28188 \begin_inset LatexCommand \index{AOMF, AOMF51}
28193 \begin_inset LatexCommand \ref{OMF file}
28197 ) optionally generated by SDCC.
28200 \begin_layout Standard
28201 Debugging On-target:
28204 \begin_layout Itemize
28205 use a MCU port pin to serially output debug data to the RS232 port of your
28207 You'll probably want some level shifting device typically involving a MAX232
28209 If the hardware serial port of the MCU is not available search for 'Software
28210 UART' in your favourite search machine.
28213 \begin_layout Itemize
28214 use an on-target monitor.
28215 In this context a monitor is a small program which usually accepts commands
28216 via a serial line and allows to set program counter, to single step through
28217 a program and read/write memory locations.
28218 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28220 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28227 \begin_layout Itemize
28228 toggle MCU port pins at strategic points within your code and use an oscilloscop
28232 digital oscilloscope
28235 \begin_inset LatexCommand \index{Oscilloscope}
28239 with deep trace memory is really helpful especially if you have to debug
28240 a realtime application.
28241 If you need to monitor more pins than your oscilloscope provides you can
28242 sometimes get away with a small R-2R network.
28243 On a single channel oscilloscope you could f.e.
28244 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28246 \begin_inset Formula $\Omega$
28249 resistor and the other one by a 5\InsetSpace ~
28251 \begin_inset Formula $\Omega$
28254 resistor to the oscilloscope probe (check output drive capability of the
28255 pins you want to monitor).
28256 If you need to monitor many more pins a
28263 \begin_layout Itemize
28277 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28282 Usually very expensive.
28283 And very nice to have too.
28284 And usually locks you (for years...) to the devices the ICE can emulate.
28288 \begin_layout Itemize
28289 use a remote debugger.
28290 In most 8-bit systems the symbol information is not available on the target,
28291 and a complete debugger is too bulky for the target system.
28292 Therefore usually a debugger on the host system connects to an on-target
28293 debugging stub which accepts only primitive commands.
28296 Terms to enter into your favourite search engine could be 'remote debugging',
28297 'gdb stub' or 'inferior debugger'.
28301 \begin_layout Itemize
28302 use an on target hardware debugger.
28303 Some of the more modern MCUs include hardware support for setting break
28304 points and monitoring/changing variables by using dedicated hardware pins.
28305 This facility doesn't require additional code to run on the target and
28310 doesn't affect runtime behaviour until a breakpoint is hit.
28311 For the mcs51 most hardware debuggers use the AOMF
28312 \begin_inset LatexCommand \index{AOMF, AOMF51}
28317 \begin_inset LatexCommand \ref{OMF file}
28325 \begin_layout Standard
28329 \begin_layout Itemize
28330 if you are not familiar with any of the following terms you're likely to
28331 run into problems rather sooner than later:
28348 As an embedded programmer you
28352 to know them so why not look them up
28356 you have problems?)
28359 \begin_layout Itemize
28360 tell someone else about your problem (actually this is a surprisingly effective
28361 means to hunt down the bug even if the listener is not familiar with your
28363 As 'failure to communicate' is probably one of the job-induced deformations
28364 of an embedded programmer this is highly encouraged.
28367 \begin_layout Section
28368 Debugging with SDCDB
28369 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28374 \begin_inset LatexCommand \index{SDCDB (debugger)}
28381 \begin_layout Standard
28382 SDCC is distributed with a source level debugger
28383 \begin_inset LatexCommand \index{Debugger}
28388 The debugger uses a command line interface, the command repertoire of the
28389 debugger has been kept as close to gdb
28390 \begin_inset LatexCommand \index{gdb}
28394 (the GNU debugger) as possible.
28395 The configuration and build process is part of the standard compiler installati
28396 on, which also builds and installs the debugger in the target directory
28397 specified during configuration.
28398 The debugger allows you debug BOTH at the C source and at the ASM source
28402 \begin_layout Subsection
28403 Compiling for Debugging
28406 \begin_layout Standard
28411 \begin_layout Standard
28421 \begin_inset LatexCommand \index{-\/-debug}
28425 option must be specified for all files for which debug information is to
28427 The compiler generates a .adb file for each of these files.
28428 The linker creates the .cdb
28429 \begin_inset LatexCommand \index{<file>.cdb}
28434 \begin_inset LatexCommand \index{<file>.adb}
28438 files and the address information.
28439 This .cdb is used by the debugger.
28442 \begin_layout Subsection
28443 How the Debugger Works
28446 \begin_layout Standard
28451 \begin_layout Standard
28460 -debug option is specified the compiler generates extra symbol information
28461 some of which are put into the assembler source and some are put into the
28463 Then the linker creates the .cdb file from the individual .adb files with
28464 the address information for the symbols.
28465 The debugger reads the symbolic information generated by the compiler &
28466 the address information generated by the linker.
28467 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28468 execution is controlled by the debugger.
28469 When a command is issued for the debugger, it translates it into appropriate
28470 commands for the simulator.
28471 (Currently SDCDM only connects to the simulator but
28476 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28480 is an effort to connect directly to the hardware.)
28483 \begin_layout Subsection
28484 Starting the Debugger SDCDB
28487 \begin_layout Standard
28488 The debugger can be started using the following command line.
28489 (Assume the file you are debugging has the file name foo).
28503 The debugger will look for the following files.
28506 \begin_layout Itemize
28507 foo.c - the source file.
28510 \begin_layout Itemize
28511 foo.cdb - the debugger symbol information file.
28514 \begin_layout Itemize
28515 foo.ihx - the Intel hex format
28516 \begin_inset LatexCommand \index{Intel hex format}
28523 \begin_layout Subsection
28524 SDCDB Command Line Options
28527 \begin_layout Itemize
28532 \begin_layout Standard
28541 -directory=<source file directory> this option can used to specify the directory
28543 The debugger will look into the directory list specified for source, cdb
28545 The items in the directory list must be separated by ':', e.g.
28546 if the source files can be in the directories /home/src1 and /home/src2,
28551 \begin_layout Standard
28560 -directory option should be -
28564 \begin_layout Standard
28573 -directory=/home/src1:/home/src2.
28574 Note there can be no spaces in the option.
28578 \begin_layout Itemize
28579 -cd <directory> - change to the <directory>.
28582 \begin_layout Itemize
28583 -fullname - used by GUI front ends.
28586 \begin_layout Itemize
28587 -cpu <cpu-type> - this argument is passed to the simulator please see the
28588 simulator docs for details.
28591 \begin_layout Itemize
28592 -X <Clock frequency > this options is passed to the simulator please see
28593 the simulator docs for details.
28596 \begin_layout Itemize
28597 -s <serial port file> passed to simulator see the simulator docs for details.
28600 \begin_layout Itemize
28601 -S <serial in,out> passed to simulator see the simulator docs for details.
28604 \begin_layout Itemize
28605 -k <port number> passed to simulator see the simulator docs for details.
28608 \begin_layout Subsection
28609 SDCDB Debugger Commands
28612 \begin_layout Standard
28613 As mentioned earlier the command interface for the debugger has been deliberatel
28614 y kept as close the GNU debugger gdb, as possible.
28615 This will help the integration with existing graphical user interfaces
28616 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28617 If you use a graphical user interface for the debugger you can skip this
28621 \begin_layout Subsubsection*
28622 break [line | file:line | function | file:function]
28625 \begin_layout Standard
28626 Set breakpoint at specified line or function:
28635 sdcdb>break foo.c:100
28637 sdcdb>break funcfoo
28639 sdcdb>break foo.c:funcfoo
28642 \begin_layout Subsubsection*
28643 clear [line | file:line | function | file:function ]
28646 \begin_layout Standard
28647 Clear breakpoint at specified line or function:
28656 sdcdb>clear foo.c:100
28658 sdcdb>clear funcfoo
28660 sdcdb>clear foo.c:funcfoo
28663 \begin_layout Subsubsection*
28667 \begin_layout Standard
28668 Continue program being debugged, after breakpoint.
28671 \begin_layout Subsubsection*
28675 \begin_layout Standard
28676 Execute till the end of the current function.
28679 \begin_layout Subsubsection*
28683 \begin_layout Standard
28684 Delete breakpoint number 'n'.
28685 If used without any option clear ALL user defined break points.
28688 \begin_layout Subsubsection*
28689 info [break | stack | frame | registers ]
28692 \begin_layout Itemize
28693 info break - list all breakpoints
28696 \begin_layout Itemize
28697 info stack - show the function call stack.
28700 \begin_layout Itemize
28701 info frame - show information about the current execution frame.
28704 \begin_layout Itemize
28705 info registers - show content of all registers.
28708 \begin_layout Subsubsection*
28712 \begin_layout Standard
28713 Step program until it reaches a different source line.
28714 Note: pressing <return> repeats the last command.
28717 \begin_layout Subsubsection*
28721 \begin_layout Standard
28722 Step program, proceeding through subroutine calls.
28725 \begin_layout Subsubsection*
28729 \begin_layout Standard
28730 Start debugged program.
28733 \begin_layout Subsubsection*
28737 \begin_layout Standard
28738 Print type information of the variable.
28741 \begin_layout Subsubsection*
28745 \begin_layout Standard
28746 print value of variable.
28749 \begin_layout Subsubsection*
28753 \begin_layout Standard
28754 load the given file name.
28755 Note this is an alternate method of loading file for debugging.
28758 \begin_layout Subsubsection*
28762 \begin_layout Standard
28763 print information about current frame.
28766 \begin_layout Subsubsection*
28770 \begin_layout Standard
28771 Toggle between C source & assembly source.
28774 \begin_layout Subsubsection*
28775 ! simulator command
28778 \begin_layout Standard
28779 Send the string following '!' to the simulator, the simulator response is
28781 Note the debugger does not interpret the command being sent to the simulator,
28782 so if a command like 'go' is sent the debugger can loose its execution
28783 context and may display incorrect values.
28786 \begin_layout Subsubsection*
28790 \begin_layout Standard
28793 My name is Bobby Brown"
28796 \begin_layout Subsection
28797 Interfacing SDCDB with DDD
28800 \begin_layout Standard
28801 \begin_inset Note Note
28804 \begin_layout Standard
28805 The screenshot was converted from png to eps with:
28806 \begin_inset Quotes sld
28809 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28810 \begin_inset Quotes srd
28813 which produces a pretty compact eps file which is free from compression
28817 \begin_layout Standard
28818 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28819 as this broke the build system on Sourceforge (pdf-file was broken.
28820 pdflatex does not accept eps files).
28828 \begin_layout Standard
28844 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28850 shows a screenshot of a debugging session with DDD
28851 \begin_inset LatexCommand \index{DDD (debugger)}
28855 (Unix only) on a simulated 8032.
28856 The debugging session might not run as smoothly as the screenshot suggests.
28857 The debugger allows setting of breakpoints, displaying and changing variables,
28858 single stepping through C and assembler code.
28861 The source was compiled with
28875 \begin_layout Standard
28887 -debug ddd_example.c
28900 and DDD was invoked with
28907 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28910 \begin_layout Standard
28911 \begin_inset Note Note
28914 \begin_layout Standard
28915 Check that the double quotes or an apostroph within the command line survive
28916 the LyX tool chain.
28917 Previously the apostrophs got slanted in the PDF output so a cut and paste
28926 \begin_layout Subsection
28927 Interfacing SDCDB with XEmacs
28928 \begin_inset LatexCommand \index{XEmacs}
28933 \begin_inset LatexCommand \index{Emacs}
28940 \begin_layout Standard
28941 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28942 sdcdb.el and sdcdbsrc.el.
28943 These two files can be found in the $(prefix)/bin directory after the installat
28945 These files need to be loaded into XEmacs for the interface to work.
28946 This can be done at XEmacs startup time by inserting the following into
28947 your '.xemacs' file (which can be found in your HOME directory):
28953 (load-file sdcdbsrc.el)
28959 .xemacs is a lisp file so the () around the command is REQUIRED.
28960 The files can also be loaded dynamically while XEmacs is running, set the
28961 environment variable 'EMACSLOADPATH' to the installation bin directory
28962 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28963 To start the interface enter the following command:
28977 You will prompted to enter the file name to be debugged.
28982 The command line options that are passed to the simulator directly are
28983 bound to default values in the file sdcdbsrc.el.
28984 The variables are listed below, these values maybe changed as required.
28987 \begin_layout Itemize
28988 sdcdbsrc-cpu-type '51
28991 \begin_layout Itemize
28992 sdcdbsrc-frequency '11059200
28995 \begin_layout Itemize
28996 sdcdbsrc-serial nil
28999 \begin_layout Standard
29000 The following is a list of key mapping for the debugger interface.
29003 \begin_layout Standard
29026 binding\InsetSpace ~
29064 -------\InsetSpace ~
29135 sdcdb-back-from-src\InsetSpace ~
29164 rom-src\InsetSpace ~
29174 SDCDB continue command
29192 sdcdb-step-from-src\InsetSpace ~
29221 hatis-c-sexp\InsetSpace ~
29231 SDCDB ptypecommand for data at
29298 sdcdbsrc-delete\InsetSpace ~
29313 B Delete all breakpoints if no arg
29362 given or delete arg (C-u arg x)
29381 -frame\InsetSpace ~
29396 SDCDB Display current frame if no arg,
29445 given or display frame arg
29513 sdcdbsrc-goto-sdcdb\InsetSpace ~
29523 Goto the SDCDB output buffer
29542 t-c-sexp\InsetSpace ~
29553 SDCDB print command for data at
29620 sdcdbsrc-goto-sdcdb\InsetSpace ~
29631 o the SDCDB output buffer
29649 sdcdbsrc-mode\InsetSpace ~
29665 Toggles Sdcdbsrc mode (turns it
29681 sdcdb-finish-from-src\InsetSpace ~
29689 SDCDB finish command
29723 Set break for line with point
29738 sdcdbsrc-mode\InsetSpace ~
29754 Toggle Sdcdbsrc mode
29770 dbsrc-srcmode\InsetSpace ~
29794 \begin_layout Chapter
29798 \begin_layout Standard
29799 Here are a few guidelines that will help the compiler generate more efficient
29800 code, some of the tips are specific to this compiler others are generally
29801 good programming practice.
29804 \begin_layout Itemize
29805 Use the smallest data type to represent your data-value.
29806 If it is known in advance that the value is going to be less than 256 then
29807 use an 'unsigned char' instead of a 'short' or 'int'.
29808 Please note, that ANSI C requires both signed and unsigned chars to be
29809 promoted to 'signed int'
29810 \begin_inset LatexCommand \index{promotion to signed int}
29815 \begin_inset Marginal
29818 \begin_layout Standard
29827 before doing any operation.
29829 \begin_inset LatexCommand \index{type promotion}
29834 \begin_inset LatexCommand \label{type promotion}
29838 can be omitted, if the result is the same.
29839 The effect of the promotion rules together with the sign-extension is often
29844 \begin_layout Verse
29847 unsigned char uc = 0xfe;
29849 if (uc * uc < 0) /* this is true! */
29862 \begin_layout Standard
29869 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29877 \begin_layout Verse
29880 (unsigned char) -12 / (signed char) -3 = ...
29883 \begin_layout Standard
29884 No, the result is not 4:
29887 \begin_layout Verse
29890 (int) (unsigned char) -12 / (int) (signed char) -3 =
29892 (int) (unsigned char)
29893 0xf4 / (int) (signed char) 0xfd =
29895 (int) 0x00f4 / (int) 0xfffd =
29900 (int) 244 / (int) -3 =
29902 (int) -81 = (int) 0xffaf;
29905 \begin_layout Standard
29906 Don't complain, that gcc gives you a different result.
29907 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29908 Therefore the results are different.
29911 \begin_inset Quotes sld
29915 \begin_inset Quotes srd
29921 \begin_layout Quote
29924 If well-defined overflow characteristics are important and negative values
29925 are not, or if you want to steer clear of sign-extension problems when
29926 manipulating bits or bytes, use one of the corresponding unsigned types.
29927 (Beware when mixing signed and unsigned values in expressions, though.)
29930 character types (especially unsigned char) can be used as "tiny" integers,
29931 doing so is sometimes more trouble than it's worth, due to unpredictable
29932 sign extension and increased code size.
29936 \begin_layout Itemize
29937 Use unsigned when it is known in advance that the value is not going to
29939 This helps especially if you are doing division or multiplication, bit-shifting
29940 or are using an array index.
29943 \begin_layout Itemize
29944 NEVER jump into a LOOP.
29947 \begin_layout Itemize
29948 Declare the variables to be local
29949 \begin_inset LatexCommand \index{local variables}
29953 whenever possible, especially loop control variables (induction).
29956 \begin_layout Itemize
29957 Have a look at the assembly listing to get a
29958 \begin_inset Quotes sld
29962 \begin_inset Quotes srd
29965 for the code generation.
29968 \begin_layout Section
29969 Porting code from or to other compilers
29970 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29977 \begin_layout Itemize
29978 check whether endianness of the compilers differs and adapt where needed.
29981 \begin_layout Itemize
29982 check the device specific header files
29983 \begin_inset LatexCommand \index{Header files}
29988 \begin_inset LatexCommand \index{Include files}
29992 for compiler specific syntax.
29993 Eventually include the file <compiler.h
29994 \begin_inset LatexCommand \index{compiler.h (include file)}
29999 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30003 to allow using common header files.
30006 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30013 \begin_layout Itemize
30014 check whether the startup code contains the correct initialization (watchdog,
30018 \begin_layout Itemize
30019 check whether the sizes of short, int, long match.
30022 \begin_layout Itemize
30023 check if some 16 or 32 bit hardware registers require a specific addressing
30024 order (least significant or most significant byte first) and adapt if needed
30033 relate to time and not to lower/upper memory location here, so this is
30038 the same as endianness).
30041 \begin_layout Itemize
30042 check whether the keyword
30046 is used where needed.
30047 The compilers might differ in their optimization characteristics (as different
30048 versions of the same compiler might also use more clever optimizations
30049 this is good idea anyway).
30051 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30058 \begin_layout Itemize
30059 check that the compilers are not told to supress warnings.
30062 \begin_layout Itemize
30063 check and convert compiler specific extensions (interrupts, memory areas,
30067 \begin_layout Itemize
30068 check for differences in type promotion.
30069 Especially check for math operations on
30078 For the sake of C99 compatibility SDCC will probably promote these to
30082 more often than other compilers.
30083 Eventually insert explicit casts to
30092 Also check that the ~\InsetSpace ~
30094 \begin_inset LatexCommand \index{\~\/ Operator}
30101 \begin_inset LatexCommand \index{bit}
30107 variables, use the !\InsetSpace ~
30110 \begin_inset LatexCommand \ref{type promotion}
30115 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30122 \begin_layout Itemize
30123 check the assembly code generated for interrupt routines (f.e.
30124 for calls to possibly non-reentrant library functions).
30127 \begin_layout Itemize
30128 check whether timing loops result in proper timing (or preferably consider
30129 a rewrite of the code with timer based delays instead).
30132 \begin_layout Itemize
30133 check for differences in printf parameters (some compilers push (va_arg
30134 \begin_inset LatexCommand \index{vararg, va\_arg}
30138 ) char variables as
30142 others push them as
30148 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30155 \begin_layout Itemize
30156 check the resulting memory map
30157 \begin_inset LatexCommand \index{Memory map}
30162 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30163 ly idata, pdata, xdata).
30164 Eventually check if unexpected library functions are included.
30167 \begin_layout Section
30169 \begin_inset LatexCommand \index{Tools}
30173 included in the distribution
30176 \begin_layout Standard
30178 \begin_inset Tabular
30179 <lyxtabular version="3" rows="12" columns="3">
30181 <column alignment="left" valignment="top" leftline="true" width="0pt">
30182 <column alignment="left" valignment="top" leftline="true" width="0pt">
30183 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30184 <row topline="true" bottomline="true">
30185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30188 \begin_layout Standard
30196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30199 \begin_layout Standard
30207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30210 \begin_layout Standard
30219 <row topline="true">
30220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30223 \begin_layout Standard
30225 \begin_inset LatexCommand \index{uCsim}
30234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30237 \begin_layout Standard
30238 Simulator for various architectures
30243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30246 \begin_layout Standard
30253 <row topline="true">
30254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30257 \begin_layout Standard
30263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30266 \begin_layout Standard
30268 \begin_inset LatexCommand \index{Header files}
30273 \begin_inset LatexCommand \index{Include files}
30282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30285 \begin_layout Standard
30286 sdcc/support/scripts
30292 <row topline="true">
30293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30296 \begin_layout Standard
30302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30305 \begin_layout Standard
30306 header file conversion
30311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30314 \begin_layout Standard
30315 sdcc/support/scripts
30321 <row topline="true">
30322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30325 \begin_layout Standard
30331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30334 \begin_layout Standard
30340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30343 \begin_layout Standard
30359 <row topline="true">
30360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30363 \begin_layout Standard
30369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30372 \begin_layout Standard
30378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30381 \begin_layout Standard
30397 <row topline="true">
30398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30401 \begin_layout Standard
30407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30410 \begin_layout Standard
30416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30419 \begin_layout Standard
30435 <row topline="true">
30436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30439 \begin_layout Standard
30445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30448 \begin_layout Standard
30454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30457 \begin_layout Standard
30473 <row topline="true">
30474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30477 \begin_layout Standard
30483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30486 \begin_layout Standard
30492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30495 \begin_layout Standard
30511 <row topline="true">
30512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30515 \begin_layout Standard
30521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30524 \begin_layout Standard
30530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30533 \begin_layout Standard
30549 <row topline="true">
30550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30553 \begin_layout Standard
30559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30562 \begin_layout Standard
30568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30571 \begin_layout Standard
30587 <row topline="true" bottomline="true">
30588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30591 \begin_layout Standard
30597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30600 \begin_layout Standard
30602 \begin_inset LatexCommand \index{packihx (tool)}
30611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30614 \begin_layout Standard
30639 \begin_layout Section
30641 \begin_inset LatexCommand \index{Documentation}
30645 included in the distribution
30648 \begin_layout Standard
30650 \begin_inset Tabular
30651 <lyxtabular version="3" rows="10" columns="2">
30653 <column alignment="block" valignment="top" leftline="true" width="40col%">
30654 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30655 <row topline="true" bottomline="true" endhead="true">
30656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30659 \begin_layout Standard
30667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30670 \begin_layout Standard
30673 Filename / Where to get
30679 <row topline="true">
30680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30683 \begin_layout Standard
30684 SDCC Compiler User Guide
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30692 \begin_layout Standard
30693 You're reading it right now
30705 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30715 <row topline="true">
30716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30719 \begin_layout Standard
30725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30728 \begin_layout Standard
30741 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30751 <row topline="true">
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30755 \begin_layout Standard
30757 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30762 \begin_inset LatexCommand \index{Assembler documentation}
30769 \begin_inset LatexCommand \index{aslink}
30774 \begin_inset LatexCommand \index{Linker documentation}
30783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30786 \begin_layout Standard
30787 sdcc/as/doc/asxhtm.html
30799 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30809 <row topline="true">
30810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30813 \begin_layout Standard
30814 SDCC regression test
30815 \begin_inset LatexCommand \index{Regression test}
30824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30827 \begin_layout Standard
30828 sdcc/doc/test_suite_spec.pdf
30840 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30850 <row topline="true">
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30854 \begin_layout Standard
30860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30863 \begin_layout Standard
30876 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30886 <row topline="true">
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30890 \begin_layout Standard
30891 Notes on debugging with SDCDB
30892 \begin_inset LatexCommand \index{SDCDB (debugger)}
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30904 \begin_layout Standard
30905 sdcc/debugger/README
30917 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30927 <row topline="true">
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30931 \begin_layout Standard
30933 \begin_inset LatexCommand \index{uCsim}
30937 Software simulator for microcontrollers
30942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30945 \begin_layout Standard
30975 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30985 <row topline="true">
30986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30989 \begin_layout Standard
30990 Temporary notes on the pic16
30991 \begin_inset LatexCommand \index{PIC16}
31000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31003 \begin_layout Standard
31004 sdcc/src/pic16/NOTES
31016 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31026 <row topline="true" bottomline="true">
31027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31030 \begin_layout Standard
31031 SDCC internal documentation (debugging file format)
31036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31039 \begin_layout Standard
31069 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31088 \begin_layout Section
31089 Related open source tools
31090 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31095 \begin_inset LatexCommand \index{Related tools}
31102 \begin_layout Standard
31104 \begin_inset Tabular
31105 <lyxtabular version="3" rows="16" columns="3">
31107 <column alignment="left" valignment="top" leftline="true" width="0pt">
31108 <column alignment="block" valignment="top" leftline="true" width="30line%">
31109 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31110 <row topline="true" bottomline="true">
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31114 \begin_layout Standard
31122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31125 \begin_layout Standard
31133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31136 \begin_layout Standard
31145 <row topline="true">
31146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31149 \begin_layout Standard
31151 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31163 \begin_layout Standard
31169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31172 \begin_layout Standard
31173 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31183 <row topline="true">
31184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31187 \begin_layout Standard
31189 \begin_inset LatexCommand \index{gputils (pic tools)}
31198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31201 \begin_layout Standard
31207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31210 \begin_layout Standard
31211 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31221 <row topline="true">
31222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31225 \begin_layout Standard
31231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31234 \begin_layout Standard
31240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31243 \begin_layout Standard
31244 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31254 <row topline="true">
31255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31258 \begin_layout Standard
31264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31267 \begin_layout Standard
31268 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31277 \begin_layout Standard
31278 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31288 <row topline="true">
31289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31292 \begin_layout Standard
31294 \begin_inset LatexCommand \index{indent (source formatting tool)}
31303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31306 \begin_layout Standard
31307 Formats C source - Master of the white spaces
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31315 \begin_layout Standard
31316 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31326 <row topline="true">
31327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31330 \begin_layout Standard
31332 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31344 \begin_layout Standard
31345 Object file conversion, checksumming, ...
31350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31353 \begin_layout Standard
31354 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31364 <row topline="true">
31365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31368 \begin_layout Standard
31370 \begin_inset LatexCommand \index{objdump (tool)}
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31382 \begin_layout Standard
31383 Object file conversion, ...
31388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31391 \begin_layout Standard
31392 Part of binutils (should be there anyway)
31398 <row topline="true">
31399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31402 \begin_layout Standard
31408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31411 \begin_layout Standard
31412 8051 monitor (hex up-/download, single step, disassemble)
31417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31420 \begin_layout Standard
31421 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31431 <row topline="true">
31432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31435 \begin_layout Standard
31437 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31449 \begin_layout Standard
31450 Source code documentation system
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31458 \begin_layout Standard
31459 \begin_inset LatexCommand \url{http://www.doxygen.org}
31469 <row topline="true">
31470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31473 \begin_layout Standard
31479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31482 \begin_layout Standard
31483 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31491 \begin_layout Standard
31492 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31502 <row topline="true">
31503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31506 \begin_layout Standard
31512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31515 \begin_layout Standard
31516 8051 monitor (hex up-/download, single step, disassemble)
31521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31524 \begin_layout Standard
31525 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31535 <row topline="true">
31536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31539 \begin_layout Standard
31541 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31553 \begin_layout Standard
31554 Statically checks c sources (see
31555 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31567 \begin_layout Standard
31568 \begin_inset LatexCommand \url{http://www.splint.org}
31578 <row topline="true" bottomline="true">
31579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31582 \begin_layout Standard
31584 \begin_inset LatexCommand \index{DDD (debugger)}
31593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31596 \begin_layout Standard
31597 Debugger, serves nicely as GUI to SDCDB
31598 \begin_inset LatexCommand \index{SDCDB (debugger)}
31607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31610 \begin_layout Standard
31611 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31621 <row bottomline="true">
31622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31625 \begin_layout Standard
31627 \begin_inset LatexCommand \index{d52}
31632 \begin_inset LatexCommand \index{d52 (disassembler)}
31641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31644 \begin_layout Standard
31645 Disassembler, can count instruction cycles
31646 \begin_inset LatexCommand \index{instruction cycles (count)}
31650 , use with options -pnd
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31658 \begin_layout Standard
31659 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31669 <row bottomline="true">
31670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31673 \begin_layout Standard
31675 \begin_inset LatexCommand \index{cmake}
31684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31687 \begin_layout Standard
31688 Cross platform build system, generates Makefiles
31689 \begin_inset LatexCommand \index{Makefile}
31693 and project workspaces
31694 \begin_inset LatexCommand \index{project workspace}
31703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31706 \begin_layout Standard
31707 \begin_inset LatexCommand \url{http://www.cmake.org}
31715 and a dedicated wiki entry:
31716 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
31735 \begin_layout Section
31736 Related documentation / recommended reading
31739 \begin_layout Standard
31741 \begin_inset Tabular
31742 <lyxtabular version="3" rows="7" columns="3">
31744 <column alignment="left" valignment="top" leftline="true" width="0pt">
31745 <column alignment="left" valignment="top" leftline="true" width="0">
31746 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31747 <row topline="true" bottomline="true">
31748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31751 \begin_layout Standard
31759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31762 \begin_layout Standard
31770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31773 \begin_layout Standard
31782 <row topline="true">
31783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31786 \begin_layout Standard
31801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31804 \begin_layout Standard
31806 \begin_inset LatexCommand \index{C Reference card}
31815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31818 \begin_layout Standard
31819 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31829 <row topline="true">
31830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31833 \begin_layout Standard
31839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31842 \begin_layout Standard
31844 \begin_inset LatexCommand \index{C FAQ}
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31856 \begin_layout Standard
31857 \begin_inset LatexCommand \url{http://www.c-faq.com}
31867 <row topline="true">
31868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31871 \begin_layout Standard
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31880 \begin_layout Standard
31881 \begin_inset Quotes sld
31885 \begin_inset Quotes srd
31893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31896 \begin_layout Standard
31899 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31909 <row topline="true">
31910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31913 \begin_layout Standard
31919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31922 \begin_layout Standard
31923 \begin_inset Quotes sld
31926 Extensions for Embedded C
31927 \begin_inset Quotes srd
31935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31938 \begin_layout Standard
31941 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31951 <row topline="true">
31952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31955 \begin_layout Standard
31961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31964 \begin_layout Standard
31965 Latest datasheet of target CPU
31970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31973 \begin_layout Standard
31980 <row topline="true" bottomline="true">
31981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31984 \begin_layout Standard
31990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31993 \begin_layout Standard
31994 Revision history of datasheet
31999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32002 \begin_layout Standard
32018 \begin_layout Section
32019 Application notes specifically for SDCC
32022 \begin_layout Standard
32023 SDCC makes no claims about the completeness of this list and about up-to-datenes
32024 s or correctness of the application notes
32025 \begin_inset LatexCommand \index{Application notes}
32032 \begin_layout Standard
32036 \begin_inset Tabular
32037 <lyxtabular version="3" rows="7" columns="3">
32039 <column alignment="block" valignment="top" leftline="true" width="17col%">
32040 <column alignment="block" valignment="top" leftline="true" width="27col%">
32041 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32042 <row topline="true" bottomline="true">
32043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32046 \begin_layout Standard
32055 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32058 \begin_layout Standard
32067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32070 \begin_layout Standard
32080 <row topline="true">
32081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32084 \begin_layout Standard
32092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32095 \begin_layout Standard
32098 Using the SDCC Compiler for the DS80C400
32099 \begin_inset LatexCommand \index{DS80C400}
32108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32111 \begin_layout Standard
32114 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32124 <row topline="true">
32125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32128 \begin_layout Standard
32136 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32139 \begin_layout Standard
32142 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32143 \begin_inset LatexCommand \index{DS89C4x0}
32147 Family of Microcontrollers
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32155 \begin_layout Standard
32158 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32168 <row topline="true">
32169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32172 \begin_layout Standard
32175 Silicon Laboratories / Cygnal
32180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32183 \begin_layout Standard
32186 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32187 \begin_inset LatexCommand \index{IDE}
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32199 \begin_layout Standard
32202 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32212 <row topline="true">
32213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32216 \begin_layout Standard
32219 Ramtron / Goal Semiconductor
32224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32227 \begin_layout Standard
32230 Interfacing SDCC to Syn and Textpad
32235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32238 \begin_layout Standard
32241 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32251 <row topline="true">
32252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32255 \begin_layout Standard
32258 Ramtron / Goal Semiconductor
32263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32266 \begin_layout Standard
32269 Installing and Configuring SDCC and Crimson Editor
32274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32277 \begin_layout Standard
32280 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32290 <row topline="true" bottomline="true">
32291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32294 \begin_layout Standard
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32305 \begin_layout Standard
32308 MSC12xx Programming with SDCC
32313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32316 \begin_layout Standard
32319 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32336 \begin_layout Section
32340 \begin_layout Standard
32341 Some questions answered, some pointers given - it might be time to in turn
32349 \begin_layout Itemize
32350 can you solve your project with the selected microcontroller? Would you
32351 find out early or rather late that your target is too small/slow/whatever?
32352 Can you switch to a slightly better device if it doesn't fit?
32355 \begin_layout Itemize
32356 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32357 and/or another programming language be more adequate? Would an operating
32358 system on the target device help?
32361 \begin_layout Itemize
32362 if you solved the problem, will the marketing department be happy?
32365 \begin_layout Itemize
32366 if the marketing department is happy, will customers be happy?
32369 \begin_layout Itemize
32370 if you're the project manager, marketing department and maybe even the customer
32371 in one person, have you tried to see the project from the outside?
32374 \begin_layout Itemize
32375 is the project done if you think it is done? Or is just that other interface/pro
32376 tocol/feature/configuration/option missing? How about website, manual(s),
32377 internationali(z|s)ation, packaging, labels, 2nd source for components,
32378 electromagnetic compatability/interference, documentation for production,
32379 production test software, update mechanism, patent issues?
32382 \begin_layout Itemize
32383 is your project adequately positioned in that magic triangle: fame, fortune,
32387 \begin_layout Standard
32388 Maybe not all answers to these questions are known and some answers may
32393 , nevertheless knowing these questions may help you to avoid burnout
32397 \begin_layout Standard
32398 burnout is bad for electronic devices, programmers and motorcycle tyres
32404 Chances are you didn't want to hear some of them...
32407 \begin_layout Chapter
32409 \begin_inset LatexCommand \index{Support}
32416 \begin_layout Standard
32417 SDCC has grown to be a large project.
32418 The compiler alone (without the preprocessor, assembler and linker) is
32419 well over 150,000 lines of code (blank stripped).
32420 The open source nature of this project is a key to its continued growth
32422 You gain the benefit and support of many active software developers and
32424 Is SDCC perfect? No, that's why we need your help.
32425 The developers take pride in fixing reported bugs.
32426 You can help by reporting the bugs and helping other SDCC users.
32427 There are lots of ways to contribute, and we encourage you to take part
32428 in making SDCC a great software package.
32432 \begin_layout Standard
32433 The SDCC project is hosted on the SDCC sourceforge site at
32434 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32439 You'll find the complete set of mailing lists
32440 \begin_inset LatexCommand \index{Mailing list(s)}
32444 , forums, bug reporting system, patch submission
32445 \begin_inset LatexCommand \index{Patch submission}
32450 \begin_inset LatexCommand \index{download}
32454 area and Subversion code repository
32455 \begin_inset LatexCommand \index{Subversion code repository}
32462 \begin_layout Section
32464 \begin_inset LatexCommand \index{Bug reporting}
32469 \begin_inset LatexCommand \index{Reporting bugs}
32476 \begin_layout Standard
32477 The recommended way of reporting bugs is using the infrastructure of the
32479 You can follow the status of bug reports there and have an overview about
32483 \begin_layout Standard
32484 Bug reports are automatically forwarded to the developer mailing list and
32485 will be fixed ASAP.
32486 When reporting a bug, it is very useful to include a small test program
32487 (the smaller the better) which reproduces the problem.
32488 If you can isolate the problem by looking at the generated assembly code,
32489 this can be very helpful.
32490 Compiling your program with the -
32494 \begin_layout Standard
32504 \begin_inset LatexCommand \index{-\/-dumpall}
32508 option can sometimes be useful in locating optimization problems.
32509 When reporting a bug please make sure you:
32512 \begin_layout Enumerate
32513 Attach the code you are compiling with SDCC.
32517 \begin_layout Enumerate
32518 Specify the exact command you use to run SDCC, or attach your Makefile.
32522 \begin_layout Enumerate
32523 Specify the SDCC version (type "
32529 "), your platform, and operating system.
32533 \begin_layout Enumerate
32534 Provide an exact copy of any error message or incorrect output.
32538 \begin_layout Enumerate
32539 Put something meaningful in the subject of your message.
32542 \begin_layout Standard
32543 Please attempt to include these 5 important parts, as applicable, in all
32544 requests for support or when reporting any problems or bugs with SDCC.
32545 Though this will make your message lengthy, it will greatly improve your
32546 chance that SDCC users and developers will be able to help you.
32547 Some SDCC developers are frustrated by bug reports without code provided
32548 that they can use to reproduce and ultimately fix the problem, so please
32549 be sure to provide sample code if you are reporting a bug!
32552 \begin_layout Standard
32553 Please have a short check that you are using a recent version of SDCC and
32554 the bug is not yet known.
32555 This is the link for reporting bugs:
32556 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32561 With SDCC on average having more than 200 downloads
32562 \begin_inset LatexCommand \index{download}
32566 on sourceforge per day
32570 \begin_layout Standard
32571 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32572 between 2002 and 2005.
32573 This does not include other methods of distribution.
32578 there must be some users.
32579 So it's not exactly easy to find a new bug.
32580 If you find one we need it:
32582 reporting bugs is good
32587 \begin_layout Section
32588 Requesting Features
32589 \begin_inset LatexCommand \label{sub:Requesting-Features}
32594 \begin_inset LatexCommand \index{Feature request}
32599 \begin_inset LatexCommand \index{Requesting features}
32606 \begin_layout Standard
32607 Like bug reports feature requests are forwarded to the developer mailing
32609 This is the link for requesting features:
32610 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32617 \begin_layout Section
32621 \begin_layout Standard
32622 Like bug reports contributed patches are forwarded to the developer mailing
32624 This is the link for submitting patches
32625 \begin_inset LatexCommand \index{Patch submission}
32630 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32637 \begin_layout Standard
32638 You need to specify some parameters to the
32642 command for the patches to be useful.
32643 If you modified more than one file a patch created f.e.
32648 \begin_inset Quotes sld
32651 diff -Naur unmodified_directory modified_directory >my_changes.patch
32652 \begin_inset Quotes srd
32658 will be fine, otherwise
32662 \begin_inset Quotes sld
32665 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32666 \begin_inset Quotes srd
32676 \begin_layout Section
32680 \begin_layout Standard
32681 These links should take you directly to the
32682 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32690 \begin_layout Standard
32691 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32692 automated messages (mid 2003)
32698 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32703 \begin_inset LatexCommand \index{Mailing list(s)}
32707 and forums are archived and searchable so if you are lucky someone already
32708 had a similar problem.
32709 While mails to the lists themselves are delivered promptly their web front
32710 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32711 if you're seriously using SDCC please consider subscribing to the lists.
32714 \begin_layout Section
32718 \begin_layout Standard
32719 You can follow the status of the Subversion version
32720 \begin_inset LatexCommand \index{version}
32724 of SDCC by watching the Changelog
32725 \begin_inset LatexCommand \index{Changelog}
32729 in the Subversion repository
32732 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32739 \begin_layout Section
32740 Subversion Source Code Repository
32743 \begin_layout Standard
32753 \begin_layout Standard
32767 or the filenames of the snapshot versions of SDCC include date and its
32769 \begin_inset LatexCommand \index{Subversion code repository}
32774 Subversion allows to download the source of recent or previous versions
32776 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32780 (by number or by date).
32781 An on-line source code browser and detailled instructions are also available
32783 SDCC versions starting from 1999 up to now are available (currently the
32784 versions prior to the conversion from cvs
32785 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32789 to Subversion (April 2006) are either by accessible by Subversion or by
32793 \begin_layout Section
32795 \begin_inset LatexCommand \index{Release policy}
32802 \begin_layout Standard
32803 Historically there often were long delays between official releases and
32804 the sourceforge download area tends to get not updated at all.
32805 Excuses in the past might have referred to problems with live range analysis,
32806 but as this was fixed a while ago, the current problem is that another
32807 excuse has to be found.
32808 Kidding aside, we have to get better there! On the other hand there are
32809 daily snapshots available at
32810 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32814 , and you can always build the very last version (hopefully with many bugs
32815 fixed, and features added) from the source code available at
32816 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32822 \begin_inset LatexCommand \index{wiki}
32827 \begin_inset LatexCommand \index{SDCC Wiki}
32832 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32836 also holds some information about past and future releases.
32839 \begin_layout Section
32841 \begin_inset LatexCommand \index{Examples}
32848 \begin_layout Standard
32849 You'll find some small examples in the directory
32851 sdcc/device/examples/.
32854 More examples and libraries are available at
32856 The SDCC Open Knowledge Resource
32857 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32864 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32871 \begin_layout Standard
32872 \begin_inset Note Note
32875 \begin_layout Standard
32876 I did insert a reference to Paul's web site here although it seems rather
32877 dedicated to a specific 8032 board (I think it's okay because it f.e.
32878 shows LCD/Harddisc interface and has a free 8051 monitor.
32879 Independent 8032 board vendors face hard competition of heavily subsidized
32880 development boards anyway).
32883 \begin_layout Standard
32884 Maybe we should include some links to real world applications.
32885 Preferably pointer to pointers (one for each architecture) so this stays
32894 \begin_layout Section
32896 \begin_inset LatexCommand \label{sec:Quality-control}
32901 \begin_inset LatexCommand \index{Quality control}
32908 \begin_layout Standard
32909 The compiler is passed through snaphot build compile and build checks.
32915 \begin_inset LatexCommand \index{Regression test}
32919 check that SDCC itself compiles flawlessly on several host platforms (i386,
32920 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
32921 and checks the quality of the code generated by SDCC by running the code
32922 for several target platforms through simulators.
32923 The regression test suite comprises more than 100 files which expand to
32924 more than 500 test cases which include more than 4500 tests.
32925 The results of these tests are published daily on SDCC's snapshot page
32926 (click on the red or green symbols on the right side of
32927 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32934 \begin_layout Standard
32935 There is a separate document
32938 \begin_inset LatexCommand \index{Test suite}
32945 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32949 about the regression test suite.
32952 \begin_layout Standard
32953 You'll find the test code in the directory
32955 sdcc/support/regression
32958 You can run these tests manually by running
32962 in this directory (or f.e.
32967 \begin_inset Quotes sld
32971 \begin_inset Quotes srd
32977 if you don't want to run the complete tests).
32978 The test code might also be interesting if you want to look for examples
32979 \begin_inset LatexCommand \index{Examples}
32983 checking corner cases of SDCC or if you plan to submit patches
32984 \begin_inset LatexCommand \index{Patch submission}
32991 \begin_layout Standard
32992 The PIC14 port uses a different set of regression tests
32993 \begin_inset LatexCommand \index{Regression test (PIC14)}
32997 , you'll find them in the directory
32999 sdcc/src/regression
33004 \begin_layout Section
33005 Use of SDCC in Education
33008 \begin_layout Standard
33017 \begin_layout Standard
33018 the phrase "use in education" might evoke the association "
33022 fit for use in education".
33023 This connotation is not intended but nevertheless risked as the licensing
33024 of SDCC makes it difficult to offer educational discounts
33030 If your rationales are to:
33033 \begin_layout Enumerate
33034 give students a chance to understand the
33038 steps of code generation
33041 \begin_layout Enumerate
33042 have a curriculum that can be extended for years.
33043 Then you could use an fpga board as target and your curriculum will seamlessly
33044 extend from logic synthesis (
33045 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33050 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33054 ), over assembly programming, to C to FPGA compilers (
33055 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33062 \begin_layout Enumerate
33063 be able to insert excursions about skills like using a revision control
33064 system, submitting/applying patches, using a type-setting (as opposed to
33065 word-processing) engine LyX/LaTeX, using
33066 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33071 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33075 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33076 Source Software, CPU simulation, compiler regression tests
33077 \begin_inset LatexCommand \index{Regression test}
33084 And if there should be a shortage of ideas then you can always point students
33085 to the ever-growing feature request list
33086 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33093 \begin_layout Enumerate
33094 not tie students to a specific host platform and instead allow them to use
33099 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33101 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33108 \begin_layout Enumerate
33109 not encourage students to use illegal copies of educational software
33112 \begin_layout Enumerate
33113 be immune to licensing/availability/price changes of the chosen tool chain
33116 \begin_layout Enumerate
33117 be able to change to a new target platform without having to adopt a new
33121 \begin_layout Enumerate
33122 have complete control over and insight into the tool chain
33125 \begin_layout Enumerate
33126 make your students aware about the pros and cons of open source software
33130 \begin_layout Enumerate
33131 give back to the public as you are probably at least partially publically
33135 \begin_layout Enumerate
33136 give students a chance to publically prove their skills and to possibly
33137 see a world wide impact
33140 \begin_layout Standard
33141 then SDCC is probably among the first choices.
33142 Well, probably SDCC might be the only choice.
33147 \begin_layout Chapter
33148 SDCC Technical Data
33151 \begin_layout Section
33153 \begin_inset LatexCommand \index{Optimizations}
33160 \begin_layout Standard
33161 SDCC performs a host of standard optimizations in addition to some MCU specific
33166 \begin_layout Subsection
33167 Sub-expression Elimination
33168 \begin_inset LatexCommand \index{Subexpression elimination}
33175 \begin_layout Standard
33176 The compiler does local and
33195 \begin_layout Verse
33203 \begin_layout Standard
33204 will be translated to
33207 \begin_layout Verse
33217 \begin_layout Standard
33218 Some subexpressions are not as obvious as the above example, e.g.:
33221 \begin_layout Verse
33229 \begin_layout Standard
33230 In this case the address arithmetic a->b[i] will be computed only once;
33231 the equivalent code in C would be.
33234 \begin_layout Verse
33244 \begin_layout Standard
33245 The compiler will try to keep these temporary variables in registers.
33248 \begin_layout Subsection
33249 Dead-Code Elimination
33250 \begin_inset LatexCommand \index{Dead-code elimination}
33257 \begin_layout Verse
33272 i = 1; \InsetSpace ~
33281 global = 1;\InsetSpace ~
33295 global = 3;\InsetSpace ~
33301 \begin_layout Standard
33305 \begin_layout Verse
33321 \begin_layout Subsection
33323 \begin_inset LatexCommand \index{Copy propagation}
33330 \begin_layout Verse
33354 \begin_layout Standard
33358 \begin_layout Verse
33382 \begin_layout Standard
33383 Note: the dead stores created by this copy propagation will be eliminated
33384 by dead-code elimination.
33387 \begin_layout Subsection
33389 \begin_inset LatexCommand \index{Loop optimization}
33394 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33401 \begin_layout Standard
33402 Two types of loop optimizations are done by SDCC
33410 of loop induction variables.
33411 In addition to the strength reduction the optimizer marks the induction
33412 variables and the register allocator tries to keep the induction variables
33413 in registers for the duration of the loop.
33414 Because of this preference of the register allocator
33415 \begin_inset LatexCommand \index{Register allocation}
33419 , loop induction optimization causes an increase in register pressure, which
33420 may cause unwanted spilling of other temporary variables into the stack
33421 \begin_inset LatexCommand \index{stack}
33426 The compiler will generate a warning message when it is forced to allocate
33427 extra space either on the stack or data space.
33428 If this extra space allocation is undesirable then induction optimization
33429 can be eliminated either for the entire source file (with -
33433 \begin_layout Standard
33442 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33444 \begin_inset LatexCommand \index{\#pragma noinduction}
33455 \begin_layout Verse
33458 for (i = 0 ; i < 100 ; i ++)
33467 \begin_layout Standard
33471 \begin_layout Verse
33476 for (i = 0; i < 100; i++)
33485 \begin_layout Standard
33486 As mentioned previously some loop invariants are not as apparent, all static
33487 address computations are also moved out of the loop.
33492 \begin_inset LatexCommand \index{Strength reduction}
33496 , this optimization substitutes an expression by a cheaper expression:
33499 \begin_layout Verse
33502 for (i=0;i < 100; i++)
33511 \begin_layout Standard
33515 \begin_layout Verse
33522 for (i=0;i< 100;i++) {
33528 ar[itemp1] = itemp2;
33546 \begin_layout Standard
33547 The more expensive multiplication
33548 \begin_inset LatexCommand \index{Multiplication}
33552 is changed to a less expensive addition.
33555 \begin_layout Subsection
33557 \begin_inset LatexCommand \index{Loop reversing}
33564 \begin_layout Standard
33565 This optimization is done to reduce the overhead of checking loop boundaries
33566 for every iteration.
33567 Some simple loops can be reversed and implemented using a
33568 \begin_inset Quotes eld
33571 decrement and jump if not zero
33572 \begin_inset Quotes erd
33576 SDCC checks for the following criterion to determine if a loop is reversible
33577 (note: more sophisticated compilers use data-dependency analysis to make
33578 this determination, SDCC uses a more simple minded analysis).
33581 \begin_layout Itemize
33582 The 'for' loop is of the form
33588 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33598 \begin_layout Itemize
33599 The <for body> does not contain
33600 \begin_inset Quotes eld
33604 \begin_inset Quotes erd
33608 \begin_inset Quotes erd
33614 \begin_layout Itemize
33615 All goto's are contained within the loop.
33618 \begin_layout Itemize
33619 No function calls within the loop.
33622 \begin_layout Itemize
33623 The loop control variable <sym> is not assigned any value within the loop
33626 \begin_layout Itemize
33627 The loop control variable does NOT participate in any arithmetic operation
33631 \begin_layout Itemize
33632 There are NO switch statements in the loop.
33635 \begin_layout Subsection
33636 Algebraic Simplifications
33639 \begin_layout Standard
33640 SDCC does numerous algebraic simplifications, the following is a small sub-set
33641 of these optimizations.
33644 \begin_layout Verse
33647 i = j + 0;\InsetSpace ~
33651 /* changed to: */\InsetSpace ~
33657 i /= 2;\InsetSpace ~
33664 /* changed to: */\InsetSpace ~
33671 = j - j;\InsetSpace ~
33675 /* changed to: */\InsetSpace ~
33681 i = j / 1;\InsetSpace ~
33685 /* changed to: */\InsetSpace ~
33692 \begin_layout Standard
33693 Note the subexpressions
33694 \begin_inset LatexCommand \index{Subexpression}
33698 given above are generally introduced by macro expansions or as a result
33699 of copy/constant propagation.
33702 \begin_layout Subsection
33703 'switch' Statements
33704 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33709 \begin_inset LatexCommand \index{switch statement}
33716 \begin_layout Standard
33717 SDCC can optimize switch statements to jump tables
33718 \begin_inset LatexCommand \index{jump tables}
33723 It makes the decision based on an estimate of the generated code size.
33724 SDCC is quite liberal in the requirements for jump table generation:
33727 \begin_layout Itemize
33728 The labels need not be in order, and the starting number need not be one
33729 or zero, the case labels are in numerical sequence or not too many case
33730 labels are missing.
33734 \begin_layout Verse
33737 switch(i) {\InsetSpace ~
33768 case 4: ...\InsetSpace ~
33800 case 5: ...\InsetSpace ~
33832 case 3: ...\InsetSpace ~
33863 case 6: ...\InsetSpace ~
33895 case 7: ...\InsetSpace ~
33927 case 8: ...\InsetSpace ~
33959 case 9: ...\InsetSpace ~
33991 case 10: ...\InsetSpace ~
34022 case 11: ...\InsetSpace ~
34089 \begin_layout Standard
34090 Both the above switch statements will be implemented using a jump-table.
34091 The example to the right side is slightly more efficient as the check for
34092 the lower boundary of the jump-table is not needed.
34096 \begin_layout Itemize
34097 The number of case labels is not larger than supported by the target architectur
34101 \begin_layout Itemize
34102 If the case labels are not in numerical sequence ('gaps' between cases)
34103 SDCC checks whether a jump table with additionally inserted dummy cases
34104 is still attractive.
34108 \begin_layout Itemize
34109 If the starting number is not zero and a check for the lower boundary of
34110 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34115 \begin_layout Standard
34116 Switch statements which have large gaps in the numeric sequence or those
34117 that have too many case labels can be split into more than one switch statement
34118 for efficient code generation, e.g.:
34121 \begin_layout Verse
34199 \begin_layout Standard
34200 If the above switch statement is broken down into two switch statements
34203 \begin_layout Verse
34246 \begin_layout Standard
34250 \begin_layout Verse
34293 \begin_layout Standard
34294 then both the switch statements will be implemented using jump-tables whereas
34295 the unmodified switch statement will not be.
34298 \begin_layout Standard
34299 \begin_inset Note Note
34302 \begin_layout Standard
34303 There might be reasons which SDCC cannot know about to either favour or
34304 not favour jump tables.
34305 If the target system has to be as quick for the last switch case as for
34306 the first (pro jump table), or if the switch argument is known to be zero
34307 in the majority of the cases (contra jump table).
34315 \begin_layout Standard
34316 The pragma nojtbound
34317 \begin_inset LatexCommand \index{\#pragma nojtbound}
34321 can be used to turn off checking the
34334 It has no effect if a default label is supplied.
34335 Use of this pragma is dangerous: if the switch
34336 \begin_inset LatexCommand \index{switch statement}
34340 argument is not matched by a case statement the processor will happily
34344 \begin_layout Subsection
34345 Bit-shifting Operations
34346 \begin_inset LatexCommand \index{Bit shifting}
34353 \begin_layout Standard
34354 Bit shifting is one of the most frequently used operation in embedded programmin
34356 SDCC tries to implement bit-shift operations in the most efficient way
34360 \begin_layout Verse
34373 \begin_layout Standard
34374 generates the following code:
34377 \begin_layout Verse
34392 \begin_layout Standard
34393 In general SDCC will never setup a loop if the shift count is known.
34397 \begin_layout Verse
34410 \begin_layout Standard
34414 \begin_layout Verse
34438 \begin_layout Subsection
34440 \begin_inset LatexCommand \index{Bit rotation}
34447 \begin_layout Standard
34448 A special case of the bit-shift operation is bit rotation
34449 \begin_inset LatexCommand \index{rotating bits}
34453 , SDCC recognizes the following expression to be a left bit-rotation:
34456 \begin_layout Verse
34464 char i;\InsetSpace ~
34475 /* unsigned is needed for rotation */
34480 i = ((i << 1) | (i >> 7));
34489 \begin_layout Standard
34490 will generate the following code:
34493 \begin_layout Verse
34510 \begin_layout Standard
34511 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34512 ns of this case will also be recognized as bit-rotation, i.e.:
34515 \begin_layout Verse
34518 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34521 \begin_layout Subsection
34522 Nibble and Byte Swapping
34525 \begin_layout Standard
34526 Other special cases of the bit-shift operations are nibble or byte swapping
34527 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34531 , SDCC recognizes the following expressions:
34534 \begin_layout Verse
34555 i = ((i << 4) | (i >> 4));
34561 j = ((j << 8) | (j >> 8));
34564 \begin_layout Standard
34565 and generates a swap instruction for the nibble swapping
34566 \begin_inset LatexCommand \index{Nibble swapping}
34570 or move instructions for the byte swapping
34571 \begin_inset LatexCommand \index{Byte swapping}
34577 \begin_inset Quotes sld
34581 \begin_inset Quotes srd
34584 example can be used to convert from little to big-endian or vice versa.
34585 If you want to change the endianness of a
34589 integer you have to cast to
34596 \begin_layout Standard
34597 Note that SDCC stores numbers in little-endian
34601 \begin_layout Standard
34602 Usually 8-bit processors don't care much about endianness.
34603 This is not the case for the standard 8051 which only has an instruction
34609 \begin_inset LatexCommand \index{DPTR}
34617 so little-endian is the more efficient byte order.
34623 \begin_inset LatexCommand \index{little-endian}
34628 \begin_inset LatexCommand \index{Endianness}
34633 lowest order first).
34636 \begin_layout Subsection
34638 \begin_inset LatexCommand \index{Highest Order Bit}
34643 \begin_inset LatexCommand \index{Any Order Bit}
34650 \begin_layout Standard
34651 It is frequently required to obtain the highest order bit of an integral
34652 type (long, int, short or char types).
34653 Also obtaining any other order bit is not uncommon.
34654 SDCC recognizes the following expressions to yield the highest order bit
34655 and generates optimized code for it, e.g.:
34658 \begin_layout Verse
34669 unsigned char hob1, aob1;
34673 bit hob2, hob3, aob2,
34683 hob1 = (gint >> 15) & 1;
34687 hob2 = (gint >> 15) & 1;
34691 hob3 = gint & 0x8000;
34696 aob1 = (gint >> 9) & 1;
34700 aob2 = (gint >> 8) & 1;
34704 aob3 = gint & 0x0800;
34714 \begin_layout Standard
34715 will generate the following code:
34718 \begin_layout Verse
34749 000A E5*01\InsetSpace ~
34776 000C 23\InsetSpace ~
34807 000D 54 01\InsetSpace ~
34835 000F F5*02\InsetSpace ~
34890 0011 E5*01\InsetSpace ~
34918 0013 33\InsetSpace ~
34948 0014 92*00\InsetSpace ~
35004 0016 E5*01\InsetSpace ~
35031 0018 33\InsetSpace ~
35061 0019 92*01\InsetSpace ~
35117 001B E5*01\InsetSpace ~
35176 001E 54 01\InsetSpace ~
35203 0020 F5*03\InsetSpace ~
35259 0022 E5*01\InsetSpace ~
35286 0024 13\InsetSpace ~
35316 0025 92*02\InsetSpace ~
35372 0027 E5*01\InsetSpace ~
35427 002B 92*03\InsetSpace ~
35455 \begin_layout Standard
35456 Other variations of these cases however will
35461 They are standard C expressions, so I heartily recommend these be the only
35462 way to get the highest order bit, (it is portable).
35463 Of course it will be recognized even if it is embedded in other expressions,
35467 \begin_layout Verse
35470 xyz = gint + ((gint >> 15) & 1);
35473 \begin_layout Standard
35474 will still be recognized.
35477 \begin_layout Subsection
35479 \begin_inset LatexCommand \index{Higher Order Byte}
35483 / Higher Order Word
35484 \begin_inset LatexCommand \index{Higher Order Word}
35491 \begin_layout Standard
35492 It is also frequently required to obtain a higher order byte or word of
35493 a larger integral type (long, int or short types).
35494 SDCC recognizes the following expressions to yield the higher order byte
35495 or word and generates optimized code for it, e.g.:
35498 \begin_layout Verse
35503 unsigned long int glong;
35511 unsigned char hob1,
35516 unsigned int how1, how2;
35525 hob1 = (gint >> 8) & 0xFF;
35529 hob2 = glong >> 24;
35533 how1 = (glong >> 16) & 0xFFFF;
35548 \begin_layout Standard
35549 will generate the following code:
35552 \begin_layout Verse
35583 0037 85*01*06\InsetSpace ~
35605 _foo_hob1_1_1,(_gint + 1)
35636 003A 85*05*07\InsetSpace ~
35658 _foo_hob2_1_1,(_glong + 3)
35688 003D 85*04*08\InsetSpace ~
35711 _foo_how1_1_1,(_glong + 2)
35713 0040 85*05*09\InsetSpace ~
35738 0043 85*03*0A\InsetSpace ~
35760 _foo_how2_1_1,(_glong + 1)
35762 0046 85*04*0B\InsetSpace ~
35785 (_foo_how2_1_1 + 1),(_glong + 2)
35788 \begin_layout Standard
35789 Again, variations of these cases may
35794 They are standard C expressions, so I heartily recommend these be the only
35795 way to get the higher order byte/word, (it is portable).
35796 Of course it will be recognized even if it is embedded in other expressions,
35800 \begin_layout Verse
35803 xyz = gint + ((gint >> 8) & 0xFF);
35806 \begin_layout Standard
35807 will still be recognized.
35810 \begin_layout Subsection
35812 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35817 \begin_inset LatexCommand \index{Peephole optimizer}
35824 \begin_layout Standard
35825 The compiler uses a rule based, pattern matching and re-writing mechanism
35826 for peep-hole optimization.
35831 a peep-hole optimizer by Christopher W.
35832 Fraser (cwfraser\InsetSpace ~
35835 A default set of rules are compiled into the compiler, additional rules
35836 may be added with the
35842 \begin_layout Standard
35852 \begin_inset LatexCommand \index{-\/-peep-file}
35859 The rule language is best illustrated with examples.
35862 \begin_layout Verse
35884 \begin_layout Standard
35885 The above rule will change the following assembly
35886 \begin_inset LatexCommand \index{Assembler routines}
35893 \begin_layout Verse
35901 \begin_layout Standard
35905 \begin_layout Verse
35911 \begin_layout Standard
35912 Note: All occurrences of a
35916 (pattern variable) must denote the same string.
35917 With the above rule, the assembly sequence:
35920 \begin_layout Verse
35928 \begin_layout Standard
35929 will remain unmodified.
35933 Other special case optimizations may be added by the
35940 \begin_layout Standard
35953 some variants of the 8051 MCU
35954 \begin_inset LatexCommand \index{MCS51 variants}
35967 The following two rules will change all
35984 \begin_layout Verse
35987 replace { lcall %1 } by { acall %1 }
35989 replace { ljmp %1 } by { ajmp %1 }
35992 \begin_layout Standard
35993 (NOTE: from version 2.7.3 on, you can use option -
35999 \begin_layout Standard
36011 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36015 , which also takes care of aligning the interrupt vectors properly.)
36020 \begin_layout Standard
36023 inline-assembler code
36025 is also passed through the peep hole optimizer, thus the peephole optimizer
36026 can also be used as an assembly level macro expander.
36027 The rules themselves are MCU dependent whereas the rule language infra-structur
36028 e is MCU independent.
36029 Peephole optimization rules for other MCU can be easily programmed using
36034 The syntax for a rule is as follows:
36037 \begin_layout Verse
36040 rule := replace [ restart ] '{' <assembly sequence> '
36078 <assembly sequence> '
36096 '}' [if <functionName> ] '
36101 \begin_layout Standard
36102 <assembly sequence> := assembly instruction (each instruction including
36103 labels must be on a separate line).
36107 The optimizer will apply to the rules
36108 one by one from the top in the sequence of their appearance, it will terminate
36109 when all rules are exhausted.
36110 If the 'restart' option is specified, then the optimizer will start matching
36111 the rules again from the top, this option for a rule is expensive (performance)
36112 , it is intended to be used in situations where a transformation will trigger
36113 the same rule again.
36114 An example of this (not a good one, it has side effects) is the following
36118 \begin_layout Verse
36138 \begin_layout Standard
36139 Note that the replace pattern cannot be a blank, but can be a comment line.
36140 Without the 'restart' option only the innermost 'pop' 'push' pair would
36141 be eliminated, i.e.:
36144 \begin_layout Verse
36156 \begin_layout Standard
36160 \begin_layout Verse
36170 \begin_layout Standard
36175 the restart option the rule will be applied again to the resulting code
36176 and then all the pop-push pairs will be eliminated to yield:
36179 \begin_layout Verse
36187 \begin_layout Standard
36188 A conditional function can be attached to a rule.
36189 Attaching rules are somewhat more involved, let me illustrate this with
36193 \begin_layout Verse
36217 \begin_layout Standard
36218 The optimizer does a look-up of a function name table defined in function
36223 in the source file SDCCpeeph.c, with the name
36228 If it finds a corresponding entry the function is called.
36229 Note there can be no parameters specified for these functions, in this
36234 is crucial, since the function
36238 expects to find the label in that particular variable (the hash table containin
36239 g the variable bindings is passed as a parameter).
36240 If you want to code more such functions, take a close look at the function
36241 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36242 Currently implemented are
36244 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36245 24bitMode, portIsDS390, 24bitModeAndPortDS390
36254 \begin_layout Standard
36255 I know this whole thing is a little kludgey, but maybe some day we will
36256 have some better means.
36257 If you are looking at this file, you will see the default rules that are
36258 compiled into the compiler, you can add your own rules in the default set
36259 there if you get tired of specifying the -
36263 \begin_layout Standard
36275 \begin_layout Section
36277 \begin_inset LatexCommand \index{ANSI-compliance}
36282 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36289 \begin_layout Standard
36290 The latest publically available version of the standard
36292 ISO/IEC 9899 - Programming languages - C
36294 should be available at:
36295 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36304 \begin_layout Standard
36305 Deviations from the compliance:
36308 \begin_layout Itemize
36309 functions are not reentrant
36310 \begin_inset LatexCommand \index{reentrant}
36314 unless explicitly declared as such or the
36320 \begin_layout Standard
36330 \begin_inset LatexCommand \index{-\/-stack-auto}
36336 command line option is specified.
36339 \begin_layout Itemize
36341 \begin_inset LatexCommand \index{struct}
36346 \begin_inset LatexCommand \index{union}
36350 cannot be assigned values directly, cannot be passed as function parameters
36351 or assigned to each other and cannot be a return value
36352 \begin_inset LatexCommand \index{return value}
36356 from a function, e.g.:
36360 \begin_layout Verse
36383 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36402 s parms) /* invalid in SDCC although allowed in ANSI */
36424 return rets; /* is invalid in SDCC although allowed in ANSI */
36430 \begin_layout Itemize
36431 initialization of structure arrays must be fully braced.
36435 \begin_layout Verse
36438 struct s { char x } a[] = {1, 2};\InsetSpace ~
36443 /* invalid in SDCC */
36446 } a[] = {{1}, {2}}; /* OK */
36450 \begin_layout Itemize
36452 \begin_inset LatexCommand \index{long long (not supported)}
36457 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36464 \begin_layout Itemize
36466 \begin_inset LatexCommand \index{double (not supported)}
36470 ' precision floating point
36471 \begin_inset LatexCommand \index{Floating point support}
36478 \begin_layout Itemize
36480 \begin_inset LatexCommand \index{K\&R style}
36484 function declarations are NOT allowed.
36488 \begin_layout Verse
36491 foo(i,j) /* this old style of function declarations */
36493 int i,j; /* is valid
36494 in ANSI but not valid in SDCC */
36509 \begin_layout Itemize
36510 Most enhancements in C99 are not supported, e.g.:
36514 \begin_layout Verse
36521 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36525 \begin_layout Itemize
36526 But some have been added recently in SDCC 2.7.0.
36527 They must be considered alpha quality however.
36531 \begin_layout Verse
36536 \begin_inset LatexCommand \index{inline (not supported)}
36542 int increment (int a) { return a+1; } /* inlines the increment without
36543 function call overhead */
36548 \begin_inset LatexCommand \index{inline (not supported)}
36554 p; /* accepted but ignored */
36558 \begin_layout Itemize
36559 Certain words that are valid identifiers in the standard may be reserved
36560 words in SDCC unless the
36566 \begin_layout Standard
36576 \begin_inset LatexCommand \index{-\/-std-c89}
36584 \begin_layout Standard
36594 \begin_inset LatexCommand \index{-\/-std-c99}
36600 command line options are used.
36601 These may include (depending on the selected processor): 'at', 'banked',
36602 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36603 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36604 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36606 Compliant equivalents of these keywords are always available in a form
36607 that begin with two underscores
36608 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36613 '__data' instead of 'data'.
36616 \begin_layout Section
36617 Cyclomatic Complexity
36618 \begin_inset LatexCommand \index{Cyclomatic complexity}
36625 \begin_layout Standard
36626 Cyclomatic complexity of a function is defined as the number of independent
36627 paths the program can take during execution of the function.
36628 This is an important number since it defines the number test cases you
36629 have to generate to validate the function.
36630 The accepted industry standard for complexity number is 10, if the cyclomatic
36631 complexity reported by SDCC exceeds 10 you should think about simplification
36632 of the function logic.
36633 Note that the complexity level is not related to the number of lines of
36634 code in a function.
36635 Large functions can have low complexity, and small functions can have large
36641 SDCC uses the following formula to compute the complexity:
36646 \begin_layout Standard
36647 complexity = (number of edges in control flow graph) - (number of nodes
36648 in control flow graph) + 2;
36652 Having said that the industry standard is 10,
36653 you should be aware that in some cases it be may unavoidable to have a
36654 complexity level of less than 10.
36655 For example if you have switch statement with more than 10 case labels,
36656 each case label adds one to the complexity level.
36657 The complexity level is by no means an absolute measure of the algorithmic
36658 complexity of the function, it does however provide a good starting point
36659 for which functions you might look at for further optimization.
36662 \begin_layout Section
36663 Retargetting for other Processors
36666 \begin_layout Standard
36667 The issues for retargetting the compiler are far too numerous to be covered
36669 What follows is a brief description of each of the seven phases of the
36670 compiler and its MCU dependency.
36673 \begin_layout Itemize
36674 Parsing the source and building the annotated parse tree.
36675 This phase is largely MCU independent (except for the language extensions).
36676 Syntax & semantic checks are also done in this phase, along with some initial
36677 optimizations like back patching labels and the pattern matching optimizations
36678 like bit-rotation etc.
36681 \begin_layout Itemize
36682 The second phase involves generating an intermediate code which can be easy
36683 manipulated during the later phases.
36684 This phase is entirely MCU independent.
36685 The intermediate code generation assumes the target machine has unlimited
36686 number of registers, and designates them with the name iTemp.
36687 The compiler can be made to dump a human readable form of the code generated
36692 \begin_layout Standard
36704 \begin_layout Itemize
36705 This phase does the bulk of the standard optimizations and is also MCU independe
36707 This phase can be broken down into several sub-phases:
36711 Break down intermediate
36712 code (iCode) into basic blocks.
36714 Do control flow & data flow analysis on the
36717 Do local common subexpression elimination, then global subexpressio
36720 Dead code elimination
36724 If loop optimizations
36725 caused any changes then do 'global subexpression elimination' and 'dead
36726 code elimination' again.
36729 \begin_layout Itemize
36730 This phase determines the live-ranges; by live range I mean those iTemp
36731 variables defined by the compiler that still survive after all the optimization
36733 Live range analysis
36734 \begin_inset LatexCommand \index{Live range analysis}
36738 is essential for register allocation, since these computation determines
36739 which of these iTemps will be assigned to registers, and for how long.
36742 \begin_layout Itemize
36743 Phase five is register allocation.
36744 There are two parts to this process.
36748 The first part I call 'register packing'
36749 (for lack of a better term).
36750 In this case several MCU specific expression folding is done to reduce
36755 The second part is more MCU independent and deals with
36756 allocating registers to the remaining live ranges.
36757 A lot of MCU specific code does creep into this phase because of the limited
36758 number of index registers available in the 8051.
36761 \begin_layout Itemize
36762 The Code generation phase is (unhappily), entirely MCU dependent and very
36763 little (if any at all) of this code can be reused for other MCU.
36764 However the scheme for allocating a homogenized assembler operand for each
36765 iCode operand may be reused.
36768 \begin_layout Itemize
36769 As mentioned in the optimization section the peep-hole optimizer is rule
36770 based system, which can reprogrammed for other MCUs.
36773 \begin_layout Standard
36774 More information is available on SDCC Wiki
36775 \begin_inset LatexCommand \index{wiki}
36780 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36784 ) and in the thread
36785 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36792 \begin_layout Chapter
36794 \begin_inset LatexCommand \index{Compiler internals}
36801 \begin_layout Section
36802 The anatomy of the compiler
36803 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36810 \begin_layout Standard
36813 This is an excerpt from an article published in Circuit Cellar Magazine
36819 It's a little outdated (the compiler is much more efficient now and user/develo
36820 per friendly), but pretty well exposes the guts of it all.
36826 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36827 It is fairly easy to retarget for other 8-bit MCU.
36828 Here we take a look at some of the internals of the compiler.
36832 \begin_layout Paragraph*
36834 \begin_inset LatexCommand \index{Parsing}
36841 \begin_layout Standard
36842 Parsing the input source file and creating an AST (Annotated Syntax Tree
36843 \begin_inset LatexCommand \index{Annotated syntax tree}
36848 This phase also involves propagating types (annotating each node of the
36849 parse tree with type information) and semantic analysis.
36850 There are some MCU specific parsing rules.
36851 For example the storage classes, the extended storage classes are MCU specific
36852 while there may be a xdata storage class for 8051 there is no such storage
36853 class for z80 or Atmel AVR.
36854 SDCC allows MCU specific storage class extensions, i.e.
36855 xdata will be treated as a storage class specifier when parsing 8051 C
36856 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36860 \begin_layout Paragraph*
36862 \begin_inset LatexCommand \index{iCode}
36869 \begin_layout Standard
36870 Intermediate code generation.
36871 In this phase the AST is broken down into three-operand form (iCode).
36872 These three operand forms are represented as doubly linked lists.
36873 ICode is the term given to the intermediate form generated by the compiler.
36874 ICode example section shows some examples of iCode generated for some simple
36875 C source functions.
36878 \begin_layout Paragraph*
36880 \begin_inset LatexCommand \index{Optimizations}
36887 \begin_layout Standard
36888 Bulk of the target independent optimizations is performed in this phase.
36889 The optimizations include constant propagation, common sub-expression eliminati
36890 on, loop invariant code movement, strength reduction of loop induction variables
36891 and dead-code elimination.
36894 \begin_layout Paragraph*
36895 Live range analysis
36896 \begin_inset LatexCommand \index{Live range analysis}
36903 \begin_layout Standard
36904 During intermediate code generation phase, the compiler assumes the target
36905 machine has infinite number of registers and generates a lot of temporary
36907 The live range computation determines the lifetime of each of these compiler-ge
36908 nerated temporaries.
36909 A picture speaks a thousand words.
36910 ICode example sections show the live range annotations for each of the
36912 It is important to note here, each iCode is assigned a number in the order
36913 of its execution in the function.
36914 The live ranges are computed in terms of these numbers.
36915 The from number is the number of the iCode which first defines the operand
36916 and the to number signifies the iCode which uses this operand last.
36919 \begin_layout Paragraph*
36920 Register Allocation
36921 \begin_inset LatexCommand \index{Register allocation}
36928 \begin_layout Standard
36929 The register allocation determines the type and number of registers needed
36931 In most MCUs only a few registers can be used for indirect addressing.
36932 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36933 address the internal ram and DPTR to indirectly address the external ram.
36934 The compiler will try to allocate the appropriate register to pointer variables
36936 ICode example section shows the operands annotated with the registers assigned
36938 The compiler will try to keep operands in registers as much as possible;
36939 there are several schemes the compiler uses to do achieve this.
36940 When the compiler runs out of registers the compiler will check to see
36941 if there are any live operands which is not used or defined in the current
36942 basic block being processed, if there are any found then it will push that
36943 operand and use the registers in this block, the operand will then be popped
36944 at the end of the basic block.
36948 \begin_layout Standard
36949 There are other MCU specific considerations in this phase.
36950 Some MCUs have an accumulator; very short-lived operands could be assigned
36951 to the accumulator instead of a general-purpose register.
36954 \begin_layout Paragraph*
36958 \begin_layout Standard
36959 Figure II gives a table of iCode
36960 \begin_inset LatexCommand \index{iCode}
36964 operations supported by the compiler.
36965 The code generation involves translating these operations into corresponding
36966 assembly code for the processor.
36967 This sounds overly simple but that is the essence of code generation.
36968 Some of the iCode operations are generated on a MCU specific manner for
36969 example, the z80 port does not use registers to pass parameters so the
36970 SEND and RECV iCode operations will not be generated, and it also does
36971 not support JUMPTABLES.
36977 \begin_layout Standard
36981 \begin_inset Tabular
36982 <lyxtabular version="3" rows="39" columns="4">
36983 <features islongtable="true" headBottomDL="true">
36984 <column alignment="block" valignment="top" leftline="true" width="13col%">
36985 <column alignment="left" valignment="top" leftline="true" width="13col%">
36986 <column alignment="block" valignment="top" leftline="true" width="22col%">
36987 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36988 <row topline="true" bottomline="true" endhead="true">
36989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36992 \begin_layout Standard
36998 \begin_inset LatexCommand \index{iCode}
37007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37010 \begin_layout Standard
37018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37021 \begin_layout Standard
37029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37032 \begin_layout Standard
37041 <row topline="true">
37042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37045 \begin_layout Standard
37053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37056 \begin_layout Standard
37059 IC_LEFT() IC_RESULT()
37064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37067 \begin_layout Standard
37075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37078 \begin_layout Standard
37081 IC_RESULT = ! IC_LEFT;
37087 <row topline="true">
37088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37091 \begin_layout Standard
37099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37102 \begin_layout Standard
37105 IC_LEFT() IC_RESULT()
37110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37113 \begin_layout Standard
37116 Bitwise complement of
37121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37124 \begin_layout Standard
37127 IC_RESULT = ~IC_LEFT;
37133 <row topline="true">
37134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37137 \begin_layout Standard
37145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37148 \begin_layout Standard
37151 IC_LEFT() IC_RESULT()
37156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37159 \begin_layout Standard
37162 Rotate right with carry
37167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37170 \begin_layout Standard
37173 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37179 <row topline="true">
37180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37183 \begin_layout Standard
37191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37194 \begin_layout Standard
37197 IC_LEFT() IC_RESULT()
37202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37205 \begin_layout Standard
37208 Rotate left with carry
37213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37216 \begin_layout Standard
37219 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37225 <row topline="true">
37226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37229 \begin_layout Standard
37237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37240 \begin_layout Standard
37243 IC_LEFT() IC_RESULT()
37248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37251 \begin_layout Standard
37254 Get the highest order bit of IC_LEFT
37259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37262 \begin_layout Standard
37265 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37271 <row topline="true">
37272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37275 \begin_layout Standard
37283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37286 \begin_layout Standard
37289 IC_LEFT() IC_RESULT()
37294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37297 \begin_layout Standard
37305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37308 \begin_layout Standard
37311 IC_RESULT = - IC_LEFT;
37317 <row topline="true">
37318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37321 \begin_layout Standard
37329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37332 \begin_layout Standard
37340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37343 \begin_layout Standard
37346 Push the operand into stack
37351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37354 \begin_layout Standard
37363 <row topline="true">
37364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37367 \begin_layout Standard
37375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37378 \begin_layout Standard
37386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37389 \begin_layout Standard
37392 Pop the operand from the stack
37397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37400 \begin_layout Standard
37409 <row topline="true">
37410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37413 \begin_layout Standard
37421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37424 \begin_layout Standard
37427 IC_LEFT() IC_RESULT()
37432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37435 \begin_layout Standard
37438 Call the function represented by IC_LEFT
37443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37446 \begin_layout Standard
37449 IC_RESULT = IC_LEFT();
37455 <row topline="true">
37456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37459 \begin_layout Standard
37467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37470 \begin_layout Standard
37473 IC_LEFT() IC_RESULT()
37478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37481 \begin_layout Standard
37484 Call via function pointer
37489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37492 \begin_layout Standard
37495 IC_RESULT = (*IC_LEFT)();
37501 <row topline="true">
37502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37505 \begin_layout Standard
37513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37516 \begin_layout Standard
37524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37527 \begin_layout Standard
37530 Return the value in operand IC_LEFT
37535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37538 \begin_layout Standard
37547 <row topline="true">
37548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37551 \begin_layout Standard
37559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37562 \begin_layout Standard
37570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37573 \begin_layout Standard
37581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37584 \begin_layout Standard
37593 <row topline="true">
37594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37597 \begin_layout Standard
37605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37608 \begin_layout Standard
37616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37619 \begin_layout Standard
37627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37630 \begin_layout Standard
37639 <row topline="true">
37640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37643 \begin_layout Standard
37651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37654 \begin_layout Standard
37657 IC_LEFT() IC_RIGHT() IC_RESULT()
37662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37665 \begin_layout Standard
37673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37676 \begin_layout Standard
37679 IC_RESULT = IC_LEFT + IC_RIGHT
37685 <row topline="true">
37686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37689 \begin_layout Standard
37697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37700 \begin_layout Standard
37703 IC_LEFT() IC_RIGHT() IC_RESULT()
37708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37711 \begin_layout Standard
37719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37722 \begin_layout Standard
37725 IC_RESULT = IC_LEFT - IC_RIGHT
37731 <row topline="true">
37732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37735 \begin_layout Standard
37743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37746 \begin_layout Standard
37749 IC_LEFT() IC_RIGHT() IC_RESULT()
37754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37757 \begin_layout Standard
37765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37768 \begin_layout Standard
37771 IC_RESULT = IC_LEFT * IC_RIGHT;
37777 <row topline="true">
37778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37781 \begin_layout Standard
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37792 \begin_layout Standard
37795 IC_LEFT() IC_RIGHT() IC_RESULT()
37800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37803 \begin_layout Standard
37811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37814 \begin_layout Standard
37817 IC_RESULT = IC_LEFT / IC_RIGHT;
37823 <row topline="true">
37824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37827 \begin_layout Standard
37835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37838 \begin_layout Standard
37841 IC_LEFT() IC_RIGHT() IC_RESULT()
37846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37849 \begin_layout Standard
37857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37860 \begin_layout Standard
37863 IC_RESULT = IC_LEFT % IC_RIGHT;
37869 <row topline="true">
37870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37873 \begin_layout Standard
37881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37884 \begin_layout Standard
37887 IC_LEFT() IC_RIGHT() IC_RESULT()
37892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37895 \begin_layout Standard
37903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37906 \begin_layout Standard
37909 IC_RESULT = IC_LEFT < IC_RIGHT;
37915 <row topline="true">
37916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37919 \begin_layout Standard
37927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37930 \begin_layout Standard
37933 IC_LEFT() IC_RIGHT() IC_RESULT()
37938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37941 \begin_layout Standard
37949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37952 \begin_layout Standard
37955 IC_RESULT = IC_LEFT > IC_RIGHT;
37961 <row topline="true">
37962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37965 \begin_layout Standard
37973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37976 \begin_layout Standard
37979 IC_LEFT() IC_RIGHT() IC_RESULT()
37984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37987 \begin_layout Standard
37995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37998 \begin_layout Standard
38001 IC_RESULT = IC_LEFT == IC_RIGHT;
38007 <row topline="true">
38008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38011 \begin_layout Standard
38019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38022 \begin_layout Standard
38025 IC_LEFT() IC_RIGHT() IC_RESULT()
38030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38033 \begin_layout Standard
38036 Logical and operation
38041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38044 \begin_layout Standard
38047 IC_RESULT = IC_LEFT && IC_RIGHT;
38053 <row topline="true">
38054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38057 \begin_layout Standard
38065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38068 \begin_layout Standard
38071 IC_LEFT() IC_RIGHT() IC_RESULT()
38076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38079 \begin_layout Standard
38082 Logical or operation
38087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38090 \begin_layout Standard
38093 IC_RESULT = IC_LEFT || IC_RIGHT;
38099 <row topline="true">
38100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38103 \begin_layout Standard
38111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38114 \begin_layout Standard
38117 IC_LEFT() IC_RIGHT() IC_RESULT()
38122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38125 \begin_layout Standard
38133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38136 \begin_layout Standard
38139 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38145 <row topline="true">
38146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38149 \begin_layout Standard
38157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38160 \begin_layout Standard
38163 IC_LEFT() IC_RIGHT() IC_RESULT()
38168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38171 \begin_layout Standard
38179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38182 \begin_layout Standard
38185 IC_RESULT = IC_LEFT | IC_RIGHT;
38191 <row topline="true">
38192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38195 \begin_layout Standard
38203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38206 \begin_layout Standard
38209 IC_LEFT() IC_RIGHT() IC_RESULT()
38214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38217 \begin_layout Standard
38225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38228 \begin_layout Standard
38231 IC_RESULT = IC_LEFT & IC_RIGHT;
38237 <row topline="true">
38238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38241 \begin_layout Standard
38249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38252 \begin_layout Standard
38255 IC_LEFT() IC_RIGHT() IC_RESULT()
38260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38263 \begin_layout Standard
38271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38274 \begin_layout Standard
38277 IC_RESULT = IC_LEFT << IC_RIGHT
38283 <row topline="true">
38284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38287 \begin_layout Standard
38295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38298 \begin_layout Standard
38301 IC_LEFT() IC_RIGHT() IC_RESULT()
38306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38309 \begin_layout Standard
38317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38320 \begin_layout Standard
38323 IC_RESULT = IC_LEFT >> IC_RIGHT
38329 <row topline="true">
38330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38333 \begin_layout Standard
38343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38346 \begin_layout Standard
38349 IC_LEFT() IC_RESULT()
38354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38357 \begin_layout Standard
38365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38368 \begin_layout Standard
38371 IC_RESULT = (*IC_LEFT);
38377 <row topline="true">
38378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38381 \begin_layout Standard
38389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38392 \begin_layout Standard
38395 IC_RIGHT() IC_RESULT()
38400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38403 \begin_layout Standard
38411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38414 \begin_layout Standard
38417 (*IC_RESULT) = IC_RIGHT;
38423 <row topline="true">
38424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38427 \begin_layout Standard
38435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38438 \begin_layout Standard
38441 IC_RIGHT() IC_RESULT()
38446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38449 \begin_layout Standard
38457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38460 \begin_layout Standard
38463 IC_RESULT = IC_RIGHT;
38469 <row topline="true">
38470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38473 \begin_layout Standard
38481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38484 \begin_layout Standard
38487 IC_COND IC_TRUE IC_LABEL
38492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38495 \begin_layout Standard
38499 If true label is present then jump to true label if condition is true else
38500 jump to false label if condition is false
38505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38508 \begin_layout Standard
38511 if (IC_COND) goto IC_TRUE;
38517 If (!IC_COND) goto IC_FALSE;
38523 <row topline="true">
38524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38527 \begin_layout Standard
38535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38538 \begin_layout Standard
38541 IC_LEFT() IC_RESULT()
38546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38549 \begin_layout Standard
38557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38560 \begin_layout Standard
38563 IC_RESULT = &IC_LEFT();
38569 <row topline="true">
38570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38573 \begin_layout Standard
38581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38584 \begin_layout Standard
38587 IC_JTCOND IC_JTLABELS
38592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38595 \begin_layout Standard
38598 Jump to list of labels depending on the value of JTCOND
38603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38606 \begin_layout Standard
38615 <row topline="true">
38616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38619 \begin_layout Standard
38627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38630 \begin_layout Standard
38633 IC_RIGHT() IC_LEFT() IC_RESULT()
38638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38641 \begin_layout Standard
38649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38652 \begin_layout Standard
38655 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38661 <row topline="true">
38662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38665 \begin_layout Standard
38673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38676 \begin_layout Standard
38684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38687 \begin_layout Standard
38690 This is used for passing parameters in registers;
38692 move IC_LEFT to the next
38693 available parameter register.
38698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38701 \begin_layout Standard
38710 <row topline="true">
38711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38714 \begin_layout Standard
38722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38725 \begin_layout Standard
38733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38736 \begin_layout Standard
38739 This is used for receiving parameters passed in registers;
38742 in the next parameter register to IC_RESULT
38747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38750 \begin_layout Standard
38759 <row topline="true" bottomline="true">
38760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38763 \begin_layout Standard
38767 (some more have been added)
38772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38775 \begin_layout Standard
38781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38784 \begin_layout Standard
38790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38793 \begin_layout Standard
38817 \begin_layout Standard
38818 \begin_inset Note Note
38821 \begin_layout Standard
38822 In the original article Figure II was announced to be downloadable on
38827 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38835 \begin_layout Paragraph*
38837 \begin_inset LatexCommand \index{iCode}
38844 \begin_layout Standard
38845 This section shows some details of iCode.
38846 The example C code does not do anything useful; it is used as an example
38847 to illustrate the intermediate code generated by the compiler.
38850 \begin_layout Verse
38860 /* This function does nothing useful.
38867 for the purpose of explaining iCode */
38870 short function (data
38879 short i=10; \InsetSpace ~
38881 /* dead initialization eliminated */
38887 /* dead initialization eliminated */
38915 /* compiler detects i,j to be induction
38920 for (i = 0, j = 10 ; i < 10 ; i++, j
38926 \begin_layout Standard
38949 mul += i * 3; \InsetSpace ~
38951 /* this multiplication remains */
38958 j * 3;\InsetSpace ~
38960 /* this multiplication changed to addition */
38974 \begin_layout Standard
38975 In addition to the operands each iCode contains information about the filename
38976 and line it corresponds to in the source file.
38977 The first field in the listing should be interpreted as follows:
38982 Filename(linenumber: iCode Execution sequence number : ICode hash table
38983 key : loop depth of the iCode).
38988 Then follows the human readable form of the ICode operation.
38989 Each operand of this triplet form can be of three basic types a) compiler
38990 generated temporary b) user defined variable c) a constant value.
38991 Note that local variables and parameters are replaced by compiler generated
38994 \begin_inset LatexCommand \index{Live range analysis}
38998 are computed only for temporaries (i.e.
38999 live ranges are not computed for global variables).
39001 \begin_inset LatexCommand \index{Register allocation}
39005 are allocated for temporaries only.
39006 Operands are formatted in the following manner:
39011 Operand Name [lr live-from : live-to ] { type information } [ registers
39017 As mentioned earlier the live ranges are computed in terms of the execution
39018 sequence number of the iCodes, for example
39020 the iTemp0 is live from (i.e.
39021 first defined in iCode with execution sequence number 3, and is last used
39022 in the iCode with sequence number 5).
39023 For induction variables such as iTemp21 the live range computation extends
39024 the lifetime from the start to the end of the loop.
39026 The register allocator
39027 used the live range information to allocate registers, the same registers
39028 may be used for different temporaries if their live ranges do not overlap,
39029 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39030 ranges do not overlap.
39031 In addition the allocator also takes into consideration the type and usage
39032 of a temporary, for example itemp6 is a pointer to near space and is used
39033 as to fetch data from (i.e.
39034 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39035 Some short lived temporaries are allocated to special registers which have
39036 meaning to the code generator e.g.
39037 iTemp13 is allocated to a pseudo register CC which tells the back end that
39038 the temporary is used only for a conditional jump the code generation makes
39039 use of this information to optimize a compare and jump ICode.
39043 \begin_inset LatexCommand \index{Loop optimization}
39047 performed by the compiler.
39048 It can detect induction variables iTemp21(i) and iTemp23(j).
39049 Also note the compiler does selective strength reduction
39050 \begin_inset LatexCommand \index{Strength reduction}
39055 the multiplication of an induction variable in line 18 (gint = j * 3) is
39056 changed to addition, a new temporary iTemp17 is allocated and assigned
39057 a initial value, a constant 3 is then added for each iteration of the loop.
39058 The compiler does not change the multiplication
39059 \begin_inset LatexCommand \index{Multiplication}
39063 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39066 Note the dead code elimination
39067 \begin_inset LatexCommand \index{Dead-code elimination}
39071 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39077 \begin_layout Standard
39080 Sample.c (5:1:0:0) _entry($9) :
39083 \begin_layout Standard
39086 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39089 \begin_layout Standard
39092 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39095 \begin_layout Standard
39098 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39101 \begin_layout Standard
39104 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39108 \begin_layout Standard
39111 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39114 \begin_layout Standard
39117 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39121 \begin_layout Standard
39124 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39127 \begin_layout Standard
39130 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39134 \begin_layout Standard
39137 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39141 \begin_layout Standard
39144 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39148 \begin_layout Standard
39151 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39155 \begin_layout Standard
39158 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39159 * int}[r0] + 0x2 {short}
39162 \begin_layout Standard
39165 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39168 \begin_layout Standard
39171 Sample.c(11:17:21:0)_whilebreak_0($3) :
39174 \begin_layout Standard
39177 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39180 \begin_layout Standard
39183 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39186 \begin_layout Standard
39189 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39192 \begin_layout Standard
39195 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39198 \begin_layout Standard
39201 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39204 \begin_layout Standard
39207 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39210 \begin_layout Standard
39213 Sample.c(15:24:26:1)_forcond_0($4) :
39216 \begin_layout Standard
39219 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39223 \begin_layout Standard
39226 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39229 \begin_layout Standard
39232 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39233 + ITemp21 [lr21:38]{short}[r4]
39236 \begin_layout Standard
39239 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39243 \begin_layout Standard
39246 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39247 + iTemp15 [lr29:30]{short}[r1]
39250 \begin_layout Standard
39253 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39257 \begin_layout Standard
39260 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39264 \begin_layout Standard
39267 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39271 \begin_layout Standard
39274 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39278 \begin_layout Standard
39281 Sample.c(19:38:47:1) goto _forcond_0($4)
39284 \begin_layout Standard
39287 Sample.c(19:39:48:0)_forbreak_0($7) :
39290 \begin_layout Standard
39293 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39294 + ITemp11 [lr19:40]{short}[r3]
39297 \begin_layout Standard
39300 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39303 \begin_layout Standard
39306 Sample.c(20:42:51:0)_return($8) :
39309 \begin_layout Standard
39312 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39318 Finally the code generated for this function:
39323 \begin_layout Standard
39329 \begin_layout Standard
39335 \begin_layout Standard
39343 \begin_layout Standard
39349 \begin_layout Standard
39357 \begin_layout Standard
39363 \begin_layout Standard
39366 ; ----------------------------------------------
39369 \begin_layout Standard
39372 ; function function
39375 \begin_layout Standard
39378 ; ----------------------------------------------
39381 \begin_layout Standard
39387 \begin_layout Standard
39390 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39393 \begin_layout Standard
39401 \begin_layout Standard
39404 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39407 \begin_layout Standard
39415 \begin_layout Standard
39418 ;_whilecontinue_0($1) :
39421 \begin_layout Standard
39427 \begin_layout Standard
39430 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39433 \begin_layout Standard
39436 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39439 \begin_layout Standard
39447 \begin_layout Standard
39455 \begin_layout Standard
39463 \begin_layout Standard
39471 \begin_layout Standard
39479 \begin_layout Standard
39487 \begin_layout Standard
39495 \begin_layout Standard
39501 \begin_layout Standard
39504 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39507 \begin_layout Standard
39515 \begin_layout Standard
39523 \begin_layout Standard
39526 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39529 \begin_layout Standard
39537 \begin_layout Standard
39545 \begin_layout Standard
39553 \begin_layout Standard
39561 \begin_layout Standard
39569 \begin_layout Standard
39577 \begin_layout Standard
39580 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39583 \begin_layout Standard
39591 \begin_layout Standard
39599 \begin_layout Standard
39607 \begin_layout Standard
39615 \begin_layout Standard
39623 \begin_layout Standard
39626 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39629 \begin_layout Standard
39637 \begin_layout Standard
39645 \begin_layout Standard
39653 \begin_layout Standard
39656 ; iTemp6 [lr5:16]{_near * int}[r0] =
39659 \begin_layout Standard
39662 ; iTemp6 [lr5:16]{_near * int}[r0] +
39665 \begin_layout Standard
39671 \begin_layout Standard
39679 \begin_layout Standard
39682 ; goto _whilecontinue_0($1)
39685 \begin_layout Standard
39693 \begin_layout Standard
39696 ; _whilebreak_0($3) :
39699 \begin_layout Standard
39705 \begin_layout Standard
39708 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39711 \begin_layout Standard
39719 \begin_layout Standard
39722 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39725 \begin_layout Standard
39733 \begin_layout Standard
39736 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39739 \begin_layout Standard
39747 \begin_layout Standard
39750 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39753 \begin_layout Standard
39761 \begin_layout Standard
39769 \begin_layout Standard
39772 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39775 \begin_layout Standard
39783 \begin_layout Standard
39791 \begin_layout Standard
39797 \begin_layout Standard
39803 \begin_layout Standard
39806 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39809 \begin_layout Standard
39812 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39815 \begin_layout Standard
39823 \begin_layout Standard
39831 \begin_layout Standard
39839 \begin_layout Standard
39847 \begin_layout Standard
39855 \begin_layout Standard
39861 \begin_layout Standard
39864 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39867 \begin_layout Standard
39870 ; iTemp21 [lr21:38]{short}[r4]
39873 \begin_layout Standard
39881 \begin_layout Standard
39889 \begin_layout Standard
39897 \begin_layout Standard
39900 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39903 \begin_layout Standard
39911 \begin_layout Standard
39919 \begin_layout Standard
39927 \begin_layout Standard
39935 \begin_layout Standard
39938 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39941 \begin_layout Standard
39944 ; iTemp15 [lr29:30]{short}[r1]
39947 \begin_layout Standard
39955 \begin_layout Standard
39963 \begin_layout Standard
39966 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39969 \begin_layout Standard
39977 \begin_layout Standard
39985 \begin_layout Standard
39993 \begin_layout Standard
40001 \begin_layout Standard
40009 \begin_layout Standard
40017 \begin_layout Standard
40020 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40023 \begin_layout Standard
40031 \begin_layout Standard
40039 \begin_layout Standard
40047 \begin_layout Standard
40055 \begin_layout Standard
40063 \begin_layout Standard
40071 \begin_layout Standard
40074 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40077 \begin_layout Standard
40085 \begin_layout Standard
40088 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40091 \begin_layout Standard
40099 \begin_layout Standard
40104 cjne r5,#0xff,00104$
40107 \begin_layout Standard
40115 \begin_layout Standard
40118 ; goto _forcond_0($4)
40121 \begin_layout Standard
40129 \begin_layout Standard
40132 ; _forbreak_0($7) :
40135 \begin_layout Standard
40141 \begin_layout Standard
40144 ; ret iTemp24 [lr40:41]{short}
40147 \begin_layout Standard
40155 \begin_layout Standard
40163 \begin_layout Standard
40171 \begin_layout Standard
40177 \begin_layout Standard
40183 \begin_layout Standard
40193 \begin_layout Section
40194 A few words about basic block successors, predecessors and dominators
40197 \begin_layout Standard
40198 Successors are basic blocks
40199 \begin_inset LatexCommand \index{Basic blocks}
40203 that might execute after this basic block.
40205 Predecessors are basic blocks
40206 that might execute before reaching this basic block.
40208 Dominators are basic
40209 blocks that WILL execute before reaching this basic block.
40214 \begin_layout Standard
40218 \begin_layout Standard
40222 \begin_layout Standard
40230 \begin_layout Standard
40234 \begin_layout Standard
40242 \begin_layout Standard
40248 \begin_layout Standard
40249 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40252 \begin_layout Standard
40253 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40256 \begin_layout Standard
40257 c) domVect of [BB4] = BB1 ...
40258 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40262 \begin_layout Chapter
40266 \begin_layout Standard
40267 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40277 Thanks to all the other volunteer developers who have helped with coding,
40278 testing, web-page creation, distribution sets, etc.
40279 You know who you are :-)
40287 Thanks to Sourceforge
40288 \begin_inset LatexCommand \url{http://www.sf.net}
40292 which has hosted the project since 1999 and donates significant download
40301 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40302 cycles and bandwidth for snapshot builds.
40307 \begin_layout Standard
40308 This document was initially written by Sandeep Dutta
40311 \begin_layout Standard
40312 All product names mentioned herein may be trademarks
40313 \begin_inset LatexCommand \index{Trademarks}
40317 of their respective companies.
40321 \begin_layout Section*
40325 \begin_layout Standard
40326 To avoid confusion, the installation and building options for SDCC itself
40327 (chapter 2) are not part of the index.
40330 \begin_layout Standard
40331 \begin_inset LatexCommand \printindex{}