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
162 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167 designed for 8 bit Microprocessors.
168 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
170 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
174 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
175 Zilog Z80 based MCUs.
176 It can be retargeted for other microprocessors, support for Microchip PIC,
177 Atmel AVR is under development.
178 The entire source code for the compiler is distributed under GPL.
180 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185 \begin_inset LatexCommand \index{aslink}
189 , an open source retargetable assembler & linker.
190 SDCC has extensive language extensions suitable for utilizing various microcont
191 rollers and underlying hardware effectively.
195 In addition to the MCU specific
196 optimizations SDCC also does a host of standard optimizations like:
199 \begin_layout Itemize
200 global sub expression elimination,
203 \begin_layout Itemize
204 loop optimizations (loop invariant, strength reduction of induction variables
208 \begin_layout Itemize
209 constant folding & propagation,
212 \begin_layout Itemize
216 \begin_layout Itemize
217 dead code elimination
220 \begin_layout Itemize
228 \begin_layout Standard
229 For the back-end SDCC uses a global register allocation scheme which should
230 be well suited for other 8 bit MCUs.
234 The peep hole optimizer uses a rule
235 based substitution mechanism which is MCU independent.
243 \begin_layout Standard
245 <lyxtabular version="3" rows="8" columns="5">
247 <column alignment="center" valignment="top" leftline="true" width="0">
248 <column alignment="center" valignment="top" leftline="true" width="0">
249 <column alignment="center" valignment="top" leftline="true" width="0">
250 <column alignment="center" valignment="top" leftline="true" width="0">
251 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
252 <row topline="true" bottomline="true">
253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
256 \begin_layout Standard
262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
265 \begin_layout Standard
271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
274 \begin_layout Standard
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
283 \begin_layout Standard
289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_layout Standard
300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
303 \begin_layout Standard
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
312 \begin_layout Standard
318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
321 \begin_layout Standard
327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
330 \begin_layout Standard
336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
339 \begin_layout Standard
347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
350 \begin_layout Standard
356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
359 \begin_layout Standard
365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_layout Standard
374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
377 \begin_layout Standard
383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
386 \begin_layout Standard
394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
397 \begin_layout Standard
403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
406 \begin_layout Standard
412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
415 \begin_layout Standard
421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
424 \begin_layout Standard
430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
433 \begin_layout Standard
441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_layout Standard
450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
453 \begin_layout Standard
459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
462 \begin_layout Standard
468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
471 \begin_layout Standard
477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
480 \begin_layout Standard
487 <row topline="true" bottomline="true">
488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
491 \begin_layout Standard
497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
500 \begin_layout Standard
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
509 \begin_layout Standard
515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
518 \begin_layout Standard
519 -2.147.483.648, +2.147.483.647
524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
527 \begin_layout Standard
534 <row topline="true" bottomline="true">
535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
538 \begin_layout Standard
544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
547 \begin_layout Standard
553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
556 \begin_layout Standard
562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
565 \begin_layout Standard
571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
574 \begin_layout Standard
590 <row topline="true" bottomline="true">
591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
594 \begin_layout Standard
600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
603 \begin_layout Standard
609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
612 \begin_layout Standard
618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
621 \begin_layout Standard
627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
630 \begin_layout Standard
643 The compiler also allows
645 inline assembler code
647 to be embedded anywhere in a function.
648 In addition, routines developed in assembly can also be called.
653 provides an option (-
657 \begin_layout Standard
666 -cyclomatic) to report the relative complexity of a function.
667 These functions can then be further optimized, or hand coded in assembly
672 SDCC also comes with a companion source level debugger SDCDB.
673 The debugger currently uses ucSim, a free open source simulator for 8051
674 and other micro-controllers.
678 The latest SDCC version can be downloaded from
679 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
685 Please note: the compiler will probably always be some steps ahead of this
690 \begin_inset LatexCommand \index{Status of documentation}
698 \begin_layout Standard
699 Obviously this has pros and cons
707 \begin_layout Section
711 \begin_layout Standard
712 All packages used in this compiler system are
720 ; source code for all the sub-packages (pre-processor, assemblers, linkers
721 etc.) is distributed with the package.
722 This documentation is maintained using a free open source word processor
725 This program is free software; you can redistribute it and/or modify
726 it under the terms of the GNU General Public License
727 \begin_inset LatexCommand \index{GNU General Public License, GPL}
731 as published by the Free Software Foundation; either version 2, or (at
732 your option) any later version.
733 This program is distributed in the hope that it will be useful, but WITHOUT
734 ANY WARRANTY; without even the implied warranty
735 \begin_inset LatexCommand \index{warranty}
739 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
740 See the GNU General Public License for more details.
741 You should have received a copy of the GNU General Public License along
742 with this program; if not, write to the Free Software Foundation, 59 Temple
743 Place - Suite 330, Boston, MA 02111-1307, USA.
744 In other words, you are welcome to use, share and improve this program.
745 You are forbidden to forbid anyone else to use, share and improve what
747 Help stamp out software-hoarding!
750 \begin_layout Section
751 Typographic conventions
752 \begin_inset LatexCommand \index{Typographic conventions}
759 \begin_layout Standard
760 Throughout this manual, we will use the following convention.
761 Commands you have to type in are printed in
769 Code samples are printed in
774 Interesting items and new terms are printed in
779 \begin_layout Section
781 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
785 with previous versions
786 \begin_inset LatexCommand \index{Compatibility with previous versions}
793 \begin_layout Standard
794 Newer versions have usually numerous bug fixes compared with the previous
796 But we also sometimes introduce some incompatibilities with older versions.
797 Not just for the fun of it, but to make the compiler more stable, efficient
799 \begin_inset LatexCommand \index{ANSI-compliance}
804 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
808 for ANSI-Compliance).
809 \begin_inset Note Note
812 \begin_layout Standard
813 It would be fine to add to each item, in which version was it changed.
823 \begin_layout Itemize
824 short is now equivalent to int (16 bits), it used to be equivalent to char
825 (8 bits) which is not ANSI compliant.
826 To maintain compatibility, old programs may be compiled using the -
830 \begin_layout Standard
839 -short-is-8bits commandline option (see
840 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
847 \begin_layout Itemize
848 the default directory for gcc-builds where include, library and documentation
849 files are stored is now in /usr/local/share.
852 \begin_layout Itemize
853 char type parameters to vararg
854 \begin_inset LatexCommand \index{vararg, va\_arg}
858 functions are casted to int unless explicitly casted
859 \begin_inset Marginal
862 \begin_layout Standard
887 will push a as an int and as a char resp.
890 \begin_layout Itemize
895 \begin_layout Standard
904 -regextend has been removed.
907 \begin_layout Itemize
912 \begin_layout Standard
921 -noregparms has been removed.
924 \begin_layout Itemize
929 \begin_layout Standard
938 -stack-after-data has been removed.
941 \begin_layout Itemize
943 \begin_inset LatexCommand \index{bit}
948 \begin_inset LatexCommand \index{sbit}
953 \begin_inset LatexCommand \index{\_\_sbit}
957 types now consistently behave like the C99 _Bool type with respect to type
959 \begin_inset LatexCommand \index{type conversion}
964 \begin_inset LatexCommand \index{type promotion}
969 The most common incompatibility resulting from this change is related to
971 \begin_inset LatexCommand \index{Bit toggling}
986 \begin_inset LatexCommand \index{\~\/ Operator}
990 b; /* equivalent to b=1 instead of toggling b */
991 \begin_inset Marginal
994 \begin_layout Standard
1007 b = !b; /* toggles b */
1011 In previous versions, both forms would have toggled the bit.
1014 \begin_layout Standard
1017 <pending: more incompatibilities?>
1020 \begin_layout Section
1024 \begin_layout Standard
1025 What do you need before you start installation of SDCC? A computer, and
1026 a desire to compute.
1027 The preferred method of installation is to compile SDCC from source using
1029 For Windows some pre-compiled binary distributions are available for your
1031 You should have some experience with command line tools and compiler use.
1034 \begin_layout Section
1038 \begin_layout Standard
1039 The SDCC home page at
1040 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1044 is a great place to find distribution sets.
1045 You can also find links to the user mailing lists that offer help or discuss
1046 SDCC with other SDCC users.
1047 Web links to other SDCC related sites can also be found here.
1048 This document can be found in the DOC directory of the source package as
1049 a text or HTML file.
1050 A pdf version of this document is available at
1051 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1056 Some of the other tools (simulator and assembler) included with SDCC contain
1057 their own documentation and can be found in the source distribution.
1058 If you want the latest unreleased software, the complete source package
1059 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1063 \begin_layout Section
1064 Wishes for the future
1067 \begin_layout Standard
1068 There are (and always will be) some things that could be done.
1069 Here are some I can think of:
1074 \begin_layout Standard
1077 char KernelFunction3(char p) at 0x340;
1082 \begin_layout Standard
1086 \begin_inset LatexCommand \index{code banking (limited support)}
1096 If you can think of some more, please see the section
1097 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1101 about filing feature requests
1102 \begin_inset LatexCommand \index{Requesting features}
1107 \begin_inset LatexCommand \index{Feature request}
1116 \begin_layout Chapter
1118 \begin_inset LatexCommand \index{Installation}
1125 \begin_layout Standard
1126 For most users it is sufficient to skip to either section
1127 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1132 \begin_inset LatexCommand \ref{sub:Windows-Install}
1137 More detailed instructions follow below.
1140 \begin_layout Section
1142 \begin_inset LatexCommand \index{Options SDCC configuration}
1149 \begin_layout Standard
1150 The install paths, search paths and other options are defined when running
1152 The defaults can be overridden by:
1156 \labelwidthstring 00.00.0000
1161 \begin_layout Standard
1170 -prefix see table below
1174 \labelwidthstring 00.00.0000
1179 \begin_layout Standard
1188 -exec_prefix see table below
1192 \labelwidthstring 00.00.0000
1197 \begin_layout Standard
1206 -bindir see table below
1210 \labelwidthstring 00.00.0000
1215 \begin_layout Standard
1224 -datadir see table below
1228 \labelwidthstring 00.00.0000
1233 \begin_layout Standard
1242 -datarootdir see table below
1248 \labelwidthstring 00.00.0000
1251 docdir environment variable, see table below
1255 \labelwidthstring 00.00.0000
1258 include_dir_suffix environment variable, see table below
1262 \labelwidthstring 00.00.0000
1265 lib_dir_suffix environment variable, see table below
1269 \labelwidthstring 00.00.0000
1272 sdccconf_h_dir_separator environment variable, either / or
1277 This character will only be used in sdccconf.h; don't forget it's a C-header,
1278 therefore a double-backslash is needed there.
1284 \labelwidthstring 00.00.0000
1289 \begin_layout Standard
1298 -disable-mcs51-port Excludes the Intel mcs51 port
1302 \labelwidthstring 00.00.0000
1307 \begin_layout Standard
1316 -disable-gbz80-port Excludes the Gameboy gbz80 port
1320 \labelwidthstring 00.00.0000
1325 \begin_layout Standard
1334 -disable-z80-port Excludes the z80 port
1338 \labelwidthstring 00.00.0000
1343 \begin_layout Standard
1352 -disable-avr-port Excludes the AVR port
1356 \labelwidthstring 00.00.0000
1361 \begin_layout Standard
1370 -disable-ds390-port Excludes the DS390 port
1374 \labelwidthstring 00.00.0000
1379 \begin_layout Standard
1388 -disable-hc08-port Excludes the HC08 port
1392 \labelwidthstring 00.00.0000
1397 \begin_layout Standard
1406 -disable-pic-port Excludes the PIC14 port
1410 \labelwidthstring 00.00.0000
1415 \begin_layout Standard
1424 -disable-pic16-port Excludes the PIC16 port
1428 \labelwidthstring 00.00.0000
1433 \begin_layout Standard
1442 -disable-xa51-port Excludes the XA51 port
1446 \labelwidthstring 00.00.0000
1451 \begin_layout Standard
1460 -disable-ucsim Disables configuring and building of ucsim
1464 \labelwidthstring 00.00.0000
1469 \begin_layout Standard
1478 -disable-device-lib Disables automatically building device libraries
1482 \labelwidthstring 00.00.0000
1487 \begin_layout Standard
1496 -disable-packihx Disables building packihx
1502 \labelwidthstring 00.00.0000
1507 \begin_layout Standard
1516 -enable-doc Build pdf, html and txt files from the lyx sources
1520 \labelwidthstring 00.00.0000
1525 \begin_layout Standard
1534 -enable-libgc Use the Bohem memory allocator.
1535 Lower runtime footprint.
1538 \begin_layout Standard
1539 Furthermore the environment variables CC, CFLAGS, ...
1540 the tools and their arguments can be influenced.
1541 Please see `configure -
1545 \begin_layout Standard
1554 -help' and the man/info pages of `configure' for details.
1559 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1560 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1561 SDCC_LIB_NAME are defined by `configure' too.
1562 At the moment it's not possible to change the default settings (it was
1563 simply never required).
1567 These configure options are compiled into the binaries,
1568 and can only be changed by rerunning 'configure' and recompiling SDCC.
1569 The configure options are written in
1573 to distinguish them from run time environment variables (see section search
1579 \begin_inset Quotes sld
1583 \begin_inset Quotes srd
1586 are used by the SDCC team to build the official Win32 binaries.
1587 The SDCC team uses Mingw32 to build the official Windows binaries, because
1591 \begin_layout Enumerate
1595 \begin_layout Enumerate
1596 a gcc compiler and last but not least
1599 \begin_layout Enumerate
1600 the binaries can be built by cross compiling on SDCC Distributed Compile
1604 \begin_layout Standard
1605 See the examples, how to pass the Win32 settings to 'configure'.
1606 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1607 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1617 \begin_layout Standard
1619 \begin_inset Tabular
1620 <lyxtabular version="3" rows="9" columns="3">
1622 <column alignment="block" valignment="top" leftline="true" width="0in">
1623 <column alignment="block" valignment="top" leftline="true" width="0in">
1624 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1625 <row topline="true" bottomline="true">
1626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1629 \begin_layout Standard
1635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1638 \begin_layout Standard
1644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1647 \begin_layout Standard
1654 <row topline="true">
1655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1658 \begin_layout Standard
1666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1669 \begin_layout Standard
1675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1678 \begin_layout Standard
1687 <row topline="true">
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1691 \begin_layout Standard
1699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_layout Standard
1710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1713 \begin_layout Standard
1722 <row topline="true">
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1726 \begin_layout Standard
1734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 \begin_layout Standard
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1750 \begin_layout Standard
1763 <row topline="true">
1764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1767 \begin_layout Standard
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1778 \begin_layout Standard
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1789 \begin_layout Standard
1798 <row topline="true">
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1802 \begin_layout Standard
1810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1813 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1826 \begin_layout Standard
1835 <row topline="true">
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1839 \begin_layout Standard
1847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1863 \begin_layout Standard
1876 <row topline="true">
1877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1880 \begin_layout Standard
1888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1891 \begin_layout Standard
1897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1900 \begin_layout Standard
1907 <row topline="true" bottomline="true">
1908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1911 \begin_layout Standard
1919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1922 \begin_layout Standard
1928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1931 \begin_layout Standard
1947 \begin_layout Standard
1949 'configure' also computes relative paths.
1950 This is needed for full relocatability of a binary package and to complete
1951 search paths (see section search paths below):
1956 \begin_layout Standard
1958 \begin_inset Tabular
1959 <lyxtabular version="3" rows="4" columns="3">
1961 <column alignment="block" valignment="top" leftline="true" width="0in">
1962 <column alignment="block" valignment="top" leftline="true" width="0in">
1963 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1964 <row topline="true" bottomline="true">
1965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1968 \begin_layout Standard
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1977 \begin_layout Standard
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1986 \begin_layout Standard
1993 <row topline="true" bottomline="true">
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_layout Standard
2005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 \begin_layout Standard
2014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2017 \begin_layout Standard
2024 <row bottomline="true">
2025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2028 \begin_layout Standard
2036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2039 \begin_layout Standard
2045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2048 \begin_layout Standard
2055 <row bottomline="true">
2056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2059 \begin_layout Standard
2067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2070 \begin_layout Standard
2076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2079 \begin_layout Standard
2095 \begin_layout Standard
2100 \begin_layout LyX-Code
2107 \begin_layout Standard
2117 \begin_inset Quotes srd
2121 \begin_inset Quotes srd
2128 \begin_layout Standard
2138 \begin_inset Quotes srd
2142 \begin_inset Quotes srd
2151 \begin_layout Standard
2164 \begin_layout Standard
2176 \begin_layout Standard
2177 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2181 \begin_layout LyX-Code
2187 \begin_inset Quotes srd
2190 i586-mingw32msvc-gcc
2191 \begin_inset Quotes srd
2195 \begin_inset Quotes srd
2198 i586-mingw32msvc-g++
2199 \begin_inset Quotes srd
2207 \begin_inset Quotes srd
2210 i586-mingw32msvc-ranlib
2211 \begin_inset Quotes srd
2219 \begin_inset Quotes srd
2222 i586-mingw32msvc-strip
2223 \begin_inset Quotes srd
2234 \begin_layout Standard
2244 \begin_inset Quotes srd
2248 \begin_inset Quotes srd
2259 \begin_layout Standard
2269 \begin_inset Quotes srd
2273 \begin_inset Quotes srd
2281 \begin_inset Quotes srd
2287 \begin_inset Quotes srd
2295 \begin_inset Quotes srd
2299 \begin_inset Quotes srd
2307 \begin_inset Quotes srd
2311 \begin_inset Quotes srd
2318 sdccconf_h_dir_separator=
2319 \begin_inset Quotes srd
2331 \begin_inset Quotes srd
2342 \begin_layout Standard
2359 \begin_layout Standard
2368 -host=i586-mingw32msvc
2376 \begin_layout Standard
2385 -build=unknown-unknown-linux-gnu
2388 \begin_layout Standard
2390 \begin_inset Quotes sld
2394 \begin_inset Quotes srd
2397 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2401 \begin_layout LyX-Code
2410 \begin_layout Standard
2420 \begin_inset Quotes srd
2424 \begin_inset Quotes srd
2435 \begin_layout Standard
2445 \begin_inset Quotes srd
2449 \begin_inset Quotes srd
2457 \begin_inset Quotes srd
2463 \begin_inset Quotes srd
2471 \begin_inset Quotes srd
2475 \begin_inset Quotes srd
2483 \begin_inset Quotes srd
2487 \begin_inset Quotes srd
2494 sdccconf_h_dir_separator=
2495 \begin_inset Quotes srd
2507 \begin_inset Quotes srd
2515 \begin_inset Quotes srd
2519 \begin_inset Quotes srd
2527 \begin_inset Quotes srd
2531 \begin_inset Quotes srd
2537 \begin_layout Standard
2538 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2543 \begin_layout Standard
2552 -C' turns on caching, which gives a little bit extra speed.
2553 However if options are changed, it can be necessary to delete the config.cache
2557 \begin_layout Section
2559 \begin_inset LatexCommand \label{sub:Install-paths}
2564 \begin_inset LatexCommand \index{Install paths}
2571 \begin_layout Standard
2572 \begin_inset VSpace medskip
2578 \begin_layout Standard
2580 \begin_inset Tabular
2581 <lyxtabular version="3" rows="5" columns="4">
2583 <column alignment="left" valignment="top" leftline="true" width="0">
2584 <column alignment="left" valignment="top" leftline="true" width="0">
2585 <column alignment="left" valignment="top" leftline="true" width="0">
2586 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2587 <row topline="true" bottomline="true">
2588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2591 \begin_layout Standard
2599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2602 \begin_layout Standard
2610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2613 \begin_layout Standard
2621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2624 \begin_layout Standard
2633 <row topline="true">
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2637 \begin_layout Standard
2643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2646 \begin_layout Standard
2654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2657 \begin_layout Standard
2663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2666 \begin_layout Standard
2677 <row topline="true">
2678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2681 \begin_layout Standard
2687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2690 \begin_layout Standard
2693 $DATADIR/ $INCLUDE_DIR_SUFFIX
2698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2701 \begin_layout Standard
2702 /usr/local/share/sdcc/include
2707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2710 \begin_layout Standard
2721 <row topline="true">
2722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2725 \begin_layout Standard
2731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2734 \begin_layout Standard
2737 $DATADIR/$LIB_DIR_SUFFIX
2742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2745 \begin_layout Standard
2746 /usr/local/share/sdcc/lib
2751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2754 \begin_layout Standard
2765 <row topline="true" bottomline="true">
2766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2769 \begin_layout Standard
2775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2778 \begin_layout Standard
2786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2789 \begin_layout Standard
2790 /usr/local/share/sdcc/doc
2795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2798 \begin_layout Standard
2819 *compiler, preprocessor, assembler, and linker
2825 is auto-appended by the compiler, e.g.
2826 small, large, z80, ds390 etc
2829 \begin_layout Standard
2831 The install paths can still be changed during `make install' with e.g.:
2834 \begin_layout LyX-Code
2835 make install prefix=$(HOME)/local/sdcc
2838 \begin_layout Standard
2839 Of course this doesn't change the search paths compiled into the binaries.
2844 r the install path can be changed by defining DESTDIR
2845 \begin_inset LatexCommand \index{DESTDIR}
2852 \begin_layout LyX-Code
2853 make install DESTDIR=$(HOME)/sdcc.rpm/
2856 \begin_layout Standard
2857 Please note that DESTDIR must have a trailing slash!
2860 \begin_layout Section
2862 \begin_inset LatexCommand \label{sub:Search-Paths}
2867 \begin_inset LatexCommand \index{Search path}
2874 \begin_layout Standard
2875 Some search paths or parts of them are determined by configure variables
2880 , see section above).
2881 Further search paths are determined by environment variables during runtime.
2884 paths searched when running the compiler are as follows (the first catch
2890 Binary files (preprocessor, assembler and linker)
2895 \begin_layout Standard
2897 \begin_inset Tabular
2898 <lyxtabular version="3" rows="4" columns="3">
2900 <column alignment="block" valignment="top" leftline="true" width="0in">
2901 <column alignment="block" valignment="top" leftline="true" width="0in">
2902 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2903 <row topline="true" bottomline="true">
2904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2907 \begin_layout Standard
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2916 \begin_layout Standard
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2925 \begin_layout Standard
2932 <row topline="true">
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2936 \begin_layout Standard
2944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2947 \begin_layout Standard
2953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2956 \begin_layout Standard
2965 <row topline="true">
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2969 \begin_layout Standard
2970 Path of argv[0] (if available)
2975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2978 \begin_layout Standard
2984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2987 \begin_layout Standard
2994 <row topline="true" bottomline="true">
2995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2998 \begin_layout Standard
3004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3007 \begin_layout Standard
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3016 \begin_layout Standard
3032 \begin_layout Standard
3040 \begin_layout Standard
3042 \begin_inset Tabular
3043 <lyxtabular version="3" rows="6" columns="3">
3045 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3046 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3047 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3048 <row topline="true" bottomline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_layout Standard
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_layout Standard
3067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3070 \begin_layout Standard
3077 <row topline="true">
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3081 \begin_layout Standard
3086 \begin_layout Standard
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_layout Standard
3108 \begin_layout Standard
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3125 \begin_layout Standard
3130 \begin_layout Standard
3145 <row topline="true">
3146 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3149 \begin_layout Standard
3155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3158 \begin_layout Standard
3164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3167 \begin_layout Standard
3174 <row topline="true">
3175 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3178 \begin_layout Standard
3190 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3193 \begin_layout Standard
3203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3206 \begin_layout Standard
3215 <row topline="true">
3216 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3219 \begin_layout Standard
3235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3238 \begin_layout Standard
3286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3289 \begin_layout Standard
3300 <row topline="true" bottomline="true">
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3304 \begin_layout Standard
3318 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3322 /usr/local/share/sdcc/
3329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3332 \begin_layout Standard
3348 \begin_layout Standard
3354 \begin_layout Standard
3363 -nostdinc disables the last two search paths.
3373 \begin_layout Standard
3374 With the exception of
3375 \begin_inset Quotes sld
3382 \begin_layout Standard
3392 \begin_inset Quotes srd
3399 is auto-appended by the compiler (e.g.
3400 small, large, z80, ds390 etc.).
3405 \begin_layout Standard
3407 \begin_inset Tabular
3408 <lyxtabular version="3" rows="6" columns="3">
3410 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3411 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3412 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3413 <row topline="true" bottomline="true">
3414 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3417 \begin_layout Standard
3423 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3435 \begin_layout Standard
3442 <row topline="true">
3443 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3446 \begin_layout Standard
3451 \begin_layout Standard
3465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3468 \begin_layout Standard
3473 \begin_layout Standard
3487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3490 \begin_layout Standard
3495 \begin_layout Standard
3510 <row topline="true">
3511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3514 \begin_layout Standard
3524 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3527 \begin_layout Standard
3537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3540 \begin_layout Standard
3553 <row topline="true">
3554 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3557 \begin_layout Standard
3564 $LIB_DIR_SUFFIX/<model>
3569 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3572 \begin_layout Standard
3584 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3587 \begin_layout Standard
3602 <row topline="true">
3603 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3606 \begin_layout Standard
3617 $LIB_DIR_SUFFIX/<model>
3622 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3625 \begin_layout Standard
3676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3679 \begin_layout Standard
3733 <row topline="true" bottomline="true">
3734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3737 \begin_layout Standard
3742 $LIB_DIR_SUFFIX/<model>
3747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3750 \begin_layout Standard
3751 /usr/local/share/sdcc/
3760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3763 \begin_layout Standard
3779 \begin_layout Standard
3780 \begin_inset Note Note
3783 \begin_layout Standard
3784 Don't delete any of the stray spaces in the table above without checking
3785 the HTML output (last line)!
3793 \begin_layout Standard
3801 \begin_layout Standard
3810 -nostdlib disables the last two search paths.
3813 \begin_layout Section
3815 \begin_inset LatexCommand \index{Building SDCC}
3822 \begin_layout Subsection
3823 Building SDCC on Linux
3824 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3831 \begin_layout Enumerate
3834 Download the source package
3836 either from the SDCC Subversion repository or from snapshot builds
3838 , it will be named something like sdcc
3849 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3856 \begin_layout Enumerate
3859 Bring up a command line terminal, such as xterm.
3862 \begin_layout Enumerate
3865 Unpack the file using a command like:
3868 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3869 \begin_inset Quotes srd
3875 , this will create a sub-directory called sdcc with all of the sources.
3878 \begin_layout Enumerate
3879 Change directory into the main SDCC directory, for example type:
3887 \begin_layout Enumerate
3897 This configures the package for compilation on your system.
3900 \begin_layout Enumerate
3914 All of the source packages will compile, this can take a while.
3917 \begin_layout Enumerate
3931 This copies the binary executables, the include files, the libraries and
3932 the documentation to the install directories.
3933 Proceed with section
3934 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3941 \begin_layout Subsection
3942 Building SDCC on Mac OS X
3945 \begin_layout Standard
3946 Follow the instruction for Linux.
3950 On Mac OS X 10.2.x it was reported, that the
3951 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3952 Fortunately there's also gcc 2.9.x installed, which works fine.
3953 This compiler can be selected by running 'configure' with:
3956 \begin_layout LyX-Code
3957 ./configure CC=gcc2 CXX=g++2
3960 \begin_layout Standard
3961 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
3963 Run 'configure' with:
3966 \begin_layout LyX-Code
3972 \begin_layout LyX-Code
3973 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
3979 \begin_layout LyX-Code
3980 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
3986 \begin_layout LyX-Code
3987 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
3990 \begin_layout Subsection
3991 Cross compiling SDCC on Linux for Windows
3994 \begin_layout Standard
3995 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3996 See section 'Configure Options'.
3999 \begin_layout Subsection
4000 Building SDCC using Cygwin and Mingw32
4003 \begin_layout Standard
4004 For building and installing a Cygwin executable follow the instructions
4010 \begin_inset Quotes sld
4014 \begin_inset Quotes srd
4017 Win32-binary can be built, which will not need the Cygwin-DLL.
4018 For the necessary 'configure' options see section 'configure options' or
4019 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4024 Cygwin on Windows download setup.exe from
4025 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4031 \begin_inset Quotes sld
4034 default text file type
4035 \begin_inset Quotes srd
4039 \begin_inset Quotes sld
4043 \begin_inset Quotes srd
4046 and download/install at least the following packages.
4047 Some packages are selected by default, others will be automatically selected
4048 because of dependencies with the manually selected packages.
4049 Never deselect these packages!
4052 \begin_layout Itemize
4056 \begin_layout Itemize
4060 \begin_layout Itemize
4061 gcc ; version 3.x is fine, no need to use the old 2.9x
4064 \begin_layout Itemize
4065 binutils ; selected with gcc
4068 \begin_layout Itemize
4072 \begin_layout Itemize
4073 rxvt ; a nice console, which makes life much easier under windoze (see below)
4076 \begin_layout Itemize
4077 man ; not really needed for building SDCC, but you'll miss it sooner or
4081 \begin_layout Itemize
4082 less ; not really needed for building SDCC, but you'll miss it sooner or
4086 \begin_layout Itemize
4087 svn ; only if you use Subversion access
4090 \begin_layout Standard
4091 If you want to develop something you'll need:
4094 \begin_layout Itemize
4095 python ; for the regression tests
4098 \begin_layout Itemize
4099 gdb ; the gnu debugger, together with the nice GUI
4100 \begin_inset Quotes sld
4104 \begin_inset Quotes srd
4110 \begin_layout Itemize
4111 openssh ; to access the CF or commit changes
4114 \begin_layout Itemize
4115 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4116 use autoconf-stable!
4119 \begin_layout Standard
4120 rxvt is a nice console with history.
4121 Replace in your cygwin.bat the line
4124 \begin_layout LyX-Code
4129 \begin_layout Standard
4141 \begin_layout Standard
4145 \begin_layout LyX-Code
4146 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4149 \begin_layout LyX-Code
4150 -bg black -fg white -geometry 100x65 -e bash -
4154 \begin_layout Standard
4166 \begin_layout Standard
4167 Text selected with the mouse is automatically copied to the clipboard, pasting
4168 works with shift-insert.
4172 The other good tip is to make sure you have no //c/-styl
4173 e paths anywhere, use /cygdrive/c/ instead.
4174 Using // invokes a network lookup which is very slow.
4176 \begin_inset Quotes sld
4180 \begin_inset Quotes srd
4183 is too long, you can change it with e.g.
4186 \begin_layout LyX-Code
4190 \begin_layout Standard
4191 SDCC sources use the unix line ending LF.
4192 Life is much easier, if you store the source tree on a drive which is mounted
4194 And use an editor which can handle LF-only line endings.
4195 Make sure not to commit files with windows line endings.
4196 The tabulator spacing
4197 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4201 used in the project is 8.
4202 Although a tabulator spacing of 8 is a sensible choice for programmers
4203 (it's a power of 2 and allows to display 8/16 bit signed variables without
4204 loosing columns) the plan is to move towards using only spaces in the source.
4207 \begin_layout Subsection
4208 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4211 \begin_layout Standard
4214 Download the source package
4216 either from the SDCC Subversion repository or from the
4217 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4223 , it will be named something like sdcc
4227 -yyyymmdd-rrrr.tar.bz2.
4230 SDCC is distributed with all the projects, workspaces, and files you need
4231 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4232 The workspace name is 'sdcc.dsw'.
4233 Please note that as it is now, all the executables are created in a folder
4237 Once built you need to copy the executables from sdcc
4241 bin before running SDCC.
4245 WARNING: Visual studio is very picky with line terminatio
4246 ns; it expects the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix
4248 When using the Subversion repository it's easiest to configure the svn
4249 client to convert automatically for you.
4250 If however you are getting a message such as "This makefile was not generated
4251 by Developer Studio etc.
4253 \begin_inset Quotes srd
4256 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4257 need to convert the Unix style line endings to DOS style line endings.
4258 To do so you can use the
4259 \begin_inset Quotes sld
4263 \begin_inset Quotes srd
4266 utility freely available on the internet.
4267 Doug Hawkins reported in the sdcc-user list that this works:
4275 SDCC> unix2dos sdcc.dsw
4281 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4285 In order to build SDCC with MSVC
4286 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4287 One good place to get them is
4288 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4296 Download the file UnxUtils
4297 \begin_inset LatexCommand \index{UnxUtils}
4302 Now you have to install the utilities and setup MSVC so it can locate the
4304 Here there are two alternatives (choose one!):
4307 \begin_layout Enumerate
4312 a) Extract UnxUtils.zip to your C:
4314 hard disk PRESERVING the original paths, otherwise bison won't work.
4315 (If you are using WinZip make certain that 'Use folder names' is selected)
4320 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4321 'Show directories for:' select 'Executable files', and in the directories
4322 window add a new path: 'C:
4332 (As a side effect, you get a bunch of Unix utilities that
4333 could be useful, such as diff and patch.)
4336 \begin_layout Enumerate
4341 This one avoids extracting a bunch of files you may not
4342 use, but requires some extra work:
4346 a) Create a directory were to put the
4347 tools needed, or use a directory already present.
4354 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4355 gawk.exe to such directory WITHOUT preserving the original paths.
4356 (If you are using WinZip make certain that 'Use folder names' is not selected)
4361 ) Rename bison.exe to '_bison.exe'.
4365 d) Create a batch file 'bison.bat' in 'C:
4369 ' and add these lines:
4389 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4393 Steps 'c' and 'd' are needed
4394 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4395 reside in some weird Unix directory, '/usr/local/share/' I think.
4396 So it is necessary to tell bison where those files are located if they
4397 are not in such directory.
4398 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4403 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4404 in 'Show directories for:' select 'Executable files', and in the directories
4405 window add a new path: 'c:
4408 Note that you can use any other path instead of 'c:
4410 util', even the path where the Visual C++ tools are, probably: 'C:
4414 Microsoft Visual Studio
4419 So you don't have to execute step 'e' :)
4422 \begin_layout Standard
4424 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4425 the executables from sdcc
4429 bin, and you can compile using SDCC.
4432 \begin_layout Subsection
4433 Building SDCC Using Borland
4436 \begin_layout Enumerate
4437 From the sdcc directory, run the command "make -f Makefile.bcc".
4438 This should regenerate all the .exe files in the bin directory except for
4442 \begin_layout Enumerate
4443 If you modify any source files and need to rebuild, be aware that the dependenci
4444 es may not be correctly calculated.
4445 The safest option is to delete all .obj files and run the build again.
4446 From a Cygwin BASH prompt, this can easily be done with the command (be
4447 sure you are in the sdcc directory):
4456 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4458 ) -print -exec rm {}
4467 or on Windows NT/2000/XP from the command prompt with the command:
4474 del /s *.obj *.lib *.rul
4477 from the sdcc directory.
4480 \begin_layout Subsection
4481 Windows Install Using a ZIP Package
4484 \begin_layout Enumerate
4485 Download the binary zip package from
4486 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4490 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4491 This should unpack to a group of sub-directories.
4492 An example directory structure after unpacking the mingw32 package is:
4497 bin for the executables, c:
4505 lib for the include and libraries.
4508 \begin_layout Enumerate
4509 Adjust your environment variable PATH to include the location of the bin
4510 directory or start sdcc using the full path.
4513 \begin_layout Subsection
4514 Windows Install Using the Setup Program
4515 \begin_inset LatexCommand \label{sub:Windows-Install}
4522 \begin_layout Standard
4523 Download the setup program
4525 sdcc-x.y.z-setup.exe
4527 for an official release from
4530 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4534 or a setup program for one of the snapshots
4536 sdcc-yyyymmdd-xxxx-setup.exe
4539 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4544 A windows typical installer will guide you through the installation process.
4547 \begin_layout Subsection
4549 \begin_inset LatexCommand \index{VPATH}
4556 \begin_layout Standard
4557 SDCC supports the VPATH feature provided by configure and make.
4558 It allows to separate the source and build trees.
4562 \begin_layout Standard
4589 \begin_layout Standard
4592 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4593 # extract source to directory sdcc
4596 \begin_layout Standard
4599 mkdir sdcc.build\InsetSpace ~
4608 # put output in sdcc.build
4611 \begin_layout Standard
4617 \begin_layout Standard
4620 ../sdcc/configure\InsetSpace ~
4628 # configure is doing all the magic!
4631 \begin_layout Standard
4637 \begin_layout Standard
4643 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4644 It automagically computes the variables srcdir, top_srcdir and top_buildir
4650 the generated files will be in ~/sdcc.build, while the source files stay
4653 This is not only usefull for building different binaries, e.g.
4654 when cross compiling.
4655 It also gives you a much better overview in the source tree when all the
4656 generated files are not scattered between the source files.
4657 And the best thing is: if you want to change a file you can leave the original
4658 file untouched in the source directory.
4659 Simply copy it to the build directory, edit it, enter `make clean', `rm
4660 Makefile.dep' and `make'.
4664 will do the rest for you!
4667 \begin_layout Section
4668 Building the Documentation
4671 \begin_layout Standard
4676 \begin_layout Standard
4685 -enable-doc to the configure arguments to build the documentation together
4686 with all the other stuff.
4687 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4688 dvips and makeindex) to get the job done.
4689 Another possibility is to change to the doc directory and to type
4693 \begin_inset Quotes srd
4697 \begin_inset Quotes srd
4704 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4707 \begin_inset LatexCommand \url{http://www.lyx.org}
4711 as editor is straightforward.
4712 Prebuilt documentation in html and pdf format is available from
4713 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4720 \begin_layout Section
4721 Reading the Documentation
4722 \begin_inset LatexCommand \index{Documentation}
4729 \begin_layout Standard
4730 Currently reading the document in pdf format is recommended, as for unknown
4731 reason the hyperlinks are working there whereas in the html version they
4736 \begin_layout Standard
4737 If you should know why please drop us a note
4744 You'll find the pdf version
4745 \begin_inset LatexCommand \index{PDF version of this document}
4750 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4757 \begin_inset LatexCommand \index{HTML version of this document}
4762 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4768 This documentation is in some aspects different from a commercial documentation:
4771 \begin_layout Itemize
4772 It tries to document SDCC for several processor architectures in one document
4773 (commercially these probably would be separate documents/products).
4775 \begin_inset LatexCommand \index{Status of documentation}
4779 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4781 Z80, PIC14, PIC16 and HC08.
4784 \begin_layout Itemize
4785 There are many references pointing away from this documentation.
4786 Don't let this distract you.
4788 was a reference like
4789 \begin_inset LatexCommand \url{http://www.opencores.org}
4793 together with a statement
4794 \begin_inset Quotes sld
4797 some processors which are targetted by SDCC can be implemented in a
4814 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4819 \begin_inset Quotes srd
4823 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4828 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4833 \begin_inset Quotes sld
4836 have you ever heard of an open source compiler that compiles a subset of
4838 \begin_inset Quotes srd
4841 we expect you to have a quick look there and come back.
4842 If you read this you are on the right track.
4845 \begin_layout Itemize
4846 Some sections attribute more space to problems, restrictions and warnings
4847 than to the solution.
4850 \begin_layout Itemize
4851 The installation section and the section about the debugger is intimidating.
4854 \begin_layout Itemize
4855 There are still lots of typos and there are more different writing styles
4859 \begin_layout Section
4860 Testing the SDCC Compiler
4861 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4868 \begin_layout Standard
4869 The first thing you should do after installing your SDCC compiler is to
4878 \begin_layout Standard
4888 \begin_inset LatexCommand \index{version}
4895 at the prompt, and the program should run and output its version like:
4899 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4903 \begin_layout Standard
4904 If it doesn't run, or gives a message about not finding sdcc program, then
4905 you need to check over your installation.
4906 Make sure that the sdcc bin directory is in your executable search path
4907 defined by the PATH environment setting (
4912 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4919 Install trouble-shooting for suggestions
4922 Make sure that the sdcc program is in the bin folder, if not perhaps something
4923 did not install correctly.
4931 is commonly installed as described in section
4932 \begin_inset Quotes sld
4935 Install and search paths
4936 \begin_inset Quotes srd
4945 Make sure the compiler works on a very simple example.
4946 Type in the following test.c program using your favorite
4971 \begin_layout Standard
4974 Compile this using the following command:
4980 If all goes well, the compiler will generate a test.asm and test.rel file.
4981 Congratulations, you've just compiled your first program with SDCC.
4982 We used the -c option to tell SDCC not to link the generated code, just
4983 to keep things simple for this step.
4991 The next step is to try it with the linker.
5001 If all goes well the compiler will link with the libraries and produce
5002 a test.ihx output file.
5003 If this step fails(no test.ihx, and the linker generates warnings), then
5004 the problem is most likely that
5012 usr/local/share/sdcc/lib directory(see
5015 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5022 Install trouble-shooting for suggestions).
5030 The final test is to ensure
5038 header files and libraries.
5039 Edit test.c and change it to the following:
5057 strcpy(str1, "testing");
5062 \begin_layout Standard
5065 Compile this by typing
5072 This should generate a test.ihx output file, and it should give no warnings
5073 such as not finding the string.h file.
5074 If it cannot find the string.h file, then the problem is that
5078 cannot find the /usr/local/share/sdcc/include directory(see the
5081 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5088 Install trouble-shooting section for suggestions).
5097 \begin_layout Standard
5109 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5113 to find exactly where SDCC is looking for the include and lib files.
5116 \begin_layout Section
5117 Install Trouble-shooting
5118 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5123 \begin_inset LatexCommand \index{Install trouble-shooting}
5130 \begin_layout Subsection
5131 If SDCC does not build correctly
5134 \begin_layout Standard
5135 A thing to try is starting from scratch by unpacking the .tgz source package
5136 again in an empty directory.
5144 ./configure 2>&1 | tee configure.log
5158 make 2>&1 | tee make.log
5165 If anything goes wrong, you can review the log files to locate the problem.
5166 Or a relevant part of this can be attached to an email that could be helpful
5167 when requesting help from the mailing list.
5170 \begin_layout Subsection
5172 \begin_inset Quotes sld
5176 \begin_inset Quotes srd
5182 \begin_layout Standard
5184 \begin_inset Quotes sld
5188 \begin_inset Quotes srd
5191 command is a script that analyzes your system and performs some configuration
5192 to ensure the source package compiles on your system.
5193 It will take a few minutes to run, and will compile a few tests to determine
5194 what compiler features are installed.
5197 \begin_layout Subsection
5199 \begin_inset Quotes sld
5203 \begin_inset Quotes srd
5209 \begin_layout Standard
5210 This runs the GNU make tool, which automatically compiles all the source
5211 packages into the final installed binary executables.
5214 \begin_layout Subsection
5216 \begin_inset Quotes sld
5220 \begin_inset Quotes erd
5226 \begin_layout Standard
5227 This will install the compiler, other executables libraries and include
5228 files into the appropriate directories.
5230 \begin_inset LatexCommand \ref{sub:Install-paths}
5236 \begin_inset LatexCommand \ref{sub:Search-Paths}
5241 about install and search paths.
5243 On most systems you will need super-user privilege
5247 \begin_layout Section
5251 \begin_layout Standard
5252 SDCC is not just a compiler, but a collection of tools by various developers.
5253 These include linkers, assemblers, simulators and other components.
5254 Here is a summary of some of the components.
5255 Note that the included simulator and assembler have separate documentation
5256 which you can find in the source package in their respective directories.
5257 As SDCC grows to include support for other processors, other packages from
5258 various developers are included and may have their own sets of documentation.
5263 might want to look at the files which are installed in <installdir>.
5264 At the time of this writing, we find the following programs for gcc-builds:
5272 \begin_layout Itemize
5273 sdcc - The compiler.
5276 \begin_layout Itemize
5277 sdcpp - The C preprocessor.
5280 \begin_layout Itemize
5281 asx8051 - The assembler for 8051 type processors.
5284 \begin_layout Itemize
5289 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5292 \begin_layout Itemize
5293 aslink -The linker for 8051 type processors.
5296 \begin_layout Itemize
5301 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5304 \begin_layout Itemize
5305 s51 - The ucSim 8051 simulator.
5308 \begin_layout Itemize
5309 sdcdb - The source debugger.
5312 \begin_layout Itemize
5313 packihx - A tool to pack (compress) Intel hex files.
5316 \begin_layout Standard
5317 In <installdir>/share/sdcc/include
5320 \begin_layout Itemize
5324 \begin_layout Standard
5325 In <installdir>/share/sdcc/lib
5328 \begin_layout Itemize
5329 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5333 \begin_layout Standard
5334 In <installdir>/share/sdcc/doc
5337 \begin_layout Itemize
5341 \begin_layout Standard
5342 As development for other processors proceeds, this list will expand to include
5343 executables to support processors like AVR, PIC, etc.
5346 \begin_layout Subsection
5350 \begin_layout Standard
5351 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5352 the assembler and linkage editor.
5355 \begin_layout Subsection
5356 sdcpp - The C-Preprocessor
5359 \begin_layout Standard
5361 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5365 is a modified version of the GNU cpp
5366 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5371 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5376 The C preprocessor is used to pull in #include sources, process #ifdef
5377 statements, #defines and so on.
5380 \begin_layout Subsection
5389 - The Assemblers and Linkage Editors
5392 \begin_layout Standard
5393 This is retargettable assembler & linkage editor, it was developed by Alan
5395 John Hartman created the version for 8051, and I (Sandeep) have made some
5396 enhancements and bug fixes for it to work properly with SDCC.
5399 \begin_layout Subsection
5403 \begin_layout Standard
5405 \begin_inset LatexCommand \index{s51}
5409 is a free open source simulator developed by Daniel Drotos.
5410 The simulator is built as part of the build process.
5411 For more information visit Daniel's web site at:
5412 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5417 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5421 \begin_layout Subsection
5422 sdcdb - Source Level Debugger
5425 \begin_layout Standard
5427 \begin_inset LatexCommand \index{SDCDB (debugger)}
5431 is the companion source level debugger.
5432 More about SDCDB in section
5433 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5438 The current version of the debugger uses Daniel's Simulator S51
5439 \begin_inset LatexCommand \index{s51}
5443 , but can be easily changed to use other simulators.
5446 \begin_layout Chapter
5450 \begin_layout Section
5454 \begin_layout Subsection
5455 Single Source File Projects
5458 \begin_layout Standard
5459 For single source file 8051 projects the process is very simple.
5460 Compile your programs with the following command
5463 "sdcc sourcefile.c".
5467 This will compile, assemble and link your source file.
5468 Output files are as follows:
5471 \begin_layout Itemize
5473 \begin_inset LatexCommand \index{<file>.asm}
5478 \begin_inset LatexCommand \index{Assembler source}
5482 file created by the compiler
5485 \begin_layout Itemize
5487 \begin_inset LatexCommand \index{<file>.lst}
5492 \begin_inset LatexCommand \index{Assembler listing}
5496 file created by the Assembler
5499 \begin_layout Itemize
5501 \begin_inset LatexCommand \index{<file>.rst}
5506 \begin_inset LatexCommand \index{Assembler listing}
5510 file updated with linkedit information, created by linkage editor
5513 \begin_layout Itemize
5515 \begin_inset LatexCommand \index{<file>.sym}
5520 \begin_inset LatexCommand \index{Symbol listing}
5524 for the sourcefile, created by the assembler
5527 \begin_layout Itemize
5529 \begin_inset LatexCommand \index{<file>.rel}
5534 \begin_inset LatexCommand \index{<file>.o}
5539 \begin_inset LatexCommand \index{Object file}
5543 created by the assembler, input to Linkage editor
5546 \begin_layout Itemize
5548 \begin_inset LatexCommand \index{<file>.map}
5553 \begin_inset LatexCommand \index{Memory map}
5557 for the load module, created by the Linker
5560 \begin_layout Itemize
5562 \begin_inset LatexCommand \index{<file>.mem}
5566 - A file with a summary of the memory usage
5569 \begin_layout Itemize
5571 \begin_inset LatexCommand \index{<file>.ihx}
5575 - The load module in Intel hex format
5576 \begin_inset LatexCommand \index{Intel hex format}
5580 (you can select the Motorola S19 format
5581 \begin_inset LatexCommand \index{Motorola S19 format}
5589 \begin_layout Standard
5599 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5604 If you need another format you might want to use
5611 \begin_inset LatexCommand \index{objdump (tool)}
5622 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5627 \begin_inset Note Note
5630 \begin_layout Standard
5637 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5642 Both formats are documented in the documentation of srecord
5643 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5650 \begin_layout Itemize
5652 \begin_inset LatexCommand \index{<file>.adb}
5656 - An intermediate file containing debug information needed to create the
5661 \begin_layout Standard
5671 \begin_inset LatexCommand \index{-\/-debug}
5678 \begin_layout Itemize
5680 \begin_inset LatexCommand \index{<file>.cdb}
5684 - An optional file (with -
5688 \begin_layout Standard
5697 -debug) containing debug information.
5698 The format is documented in cdbfileformat.pdf
5701 \begin_layout Itemize
5704 \begin_inset LatexCommand \index{<file> (no extension)}
5708 An optional AOMF or AOMF51
5709 \begin_inset LatexCommand \index{AOMF, AOMF51}
5714 \begin_inset LatexCommand \label{OMF file}
5718 file containing debug information (generated with option -
5722 \begin_layout Standard
5748 ormat is a subformat of the OMF51 format and is commonly used by third party
5750 \begin_inset LatexCommand \index{Debugger}
5754 , simulators, emulators).
5757 \begin_layout Itemize
5759 \begin_inset LatexCommand \index{<file>.dump*}
5763 - Dump file to debug the compiler it self (generated with option -
5767 \begin_layout Standard
5776 -dumpall) (see section
5777 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5783 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5789 \begin_inset Quotes sld
5792 Anatomy of the compiler
5793 \begin_inset Quotes srd
5799 \begin_layout Subsection
5800 Postprocessing the Intel Hex
5801 \begin_inset LatexCommand \index{Intel hex format}
5806 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5813 \begin_layout Standard
5814 In most cases this won't be needed but the Intel Hex file
5815 \begin_inset LatexCommand \index{<file>.ihx}
5819 which is generated by SDCC might include lines of varying length and the
5820 addresses within the file are not guaranteed to be strictly ascending.
5821 If your toolchain or a bootloader does not like this you can use the tool
5826 \begin_inset LatexCommand \index{packihx (tool)}
5830 which is part of the SDCC distribution:
5837 packihx sourcefile.ihx >sourcefile.hex
5844 The separately available
5849 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5853 package additionally allows to set undefined locations to a predefined
5854 value, to insert checksums
5855 \begin_inset LatexCommand \index{checksum}
5859 of various flavours (crc, add, xor) and to perform other manipulations
5860 (convert, split, crop, offset, ...).
5867 srec_cat\InsetSpace ~
5869 sourcefile.ihx -intel\InsetSpace ~
5871 -o sourcefile.hex -intel
5878 An example for a more complex command line
5882 \begin_layout Standard
5883 the command backfills
5884 \begin_inset LatexCommand \index{backfill unused memory}
5888 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5890 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5891 will be interpreted as an
5899 (where an emergency routine could sit).
5912 srec_cat\InsetSpace ~
5913 sourcefile.ihx -intel\InsetSpace ~
5915 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5916 -little-endian-checksum-nega
5917 tive 0xfffe 0x02 0x02\InsetSpace ~
5919 -o sourcefile.hex -intel
5928 The srecord package is available at
5929 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5936 \begin_layout Subsection
5937 Projects with Multiple Source Files
5940 \begin_layout Standard
5941 SDCC can compile only ONE file at a time.
5942 Let us for example assume that you have a project containing the following
5947 foo1.c (contains some functions)
5949 foo2.c (contains some more functions)
5952 n.c (contains more functions and the function main)
5960 The first two files will need to be compiled separately with the commands:
5988 Then compile the source file containing the
5993 \begin_inset LatexCommand \index{Linker}
5997 the files together with the following command:
6005 foomain.c\InsetSpace ~
6006 foo1.rel\InsetSpace ~
6011 \begin_inset LatexCommand \index{<file>.rel}
6023 can be separately compiled as well:
6034 sdcc foomain.rel foo1.rel foo2.rel
6041 The file containing the
6053 file specified in the command line, since the linkage editor processes
6054 file in the order they are presented to it.
6055 The linker is invoked from SDCC using a script file with extension .lnk
6056 \begin_inset LatexCommand \index{<file>.lnk}
6061 You can view this file to troubleshoot linking problems such as those arising
6062 from missing libraries.
6065 \begin_layout Subsection
6066 Projects with Additional Libraries
6067 \begin_inset LatexCommand \index{Libraries}
6074 \begin_layout Standard
6075 Some reusable routines may be compiled into a library, see the documentation
6076 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6080 \begin_inset LatexCommand \index{<file>.lib}
6087 Libraries created in this manner can be included in the command line.
6088 Make sure you include the -L <library-path> option to tell the linker where
6089 to look for these files if they are not in the current directory.
6090 Here is an example, assuming you have the source file
6102 (if that is not the same as your current project):
6109 sdcc foomain.c foolib.lib -L mylib
6120 must be an absolute path name.
6124 The most efficient way to use libraries is
6125 to keep separate modules in separate source files.
6126 The lib file now should name all the modules.rel
6127 \begin_inset LatexCommand \index{<file>.rel}
6132 For an example see the standard library file
6136 in the directory <installdir>/share/lib/small.
6139 \begin_layout Subsection
6140 Using sdcclib to Create and Manage Libraries
6141 \begin_inset LatexCommand \index{sdcclib}
6148 \begin_layout Standard
6149 Alternatively, instead of having a .rel file for each entry on the library
6150 file as described in the preceding section, sdcclib can be used to embed
6151 all the modules belonging to such library in the library file itself.
6152 This results in a larger library file, but it greatly reduces the number
6153 of disk files accessed by the linker.
6154 Additionally, the packed library file contains an index of all include
6155 modules and symbols that significantly speeds up the linking process.
6156 To display a list of options supported by sdcclib type:
6161 \begin_layout Standard
6166 \begin_inset LatexCommand \index{sdcclib}
6177 To create a new library file, start by compiling all the required modules.
6183 \begin_layout Standard
6190 \begin_layout Standard
6197 \begin_layout Standard
6204 \begin_layout Standard
6211 \begin_layout Standard
6220 \begin_layout Standard
6221 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6223 The next step is to add the .rel files to the library file:
6228 \begin_layout Standard
6232 sdcclib libint.lib _divsint.rel
6235 \begin_inset LatexCommand \index{sdcclib}
6242 \begin_layout Standard
6246 sdcclib libint.lib _divuint.rel
6249 \begin_layout Standard
6253 sdcclib libint.lib _modsint.rel
6256 \begin_layout Standard
6260 sdcclib libint.lib _moduint.rel
6263 \begin_layout Standard
6267 sdcclib libint.lib _mulint.rel
6275 \begin_layout Standard
6284 \begin_layout Standard
6288 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6296 \begin_layout Standard
6297 If the file already exists in the library, it will be replaced.
6298 If a list of .rel files is available, you can tell sdcclib to add those
6300 For example, if the file 'myliblist.txt' contains
6308 \begin_layout Standard
6315 \begin_layout Standard
6322 \begin_layout Standard
6329 \begin_layout Standard
6336 \begin_layout Standard
6348 \begin_layout Standard
6357 \begin_layout Standard
6361 sdcclib -l libint.lib myliblist.txt
6369 \begin_layout Standard
6370 Additionally, you can instruct sdcclib to compiles the files before adding
6371 them to the library.
6372 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6381 \begin_layout Standard
6385 set SDCCLIB_CC=sdcc -c
6388 \begin_layout Standard
6392 sdcclib -l libint.lib myliblist.txt
6400 \begin_layout Standard
6401 To see what modules and symbols are included in the library, options -s
6402 and -m are available.
6410 sdcclib -s libint.lib
6413 \begin_inset LatexCommand \index{sdcclib}
6425 \begin_layout Standard
6431 \begin_layout Standard
6437 \begin_layout Standard
6445 \begin_layout Standard
6451 \begin_layout Standard
6457 \begin_layout Standard
6463 \begin_layout Standard
6469 \begin_layout Standard
6477 \begin_layout Standard
6483 \begin_layout Standard
6489 \begin_layout Standard
6497 \begin_layout Standard
6503 \begin_layout Standard
6509 \begin_layout Standard
6515 \begin_layout Standard
6523 \begin_layout Standard
6529 \begin_layout Standard
6540 \begin_layout Standard
6541 If the source files are compiled using -
6545 \begin_layout Standard
6555 \begin_inset LatexCommand \index{-\/-debug}
6559 , the corresponding debug information file .adb will be include in the library
6561 The library files created with sdcclib are plain text files, so they can
6562 be viewed with a text editor.
6563 It is not recomended to modify a library file created with sdcclib using
6564 a text editor, as there are file indexes numbers located accross the file
6565 used by the linker to quickly locate the required module to link.
6566 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6567 it can be safely deleted, since all the information required for linking
6568 is embedded in the library file itself.
6569 Library files created using sdcclib are used as described in the preceding
6571 \begin_inset VSpace bigskip
6577 \begin_layout Section
6578 Command Line Options
6579 \begin_inset LatexCommand \index{Command Line Options}
6584 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6591 \begin_layout Subsection
6592 Processor Selection Options
6593 \begin_inset LatexCommand \index{Options processor selection}
6598 \begin_inset LatexCommand \index{Processor selection options}
6606 \labelwidthstring 00.00.0000
6610 \begin_inset LatexCommand \index{-mmcs51}
6616 Generate code for the Intel MCS51
6617 \begin_inset LatexCommand \index{MCS51}
6621 family of processors.
6622 This is the default processor target.
6626 \labelwidthstring 00.00.0000
6630 \begin_inset LatexCommand \index{-mds390}
6636 Generate code for the Dallas DS80C390
6637 \begin_inset LatexCommand \index{DS80C390}
6645 \labelwidthstring 00.00.0000
6649 \begin_inset LatexCommand \index{-mds400}
6655 Generate code for the Dallas DS80C400
6656 \begin_inset LatexCommand \index{DS80C400}
6664 \labelwidthstring 00.00.0000
6668 \begin_inset LatexCommand \index{-mhc08}
6674 Generate code for the Freescale/Motorola HC08
6675 \begin_inset LatexCommand \index{HC08}
6679 family of processors.
6683 \labelwidthstring 00.00.0000
6687 \begin_inset LatexCommand \index{-mz80}
6693 Generate code for the Zilog Z80
6694 \begin_inset LatexCommand \index{Z80}
6698 family of processors.
6702 \labelwidthstring 00.00.0000
6706 \begin_inset LatexCommand \index{-mgbz80}
6712 Generate code for the GameBoy Z80
6713 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6717 processor (Not actively maintained).
6721 \labelwidthstring 00.00.0000
6725 \begin_inset LatexCommand \index{-mavr}
6731 Generate code for the Atmel AVR
6732 \begin_inset LatexCommand \index{AVR}
6736 processor (Not maintained, not complete).
6737 AVR users should probably have a look at winavr
6738 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6743 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6747 , which is based on AVR-port of the gcc compiler.
6750 \begin_layout Standard
6751 \begin_inset Note Note
6754 \begin_layout Standard
6755 I think it is fair to direct users there for now.
6756 Open source is also about avoiding unnecessary work .
6757 But I didn't find the 'official' link.
6766 \labelwidthstring 00.00.0000
6770 \begin_inset LatexCommand \index{-mpic14}
6776 Generate code for the Microchip PIC 14
6777 \begin_inset LatexCommand \index{PIC14}
6781 -bit processors (p16f84 and variants.
6782 In development, not complete).
6785 \begin_layout Standard
6786 \begin_inset Note Note
6789 \begin_layout Standard
6790 p16f627 p16f628 p16f84 p16f873 p16f877?
6799 \labelwidthstring 00.00.0000
6803 \begin_inset LatexCommand \index{-mpic16}
6809 Generate code for the Microchip PIC 16
6810 \begin_inset LatexCommand \index{PIC16}
6814 -bit processors (p18f452 and variants.
6815 In development, not complete).
6819 \labelwidthstring 00.00.0000
6824 Generate code for the Toshiba TLCS-900H
6825 \begin_inset LatexCommand \index{TLCS-900H}
6829 processor (Not maintained, not complete).
6833 \labelwidthstring 00.00.0000
6837 \begin_inset LatexCommand \index{-mxa51}
6843 Generate code for the Phillips XA51
6844 \begin_inset LatexCommand \index{XA51}
6848 processor (Not maintained, not complete).
6851 \begin_layout Standard
6852 \begin_inset VSpace bigskip
6858 \begin_layout Subsection
6859 Preprocessor Options
6860 \begin_inset LatexCommand \index{Options preprocessor}
6865 \begin_inset LatexCommand \index{Preprocessor options}
6870 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6878 \labelwidthstring 00.00.0000
6882 \begin_inset LatexCommand \index{-I<path>}
6888 The additional location where the preprocessor will look for <..h> or
6889 \begin_inset Quotes eld
6893 \begin_inset Quotes erd
6900 \labelwidthstring 00.00.0000
6904 \begin_inset LatexCommand \index{-D<macro[=value]>}
6910 Command line definition of macros.
6911 Passed to the preprocessor.
6915 \labelwidthstring 00.00.0000
6919 \begin_inset LatexCommand \index{-M}
6925 Tell the preprocessor to output a rule suitable for make describing the
6926 dependencies of each object file.
6927 For each source file, the preprocessor outputs one make-rule whose target
6928 is the object file name for that source file and whose dependencies are
6929 all the files `#include'd in it.
6930 This rule may be a single line or may be continued with `
6932 '-newline if it is long.
6933 The list of rules is printed on standard output instead of the preprocessed
6936 \begin_inset LatexCommand \index{-E}
6944 \labelwidthstring 00.00.0000
6948 \begin_inset LatexCommand \index{-C}
6954 Tell the preprocessor not to discard comments.
6955 Used with the `-E' option.
6959 \labelwidthstring 00.00.0000
6963 \begin_inset LatexCommand \index{-MM}
6969 Like `-M' but the output mentions only the user header files included with
6971 \begin_inset Quotes eld
6975 System header files included with `#include <file>' are omitted.
6979 \labelwidthstring 00.00.0000
6983 \begin_inset LatexCommand \index{-Aquestion(answer)}
6989 Assert the answer answer for question, in case it is tested with a preprocessor
6990 conditional such as `#if #question(answer)'.
6991 `-A-' disables the standard assertions that normally describe the target
6996 \labelwidthstring 00.00.0000
7000 \begin_inset LatexCommand \index{-Umacro}
7006 Undefine macro macro.
7007 `-U' options are evaluated after all `-D' options, but before any `-include'
7008 and `-imacros' options.
7012 \labelwidthstring 00.00.0000
7016 \begin_inset LatexCommand \index{-dM}
7022 Tell the preprocessor to output only a list of the macro definitions that
7023 are in effect at the end of preprocessing.
7024 Used with the `-E' option.
7028 \labelwidthstring 00.00.0000
7032 \begin_inset LatexCommand \index{-dD}
7038 Tell the preprocessor to pass all macro definitions into the output, in
7039 their proper sequence in the rest of the output.
7043 \labelwidthstring 00.00.0000
7047 \begin_inset LatexCommand \index{-dN}
7053 Like `-dD' except that the macro arguments and contents are omitted.
7054 Only `#define name' is included in the output.
7058 \labelwidthstring 00.00.0000
7061 -pedantic-parse-number
7062 \begin_inset LatexCommand \index{pedantic}
7067 \begin_inset LatexCommand \index{-pedantic-parse-number}
7075 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7083 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7084 and the macro LO_B(3) gets expanded.
7085 See also #pragma pedantic_parse_number
7086 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7091 \begin_inset LatexCommand \ref{sec:Pragmas}
7097 Note: this functionality is not in conformance with C99 standard!
7101 \labelwidthstring 00.00.0000
7105 preprocessorOption[,preprocessorOption]
7108 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7113 Pass the preprocessorOption to the preprocessor
7118 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7123 SDCC uses an adapted version of the preprocessor
7127 of the GNU Compiler Collection
7128 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7137 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7141 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7146 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7153 \begin_layout Standard
7154 \begin_inset VSpace bigskip
7160 \begin_layout Subsection
7162 \begin_inset LatexCommand \index{Options linker}
7167 \begin_inset LatexCommand \index{Linker options}
7175 \labelwidthstring 00.00.0000
7185 \begin_layout Standard
7197 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7202 \begin_inset LatexCommand \index{-L -\/-lib-path}
7209 <absolute path to additional libraries> This option is passed to the linkage
7210 editor's additional libraries
7211 \begin_inset LatexCommand \index{Libraries}
7216 The path name must be absolute.
7217 Additional library files may be specified in the command line.
7218 See section Compiling programs for more details.
7222 \labelwidthstring 00.00.0000
7229 \begin_layout Standard
7241 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7246 <Value> The start location of the external ram
7247 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7251 , default value is 0.
7252 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7256 \begin_layout Standard
7265 -xram-loc 0x8000 or -
7269 \begin_layout Standard
7282 \labelwidthstring 00.00.0000
7289 \begin_layout Standard
7301 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7306 <Value> The start location of the code
7307 \begin_inset LatexCommand \index{code}
7311 segment, default value 0.
7312 Note when this option is used the interrupt vector table
7313 \begin_inset LatexCommand \index{interrupt vector table}
7317 is also relocated to the given address.
7318 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7322 \begin_layout Standard
7331 -code-loc 0x8000 or -
7335 \begin_layout Standard
7348 \labelwidthstring 00.00.0000
7355 \begin_layout Standard
7367 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7372 <Value> By default the stack
7373 \begin_inset LatexCommand \index{stack}
7377 is placed after the data segment.
7378 Using this option the stack can be placed anywhere in the internal memory
7380 The value entered can be in Hexadecimal or Decimal format, e.g.
7385 \begin_layout Standard
7394 -stack-loc 0x20 or -
7398 \begin_layout Standard
7408 Since the sp register is incremented before a push or call, the initial
7409 sp will be set to one byte prior the provided value.
7410 The provided value should not overlap any other memory areas such as used
7411 register banks or the data segment and with enough space for the current
7419 \begin_layout Standard
7432 \begin_inset LatexCommand \index{-\/-pack-iram}
7436 option (which is now a default setting) will override this setting, so
7437 you should also specify the
7443 \begin_layout Standard
7456 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7460 option if you need to manually place the stack.
7464 \labelwidthstring 00.00.0000
7471 \begin_layout Standard
7483 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7488 <Value> By default the external stack
7489 \begin_inset LatexCommand \index{xstack}
7493 is placed after the pdata
7494 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7499 Using this option the xstack can be placed anywhere in the external memory
7501 The value entered can be in Hexadecimal or Decimal format, e.g.
7506 \begin_layout Standard
7515 -xstack-loc 0x8000 or -
7519 \begin_layout Standard
7529 The provided value should not overlap any other memory areas such as the
7530 pdata or xdata segment and with enough space for the current application.
7534 \labelwidthstring 00.00.0000
7541 \begin_layout Standard
7553 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7558 <Value> The start location of the internal ram data
7559 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7564 The value entered can be in Hexadecimal or Decimal format, eg.
7569 \begin_layout Standard
7582 \begin_layout Standard
7592 (By default, the start location of the internal ram data segment is set
7593 as low as possible in memory, taking into account the used register banks
7594 and the bit segment at address 0x20.
7595 For example if register banks 0 and 1 are used without bit variables, the
7596 data segment will be set, if -
7600 \begin_layout Standard
7609 -data-loc is not used, to location 0x10.)
7613 \labelwidthstring 00.00.0000
7620 \begin_layout Standard
7632 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7637 <Value> The start location of the indirectly addressable internal ram
7638 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7642 of the 8051, default value is 0x80.
7643 The value entered can be in Hexadecimal or Decimal format, eg.
7648 \begin_layout Standard
7657 -idata-loc 0x88 or -
7661 \begin_layout Standard
7674 \labelwidthstring 00.00.0000
7681 \begin_layout Standard
7693 <Value> The start location of the bit
7694 \begin_inset LatexCommand \index{bit}
7698 addressable internal ram of the 8051.
7704 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7709 \labelwidthstring 00.00.0000
7716 \begin_layout Standard
7726 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7732 The linker output (final object code) is in Intel Hex format.
7733 \begin_inset LatexCommand \index{Intel hex format}
7737 This is the default option.
7738 The format itself is documented in the documentation of srecord
7739 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7747 \labelwidthstring 00.00.0000
7754 \begin_layout Standard
7764 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7770 The linker output (final object code) is in Motorola S19 format
7771 \begin_inset LatexCommand \index{Motorola S19 format}
7776 The format itself is documented in the documentation of srecord.
7780 \labelwidthstring 00.00.0000
7787 \begin_layout Standard
7797 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7802 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7808 The linker output (final object code) is in ELF format
7809 \begin_inset LatexCommand \index{ELF format}
7814 (Currently only supported for the HC08
7815 \begin_inset LatexCommand \index{HC08}
7823 \labelwidthstring 00.00.0000
7827 linkOption[,linkOption]
7830 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7835 Pass the linkOption to the linker.
7836 If a bootloader is used an option like
7837 \begin_inset Quotes sld
7842 \begin_inset Quotes srd
7845 would be typical to set the start of the code segment.
7846 See also #pragma constseg and #pragma codeseg in section
7847 \begin_inset LatexCommand \ref{sec:Pragmas}
7852 File sdcc/as/doc/asxhtm.html has more on linker options.
7855 \begin_layout Standard
7856 \begin_inset VSpace bigskip
7862 \begin_layout Subsection
7864 \begin_inset LatexCommand \index{Options MCS51}
7869 \begin_inset LatexCommand \index{MCS51 options}
7877 \labelwidthstring 00.00.0000
7884 \begin_layout Standard
7894 \begin_inset LatexCommand \index{-\/-model-small}
7900 Generate code for Small Model programs, see section Memory Models for more
7902 This is the default model.
7906 \labelwidthstring 00.00.0000
7913 \begin_layout Standard
7923 \begin_inset LatexCommand \index{-\/-model-medium}
7929 Generate code for Medium model programs, see section Memory Models for
7931 If this option is used all source files in the project have to be compiled
7933 It must also be used when invoking the linker.
7937 \labelwidthstring 00.00.0000
7944 \begin_layout Standard
7954 \begin_inset LatexCommand \index{-\/-model-large}
7960 Generate code for Large model programs, see section Memory Models for more
7962 If this option is used all source files in the project have to be compiled
7964 It must also be used when invoking the linker.
7968 \labelwidthstring 00.00.0000
7975 \begin_layout Standard
7985 \begin_inset LatexCommand \index{-\/-xstack}
7991 Uses a pseudo stack in the pdata
7992 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7996 area (usually the first 256 bytes in the external ram) for allocating variables
7997 and passing parameters.
7999 \begin_inset LatexCommand \ref{sub:External-Stack}
8004 External Stack for more details.
8008 \labelwidthstring 00.00.0000
8015 \begin_layout Standard
8028 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8032 Causes the linker to check if the internal ram usage is within limits of
8037 \labelwidthstring 00.00.0000
8044 \begin_layout Standard
8057 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8061 Causes the linker to check if the external ram usage is within limits of
8066 \labelwidthstring 00.00.0000
8073 \begin_layout Standard
8086 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8090 Causes the linker to check if the code memory usage is within limits of
8095 \labelwidthstring 00.00.0000
8102 \begin_layout Standard
8115 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8119 Causes the linker to check if there is at minimum <Value> bytes for stack.
8123 \labelwidthstring 00.00.0000
8130 \begin_layout Standard
8143 \begin_inset LatexCommand \index{-\/-pack-iram}
8147 Causes the linker to use unused register banks for data variables and pack
8148 data, idata and stack together.
8149 This is the default now.
8153 \labelwidthstring 00.00.0000
8160 \begin_layout Standard
8173 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8177 Causes the linker to use old style for allocating memory areas.
8181 \labelwidthstring 00.00.0000
8188 \begin_layout Standard
8201 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8205 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8207 Only use this option if your code is in the same 2k block of memory.
8208 You may need to use this option for some 8051 derivatives which lack the
8209 lcall/ljmp instructions..
8212 \begin_layout Standard
8213 \begin_inset VSpace bigskip
8219 \begin_layout Subsection
8220 DS390 / DS400 Options
8221 \begin_inset LatexCommand \index{Options DS390}
8226 \begin_inset LatexCommand \index{DS390}
8234 \labelwidthstring 00.00.0000
8241 \begin_layout Standard
8253 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8257 Generate 24-bit flat mode code.
8258 This is the one and only that the ds390 code generator supports right now
8259 and is default when using
8264 See section Memory Models for more details.
8268 \labelwidthstring 00.00.0000
8275 \begin_layout Standard
8285 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8291 disable interrupts during ESP:SP updates.
8295 \labelwidthstring 00.00.0000
8302 \begin_layout Standard
8314 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8318 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8319 This is the one and only that the ds390 code generator supports right now
8320 and is default when using
8325 In this mode, the stack is located in the lower 1K of the internal RAM,
8326 which is mapped to 0x400000.
8327 Note that the support is incomplete, since it still uses a single byte
8328 as the stack pointer.
8329 This means that only the lower 256 bytes of the potential 1K stack space
8330 will actually be used.
8331 However, this does allow you to reclaim the precious 256 bytes of low RAM
8332 for use for the DATA and IDATA segments.
8333 The compiler will not generate any code to put the processor into 10 bit
8335 It is important to ensure that the processor is in this mode before calling
8336 any re-entrant functions compiled with this option.
8337 In principle, this should work with the
8343 \begin_layout Standard
8353 \begin_inset LatexCommand \index{-\/-stack-auto}
8359 option, but that has not been tested.
8360 It is incompatible with the
8366 \begin_layout Standard
8376 \begin_inset LatexCommand \index{-\/-xstack}
8383 It also only makes sense if the processor is in 24 bit contiguous addressing
8390 \begin_layout Standard
8399 -model-flat24 option
8404 \begin_inset Note Note
8408 \labelwidthstring 00.00.0000
8415 \begin_layout Standard
8424 -stack-8-bit - switches off the 10-bit mode
8433 \labelwidthstring 00.00.0000
8440 \begin_layout Standard
8450 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8456 insert call to function __stack_probe at each function prologue.
8460 \labelwidthstring 00.00.0000
8467 \begin_layout Standard
8477 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8483 <nnnn> LibraryID used in -mTININative.
8487 \labelwidthstring 00.00.0000
8494 \begin_layout Standard
8504 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8510 generate code for DS390 Arithmetic Accelerator.
8513 \begin_layout Standard
8514 \begin_inset VSpace bigskip
8520 \begin_layout Subsection
8522 \begin_inset LatexCommand \index{Options Z80}
8527 \begin_inset LatexCommand \index{Z80}
8535 \labelwidthstring 00.00.0000
8542 \begin_layout Standard
8554 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8558 Force a called function to always save BC.
8562 \labelwidthstring 00.00.0000
8569 \begin_layout Standard
8581 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8585 When linking, skip the standard crt0.o object file.
8586 You must provide your own crt0.o for your system when linking.
8590 \labelwidthstring 00.00.0000
8597 \begin_layout Standard
8609 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8613 Determinate PORT I/O mode (<Value> is z80 or z180).
8617 \labelwidthstring 00.00.0000
8624 \begin_layout Standard
8636 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8640 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8644 \labelwidthstring 00.00.0000
8651 \begin_layout Standard
8664 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8668 Use <Value> for the code segment name.
8672 \labelwidthstring 00.00.0000
8679 \begin_layout Standard
8692 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8696 Use <Value> for the const segment name.
8700 \labelwidthstring 00.00.0000
8701 \begin_inset VSpace bigskip
8707 \begin_layout Subsection
8709 \begin_inset LatexCommand \index{Options GBZ80}
8714 \begin_inset LatexCommand \index{GBZ80}
8722 \labelwidthstring 00.00.0000
8729 \begin_layout Standard
8741 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8745 Force a called function to always save BC.
8749 \labelwidthstring 00.00.0000
8756 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8760 Use code bank <Num>.
8764 \labelwidthstring 00.00.0000
8771 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8775 Use data bank <Num>.
8779 \labelwidthstring 00.00.0000
8786 \begin_layout Standard
8799 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8803 Use <Value> for the code segment name.
8807 \labelwidthstring 00.00.0000
8814 \begin_layout Standard
8827 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8831 Use <Value> for the const segment name.
8834 \begin_layout Standard
8835 \begin_inset VSpace bigskip
8841 \begin_layout Subsection
8842 Optimization Options
8843 \begin_inset LatexCommand \index{Options optimization}
8848 \begin_inset LatexCommand \index{Optimization options}
8856 \labelwidthstring 00.00.0000
8863 \begin_layout Standard
8873 \begin_inset LatexCommand \index{-\/-nogcse}
8879 Will not do global subexpression elimination, this option may be used when
8880 the compiler creates undesirably large stack/data spaces to store compiler
8890 \begin_inset LatexCommand \index{sloc (spill location)}
8895 A warning message will be generated when this happens and the compiler
8896 will indicate the number of extra bytes it allocated.
8897 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8899 \begin_inset LatexCommand \index{\#pragma nogcse}
8903 can be used to turn off global subexpression elimination
8904 \begin_inset LatexCommand \index{Subexpression elimination}
8908 for a given function only.
8912 \labelwidthstring 00.00.0000
8919 \begin_layout Standard
8929 \begin_inset LatexCommand \index{-\/-noinvariant}
8935 Will not do loop invariant optimizations, this may be turned off for reasons
8936 explained for the previous option.
8937 For more details of loop optimizations performed see Loop Invariants in
8939 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8944 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8946 \begin_inset LatexCommand \index{\#pragma noinvariant}
8950 can be used to turn off invariant optimizations for a given function only.
8954 \labelwidthstring 00.00.0000
8961 \begin_layout Standard
8971 \begin_inset LatexCommand \index{-\/-noinduction}
8977 Will not do loop induction optimizations, see section strength reduction
8979 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8981 \begin_inset LatexCommand \index{\#pragma noinduction}
8985 can be used to turn off induction optimizations for a given function only.
8989 \labelwidthstring 00.00.0000
8996 \begin_layout Standard
9006 \begin_inset LatexCommand \index{-\/-nojtbound}
9012 Will not generate boundary condition check when switch statements
9013 \begin_inset LatexCommand \index{switch statement}
9017 are implemented using jump-tables.
9019 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9024 Switch Statements for more details.
9025 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9027 \begin_inset LatexCommand \index{\#pragma nojtbound}
9031 can be used to turn off boundary checking for jump tables for a given function
9036 \labelwidthstring 00.00.0000
9043 \begin_layout Standard
9053 \begin_inset LatexCommand \index{-\/-noloopreverse}
9059 Will not do loop reversal
9060 \begin_inset LatexCommand \index{Loop reversing}
9068 \labelwidthstring 00.00.0000
9073 \begin_layout Standard
9087 \begin_inset LatexCommand \index{-\/-nolabelopt }
9091 Will not optimize labels (makes the dumpfiles more readable).
9095 \labelwidthstring 00.00.0000
9102 \begin_layout Standard
9112 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9118 Will not memcpy initialized data from code space into xdata space.
9119 This saves a few bytes in code space if you don't have initialized data
9120 \begin_inset LatexCommand \index{Variable initialization}
9128 \labelwidthstring 00.00.0000
9135 \begin_layout Standard
9145 \begin_inset LatexCommand \index{-\/-nooverlay}
9151 The compiler will not overlay parameters and local variables of any function,
9152 see section Parameters and local variables for more details.
9156 \labelwidthstring 00.00.0000
9163 \begin_layout Standard
9173 \begin_inset LatexCommand \index{-\/-no-peep}
9179 Disable peep-hole optimization with built-in rules.
9183 \labelwidthstring 00.00.0000
9190 \begin_layout Standard
9202 \begin_inset LatexCommand \index{-\/-peep-file}
9207 <filename> This option can be used to use additional rules to be used by
9208 the peep hole optimizer.
9210 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9215 Peep Hole optimizations for details on how to write these rules.
9219 \labelwidthstring 00.00.0000
9226 \begin_layout Standard
9236 \begin_inset LatexCommand \index{-\/-peep-asm}
9242 Pass the inline assembler code through the peep hole optimizer.
9243 This can cause unexpected changes to inline assembler code, please go through
9244 the peephole optimizer
9245 \begin_inset LatexCommand \index{Peephole optimizer}
9249 rules defined in the source file tree '<target>/peeph.def' before using
9254 \labelwidthstring 00.00.0000
9261 \begin_layout Standard
9271 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9277 The compiler will optimize code generation towards fast code, possibly
9278 at the expense of code size.
9282 \labelwidthstring 00.00.0000
9289 \begin_layout Standard
9299 \begin_inset LatexCommand \index{-\/-opt-code-size}
9305 The compiler will optimize code generation towards compact code, possibly
9306 at the expense of code speed.
9309 \begin_layout Standard
9310 \begin_inset VSpace bigskip
9316 \begin_layout Subsection
9318 \begin_inset LatexCommand \index{Options other}
9326 \labelwidthstring 00.00.0000
9334 \begin_layout Standard
9344 \begin_inset LatexCommand \index{-\/-compile-only}
9349 \begin_inset LatexCommand \index{-c -\/-compile-only}
9355 will compile and assemble the source, but will not call the linkage editor.
9359 \labelwidthstring 00.00.0000
9368 \begin_layout Standard
9380 \begin_inset LatexCommand \index{-\/-c1mode}
9386 reads the preprocessed source from standard input and compiles it.
9387 The file name for the assembler output must be specified using the -o option.
9391 \labelwidthstring 00.00.0000
9395 \begin_inset LatexCommand \index{-E}
9401 Run only the C preprocessor.
9402 Preprocess all the C source files specified and output the results to standard
9407 \labelwidthstring 00.00.0000
9412 \begin_inset LatexCommand \index{-o <path/file>}
9418 The output path where everything will be placed or the file name used for
9419 all generated output files.
9420 If the parameter is a path, it must have a trailing slash (or backslash
9421 for the Windows binaries) to be recognized as a path.Note for Windows users:
9422 if the path contains spaces, it should be surrounded by quotes.
9423 The trailing backslash should be doubled in order to prevent escaping the
9424 final quote, for example:
9427 \begin_inset Quotes sld
9441 \begin_inset Quotes srd
9446 or put after the final quote, for example:
9449 \begin_inset Quotes sld
9459 \begin_inset Quotes srd
9467 The path using slashes for directory delimiters can be used too, for example:
9470 \begin_inset Quotes sld
9473 F:/Projects/test3/output 1/
9474 \begin_inset Quotes srd
9483 \labelwidthstring 00.00.0000
9490 \begin_layout Standard
9500 \begin_inset LatexCommand \index{-\/-stack-auto}
9506 All functions in the source file will be compiled as
9511 \begin_inset LatexCommand \index{reentrant}
9516 the parameters and local variables will be allocated on the stack
9517 \begin_inset LatexCommand \index{stack}
9523 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9527 Parameters and Local Variables for more details.
9528 If this option is used all source files in the project should be compiled
9530 It automatically implies -
9536 \begin_layout Standard
9547 -int-long-reent and -
9553 \begin_layout Standard
9568 \labelwidthstring 00.00.0000
9575 \begin_layout Standard
9585 \begin_inset LatexCommand \index{-\/-callee-saves}
9590 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9594 function1[,function2][,function3]....
9597 The compiler by default uses a caller saves convention for register saving
9598 across function calls, however this can cause unnecessary register pushing
9599 and popping when calling small functions from larger functions.
9600 This option can be used to switch the register saving convention for the
9601 function names specified.
9602 The compiler will not save registers when calling these functions, no extra
9603 code will be generated at the entry and exit (function prologue
9606 \begin_inset LatexCommand \index{function prologue}
9615 \begin_inset LatexCommand \index{function epilogue}
9621 ) for these functions to save and restore the registers used by these functions,
9622 this can SUBSTANTIALLY reduce code and improve run time performance of
9624 In the future the compiler (with inter procedural analysis) will be able
9625 to determine the appropriate scheme to use for each function call.
9626 DO NOT use this option for built-in functions such as _mulint..., if this
9627 option is used for a library function the appropriate library function
9628 needs to be recompiled with the same option.
9629 If the project consists of multiple source files then all the source file
9630 should be compiled with the same -
9634 \begin_layout Standard
9643 -callee-saves option string.
9644 Also see #pragma\InsetSpace ~
9646 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9651 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9659 \labelwidthstring 00.00.0000
9666 \begin_layout Standard
9676 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9686 \begin_layout Standard
9695 -callee-saves will be applied to all functions by default.
9699 \labelwidthstring 00.00.0000
9706 \begin_layout Standard
9716 \begin_inset LatexCommand \index{-\/-debug}
9722 When this option is used the compiler will generate debug information.
9723 The debug information collected in a file with .cdb extension can be used
9725 For more information see documentation for SDCDB.
9726 Another file with no extension contains debug information in AOMF or AOMF51
9727 \begin_inset LatexCommand \index{AOMF, AOMF51}
9731 format which is commonly used by third party tools.
9735 \labelwidthstring 00.00.0000
9739 \begin_inset LatexCommand \index{-S}
9745 Stop after the stage of compilation proper; do not assemble.
9746 The output is an assembler code file for the input file specified.
9750 \labelwidthstring 00.00.0000
9757 \begin_layout Standard
9767 \begin_inset LatexCommand \index{-\/-int-long-reent}
9773 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9774 Note by default these libraries are compiled as non-reentrant.
9775 See section Installation for more details.
9779 \labelwidthstring 00.00.0000
9786 \begin_layout Standard
9796 \begin_inset LatexCommand \index{-\/-cyclomatic}
9802 This option will cause the compiler to generate an information message for
9803 each function in the source file.
9804 The message contains some
9808 information about the function.
9809 The number of edges and nodes the compiler detected in the control flow
9810 graph of the function, and most importantly the
9812 cyclomatic complexity
9813 \begin_inset LatexCommand \index{Cyclomatic complexity}
9819 see section on Cyclomatic Complexity for more details.
9823 \labelwidthstring 00.00.0000
9830 \begin_layout Standard
9840 \begin_inset LatexCommand \index{-\/-float-reent}
9846 Floating point library is compiled as reentrant
9847 \begin_inset LatexCommand \index{reentrant}
9852 See section Installation for more details.
9856 \labelwidthstring 00.00.0000
9863 \begin_layout Standard
9873 \begin_inset LatexCommand \index{-\/-funsigned-char}
9879 The default signedness for every type is
9884 In some embedded environments the default signedness of
9893 To set the signess for characters to unsigned, use the option -
9899 \begin_layout Standard
9911 If this option is set and no signedness keyword (unsigned/signed) is given,
9912 a char will be signed.
9913 All other types are unaffected.
9917 \labelwidthstring 00.00.0000
9924 \begin_layout Standard
9934 \begin_inset LatexCommand \index{-\/-main-return}
9940 This option can be used if the code generated is called by a monitor program
9941 or if the main routine includes an endless loop.
9942 This option results in slightly smaller code and saves two bytes of stack
9944 The return from the 'main'
9945 \begin_inset LatexCommand \index{main return}
9949 function will return to the function calling main.
9950 The default setting is to lock up i.e.
9959 \labelwidthstring 00.00.0000
9966 \begin_layout Standard
9976 \begin_inset LatexCommand \index{-\/-nostdinc}
9982 This will prevent the compiler from passing on the default include path
9983 to the preprocessor.
9987 \labelwidthstring 00.00.0000
9994 \begin_layout Standard
10004 \begin_inset LatexCommand \index{-\/-nostdlib}
10010 This will prevent the compiler from passing on the default library
10011 \begin_inset LatexCommand \index{Libraries}
10015 path to the linker.
10019 \labelwidthstring 00.00.0000
10026 \begin_layout Standard
10036 \begin_inset LatexCommand \index{-\/-verbose}
10042 Shows the various actions the compiler is performing.
10046 \labelwidthstring 00.00.0000
10050 \begin_inset LatexCommand \index{-V}
10056 Shows the actual commands the compiler is executing.
10060 \labelwidthstring 00.00.0000
10067 \begin_layout Standard
10077 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10083 Hides your ugly and inefficient c-code from the asm file, so you can always
10084 blame the compiler :)
10088 \labelwidthstring 00.00.0000
10095 \begin_layout Standard
10105 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10111 Include code generator and peep-hole comments in the generated asm files.
10115 \labelwidthstring 00.00.0000
10122 \begin_layout Standard
10132 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10138 Don't include peep-hole comments in the generated asm files even if -
10144 \begin_layout Standard
10155 -fverbose-asm option is specified.
10159 \labelwidthstring 00.00.0000
10166 \begin_layout Standard
10176 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10182 Include i-codes in the asm file.
10183 Sounds like noise but is most helpful for debugging the compiler itself.
10187 \labelwidthstring 00.00.0000
10194 \begin_layout Standard
10204 \begin_inset LatexCommand \index{pedantic}
10209 \begin_inset LatexCommand \index{-\/-less-pedantic}
10216 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10220 Disable some of the more pedantic warnings
10221 \begin_inset LatexCommand \index{Warnings}
10226 For more details, see the less_pedantic pragma
10227 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10235 \labelwidthstring 00.00.0000
10242 \begin_layout Standard
10251 -disable-warning\InsetSpace ~
10253 \begin_inset LatexCommand \index{-\/-disable-warning}
10259 Disable specific warning with number <nnnn>.
10263 \labelwidthstring 00.00.0000
10270 \begin_layout Standard
10280 \begin_inset LatexCommand \index{-\/-Werror}
10286 Treat all warnings as errors.
10290 \labelwidthstring 00.00.0000
10297 \begin_layout Standard
10307 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10313 Display the directories in the compiler's search path
10317 \labelwidthstring 00.00.0000
10324 \begin_layout Standard
10334 \begin_inset LatexCommand \index{-\/-vc}
10340 Display errors and warnings using MSVC style, so you can use SDCC with
10341 the visual studio IDE
10342 \begin_inset LatexCommand \index{IDE}
10347 With SDCC both offering a GCC-like (the default) and a MSVC-like
10348 \begin_inset LatexCommand \index{MSVC output style}
10352 output style, integration into most programming editors should be straightforwa
10357 \labelwidthstring 00.00.0000
10364 \begin_layout Standard
10374 \begin_inset LatexCommand \index{-\/-use-stdout}
10380 Send errors and warnings to stdout instead of stderr.
10384 \labelwidthstring 00.00.0000
10388 asmOption[,asmOption]
10391 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10396 Pass the asmOption to the assembler
10397 \begin_inset LatexCommand \index{Options assembler}
10402 \begin_inset LatexCommand \index{Assembler options}
10407 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10411 \labelwidthstring 00.00.0000
10418 \begin_layout Standard
10428 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10434 Generally follow the C89 standard, but allow SDCC features that conflict
10435 with the standard (default).
10439 \labelwidthstring 00.00.0000
10446 \begin_layout Standard
10456 \begin_inset LatexCommand \index{-\/-std-c89}
10462 Follow the C89 standard and disable SDCC features that conflict with the
10467 \labelwidthstring 00.00.0000
10474 \begin_layout Standard
10484 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10490 Generally follow the C99 standard, but allow SDCC features that conflict
10491 with the standard (incomplete support).
10495 \labelwidthstring 00.00.0000
10502 \begin_layout Standard
10512 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10518 Follow the C99 standard and disable SDCC features that conflict with the
10519 standard (incomplete support).
10523 \labelwidthstring 00.00.0000
10530 \begin_layout Standard
10542 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10547 <Name> The name to be used for the code
10548 \begin_inset LatexCommand \index{code}
10552 segment, default CSEG.
10553 This is useful if you need to tell the compiler to put the code in a special
10554 segment so you can later on tell the linker to put this segment in a special
10556 Can be used for instance when using bank switching to put the code in a
10561 \labelwidthstring 00.00.0000
10568 \begin_layout Standard
10580 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10585 <Name> The name to be used for the const
10586 \begin_inset LatexCommand \index{const}
10590 segment, default CONST.
10591 This is useful if you need to tell the compiler to put the const data in
10592 a special segment so you can later on tell the linker to put this segment
10593 in a special place in memory.
10594 Can be used for instance when using bank switching to put the const data
10599 \labelwidthstring 00.00.0000
10606 \begin_layout Standard
10615 -fdollars-in-identifiers
10616 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10622 Permit '$' as an identifier character.
10626 \labelwidthstring 00.00.0000
10633 \begin_layout Standard
10645 \begin_inset LatexCommand \index{-\/-more-pedantic}
10650 \begin_inset LatexCommand \index{pedantic}
10660 a SDCC compiler option but if you want
10664 warnings you can use a separate tool dedicated to syntax checking like
10666 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10671 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10676 \begin_inset LatexCommand \url{http://www.splint.org}
10681 To make your source files parseable by splint you will have to include
10686 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10690 in your source file and add brackets around extended keywords (like
10693 \begin_inset Quotes sld
10706 \begin_inset Quotes srd
10714 \begin_inset Quotes sld
10717 __interrupt\InsetSpace ~
10719 \begin_inset Quotes srd
10726 Splint has an excellent on line manual at
10727 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10731 and it's capabilities go beyond pure syntax checking.
10732 You'll need to tell splint the location of SDCC's include files so a typical
10733 command line could look like this:
10737 splint\InsetSpace ~
10739 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10745 \labelwidthstring 00.00.0000
10752 \begin_layout Standard
10764 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10769 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10773 Treat short as 8-bit (for backward compatibility with older versions of
10774 compiler - see section
10775 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10782 \begin_layout Standard
10783 \begin_inset VSpace bigskip
10789 \begin_layout Subsection
10790 Intermediate Dump Options
10791 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10796 \begin_inset LatexCommand \index{Options intermediate dump}
10801 \begin_inset LatexCommand \index{Intermediate dump options}
10808 \begin_layout Standard
10809 The following options are provided for the purpose of retargetting and debugging
10811 They provide a means to dump the intermediate code (iCode
10812 \begin_inset LatexCommand \index{iCode}
10816 ) generated by the compiler in human readable form at various stages of
10817 the compilation process.
10818 More on iCodes see chapter
10819 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10824 \begin_inset Quotes srd
10827 The anatomy of the compiler
10828 \begin_inset Quotes srd
10835 \labelwidthstring 00.00.0000
10842 \begin_layout Standard
10852 \begin_inset LatexCommand \index{-\/-dumpraw}
10858 This option will cause the compiler to dump the intermediate code into
10861 <source filename>.dumpraw
10863 just after the intermediate code has been generated for a function, i.e.
10864 before any optimizations are done.
10866 \begin_inset LatexCommand \index{Basic blocks}
10870 at this stage ordered in the depth first number, so they may not be in
10871 sequence of execution.
10875 \labelwidthstring 00.00.0000
10882 \begin_layout Standard
10892 \begin_inset LatexCommand \index{-\/-dumpgcse}
10898 Will create a dump of iCodes, after global subexpression elimination
10899 \begin_inset LatexCommand \index{Global subexpression elimination}
10903 , into a file named
10905 <source filename>.dumpgcse.
10909 \labelwidthstring 00.00.0000
10916 \begin_layout Standard
10926 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10932 Will create a dump of iCodes, after deadcode elimination
10933 \begin_inset LatexCommand \index{Dead-code elimination}
10937 , into a file named
10939 <source filename>.dumpdeadcode.
10943 \labelwidthstring 00.00.0000
10950 \begin_layout Standard
10960 \begin_inset LatexCommand \index{-\/-dumploop}
10966 Will create a dump of iCodes, after loop optimizations
10967 \begin_inset LatexCommand \index{Loop optimization}
10971 , into a file named
10973 <source filename>.dumploop.
10977 \labelwidthstring 00.00.0000
10984 \begin_layout Standard
10994 \begin_inset LatexCommand \index{-\/-dumprange}
11000 Will create a dump of iCodes, after live range analysis
11001 \begin_inset LatexCommand \index{Live range analysis}
11005 , into a file named
11007 <source filename>.dumprange.
11011 \labelwidthstring 00.00.0000
11018 \begin_layout Standard
11028 \begin_inset LatexCommand \index{-\/-dumlrange}
11034 Will dump the life ranges
11035 \begin_inset LatexCommand \index{Live range analysis}
11043 \labelwidthstring 00.00.0000
11050 \begin_layout Standard
11060 \begin_inset LatexCommand \index{-\/-dumpregassign}
11066 Will create a dump of iCodes, after register assignment
11067 \begin_inset LatexCommand \index{Register assignment}
11071 , into a file named
11073 <source filename>.dumprassgn.
11077 \labelwidthstring 00.00.0000
11084 \begin_layout Standard
11094 \begin_inset LatexCommand \index{-\/-dumplrange}
11100 Will create a dump of the live ranges of iTemp's
11104 \labelwidthstring 00.00.0000
11111 \begin_layout Standard
11121 \begin_inset LatexCommand \index{-\/-dumpall}
11127 Will cause all the above mentioned dumps to be created.
11130 \begin_layout Standard
11131 \begin_inset VSpace bigskip
11137 \begin_layout Subsection
11138 Redirecting output on Windows Shells
11141 \begin_layout Standard
11142 By default SDCC writes its error messages to
11143 \begin_inset Quotes sld
11147 \begin_inset Quotes srd
11151 To force all messages to
11152 \begin_inset Quotes sld
11156 \begin_inset Quotes srd
11168 \begin_layout Standard
11183 \begin_inset LatexCommand \index{-\/-use-stdout}
11188 Additionally, if you happen to have visual studio installed in your windows
11189 machine, you can use it to compile your sources using a custom build and
11196 \begin_layout Standard
11208 \begin_inset LatexCommand \index{-\/-vc}
11213 Something like this should work:
11232 \begin_layout Standard
11251 \begin_layout Standard
11263 -model-large -c $(InputPath)
11266 \begin_inset VSpace bigskip
11272 \begin_layout Section
11273 Environment variables
11274 \begin_inset LatexCommand \index{Environment variables}
11281 \begin_layout Standard
11282 SDCC recognizes the following environment variables:
11286 \labelwidthstring 00.00.0000
11290 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11296 SDCC installs a signal handler
11297 \begin_inset LatexCommand \index{signal handler}
11301 to be able to delete temporary files after an user break (^C) or an exception.
11302 If this environment variable is set, SDCC won't install the signal handler
11303 in order to be able to debug SDCC.
11307 \labelwidthstring 00.00.0000
11313 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11319 Path, where temporary files will be created.
11320 The order of the variables is the search order.
11321 In a standard *nix environment these variables are not set, and there's
11322 no need to set them.
11323 On Windows it's recommended to set one of them.
11327 \labelwidthstring 00.00.0000
11331 \begin_inset LatexCommand \index{SDCC\_HOME}
11338 \begin_inset LatexCommand \ref{sub:Install-paths}
11344 \begin_inset Quotes sld
11348 \begin_inset Quotes srd
11355 \labelwidthstring 00.00.0000
11359 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11366 \begin_inset LatexCommand \ref{sub:Search-Paths}
11372 \begin_inset Quotes sld
11376 \begin_inset Quotes srd
11383 \labelwidthstring 00.00.0000
11387 \begin_inset LatexCommand \index{SDCC\_LIB}
11394 \begin_inset LatexCommand \ref{sub:Search-Paths}
11400 \begin_inset Quotes sld
11404 \begin_inset Quotes srd
11410 \begin_layout Standard
11411 There are some more environment variables recognized by SDCC, but these
11412 are solely used for debugging purposes.
11413 They can change or disappear very quickly, and will never be documented.
11414 \begin_inset VSpace bigskip
11420 \begin_layout Section
11421 Storage Class Language Extensions
11424 \begin_layout Subsection
11425 MCS51/DS390 Storage Class
11426 \begin_inset LatexCommand \index{Storage class}
11430 Language Extensions
11433 \begin_layout Standard
11434 In addition to the ANSI storage classes SDCC allows the following MCS51
11435 specific storage classes:
11438 \begin_layout Subsubsection
11440 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11445 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11450 \begin_inset LatexCommand \index{near (storage class)}
11455 \begin_inset LatexCommand \index{\_\_near (storage class)}
11462 \begin_layout Standard
11467 storage class for the Small Memory model (
11475 or the more ANSI-C compliant forms
11483 can be used synonymously).
11484 Variables declared with this storage class will be allocated in the directly
11485 addressable portion of the internal RAM of a 8051, e.g.:
11488 \begin_layout Verse
11491 __data unsigned char test_data;
11494 \begin_layout Standard
11495 Writing 0x01 to this variable generates the assembly code:
11498 \begin_layout Verse
11501 75*00 01\InsetSpace ~
11509 \begin_layout Subsubsection
11511 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11516 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11521 \begin_inset LatexCommand \index{far (storage class)}
11526 \begin_inset LatexCommand \index{\_\_far (storage class)}
11533 \begin_layout Standard
11534 Variables declared with this storage class will be placed in the external
11540 storage class for the Large Memory model, e.g.:
11543 \begin_layout Verse
11546 __xdata unsigned char test_xdata;
11549 \begin_layout Standard
11550 Writing 0x01 to this variable generates the assembly code:
11553 \begin_layout Verse
11556 90s00r00\InsetSpace ~
11587 \begin_layout Subsubsection
11589 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11594 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11601 \begin_layout Standard
11602 Variables declared with this storage class will be allocated into the indirectly
11603 addressable portion of the internal ram of a 8051, e.g.:
11606 \begin_layout Verse
11609 __idata unsigned char test_idata;
11612 \begin_layout Standard
11613 Writing 0x01 to this variable generates the assembly code:
11616 \begin_layout Verse
11643 \begin_layout Standard
11644 Please note, the first 128 byte of idata physically access the same RAM
11645 as the data memory.
11646 The original 8051 had 128 byte idata memory, nowadays most devices have
11647 256 byte idata memory.
11649 \begin_inset LatexCommand \index{stack}
11653 is located in idata memory.
11656 \begin_layout Subsubsection
11658 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11663 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11670 \begin_layout Standard
11671 Paged xdata access is just as straightforward as using the other addressing
11673 It is typically located at the start of xdata and has a maximum size of
11675 The following example writes 0x01 to the pdata variable.
11676 Please note, pdata access physically accesses xdata memory.
11677 The high byte of the address is determined by port P2
11678 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11682 (or in case of some 8051 variants by a separate Special Function Register,
11684 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11693 storage class for the Medium Memory model, e.g.:
11696 \begin_layout Verse
11699 __pdata unsigned char test_pdata;
11702 \begin_layout Standard
11703 Writing 0x01 to this variable generates the assembly code:
11706 \begin_layout Verse
11715 mov r0,#_test_pdata
11737 \begin_layout Standard
11742 \begin_layout Standard
11752 \begin_inset LatexCommand \index{-\/-xstack}
11756 option is used the pdata memory area is followed by the xstack memory area
11757 and the sum of their sizes is limited to 256 bytes.
11760 \begin_layout Subsubsection
11762 \begin_inset LatexCommand \index{code}
11767 \begin_inset LatexCommand \index{\_\_code}
11774 \begin_layout Standard
11775 'Variables' declared with this storage class will be placed in the code
11779 \begin_layout Verse
11782 __code unsigned char test_code;
11785 \begin_layout Standard
11786 Read access to this variable generates the assembly code:
11789 \begin_layout Verse
11792 90s00r6F\InsetSpace ~
11795 mov dptr,#_test_code
11820 \begin_layout Standard
11825 indexed arrays of characters in code memory can be accessed efficiently:
11828 \begin_layout Verse
11831 __code char test_array[] = {'c','h','e','a','p'};
11834 \begin_layout Standard
11835 Read access to this array using an 8-bit unsigned index generates the assembly
11839 \begin_layout Verse
11851 \begin_layout Verse
11854 90s00r41\InsetSpace ~
11857 mov dptr,#_test_array
11860 \begin_layout Verse
11875 \begin_layout Subsubsection
11877 \begin_inset LatexCommand \index{bit}
11882 \begin_inset LatexCommand \index{\_\_bit}
11889 \begin_layout Standard
11890 This is a data-type and a storage class specifier.
11891 When a variable is declared as a bit, it is allocated into the bit addressable
11892 memory of 8051, e.g.:
11895 \begin_layout Verse
11901 \begin_layout Standard
11902 Writing 1 to this variable generates the assembly code:
11905 \begin_layout Verse
11919 \begin_layout Standard
11920 The bit addressable memory consists of 128 bits which are located from 0x20
11921 to 0x2f in data memory.
11923 Apart from this 8051 specific storage class most
11924 architectures support ANSI-C bitfields
11925 \begin_inset LatexCommand \index{bitfields}
11933 \begin_layout Standard
11934 Not really meant as examples, but nevertheless showing what bitfields are
11935 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11941 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11942 signed modifier are implemented as unsigned.
11945 \begin_layout Subsubsection
11947 \begin_inset LatexCommand \index{sfr}
11952 \begin_inset LatexCommand \index{\_\_sfr}
11957 \begin_inset LatexCommand \index{sfr16}
11962 \begin_inset LatexCommand \index{\_\_sfr16}
11967 \begin_inset LatexCommand \index{sfr32}
11972 \begin_inset LatexCommand \index{\_\_sfr32}
11977 \begin_inset LatexCommand \index{\_\_sbit}
11982 \begin_inset LatexCommand \index{sbit}
11989 \begin_layout Standard
11990 Like the bit keyword,
11992 sfr / sfr16 / sfr32 / sbit
11994 signify both a data-type and storage class, they are used to describe the
12014 variables of a 8051, eg:
12017 \begin_layout Verse
12021 \begin_inset LatexCommand \index{at}
12026 \begin_inset LatexCommand \index{\_\_at}
12030 (0x80) P0;\InsetSpace ~
12031 /* special function register P0 at location 0x80 */
12036 special function register combination for timer 0
12040 with the high byte at
12041 location 0x8C and the low byte at location 0x8A */
12043 __sfr16 __at (0x8C8A)
12049 \begin_inset LatexCommand \index{at}
12054 \begin_inset LatexCommand \index{\_\_at}
12058 (0xd7) CY;\InsetSpace ~
12060 \begin_inset LatexCommand \index{Flags}
12065 \begin_inset LatexCommand \index{Carry flag}
12072 \begin_layout Standard
12073 Special function registers which are located on an address dividable by
12074 8 are bit-addressable, an
12078 addresses a specific bit within these sfr.
12080 16 Bit and 32 bit special function
12081 register combinations which require a certain access order are better not
12091 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12092 this is not guaranteed.
12097 \begin_layout Standard
12098 Please note, if you use a header file which was written for another compiler
12099 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12105 Specifically the syntax
12108 sfr P0 = 0x80;\InsetSpace ~
12115 by SDCC to an assignment of 0x80 to a variable called P0
12118 \begin_inset Marginal
12121 \begin_layout Standard
12132 Nevertheless it is possible to write header files
12133 \begin_inset LatexCommand \index{Header files}
12138 \begin_inset LatexCommand \index{Include files}
12142 which can be shared among different compilers (see section
12143 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12150 \begin_layout Subsubsection
12152 \begin_inset LatexCommand \index{Pointer}
12156 to MCS51/DS390 specific memory spaces
12159 \begin_layout Standard
12160 SDCC allows (via language extensions) pointers to explicitly point to any
12161 of the memory spaces
12162 \begin_inset LatexCommand \index{Memory model}
12167 In addition to the explicit pointers, the compiler uses (by default) generic
12168 pointers which can be used to point to any of the memory spaces.
12173 declaration examples:
12176 \begin_layout Verse
12179 /* pointer physically in internal ram pointing to object in external ram
12182 __xdata unsigned char * __data p;
12186 /* pointer physically in external ram
12187 pointing to object in internal ram */
12189 __data unsigned char * __xdata p;
12194 pointer physically in code rom pointing to data in xdata space */
12197 unsigned char * __code p;
12201 /* pointer physically in code space pointing to
12202 data in code space */
12204 __code unsigned char * __code p;
12209 physically located in xdata space */
12211 unsigned char * __xdata p;
12216 pointer physically located in default memory space */
12223 the following is a function pointer
12224 \begin_inset LatexCommand \index{function pointer}
12228 physically located in data space */
12230 char (* __data fp)(void);
12233 \begin_layout Standard
12234 Well you get the idea.
12238 All unqualified pointers are treated as 3-byte (4-byte
12251 The highest order byte of the
12255 pointers contains the data space information.
12256 Assembler support routines are called whenever data is stored or retrieved
12262 These are useful for developing reusable library
12263 \begin_inset LatexCommand \index{Libraries}
12268 Explicitly specifying the pointer
12269 \begin_inset LatexCommand \index{pointer}
12273 type will generate the most efficient code.
12276 \begin_layout Subsubsection
12277 Notes on MCS51 memory
12278 \begin_inset LatexCommand \index{MCS51 memory}
12285 \begin_layout Standard
12286 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12287 RAM memory which is structured as follows:
12291 - Bytes 00-1F - 32 bytes to hold
12292 up to 4 banks of the registers R0 to R7,
12294 - Bytes 20-2F - 16 bytes to hold
12296 \begin_inset LatexCommand \index{bit}
12302 - Bytes 30-7F - 80 bytes for general purpose use.
12307 \begin_layout Standard
12308 Additionally some members of the MCS51 family may have up to 128 bytes of
12309 additional, indirectly addressable, internal RAM memory (
12314 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12319 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12324 Furthermore, some chips may have some built in external memory (
12329 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12334 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12338 ) which should not be confused with the internal, directly addressable RAM
12344 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12349 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12354 Sometimes this built in
12358 memory has to be activated before using it (you can probably find this
12359 information on the datasheet of the microcontroller your are using, see
12361 \begin_inset LatexCommand \ref{sub:Startup-Code}
12369 \begin_layout Standard
12370 Normally SDCC will only use the first bank
12371 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12375 of registers (register bank 0), but it is possible to specify that other
12376 banks of registers (keyword
12379 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12384 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12390 ) should be used for example in interrupt
12391 \begin_inset LatexCommand \index{interrupt}
12396 \begin_inset LatexCommand \index{\_\_interrupt}
12401 By default, the compiler will place the stack after the last byte of allocated
12402 memory for variables.
12403 For example, if the first 2 banks of registers are used, and only four
12408 variables, it will position the base of the internal stack at address 20
12410 This implies that as the stack
12411 \begin_inset LatexCommand \index{stack}
12415 grows, it will use up the remaining register banks, and the 16 bytes used
12416 by the 128 bit variables, and 80 bytes for general purpose use.
12417 If any bit variables are used, the data variables will be placed in unused
12418 register banks and after the byte holding the last bit variable.
12419 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12424 variables will be placed starting from address 0x10 to 0x20 and continue
12430 \begin_layout Standard
12440 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12444 to specify the start address of the
12452 \begin_layout Standard
12462 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12466 to specify the size of the total internal RAM (
12479 \begin_layout Standard
12480 By default the 8051 linker will place the stack after the last byte of (i)data
12486 \begin_layout Standard
12496 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12500 allows you to specify the start of the stack, i.e.
12501 you could start it after any data in the general purpose area.
12502 If your microcontroller has additional indirectly addressable internal
12507 ) you can place the stack on it.
12508 You may also need to use -
12512 \begin_layout Standard
12522 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12526 to set the start address of the external RAM (
12534 \begin_layout Standard
12544 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12548 to specify its size.
12549 Same goes for the code memory, using -
12553 \begin_layout Standard
12563 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12571 \begin_layout Standard
12581 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12586 If in doubt, don't specify any options and see if the resulting memory
12587 layout is appropriate, then you can adjust it.
12590 \begin_layout Standard
12591 The linker generates two files with memory allocation information.
12592 The first, with extension .map
12593 \begin_inset LatexCommand \index{<file>.map}
12597 shows all the variables and segments.
12598 The second with extension .mem
12599 \begin_inset LatexCommand \index{<file>.mem}
12603 shows the final memory layout.
12604 The linker will complain either if memory segments overlap, there is not
12605 enough memory, or there is not enough space for stack.
12606 If you get any linking warnings and/or errors related to stack or segments
12607 allocation, take a look at either the .map or .mem files to find out what
12609 The .mem file may even suggest a solution to the problem.
12610 \begin_inset VSpace bigskip
12616 \begin_layout Subsection
12617 Z80/Z180 Storage Class
12618 \begin_inset LatexCommand \index{Z80!Storage class}
12622 Language Extensions
12625 \begin_layout Subsubsection
12627 \begin_inset LatexCommand \index{sfr}
12632 \begin_inset LatexCommand \index{\_\_sfr}
12636 (in/out to 8-bit addresses)
12639 \begin_layout Standard
12641 \begin_inset LatexCommand \index{Z80}
12645 family has separate address spaces for memory and
12655 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12660 \begin_inset LatexCommand \index{Z80!I/O memory}
12665 \begin_inset LatexCommand \index{Z180!I/O memory}
12669 is accessed with special instructions, e.g.:
12672 \begin_layout Verse
12675 sfr at 0x78 IoPort;\InsetSpace ~
12677 /* define a var in I/O space at 78h called IoPort */
12680 \begin_layout Standard
12681 Writing 0x01 to this variable generates the assembly code:
12684 \begin_layout Verse
12704 \begin_layout Subsubsection
12706 \begin_inset LatexCommand \index{sfr}
12711 \begin_inset LatexCommand \index{\_\_sfr}
12715 (in/out to 16-bit addresses)
12718 \begin_layout Standard
12723 is used to support 16 bit addresses in I/O memory e.g.:
12726 \begin_layout Verse
12730 \begin_inset LatexCommand \index{at}
12735 \begin_inset LatexCommand \index{\_\_at}
12742 \begin_layout Standard
12743 Writing 0x01 to this variable generates the assembly code:
12746 \begin_layout Verse
12749 01 23 01\InsetSpace ~
12771 \begin_layout Subsubsection
12773 \begin_inset LatexCommand \index{sfr}
12778 \begin_inset LatexCommand \index{\_\_sfr}
12782 (in0/out0 to 8 bit addresses on Z180
12783 \begin_inset LatexCommand \index{Z180}
12788 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12795 \begin_layout Standard
12796 The compiler option -
12800 \begin_layout Standard
12810 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12814 =180 (80) and a compiler #pragma\InsetSpace ~
12816 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12820 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12830 If you include the file z180.h this will be set automatically.
12831 \begin_inset VSpace bigskip
12837 \begin_layout Subsection
12839 \begin_inset LatexCommand \index{HC08!Storage class}
12843 Language Extensions
12846 \begin_layout Subsubsection
12848 \begin_inset LatexCommand \index{data (hc08 storage class)}
12853 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12860 \begin_layout Standard
12861 The data storage class declares a variable that resides in the first 256
12862 bytes of memory (the direct page).
12864 \begin_inset LatexCommand \index{HC08}
12868 is most efficient at accessing variables (especially pointers) stored here.
12871 \begin_layout Subsubsection
12873 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12878 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12885 \begin_layout Standard
12886 The xdata storage class declares a variable that can reside anywhere in
12888 This is the default if no storage class is specified.
12889 \begin_inset VSpace bigskip
12895 \begin_layout Section
12896 Absolute Addressing
12897 \begin_inset LatexCommand \index{Absolute addressing}
12904 \begin_layout Standard
12905 Data items can be assigned an absolute address with the
12908 \begin_inset LatexCommand \index{at}
12913 \begin_inset LatexCommand \index{\_\_at}
12919 keyword, in addition to a storage class, e.g.:
12922 \begin_layout Verse
12926 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12931 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12936 \begin_inset LatexCommand \index{at}
12941 \begin_inset LatexCommand \index{\_\_at}
12945 0x7ffe unsigned int chksum;
12948 \begin_layout Standard
12949 or, better conforming to ISO/IEC 9899 C:
12952 \begin_layout Verse
12955 __xdata __at (0x7ffe) unsigned int chksum;
12958 \begin_layout Standard
12959 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12960 of the external ram.
12965 reserve any space for variables declared in this way
12966 \begin_inset Marginal
12969 \begin_layout Standard
12978 (they are implemented with an equate in the assembler).
12979 Thus it is left to the programmer to make sure there are no overlaps with
12980 other variables that are declared without the absolute address.
12981 The assembler listing file (.lst
12982 \begin_inset LatexCommand \index{<file>.lst}
12986 ) and the linker output files (.rst
12987 \begin_inset LatexCommand \index{<file>.rst}
12992 \begin_inset LatexCommand \index{<file>.map}
12996 ) are good places to look for such overlaps.
12999 \begin_layout Standard
13000 If however you provide an initializer
13001 \begin_inset LatexCommand \index{Variable initialization}
13005 actual memory allocation will take place and overlaps will be detected
13010 \begin_layout Verse
13013 __code __at (0x7ff0) char Id[5] =
13014 \begin_inset Quotes sld
13018 \begin_inset Quotes srd
13024 \begin_layout Standard
13025 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13029 \begin_layout Standard
13030 In case of memory mapped I/O devices the keyword
13034 has to be used to tell the compiler that accesses might not be removed:
13037 \begin_layout Verse
13041 \begin_inset LatexCommand \index{volatile}
13046 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13051 \begin_inset LatexCommand \index{at}
13055 (0x8000) unsigned char PORTA_8255;
13058 \begin_layout Standard
13059 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13064 \begin_inset LatexCommand \index{Aligned array}
13071 starts at a block (256 byte) boundary
13072 \begin_inset LatexCommand \index{block boundary}
13077 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13083 Absolute addresses can be specified for variables in all
13084 storage classes, e.g.:
13087 \begin_layout Verse
13091 \begin_inset LatexCommand \index{bit}
13096 \begin_inset LatexCommand \index{at}
13103 \begin_layout Standard
13104 The above example will allocate the variable at offset 0x02 in the bit-addressab
13106 There is no real advantage to assigning absolute addresses to variables
13107 in this manner, unless you want strict control over all the variables allocated.
13108 One possible use would be to write hardware portable code.
13109 For example, if you have a routine that uses one or more of the microcontroller
13110 I/O pins, and such pins are different for two different hardwares, you
13111 can declare the I/O pins in your routine using:
13114 \begin_layout Verse
13118 \begin_inset LatexCommand \index{volatile}
13122 __bit MOSI;\InsetSpace ~
13126 /* master out, slave in */
13128 extern volatile __bit MISO;\InsetSpace ~
13135 extern volatile __bit MCLK;\InsetSpace ~
13144 Output of a byte on a 3-wire serial bus.
13149 If needed adapt polarity of clock,
13150 polarity of data and bit order
13155 unsigned char spi_io(unsigned char out_byte)
13180 MOSI = out_byte & 0x80;
13211 nop _endasm; */\InsetSpace ~
13219 /* for slow peripherals */
13271 \begin_layout Standard
13272 Then, someplace in the code for the first hardware you would use
13275 \begin_layout Verse
13279 \begin_inset LatexCommand \index{at}
13284 \begin_inset LatexCommand \index{\_\_at}
13288 (0x80) MOSI;\InsetSpace ~
13292 /* I/O port 0, bit 0 */
13294 __bit __at (0x81) MISO;\InsetSpace ~
13301 __bit __at (0x82) MCLK;\InsetSpace ~
13305 /* I/O port 0, bit 2 */
13308 \begin_layout Standard
13309 Similarly, for the second hardware you would use
13312 \begin_layout Verse
13315 __bit __at (0x83) MOSI;\InsetSpace ~
13319 /* I/O port 0, bit 3 */
13321 __bit __at (0x91) MISO;\InsetSpace ~
13326 I/O port 1, bit 1 */
13329 \begin_inset LatexCommand \index{bit}
13333 __at (0x92) MCLK;\InsetSpace ~
13337 /* I/O port 1, bit 2 */
13340 \begin_layout Standard
13341 and you can use the same hardware dependent routine without changes, as
13342 for example in a library.
13343 This is somehow similar to sbit, but only one absolute address has to be
13344 specified in the whole project.
13345 \begin_inset VSpace bigskip
13351 \begin_layout Section
13353 \begin_inset LatexCommand \index{Parameters}
13358 \begin_inset LatexCommand \index{function parameter}
13363 \begin_inset LatexCommand \index{local variables}
13368 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13375 \begin_layout Standard
13376 Automatic (local) variables and parameters to functions can either be placed
13377 on the stack or in data-space.
13378 The default action of the compiler is to place these variables in the internal
13379 RAM (for small model) or external RAM (for medium or large model).
13380 This in fact makes them similar to
13383 \begin_inset LatexCommand \index{static}
13389 so by default functions are non-reentrant
13390 \begin_inset LatexCommand \index{reentrant}
13398 They can be placed on the stack
13399 \begin_inset LatexCommand \index{stack}
13409 \begin_layout Standard
13419 \begin_inset LatexCommand \index{-\/-stack-auto}
13427 #pragma\InsetSpace ~
13431 \begin_inset LatexCommand \index{\#pragma stackauto}
13438 \begin_inset LatexCommand \index{reentrant}
13444 keyword in the function declaration, e.g.:
13447 \begin_layout Verse
13450 unsigned char foo(char i) __reentrant
13463 \begin_layout Standard
13464 Since stack space on 8051 is limited, the
13474 \begin_layout Standard
13485 option should be used sparingly.
13486 Note that the reentrant keyword just means that the parameters & local
13487 variables will be allocated to the stack, it
13491 mean that the function is register bank
13492 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13501 \begin_inset LatexCommand \index{local variables}
13505 can be assigned storage classes and absolute
13506 \begin_inset LatexCommand \index{Absolute addressing}
13513 \begin_layout Verse
13516 unsigned char foo()
13524 __xdata unsigned char i;
13537 \begin_inset LatexCommand \index{at}
13541 (0x31) unsigned char j;
13552 \begin_layout Standard
13553 In the above example the variable
13557 will be allocated in the external ram,
13561 in bit addressable space and
13572 \begin_layout Standard
13583 or when a function is declared as
13587 this should only be done for static variables.
13590 \begin_layout Standard
13592 \begin_inset LatexCommand \index{function parameter}
13596 however are not allowed any storage class
13597 \begin_inset LatexCommand \index{Storage class}
13601 , (storage classes for parameters will be ignored), their allocation is
13602 governed by the memory model in use, and the reentrancy options.
13605 \begin_layout Standard
13606 It is however allowed to use bit parameters in reentrant functions and also
13607 non-static local bit variables are supported.
13608 Efficient use is limited to 8 semi-bitregisters in bit space.
13609 They are pushed and popped to stack
13610 \begin_inset LatexCommand \index{stack}
13614 as a single byte just like the normal registers.
13617 \begin_layout Section
13619 \begin_inset LatexCommand \label{sub:Overlaying}
13624 \begin_inset LatexCommand \index{Overlaying}
13631 \begin_layout Standard
13633 \begin_inset LatexCommand \index{reentrant}
13637 functions SDCC will try to reduce internal ram space usage by overlaying
13638 parameters and local variables of a function (if possible).
13639 Parameters and local variables
13640 \begin_inset LatexCommand \index{local variables}
13644 of a function will be allocated to an overlayable segment if the function
13647 no other function calls and the function is non-reentrant and the memory
13649 \begin_inset LatexCommand \index{Memory model}
13656 If an explicit storage class
13657 \begin_inset LatexCommand \index{Storage class}
13661 is specified for a local variable, it will NOT be overlayed.
13664 \begin_layout Standard
13665 Note that the compiler (not the linkage editor) makes the decision for overlayin
13667 Functions that are called from an interrupt service routine
13668 \begin_inset Marginal
13671 \begin_layout Standard
13679 should be preceded by a #pragma\InsetSpace ~
13681 \begin_inset LatexCommand \index{\#pragma nooverlay}
13685 if they are not reentrant.
13688 \begin_layout Standard
13689 Also note that the compiler does not do any processing of inline assembler
13690 code, so the compiler might incorrectly assign local variables and parameters
13691 of a function into the overlay segment if the inline assembler code calls
13692 other c-functions that might use the overlay.
13693 In that case the #pragma\InsetSpace ~
13694 nooverlay should be used.
13697 \begin_layout Standard
13698 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13700 \begin_inset LatexCommand \index{Multiplication}
13705 \begin_inset LatexCommand \index{Division}
13709 will NOT be overlayed since these are implemented using external functions,
13713 \begin_layout Verse
13719 \begin_inset LatexCommand \index{\#pragma nooverlay}
13725 void set_error(unsigned char errcd)
13743 \begin_inset LatexCommand \index{interrupt}
13772 \begin_layout Standard
13773 In the above example the parameter
13781 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13783 not present, this could cause unpredictable runtime behavior when called
13784 from an interrupt service routine.
13785 The #pragma\InsetSpace ~
13786 nooverlay ensures that the parameters and local variables for
13787 the function are NOT overlayed.
13788 \begin_inset VSpace bigskip
13794 \begin_layout Section
13795 Interrupt Service Routines
13796 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13803 \begin_layout Subsection
13804 General Information
13807 \begin_layout Standard
13820 outines to be coded in C, with some extended keywords.
13823 \begin_layout Verse
13826 void timer_isr (void) __interrupt (1) __using (1)
13839 \begin_layout Standard
13840 The optional number following the
13843 \begin_inset LatexCommand \index{interrupt}
13848 \begin_inset LatexCommand \index{\_\_interrupt}
13854 keyword is the interrupt number this routine will service.
13855 When present, the compiler will insert a call to this routine in the interrupt
13857 \begin_inset LatexCommand \index{interrupt vector table}
13861 for the interrupt number specified.
13862 If you have multiple source files in your project, interrupt service routines
13863 can be present in any of them, but a prototype of the isr MUST be present
13864 or included in the file that contains the function
13869 The optional (8051 specific) keyword
13872 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13877 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13883 can be used to tell the compiler to use the specified register bank when
13884 generating code for this function.
13886 Interrupt service routines open the door
13887 for some very interesting bugs:
13890 \begin_layout Subsubsection
13891 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13895 Common interrupt pitfall: variable not declared
13900 \begin_layout Standard
13901 If an interrupt service routine changes variables which are accessed by
13902 other functions these variables have to be declared
13907 \begin_inset LatexCommand \index{volatile}
13913 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13920 \begin_layout Subsubsection
13921 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13925 Common interrupt pitfall:
13930 \begin_layout Standard
13931 If the access to these variables is not
13934 \begin_inset LatexCommand \index{atomic}
13941 the processor needs more than one instruction for the access and could
13942 be interrupted while accessing the variable) the interrupt must be disabled
13943 during the access to avoid inconsistent data.
13945 Access to 16 or 32 bit variables
13946 is obviously not atomic on 8 bit CPUs and should be protected by disabling
13948 You're not automatically on the safe side if you use 8 bit variables though.
13949 We need an example here: f.e.
13950 on the 8051 the harmless looking
13951 \begin_inset Quotes srd
13961 \begin_inset Quotes sld
13970 \begin_inset Quotes srd
13980 \begin_inset Quotes sld
13983 from within an interrupt routine might get lost if the interrupt occurs
13985 \begin_inset Quotes sld
13990 counter\InsetSpace ~
13995 \begin_inset Quotes srd
13998 is not atomic on the 8051 even if
14002 is located in data memory.
14004 Bugs like these are hard to reproduce and can
14005 cause a lot of trouble.
14008 \begin_layout Subsubsection
14009 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14013 Common interrupt pitfall:
14018 \begin_layout Standard
14019 The return address and the registers used in the interrupt service routine
14020 are saved on the stack
14021 \begin_inset LatexCommand \index{stack}
14025 so there must be sufficient stack space.
14026 If there isn't variables or registers (or even the return address itself)
14033 \begin_inset LatexCommand \index{stack overflow}
14037 is most likely to happen if the interrupt occurs during the
14038 \begin_inset Quotes sld
14042 \begin_inset Quotes srd
14045 subroutine when the stack is already in use for f.e.
14046 many return addresses.
14049 \begin_layout Subsubsection
14050 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14054 Common interrupt pitfall:
14056 use of non-reentrant functions
14059 \begin_layout Standard
14060 A special note here, int (16 bit) and long (32 bit) integer division
14061 \begin_inset LatexCommand \index{Division}
14066 \begin_inset LatexCommand \index{Multiplication}
14071 \begin_inset LatexCommand \index{Modulus}
14076 \begin_inset LatexCommand \index{Floating point support}
14080 operations are implemented using external support routines.
14081 If an interrupt service routine needs to do any of these operations then
14082 the support routines (as mentioned in a following section) will have to
14083 be recompiled using the
14089 \begin_layout Standard
14099 \begin_inset LatexCommand \index{-\/-stack-auto}
14105 option and the source file will need to be compiled using the
14111 \begin_layout Standard
14123 \begin_inset LatexCommand \index{-\/-int-long-reent}
14129 Note, the type promotion
14130 \begin_inset LatexCommand \index{type promotion}
14134 required by ANSI C can cause 16 bit routines to be used
14135 \begin_inset Marginal
14138 \begin_layout Standard
14147 without the programmer being aware of it.
14151 (unsigned char)(tail-1)
14153 within the if clause in section
14154 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14161 \begin_layout Standard
14162 Calling other functions from an interrupt service routine is not recommended,
14163 avoid it if possible.
14164 Note that when some function is called from an interrupt service routine
14165 it should be preceded by a #pragma\InsetSpace ~
14167 \begin_inset LatexCommand \index{\#pragma nooverlay}
14171 if it is not reentrant.
14172 Furthermore nonreentrant functions should not be called from the main program
14173 while the interrupt service routine might be active.
14174 They also must not be called from low priority interrupt service routines
14175 while a high priority interrupt service routine might be active.
14176 You could use semaphores or make the function
14180 if all parameters are passed in registers.
14183 \begin_inset LatexCommand \ref{sub:Overlaying}
14188 about Overlaying and section
14189 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14194 about Functions using private register banks.
14195 \begin_inset VSpace bigskip
14201 \begin_layout Subsection
14202 MCS51/DS390 Interrupt Service Routines
14205 \begin_layout Standard
14207 \begin_inset LatexCommand \index{interrupt}
14211 numbers and the corresponding address & descriptions for the Standard 8051/8052
14213 SDCC will automatically adjust the
14214 \begin_inset LatexCommand \index{interrupt vector table}
14218 to the maximum interrupt number specified.
14223 \begin_layout Standard
14225 \begin_inset Tabular
14226 <lyxtabular version="3" rows="9" columns="3">
14228 <column alignment="center" valignment="top" leftline="true" width="0in">
14229 <column alignment="left" valignment="top" leftline="true" width="0in">
14230 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14231 <row topline="true" bottomline="true">
14232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14235 \begin_layout Standard
14241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14244 \begin_layout Standard
14250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14253 \begin_layout Standard
14260 <row topline="true">
14261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14264 \begin_layout Standard
14270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14273 \begin_layout Standard
14279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14282 \begin_layout Standard
14289 <row topline="true">
14290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14293 \begin_layout Standard
14299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14302 \begin_layout Standard
14308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14311 \begin_layout Standard
14318 <row topline="true">
14319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14322 \begin_layout Standard
14328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14331 \begin_layout Standard
14337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14340 \begin_layout Standard
14347 <row topline="true">
14348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14351 \begin_layout Standard
14357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14360 \begin_layout Standard
14366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14369 \begin_layout Standard
14376 <row topline="true">
14377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14380 \begin_layout Standard
14386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14389 \begin_layout Standard
14395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14398 \begin_layout Standard
14405 <row topline="true">
14406 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14409 \begin_layout Standard
14415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14418 \begin_layout Standard
14424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14427 \begin_layout Standard
14434 <row topline="true">
14435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14438 \begin_layout Standard
14444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14447 \begin_layout Standard
14453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14456 \begin_layout Standard
14463 <row topline="true" bottomline="true">
14464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14467 \begin_layout Standard
14473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14476 \begin_layout Standard
14482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14485 \begin_layout Standard
14501 \begin_layout Standard
14502 If the interrupt service routine is defined without
14505 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14510 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14516 a register bank or with register bank 0 (
14520 0), the compiler will save the registers used by itself on the stack upon
14521 entry and restore them at exit, however if such an interrupt service routine
14522 calls another function then the entire register bank will be saved on the
14524 This scheme may be advantageous for small interrupt service routines which
14525 have low register usage.
14528 \begin_layout Standard
14529 If the interrupt service routine is defined to be using a specific register
14534 & psw are saved and restored, if such an interrupt service routine calls
14535 another function (using another register bank) then the entire register
14536 bank of the called function will be saved on the stack
14537 \begin_inset LatexCommand \index{stack}
14542 This scheme is recommended for larger interrupt service routines.
14543 \begin_inset VSpace bigskip
14549 \begin_layout Subsection
14551 \begin_inset LatexCommand \index{HC08}
14555 Interrupt Service Routines
14558 \begin_layout Standard
14559 Since the number of interrupts
14560 \begin_inset LatexCommand \index{HC08!interrupt}
14564 available is chip specific and the interrupt vector table always ends at
14565 the last byte of memory, the interrupt numbers corresponds to the interrupt
14566 vectors in reverse order of address.
14567 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14568 2 will use the interrupt vector at 0xfffa, and so on.
14569 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14570 this way; instead see section
14571 \begin_inset LatexCommand \ref{sub:Startup-Code}
14575 for details on customizing startup.
14576 \begin_inset VSpace bigskip
14582 \begin_layout Subsection
14583 Z80 Interrupt Service Routines
14586 \begin_layout Standard
14588 \begin_inset LatexCommand \index{Z80}
14592 uses several different methods for determining the correct interrupt
14593 \begin_inset LatexCommand \index{Z80!interrupt}
14597 vector depending on the hardware implementation.
14598 Therefore, SDCC ignores the optional interrupt number and does not attempt
14599 to generate an interrupt vector table.
14602 \begin_layout Standard
14603 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14604 instruction to return from the interrupt.
14605 To write an interrupt handler for the non-maskable interrupt, which needs
14606 a RETN instruction instead, add the
14613 \begin_layout Verse
14616 void nmi_isr (void) critical interrupt
14629 \begin_layout Standard
14630 However if you need to create a non-interruptable interrupt service routine
14631 you would also require the
14636 To distinguish between this and an nmi_isr you must provide an interrupt
14638 \begin_inset VSpace bigskip
14644 \begin_layout Section
14645 Enabling and Disabling Interrupts
14648 \begin_layout Subsection
14649 Critical Functions and Critical Statements
14652 \begin_layout Standard
14653 A special keyword may be associated with a block or a function declaring
14659 SDCC will generate code to disable all interrupts
14660 \begin_inset LatexCommand \index{interrupt}
14664 upon entry to a critical function and restore the interrupt enable to the
14665 previous state before returning.
14666 Nesting critical functions will need one additional byte on the stack
14667 \begin_inset LatexCommand \index{stack}
14674 \begin_layout Verse
14677 int foo () __critical
14678 \begin_inset LatexCommand \index{critical}
14683 \begin_inset LatexCommand \index{\_\_critical}
14706 \begin_layout Standard
14707 The critical attribute maybe used with other attributes like
14717 may also be used to disable interrupts more locally:
14720 \begin_layout Verse
14726 \begin_layout Standard
14727 More than one statement could have been included in the block.
14730 \begin_layout Subsection
14731 Enabling and Disabling Interrupts directly
14734 \begin_layout Standard
14736 \begin_inset LatexCommand \index{interrupt}
14740 can also be disabled and enabled directly (8051):
14743 \begin_layout Verse
14746 EA = 0;\InsetSpace ~
14772 \begin_layout Verse
14808 \begin_layout Verse
14811 EA = 1;\InsetSpace ~
14840 \begin_layout Verse
14879 \begin_layout Standard
14880 On other architectures which have seperate opcodes for enabling and disabling
14881 interrupts you might want to make use of defines with inline assembly
14882 \begin_inset LatexCommand \index{Assembler routines}
14887 \begin_inset LatexCommand \index{HC08!interrupt}
14894 \begin_layout Verse
14898 \begin_inset LatexCommand \index{\_asm}
14907 \begin_inset LatexCommand \index{\_endasm}
14914 \begin_layout Verse
14917 #define SEI _asm\InsetSpace ~
14924 \begin_layout Verse
14930 \begin_layout Standard
14931 Note: it is sometimes sufficient to disable only a specific interrupt source
14933 a timer or serial interrupt by manipulating an
14936 \begin_inset LatexCommand \index{interrupt mask}
14945 \begin_layout Standard
14946 Usually the time during which interrupts are disabled should be kept as
14948 This minimizes both
14953 \begin_inset LatexCommand \index{interrupt latency}
14957 (the time between the occurrence of the interrupt and the execution of
14958 the first code in the interrupt routine) and
14963 \begin_inset LatexCommand \index{interrupt jitter}
14967 (the difference between the shortest and the longest interrupt latency).
14968 These really are something different, f.e.
14969 a serial interrupt has to be served before its buffer overruns so it cares
14970 for the maximum interrupt latency, whereas it does not care about jitter.
14971 On a loudspeaker driven via a digital to analog converter which is fed
14972 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14973 a much smaller jitter will be very audible.
14976 \begin_layout Standard
14977 You can reenable interrupts within an interrupt routine and on some architecture
14978 s you can make use of two (or more) levels of
14980 interrupt priorities
14983 \begin_inset LatexCommand \index{interrupt priority}
14988 On some architectures which don't support interrupt priorities these can
14989 be implemented by manipulating the interrupt mask and reenabling interrupts
14990 within the interrupt routine.
14991 Check there is sufficient space on the stack
14992 \begin_inset LatexCommand \index{stack}
14996 and don't add complexity unless you have to.
14999 \begin_layout Subsection
15001 \begin_inset LatexCommand \index{semaphore}
15005 locking (mcs51/ds390)
15008 \begin_layout Standard
15009 Some architectures (mcs51/ds390) have an atomic
15010 \begin_inset LatexCommand \index{atomic}
15014 bit test andclearinstruction.
15015 These type of instructions are typically used in preemptive multitasking
15016 systems, where a routine f.e.
15017 claims the use of a data structure ('acquires a lock
15018 \begin_inset LatexCommand \index{lock}
15022 on it'), makes some modifications and then releases the lock when the data
15023 structure is consistent again.
15024 The instruction may also be used if interrupt and non-interrupt code have
15025 to compete for a resource.
15026 With the atomic bit test and clear instruction interrupts
15027 \begin_inset LatexCommand \index{interrupt}
15031 don't have to be disabled for the locking operation.
15034 \begin_layout Standard
15035 SDCC generates this instruction if the source follows this pattern:
15038 \begin_layout Verse
15042 \begin_inset LatexCommand \index{volatile}
15046 bit resource_is_free;
15050 if (resource_is_free)
15060 resource_is_free=0;
15080 \begin_layout Standard
15081 Note, mcs51 and ds390 support only an atomic
15082 \begin_inset LatexCommand \index{atomic}
15090 instruction (as opposed to atomic bit test and
15095 \begin_layout Section
15096 Functions using private register banks
15097 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15104 \begin_layout Standard
15105 Some architectures have support for quickly changing register sets.
15106 SDCC supports this feature with the
15109 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15114 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15120 attribute (which tells the compiler to use a register bank
15121 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15125 other than the default bank zero).
15126 It should only be applied to
15129 \begin_inset LatexCommand \index{interrupt}
15135 functions (see footnote below).
15136 This will in most circumstances make the generated ISR code more efficient
15137 since it will not have to save registers on the stack.
15140 \begin_layout Standard
15145 attribute will have no effect on the generated code for a
15149 function (but may occasionally be useful anyway
15153 \begin_layout Standard
15154 possible exception: if a function is called ONLY from 'interrupt' functions
15155 using a particular bank, it can be declared with the same 'using' attribute
15156 as the calling 'interrupt' functions.
15157 For instance, if you have several ISRs using bank one, and all of them
15158 call memcpy(), it might make sense to create a specialized version of memcpy()
15159 'using 1', since this would prevent the ISR from having to save bank zero
15160 to the stack on entry and switch to bank zero before calling the function
15169 (pending: Note, nowadays the
15173 attribute has an effect onthe generated code for a
15184 \begin_layout Standard
15189 function using a non-zero bank will assume that it can trash that register
15190 bank, and will not save it.
15191 Since high-priority interrupts
15192 \begin_inset LatexCommand \index{interrupts}
15197 \begin_inset LatexCommand \index{interrupt priority}
15201 can interrupt low-priority ones on the 8051 and friends, this means that
15202 if a high-priority ISR
15206 a particular bank occurs while processing a low-priority ISR
15210 the same bank, terrible and bad things can happen.
15211 To prevent this, no single register bank should be
15215 by both a high priority and a low priority ISR.
15216 This is probably most easily done by having all high priority ISRs use
15217 one bank and all low priority ISRs use another.
15218 If you have an ISR which can change priority at runtime, you're on your
15219 own: I suggest using the default bank zero and taking the small performance
15223 \begin_layout Standard
15224 It is most efficient if your ISR calls no other functions.
15225 If your ISR must call other functions, it is most efficient if those functions
15226 use the same bank as the ISR (see note 1 below); the next best is if the
15227 called functions use bank zero.
15228 It is very inefficient to call a function using a different, non-zero bank
15230 \begin_inset VSpace bigskip
15236 \begin_layout Section
15238 \begin_inset LatexCommand \label{sub:Startup-Code}
15243 \begin_inset LatexCommand \index{Startup code}
15250 \begin_layout Subsection
15251 MCS51/DS390 Startup Code
15254 \begin_layout Standard
15255 The compiler triggers the linker to link certain initialization modules
15256 from the runtime library
15257 \begin_inset LatexCommand \index{Runtime library}
15261 called crt<something>.
15262 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15263 GSINIT5) is not linked unless the -
15269 \begin_layout Standard
15280 -xstack option is used.
15281 These modules are highly entangled by the use of special segments/areas,
15282 but a common layout is shown below:
15285 \begin_layout Verse
15293 \begin_layout Verse
15317 ljmp __sdcc_gsinit_startup
15320 \begin_layout Verse
15328 \begin_layout Verse
15340 .area GSINIT0 (CODE)
15342 __sdcc_gsinit_startup::
15352 mov sp,#__start__stack - 1
15355 \begin_layout Verse
15363 \begin_layout Verse
15375 .area GSINIT1 (CODE)
15377 __sdcc_init_xstack::
15379 ; Need to initialize in GSINIT1 in
15380 case the user's __sdcc_external_startup uses the xstack.
15390 mov __XPAGE,#(__start__x
15401 mov _spx,#__start__xstack
15404 \begin_layout Verse
15412 \begin_layout Verse
15424 .area GSINIT2 (CODE)
15434 lcall __sdcc_external_startup
15454 jz __sdcc_init_data
15465 __sdcc_program_startup
15470 \begin_layout Verse
15478 \begin_layout Verse
15490 .area GSINIT3 (CODE)
15543 mov r2,#((l_XINIT+255) >> 8)
15574 __XPAGE,#(s_XISEG >> 8)
15576 00001$:\InsetSpace ~
15640 00002$:\InsetSpace ~
15667 \begin_layout Verse
15675 \begin_layout Verse
15687 .area GSINIT4 (CODE)
15689 __mcs51_genRAMCLEAR::
15711 00004$:\InsetSpace ~
15725 ; _mcs51_genRAMCLEAR() end
15728 \begin_layout Verse
15736 \begin_layout Verse
15748 .area GSINIT4 (CODE)
15750 __mcs51_genXRAMCLEAR::
15811 mov __XPAGE,#(s_PSEG >> 8)
15823 00005$:\InsetSpace ~
15898 mov r1,#((l_XSEG + 255) >> 8)
15920 00007$:\InsetSpace ~
15957 \begin_layout Verse
15965 \begin_layout Verse
15977 .area GSINIT5 (CODE)
15979 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15982 ; and __mcs51_genRAMCLEAR modifies _spx.
15992 mov __XPAGE,#(__start__x
16003 mov _spx,#__start__xstack
16006 \begin_layout Verse
16011 (application modules)
16014 \begin_layout Verse
16026 .area GSINIT (CODE)
16029 \begin_layout Verse
16037 \begin_layout Verse
16049 .area GSFINAL (CODE)
16059 ljmp __sdcc_program_startup
16061 ;---------------------------------
16062 -----------------------
16066 ;--------------------------------------------------
16089 __sdcc_program_startup:
16102 return from main will lock up
16115 \begin_layout Standard
16116 One of these modules (crtstart.asm) contains a call to the C routine
16118 _sdcc_external_startup()
16119 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16125 at the start of the CODE area.
16126 This routine is also in the runtime library
16127 \begin_inset LatexCommand \index{Runtime library}
16131 and returns 0 by default.
16132 If this routine returns a non-zero value, the static & global variable
16133 initialization will be skipped and the function main will be invoked.
16134 Otherwise static & global variables will be initialized before the function
16138 _sdcc_external_startup()
16140 routine to your program to override the default if you need to setup hardware
16141 or perform some other critical operation prior to static & global variable
16143 \begin_inset LatexCommand \index{Variable initialization}
16148 On some mcs51 variants xdata
16149 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16153 memory has to be explicitly enabled before it can be accessed or if the
16155 \begin_inset LatexCommand \index{watchdog}
16159 needs to be disabled, this is the place to do it.
16160 The startup code clears all internal data memory, 256 bytes by default,
16161 but from 0 to n-1 if
16167 \begin_layout Standard
16177 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16184 (recommended for Chipcon CC1010).
16187 \begin_layout Standard
16188 See also the compiler options
16194 \begin_layout Standard
16210 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16220 \begin_layout Standard
16232 \begin_inset LatexCommand \index{-\/-main-return}
16237 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16241 about MCS51-variants.
16246 \begin_layout Standard
16247 While these initialization modules are meant as generic startup code there
16248 might be the need for customization.
16249 Let's assume the return value of
16251 _sdcc_external_startup()
16257 should not be checked (or
16259 _sdcc_external_startup()
16261 should not be called at all).
16262 The recommended way would be to copy
16268 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16272 ) into the source directory, adapt it there, then assemble it with
16278 \begin_layout Standard
16279 \begin_inset Quotes sld
16283 \begin_inset Quotes srd
16286 are the assembler options used in
16287 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16298 and when linking your project explicitely specify
16303 As a bonus a listing of the relocated object file
16310 \begin_layout Standard
16311 \begin_inset VSpace bigskip
16317 \begin_layout Subsection
16321 \begin_layout Standard
16323 \begin_inset LatexCommand \index{HC08}
16327 startup code follows the same scheme as the MCS51 startup code.
16328 \begin_inset VSpace bigskip
16334 \begin_layout Subsection
16338 \begin_layout Standard
16340 \begin_inset LatexCommand \index{Z80}
16344 the startup code is inserted by linking with crt0.o which is generated from
16345 sdcc/device/lib/z80/crt0.s.
16346 If you need a different startup code you can use the compiler option
16355 \begin_layout Standard
16370 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16374 and provide your own crt0.o.
16375 \begin_inset VSpace bigskip
16381 \begin_layout Section
16382 Inline Assembler Code
16383 \begin_inset LatexCommand \index{Assembler routines}
16390 \begin_layout Subsection
16391 A Step by Step Introduction
16392 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16399 \begin_layout Standard
16400 Starting from a small snippet of c-code this example shows for the MCS51
16401 how to use inline assembly, access variables, a function parameter and
16402 an array in xdata memory.
16403 The example uses an MCS51 here but is easily adapted for other architectures.
16404 This is a buffer routine which should be optimized:
16407 \begin_layout Verse
16411 unsigned char __far
16412 \begin_inset LatexCommand \index{far (storage class)}
16417 \begin_inset LatexCommand \index{\_\_far (storage class)}
16422 \begin_inset LatexCommand \index{at}
16427 \begin_inset LatexCommand \index{\_\_at}
16431 (0x7f00) buf[0x100];
16432 \begin_inset LatexCommand \index{Aligned array}
16438 unsigned char head, tail;\InsetSpace ~
16456 \begin_inset LatexCommand \index{interrupt}
16508 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16520 void to_buffer( unsigned char c )
16528 if( head != (unsigned char)(tail-1)
16535 \begin_inset LatexCommand \index{promotion to signed int}
16540 \begin_inset LatexCommand \index{type promotion}
16545 \begin_inset Marginal
16548 \begin_layout Standard
16567 buf[ head++ ] = c;\InsetSpace ~
16583 /* access to a 256 byte aligned array */
16588 \begin_layout Standard
16589 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16590 then a corresponding buffer.asm file is generated.
16591 We define a new function
16595 in file buffer.c in which we cut and paste the generated code, removing
16596 unwanted comments and some ':'.
16598 \begin_inset Quotes sld
16606 \begin_inset Quotes srd
16610 \begin_inset Quotes sld
16618 \begin_inset Quotes srd
16625 \begin_layout Standard
16626 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16627 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16629 The latter is also used in the library functions.
16634 to the beginning and the end of the function body:
16637 \begin_layout Verse
16641 /* With a cut and paste from the .asm file, we have something to start with.
16647 function is not yet OK! (registers aren't saved) */
16649 void to_buffer_asm(
16659 \begin_inset LatexCommand \index{\_asm}
16664 \begin_inset LatexCommand \index{\_\_asm}
16678 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16684 \begin_inset LatexCommand \index{promotion to signed int}
16689 \begin_inset LatexCommand \index{type promotion}
16742 buf[ head++ ] = c; /* access to a 256 byte aligned array */
16743 \begin_inset LatexCommand \index{Aligned array}
16809 \begin_inset LatexCommand \index{\_endasm}
16814 \begin_inset LatexCommand \index{\_\_endasm}
16823 \begin_layout Standard
16824 The new file buffer.c should compile with only one warning about the unreferenced
16825 function argument 'c'.
16826 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16827 (1) and finally have:
16830 \begin_layout Verse
16834 unsigned char __far __at(0x7f00) buf[0x100];
16836 unsigned char head, tail;
16847 void to_buffer( unsigned char c )
16856 head != (unsigned char)(tail-1) )
16885 c; // to avoid warning: unreferenced function argument
16892 \begin_inset LatexCommand \index{\_asm}
16897 \begin_inset LatexCommand \index{\_\_asm}
16911 ; save used registers here.
16921 ; If we were still using r2,r3 we would have to
16924 ; if( head != (unsigned char)(tail-1) )
16968 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
16993 ; buf[ head++ ] = c;
17004 a,dpl \InsetSpace ~
17011 ; dpl holds lower byte of function
17023 dpl,_head \InsetSpace ~
17026 ; buf is 0x100 byte aligned so head can be used directly
17069 ; we could do an ANL _head,#0x0f here
17070 to use a smaller buffer (see above)
17082 ; restore used registers here
17090 \begin_inset LatexCommand \index{\_endasm}
17095 \begin_inset LatexCommand \index{\_\_endasm}
17106 \begin_layout Standard
17107 The inline assembler code can contain any valid code understood by the assembler
17108 , this includes any assembler directives and comment lines.
17109 The assembler does not like some characters like ':' or ''' in comments.
17110 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17111 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17116 \begin_inset LatexCommand \index{Assembler documentation}
17121 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17129 \begin_layout Standard
17130 The compiler does not do any validation of the code within the
17133 \begin_inset LatexCommand \index{\_asm}
17138 \begin_inset LatexCommand \index{\_\_asm}
17146 \begin_inset LatexCommand \index{\_endasm}
17151 \begin_inset LatexCommand \index{\_\_endasm}
17160 Specifically it will not know which registers are used and thus register
17162 \begin_inset LatexCommand \index{push/pop}
17166 has to be done manually.
17169 \begin_layout Standard
17170 It is recommended that each assembly instruction (including labels) be placed
17171 in a separate line (as the example shows).
17176 \begin_layout Standard
17188 \begin_inset LatexCommand \index{-\/-peep-asm}
17194 command line option is used, the inline assembler code will be passed through
17195 the peephole optimizer
17196 \begin_inset LatexCommand \index{Peephole optimizer}
17201 There are only a few (if any) cases where this option makes sense, it might
17202 cause some unexpected changes in the inline assembler code.
17203 Please go through the peephole optimizer rules defined in file
17207 before using this option.
17210 \begin_layout Subsection
17212 \begin_inset LatexCommand \label{sub:Naked-Functions}
17217 \begin_inset LatexCommand \index{Naked functions}
17224 \begin_layout Standard
17225 A special keyword may be associated with a function declaring it as
17228 \begin_inset LatexCommand \index{\_naked}
17233 \begin_inset LatexCommand \index{\_\_naked}
17243 function modifier attribute prevents the compiler from generating prologue
17244 \begin_inset LatexCommand \index{function prologue}
17249 \begin_inset LatexCommand \index{function epilogue}
17253 code for that function.
17254 This means that the user is entirely responsible for such things as saving
17255 any registers that may need to be preserved, selecting the proper register
17256 bank, generating the
17260 instruction at the end, etc.
17261 Practically, this means that the contents of the function must be written
17262 in inline assembler.
17263 This is particularly useful for interrupt functions, which can have a large
17264 (and often unnecessary) prologue/epilogue.
17265 For example, compare the code generated by these two functions:
17268 \begin_layout Verse
17272 \begin_inset LatexCommand \index{volatile}
17276 data unsigned char counter;
17280 void simpleInterrupt(void) __interrupt
17281 \begin_inset LatexCommand \index{interrupt}
17286 \begin_inset LatexCommand \index{\_\_interrupt}
17304 void nakedInterrupt(void) __interrupt (2) __naked
17313 \begin_inset LatexCommand \index{\_asm}
17318 \begin_inset LatexCommand \index{\_\_asm}
17335 _counter ; does not change flags, no need to save psw
17348 include ret or reti in _naked function.
17355 \begin_inset LatexCommand \index{\_endasm}
17360 \begin_inset LatexCommand \index{\_\_endasm}
17369 \begin_layout Standard
17370 For an 8051 target, the generated simpleInterrupt looks like:
17373 \begin_layout Verse
17380 example, recent versions of SDCC generate
17386 code for simpleInterrupt() and nakedInterrupt()!
17527 \begin_layout Standard
17528 whereas nakedInterrupt looks like:
17531 \begin_layout Verse
17544 _counter ; does not change flags, no need to save psw
17563 MUST explicitly include ret or reti in _naked function
17566 \begin_layout Standard
17567 The related directive #pragma exclude
17568 \begin_inset LatexCommand \index{\#pragma exclude}
17572 allows a more fine grained control over pushing & popping
17573 \begin_inset LatexCommand \index{push/pop}
17580 \begin_layout Standard
17581 While there is nothing preventing you from writing C code inside a
17585 function, there are many ways to shoot yourself in the foot doing this,
17586 and it is recommended that you stick to inline assembler.
17589 \begin_layout Subsection
17590 Use of Labels within Inline Assembler
17593 \begin_layout Standard
17594 SDCC allows the use of in-line assembler with a few restrictions regarding
17596 All labels defined within inline assembler code have to be of the form
17600 where nnnnn is a number less than 100 (which implies a limit of utmost
17601 100 inline assembler labels
17612 \begin_layout Standard
17613 This is a slightly more stringent rule than absolutely necessary, but stays
17614 always on the safe side.
17615 Labels in the form of nnnnn$ are local labels in the assembler, locality
17616 of which is confined within two labels of the standard form.
17617 The compiler uses the same form for labels within a function (but starting
17618 from nnnnn=00100); and places always a standard label at the beginning
17619 of a function, thus limiting the locality of labels within the scope of
17621 So, if the inline assembler part would be embedded into C-code, an improperly
17622 placed non-local label in the assembler would break up the reference space
17623 for labels created by the compiler for the C-code, leading to an assembling
17627 \begin_layout Standard
17628 The numeric part of local labels does not need to have 5 digits (although
17629 this is the form of labels output by the compiler), any valid integer will
17631 Please refer to the assemblers documentation for further details.
17639 \begin_layout Verse
17643 \begin_inset LatexCommand \index{\_asm}
17648 \begin_inset LatexCommand \index{\_\_asm}
17678 \begin_inset LatexCommand \index{\_endasm}
17683 \begin_inset LatexCommand \index{\_\_endasm}
17690 \begin_layout Standard
17691 Inline assembler code cannot reference any C-labels, however it can reference
17693 \begin_inset LatexCommand \index{Labels}
17697 defined by the inline assembler, e.g.:
17700 \begin_layout Verse
17723 ; some assembler code
17746 clabel:\InsetSpace ~
17748 /* inline assembler cannot reference this label */
17752 \begin_layout Standard
17757 is translated by the compiler into a local label, so the locality of labels
17758 within the function is not broken.
17775 0003$: ;label (can be referenced by inline assembler only)
17782 \begin_inset LatexCommand \index{\_endasm}
17787 \begin_inset LatexCommand \index{\_\_endasm}
17797 /* some more c code */
17802 \begin_layout Standard
17803 In other words inline assembly code can access labels defined in inline
17804 assembly within the scope of the function.
17805 The same goes the other way, i.e.
17806 labels defines in inline assembly can not be accessed by C statements.
17809 \begin_layout Section
17810 Interfacing with Assembler Code
17811 \begin_inset LatexCommand \index{Assembler routines}
17818 \begin_layout Subsection
17819 Global Registers used for Parameter Passing
17820 \begin_inset LatexCommand \index{Parameter passing}
17827 \begin_layout Standard
17828 The compiler always uses the global registers
17831 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17836 \begin_inset LatexCommand \index{DPTR}
17841 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17850 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17856 to pass the first (non-bit) parameter to a function, and also to pass the
17858 \begin_inset LatexCommand \index{return value}
17862 of function; according to the following scheme: one byte return value in
17866 , two byte value in
17875 three byte values (generic pointers) in
17887 , and four byte values in
17905 \begin_inset LatexCommand \index{generic pointer}
17909 contain type of accessed memory in
17930 \begin_inset Note Note
17933 \begin_layout Standard
17934 This might not be the case of certain memory models (medium???)
17942 \begin_layout Standard
17943 The second parameter onwards is either allocated on the stack (for reentrant
17948 \begin_layout Standard
17957 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17960 \begin_layout Standard
17961 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
17962 space for reentrant functions or allocated directly in bit memory otherwise.
17965 \begin_layout Standard
17966 Functions (with two or more parameters or bit parameters) that are called
17967 through function pointers
17968 \begin_inset LatexCommand \index{function pointers}
17972 must therefor be reentrant so the compiler knows how to pass the parameters.
17975 \begin_layout Subsection
17979 \begin_layout Standard
17980 Unless the called function is declared as
17985 \begin_inset LatexCommand \index{naked}
17993 \begin_layout Standard
18003 \begin_inset LatexCommand \index{-\/-callee-saves}
18011 \begin_layout Standard
18020 -all-callee-saves command line option or the corresponding callee_saves
18021 pragma are used, the caller will save the registers (
18025 ) around the call, so the called function can destroy they content freely.
18028 \begin_layout Standard
18029 If the called function is not declared as
18033 , the caller will swap register banks around the call, if caller and callee
18034 use different register banks (having them defined by the
18041 \begin_layout Standard
18042 The called function can also use
18058 observing that they are used for parameter/return value passing.
18061 \begin_layout Subsection
18062 Assembler Routine (non-reentrant)
18065 \begin_layout Standard
18066 In the following example
18067 \begin_inset LatexCommand \index{reentrant}
18072 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18076 the function c_func calls an assembler routine asm_func, which takes two
18078 \begin_inset LatexCommand \index{function parameter}
18085 \begin_layout Verse
18088 extern int asm_func(unsigned char, unsigned char);
18092 int c_func (unsigned char
18093 i, unsigned char j)
18101 return asm_func(i,j);
18115 return c_func(10,9);
18120 \begin_layout Standard
18121 The corresponding assembler function is:
18124 \begin_layout Verse
18127 .globl _asm_func_PARM_2
18229 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18246 \begin_layout Standard
18247 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18248 the parameter number starting from 1, and counting from the left.
18249 The first parameter is passed in
18265 according to the description above.
18266 The variable name for the second parameter will be _<function_name>_PARM_2.
18271 ble the assembler routine with the following command:
18278 asx8051 -losg asmfunc.asm
18285 Then compile and link the assembler routine to the C source file with the
18293 sdcc cfunc.c asmfunc.rel
18296 \begin_layout Subsection
18297 Assembler Routine (reentrant)
18300 \begin_layout Standard
18302 \begin_inset LatexCommand \index{reentrant}
18307 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18311 the second parameter
18312 \begin_inset LatexCommand \index{function parameter}
18316 onwards will be passed on the stack, the parameters are pushed from right
18318 before the call the second leftmost parameter will be on the top of the
18319 stack (the leftmost parameter is passed in registers).
18320 Here is an example:
18323 \begin_layout Verse
18326 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18331 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18354 return c_func(10,9,8);
18359 \begin_layout Standard
18360 The corresponding (unoptimized) assembler routine is:
18363 \begin_layout Verse
18383 _bp,sp\InsetSpace ~
18389 ;stack contains: _bp, return address,
18390 second parameter, third parameter
18414 a,#0xfd\InsetSpace ~
18420 pointer to the second parameter
18444 a,#0xfc\InsetSpace ~
18450 to the rightmost parameter
18491 result (= sum of all three parameters)
18506 ;return value goes into dptr
18540 \begin_layout Standard
18541 The compiling and linking procedure remains the same, however note the extra
18542 entry & exit linkage required for the assembler code, _bp is the stack
18543 frame pointer and is used to compute the offset into the stack for parameters
18544 and local variables.
18545 \begin_inset VSpace bigskip
18551 \begin_layout Section
18553 \begin_inset LatexCommand \index{int (16 bit)}
18558 \begin_inset LatexCommand \index{long (32 bit)}
18565 \begin_layout Standard
18566 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18567 multiplication and modulus operations are implemented by support routines.
18568 These support routines are all developed in ANSI-C to facilitate porting
18569 to other MCUs, although some model specific assembler optimizations are
18571 The following files contain the described routines, all of them can be
18572 found in <installdir>/share/sdcc/lib.
18577 \begin_layout Standard
18579 \begin_inset Tabular
18580 <lyxtabular version="3" rows="11" columns="2">
18582 <column alignment="left" valignment="top" leftline="true" width="0">
18583 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18584 <row topline="true" bottomline="true">
18585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18588 \begin_layout Standard
18596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18599 \begin_layout Standard
18608 <row topline="true">
18609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18612 \begin_layout Standard
18618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18621 \begin_layout Standard
18622 16 bit multiplication
18628 <row topline="true">
18629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18632 \begin_layout Standard
18638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18641 \begin_layout Standard
18642 signed 16 bit division (calls _divuint)
18648 <row topline="true">
18649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18652 \begin_layout Standard
18658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18661 \begin_layout Standard
18662 unsigned 16 bit division
18668 <row topline="true">
18669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18672 \begin_layout Standard
18678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18681 \begin_layout Standard
18682 signed 16 bit modulus (calls _moduint)
18688 <row topline="true">
18689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18692 \begin_layout Standard
18698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18701 \begin_layout Standard
18702 unsigned 16 bit modulus
18708 <row topline="true">
18709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18712 \begin_layout Standard
18718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18721 \begin_layout Standard
18722 32 bit multiplication
18728 <row topline="true">
18729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18732 \begin_layout Standard
18738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18741 \begin_layout Standard
18742 signed 32 division (calls _divulong)
18748 <row topline="true">
18749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18752 \begin_layout Standard
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18761 \begin_layout Standard
18762 unsigned 32 division
18768 <row topline="true">
18769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18772 \begin_layout Standard
18778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18781 \begin_layout Standard
18782 signed 32 bit modulus (calls _modulong)
18788 <row topline="true" bottomline="true">
18789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18792 \begin_layout Standard
18798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18801 \begin_layout Standard
18802 unsigned 32 bit modulus
18817 \begin_layout Standard
18818 Since they are compiled as
18823 \begin_inset LatexCommand \index{reentrant}
18828 \begin_inset LatexCommand \index{interrupt}
18832 service routines should not do any of the above operations.
18833 If this is unavoidable then the above routines will need to be compiled
18840 \begin_layout Standard
18850 \begin_inset LatexCommand \index{-\/-stack-auto}
18856 option, after which the source program will have to be compiled with
18862 \begin_layout Standard
18872 \begin_inset LatexCommand \index{-\/-int-long-reent}
18879 Notice that you don't have to call these routines directly.
18880 The compiler will use them automatically every time an integer operation
18884 \begin_layout Section
18885 Floating Point Support
18886 \begin_inset LatexCommand \index{Floating point support}
18893 \begin_layout Standard
18894 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18895 The floating point support routines are derived from gcc's floatlib.c and
18896 consist of the following routines:
18901 \begin_layout Standard
18905 \begin_inset Tabular
18906 <lyxtabular version="3" rows="17" columns="2">
18908 <column alignment="left" valignment="top" leftline="true" width="0">
18909 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18910 <row topline="true" bottomline="true">
18911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18914 \begin_layout Standard
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18932 \begin_layout Standard
18939 <row topline="true">
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18943 \begin_layout Standard
18958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18961 \begin_layout Standard
18971 add floating point numbers
18977 <row topline="true">
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18981 \begin_layout Standard
18996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18999 \begin_layout Standard
19009 subtract floating point numbers
19015 <row topline="true">
19016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19019 \begin_layout Standard
19034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19037 \begin_layout Standard
19047 divide floating point numbers
19053 <row topline="true">
19054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19057 \begin_layout Standard
19072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19075 \begin_layout Standard
19085 multiply floating point numbers
19091 <row topline="true">
19092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19095 \begin_layout Standard
19110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19113 \begin_layout Standard
19123 convert floating point to unsigned char
19129 <row topline="true">
19130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19133 \begin_layout Standard
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19151 \begin_layout Standard
19161 convert floating point to signed char
19167 <row topline="true">
19168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19171 \begin_layout Standard
19186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19189 \begin_layout Standard
19199 convert floating point to unsigned int
19205 <row topline="true">
19206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19209 \begin_layout Standard
19224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19227 \begin_layout Standard
19237 convert floating point to signed int
19243 <row topline="true">
19244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19247 \begin_layout Standard
19270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19273 \begin_layout Standard
19283 convert floating point to unsigned long
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19293 \begin_layout Standard
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19311 \begin_layout Standard
19321 convert floating point to signed long
19327 <row topline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19331 \begin_layout Standard
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19349 \begin_layout Standard
19359 convert unsigned char to floating point
19365 <row topline="true">
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19369 \begin_layout Standard
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19387 \begin_layout Standard
19397 convert char to floating point number
19403 <row topline="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_layout Standard
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19425 \begin_layout Standard
19435 convert unsigned int to floating point
19441 <row topline="true">
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19445 \begin_layout Standard
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19463 \begin_layout Standard
19473 convert int to floating point numbers
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19483 \begin_layout Standard
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19501 \begin_layout Standard
19511 convert unsigned long to floating point number
19517 <row topline="true" bottomline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19521 \begin_layout Standard
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19539 \begin_layout Standard
19549 convert long to floating point number
19564 \begin_layout Standard
19565 These support routines are developed in ANSI-C so there is room for space
19566 and speed improvement
19570 \begin_layout Standard
19571 These floating point routines (
19575 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19581 Note if all these routines are used simultaneously the data space might
19583 For serious floating point usage the large model might be needed.
19584 Also notice that you don't have to call this routines directly.
19585 The compiler will use them automatically every time a floating point operation
19587 \begin_inset VSpace bigskip
19593 \begin_layout Section
19595 \begin_inset LatexCommand \index{Libraries}
19602 \begin_layout Standard
19605 <pending: this is messy and incomplete - a little more information is in
19606 sdcc/doc/libdoc.txt
19611 \begin_layout Subsection
19612 Compiler support routines (_gptrget, _mulint etc.)
19615 \begin_layout Subsection
19616 Stdclib functions (puts, printf, strcat etc.)
19619 \begin_layout Subsubsection
19623 \begin_layout Paragraph
19624 getchar(), putchar()
19627 \begin_layout Standard
19628 \begin_inset LatexCommand \index{<stdio.h>}
19632 As usual on embedded systems you have to provide your own
19635 \begin_inset LatexCommand \index{getchar()}
19644 \begin_inset LatexCommand \index{putchar()}
19651 SDCC does not know whether the system connects to a serial line with or
19652 without handshake, LCD, keyboard or other device.
19666 You'll find examples for serial routines f.e.
19667 in sdcc/device/lib.
19668 For the mcs51 this minimalistic polling
19672 routine might be a start:
19675 \begin_layout Verse
19678 void putchar (char c) {
19684 while (!TI)\InsetSpace ~
19687 /* assumes UART is initialized */
19715 \begin_layout Paragraph
19719 \begin_layout Standard
19723 \begin_inset LatexCommand \index{printf()}
19733 does not support float (except on ds390).
19734 To enable this recompile it with the option
19740 \begin_layout Standard
19750 \begin_inset LatexCommand \index{USE\_FLOATS}
19756 on the command line.
19763 \begin_layout Standard
19773 \begin_inset LatexCommand \index{-\/-model-large}
19779 for the mcs51 port, since this uses a lot of memory.
19782 \begin_layout Standard
19783 If you're short on code memory you might want to use
19786 \begin_inset LatexCommand \index{printf\_small()}
19800 For the mcs51 there additionally are assembly versions
19803 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19809 (subset of printf using less than 270 bytes) and
19812 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19821 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19827 (floating-point aware version of printf_fast) which should fit the requirements
19828 of many embedded systems (printf_fast() can be customized by unsetting
19833 support long variables and field widths).
19834 Be sure to use only one of these printf options within a project.
19839 \begin_layout Standard
19840 Feature matrix of different
19847 \begin_layout Standard
19848 \begin_inset Tabular
19849 <lyxtabular version="3" rows="14" columns="7">
19850 <features islongtable="true">
19851 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19852 <column alignment="center" valignment="top" leftline="true" width="0">
19853 <column alignment="center" valignment="top" leftline="true" width="12col%">
19854 <column alignment="center" valignment="top" leftline="true" width="10col%">
19855 <column alignment="center" valignment="top" leftline="true" width="0">
19856 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19857 <column alignment="center" valignment="top" rightline="true" width="0">
19858 <row topline="true" bottomline="true" endhead="true">
19859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19862 \begin_layout Standard
19871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_layout Standard
19876 \begin_inset LatexCommand \index{printf}
19885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19888 \begin_layout Standard
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19899 \begin_layout Standard
19905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19908 \begin_layout Standard
19914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19917 \begin_layout Standard
19923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19926 \begin_layout Standard
19933 <row topline="true" endhead="true">
19934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19937 \begin_layout Standard
19943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19946 \begin_layout Standard
19954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19957 \begin_layout Standard
19965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19968 \begin_layout Standard
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_layout Standard
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19990 \begin_layout Standard
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20001 \begin_layout Standard
20010 <row topline="true" endhead="true">
20011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20014 \begin_layout Standard
20015 \begin_inset Quotes sld
20019 \begin_inset Quotes srd
20025 \begin_layout Standard
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20034 \begin_layout Standard
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20043 \begin_layout Standard
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20052 \begin_layout Standard
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20061 \begin_layout Standard
20067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_layout Standard
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20079 \begin_layout Standard
20086 <row topline="true" endhead="true">
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20090 \begin_layout Standard
20094 \begin_layout Standard
20100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20103 \begin_layout Standard
20109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20112 \begin_layout Standard
20118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20121 \begin_layout Standard
20122 0.45k / 0.47k (+ _ltoa)
20127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20130 \begin_layout Standard
20136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20139 \begin_layout Standard
20145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20148 \begin_layout Standard
20155 <row topline="true">
20156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_layout Standard
20165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20168 \begin_layout Standard
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20181 \begin_layout Standard
20228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20231 \begin_layout Standard
20270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20273 \begin_layout Standard
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20282 \begin_layout Standard
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20291 \begin_layout Standard
20298 <row topline="true">
20299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20302 \begin_layout Standard
20303 long (32 bit) support
20308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20311 \begin_layout Standard
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20320 \begin_layout Standard
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20329 \begin_layout Standard
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20338 \begin_layout Standard
20344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20347 \begin_layout Standard
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20365 \begin_layout Standard
20372 <row topline="true">
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20376 \begin_layout Standard
20377 byte arguments on stack
20382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20385 \begin_layout Standard
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_layout Standard
20400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 \begin_layout Standard
20409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20412 \begin_layout Standard
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20421 \begin_layout Standard
20427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20430 \begin_layout Standard
20437 <row topline="true">
20438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20441 \begin_layout Standard
20443 \begin_inset LatexCommand \index{Floating point support}
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 \begin_layout Standard
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_layout Standard
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_layout Standard
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_layout Standard
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_layout Standard
20496 \begin_layout Standard
20497 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20510 \begin_layout Standard
20517 <row topline="true">
20518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20521 \begin_layout Standard
20522 float formats %e %g
20527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20530 \begin_layout Standard
20536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20539 \begin_layout Standard
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" rightline="true" usebox="none">
20566 \begin_layout Standard
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20575 \begin_layout Standard
20582 <row topline="true" bottomline="true">
20583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20586 \begin_layout Standard
20592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20595 \begin_layout Standard
20601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20604 \begin_layout Standard
20610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20613 \begin_layout Standard
20619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20622 \begin_layout Standard
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20631 \begin_layout Standard
20637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20640 \begin_layout Standard
20647 <row bottomline="true">
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20651 \begin_layout Standard
20656 \begin_layout Standard
20657 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20661 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20669 \begin_layout Standard
20675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20678 \begin_layout Standard
20684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20687 \begin_layout Standard
20693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20696 \begin_layout Standard
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20705 \begin_layout Standard
20711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20714 \begin_layout Standard
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20723 \begin_layout Standard
20730 <row bottomline="true">
20731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20734 \begin_layout Standard
20739 \begin_layout Standard
20740 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
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" usebox="none">
20794 \begin_layout Standard
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20803 \begin_layout Standard
20808 \begin_layout Standard
20809 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20820 <row bottomline="true">
20821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20824 \begin_layout Standard
20829 \begin_layout Standard
20830 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20839 \begin_layout Standard
20845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20848 \begin_layout Standard
20854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20857 \begin_layout Standard
20863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20866 \begin_layout Standard
20872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20875 \begin_layout Standard
20881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20884 \begin_layout Standard
20890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20893 \begin_layout Standard
20900 <row bottomline="true">
20901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20904 \begin_layout Standard
20909 \begin_layout Standard
20910 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20919 \begin_layout Standard
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20928 \begin_layout Standard
20934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20937 \begin_layout Standard
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_layout Standard
20952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20955 \begin_layout Standard
20961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20964 \begin_layout Standard
20970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20973 \begin_layout Standard
20987 \begin_layout Subsubsection
20989 \begin_inset LatexCommand \index{malloc.h}
20996 \begin_layout Standard
20997 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20998 using dynamic memory allocation
20999 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21004 \begin_inset LatexCommand \index{heap (malloc)}
21008 space of 1024 bytes is provided for malloc to allocate memory from.
21009 If you need a different heap size you need to recompile _heap.c with the
21010 required size defined in HEAP_SIZE.
21011 It is recommended to make a copy of this file into your project directory
21012 and compile it there with:
21015 \begin_layout Verse
21018 sdcc -c _heap.c -D HEAD_SIZE=2048
21021 \begin_layout Standard
21022 And then link it with:
21025 \begin_layout Verse
21028 sdcc main.rel _heap.rel
21031 \begin_layout Subsection
21032 Math functions (sinf, powf, sqrtf etc.)
21035 \begin_layout Subsubsection
21039 \begin_layout Standard
21040 See definitions in file <math.h>.
21043 \begin_layout Subsection
21047 \begin_layout Standard
21049 \begin_inset LatexCommand \index{Libraries}
21053 included in SDCC should have a license at least as liberal as the GNU Lesser
21054 General Public License
21055 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21066 \begin_layout Standard
21067 \begin_inset Note Note
21070 \begin_layout Standard
21071 license statements for the libraries are missing.
21072 sdcc/device/lib/ser_ir.c
21075 \begin_layout Standard
21077 come with a GPL (as opposed to LGPL) License - this will not be liberal
21078 enough for many embedded programmers.
21086 \begin_layout Standard
21087 If you have ported some library or want to share experience about some code
21089 falls into any of these categories Busses (I
21090 \begin_inset Formula $^{\textrm{2}}$
21093 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21094 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21095 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21096 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21101 would certainly like to hear about it.
21104 \begin_layout Standard
21105 Programmers coding for embedded systems are not especially famous for being
21106 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21107 e these references are very valuable.
21108 Let's help to create a climate where information is shared.
21109 \begin_inset VSpace bigskip
21115 \begin_layout Section
21119 \begin_layout Subsection
21120 MCS51 Memory Models
21121 \begin_inset LatexCommand \index{Memory model}
21126 \begin_inset LatexCommand \index{MCS51 memory model}
21133 \begin_layout Subsubsection
21134 Small, Medium and Large
21137 \begin_layout Standard
21138 SDCC allows three memory models for MCS51 code,
21147 Modules compiled with different memory models should
21151 be combined together or the results would be unpredictable.
21152 The library routines supplied with the compiler are compiled as small,
21154 The compiled library modules are contained in separate directories as small,
21155 medium and large so that you can link to the appropriate set.
21158 \begin_layout Standard
21159 When the medium or large model is used all variables declared without a
21160 storage class will be allocated into the external ram, this includes all
21161 parameters and local variables (for non-reentrant
21162 \begin_inset LatexCommand \index{reentrant}
21167 When the small model is used variables without storage class are allocated
21168 in the internal ram.
21171 \begin_layout Standard
21172 Judicious usage of the processor specific storage classes
21173 \begin_inset LatexCommand \index{Storage class}
21177 and the 'reentrant' function type will yield much more efficient code,
21178 than using the large model.
21179 Several optimizations are disabled when the program is compiled using the
21180 large model, it is therefore recommended that the small model be used unless
21181 absolutely required.
21184 \begin_layout Subsubsection
21186 \begin_inset LatexCommand \label{sub:External-Stack}
21191 \begin_inset LatexCommand \index{stack}
21196 \begin_inset LatexCommand \index{External stack (mcs51)}
21203 \begin_layout Standard
21204 The external stack (-
21208 \begin_layout Standard
21218 \begin_inset LatexCommand \index{-\/-xstack}
21222 ) is located in pdata
21223 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21227 memory (usually at the start of the external ram segment) and uses all
21228 unused space in pdata (max.
21234 \begin_layout Standard
21243 -xstack option is used to compile the program, the parameters and local
21245 \begin_inset LatexCommand \index{local variables}
21249 of all reentrant functions are allocated in this area.
21250 This option is provided for programs with large stack space requirements.
21251 When used with the -
21255 \begin_layout Standard
21265 \begin_inset LatexCommand \index{-\/-stack-auto}
21269 option, all parameters and local variables are allocated on the external
21270 stack (note: support libraries will need to be recompiled with the same
21272 There is a predefined target in the library makefile).
21275 \begin_layout Standard
21276 The compiler outputs the higher order address byte of the external ram segment
21278 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21283 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21287 ), therefore when using the External Stack option, this port
21291 be used by the application program.
21294 \begin_layout Subsection
21296 \begin_inset LatexCommand \index{Memory model}
21301 \begin_inset LatexCommand \index{DS390 memory model}
21308 \begin_layout Standard
21309 The only model supported is Flat 24
21310 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21315 This generates code for the 24 bit contiguous addressing mode of the Dallas
21317 In this mode, up to four meg of external RAM or code space can be directly
21319 See the data sheets at www.dalsemi.com for further information on this part.
21324 that the compiler does not generate any code to place the processor into
21325 24 bitmode (although
21329 in the ds390 libraries will do that for you).
21335 \begin_inset LatexCommand \index{Tinibios (DS390)}
21339 , the boot loader or similar code must ensure that the processor is in 24
21340 bit contiguous addressing mode before calling the SDCC startup code.
21351 \begin_layout Standard
21362 option, variables will by default be placed into the XDATA segment.
21367 may be placed anywhere in the 4 meg address space using the usual -
21371 \begin_layout Standard
21381 Note that if any segments are located above 64K, the -r flag must be passed
21382 to the linker to generate the proper segment relocations, and the Intel
21383 HEX output format must be used.
21384 The -r flag can be passed to the linker by using the option
21388 on the SDCC command line.
21389 However, currently the linker can not handle code segments > 64k.
21392 \begin_layout Section
21394 \begin_inset LatexCommand \label{sec:Pragmas}
21399 \begin_inset LatexCommand \index{Pragmas}
21406 \begin_layout Standard
21407 Pragmas are used to turn on and/or off certain compiler options.
21408 Some of them are closely related to corresponding command-line options
21410 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21416 Pragmas should be placed before and/or after a function, placing pragmas
21417 inside a function body could have unpredictable results.
21422 following #pragma directives:
21425 \begin_layout Itemize
21431 \begin_inset LatexCommand \index{\#pragma save}
21435 - this will save most current options to the save/restore stack.
21436 See #pragma\InsetSpace ~
21440 \begin_layout Itemize
21446 \begin_inset LatexCommand \index{\#pragma restore}
21450 - will restore saved options from the last save.
21451 saves & restores can be nested.
21452 SDCC uses a save/restore stack: save pushes current options to the stack,
21453 restore pulls current options from the stack.
21454 See #pragma\InsetSpace ~
21460 \begin_layout Itemize
21466 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21471 \begin_inset LatexCommand \index{function prologue}
21475 function1[,function2[,function3...]]
21476 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21480 - The compiler by default uses a caller saves convention for register saving
21481 across function calls, however this can cause unnecessary register pushing
21483 \begin_inset LatexCommand \index{push/pop}
21487 when calling small functions from larger functions.
21488 This option can be used to switch off the register saving convention for
21489 the function names specified.
21490 The compiler will not save registers when calling these functions, extra
21491 code need to be manually inserted at the entry and exit for these functions
21492 to save and restore the registers used by these functions, this can SUBSTANTIAL
21493 LY reduce code and improve run time performance of the generated code.
21494 In the future the compiler (with inter procedural analysis) may be able
21495 to determine the appropriate scheme to use for each function call.
21500 \begin_layout Standard
21509 -callee-saves command line option is used (see page
21510 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21514 ), the function names specified in #pragma\InsetSpace ~
21516 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21520 is appended to the list of functions specified in the command line.
21523 \begin_layout Itemize
21529 \begin_inset LatexCommand \index{\#pragma exclude}
21533 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21534 of pairs of push/pop
21535 \begin_inset LatexCommand \index{push/pop}
21544 \begin_inset LatexCommand \index{interrupt}
21557 The directive should be placed immediately before the ISR function definition
21558 and it affects ALL ISR functions following it.
21559 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21560 exclude\InsetSpace ~
21562 \begin_inset LatexCommand \index{\#pragma exclude}
21567 See also the related keyword _naked
21568 \begin_inset LatexCommand \index{\_naked}
21573 \begin_inset LatexCommand \index{\_\_naked}
21580 \begin_layout Itemize
21586 \begin_inset LatexCommand \index{pedantic}
21591 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21596 \begin_inset LatexCommand \label{ite:less_pedantic}
21600 - the compiler will not warn you anymore for obvious mistakes, you're on
21602 See also the command line option -
21606 \begin_layout Standard
21616 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21622 More specifically, the following warnings will be disabled:
21624 comparison is always [true/false] due to limited range of data type
21628 overflow in implicit constant conversion
21630 (158); [the (in)famous]
21632 conditional flow changed by optimizer: so said EVELYN the modified DOG
21636 function '[function name]' must return value
21640 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21641 level) are disabled, too, namely:
21644 \begin_inset Note Note
21647 \begin_layout Standard
21648 dunno what comes here - this warning appears to be unused altogether
21657 [left/right] shifting more than size of object changed to zero
21665 integer overflow in expression
21669 unmatched #pragma save and #pragma restore
21673 comparison of 'signed char' with 'unsigned char' requires promotion to int
21677 ISO C90 does not support flexible array members
21681 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21685 \begin_inset Note Note
21688 \begin_layout Standard
21689 appears to be always blank - what was supposed to be here?
21698 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21699 complexity [number]
21704 \begin_layout Itemize
21710 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21714 - the compiler will not warn you anymore about warning number <nnnn>.
21717 \begin_layout Itemize
21723 \begin_inset LatexCommand \index{\#pragma nogcse}
21727 - will stop global common subexpression elimination.
21730 \begin_layout Itemize
21736 \begin_inset LatexCommand \index{\#pragma noinduction}
21740 - will stop loop induction optimizations.
21743 \begin_layout Itemize
21749 \begin_inset LatexCommand \index{\#pragma noinvariant}
21753 - will not do loop invariant optimizations.
21754 For more details see Loop Invariants in section
21755 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21762 \begin_layout Itemize
21768 \begin_inset LatexCommand \index{\#pragma noiv}
21772 - Do not generate interrupt
21773 \begin_inset LatexCommand \index{interrupt}
21778 \begin_inset LatexCommand \index{interrupt vector table}
21782 entries for all ISR functions defined after the pragma.
21783 This is useful in cases where the interrupt vector table must be defined
21784 manually, or when there is a secondary, manually defined interrupt vector
21786 for the autovector feature of the Cypress EZ-USB FX2).
21787 More elegantly this can be achieved by obmitting the optional interrupt
21788 number after the interrupt keyword, see section
21789 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21797 \begin_layout Itemize
21803 \begin_inset LatexCommand \index{\#pragma nojtbound}
21807 - will not generate code for boundary value checking, when switch statements
21808 are turned into jump-tables (dangerous).
21809 For more details see section
21810 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21817 \begin_layout Itemize
21823 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21827 - Will not do loop reversal optimization
21830 \begin_layout Itemize
21836 \begin_inset LatexCommand \index{\#pragma nooverlay}
21840 - the compiler will not overlay the parameters and local variables of a
21844 \begin_layout Itemize
21850 \begin_inset LatexCommand \index{\#pragma stackauto}
21858 \begin_layout Standard
21868 \begin_inset LatexCommand \index{-\/-stack-auto}
21873 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21877 Parameters and Local Variables.
21880 \begin_layout Itemize
21886 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21890 - The compiler will optimize code generation towards fast code, possibly
21891 at the expense of code size.
21892 Currently this has little effect.
21895 \begin_layout Itemize
21901 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21905 - The compiler will optimize code generation towards compact code, possibly
21906 at the expense of code speed.
21907 Currently this has little effect.
21910 \begin_layout Itemize
21916 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21920 - The compiler will attempt to generate code that is both compact and fast,
21921 as long as meeting one goal is not a detriment to the other (this is the
21925 \begin_layout Itemize
21931 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21935 - Generally follow the C89 standard, but allow SDCC features that conflict
21936 with the standard (default).
21939 \begin_layout Itemize
21945 \begin_inset LatexCommand \index{\#pragma std\_c89}
21949 - Follow the C89 standard and disable SDCC features that conflict with the
21953 \begin_layout Itemize
21959 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21963 - Generally follow the C99 standard, but allow SDCC features that conflict
21964 with the standard (incomplete support).
21967 \begin_layout Itemize
21973 \begin_inset LatexCommand \index{\#pragma std\_c99}
21977 - Follow the C99 standard and disable SDCC features that conflict with the
21978 standard (incomplete support).
21981 \begin_layout Itemize
21987 \begin_inset LatexCommand \index{\#pragma codeseg}
21991 - Use this name (max.
21992 8 characters) for the code segment.
21997 \begin_layout Standard
22009 \begin_layout Itemize
22015 \begin_inset LatexCommand \index{\#pragma constseg}
22019 - Use this name (max.
22020 8 characters) for the const segment.
22025 \begin_layout Standard
22037 \begin_layout Standard
22038 The preprocessor SDCPP
22039 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22043 supports the following #pragma directives:
22046 \begin_layout Itemize
22049 pedantic_parse_number
22052 \begin_inset LatexCommand \index{pedantic}
22057 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22062 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22066 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22067 properly and the macro LO_B(3) gets expanded.
22073 \begin_layout Standard
22082 -pedantic-parse-number command line option
22083 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22089 Below is an example on how to use this pragma.
22092 Note: this functionality is not in conformance with standard!
22095 \begin_layout Verse
22098 #pragma pedantic_parse_number +
22099 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22107 #define LO_B(x) ((x) & 0xff)
22111 unsigned char foo(void)
22118 unsigned char c=0xfe-LO_B(3)
22133 \begin_layout Itemize
22139 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22143 (+ | -) - switch _asm _endasm block preprocessing on / off.
22145 You use this prama to define multilines of assembly code.
22146 This will prevent the preprocessor from changing the formating required
22148 Below is an example on how to use this pragma.
22151 \begin_layout Verse
22154 #pragma preproc_asm -
22155 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22161 #define MYDELAY _asm
22166 nop ;my assembly comment...
22180 #pragma preproc_asm
22209 \begin_layout Itemize
22215 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22219 (+ | -) - Allow "naked" hash in macro definition, for example:
22223 #define DIR_LO(x) #(x & 0xff)
22228 Below is an example on how to use this pragma.
22231 \begin_layout Verse
22234 #pragma preproc_asm +
22236 #pragma sdcc_hash +
22237 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22252 mov R6_B3, #(x & 0xff)
22259 mov R7_B3, #((x >> 8) & 0xff)
22283 \begin_layout Standard
22284 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22285 ons which might cause the compiler to generate extra stack and/or data space
22286 to store compiler generated temporary variables.
22287 This usually happens in large functions.
22288 Pragma directives should be used as shown in the following example, they
22289 are used to control options and optimizations for a given function.
22292 \begin_layout Verse
22296 \begin_inset LatexCommand \index{\#pragma save}
22307 /* save the current settings */
22310 \begin_inset LatexCommand \index{\#pragma nogcse}
22319 /* turnoff global subexpression elimination */
22321 #pragma noinduction
22322 \begin_inset LatexCommand \index{\#pragma noinduction}
22326 /* turn off induction optimizations */
22348 \begin_inset LatexCommand \index{\#pragma restore}
22352 /* turn the optimizations back on */
22355 \begin_layout Standard
22356 The compiler will generate a warning message when extra space is allocated.
22357 It is strongly recommended that the save and restore pragmas be used when
22358 changing options for a function.
22367 \begin_layout Section
22368 Defines Created by the Compiler
22371 \begin_layout Standard
22372 The compiler creates the following #defines
22373 \begin_inset LatexCommand \index{\#defines}
22378 \begin_inset LatexCommand \index{Defines created by the compiler}
22387 \begin_layout Standard
22388 \begin_inset Tabular
22389 <lyxtabular version="3" rows="11" columns="2">
22391 <column alignment="left" valignment="top" leftline="true" width="3in">
22392 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22393 <row topline="true" bottomline="true">
22394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22397 \begin_layout Standard
22405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22408 \begin_layout Standard
22417 <row topline="true">
22418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22421 \begin_layout Standard
22423 \begin_inset LatexCommand \index{SDCC}
22432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22435 \begin_layout Standard
22437 Since version 2.5.6 the version number as an int (ex.
22444 <row topline="true">
22445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22448 \begin_layout Standard
22450 \begin_inset LatexCommand \index{SDCC\_mcs51}
22455 \begin_inset LatexCommand \index{SDCC\_ds390}
22460 \begin_inset LatexCommand \index{SDCC\_z80}
22469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22472 \begin_layout Standard
22473 depending on the model used (e.g.: -mds390)
22479 <row topline="true">
22480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22483 \begin_layout Standard
22485 \begin_inset LatexCommand \index{\_\_mcs51}
22490 \begin_inset LatexCommand \index{\_\_ds390}
22495 \begin_inset LatexCommand \index{\_\_hc08}
22500 \begin_inset LatexCommand \index{\_\_z80}
22509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22512 \begin_layout Standard
22513 depending on the model used (e.g.
22520 <row topline="true">
22521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22524 \begin_layout Standard
22526 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22538 \begin_layout Standard
22545 \begin_layout Standard
22562 <row topline="true">
22563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22566 \begin_layout Standard
22568 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22580 \begin_layout Standard
22587 \begin_layout Standard
22604 <row topline="true">
22605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22608 \begin_layout Standard
22610 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22622 \begin_layout Standard
22629 \begin_layout Standard
22646 <row topline="true">
22647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22650 \begin_layout Standard
22652 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22664 \begin_layout Standard
22671 \begin_layout Standard
22688 <row topline="true">
22689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22692 \begin_layout Standard
22694 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22706 \begin_layout Standard
22713 \begin_layout Standard
22730 <row topline="true">
22731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22734 \begin_layout Standard
22736 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22748 \begin_layout Standard
22759 <row topline="true" bottomline="true">
22760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22763 \begin_layout Standard
22765 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 \begin_layout Standard
22795 \begin_layout Chapter
22796 Notes on supported Processors
22799 \begin_layout Section
22801 \begin_inset LatexCommand \label{sub:MCS51-variants}
22806 \begin_inset LatexCommand \index{MCS51 variants}
22813 \begin_layout Standard
22814 MCS51 processors are available from many vendors and come in many different
22816 While they might differ considerably in respect to Special Function Registers
22817 the core MCS51 is usually not modified or is kept compatible.
22820 \begin_layout Subsection
22821 pdata access by SFR
22824 \begin_layout Standard
22825 With the upcome of devices with internal xdata and flash memory devices
22827 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22831 as dedicated I/O port is becoming more popular.
22832 Switching the high byte for pdata
22833 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22837 access which was formerly done by port P2 is then achieved by a Special
22839 \begin_inset LatexCommand \index{sfr}
22844 In well-established MCS51 tradition the address of this
22848 is where the chip designers decided to put it.
22849 Needless to say that they didn't agree on a common name either.
22850 So that the startup code can correctly initialize xdata variables, you
22851 should define an sfr with the name _XPAGE
22854 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22860 at the appropriate location if the default, port P2, is not used for this.
22864 \begin_layout Verse
22867 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22871 \begin_layout Verse
22874 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22879 \begin_layout Verse
22882 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22886 \begin_layout Verse
22889 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22893 \begin_layout Verse
22896 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22900 \begin_layout Standard
22901 For more exotic implementations further customizations may be needed.
22903 \begin_inset LatexCommand \ref{sub:Startup-Code}
22907 for other possibilities.
22910 \begin_layout Subsection
22911 Other Features available by SFR
22914 \begin_layout Standard
22915 Some MCS51 variants offer features like Double DPTR
22916 \begin_inset LatexCommand \index{DPTR}
22920 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22921 These are currently not used for the MCS51 port.
22922 If you absolutely need them you can fall back to inline assembly or submit
22924 \begin_inset VSpace bigskip
22930 \begin_layout Section
22934 \begin_layout Standard
22936 \begin_inset LatexCommand \index{DS80C400}
22941 \begin_inset LatexCommand \index{DS400}
22945 microcontroller has a rich set of peripherals.
22946 In its built-in ROM library it includes functions to access some of the
22947 features, among them is a TCP stack with IP4 and IP6 support.
22948 Library headers (currently in beta status) and other files are provided
22952 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22957 \begin_inset VSpace bigskip
22963 \begin_layout Section
22964 The Z80 and gbz80 port
22967 \begin_layout Standard
22968 SDCC can target both the Zilog Z80
22969 \begin_inset LatexCommand \index{Z80}
22973 and the Nintendo Gameboy's Z80-like gbz80
22974 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22979 The Z80 port is passed through the same
22982 \begin_inset LatexCommand \index{Regression test}
22989 \begin_inset LatexCommand \ref{sec:Quality-control}
22993 ) as the MCS51 and DS390 ports, so floating point support, support for long
22994 variables and bitfield support is fine.
22995 See mailing lists and forums about interrupt routines.
22998 \begin_layout Standard
22999 As always, the code is the authoritative reference - see z80/ralloc.c and
23002 \begin_inset LatexCommand \index{Z80!stack}
23006 frame is similar to that generated by the IAR Z80 compiler.
23007 IX is used as the base pointer, HL and IY are used as a temporary registers,
23008 and BC and DE are available for holding variables.
23010 \begin_inset LatexCommand \index{Z80!return value}
23014 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23016 The gbz80 port use the same set of registers for the return values, but
23017 in a different order of significance: E (one byte), DE (two bytes), or
23019 \begin_inset VSpace bigskip
23025 \begin_layout Section
23029 \begin_layout Standard
23030 The port to the Freescale/Motorola HC08
23031 \begin_inset LatexCommand \index{HC08}
23035 family has been added in October 2003, and is still undergoing some basic
23037 The code generator is complete, but the register allocation is still quite
23039 Some of the SDCC's standard C library functions have embedded non-HC08
23040 inline assembly and so are not yet usable.
23043 \begin_layout Standard
23044 The HC08 port passes the regression test suite (see section
23045 \begin_inset LatexCommand \ref{sec:Quality-control}
23050 \begin_inset VSpace bigskip
23058 \begin_layout Section
23060 \begin_inset LatexCommand \index{PIC14}
23067 \begin_layout Standard
23068 The PIC14 port adds support for Microchip
23069 \begin_inset LatexCommand \index{Microchip}
23074 \begin_inset Formula $^{\text{TM}}$
23078 \begin_inset LatexCommand \index{PIC14}
23083 \begin_inset Formula $^{\text{TM}}$
23086 MCUs with 14 bit wide instructions.
23087 This port is not yet mature and still lacks many features.
23088 However, it can work for simple code.
23091 \begin_layout Standard
23092 Currently supported devices include:
23095 \begin_layout Standard
23096 12F: 629, 635, 675, 683
23099 \begin_layout Standard
23103 \begin_layout Standard
23107 \begin_layout Standard
23108 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23111 \begin_layout Standard
23112 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23116 \begin_layout Standard
23120 \begin_layout Standard
23121 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23125 \begin_layout Standard
23126 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23129 \begin_layout Standard
23130 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23134 \begin_layout Standard
23135 16F: 913, 914, 916, 917
23138 \begin_layout Standard
23139 An up-to-date list of currently supported devices can be obtained via
23141 sdcc -mpic14 -phelp foo.c
23143 (foo.c must exist...).
23146 \begin_layout Subsection
23148 \begin_inset LatexCommand \index{code page (pic14)}
23153 \begin_inset LatexCommand \index{Memory bank (pic14)}
23160 \begin_layout Standard
23161 The linker organizes allocation for the code page and RAM banks.
23162 It does not have intimate knowledge of the code flow.
23163 It will put all the code section of a single .asm file into a single code
23165 In order to make use of multiple code pages, separate asm files must be
23167 The compiler assigns all
23171 functions of a single .c file into the same code page.
23175 To get the best results,
23176 follow these guidelines:
23179 \begin_layout Enumerate
23180 Make local functions static, as non static functions require code page selection
23183 Due to the way sdcc handles functions, place called functions prior
23184 to calling functions in the file wherever possible: Otherwise sdcc will
23185 insert unneccessary pagesel directives around the call, believing that
23186 the called function is externally defined.
23189 \begin_layout Enumerate
23190 For devices that have multiple code pages it is more efficient to use the
23191 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23192 but only 2 files for the 16F874.
23193 This way the linker can put the code for each file into different code
23194 pages and there will be less page selection overhead.
23197 \begin_layout Enumerate
23198 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23199 instruction set), use `unsigned char' wherever possible instead of `int'.
23202 \begin_layout Subsection
23203 Adding New Devices to the Port
23206 \begin_layout Standard
23207 Adding support for a new 14
23211 \begin_layout Standard
23220 bit PIC MCU requires the following steps:
23223 \begin_layout Enumerate
23224 Create a new device description.
23226 Each device is described in two files: pic16f*.h
23228 These files primarily define SFRs, structs to access their bits, and symbolic
23229 configuration options.
23230 Both files can be generated from gputils' .inc files using the perl script
23232 support/scripts/inc2h.pl
23235 This file also contains further instructions on how to proceed.
23238 \begin_layout Enumerate
23239 Copy the .h file into SDCC's include path and either add the .c file to your
23240 project or copy it to
23242 device/lib/pic/libdev
23245 Afterwards, rebuild and install the libraries.
23248 \begin_layout Enumerate
23249 Edit pic14devices.txt in SDCC's include path (
23251 device/include/pic/
23253 in the source tree or
23255 /usr/local/share/sdcc/include/pic
23257 after installation).
23259 You need to add a device specification here to make
23260 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23262 Probably you can copy and modify an existing entry.
23263 The file format is documented at the top of the file.
23266 \begin_layout Subsection
23270 \begin_layout Standard
23271 For the interrupt function, use the keyword `__interrupt'
23272 \begin_inset LatexCommand \index{PIC14!interrupt}
23276 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23277 there to avoid a syntax error - it ought to be fixed).
23281 \begin_layout Verse
23284 void Intr(void) __interrupt 0
23290 T0IF = 0; /* Clear timer interrupt */
23295 \begin_layout Subsection
23296 Linking and Assembling
23299 \begin_layout Standard
23300 For assembling you can use either GPUTILS'
23301 \begin_inset LatexCommand \index{gputils (pic tools)}
23305 gpasm.exe or MPLAB's mpasmwin.exe.
23306 GPUTILS are available from
23307 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23312 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23313 If you use MPLAB and an interrupt function then the linker script file
23314 vectors section will need to be enlarged to link with mplink.
23325 \begin_layout Verse
23338 sdcc -V -mpic14 -p16f877 -c $<
23342 $(PRJ).hex: $(OBJS)
23352 gplink -m -s $(PRJ).lkr
23353 -o $(PRJ).hex $(OBJS) libsdcc.lib
23356 \begin_layout Standard
23364 \begin_layout Verse
23377 sdcc -S -V -mpic14 -p16f877 $<
23387 mpasmwin /q /o $*.asm
23391 $(PRJ).hex: $(OBJS)
23402 /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23405 \begin_layout Standard
23406 Please note that indentations within a
23410 have to be done with a tabulator character.
23413 \begin_layout Subsection
23414 Command-Line Options
23417 \begin_layout Standard
23418 Besides the switches common to all SDCC backends, the PIC14 port accepts
23419 the following options (for an updated list see sdcc -
23423 \begin_layout Standard
23435 \begin_layout Description
23440 \begin_layout Standard
23450 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23454 emit debug info in assembly output
23457 \begin_layout Description
23462 \begin_layout Standard
23472 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23476 disable (slightly faulty) optimization on pCode
23479 \begin_layout Description
23484 \begin_layout Standard
23494 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23498 sets the lowest address of the argument passing stack (defaults to a suitably
23499 large shared databank to reduce BANKSEL overhead)
23502 \begin_layout Description
23507 \begin_layout Standard
23517 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23521 sets the size if the argument passing stack (default: 16, minimum: 4)
23524 \begin_layout Subsection
23525 Environment Variables
23528 \begin_layout Standard
23529 The PIC14 port recognizes the following environment variables:
23532 \begin_layout Description
23533 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23534 register (the ones called r0xNNNN) in a section of its own.
23535 By default (if this variable is unset), sdcc tries to cluster registers
23536 in sections in order to reduce the BANKSEL overhead when accessing them.
23539 \begin_layout Subsection
23543 \begin_layout Standard
23544 The PIC14 library currently only contains support routines required by the
23545 compiler to implement multiplication, division, and floating point support.
23546 No libc-like replacement is available at the moment, though many of the
23547 common sdcc library sources (in
23551 ) should also compile with the PIC14 port.
23554 \begin_layout Subsubsection
23555 error: missing definition for symbol ``__gptrget1''
23558 \begin_layout Standard
23559 The PIC14 port uses library routines to provide more complex operations
23560 like multiplication, division/modulus and (generic) pointer dereferencing.
23561 In order to add these routines to your project, you must link with PIC14's
23566 For single source file projects this is done automatically, more complex
23571 to the linker's arguments.
23572 Make sure you also add an include path for the library (using the -I switch
23576 \begin_layout Subsubsection
23577 Processor mismatch in file ``XXX''.
23580 \begin_layout Standard
23581 This warning can usually be ignored due to the very good compatibility amongst
23586 \begin_layout Standard
23596 \begin_inset LatexCommand \index{PIC14}
23603 \begin_layout Standard
23604 You might also consider recompiling the library for your specific device
23605 by changing the ARCH=p16f877 (default target) entry in
23607 device/lib/pic/Makefile.in
23611 device/lib/pic/Makefile
23613 to reflect your device.
23614 This might even improve performance for smaller devices as unneccesary
23615 BANKSELs might be removed.
23618 \begin_layout Subsection
23622 \begin_layout Subsubsection
23626 \begin_layout Standard
23627 Functions with variable argument lists (like printf) are not yet supported.
23628 Similarly, taking the argument of the first argument passed into a function
23629 does not work: It is currently passed in WREG and has no address...
23632 \begin_layout Subsubsection
23633 Regression tests fail
23636 \begin_layout Standard
23637 Though the small subset of regression tests in src/regression passes, SDCC
23638 regression test suite does not, indicating that there are still major bugs
23640 However, many smaller projects have successfully used SDCC in the past...
23643 \begin_layout Standard
23651 \begin_layout Section
23653 \begin_inset LatexCommand \index{PIC16}
23660 \begin_layout Standard
23661 The PIC16 port adds support for Microchip
23662 \begin_inset LatexCommand \index{Microchip}
23667 \begin_inset Formula $^{\text{TM}}$
23671 \begin_inset LatexCommand \index{PIC}
23676 \begin_inset Formula $^{\text{TM}}$
23679 MCUs with 16 bit wide instructions.
23680 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23681 ; devices supported by the port include:
23684 \begin_layout Standard
23685 18F: 242, 248, 252, 258, 442, 448, 452, 458
23688 \begin_layout Standard
23692 \begin_layout Standard
23693 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23697 \begin_layout Standard
23698 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23702 \begin_layout Standard
23703 18F: 6520, 6620, 6680, 6720
23706 \begin_layout Standard
23707 18F: 8520, 8620, 8680, 8720
23710 \begin_layout Subsection
23714 \begin_layout Standard
23715 PIC16 port supports the standard command line arguments as supposed, with
23716 the exception of certain cases that will be mentioned in the following
23720 \begin_layout Description
23725 \begin_layout Standard
23735 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23743 \begin_layout Standard
23755 \begin_layout Description
23760 \begin_layout Standard
23769 -fommit-frame-pointer
23770 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23774 Frame pointer will be omitted when the function uses no local variables.
23777 \begin_layout Subsection
23778 Port Specific Options
23779 \begin_inset LatexCommand \index{Options PIC16}
23786 \begin_layout Standard
23787 The port specific options appear after the global options in the sdcc -
23791 \begin_layout Standard
23803 \begin_layout Subsubsection
23804 Code Generation Options
23807 \begin_layout Standard
23808 These options influence the generated assembler code.
23811 \begin_layout Description
23816 \begin_layout Standard
23825 -pstack-model=[model] Used in conjuction with the command above.
23826 Defines the stack model to be used, valid stack models are:
23831 \labelwidthstring 00.00.0000
23836 Selects small stack model.
23837 8 bit stack and frame pointers.
23838 Supports 256 bytes stack size.
23842 \labelwidthstring 00.00.0000
23847 Selects large stack model.
23848 16 bit stack and frame pointers.
23849 Supports 65536 bytes stack size.
23853 \begin_layout Description
23858 \begin_layout Standard
23867 -pno-banksel Do not generate BANKSEL assembler directives.
23870 \begin_layout Description
23875 \begin_layout Standard
23884 -extended Enable extended instruction set/literal offset addressing mode.
23888 \begin_layout Subsubsection
23889 Optimization Options
23892 \begin_layout Description
23897 \begin_layout Standard
23906 -obanksel=n Set optimization level for inserting BANKSELs.
23913 \labelwidthstring 00.00.0000
23918 \labelwidthstring 00.00.0000
23919 1 checks previous used register and if it is the same then does not emit
23920 BANKSEL, accounts only for labels.
23924 \labelwidthstring 00.00.0000
23925 2 tries to check the location of (even different) symbols and removes BANKSELs
23926 if they are in the same bank.
23930 Important: There might be problems if the linker script has data sections
23931 across bank borders!
23935 \begin_layout Description
23940 \begin_layout Standard
23949 -denable-peeps Force the usage of peepholes.
23953 \begin_layout Description
23958 \begin_layout Standard
23967 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23970 \begin_layout Description
23975 \begin_layout Standard
23984 -optimize-cmp Try to optimize some compares.
23987 \begin_layout Description
23992 \begin_layout Standard
24001 -optimize-df Analyze the dataflow of the generated code and improve it.
24004 \begin_layout Subsubsection
24008 \begin_layout Description
24013 \begin_layout Standard
24022 -asm= Sets the full path and name of an external assembler to call.
24025 \begin_layout Description
24030 \begin_layout Standard
24040 \begin_inset LatexCommand \index{PIC16!MPLAB}
24044 compatibility option.
24045 Currently only suppresses special gpasm directives.
24048 \begin_layout Subsubsection
24052 \begin_layout Description
24057 \begin_layout Standard
24066 -link= Sets the full path and name of an external linker to call.
24069 \begin_layout Description
24074 \begin_layout Standard
24083 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24084 unitialized data variables with [kword].
24085 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24088 \begin_layout Description
24093 \begin_layout Standard
24102 -ivt-loc=n Place the interrupt vector table at address
24107 Useful for bootloaders.
24110 \begin_layout Description
24115 \begin_layout Standard
24124 -nodefaultlibs Do not link default libraries when linking.
24127 \begin_layout Description
24132 \begin_layout Standard
24141 -use-crt= Use a custom run-time module instead of the defaults.
24144 \begin_layout Description
24149 \begin_layout Standard
24158 -no-crt Don't link the default run-time modules
24161 \begin_layout Subsubsection
24165 \begin_layout Standard
24166 Debugging options enable extra debugging information in the output files.
24169 \begin_layout Description
24174 \begin_layout Standard
24183 -debug-xtra Similar to -
24187 \begin_layout Standard
24197 \begin_inset LatexCommand \index{-\/-debug}
24201 , but dumps more information.
24204 \begin_layout Description
24209 \begin_layout Standard
24218 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24220 <source> is the name of the file being compiled.
24223 \begin_layout Description
24228 \begin_layout Standard
24237 -pcode-verbose Enable pcode debugging information in translation.
24240 \begin_layout Description
24245 \begin_layout Standard
24254 -calltree Dump call tree in .calltree file.
24257 \begin_layout Description
24262 \begin_layout Standard
24271 -gstack Trace push/pops for stack pointer overflow.
24274 \begin_layout Subsection
24275 Enviroment Variables
24278 \begin_layout Standard
24279 There is a number of enviromental variables that can be used when running
24280 SDCC to enable certain optimizations or force a specific program behaviour.
24281 these variables are primarily for debugging purposes so they can be enabled/dis
24285 \begin_layout Standard
24286 Currently there is only two such variables available:
24289 \begin_layout Description
24290 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24291 bitfields is optimized by directly loading FSR0 with the address of the
24292 bitfield structure.
24293 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24295 This step saves data ram and code space for functions that make heavy use
24297 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24301 \begin_layout Description
24302 NO_REG_OPT Do not perform pCode registers optimization.
24303 This should be used for debugging purposes.
24304 If bugs in the pcode optimizer are found, users can benefit from temporarily
24305 disabling the optimizer until the bug is fixed.
24308 \begin_layout Subsection
24309 Preprocessor Macros
24312 \begin_layout Standard
24314 \begin_inset LatexCommand \index{PIC16}
24318 port defines the following preprocessor macros while translating a source.
24321 \begin_layout Standard
24323 \begin_inset Tabular
24324 <lyxtabular version="3" rows="6" columns="2">
24326 <column alignment="center" valignment="top" leftline="true" width="0">
24327 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24328 <row topline="true" bottomline="true">
24329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24332 \begin_layout Standard
24338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24341 \begin_layout Standard
24348 <row topline="true">
24349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24352 \begin_layout Standard
24358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24361 \begin_layout Standard
24362 Port identification
24368 <row topline="true">
24369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24372 \begin_layout Standard
24377 \begin_layout Standard
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24394 \begin_layout Standard
24395 Port identification (same as above)
24401 <row topline="true">
24402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24405 \begin_layout Standard
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24414 \begin_layout Standard
24415 MCU Identification.
24419 is the microcontrol identification number, i.e.
24426 <row topline="true">
24427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24430 \begin_layout Standard
24435 \begin_layout Standard
24449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24452 \begin_layout Standard
24453 MCU Identification (same as above)
24459 <row topline="true" bottomline="true">
24460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24463 \begin_layout Standard
24469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24472 \begin_layout Standard
24473 nnn = SMALL or LARGE respectively according to the stack model used
24486 \begin_layout Standard
24487 In addition the following macros are defined when calling assembler:
24490 \begin_layout Standard
24492 \begin_inset Tabular
24493 <lyxtabular version="3" rows="4" columns="2">
24495 <column alignment="center" valignment="top" leftline="true" width="0">
24496 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24497 <row topline="true" bottomline="true">
24498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24501 \begin_layout Standard
24507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24510 \begin_layout Standard
24517 <row topline="true">
24518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24521 \begin_layout Standard
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24530 \begin_layout Standard
24531 MCU Identification.
24535 is the microcontrol identification number, i.e.
24542 <row topline="true">
24543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24546 \begin_layout Standard
24552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24555 \begin_layout Standard
24556 nnn = SMALL or LARGE respectively according to the memory model used for
24563 <row topline="true" bottomline="true">
24564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24567 \begin_layout Standard
24573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24576 \begin_layout Standard
24577 nnn = SMALL or LARGE respectively according to the stack model used
24590 \begin_layout Subsection
24594 \begin_layout Standard
24596 \begin_inset LatexCommand \index{PIC16}
24600 port uses the following directories for searching header files and libraries.
24603 \begin_layout Standard
24605 \begin_inset Tabular
24606 <lyxtabular version="3" rows="3" columns="4">
24608 <column alignment="center" valignment="top" leftline="true" width="0">
24609 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24610 <column alignment="center" valignment="top" width="0">
24611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24612 <row topline="true" bottomline="true">
24613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24616 \begin_layout Standard
24622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24625 \begin_layout Standard
24631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24634 \begin_layout Standard
24640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24643 \begin_layout Standard
24650 <row topline="true">
24651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24654 \begin_layout Standard
24655 PREFIX/sdcc/include/pic16
24660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24663 \begin_layout Standard
24664 PIC16 specific headers
24669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24672 \begin_layout Standard
24678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24681 \begin_layout Standard
24688 <row topline="true" bottomline="true">
24689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24692 \begin_layout Standard
24693 PREFIX/sdcc/lib/pic16
24698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24701 \begin_layout Standard
24702 PIC16 specific libraries
24707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24710 \begin_layout Standard
24716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24719 \begin_layout Standard
24733 \begin_layout Subsection
24735 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24742 \begin_layout Standard
24744 \begin_inset LatexCommand \index{PIC16}
24748 port currently supports the following pragmas:
24751 \begin_layout Description
24753 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24757 This forces the code generator to initialize the stack & frame pointers
24758 at a specific address.
24759 This is an ad hoc solution for cases where no STACK directive is available
24760 in the linker script or gplink is not instructed to create a stack section.
24763 stack pragma should be used only once in a project.
24764 Multiple pragmas may result in indeterminate behaviour of the program.
24768 \begin_layout Standard
24769 The old format (ie.
24770 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24771 cross page boundaries (or even exceed the available data RAM) and crash
24773 Make sure that stack does not cross page boundaries when using the SMALL
24781 The format is as follows:
24786 \begin_layout LyX-Code
24787 #pragma stack bottom_address [stack_size]
24792 \begin_layout Standard
24797 is the lower bound of the stack section.
24798 The stack pointer initially will point at address (bottom_address+stack_size-1).
24801 \begin_layout LyX-Code
24805 \begin_layout LyX-Code
24809 \begin_layout LyX-Code
24810 /* initializes stack of 100 bytes at RAM address 0x200 */
24813 \begin_layout LyX-Code
24814 #pragma stack 0x200 100
24817 \begin_layout Standard
24818 If the stack_size field is omitted then a stack is created with the default
24820 This size might be enough for most programs, but its not enough for operations
24821 with deep function nesting or excessive stack usage.
24824 \begin_layout Description
24826 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24830 Force a function to a static FLASH address.
24833 \begin_layout LyX-Code
24837 \begin_layout LyX-Code
24841 \begin_layout LyX-Code
24842 /* place function test_func at 0x4000 */
24845 \begin_layout LyX-Code
24846 #pragma code test_func 0x4000
24849 \begin_layout LyX-Code
24853 \begin_layout Description
24854 library instructs the linker to use a library module.
24859 \begin_layout LyX-Code
24860 #pragma library module_name
24863 \begin_layout Standard
24868 can be any library or object file (including its path).
24869 Note that there are four reserved keywords which have special meaning.
24873 \begin_layout Standard
24875 \begin_inset Tabular
24876 <lyxtabular version="3" rows="6" columns="3">
24878 <column alignment="center" valignment="top" leftline="true" width="0">
24879 <column alignment="block" valignment="top" leftline="true" width="20page%">
24880 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24881 <row topline="true" bottomline="true">
24882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24885 \begin_layout Standard
24891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24894 \begin_layout Standard
24900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24903 \begin_layout Standard
24910 <row topline="true">
24911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24914 \begin_layout Standard
24922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24925 \begin_layout Standard
24926 ignore all library pragmas
24931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24934 \begin_layout Standard
24943 <row topline="true">
24944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24947 \begin_layout Standard
24955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24958 \begin_layout Standard
24964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24967 \begin_layout Standard
24978 <row topline="true">
24979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24982 \begin_layout Standard
24990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24993 \begin_layout Standard
24994 link the Math libarary
24999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25002 \begin_layout Standard
25013 <row topline="true">
25014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25017 \begin_layout Standard
25025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25028 \begin_layout Standard
25029 link the I/O library
25034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25037 \begin_layout Standard
25048 <row topline="true" bottomline="true">
25049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25052 \begin_layout Standard
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25063 \begin_layout Standard
25064 link the debug library
25069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25072 \begin_layout Standard
25089 * is the device number, i.e.
25090 452 for PIC18F452 MCU.
25093 \begin_layout Standard
25094 This feature allows for linking with specific libraries withoug having to
25095 explicit name them in the command line.
25100 keyword will reject all modules specified by the library pragma.
25103 \begin_layout Description
25104 udata The pragma udata instructs the compiler to emit code so that linker
25105 will place a variable at a specific memory bank.
25108 \begin_layout LyX-Code
25112 \begin_layout LyX-Code
25116 \begin_layout LyX-Code
25117 /* places variable foo at bank2 */
25120 \begin_layout LyX-Code
25121 #pragma udata bank2 foo
25124 \begin_layout LyX-Code
25128 \begin_layout Standard
25129 In order for this pragma to work extra SECTION directives should be added
25130 in the .lkr script.
25131 In the following example a sample .lkr file is shown:
25134 \begin_layout LyX-Code
25138 \begin_layout LyX-Code
25139 // Sample linker script for the PIC18F452 processor
25142 \begin_layout LyX-Code
25146 \begin_layout LyX-Code
25147 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25150 \begin_layout LyX-Code
25151 CODEPAGE NAME=page START=0x2A END=0x7FFF
25154 \begin_layout LyX-Code
25155 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25158 \begin_layout LyX-Code
25159 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25162 \begin_layout LyX-Code
25163 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25166 \begin_layout LyX-Code
25167 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25170 \begin_layout LyX-Code
25171 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25174 \begin_layout LyX-Code
25178 \begin_layout LyX-Code
25179 DATABANK NAME=gpr0 START=0x80 END=0xFF
25182 \begin_layout LyX-Code
25183 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25186 \begin_layout LyX-Code
25187 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25190 \begin_layout LyX-Code
25191 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25194 \begin_layout LyX-Code
25195 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25198 \begin_layout LyX-Code
25199 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25202 \begin_layout LyX-Code
25203 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25206 \begin_layout LyX-Code
25210 \begin_layout LyX-Code
25211 SECTION NAME=CONFIG ROM=config
25214 \begin_layout LyX-Code
25218 \begin_layout LyX-Code
25219 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25222 \begin_layout LyX-Code
25223 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25226 \begin_layout LyX-Code
25227 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25230 \begin_layout LyX-Code
25231 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25234 \begin_layout LyX-Code
25235 SECTION NAME=bank4 RAM=gpr4
25238 \begin_layout LyX-Code
25239 SECTION NAME=bank5 RAM=gpr5
25242 \begin_layout Standard
25243 The linker will recognise the section name set in the pragma statement and
25244 will position the variable at the memory bank set with the RAM field at
25245 the SECTION line in the linker script file.
25248 \begin_layout Subsection
25250 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25257 \begin_layout Standard
25258 There is one main header file
25259 \begin_inset LatexCommand \index{PIC16!Header files}
25263 that can be included to the source files using the pic16
25264 \begin_inset LatexCommand \index{PIC16}
25274 This header file contains the definitions for the processor special registers,
25275 so it is necessary if the source accesses them.
25276 It can be included by adding the following line in the beginning of the
25280 \begin_layout LyX-Code
25281 #include <pic18fregs.h>
25284 \begin_layout Standard
25285 The specific microcontroller is selected within the pic18fregs.h automatically,
25286 so the same source can be used with a variety of devices.
25289 \begin_layout Subsection
25293 \begin_layout Standard
25295 \begin_inset LatexCommand \index{PIC16!Libraries}
25300 \begin_inset LatexCommand \index{PIC16}
25304 port depends on are the microcontroller device libraries which contain
25305 the symbol definitions for the microcontroller special function registers.
25306 These libraries have the format pic18fxxxx.lib, where
25310 is the microcontroller identification number.
25311 The specific library is selected automatically by the compiler at link
25312 stage according to the selected device.
25315 \begin_layout Standard
25316 Libraries are created with gplib which is part of the gputils package
25317 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25324 \begin_layout Subsubsection*
25325 Building the libraries
25328 \begin_layout Standard
25329 Before using SDCC/pic16 there are some libraries that need to be compiled.
25330 This process is not done automatically by SDCC since not all users use
25331 SDCC for pic16 projects.
25332 So each user should compile the libraries separately.
25335 \begin_layout Standard
25336 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25339 \begin_layout LyX-Code
25340 cd device/lib/pic16
25343 \begin_layout LyX-Code
25347 \begin_layout LyX-Code
25351 \begin_layout LyX-Code
25355 \begin_layout LyX-Code
25359 \begin_layout LyX-Code
25360 su -c 'make install' # install the libraries, you need the root password
25363 \begin_layout Standard
25364 If you need to install the headers too, do:
25367 \begin_layout LyX-Code
25371 \begin_layout LyX-Code
25372 su -c 'make install' # install the headers, you need the root password
25375 \begin_layout Standard
25376 There exist a special target to build the I/O libraries.
25377 This target is not automatically build because it will build the I/O library
25383 This way building will take quite a lot of time.
25384 Users are advised to edit the
25386 device/lib/pic16/pics.build
25388 file and then execute:
25391 \begin_layout LyX-Code
25395 \begin_layout Subsection
25396 Adding New Devices to the Port
25399 \begin_layout Standard
25400 Adding support for a new 16
25404 \begin_layout Standard
25413 bit PIC MCU requires the following steps:
25416 \begin_layout Enumerate
25417 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25421 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25425 \begin_layout Enumerate
25428 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25431 \begin_layout Enumerate
25434 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25437 \begin_layout Enumerate
25440 /path/to/sdcc/device/lib/pic16/pics.all
25448 Note: No 18f prefix here!
25451 \begin_layout Enumerate
25454 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25458 Add your DEVICE if it does not compile in
25473 \begin_layout Enumerate
25476 /path/to/sdcc/device/include/pic16/pic18fregs.h
25479 The file format is self-explanatory, just add
25483 #elif defined(picDEVICE)
25485 # include <picDEVICE.h>
25489 at the right place (keep it sorted).
25492 \begin_layout Enumerate
25495 /path/to/sdcc/src/pic16/devices.inc
25498 Copy and modify an existing entry and insert it at the correct place (keep
25500 The file is hardly documented, look at the entries for the 18f2221...
25503 \begin_layout Enumerate
25504 Recompile SDCC, including the pic16 libraries.
25507 \begin_layout Subsection
25511 \begin_layout Standard
25512 The following memory models are supported by the PIC16 port:
25515 \begin_layout Itemize
25519 \begin_layout Itemize
25523 \begin_layout Standard
25524 Memory model affects the default size of pointers within the source.
25525 The sizes are shown in the next table:
25528 \begin_layout Standard
25530 \begin_inset Tabular
25531 <lyxtabular version="3" rows="3" columns="3">
25533 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25534 <column alignment="center" valignment="top" leftline="true" width="0">
25535 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25536 <row topline="true" bottomline="true">
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25540 \begin_layout Standard
25541 Pointer sizes according to memory model
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25549 \begin_layout Standard
25555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25558 \begin_layout Standard
25565 <row topline="true" bottomline="true">
25566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25569 \begin_layout Standard
25575 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25578 \begin_layout Standard
25584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25587 \begin_layout Standard
25594 <row topline="true" bottomline="true">
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25598 \begin_layout Standard
25604 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25607 \begin_layout Standard
25613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25616 \begin_layout Standard
25630 \begin_layout Standard
25631 It is advisable that all sources within a project are compiled with the
25633 If one wants to override the default memory model, this can be done by
25634 declaring a pointer as
25643 Far selects large memory model's pointers, while near selects small memory
25647 \begin_layout Standard
25648 The standard device libraries (see
25649 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25653 ) contain no reference to pointers, so they can be used with both memory
25657 \begin_layout Subsection
25661 \begin_layout Standard
25663 \begin_inset LatexCommand \index{PIC16!stack}
25667 implementation for the PIC16 port uses two indirect registers, FSR1 and
25671 \begin_layout Description
25672 FSR1 is assigned as stack pointer
25675 \begin_layout Description
25676 FSR2 is assigned as frame pointer
25679 \begin_layout Standard
25680 The following stack models are supported by the PIC16 port
25683 \begin_layout Itemize
25691 \begin_layout Itemize
25699 \begin_layout Standard
25704 model means that only the FSRxL byte is used to access stack and frame,
25711 uses both FSRxL and FSRxH registers.
25712 The following table shows the stack/frame pointers sizes according to stack
25713 model and the maximum space they can address:
25716 \begin_layout Standard
25718 \begin_inset Tabular
25719 <lyxtabular version="3" rows="3" columns="3">
25721 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25722 <column alignment="center" valignment="top" leftline="true" width="0">
25723 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25724 <row topline="true" bottomline="true">
25725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25728 \begin_layout Standard
25729 Stack & Frame pointer sizes according to stack model
25734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25737 \begin_layout Standard
25743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25746 \begin_layout Standard
25753 <row topline="true">
25754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25757 \begin_layout Standard
25763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25766 \begin_layout Standard
25772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25775 \begin_layout Standard
25782 <row topline="true" bottomline="true">
25783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25786 \begin_layout Standard
25792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25795 \begin_layout Standard
25801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25804 \begin_layout Standard
25818 \begin_layout Standard
25823 stack model is currently not working properly throughout the code generator.
25824 So its use is not advised.
25825 Also there are some other points that need special care:
25830 \begin_layout Enumerate
25831 Do not create stack sections with size more than one physical bank (that
25835 \begin_layout Enumerate
25836 Stack sections should no cross physical bank limits (i.e.
25837 #pragma stack 0x50 0x100)
25840 \begin_layout Standard
25841 These limitations are caused by the fact that only FSRxL is modified when
25842 using SMALL stack model, so no more than 256 bytes of stack can be used.
25843 This problem will disappear after LARGE model is fully implemented.
25846 \begin_layout Subsection
25850 \begin_layout Standard
25851 In addition to the standard SDCC function keywords, PIC16
25852 \begin_inset LatexCommand \index{PIC16}
25856 port makes available two more:
25859 \begin_layout Description
25861 \begin_inset LatexCommand \index{PIC16!wparam}
25865 Use the WREG to pass one byte of the first function argument.
25866 This improves speed but you may not use this for functions with arguments
25867 that are called via function pointers, otherwise the first byte of the
25868 first parameter will get lost.
25872 \begin_layout LyX-Code
25873 void func_wparam(int a) wparam
25876 \begin_layout LyX-Code
25880 \begin_layout LyX-Code
25881 /* WREG hold the lower part of a */
25884 \begin_layout LyX-Code
25885 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25889 \begin_layout LyX-Code
25893 \begin_layout LyX-Code
25897 \begin_layout Description
25899 \begin_inset LatexCommand \index{PIC16!shadowregs}
25903 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25904 hardware shadow registers which hold the values of WREG, STATUS and BSR
25906 This can be done by adding the keyword
25914 keyword in the function's header.
25917 \begin_layout LyX-Code
25918 void isr_shadow(void) shadowregs interrupt 1
25921 \begin_layout LyX-Code
25925 \begin_layout LyX-Code
25929 \begin_layout LyX-Code
25933 \begin_layout Standard
25938 instructs the code generator not to store/restore WREG, STATUS, BSR when
25939 entering/exiting the ISR.
25942 \begin_layout Subsection
25943 Function return values
25946 \begin_layout Standard
25947 Return values from functions are placed to the appropriate registers following
25948 a modified Microchip policy optimized for SDCC.
25949 The following table shows these registers:
25952 \begin_layout Standard
25954 \begin_inset Tabular
25955 <lyxtabular version="3" rows="6" columns="2">
25957 <column alignment="center" valignment="top" leftline="true" width="0">
25958 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25959 <row topline="true" bottomline="true">
25960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25963 \begin_layout Standard
25969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25972 \begin_layout Standard
25973 destination register
25979 <row topline="true">
25980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25983 \begin_layout Standard
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25992 \begin_layout Standard
25999 <row topline="true">
26000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26003 \begin_layout Standard
26009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26012 \begin_layout Standard
26019 <row topline="true">
26020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26023 \begin_layout Standard
26029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26032 \begin_layout Standard
26039 <row topline="true">
26040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26043 \begin_layout Standard
26049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26052 \begin_layout Standard
26053 FSR0L:PRODH:PRODL:WREG
26059 <row topline="true" bottomline="true">
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26063 \begin_layout Standard
26069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26072 \begin_layout Standard
26073 on stack, FSR0 points to the beginning
26086 \begin_layout Subsection
26090 \begin_layout Standard
26092 \begin_inset LatexCommand \index{PIC16!interrupt}
26096 service routine (ISR) is declared using the
26103 \begin_layout LyX-Code
26104 void isr(void) interrupt
26109 \begin_layout LyX-Code
26113 \begin_layout LyX-Code
26117 \begin_layout LyX-Code
26121 \begin_layout Standard
26126 is the interrupt number, which for PIC18F devices can be:
26129 \begin_layout Standard
26131 \begin_inset Tabular
26132 <lyxtabular version="3" rows="4" columns="3">
26134 <column alignment="center" valignment="top" leftline="true" width="0">
26135 <column alignment="center" valignment="top" leftline="true" width="0">
26136 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26137 <row topline="true" bottomline="true">
26138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26141 \begin_layout Standard
26149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26152 \begin_layout Standard
26158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26161 \begin_layout Standard
26162 Interrupt Vector Address
26168 <row topline="true">
26169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26172 \begin_layout Standard
26178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26181 \begin_layout Standard
26187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26190 \begin_layout Standard
26197 <row topline="true">
26198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26201 \begin_layout Standard
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26219 \begin_layout Standard
26229 HIGH priority interrupts
26234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26237 \begin_layout Standard
26244 <row topline="true" bottomline="true">
26245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26248 \begin_layout Standard
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26257 \begin_layout Standard
26258 LOW priority interrupts
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26266 \begin_layout Standard
26280 \begin_layout Standard
26281 When generating assembly code for ISR the code generator places a
26287 Interrupt Vector Address
26289 which points at the genetated ISR.
26290 This single GOTO instruction is part of an automatically generated
26292 interrupt entry point
26295 The actuall ISR code is placed as normally would in the code space.
26296 Upon interrupt request, the GOTO instruction is executed which jumps to
26298 When declaring interrupt functions as _naked this GOTO instruction is
26303 The whole interrupt functions is therefore placed at the Interrupt Vector
26304 Address of the specific interrupt.
26305 This is not a problem for the LOW priority interrupts, but it is a problem
26306 for the RESET and the HIGH priority interrupts because code may be written
26307 at the next interrupt's vector address and cause undeterminate program
26308 behaviour if that interrupt is raised.
26312 \begin_layout Standard
26313 This is not a problem when
26316 \begin_layout Enumerate
26317 this is a HIGH interrupt ISR and LOW interrupts are
26324 \begin_layout Enumerate
26325 when the ISR is small enough not to reach the next interrupt's vector address.
26333 \begin_layout Standard
26339 This way a function is generated similar to an ISR, but it is not assigned
26343 \begin_layout Standard
26344 When entering an interrupt, currently the PIC16
26345 \begin_inset LatexCommand \index{PIC16}
26349 port automatically saves the following registers:
26352 \begin_layout Itemize
26356 \begin_layout Itemize
26360 \begin_layout Itemize
26364 \begin_layout Itemize
26365 PROD (PRODL and PRODH)
26368 \begin_layout Itemize
26369 FSR0 (FSR0L and FSR0H)
26372 \begin_layout Standard
26373 These registers are restored upon return from the interrupt routine.
26377 \begin_layout Standard
26378 NOTE that when the _naked attribute is specified for an interrupt routine,
26379 then NO registers are stored or restored.
26387 \begin_layout Subsection
26391 \begin_layout Standard
26392 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26393 There are 3 types of generic pointers currently implemented data, code
26394 and eeprom pointers.
26395 They are differentiated by the value of the 7th and 6th bits of the upper
26399 \begin_layout Standard
26401 \begin_inset Tabular
26402 <lyxtabular version="3" rows="5" columns="5">
26404 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26405 <column alignment="center" valignment="top" width="0">
26406 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26407 <column alignment="center" valignment="top" width="0">
26408 <column alignment="left" valignment="top" rightline="true" width="0">
26409 <row topline="true" bottomline="true">
26410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26413 \begin_layout Standard
26419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26422 \begin_layout Standard
26428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26431 \begin_layout Standard
26437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26440 \begin_layout Standard
26441 rest of the pointer
26446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26449 \begin_layout Standard
26456 <row topline="true" bottomline="true">
26457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26460 \begin_layout Standard
26466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26469 \begin_layout Standard
26475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26478 \begin_layout Standard
26484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26487 \begin_layout Standard
26492 uuuuuu uuuuxxxx xxxxxxxx
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26500 \begin_layout Standard
26501 a 12-bit data pointer in data RAM memory
26507 <row bottomline="true">
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26511 \begin_layout Standard
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26520 \begin_layout Standard
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26529 \begin_layout Standard
26535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26538 \begin_layout Standard
26543 uxxxxx xxxxxxxx xxxxxxxx
26548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26551 \begin_layout Standard
26552 a 21-bit code pointer in FLASH memory
26558 <row bottomline="true">
26559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26562 \begin_layout Standard
26568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26571 \begin_layout Standard
26577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26580 \begin_layout Standard
26586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26589 \begin_layout Standard
26594 uuuuuu uuuuuuxx xxxxxxxx
26599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26602 \begin_layout Standard
26603 a 10-bit eeprom pointer in EEPROM memory
26609 <row bottomline="true">
26610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26613 \begin_layout Standard
26619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26622 \begin_layout Standard
26628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26631 \begin_layout Standard
26637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26640 \begin_layout Standard
26645 xxxxxx xxxxxxxx xxxxxxxx
26650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26653 \begin_layout Standard
26654 unimplemented pointer type
26667 \begin_layout Standard
26668 Generic pointer are read and written with a set of library functions which
26669 read/write 1, 2, 3, 4 bytes.
26672 \begin_layout Subsection
26676 \begin_layout Subsubsection
26677 Standard I/O Streams
26680 \begin_layout Standard
26685 the type FILE is defined as:
26688 \begin_layout LyX-Code
26689 typedef char * FILE;
26692 \begin_layout Standard
26693 This type is the stream type implemented I/O in the PIC18F devices.
26694 Also the standard input and output streams are declared in stdio.h:
26697 \begin_layout LyX-Code
26698 extern FILE * stdin;
26701 \begin_layout LyX-Code
26702 extern FILE * stdout;
26705 \begin_layout Standard
26706 The FILE type is actually a generic pointer which defines one more type
26707 of generic pointers, the
26712 This new type has the format:
26715 \begin_layout Standard
26717 \begin_inset Tabular
26718 <lyxtabular version="3" rows="2" columns="7">
26720 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26721 <column alignment="center" valignment="top" width="0">
26722 <column alignment="center" valignment="top" leftline="true" width="0">
26723 <column alignment="center" valignment="top" leftline="true" width="0">
26724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26725 <column alignment="center" valignment="top" width="0">
26726 <column alignment="left" valignment="top" rightline="true" width="0">
26727 <row topline="true" bottomline="true">
26728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26731 \begin_layout Standard
26737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26740 \begin_layout Standard
26746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26749 \begin_layout Standard
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26758 \begin_layout Standard
26764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26767 \begin_layout Standard
26773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26776 \begin_layout Standard
26777 rest of the pointer
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26785 \begin_layout Standard
26792 <row topline="true" bottomline="true">
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26796 \begin_layout Standard
26802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26805 \begin_layout Standard
26811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26814 \begin_layout Standard
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26823 \begin_layout Standard
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26832 \begin_layout Standard
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26841 \begin_layout Standard
26851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26854 \begin_layout Standard
26855 upper byte high nubble is 0x2n, the rest are zeroes
26868 \begin_layout Standard
26869 Currently implemented there are 3 types of streams defined:
26872 \begin_layout Standard
26874 \begin_inset Tabular
26875 <lyxtabular version="3" rows="4" columns="4">
26877 <column alignment="center" valignment="top" leftline="true" width="0">
26878 <column alignment="center" valignment="top" leftline="true" width="0">
26879 <column alignment="center" valignment="top" leftline="true" width="0">
26880 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26881 <row topline="true" bottomline="true">
26882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26885 \begin_layout Standard
26891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26894 \begin_layout Standard
26900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26903 \begin_layout Standard
26909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26912 \begin_layout Standard
26919 <row topline="true">
26920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26923 \begin_layout Standard
26929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26932 \begin_layout Standard
26940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26943 \begin_layout Standard
26949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26952 \begin_layout Standard
26953 Writes/Reads characters via the USART peripheral
26959 <row topline="true">
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26963 \begin_layout Standard
26969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26972 \begin_layout Standard
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26983 \begin_layout Standard
26989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26992 \begin_layout Standard
26993 Writes/Reads characters via the MSSP peripheral
26999 <row topline="true" bottomline="true">
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27003 \begin_layout Standard
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27012 \begin_layout Standard
27020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27023 \begin_layout Standard
27029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27032 \begin_layout Standard
27033 Writes/Reads characters via used defined functions
27046 \begin_layout Standard
27047 The stream identifiers are declared as macros in the stdio.h header.
27050 \begin_layout Standard
27051 In the libc library there exist the functions that are used to write to
27052 each of the above streams.
27056 \begin_layout Description
27061 \begin_layout Standard
27070 _stream_usart_putchar writes a character at the USART stream
27073 \begin_layout Description
27078 \begin_layout Standard
27087 _stream_mssp_putchar writes a character at the MSSP stream
27090 \begin_layout Description
27091 putchar dummy function.
27092 This writes a character to a user specified manner.
27095 \begin_layout Standard
27096 In order to increase performance
27100 is declared in stdio.h as having its parameter in WREG (it has the wparam
27102 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27103 in a user-friendly way.
27107 is the name of the variable that holds the character to print.
27108 An example follows:
27111 \begin_layout LyX-Code
27112 #include <pic18fregs.h>
27121 \begin_layout LyX-Code
27125 \begin_layout LyX-Code
27126 PORTA = c; /* dump character c to PORTA */
27129 \begin_layout LyX-Code
27137 \begin_layout LyX-Code
27141 \begin_layout LyX-Code
27142 stdout = STREAM_USER; /* this is not necessary, since stdout points
27145 \begin_layout LyX-Code
27146 * by default to STREAM_USER */
27149 \begin_layout LyX-Code
27151 \begin_inset Quotes sld
27154 This is a printf test
27157 \begin_inset Quotes srd
27163 \begin_layout LyX-Code
27167 \begin_layout LyX-Code
27171 \begin_layout Subsubsection
27175 \begin_layout Standard
27176 PIC16 contains an implementation of the printf-family of functions.
27177 There exist the following functions:
27180 \begin_layout LyX-Code
27181 extern unsigned int sprintf(char *buf, char *fmt, ...);
27184 \begin_layout LyX-Code
27185 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27188 \begin_layout LyX-Code
27192 \begin_layout LyX-Code
27193 extern unsigned int printf(char *fmt, ...);
27196 \begin_layout LyX-Code
27197 extern unsigned int vprintf(char *fmt, va_lista ap);
27200 \begin_layout LyX-Code
27204 \begin_layout LyX-Code
27205 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27208 \begin_layout LyX-Code
27209 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27212 \begin_layout Standard
27213 For sprintf and vsprintf
27217 should normally be a data pointer where the resulting string will be placed.
27218 No range checking is done so the user should allocate the necessery buffer.
27219 For fprintf and vfprintf
27223 should be a stream pointer (i.e.
27224 stdout, STREAM_MSSP, etc...).
27227 \begin_layout Subsubsection
27231 \begin_layout Standard
27232 The PIC18F family of microcontrollers supports a number of interrupt sources.
27233 A list of these interrupts is shown in the following table:
27236 \begin_layout Standard
27238 \begin_inset Tabular
27239 <lyxtabular version="3" rows="11" columns="4">
27241 <column alignment="left" valignment="top" leftline="true" width="0">
27242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27243 <column alignment="left" valignment="top" leftline="true" width="0">
27244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27245 <row topline="true" bottomline="true">
27246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27249 \begin_layout Standard
27255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27258 \begin_layout Standard
27264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27267 \begin_layout Standard
27273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27276 \begin_layout Standard
27283 <row topline="true">
27284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27287 \begin_layout Standard
27293 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27296 \begin_layout Standard
27297 PORTB change interrupt
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27305 \begin_layout Standard
27311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27314 \begin_layout Standard
27315 EEPROM/FLASH write complete interrupt
27321 <row topline="true">
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27325 \begin_layout Standard
27331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27334 \begin_layout Standard
27335 INT0 external interrupt
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27343 \begin_layout Standard
27349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27352 \begin_layout Standard
27353 Bus collision interrupt
27359 <row topline="true">
27360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27363 \begin_layout Standard
27369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27372 \begin_layout Standard
27373 INT1 external interrupt
27378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27381 \begin_layout Standard
27387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27390 \begin_layout Standard
27391 Low voltage detect interrupt
27397 <row topline="true">
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27401 \begin_layout Standard
27407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27410 \begin_layout Standard
27411 INT2 external interrupt
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27419 \begin_layout Standard
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27428 \begin_layout Standard
27429 Parallel slave port interrupt
27435 <row topline="true">
27436 <cell alignment="center" valignment="top" topline="true" leftline="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
27449 CCP1 module interrupt
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27457 \begin_layout Standard
27463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27466 \begin_layout Standard
27467 AD convertion complete interrupt
27473 <row topline="true">
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27477 \begin_layout Standard
27483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27486 \begin_layout Standard
27487 CCP2 module interrupt
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27495 \begin_layout Standard
27501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27504 \begin_layout Standard
27505 USART receive interrupt
27511 <row topline="true">
27512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27515 \begin_layout Standard
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27524 \begin_layout Standard
27525 TMR0 overflow interrupt
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27533 \begin_layout Standard
27539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27542 \begin_layout Standard
27543 USART transmit interrupt
27549 <row topline="true">
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27553 \begin_layout Standard
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27562 \begin_layout Standard
27563 TMR1 overflow interrupt
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27571 \begin_layout Standard
27577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27580 \begin_layout Standard
27581 SSP receive/transmit interrupt
27587 <row topline="true">
27588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27591 \begin_layout Standard
27597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27600 \begin_layout Standard
27601 TMR2 matches PR2 interrupt
27606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27609 \begin_layout Standard
27615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27618 \begin_layout Standard
27625 <row topline="true" bottomline="true">
27626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27629 \begin_layout Standard
27635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27638 \begin_layout Standard
27639 TMR3 overflow interrupt
27644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27647 \begin_layout Standard
27653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27656 \begin_layout Standard
27670 \begin_layout Standard
27671 The prototypes for these names are defined in the header file
27678 \begin_layout Standard
27679 In order to simplify signal handling, a number of macros is provided:
27683 \labelwidthstring 00.00.0000
27684 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27685 high priority interrupts.
27689 is the function name to use.
27693 \labelwidthstring 00.00.0000
27694 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27695 low priority interrupt.
27699 is the function name to use.
27703 \labelwidthstring 00.00.0000
27704 DEF_HANDLER(sig,handler) define a handler for signal
27710 \labelwidthstring 00.00.0000
27711 END_DEF end the declaration of the dispatch table.
27714 \begin_layout Standard
27715 Additionally there are two more macros to simplify the declaration of the
27720 \labelwidthstring 00.00.0000
27723 SIGHANDLER(handler)
27725 this declares the function prototype for the
27733 \labelwidthstring 00.00.0000
27734 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27737 \begin_layout Standard
27738 An example of using the macros above is shown below:
27741 \begin_layout LyX-Code
27742 #include <pic18fregs.h>
27745 \begin_layout LyX-Code
27746 #include <signal.h>
27750 DEF_INTHIGH(high_int)
27753 \begin_layout LyX-Code
27754 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27757 \begin_layout LyX-Code
27758 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27761 \begin_layout LyX-Code
27766 SIGHANDLER(_tmr0_handler)
27769 \begin_layout LyX-Code
27773 \begin_layout LyX-Code
27774 /* action to be taken when timer 0 overflows */
27777 \begin_layout LyX-Code
27782 SIGHANDLERNAKED(_bcol_handler)
27785 \begin_layout LyX-Code
27789 \begin_layout LyX-Code
27793 \begin_layout LyX-Code
27794 /* action to be taken when bus collision occurs */
27797 \begin_layout LyX-Code
27801 \begin_layout LyX-Code
27805 \begin_layout LyX-Code
27809 \begin_layout Standard
27814 Special care should be taken when using the above scheme:
27817 \begin_layout Itemize
27818 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27821 \begin_layout Itemize
27822 when declaring SIGHANDLERNAKED handler never forget to use
27826 for proper returning.
27829 \begin_layout Subsection
27833 \begin_layout Standard
27834 Here you can find some general tips for compiling programs with SDCC/pic16.
27837 \begin_layout Subsubsection
27841 \begin_layout Standard
27843 \begin_inset LatexCommand \index{PIC16!stack}
27847 size (that is 64 bytes) probably is enough for many programs.
27848 One must take care that when there are many levels of function nesting,
27849 or there is excessive usage of stack, its size should be extended.
27850 An example of such a case is the printf/sprintf family of functions.
27851 If you encounter problems like not being able to print integers, then you
27852 need to set the stack size around the maximum (256 for small stack model).
27853 The following diagram shows what happens when calling printf to print an
27857 \begin_layout LyX-Code
27858 printf () --> ltoa () --> ultoa () --> divschar ()
27861 \begin_layout Standard
27862 It is should be understood that stack is easily consumed when calling complicate
27864 Using command line arguments like -
27868 \begin_layout Standard
27877 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27879 Other ways to reduce stack usage may exist.
27882 \begin_layout Subsection
27886 \begin_layout Standard
27887 The PIC16 Port currently does not pass SDCC's regression test
27888 \begin_inset LatexCommand \index{Regression test (PIC16)}
27893 \begin_inset LatexCommand \ref{sec:Quality-control}
27897 ) and thus the snapshot build regression tests for the PIC16 target are
27898 currently disabled for all hosts
27903 \begin_layout Chapter
27907 \begin_layout Standard
27908 There are several approaches to debugging your code.
27909 This chapter is meant to show your options and to give detail on some of
27914 When writing your code:
27917 \begin_layout Itemize
27918 write your code with debugging in mind (avoid duplicating code, put conceptually
27919 similar variables into structs, use structured code, have strategic points
27920 within your code where all variables are consistent, ...)
27923 \begin_layout Itemize
27924 run a syntax-checking tool like splint
27925 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27930 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27938 \begin_layout Standard
27948 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27955 \begin_layout Itemize
27956 for the high level code use a C-compiler (like f.e.
27957 GCC) to compile run and debug the code on your host.
27962 \begin_layout Standard
27972 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27976 ) on how to handle syntax extensions like __xdata, __at(), ...
27979 \begin_layout Itemize
27980 use another C-compiler to compile code for your target.
27981 Always an option but not recommended:) And not very likely to help you.
27982 If you seriously consider walking this path you should at least occasionally
27983 check portability of your code.
27984 Most commercial compiler vendors will offer an evaluation version so you
27985 can test compile your code or snippets of your code.
27988 \begin_layout Standard
27989 Debugging on a simulator:
27992 \begin_layout Itemize
27993 there is a separate section about SDCDB (section
27994 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28001 \begin_layout Itemize
28002 or (8051 specific) use a freeware/commercial simulator which interfaces
28004 \begin_inset LatexCommand \index{AOMF, AOMF51}
28009 \begin_inset LatexCommand \ref{OMF file}
28013 ) optionally generated by SDCC.
28016 \begin_layout Standard
28017 Debugging On-target:
28020 \begin_layout Itemize
28021 use a MCU port pin to serially output debug data to the RS232 port of your
28023 You'll probably want some level shifting device typically involving a MAX232
28025 If the hardware serial port of the MCU is not available search for 'Software
28026 UART' in your favourite search machine.
28029 \begin_layout Itemize
28030 use an on-target monitor.
28031 In this context a monitor is a small program which usually accepts commands
28032 via a serial line and allows to set program counter, to single step through
28033 a program and read/write memory locations.
28034 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28035 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28042 \begin_layout Itemize
28043 toggle MCU port pins at strategic points within your code and use an oscilloscop
28047 digital oscilloscope
28050 \begin_inset LatexCommand \index{Oscilloscope}
28054 with deep trace memory is really helpful especially if you have to debug
28055 a realtime application.
28056 If you need to monitor more pins than your oscilloscope provides you can
28057 sometimes get away with a small R-2R network.
28058 On a single channel oscilloscope you could f.e.
28059 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28061 \begin_inset Formula $\Omega$
28064 resistor and the other one by a 5\InsetSpace ~
28066 \begin_inset Formula $\Omega$
28069 resistor to the oscilloscope probe (check output drive capability of the
28070 pins you want to monitor).
28071 If you need to monitor many more pins a
28078 \begin_layout Itemize
28092 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28097 Usually very expensive.
28098 And very nice to have too.
28099 And usually locks you (for years...) to the devices the ICE can emulate.
28102 \begin_layout Itemize
28103 use a remote debugger.
28104 In most 8-bit systems the symbol information is not available on the target,
28105 and a complete debugger is too bulky for the target system.
28106 Therefore usually a debugger on the host system connects to an on-target
28107 debugging stub which accepts only primitive commands.
28109 Terms to enter into
28110 your favourite search engine could be 'remote debugging', 'gdb stub' or
28111 'inferior debugger'.
28115 \begin_layout Itemize
28116 use an on target hardware debugger.
28117 Some of the more modern MCUs include hardware support for setting break
28118 points and monitoring/changing variables by using dedicated hardware pins.
28119 This facility doesn't require additional code to run on the target and
28123 doesn't affect runtime behaviour until a breakpoint is hit.
28124 For the mcs51 most hardware debuggers use the AOMF
28125 \begin_inset LatexCommand \index{AOMF, AOMF51}
28130 \begin_inset LatexCommand \ref{OMF file}
28137 \begin_layout Standard
28141 \begin_layout Itemize
28142 if you are not familiar with any of the following terms you're likely to
28143 run into problems rather sooner than later:
28160 As an embedded programmer you
28164 to know them so why not look them up
28168 you have problems?)
28171 \begin_layout Itemize
28172 tell someone else about your problem (actually this is a surprisingly effective
28173 means to hunt down the bug even if the listener is not familiar with your
28175 As 'failure to communicate' is probably one of the job-induced deformations
28176 of an embedded programmer this is highly encouraged.
28179 \begin_layout Section
28180 Debugging with SDCDB
28181 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28186 \begin_inset LatexCommand \index{SDCDB (debugger)}
28193 \begin_layout Standard
28194 SDCC is distributed with a source level debugger
28195 \begin_inset LatexCommand \index{Debugger}
28200 The debugger uses a command line interface, the command repertoire of the
28201 debugger has been kept as close to gdb
28202 \begin_inset LatexCommand \index{gdb}
28206 (the GNU debugger) as possible.
28207 The configuration and build process is part of the standard compiler installati
28208 on, which also builds and installs the debugger in the target directory
28209 specified during configuration.
28210 The debugger allows you debug BOTH at the C source and at the ASM source
28214 \begin_layout Subsection
28215 Compiling for Debugging
28218 \begin_layout Standard
28223 \begin_layout Standard
28233 \begin_inset LatexCommand \index{-\/-debug}
28237 option must be specified for all files for which debug information is to
28239 The compiler generates a .adb file for each of these files.
28240 The linker creates the .cdb
28241 \begin_inset LatexCommand \index{<file>.cdb}
28246 \begin_inset LatexCommand \index{<file>.adb}
28250 files and the address information.
28251 This .cdb is used by the debugger.
28254 \begin_layout Subsection
28255 How the Debugger Works
28258 \begin_layout Standard
28263 \begin_layout Standard
28272 -debug option is specified the compiler generates extra symbol information
28273 some of which are put into the assembler source and some are put into the
28275 Then the linker creates the .cdb file from the individual .adb files with
28276 the address information for the symbols.
28277 The debugger reads the symbolic information generated by the compiler &
28278 the address information generated by the linker.
28279 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28280 execution is controlled by the debugger.
28281 When a command is issued for the debugger, it translates it into appropriate
28282 commands for the simulator.
28283 (Currently SDCDM only connects to the simulator but
28288 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28292 is an effort to connect directly to the hardware.)
28295 \begin_layout Subsection
28296 Starting the Debugger SDCDB
28299 \begin_layout Standard
28300 The debugger can be started using the following command line.
28301 (Assume the file you are debugging has the file name foo).
28315 The debugger will look for the following files.
28318 \begin_layout Itemize
28319 foo.c - the source file.
28322 \begin_layout Itemize
28323 foo.cdb - the debugger symbol information file.
28326 \begin_layout Itemize
28327 foo.ihx - the Intel hex format
28328 \begin_inset LatexCommand \index{Intel hex format}
28335 \begin_layout Subsection
28336 SDCDB Command Line Options
28339 \begin_layout Itemize
28344 \begin_layout Standard
28353 -directory=<source file directory> this option can used to specify the directory
28355 The debugger will look into the directory list specified for source, cdb
28357 The items in the directory list must be separated by ':', e.g.
28358 if the source files can be in the directories /home/src1 and /home/src2,
28363 \begin_layout Standard
28372 -directory option should be -
28376 \begin_layout Standard
28385 -directory=/home/src1:/home/src2.
28386 Note there can be no spaces in the option.
28389 \begin_layout Itemize
28390 -cd <directory> - change to the <directory>.
28393 \begin_layout Itemize
28394 -fullname - used by GUI front ends.
28397 \begin_layout Itemize
28398 -cpu <cpu-type> - this argument is passed to the simulator please see the
28399 simulator docs for details.
28402 \begin_layout Itemize
28403 -X <Clock frequency > this options is passed to the simulator please see
28404 the simulator docs for details.
28407 \begin_layout Itemize
28408 -s <serial port file> passed to simulator see the simulator docs for details.
28411 \begin_layout Itemize
28412 -S <serial in,out> passed to simulator see the simulator docs for details.
28415 \begin_layout Itemize
28416 -k <port number> passed to simulator see the simulator docs for details.
28419 \begin_layout Subsection
28420 SDCDB Debugger Commands
28423 \begin_layout Standard
28424 As mentioned earlier the command interface for the debugger has been deliberatel
28425 y kept as close the GNU debugger gdb, as possible.
28426 This will help the integration with existing graphical user interfaces
28427 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28428 If you use a graphical user interface for the debugger you can skip this
28432 \begin_layout Subsubsection*
28433 break [line | file:line | function | file:function]
28436 \begin_layout Standard
28437 Set breakpoint at specified line or function:
28446 sdcdb>break foo.c:100
28448 sdcdb>break funcfoo
28450 sdcdb>break foo.c:funcfoo
28453 \begin_layout Subsubsection*
28454 clear [line | file:line | function | file:function ]
28457 \begin_layout Standard
28458 Clear breakpoint at specified line or function:
28467 sdcdb>clear foo.c:100
28469 sdcdb>clear funcfoo
28471 sdcdb>clear foo.c:funcfoo
28474 \begin_layout Subsubsection*
28478 \begin_layout Standard
28479 Continue program being debugged, after breakpoint.
28482 \begin_layout Subsubsection*
28486 \begin_layout Standard
28487 Execute till the end of the current function.
28490 \begin_layout Subsubsection*
28494 \begin_layout Standard
28495 Delete breakpoint number 'n'.
28496 If used without any option clear ALL user defined break points.
28499 \begin_layout Subsubsection*
28500 info [break | stack | frame | registers ]
28503 \begin_layout Itemize
28504 info break - list all breakpoints
28507 \begin_layout Itemize
28508 info stack - show the function call stack.
28511 \begin_layout Itemize
28512 info frame - show information about the current execution frame.
28515 \begin_layout Itemize
28516 info registers - show content of all registers.
28519 \begin_layout Subsubsection*
28523 \begin_layout Standard
28524 Step program until it reaches a different source line.
28525 Note: pressing <return> repeats the last command.
28528 \begin_layout Subsubsection*
28532 \begin_layout Standard
28533 Step program, proceeding through subroutine calls.
28536 \begin_layout Subsubsection*
28540 \begin_layout Standard
28541 Start debugged program.
28544 \begin_layout Subsubsection*
28548 \begin_layout Standard
28549 Print type information of the variable.
28552 \begin_layout Subsubsection*
28556 \begin_layout Standard
28557 print value of variable.
28560 \begin_layout Subsubsection*
28564 \begin_layout Standard
28565 load the given file name.
28566 Note this is an alternate method of loading file for debugging.
28569 \begin_layout Subsubsection*
28573 \begin_layout Standard
28574 print information about current frame.
28577 \begin_layout Subsubsection*
28581 \begin_layout Standard
28582 Toggle between C source & assembly source.
28585 \begin_layout Subsubsection*
28586 ! simulator command
28589 \begin_layout Standard
28590 Send the string following '!' to the simulator, the simulator response is
28592 Note the debugger does not interpret the command being sent to the simulator,
28593 so if a command like 'go' is sent the debugger can loose its execution
28594 context and may display incorrect values.
28597 \begin_layout Subsubsection*
28601 \begin_layout Standard
28604 My name is Bobby Brown"
28607 \begin_layout Subsection
28608 Interfacing SDCDB with DDD
28611 \begin_layout Standard
28612 \begin_inset Note Note
28615 \begin_layout Standard
28616 The screenshot was converted from png to eps with:
28617 \begin_inset Quotes sld
28620 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28621 \begin_inset Quotes srd
28624 which produces a pretty compact eps file which is free from compression
28628 \begin_layout Standard
28629 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28630 as this broke the build system on Sourceforge (pdf-file was broken.
28631 pdflatex does not accept eps files).
28639 \begin_layout Standard
28655 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28661 shows a screenshot of a debugging session with DDD
28662 \begin_inset LatexCommand \index{DDD (debugger)}
28666 (Unix only) on a simulated 8032.
28667 The debugging session might not run as smoothly as the screenshot suggests.
28668 The debugger allows setting of breakpoints, displaying and changing variables,
28669 single stepping through C and assembler code.
28671 The source was compiled with
28685 \begin_layout Standard
28697 -debug ddd_example.c
28704 and DDD was invoked with
28711 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28714 \begin_layout Standard
28715 \begin_inset Note Note
28718 \begin_layout Standard
28719 Check that the double quotes or an apostroph within the command line survive
28720 the LyX tool chain.
28721 Previously the apostrophs got slanted in the PDF output so a cut and paste
28730 \begin_layout Subsection
28731 Interfacing SDCDB with XEmacs
28732 \begin_inset LatexCommand \index{XEmacs}
28737 \begin_inset LatexCommand \index{Emacs}
28744 \begin_layout Standard
28745 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28746 sdcdb.el and sdcdbsrc.el.
28747 These two files can be found in the $(prefix)/bin directory after the installat
28749 These files need to be loaded into XEmacs for the interface to work.
28750 This can be done at XEmacs startup time by inserting the following into
28751 your '.xemacs' file (which can be found in your HOME directory):
28757 (load-file sdcdbsrc.el)
28763 .xemacs is a lisp file so the () around the command is REQUIRED.
28764 The files can also be loaded dynamically while XEmacs is running, set the
28765 environment variable 'EMACSLOADPATH' to the installation bin directory
28766 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28767 To start the interface enter the following command:
28781 You will prompted to enter the file name to be debugged.
28786 options that are passed to the simulator directly are bound to default
28787 values in the file sdcdbsrc.el.
28788 The variables are listed below, these values maybe changed as required.
28791 \begin_layout Itemize
28792 sdcdbsrc-cpu-type '51
28795 \begin_layout Itemize
28796 sdcdbsrc-frequency '11059200
28799 \begin_layout Itemize
28800 sdcdbsrc-serial nil
28803 \begin_layout Standard
28804 The following is a list of key mapping for the debugger interface.
28807 \begin_layout Standard
28830 binding\InsetSpace ~
28868 -------\InsetSpace ~
28939 sdcdb-back-from-src\InsetSpace ~
28978 SDCDB continue command
28996 sdcdb-step-from-src\InsetSpace ~
29025 c-sexp\InsetSpace ~
29035 SDCDB ptypecommand for data at
29102 sdcdbsrc-delete\InsetSpace ~
29117 Delete all breakpoints if no arg
29166 given or delete arg (C-u arg x)
29200 SDCDB Display current frame if no arg,
29249 given or display frame arg
29317 sdcdbsrc-goto-sdcdb\InsetSpace ~
29327 Goto the SDCDB output buffer
29345 sdcdb-print-c-sexp\InsetSpace ~
29357 DB print command for data at
29424 sdcdbsrc-goto-sdcdb\InsetSpace ~
29435 SDCDB output buffer
29453 sdcdbsrc-mode\InsetSpace ~
29469 Toggles Sdcdbsrc mode (turns it off)
29485 sdcdb-finish-from-src\InsetSpace ~
29493 SDCDB finish command
29508 sdcdb-break\InsetSpace ~
29527 for line with point
29542 sdcdbsrc-mode\InsetSpace ~
29558 Toggle Sdcdbsrc mode
29598 \begin_layout Chapter
29602 \begin_layout Standard
29603 Here are a few guidelines that will help the compiler generate more efficient
29604 code, some of the tips are specific to this compiler others are generally
29605 good programming practice.
29608 \begin_layout Itemize
29609 Use the smallest data type to represent your data-value.
29610 If it is known in advance that the value is going to be less than 256 then
29611 use an 'unsigned char' instead of a 'short' or 'int'.
29612 Please note, that ANSI C requires both signed and unsigned chars to be
29613 promoted to 'signed int'
29614 \begin_inset LatexCommand \index{promotion to signed int}
29619 \begin_inset Marginal
29622 \begin_layout Standard
29631 before doing any operation.
29633 \begin_inset LatexCommand \index{type promotion}
29638 \begin_inset LatexCommand \label{type promotion}
29642 can be omitted, if the result is the same.
29643 The effect of the promotion rules together with the sign-extension is often
29648 \begin_layout Verse
29651 unsigned char uc = 0xfe;
29653 if (uc * uc < 0) /* this is true! */
29666 \begin_layout Standard
29673 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29680 \begin_layout Verse
29683 (unsigned char) -12 / (signed char) -3 = ...
29686 \begin_layout Standard
29687 No, the result is not 4:
29690 \begin_layout Verse
29693 (int) (unsigned char) -12 / (int) (signed char) -3 =
29695 (int) (unsigned char)
29696 0xf4 / (int) (signed char) 0xfd =
29698 (int) 0x00f4 / (int) 0xfffd =
29703 (int) 244 / (int) -3 =
29705 (int) -81 = (int) 0xffaf;
29708 \begin_layout Standard
29709 Don't complain, that gcc gives you a different result.
29710 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29711 Therefore the results are different.
29714 \begin_inset Quotes sld
29718 \begin_inset Quotes srd
29724 \begin_layout Quote
29727 If well-defined overflow characteristics are important and negative values
29728 are not, or if you want to steer clear of sign-extension problems when
29729 manipulating bits or bytes, use one of the corresponding unsigned types.
29730 (Beware when mixing signed and unsigned values in expressions, though.)
29733 character types (especially unsigned char) can be used as "tiny" integers,
29734 doing so is sometimes more trouble than it's worth, due to unpredictable
29735 sign extension and increased code size.
29739 \begin_layout Itemize
29740 Use unsigned when it is known in advance that the value is not going to
29742 This helps especially if you are doing division or multiplication, bit-shifting
29743 or are using an array index.
29746 \begin_layout Itemize
29747 NEVER jump into a LOOP.
29750 \begin_layout Itemize
29751 Declare the variables to be local
29752 \begin_inset LatexCommand \index{local variables}
29756 whenever possible, especially loop control variables (induction).
29759 \begin_layout Itemize
29760 Have a look at the assembly listing to get a
29761 \begin_inset Quotes sld
29765 \begin_inset Quotes srd
29768 for the code generation.
29771 \begin_layout Section
29772 Porting code from or to other compilers
29773 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29780 \begin_layout Itemize
29781 check whether endianness of the compilers differs and adapt where needed.
29784 \begin_layout Itemize
29785 check the device specific header files
29786 \begin_inset LatexCommand \index{Header files}
29791 \begin_inset LatexCommand \index{Include files}
29795 for compiler specific syntax.
29796 Eventually include the file <compiler.h
29797 \begin_inset LatexCommand \index{compiler.h (include file)}
29802 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29806 to allow using common header files.
29809 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29816 \begin_layout Itemize
29817 check whether the startup code contains the correct initialization (watchdog,
29821 \begin_layout Itemize
29822 check whether the sizes of short, int, long match.
29825 \begin_layout Itemize
29826 check if some 16 or 32 bit hardware registers require a specific addressing
29827 order (least significant or most significant byte first) and adapt if needed
29836 relate to time and not to lower/upper memory location here, so this is
29840 the same as endianness).
29843 \begin_layout Itemize
29844 check whether the keyword
29848 is used where needed.
29849 The compilers might differ in their optimization characteristics (as different
29850 versions of the same compiler might also use more clever optimizations
29851 this is good idea anyway).
29853 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29860 \begin_layout Itemize
29861 check that the compilers are not told to supress warnings.
29864 \begin_layout Itemize
29865 check and convert compiler specific extensions (interrupts, memory areas,
29869 \begin_layout Itemize
29870 check for differences in type promotion.
29871 Especially check for math operations on
29880 For the sake of C99 compatibility SDCC will probably promote these to
29884 more often than other compilers.
29885 Eventually insert explicit casts to
29894 Also check that the ~\InsetSpace ~
29896 \begin_inset LatexCommand \index{\~\/ Operator}
29903 \begin_inset LatexCommand \index{bit}
29909 variables, use the !\InsetSpace ~
29912 \begin_inset LatexCommand \ref{type promotion}
29917 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29924 \begin_layout Itemize
29925 check the assembly code generated for interrupt routines (f.e.
29926 for calls to possibly non-reentrant library functions).
29929 \begin_layout Itemize
29930 check whether timing loops result in proper timing (or preferably consider
29931 a rewrite of the code with timer based delays instead).
29934 \begin_layout Itemize
29935 check for differences in printf parameters (some compilers push (va_arg
29936 \begin_inset LatexCommand \index{vararg, va\_arg}
29940 ) char variables as
29944 others push them as
29950 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29957 \begin_layout Itemize
29958 check the resulting memory map
29959 \begin_inset LatexCommand \index{Memory map}
29964 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29965 ly idata, pdata, xdata).
29966 Eventually check if unexpected library functions are included.
29969 \begin_layout Section
29971 \begin_inset LatexCommand \index{Tools}
29975 included in the distribution
29978 \begin_layout Standard
29980 \begin_inset Tabular
29981 <lyxtabular version="3" rows="12" columns="3">
29983 <column alignment="left" valignment="top" leftline="true" width="0pt">
29984 <column alignment="left" valignment="top" leftline="true" width="0pt">
29985 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29986 <row topline="true" bottomline="true">
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29990 \begin_layout Standard
29998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30001 \begin_layout Standard
30009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30012 \begin_layout Standard
30021 <row topline="true">
30022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30025 \begin_layout Standard
30027 \begin_inset LatexCommand \index{uCsim}
30036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30039 \begin_layout Standard
30040 Simulator for various architectures
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30048 \begin_layout Standard
30055 <row topline="true">
30056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30059 \begin_layout Standard
30065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30068 \begin_layout Standard
30070 \begin_inset LatexCommand \index{Header files}
30075 \begin_inset LatexCommand \index{Include files}
30084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30087 \begin_layout Standard
30088 sdcc/support/scripts
30094 <row topline="true">
30095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30098 \begin_layout Standard
30104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30107 \begin_layout Standard
30108 header file conversion
30113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30116 \begin_layout Standard
30117 sdcc/support/scripts
30123 <row topline="true">
30124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30127 \begin_layout Standard
30133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30136 \begin_layout Standard
30142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30145 \begin_layout Standard
30161 <row topline="true">
30162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30165 \begin_layout Standard
30171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30174 \begin_layout Standard
30180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30183 \begin_layout Standard
30199 <row topline="true">
30200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30203 \begin_layout Standard
30209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30212 \begin_layout Standard
30218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30221 \begin_layout Standard
30237 <row topline="true">
30238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30241 \begin_layout Standard
30247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30250 \begin_layout Standard
30256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30259 \begin_layout Standard
30275 <row topline="true">
30276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30279 \begin_layout Standard
30285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30288 \begin_layout Standard
30294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30297 \begin_layout Standard
30313 <row topline="true">
30314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30317 \begin_layout Standard
30323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30326 \begin_layout Standard
30332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30335 \begin_layout Standard
30351 <row topline="true">
30352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30355 \begin_layout Standard
30361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30364 \begin_layout Standard
30370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30373 \begin_layout Standard
30389 <row topline="true" bottomline="true">
30390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30393 \begin_layout Standard
30399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30402 \begin_layout Standard
30404 \begin_inset LatexCommand \index{packihx (tool)}
30413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30416 \begin_layout Standard
30441 \begin_layout Section
30443 \begin_inset LatexCommand \index{Documentation}
30447 included in the distribution
30450 \begin_layout Standard
30452 \begin_inset Tabular
30453 <lyxtabular version="3" rows="10" columns="2">
30455 <column alignment="block" valignment="top" leftline="true" width="40col%">
30456 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30457 <row topline="true" bottomline="true" endhead="true">
30458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30461 \begin_layout Standard
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30472 \begin_layout Standard
30475 Filename / Where to get
30481 <row topline="true">
30482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30485 \begin_layout Standard
30486 SDCC Compiler User Guide
30491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30494 \begin_layout Standard
30495 You're reading it right now
30507 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30517 <row topline="true">
30518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30521 \begin_layout Standard
30527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30530 \begin_layout Standard
30543 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30553 <row topline="true">
30554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30557 \begin_layout Standard
30559 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30564 \begin_inset LatexCommand \index{Assembler documentation}
30571 \begin_inset LatexCommand \index{aslink}
30576 \begin_inset LatexCommand \index{Linker documentation}
30585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30588 \begin_layout Standard
30589 sdcc/as/doc/asxhtm.html
30601 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30611 <row topline="true">
30612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30615 \begin_layout Standard
30616 SDCC regression test
30617 \begin_inset LatexCommand \index{Regression test}
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30629 \begin_layout Standard
30630 sdcc/doc/test_suite_spec.pdf
30642 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30652 <row topline="true">
30653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30656 \begin_layout Standard
30662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30665 \begin_layout Standard
30678 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30688 <row topline="true">
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30692 \begin_layout Standard
30693 Notes on debugging with SDCDB
30694 \begin_inset LatexCommand \index{SDCDB (debugger)}
30703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30706 \begin_layout Standard
30707 sdcc/debugger/README
30719 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30729 <row topline="true">
30730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30733 \begin_layout Standard
30735 \begin_inset LatexCommand \index{uCsim}
30739 Software simulator for microcontrollers
30744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30747 \begin_layout Standard
30777 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30787 <row topline="true">
30788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30791 \begin_layout Standard
30792 Temporary notes on the pic16
30793 \begin_inset LatexCommand \index{PIC16}
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30805 \begin_layout Standard
30806 sdcc/src/pic16/NOTES
30818 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30828 <row topline="true" bottomline="true">
30829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30832 \begin_layout Standard
30833 SDCC internal documentation (debugging file format)
30838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30841 \begin_layout Standard
30871 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30890 \begin_layout Section
30891 Related open source tools
30892 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30897 \begin_inset LatexCommand \index{Related tools}
30904 \begin_layout Standard
30906 \begin_inset Tabular
30907 <lyxtabular version="3" rows="16" columns="3">
30909 <column alignment="left" valignment="top" leftline="true" width="0pt">
30910 <column alignment="block" valignment="top" leftline="true" width="30line%">
30911 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
30912 <row topline="true" bottomline="true">
30913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30916 \begin_layout Standard
30924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30927 \begin_layout Standard
30935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30938 \begin_layout Standard
30947 <row topline="true">
30948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30951 \begin_layout Standard
30953 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30965 \begin_layout Standard
30971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30974 \begin_layout Standard
30975 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30985 <row topline="true">
30986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30989 \begin_layout Standard
30991 \begin_inset LatexCommand \index{gputils (pic tools)}
31000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31003 \begin_layout Standard
31009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31012 \begin_layout Standard
31013 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31023 <row topline="true">
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31027 \begin_layout Standard
31033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31036 \begin_layout Standard
31042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31045 \begin_layout Standard
31046 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31056 <row topline="true">
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31060 \begin_layout Standard
31066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31069 \begin_layout Standard
31070 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31079 \begin_layout Standard
31080 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31090 <row topline="true">
31091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31094 \begin_layout Standard
31096 \begin_inset LatexCommand \index{indent (source formatting tool)}
31105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31108 \begin_layout Standard
31109 Formats C source - Master of the white spaces
31114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31117 \begin_layout Standard
31118 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31128 <row topline="true">
31129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31132 \begin_layout Standard
31134 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31146 \begin_layout Standard
31147 Object file conversion, checksumming, ...
31152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31155 \begin_layout Standard
31156 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31166 <row topline="true">
31167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31170 \begin_layout Standard
31172 \begin_inset LatexCommand \index{objdump (tool)}
31181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31184 \begin_layout Standard
31185 Object file conversion, ...
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31193 \begin_layout Standard
31194 Part of binutils (should be there anyway)
31200 <row topline="true">
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31204 \begin_layout Standard
31210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31213 \begin_layout Standard
31214 8051 monitor (hex up-/download, single step, disassemble)
31219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31222 \begin_layout Standard
31223 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31233 <row topline="true">
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31237 \begin_layout Standard
31239 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31251 \begin_layout Standard
31252 Source code documentation system
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31260 \begin_layout Standard
31261 \begin_inset LatexCommand \url{http://www.doxygen.org}
31271 <row topline="true">
31272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31275 \begin_layout Standard
31281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31284 \begin_layout Standard
31285 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31293 \begin_layout Standard
31294 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31304 <row topline="true">
31305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31308 \begin_layout Standard
31314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31317 \begin_layout Standard
31318 8051 monitor (hex up-/download, single step, disassemble)
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31326 \begin_layout Standard
31327 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31337 <row topline="true">
31338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31341 \begin_layout Standard
31343 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31355 \begin_layout Standard
31356 Statically checks c sources (see
31357 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31369 \begin_layout Standard
31370 \begin_inset LatexCommand \url{http://www.splint.org}
31380 <row topline="true" bottomline="true">
31381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31384 \begin_layout Standard
31386 \begin_inset LatexCommand \index{DDD (debugger)}
31395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31398 \begin_layout Standard
31399 Debugger, serves nicely as GUI to SDCDB
31400 \begin_inset LatexCommand \index{SDCDB (debugger)}
31409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31412 \begin_layout Standard
31413 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31423 <row bottomline="true">
31424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31427 \begin_layout Standard
31429 \begin_inset LatexCommand \index{d52}
31434 \begin_inset LatexCommand \index{d52 (disassembler)}
31443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31446 \begin_layout Standard
31447 Disassembler, can count instruction cycles
31448 \begin_inset LatexCommand \index{instruction cycles (count)}
31452 , use with options -pnd
31457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31460 \begin_layout Standard
31461 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31471 <row bottomline="true">
31472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31475 \begin_layout Standard
31477 \begin_inset LatexCommand \index{cmake}
31486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31489 \begin_layout Standard
31490 Cross platform build system, generates Makefiles
31491 \begin_inset LatexCommand \index{Makefile}
31495 and project workspaces
31496 \begin_inset LatexCommand \index{project workspace}
31505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31508 \begin_layout Standard
31509 \begin_inset LatexCommand \url{http://www.cmake.org}
31517 and a dedicated wiki entry:
31518 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
31537 \begin_layout Section
31538 Related documentation / recommended reading
31541 \begin_layout Standard
31543 \begin_inset Tabular
31544 <lyxtabular version="3" rows="7" columns="3">
31546 <column alignment="left" valignment="top" leftline="true" width="0pt">
31547 <column alignment="left" valignment="top" leftline="true" width="0">
31548 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31549 <row topline="true" bottomline="true">
31550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31553 \begin_layout Standard
31561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31564 \begin_layout Standard
31572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31575 \begin_layout Standard
31584 <row topline="true">
31585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31588 \begin_layout Standard
31603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31606 \begin_layout Standard
31608 \begin_inset LatexCommand \index{C Reference card}
31617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31620 \begin_layout Standard
31621 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31631 <row topline="true">
31632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31635 \begin_layout Standard
31641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31644 \begin_layout Standard
31646 \begin_inset LatexCommand \index{C FAQ}
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31658 \begin_layout Standard
31659 \begin_inset LatexCommand \url{http://www.c-faq.com}
31669 <row topline="true">
31670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31673 \begin_layout Standard
31679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31682 \begin_layout Standard
31683 \begin_inset Quotes sld
31687 \begin_inset Quotes srd
31695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31698 \begin_layout Standard
31701 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31711 <row topline="true">
31712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31715 \begin_layout Standard
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31724 \begin_layout Standard
31725 \begin_inset Quotes sld
31728 Extensions for Embedded C
31729 \begin_inset Quotes srd
31737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31740 \begin_layout Standard
31743 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31753 <row topline="true">
31754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31757 \begin_layout Standard
31763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31766 \begin_layout Standard
31767 Latest datasheet of target CPU
31772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31775 \begin_layout Standard
31782 <row topline="true" bottomline="true">
31783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31786 \begin_layout Standard
31792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31795 \begin_layout Standard
31796 Revision history of datasheet
31801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31804 \begin_layout Standard
31820 \begin_layout Section
31821 Application notes specifically for SDCC
31824 \begin_layout Standard
31825 SDCC makes no claims about the completeness of this list and about up-to-datenes
31826 s or correctness of the application notes
31827 \begin_inset LatexCommand \index{Application notes}
31834 \begin_layout Standard
31838 \begin_inset Tabular
31839 <lyxtabular version="3" rows="7" columns="3">
31841 <column alignment="block" valignment="top" leftline="true" width="17col%">
31842 <column alignment="block" valignment="top" leftline="true" width="27col%">
31843 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31844 <row topline="true" bottomline="true">
31845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31848 \begin_layout Standard
31857 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31860 \begin_layout Standard
31869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31872 \begin_layout Standard
31882 <row topline="true">
31883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31886 \begin_layout Standard
31894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31897 \begin_layout Standard
31900 Using the SDCC Compiler for the DS80C400
31901 \begin_inset LatexCommand \index{DS80C400}
31910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31913 \begin_layout Standard
31916 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31926 <row topline="true">
31927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31930 \begin_layout Standard
31938 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31941 \begin_layout Standard
31944 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31945 \begin_inset LatexCommand \index{DS89C4x0}
31949 Family of Microcontrollers
31954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31957 \begin_layout Standard
31960 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31970 <row topline="true">
31971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31974 \begin_layout Standard
31977 Silicon Laboratories / Cygnal
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31985 \begin_layout Standard
31988 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31989 \begin_inset LatexCommand \index{IDE}
31998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32001 \begin_layout Standard
32004 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32014 <row topline="true">
32015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32018 \begin_layout Standard
32021 Ramtron / Goal Semiconductor
32026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32029 \begin_layout Standard
32032 Interfacing SDCC to Syn and Textpad
32037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32040 \begin_layout Standard
32043 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32053 <row topline="true">
32054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32057 \begin_layout Standard
32060 Ramtron / Goal Semiconductor
32065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32068 \begin_layout Standard
32071 Installing and Configuring SDCC and Crimson Editor
32076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32079 \begin_layout Standard
32082 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32092 <row topline="true" bottomline="true">
32093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32096 \begin_layout Standard
32104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32107 \begin_layout Standard
32110 MSC12xx Programming with SDCC
32115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32118 \begin_layout Standard
32121 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32138 \begin_layout Section
32142 \begin_layout Standard
32143 Some questions answered, some pointers given - it might be time to in turn
32151 \begin_layout Itemize
32152 can you solve your project with the selected microcontroller? Would you
32153 find out early or rather late that your target is too small/slow/whatever?
32154 Can you switch to a slightly better device if it doesn't fit?
32157 \begin_layout Itemize
32158 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32159 and/or another programming language be more adequate? Would an operating
32160 system on the target device help?
32163 \begin_layout Itemize
32164 if you solved the problem, will the marketing department be happy?
32167 \begin_layout Itemize
32168 if the marketing department is happy, will customers be happy?
32171 \begin_layout Itemize
32172 if you're the project manager, marketing department and maybe even the customer
32173 in one person, have you tried to see the project from the outside?
32176 \begin_layout Itemize
32177 is the project done if you think it is done? Or is just that other interface/pro
32178 tocol/feature/configuration/option missing? How about website, manual(s),
32179 internationali(z|s)ation, packaging, labels, 2nd source for components,
32180 electromagnetic compatability/interference, documentation for production,
32181 production test software, update mechanism, patent issues?
32184 \begin_layout Itemize
32185 is your project adequately positioned in that magic triangle: fame, fortune,
32189 \begin_layout Standard
32190 Maybe not all answers to these questions are known and some answers may
32195 , nevertheless knowing these questions may help you to avoid burnout
32199 \begin_layout Standard
32200 burnout is bad for electronic devices, programmers and motorcycle tyres
32206 Chances are you didn't want to hear some of them...
32209 \begin_layout Chapter
32211 \begin_inset LatexCommand \index{Support}
32218 \begin_layout Standard
32219 SDCC has grown to be a large project.
32220 The compiler alone (without the preprocessor, assembler and linker) is
32221 well over 150,000 lines of code (blank stripped).
32222 The open source nature of this project is a key to its continued growth
32224 You gain the benefit and support of many active software developers and
32226 Is SDCC perfect? No, that's why we need your help.
32227 The developers take pride in fixing reported bugs.
32228 You can help by reporting the bugs and helping other SDCC users.
32229 There are lots of ways to contribute, and we encourage you to take part
32230 in making SDCC a great software package.
32233 \begin_layout Standard
32234 The SDCC project is hosted on the SDCC sourceforge site at
32235 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32240 You'll find the complete set of mailing lists
32241 \begin_inset LatexCommand \index{Mailing list(s)}
32245 , forums, bug reporting system, patch submission
32246 \begin_inset LatexCommand \index{Patch submission}
32251 \begin_inset LatexCommand \index{download}
32255 area and Subversion code repository
32256 \begin_inset LatexCommand \index{Subversion code repository}
32263 \begin_layout Section
32265 \begin_inset LatexCommand \index{Bug reporting}
32270 \begin_inset LatexCommand \index{Reporting bugs}
32277 \begin_layout Standard
32278 The recommended way of reporting bugs is using the infrastructure of the
32280 You can follow the status of bug reports there and have an overview about
32284 \begin_layout Standard
32285 Bug reports are automatically forwarded to the developer mailing list and
32286 will be fixed ASAP.
32287 When reporting a bug, it is very useful to include a small test program
32288 (the smaller the better) which reproduces the problem.
32289 If you can isolate the problem by looking at the generated assembly code,
32290 this can be very helpful.
32291 Compiling your program with the -
32295 \begin_layout Standard
32305 \begin_inset LatexCommand \index{-\/-dumpall}
32309 option can sometimes be useful in locating optimization problems.
32310 When reporting a bug please make sure you:
32313 \begin_layout Enumerate
32314 Attach the code you are compiling with SDCC.
32317 \begin_layout Enumerate
32318 Specify the exact command you use to run SDCC, or attach your Makefile.
32321 \begin_layout Enumerate
32322 Specify the SDCC version (type "
32328 "), your platform, and operating system.
32331 \begin_layout Enumerate
32332 Provide an exact copy of any error message or incorrect output.
32335 \begin_layout Enumerate
32336 Put something meaningful in the subject of your message.
32339 \begin_layout Standard
32340 Please attempt to include these 5 important parts, as applicable, in all
32341 requests for support or when reporting any problems or bugs with SDCC.
32342 Though this will make your message lengthy, it will greatly improve your
32343 chance that SDCC users and developers will be able to help you.
32344 Some SDCC developers are frustrated by bug reports without code provided
32345 that they can use to reproduce and ultimately fix the problem, so please
32346 be sure to provide sample code if you are reporting a bug!
32349 \begin_layout Standard
32350 Please have a short check that you are using a recent version of SDCC and
32351 the bug is not yet known.
32352 This is the link for reporting bugs:
32353 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32358 With SDCC on average having more than 200 downloads
32359 \begin_inset LatexCommand \index{download}
32363 on sourceforge per day
32367 \begin_layout Standard
32368 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32369 between 2002 and 2005.
32370 This does not include other methods of distribution.
32375 there must be some users.
32376 So it's not exactly easy to find a new bug.
32377 If you find one we need it:
32379 reporting bugs is good
32384 \begin_layout Section
32385 Requesting Features
32386 \begin_inset LatexCommand \label{sub:Requesting-Features}
32391 \begin_inset LatexCommand \index{Feature request}
32396 \begin_inset LatexCommand \index{Requesting features}
32403 \begin_layout Standard
32404 Like bug reports feature requests are forwarded to the developer mailing
32406 This is the link for requesting features:
32407 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32414 \begin_layout Section
32418 \begin_layout Standard
32419 Like bug reports contributed patches are forwarded to the developer mailing
32421 This is the link for submitting patches
32422 \begin_inset LatexCommand \index{Patch submission}
32427 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32434 \begin_layout Standard
32435 You need to specify some parameters to the
32439 command for the patches to be useful.
32440 If you modified more than one file a patch created f.e.
32445 \begin_inset Quotes sld
32448 diff -Naur unmodified_directory modified_directory >my_changes.patch
32449 \begin_inset Quotes srd
32455 will be fine, otherwise
32459 \begin_inset Quotes sld
32462 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32463 \begin_inset Quotes srd
32472 \begin_layout Section
32476 \begin_layout Standard
32477 These links should take you directly to the
32478 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32486 \begin_layout Standard
32487 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32488 automated messages (mid 2003)
32494 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32499 \begin_inset LatexCommand \index{Mailing list(s)}
32503 and forums are archived and searchable so if you are lucky someone already
32504 had a similar problem.
32505 While mails to the lists themselves are delivered promptly their web front
32506 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32507 if you're seriously using SDCC please consider subscribing to the lists.
32510 \begin_layout Section
32514 \begin_layout Standard
32515 You can follow the status of the Subversion version
32516 \begin_inset LatexCommand \index{version}
32520 of SDCC by watching the Changelog
32521 \begin_inset LatexCommand \index{Changelog}
32525 in the Subversion repository
32528 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32535 \begin_layout Section
32536 Subversion Source Code Repository
32539 \begin_layout Standard
32549 \begin_layout Standard
32563 or the filenames of the snapshot versions of SDCC include date and its
32565 \begin_inset LatexCommand \index{Subversion code repository}
32570 Subversion allows to download the source of recent or previous versions
32571 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32575 (by number or by date).
32576 An on-line source code browser and detailled instructions are also available
32578 SDCC versions starting from 1999 up to now are available (currently the
32579 versions prior to the conversion from cvs
32580 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32584 to Subversion (April 2006) are either by accessible by Subversion or by
32588 \begin_layout Section
32590 \begin_inset LatexCommand \index{Release policy}
32597 \begin_layout Standard
32598 Historically there often were long delays between official releases and
32599 the sourceforge download area tends to get not updated at all.
32600 Excuses in the past might have referred to problems with live range analysis,
32601 but as this was fixed a while ago, the current problem is that another
32602 excuse has to be found.
32603 Kidding aside, we have to get better there! On the other hand there are
32604 daily snapshots available at
32605 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32609 , and you can always build the very last version (hopefully with many bugs
32610 fixed, and features added) from the source code available at
32611 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32617 \begin_inset LatexCommand \index{wiki}
32622 \begin_inset LatexCommand \index{SDCC Wiki}
32627 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32631 also holds some information about past and future releases.
32634 \begin_layout Section
32636 \begin_inset LatexCommand \index{Examples}
32643 \begin_layout Standard
32644 You'll find some small examples in the directory
32646 sdcc/device/examples/.
32648 More examples and libraries are available at
32650 The SDCC Open Knowledge Resource
32651 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32658 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32665 \begin_layout Standard
32666 \begin_inset Note Note
32669 \begin_layout Standard
32670 I did insert a reference to Paul's web site here although it seems rather
32671 dedicated to a specific 8032 board (I think it's okay because it f.e.
32672 shows LCD/Harddisc interface and has a free 8051 monitor.
32673 Independent 8032 board vendors face hard competition of heavily subsidized
32674 development boards anyway).
32677 \begin_layout Standard
32678 Maybe we should include some links to real world applications.
32679 Preferably pointer to pointers (one for each architecture) so this stays
32688 \begin_layout Section
32690 \begin_inset LatexCommand \label{sec:Quality-control}
32695 \begin_inset LatexCommand \index{Quality control}
32702 \begin_layout Standard
32703 The compiler is passed through snaphot build compile and build checks.
32709 \begin_inset LatexCommand \index{Regression test}
32713 check that SDCC itself compiles flawlessly on several host platforms (i386,
32714 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
32715 and checks the quality of the code generated by SDCC by running the code
32716 for several target platforms through simulators.
32717 The regression test suite comprises more than 100 files which expand to
32718 more than 500 test cases which include more than 4500 tests.
32719 The results of these tests are published daily on SDCC's snapshot page
32720 (click on the red or green symbols on the right side of
32721 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32728 \begin_layout Standard
32729 There is a separate document
32732 \begin_inset LatexCommand \index{Test suite}
32739 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32743 about the regression test suite.
32746 \begin_layout Standard
32747 You'll find the test code in the directory
32749 sdcc/support/regression
32752 You can run these tests manually by running
32756 in this directory (or f.e.
32760 \begin_inset Quotes sld
32764 \begin_inset Quotes srd
32770 if you don't want to run the complete tests).
32771 The test code might also be interesting if you want to look for examples
32772 \begin_inset LatexCommand \index{Examples}
32776 checking corner cases of SDCC or if you plan to submit patches
32777 \begin_inset LatexCommand \index{Patch submission}
32784 \begin_layout Standard
32785 The PIC14 port uses a different set of regression tests
32786 \begin_inset LatexCommand \index{Regression test (PIC14)}
32790 , you'll find them in the directory
32792 sdcc/src/regression
32797 \begin_layout Section
32798 Use of SDCC in Education
32801 \begin_layout Standard
32810 \begin_layout Standard
32811 the phrase "use in education" might evoke the association "
32815 fit for use in education".
32816 This connotation is not intended but nevertheless risked as the licensing
32817 of SDCC makes it difficult to offer educational discounts
32823 If your rationales are to:
32826 \begin_layout Enumerate
32827 give students a chance to understand the
32831 steps of code generation
32834 \begin_layout Enumerate
32835 have a curriculum that can be extended for years.
32836 Then you could use an fpga board as target and your curriculum will seamlessly
32837 extend from logic synthesis (
32838 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32843 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32847 ), over assembly programming, to C to FPGA compilers (
32848 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32855 \begin_layout Enumerate
32856 be able to insert excursions about skills like using a revision control
32857 system, submitting/applying patches, using a type-setting (as opposed to
32858 word-processing) engine LyX/LaTeX, using
32859 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32864 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32868 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32869 Source Software, CPU simulation, compiler regression tests
32870 \begin_inset LatexCommand \index{Regression test}
32876 And if there should be a shortage of ideas then you can always point students
32877 to the ever-growing feature request list
32878 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32885 \begin_layout Enumerate
32886 not tie students to a specific host platform and instead allow them to use
32891 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32893 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32900 \begin_layout Enumerate
32901 not encourage students to use illegal copies of educational software
32904 \begin_layout Enumerate
32905 be immune to licensing/availability/price changes of the chosen tool chain
32908 \begin_layout Enumerate
32909 be able to change to a new target platform without having to adopt a new
32913 \begin_layout Enumerate
32914 have complete control over and insight into the tool chain
32917 \begin_layout Enumerate
32918 make your students aware about the pros and cons of open source software
32922 \begin_layout Enumerate
32923 give back to the public as you are probably at least partially publically
32927 \begin_layout Enumerate
32928 give students a chance to publically prove their skills and to possibly
32929 see a world wide impact
32932 \begin_layout Standard
32933 then SDCC is probably among the first choices.
32934 Well, probably SDCC might be the only choice.
32939 \begin_layout Chapter
32940 SDCC Technical Data
32943 \begin_layout Section
32945 \begin_inset LatexCommand \index{Optimizations}
32952 \begin_layout Standard
32953 SDCC performs a host of standard optimizations in addition to some MCU specific
32957 \begin_layout Subsection
32958 Sub-expression Elimination
32959 \begin_inset LatexCommand \index{Subexpression elimination}
32966 \begin_layout Standard
32967 The compiler does local and
32986 \begin_layout Verse
32994 \begin_layout Standard
32995 will be translated to
32998 \begin_layout Verse
33008 \begin_layout Standard
33009 Some subexpressions are not as obvious as the above example, e.g.:
33012 \begin_layout Verse
33020 \begin_layout Standard
33021 In this case the address arithmetic a->b[i] will be computed only once;
33022 the equivalent code in C would be.
33025 \begin_layout Verse
33035 \begin_layout Standard
33036 The compiler will try to keep these temporary variables in registers.
33039 \begin_layout Subsection
33040 Dead-Code Elimination
33041 \begin_inset LatexCommand \index{Dead-code elimination}
33048 \begin_layout Verse
33063 i = 1; \InsetSpace ~
33072 global = 1;\InsetSpace ~
33086 global = 3;\InsetSpace ~
33092 \begin_layout Standard
33096 \begin_layout Verse
33112 \begin_layout Subsection
33114 \begin_inset LatexCommand \index{Copy propagation}
33121 \begin_layout Verse
33145 \begin_layout Standard
33149 \begin_layout Verse
33173 \begin_layout Standard
33174 Note: the dead stores created by this copy propagation will be eliminated
33175 by dead-code elimination.
33178 \begin_layout Subsection
33180 \begin_inset LatexCommand \index{Loop optimization}
33185 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33192 \begin_layout Standard
33193 Two types of loop optimizations are done by SDCC
33201 of loop induction variables.
33202 In addition to the strength reduction the optimizer marks the induction
33203 variables and the register allocator tries to keep the induction variables
33204 in registers for the duration of the loop.
33205 Because of this preference of the register allocator
33206 \begin_inset LatexCommand \index{Register allocation}
33210 , loop induction optimization causes an increase in register pressure, which
33211 may cause unwanted spilling of other temporary variables into the stack
33212 \begin_inset LatexCommand \index{stack}
33217 The compiler will generate a warning message when it is forced to allocate
33218 extra space either on the stack or data space.
33219 If this extra space allocation is undesirable then induction optimization
33220 can be eliminated either for the entire source file (with -
33224 \begin_layout Standard
33233 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33235 \begin_inset LatexCommand \index{\#pragma noinduction}
33246 \begin_layout Verse
33249 for (i = 0 ; i < 100 ; i ++)
33258 \begin_layout Standard
33262 \begin_layout Verse
33267 for (i = 0; i < 100; i++)
33276 \begin_layout Standard
33277 As mentioned previously some loop invariants are not as apparent, all static
33278 address computations are also moved out of the loop.
33283 \begin_inset LatexCommand \index{Strength reduction}
33287 , this optimization substitutes an expression by a cheaper expression:
33290 \begin_layout Verse
33293 for (i=0;i < 100; i++)
33302 \begin_layout Standard
33306 \begin_layout Verse
33313 for (i=0;i< 100;i++) {
33319 ar[itemp1] = itemp2;
33337 \begin_layout Standard
33338 The more expensive multiplication
33339 \begin_inset LatexCommand \index{Multiplication}
33343 is changed to a less expensive addition.
33346 \begin_layout Subsection
33348 \begin_inset LatexCommand \index{Loop reversing}
33355 \begin_layout Standard
33356 This optimization is done to reduce the overhead of checking loop boundaries
33357 for every iteration.
33358 Some simple loops can be reversed and implemented using a
33359 \begin_inset Quotes eld
33362 decrement and jump if not zero
33363 \begin_inset Quotes erd
33367 SDCC checks for the following criterion to determine if a loop is reversible
33368 (note: more sophisticated compilers use data-dependency analysis to make
33369 this determination, SDCC uses a more simple minded analysis).
33372 \begin_layout Itemize
33373 The 'for' loop is of the form
33379 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33389 \begin_layout Itemize
33390 The <for body> does not contain
33391 \begin_inset Quotes eld
33395 \begin_inset Quotes erd
33399 \begin_inset Quotes erd
33405 \begin_layout Itemize
33406 All goto's are contained within the loop.
33409 \begin_layout Itemize
33410 No function calls within the loop.
33413 \begin_layout Itemize
33414 The loop control variable <sym> is not assigned any value within the loop
33417 \begin_layout Itemize
33418 The loop control variable does NOT participate in any arithmetic operation
33422 \begin_layout Itemize
33423 There are NO switch statements in the loop.
33426 \begin_layout Subsection
33427 Algebraic Simplifications
33430 \begin_layout Standard
33431 SDCC does numerous algebraic simplifications, the following is a small sub-set
33432 of these optimizations.
33435 \begin_layout Verse
33438 i = j + 0;\InsetSpace ~
33442 /* changed to: */\InsetSpace ~
33448 i /= 2;\InsetSpace ~
33455 /* changed to: */\InsetSpace ~
33462 j - j;\InsetSpace ~
33466 /* changed to: */\InsetSpace ~
33472 i = j / 1;\InsetSpace ~
33476 /* changed to: */\InsetSpace ~
33483 \begin_layout Standard
33484 Note the subexpressions
33485 \begin_inset LatexCommand \index{Subexpression}
33489 given above are generally introduced by macro expansions or as a result
33490 of copy/constant propagation.
33493 \begin_layout Subsection
33494 'switch' Statements
33495 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33500 \begin_inset LatexCommand \index{switch statement}
33507 \begin_layout Standard
33508 SDCC can optimize switch statements to jump tables
33509 \begin_inset LatexCommand \index{jump tables}
33514 It makes the decision based on an estimate of the generated code size.
33515 SDCC is quite liberal in the requirements for jump table generation:
33518 \begin_layout Itemize
33519 The labels need not be in order, and the starting number need not be one
33520 or zero, the case labels are in numerical sequence or not too many case
33521 labels are missing.
33525 \begin_layout Verse
33528 switch(i) {\InsetSpace ~
33559 case 4: ...\InsetSpace ~
33590 case 5: ...\InsetSpace ~
33621 case 3: ...\InsetSpace ~
33652 case 6: ...\InsetSpace ~
33684 case 7: ...\InsetSpace ~
33715 case 8: ...\InsetSpace ~
33746 case 9: ...\InsetSpace ~
33777 case 10: ...\InsetSpace ~
33808 11: ...\InsetSpace ~
33874 \begin_layout Standard
33875 Both the above switch statements will be implemented using a jump-table.
33876 The example to the right side is slightly more efficient as the check for
33877 the lower boundary of the jump-table is not needed.
33881 \begin_layout Itemize
33882 The number of case labels is not larger than supported by the target architectur
33886 \begin_layout Itemize
33887 If the case labels are not in numerical sequence ('gaps' between cases)
33888 SDCC checks whether a jump table with additionally inserted dummy cases
33889 is still attractive.
33892 \begin_layout Itemize
33893 If the starting number is not zero and a check for the lower boundary of
33894 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33899 \begin_layout Standard
33900 Switch statements which have large gaps in the numeric sequence or those
33901 that have too many case labels can be split into more than one switch statement
33902 for efficient code generation, e.g.:
33905 \begin_layout Verse
33970 \begin_layout Standard
33971 If the above switch statement is broken down into two switch statements
33974 \begin_layout Verse
34010 \begin_layout Standard
34014 \begin_layout Verse
34051 \begin_layout Standard
34052 then both the switch statements will be implemented using jump-tables whereas
34053 the unmodified switch statement will not be.
34056 \begin_layout Standard
34057 \begin_inset Note Note
34060 \begin_layout Standard
34061 There might be reasons which SDCC cannot know about to either favour or
34062 not favour jump tables.
34063 If the target system has to be as quick for the last switch case as for
34064 the first (pro jump table), or if the switch argument is known to be zero
34065 in the majority of the cases (contra jump table).
34073 \begin_layout Standard
34074 The pragma nojtbound
34075 \begin_inset LatexCommand \index{\#pragma nojtbound}
34079 can be used to turn off checking the
34092 It has no effect if a default label is supplied.
34093 Use of this pragma is dangerous: if the switch
34094 \begin_inset LatexCommand \index{switch statement}
34098 argument is not matched by a case statement the processor will happily
34102 \begin_layout Subsection
34103 Bit-shifting Operations
34104 \begin_inset LatexCommand \index{Bit shifting}
34111 \begin_layout Standard
34112 Bit shifting is one of the most frequently used operation in embedded programmin
34114 SDCC tries to implement bit-shift operations in the most efficient way
34118 \begin_layout Verse
34130 \begin_layout Standard
34131 generates the following code:
34134 \begin_layout Verse
34149 \begin_layout Standard
34150 In general SDCC will never setup a loop if the shift count is known.
34154 \begin_layout Verse
34166 \begin_layout Standard
34170 \begin_layout Verse
34194 \begin_layout Subsection
34196 \begin_inset LatexCommand \index{Bit rotation}
34203 \begin_layout Standard
34204 A special case of the bit-shift operation is bit rotation
34205 \begin_inset LatexCommand \index{rotating bits}
34209 , SDCC recognizes the following expression to be a left bit-rotation:
34212 \begin_layout Verse
34220 char i;\InsetSpace ~
34231 /* unsigned is needed for rotation */
34235 i = ((i << 1) | (i >> 7));
34244 \begin_layout Standard
34245 will generate the following code:
34248 \begin_layout Verse
34265 \begin_layout Standard
34266 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34267 ns of this case will also be recognized as bit-rotation, i.e.:
34270 \begin_layout Verse
34273 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34276 \begin_layout Subsection
34277 Nibble and Byte Swapping
34280 \begin_layout Standard
34281 Other special cases of the bit-shift operations are nibble or byte swapping
34282 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34286 , SDCC recognizes the following expressions:
34289 \begin_layout Verse
34309 i = ((i << 4) | (i >> 4));
34315 j = ((j << 8) | (j >> 8));
34318 \begin_layout Standard
34319 and generates a swap instruction for the nibble swapping
34320 \begin_inset LatexCommand \index{Nibble swapping}
34324 or move instructions for the byte swapping
34325 \begin_inset LatexCommand \index{Byte swapping}
34331 \begin_inset Quotes sld
34335 \begin_inset Quotes srd
34338 example can be used to convert from little to big-endian or vice versa.
34339 If you want to change the endianness of a
34343 integer you have to cast to
34350 \begin_layout Standard
34351 Note that SDCC stores numbers in little-endian
34355 \begin_layout Standard
34356 Usually 8-bit processors don't care much about endianness.
34357 This is not the case for the standard 8051 which only has an instruction
34363 \begin_inset LatexCommand \index{DPTR}
34367 -datapointerso little-endian is the more efficient byte order.
34373 \begin_inset LatexCommand \index{little-endian}
34378 \begin_inset LatexCommand \index{Endianness}
34383 lowest order first).
34386 \begin_layout Subsection
34388 \begin_inset LatexCommand \index{Highest Order Bit}
34393 \begin_inset LatexCommand \index{Any Order Bit}
34400 \begin_layout Standard
34401 It is frequently required to obtain the highest order bit of an integral
34402 type (long, int, short or char types).
34403 Also obtaining any other order bit is not uncommon.
34404 SDCC recognizes the following expressions to yield the highest order bit
34405 and generates optimized code for it, e.g.:
34408 \begin_layout Verse
34419 unsigned char hob1, aob1;
34423 bit hob2, hob3, aob2,
34432 hob1 = (gint >> 15) & 1;
34436 hob2 = (gint >> 15) & 1;
34440 hob3 = gint & 0x8000;
34449 aob2 = (gint >> 8) & 1;
34453 aob3 = gint & 0x0800;
34462 \begin_layout Standard
34463 will generate the following code:
34466 \begin_layout Verse
34497 000A E5*01\InsetSpace ~
34524 000C 23\InsetSpace ~
34555 000D 54 01\InsetSpace ~
34583 000F F5*02\InsetSpace ~
34638 0011 E5*01\InsetSpace ~
34666 0013 33\InsetSpace ~
34696 0014 92*00\InsetSpace ~
34752 0016 E5*01\InsetSpace ~
34779 0018 33\InsetSpace ~
34809 0019 92*01\InsetSpace ~
34865 001B E5*01\InsetSpace ~
34892 001D 03\InsetSpace ~
34923 001E 54 01\InsetSpace ~
34951 0020 F5*03\InsetSpace ~
35006 0022 E5*01\InsetSpace ~
35034 0024 13\InsetSpace ~
35064 0025 92*02\InsetSpace ~
35120 0027 E5*01\InsetSpace ~
35147 0029 A2 E3\InsetSpace ~
35203 \begin_layout Standard
35204 Other variations of these cases however will
35209 They are standard C expressions, so I heartily recommend these be the only
35210 way to get the highest order bit, (it is portable).
35211 Of course it will be recognized even if it is embedded in other expressions,
35215 \begin_layout Verse
35218 xyz = gint + ((gint >> 15) & 1);
35221 \begin_layout Standard
35222 will still be recognized.
35225 \begin_layout Subsection
35227 \begin_inset LatexCommand \index{Higher Order Byte}
35231 / Higher Order Word
35232 \begin_inset LatexCommand \index{Higher Order Word}
35239 \begin_layout Standard
35240 It is also frequently required to obtain a higher order byte or word of
35241 a larger integral type (long, int or short types).
35242 SDCC recognizes the following expressions to yield the higher order byte
35243 or word and generates optimized code for it, e.g.:
35246 \begin_layout Verse
35251 unsigned long int glong;
35259 unsigned char hob1, hob2;
35264 ned int how1, how2;
35272 hob1 = (gint >> 8) & 0xFF;
35276 hob2 = glong >> 24;
35294 \begin_layout Standard
35295 will generate the following code:
35298 \begin_layout Verse
35329 0037 85*01*06\InsetSpace ~
35351 _foo_hob1_1_1,(_gint + 1)
35382 85*05*07\InsetSpace ~
35404 _foo_hob2_1_1,(_glong + 3)
35434 003D 85*04*08\InsetSpace ~
35457 _foo_how1_1_1,(_glong + 2)
35459 0040 85*05*09\InsetSpace ~
35481 (_foo_how1_1_1 + 1),(_glong
35484 0043 85*03*0A\InsetSpace ~
35506 _foo_how2_1_1,(_glong + 1)
35508 0046 85*04*0B\InsetSpace ~
35531 (_foo_how2_1_1 + 1),(_glong + 2)
35534 \begin_layout Standard
35535 Again, variations of these cases may
35540 They are standard C expressions, so I heartily recommend these be the only
35541 way to get the higher order byte/word, (it is portable).
35542 Of course it will be recognized even if it is embedded in other expressions,
35546 \begin_layout Verse
35549 xyz = gint + ((gint >> 8) & 0xFF);
35552 \begin_layout Standard
35553 will still be recognized.
35556 \begin_layout Subsection
35558 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35563 \begin_inset LatexCommand \index{Peephole optimizer}
35570 \begin_layout Standard
35571 The compiler uses a rule based, pattern matching and re-writing mechanism
35572 for peep-hole optimization.
35577 a peep-hole optimizer by Christopher W.
35578 Fraser (cwfraser\InsetSpace ~
35581 A default set of rules are compiled into the compiler, additional rules
35582 may be added with the
35588 \begin_layout Standard
35598 \begin_inset LatexCommand \index{-\/-peep-file}
35605 The rule language is best illustrated with examples.
35608 \begin_layout Verse
35630 \begin_layout Standard
35631 The above rule will change the following assembly
35632 \begin_inset LatexCommand \index{Assembler routines}
35639 \begin_layout Verse
35647 \begin_layout Standard
35651 \begin_layout Verse
35657 \begin_layout Standard
35658 Note: All occurrences of a
35662 (pattern variable) must denote the same string.
35663 With the above rule, the assembly sequence:
35666 \begin_layout Verse
35674 \begin_layout Standard
35675 will remain unmodified.
35679 Other special case optimizations may be added by the
35686 \begin_layout Standard
35699 some variants of the 8051 MCU
35700 \begin_inset LatexCommand \index{MCS51 variants}
35713 The following two rules will change all
35730 \begin_layout Verse
35733 replace { lcall %1 } by { acall %1 }
35735 replace { ljmp %1 } by { ajmp %1 }
35738 \begin_layout Standard
35739 (NOTE: from version 2.7.3 on, you can use option -
35745 \begin_layout Standard
35757 \begin_inset LatexCommand \index{-\/-acall-ajmp}
35761 , which also takes care of aligning the interrupt vectors properly.)
35766 \begin_layout Standard
35769 inline-assembler code
35771 is also passed through the peep hole optimizer, thus the peephole optimizer
35772 can also be used as an assembly level macro expander.
35773 The rules themselves are MCU dependent whereas the rule language infra-structur
35774 e is MCU independent.
35775 Peephole optimization rules for other MCU can be easily programmed using
35780 The syntax for a rule is as follows:
35783 \begin_layout Verse
35786 rule := replace [ restart ] '{' <assembly sequence> '
35824 <assembly sequence> '
35842 '}' [if <functionName> ] '
35847 \begin_layout Standard
35848 <assembly sequence> := assembly instruction (each instruction including
35849 labels must be on a separate line).
35853 The optimizer will apply to the rules
35854 one by one from the top in the sequence of their appearance, it will terminate
35855 when all rules are exhausted.
35856 If the 'restart' option is specified, then the optimizer will start matching
35857 the rules again from the top, this option for a rule is expensive (performance)
35858 , it is intended to be used in situations where a transformation will trigger
35859 the same rule again.
35860 An example of this (not a good one, it has side effects) is the following
35864 \begin_layout Verse
35884 \begin_layout Standard
35885 Note that the replace pattern cannot be a blank, but can be a comment line.
35886 Without the 'restart' option only the innermost 'pop' 'push' pair would
35887 be eliminated, i.e.:
35890 \begin_layout Verse
35902 \begin_layout Standard
35906 \begin_layout Verse
35916 \begin_layout Standard
35921 the restart option the rule will be applied again to the resulting code
35922 and then all the pop-push pairs will be eliminated to yield:
35925 \begin_layout Verse
35933 \begin_layout Standard
35934 A conditional function can be attached to a rule.
35935 Attaching rules are somewhat more involved, let me illustrate this with
35939 \begin_layout Verse
35963 \begin_layout Standard
35964 The optimizer does a look-up of a function name table defined in function
35968 in the source file SDCCpeeph.c, with the name
35973 If it finds a corresponding entry the function is called.
35974 Note there can be no parameters specified for these functions, in this
35979 is crucial, since the function
35983 expects to find the label in that particular variable (the hash table containin
35984 g the variable bindings is passed as a parameter).
35985 If you want to code more such functions, take a close look at the function
35986 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35987 Currently implemented are
35989 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35990 24bitMode, portIsDS390, 24bitModeAndPortDS390
35999 \begin_layout Standard
36000 I know this whole thing is a little kludgey, but maybe some day we will
36001 have some better means.
36002 If you are looking at this file, you will see the default rules that are
36003 compiled into the compiler, you can add your own rules in the default set
36004 there if you get tired of specifying the -
36008 \begin_layout Standard
36020 \begin_layout Section
36022 \begin_inset LatexCommand \index{ANSI-compliance}
36027 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36034 \begin_layout Standard
36035 The latest publically available version of the standard
36037 ISO/IEC 9899 - Programming languages - C
36039 should be available at:
36040 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36049 \begin_layout Standard
36050 Deviations from the compliance:
36053 \begin_layout Itemize
36054 functions are not reentrant
36055 \begin_inset LatexCommand \index{reentrant}
36059 unless explicitly declared as such or the
36065 \begin_layout Standard
36075 \begin_inset LatexCommand \index{-\/-stack-auto}
36081 command line option is specified.
36084 \begin_layout Itemize
36086 \begin_inset LatexCommand \index{struct}
36091 \begin_inset LatexCommand \index{union}
36095 cannot be assigned values directly, cannot be passed as function parameters
36096 or assigned to each other and cannot be a return value
36097 \begin_inset LatexCommand \index{return value}
36101 from a function, e.g.:
36105 \begin_layout Verse
36127 s1 = s2 ; /* is invalid in SDCC although allowed
36146 s parms) /* invalid in SDCC although allowed in ANSI */
36167 rets; /* is invalid in SDCC although allowed in ANSI */
36173 \begin_layout Itemize
36174 initialization of structure arrays must be fully braced.
36178 \begin_layout Verse
36181 struct s { char x } a[] = {1, 2};\InsetSpace ~
36186 /* invalid in SDCC */
36189 } a[] = {{1}, {2}}; /* OK */
36193 \begin_layout Itemize
36195 \begin_inset LatexCommand \index{long long (not supported)}
36200 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36207 \begin_layout Itemize
36209 \begin_inset LatexCommand \index{double (not supported)}
36213 ' precision floating point
36214 \begin_inset LatexCommand \index{Floating point support}
36221 \begin_layout Itemize
36223 \begin_inset LatexCommand \index{K\&R style}
36227 function declarations are NOT allowed.
36231 \begin_layout Verse
36234 foo(i,j) /* this old style of function declarations */
36236 int i,j; /* is valid
36237 in ANSI but not valid in SDCC */
36251 \begin_layout Itemize
36252 Most enhancements in C99 are not supported, e.g.:
36256 \begin_layout Verse
36263 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36267 \begin_layout Itemize
36268 But some have been added recently in SDCC 2.7.0.
36269 They must be considered alpha quality however.
36273 \begin_layout Verse
36278 \begin_inset LatexCommand \index{inline (not supported)}
36284 int increment (int a) { return a+1; } /* inlines the increment without
36285 function call overhead */
36290 \begin_inset LatexCommand \index{inline (not supported)}
36296 p; /* accepted but ignored */
36300 \begin_layout Itemize
36301 Certain words that are valid identifiers in the standard may be reserved
36302 words in SDCC unless the
36308 \begin_layout Standard
36318 \begin_inset LatexCommand \index{-\/-std-c89}
36326 \begin_layout Standard
36336 \begin_inset LatexCommand \index{-\/-std-c99}
36342 command line options are used.
36343 These may include (depending on the selected processor): 'at', 'banked',
36344 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36345 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36346 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36348 Compliant equivalents of these keywords are always available in a form
36349 that begin with two underscores
36350 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36355 '__data' instead of 'data'.
36358 \begin_layout Itemize
36359 integer promotion of variable arguments is not performed if the argument
36360 is explicitly taypecasted unless the
36366 \begin_layout Standard
36376 \begin_inset LatexCommand \index{-\/-std-c89}
36384 \begin_layout Standard
36394 \begin_inset LatexCommand \index{-\/-std-c99}
36400 command line options are used.
36404 \begin_layout Verse
36407 void vararg_func (char *str, ...) { atr; }
36424 u is promoted to int before
36429 * passing to function */
36434 \begin_inset Quotes sld
36438 \begin_inset Quotes srd
36447 /* argument u is not promoted to int,
36452 * it is passed as char to function
36458 if --std-cXX is not defined;
36463 * is promoted to int before passing
36469 if --std-cXX is defined */
36474 \begin_inset Quotes sld
36478 \begin_inset Quotes srd
36487 \begin_layout Section
36488 Cyclomatic Complexity
36489 \begin_inset LatexCommand \index{Cyclomatic complexity}
36496 \begin_layout Standard
36497 Cyclomatic complexity of a function is defined as the number of independent
36498 paths the program can take during execution of the function.
36499 This is an important number since it defines the number test cases you
36500 have to generate to validate the function.
36501 The accepted industry standard for complexity number is 10, if the cyclomatic
36502 complexity reported by SDCC exceeds 10 you should think about simplification
36503 of the function logic.
36504 Note that the complexity level is not related to the number of lines of
36505 code in a function.
36506 Large functions can have low complexity, and small functions can have large
36511 SDCC uses the following formula to compute the complexity:
36516 \begin_layout Standard
36517 complexity = (number of edges in control flow graph) - (number of nodes
36518 in control flow graph) + 2;
36522 Having said that the industry standard is 10,
36523 you should be aware that in some cases it be may unavoidable to have a
36524 complexity level of less than 10.
36525 For example if you have switch statement with more than 10 case labels,
36526 each case label adds one to the complexity level.
36527 The complexity level is by no means an absolute measure of the algorithmic
36528 complexity of the function, it does however provide a good starting point
36529 for which functions you might look at for further optimization.
36532 \begin_layout Section
36533 Retargetting for other Processors
36536 \begin_layout Standard
36537 The issues for retargetting the compiler are far too numerous to be covered
36539 What follows is a brief description of each of the seven phases of the
36540 compiler and its MCU dependency.
36543 \begin_layout Itemize
36544 Parsing the source and building the annotated parse tree.
36545 This phase is largely MCU independent (except for the language extensions).
36546 Syntax & semantic checks are also done in this phase, along with some initial
36547 optimizations like back patching labels and the pattern matching optimizations
36548 like bit-rotation etc.
36551 \begin_layout Itemize
36552 The second phase involves generating an intermediate code which can be easy
36553 manipulated during the later phases.
36554 This phase is entirely MCU independent.
36555 The intermediate code generation assumes the target machine has unlimited
36556 number of registers, and designates them with the name iTemp.
36557 The compiler can be made to dump a human readable form of the code generated
36562 \begin_layout Standard
36574 \begin_layout Itemize
36575 This phase does the bulk of the standard optimizations and is also MCU independe
36577 This phase can be broken down into several sub-phases:
36581 Break down intermediate
36582 code (iCode) into basic blocks.
36584 Do control flow & data flow analysis on the
36587 Do local common subexpression elimination, then global subexpressio
36590 Dead code elimination
36594 If loop optimizations
36595 caused any changes then do 'global subexpression elimination' and 'dead
36596 code elimination' again.
36599 \begin_layout Itemize
36600 This phase determines the live-ranges; by live range I mean those iTemp
36601 variables defined by the compiler that still survive after all the optimization
36603 Live range analysis
36604 \begin_inset LatexCommand \index{Live range analysis}
36608 is essential for register allocation, since these computation determines
36609 which of these iTemps will be assigned to registers, and for how long.
36612 \begin_layout Itemize
36613 Phase five is register allocation.
36614 There are two parts to this process.
36618 The first part I call 'register packing'
36619 (for lack of a better term).
36620 In this case several MCU specific expression folding is done to reduce
36625 The second part is more MCU independent and deals with
36626 allocating registers to the remaining live ranges.
36627 A lot of MCU specific code does creep into this phase because of the limited
36628 number of index registers available in the 8051.
36631 \begin_layout Itemize
36632 The Code generation phase is (unhappily), entirely MCU dependent and very
36633 little (if any at all) of this code can be reused for other MCU.
36634 However the scheme for allocating a homogenized assembler operand for each
36635 iCode operand may be reused.
36638 \begin_layout Itemize
36639 As mentioned in the optimization section the peep-hole optimizer is rule
36640 based system, which can reprogrammed for other MCUs.
36643 \begin_layout Standard
36644 More information is available on SDCC Wiki
36645 \begin_inset LatexCommand \index{wiki}
36650 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36654 ) and in the thread
36655 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36662 \begin_layout Chapter
36664 \begin_inset LatexCommand \index{Compiler internals}
36671 \begin_layout Section
36672 The anatomy of the compiler
36673 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36680 \begin_layout Standard
36683 This is an excerpt from an article published in Circuit Cellar Magazine
36689 It's a little outdated (the compiler is much more efficient now and user/develo
36690 per friendly), but pretty well exposes the guts of it all.
36696 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36697 It is fairly easy to retarget for other 8-bit MCU.
36698 Here we take a look at some of the internals of the compiler.
36701 \begin_layout Paragraph*
36703 \begin_inset LatexCommand \index{Parsing}
36710 \begin_layout Standard
36711 Parsing the input source file and creating an AST (Annotated Syntax Tree
36712 \begin_inset LatexCommand \index{Annotated syntax tree}
36717 This phase also involves propagating types (annotating each node of the
36718 parse tree with type information) and semantic analysis.
36719 There are some MCU specific parsing rules.
36720 For example the storage classes, the extended storage classes are MCU specific
36721 while there may be a xdata storage class for 8051 there is no such storage
36722 class for z80 or Atmel AVR.
36723 SDCC allows MCU specific storage class extensions, i.e.
36724 xdata will be treated as a storage class specifier when parsing 8051 C
36725 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36729 \begin_layout Paragraph*
36731 \begin_inset LatexCommand \index{iCode}
36738 \begin_layout Standard
36739 Intermediate code generation.
36740 In this phase the AST is broken down into three-operand form (iCode).
36741 These three operand forms are represented as doubly linked lists.
36742 ICode is the term given to the intermediate form generated by the compiler.
36743 ICode example section shows some examples of iCode generated for some simple
36744 C source functions.
36747 \begin_layout Paragraph*
36749 \begin_inset LatexCommand \index{Optimizations}
36756 \begin_layout Standard
36757 Bulk of the target independent optimizations is performed in this phase.
36758 The optimizations include constant propagation, common sub-expression eliminati
36759 on, loop invariant code movement, strength reduction of loop induction variables
36760 and dead-code elimination.
36763 \begin_layout Paragraph*
36764 Live range analysis
36765 \begin_inset LatexCommand \index{Live range analysis}
36772 \begin_layout Standard
36773 During intermediate code generation phase, the compiler assumes the target
36774 machine has infinite number of registers and generates a lot of temporary
36776 The live range computation determines the lifetime of each of these compiler-ge
36777 nerated temporaries.
36778 A picture speaks a thousand words.
36779 ICode example sections show the live range annotations for each of the
36781 It is important to note here, each iCode is assigned a number in the order
36782 of its execution in the function.
36783 The live ranges are computed in terms of these numbers.
36784 The from number is the number of the iCode which first defines the operand
36785 and the to number signifies the iCode which uses this operand last.
36788 \begin_layout Paragraph*
36789 Register Allocation
36790 \begin_inset LatexCommand \index{Register allocation}
36797 \begin_layout Standard
36798 The register allocation determines the type and number of registers needed
36800 In most MCUs only a few registers can be used for indirect addressing.
36801 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36802 address the internal ram and DPTR to indirectly address the external ram.
36803 The compiler will try to allocate the appropriate register to pointer variables
36805 ICode example section shows the operands annotated with the registers assigned
36807 The compiler will try to keep operands in registers as much as possible;
36808 there are several schemes the compiler uses to do achieve this.
36809 When the compiler runs out of registers the compiler will check to see
36810 if there are any live operands which is not used or defined in the current
36811 basic block being processed, if there are any found then it will push that
36812 operand and use the registers in this block, the operand will then be popped
36813 at the end of the basic block.
36816 \begin_layout Standard
36817 There are other MCU specific considerations in this phase.
36818 Some MCUs have an accumulator; very short-lived operands could be assigned
36819 to the accumulator instead of a general-purpose register.
36822 \begin_layout Paragraph*
36826 \begin_layout Standard
36827 Figure II gives a table of iCode
36828 \begin_inset LatexCommand \index{iCode}
36832 operations supported by the compiler.
36833 The code generation involves translating these operations into corresponding
36834 assembly code for the processor.
36835 This sounds overly simple but that is the essence of code generation.
36836 Some of the iCode operations are generated on a MCU specific manner for
36837 example, the z80 port does not use registers to pass parameters so the
36838 SEND and RECV iCode operations will not be generated, and it also does
36839 not support JUMPTABLES.
36844 \begin_layout Standard
36848 \begin_inset Tabular
36849 <lyxtabular version="3" rows="39" columns="4">
36850 <features islongtable="true" headBottomDL="true">
36851 <column alignment="block" valignment="top" leftline="true" width="13col%">
36852 <column alignment="left" valignment="top" leftline="true" width="13col%">
36853 <column alignment="block" valignment="top" leftline="true" width="22col%">
36854 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36855 <row topline="true" bottomline="true" endhead="true">
36856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36859 \begin_layout Standard
36865 \begin_inset LatexCommand \index{iCode}
36874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36877 \begin_layout Standard
36885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36888 \begin_layout Standard
36896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36899 \begin_layout Standard
36908 <row topline="true">
36909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36912 \begin_layout Standard
36920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36923 \begin_layout Standard
36926 IC_LEFT() IC_RESULT()
36931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36934 \begin_layout Standard
36942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36945 \begin_layout Standard
36948 IC_RESULT = ! IC_LEFT;
36954 <row topline="true">
36955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36958 \begin_layout Standard
36966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36969 \begin_layout Standard
36972 IC_LEFT() IC_RESULT()
36977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36980 \begin_layout Standard
36983 Bitwise complement of
36988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36991 \begin_layout Standard
36994 IC_RESULT = ~IC_LEFT;
37000 <row topline="true">
37001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37004 \begin_layout Standard
37012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37015 \begin_layout Standard
37018 IC_LEFT() IC_RESULT()
37023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37026 \begin_layout Standard
37029 Rotate right with carry
37034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37037 \begin_layout Standard
37040 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37046 <row topline="true">
37047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37050 \begin_layout Standard
37058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37061 \begin_layout Standard
37064 IC_LEFT() IC_RESULT()
37069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37072 \begin_layout Standard
37075 Rotate left with carry
37080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37083 \begin_layout Standard
37086 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37092 <row topline="true">
37093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37096 \begin_layout Standard
37104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37107 \begin_layout Standard
37110 IC_LEFT() IC_RESULT()
37115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37118 \begin_layout Standard
37121 Get the highest order bit of IC_LEFT
37126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37129 \begin_layout Standard
37132 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37138 <row topline="true">
37139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37142 \begin_layout Standard
37150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37153 \begin_layout Standard
37156 IC_LEFT() IC_RESULT()
37161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37164 \begin_layout Standard
37172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37175 \begin_layout Standard
37178 IC_RESULT = - IC_LEFT;
37184 <row topline="true">
37185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37188 \begin_layout Standard
37196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37199 \begin_layout Standard
37207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37210 \begin_layout Standard
37213 Push the operand into stack
37218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37221 \begin_layout Standard
37230 <row topline="true">
37231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37234 \begin_layout Standard
37242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37245 \begin_layout Standard
37253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37256 \begin_layout Standard
37259 Pop the operand from the stack
37264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37267 \begin_layout Standard
37276 <row topline="true">
37277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37280 \begin_layout Standard
37288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37291 \begin_layout Standard
37294 IC_LEFT() IC_RESULT()
37299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37302 \begin_layout Standard
37305 Call the function represented by IC_LEFT
37310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37313 \begin_layout Standard
37316 IC_RESULT = IC_LEFT();
37322 <row topline="true">
37323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37326 \begin_layout Standard
37334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37337 \begin_layout Standard
37340 IC_LEFT() IC_RESULT()
37345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37348 \begin_layout Standard
37351 Call via function pointer
37356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37359 \begin_layout Standard
37362 IC_RESULT = (*IC_LEFT)();
37368 <row topline="true">
37369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37372 \begin_layout Standard
37380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37383 \begin_layout Standard
37391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37394 \begin_layout Standard
37397 Return the value in operand IC_LEFT
37402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37405 \begin_layout Standard
37414 <row topline="true">
37415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37418 \begin_layout Standard
37426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37429 \begin_layout Standard
37437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37440 \begin_layout Standard
37448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37451 \begin_layout Standard
37460 <row topline="true">
37461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37464 \begin_layout Standard
37472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37475 \begin_layout Standard
37483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37486 \begin_layout Standard
37494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37497 \begin_layout Standard
37506 <row topline="true">
37507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37510 \begin_layout Standard
37518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37521 \begin_layout Standard
37524 IC_LEFT() IC_RIGHT() IC_RESULT()
37529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37532 \begin_layout Standard
37540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37543 \begin_layout Standard
37546 IC_RESULT = IC_LEFT + IC_RIGHT
37552 <row topline="true">
37553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37556 \begin_layout Standard
37564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37567 \begin_layout Standard
37570 IC_LEFT() IC_RIGHT() IC_RESULT()
37575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37578 \begin_layout Standard
37586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37589 \begin_layout Standard
37592 IC_RESULT = IC_LEFT - IC_RIGHT
37598 <row topline="true">
37599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37602 \begin_layout Standard
37610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37613 \begin_layout Standard
37616 IC_LEFT() IC_RIGHT() IC_RESULT()
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37624 \begin_layout Standard
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37635 \begin_layout Standard
37638 IC_RESULT = IC_LEFT * IC_RIGHT;
37644 <row topline="true">
37645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37648 \begin_layout Standard
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37659 \begin_layout Standard
37662 IC_LEFT() IC_RIGHT() IC_RESULT()
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37670 \begin_layout Standard
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37681 \begin_layout Standard
37684 IC_RESULT = IC_LEFT / IC_RIGHT;
37690 <row topline="true">
37691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37694 \begin_layout Standard
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37705 \begin_layout Standard
37708 IC_LEFT() IC_RIGHT() IC_RESULT()
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37716 \begin_layout Standard
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37727 \begin_layout Standard
37730 IC_RESULT = IC_LEFT % IC_RIGHT;
37736 <row topline="true">
37737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37740 \begin_layout Standard
37748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37751 \begin_layout Standard
37754 IC_LEFT() IC_RIGHT() IC_RESULT()
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_layout Standard
37770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37773 \begin_layout Standard
37776 IC_RESULT = IC_LEFT < IC_RIGHT;
37782 <row topline="true">
37783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37786 \begin_layout Standard
37794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37797 \begin_layout Standard
37800 IC_LEFT() IC_RIGHT() IC_RESULT()
37805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37808 \begin_layout Standard
37816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37819 \begin_layout Standard
37822 IC_RESULT = IC_LEFT > IC_RIGHT;
37828 <row topline="true">
37829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37832 \begin_layout Standard
37840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37843 \begin_layout Standard
37846 IC_LEFT() IC_RIGHT() IC_RESULT()
37851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37854 \begin_layout Standard
37862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37865 \begin_layout Standard
37868 IC_RESULT = IC_LEFT == IC_RIGHT;
37874 <row topline="true">
37875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37878 \begin_layout Standard
37886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37889 \begin_layout Standard
37892 IC_LEFT() IC_RIGHT() IC_RESULT()
37897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37900 \begin_layout Standard
37903 Logical and operation
37908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37911 \begin_layout Standard
37914 IC_RESULT = IC_LEFT && IC_RIGHT;
37920 <row topline="true">
37921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37924 \begin_layout Standard
37932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37935 \begin_layout Standard
37938 IC_LEFT() IC_RIGHT() IC_RESULT()
37943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37946 \begin_layout Standard
37949 Logical or operation
37954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37957 \begin_layout Standard
37960 IC_RESULT = IC_LEFT || IC_RIGHT;
37966 <row topline="true">
37967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37970 \begin_layout Standard
37978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37981 \begin_layout Standard
37984 IC_LEFT() IC_RIGHT() IC_RESULT()
37989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37992 \begin_layout Standard
38000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38003 \begin_layout Standard
38006 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38012 <row topline="true">
38013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38016 \begin_layout Standard
38024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38027 \begin_layout Standard
38030 IC_LEFT() IC_RIGHT() IC_RESULT()
38035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38038 \begin_layout Standard
38046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38049 \begin_layout Standard
38052 IC_RESULT = IC_LEFT | IC_RIGHT;
38058 <row topline="true">
38059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38062 \begin_layout Standard
38070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38073 \begin_layout Standard
38076 IC_LEFT() IC_RIGHT() IC_RESULT()
38081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38084 \begin_layout Standard
38092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38095 \begin_layout Standard
38098 IC_RESULT = IC_LEFT & IC_RIGHT;
38104 <row topline="true">
38105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38108 \begin_layout Standard
38116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38119 \begin_layout Standard
38122 IC_LEFT() IC_RIGHT() IC_RESULT()
38127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38130 \begin_layout Standard
38138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38141 \begin_layout Standard
38144 IC_RESULT = IC_LEFT << IC_RIGHT
38150 <row topline="true">
38151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38154 \begin_layout Standard
38162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38165 \begin_layout Standard
38168 IC_LEFT() IC_RIGHT() IC_RESULT()
38173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38176 \begin_layout Standard
38184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38187 \begin_layout Standard
38190 IC_RESULT = IC_LEFT >> IC_RIGHT
38196 <row topline="true">
38197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38200 \begin_layout Standard
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38213 \begin_layout Standard
38216 IC_LEFT() IC_RESULT()
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38224 \begin_layout Standard
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38235 \begin_layout Standard
38238 IC_RESULT = (*IC_LEFT);
38244 <row topline="true">
38245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38248 \begin_layout Standard
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38259 \begin_layout Standard
38262 IC_RIGHT() IC_RESULT()
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38270 \begin_layout Standard
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38281 \begin_layout Standard
38284 (*IC_RESULT) = IC_RIGHT;
38290 <row topline="true">
38291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38294 \begin_layout Standard
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38305 \begin_layout Standard
38308 IC_RIGHT() IC_RESULT()
38313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38316 \begin_layout Standard
38324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38327 \begin_layout Standard
38330 IC_RESULT = IC_RIGHT;
38336 <row topline="true">
38337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38340 \begin_layout Standard
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38351 \begin_layout Standard
38354 IC_COND IC_TRUE IC_LABEL
38359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38362 \begin_layout Standard
38366 If true label is present then jump to true label if condition is true else
38367 jump to false label if condition is false
38372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38375 \begin_layout Standard
38378 if (IC_COND) goto IC_TRUE;
38384 If (!IC_COND) goto IC_FALSE;
38390 <row topline="true">
38391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38394 \begin_layout Standard
38402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38405 \begin_layout Standard
38408 IC_LEFT() IC_RESULT()
38413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38416 \begin_layout Standard
38424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38427 \begin_layout Standard
38430 IC_RESULT = &IC_LEFT();
38436 <row topline="true">
38437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38440 \begin_layout Standard
38448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38451 \begin_layout Standard
38454 IC_JTCOND IC_JTLABELS
38459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38462 \begin_layout Standard
38465 Jump to list of labels depending on the value of JTCOND
38470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38473 \begin_layout Standard
38482 <row topline="true">
38483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38486 \begin_layout Standard
38494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38497 \begin_layout Standard
38500 IC_RIGHT() IC_LEFT() IC_RESULT()
38505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38508 \begin_layout Standard
38516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38519 \begin_layout Standard
38522 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38528 <row topline="true">
38529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38532 \begin_layout Standard
38540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38543 \begin_layout Standard
38551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38554 \begin_layout Standard
38557 This is used for passing parameters in registers;
38559 move IC_LEFT to the next
38560 available parameter register.
38565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38568 \begin_layout Standard
38577 <row topline="true">
38578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38581 \begin_layout Standard
38589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38592 \begin_layout Standard
38600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38603 \begin_layout Standard
38606 This is used for receiving parameters passed in registers;
38609 in the next parameter register to IC_RESULT
38614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38617 \begin_layout Standard
38626 <row topline="true" bottomline="true">
38627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38630 \begin_layout Standard
38634 (some more have been added)
38639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38642 \begin_layout Standard
38648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38651 \begin_layout Standard
38657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38660 \begin_layout Standard
38683 \begin_layout Standard
38684 \begin_inset Note Note
38687 \begin_layout Standard
38688 In the original article Figure II was announced to be downloadable on
38693 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38701 \begin_layout Paragraph*
38703 \begin_inset LatexCommand \index{iCode}
38710 \begin_layout Standard
38711 This section shows some details of iCode.
38712 The example C code does not do anything useful; it is used as an example
38713 to illustrate the intermediate code generated by the compiler.
38716 \begin_layout Verse
38726 /* This function does nothing useful.
38733 for the purpose of explaining iCode */
38736 short function (data
38745 short i=10; \InsetSpace ~
38747 /* dead initialization eliminated */
38753 /* dead initialization eliminated */
38781 /* compiler detects i,j to be induction variables
38786 for (i = 0, j = 10 ; i < 10 ; i++, j
38792 \begin_layout Standard
38815 mul += i * 3; \InsetSpace ~
38817 /* this multiplication remains */
38824 j * 3;\InsetSpace ~
38826 /* this multiplication changed to addition */
38840 \begin_layout Standard
38841 In addition to the operands each iCode contains information about the filename
38842 and line it corresponds to in the source file.
38843 The first field in the listing should be interpreted as follows:
38848 Filename(linenumber: iCode Execution sequence number : ICode hash table
38849 key : loop depth of the iCode).
38854 Then follows the human readable form of the ICode operation.
38855 Each operand of this triplet form can be of three basic types a) compiler
38856 generated temporary b) user defined variable c) a constant value.
38857 Note that local variables and parameters are replaced by compiler generated
38860 \begin_inset LatexCommand \index{Live range analysis}
38864 are computed only for temporaries (i.e.
38865 live ranges are not computed for global variables).
38867 \begin_inset LatexCommand \index{Register allocation}
38871 are allocated for temporaries only.
38872 Operands are formatted in the following manner:
38877 Operand Name [lr live-from : live-to ] { type information } [ registers
38883 As mentioned earlier the live ranges are computed in terms of the execution
38884 sequence number of the iCodes, for example
38886 the iTemp0 is live from (i.e.
38887 first defined in iCode with execution sequence number 3, and is last used
38888 in the iCode with sequence number 5).
38889 For induction variables such as iTemp21 the live range computation extends
38890 the lifetime from the start to the end of the loop.
38892 The register allocator
38893 used the live range information to allocate registers, the same registers
38894 may be used for different temporaries if their live ranges do not overlap,
38895 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38896 ranges do not overlap.
38897 In addition the allocator also takes into consideration the type and usage
38898 of a temporary, for example itemp6 is a pointer to near space and is used
38899 as to fetch data from (i.e.
38900 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38901 Some short lived temporaries are allocated to special registers which have
38902 meaning to the code generator e.g.
38903 iTemp13 is allocated to a pseudo register CC which tells the back end that
38904 the temporary is used only for a conditional jump the code generation makes
38905 use of this information to optimize a compare and jump ICode.
38909 \begin_inset LatexCommand \index{Loop optimization}
38913 performed by the compiler.
38914 It can detect induction variables iTemp21(i) and iTemp23(j).
38915 Also note the compiler does selective strength reduction
38916 \begin_inset LatexCommand \index{Strength reduction}
38921 the multiplication of an induction variable in line 18 (gint = j * 3) is
38922 changed to addition, a new temporary iTemp17 is allocated and assigned
38923 a initial value, a constant 3 is then added for each iteration of the loop.
38924 The compiler does not change the multiplication
38925 \begin_inset LatexCommand \index{Multiplication}
38929 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38932 Note the dead code elimination
38933 \begin_inset LatexCommand \index{Dead-code elimination}
38937 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38943 \begin_layout Standard
38946 Sample.c (5:1:0:0) _entry($9) :
38949 \begin_layout Standard
38952 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38955 \begin_layout Standard
38958 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38961 \begin_layout Standard
38964 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38967 \begin_layout Standard
38970 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38974 \begin_layout Standard
38977 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38980 \begin_layout Standard
38983 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38987 \begin_layout Standard
38990 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38993 \begin_layout Standard
38996 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39000 \begin_layout Standard
39003 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39007 \begin_layout Standard
39010 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39014 \begin_layout Standard
39017 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39021 \begin_layout Standard
39024 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39025 * int}[r0] + 0x2 {short}
39028 \begin_layout Standard
39031 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39034 \begin_layout Standard
39037 Sample.c(11:17:21:0)_whilebreak_0($3) :
39040 \begin_layout Standard
39043 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39046 \begin_layout Standard
39049 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39052 \begin_layout Standard
39055 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39058 \begin_layout Standard
39061 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39064 \begin_layout Standard
39067 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39070 \begin_layout Standard
39073 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39076 \begin_layout Standard
39079 Sample.c(15:24:26:1)_forcond_0($4) :
39082 \begin_layout Standard
39085 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39089 \begin_layout Standard
39092 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39095 \begin_layout Standard
39098 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39099 + ITemp21 [lr21:38]{short}[r4]
39102 \begin_layout Standard
39105 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39109 \begin_layout Standard
39112 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39113 + iTemp15 [lr29:30]{short}[r1]
39116 \begin_layout Standard
39119 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39123 \begin_layout Standard
39126 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39130 \begin_layout Standard
39133 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39137 \begin_layout Standard
39140 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39144 \begin_layout Standard
39147 Sample.c(19:38:47:1) goto _forcond_0($4)
39150 \begin_layout Standard
39153 Sample.c(19:39:48:0)_forbreak_0($7) :
39156 \begin_layout Standard
39159 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39160 + ITemp11 [lr19:40]{short}[r3]
39163 \begin_layout Standard
39166 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39169 \begin_layout Standard
39172 Sample.c(20:42:51:0)_return($8) :
39175 \begin_layout Standard
39178 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39184 Finally the code generated for this function:
39189 \begin_layout Standard
39195 \begin_layout Standard
39201 \begin_layout Standard
39209 \begin_layout Standard
39215 \begin_layout Standard
39223 \begin_layout Standard
39229 \begin_layout Standard
39232 ; ----------------------------------------------
39235 \begin_layout Standard
39238 ; function function
39241 \begin_layout Standard
39244 ; ----------------------------------------------
39247 \begin_layout Standard
39253 \begin_layout Standard
39256 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39259 \begin_layout Standard
39267 \begin_layout Standard
39270 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39273 \begin_layout Standard
39281 \begin_layout Standard
39284 ;_whilecontinue_0($1) :
39287 \begin_layout Standard
39293 \begin_layout Standard
39296 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39299 \begin_layout Standard
39302 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39305 \begin_layout Standard
39313 \begin_layout Standard
39321 \begin_layout Standard
39329 \begin_layout Standard
39337 \begin_layout Standard
39345 \begin_layout Standard
39353 \begin_layout Standard
39361 \begin_layout Standard
39367 \begin_layout Standard
39370 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39373 \begin_layout Standard
39381 \begin_layout Standard
39389 \begin_layout Standard
39392 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39395 \begin_layout Standard
39403 \begin_layout Standard
39411 \begin_layout Standard
39419 \begin_layout Standard
39427 \begin_layout Standard
39435 \begin_layout Standard
39443 \begin_layout Standard
39446 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39449 \begin_layout Standard
39457 \begin_layout Standard
39465 \begin_layout Standard
39473 \begin_layout Standard
39481 \begin_layout Standard
39489 \begin_layout Standard
39492 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39495 \begin_layout Standard
39503 \begin_layout Standard
39511 \begin_layout Standard
39519 \begin_layout Standard
39522 ; iTemp6 [lr5:16]{_near * int}[r0] =
39525 \begin_layout Standard
39528 ; iTemp6 [lr5:16]{_near * int}[r0] +
39531 \begin_layout Standard
39537 \begin_layout Standard
39545 \begin_layout Standard
39548 ; goto _whilecontinue_0($1)
39551 \begin_layout Standard
39559 \begin_layout Standard
39562 ; _whilebreak_0($3) :
39565 \begin_layout Standard
39571 \begin_layout Standard
39574 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39577 \begin_layout Standard
39585 \begin_layout Standard
39588 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39591 \begin_layout Standard
39599 \begin_layout Standard
39602 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39605 \begin_layout Standard
39613 \begin_layout Standard
39616 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39619 \begin_layout Standard
39627 \begin_layout Standard
39635 \begin_layout Standard
39638 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39641 \begin_layout Standard
39649 \begin_layout Standard
39657 \begin_layout Standard
39663 \begin_layout Standard
39669 \begin_layout Standard
39672 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39675 \begin_layout Standard
39678 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39681 \begin_layout Standard
39689 \begin_layout Standard
39697 \begin_layout Standard
39705 \begin_layout Standard
39713 \begin_layout Standard
39721 \begin_layout Standard
39727 \begin_layout Standard
39730 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39733 \begin_layout Standard
39736 ; iTemp21 [lr21:38]{short}[r4]
39739 \begin_layout Standard
39747 \begin_layout Standard
39755 \begin_layout Standard
39763 \begin_layout Standard
39766 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39769 \begin_layout Standard
39777 \begin_layout Standard
39785 \begin_layout Standard
39793 \begin_layout Standard
39801 \begin_layout Standard
39804 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39807 \begin_layout Standard
39810 ; iTemp15 [lr29:30]{short}[r1]
39813 \begin_layout Standard
39821 \begin_layout Standard
39829 \begin_layout Standard
39832 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39835 \begin_layout Standard
39843 \begin_layout Standard
39851 \begin_layout Standard
39859 \begin_layout Standard
39867 \begin_layout Standard
39875 \begin_layout Standard
39883 \begin_layout Standard
39886 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39889 \begin_layout Standard
39897 \begin_layout Standard
39905 \begin_layout Standard
39913 \begin_layout Standard
39921 \begin_layout Standard
39929 \begin_layout Standard
39937 \begin_layout Standard
39940 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39943 \begin_layout Standard
39951 \begin_layout Standard
39954 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39957 \begin_layout Standard
39965 \begin_layout Standard
39970 cjne r5,#0xff,00104$
39973 \begin_layout Standard
39981 \begin_layout Standard
39984 ; goto _forcond_0($4)
39987 \begin_layout Standard
39995 \begin_layout Standard
39998 ; _forbreak_0($7) :
40001 \begin_layout Standard
40007 \begin_layout Standard
40010 ; ret iTemp24 [lr40:41]{short}
40013 \begin_layout Standard
40021 \begin_layout Standard
40029 \begin_layout Standard
40037 \begin_layout Standard
40043 \begin_layout Standard
40049 \begin_layout Standard
40059 \begin_layout Section
40060 A few words about basic block successors, predecessors and dominators
40063 \begin_layout Standard
40064 Successors are basic blocks
40065 \begin_inset LatexCommand \index{Basic blocks}
40069 that might execute after this basic block.
40071 Predecessors are basic blocks
40072 that might execute before reaching this basic block.
40074 Dominators are basic
40075 blocks that WILL execute before reaching this basic block.
40080 \begin_layout Standard
40084 \begin_layout Standard
40088 \begin_layout Standard
40096 \begin_layout Standard
40100 \begin_layout Standard
40108 \begin_layout Standard
40114 \begin_layout Standard
40115 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40118 \begin_layout Standard
40119 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40122 \begin_layout Standard
40123 c) domVect of [BB4] = BB1 ...
40124 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40128 \begin_layout Chapter
40132 \begin_layout Standard
40133 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40143 Thanks to all the other volunteer developers who have helped with coding,
40144 testing, web-page creation, distribution sets, etc.
40145 You know who you are :-)
40153 Thanks to Sourceforge
40154 \begin_inset LatexCommand \url{http://www.sf.net}
40158 which has hosted the project since 1999 and donates significant download
40167 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40168 cycles and bandwidth for snapshot builds.
40173 \begin_layout Standard
40174 This document was initially written by Sandeep Dutta
40177 \begin_layout Standard
40178 All product names mentioned herein may be trademarks
40179 \begin_inset LatexCommand \index{Trademarks}
40183 of their respective companies.
40186 \begin_layout Section*
40190 \begin_layout Standard
40191 To avoid confusion, the installation and building options for SDCC itself
40192 (chapter 2) are not part of the index.
40195 \begin_layout Standard
40196 \begin_inset LatexCommand \printindex{}