1 #LyX 1.4.5 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc.) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the -
843 \begin_layout Standard
852 -short-is-8bits commandline option (see
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862 files are stored is now in /usr/local/share.
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
871 functions are casted to int unless explicitly casted
872 \begin_inset Marginal
875 \begin_layout Standard
900 will push a as an int and as a char resp.
903 \begin_layout Itemize
908 \begin_layout Standard
917 -regextend has been removed.
920 \begin_layout Itemize
925 \begin_layout Standard
934 -noregparms has been removed.
937 \begin_layout Itemize
942 \begin_layout Standard
951 -stack-after-data has been removed.
954 \begin_layout Itemize
956 \begin_inset LatexCommand \index{bit}
961 \begin_inset LatexCommand \index{sbit}
966 \begin_inset LatexCommand \index{\_\_sbit}
970 types now consistently behave like the C99 _Bool type with respect to type
972 \begin_inset LatexCommand \index{type conversion}
977 \begin_inset LatexCommand \index{type promotion}
982 The most common incompatibility resulting from this change is related to
984 \begin_inset LatexCommand \index{Bit toggling}
999 \begin_inset LatexCommand \index{\~\/ Operator}
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1007 \begin_layout Standard
1020 b = !b; /* toggles b */
1024 In previous versions, both forms would have toggled the bit.
1027 \begin_layout Standard
1030 <pending: more incompatibilities?>
1033 \begin_layout Section
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039 a desire to compute.
1040 The preferred method of installation is to compile SDCC from source using
1042 For Windows some pre-compiled binary distributions are available for your
1044 You should have some experience with command line tools and compiler use.
1047 \begin_layout Section
1051 \begin_layout Standard
1052 The SDCC home page at
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1057 is a great place to find distribution sets.
1058 You can also find links to the user mailing lists that offer help or discuss
1059 SDCC with other SDCC users.
1060 Web links to other SDCC related sites can also be found here.
1061 This document can be found in the DOC directory of the source package as
1062 a text or HTML file.
1063 A pdf version of this document is available at
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1069 Some of the other tools (simulator and assembler) included with SDCC contain
1070 their own documentation and can be found in the source distribution.
1071 If you want the latest unreleased software, the complete source package
1072 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1076 \begin_layout Section
1077 Wishes for the future
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082 Here are some I can think of:
1087 \begin_layout Standard
1090 char KernelFunction3(char p) at 0x340;
1095 \begin_layout Standard
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1109 If you can think of some more, please see the section
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1114 about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1120 \begin_inset LatexCommand \index{Feature request}
1129 \begin_layout Chapter
1131 \begin_inset LatexCommand \index{Installation}
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1150 More detailed instructions follow below.
1153 \begin_layout Section
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1165 The defaults can be overridden by:
1169 \labelwidthstring 00.00.0000
1174 \begin_layout Standard
1183 -prefix see table below
1187 \labelwidthstring 00.00.0000
1192 \begin_layout Standard
1201 -exec_prefix see table below
1205 \labelwidthstring 00.00.0000
1210 \begin_layout Standard
1219 -bindir see table below
1223 \labelwidthstring 00.00.0000
1228 \begin_layout Standard
1237 -datadir see table below
1241 \labelwidthstring 00.00.0000
1246 \begin_layout Standard
1255 -datarootdir see table below
1261 \labelwidthstring 00.00.0000
1264 docdir environment variable, see table below
1268 \labelwidthstring 00.00.0000
1271 include_dir_suffix environment variable, see table below
1275 \labelwidthstring 00.00.0000
1278 lib_dir_suffix environment variable, see table below
1282 \labelwidthstring 00.00.0000
1285 sdccconf_h_dir_separator environment variable, either / or
1290 This character will only be used in sdccconf.h; don't forget it's a C-header,
1291 therefore a double-backslash is needed there.
1297 \labelwidthstring 00.00.0000
1302 \begin_layout Standard
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1315 \labelwidthstring 00.00.0000
1320 \begin_layout Standard
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1333 \labelwidthstring 00.00.0000
1338 \begin_layout Standard
1347 -disable-z80-port Excludes the z80 port
1351 \labelwidthstring 00.00.0000
1356 \begin_layout Standard
1365 -disable-avr-port Excludes the AVR port
1369 \labelwidthstring 00.00.0000
1374 \begin_layout Standard
1383 -disable-ds390-port Excludes the DS390 port
1387 \labelwidthstring 00.00.0000
1392 \begin_layout Standard
1401 -disable-hc08-port Excludes the HC08 port
1405 \labelwidthstring 00.00.0000
1410 \begin_layout Standard
1419 -disable-pic-port Excludes the PIC14 port
1423 \labelwidthstring 00.00.0000
1428 \begin_layout Standard
1437 -disable-pic16-port Excludes the PIC16 port
1441 \labelwidthstring 00.00.0000
1446 \begin_layout Standard
1455 -disable-xa51-port Excludes the XA51 port
1459 \labelwidthstring 00.00.0000
1464 \begin_layout Standard
1473 -disable-ucsim Disables configuring and building of ucsim
1477 \labelwidthstring 00.00.0000
1482 \begin_layout Standard
1491 -disable-device-lib Disables automatically building device libraries
1495 \labelwidthstring 00.00.0000
1500 \begin_layout Standard
1509 -disable-packihx Disables building packihx
1515 \labelwidthstring 00.00.0000
1520 \begin_layout Standard
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1533 \labelwidthstring 00.00.0000
1538 \begin_layout Standard
1547 -enable-libgc Use the Bohem memory allocator.
1548 Lower runtime footprint.
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553 the tools and their arguments can be influenced.
1554 Please see `configure -
1558 \begin_layout Standard
1567 -help' and the man/info pages of `configure' for details.
1572 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574 SDCC_LIB_NAME are defined by `configure' too.
1575 At the moment it's not possible to change the default settings (it was
1576 simply never required).
1580 These configure options are compiled into the binaries,
1581 and can only be changed by rerunning 'configure' and recompiling SDCC.
1582 The configure options are written in
1586 to distinguish them from run time environment variables (see section search
1592 \begin_inset Quotes sld
1596 \begin_inset Quotes srd
1599 are used by the SDCC team to build the official Win32 binaries.
1600 The SDCC team uses Mingw32 to build the official Windows binaries, because
1604 \begin_layout Enumerate
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1630 \begin_layout Standard
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 \begin_layout Standard
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_layout Standard
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1660 \begin_layout Standard
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_layout Standard
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_layout Standard
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1691 \begin_layout Standard
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1704 \begin_layout Standard
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1715 \begin_layout Standard
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 \begin_layout Standard
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_layout Standard
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 \begin_layout Standard
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1780 \begin_layout Standard
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 \begin_layout Standard
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_layout Standard
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 \begin_layout Standard
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1839 \begin_layout Standard
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1876 \begin_layout Standard
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_layout Standard
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_layout Standard
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1924 \begin_layout Standard
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1935 \begin_layout Standard
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1944 \begin_layout Standard
1960 \begin_layout Standard
1962 'configure' also computes relative paths.
1963 This is needed for full relocatability of a binary package and to complete
1964 search paths (see section search paths below):
1969 \begin_layout Standard
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 \begin_layout Standard
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_layout Standard
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 \begin_layout Standard
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2052 \begin_layout Standard
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2061 \begin_layout Standard
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2072 \begin_layout Standard
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 \begin_layout Standard
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2092 \begin_layout Standard
2108 \begin_layout Standard
2113 \begin_layout LyX-Code
2120 \begin_layout Standard
2130 \begin_inset Quotes srd
2134 \begin_inset Quotes srd
2141 \begin_layout Standard
2151 \begin_inset Quotes srd
2155 \begin_inset Quotes srd
2164 \begin_layout Standard
2177 \begin_layout Standard
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2194 \begin_layout LyX-Code
2200 \begin_inset Quotes srd
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2208 \begin_inset Quotes srd
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2220 \begin_inset Quotes srd
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2232 \begin_inset Quotes srd
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2247 \begin_layout Standard
2257 \begin_inset Quotes srd
2261 \begin_inset Quotes srd
2272 \begin_layout Standard
2282 \begin_inset Quotes srd
2286 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2300 \begin_inset Quotes srd
2308 \begin_inset Quotes srd
2312 \begin_inset Quotes srd
2320 \begin_inset Quotes srd
2324 \begin_inset Quotes srd
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2344 \begin_inset Quotes srd
2355 \begin_layout Standard
2372 \begin_layout Standard
2381 -host=i586-mingw32msvc
2389 \begin_layout Standard
2398 -build=unknown-unknown-linux-gnu
2401 \begin_layout Standard
2403 \begin_inset Quotes sld
2407 \begin_inset Quotes srd
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2414 \begin_layout LyX-Code
2423 \begin_layout Standard
2433 \begin_inset Quotes srd
2437 \begin_inset Quotes srd
2448 \begin_layout Standard
2458 \begin_inset Quotes srd
2462 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2476 \begin_inset Quotes srd
2484 \begin_inset Quotes srd
2488 \begin_inset Quotes srd
2496 \begin_inset Quotes srd
2500 \begin_inset Quotes srd
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2520 \begin_inset Quotes srd
2528 \begin_inset Quotes srd
2532 \begin_inset Quotes srd
2540 \begin_inset Quotes srd
2544 \begin_inset Quotes srd
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2556 \begin_layout Standard
2565 -C' turns on caching, which gives a little bit extra speed.
2566 However if options are changed, it can be necessary to delete the config.cache
2570 \begin_layout Section
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2577 \begin_inset LatexCommand \index{Install paths}
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2591 \begin_layout Standard
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2604 \begin_layout Standard
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 \begin_layout Standard
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_layout Standard
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2637 \begin_layout Standard
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_layout Standard
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_layout Standard
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_layout Standard
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2679 \begin_layout Standard
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 \begin_layout Standard
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2703 \begin_layout Standard
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2723 \begin_layout Standard
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_layout Standard
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_layout Standard
2750 $DATADIR/$LIB_DIR_SUFFIX
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2767 \begin_layout Standard
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_layout Standard
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_layout Standard
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_layout Standard
2832 *compiler, preprocessor, assembler, and linker
2838 is auto-appended by the compiler, e.g.
2839 small, large, z80, ds390 etc
2842 \begin_layout Standard
2844 The install paths can still be changed during `make install' with e.g.:
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2873 \begin_layout Section
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2880 \begin_inset LatexCommand \index{Search path}
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2893 , see section above).
2894 Further search paths are determined by environment variables during runtime.
2897 The paths searched when running the compiler are as follows (the first
2903 Binary files (preprocessor, assembler and linker)
2908 \begin_layout Standard
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2920 \begin_layout Standard
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_layout Standard
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2938 \begin_layout Standard
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2949 \begin_layout Standard
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2969 \begin_layout Standard
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2991 \begin_layout Standard
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3000 \begin_layout Standard
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_layout Standard
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3020 \begin_layout Standard
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3029 \begin_layout Standard
3045 \begin_layout Standard
3053 \begin_layout Standard
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_layout Standard
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3074 \begin_layout Standard
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3083 \begin_layout Standard
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_layout Standard
3099 \begin_layout Standard
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3121 \begin_layout Standard
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3138 \begin_layout Standard
3143 \begin_layout Standard
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3162 \begin_layout Standard
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_layout Standard
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 \begin_layout Standard
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3191 \begin_layout Standard
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_layout Standard
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3219 \begin_layout Standard
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3232 \begin_layout Standard
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3251 \begin_layout Standard
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3302 \begin_layout Standard
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3317 \begin_layout Standard
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3345 \begin_layout Standard
3361 \begin_layout Standard
3367 \begin_layout Standard
3376 -nostdinc disables the last two search paths.
3386 \begin_layout Standard
3387 With the exception of
3388 \begin_inset Quotes sld
3395 \begin_layout Standard
3405 \begin_inset Quotes srd
3412 is auto-appended by the compiler (e.g.
3413 small, large, z80, ds390 etc.).
3419 \begin_layout Standard
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_layout Standard
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3440 \begin_layout Standard
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3449 \begin_layout Standard
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3460 \begin_layout Standard
3465 \begin_layout Standard
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3482 \begin_layout Standard
3487 \begin_layout Standard
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3504 \begin_layout Standard
3509 \begin_layout Standard
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3528 \begin_layout Standard
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3554 \begin_layout Standard
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_layout Standard
3578 $LIB_DIR_SUFFIX/<model>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3586 \begin_layout Standard
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3601 \begin_layout Standard
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3620 \begin_layout Standard
3631 $LIB_DIR_SUFFIX/<model>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3639 \begin_layout Standard
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3693 \begin_layout Standard
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3751 \begin_layout Standard
3756 $LIB_DIR_SUFFIX/<model>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3777 \begin_layout Standard
3793 \begin_layout Standard
3794 \begin_inset Note Note
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799 the HTML output (last line)!
3807 \begin_layout Standard
3815 \begin_layout Standard
3824 -nostdlib disables the last two search paths.
3827 \begin_layout Section
3829 \begin_inset LatexCommand \index{Building SDCC}
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3845 \begin_layout Enumerate
3848 Download the source package
3850 either from the SDCC Subversion repository or from snapshot builds
3852 , it will be named something like sdcc
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3870 \begin_layout Enumerate
3873 Bring up a command line terminal, such as xterm.
3876 \begin_layout Enumerate
3879 Unpack the file using a command like:
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3889 , this will create a sub-directory called sdcc with all of the sources.
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type:
3901 \begin_layout Enumerate
3911 This configures the package for compilation on your system.
3914 \begin_layout Enumerate
3928 All of the source packages will compile, this can take a while.
3931 \begin_layout Enumerate
3945 This copies the binary executables, the include files, the libraries and
3946 the documentation to the install directories.
3947 Proceed with section
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3964 On Mac OS X 10.2.x it was reported, that the
3965 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966 Fortunately there's also gcc 2.9.x installed, which works fine.
3967 This compiler can be selected by running 'configure' with:
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3974 \begin_layout Standard
3975 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
3977 Run 'configure' with:
3980 \begin_layout LyX-Code
3986 \begin_layout LyX-Code
3987 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
3993 \begin_layout LyX-Code
3994 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4000 \begin_layout LyX-Code
4001 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4004 \begin_layout Subsection
4005 Cross compiling SDCC on Linux for Windows
4008 \begin_layout Standard
4009 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4010 See section 'Configure Options'.
4013 \begin_layout Subsection
4014 Building SDCC using Cygwin and Mingw32
4017 \begin_layout Standard
4018 For building and installing a Cygwin executable follow the instructions
4024 \begin_inset Quotes sld
4028 \begin_inset Quotes srd
4031 Win32-binary can be built, which will not need the Cygwin-DLL.
4032 For the necessary 'configure' options see section 'configure options' or
4033 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4038 Cygwin on Windows download setup.exe from
4039 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4045 \begin_inset Quotes sld
4048 default text file type
4049 \begin_inset Quotes srd
4053 \begin_inset Quotes sld
4057 \begin_inset Quotes srd
4060 and download/install at least the following packages.
4061 Some packages are selected by default, others will be automatically selected
4062 because of dependencies with the manually selected packages.
4063 Never deselect these packages!
4066 \begin_layout Itemize
4070 \begin_layout Itemize
4074 \begin_layout Itemize
4075 gcc ; version 3.x is fine, no need to use the old 2.9x
4078 \begin_layout Itemize
4079 binutils ; selected with gcc
4082 \begin_layout Itemize
4086 \begin_layout Itemize
4087 rxvt ; a nice console, which makes life much easier under windoze (see below)
4090 \begin_layout Itemize
4091 man ; not really needed for building SDCC, but you'll miss it sooner or
4095 \begin_layout Itemize
4096 less ; not really needed for building SDCC, but you'll miss it sooner or
4100 \begin_layout Itemize
4101 svn ; only if you use Subversion access
4104 \begin_layout Standard
4105 If you want to develop something you'll need:
4108 \begin_layout Itemize
4109 python ; for the regression tests
4112 \begin_layout Itemize
4113 gdb ; the gnu debugger, together with the nice GUI
4114 \begin_inset Quotes sld
4118 \begin_inset Quotes srd
4124 \begin_layout Itemize
4125 openssh ; to access the CF or commit changes
4128 \begin_layout Itemize
4129 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4130 use autoconf-stable!
4133 \begin_layout Standard
4134 rxvt is a nice console with history.
4135 Replace in your cygwin.bat the line
4138 \begin_layout LyX-Code
4143 \begin_layout Standard
4155 \begin_layout Standard
4159 \begin_layout LyX-Code
4160 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4163 \begin_layout LyX-Code
4164 -bg black -fg white -geometry 100x65 -e bash -
4168 \begin_layout Standard
4180 \begin_layout Standard
4181 Text selected with the mouse is automatically copied to the clipboard, pasting
4182 works with shift-insert.
4186 The other good tip is to make sure you have no //c/-styl
4187 e paths anywhere, use /cygdrive/c/ instead.
4188 Using // invokes a network lookup which is very slow.
4190 \begin_inset Quotes sld
4194 \begin_inset Quotes srd
4197 is too long, you can change it with e.g.
4200 \begin_layout LyX-Code
4204 \begin_layout Standard
4205 SDCC sources use the unix line ending LF.
4206 Life is much easier, if you store the source tree on a drive which is mounted
4208 And use an editor which can handle LF-only line endings.
4209 Make sure not to commit files with windows line endings.
4210 The tabulator spacing
4211 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4215 used in the project is 8.
4216 Although a tabulator spacing of 8 is a sensible choice for programmers
4217 (it's a power of 2 and allows to display 8/16 bit signed variables without
4218 loosing columns) the plan is to move towards using only spaces in the source.
4221 \begin_layout Subsection
4222 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4225 \begin_layout Standard
4228 Download the source package
4230 either from the SDCC Subversion repository or from the
4231 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4237 , it will be named something like sdcc
4241 -yyyymmdd-rrrr.tar.bz2.
4244 SDCC is distributed with all the projects, workspaces, and files you need
4245 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4246 The workspace name is 'sdcc.dsw'.
4247 Please note that as it is now, all the executables are created in a folder
4251 Once built you need to copy the executables from sdcc
4255 bin before running SDCC.
4260 WARNING: Visual studio is very picky with line terminations; it expects
4261 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4262 When using the Subversion repository it's easiest to configure the svn
4263 client to convert automatically for you.
4264 If however you are getting a message such as "This makefile was not generated
4265 by Developer Studio etc.
4267 \begin_inset Quotes srd
4270 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4271 need to convert the Unix style line endings to DOS style line endings.
4272 To do so you can use the
4273 \begin_inset Quotes sld
4277 \begin_inset Quotes srd
4280 utility freely available on the internet.
4281 Doug Hawkins reported in the sdcc-user list that this works:
4289 SDCC> unix2dos sdcc.dsw
4295 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4299 In order to build SDCC with MSVC
4300 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4301 One good place to get them is
4302 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4310 Download the file UnxUtils
4311 \begin_inset LatexCommand \index{UnxUtils}
4316 Now you have to install the utilities and setup MSVC so it can locate the
4318 Here there are two alternatives (choose one!):
4321 \begin_layout Enumerate
4326 a) Extract UnxUtils.zip to your C:
4328 hard disk PRESERVING the original paths, otherwise bison won't work.
4329 (If you are using WinZip make certain that 'Use folder names' is selected)
4334 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4335 'Show directories for:' select 'Executable files', and in the directories
4336 window add a new path: 'C:
4346 (As a side effect, you get a bunch of Unix utilities that
4347 could be useful, such as diff and patch.)
4350 \begin_layout Enumerate
4355 This one avoids extracting a bunch of files you may not
4356 use, but requires some extra work:
4360 a) Create a directory were to put the
4361 tools needed, or use a directory already present.
4368 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4369 gawk.exe to such directory WITHOUT preserving the original paths.
4370 (If you are using WinZip make certain that 'Use folder names' is not selected)
4375 ) Rename bison.exe to '_bison.exe'.
4379 d) Create a batch file 'bison.bat' in 'C:
4383 ' and add these lines:
4403 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4407 Steps 'c' and 'd' are needed
4408 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4409 reside in some weird Unix directory, '/usr/local/share/' I think.
4410 So it is necessary to tell bison where those files are located if they
4411 are not in such directory.
4412 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4417 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4418 in 'Show directories for:' select 'Executable files', and in the directories
4419 window add a new path: 'c:
4422 Note that you can use any other path instead of 'c:
4424 util', even the path where the Visual C++ tools are, probably: 'C:
4428 Microsoft Visual Studio
4433 So you don't have to execute step 'e' :)
4436 \begin_layout Standard
4438 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4439 the executables from sdcc
4443 bin, and you can compile using SDCC.
4446 \begin_layout Subsection
4447 Building SDCC Using Borland
4450 \begin_layout Enumerate
4451 From the sdcc directory, run the command "make -f Makefile.bcc".
4452 This should regenerate all the .exe files in the bin directory except for
4456 \begin_layout Enumerate
4457 If you modify any source files and need to rebuild, be aware that the dependenci
4458 es may not be correctly calculated.
4459 The safest option is to delete all .obj files and run the build again.
4460 From a Cygwin BASH prompt, this can easily be done with the command (be
4461 sure you are in the sdcc directory):
4471 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4473 ) -print -exec rm {}
4482 or on Windows NT/2000/XP from the command prompt with the command:
4489 del /s *.obj *.lib *.rul
4492 from the sdcc directory.
4495 \begin_layout Subsection
4496 Windows Install Using a ZIP Package
4499 \begin_layout Enumerate
4500 Download the binary zip package from
4501 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4505 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4506 This should unpack to a group of sub-directories.
4507 An example directory structure after unpacking the mingw32 package is:
4512 bin for the executables, c:
4520 lib for the include and libraries.
4523 \begin_layout Enumerate
4524 Adjust your environment variable PATH to include the location of the bin
4525 directory or start sdcc using the full path.
4528 \begin_layout Subsection
4529 Windows Install Using the Setup Program
4530 \begin_inset LatexCommand \label{sub:Windows-Install}
4537 \begin_layout Standard
4538 Download the setup program
4540 sdcc-x.y.z-setup.exe
4542 for an official release from
4545 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4549 or a setup program for one of the snapshots
4551 sdcc-yyyymmdd-xxxx-setup.exe
4554 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4559 A windows typical installer will guide you through the installation process.
4562 \begin_layout Subsection
4564 \begin_inset LatexCommand \index{VPATH}
4571 \begin_layout Standard
4572 SDCC supports the VPATH feature provided by configure and make.
4573 It allows to separate the source and build trees.
4577 \begin_layout Standard
4604 \begin_layout Standard
4607 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4608 # extract source to directory sdcc
4611 \begin_layout Standard
4614 mkdir sdcc.build\InsetSpace ~
4623 # put output in sdcc.build
4626 \begin_layout Standard
4632 \begin_layout Standard
4635 ../sdcc/configure\InsetSpace ~
4643 # configure is doing all the magic!
4646 \begin_layout Standard
4652 \begin_layout Standard
4658 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4659 It automagically computes the variables srcdir, top_srcdir and top_buildir
4665 the generated files will be in ~/sdcc.build, while the source files stay
4668 This is not only usefull for building different binaries, e.g.
4669 when cross compiling.
4670 It also gives you a much better overview in the source tree when all the
4671 generated files are not scattered between the source files.
4672 And the best thing is: if you want to change a file you can leave the original
4673 file untouched in the source directory.
4674 Simply copy it to the build directory, edit it, enter `make clean', `rm
4675 Makefile.dep' and `make'.
4680 will do the rest for you!
4683 \begin_layout Section
4684 Building the Documentation
4687 \begin_layout Standard
4692 \begin_layout Standard
4701 -enable-doc to the configure arguments to build the documentation together
4702 with all the other stuff.
4703 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4704 dvips and makeindex) to get the job done.
4705 Another possibility is to change to the doc directory and to type
4709 \begin_inset Quotes srd
4713 \begin_inset Quotes srd
4720 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4723 \begin_inset LatexCommand \url{http://www.lyx.org}
4727 as editor is straightforward.
4728 Prebuilt documentation in html and pdf format is available from
4729 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4736 \begin_layout Section
4737 Reading the Documentation
4738 \begin_inset LatexCommand \index{Documentation}
4745 \begin_layout Standard
4746 Currently reading the document in pdf format is recommended, as for unknown
4747 reason the hyperlinks are working there whereas in the html version they
4752 \begin_layout Standard
4753 If you should know why please drop us a note
4761 You'll find the pdf version
4762 \begin_inset LatexCommand \index{PDF version of this document}
4767 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4775 \begin_inset LatexCommand \index{HTML version of this document}
4780 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4786 This documentation is in some aspects different from a commercial documentation:
4790 \begin_layout Itemize
4791 It tries to document SDCC for several processor architectures in one document
4792 (commercially these probably would be separate documents/products).
4794 \begin_inset LatexCommand \index{Status of documentation}
4798 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4800 Z80, PIC14, PIC16 and HC08.
4803 \begin_layout Itemize
4804 There are many references pointing away from this documentation.
4805 Don't let this distract you.
4807 was a reference like
4808 \begin_inset LatexCommand \url{http://www.opencores.org}
4812 together with a statement
4813 \begin_inset Quotes sld
4816 some processors which are targetted by SDCC can be implemented in a
4833 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4838 \begin_inset Quotes srd
4842 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4847 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4852 \begin_inset Quotes sld
4855 have you ever heard of an open source compiler that compiles a subset of
4857 \begin_inset Quotes srd
4860 we expect you to have a quick look there and come back.
4861 If you read this you are on the right track.
4864 \begin_layout Itemize
4865 Some sections attribute more space to problems, restrictions and warnings
4866 than to the solution.
4869 \begin_layout Itemize
4870 The installation section and the section about the debugger is intimidating.
4873 \begin_layout Itemize
4874 There are still lots of typos and there are more different writing styles
4878 \begin_layout Section
4879 Testing the SDCC Compiler
4880 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4887 \begin_layout Standard
4888 The first thing you should do after installing your SDCC compiler is to
4897 \begin_layout Standard
4907 \begin_inset LatexCommand \index{version}
4914 at the prompt, and the program should run and output its version like:
4919 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4923 \begin_layout Standard
4924 If it doesn't run, or gives a message about not finding sdcc program, then
4925 you need to check over your installation.
4926 Make sure that the sdcc bin directory is in your executable search path
4927 defined by the PATH environment setting (
4932 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4939 Install trouble-shooting for suggestions
4942 Make sure that the sdcc program is in the bin folder, if not perhaps something
4943 did not install correctly.
4951 is commonly installed as described in section
4952 \begin_inset Quotes sld
4955 Install and search paths
4956 \begin_inset Quotes srd
4965 Make sure the compiler works on a very simple example.
4966 Type in the following test.c program using your favorite
4991 \begin_layout Standard
4994 Compile this using the following command:
5003 If all goes well, the compiler will generate a test.asm and test.rel file.
5004 Congratulations, you've just compiled your first program with SDCC.
5005 We used the -c option to tell SDCC not to link the generated code, just
5006 to keep things simple for this step.
5014 The next step is to try it with the linker.
5024 If all goes well the compiler will link with the libraries and produce
5025 a test.ihx output file.
5030 (no test.ihx, and the linker generates warnings), then the problem is most
5039 usr/local/share/sdcc/lib directory
5046 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5053 Install trouble-shooting for suggestions).
5061 The final test is to ensure
5069 header files and libraries.
5070 Edit test.c and change it to the following:
5088 strcpy(str1, "testing");
5093 \begin_layout Standard
5096 Compile this by typing
5103 This should generate a test.ihx output file, and it should give no warnings
5104 such as not finding the string.h file.
5105 If it cannot find the string.h file, then the problem is that
5109 cannot find the /usr/local/share/sdcc/include directory
5116 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5123 Install trouble-shooting section for suggestions).
5132 \begin_layout Standard
5144 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5148 to find exactly where SDCC is looking for the include and lib files.
5151 \begin_layout Section
5152 Install Trouble-shooting
5153 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5158 \begin_inset LatexCommand \index{Install trouble-shooting}
5165 \begin_layout Subsection
5166 If SDCC does not build correctly
5169 \begin_layout Standard
5170 A thing to try is starting from scratch by unpacking the .tgz source package
5171 again in an empty directory.
5179 ./configure 2>&1 | tee configure.log
5193 make 2>&1 | tee make.log
5200 If anything goes wrong, you can review the log files to locate the problem.
5201 Or a relevant part of this can be attached to an email that could be helpful
5202 when requesting help from the mailing list.
5205 \begin_layout Subsection
5207 \begin_inset Quotes sld
5211 \begin_inset Quotes srd
5217 \begin_layout Standard
5219 \begin_inset Quotes sld
5223 \begin_inset Quotes srd
5226 command is a script that analyzes your system and performs some configuration
5227 to ensure the source package compiles on your system.
5228 It will take a few minutes to run, and will compile a few tests to determine
5229 what compiler features are installed.
5232 \begin_layout Subsection
5234 \begin_inset Quotes sld
5238 \begin_inset Quotes srd
5244 \begin_layout Standard
5245 This runs the GNU make tool, which automatically compiles all the source
5246 packages into the final installed binary executables.
5249 \begin_layout Subsection
5251 \begin_inset Quotes sld
5255 \begin_inset Quotes erd
5261 \begin_layout Standard
5262 This will install the compiler, other executables libraries and include
5263 files into the appropriate directories.
5265 \begin_inset LatexCommand \ref{sub:Install-paths}
5271 \begin_inset LatexCommand \ref{sub:Search-Paths}
5276 about install and search paths.
5278 On most systems you will need super-user privilege
5282 \begin_layout Section
5286 \begin_layout Standard
5287 SDCC is not just a compiler, but a collection of tools by various developers.
5288 These include linkers, assemblers, simulators and other components.
5289 Here is a summary of some of the components.
5290 Note that the included simulator and assembler have separate documentation
5291 which you can find in the source package in their respective directories.
5292 As SDCC grows to include support for other processors, other packages from
5293 various developers are included and may have their own sets of documentation.
5298 might want to look at the files which are installed in <installdir>.
5299 At the time of this writing, we find the following programs for gcc-builds:
5304 In <installdir>/bin:
5307 \begin_layout Itemize
5308 sdcc - The compiler.
5311 \begin_layout Itemize
5312 sdcpp - The C preprocessor.
5315 \begin_layout Itemize
5316 asx8051 - The assembler for 8051 type processors.
5319 \begin_layout Itemize
5324 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5327 \begin_layout Itemize
5328 aslink -The linker for 8051 type processors.
5331 \begin_layout Itemize
5336 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5339 \begin_layout Itemize
5340 s51 - The ucSim 8051 simulator.
5343 \begin_layout Itemize
5344 sdcdb - The source debugger.
5347 \begin_layout Itemize
5348 packihx - A tool to pack (compress) Intel hex files.
5351 \begin_layout Standard
5352 In <installdir>/share/sdcc/include
5355 \begin_layout Itemize
5359 \begin_layout Standard
5360 In <installdir>/share/sdcc/lib
5363 \begin_layout Itemize
5364 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5368 \begin_layout Standard
5369 In <installdir>/share/sdcc/doc
5372 \begin_layout Itemize
5376 \begin_layout Standard
5377 As development for other processors proceeds, this list will expand to include
5378 executables to support processors like AVR, PIC, etc.
5381 \begin_layout Subsection
5385 \begin_layout Standard
5386 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5387 the assembler and linkage editor.
5390 \begin_layout Subsection
5391 sdcpp - The C-Preprocessor
5394 \begin_layout Standard
5396 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5400 is a modified version of the GNU cpp
5401 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5406 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5411 The C preprocessor is used to pull in #include sources, process #ifdef
5412 statements, #defines and so on.
5415 \begin_layout Subsection
5424 - The Assemblers and Linkage Editors
5427 \begin_layout Standard
5428 This is retargettable assembler & linkage editor, it was developed by Alan
5430 John Hartman created the version for 8051, and I (Sandeep) have made some
5431 enhancements and bug fixes for it to work properly with SDCC.
5434 \begin_layout Subsection
5438 \begin_layout Standard
5440 \begin_inset LatexCommand \index{s51}
5444 is a free open source simulator developed by Daniel Drotos.
5445 The simulator is built as part of the build process.
5446 For more information visit Daniel's web site at:
5447 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5452 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5456 \begin_layout Subsection
5457 sdcdb - Source Level Debugger
5460 \begin_layout Standard
5462 \begin_inset LatexCommand \index{SDCDB (debugger)}
5466 is the companion source level debugger.
5467 More about SDCDB in section
5468 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5473 The current version of the debugger uses Daniel's Simulator S51
5474 \begin_inset LatexCommand \index{s51}
5478 , but can be easily changed to use other simulators.
5481 \begin_layout Chapter
5485 \begin_layout Section
5489 \begin_layout Subsection
5490 Single Source File Projects
5493 \begin_layout Standard
5494 For single source file 8051 projects the process is very simple.
5495 Compile your programs with the following command
5498 "sdcc sourcefile.c".
5502 This will compile, assemble and link your source file.
5503 Output files are as follows:
5506 \begin_layout Itemize
5508 \begin_inset LatexCommand \index{<file>.asm}
5513 \begin_inset LatexCommand \index{Assembler source}
5517 file created by the compiler
5520 \begin_layout Itemize
5522 \begin_inset LatexCommand \index{<file>.lst}
5527 \begin_inset LatexCommand \index{Assembler listing}
5531 file created by the Assembler
5534 \begin_layout Itemize
5536 \begin_inset LatexCommand \index{<file>.rst}
5541 \begin_inset LatexCommand \index{Assembler listing}
5545 file updated with linkedit information, created by linkage editor
5548 \begin_layout Itemize
5550 \begin_inset LatexCommand \index{<file>.sym}
5555 \begin_inset LatexCommand \index{Symbol listing}
5559 for the sourcefile, created by the assembler
5562 \begin_layout Itemize
5564 \begin_inset LatexCommand \index{<file>.rel}
5569 \begin_inset LatexCommand \index{<file>.o}
5574 \begin_inset LatexCommand \index{Object file}
5578 created by the assembler, input to Linkage editor
5581 \begin_layout Itemize
5583 \begin_inset LatexCommand \index{<file>.map}
5588 \begin_inset LatexCommand \index{Memory map}
5592 for the load module, created by the Linker
5595 \begin_layout Itemize
5597 \begin_inset LatexCommand \index{<file>.mem}
5601 - A file with a summary of the memory usage
5604 \begin_layout Itemize
5606 \begin_inset LatexCommand \index{<file>.ihx}
5610 - The load module in Intel hex format
5611 \begin_inset LatexCommand \index{Intel hex format}
5615 (you can select the Motorola S19 format
5616 \begin_inset LatexCommand \index{Motorola S19 format}
5624 \begin_layout Standard
5634 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5639 If you need another format you might want to use
5646 \begin_inset LatexCommand \index{objdump (tool)}
5657 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5662 \begin_inset Note Note
5665 \begin_layout Standard
5672 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5677 Both formats are documented in the documentation of srecord
5678 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5685 \begin_layout Itemize
5687 \begin_inset LatexCommand \index{<file>.adb}
5691 - An intermediate file containing debug information needed to create the
5696 \begin_layout Standard
5706 \begin_inset LatexCommand \index{-\/-debug}
5713 \begin_layout Itemize
5715 \begin_inset LatexCommand \index{<file>.cdb}
5719 - An optional file (with -
5723 \begin_layout Standard
5732 -debug) containing debug information.
5733 The format is documented in cdbfileformat.pdf
5736 \begin_layout Itemize
5739 \begin_inset LatexCommand \index{<file> (no extension)}
5743 An optional AOMF or AOMF51
5744 \begin_inset LatexCommand \index{AOMF, AOMF51}
5749 \begin_inset LatexCommand \label{OMF file}
5753 file containing debug information (generated with option -
5757 \begin_layout Standard
5783 ormat is a subformat of the OMF51 format and is commonly used by third party
5785 \begin_inset LatexCommand \index{Debugger}
5789 , simulators, emulators).
5792 \begin_layout Itemize
5794 \begin_inset LatexCommand \index{<file>.dump*}
5798 - Dump file to debug the compiler it self (generated with option -
5802 \begin_layout Standard
5811 -dumpall) (see section
5812 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5818 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5824 \begin_inset Quotes sld
5827 Anatomy of the compiler
5828 \begin_inset Quotes srd
5834 \begin_layout Subsection
5835 Postprocessing the Intel Hex
5836 \begin_inset LatexCommand \index{Intel hex format}
5841 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5848 \begin_layout Standard
5849 In most cases this won't be needed but the Intel Hex file
5850 \begin_inset LatexCommand \index{<file>.ihx}
5854 which is generated by SDCC might include lines of varying length and the
5855 addresses within the file are not guaranteed to be strictly ascending.
5856 If your toolchain or a bootloader does not like this you can use the tool
5862 \begin_inset LatexCommand \index{packihx (tool)}
5866 which is part of the SDCC distribution:
5873 packihx sourcefile.ihx >sourcefile.hex
5880 The separately available
5885 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5889 package additionally allows to set undefined locations to a predefined
5890 value, to insert checksums
5891 \begin_inset LatexCommand \index{checksum}
5895 of various flavours (crc, add, xor) and to perform other manipulations
5896 (convert, split, crop, offset, ...).
5904 srec_cat\InsetSpace ~
5906 sourcefile.ihx -intel\InsetSpace ~
5908 -o sourcefile.hex -intel
5915 An example for a more complex command line
5919 \begin_layout Standard
5920 the command backfills
5921 \begin_inset LatexCommand \index{backfill unused memory}
5925 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5927 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5928 will be interpreted as an
5936 (where an emergency routine could sit).
5949 srec_cat\InsetSpace ~
5950 sourcefile.ihx -intel\InsetSpace ~
5952 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5953 -little-endian-checksum-nega
5954 tive 0xfffe 0x02 0x02\InsetSpace ~
5956 -o sourcefile.hex -intel
5965 The srecord package is available at
5966 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5973 \begin_layout Subsection
5974 Projects with Multiple Source Files
5977 \begin_layout Standard
5978 SDCC can compile only ONE file at a time.
5979 Let us for example assume that you have a project containing the following
5984 foo1.c (contains some functions)
5986 foo2.c (contains some more functions)
5989 n.c (contains more functions and the function main)
5997 The first two files will need to be compiled separately with the commands:
6029 Then compile the source file containing the
6034 \begin_inset LatexCommand \index{Linker}
6038 the files together with the following command:
6046 foomain.c\InsetSpace ~
6047 foo1.rel\InsetSpace ~
6052 \begin_inset LatexCommand \index{<file>.rel}
6064 can be separately compiled as well:
6075 sdcc foomain.rel foo1.rel foo2.rel
6082 The file containing the
6097 file specified in the command line, since the linkage editor processes
6098 file in the order they are presented to it.
6099 The linker is invoked from SDCC using a script file with extension .lnk
6100 \begin_inset LatexCommand \index{<file>.lnk}
6105 You can view this file to troubleshoot linking problems such as those arising
6106 from missing libraries.
6109 \begin_layout Subsection
6110 Projects with Additional Libraries
6111 \begin_inset LatexCommand \index{Libraries}
6118 \begin_layout Standard
6119 Some reusable routines may be compiled into a library, see the documentation
6120 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6124 \begin_inset LatexCommand \index{<file>.lib}
6131 Libraries created in this manner can be included in the command line.
6132 Make sure you include the -L <library-path> option to tell the linker where
6133 to look for these files if they are not in the current directory.
6134 Here is an example, assuming you have the source file
6146 (if that is not the same as your current project):
6153 sdcc foomain.c foolib.lib -L mylib
6164 must be an absolute path name.
6168 The most efficient way to use libraries is
6169 to keep separate modules in separate source files.
6170 The lib file now should name all the modules.rel
6171 \begin_inset LatexCommand \index{<file>.rel}
6176 For an example see the standard library file
6180 in the directory <installdir>/share/lib/small.
6183 \begin_layout Subsection
6184 Using sdcclib to Create and Manage Libraries
6185 \begin_inset LatexCommand \index{sdcclib}
6192 \begin_layout Standard
6193 Alternatively, instead of having a .rel file for each entry on the library
6194 file as described in the preceding section, sdcclib can be used to embed
6195 all the modules belonging to such library in the library file itself.
6196 This results in a larger library file, but it greatly reduces the number
6197 of disk files accessed by the linker.
6198 Additionally, the packed library file contains an index of all include
6199 modules and symbols that significantly speeds up the linking process.
6200 To display a list of options supported by sdcclib type:
6205 \begin_layout Standard
6210 \begin_inset LatexCommand \index{sdcclib}
6221 To create a new library file, start by compiling all the required modules.
6227 \begin_layout Standard
6234 \begin_layout Standard
6241 \begin_layout Standard
6248 \begin_layout Standard
6255 \begin_layout Standard
6264 \begin_layout Standard
6265 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6267 The next step is to add the .rel files to the library file:
6272 \begin_layout Standard
6276 sdcclib libint.lib _divsint.rel
6279 \begin_inset LatexCommand \index{sdcclib}
6286 \begin_layout Standard
6290 sdcclib libint.lib _divuint.rel
6293 \begin_layout Standard
6297 sdcclib libint.lib _modsint.rel
6300 \begin_layout Standard
6304 sdcclib libint.lib _moduint.rel
6307 \begin_layout Standard
6311 sdcclib libint.lib _mulint.rel
6319 \begin_layout Standard
6328 \begin_layout Standard
6332 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6340 \begin_layout Standard
6341 If the file already exists in the library, it will be replaced.
6342 If a list of .rel files is available, you can tell sdcclib to add those
6344 For example, if the file 'myliblist.txt' contains
6352 \begin_layout Standard
6359 \begin_layout Standard
6366 \begin_layout Standard
6373 \begin_layout Standard
6380 \begin_layout Standard
6392 \begin_layout Standard
6401 \begin_layout Standard
6405 sdcclib -l libint.lib myliblist.txt
6413 \begin_layout Standard
6414 Additionally, you can instruct sdcclib to compiles the files before adding
6415 them to the library.
6416 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6425 \begin_layout Standard
6429 set SDCCLIB_CC=sdcc -c
6432 \begin_layout Standard
6436 sdcclib -l libint.lib myliblist.txt
6444 \begin_layout Standard
6445 To see what modules and symbols are included in the library, options -s
6446 and -m are available.
6454 sdcclib -s libint.lib
6457 \begin_inset LatexCommand \index{sdcclib}
6469 \begin_layout Standard
6475 \begin_layout Standard
6481 \begin_layout Standard
6489 \begin_layout Standard
6495 \begin_layout Standard
6501 \begin_layout Standard
6507 \begin_layout Standard
6513 \begin_layout Standard
6521 \begin_layout Standard
6527 \begin_layout Standard
6533 \begin_layout Standard
6541 \begin_layout Standard
6547 \begin_layout Standard
6553 \begin_layout Standard
6559 \begin_layout Standard
6567 \begin_layout Standard
6573 \begin_layout Standard
6584 \begin_layout Standard
6585 If the source files are compiled using -
6589 \begin_layout Standard
6599 \begin_inset LatexCommand \index{-\/-debug}
6603 , the corresponding debug information file .adb will be include in the library
6605 The library files created with sdcclib are plain text files, so they can
6606 be viewed with a text editor.
6607 It is not recomended to modify a library file created with sdcclib using
6608 a text editor, as there are file indexes numbers located accross the file
6609 used by the linker to quickly locate the required module to link.
6610 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6611 it can be safely deleted, since all the information required for linking
6612 is embedded in the library file itself.
6613 Library files created using sdcclib are used as described in the preceding
6615 \begin_inset VSpace bigskip
6621 \begin_layout Section
6622 Command Line Options
6623 \begin_inset LatexCommand \index{Command Line Options}
6628 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6635 \begin_layout Subsection
6636 Processor Selection Options
6637 \begin_inset LatexCommand \index{Options processor selection}
6642 \begin_inset LatexCommand \index{Processor selection options}
6650 \labelwidthstring 00.00.0000
6654 \begin_inset LatexCommand \index{-mmcs51}
6660 Generate code for the Intel MCS51
6661 \begin_inset LatexCommand \index{MCS51}
6665 family of processors.
6666 This is the default processor target.
6670 \labelwidthstring 00.00.0000
6674 \begin_inset LatexCommand \index{-mds390}
6680 Generate code for the Dallas DS80C390
6681 \begin_inset LatexCommand \index{DS80C390}
6689 \labelwidthstring 00.00.0000
6693 \begin_inset LatexCommand \index{-mds400}
6699 Generate code for the Dallas DS80C400
6700 \begin_inset LatexCommand \index{DS80C400}
6708 \labelwidthstring 00.00.0000
6712 \begin_inset LatexCommand \index{-mhc08}
6718 Generate code for the Freescale/Motorola HC08
6719 \begin_inset LatexCommand \index{HC08}
6723 family of processors.
6727 \labelwidthstring 00.00.0000
6731 \begin_inset LatexCommand \index{-mz80}
6737 Generate code for the Zilog Z80
6738 \begin_inset LatexCommand \index{Z80}
6742 family of processors.
6746 \labelwidthstring 00.00.0000
6750 \begin_inset LatexCommand \index{-mgbz80}
6756 Generate code for the GameBoy Z80
6757 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6761 processor (Not actively maintained).
6765 \labelwidthstring 00.00.0000
6769 \begin_inset LatexCommand \index{-mavr}
6775 Generate code for the Atmel AVR
6776 \begin_inset LatexCommand \index{AVR}
6780 processor (Not maintained, not complete).
6781 AVR users should probably have a look at winavr
6782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6787 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6791 , which is based on AVR-port of the gcc compiler.
6794 \begin_layout Standard
6795 \begin_inset Note Note
6798 \begin_layout Standard
6799 I think it is fair to direct users there for now.
6800 Open source is also about avoiding unnecessary work .
6801 But I didn't find the 'official' link.
6810 \labelwidthstring 00.00.0000
6814 \begin_inset LatexCommand \index{-mpic14}
6820 Generate code for the Microchip PIC 14
6821 \begin_inset LatexCommand \index{PIC14}
6825 -bit processors (p16f84 and variants.
6826 In development, not complete).
6829 \begin_layout Standard
6830 \begin_inset Note Note
6833 \begin_layout Standard
6834 p16f627 p16f628 p16f84 p16f873 p16f877?
6843 \labelwidthstring 00.00.0000
6847 \begin_inset LatexCommand \index{-mpic16}
6853 Generate code for the Microchip PIC 16
6854 \begin_inset LatexCommand \index{PIC16}
6858 -bit processors (p18f452 and variants.
6859 In development, not complete).
6863 \labelwidthstring 00.00.0000
6868 Generate code for the Toshiba TLCS-900H
6869 \begin_inset LatexCommand \index{TLCS-900H}
6873 processor (Not maintained, not complete).
6877 \labelwidthstring 00.00.0000
6881 \begin_inset LatexCommand \index{-mxa51}
6887 Generate code for the Phillips XA51
6888 \begin_inset LatexCommand \index{XA51}
6892 processor (Not maintained, not complete).
6895 \begin_layout Standard
6896 \begin_inset VSpace bigskip
6902 \begin_layout Subsection
6903 Preprocessor Options
6904 \begin_inset LatexCommand \index{Options preprocessor}
6909 \begin_inset LatexCommand \index{Preprocessor options}
6914 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6922 \labelwidthstring 00.00.0000
6926 \begin_inset LatexCommand \index{-I<path>}
6932 The additional location where the preprocessor will look for <..h> or
6933 \begin_inset Quotes eld
6937 \begin_inset Quotes erd
6944 \labelwidthstring 00.00.0000
6948 \begin_inset LatexCommand \index{-D<macro[=value]>}
6954 Command line definition of macros.
6955 Passed to the preprocessor.
6959 \labelwidthstring 00.00.0000
6963 \begin_inset LatexCommand \index{-M}
6969 Tell the preprocessor to output a rule suitable for make describing the
6970 dependencies of each object file.
6971 For each source file, the preprocessor outputs one make-rule whose target
6972 is the object file name for that source file and whose dependencies are
6973 all the files `#include'd in it.
6974 This rule may be a single line or may be continued with `
6976 '-newline if it is long.
6977 The list of rules is printed on standard output instead of the preprocessed
6980 \begin_inset LatexCommand \index{-E}
6988 \labelwidthstring 00.00.0000
6992 \begin_inset LatexCommand \index{-C}
6998 Tell the preprocessor not to discard comments.
6999 Used with the `-E' option.
7003 \labelwidthstring 00.00.0000
7007 \begin_inset LatexCommand \index{-MM}
7018 Like `-M' but the output mentions only the user header files included with
7020 \begin_inset Quotes eld
7024 System header files included with `#include <file>' are omitted.
7028 \labelwidthstring 00.00.0000
7032 \begin_inset LatexCommand \index{-Aquestion(answer)}
7038 Assert the answer answer for question, in case it is tested with a preprocessor
7039 conditional such as `#if #question(answer)'.
7040 `-A-' disables the standard assertions that normally describe the target
7045 \labelwidthstring 00.00.0000
7049 \begin_inset LatexCommand \index{-Umacro}
7055 Undefine macro macro.
7056 `-U' options are evaluated after all `-D' options, but before any `-include'
7057 and `-imacros' options.
7061 \labelwidthstring 00.00.0000
7065 \begin_inset LatexCommand \index{-dM}
7071 Tell the preprocessor to output only a list of the macro definitions that
7072 are in effect at the end of preprocessing.
7073 Used with the `-E' option.
7077 \labelwidthstring 00.00.0000
7081 \begin_inset LatexCommand \index{-dD}
7087 Tell the preprocessor to pass all macro definitions into the output, in
7088 their proper sequence in the rest of the output.
7092 \labelwidthstring 00.00.0000
7096 \begin_inset LatexCommand \index{-dN}
7107 Like `-dD' except that the macro arguments and contents are omitted.
7108 Only `#define name' is included in the output.
7112 \labelwidthstring 00.00.0000
7115 -pedantic-parse-number
7116 \begin_inset LatexCommand \index{pedantic}
7121 \begin_inset LatexCommand \index{-pedantic-parse-number}
7129 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7137 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7138 and the macro LO_B(3) gets expanded.
7139 See also #pragma pedantic_parse_number
7140 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7145 \begin_inset LatexCommand \ref{sec:Pragmas}
7151 Note: this functionality is not in conformance with C99 standard!
7155 \labelwidthstring 00.00.0000
7159 preprocessorOption[,preprocessorOption]
7162 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7167 Pass the preprocessorOption to the preprocessor
7172 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7177 SDCC uses an adapted version of the preprocessor
7181 of the GNU Compiler Collection
7182 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7191 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7195 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7200 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7207 \begin_layout Standard
7208 \begin_inset VSpace bigskip
7214 \begin_layout Subsection
7216 \begin_inset LatexCommand \index{Options linker}
7221 \begin_inset LatexCommand \index{Linker options}
7229 \labelwidthstring 00.00.0000
7239 \begin_layout Standard
7251 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7256 \begin_inset LatexCommand \index{-L -\/-lib-path}
7263 <absolute path to additional libraries> This option is passed to the linkage
7264 editor's additional libraries
7265 \begin_inset LatexCommand \index{Libraries}
7270 The path name must be absolute.
7271 Additional library files may be specified in the command line.
7272 See section Compiling programs for more details.
7276 \labelwidthstring 00.00.0000
7283 \begin_layout Standard
7295 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7300 <Value> The start location of the external ram
7301 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7305 , default value is 0.
7306 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7310 \begin_layout Standard
7319 -xram-loc 0x8000 or -
7323 \begin_layout Standard
7336 \labelwidthstring 00.00.0000
7343 \begin_layout Standard
7355 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7360 <Value> The start location of the code
7361 \begin_inset LatexCommand \index{code}
7365 segment, default value 0.
7366 Note when this option is used the interrupt vector table
7367 \begin_inset LatexCommand \index{interrupt vector table}
7371 is also relocated to the given address.
7372 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7376 \begin_layout Standard
7385 -code-loc 0x8000 or -
7389 \begin_layout Standard
7402 \labelwidthstring 00.00.0000
7409 \begin_layout Standard
7421 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7426 <Value> By default the stack
7427 \begin_inset LatexCommand \index{stack}
7431 is placed after the data segment.
7432 Using this option the stack can be placed anywhere in the internal memory
7434 The value entered can be in Hexadecimal or Decimal format, e.g.
7439 \begin_layout Standard
7448 -stack-loc 0x20 or -
7452 \begin_layout Standard
7462 Since the sp register is incremented before a push or call, the initial
7463 sp will be set to one byte prior the provided value.
7464 The provided value should not overlap any other memory areas such as used
7465 register banks or the data segment and with enough space for the current
7473 \begin_layout Standard
7486 \begin_inset LatexCommand \index{-\/-pack-iram}
7490 option (which is now a default setting) will override this setting, so
7491 you should also specify the
7497 \begin_layout Standard
7510 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7514 option if you need to manually place the stack.
7518 \labelwidthstring 00.00.0000
7525 \begin_layout Standard
7537 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7542 <Value> By default the external stack
7543 \begin_inset LatexCommand \index{xstack}
7547 is placed after the pdata
7548 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7553 Using this option the xstack can be placed anywhere in the external memory
7555 The value entered can be in Hexadecimal or Decimal format, e.g.
7560 \begin_layout Standard
7569 -xstack-loc 0x8000 or -
7573 \begin_layout Standard
7583 The provided value should not overlap any other memory areas such as the
7584 pdata or xdata segment and with enough space for the current application.
7588 \labelwidthstring 00.00.0000
7595 \begin_layout Standard
7607 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7612 <Value> The start location of the internal ram data
7613 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7618 The value entered can be in Hexadecimal or Decimal format, eg.
7623 \begin_layout Standard
7636 \begin_layout Standard
7646 (By default, the start location of the internal ram data segment is set
7647 as low as possible in memory, taking into account the used register banks
7648 and the bit segment at address 0x20.
7649 For example if register banks 0 and 1 are used without bit variables, the
7650 data segment will be set, if -
7654 \begin_layout Standard
7663 -data-loc is not used, to location 0x10.)
7667 \labelwidthstring 00.00.0000
7674 \begin_layout Standard
7686 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7691 <Value> The start location of the indirectly addressable internal ram
7692 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7696 of the 8051, default value is 0x80.
7697 The value entered can be in Hexadecimal or Decimal format, eg.
7702 \begin_layout Standard
7711 -idata-loc 0x88 or -
7715 \begin_layout Standard
7728 \labelwidthstring 00.00.0000
7735 \begin_layout Standard
7747 <Value> The start location of the bit
7748 \begin_inset LatexCommand \index{bit}
7752 addressable internal ram of the 8051.
7758 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7763 \labelwidthstring 00.00.0000
7770 \begin_layout Standard
7780 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7789 The linker output (final object code) is in Intel Hex format.
7790 \begin_inset LatexCommand \index{Intel hex format}
7794 This is the default option.
7795 The format itself is documented in the documentation of srecord
7796 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7804 \labelwidthstring 00.00.0000
7811 \begin_layout Standard
7821 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7830 The linker output (final object code) is in Motorola S19 format
7831 \begin_inset LatexCommand \index{Motorola S19 format}
7836 The format itself is documented in the documentation of srecord.
7840 \labelwidthstring 00.00.0000
7847 \begin_layout Standard
7857 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7862 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7871 The linker output (final object code) is in ELF format
7872 \begin_inset LatexCommand \index{ELF format}
7877 (Currently only supported for the HC08
7878 \begin_inset LatexCommand \index{HC08}
7886 \labelwidthstring 00.00.0000
7890 linkOption[,linkOption]
7893 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7898 Pass the linkOption to the linker.
7899 If a bootloader is used an option like
7900 \begin_inset Quotes sld
7905 \begin_inset Quotes srd
7908 would be typical to set the start of the code segment.
7909 See also #pragma constseg and #pragma codeseg in section
7910 \begin_inset LatexCommand \ref{sec:Pragmas}
7915 File sdcc/as/doc/asxhtm.html has more on linker options.
7918 \begin_layout Standard
7919 \begin_inset VSpace bigskip
7925 \begin_layout Subsection
7927 \begin_inset LatexCommand \index{Options MCS51}
7932 \begin_inset LatexCommand \index{MCS51 options}
7940 \labelwidthstring 00.00.0000
7947 \begin_layout Standard
7957 \begin_inset LatexCommand \index{-\/-model-small}
7968 Generate code for Small Model programs, see section Memory Models for more
7970 This is the default model.
7974 \labelwidthstring 00.00.0000
7981 \begin_layout Standard
7991 \begin_inset LatexCommand \index{-\/-model-medium}
7997 Generate code for Medium model programs, see section Memory Models for
7999 If this option is used all source files in the project have to be compiled
8001 It must also be used when invoking the linker.
8005 \labelwidthstring 00.00.0000
8012 \begin_layout Standard
8022 \begin_inset LatexCommand \index{-\/-model-large}
8028 Generate code for Large model programs, see section Memory Models for more
8030 If this option is used all source files in the project have to be compiled
8032 It must also be used when invoking the linker.
8036 \labelwidthstring 00.00.0000
8043 \begin_layout Standard
8053 \begin_inset LatexCommand \index{-\/-xstack}
8059 Uses a pseudo stack in the pdata
8060 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8064 area (usually the first 256 bytes in the external ram) for allocating variables
8065 and passing parameters.
8067 \begin_inset LatexCommand \ref{sub:External-Stack}
8072 External Stack for more details.
8076 \labelwidthstring 00.00.0000
8083 \begin_layout Standard
8096 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8100 Causes the linker to check if the internal ram usage is within limits of
8105 \labelwidthstring 00.00.0000
8112 \begin_layout Standard
8125 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8129 Causes the linker to check if the external ram usage is within limits of
8134 \labelwidthstring 00.00.0000
8141 \begin_layout Standard
8154 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8158 Causes the linker to check if the code memory usage is within limits of
8163 \labelwidthstring 00.00.0000
8170 \begin_layout Standard
8183 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8187 Causes the linker to check if there is at minimum <Value> bytes for stack.
8191 \labelwidthstring 00.00.0000
8198 \begin_layout Standard
8211 \begin_inset LatexCommand \index{-\/-pack-iram}
8215 Causes the linker to use unused register banks for data variables and pack
8216 data, idata and stack together.
8217 This is the default now.
8221 \labelwidthstring 00.00.0000
8228 \begin_layout Standard
8241 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8245 Causes the linker to use old style for allocating memory areas.
8249 \labelwidthstring 00.00.0000
8256 \begin_layout Standard
8269 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8273 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8275 Only use this option if your code is in the same 2k block of memory.
8276 You may need to use this option for some 8051 derivatives which lack the
8277 lcall/ljmp instructions..
8280 \begin_layout Standard
8281 \begin_inset VSpace bigskip
8287 \begin_layout Subsection
8288 DS390 / DS400 Options
8289 \begin_inset LatexCommand \index{Options DS390}
8294 \begin_inset LatexCommand \index{DS390}
8302 \labelwidthstring 00.00.0000
8309 \begin_layout Standard
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8331 Generate 24-bit flat mode code.
8332 This is the one and only that the ds390 code generator supports right now
8333 and is default when using
8338 See section Memory Models for more details.
8342 \labelwidthstring 00.00.0000
8349 \begin_layout Standard
8359 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8365 disable interrupts during ESP:SP updates.
8369 \labelwidthstring 00.00.0000
8376 \begin_layout Standard
8388 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8392 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8393 This is the one and only that the ds390 code generator supports right now
8394 and is default when using
8399 In this mode, the stack is located in the lower 1K of the internal RAM,
8400 which is mapped to 0x400000.
8401 Note that the support is incomplete, since it still uses a single byte
8402 as the stack pointer.
8403 This means that only the lower 256 bytes of the potential 1K stack space
8404 will actually be used.
8405 However, this does allow you to reclaim the precious 256 bytes of low RAM
8406 for use for the DATA and IDATA segments.
8407 The compiler will not generate any code to put the processor into 10 bit
8409 It is important to ensure that the processor is in this mode before calling
8410 any re-entrant functions compiled with this option.
8411 In principle, this should work with the
8417 \begin_layout Standard
8427 \begin_inset LatexCommand \index{-\/-stack-auto}
8433 option, but that has not been tested.
8434 It is incompatible with the
8440 \begin_layout Standard
8450 \begin_inset LatexCommand \index{-\/-xstack}
8457 It also only makes sense if the processor is in 24 bit contiguous addressing
8464 \begin_layout Standard
8473 -model-flat24 option
8478 \begin_inset Note Note
8482 \labelwidthstring 00.00.0000
8489 \begin_layout Standard
8498 -stack-8-bit - switches off the 10-bit mode
8507 \labelwidthstring 00.00.0000
8514 \begin_layout Standard
8524 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8530 insert call to function __stack_probe at each function prologue.
8534 \labelwidthstring 00.00.0000
8541 \begin_layout Standard
8551 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8557 <nnnn> LibraryID used in -mTININative.
8562 \labelwidthstring 00.00.0000
8569 \begin_layout Standard
8579 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8585 generate code for DS390 Arithmetic Accelerator.
8589 \begin_layout Standard
8590 \begin_inset VSpace bigskip
8596 \begin_layout Subsection
8598 \begin_inset LatexCommand \index{Options Z80}
8603 \begin_inset LatexCommand \index{Z80}
8611 \labelwidthstring 00.00.0000
8618 \begin_layout Standard
8630 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8640 Force a called function to always save BC.
8644 \labelwidthstring 00.00.0000
8651 \begin_layout Standard
8663 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8667 When linking, skip the standard crt0.o object file.
8668 You must provide your own crt0.o for your system when linking.
8672 \labelwidthstring 00.00.0000
8679 \begin_layout Standard
8691 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8695 Determinate PORT I/O mode (<Value> is z80 or z180).
8699 \labelwidthstring 00.00.0000
8706 \begin_layout Standard
8718 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8722 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8726 \labelwidthstring 00.00.0000
8733 \begin_layout Standard
8746 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8750 Use <Value> for the code segment name.
8754 \labelwidthstring 00.00.0000
8761 \begin_layout Standard
8774 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8778 Use <Value> for the const segment name.
8782 \labelwidthstring 00.00.0000
8783 \begin_inset VSpace bigskip
8789 \begin_layout Subsection
8791 \begin_inset LatexCommand \index{Options GBZ80}
8796 \begin_inset LatexCommand \index{GBZ80}
8804 \labelwidthstring 00.00.0000
8811 \begin_layout Standard
8823 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8833 Force a called function to always save BC.
8837 \labelwidthstring 00.00.0000
8844 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8848 Use code bank <Num>.
8852 \labelwidthstring 00.00.0000
8859 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8863 Use data bank <Num>.
8867 \labelwidthstring 00.00.0000
8874 \begin_layout Standard
8887 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8891 Use <Value> for the code segment name.
8895 \labelwidthstring 00.00.0000
8902 \begin_layout Standard
8915 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8919 Use <Value> for the const segment name.
8922 \begin_layout Standard
8923 \begin_inset VSpace bigskip
8929 \begin_layout Subsection
8930 Optimization Options
8931 \begin_inset LatexCommand \index{Options optimization}
8936 \begin_inset LatexCommand \index{Optimization options}
8944 \labelwidthstring 00.00.0000
8951 \begin_layout Standard
8961 \begin_inset LatexCommand \index{-\/-nogcse}
8967 Will not do global subexpression elimination, this option may be used when
8968 the compiler creates undesirably large stack/data spaces to store compiler
8978 \begin_inset LatexCommand \index{sloc (spill location)}
8983 A warning message will be generated when this happens and the compiler
8984 will indicate the number of extra bytes it allocated.
8985 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8987 \begin_inset LatexCommand \index{\#pragma nogcse}
8991 can be used to turn off global subexpression elimination
8992 \begin_inset LatexCommand \index{Subexpression elimination}
8996 for a given function only.
9000 \labelwidthstring 00.00.0000
9007 \begin_layout Standard
9017 \begin_inset LatexCommand \index{-\/-noinvariant}
9023 Will not do loop invariant optimizations, this may be turned off for reasons
9024 explained for the previous option.
9025 For more details of loop optimizations performed see Loop Invariants in
9027 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9032 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9034 \begin_inset LatexCommand \index{\#pragma noinvariant}
9038 can be used to turn off invariant optimizations for a given function only.
9042 \labelwidthstring 00.00.0000
9049 \begin_layout Standard
9059 \begin_inset LatexCommand \index{-\/-noinduction}
9065 Will not do loop induction optimizations, see section strength reduction
9067 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9069 \begin_inset LatexCommand \index{\#pragma noinduction}
9073 can be used to turn off induction optimizations for a given function only.
9077 \labelwidthstring 00.00.0000
9084 \begin_layout Standard
9094 \begin_inset LatexCommand \index{-\/-nojtbound}
9105 Will not generate boundary condition check when switch statements
9106 \begin_inset LatexCommand \index{switch statement}
9110 are implemented using jump-tables.
9112 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9117 Switch Statements for more details.
9118 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9120 \begin_inset LatexCommand \index{\#pragma nojtbound}
9124 can be used to turn off boundary checking for jump tables for a given function
9129 \labelwidthstring 00.00.0000
9136 \begin_layout Standard
9146 \begin_inset LatexCommand \index{-\/-noloopreverse}
9155 Will not do loop reversal
9156 \begin_inset LatexCommand \index{Loop reversing}
9164 \labelwidthstring 00.00.0000
9169 \begin_layout Standard
9183 \begin_inset LatexCommand \index{-\/-nolabelopt }
9187 Will not optimize labels (makes the dumpfiles more readable).
9191 \labelwidthstring 00.00.0000
9198 \begin_layout Standard
9208 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9214 Will not memcpy initialized data from code space into xdata space.
9215 This saves a few bytes in code space if you don't have initialized data
9216 \begin_inset LatexCommand \index{Variable initialization}
9224 \labelwidthstring 00.00.0000
9231 \begin_layout Standard
9241 \begin_inset LatexCommand \index{-\/-nooverlay}
9247 The compiler will not overlay parameters and local variables of any function,
9248 see section Parameters and local variables for more details.
9252 \labelwidthstring 00.00.0000
9259 \begin_layout Standard
9269 \begin_inset LatexCommand \index{-\/-no-peep}
9275 Disable peep-hole optimization with built-in rules.
9279 \labelwidthstring 00.00.0000
9286 \begin_layout Standard
9298 \begin_inset LatexCommand \index{-\/-peep-file}
9303 <filename> This option can be used to use additional rules to be used by
9304 the peep hole optimizer.
9306 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9311 Peep Hole optimizations for details on how to write these rules.
9315 \labelwidthstring 00.00.0000
9322 \begin_layout Standard
9332 \begin_inset LatexCommand \index{-\/-peep-asm}
9338 Pass the inline assembler code through the peep hole optimizer.
9339 This can cause unexpected changes to inline assembler code, please go through
9340 the peephole optimizer
9341 \begin_inset LatexCommand \index{Peephole optimizer}
9345 rules defined in the source file tree '<target>/peeph.def' before using
9350 \labelwidthstring 00.00.0000
9357 \begin_layout Standard
9367 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9373 The compiler will optimize code generation towards fast code, possibly
9374 at the expense of code size.
9378 \labelwidthstring 00.00.0000
9385 \begin_layout Standard
9395 \begin_inset LatexCommand \index{-\/-opt-code-size}
9401 The compiler will optimize code generation towards compact code, possibly
9402 at the expense of code speed.
9405 \begin_layout Standard
9406 \begin_inset VSpace bigskip
9412 \begin_layout Subsection
9414 \begin_inset LatexCommand \index{Options other}
9422 \labelwidthstring 00.00.0000
9430 \begin_layout Standard
9440 \begin_inset LatexCommand \index{-\/-compile-only}
9445 \begin_inset LatexCommand \index{-c -\/-compile-only}
9451 will compile and assemble the source, but will not call the linkage editor.
9455 \labelwidthstring 00.00.0000
9464 \begin_layout Standard
9476 \begin_inset LatexCommand \index{-\/-c1mode}
9482 reads the preprocessed source from standard input and compiles it.
9483 The file name for the assembler output must be specified using the -o option.
9487 \labelwidthstring 00.00.0000
9491 \begin_inset LatexCommand \index{-E}
9497 Run only the C preprocessor.
9498 Preprocess all the C source files specified and output the results to standard
9503 \labelwidthstring 00.00.0000
9508 \begin_inset LatexCommand \index{-o <path/file>}
9514 The output path where everything will be placed or the file name used for
9515 all generated output files.
9516 If the parameter is a path, it must have a trailing slash (or backslash
9517 for the Windows binaries) to be recognized as a path.
9522 Note for Windows users: if the path contains spaces, it should be surrounded
9524 The trailing backslash should be doubled in order to prevent escaping the
9525 final quote, for example:
9528 \begin_inset Quotes sld
9542 \begin_inset Quotes srd
9547 or put after the final quote, for example:
9550 \begin_inset Quotes sld
9560 \begin_inset Quotes srd
9568 The path using slashes for directory delimiters can be used too, for example:
9572 \begin_inset Quotes sld
9575 F:/Projects/test3/output 1/
9576 \begin_inset Quotes srd
9585 \labelwidthstring 00.00.0000
9592 \begin_layout Standard
9602 \begin_inset LatexCommand \index{-\/-stack-auto}
9613 All functions in the source file will be compiled as
9618 \begin_inset LatexCommand \index{reentrant}
9623 the parameters and local variables will be allocated on the stack
9624 \begin_inset LatexCommand \index{stack}
9630 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9634 Parameters and Local Variables for more details.
9635 If this option is used all source files in the project should be compiled
9637 It automatically implies -
9643 \begin_layout Standard
9654 -int-long-reent and -
9660 \begin_layout Standard
9676 \labelwidthstring 00.00.0000
9683 \begin_layout Standard
9693 \begin_inset LatexCommand \index{-\/-callee-saves}
9698 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9702 function1[,function2][,function3]....
9705 The compiler by default uses a caller saves convention for register saving
9706 across function calls, however this can cause unnecessary register pushing
9707 and popping when calling small functions from larger functions.
9708 This option can be used to switch the register saving convention for the
9709 function names specified.
9710 The compiler will not save registers when calling these functions, no extra
9711 code will be generated at the entry and exit (function prologue
9714 \begin_inset LatexCommand \index{function prologue}
9723 \begin_inset LatexCommand \index{function epilogue}
9729 ) for these functions to save and restore the registers used by these functions,
9730 this can SUBSTANTIALLY reduce code and improve run time performance of
9732 In the future the compiler (with inter procedural analysis) will be able
9733 to determine the appropriate scheme to use for each function call.
9734 DO NOT use this option for built-in functions such as _mulint..., if this
9735 option is used for a library function the appropriate library function
9736 needs to be recompiled with the same option.
9737 If the project consists of multiple source files then all the source file
9738 should be compiled with the same -
9742 \begin_layout Standard
9751 -callee-saves option string.
9752 Also see #pragma\InsetSpace ~
9754 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9759 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9767 \labelwidthstring 00.00.0000
9774 \begin_layout Standard
9784 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9798 \begin_layout Standard
9807 -callee-saves will be applied to all functions by default.
9811 \labelwidthstring 00.00.0000
9818 \begin_layout Standard
9828 \begin_inset LatexCommand \index{-\/-debug}
9837 When this option is used the compiler will generate debug information.
9838 The debug information collected in a file with .cdb extension can be used
9840 For more information see documentation for SDCDB.
9841 Another file with no extension contains debug information in AOMF or AOMF51
9842 \begin_inset LatexCommand \index{AOMF, AOMF51}
9846 format which is commonly used by third party tools.
9850 \labelwidthstring 00.00.0000
9854 \begin_inset LatexCommand \index{-S}
9865 Stop after the stage of compilation proper; do not assemble.
9866 The output is an assembler code file for the input file specified.
9870 \labelwidthstring 00.00.0000
9877 \begin_layout Standard
9887 \begin_inset LatexCommand \index{-\/-int-long-reent}
9893 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9894 Note by default these libraries are compiled as non-reentrant.
9895 See section Installation for more details.
9899 \labelwidthstring 00.00.0000
9906 \begin_layout Standard
9916 \begin_inset LatexCommand \index{-\/-cyclomatic}
9925 This option will cause the compiler to generate an information message for
9926 each function in the source file.
9927 The message contains some
9931 information about the function.
9932 The number of edges and nodes the compiler detected in the control flow
9933 graph of the function, and most importantly the
9935 cyclomatic complexity
9936 \begin_inset LatexCommand \index{Cyclomatic complexity}
9942 see section on Cyclomatic Complexity for more details.
9946 \labelwidthstring 00.00.0000
9953 \begin_layout Standard
9963 \begin_inset LatexCommand \index{-\/-float-reent}
9969 Floating point library is compiled as reentrant
9970 \begin_inset LatexCommand \index{reentrant}
9975 See section Installation for more details.
9979 \labelwidthstring 00.00.0000
9986 \begin_layout Standard
9996 \begin_inset LatexCommand \index{-\/-funsigned-char}
10002 The default signedness for every type is
10007 In some embedded environments the default signedness of
10016 To set the signess for characters to unsigned, use the option -
10022 \begin_layout Standard
10034 If this option is set and no signedness keyword (unsigned/signed) is given,
10035 a char will be signed.
10036 All other types are unaffected.
10040 \labelwidthstring 00.00.0000
10047 \begin_layout Standard
10057 \begin_inset LatexCommand \index{-\/-main-return}
10063 This option can be used if the code generated is called by a monitor program
10064 or if the main routine includes an endless loop.
10065 This option results in slightly smaller code and saves two bytes of stack
10067 The return from the 'main'
10068 \begin_inset LatexCommand \index{main return}
10072 function will return to the function calling main.
10073 The default setting is to lock up i.e.
10082 \labelwidthstring 00.00.0000
10089 \begin_layout Standard
10099 \begin_inset LatexCommand \index{-\/-nostdinc}
10105 This will prevent the compiler from passing on the default include path
10106 to the preprocessor.
10110 \labelwidthstring 00.00.0000
10117 \begin_layout Standard
10127 \begin_inset LatexCommand \index{-\/-nostdlib}
10133 This will prevent the compiler from passing on the default library
10134 \begin_inset LatexCommand \index{Libraries}
10138 path to the linker.
10142 \labelwidthstring 00.00.0000
10149 \begin_layout Standard
10159 \begin_inset LatexCommand \index{-\/-verbose}
10165 Shows the various actions the compiler is performing.
10169 \labelwidthstring 00.00.0000
10173 \begin_inset LatexCommand \index{-V}
10179 Shows the actual commands the compiler is executing.
10183 \labelwidthstring 00.00.0000
10190 \begin_layout Standard
10200 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10206 Hides your ugly and inefficient c-code from the asm file, so you can always
10207 blame the compiler :)
10211 \labelwidthstring 00.00.0000
10218 \begin_layout Standard
10228 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10234 Include code generator and peep-hole comments in the generated asm files.
10238 \labelwidthstring 00.00.0000
10245 \begin_layout Standard
10255 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10261 Don't include peep-hole comments in the generated asm files even if -
10267 \begin_layout Standard
10278 -fverbose-asm option is specified.
10282 \labelwidthstring 00.00.0000
10289 \begin_layout Standard
10299 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10305 Include i-codes in the asm file.
10306 Sounds like noise but is most helpful for debugging the compiler itself.
10310 \labelwidthstring 00.00.0000
10317 \begin_layout Standard
10327 \begin_inset LatexCommand \index{pedantic}
10332 \begin_inset LatexCommand \index{-\/-less-pedantic}
10339 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10343 Disable some of the more pedantic warnings
10344 \begin_inset LatexCommand \index{Warnings}
10349 For more details, see the less_pedantic pragma
10350 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10358 \labelwidthstring 00.00.0000
10365 \begin_layout Standard
10374 -disable-warning\InsetSpace ~
10376 \begin_inset LatexCommand \index{-\/-disable-warning}
10382 Disable specific warning with number <nnnn>.
10386 \labelwidthstring 00.00.0000
10393 \begin_layout Standard
10403 \begin_inset LatexCommand \index{-\/-Werror}
10409 Treat all warnings as errors.
10413 \labelwidthstring 00.00.0000
10420 \begin_layout Standard
10430 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10436 Display the directories in the compiler's search path
10440 \labelwidthstring 00.00.0000
10447 \begin_layout Standard
10457 \begin_inset LatexCommand \index{-\/-vc}
10463 Display errors and warnings using MSVC style, so you can use SDCC with
10464 the visual studio IDE
10465 \begin_inset LatexCommand \index{IDE}
10470 With SDCC both offering a GCC-like (the default) and a MSVC-like
10471 \begin_inset LatexCommand \index{MSVC output style}
10475 output style, integration into most programming editors should be straightforwa
10480 \labelwidthstring 00.00.0000
10487 \begin_layout Standard
10497 \begin_inset LatexCommand \index{-\/-use-stdout}
10503 Send errors and warnings to stdout instead of stderr.
10507 \labelwidthstring 00.00.0000
10511 asmOption[,asmOption]
10514 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10519 Pass the asmOption to the assembler
10520 \begin_inset LatexCommand \index{Options assembler}
10525 \begin_inset LatexCommand \index{Assembler options}
10530 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10534 \labelwidthstring 00.00.0000
10541 \begin_layout Standard
10551 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10557 Generally follow the C89 standard, but allow SDCC features that conflict
10558 with the standard (default).
10562 \labelwidthstring 00.00.0000
10569 \begin_layout Standard
10579 \begin_inset LatexCommand \index{-\/-std-c89}
10585 Follow the C89 standard and disable SDCC features that conflict with the
10590 \labelwidthstring 00.00.0000
10597 \begin_layout Standard
10607 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10613 Generally follow the C99 standard, but allow SDCC features that conflict
10614 with the standard (incomplete support).
10618 \labelwidthstring 00.00.0000
10625 \begin_layout Standard
10635 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10641 Follow the C99 standard and disable SDCC features that conflict with the
10642 standard (incomplete support).
10646 \labelwidthstring 00.00.0000
10653 \begin_layout Standard
10665 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10670 <Name> The name to be used for the code
10671 \begin_inset LatexCommand \index{code}
10675 segment, default CSEG.
10676 This is useful if you need to tell the compiler to put the code in a special
10677 segment so you can later on tell the linker to put this segment in a special
10679 Can be used for instance when using bank switching to put the code in a
10684 \labelwidthstring 00.00.0000
10691 \begin_layout Standard
10703 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10708 <Name> The name to be used for the const
10709 \begin_inset LatexCommand \index{const}
10713 segment, default CONST.
10714 This is useful if you need to tell the compiler to put the const data in
10715 a special segment so you can later on tell the linker to put this segment
10716 in a special place in memory.
10717 Can be used for instance when using bank switching to put the const data
10722 \labelwidthstring 00.00.0000
10729 \begin_layout Standard
10738 -fdollars-in-identifiers
10739 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10745 Permit '$' as an identifier character.
10749 \labelwidthstring 00.00.0000
10756 \begin_layout Standard
10768 \begin_inset LatexCommand \index{-\/-more-pedantic}
10773 \begin_inset LatexCommand \index{pedantic}
10783 a SDCC compiler option but if you want
10787 warnings you can use a separate tool dedicated to syntax checking like
10789 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10794 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10799 \begin_inset LatexCommand \url{http://www.splint.org}
10804 To make your source files parseable by splint you will have to include
10810 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10814 in your source file and add brackets around extended keywords (like
10817 \begin_inset Quotes sld
10830 \begin_inset Quotes srd
10838 \begin_inset Quotes sld
10841 __interrupt\InsetSpace ~
10843 \begin_inset Quotes srd
10851 Splint has an excellent on line manual at
10852 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10856 and it's capabilities go beyond pure syntax checking.
10857 You'll need to tell splint the location of SDCC's include files so a typical
10858 command line could look like this:
10862 splint\InsetSpace ~
10864 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10870 \labelwidthstring 00.00.0000
10877 \begin_layout Standard
10889 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10894 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10898 Treat short as 8-bit (for backward compatibility with older versions of
10899 compiler - see section
10900 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10907 \begin_layout Standard
10908 \begin_inset VSpace bigskip
10914 \begin_layout Subsection
10915 Intermediate Dump Options
10916 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10921 \begin_inset LatexCommand \index{Options intermediate dump}
10926 \begin_inset LatexCommand \index{Intermediate dump options}
10933 \begin_layout Standard
10934 The following options are provided for the purpose of retargetting and debugging
10936 They provide a means to dump the intermediate code (iCode
10937 \begin_inset LatexCommand \index{iCode}
10941 ) generated by the compiler in human readable form at various stages of
10942 the compilation process.
10943 More on iCodes see chapter
10944 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10949 \begin_inset Quotes srd
10952 The anatomy of the compiler
10953 \begin_inset Quotes srd
10960 \labelwidthstring 00.00.0000
10967 \begin_layout Standard
10977 \begin_inset LatexCommand \index{-\/-dumpraw}
10983 This option will cause the compiler to dump the intermediate code into
10986 <source filename>.dumpraw
10988 just after the intermediate code has been generated for a function, i.e.
10989 before any optimizations are done.
10991 \begin_inset LatexCommand \index{Basic blocks}
10995 at this stage ordered in the depth first number, so they may not be in
10996 sequence of execution.
11000 \labelwidthstring 00.00.0000
11007 \begin_layout Standard
11017 \begin_inset LatexCommand \index{-\/-dumpgcse}
11023 Will create a dump of iCodes, after global subexpression elimination
11024 \begin_inset LatexCommand \index{Global subexpression elimination}
11028 , into a file named
11030 <source filename>.dumpgcse.
11034 \labelwidthstring 00.00.0000
11041 \begin_layout Standard
11051 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11057 Will create a dump of iCodes, after deadcode elimination
11058 \begin_inset LatexCommand \index{Dead-code elimination}
11062 , into a file named
11064 <source filename>.dumpdeadcode.
11068 \labelwidthstring 00.00.0000
11075 \begin_layout Standard
11085 \begin_inset LatexCommand \index{-\/-dumploop}
11094 Will create a dump of iCodes, after loop optimizations
11095 \begin_inset LatexCommand \index{Loop optimization}
11099 , into a file named
11101 <source filename>.dumploop.
11105 \labelwidthstring 00.00.0000
11112 \begin_layout Standard
11122 \begin_inset LatexCommand \index{-\/-dumprange}
11131 Will create a dump of iCodes, after live range analysis
11132 \begin_inset LatexCommand \index{Live range analysis}
11136 , into a file named
11138 <source filename>.dumprange.
11142 \labelwidthstring 00.00.0000
11149 \begin_layout Standard
11159 \begin_inset LatexCommand \index{-\/-dumlrange}
11165 Will dump the life ranges
11166 \begin_inset LatexCommand \index{Live range analysis}
11174 \labelwidthstring 00.00.0000
11181 \begin_layout Standard
11191 \begin_inset LatexCommand \index{-\/-dumpregassign}
11200 Will create a dump of iCodes, after register assignment
11201 \begin_inset LatexCommand \index{Register assignment}
11205 , into a file named
11207 <source filename>.dumprassgn.
11211 \labelwidthstring 00.00.0000
11218 \begin_layout Standard
11228 \begin_inset LatexCommand \index{-\/-dumplrange}
11234 Will create a dump of the live ranges of iTemp's
11238 \labelwidthstring 00.00.0000
11245 \begin_layout Standard
11255 \begin_inset LatexCommand \index{-\/-dumpall}
11266 Will cause all the above mentioned dumps to be created.
11269 \begin_layout Standard
11270 \begin_inset VSpace bigskip
11276 \begin_layout Subsection
11277 Redirecting output on Windows Shells
11280 \begin_layout Standard
11281 By default SDCC writes its error messages to
11282 \begin_inset Quotes sld
11286 \begin_inset Quotes srd
11290 To force all messages to
11291 \begin_inset Quotes sld
11295 \begin_inset Quotes srd
11307 \begin_layout Standard
11322 \begin_inset LatexCommand \index{-\/-use-stdout}
11327 Additionally, if you happen to have visual studio installed in your windows
11328 machine, you can use it to compile your sources using a custom build and
11335 \begin_layout Standard
11347 \begin_inset LatexCommand \index{-\/-vc}
11352 Something like this should work:
11371 \begin_layout Standard
11390 \begin_layout Standard
11402 -model-large -c $(InputPath)
11405 \begin_inset VSpace bigskip
11411 \begin_layout Section
11412 Environment variables
11413 \begin_inset LatexCommand \index{Environment variables}
11420 \begin_layout Standard
11421 SDCC recognizes the following environment variables:
11425 \labelwidthstring 00.00.0000
11429 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11435 SDCC installs a signal handler
11436 \begin_inset LatexCommand \index{signal handler}
11440 to be able to delete temporary files after an user break (^C) or an exception.
11441 If this environment variable is set, SDCC won't install the signal handler
11442 in order to be able to debug SDCC.
11446 \labelwidthstring 00.00.0000
11452 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11458 Path, where temporary files will be created.
11459 The order of the variables is the search order.
11460 In a standard *nix environment these variables are not set, and there's
11461 no need to set them.
11462 On Windows it's recommended to set one of them.
11466 \labelwidthstring 00.00.0000
11470 \begin_inset LatexCommand \index{SDCC\_HOME}
11477 \begin_inset LatexCommand \ref{sub:Install-paths}
11483 \begin_inset Quotes sld
11487 \begin_inset Quotes srd
11494 \labelwidthstring 00.00.0000
11498 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11505 \begin_inset LatexCommand \ref{sub:Search-Paths}
11511 \begin_inset Quotes sld
11515 \begin_inset Quotes srd
11522 \labelwidthstring 00.00.0000
11526 \begin_inset LatexCommand \index{SDCC\_LIB}
11533 \begin_inset LatexCommand \ref{sub:Search-Paths}
11539 \begin_inset Quotes sld
11543 \begin_inset Quotes srd
11549 \begin_layout Standard
11550 There are some more environment variables recognized by SDCC, but these
11551 are solely used for debugging purposes.
11552 They can change or disappear very quickly, and will never be documented.
11553 \begin_inset VSpace bigskip
11559 \begin_layout Section
11560 Storage Class Language Extensions
11563 \begin_layout Subsection
11564 MCS51/DS390 Storage Class
11565 \begin_inset LatexCommand \index{Storage class}
11569 Language Extensions
11572 \begin_layout Standard
11573 In addition to the ANSI storage classes SDCC allows the following MCS51
11574 specific storage classes:
11577 \begin_layout Subsubsection
11579 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11584 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11589 \begin_inset LatexCommand \index{near (storage class)}
11594 \begin_inset LatexCommand \index{\_\_near (storage class)}
11601 \begin_layout Standard
11606 storage class for the Small Memory model (
11614 or the more ANSI-C compliant forms
11622 can be used synonymously).
11623 Variables declared with this storage class will be allocated in the directly
11624 addressable portion of the internal RAM of a 8051, e.g.:
11627 \begin_layout Verse
11630 __data unsigned char test_data;
11633 \begin_layout Standard
11634 Writing 0x01 to this variable generates the assembly code:
11637 \begin_layout Verse
11640 75*00 01\InsetSpace ~
11648 \begin_layout Subsubsection
11650 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11655 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11660 \begin_inset LatexCommand \index{far (storage class)}
11665 \begin_inset LatexCommand \index{\_\_far (storage class)}
11672 \begin_layout Standard
11673 Variables declared with this storage class will be placed in the external
11679 storage class for the Large Memory model, e.g.:
11682 \begin_layout Verse
11685 __xdata unsigned char test_xdata;
11688 \begin_layout Standard
11689 Writing 0x01 to this variable generates the assembly code:
11692 \begin_layout Verse
11695 90s00r00\InsetSpace ~
11726 \begin_layout Subsubsection
11728 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11733 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11740 \begin_layout Standard
11741 Variables declared with this storage class will be allocated into the indirectly
11742 addressable portion of the internal ram of a 8051, e.g.:
11745 \begin_layout Verse
11748 __idata unsigned char test_idata;
11751 \begin_layout Standard
11752 Writing 0x01 to this variable generates the assembly code:
11755 \begin_layout Verse
11782 \begin_layout Standard
11783 Please note, the first 128 byte of idata physically access the same RAM
11784 as the data memory.
11785 The original 8051 had 128 byte idata memory, nowadays most devices have
11786 256 byte idata memory.
11788 \begin_inset LatexCommand \index{stack}
11792 is located in idata memory.
11795 \begin_layout Subsubsection
11797 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11802 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11809 \begin_layout Standard
11810 Paged xdata access is just as straightforward as using the other addressing
11812 It is typically located at the start of xdata and has a maximum size of
11814 The following example writes 0x01 to the pdata variable.
11815 Please note, pdata access physically accesses xdata memory.
11816 The high byte of the address is determined by port P2
11817 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11821 (or in case of some 8051 variants by a separate Special Function Register,
11823 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11832 storage class for the Medium Memory model, e.g.:
11835 \begin_layout Verse
11838 __pdata unsigned char test_pdata;
11841 \begin_layout Standard
11842 Writing 0x01 to this variable generates the assembly code:
11845 \begin_layout Verse
11854 mov r0,#_test_pdata
11876 \begin_layout Standard
11881 \begin_layout Standard
11891 \begin_inset LatexCommand \index{-\/-xstack}
11895 option is used the pdata memory area is followed by the xstack memory area
11896 and the sum of their sizes is limited to 256 bytes.
11899 \begin_layout Subsubsection
11901 \begin_inset LatexCommand \index{code}
11906 \begin_inset LatexCommand \index{\_\_code}
11913 \begin_layout Standard
11914 'Variables' declared with this storage class will be placed in the code
11918 \begin_layout Verse
11921 __code unsigned char test_code;
11924 \begin_layout Standard
11925 Read access to this variable generates the assembly code:
11928 \begin_layout Verse
11931 90s00r6F\InsetSpace ~
11934 mov dptr,#_test_code
11959 \begin_layout Standard
11964 indexed arrays of characters in code memory can be accessed efficiently:
11967 \begin_layout Verse
11970 __code char test_array[] = {'c','h','e','a','p'};
11973 \begin_layout Standard
11974 Read access to this array using an 8-bit unsigned index generates the assembly
11978 \begin_layout Verse
11990 \begin_layout Verse
11993 90s00r41\InsetSpace ~
11996 mov dptr,#_test_array
11999 \begin_layout Verse
12014 \begin_layout Subsubsection
12016 \begin_inset LatexCommand \index{bit}
12021 \begin_inset LatexCommand \index{\_\_bit}
12028 \begin_layout Standard
12029 This is a data-type and a storage class specifier.
12030 When a variable is declared as a bit, it is allocated into the bit addressable
12031 memory of 8051, e.g.:
12034 \begin_layout Verse
12040 \begin_layout Standard
12041 Writing 1 to this variable generates the assembly code:
12044 \begin_layout Verse
12058 \begin_layout Standard
12059 The bit addressable memory consists of 128 bits which are located from 0x20
12060 to 0x2f in data memory.
12063 Apart from this 8051 specific storage class most architectures support
12065 \begin_inset LatexCommand \index{bitfields}
12073 \begin_layout Standard
12074 Not really meant as examples, but nevertheless showing what bitfields are
12075 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12081 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12082 signed modifier are implemented as unsigned.
12085 \begin_layout Subsubsection
12087 \begin_inset LatexCommand \index{sfr}
12092 \begin_inset LatexCommand \index{\_\_sfr}
12097 \begin_inset LatexCommand \index{sfr16}
12102 \begin_inset LatexCommand \index{\_\_sfr16}
12107 \begin_inset LatexCommand \index{sfr32}
12112 \begin_inset LatexCommand \index{\_\_sfr32}
12117 \begin_inset LatexCommand \index{\_\_sbit}
12122 \begin_inset LatexCommand \index{sbit}
12129 \begin_layout Standard
12130 Like the bit keyword,
12132 sfr / sfr16 / sfr32 / sbit
12134 signify both a data-type and storage class, they are used to describe the
12155 variables of a 8051, eg:
12158 \begin_layout Verse
12162 \begin_inset LatexCommand \index{at}
12167 \begin_inset LatexCommand \index{\_\_at}
12171 (0x80) P0;\InsetSpace ~
12172 /* special function register P0 at location 0x80 */
12177 special function register combination for timer 0
12181 with the high byte at
12182 location 0x8C and the low byte at location 0x8A */
12184 __sfr16 __at (0x8C8A)
12190 \begin_inset LatexCommand \index{at}
12195 \begin_inset LatexCommand \index{\_\_at}
12199 (0xd7) CY;\InsetSpace ~
12201 \begin_inset LatexCommand \index{Flags}
12206 \begin_inset LatexCommand \index{Carry flag}
12213 \begin_layout Standard
12214 Special function registers which are located on an address dividable by
12215 8 are bit-addressable, an
12219 addresses a specific bit within these sfr.
12221 16 Bit and 32 bit special function
12222 register combinations which require a certain access order are better not
12232 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12233 this is not guaranteed.
12238 \begin_layout Standard
12239 Please note, if you use a header file which was written for another compiler
12240 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12246 Specifically the syntax
12249 sfr P0 = 0x80;\InsetSpace ~
12256 by SDCC to an assignment of 0x80 to a variable called P0
12259 \begin_inset Marginal
12262 \begin_layout Standard
12274 Nevertheless it is possible to write header files
12275 \begin_inset LatexCommand \index{Header files}
12280 \begin_inset LatexCommand \index{Include files}
12284 which can be shared among different compilers (see section
12285 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12293 \begin_layout Subsubsection
12295 \begin_inset LatexCommand \index{Pointer}
12299 to MCS51/DS390 specific memory spaces
12302 \begin_layout Standard
12303 SDCC allows (via language extensions) pointers to explicitly point to any
12304 of the memory spaces
12305 \begin_inset LatexCommand \index{Memory model}
12310 In addition to the explicit pointers, the compiler uses (by default) generic
12311 pointers which can be used to point to any of the memory spaces.
12316 declaration examples:
12319 \begin_layout Verse
12322 /* pointer physically in internal ram pointing to object in external ram
12325 __xdata unsigned char * __data p;
12329 /* pointer physically in external ram
12330 pointing to object in internal ram */
12332 __data unsigned char * __xdata p;
12337 pointer physically in code rom pointing to data in xdata space */
12340 unsigned char * __code p;
12344 /* pointer physically in code space pointing to
12345 data in code space */
12347 __code unsigned char * __code p;
12352 physically located in xdata space */
12354 unsigned char * __xdata p;
12359 pointer physically located in default memory space */
12366 the following is a function pointer
12367 \begin_inset LatexCommand \index{function pointer}
12371 physically located in data space */
12373 char (* __data fp)(void);
12376 \begin_layout Standard
12377 Well you get the idea.
12382 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12395 The highest order byte of the
12399 pointers contains the data space information.
12400 Assembler support routines are called whenever data is stored or retrieved
12406 These are useful for developing reusable library
12407 \begin_inset LatexCommand \index{Libraries}
12412 Explicitly specifying the pointer
12413 \begin_inset LatexCommand \index{pointer}
12417 type will generate the most efficient code.
12420 \begin_layout Subsubsection
12421 Notes on MCS51 memory
12422 \begin_inset LatexCommand \index{MCS51 memory}
12429 \begin_layout Standard
12430 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12431 RAM memory which is structured as follows:
12435 - Bytes 00-1F - 32 bytes to hold
12436 up to 4 banks of the registers R0 to R7,
12438 - Bytes 20-2F - 16 bytes to hold
12440 \begin_inset LatexCommand \index{bit}
12446 - Bytes 30-7F - 80 bytes for general purpose use.
12451 \begin_layout Standard
12452 Additionally some members of the MCS51 family may have up to 128 bytes of
12453 additional, indirectly addressable, internal RAM memory (
12458 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12463 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12468 Furthermore, some chips may have some built in external memory (
12473 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12478 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12482 ) which should not be confused with the internal, directly addressable RAM
12488 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12493 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12498 Sometimes this built in
12502 memory has to be activated before using it (you can probably find this
12503 information on the datasheet of the microcontroller your are using, see
12505 \begin_inset LatexCommand \ref{sub:Startup-Code}
12513 \begin_layout Standard
12514 Normally SDCC will only use the first bank
12515 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12519 of registers (register bank 0), but it is possible to specify that other
12520 banks of registers (keyword
12527 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12532 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12538 ) should be used for example in interrupt
12539 \begin_inset LatexCommand \index{interrupt}
12544 \begin_inset LatexCommand \index{\_\_interrupt}
12549 By default, the compiler will place the stack after the last byte of allocated
12550 memory for variables.
12551 For example, if the first 2 banks of registers are used, and only four
12556 variables, it will position the base of the internal stack at address 20
12558 This implies that as the stack
12559 \begin_inset LatexCommand \index{stack}
12563 grows, it will use up the remaining register banks, and the 16 bytes used
12564 by the 128 bit variables, and 80 bytes for general purpose use.
12565 If any bit variables are used, the data variables will be placed in unused
12566 register banks and after the byte holding the last bit variable.
12567 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12572 variables will be placed starting from address 0x10 to 0x20 and continue
12578 \begin_layout Standard
12588 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12592 to specify the start address of the
12600 \begin_layout Standard
12610 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12614 to specify the size of the total internal RAM (
12628 \begin_layout Standard
12629 By default the 8051 linker will place the stack after the last byte of (i)data
12635 \begin_layout Standard
12645 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12649 allows you to specify the start of the stack, i.e.
12650 you could start it after any data in the general purpose area.
12651 If your microcontroller has additional indirectly addressable internal
12656 ) you can place the stack on it.
12657 You may also need to use -
12661 \begin_layout Standard
12671 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12675 to set the start address of the external RAM (
12683 \begin_layout Standard
12693 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12697 to specify its size.
12698 Same goes for the code memory, using -
12702 \begin_layout Standard
12712 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12720 \begin_layout Standard
12730 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12735 If in doubt, don't specify any options and see if the resulting memory
12736 layout is appropriate, then you can adjust it.
12739 \begin_layout Standard
12740 The linker generates two files with memory allocation information.
12741 The first, with extension .map
12742 \begin_inset LatexCommand \index{<file>.map}
12746 shows all the variables and segments.
12747 The second with extension .mem
12748 \begin_inset LatexCommand \index{<file>.mem}
12752 shows the final memory layout.
12753 The linker will complain either if memory segments overlap, there is not
12754 enough memory, or there is not enough space for stack.
12755 If you get any linking warnings and/or errors related to stack or segments
12756 allocation, take a look at either the .map or .mem files to find out what
12758 The .mem file may even suggest a solution to the problem.
12759 \begin_inset VSpace bigskip
12765 \begin_layout Subsection
12766 Z80/Z180 Storage Class
12767 \begin_inset LatexCommand \index{Z80!Storage class}
12771 Language Extensions
12774 \begin_layout Subsubsection
12776 \begin_inset LatexCommand \index{sfr}
12781 \begin_inset LatexCommand \index{\_\_sfr}
12785 (in/out to 8-bit addresses)
12788 \begin_layout Standard
12790 \begin_inset LatexCommand \index{Z80}
12794 family has separate address spaces for memory and
12804 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12809 \begin_inset LatexCommand \index{Z80!I/O memory}
12814 \begin_inset LatexCommand \index{Z180!I/O memory}
12818 is accessed with special instructions, e.g.:
12821 \begin_layout Verse
12824 sfr at 0x78 IoPort;\InsetSpace ~
12826 /* define a var in I/O space at 78h called IoPort */
12830 \begin_layout Standard
12831 Writing 0x01 to this variable generates the assembly code:
12834 \begin_layout Verse
12854 \begin_layout Subsubsection
12856 \begin_inset LatexCommand \index{sfr}
12861 \begin_inset LatexCommand \index{\_\_sfr}
12865 (in/out to 16-bit addresses)
12868 \begin_layout Standard
12873 is used to support 16 bit addresses in I/O memory e.g.:
12876 \begin_layout Verse
12880 \begin_inset LatexCommand \index{at}
12885 \begin_inset LatexCommand \index{\_\_at}
12892 \begin_layout Standard
12893 Writing 0x01 to this variable generates the assembly code:
12896 \begin_layout Verse
12899 01 23 01\InsetSpace ~
12921 \begin_layout Subsubsection
12923 \begin_inset LatexCommand \index{sfr}
12928 \begin_inset LatexCommand \index{\_\_sfr}
12932 (in0/out0 to 8 bit addresses on Z180
12933 \begin_inset LatexCommand \index{Z180}
12938 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12945 \begin_layout Standard
12946 The compiler option -
12950 \begin_layout Standard
12960 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12964 =180 (80) and a compiler #pragma\InsetSpace ~
12966 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12970 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12980 If you include the file z180.h this will be set automatically.
12981 \begin_inset VSpace bigskip
12987 \begin_layout Subsection
12989 \begin_inset LatexCommand \index{HC08!Storage class}
12993 Language Extensions
12996 \begin_layout Subsubsection
12998 \begin_inset LatexCommand \index{data (hc08 storage class)}
13003 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13010 \begin_layout Standard
13011 The data storage class declares a variable that resides in the first 256
13012 bytes of memory (the direct page).
13014 \begin_inset LatexCommand \index{HC08}
13018 is most efficient at accessing variables (especially pointers) stored here.
13021 \begin_layout Subsubsection
13023 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13028 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13035 \begin_layout Standard
13036 The xdata storage class declares a variable that can reside anywhere in
13038 This is the default if no storage class is specified.
13040 \begin_inset VSpace bigskip
13046 \begin_layout Section
13047 Absolute Addressing
13048 \begin_inset LatexCommand \index{Absolute addressing}
13055 \begin_layout Standard
13056 Data items can be assigned an absolute address with the
13059 \begin_inset LatexCommand \index{at}
13064 \begin_inset LatexCommand \index{\_\_at}
13070 keyword, in addition to a storage class, e.g.:
13073 \begin_layout Verse
13077 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13082 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13087 \begin_inset LatexCommand \index{at}
13092 \begin_inset LatexCommand \index{\_\_at}
13096 0x7ffe unsigned int chksum;
13099 \begin_layout Standard
13100 or, better conforming to ISO/IEC 9899 C:
13103 \begin_layout Verse
13106 __xdata __at (0x7ffe) unsigned int chksum;
13109 \begin_layout Standard
13110 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13111 of the external ram.
13116 reserve any space for variables declared in this way
13117 \begin_inset Marginal
13120 \begin_layout Standard
13129 (they are implemented with an equate in the assembler).
13130 Thus it is left to the programmer to make sure there are no overlaps with
13131 other variables that are declared without the absolute address.
13132 The assembler listing file (.lst
13133 \begin_inset LatexCommand \index{<file>.lst}
13137 ) and the linker output files (.rst
13138 \begin_inset LatexCommand \index{<file>.rst}
13143 \begin_inset LatexCommand \index{<file>.map}
13147 ) are good places to look for such overlaps.
13150 \begin_layout Standard
13151 If however you provide an initializer
13152 \begin_inset LatexCommand \index{Variable initialization}
13156 actual memory allocation will take place and overlaps will be detected
13161 \begin_layout Verse
13164 __code __at (0x7ff0) char Id[5] =
13165 \begin_inset Quotes sld
13169 \begin_inset Quotes srd
13175 \begin_layout Standard
13176 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13180 \begin_layout Standard
13181 In case of memory mapped I/O devices the keyword
13185 has to be used to tell the compiler that accesses might not be removed:
13188 \begin_layout Verse
13192 \begin_inset LatexCommand \index{volatile}
13197 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13202 \begin_inset LatexCommand \index{at}
13206 (0x8000) unsigned char PORTA_8255;
13209 \begin_layout Standard
13210 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13215 \begin_inset LatexCommand \index{Aligned array}
13222 starts at a block (256 byte) boundary
13223 \begin_inset LatexCommand \index{block boundary}
13228 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13234 Absolute addresses can be specified for variables in all
13235 storage classes, e.g.:
13238 \begin_layout Verse
13242 \begin_inset LatexCommand \index{bit}
13247 \begin_inset LatexCommand \index{at}
13254 \begin_layout Standard
13255 The above example will allocate the variable at offset 0x02 in the bit-addressab
13257 There is no real advantage to assigning absolute addresses to variables
13258 in this manner, unless you want strict control over all the variables allocated.
13259 One possible use would be to write hardware portable code.
13260 For example, if you have a routine that uses one or more of the microcontroller
13261 I/O pins, and such pins are different for two different hardwares, you
13262 can declare the I/O pins in your routine using:
13265 \begin_layout Verse
13269 \begin_inset LatexCommand \index{volatile}
13273 __bit MOSI;\InsetSpace ~
13277 /* master out, slave in */
13279 extern volatile __bit MISO;\InsetSpace ~
13286 extern volatile __bit MCLK;\InsetSpace ~
13295 Output of a byte on a 3-wire serial bus.
13300 If needed adapt polarity of clock,
13301 polarity of data and bit order
13306 unsigned char spi_io(unsigned char out_byte)
13331 MOSI = out_byte & 0x80;
13362 /* _asm nop _endasm; */\InsetSpace ~
13370 /* for slow peripherals */
13422 \begin_layout Standard
13423 Then, someplace in the code for the first hardware you would use
13426 \begin_layout Verse
13430 \begin_inset LatexCommand \index{at}
13435 \begin_inset LatexCommand \index{\_\_at}
13439 (0x80) MOSI;\InsetSpace ~
13443 /* I/O port 0, bit 0 */
13445 __bit __at (0x81) MISO;\InsetSpace ~
13452 __bit __at (0x82) MCLK;\InsetSpace ~
13456 /* I/O port 0, bit 2 */
13459 \begin_layout Standard
13460 Similarly, for the second hardware you would use
13463 \begin_layout Verse
13466 __bit __at (0x83) MOSI;\InsetSpace ~
13470 /* I/O port 0, bit 3 */
13472 __bit __at (0x91) MISO;\InsetSpace ~
13477 I/O port 1, bit 1 */
13480 \begin_inset LatexCommand \index{bit}
13484 __at (0x92) MCLK;\InsetSpace ~
13488 /* I/O port 1, bit 2 */
13491 \begin_layout Standard
13492 and you can use the same hardware dependent routine without changes, as
13493 for example in a library.
13494 This is somehow similar to sbit, but only one absolute address has to be
13495 specified in the whole project.
13496 \begin_inset VSpace bigskip
13502 \begin_layout Section
13504 \begin_inset LatexCommand \index{Parameters}
13509 \begin_inset LatexCommand \index{function parameter}
13514 \begin_inset LatexCommand \index{local variables}
13519 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13526 \begin_layout Standard
13527 Automatic (local) variables and parameters to functions can either be placed
13528 on the stack or in data-space.
13529 The default action of the compiler is to place these variables in the internal
13530 RAM (for small model) or external RAM (for medium or large model).
13531 This in fact makes them similar to
13534 \begin_inset LatexCommand \index{static}
13540 so by default functions are non-reentrant
13541 \begin_inset LatexCommand \index{reentrant}
13550 They can be placed on the stack
13551 \begin_inset LatexCommand \index{stack}
13561 \begin_layout Standard
13571 \begin_inset LatexCommand \index{-\/-stack-auto}
13579 #pragma\InsetSpace ~
13583 \begin_inset LatexCommand \index{\#pragma stackauto}
13590 \begin_inset LatexCommand \index{reentrant}
13596 keyword in the function declaration, e.g.:
13599 \begin_layout Verse
13602 unsigned char foo(char i) __reentrant
13616 \begin_layout Standard
13617 Since stack space on 8051 is limited, the
13627 \begin_layout Standard
13638 option should be used sparingly.
13639 Note that the reentrant keyword just means that the parameters & local
13640 variables will be allocated to the stack, it
13644 mean that the function is register bank
13645 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13654 \begin_inset LatexCommand \index{local variables}
13658 can be assigned storage classes and absolute
13659 \begin_inset LatexCommand \index{Absolute addressing}
13666 \begin_layout Verse
13669 unsigned char foo()
13677 __xdata unsigned char i;
13690 \begin_inset LatexCommand \index{at}
13694 (0x31) unsigned char j;
13706 \begin_layout Standard
13707 In the above example the variable
13711 will be allocated in the external ram,
13715 in bit addressable space and
13726 \begin_layout Standard
13737 or when a function is declared as
13741 this should only be done for static variables.
13744 \begin_layout Standard
13746 \begin_inset LatexCommand \index{function parameter}
13750 however are not allowed any storage class
13751 \begin_inset LatexCommand \index{Storage class}
13755 , (storage classes for parameters will be ignored), their allocation is
13756 governed by the memory model in use, and the reentrancy options.
13759 \begin_layout Standard
13760 It is however allowed to use bit parameters in reentrant functions and also
13761 non-static local bit variables are supported.
13762 Efficient use is limited to 8 semi-bitregisters in bit space.
13763 They are pushed and popped to stack
13764 \begin_inset LatexCommand \index{stack}
13768 as a single byte just like the normal registers.
13771 \begin_layout Section
13773 \begin_inset LatexCommand \label{sub:Overlaying}
13778 \begin_inset LatexCommand \index{Overlaying}
13785 \begin_layout Standard
13787 \begin_inset LatexCommand \index{reentrant}
13791 functions SDCC will try to reduce internal ram space usage by overlaying
13792 parameters and local variables of a function (if possible).
13793 Parameters and local variables
13794 \begin_inset LatexCommand \index{local variables}
13798 of a function will be allocated to an overlayable segment if the function
13801 no other function calls and the function is non-reentrant and the memory
13803 \begin_inset LatexCommand \index{Memory model}
13810 If an explicit storage class
13811 \begin_inset LatexCommand \index{Storage class}
13815 is specified for a local variable, it will NOT be overlayed.
13818 \begin_layout Standard
13819 Note that the compiler (not the linkage editor) makes the decision for overlayin
13821 Functions that are called from an interrupt service routine
13822 \begin_inset Marginal
13825 \begin_layout Standard
13833 should be preceded by a #pragma\InsetSpace ~
13835 \begin_inset LatexCommand \index{\#pragma nooverlay}
13839 if they are not reentrant.
13842 \begin_layout Standard
13843 Also note that the compiler does not do any processing of inline assembler
13844 code, so the compiler might incorrectly assign local variables and parameters
13845 of a function into the overlay segment if the inline assembler code calls
13846 other c-functions that might use the overlay.
13847 In that case the #pragma\InsetSpace ~
13848 nooverlay should be used.
13851 \begin_layout Standard
13852 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13854 \begin_inset LatexCommand \index{Multiplication}
13859 \begin_inset LatexCommand \index{Division}
13863 will NOT be overlayed since these are implemented using external functions,
13867 \begin_layout Verse
13873 \begin_inset LatexCommand \index{\#pragma nooverlay}
13879 void set_error(unsigned char errcd)
13896 some_isr () __interrupt
13897 \begin_inset LatexCommand \index{interrupt}
13927 \begin_layout Standard
13928 In the above example the parameter
13936 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13938 not present, this could cause unpredictable runtime behavior when called
13939 from an interrupt service routine.
13940 The #pragma\InsetSpace ~
13941 nooverlay ensures that the parameters and local variables for
13942 the function are NOT overlayed.
13943 \begin_inset VSpace bigskip
13949 \begin_layout Section
13950 Interrupt Service Routines
13951 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13958 \begin_layout Subsection
13959 General Information
13962 \begin_layout Standard
13975 outines to be coded in C, with some extended keywords.
13978 \begin_layout Verse
13981 void timer_isr (void) __interrupt (1) __using (1)
13995 \begin_layout Standard
13996 The optional number following the
13999 \begin_inset LatexCommand \index{interrupt}
14004 \begin_inset LatexCommand \index{\_\_interrupt}
14010 keyword is the interrupt number this routine will service.
14011 When present, the compiler will insert a call to this routine in the interrupt
14013 \begin_inset LatexCommand \index{interrupt vector table}
14017 for the interrupt number specified.
14018 If you have multiple source files in your project, interrupt service routines
14019 can be present in any of them, but a prototype of the isr MUST be present
14020 or included in the file that contains the function
14025 The optional (8051 specific) keyword
14028 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14033 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14039 can be used to tell the compiler to use the specified register bank when
14040 generating code for this function.
14043 Interrupt service routines open the door for some very interesting bugs:
14046 \begin_layout Subsubsection
14047 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14051 Common interrupt pitfall: variable not declared
14056 \begin_layout Standard
14057 If an interrupt service routine changes variables which are accessed by
14058 other functions these variables have to be declared
14063 \begin_inset LatexCommand \index{volatile}
14069 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14076 \begin_layout Subsubsection
14077 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14081 Common interrupt pitfall:
14086 \begin_layout Standard
14087 If the access to these variables is not
14090 \begin_inset LatexCommand \index{atomic}
14097 the processor needs more than one instruction for the access and could
14098 be interrupted while accessing the variable) the interrupt must be disabled
14099 during the access to avoid inconsistent data.
14102 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14103 and should be protected by disabling interrupts.
14104 You're not automatically on the safe side if you use 8 bit variables though.
14105 We need an example here: f.e.
14106 on the 8051 the harmless looking
14107 \begin_inset Quotes srd
14117 \begin_inset Quotes sld
14126 \begin_inset Quotes srd
14136 \begin_inset Quotes sld
14139 from within an interrupt routine might get lost if the interrupt occurs
14142 \begin_inset Quotes sld
14147 counter\InsetSpace ~
14152 \begin_inset Quotes srd
14155 is not atomic on the 8051 even if
14159 is located in data memory.
14161 Bugs like these are hard to reproduce and can
14162 cause a lot of trouble.
14166 \begin_layout Subsubsection
14167 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14171 Common interrupt pitfall:
14176 \begin_layout Standard
14177 The return address and the registers used in the interrupt service routine
14178 are saved on the stack
14179 \begin_inset LatexCommand \index{stack}
14183 so there must be sufficient stack space.
14184 If there isn't variables or registers (or even the return address itself)
14191 \begin_inset LatexCommand \index{stack overflow}
14195 is most likely to happen if the interrupt occurs during the
14196 \begin_inset Quotes sld
14200 \begin_inset Quotes srd
14203 subroutine when the stack is already in use for f.e.
14204 many return addresses.
14207 \begin_layout Subsubsection
14208 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14212 Common interrupt pitfall:
14214 use of non-reentrant functions
14217 \begin_layout Standard
14218 A special note here, int (16 bit) and long (32 bit) integer division
14219 \begin_inset LatexCommand \index{Division}
14224 \begin_inset LatexCommand \index{Multiplication}
14229 \begin_inset LatexCommand \index{Modulus}
14234 \begin_inset LatexCommand \index{Floating point support}
14238 operations are implemented using external support routines.
14239 If an interrupt service routine needs to do any of these operations then
14240 the support routines (as mentioned in a following section) will have to
14241 be recompiled using the
14247 \begin_layout Standard
14257 \begin_inset LatexCommand \index{-\/-stack-auto}
14263 option and the source file will need to be compiled using the
14269 \begin_layout Standard
14281 \begin_inset LatexCommand \index{-\/-int-long-reent}
14288 Note, the type promotion
14289 \begin_inset LatexCommand \index{type promotion}
14293 required by ANSI C can cause 16 bit routines to be used
14294 \begin_inset Marginal
14297 \begin_layout Standard
14306 without the programmer being aware of it.
14310 (unsigned char)(tail-1)
14312 within the if clause in section
14313 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14320 \begin_layout Standard
14321 Calling other functions from an interrupt service routine is not recommended,
14322 avoid it if possible.
14323 Note that when some function is called from an interrupt service routine
14324 it should be preceded by a #pragma\InsetSpace ~
14326 \begin_inset LatexCommand \index{\#pragma nooverlay}
14330 if it is not reentrant.
14331 Furthermore nonreentrant functions should not be called from the main program
14332 while the interrupt service routine might be active.
14333 They also must not be called from low priority interrupt service routines
14334 while a high priority interrupt service routine might be active.
14335 You could use semaphores or make the function
14339 if all parameters are passed in registers.
14342 \begin_inset LatexCommand \ref{sub:Overlaying}
14347 about Overlaying and section
14348 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14353 about Functions using private register banks.
14354 \begin_inset VSpace bigskip
14360 \begin_layout Subsection
14361 MCS51/DS390 Interrupt Service Routines
14364 \begin_layout Standard
14366 \begin_inset LatexCommand \index{interrupt}
14370 numbers and the corresponding address & descriptions for the Standard 8051/8052
14372 SDCC will automatically adjust the
14373 \begin_inset LatexCommand \index{interrupt vector table}
14377 to the maximum interrupt number specified.
14382 \begin_layout Standard
14384 \begin_inset Tabular
14385 <lyxtabular version="3" rows="9" columns="3">
14387 <column alignment="center" valignment="top" leftline="true" width="0in">
14388 <column alignment="left" valignment="top" leftline="true" width="0in">
14389 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14390 <row topline="true" bottomline="true">
14391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14394 \begin_layout Standard
14400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14403 \begin_layout Standard
14409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14412 \begin_layout Standard
14419 <row topline="true">
14420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14423 \begin_layout Standard
14429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14432 \begin_layout Standard
14438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14441 \begin_layout Standard
14448 <row topline="true">
14449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14452 \begin_layout Standard
14458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14461 \begin_layout Standard
14467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14470 \begin_layout Standard
14477 <row topline="true">
14478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14481 \begin_layout Standard
14487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14490 \begin_layout Standard
14496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14499 \begin_layout Standard
14506 <row topline="true">
14507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14510 \begin_layout Standard
14516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14519 \begin_layout Standard
14525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14528 \begin_layout Standard
14535 <row topline="true">
14536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14539 \begin_layout Standard
14545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14548 \begin_layout Standard
14554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14557 \begin_layout Standard
14564 <row topline="true">
14565 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14568 \begin_layout Standard
14574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14577 \begin_layout Standard
14583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14586 \begin_layout Standard
14593 <row topline="true">
14594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14597 \begin_layout Standard
14603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14606 \begin_layout Standard
14612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14615 \begin_layout Standard
14622 <row topline="true" bottomline="true">
14623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14626 \begin_layout Standard
14632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14635 \begin_layout Standard
14641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14644 \begin_layout Standard
14660 \begin_layout Standard
14661 If the interrupt service routine is defined without
14664 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14669 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14675 a register bank or with register bank 0 (
14679 0), the compiler will save the registers used by itself on the stack upon
14680 entry and restore them at exit, however if such an interrupt service routine
14681 calls another function then the entire register bank will be saved on the
14683 This scheme may be advantageous for small interrupt service routines which
14684 have low register usage.
14687 \begin_layout Standard
14688 If the interrupt service routine is defined to be using a specific register
14693 & psw are saved and restored, if such an interrupt service routine calls
14694 another function (using another register bank) then the entire register
14695 bank of the called function will be saved on the stack
14696 \begin_inset LatexCommand \index{stack}
14701 This scheme is recommended for larger interrupt service routines.
14702 \begin_inset VSpace bigskip
14708 \begin_layout Subsection
14710 \begin_inset LatexCommand \index{HC08}
14714 Interrupt Service Routines
14717 \begin_layout Standard
14718 Since the number of interrupts
14719 \begin_inset LatexCommand \index{HC08!interrupt}
14723 available is chip specific and the interrupt vector table always ends at
14724 the last byte of memory, the interrupt numbers corresponds to the interrupt
14725 vectors in reverse order of address.
14726 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14727 2 will use the interrupt vector at 0xfffa, and so on.
14728 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14729 this way; instead see section
14730 \begin_inset LatexCommand \ref{sub:Startup-Code}
14734 for details on customizing startup.
14735 \begin_inset VSpace bigskip
14741 \begin_layout Subsection
14742 Z80 Interrupt Service Routines
14745 \begin_layout Standard
14747 \begin_inset LatexCommand \index{Z80}
14751 uses several different methods for determining the correct interrupt
14752 \begin_inset LatexCommand \index{Z80!interrupt}
14756 vector depending on the hardware implementation.
14757 Therefore, SDCC ignores the optional interrupt number and does not attempt
14758 to generate an interrupt vector table.
14761 \begin_layout Standard
14762 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14763 instruction to return from the interrupt.
14764 To write an interrupt handler for the non-maskable interrupt, which needs
14765 a RETN instruction instead, add the
14772 \begin_layout Verse
14775 void nmi_isr (void) critical interrupt
14789 \begin_layout Standard
14790 However if you need to create a non-interruptable interrupt service routine
14791 you would also require the
14796 To distinguish between this and an nmi_isr you must provide an interrupt
14798 \begin_inset VSpace bigskip
14804 \begin_layout Section
14805 Enabling and Disabling Interrupts
14808 \begin_layout Subsection
14809 Critical Functions and Critical Statements
14812 \begin_layout Standard
14813 A special keyword may be associated with a block or a function declaring
14819 SDCC will generate code to disable all interrupts
14820 \begin_inset LatexCommand \index{interrupt}
14824 upon entry to a critical function and restore the interrupt enable to the
14825 previous state before returning.
14826 Nesting critical functions will need one additional byte on the stack
14827 \begin_inset LatexCommand \index{stack}
14834 \begin_layout Verse
14837 int foo () __critical
14838 \begin_inset LatexCommand \index{critical}
14843 \begin_inset LatexCommand \index{\_\_critical}
14868 \begin_layout Standard
14869 The critical attribute maybe used with other attributes like
14879 may also be used to disable interrupts more locally:
14882 \begin_layout Verse
14888 \begin_layout Standard
14889 More than one statement could have been included in the block.
14892 \begin_layout Subsection
14893 Enabling and Disabling Interrupts directly
14896 \begin_layout Standard
14898 \begin_inset LatexCommand \index{interrupt}
14902 can also be disabled and enabled directly (8051):
14905 \begin_layout Verse
14908 EA = 0;\InsetSpace ~
14934 \begin_layout Verse
14970 \begin_layout Verse
14973 EA = 1;\InsetSpace ~
15002 \begin_layout Verse
15041 \begin_layout Standard
15042 On other architectures which have seperate opcodes for enabling and disabling
15043 interrupts you might want to make use of defines with inline assembly
15044 \begin_inset LatexCommand \index{Assembler routines}
15049 \begin_inset LatexCommand \index{HC08!interrupt}
15056 \begin_layout Verse
15060 \begin_inset LatexCommand \index{\_asm}
15069 \begin_inset LatexCommand \index{\_endasm}
15076 \begin_layout Verse
15079 #define SEI _asm\InsetSpace ~
15086 \begin_layout Verse
15092 \begin_layout Standard
15093 Note: it is sometimes sufficient to disable only a specific interrupt source
15095 a timer or serial interrupt by manipulating an
15098 \begin_inset LatexCommand \index{interrupt mask}
15108 \begin_layout Standard
15109 Usually the time during which interrupts are disabled should be kept as
15111 This minimizes both
15116 \begin_inset LatexCommand \index{interrupt latency}
15120 (the time between the occurrence of the interrupt and the execution of
15121 the first code in the interrupt routine) and
15126 \begin_inset LatexCommand \index{interrupt jitter}
15130 (the difference between the shortest and the longest interrupt latency).
15131 These really are something different, f.e.
15132 a serial interrupt has to be served before its buffer overruns so it cares
15133 for the maximum interrupt latency, whereas it does not care about jitter.
15134 On a loudspeaker driven via a digital to analog converter which is fed
15135 by an interrupt a latency of a few milliseconds might be tolerable, whereas
15136 a much smaller jitter will be very audible.
15139 \begin_layout Standard
15140 You can reenable interrupts within an interrupt routine and on some architecture
15141 s you can make use of two (or more) levels of
15143 interrupt priorities
15146 \begin_inset LatexCommand \index{interrupt priority}
15151 On some architectures which don't support interrupt priorities these can
15152 be implemented by manipulating the interrupt mask and reenabling interrupts
15153 within the interrupt routine.
15154 Check there is sufficient space on the stack
15155 \begin_inset LatexCommand \index{stack}
15159 and don't add complexity unless you have to.
15163 \begin_layout Subsection
15165 \begin_inset LatexCommand \index{semaphore}
15169 locking (mcs51/ds390)
15172 \begin_layout Standard
15173 Some architectures (mcs51/ds390) have an atomic
15174 \begin_inset LatexCommand \index{atomic}
15187 These type of instructions are typically used in preemptive multitasking
15188 systems, where a routine f.e.
15189 claims the use of a data structure ('acquires a lock
15190 \begin_inset LatexCommand \index{lock}
15194 on it'), makes some modifications and then releases the lock when the data
15195 structure is consistent again.
15196 The instruction may also be used if interrupt and non-interrupt code have
15197 to compete for a resource.
15198 With the atomic bit test and clear instruction interrupts
15199 \begin_inset LatexCommand \index{interrupt}
15203 don't have to be disabled for the locking operation.
15207 \begin_layout Standard
15208 SDCC generates this instruction if the source follows this pattern:
15211 \begin_layout Verse
15215 \begin_inset LatexCommand \index{volatile}
15219 bit resource_is_free;
15223 if (resource_is_free)
15233 resource_is_free=0;
15246 resource_is_free=1;
15253 \begin_layout Standard
15254 Note, mcs51 and ds390 support only an atomic
15255 \begin_inset LatexCommand \index{atomic}
15263 instruction (as opposed to atomic bit test and
15268 \begin_layout Section
15269 Functions using private register banks
15270 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15277 \begin_layout Standard
15278 Some architectures have support for quickly changing register sets.
15279 SDCC supports this feature with the
15282 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15287 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15293 attribute (which tells the compiler to use a register bank
15294 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15298 other than the default bank zero).
15299 It should only be applied to
15302 \begin_inset LatexCommand \index{interrupt}
15308 functions (see footnote below).
15309 This will in most circumstances make the generated ISR code more efficient
15310 since it will not have to save registers on the stack.
15313 \begin_layout Standard
15318 attribute will have no effect on the generated code for a
15322 function (but may occasionally be useful anyway
15326 \begin_layout Standard
15327 possible exception: if a function is called ONLY from 'interrupt' functions
15328 using a particular bank, it can be declared with the same 'using' attribute
15329 as the calling 'interrupt' functions.
15330 For instance, if you have several ISRs using bank one, and all of them
15331 call memcpy(), it might make sense to create a specialized version of memcpy()
15332 'using 1', since this would prevent the ISR from having to save bank zero
15333 to the stack on entry and switch to bank zero before calling the function
15342 (pending: Note, nowadays the
15346 attribute has an effect on
15350 the generated code for a
15361 \begin_layout Standard
15366 function using a non-zero bank will assume that it can trash that register
15367 bank, and will not save it.
15368 Since high-priority interrupts
15369 \begin_inset LatexCommand \index{interrupts}
15374 \begin_inset LatexCommand \index{interrupt priority}
15378 can interrupt low-priority ones on the 8051 and friends, this means that
15379 if a high-priority ISR
15383 a particular bank occurs while processing a low-priority ISR
15387 the same bank, terrible and bad things can happen.
15388 To prevent this, no single register bank should be
15392 by both a high priority and a low priority ISR.
15393 This is probably most easily done by having all high priority ISRs use
15394 one bank and all low priority ISRs use another.
15395 If you have an ISR which can change priority at runtime, you're on your
15396 own: I suggest using the default bank zero and taking the small performance
15400 \begin_layout Standard
15401 It is most efficient if your ISR calls no other functions.
15402 If your ISR must call other functions, it is most efficient if those functions
15403 use the same bank as the ISR (see note 1 below); the next best is if the
15404 called functions use bank zero.
15405 It is very inefficient to call a function using a different, non-zero bank
15408 \begin_inset VSpace bigskip
15414 \begin_layout Section
15416 \begin_inset LatexCommand \label{sub:Startup-Code}
15421 \begin_inset LatexCommand \index{Startup code}
15428 \begin_layout Subsection
15429 MCS51/DS390 Startup Code
15432 \begin_layout Standard
15433 The compiler triggers the linker to link certain initialization modules
15434 from the runtime library
15435 \begin_inset LatexCommand \index{Runtime library}
15439 called crt<something>.
15440 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15441 GSINIT5) is not linked unless the -
15447 \begin_layout Standard
15458 -xstack option is used.
15459 These modules are highly entangled by the use of special segments/areas,
15460 but a common layout is shown below:
15463 \begin_layout Verse
15471 \begin_layout Verse
15495 ljmp __sdcc_gsinit_startup
15498 \begin_layout Verse
15506 \begin_layout Verse
15518 .area GSINIT0 (CODE)
15520 __sdcc_gsinit_startup::
15530 mov sp,#__start__stack - 1
15533 \begin_layout Verse
15541 \begin_layout Verse
15553 .area GSINIT1 (CODE)
15555 __sdcc_init_xstack::
15557 ; Need to initialize in GSINIT1 in
15558 case the user's __sdcc_external_startup uses the xstack.
15568 mov __XPAGE,#(__start__x
15579 mov _spx,#__start__xstack
15582 \begin_layout Verse
15590 \begin_layout Verse
15602 .area GSINIT2 (CODE)
15612 lcall __sdcc_external_startup
15632 jz __sdcc_init_data
15643 __sdcc_program_startup
15648 \begin_layout Verse
15656 \begin_layout Verse
15668 .area GSINIT3 (CODE)
15721 mov r2,#((l_XINIT+255) >> 8)
15752 __XPAGE,#(s_XISEG >> 8)
15754 00001$:\InsetSpace ~
15818 00002$:\InsetSpace ~
15845 \begin_layout Verse
15853 \begin_layout Verse
15865 .area GSINIT4 (CODE)
15867 __mcs51_genRAMCLEAR::
15889 00004$:\InsetSpace ~
15903 ; _mcs51_genRAMCLEAR() end
15906 \begin_layout Verse
15914 \begin_layout Verse
15926 .area GSINIT4 (CODE)
15928 __mcs51_genXRAMCLEAR::
15989 mov __XPAGE,#(s_PSEG >> 8)
16001 00005$:\InsetSpace ~
16076 mov r1,#((l_XSEG + 255) >> 8)
16098 00007$:\InsetSpace ~
16135 \begin_layout Verse
16143 \begin_layout Verse
16155 .area GSINIT5 (CODE)
16157 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16160 ; and __mcs51_genRAMCLEAR modifies _spx.
16170 mov __XPAGE,#(__start__x
16181 mov _spx,#__start__xstack
16184 \begin_layout Verse
16189 (application modules)
16192 \begin_layout Verse
16204 .area GSINIT (CODE)
16207 \begin_layout Verse
16215 \begin_layout Verse
16227 .area GSFINAL (CODE)
16237 ljmp __sdcc_program_startup
16239 ;---------------------------------
16240 -----------------------
16244 ;--------------------------------------------------
16267 __sdcc_program_startup:
16280 return from main will lock up
16293 \begin_layout Standard
16294 One of these modules (crtstart.asm) contains a call to the C routine
16296 _sdcc_external_startup()
16297 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16306 at the start of the CODE area.
16307 This routine is also in the runtime library
16308 \begin_inset LatexCommand \index{Runtime library}
16312 and returns 0 by default.
16313 If this routine returns a non-zero value, the static & global variable
16314 initialization will be skipped and the function main will be invoked.
16315 Otherwise static & global variables will be initialized before the function
16319 _sdcc_external_startup()
16321 routine to your program to override the default if you need to setup hardware
16322 or perform some other critical operation prior to static & global variable
16324 \begin_inset LatexCommand \index{Variable initialization}
16329 On some mcs51 variants xdata
16330 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16334 memory has to be explicitly enabled before it can be accessed or if the
16336 \begin_inset LatexCommand \index{watchdog}
16340 needs to be disabled, this is the place to do it.
16341 The startup code clears all internal data memory, 256 bytes by default,
16342 but from 0 to n-1 if
16348 \begin_layout Standard
16358 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16365 (recommended for Chipcon CC1010).
16368 \begin_layout Standard
16369 See also the compiler options
16375 \begin_layout Standard
16391 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16401 \begin_layout Standard
16413 \begin_inset LatexCommand \index{-\/-main-return}
16418 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16422 about MCS51-variants.
16427 \begin_layout Standard
16428 While these initialization modules are meant as generic startup code there
16429 might be the need for customization.
16430 Let's assume the return value of
16432 _sdcc_external_startup()
16438 should not be checked (or
16440 _sdcc_external_startup()
16442 should not be called at all).
16443 The recommended way would be to copy
16449 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16453 ) into the source directory, adapt it there, then assemble it with
16459 \begin_layout Standard
16460 \begin_inset Quotes sld
16464 \begin_inset Quotes srd
16467 are the assembler options used in
16468 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16479 and when linking your project explicitely specify
16484 As a bonus a listing of the relocated object file
16491 \begin_layout Standard
16492 \begin_inset VSpace bigskip
16498 \begin_layout Subsection
16502 \begin_layout Standard
16504 \begin_inset LatexCommand \index{HC08}
16508 startup code follows the same scheme as the MCS51 startup code.
16509 \begin_inset VSpace bigskip
16515 \begin_layout Subsection
16519 \begin_layout Standard
16521 \begin_inset LatexCommand \index{Z80}
16525 the startup code is inserted by linking with crt0.o which is generated from
16526 sdcc/device/lib/z80/crt0.s.
16527 If you need a different startup code you can use the compiler option
16536 \begin_layout Standard
16551 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16555 and provide your own crt0.o.
16557 \begin_inset VSpace bigskip
16563 \begin_layout Section
16564 Inline Assembler Code
16565 \begin_inset LatexCommand \index{Assembler routines}
16572 \begin_layout Subsection
16573 A Step by Step Introduction
16574 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16581 \begin_layout Standard
16582 Starting from a small snippet of c-code this example shows for the MCS51
16583 how to use inline assembly, access variables, a function parameter and
16584 an array in xdata memory.
16585 The example uses an MCS51 here but is easily adapted for other architectures.
16586 This is a buffer routine which should be optimized:
16589 \begin_layout Verse
16593 unsigned char __far
16594 \begin_inset LatexCommand \index{far (storage class)}
16599 \begin_inset LatexCommand \index{\_\_far (storage class)}
16604 \begin_inset LatexCommand \index{at}
16609 \begin_inset LatexCommand \index{\_\_at}
16613 (0x7f00) buf[0x100];
16614 \begin_inset LatexCommand \index{Aligned array}
16620 unsigned char head, tail;\InsetSpace ~
16638 \begin_inset LatexCommand \index{interrupt}
16690 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16702 void to_buffer( unsigned char c )
16710 if( head != (unsigned char)(tail-1)
16717 \begin_inset LatexCommand \index{promotion to signed int}
16722 \begin_inset LatexCommand \index{type promotion}
16727 \begin_inset Marginal
16730 \begin_layout Standard
16749 buf[ head++ ] = c;\InsetSpace ~
16765 /* access to a 256 byte aligned array */
16770 \begin_layout Standard
16771 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16772 then a corresponding buffer.asm file is generated.
16773 We define a new function
16777 in file buffer.c in which we cut and paste the generated code, removing
16778 unwanted comments and some ':'.
16780 \begin_inset Quotes sld
16788 \begin_inset Quotes srd
16792 \begin_inset Quotes sld
16800 \begin_inset Quotes srd
16807 \begin_layout Standard
16808 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16809 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16811 The latter is also used in the library functions.
16816 to the beginning and the end of the function body:
16819 \begin_layout Verse
16823 /* With a cut and paste from the .asm file, we have something to start with.
16829 function is not yet OK! (registers aren't saved) */
16831 void to_buffer_asm(
16841 \begin_inset LatexCommand \index{\_asm}
16846 \begin_inset LatexCommand \index{\_\_asm}
16860 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16866 \begin_inset LatexCommand \index{promotion to signed int}
16871 \begin_inset LatexCommand \index{type promotion}
16924 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16925 \begin_inset LatexCommand \index{Aligned array}
16991 \begin_inset LatexCommand \index{\_endasm}
16996 \begin_inset LatexCommand \index{\_\_endasm}
17005 \begin_layout Standard
17006 The new file buffer.c should compile with only one warning about the unreferenced
17007 function argument 'c'.
17008 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17009 (1) and finally have:
17012 \begin_layout Verse
17016 unsigned char __far __at(0x7f00) buf[0x100];
17018 unsigned char head, tail;
17029 void to_buffer( unsigned char c )
17038 head != (unsigned char)(tail-1) )
17067 c; // to avoid warning: unreferenced function argument
17074 \begin_inset LatexCommand \index{\_asm}
17079 \begin_inset LatexCommand \index{\_\_asm}
17093 ; save used registers here.
17104 ; If we were still using r2,r3 we would have to push them here.
17107 ; if( head != (unsigned char)(tail-1) )
17151 could do an ANL a,#0x0f here to use a smaller buffer (see below)
17187 a,dpl \InsetSpace ~
17194 ; dpl holds lower byte of function argument
17206 dpl,_head \InsetSpace ~
17209 ; buf is 0x100 byte aligned so head can be used directly
17252 ; we could do an ANL _head,#0x0f here to use a
17253 smaller buffer (see above)
17265 ; restore used registers here
17272 \begin_inset LatexCommand \index{\_endasm}
17277 \begin_inset LatexCommand \index{\_\_endasm}
17288 \begin_layout Standard
17289 The inline assembler code can contain any valid code understood by the assembler
17290 , this includes any assembler directives and comment lines.
17291 The assembler does not like some characters like ':' or ''' in comments.
17292 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17293 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17298 \begin_inset LatexCommand \index{Assembler documentation}
17303 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17311 \begin_layout Standard
17312 The compiler does not do any validation of the code within the
17315 \begin_inset LatexCommand \index{\_asm}
17320 \begin_inset LatexCommand \index{\_\_asm}
17328 \begin_inset LatexCommand \index{\_endasm}
17333 \begin_inset LatexCommand \index{\_\_endasm}
17342 Specifically it will not know which registers are used and thus register
17344 \begin_inset LatexCommand \index{push/pop}
17348 has to be done manually.
17352 \begin_layout Standard
17353 It is recommended that each assembly instruction (including labels) be placed
17354 in a separate line (as the example shows).
17359 \begin_layout Standard
17371 \begin_inset LatexCommand \index{-\/-peep-asm}
17377 command line option is used, the inline assembler code will be passed through
17378 the peephole optimizer
17379 \begin_inset LatexCommand \index{Peephole optimizer}
17384 There are only a few (if any) cases where this option makes sense, it might
17385 cause some unexpected changes in the inline assembler code.
17386 Please go through the peephole optimizer rules defined in file
17390 before using this option.
17393 \begin_layout Subsection
17395 \begin_inset LatexCommand \label{sub:Naked-Functions}
17400 \begin_inset LatexCommand \index{Naked functions}
17407 \begin_layout Standard
17408 A special keyword may be associated with a function declaring it as
17411 \begin_inset LatexCommand \index{\_naked}
17416 \begin_inset LatexCommand \index{\_\_naked}
17427 function modifier attribute prevents the compiler from generating prologue
17428 \begin_inset LatexCommand \index{function prologue}
17433 \begin_inset LatexCommand \index{function epilogue}
17437 code for that function.
17438 This means that the user is entirely responsible for such things as saving
17439 any registers that may need to be preserved, selecting the proper register
17440 bank, generating the
17444 instruction at the end, etc.
17445 Practically, this means that the contents of the function must be written
17446 in inline assembler.
17447 This is particularly useful for interrupt functions, which can have a large
17448 (and often unnecessary) prologue/epilogue.
17449 For example, compare the code generated by these two functions:
17452 \begin_layout Verse
17456 \begin_inset LatexCommand \index{volatile}
17460 data unsigned char counter;
17464 void simpleInterrupt(void) __interrupt
17465 \begin_inset LatexCommand \index{interrupt}
17470 \begin_inset LatexCommand \index{\_\_interrupt}
17488 void nakedInterrupt(void) __interrupt (2) __naked
17497 \begin_inset LatexCommand \index{\_asm}
17502 \begin_inset LatexCommand \index{\_\_asm}
17519 _counter ; does not change flags, no need to save psw
17532 include ret or reti in _naked function.
17539 \begin_inset LatexCommand \index{\_endasm}
17544 \begin_inset LatexCommand \index{\_\_endasm}
17553 \begin_layout Standard
17554 For an 8051 target, the generated simpleInterrupt looks like:
17557 \begin_layout Verse
17564 example, recent versions of SDCC generate
17570 code for simpleInterrupt() and nakedInterrupt()!
17711 \begin_layout Standard
17712 whereas nakedInterrupt looks like:
17715 \begin_layout Verse
17728 _counter ; does not change flags, no need to save psw
17747 MUST explicitly include ret or reti in _naked function
17750 \begin_layout Standard
17751 The related directive #pragma exclude
17752 \begin_inset LatexCommand \index{\#pragma exclude}
17756 allows a more fine grained control over pushing & popping
17757 \begin_inset LatexCommand \index{push/pop}
17764 \begin_layout Standard
17765 While there is nothing preventing you from writing C code inside a
17769 function, there are many ways to shoot yourself in the foot doing this,
17770 and it is recommended that you stick to inline assembler.
17773 \begin_layout Subsection
17774 Use of Labels within Inline Assembler
17777 \begin_layout Standard
17778 SDCC allows the use of in-line assembler with a few restrictions regarding
17780 All labels defined within inline assembler code have to be of the form
17785 where nnnnn is a number less than 100 (which implies a limit of utmost
17786 100 inline assembler labels
17797 \begin_layout Standard
17798 This is a slightly more stringent rule than absolutely necessary, but stays
17799 always on the safe side.
17800 Labels in the form of nnnnn$ are local labels in the assembler, locality
17801 of which is confined within two labels of the standard form.
17802 The compiler uses the same form for labels within a function (but starting
17803 from nnnnn=00100); and places always a standard label at the beginning
17804 of a function, thus limiting the locality of labels within the scope of
17806 So, if the inline assembler part would be embedded into C-code, an improperly
17807 placed non-local label in the assembler would break up the reference space
17808 for labels created by the compiler for the C-code, leading to an assembling
17812 \begin_layout Standard
17813 The numeric part of local labels does not need to have 5 digits (although
17814 this is the form of labels output by the compiler), any valid integer will
17816 Please refer to the assemblers documentation for further details.
17824 \begin_layout Verse
17828 \begin_inset LatexCommand \index{\_asm}
17833 \begin_inset LatexCommand \index{\_\_asm}
17863 \begin_inset LatexCommand \index{\_endasm}
17868 \begin_inset LatexCommand \index{\_\_endasm}
17875 \begin_layout Standard
17876 Inline assembler code cannot reference any C-labels, however it can reference
17878 \begin_inset LatexCommand \index{Labels}
17882 defined by the inline assembler, e.g.:
17885 \begin_layout Verse
17908 ; some assembler code
17929 /* some more c code */
17931 clabel:\InsetSpace ~
17933 /* inline assembler cannot reference this
17938 \begin_layout Standard
17943 is translated by the compiler into a local label, so the locality of labels
17944 within the function is not broken.
17961 0003$: ;label (can be referenced by inline assembler only)
17968 \begin_inset LatexCommand \index{\_endasm}
17973 \begin_inset LatexCommand \index{\_\_endasm}
17983 /* some more c code */
17988 \begin_layout Standard
17989 In other words inline assembly code can access labels defined in inline
17990 assembly within the scope of the function.
17991 The same goes the other way, i.e.
17992 labels defines in inline assembly can not be accessed by C statements.
17995 \begin_layout Section
17996 Interfacing with Assembler Code
17997 \begin_inset LatexCommand \index{Assembler routines}
18004 \begin_layout Subsection
18005 Global Registers used for Parameter Passing
18006 \begin_inset LatexCommand \index{Parameter passing}
18013 \begin_layout Standard
18014 The compiler always uses the global registers
18017 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18022 \begin_inset LatexCommand \index{DPTR}
18027 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18036 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18042 to pass the first (non-bit) parameter to a function, and also to pass the
18044 \begin_inset LatexCommand \index{return value}
18048 of function; according to the following scheme: one byte return value in
18053 , two byte value in
18062 three byte values (generic pointers) in
18074 , and four byte values in
18092 \begin_inset LatexCommand \index{generic pointer}
18096 contain type of accessed memory in
18117 \begin_inset Note Note
18120 \begin_layout Standard
18121 This might not be the case of certain memory models (medium???)
18129 \begin_layout Standard
18130 The second parameter onwards is either allocated on the stack (for reentrant
18135 \begin_layout Standard
18144 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18147 \begin_layout Standard
18148 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18149 space for reentrant functions or allocated directly in bit memory otherwise.
18152 \begin_layout Standard
18153 Functions (with two or more parameters or bit parameters) that are called
18154 through function pointers
18155 \begin_inset LatexCommand \index{function pointers}
18159 must therefor be reentrant so the compiler knows how to pass the parameters.
18162 \begin_layout Subsection
18166 \begin_layout Standard
18167 Unless the called function is declared as
18172 \begin_inset LatexCommand \index{naked}
18180 \begin_layout Standard
18190 \begin_inset LatexCommand \index{-\/-callee-saves}
18198 \begin_layout Standard
18207 -all-callee-saves command line option or the corresponding callee_saves
18208 pragma are used, the caller will save the registers (
18212 ) around the call, so the called function can destroy they content freely.
18215 \begin_layout Standard
18216 If the called function is not declared as
18220 , the caller will swap register banks around the call, if caller and callee
18221 use different register banks (having them defined by the
18229 \begin_layout Standard
18230 The called function can also use
18246 observing that they are used for parameter/return value passing.
18249 \begin_layout Subsection
18250 Assembler Routine (non-reentrant)
18253 \begin_layout Standard
18254 In the following example
18255 \begin_inset LatexCommand \index{reentrant}
18260 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18264 the function c_func calls an assembler routine asm_func, which takes two
18266 \begin_inset LatexCommand \index{function parameter}
18273 \begin_layout Verse
18276 extern int asm_func(unsigned char, unsigned char);
18280 int c_func (unsigned char
18281 i, unsigned char j)
18289 return asm_func(i,j);
18303 return c_func(10,9);
18308 \begin_layout Standard
18309 The corresponding assembler function is:
18312 \begin_layout Verse
18315 .globl _asm_func_PARM_2
18417 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18434 \begin_layout Standard
18435 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18436 the parameter number starting from 1, and counting from the left.
18437 The first parameter is passed in
18453 according to the description above.
18454 The variable name for the second parameter will be _<function_name>_PARM_2.
18459 ble the assembler routine with the following command:
18466 asx8051 -losg asmfunc.asm
18473 Then compile and link the assembler routine to the C source file with the
18481 sdcc cfunc.c asmfunc.rel
18484 \begin_layout Subsection
18485 Assembler Routine (reentrant)
18488 \begin_layout Standard
18490 \begin_inset LatexCommand \index{reentrant}
18495 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18499 the second parameter
18500 \begin_inset LatexCommand \index{function parameter}
18504 onwards will be passed on the stack, the parameters are pushed from right
18506 before the call the second leftmost parameter will be on the top of the
18507 stack (the leftmost parameter is passed in registers).
18508 Here is an example:
18511 \begin_layout Verse
18514 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18519 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18528 return asm_func(i,j,k);
18542 return c_func(10,9,8);
18547 \begin_layout Standard
18548 The corresponding (unoptimized) assembler routine is:
18551 \begin_layout Verse
18571 _bp,sp\InsetSpace ~
18577 ;stack contains: _bp, return
18578 address, second parameter, third parameter
18602 a,#0xfd\InsetSpace ~
18608 pointer to the second parameter
18632 a,#0xfc\InsetSpace ~
18638 to the rightmost parameter
18679 result (= sum of all three parameters)
18694 ;return value goes into dptr
18728 \begin_layout Standard
18729 The compiling and linking procedure remains the same, however note the extra
18730 entry & exit linkage required for the assembler code, _bp is the stack
18731 frame pointer and is used to compute the offset into the stack for parameters
18732 and local variables.
18733 \begin_inset VSpace bigskip
18739 \begin_layout Section
18741 \begin_inset LatexCommand \index{int (16 bit)}
18746 \begin_inset LatexCommand \index{long (32 bit)}
18753 \begin_layout Standard
18754 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18755 multiplication and modulus operations are implemented by support routines.
18756 These support routines are all developed in ANSI-C to facilitate porting
18757 to other MCUs, although some model specific assembler optimizations are
18759 The following files contain the described routines, all of them can be
18760 found in <installdir>/share/sdcc/lib.
18765 \begin_layout Standard
18767 \begin_inset Tabular
18768 <lyxtabular version="3" rows="11" columns="2">
18770 <column alignment="left" valignment="top" leftline="true" width="0">
18771 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18772 <row topline="true" bottomline="true">
18773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18776 \begin_layout Standard
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18787 \begin_layout Standard
18796 <row topline="true">
18797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18800 \begin_layout Standard
18806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18809 \begin_layout Standard
18810 16 bit multiplication
18816 <row topline="true">
18817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18820 \begin_layout Standard
18826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18829 \begin_layout Standard
18830 signed 16 bit division (calls _divuint)
18836 <row topline="true">
18837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18840 \begin_layout Standard
18846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18849 \begin_layout Standard
18850 unsigned 16 bit division
18856 <row topline="true">
18857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18860 \begin_layout Standard
18866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18869 \begin_layout Standard
18870 signed 16 bit modulus (calls _moduint)
18876 <row topline="true">
18877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18880 \begin_layout Standard
18886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18889 \begin_layout Standard
18890 unsigned 16 bit modulus
18896 <row topline="true">
18897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18900 \begin_layout Standard
18906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18909 \begin_layout Standard
18910 32 bit multiplication
18916 <row topline="true">
18917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18920 \begin_layout Standard
18926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18929 \begin_layout Standard
18930 signed 32 division (calls _divulong)
18936 <row topline="true">
18937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18940 \begin_layout Standard
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18949 \begin_layout Standard
18950 unsigned 32 division
18956 <row topline="true">
18957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18960 \begin_layout Standard
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18969 \begin_layout Standard
18970 signed 32 bit modulus (calls _modulong)
18976 <row topline="true" bottomline="true">
18977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18980 \begin_layout Standard
18986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18989 \begin_layout Standard
18990 unsigned 32 bit modulus
19005 \begin_layout Standard
19006 Since they are compiled as
19011 \begin_inset LatexCommand \index{reentrant}
19016 \begin_inset LatexCommand \index{interrupt}
19020 service routines should not do any of the above operations.
19021 If this is unavoidable then the above routines will need to be compiled
19028 \begin_layout Standard
19038 \begin_inset LatexCommand \index{-\/-stack-auto}
19044 option, after which the source program will have to be compiled with
19050 \begin_layout Standard
19060 \begin_inset LatexCommand \index{-\/-int-long-reent}
19067 Notice that you don't have to call these routines directly.
19068 The compiler will use them automatically every time an integer operation
19072 \begin_layout Section
19073 Floating Point Support
19074 \begin_inset LatexCommand \index{Floating point support}
19081 \begin_layout Standard
19082 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19083 The floating point support routines are derived from gcc's floatlib.c and
19084 consist of the following routines:
19089 \begin_layout Standard
19093 \begin_inset Tabular
19094 <lyxtabular version="3" rows="17" columns="2">
19096 <column alignment="left" valignment="top" leftline="true" width="0">
19097 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19098 <row topline="true" bottomline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19102 \begin_layout Standard
19117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19120 \begin_layout Standard
19127 <row topline="true">
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19131 \begin_layout Standard
19146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19149 \begin_layout Standard
19159 add floating point numbers
19165 <row topline="true">
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19169 \begin_layout Standard
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19187 \begin_layout Standard
19197 subtract floating point numbers
19203 <row topline="true">
19204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19207 \begin_layout Standard
19222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19225 \begin_layout Standard
19235 divide floating point numbers
19241 <row topline="true">
19242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19245 \begin_layout Standard
19260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19263 \begin_layout Standard
19273 multiply floating point numbers
19279 <row topline="true">
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19283 \begin_layout Standard
19298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19301 \begin_layout Standard
19311 convert floating point to unsigned char
19317 <row topline="true">
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19321 \begin_layout Standard
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19339 \begin_layout Standard
19349 convert floating point to signed char
19355 <row topline="true">
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19359 \begin_layout Standard
19374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19377 \begin_layout Standard
19387 convert floating point to unsigned int
19393 <row topline="true">
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19397 \begin_layout Standard
19412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19415 \begin_layout Standard
19425 convert floating point to signed int
19431 <row topline="true">
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19435 \begin_layout Standard
19458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19461 \begin_layout Standard
19471 convert floating point to unsigned long
19477 <row topline="true">
19478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_layout Standard
19496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19499 \begin_layout Standard
19509 convert floating point to signed long
19515 <row topline="true">
19516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_layout Standard
19534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_layout Standard
19547 convert unsigned char to floating point
19553 <row topline="true">
19554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19557 \begin_layout Standard
19572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19575 \begin_layout Standard
19585 convert char to floating point number
19591 <row topline="true">
19592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19595 \begin_layout Standard
19610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19613 \begin_layout Standard
19623 convert unsigned int to floating point
19629 <row topline="true">
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19633 \begin_layout Standard
19648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19651 \begin_layout Standard
19661 convert int to floating point numbers
19667 <row topline="true">
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19671 \begin_layout Standard
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19689 \begin_layout Standard
19699 convert unsigned long to floating point number
19705 <row topline="true" bottomline="true">
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19709 \begin_layout Standard
19724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19727 \begin_layout Standard
19737 convert long to floating point number
19752 \begin_layout Standard
19753 These support routines are developed in ANSI-C so there is room for space
19754 and speed improvement
19758 \begin_layout Standard
19759 These floating point routines (
19763 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19770 Note if all these routines are used simultaneously the data space might
19772 For serious floating point usage the large model might be needed.
19773 Also notice that you don't have to call this routines directly.
19774 The compiler will use them automatically every time a floating point operation
19776 \begin_inset VSpace bigskip
19782 \begin_layout Section
19784 \begin_inset LatexCommand \index{Libraries}
19791 \begin_layout Standard
19794 <pending: this is messy and incomplete - a little more information is in
19795 sdcc/doc/libdoc.txt
19800 \begin_layout Subsection
19801 Compiler support routines (_gptrget, _mulint etc.)
19804 \begin_layout Subsection
19805 Stdclib functions (puts, printf, strcat etc.)
19808 \begin_layout Subsubsection
19812 \begin_layout Paragraph
19813 getchar(), putchar()
19816 \begin_layout Standard
19817 \begin_inset LatexCommand \index{<stdio.h>}
19821 As usual on embedded systems you have to provide your own
19824 \begin_inset LatexCommand \index{getchar()}
19833 \begin_inset LatexCommand \index{putchar()}
19840 SDCC does not know whether the system connects to a serial line with or
19841 without handshake, LCD, keyboard or other device.
19855 You'll find examples for serial routines f.e.
19856 in sdcc/device/lib.
19857 For the mcs51 this minimalistic polling
19861 routine might be a start:
19864 \begin_layout Verse
19867 void putchar (char c) {
19873 while (!TI)\InsetSpace ~
19876 /* assumes UART is initialized */
19904 \begin_layout Paragraph
19908 \begin_layout Standard
19912 \begin_inset LatexCommand \index{printf()}
19922 does not support float (except on ds390).
19923 To enable this recompile it with the option
19929 \begin_layout Standard
19939 \begin_inset LatexCommand \index{USE\_FLOATS}
19945 on the command line.
19952 \begin_layout Standard
19962 \begin_inset LatexCommand \index{-\/-model-large}
19968 for the mcs51 port, since this uses a lot of memory.
19971 \begin_layout Standard
19972 If you're short on code memory you might want to use
19975 \begin_inset LatexCommand \index{printf\_small()}
19990 For the mcs51 there additionally are assembly versions
19993 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19999 (subset of printf using less than 270 bytes) and
20002 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20011 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20017 (floating-point aware version of printf_fast) which should fit the requirements
20018 of many embedded systems (printf_fast() can be customized by unsetting
20023 support long variables and field widths).
20024 Be sure to use only one of these printf options within a project.
20029 \begin_layout Standard
20030 Feature matrix of different
20037 \begin_layout Standard
20038 \begin_inset Tabular
20039 <lyxtabular version="3" rows="14" columns="7">
20040 <features islongtable="true">
20041 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20042 <column alignment="center" valignment="top" leftline="true" width="0">
20043 <column alignment="center" valignment="top" leftline="true" width="12col%">
20044 <column alignment="center" valignment="top" leftline="true" width="10col%">
20045 <column alignment="center" valignment="top" leftline="true" width="0">
20046 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20047 <column alignment="center" valignment="top" rightline="true" width="0">
20048 <row topline="true" bottomline="true" endhead="true">
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20052 \begin_layout Standard
20061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20064 \begin_layout Standard
20066 \begin_inset LatexCommand \index{printf}
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20078 \begin_layout Standard
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20098 \begin_layout Standard
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20107 \begin_layout Standard
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20116 \begin_layout Standard
20123 <row topline="true" endhead="true">
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20127 \begin_layout Standard
20133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20136 \begin_layout Standard
20144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20147 \begin_layout Standard
20155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20158 \begin_layout Standard
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20169 \begin_layout Standard
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20180 \begin_layout Standard
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20191 \begin_layout Standard
20200 <row topline="true" endhead="true">
20201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20204 \begin_layout Standard
20205 \begin_inset Quotes sld
20209 \begin_inset Quotes srd
20215 \begin_layout Standard
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_layout Standard
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20233 \begin_layout Standard
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20242 \begin_layout Standard
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_layout Standard
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20260 \begin_layout Standard
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20269 \begin_layout Standard
20276 <row topline="true" endhead="true">
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20280 \begin_layout Standard
20284 \begin_layout Standard
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20293 \begin_layout Standard
20299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20302 \begin_layout Standard
20308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20311 \begin_layout Standard
20312 0.45k / 0.47k (+ _ltoa)
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" rightline="true" usebox="none">
20329 \begin_layout Standard
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20338 \begin_layout Standard
20345 <row topline="true">
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20349 \begin_layout Standard
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20358 \begin_layout Standard
20368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20371 \begin_layout Standard
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20421 \begin_layout Standard
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20463 \begin_layout Standard
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20472 \begin_layout Standard
20478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20481 \begin_layout Standard
20488 <row topline="true">
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_layout Standard
20493 long (32 bit) support
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20501 \begin_layout Standard
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20510 \begin_layout Standard
20516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20519 \begin_layout Standard
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20528 \begin_layout Standard
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20537 \begin_layout Standard
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20555 \begin_layout Standard
20562 <row topline="true">
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20566 \begin_layout Standard
20567 byte arguments on stack
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20575 \begin_layout Standard
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20584 \begin_layout Standard
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_layout Standard
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20602 \begin_layout Standard
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 \begin_layout Standard
20617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20620 \begin_layout Standard
20627 <row topline="true">
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20631 \begin_layout Standard
20633 \begin_inset LatexCommand \index{Floating point support}
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20645 \begin_layout Standard
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20663 \begin_layout Standard
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_layout Standard
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20681 \begin_layout Standard
20686 \begin_layout Standard
20687 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20700 \begin_layout Standard
20707 <row topline="true">
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20711 \begin_layout Standard
20712 float formats %e %g
20717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20720 \begin_layout Standard
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20729 \begin_layout Standard
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20738 \begin_layout Standard
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20747 \begin_layout Standard
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20756 \begin_layout Standard
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20765 \begin_layout Standard
20772 <row topline="true" bottomline="true">
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" usebox="none">
20803 \begin_layout Standard
20809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20812 \begin_layout Standard
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20821 \begin_layout Standard
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20830 \begin_layout Standard
20837 <row bottomline="true">
20838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20841 \begin_layout Standard
20846 \begin_layout Standard
20847 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20851 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20859 \begin_layout Standard
20865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20868 \begin_layout Standard
20874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20877 \begin_layout Standard
20883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20886 \begin_layout Standard
20892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20895 \begin_layout Standard
20901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20904 \begin_layout Standard
20910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20913 \begin_layout Standard
20920 <row bottomline="true">
20921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20924 \begin_layout Standard
20929 \begin_layout Standard
20930 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20939 \begin_layout Standard
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20948 \begin_layout Standard
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20957 \begin_layout Standard
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20966 \begin_layout Standard
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20975 \begin_layout Standard
20981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20984 \begin_layout Standard
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20993 \begin_layout Standard
20998 \begin_layout Standard
20999 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21010 <row bottomline="true">
21011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21014 \begin_layout Standard
21019 \begin_layout Standard
21020 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21029 \begin_layout Standard
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 \begin_layout Standard
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21047 \begin_layout Standard
21053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21056 \begin_layout Standard
21062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21065 \begin_layout Standard
21071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21074 \begin_layout Standard
21080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21083 \begin_layout Standard
21090 <row bottomline="true">
21091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21094 \begin_layout Standard
21099 \begin_layout Standard
21100 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21109 \begin_layout Standard
21115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21118 \begin_layout Standard
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21127 \begin_layout Standard
21133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21136 \begin_layout Standard
21142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21145 \begin_layout Standard
21151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21154 \begin_layout Standard
21160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21163 \begin_layout Standard
21177 \begin_layout Subsubsection
21179 \begin_inset LatexCommand \index{malloc.h}
21186 \begin_layout Standard
21187 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21188 using dynamic memory allocation
21189 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21194 \begin_inset LatexCommand \index{heap (malloc)}
21198 space of 1024 bytes is provided for malloc to allocate memory from.
21199 If you need a different heap size you need to recompile _heap.c with the
21200 required size defined in HEAP_SIZE.
21201 It is recommended to make a copy of this file into your project directory
21202 and compile it there with:
21205 \begin_layout Verse
21208 sdcc -c _heap.c -D HEAD_SIZE=2048
21211 \begin_layout Standard
21212 And then link it with:
21215 \begin_layout Verse
21218 sdcc main.rel _heap.rel
21221 \begin_layout Subsection
21222 Math functions (sinf, powf, sqrtf etc.)
21225 \begin_layout Subsubsection
21229 \begin_layout Standard
21230 See definitions in file <math.h>.
21233 \begin_layout Subsection
21237 \begin_layout Standard
21239 \begin_inset LatexCommand \index{Libraries}
21243 included in SDCC should have a license at least as liberal as the GNU Lesser
21244 General Public License
21245 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21256 \begin_layout Standard
21257 \begin_inset Note Note
21260 \begin_layout Standard
21261 license statements for the libraries are missing.
21262 sdcc/device/lib/ser_ir.c
21265 \begin_layout Standard
21267 come with a GPL (as opposed to LGPL) License - this will not be liberal
21268 enough for many embedded programmers.
21276 \begin_layout Standard
21277 If you have ported some library or want to share experience about some code
21279 falls into any of these categories Busses (I
21280 \begin_inset Formula $^{\textrm{2}}$
21283 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21284 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21285 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
21286 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21291 would certainly like to hear about it.
21294 \begin_layout Standard
21295 Programmers coding for embedded systems are not especially famous for being
21296 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21297 e these references are very valuable.
21298 Let's help to create a climate where information is shared.
21299 \begin_inset VSpace bigskip
21305 \begin_layout Section
21309 \begin_layout Subsection
21310 MCS51 Memory Models
21311 \begin_inset LatexCommand \index{Memory model}
21316 \begin_inset LatexCommand \index{MCS51 memory model}
21323 \begin_layout Subsubsection
21324 Small, Medium and Large
21327 \begin_layout Standard
21328 SDCC allows three memory models for MCS51 code,
21337 Modules compiled with different memory models should
21341 be combined together or the results would be unpredictable.
21342 The library routines supplied with the compiler are compiled as small,
21344 The compiled library modules are contained in separate directories as small,
21345 medium and large so that you can link to the appropriate set.
21348 \begin_layout Standard
21349 When the medium or large model is used all variables declared without a
21350 storage class will be allocated into the external ram, this includes all
21351 parameters and local variables (for non-reentrant
21352 \begin_inset LatexCommand \index{reentrant}
21357 When the small model is used variables without storage class are allocated
21358 in the internal ram.
21361 \begin_layout Standard
21362 Judicious usage of the processor specific storage classes
21363 \begin_inset LatexCommand \index{Storage class}
21367 and the 'reentrant' function type will yield much more efficient code,
21368 than using the large model.
21369 Several optimizations are disabled when the program is compiled using the
21370 large model, it is therefore recommended that the small model be used unless
21371 absolutely required.
21374 \begin_layout Subsubsection
21376 \begin_inset LatexCommand \label{sub:External-Stack}
21381 \begin_inset LatexCommand \index{stack}
21386 \begin_inset LatexCommand \index{External stack (mcs51)}
21393 \begin_layout Standard
21394 The external stack (-
21398 \begin_layout Standard
21408 \begin_inset LatexCommand \index{-\/-xstack}
21412 ) is located in pdata
21413 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21417 memory (usually at the start of the external ram segment) and uses all
21418 unused space in pdata (max.
21424 \begin_layout Standard
21433 -xstack option is used to compile the program, the parameters and local
21435 \begin_inset LatexCommand \index{local variables}
21439 of all reentrant functions are allocated in this area.
21440 This option is provided for programs with large stack space requirements.
21441 When used with the -
21445 \begin_layout Standard
21455 \begin_inset LatexCommand \index{-\/-stack-auto}
21459 option, all parameters and local variables are allocated on the external
21460 stack (note: support libraries will need to be recompiled with the same
21462 There is a predefined target in the library makefile).
21465 \begin_layout Standard
21466 The compiler outputs the higher order address byte of the external ram segment
21468 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21473 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21477 ), therefore when using the External Stack option, this port
21481 be used by the application program.
21484 \begin_layout Subsection
21486 \begin_inset LatexCommand \index{Memory model}
21491 \begin_inset LatexCommand \index{DS390 memory model}
21498 \begin_layout Standard
21499 The only model supported is Flat 24
21500 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21505 This generates code for the 24 bit contiguous addressing mode of the Dallas
21507 In this mode, up to four meg of external RAM or code space can be directly
21509 See the data sheets at www.dalsemi.com for further information on this part.
21514 that the compiler does not generate any code to place the processor into
21515 24 bitmode (although
21519 in the ds390 libraries will do that for you).
21525 \begin_inset LatexCommand \index{Tinibios (DS390)}
21529 , the boot loader or similar code must ensure that the processor is in 24
21530 bit contiguous addressing mode before calling the SDCC startup code.
21541 \begin_layout Standard
21552 option, variables will by default be placed into the XDATA segment.
21557 Segments may be placed anywhere in the 4 meg address space using the usual
21562 \begin_layout Standard
21572 Note that if any segments are located above 64K, the -r flag must be passed
21573 to the linker to generate the proper segment relocations, and the Intel
21574 HEX output format must be used.
21575 The -r flag can be passed to the linker by using the option
21579 on the SDCC command line.
21580 However, currently the linker can not handle code segments > 64k.
21583 \begin_layout Section
21585 \begin_inset LatexCommand \label{sec:Pragmas}
21590 \begin_inset LatexCommand \index{Pragmas}
21597 \begin_layout Standard
21598 Pragmas are used to turn on and/or off certain compiler options.
21599 Some of them are closely related to corresponding command-line options
21601 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21607 Pragmas should be placed before and/or after a function, placing pragmas
21608 inside a function body could have unpredictable results.
21613 following #pragma directives:
21616 \begin_layout Itemize
21622 \begin_inset LatexCommand \index{\#pragma save}
21626 - this will save most current options to the save/restore stack.
21627 See #pragma\InsetSpace ~
21631 \begin_layout Itemize
21637 \begin_inset LatexCommand \index{\#pragma restore}
21641 - will restore saved options from the last save.
21642 saves & restores can be nested.
21643 SDCC uses a save/restore stack: save pushes current options to the stack,
21644 restore pulls current options from the stack.
21645 See #pragma\InsetSpace ~
21651 \begin_layout Itemize
21657 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21662 \begin_inset LatexCommand \index{function prologue}
21666 function1[,function2[,function3...]]
21667 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21671 - The compiler by default uses a caller saves convention for register saving
21672 across function calls, however this can cause unnecessary register pushing
21674 \begin_inset LatexCommand \index{push/pop}
21678 when calling small functions from larger functions.
21679 This option can be used to switch off the register saving convention for
21680 the function names specified.
21681 The compiler will not save registers when calling these functions, extra
21682 code need to be manually inserted at the entry and exit for these functions
21683 to save and restore the registers used by these functions, this can SUBSTANTIAL
21684 LY reduce code and improve run time performance of the generated code.
21685 In the future the compiler (with inter procedural analysis) may be able
21686 to determine the appropriate scheme to use for each function call.
21691 \begin_layout Standard
21700 -callee-saves command line option is used (see page
21701 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21705 ), the function names specified in #pragma\InsetSpace ~
21707 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21711 is appended to the list of functions specified in the command line.
21714 \begin_layout Itemize
21720 \begin_inset LatexCommand \index{\#pragma exclude}
21724 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21725 of pairs of push/pop
21726 \begin_inset LatexCommand \index{push/pop}
21735 \begin_inset LatexCommand \index{interrupt}
21748 The directive should be placed immediately before the ISR function definition
21749 and it affects ALL ISR functions following it.
21750 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21751 exclude\InsetSpace ~
21753 \begin_inset LatexCommand \index{\#pragma exclude}
21758 See also the related keyword _naked
21759 \begin_inset LatexCommand \index{\_naked}
21764 \begin_inset LatexCommand \index{\_\_naked}
21771 \begin_layout Itemize
21777 \begin_inset LatexCommand \index{pedantic}
21782 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21787 \begin_inset LatexCommand \label{ite:less_pedantic}
21791 - the compiler will not warn you anymore for obvious mistakes, you're on
21793 See also the command line option -
21797 \begin_layout Standard
21807 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21814 More specifically, the following warnings will be disabled:
21816 comparison is always [true/false] due to limited range of data type
21820 overflow in implicit constant conversion
21822 (158); [the (in)famous]
21824 conditional flow changed by optimizer: so said EVELYN the modified DOG
21828 function '[function name]' must return value
21833 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21834 level) are disabled, too, namely:
21837 \begin_inset Note Note
21840 \begin_layout Standard
21841 dunno what comes here - this warning appears to be unused altogether
21850 [left/right] shifting more than size of object changed to zero
21858 integer overflow in expression
21862 unmatched #pragma save and #pragma restore
21866 comparison of 'signed char' with 'unsigned char' requires promotion to int
21870 ISO C90 does not support flexible array members
21874 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21878 \begin_inset Note Note
21881 \begin_layout Standard
21882 appears to be always blank - what was supposed to be here?
21891 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21892 complexity [number]
21897 \begin_layout Itemize
21903 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21907 - the compiler will not warn you anymore about warning number <nnnn>.
21910 \begin_layout Itemize
21916 \begin_inset LatexCommand \index{\#pragma nogcse}
21920 - will stop global common subexpression elimination.
21923 \begin_layout Itemize
21929 \begin_inset LatexCommand \index{\#pragma noinduction}
21933 - will stop loop induction optimizations.
21936 \begin_layout Itemize
21942 \begin_inset LatexCommand \index{\#pragma noinvariant}
21946 - will not do loop invariant optimizations.
21947 For more details see Loop Invariants in section
21948 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21955 \begin_layout Itemize
21961 \begin_inset LatexCommand \index{\#pragma noiv}
21965 - Do not generate interrupt
21966 \begin_inset LatexCommand \index{interrupt}
21971 \begin_inset LatexCommand \index{interrupt vector table}
21975 entries for all ISR functions defined after the pragma.
21976 This is useful in cases where the interrupt vector table must be defined
21977 manually, or when there is a secondary, manually defined interrupt vector
21979 for the autovector feature of the Cypress EZ-USB FX2).
21980 More elegantly this can be achieved by obmitting the optional interrupt
21981 number after the interrupt keyword, see section
21982 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21990 \begin_layout Itemize
21996 \begin_inset LatexCommand \index{\#pragma nojtbound}
22000 - will not generate code for boundary value checking, when switch statements
22001 are turned into jump-tables (dangerous).
22002 For more details see section
22003 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22010 \begin_layout Itemize
22016 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22020 - Will not do loop reversal optimization
22023 \begin_layout Itemize
22029 \begin_inset LatexCommand \index{\#pragma nooverlay}
22033 - the compiler will not overlay the parameters and local variables of a
22037 \begin_layout Itemize
22043 \begin_inset LatexCommand \index{\#pragma stackauto}
22051 \begin_layout Standard
22061 \begin_inset LatexCommand \index{-\/-stack-auto}
22066 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22070 Parameters and Local Variables.
22073 \begin_layout Itemize
22079 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22083 - The compiler will optimize code generation towards fast code, possibly
22084 at the expense of code size.
22085 Currently this has little effect.
22088 \begin_layout Itemize
22094 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22098 - The compiler will optimize code generation towards compact code, possibly
22099 at the expense of code speed.
22100 Currently this has little effect.
22103 \begin_layout Itemize
22109 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22113 - The compiler will attempt to generate code that is both compact and fast,
22114 as long as meeting one goal is not a detriment to the other (this is the
22119 \begin_layout Itemize
22125 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22129 - Generally follow the C89 standard, but allow SDCC features that conflict
22130 with the standard (default).
22133 \begin_layout Itemize
22139 \begin_inset LatexCommand \index{\#pragma std\_c89}
22143 - Follow the C89 standard and disable SDCC features that conflict with the
22147 \begin_layout Itemize
22153 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22157 - Generally follow the C99 standard, but allow SDCC features that conflict
22158 with the standard (incomplete support).
22161 \begin_layout Itemize
22167 \begin_inset LatexCommand \index{\#pragma std\_c99}
22171 - Follow the C99 standard and disable SDCC features that conflict with the
22172 standard (incomplete support).
22175 \begin_layout Itemize
22181 \begin_inset LatexCommand \index{\#pragma codeseg}
22185 - Use this name (max.
22186 8 characters) for the code segment.
22191 \begin_layout Standard
22203 \begin_layout Itemize
22209 \begin_inset LatexCommand \index{\#pragma constseg}
22213 - Use this name (max.
22214 8 characters) for the const segment.
22219 \begin_layout Standard
22231 \begin_layout Standard
22232 The preprocessor SDCPP
22233 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22237 supports the following #pragma directives:
22240 \begin_layout Itemize
22243 pedantic_parse_number
22246 \begin_inset LatexCommand \index{pedantic}
22251 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22256 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22260 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22261 properly and the macro LO_B(3) gets expanded.
22267 \begin_layout Standard
22276 -pedantic-parse-number command line option
22277 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22284 Below is an example on how to use this pragma.
22287 Note: this functionality is not in conformance with standard!
22290 \begin_layout Verse
22293 #pragma pedantic_parse_number +
22294 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22302 #define LO_B(x) ((x) & 0xff)
22306 unsigned char foo(void)
22313 unsigned char c=0xfe-LO_B(3)
22328 \begin_layout Itemize
22334 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22338 (+ | -) - switch _asm _endasm block preprocessing on / off.
22340 You use this prama to define multilines of assembly code.
22341 This will prevent the preprocessor from changing the formating required
22343 Below is an example on how to use this pragma.
22346 \begin_layout Verse
22349 #pragma preproc_asm -
22350 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22356 #define MYDELAY _asm
22361 nop ;my assembly comment...
22375 #pragma preproc_asm
22406 \begin_layout Itemize
22412 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22416 (+ | -) - Allow "naked" hash in macro definition, for example:
22420 #define DIR_LO(x) #(x & 0xff)
22425 Below is an example on how to use this pragma.
22428 \begin_layout Verse
22431 #pragma preproc_asm +
22433 #pragma sdcc_hash +
22434 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22449 mov R6_B3, #(x & 0xff)
22456 mov R7_B3, #((x >> 8) & 0xff)
22480 \begin_layout Standard
22481 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22482 ons which might cause the compiler to generate extra stack and/or data space
22483 to store compiler generated temporary variables.
22484 This usually happens in large functions.
22485 Pragma directives should be used as shown in the following example, they
22486 are used to control options and optimizations for a given function.
22490 \begin_layout Verse
22494 \begin_inset LatexCommand \index{\#pragma save}
22505 /* save the current settings */
22508 \begin_inset LatexCommand \index{\#pragma nogcse}
22517 /* turnoff global subexpression elimination */
22519 #pragma noinduction
22520 \begin_inset LatexCommand \index{\#pragma noinduction}
22524 /* turn off induction optimizations */
22547 \begin_inset LatexCommand \index{\#pragma restore}
22551 /* turn the optimizations back on */
22554 \begin_layout Standard
22555 The compiler will generate a warning message when extra space is allocated.
22556 It is strongly recommended that the save and restore pragmas be used when
22557 changing options for a function.
22566 \begin_layout Section
22567 Defines Created by the Compiler
22570 \begin_layout Standard
22571 The compiler creates the following #defines
22572 \begin_inset LatexCommand \index{\#defines}
22577 \begin_inset LatexCommand \index{Defines created by the compiler}
22586 \begin_layout Standard
22587 \begin_inset Tabular
22588 <lyxtabular version="3" rows="11" columns="2">
22590 <column alignment="left" valignment="top" leftline="true" width="3in">
22591 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22592 <row topline="true" bottomline="true">
22593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22596 \begin_layout Standard
22604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22607 \begin_layout Standard
22616 <row topline="true">
22617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22620 \begin_layout Standard
22622 \begin_inset LatexCommand \index{SDCC}
22631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22634 \begin_layout Standard
22636 Since version 2.5.6 the version number as an int (ex.
22643 <row topline="true">
22644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22647 \begin_layout Standard
22649 \begin_inset LatexCommand \index{SDCC\_mcs51}
22654 \begin_inset LatexCommand \index{SDCC\_ds390}
22659 \begin_inset LatexCommand \index{SDCC\_z80}
22668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22671 \begin_layout Standard
22672 depending on the model used (e.g.: -mds390)
22678 <row topline="true">
22679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22682 \begin_layout Standard
22684 \begin_inset LatexCommand \index{\_\_mcs51}
22689 \begin_inset LatexCommand \index{\_\_ds390}
22694 \begin_inset LatexCommand \index{\_\_hc08}
22699 \begin_inset LatexCommand \index{\_\_z80}
22708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22711 \begin_layout Standard
22712 depending on the model used (e.g.
22719 <row topline="true">
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22723 \begin_layout Standard
22725 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22737 \begin_layout Standard
22744 \begin_layout Standard
22761 <row topline="true">
22762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22765 \begin_layout Standard
22767 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22779 \begin_layout Standard
22786 \begin_layout Standard
22803 <row topline="true">
22804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22807 \begin_layout Standard
22809 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22821 \begin_layout Standard
22828 \begin_layout Standard
22845 <row topline="true">
22846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22849 \begin_layout Standard
22851 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22863 \begin_layout Standard
22870 \begin_layout Standard
22887 <row topline="true">
22888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22891 \begin_layout Standard
22893 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22905 \begin_layout Standard
22912 \begin_layout Standard
22929 <row topline="true">
22930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22933 \begin_layout Standard
22935 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22947 \begin_layout Standard
22958 <row topline="true" bottomline="true">
22959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22962 \begin_layout Standard
22964 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22976 \begin_layout Standard
22994 \begin_layout Chapter
22995 Notes on supported Processors
22998 \begin_layout Section
23000 \begin_inset LatexCommand \label{sub:MCS51-variants}
23005 \begin_inset LatexCommand \index{MCS51 variants}
23012 \begin_layout Standard
23013 MCS51 processors are available from many vendors and come in many different
23015 While they might differ considerably in respect to Special Function Registers
23016 the core MCS51 is usually not modified or is kept compatible.
23020 \begin_layout Subsection
23021 pdata access by SFR
23024 \begin_layout Standard
23025 With the upcome of devices with internal xdata and flash memory devices
23027 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23031 as dedicated I/O port is becoming more popular.
23032 Switching the high byte for pdata
23033 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23037 access which was formerly done by port P2 is then achieved by a Special
23039 \begin_inset LatexCommand \index{sfr}
23044 In well-established MCS51 tradition the address of this
23048 is where the chip designers decided to put it.
23049 Needless to say that they didn't agree on a common name either.
23050 So that the startup code can correctly initialize xdata variables, you
23051 should define an sfr with the name _XPAGE
23054 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23060 at the appropriate location if the default, port P2, is not used for this.
23064 \begin_layout Verse
23067 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23071 \begin_layout Verse
23074 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23079 \begin_layout Verse
23082 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23086 \begin_layout Verse
23089 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23093 \begin_layout Verse
23096 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23100 \begin_layout Standard
23101 For more exotic implementations further customizations may be needed.
23103 \begin_inset LatexCommand \ref{sub:Startup-Code}
23107 for other possibilities.
23110 \begin_layout Subsection
23111 Other Features available by SFR
23114 \begin_layout Standard
23115 Some MCS51 variants offer features like Double DPTR
23116 \begin_inset LatexCommand \index{DPTR}
23120 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23121 These are currently not used for the MCS51 port.
23122 If you absolutely need them you can fall back to inline assembly or submit
23124 \begin_inset VSpace bigskip
23130 \begin_layout Section
23134 \begin_layout Standard
23136 \begin_inset LatexCommand \index{DS80C400}
23141 \begin_inset LatexCommand \index{DS400}
23145 microcontroller has a rich set of peripherals.
23146 In its built-in ROM library it includes functions to access some of the
23147 features, among them is a TCP stack with IP4 and IP6 support.
23148 Library headers (currently in beta status) and other files are provided
23152 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23158 \begin_inset VSpace bigskip
23164 \begin_layout Section
23165 The Z80 and gbz80 port
23168 \begin_layout Standard
23169 SDCC can target both the Zilog Z80
23170 \begin_inset LatexCommand \index{Z80}
23174 and the Nintendo Gameboy's Z80-like gbz80
23175 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23180 The Z80 port is passed through the same
23183 \begin_inset LatexCommand \index{Regression test}
23190 \begin_inset LatexCommand \ref{sec:Quality-control}
23194 ) as the MCS51 and DS390 ports, so floating point support, support for long
23195 variables and bitfield support is fine.
23196 See mailing lists and forums about interrupt routines.
23199 \begin_layout Standard
23200 As always, the code is the authoritative reference - see z80/ralloc.c and
23203 \begin_inset LatexCommand \index{Z80!stack}
23207 frame is similar to that generated by the IAR Z80 compiler.
23208 IX is used as the base pointer, HL and IY are used as a temporary registers,
23209 and BC and DE are available for holding variables.
23211 \begin_inset LatexCommand \index{Z80!return value}
23215 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23217 The gbz80 port use the same set of registers for the return values, but
23218 in a different order of significance: E (one byte), DE (two bytes), or
23220 \begin_inset VSpace bigskip
23226 \begin_layout Section
23230 \begin_layout Standard
23231 The port to the Freescale/Motorola HC08
23232 \begin_inset LatexCommand \index{HC08}
23236 family has been added in October 2003, and is still undergoing some basic
23238 The code generator is complete, but the register allocation is still quite
23240 Some of the SDCC's standard C library functions have embedded non-HC08
23241 inline assembly and so are not yet usable.
23244 \begin_layout Standard
23245 The HC08 port passes the regression test suite (see section
23246 \begin_inset LatexCommand \ref{sec:Quality-control}
23251 \begin_inset VSpace bigskip
23259 \begin_layout Section
23261 \begin_inset LatexCommand \index{PIC14}
23268 \begin_layout Standard
23269 The PIC14 port adds support for Microchip
23270 \begin_inset LatexCommand \index{Microchip}
23275 \begin_inset Formula $^{\text{TM}}$
23279 \begin_inset LatexCommand \index{PIC14}
23284 \begin_inset Formula $^{\text{TM}}$
23287 MCUs with 14 bit wide instructions.
23288 This port is not yet mature and still lacks many features.
23289 However, it can work for simple code.
23292 \begin_layout Standard
23293 Currently supported devices include:
23296 \begin_layout Standard
23297 12F: 629, 635, 675, 683
23300 \begin_layout Standard
23304 \begin_layout Standard
23308 \begin_layout Standard
23309 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23312 \begin_layout Standard
23313 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23317 \begin_layout Standard
23321 \begin_layout Standard
23322 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23326 \begin_layout Standard
23327 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23330 \begin_layout Standard
23331 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23335 \begin_layout Standard
23336 16F: 913, 914, 916, 917
23339 \begin_layout Standard
23340 An up-to-date list of currently supported devices can be obtained via
23342 sdcc -mpic14 -phelp foo.c
23344 (foo.c must exist...).
23347 \begin_layout Subsection
23349 \begin_inset LatexCommand \index{code page (pic14)}
23354 \begin_inset LatexCommand \index{Memory bank (pic14)}
23361 \begin_layout Standard
23362 The linker organizes allocation for the code page and RAM banks.
23363 It does not have intimate knowledge of the code flow.
23364 It will put all the code section of a single .asm file into a single code
23366 In order to make use of multiple code pages, separate asm files must be
23368 The compiler assigns all
23372 functions of a single .c file into the same code page.
23376 To get the best results,
23377 follow these guidelines:
23380 \begin_layout Enumerate
23381 Make local functions static, as non static functions require code page selection
23384 Due to the way sdcc handles functions, place called functions prior
23385 to calling functions in the file wherever possible: Otherwise sdcc will
23386 insert unneccessary pagesel directives around the call, believing that
23387 the called function is externally defined.
23390 \begin_layout Enumerate
23391 For devices that have multiple code pages it is more efficient to use the
23392 same number of files as pages: Use up to 4 separate .c files for the 16F877,
23393 but only 2 files for the 16F874.
23394 This way the linker can put the code for each file into different code
23395 pages and there will be less page selection overhead.
23398 \begin_layout Enumerate
23399 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23400 instruction set), use `unsigned char' wherever possible instead of `int'.
23403 \begin_layout Subsection
23404 Adding New Devices to the Port
23407 \begin_layout Standard
23408 Adding support for a new 14
23412 \begin_layout Standard
23421 bit PIC MCU requires the following steps:
23424 \begin_layout Enumerate
23425 Create a new device description.
23427 Each device is described in two files: pic16f*.h
23429 These files primarily define SFRs, structs to access their bits, and symbolic
23430 configuration options.
23431 Both files can be generated from gputils' .inc files using the perl script
23434 support/scripts/inc2h.pl
23437 This file also contains further instructions on how to proceed.
23440 \begin_layout Enumerate
23441 Copy the .h file into SDCC's include path and either add the .c file to your
23442 project or copy it to
23444 device/lib/pic/libdev
23447 Afterwards, rebuild and install the libraries.
23450 \begin_layout Enumerate
23451 Edit pic14devices.txt in SDCC's include path (
23453 device/include/pic/
23455 in the source tree or
23457 /usr/local/share/sdcc/include/pic
23459 after installation).
23461 You need to add a device specification here to make
23462 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23464 Probably you can copy and modify an existing entry.
23465 The file format is documented at the top of the file.
23468 \begin_layout Subsection
23472 \begin_layout Standard
23473 For the interrupt function, use the keyword `__interrupt'
23474 \begin_inset LatexCommand \index{PIC14!interrupt}
23478 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23479 there to avoid a syntax error - it ought to be fixed).
23483 \begin_layout Verse
23486 void Intr(void) __interrupt 0
23492 T0IF = 0; /* Clear timer interrupt */
23497 \begin_layout Subsection
23498 Linking and Assembling
23501 \begin_layout Standard
23502 For assembling you can use either GPUTILS'
23503 \begin_inset LatexCommand \index{gputils (pic tools)}
23507 gpasm.exe or MPLAB's mpasmwin.exe.
23508 GPUTILS are available from
23509 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23514 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23515 If you use MPLAB and an interrupt function then the linker script file
23516 vectors section will need to be enlarged to link with mplink.
23527 \begin_layout Verse
23540 sdcc -V -mpic14 -p16f877 -c $<
23544 $(PRJ).hex: $(OBJS)
23554 gplink -m -s $(PRJ).lkr
23555 -o $(PRJ).hex $(OBJS) libsdcc.lib
23558 \begin_layout Standard
23566 \begin_layout Verse
23579 sdcc -S -V -mpic14 -p16f877 $<
23589 mpasmwin /q /o $*.asm
23593 $(PRJ).hex: $(OBJS)
23604 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23607 \begin_layout Standard
23608 Please note that indentations within a
23612 have to be done with a tabulator character.
23615 \begin_layout Subsection
23616 Command-Line Options
23619 \begin_layout Standard
23620 Besides the switches common to all SDCC backends, the PIC14 port accepts
23621 the following options (for an updated list see sdcc -
23625 \begin_layout Standard
23637 \begin_layout Description
23642 \begin_layout Standard
23652 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23656 emit debug info in assembly output
23659 \begin_layout Description
23664 \begin_layout Standard
23674 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23678 disable (slightly faulty) optimization on pCode
23681 \begin_layout Description
23686 \begin_layout Standard
23696 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23700 sets the lowest address of the argument passing stack (defaults to a suitably
23701 large shared databank to reduce BANKSEL overhead)
23704 \begin_layout Description
23709 \begin_layout Standard
23719 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23723 sets the size if the argument passing stack (default: 16, minimum: 4)
23726 \begin_layout Subsection
23727 Environment Variables
23730 \begin_layout Standard
23731 The PIC14 port recognizes the following environment variables:
23734 \begin_layout Description
23735 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23736 register (the ones called r0xNNNN) in a section of its own.
23737 By default (if this variable is unset), sdcc tries to cluster registers
23738 in sections in order to reduce the BANKSEL overhead when accessing them.
23741 \begin_layout Subsection
23745 \begin_layout Standard
23746 The PIC14 library currently only contains support routines required by the
23747 compiler to implement multiplication, division, and floating point support.
23748 No libc-like replacement is available at the moment, though many of the
23749 common sdcc library sources (in
23753 ) should also compile with the PIC14 port.
23756 \begin_layout Subsubsection
23757 error: missing definition for symbol ``__gptrget1''
23760 \begin_layout Standard
23761 The PIC14 port uses library routines to provide more complex operations
23762 like multiplication, division/modulus and (generic) pointer dereferencing.
23763 In order to add these routines to your project, you must link with PIC14's
23769 For single source file projects this is done automatically, more complex
23774 to the linker's arguments.
23775 Make sure you also add an include path for the library (using the -I switch
23779 \begin_layout Subsubsection
23780 Processor mismatch in file ``XXX''.
23783 \begin_layout Standard
23784 This warning can usually be ignored due to the very good compatibility amongst
23789 \begin_layout Standard
23799 \begin_inset LatexCommand \index{PIC14}
23806 \begin_layout Standard
23807 You might also consider recompiling the library for your specific device
23808 by changing the ARCH=p16f877 (default target) entry in
23810 device/lib/pic/Makefile.in
23814 device/lib/pic/Makefile
23816 to reflect your device.
23817 This might even improve performance for smaller devices as unneccesary
23818 BANKSELs might be removed.
23821 \begin_layout Subsection
23825 \begin_layout Subsubsection
23829 \begin_layout Standard
23830 Functions with variable argument lists (like printf) are not yet supported.
23831 Similarly, taking the argument of the first argument passed into a function
23832 does not work: It is currently passed in WREG and has no address...
23835 \begin_layout Subsubsection
23836 Regression tests fail
23839 \begin_layout Standard
23840 Though the small subset of regression tests in src/regression passes, SDCC
23841 regression test suite does not, indicating that there are still major bugs
23843 However, many smaller projects have successfully used SDCC in the past...
23846 \begin_layout Standard
23854 \begin_layout Section
23856 \begin_inset LatexCommand \index{PIC16}
23863 \begin_layout Standard
23864 The PIC16 port adds support for Microchip
23865 \begin_inset LatexCommand \index{Microchip}
23870 \begin_inset Formula $^{\text{TM}}$
23874 \begin_inset LatexCommand \index{PIC}
23879 \begin_inset Formula $^{\text{TM}}$
23882 MCUs with 16 bit wide instructions.
23883 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23884 ; devices supported by the port include:
23887 \begin_layout Standard
23888 18F: 242, 248, 252, 258, 442, 448, 452, 458
23891 \begin_layout Standard
23895 \begin_layout Standard
23896 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23900 \begin_layout Standard
23901 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23905 \begin_layout Standard
23906 18F: 6520, 6620, 6680, 6720
23909 \begin_layout Standard
23910 18F: 8520, 8620, 8680, 8720
23913 \begin_layout Subsection
23917 \begin_layout Standard
23918 PIC16 port supports the standard command line arguments as supposed, with
23919 the exception of certain cases that will be mentioned in the following
23923 \begin_layout Description
23928 \begin_layout Standard
23938 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23946 \begin_layout Standard
23958 \begin_layout Description
23963 \begin_layout Standard
23972 -fommit-frame-pointer
23973 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23977 Frame pointer will be omitted when the function uses no local variables.
23980 \begin_layout Subsection
23981 Port Specific Options
23982 \begin_inset LatexCommand \index{Options PIC16}
23989 \begin_layout Standard
23990 The port specific options appear after the global options in the sdcc -
23994 \begin_layout Standard
24006 \begin_layout Subsubsection
24007 Code Generation Options
24010 \begin_layout Standard
24011 These options influence the generated assembler code.
24014 \begin_layout Description
24019 \begin_layout Standard
24028 -pstack-model=[model] Used in conjuction with the command above.
24029 Defines the stack model to be used, valid stack models are:
24034 \labelwidthstring 00.00.0000
24039 Selects small stack model.
24040 8 bit stack and frame pointers.
24041 Supports 256 bytes stack size.
24045 \labelwidthstring 00.00.0000
24050 Selects large stack model.
24051 16 bit stack and frame pointers.
24052 Supports 65536 bytes stack size.
24056 \begin_layout Description
24061 \begin_layout Standard
24070 -pno-banksel Do not generate BANKSEL assembler directives.
24073 \begin_layout Description
24078 \begin_layout Standard
24087 -extended Enable extended instruction set/literal offset addressing mode.
24091 \begin_layout Subsubsection
24092 Optimization Options
24095 \begin_layout Description
24100 \begin_layout Standard
24109 -obanksel=n Set optimization level for inserting BANKSELs.
24116 \labelwidthstring 00.00.0000
24121 \labelwidthstring 00.00.0000
24122 1 checks previous used register and if it is the same then does not emit
24123 BANKSEL, accounts only for labels.
24127 \labelwidthstring 00.00.0000
24128 2 tries to check the location of (even different) symbols and removes BANKSELs
24129 if they are in the same bank.
24134 Important: There might be problems if the linker script has data sections
24135 across bank borders!
24139 \begin_layout Description
24144 \begin_layout Standard
24153 -denable-peeps Force the usage of peepholes.
24157 \begin_layout Description
24162 \begin_layout Standard
24171 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24174 \begin_layout Description
24179 \begin_layout Standard
24188 -optimize-cmp Try to optimize some compares.
24191 \begin_layout Description
24196 \begin_layout Standard
24205 -optimize-df Analyze the dataflow of the generated code and improve it.
24208 \begin_layout Subsubsection
24212 \begin_layout Description
24217 \begin_layout Standard
24226 -asm= Sets the full path and name of an external assembler to call.
24229 \begin_layout Description
24234 \begin_layout Standard
24244 \begin_inset LatexCommand \index{PIC16!MPLAB}
24248 compatibility option.
24249 Currently only suppresses special gpasm directives.
24252 \begin_layout Subsubsection
24256 \begin_layout Description
24261 \begin_layout Standard
24270 -link= Sets the full path and name of an external linker to call.
24273 \begin_layout Description
24278 \begin_layout Standard
24287 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24288 unitialized data variables with [kword].
24289 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24292 \begin_layout Description
24297 \begin_layout Standard
24306 -ivt-loc=n Place the interrupt vector table at address
24311 Useful for bootloaders.
24314 \begin_layout Description
24319 \begin_layout Standard
24328 -nodefaultlibs Do not link default libraries when linking.
24331 \begin_layout Description
24336 \begin_layout Standard
24345 -use-crt= Use a custom run-time module instead of the defaults.
24348 \begin_layout Description
24353 \begin_layout Standard
24362 -no-crt Don't link the default run-time modules
24365 \begin_layout Subsubsection
24369 \begin_layout Standard
24370 Debugging options enable extra debugging information in the output files.
24373 \begin_layout Description
24378 \begin_layout Standard
24387 -debug-xtra Similar to -
24391 \begin_layout Standard
24401 \begin_inset LatexCommand \index{-\/-debug}
24405 , but dumps more information.
24408 \begin_layout Description
24413 \begin_layout Standard
24422 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24424 <source> is the name of the file being compiled.
24427 \begin_layout Description
24432 \begin_layout Standard
24441 -pcode-verbose Enable pcode debugging information in translation.
24444 \begin_layout Description
24449 \begin_layout Standard
24458 -calltree Dump call tree in .calltree file.
24461 \begin_layout Description
24466 \begin_layout Standard
24475 -gstack Trace push/pops for stack pointer overflow.
24478 \begin_layout Subsection
24479 Enviroment Variables
24482 \begin_layout Standard
24483 There is a number of enviromental variables that can be used when running
24484 SDCC to enable certain optimizations or force a specific program behaviour.
24485 these variables are primarily for debugging purposes so they can be enabled/dis
24489 \begin_layout Standard
24490 Currently there is only two such variables available:
24493 \begin_layout Description
24494 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24495 bitfields is optimized by directly loading FSR0 with the address of the
24496 bitfield structure.
24497 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24499 This step saves data ram and code space for functions that make heavy use
24501 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24506 \begin_layout Description
24507 NO_REG_OPT Do not perform pCode registers optimization.
24508 This should be used for debugging purposes.
24509 If bugs in the pcode optimizer are found, users can benefit from temporarily
24510 disabling the optimizer until the bug is fixed.
24513 \begin_layout Subsection
24514 Preprocessor Macros
24517 \begin_layout Standard
24519 \begin_inset LatexCommand \index{PIC16}
24523 port defines the following preprocessor macros while translating a source.
24526 \begin_layout Standard
24528 \begin_inset Tabular
24529 <lyxtabular version="3" rows="6" columns="2">
24531 <column alignment="center" valignment="top" leftline="true" width="0">
24532 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24533 <row topline="true" bottomline="true">
24534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24537 \begin_layout Standard
24543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24546 \begin_layout Standard
24553 <row topline="true">
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24557 \begin_layout Standard
24563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24566 \begin_layout Standard
24567 Port identification
24573 <row topline="true">
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24577 \begin_layout Standard
24582 \begin_layout Standard
24596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24599 \begin_layout Standard
24600 Port identification (same as above)
24606 <row topline="true">
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24610 \begin_layout Standard
24616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24619 \begin_layout Standard
24620 MCU Identification.
24625 is the microcontrol identification number, i.e.
24632 <row topline="true">
24633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24636 \begin_layout Standard
24641 \begin_layout Standard
24655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24658 \begin_layout Standard
24659 MCU Identification (same as above)
24665 <row topline="true" bottomline="true">
24666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24669 \begin_layout Standard
24675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24678 \begin_layout Standard
24679 nnn = SMALL or LARGE respectively according to the stack model used
24692 \begin_layout Standard
24693 In addition the following macros are defined when calling assembler:
24696 \begin_layout Standard
24698 \begin_inset Tabular
24699 <lyxtabular version="3" rows="4" columns="2">
24701 <column alignment="center" valignment="top" leftline="true" width="0">
24702 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24703 <row topline="true" bottomline="true">
24704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24707 \begin_layout Standard
24713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24716 \begin_layout Standard
24723 <row topline="true">
24724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24727 \begin_layout Standard
24733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24736 \begin_layout Standard
24737 MCU Identification.
24742 is the microcontrol identification number, i.e.
24749 <row topline="true">
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24753 \begin_layout Standard
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24762 \begin_layout Standard
24763 nnn = SMALL or LARGE respectively according to the memory model used for
24770 <row topline="true" bottomline="true">
24771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24774 \begin_layout Standard
24780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24783 \begin_layout Standard
24784 nnn = SMALL or LARGE respectively according to the stack model used
24797 \begin_layout Subsection
24801 \begin_layout Standard
24803 \begin_inset LatexCommand \index{PIC16}
24807 port uses the following directories for searching header files and libraries.
24810 \begin_layout Standard
24812 \begin_inset Tabular
24813 <lyxtabular version="3" rows="3" columns="4">
24815 <column alignment="center" valignment="top" leftline="true" width="0">
24816 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24817 <column alignment="center" valignment="top" width="0">
24818 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24819 <row topline="true" bottomline="true">
24820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24823 \begin_layout Standard
24829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24832 \begin_layout Standard
24838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24841 \begin_layout Standard
24847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24850 \begin_layout Standard
24857 <row topline="true">
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24861 \begin_layout Standard
24862 PREFIX/sdcc/include/pic16
24867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24870 \begin_layout Standard
24871 PIC16 specific headers
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24879 \begin_layout Standard
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24888 \begin_layout Standard
24895 <row topline="true" bottomline="true">
24896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24899 \begin_layout Standard
24900 PREFIX/sdcc/lib/pic16
24905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24908 \begin_layout Standard
24909 PIC16 specific libraries
24914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24917 \begin_layout Standard
24923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24926 \begin_layout Standard
24940 \begin_layout Subsection
24942 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24949 \begin_layout Standard
24951 \begin_inset LatexCommand \index{PIC16}
24955 port currently supports the following pragmas:
24958 \begin_layout Description
24960 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24964 This forces the code generator to initialize the stack & frame pointers
24965 at a specific address.
24966 This is an ad hoc solution for cases where no STACK directive is available
24967 in the linker script or gplink is not instructed to create a stack section.
24970 stack pragma should be used only once in a project.
24971 Multiple pragmas may result in indeterminate behaviour of the program.
24975 \begin_layout Standard
24976 The old format (ie.
24977 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24978 cross page boundaries (or even exceed the available data RAM) and crash
24980 Make sure that stack does not cross page boundaries when using the SMALL
24988 The format is as follows:
24993 \begin_layout LyX-Code
24994 #pragma stack bottom_address [stack_size]
24999 \begin_layout Standard
25004 is the lower bound of the stack section.
25005 The stack pointer initially will point at address (bottom_address+stack_size-1).
25008 \begin_layout LyX-Code
25012 \begin_layout LyX-Code
25016 \begin_layout LyX-Code
25017 /* initializes stack of 100 bytes at RAM address 0x200 */
25020 \begin_layout LyX-Code
25021 #pragma stack 0x200 100
25024 \begin_layout Standard
25025 If the stack_size field is omitted then a stack is created with the default
25027 This size might be enough for most programs, but its not enough for operations
25028 with deep function nesting or excessive stack usage.
25031 \begin_layout Description
25033 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25037 Force a function to a static FLASH address.
25040 \begin_layout LyX-Code
25044 \begin_layout LyX-Code
25048 \begin_layout LyX-Code
25049 /* place function test_func at 0x4000 */
25052 \begin_layout LyX-Code
25053 #pragma code test_func 0x4000
25056 \begin_layout LyX-Code
25060 \begin_layout Description
25061 library instructs the linker to use a library module.
25066 \begin_layout LyX-Code
25067 #pragma library module_name
25070 \begin_layout Standard
25075 can be any library or object file (including its path).
25076 Note that there are four reserved keywords which have special meaning.
25080 \begin_layout Standard
25082 \begin_inset Tabular
25083 <lyxtabular version="3" rows="6" columns="3">
25085 <column alignment="center" valignment="top" leftline="true" width="0">
25086 <column alignment="block" valignment="top" leftline="true" width="20page%">
25087 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25088 <row topline="true" bottomline="true">
25089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25092 \begin_layout Standard
25098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25101 \begin_layout Standard
25107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25110 \begin_layout Standard
25117 <row topline="true">
25118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25121 \begin_layout Standard
25129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25132 \begin_layout Standard
25133 ignore all library pragmas
25138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25141 \begin_layout Standard
25150 <row topline="true">
25151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25154 \begin_layout Standard
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25165 \begin_layout Standard
25171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25174 \begin_layout Standard
25185 <row topline="true">
25186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25189 \begin_layout Standard
25197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25200 \begin_layout Standard
25201 link the Math libarary
25206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25209 \begin_layout Standard
25220 <row topline="true">
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25224 \begin_layout Standard
25232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25235 \begin_layout Standard
25236 link the I/O library
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25244 \begin_layout Standard
25255 <row topline="true" bottomline="true">
25256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25259 \begin_layout Standard
25267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25270 \begin_layout Standard
25271 link the debug library
25276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25279 \begin_layout Standard
25296 * is the device number, i.e.
25297 452 for PIC18F452 MCU.
25300 \begin_layout Standard
25301 This feature allows for linking with specific libraries withoug having to
25302 explicit name them in the command line.
25307 keyword will reject all modules specified by the library pragma.
25310 \begin_layout Description
25311 udata The pragma udata instructs the compiler to emit code so that linker
25312 will place a variable at a specific memory bank.
25315 \begin_layout LyX-Code
25319 \begin_layout LyX-Code
25323 \begin_layout LyX-Code
25324 /* places variable foo at bank2 */
25327 \begin_layout LyX-Code
25328 #pragma udata bank2 foo
25331 \begin_layout LyX-Code
25335 \begin_layout Standard
25336 In order for this pragma to work extra SECTION directives should be added
25337 in the .lkr script.
25338 In the following example a sample .lkr file is shown:
25341 \begin_layout LyX-Code
25345 \begin_layout LyX-Code
25346 // Sample linker script for the PIC18F452 processor
25349 \begin_layout LyX-Code
25353 \begin_layout LyX-Code
25354 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
25357 \begin_layout LyX-Code
25358 CODEPAGE NAME=page START=0x2A END=0x7FFF
25361 \begin_layout LyX-Code
25362 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
25365 \begin_layout LyX-Code
25366 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
25369 \begin_layout LyX-Code
25370 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
25373 \begin_layout LyX-Code
25374 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
25377 \begin_layout LyX-Code
25378 ACCESSBANK NAME=accessram START=0x0 END=0x7F
25381 \begin_layout LyX-Code
25385 \begin_layout LyX-Code
25386 DATABANK NAME=gpr0 START=0x80 END=0xFF
25389 \begin_layout LyX-Code
25390 DATABANK NAME=gpr1 START=0x100 END=0x1FF
25393 \begin_layout LyX-Code
25394 DATABANK NAME=gpr2 START=0x200 END=0x2FF
25397 \begin_layout LyX-Code
25398 DATABANK NAME=gpr3 START=0x300 END=0x3FF
25401 \begin_layout LyX-Code
25402 DATABANK NAME=gpr4 START=0x400 END=0x4FF
25405 \begin_layout LyX-Code
25406 DATABANK NAME=gpr5 START=0x500 END=0x5FF
25409 \begin_layout LyX-Code
25410 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
25413 \begin_layout LyX-Code
25417 \begin_layout LyX-Code
25418 SECTION NAME=CONFIG ROM=config
25421 \begin_layout LyX-Code
25425 \begin_layout LyX-Code
25426 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25429 \begin_layout LyX-Code
25430 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25433 \begin_layout LyX-Code
25434 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25437 \begin_layout LyX-Code
25438 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25441 \begin_layout LyX-Code
25442 SECTION NAME=bank4 RAM=gpr4
25445 \begin_layout LyX-Code
25446 SECTION NAME=bank5 RAM=gpr5
25449 \begin_layout Standard
25450 The linker will recognise the section name set in the pragma statement and
25451 will position the variable at the memory bank set with the RAM field at
25452 the SECTION line in the linker script file.
25455 \begin_layout Subsection
25457 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25464 \begin_layout Standard
25465 There is one main header file
25466 \begin_inset LatexCommand \index{PIC16!Header files}
25470 that can be included to the source files using the pic16
25471 \begin_inset LatexCommand \index{PIC16}
25481 This header file contains the definitions for the processor special registers,
25482 so it is necessary if the source accesses them.
25483 It can be included by adding the following line in the beginning of the
25487 \begin_layout LyX-Code
25488 #include <pic18fregs.h>
25491 \begin_layout Standard
25492 The specific microcontroller is selected within the pic18fregs.h automatically,
25493 so the same source can be used with a variety of devices.
25496 \begin_layout Subsection
25500 \begin_layout Standard
25502 \begin_inset LatexCommand \index{PIC16!Libraries}
25507 \begin_inset LatexCommand \index{PIC16}
25511 port depends on are the microcontroller device libraries which contain
25512 the symbol definitions for the microcontroller special function registers.
25513 These libraries have the format pic18fxxxx.lib, where
25517 is the microcontroller identification number.
25518 The specific library is selected automatically by the compiler at link
25519 stage according to the selected device.
25522 \begin_layout Standard
25523 Libraries are created with gplib which is part of the gputils package
25524 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25531 \begin_layout Subsubsection*
25532 Building the libraries
25535 \begin_layout Standard
25536 Before using SDCC/pic16 there are some libraries that need to be compiled.
25537 This process is not done automatically by SDCC since not all users use
25538 SDCC for pic16 projects.
25539 So each user should compile the libraries separately.
25542 \begin_layout Standard
25543 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25546 \begin_layout LyX-Code
25547 cd device/lib/pic16
25550 \begin_layout LyX-Code
25554 \begin_layout LyX-Code
25558 \begin_layout LyX-Code
25562 \begin_layout LyX-Code
25566 \begin_layout LyX-Code
25567 su -c 'make install' # install the libraries, you need the root password
25570 \begin_layout Standard
25571 If you need to install the headers too, do:
25574 \begin_layout LyX-Code
25578 \begin_layout LyX-Code
25579 su -c 'make install' # install the headers, you need the root password
25582 \begin_layout Standard
25583 There exist a special target to build the I/O libraries.
25584 This target is not automatically build because it will build the I/O library
25590 This way building will take quite a lot of time.
25591 Users are advised to edit the
25593 device/lib/pic16/pics.build
25595 file and then execute:
25598 \begin_layout LyX-Code
25602 \begin_layout Subsection
25603 Adding New Devices to the Port
25606 \begin_layout Standard
25607 Adding support for a new 16
25611 \begin_layout Standard
25620 bit PIC MCU requires the following steps:
25623 \begin_layout Enumerate
25624 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25628 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25632 \begin_layout Enumerate
25635 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25638 \begin_layout Enumerate
25641 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25644 \begin_layout Enumerate
25647 /path/to/sdcc/device/lib/pic16/pics.all
25655 Note: No 18f prefix here!
25658 \begin_layout Enumerate
25661 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25665 Add your DEVICE if it does not compile in
25680 \begin_layout Enumerate
25683 /path/to/sdcc/device/include/pic16/pic18fregs.h
25686 The file format is self-explanatory, just add
25690 #elif defined(picDEVICE)
25692 # include <picDEVICE.h>
25696 at the right place (keep it sorted).
25699 \begin_layout Enumerate
25702 /path/to/sdcc/src/pic16/devices.inc
25705 Copy and modify an existing entry and insert it at the correct place (keep
25707 The file is hardly documented, look at the entries for the 18f2221...
25710 \begin_layout Enumerate
25711 Recompile SDCC, including the pic16 libraries.
25714 \begin_layout Subsection
25718 \begin_layout Standard
25719 The following memory models are supported by the PIC16 port:
25722 \begin_layout Itemize
25726 \begin_layout Itemize
25730 \begin_layout Standard
25731 Memory model affects the default size of pointers within the source.
25732 The sizes are shown in the next table:
25735 \begin_layout Standard
25737 \begin_inset Tabular
25738 <lyxtabular version="3" rows="3" columns="3">
25740 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25741 <column alignment="center" valignment="top" leftline="true" width="0">
25742 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25743 <row topline="true" bottomline="true">
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25747 \begin_layout Standard
25748 Pointer sizes according to memory model
25753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25756 \begin_layout Standard
25762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25765 \begin_layout Standard
25772 <row topline="true" bottomline="true">
25773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25776 \begin_layout Standard
25782 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25785 \begin_layout Standard
25791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25794 \begin_layout Standard
25801 <row topline="true" bottomline="true">
25802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25805 \begin_layout Standard
25811 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25814 \begin_layout Standard
25820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25823 \begin_layout Standard
25837 \begin_layout Standard
25838 It is advisable that all sources within a project are compiled with the
25840 If one wants to override the default memory model, this can be done by
25841 declaring a pointer as
25850 Far selects large memory model's pointers, while near selects small memory
25854 \begin_layout Standard
25855 The standard device libraries (see
25856 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25860 ) contain no reference to pointers, so they can be used with both memory
25864 \begin_layout Subsection
25868 \begin_layout Standard
25870 \begin_inset LatexCommand \index{PIC16!stack}
25874 implementation for the PIC16 port uses two indirect registers, FSR1 and
25878 \begin_layout Description
25879 FSR1 is assigned as stack pointer
25882 \begin_layout Description
25883 FSR2 is assigned as frame pointer
25886 \begin_layout Standard
25887 The following stack models are supported by the PIC16 port
25890 \begin_layout Itemize
25898 \begin_layout Itemize
25906 \begin_layout Standard
25911 model means that only the FSRxL byte is used to access stack and frame,
25918 uses both FSRxL and FSRxH registers.
25919 The following table shows the stack/frame pointers sizes according to stack
25920 model and the maximum space they can address:
25923 \begin_layout Standard
25925 \begin_inset Tabular
25926 <lyxtabular version="3" rows="3" columns="3">
25928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25929 <column alignment="center" valignment="top" leftline="true" width="0">
25930 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25931 <row topline="true" bottomline="true">
25932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25935 \begin_layout Standard
25936 Stack & Frame pointer sizes according to stack model
25941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25944 \begin_layout Standard
25950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25953 \begin_layout Standard
25960 <row topline="true">
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25964 \begin_layout Standard
25970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25973 \begin_layout Standard
25979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25982 \begin_layout Standard
25989 <row topline="true" bottomline="true">
25990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25993 \begin_layout Standard
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26002 \begin_layout Standard
26008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26011 \begin_layout Standard
26025 \begin_layout Standard
26030 stack model is currently not working properly throughout the code generator.
26031 So its use is not advised.
26032 Also there are some other points that need special care:
26037 \begin_layout Enumerate
26038 Do not create stack sections with size more than one physical bank (that
26042 \begin_layout Enumerate
26043 Stack sections should no cross physical bank limits (i.e.
26044 #pragma stack 0x50 0x100)
26047 \begin_layout Standard
26048 These limitations are caused by the fact that only FSRxL is modified when
26049 using SMALL stack model, so no more than 256 bytes of stack can be used.
26050 This problem will disappear after LARGE model is fully implemented.
26053 \begin_layout Subsection
26057 \begin_layout Standard
26058 In addition to the standard SDCC function keywords, PIC16
26059 \begin_inset LatexCommand \index{PIC16}
26063 port makes available two more:
26066 \begin_layout Description
26068 \begin_inset LatexCommand \index{PIC16!wparam}
26072 Use the WREG to pass one byte of the first function argument.
26073 This improves speed but you may not use this for functions with arguments
26074 that are called via function pointers, otherwise the first byte of the
26075 first parameter will get lost.
26079 \begin_layout LyX-Code
26080 void func_wparam(int a) wparam
26083 \begin_layout LyX-Code
26087 \begin_layout LyX-Code
26088 /* WREG hold the lower part of a */
26091 \begin_layout LyX-Code
26092 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26096 \begin_layout LyX-Code
26100 \begin_layout LyX-Code
26104 \begin_layout Description
26106 \begin_inset LatexCommand \index{PIC16!shadowregs}
26110 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26111 hardware shadow registers which hold the values of WREG, STATUS and BSR
26113 This can be done by adding the keyword
26121 keyword in the function's header.
26124 \begin_layout LyX-Code
26125 void isr_shadow(void) shadowregs interrupt 1
26128 \begin_layout LyX-Code
26132 \begin_layout LyX-Code
26136 \begin_layout LyX-Code
26140 \begin_layout Standard
26145 instructs the code generator not to store/restore WREG, STATUS, BSR when
26146 entering/exiting the ISR.
26149 \begin_layout Subsection
26150 Function return values
26153 \begin_layout Standard
26154 Return values from functions are placed to the appropriate registers following
26155 a modified Microchip policy optimized for SDCC.
26156 The following table shows these registers:
26159 \begin_layout Standard
26161 \begin_inset Tabular
26162 <lyxtabular version="3" rows="6" columns="2">
26164 <column alignment="center" valignment="top" leftline="true" width="0">
26165 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26166 <row topline="true" bottomline="true">
26167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26170 \begin_layout Standard
26176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26179 \begin_layout Standard
26180 destination register
26186 <row topline="true">
26187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26190 \begin_layout Standard
26196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26199 \begin_layout Standard
26206 <row topline="true">
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26210 \begin_layout Standard
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26219 \begin_layout Standard
26226 <row topline="true">
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26230 \begin_layout Standard
26236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26239 \begin_layout Standard
26246 <row topline="true">
26247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26250 \begin_layout Standard
26256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26259 \begin_layout Standard
26260 FSR0L:PRODH:PRODL:WREG
26266 <row topline="true" bottomline="true">
26267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26270 \begin_layout Standard
26276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26279 \begin_layout Standard
26280 on stack, FSR0 points to the beginning
26293 \begin_layout Subsection
26297 \begin_layout Standard
26299 \begin_inset LatexCommand \index{PIC16!interrupt}
26303 service routine (ISR) is declared using the
26310 \begin_layout LyX-Code
26311 void isr(void) interrupt
26316 \begin_layout LyX-Code
26320 \begin_layout LyX-Code
26324 \begin_layout LyX-Code
26328 \begin_layout Standard
26333 is the interrupt number, which for PIC18F devices can be:
26336 \begin_layout Standard
26338 \begin_inset Tabular
26339 <lyxtabular version="3" rows="4" columns="3">
26341 <column alignment="center" valignment="top" leftline="true" width="0">
26342 <column alignment="center" valignment="top" leftline="true" width="0">
26343 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26344 <row topline="true" bottomline="true">
26345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26348 \begin_layout Standard
26356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26359 \begin_layout Standard
26365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26368 \begin_layout Standard
26369 Interrupt Vector Address
26375 <row topline="true">
26376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26379 \begin_layout Standard
26385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26388 \begin_layout Standard
26394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26397 \begin_layout Standard
26404 <row topline="true">
26405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26408 \begin_layout Standard
26423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26426 \begin_layout Standard
26436 HIGH priority interrupts
26441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26444 \begin_layout Standard
26451 <row topline="true" bottomline="true">
26452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26455 \begin_layout Standard
26461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26464 \begin_layout Standard
26465 LOW priority interrupts
26470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26473 \begin_layout Standard
26487 \begin_layout Standard
26488 When generating assembly code for ISR the code generator places a
26494 Interrupt Vector Address
26496 which points at the genetated ISR.
26497 This single GOTO instruction is part of an automatically generated
26499 interrupt entry point
26502 The actuall ISR code is placed as normally would in the code space.
26503 Upon interrupt request, the GOTO instruction is executed which jumps to
26505 When declaring interrupt functions as _naked this GOTO instruction is
26510 The whole interrupt functions is therefore placed at the Interrupt Vector
26511 Address of the specific interrupt.
26512 This is not a problem for the LOW priority interrupts, but it is a problem
26513 for the RESET and the HIGH priority interrupts because code may be written
26514 at the next interrupt's vector address and cause undeterminate program
26515 behaviour if that interrupt is raised.
26519 \begin_layout Standard
26520 This is not a problem when
26523 \begin_layout Enumerate
26524 this is a HIGH interrupt ISR and LOW interrupts are
26531 \begin_layout Enumerate
26532 when the ISR is small enough not to reach the next interrupt's vector address.
26540 \begin_layout Standard
26546 This way a function is generated similar to an ISR, but it is not assigned
26550 \begin_layout Standard
26551 When entering an interrupt, currently the PIC16
26552 \begin_inset LatexCommand \index{PIC16}
26556 port automatically saves the following registers:
26559 \begin_layout Itemize
26563 \begin_layout Itemize
26567 \begin_layout Itemize
26571 \begin_layout Itemize
26572 PROD (PRODL and PRODH)
26575 \begin_layout Itemize
26576 FSR0 (FSR0L and FSR0H)
26579 \begin_layout Standard
26580 These registers are restored upon return from the interrupt routine.
26584 \begin_layout Standard
26585 NOTE that when the _naked attribute is specified for an interrupt routine,
26586 then NO registers are stored or restored.
26594 \begin_layout Subsection
26598 \begin_layout Standard
26599 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26600 There are 3 types of generic pointers currently implemented data, code
26601 and eeprom pointers.
26602 They are differentiated by the value of the 7th and 6th bits of the upper
26606 \begin_layout Standard
26608 \begin_inset Tabular
26609 <lyxtabular version="3" rows="5" columns="5">
26611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26612 <column alignment="center" valignment="top" width="0">
26613 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26614 <column alignment="center" valignment="top" width="0">
26615 <column alignment="left" valignment="top" rightline="true" width="0">
26616 <row topline="true" bottomline="true">
26617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26620 \begin_layout Standard
26626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26629 \begin_layout Standard
26635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26638 \begin_layout Standard
26644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26647 \begin_layout Standard
26648 rest of the pointer
26653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26656 \begin_layout Standard
26663 <row topline="true" bottomline="true">
26664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26667 \begin_layout Standard
26673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26676 \begin_layout Standard
26682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26685 \begin_layout Standard
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26694 \begin_layout Standard
26699 uuuuuu uuuuxxxx xxxxxxxx
26704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26707 \begin_layout Standard
26708 a 12-bit data pointer in data RAM memory
26714 <row bottomline="true">
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26718 \begin_layout Standard
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26727 \begin_layout Standard
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26736 \begin_layout Standard
26742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26745 \begin_layout Standard
26750 uxxxxx xxxxxxxx xxxxxxxx
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26758 \begin_layout Standard
26759 a 21-bit code pointer in FLASH memory
26765 <row bottomline="true">
26766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26769 \begin_layout Standard
26775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26778 \begin_layout Standard
26784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26787 \begin_layout Standard
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26796 \begin_layout Standard
26801 uuuuuu uuuuuuxx xxxxxxxx
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26809 \begin_layout Standard
26810 a 10-bit eeprom pointer in EEPROM memory
26816 <row bottomline="true">
26817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26820 \begin_layout Standard
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26829 \begin_layout Standard
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26838 \begin_layout Standard
26844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26847 \begin_layout Standard
26852 xxxxxx xxxxxxxx xxxxxxxx
26857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26860 \begin_layout Standard
26861 unimplemented pointer type
26874 \begin_layout Standard
26875 Generic pointer are read and written with a set of library functions which
26876 read/write 1, 2, 3, 4 bytes.
26879 \begin_layout Subsection
26883 \begin_layout Subsubsection
26884 Standard I/O Streams
26887 \begin_layout Standard
26892 the type FILE is defined as:
26895 \begin_layout LyX-Code
26896 typedef char * FILE;
26899 \begin_layout Standard
26900 This type is the stream type implemented I/O in the PIC18F devices.
26901 Also the standard input and output streams are declared in stdio.h:
26904 \begin_layout LyX-Code
26905 extern FILE * stdin;
26908 \begin_layout LyX-Code
26909 extern FILE * stdout;
26912 \begin_layout Standard
26913 The FILE type is actually a generic pointer which defines one more type
26914 of generic pointers, the
26919 This new type has the format:
26922 \begin_layout Standard
26924 \begin_inset Tabular
26925 <lyxtabular version="3" rows="2" columns="7">
26927 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26928 <column alignment="center" valignment="top" width="0">
26929 <column alignment="center" valignment="top" leftline="true" width="0">
26930 <column alignment="center" valignment="top" leftline="true" width="0">
26931 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26932 <column alignment="center" valignment="top" width="0">
26933 <column alignment="left" valignment="top" rightline="true" width="0">
26934 <row topline="true" bottomline="true">
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26938 \begin_layout Standard
26944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26947 \begin_layout Standard
26953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26956 \begin_layout Standard
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26965 \begin_layout Standard
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26974 \begin_layout Standard
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26983 \begin_layout Standard
26984 rest of the pointer
26989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26992 \begin_layout Standard
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
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_layout Standard
27027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27030 \begin_layout Standard
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27039 \begin_layout Standard
27045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27048 \begin_layout Standard
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27061 \begin_layout Standard
27062 upper byte high nubble is 0x2n, the rest are zeroes
27075 \begin_layout Standard
27076 Currently implemented there are 3 types of streams defined:
27079 \begin_layout Standard
27081 \begin_inset Tabular
27082 <lyxtabular version="3" rows="4" columns="4">
27084 <column alignment="center" valignment="top" leftline="true" width="0">
27085 <column alignment="center" valignment="top" leftline="true" width="0">
27086 <column alignment="center" valignment="top" leftline="true" width="0">
27087 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27088 <row topline="true" bottomline="true">
27089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27092 \begin_layout Standard
27098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27101 \begin_layout Standard
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27110 \begin_layout Standard
27116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27119 \begin_layout Standard
27126 <row topline="true">
27127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27130 \begin_layout Standard
27136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27139 \begin_layout Standard
27147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27150 \begin_layout Standard
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27159 \begin_layout Standard
27160 Writes/Reads characters via the USART peripheral
27166 <row topline="true">
27167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27170 \begin_layout Standard
27176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27179 \begin_layout Standard
27187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27190 \begin_layout Standard
27196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27199 \begin_layout Standard
27200 Writes/Reads characters via the MSSP peripheral
27206 <row topline="true" bottomline="true">
27207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27210 \begin_layout Standard
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27219 \begin_layout Standard
27227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27230 \begin_layout Standard
27236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27239 \begin_layout Standard
27240 Writes/Reads characters via used defined functions
27253 \begin_layout Standard
27254 The stream identifiers are declared as macros in the stdio.h header.
27257 \begin_layout Standard
27258 In the libc library there exist the functions that are used to write to
27259 each of the above streams.
27263 \begin_layout Description
27268 \begin_layout Standard
27277 _stream_usart_putchar writes a character at the USART stream
27280 \begin_layout Description
27285 \begin_layout Standard
27294 _stream_mssp_putchar writes a character at the MSSP stream
27297 \begin_layout Description
27298 putchar dummy function.
27299 This writes a character to a user specified manner.
27302 \begin_layout Standard
27303 In order to increase performance
27307 is declared in stdio.h as having its parameter in WREG (it has the wparam
27309 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27310 in a user-friendly way.
27315 is the name of the variable that holds the character to print.
27316 An example follows:
27319 \begin_layout LyX-Code
27320 #include <pic18fregs.h>
27329 \begin_layout LyX-Code
27333 \begin_layout LyX-Code
27334 PORTA = c; /* dump character c to PORTA */
27337 \begin_layout LyX-Code
27345 \begin_layout LyX-Code
27349 \begin_layout LyX-Code
27350 stdout = STREAM_USER; /* this is not necessary, since stdout points
27353 \begin_layout LyX-Code
27354 * by default to STREAM_USER */
27357 \begin_layout LyX-Code
27359 \begin_inset Quotes sld
27362 This is a printf test
27365 \begin_inset Quotes srd
27371 \begin_layout LyX-Code
27375 \begin_layout LyX-Code
27379 \begin_layout Subsubsection
27383 \begin_layout Standard
27384 PIC16 contains an implementation of the printf-family of functions.
27385 There exist the following functions:
27388 \begin_layout LyX-Code
27389 extern unsigned int sprintf(char *buf, char *fmt, ...);
27392 \begin_layout LyX-Code
27393 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27396 \begin_layout LyX-Code
27400 \begin_layout LyX-Code
27401 extern unsigned int printf(char *fmt, ...);
27404 \begin_layout LyX-Code
27405 extern unsigned int vprintf(char *fmt, va_lista ap);
27408 \begin_layout LyX-Code
27412 \begin_layout LyX-Code
27413 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27416 \begin_layout LyX-Code
27417 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27420 \begin_layout Standard
27421 For sprintf and vsprintf
27425 should normally be a data pointer where the resulting string will be placed.
27426 No range checking is done so the user should allocate the necessery buffer.
27427 For fprintf and vfprintf
27431 should be a stream pointer (i.e.
27432 stdout, STREAM_MSSP, etc...).
27435 \begin_layout Subsubsection
27439 \begin_layout Standard
27440 The PIC18F family of microcontrollers supports a number of interrupt sources.
27441 A list of these interrupts is shown in the following table:
27444 \begin_layout Standard
27446 \begin_inset Tabular
27447 <lyxtabular version="3" rows="11" columns="4">
27449 <column alignment="left" valignment="top" leftline="true" width="0">
27450 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27451 <column alignment="left" valignment="top" leftline="true" width="0">
27452 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27453 <row topline="true" bottomline="true">
27454 <cell alignment="center" valignment="top" topline="true" leftline="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
27472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27475 \begin_layout Standard
27481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27484 \begin_layout Standard
27491 <row topline="true">
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27495 \begin_layout Standard
27501 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27504 \begin_layout Standard
27505 PORTB change interrupt
27510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27513 \begin_layout Standard
27519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27522 \begin_layout Standard
27523 EEPROM/FLASH write complete interrupt
27529 <row topline="true">
27530 <cell alignment="center" valignment="top" topline="true" leftline="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 INT0 external interrupt
27548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27551 \begin_layout Standard
27557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27560 \begin_layout Standard
27561 Bus collision interrupt
27567 <row topline="true">
27568 <cell alignment="center" valignment="top" topline="true" leftline="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 INT1 external interrupt
27586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27589 \begin_layout Standard
27595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27598 \begin_layout Standard
27599 Low voltage detect interrupt
27605 <row topline="true">
27606 <cell alignment="center" valignment="top" topline="true" leftline="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
27619 INT2 external interrupt
27624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27627 \begin_layout Standard
27633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27636 \begin_layout Standard
27637 Parallel slave port interrupt
27643 <row topline="true">
27644 <cell alignment="center" valignment="top" topline="true" leftline="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
27657 CCP1 module interrupt
27662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27665 \begin_layout Standard
27671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27674 \begin_layout Standard
27675 AD convertion complete interrupt
27681 <row topline="true">
27682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27685 \begin_layout Standard
27691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27694 \begin_layout Standard
27695 CCP2 module interrupt
27700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27703 \begin_layout Standard
27709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27712 \begin_layout Standard
27713 USART receive interrupt
27719 <row topline="true">
27720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27723 \begin_layout Standard
27729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27732 \begin_layout Standard
27733 TMR0 overflow interrupt
27738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27741 \begin_layout Standard
27747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27750 \begin_layout Standard
27751 USART transmit interrupt
27757 <row topline="true">
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27761 \begin_layout Standard
27767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27770 \begin_layout Standard
27771 TMR1 overflow interrupt
27776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27779 \begin_layout Standard
27785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27788 \begin_layout Standard
27789 SSP receive/transmit interrupt
27795 <row topline="true">
27796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27799 \begin_layout Standard
27805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27808 \begin_layout Standard
27809 TMR2 matches PR2 interrupt
27814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27817 \begin_layout Standard
27823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27826 \begin_layout Standard
27833 <row topline="true" bottomline="true">
27834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27837 \begin_layout Standard
27843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27846 \begin_layout Standard
27847 TMR3 overflow interrupt
27852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27855 \begin_layout Standard
27861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27864 \begin_layout Standard
27878 \begin_layout Standard
27879 The prototypes for these names are defined in the header file
27886 \begin_layout Standard
27887 In order to simplify signal handling, a number of macros is provided:
27891 \labelwidthstring 00.00.0000
27892 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27893 high priority interrupts.
27898 is the function name to use.
27902 \labelwidthstring 00.00.0000
27903 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27904 low priority interrupt.
27909 is the function name to use.
27913 \labelwidthstring 00.00.0000
27914 DEF_HANDLER(sig,handler) define a handler for signal
27920 \labelwidthstring 00.00.0000
27921 END_DEF end the declaration of the dispatch table.
27924 \begin_layout Standard
27925 Additionally there are two more macros to simplify the declaration of the
27930 \labelwidthstring 00.00.0000
27933 SIGHANDLER(handler)
27935 this declares the function prototype for the
27943 \labelwidthstring 00.00.0000
27944 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27947 \begin_layout Standard
27948 An example of using the macros above is shown below:
27951 \begin_layout LyX-Code
27952 #include <pic18fregs.h>
27955 \begin_layout LyX-Code
27956 #include <signal.h>
27960 DEF_INTHIGH(high_int)
27963 \begin_layout LyX-Code
27964 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27967 \begin_layout LyX-Code
27968 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27971 \begin_layout LyX-Code
27976 SIGHANDLER(_tmr0_handler)
27979 \begin_layout LyX-Code
27983 \begin_layout LyX-Code
27984 /* action to be taken when timer 0 overflows */
27987 \begin_layout LyX-Code
27992 SIGHANDLERNAKED(_bcol_handler)
27995 \begin_layout LyX-Code
27999 \begin_layout LyX-Code
28003 \begin_layout LyX-Code
28004 /* action to be taken when bus collision occurs */
28007 \begin_layout LyX-Code
28011 \begin_layout LyX-Code
28015 \begin_layout LyX-Code
28019 \begin_layout Standard
28024 Special care should be taken when using the above scheme:
28027 \begin_layout Itemize
28028 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28031 \begin_layout Itemize
28032 when declaring SIGHANDLERNAKED handler never forget to use
28036 for proper returning.
28039 \begin_layout Subsection
28043 \begin_layout Standard
28044 Here you can find some general tips for compiling programs with SDCC/pic16.
28047 \begin_layout Subsubsection
28051 \begin_layout Standard
28053 \begin_inset LatexCommand \index{PIC16!stack}
28057 size (that is 64 bytes) probably is enough for many programs.
28058 One must take care that when there are many levels of function nesting,
28059 or there is excessive usage of stack, its size should be extended.
28060 An example of such a case is the printf/sprintf family of functions.
28061 If you encounter problems like not being able to print integers, then you
28062 need to set the stack size around the maximum (256 for small stack model).
28063 The following diagram shows what happens when calling printf to print an
28067 \begin_layout LyX-Code
28068 printf () --> ltoa () --> ultoa () --> divschar ()
28071 \begin_layout Standard
28072 It is should be understood that stack is easily consumed when calling complicate
28074 Using command line arguments like -
28078 \begin_layout Standard
28087 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28089 Other ways to reduce stack usage may exist.
28092 \begin_layout Subsection
28096 \begin_layout Standard
28097 The PIC16 Port currently does not pass SDCC's regression test
28098 \begin_inset LatexCommand \index{Regression test (PIC16)}
28103 \begin_inset LatexCommand \ref{sec:Quality-control}
28107 ) and thus the snapshot build regression tests for the PIC16 target are
28108 currently disabled for all hosts
28113 \begin_layout Chapter
28117 \begin_layout Standard
28118 There are several approaches to debugging your code.
28119 This chapter is meant to show your options and to give detail on some of
28124 When writing your code:
28127 \begin_layout Itemize
28128 write your code with debugging in mind (avoid duplicating code, put conceptually
28129 similar variables into structs, use structured code, have strategic points
28130 within your code where all variables are consistent, ...)
28133 \begin_layout Itemize
28134 run a syntax-checking tool like splint
28135 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28140 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28148 \begin_layout Standard
28158 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28165 \begin_layout Itemize
28166 for the high level code use a C-compiler (like f.e.
28167 GCC) to compile run and debug the code on your host.
28172 \begin_layout Standard
28182 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28186 ) on how to handle syntax extensions like __xdata, __at(), ...
28190 \begin_layout Itemize
28191 use another C-compiler to compile code for your target.
28192 Always an option but not recommended:) And not very likely to help you.
28193 If you seriously consider walking this path you should at least occasionally
28194 check portability of your code.
28195 Most commercial compiler vendors will offer an evaluation version so you
28196 can test compile your code or snippets of your code.
28199 \begin_layout Standard
28200 Debugging on a simulator:
28203 \begin_layout Itemize
28204 there is a separate section about SDCDB (section
28205 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28212 \begin_layout Itemize
28213 or (8051 specific) use a freeware/commercial simulator which interfaces
28215 \begin_inset LatexCommand \index{AOMF, AOMF51}
28220 \begin_inset LatexCommand \ref{OMF file}
28224 ) optionally generated by SDCC.
28227 \begin_layout Standard
28228 Debugging On-target:
28231 \begin_layout Itemize
28232 use a MCU port pin to serially output debug data to the RS232 port of your
28234 You'll probably want some level shifting device typically involving a MAX232
28236 If the hardware serial port of the MCU is not available search for 'Software
28237 UART' in your favourite search machine.
28240 \begin_layout Itemize
28241 use an on-target monitor.
28242 In this context a monitor is a small program which usually accepts commands
28243 via a serial line and allows to set program counter, to single step through
28244 a program and read/write memory locations.
28245 For the 8051 good examples of monitors are paulmon and cmon51 (see section
28247 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28254 \begin_layout Itemize
28255 toggle MCU port pins at strategic points within your code and use an oscilloscop
28259 digital oscilloscope
28262 \begin_inset LatexCommand \index{Oscilloscope}
28266 with deep trace memory is really helpful especially if you have to debug
28267 a realtime application.
28268 If you need to monitor more pins than your oscilloscope provides you can
28269 sometimes get away with a small R-2R network.
28270 On a single channel oscilloscope you could f.e.
28271 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28273 \begin_inset Formula $\Omega$
28276 resistor and the other one by a 5\InsetSpace ~
28278 \begin_inset Formula $\Omega$
28281 resistor to the oscilloscope probe (check output drive capability of the
28282 pins you want to monitor).
28283 If you need to monitor many more pins a
28290 \begin_layout Itemize
28304 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28309 Usually very expensive.
28310 And very nice to have too.
28311 And usually locks you (for years...) to the devices the ICE can emulate.
28315 \begin_layout Itemize
28316 use a remote debugger.
28317 In most 8-bit systems the symbol information is not available on the target,
28318 and a complete debugger is too bulky for the target system.
28319 Therefore usually a debugger on the host system connects to an on-target
28320 debugging stub which accepts only primitive commands.
28323 Terms to enter into your favourite search engine could be 'remote debugging',
28324 'gdb stub' or 'inferior debugger'.
28328 \begin_layout Itemize
28329 use an on target hardware debugger.
28330 Some of the more modern MCUs include hardware support for setting break
28331 points and monitoring/changing variables by using dedicated hardware pins.
28332 This facility doesn't require additional code to run on the target and
28337 doesn't affect runtime behaviour until a breakpoint is hit.
28338 For the mcs51 most hardware debuggers use the AOMF
28339 \begin_inset LatexCommand \index{AOMF, AOMF51}
28344 \begin_inset LatexCommand \ref{OMF file}
28352 \begin_layout Standard
28356 \begin_layout Itemize
28357 if you are not familiar with any of the following terms you're likely to
28358 run into problems rather sooner than later:
28375 As an embedded programmer you
28379 to know them so why not look them up
28383 you have problems?)
28386 \begin_layout Itemize
28387 tell someone else about your problem (actually this is a surprisingly effective
28388 means to hunt down the bug even if the listener is not familiar with your
28390 As 'failure to communicate' is probably one of the job-induced deformations
28391 of an embedded programmer this is highly encouraged.
28394 \begin_layout Section
28395 Debugging with SDCDB
28396 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28401 \begin_inset LatexCommand \index{SDCDB (debugger)}
28408 \begin_layout Standard
28409 SDCC is distributed with a source level debugger
28410 \begin_inset LatexCommand \index{Debugger}
28415 The debugger uses a command line interface, the command repertoire of the
28416 debugger has been kept as close to gdb
28417 \begin_inset LatexCommand \index{gdb}
28421 (the GNU debugger) as possible.
28422 The configuration and build process is part of the standard compiler installati
28423 on, which also builds and installs the debugger in the target directory
28424 specified during configuration.
28425 The debugger allows you debug BOTH at the C source and at the ASM source
28429 \begin_layout Subsection
28430 Compiling for Debugging
28433 \begin_layout Standard
28438 \begin_layout Standard
28448 \begin_inset LatexCommand \index{-\/-debug}
28452 option must be specified for all files for which debug information is to
28454 The compiler generates a .adb file for each of these files.
28455 The linker creates the .cdb
28456 \begin_inset LatexCommand \index{<file>.cdb}
28461 \begin_inset LatexCommand \index{<file>.adb}
28465 files and the address information.
28466 This .cdb is used by the debugger.
28469 \begin_layout Subsection
28470 How the Debugger Works
28473 \begin_layout Standard
28478 \begin_layout Standard
28487 -debug option is specified the compiler generates extra symbol information
28488 some of which are put into the assembler source and some are put into the
28490 Then the linker creates the .cdb file from the individual .adb files with
28491 the address information for the symbols.
28492 The debugger reads the symbolic information generated by the compiler &
28493 the address information generated by the linker.
28494 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28495 execution is controlled by the debugger.
28496 When a command is issued for the debugger, it translates it into appropriate
28497 commands for the simulator.
28498 (Currently SDCDM only connects to the simulator but
28503 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28507 is an effort to connect directly to the hardware.)
28510 \begin_layout Subsection
28511 Starting the Debugger SDCDB
28514 \begin_layout Standard
28515 The debugger can be started using the following command line.
28516 (Assume the file you are debugging has the file name foo).
28530 The debugger will look for the following files.
28533 \begin_layout Itemize
28534 foo.c - the source file.
28537 \begin_layout Itemize
28538 foo.cdb - the debugger symbol information file.
28541 \begin_layout Itemize
28542 foo.ihx - the Intel hex format
28543 \begin_inset LatexCommand \index{Intel hex format}
28550 \begin_layout Subsection
28551 SDCDB Command Line Options
28554 \begin_layout Itemize
28559 \begin_layout Standard
28568 -directory=<source file directory> this option can used to specify the directory
28570 The debugger will look into the directory list specified for source, cdb
28572 The items in the directory list must be separated by ':', e.g.
28573 if the source files can be in the directories /home/src1 and /home/src2,
28578 \begin_layout Standard
28587 -directory option should be -
28591 \begin_layout Standard
28600 -directory=/home/src1:/home/src2.
28601 Note there can be no spaces in the option.
28605 \begin_layout Itemize
28606 -cd <directory> - change to the <directory>.
28609 \begin_layout Itemize
28610 -fullname - used by GUI front ends.
28613 \begin_layout Itemize
28614 -cpu <cpu-type> - this argument is passed to the simulator please see the
28615 simulator docs for details.
28618 \begin_layout Itemize
28619 -X <Clock frequency > this options is passed to the simulator please see
28620 the simulator docs for details.
28623 \begin_layout Itemize
28624 -s <serial port file> passed to simulator see the simulator docs for details.
28627 \begin_layout Itemize
28628 -S <serial in,out> passed to simulator see the simulator docs for details.
28631 \begin_layout Itemize
28632 -k <port number> passed to simulator see the simulator docs for details.
28635 \begin_layout Subsection
28636 SDCDB Debugger Commands
28639 \begin_layout Standard
28640 As mentioned earlier the command interface for the debugger has been deliberatel
28641 y kept as close the GNU debugger gdb, as possible.
28642 This will help the integration with existing graphical user interfaces
28643 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28644 If you use a graphical user interface for the debugger you can skip this
28648 \begin_layout Subsubsection*
28649 break [line | file:line | function | file:function]
28652 \begin_layout Standard
28653 Set breakpoint at specified line or function:
28662 sdcdb>break foo.c:100
28664 sdcdb>break funcfoo
28666 sdcdb>break foo.c:funcfoo
28669 \begin_layout Subsubsection*
28670 clear [line | file:line | function | file:function ]
28673 \begin_layout Standard
28674 Clear breakpoint at specified line or function:
28683 sdcdb>clear foo.c:100
28685 sdcdb>clear funcfoo
28687 sdcdb>clear foo.c:funcfoo
28690 \begin_layout Subsubsection*
28694 \begin_layout Standard
28695 Continue program being debugged, after breakpoint.
28698 \begin_layout Subsubsection*
28702 \begin_layout Standard
28703 Execute till the end of the current function.
28706 \begin_layout Subsubsection*
28710 \begin_layout Standard
28711 Delete breakpoint number 'n'.
28712 If used without any option clear ALL user defined break points.
28715 \begin_layout Subsubsection*
28716 info [break | stack | frame | registers ]
28719 \begin_layout Itemize
28720 info break - list all breakpoints
28723 \begin_layout Itemize
28724 info stack - show the function call stack.
28727 \begin_layout Itemize
28728 info frame - show information about the current execution frame.
28731 \begin_layout Itemize
28732 info registers - show content of all registers.
28735 \begin_layout Subsubsection*
28739 \begin_layout Standard
28740 Step program until it reaches a different source line.
28741 Note: pressing <return> repeats the last command.
28744 \begin_layout Subsubsection*
28748 \begin_layout Standard
28749 Step program, proceeding through subroutine calls.
28752 \begin_layout Subsubsection*
28756 \begin_layout Standard
28757 Start debugged program.
28760 \begin_layout Subsubsection*
28764 \begin_layout Standard
28765 Print type information of the variable.
28768 \begin_layout Subsubsection*
28772 \begin_layout Standard
28773 print value of variable.
28776 \begin_layout Subsubsection*
28780 \begin_layout Standard
28781 load the given file name.
28782 Note this is an alternate method of loading file for debugging.
28785 \begin_layout Subsubsection*
28789 \begin_layout Standard
28790 print information about current frame.
28793 \begin_layout Subsubsection*
28797 \begin_layout Standard
28798 Toggle between C source & assembly source.
28801 \begin_layout Subsubsection*
28802 ! simulator command
28805 \begin_layout Standard
28806 Send the string following '!' to the simulator, the simulator response is
28808 Note the debugger does not interpret the command being sent to the simulator,
28809 so if a command like 'go' is sent the debugger can loose its execution
28810 context and may display incorrect values.
28813 \begin_layout Subsubsection*
28817 \begin_layout Standard
28820 My name is Bobby Brown"
28823 \begin_layout Subsection
28824 Interfacing SDCDB with DDD
28827 \begin_layout Standard
28828 \begin_inset Note Note
28831 \begin_layout Standard
28832 The screenshot was converted from png to eps with:
28833 \begin_inset Quotes sld
28836 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28837 \begin_inset Quotes srd
28840 which produces a pretty compact eps file which is free from compression
28844 \begin_layout Standard
28845 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28846 as this broke the build system on Sourceforge (pdf-file was broken.
28847 pdflatex does not accept eps files).
28855 \begin_layout Standard
28871 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28877 shows a screenshot of a debugging session with DDD
28878 \begin_inset LatexCommand \index{DDD (debugger)}
28882 (Unix only) on a simulated 8032.
28883 The debugging session might not run as smoothly as the screenshot suggests.
28884 The debugger allows setting of breakpoints, displaying and changing variables,
28885 single stepping through C and assembler code.
28888 The source was compiled with
28902 \begin_layout Standard
28914 -debug ddd_example.c
28927 and DDD was invoked with
28934 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28937 \begin_layout Standard
28938 \begin_inset Note Note
28941 \begin_layout Standard
28942 Check that the double quotes or an apostroph within the command line survive
28943 the LyX tool chain.
28944 Previously the apostrophs got slanted in the PDF output so a cut and paste
28953 \begin_layout Subsection
28954 Interfacing SDCDB with XEmacs
28955 \begin_inset LatexCommand \index{XEmacs}
28960 \begin_inset LatexCommand \index{Emacs}
28967 \begin_layout Standard
28968 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28969 sdcdb.el and sdcdbsrc.el.
28970 These two files can be found in the $(prefix)/bin directory after the installat
28972 These files need to be loaded into XEmacs for the interface to work.
28973 This can be done at XEmacs startup time by inserting the following into
28974 your '.xemacs' file (which can be found in your HOME directory):
28980 (load-file sdcdbsrc.el)
28986 .xemacs is a lisp file so the () around the command is REQUIRED.
28987 The files can also be loaded dynamically while XEmacs is running, set the
28988 environment variable 'EMACSLOADPATH' to the installation bin directory
28989 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28990 To start the interface enter the following command:
29004 You will prompted to enter the file name to be debugged.
29009 The command line options that are passed to the simulator directly are
29010 bound to default values in the file sdcdbsrc.el.
29011 The variables are listed below, these values maybe changed as required.
29014 \begin_layout Itemize
29015 sdcdbsrc-cpu-type '51
29018 \begin_layout Itemize
29019 sdcdbsrc-frequency '11059200
29022 \begin_layout Itemize
29023 sdcdbsrc-serial nil
29026 \begin_layout Standard
29027 The following is a list of key mapping for the debugger interface.
29030 \begin_layout Standard
29053 binding\InsetSpace ~
29091 -------\InsetSpace ~
29162 sdcdb-back-from-src\InsetSpace ~
29191 rom-src\InsetSpace ~
29201 SDCDB continue command
29219 sdcdb-step-from-src\InsetSpace ~
29248 hatis-c-sexp\InsetSpace ~
29258 SDCDB ptypecommand for data at
29325 sdcdbsrc-delete\InsetSpace ~
29340 B Delete all breakpoints if no arg
29389 given or delete arg (C-u arg x)
29408 -frame\InsetSpace ~
29423 SDCDB Display current frame if no arg,
29472 given or display frame arg
29540 sdcdbsrc-goto-sdcdb\InsetSpace ~
29550 Goto the SDCDB output buffer
29569 t-c-sexp\InsetSpace ~
29580 SDCDB print command for data at
29647 sdcdbsrc-goto-sdcdb\InsetSpace ~
29658 o the SDCDB output buffer
29676 sdcdbsrc-mode\InsetSpace ~
29692 Toggles Sdcdbsrc mode (turns it
29708 sdcdb-finish-from-src\InsetSpace ~
29716 SDCDB finish command
29750 Set break for line with point
29765 sdcdbsrc-mode\InsetSpace ~
29781 Toggle Sdcdbsrc mode
29797 dbsrc-srcmode\InsetSpace ~
29821 \begin_layout Chapter
29825 \begin_layout Standard
29826 Here are a few guidelines that will help the compiler generate more efficient
29827 code, some of the tips are specific to this compiler others are generally
29828 good programming practice.
29831 \begin_layout Itemize
29832 Use the smallest data type to represent your data-value.
29833 If it is known in advance that the value is going to be less than 256 then
29834 use an 'unsigned char' instead of a 'short' or 'int'.
29835 Please note, that ANSI C requires both signed and unsigned chars to be
29836 promoted to 'signed int'
29837 \begin_inset LatexCommand \index{promotion to signed int}
29842 \begin_inset Marginal
29845 \begin_layout Standard
29854 before doing any operation.
29856 \begin_inset LatexCommand \index{type promotion}
29861 \begin_inset LatexCommand \label{type promotion}
29865 can be omitted, if the result is the same.
29866 The effect of the promotion rules together with the sign-extension is often
29871 \begin_layout Verse
29874 unsigned char uc = 0xfe;
29876 if (uc * uc < 0) /* this is true! */
29889 \begin_layout Standard
29896 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29904 \begin_layout Verse
29907 (unsigned char) -12 / (signed char) -3 = ...
29910 \begin_layout Standard
29911 No, the result is not 4:
29914 \begin_layout Verse
29917 (int) (unsigned char) -12 / (int) (signed char) -3 =
29919 (int) (unsigned char)
29920 0xf4 / (int) (signed char) 0xfd =
29922 (int) 0x00f4 / (int) 0xfffd =
29927 (int) 244 / (int) -3 =
29929 (int) -81 = (int) 0xffaf;
29932 \begin_layout Standard
29933 Don't complain, that gcc gives you a different result.
29934 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29935 Therefore the results are different.
29938 \begin_inset Quotes sld
29942 \begin_inset Quotes srd
29948 \begin_layout Quote
29951 If well-defined overflow characteristics are important and negative values
29952 are not, or if you want to steer clear of sign-extension problems when
29953 manipulating bits or bytes, use one of the corresponding unsigned types.
29954 (Beware when mixing signed and unsigned values in expressions, though.)
29957 character types (especially unsigned char) can be used as "tiny" integers,
29958 doing so is sometimes more trouble than it's worth, due to unpredictable
29959 sign extension and increased code size.
29963 \begin_layout Itemize
29964 Use unsigned when it is known in advance that the value is not going to
29966 This helps especially if you are doing division or multiplication, bit-shifting
29967 or are using an array index.
29970 \begin_layout Itemize
29971 NEVER jump into a LOOP.
29974 \begin_layout Itemize
29975 Declare the variables to be local
29976 \begin_inset LatexCommand \index{local variables}
29980 whenever possible, especially loop control variables (induction).
29983 \begin_layout Itemize
29984 Have a look at the assembly listing to get a
29985 \begin_inset Quotes sld
29989 \begin_inset Quotes srd
29992 for the code generation.
29995 \begin_layout Section
29996 Porting code from or to other compilers
29997 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30004 \begin_layout Itemize
30005 check whether endianness of the compilers differs and adapt where needed.
30008 \begin_layout Itemize
30009 check the device specific header files
30010 \begin_inset LatexCommand \index{Header files}
30015 \begin_inset LatexCommand \index{Include files}
30019 for compiler specific syntax.
30020 Eventually include the file <compiler.h
30021 \begin_inset LatexCommand \index{compiler.h (include file)}
30026 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30030 to allow using common header files.
30033 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30040 \begin_layout Itemize
30041 check whether the startup code contains the correct initialization (watchdog,
30045 \begin_layout Itemize
30046 check whether the sizes of short, int, long match.
30049 \begin_layout Itemize
30050 check if some 16 or 32 bit hardware registers require a specific addressing
30051 order (least significant or most significant byte first) and adapt if needed
30060 relate to time and not to lower/upper memory location here, so this is
30065 the same as endianness).
30068 \begin_layout Itemize
30069 check whether the keyword
30073 is used where needed.
30074 The compilers might differ in their optimization characteristics (as different
30075 versions of the same compiler might also use more clever optimizations
30076 this is good idea anyway).
30078 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30085 \begin_layout Itemize
30086 check that the compilers are not told to supress warnings.
30089 \begin_layout Itemize
30090 check and convert compiler specific extensions (interrupts, memory areas,
30094 \begin_layout Itemize
30095 check for differences in type promotion.
30096 Especially check for math operations on
30105 For the sake of C99 compatibility SDCC will probably promote these to
30109 more often than other compilers.
30110 Eventually insert explicit casts to
30119 Also check that the ~\InsetSpace ~
30121 \begin_inset LatexCommand \index{\~\/ Operator}
30128 \begin_inset LatexCommand \index{bit}
30134 variables, use the !\InsetSpace ~
30137 \begin_inset LatexCommand \ref{type promotion}
30142 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30149 \begin_layout Itemize
30150 check the assembly code generated for interrupt routines (f.e.
30151 for calls to possibly non-reentrant library functions).
30154 \begin_layout Itemize
30155 check whether timing loops result in proper timing (or preferably consider
30156 a rewrite of the code with timer based delays instead).
30159 \begin_layout Itemize
30160 check for differences in printf parameters (some compilers push (va_arg
30161 \begin_inset LatexCommand \index{vararg, va\_arg}
30165 ) char variables as
30169 others push them as
30175 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30182 \begin_layout Itemize
30183 check the resulting memory map
30184 \begin_inset LatexCommand \index{Memory map}
30189 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30190 ly idata, pdata, xdata).
30191 Eventually check if unexpected library functions are included.
30194 \begin_layout Section
30196 \begin_inset LatexCommand \index{Tools}
30200 included in the distribution
30203 \begin_layout Standard
30205 \begin_inset Tabular
30206 <lyxtabular version="3" rows="12" columns="3">
30208 <column alignment="left" valignment="top" leftline="true" width="0pt">
30209 <column alignment="left" valignment="top" leftline="true" width="0pt">
30210 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30211 <row topline="true" bottomline="true">
30212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30215 \begin_layout Standard
30223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30226 \begin_layout Standard
30234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30237 \begin_layout Standard
30246 <row topline="true">
30247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30250 \begin_layout Standard
30252 \begin_inset LatexCommand \index{uCsim}
30261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30264 \begin_layout Standard
30265 Simulator for various architectures
30270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30273 \begin_layout Standard
30280 <row topline="true">
30281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30284 \begin_layout Standard
30290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30293 \begin_layout Standard
30295 \begin_inset LatexCommand \index{Header files}
30300 \begin_inset LatexCommand \index{Include files}
30309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30312 \begin_layout Standard
30313 sdcc/support/scripts
30319 <row topline="true">
30320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30323 \begin_layout Standard
30329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30332 \begin_layout Standard
30333 header file conversion
30338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30341 \begin_layout Standard
30342 sdcc/support/scripts
30348 <row topline="true">
30349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30352 \begin_layout Standard
30358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30361 \begin_layout Standard
30367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30370 \begin_layout Standard
30386 <row topline="true">
30387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30390 \begin_layout Standard
30396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30399 \begin_layout Standard
30405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30408 \begin_layout Standard
30424 <row topline="true">
30425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30428 \begin_layout Standard
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30437 \begin_layout Standard
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30446 \begin_layout Standard
30462 <row topline="true">
30463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30466 \begin_layout Standard
30472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30475 \begin_layout Standard
30481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30484 \begin_layout Standard
30500 <row topline="true">
30501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30504 \begin_layout Standard
30510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30513 \begin_layout Standard
30519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30522 \begin_layout Standard
30538 <row topline="true">
30539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30542 \begin_layout Standard
30548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30551 \begin_layout Standard
30557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30560 \begin_layout Standard
30576 <row topline="true">
30577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30580 \begin_layout Standard
30586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30589 \begin_layout Standard
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30598 \begin_layout Standard
30614 <row topline="true" bottomline="true">
30615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30618 \begin_layout Standard
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30627 \begin_layout Standard
30629 \begin_inset LatexCommand \index{packihx (tool)}
30638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30641 \begin_layout Standard
30666 \begin_layout Section
30668 \begin_inset LatexCommand \index{Documentation}
30672 included in the distribution
30675 \begin_layout Standard
30677 \begin_inset Tabular
30678 <lyxtabular version="3" rows="10" columns="2">
30680 <column alignment="block" valignment="top" leftline="true" width="40col%">
30681 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30682 <row topline="true" bottomline="true" endhead="true">
30683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30686 \begin_layout Standard
30694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30697 \begin_layout Standard
30700 Filename / Where to get
30706 <row topline="true">
30707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30710 \begin_layout Standard
30711 SDCC Compiler User Guide
30716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30719 \begin_layout Standard
30720 You're reading it right now
30732 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30742 <row topline="true">
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30746 \begin_layout Standard
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30755 \begin_layout Standard
30768 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30778 <row topline="true">
30779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30782 \begin_layout Standard
30784 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30789 \begin_inset LatexCommand \index{Assembler documentation}
30796 \begin_inset LatexCommand \index{aslink}
30801 \begin_inset LatexCommand \index{Linker documentation}
30810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30813 \begin_layout Standard
30814 sdcc/as/doc/asxhtm.html
30826 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30836 <row topline="true">
30837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30840 \begin_layout Standard
30841 SDCC regression test
30842 \begin_inset LatexCommand \index{Regression test}
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30854 \begin_layout Standard
30855 sdcc/doc/test_suite_spec.pdf
30867 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30877 <row topline="true">
30878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30881 \begin_layout Standard
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30890 \begin_layout Standard
30903 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30913 <row topline="true">
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30917 \begin_layout Standard
30918 Notes on debugging with SDCDB
30919 \begin_inset LatexCommand \index{SDCDB (debugger)}
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30931 \begin_layout Standard
30932 sdcc/debugger/README
30944 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30954 <row topline="true">
30955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30958 \begin_layout Standard
30960 \begin_inset LatexCommand \index{uCsim}
30964 Software simulator for microcontrollers
30969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30972 \begin_layout Standard
31002 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31012 <row topline="true">
31013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31016 \begin_layout Standard
31017 Temporary notes on the pic16
31018 \begin_inset LatexCommand \index{PIC16}
31027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31030 \begin_layout Standard
31031 sdcc/src/pic16/NOTES
31043 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31053 <row topline="true" bottomline="true">
31054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31057 \begin_layout Standard
31058 SDCC internal documentation (debugging file format)
31063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31066 \begin_layout Standard
31096 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31115 \begin_layout Section
31116 Related open source tools
31117 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31122 \begin_inset LatexCommand \index{Related tools}
31129 \begin_layout Standard
31131 \begin_inset Tabular
31132 <lyxtabular version="3" rows="16" columns="3">
31134 <column alignment="left" valignment="top" leftline="true" width="0pt">
31135 <column alignment="block" valignment="top" leftline="true" width="30line%">
31136 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31137 <row topline="true" bottomline="true">
31138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31141 \begin_layout Standard
31149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31152 \begin_layout Standard
31160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31163 \begin_layout Standard
31172 <row topline="true">
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31176 \begin_layout Standard
31178 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31190 \begin_layout Standard
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31199 \begin_layout Standard
31200 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31210 <row topline="true">
31211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31214 \begin_layout Standard
31216 \begin_inset LatexCommand \index{gputils (pic tools)}
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_layout Standard
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31237 \begin_layout Standard
31238 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31248 <row topline="true">
31249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31252 \begin_layout Standard
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31261 \begin_layout Standard
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31270 \begin_layout Standard
31271 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31281 <row topline="true">
31282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31285 \begin_layout Standard
31291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31294 \begin_layout Standard
31295 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31304 \begin_layout Standard
31305 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31315 <row topline="true">
31316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31319 \begin_layout Standard
31321 \begin_inset LatexCommand \index{indent (source formatting tool)}
31330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31333 \begin_layout Standard
31334 Formats C source - Master of the white spaces
31339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31342 \begin_layout Standard
31343 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31353 <row topline="true">
31354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31357 \begin_layout Standard
31359 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31371 \begin_layout Standard
31372 Object file conversion, checksumming, ...
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31380 \begin_layout Standard
31381 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31391 <row topline="true">
31392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31395 \begin_layout Standard
31397 \begin_inset LatexCommand \index{objdump (tool)}
31406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31409 \begin_layout Standard
31410 Object file conversion, ...
31415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31418 \begin_layout Standard
31419 Part of binutils (should be there anyway)
31425 <row topline="true">
31426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31429 \begin_layout Standard
31435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31438 \begin_layout Standard
31439 8051 monitor (hex up-/download, single step, disassemble)
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31447 \begin_layout Standard
31448 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31458 <row topline="true">
31459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31462 \begin_layout Standard
31464 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31476 \begin_layout Standard
31477 Source code documentation system
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31485 \begin_layout Standard
31486 \begin_inset LatexCommand \url{http://www.doxygen.org}
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31500 \begin_layout Standard
31506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31509 \begin_layout Standard
31510 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31518 \begin_layout Standard
31519 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31529 <row topline="true">
31530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31533 \begin_layout Standard
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31542 \begin_layout Standard
31543 8051 monitor (hex up-/download, single step, disassemble)
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31551 \begin_layout Standard
31552 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31562 <row topline="true">
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31566 \begin_layout Standard
31568 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31580 \begin_layout Standard
31581 Statically checks c sources (see
31582 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31594 \begin_layout Standard
31595 \begin_inset LatexCommand \url{http://www.splint.org}
31605 <row topline="true" bottomline="true">
31606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31609 \begin_layout Standard
31611 \begin_inset LatexCommand \index{DDD (debugger)}
31620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31623 \begin_layout Standard
31624 Debugger, serves nicely as GUI to SDCDB
31625 \begin_inset LatexCommand \index{SDCDB (debugger)}
31634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31637 \begin_layout Standard
31638 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31648 <row bottomline="true">
31649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31652 \begin_layout Standard
31654 \begin_inset LatexCommand \index{d52}
31659 \begin_inset LatexCommand \index{d52 (disassembler)}
31668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31671 \begin_layout Standard
31672 Disassembler, can count instruction cycles
31673 \begin_inset LatexCommand \index{instruction cycles (count)}
31677 , use with options -pnd
31682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31685 \begin_layout Standard
31686 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31696 <row bottomline="true">
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31700 \begin_layout Standard
31702 \begin_inset LatexCommand \index{cmake}
31711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31714 \begin_layout Standard
31715 Cross platform build system, generates Makefiles
31716 \begin_inset LatexCommand \index{Makefile}
31720 and project workspaces
31721 \begin_inset LatexCommand \index{project workspace}
31730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31733 \begin_layout Standard
31734 \begin_inset LatexCommand \url{http://www.cmake.org}
31742 and a dedicated wiki entry:
31743 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
31762 \begin_layout Section
31763 Related documentation / recommended reading
31766 \begin_layout Standard
31768 \begin_inset Tabular
31769 <lyxtabular version="3" rows="7" columns="3">
31771 <column alignment="left" valignment="top" leftline="true" width="0pt">
31772 <column alignment="left" valignment="top" leftline="true" width="0">
31773 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31774 <row topline="true" bottomline="true">
31775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31778 \begin_layout Standard
31786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31789 \begin_layout Standard
31797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31800 \begin_layout Standard
31809 <row topline="true">
31810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31813 \begin_layout Standard
31828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31831 \begin_layout Standard
31833 \begin_inset LatexCommand \index{C Reference card}
31842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31845 \begin_layout Standard
31846 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31856 <row topline="true">
31857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31860 \begin_layout Standard
31866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31869 \begin_layout Standard
31871 \begin_inset LatexCommand \index{C FAQ}
31880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31883 \begin_layout Standard
31884 \begin_inset LatexCommand \url{http://www.c-faq.com}
31894 <row topline="true">
31895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31898 \begin_layout Standard
31904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31907 \begin_layout Standard
31908 \begin_inset Quotes sld
31912 \begin_inset Quotes srd
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31923 \begin_layout Standard
31926 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31936 <row topline="true">
31937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31940 \begin_layout Standard
31946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31949 \begin_layout Standard
31950 \begin_inset Quotes sld
31953 Extensions for Embedded C
31954 \begin_inset Quotes srd
31962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31965 \begin_layout Standard
31968 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31978 <row topline="true">
31979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31982 \begin_layout Standard
31988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31991 \begin_layout Standard
31992 Latest datasheet of target CPU
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32000 \begin_layout Standard
32007 <row topline="true" bottomline="true">
32008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32011 \begin_layout Standard
32017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32020 \begin_layout Standard
32021 Revision history of datasheet
32026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32029 \begin_layout Standard
32045 \begin_layout Section
32046 Application notes specifically for SDCC
32049 \begin_layout Standard
32050 SDCC makes no claims about the completeness of this list and about up-to-datenes
32051 s or correctness of the application notes
32052 \begin_inset LatexCommand \index{Application notes}
32059 \begin_layout Standard
32063 \begin_inset Tabular
32064 <lyxtabular version="3" rows="7" columns="3">
32066 <column alignment="block" valignment="top" leftline="true" width="17col%">
32067 <column alignment="block" valignment="top" leftline="true" width="27col%">
32068 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32069 <row topline="true" bottomline="true">
32070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32073 \begin_layout Standard
32082 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32085 \begin_layout Standard
32094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32097 \begin_layout Standard
32107 <row topline="true">
32108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32111 \begin_layout Standard
32119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32122 \begin_layout Standard
32125 Using the SDCC Compiler for the DS80C400
32126 \begin_inset LatexCommand \index{DS80C400}
32135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32138 \begin_layout Standard
32141 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32151 <row topline="true">
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32155 \begin_layout Standard
32163 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32166 \begin_layout Standard
32169 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32170 \begin_inset LatexCommand \index{DS89C4x0}
32174 Family of Microcontrollers
32179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32182 \begin_layout Standard
32185 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32195 <row topline="true">
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32199 \begin_layout Standard
32202 Silicon Laboratories / Cygnal
32207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32210 \begin_layout Standard
32213 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32214 \begin_inset LatexCommand \index{IDE}
32223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32226 \begin_layout Standard
32229 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32239 <row topline="true">
32240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32243 \begin_layout Standard
32246 Ramtron / Goal Semiconductor
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32254 \begin_layout Standard
32257 Interfacing SDCC to Syn and Textpad
32262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32265 \begin_layout Standard
32268 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32278 <row topline="true">
32279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32282 \begin_layout Standard
32285 Ramtron / Goal Semiconductor
32290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32293 \begin_layout Standard
32296 Installing and Configuring SDCC and Crimson Editor
32301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32304 \begin_layout Standard
32307 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32317 <row topline="true" bottomline="true">
32318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32321 \begin_layout Standard
32329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32332 \begin_layout Standard
32335 MSC12xx Programming with SDCC
32340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32343 \begin_layout Standard
32346 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32363 \begin_layout Section
32367 \begin_layout Standard
32368 Some questions answered, some pointers given - it might be time to in turn
32376 \begin_layout Itemize
32377 can you solve your project with the selected microcontroller? Would you
32378 find out early or rather late that your target is too small/slow/whatever?
32379 Can you switch to a slightly better device if it doesn't fit?
32382 \begin_layout Itemize
32383 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32384 and/or another programming language be more adequate? Would an operating
32385 system on the target device help?
32388 \begin_layout Itemize
32389 if you solved the problem, will the marketing department be happy?
32392 \begin_layout Itemize
32393 if the marketing department is happy, will customers be happy?
32396 \begin_layout Itemize
32397 if you're the project manager, marketing department and maybe even the customer
32398 in one person, have you tried to see the project from the outside?
32401 \begin_layout Itemize
32402 is the project done if you think it is done? Or is just that other interface/pro
32403 tocol/feature/configuration/option missing? How about website, manual(s),
32404 internationali(z|s)ation, packaging, labels, 2nd source for components,
32405 electromagnetic compatability/interference, documentation for production,
32406 production test software, update mechanism, patent issues?
32409 \begin_layout Itemize
32410 is your project adequately positioned in that magic triangle: fame, fortune,
32414 \begin_layout Standard
32415 Maybe not all answers to these questions are known and some answers may
32420 , nevertheless knowing these questions may help you to avoid burnout
32424 \begin_layout Standard
32425 burnout is bad for electronic devices, programmers and motorcycle tyres
32431 Chances are you didn't want to hear some of them...
32434 \begin_layout Chapter
32436 \begin_inset LatexCommand \index{Support}
32443 \begin_layout Standard
32444 SDCC has grown to be a large project.
32445 The compiler alone (without the preprocessor, assembler and linker) is
32446 well over 150,000 lines of code (blank stripped).
32447 The open source nature of this project is a key to its continued growth
32449 You gain the benefit and support of many active software developers and
32451 Is SDCC perfect? No, that's why we need your help.
32452 The developers take pride in fixing reported bugs.
32453 You can help by reporting the bugs and helping other SDCC users.
32454 There are lots of ways to contribute, and we encourage you to take part
32455 in making SDCC a great software package.
32459 \begin_layout Standard
32460 The SDCC project is hosted on the SDCC sourceforge site at
32461 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32466 You'll find the complete set of mailing lists
32467 \begin_inset LatexCommand \index{Mailing list(s)}
32471 , forums, bug reporting system, patch submission
32472 \begin_inset LatexCommand \index{Patch submission}
32477 \begin_inset LatexCommand \index{download}
32481 area and Subversion code repository
32482 \begin_inset LatexCommand \index{Subversion code repository}
32489 \begin_layout Section
32491 \begin_inset LatexCommand \index{Bug reporting}
32496 \begin_inset LatexCommand \index{Reporting bugs}
32503 \begin_layout Standard
32504 The recommended way of reporting bugs is using the infrastructure of the
32506 You can follow the status of bug reports there and have an overview about
32510 \begin_layout Standard
32511 Bug reports are automatically forwarded to the developer mailing list and
32512 will be fixed ASAP.
32513 When reporting a bug, it is very useful to include a small test program
32514 (the smaller the better) which reproduces the problem.
32515 If you can isolate the problem by looking at the generated assembly code,
32516 this can be very helpful.
32517 Compiling your program with the -
32521 \begin_layout Standard
32531 \begin_inset LatexCommand \index{-\/-dumpall}
32535 option can sometimes be useful in locating optimization problems.
32536 When reporting a bug please make sure you:
32539 \begin_layout Enumerate
32540 Attach the code you are compiling with SDCC.
32544 \begin_layout Enumerate
32545 Specify the exact command you use to run SDCC, or attach your Makefile.
32549 \begin_layout Enumerate
32550 Specify the SDCC version (type "
32556 "), your platform, and operating system.
32560 \begin_layout Enumerate
32561 Provide an exact copy of any error message or incorrect output.
32565 \begin_layout Enumerate
32566 Put something meaningful in the subject of your message.
32569 \begin_layout Standard
32570 Please attempt to include these 5 important parts, as applicable, in all
32571 requests for support or when reporting any problems or bugs with SDCC.
32572 Though this will make your message lengthy, it will greatly improve your
32573 chance that SDCC users and developers will be able to help you.
32574 Some SDCC developers are frustrated by bug reports without code provided
32575 that they can use to reproduce and ultimately fix the problem, so please
32576 be sure to provide sample code if you are reporting a bug!
32579 \begin_layout Standard
32580 Please have a short check that you are using a recent version of SDCC and
32581 the bug is not yet known.
32582 This is the link for reporting bugs:
32583 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32588 With SDCC on average having more than 200 downloads
32589 \begin_inset LatexCommand \index{download}
32593 on sourceforge per day
32597 \begin_layout Standard
32598 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32599 between 2002 and 2005.
32600 This does not include other methods of distribution.
32605 there must be some users.
32606 So it's not exactly easy to find a new bug.
32607 If you find one we need it:
32609 reporting bugs is good
32614 \begin_layout Section
32615 Requesting Features
32616 \begin_inset LatexCommand \label{sub:Requesting-Features}
32621 \begin_inset LatexCommand \index{Feature request}
32626 \begin_inset LatexCommand \index{Requesting features}
32633 \begin_layout Standard
32634 Like bug reports feature requests are forwarded to the developer mailing
32636 This is the link for requesting features:
32637 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32644 \begin_layout Section
32648 \begin_layout Standard
32649 Like bug reports contributed patches are forwarded to the developer mailing
32651 This is the link for submitting patches
32652 \begin_inset LatexCommand \index{Patch submission}
32657 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32664 \begin_layout Standard
32665 You need to specify some parameters to the
32669 command for the patches to be useful.
32670 If you modified more than one file a patch created f.e.
32675 \begin_inset Quotes sld
32678 diff -Naur unmodified_directory modified_directory >my_changes.patch
32679 \begin_inset Quotes srd
32685 will be fine, otherwise
32689 \begin_inset Quotes sld
32692 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32693 \begin_inset Quotes srd
32703 \begin_layout Section
32707 \begin_layout Standard
32708 These links should take you directly to the
32709 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32717 \begin_layout Standard
32718 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32719 automated messages (mid 2003)
32725 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32730 \begin_inset LatexCommand \index{Mailing list(s)}
32734 and forums are archived and searchable so if you are lucky someone already
32735 had a similar problem.
32736 While mails to the lists themselves are delivered promptly their web front
32737 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32738 if you're seriously using SDCC please consider subscribing to the lists.
32741 \begin_layout Section
32745 \begin_layout Standard
32746 You can follow the status of the Subversion version
32747 \begin_inset LatexCommand \index{version}
32751 of SDCC by watching the Changelog
32752 \begin_inset LatexCommand \index{Changelog}
32756 in the Subversion repository
32759 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32766 \begin_layout Section
32767 Subversion Source Code Repository
32770 \begin_layout Standard
32780 \begin_layout Standard
32794 or the filenames of the snapshot versions of SDCC include date and its
32796 \begin_inset LatexCommand \index{Subversion code repository}
32801 Subversion allows to download the source of recent or previous versions
32803 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32807 (by number or by date).
32808 An on-line source code browser and detailled instructions are also available
32810 SDCC versions starting from 1999 up to now are available (currently the
32811 versions prior to the conversion from cvs
32812 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32816 to Subversion (April 2006) are either by accessible by Subversion or by
32820 \begin_layout Section
32822 \begin_inset LatexCommand \index{Release policy}
32829 \begin_layout Standard
32830 Historically there often were long delays between official releases and
32831 the sourceforge download area tends to get not updated at all.
32832 Excuses in the past might have referred to problems with live range analysis,
32833 but as this was fixed a while ago, the current problem is that another
32834 excuse has to be found.
32835 Kidding aside, we have to get better there! On the other hand there are
32836 daily snapshots available at
32837 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32841 , and you can always build the very last version (hopefully with many bugs
32842 fixed, and features added) from the source code available at
32843 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32849 \begin_inset LatexCommand \index{wiki}
32854 \begin_inset LatexCommand \index{SDCC Wiki}
32859 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32863 also holds some information about past and future releases.
32866 \begin_layout Section
32868 \begin_inset LatexCommand \index{Examples}
32875 \begin_layout Standard
32876 You'll find some small examples in the directory
32878 sdcc/device/examples/.
32881 More examples and libraries are available at
32883 The SDCC Open Knowledge Resource
32884 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32891 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32898 \begin_layout Standard
32899 \begin_inset Note Note
32902 \begin_layout Standard
32903 I did insert a reference to Paul's web site here although it seems rather
32904 dedicated to a specific 8032 board (I think it's okay because it f.e.
32905 shows LCD/Harddisc interface and has a free 8051 monitor.
32906 Independent 8032 board vendors face hard competition of heavily subsidized
32907 development boards anyway).
32910 \begin_layout Standard
32911 Maybe we should include some links to real world applications.
32912 Preferably pointer to pointers (one for each architecture) so this stays
32921 \begin_layout Section
32923 \begin_inset LatexCommand \label{sec:Quality-control}
32928 \begin_inset LatexCommand \index{Quality control}
32935 \begin_layout Standard
32936 The compiler is passed through snaphot build compile and build checks.
32942 \begin_inset LatexCommand \index{Regression test}
32946 check that SDCC itself compiles flawlessly on several host platforms (i386,
32947 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
32948 and checks the quality of the code generated by SDCC by running the code
32949 for several target platforms through simulators.
32950 The regression test suite comprises more than 100 files which expand to
32951 more than 500 test cases which include more than 4500 tests.
32952 The results of these tests are published daily on SDCC's snapshot page
32953 (click on the red or green symbols on the right side of
32954 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32961 \begin_layout Standard
32962 There is a separate document
32965 \begin_inset LatexCommand \index{Test suite}
32972 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32976 about the regression test suite.
32979 \begin_layout Standard
32980 You'll find the test code in the directory
32982 sdcc/support/regression
32985 You can run these tests manually by running
32989 in this directory (or f.e.
32994 \begin_inset Quotes sld
32998 \begin_inset Quotes srd
33004 if you don't want to run the complete tests).
33005 The test code might also be interesting if you want to look for examples
33006 \begin_inset LatexCommand \index{Examples}
33010 checking corner cases of SDCC or if you plan to submit patches
33011 \begin_inset LatexCommand \index{Patch submission}
33018 \begin_layout Standard
33019 The PIC14 port uses a different set of regression tests
33020 \begin_inset LatexCommand \index{Regression test (PIC14)}
33024 , you'll find them in the directory
33026 sdcc/src/regression
33031 \begin_layout Section
33032 Use of SDCC in Education
33035 \begin_layout Standard
33044 \begin_layout Standard
33045 the phrase "use in education" might evoke the association "
33049 fit for use in education".
33050 This connotation is not intended but nevertheless risked as the licensing
33051 of SDCC makes it difficult to offer educational discounts
33057 If your rationales are to:
33060 \begin_layout Enumerate
33061 give students a chance to understand the
33065 steps of code generation
33068 \begin_layout Enumerate
33069 have a curriculum that can be extended for years.
33070 Then you could use an fpga board as target and your curriculum will seamlessly
33071 extend from logic synthesis (
33072 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33077 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33081 ), over assembly programming, to C to FPGA compilers (
33082 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33089 \begin_layout Enumerate
33090 be able to insert excursions about skills like using a revision control
33091 system, submitting/applying patches, using a type-setting (as opposed to
33092 word-processing) engine LyX/LaTeX, using
33093 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33098 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33102 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33103 Source Software, CPU simulation, compiler regression tests
33104 \begin_inset LatexCommand \index{Regression test}
33111 And if there should be a shortage of ideas then you can always point students
33112 to the ever-growing feature request list
33113 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33120 \begin_layout Enumerate
33121 not tie students to a specific host platform and instead allow them to use
33126 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33128 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33135 \begin_layout Enumerate
33136 not encourage students to use illegal copies of educational software
33139 \begin_layout Enumerate
33140 be immune to licensing/availability/price changes of the chosen tool chain
33143 \begin_layout Enumerate
33144 be able to change to a new target platform without having to adopt a new
33148 \begin_layout Enumerate
33149 have complete control over and insight into the tool chain
33152 \begin_layout Enumerate
33153 make your students aware about the pros and cons of open source software
33157 \begin_layout Enumerate
33158 give back to the public as you are probably at least partially publically
33162 \begin_layout Enumerate
33163 give students a chance to publically prove their skills and to possibly
33164 see a world wide impact
33167 \begin_layout Standard
33168 then SDCC is probably among the first choices.
33169 Well, probably SDCC might be the only choice.
33174 \begin_layout Chapter
33175 SDCC Technical Data
33178 \begin_layout Section
33180 \begin_inset LatexCommand \index{Optimizations}
33187 \begin_layout Standard
33188 SDCC performs a host of standard optimizations in addition to some MCU specific
33193 \begin_layout Subsection
33194 Sub-expression Elimination
33195 \begin_inset LatexCommand \index{Subexpression elimination}
33202 \begin_layout Standard
33203 The compiler does local and
33222 \begin_layout Verse
33230 \begin_layout Standard
33231 will be translated to
33234 \begin_layout Verse
33244 \begin_layout Standard
33245 Some subexpressions are not as obvious as the above example, e.g.:
33248 \begin_layout Verse
33256 \begin_layout Standard
33257 In this case the address arithmetic a->b[i] will be computed only once;
33258 the equivalent code in C would be.
33261 \begin_layout Verse
33271 \begin_layout Standard
33272 The compiler will try to keep these temporary variables in registers.
33275 \begin_layout Subsection
33276 Dead-Code Elimination
33277 \begin_inset LatexCommand \index{Dead-code elimination}
33284 \begin_layout Verse
33299 i = 1; \InsetSpace ~
33308 global = 1;\InsetSpace ~
33322 global = 3;\InsetSpace ~
33328 \begin_layout Standard
33332 \begin_layout Verse
33348 \begin_layout Subsection
33350 \begin_inset LatexCommand \index{Copy propagation}
33357 \begin_layout Verse
33381 \begin_layout Standard
33385 \begin_layout Verse
33409 \begin_layout Standard
33410 Note: the dead stores created by this copy propagation will be eliminated
33411 by dead-code elimination.
33414 \begin_layout Subsection
33416 \begin_inset LatexCommand \index{Loop optimization}
33421 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33428 \begin_layout Standard
33429 Two types of loop optimizations are done by SDCC
33437 of loop induction variables.
33438 In addition to the strength reduction the optimizer marks the induction
33439 variables and the register allocator tries to keep the induction variables
33440 in registers for the duration of the loop.
33441 Because of this preference of the register allocator
33442 \begin_inset LatexCommand \index{Register allocation}
33446 , loop induction optimization causes an increase in register pressure, which
33447 may cause unwanted spilling of other temporary variables into the stack
33448 \begin_inset LatexCommand \index{stack}
33453 The compiler will generate a warning message when it is forced to allocate
33454 extra space either on the stack or data space.
33455 If this extra space allocation is undesirable then induction optimization
33456 can be eliminated either for the entire source file (with -
33460 \begin_layout Standard
33469 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33471 \begin_inset LatexCommand \index{\#pragma noinduction}
33482 \begin_layout Verse
33485 for (i = 0 ; i < 100 ; i ++)
33494 \begin_layout Standard
33498 \begin_layout Verse
33503 for (i = 0; i < 100; i++)
33512 \begin_layout Standard
33513 As mentioned previously some loop invariants are not as apparent, all static
33514 address computations are also moved out of the loop.
33519 \begin_inset LatexCommand \index{Strength reduction}
33523 , this optimization substitutes an expression by a cheaper expression:
33526 \begin_layout Verse
33529 for (i=0;i < 100; i++)
33538 \begin_layout Standard
33542 \begin_layout Verse
33549 for (i=0;i< 100;i++) {
33555 ar[itemp1] = itemp2;
33573 \begin_layout Standard
33574 The more expensive multiplication
33575 \begin_inset LatexCommand \index{Multiplication}
33579 is changed to a less expensive addition.
33582 \begin_layout Subsection
33584 \begin_inset LatexCommand \index{Loop reversing}
33591 \begin_layout Standard
33592 This optimization is done to reduce the overhead of checking loop boundaries
33593 for every iteration.
33594 Some simple loops can be reversed and implemented using a
33595 \begin_inset Quotes eld
33598 decrement and jump if not zero
33599 \begin_inset Quotes erd
33603 SDCC checks for the following criterion to determine if a loop is reversible
33604 (note: more sophisticated compilers use data-dependency analysis to make
33605 this determination, SDCC uses a more simple minded analysis).
33608 \begin_layout Itemize
33609 The 'for' loop is of the form
33615 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33625 \begin_layout Itemize
33626 The <for body> does not contain
33627 \begin_inset Quotes eld
33631 \begin_inset Quotes erd
33635 \begin_inset Quotes erd
33641 \begin_layout Itemize
33642 All goto's are contained within the loop.
33645 \begin_layout Itemize
33646 No function calls within the loop.
33649 \begin_layout Itemize
33650 The loop control variable <sym> is not assigned any value within the loop
33653 \begin_layout Itemize
33654 The loop control variable does NOT participate in any arithmetic operation
33658 \begin_layout Itemize
33659 There are NO switch statements in the loop.
33662 \begin_layout Subsection
33663 Algebraic Simplifications
33666 \begin_layout Standard
33667 SDCC does numerous algebraic simplifications, the following is a small sub-set
33668 of these optimizations.
33671 \begin_layout Verse
33674 i = j + 0;\InsetSpace ~
33678 /* changed to: */\InsetSpace ~
33684 i /= 2;\InsetSpace ~
33691 /* changed to: */\InsetSpace ~
33698 = j - j;\InsetSpace ~
33702 /* changed to: */\InsetSpace ~
33708 i = j / 1;\InsetSpace ~
33712 /* changed to: */\InsetSpace ~
33719 \begin_layout Standard
33720 Note the subexpressions
33721 \begin_inset LatexCommand \index{Subexpression}
33725 given above are generally introduced by macro expansions or as a result
33726 of copy/constant propagation.
33729 \begin_layout Subsection
33730 'switch' Statements
33731 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33736 \begin_inset LatexCommand \index{switch statement}
33743 \begin_layout Standard
33744 SDCC can optimize switch statements to jump tables
33745 \begin_inset LatexCommand \index{jump tables}
33750 It makes the decision based on an estimate of the generated code size.
33751 SDCC is quite liberal in the requirements for jump table generation:
33754 \begin_layout Itemize
33755 The labels need not be in order, and the starting number need not be one
33756 or zero, the case labels are in numerical sequence or not too many case
33757 labels are missing.
33761 \begin_layout Verse
33764 switch(i) {\InsetSpace ~
33795 case 4: ...\InsetSpace ~
33827 case 5: ...\InsetSpace ~
33859 case 3: ...\InsetSpace ~
33890 case 6: ...\InsetSpace ~
33922 case 7: ...\InsetSpace ~
33954 case 8: ...\InsetSpace ~
33986 case 9: ...\InsetSpace ~
34018 case 10: ...\InsetSpace ~
34049 case 11: ...\InsetSpace ~
34116 \begin_layout Standard
34117 Both the above switch statements will be implemented using a jump-table.
34118 The example to the right side is slightly more efficient as the check for
34119 the lower boundary of the jump-table is not needed.
34123 \begin_layout Itemize
34124 The number of case labels is not larger than supported by the target architectur
34128 \begin_layout Itemize
34129 If the case labels are not in numerical sequence ('gaps' between cases)
34130 SDCC checks whether a jump table with additionally inserted dummy cases
34131 is still attractive.
34135 \begin_layout Itemize
34136 If the starting number is not zero and a check for the lower boundary of
34137 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34142 \begin_layout Standard
34143 Switch statements which have large gaps in the numeric sequence or those
34144 that have too many case labels can be split into more than one switch statement
34145 for efficient code generation, e.g.:
34148 \begin_layout Verse
34226 \begin_layout Standard
34227 If the above switch statement is broken down into two switch statements
34230 \begin_layout Verse
34273 \begin_layout Standard
34277 \begin_layout Verse
34320 \begin_layout Standard
34321 then both the switch statements will be implemented using jump-tables whereas
34322 the unmodified switch statement will not be.
34325 \begin_layout Standard
34326 \begin_inset Note Note
34329 \begin_layout Standard
34330 There might be reasons which SDCC cannot know about to either favour or
34331 not favour jump tables.
34332 If the target system has to be as quick for the last switch case as for
34333 the first (pro jump table), or if the switch argument is known to be zero
34334 in the majority of the cases (contra jump table).
34342 \begin_layout Standard
34343 The pragma nojtbound
34344 \begin_inset LatexCommand \index{\#pragma nojtbound}
34348 can be used to turn off checking the
34361 It has no effect if a default label is supplied.
34362 Use of this pragma is dangerous: if the switch
34363 \begin_inset LatexCommand \index{switch statement}
34367 argument is not matched by a case statement the processor will happily
34371 \begin_layout Subsection
34372 Bit-shifting Operations
34373 \begin_inset LatexCommand \index{Bit shifting}
34380 \begin_layout Standard
34381 Bit shifting is one of the most frequently used operation in embedded programmin
34383 SDCC tries to implement bit-shift operations in the most efficient way
34387 \begin_layout Verse
34400 \begin_layout Standard
34401 generates the following code:
34404 \begin_layout Verse
34419 \begin_layout Standard
34420 In general SDCC will never setup a loop if the shift count is known.
34424 \begin_layout Verse
34437 \begin_layout Standard
34441 \begin_layout Verse
34465 \begin_layout Subsection
34467 \begin_inset LatexCommand \index{Bit rotation}
34474 \begin_layout Standard
34475 A special case of the bit-shift operation is bit rotation
34476 \begin_inset LatexCommand \index{rotating bits}
34480 , SDCC recognizes the following expression to be a left bit-rotation:
34483 \begin_layout Verse
34491 char i;\InsetSpace ~
34502 /* unsigned is needed for rotation */
34507 i = ((i << 1) | (i >> 7));
34516 \begin_layout Standard
34517 will generate the following code:
34520 \begin_layout Verse
34537 \begin_layout Standard
34538 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34539 ns of this case will also be recognized as bit-rotation, i.e.:
34542 \begin_layout Verse
34545 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34548 \begin_layout Subsection
34549 Nibble and Byte Swapping
34552 \begin_layout Standard
34553 Other special cases of the bit-shift operations are nibble or byte swapping
34554 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34558 , SDCC recognizes the following expressions:
34561 \begin_layout Verse
34582 i = ((i << 4) | (i >> 4));
34588 j = ((j << 8) | (j >> 8));
34591 \begin_layout Standard
34592 and generates a swap instruction for the nibble swapping
34593 \begin_inset LatexCommand \index{Nibble swapping}
34597 or move instructions for the byte swapping
34598 \begin_inset LatexCommand \index{Byte swapping}
34604 \begin_inset Quotes sld
34608 \begin_inset Quotes srd
34611 example can be used to convert from little to big-endian or vice versa.
34612 If you want to change the endianness of a
34616 integer you have to cast to
34623 \begin_layout Standard
34624 Note that SDCC stores numbers in little-endian
34628 \begin_layout Standard
34629 Usually 8-bit processors don't care much about endianness.
34630 This is not the case for the standard 8051 which only has an instruction
34636 \begin_inset LatexCommand \index{DPTR}
34644 so little-endian is the more efficient byte order.
34650 \begin_inset LatexCommand \index{little-endian}
34655 \begin_inset LatexCommand \index{Endianness}
34660 lowest order first).
34663 \begin_layout Subsection
34665 \begin_inset LatexCommand \index{Highest Order Bit}
34670 \begin_inset LatexCommand \index{Any Order Bit}
34677 \begin_layout Standard
34678 It is frequently required to obtain the highest order bit of an integral
34679 type (long, int, short or char types).
34680 Also obtaining any other order bit is not uncommon.
34681 SDCC recognizes the following expressions to yield the highest order bit
34682 and generates optimized code for it, e.g.:
34685 \begin_layout Verse
34696 unsigned char hob1, aob1;
34700 bit hob2, hob3, aob2,
34710 hob1 = (gint >> 15) & 1;
34714 hob2 = (gint >> 15) & 1;
34718 hob3 = gint & 0x8000;
34723 aob1 = (gint >> 9) & 1;
34727 aob2 = (gint >> 8) & 1;
34731 aob3 = gint & 0x0800;
34741 \begin_layout Standard
34742 will generate the following code:
34745 \begin_layout Verse
34776 000A E5*01\InsetSpace ~
34803 000C 23\InsetSpace ~
34834 000D 54 01\InsetSpace ~
34862 000F F5*02\InsetSpace ~
34917 0011 E5*01\InsetSpace ~
34945 0013 33\InsetSpace ~
34975 0014 92*00\InsetSpace ~
35031 0016 E5*01\InsetSpace ~
35058 0018 33\InsetSpace ~
35088 0019 92*01\InsetSpace ~
35144 001B E5*01\InsetSpace ~
35203 001E 54 01\InsetSpace ~
35230 0020 F5*03\InsetSpace ~
35286 0022 E5*01\InsetSpace ~
35313 0024 13\InsetSpace ~
35343 0025 92*02\InsetSpace ~
35399 0027 E5*01\InsetSpace ~
35454 002B 92*03\InsetSpace ~
35482 \begin_layout Standard
35483 Other variations of these cases however will
35488 They are standard C expressions, so I heartily recommend these be the only
35489 way to get the highest order bit, (it is portable).
35490 Of course it will be recognized even if it is embedded in other expressions,
35494 \begin_layout Verse
35497 xyz = gint + ((gint >> 15) & 1);
35500 \begin_layout Standard
35501 will still be recognized.
35504 \begin_layout Subsection
35506 \begin_inset LatexCommand \index{Higher Order Byte}
35510 / Higher Order Word
35511 \begin_inset LatexCommand \index{Higher Order Word}
35518 \begin_layout Standard
35519 It is also frequently required to obtain a higher order byte or word of
35520 a larger integral type (long, int or short types).
35521 SDCC recognizes the following expressions to yield the higher order byte
35522 or word and generates optimized code for it, e.g.:
35525 \begin_layout Verse
35530 unsigned long int glong;
35538 unsigned char hob1,
35543 unsigned int how1, how2;
35552 hob1 = (gint >> 8) & 0xFF;
35556 hob2 = glong >> 24;
35560 how1 = (glong >> 16) & 0xFFFF;
35575 \begin_layout Standard
35576 will generate the following code:
35579 \begin_layout Verse
35610 0037 85*01*06\InsetSpace ~
35632 _foo_hob1_1_1,(_gint + 1)
35663 003A 85*05*07\InsetSpace ~
35685 _foo_hob2_1_1,(_glong + 3)
35715 003D 85*04*08\InsetSpace ~
35738 _foo_how1_1_1,(_glong + 2)
35740 0040 85*05*09\InsetSpace ~
35765 0043 85*03*0A\InsetSpace ~
35787 _foo_how2_1_1,(_glong + 1)
35789 0046 85*04*0B\InsetSpace ~
35812 (_foo_how2_1_1 + 1),(_glong + 2)
35815 \begin_layout Standard
35816 Again, variations of these cases may
35821 They are standard C expressions, so I heartily recommend these be the only
35822 way to get the higher order byte/word, (it is portable).
35823 Of course it will be recognized even if it is embedded in other expressions,
35827 \begin_layout Verse
35830 xyz = gint + ((gint >> 8) & 0xFF);
35833 \begin_layout Standard
35834 will still be recognized.
35837 \begin_layout Subsection
35839 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35844 \begin_inset LatexCommand \index{Peephole optimizer}
35851 \begin_layout Standard
35852 The compiler uses a rule based, pattern matching and re-writing mechanism
35853 for peep-hole optimization.
35858 a peep-hole optimizer by Christopher W.
35859 Fraser (cwfraser\InsetSpace ~
35862 A default set of rules are compiled into the compiler, additional rules
35863 may be added with the
35869 \begin_layout Standard
35879 \begin_inset LatexCommand \index{-\/-peep-file}
35886 The rule language is best illustrated with examples.
35889 \begin_layout Verse
35911 \begin_layout Standard
35912 The above rule will change the following assembly
35913 \begin_inset LatexCommand \index{Assembler routines}
35920 \begin_layout Verse
35928 \begin_layout Standard
35932 \begin_layout Verse
35938 \begin_layout Standard
35939 Note: All occurrences of a
35943 (pattern variable) must denote the same string.
35944 With the above rule, the assembly sequence:
35947 \begin_layout Verse
35955 \begin_layout Standard
35956 will remain unmodified.
35960 Other special case optimizations may be added by the
35967 \begin_layout Standard
35980 some variants of the 8051 MCU
35981 \begin_inset LatexCommand \index{MCS51 variants}
35994 The following two rules will change all
36011 \begin_layout Verse
36014 replace { lcall %1 } by { acall %1 }
36016 replace { ljmp %1 } by { ajmp %1 }
36019 \begin_layout Standard
36020 (NOTE: from version 2.7.3 on, you can use option -
36026 \begin_layout Standard
36038 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36042 , which also takes care of aligning the interrupt vectors properly.)
36047 \begin_layout Standard
36050 inline-assembler code
36052 is also passed through the peep hole optimizer, thus the peephole optimizer
36053 can also be used as an assembly level macro expander.
36054 The rules themselves are MCU dependent whereas the rule language infra-structur
36055 e is MCU independent.
36056 Peephole optimization rules for other MCU can be easily programmed using
36061 The syntax for a rule is as follows:
36064 \begin_layout Verse
36067 rule := replace [ restart ] '{' <assembly sequence> '
36105 <assembly sequence> '
36123 '}' [if <functionName> ] '
36128 \begin_layout Standard
36129 <assembly sequence> := assembly instruction (each instruction including
36130 labels must be on a separate line).
36134 The optimizer will apply to the rules
36135 one by one from the top in the sequence of their appearance, it will terminate
36136 when all rules are exhausted.
36137 If the 'restart' option is specified, then the optimizer will start matching
36138 the rules again from the top, this option for a rule is expensive (performance)
36139 , it is intended to be used in situations where a transformation will trigger
36140 the same rule again.
36141 An example of this (not a good one, it has side effects) is the following
36145 \begin_layout Verse
36165 \begin_layout Standard
36166 Note that the replace pattern cannot be a blank, but can be a comment line.
36167 Without the 'restart' option only the innermost 'pop' 'push' pair would
36168 be eliminated, i.e.:
36171 \begin_layout Verse
36183 \begin_layout Standard
36187 \begin_layout Verse
36197 \begin_layout Standard
36202 the restart option the rule will be applied again to the resulting code
36203 and then all the pop-push pairs will be eliminated to yield:
36206 \begin_layout Verse
36214 \begin_layout Standard
36215 A conditional function can be attached to a rule.
36216 Attaching rules are somewhat more involved, let me illustrate this with
36220 \begin_layout Verse
36244 \begin_layout Standard
36245 The optimizer does a look-up of a function name table defined in function
36250 in the source file SDCCpeeph.c, with the name
36255 If it finds a corresponding entry the function is called.
36256 Note there can be no parameters specified for these functions, in this
36261 is crucial, since the function
36265 expects to find the label in that particular variable (the hash table containin
36266 g the variable bindings is passed as a parameter).
36267 If you want to code more such functions, take a close look at the function
36268 labelInRange and the calling mechanism in source file SDCCpeeph.c.
36269 Currently implemented are
36271 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36272 24bitMode, portIsDS390, 24bitModeAndPortDS390
36281 \begin_layout Standard
36282 I know this whole thing is a little kludgey, but maybe some day we will
36283 have some better means.
36284 If you are looking at this file, you will see the default rules that are
36285 compiled into the compiler, you can add your own rules in the default set
36286 there if you get tired of specifying the -
36290 \begin_layout Standard
36302 \begin_layout Section
36304 \begin_inset LatexCommand \index{ANSI-compliance}
36309 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36316 \begin_layout Standard
36317 The latest publically available version of the standard
36319 ISO/IEC 9899 - Programming languages - C
36321 should be available at:
36322 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36331 \begin_layout Standard
36332 Deviations from the compliance:
36335 \begin_layout Itemize
36336 functions are not reentrant
36337 \begin_inset LatexCommand \index{reentrant}
36341 unless explicitly declared as such or the
36347 \begin_layout Standard
36357 \begin_inset LatexCommand \index{-\/-stack-auto}
36363 command line option is specified.
36366 \begin_layout Itemize
36368 \begin_inset LatexCommand \index{struct}
36373 \begin_inset LatexCommand \index{union}
36377 cannot be assigned values directly, cannot be passed as function parameters
36378 or assigned to each other and cannot be a return value
36379 \begin_inset LatexCommand \index{return value}
36383 from a function, e.g.:
36387 \begin_layout Verse
36410 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
36429 s parms) /* invalid in SDCC although allowed in ANSI */
36451 return rets; /* is invalid in SDCC although allowed in ANSI */
36457 \begin_layout Itemize
36458 initialization of structure arrays must be fully braced.
36462 \begin_layout Verse
36465 struct s { char x } a[] = {1, 2};\InsetSpace ~
36470 /* invalid in SDCC */
36473 } a[] = {{1}, {2}}; /* OK */
36477 \begin_layout Itemize
36479 \begin_inset LatexCommand \index{long long (not supported)}
36484 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36491 \begin_layout Itemize
36493 \begin_inset LatexCommand \index{double (not supported)}
36497 ' precision floating point
36498 \begin_inset LatexCommand \index{Floating point support}
36505 \begin_layout Itemize
36507 \begin_inset LatexCommand \index{K\&R style}
36511 function declarations are NOT allowed.
36515 \begin_layout Verse
36518 foo(i,j) /* this old style of function declarations */
36520 int i,j; /* is valid
36521 in ANSI but not valid in SDCC */
36536 \begin_layout Itemize
36537 Most enhancements in C99 are not supported, e.g.:
36541 \begin_layout Verse
36548 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36552 \begin_layout Itemize
36553 But some have been added recently in SDCC 2.7.0.
36554 They must be considered alpha quality however.
36558 \begin_layout Verse
36563 \begin_inset LatexCommand \index{inline (not supported)}
36569 int increment (int a) { return a+1; } /* inlines the increment without
36570 function call overhead */
36575 \begin_inset LatexCommand \index{inline (not supported)}
36581 p; /* accepted but ignored */
36585 \begin_layout Itemize
36586 Certain words that are valid identifiers in the standard may be reserved
36587 words in SDCC unless the
36593 \begin_layout Standard
36603 \begin_inset LatexCommand \index{-\/-std-c89}
36611 \begin_layout Standard
36621 \begin_inset LatexCommand \index{-\/-std-c99}
36627 command line options are used.
36628 These may include (depending on the selected processor): 'at', 'banked',
36629 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36630 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36631 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36633 Compliant equivalents of these keywords are always available in a form
36634 that begin with two underscores
36635 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36640 '__data' instead of 'data'.
36643 \begin_layout Section
36644 Cyclomatic Complexity
36645 \begin_inset LatexCommand \index{Cyclomatic complexity}
36652 \begin_layout Standard
36653 Cyclomatic complexity of a function is defined as the number of independent
36654 paths the program can take during execution of the function.
36655 This is an important number since it defines the number test cases you
36656 have to generate to validate the function.
36657 The accepted industry standard for complexity number is 10, if the cyclomatic
36658 complexity reported by SDCC exceeds 10 you should think about simplification
36659 of the function logic.
36660 Note that the complexity level is not related to the number of lines of
36661 code in a function.
36662 Large functions can have low complexity, and small functions can have large
36668 SDCC uses the following formula to compute the complexity:
36673 \begin_layout Standard
36674 complexity = (number of edges in control flow graph) - (number of nodes
36675 in control flow graph) + 2;
36679 Having said that the industry standard is 10,
36680 you should be aware that in some cases it be may unavoidable to have a
36681 complexity level of less than 10.
36682 For example if you have switch statement with more than 10 case labels,
36683 each case label adds one to the complexity level.
36684 The complexity level is by no means an absolute measure of the algorithmic
36685 complexity of the function, it does however provide a good starting point
36686 for which functions you might look at for further optimization.
36689 \begin_layout Section
36690 Retargetting for other Processors
36693 \begin_layout Standard
36694 The issues for retargetting the compiler are far too numerous to be covered
36696 What follows is a brief description of each of the seven phases of the
36697 compiler and its MCU dependency.
36700 \begin_layout Itemize
36701 Parsing the source and building the annotated parse tree.
36702 This phase is largely MCU independent (except for the language extensions).
36703 Syntax & semantic checks are also done in this phase, along with some initial
36704 optimizations like back patching labels and the pattern matching optimizations
36705 like bit-rotation etc.
36708 \begin_layout Itemize
36709 The second phase involves generating an intermediate code which can be easy
36710 manipulated during the later phases.
36711 This phase is entirely MCU independent.
36712 The intermediate code generation assumes the target machine has unlimited
36713 number of registers, and designates them with the name iTemp.
36714 The compiler can be made to dump a human readable form of the code generated
36719 \begin_layout Standard
36731 \begin_layout Itemize
36732 This phase does the bulk of the standard optimizations and is also MCU independe
36734 This phase can be broken down into several sub-phases:
36738 Break down intermediate
36739 code (iCode) into basic blocks.
36741 Do control flow & data flow analysis on the
36744 Do local common subexpression elimination, then global subexpressio
36747 Dead code elimination
36751 If loop optimizations
36752 caused any changes then do 'global subexpression elimination' and 'dead
36753 code elimination' again.
36756 \begin_layout Itemize
36757 This phase determines the live-ranges; by live range I mean those iTemp
36758 variables defined by the compiler that still survive after all the optimization
36760 Live range analysis
36761 \begin_inset LatexCommand \index{Live range analysis}
36765 is essential for register allocation, since these computation determines
36766 which of these iTemps will be assigned to registers, and for how long.
36769 \begin_layout Itemize
36770 Phase five is register allocation.
36771 There are two parts to this process.
36775 The first part I call 'register packing'
36776 (for lack of a better term).
36777 In this case several MCU specific expression folding is done to reduce
36782 The second part is more MCU independent and deals with
36783 allocating registers to the remaining live ranges.
36784 A lot of MCU specific code does creep into this phase because of the limited
36785 number of index registers available in the 8051.
36788 \begin_layout Itemize
36789 The Code generation phase is (unhappily), entirely MCU dependent and very
36790 little (if any at all) of this code can be reused for other MCU.
36791 However the scheme for allocating a homogenized assembler operand for each
36792 iCode operand may be reused.
36795 \begin_layout Itemize
36796 As mentioned in the optimization section the peep-hole optimizer is rule
36797 based system, which can reprogrammed for other MCUs.
36800 \begin_layout Standard
36801 More information is available on SDCC Wiki
36802 \begin_inset LatexCommand \index{wiki}
36807 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36811 ) and in the thread
36812 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36819 \begin_layout Chapter
36821 \begin_inset LatexCommand \index{Compiler internals}
36828 \begin_layout Section
36829 The anatomy of the compiler
36830 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36837 \begin_layout Standard
36840 This is an excerpt from an article published in Circuit Cellar Magazine
36846 It's a little outdated (the compiler is much more efficient now and user/develo
36847 per friendly), but pretty well exposes the guts of it all.
36853 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36854 It is fairly easy to retarget for other 8-bit MCU.
36855 Here we take a look at some of the internals of the compiler.
36859 \begin_layout Paragraph*
36861 \begin_inset LatexCommand \index{Parsing}
36868 \begin_layout Standard
36869 Parsing the input source file and creating an AST (Annotated Syntax Tree
36870 \begin_inset LatexCommand \index{Annotated syntax tree}
36875 This phase also involves propagating types (annotating each node of the
36876 parse tree with type information) and semantic analysis.
36877 There are some MCU specific parsing rules.
36878 For example the storage classes, the extended storage classes are MCU specific
36879 while there may be a xdata storage class for 8051 there is no such storage
36880 class for z80 or Atmel AVR.
36881 SDCC allows MCU specific storage class extensions, i.e.
36882 xdata will be treated as a storage class specifier when parsing 8051 C
36883 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36887 \begin_layout Paragraph*
36889 \begin_inset LatexCommand \index{iCode}
36896 \begin_layout Standard
36897 Intermediate code generation.
36898 In this phase the AST is broken down into three-operand form (iCode).
36899 These three operand forms are represented as doubly linked lists.
36900 ICode is the term given to the intermediate form generated by the compiler.
36901 ICode example section shows some examples of iCode generated for some simple
36902 C source functions.
36905 \begin_layout Paragraph*
36907 \begin_inset LatexCommand \index{Optimizations}
36914 \begin_layout Standard
36915 Bulk of the target independent optimizations is performed in this phase.
36916 The optimizations include constant propagation, common sub-expression eliminati
36917 on, loop invariant code movement, strength reduction of loop induction variables
36918 and dead-code elimination.
36921 \begin_layout Paragraph*
36922 Live range analysis
36923 \begin_inset LatexCommand \index{Live range analysis}
36930 \begin_layout Standard
36931 During intermediate code generation phase, the compiler assumes the target
36932 machine has infinite number of registers and generates a lot of temporary
36934 The live range computation determines the lifetime of each of these compiler-ge
36935 nerated temporaries.
36936 A picture speaks a thousand words.
36937 ICode example sections show the live range annotations for each of the
36939 It is important to note here, each iCode is assigned a number in the order
36940 of its execution in the function.
36941 The live ranges are computed in terms of these numbers.
36942 The from number is the number of the iCode which first defines the operand
36943 and the to number signifies the iCode which uses this operand last.
36946 \begin_layout Paragraph*
36947 Register Allocation
36948 \begin_inset LatexCommand \index{Register allocation}
36955 \begin_layout Standard
36956 The register allocation determines the type and number of registers needed
36958 In most MCUs only a few registers can be used for indirect addressing.
36959 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36960 address the internal ram and DPTR to indirectly address the external ram.
36961 The compiler will try to allocate the appropriate register to pointer variables
36963 ICode example section shows the operands annotated with the registers assigned
36965 The compiler will try to keep operands in registers as much as possible;
36966 there are several schemes the compiler uses to do achieve this.
36967 When the compiler runs out of registers the compiler will check to see
36968 if there are any live operands which is not used or defined in the current
36969 basic block being processed, if there are any found then it will push that
36970 operand and use the registers in this block, the operand will then be popped
36971 at the end of the basic block.
36975 \begin_layout Standard
36976 There are other MCU specific considerations in this phase.
36977 Some MCUs have an accumulator; very short-lived operands could be assigned
36978 to the accumulator instead of a general-purpose register.
36981 \begin_layout Paragraph*
36985 \begin_layout Standard
36986 Figure II gives a table of iCode
36987 \begin_inset LatexCommand \index{iCode}
36991 operations supported by the compiler.
36992 The code generation involves translating these operations into corresponding
36993 assembly code for the processor.
36994 This sounds overly simple but that is the essence of code generation.
36995 Some of the iCode operations are generated on a MCU specific manner for
36996 example, the z80 port does not use registers to pass parameters so the
36997 SEND and RECV iCode operations will not be generated, and it also does
36998 not support JUMPTABLES.
37004 \begin_layout Standard
37008 \begin_inset Tabular
37009 <lyxtabular version="3" rows="39" columns="4">
37010 <features islongtable="true" headBottomDL="true">
37011 <column alignment="block" valignment="top" leftline="true" width="13col%">
37012 <column alignment="left" valignment="top" leftline="true" width="13col%">
37013 <column alignment="block" valignment="top" leftline="true" width="22col%">
37014 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37015 <row topline="true" bottomline="true" endhead="true">
37016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37019 \begin_layout Standard
37025 \begin_inset LatexCommand \index{iCode}
37034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37037 \begin_layout Standard
37045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37048 \begin_layout Standard
37056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37059 \begin_layout Standard
37068 <row topline="true">
37069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37072 \begin_layout Standard
37080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37083 \begin_layout Standard
37086 IC_LEFT() IC_RESULT()
37091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37094 \begin_layout Standard
37102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37105 \begin_layout Standard
37108 IC_RESULT = ! IC_LEFT;
37114 <row topline="true">
37115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37118 \begin_layout Standard
37126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37129 \begin_layout Standard
37132 IC_LEFT() IC_RESULT()
37137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37140 \begin_layout Standard
37143 Bitwise complement of
37148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37151 \begin_layout Standard
37154 IC_RESULT = ~IC_LEFT;
37160 <row topline="true">
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" usebox="none">
37175 \begin_layout Standard
37178 IC_LEFT() IC_RESULT()
37183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37186 \begin_layout Standard
37189 Rotate right with carry
37194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37197 \begin_layout Standard
37200 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37206 <row topline="true">
37207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37210 \begin_layout Standard
37218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37221 \begin_layout Standard
37224 IC_LEFT() IC_RESULT()
37229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37232 \begin_layout Standard
37235 Rotate left with carry
37240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37243 \begin_layout Standard
37246 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37252 <row topline="true">
37253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37256 \begin_layout Standard
37264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37267 \begin_layout Standard
37270 IC_LEFT() IC_RESULT()
37275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37278 \begin_layout Standard
37281 Get the highest order bit of IC_LEFT
37286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37289 \begin_layout Standard
37292 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37298 <row topline="true">
37299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37302 \begin_layout Standard
37310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37313 \begin_layout Standard
37316 IC_LEFT() IC_RESULT()
37321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37324 \begin_layout Standard
37332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37335 \begin_layout Standard
37338 IC_RESULT = - IC_LEFT;
37344 <row topline="true">
37345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37348 \begin_layout Standard
37356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37359 \begin_layout Standard
37367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37370 \begin_layout Standard
37373 Push the operand into stack
37378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37381 \begin_layout Standard
37390 <row topline="true">
37391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37394 \begin_layout Standard
37402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37405 \begin_layout Standard
37413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37416 \begin_layout Standard
37419 Pop the operand from the stack
37424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37427 \begin_layout Standard
37436 <row topline="true">
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" usebox="none">
37451 \begin_layout Standard
37454 IC_LEFT() IC_RESULT()
37459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37462 \begin_layout Standard
37465 Call the function represented by IC_LEFT
37470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37473 \begin_layout Standard
37476 IC_RESULT = IC_LEFT();
37482 <row topline="true">
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" usebox="none">
37497 \begin_layout Standard
37500 IC_LEFT() IC_RESULT()
37505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37508 \begin_layout Standard
37511 Call via function pointer
37516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37519 \begin_layout Standard
37522 IC_RESULT = (*IC_LEFT)();
37528 <row topline="true">
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" usebox="none">
37543 \begin_layout Standard
37551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37554 \begin_layout Standard
37557 Return the value in operand IC_LEFT
37562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37565 \begin_layout Standard
37574 <row topline="true">
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" usebox="none">
37589 \begin_layout Standard
37597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37600 \begin_layout Standard
37608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37611 \begin_layout Standard
37620 <row topline="true">
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" usebox="none">
37635 \begin_layout Standard
37643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37646 \begin_layout Standard
37654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37657 \begin_layout Standard
37666 <row topline="true">
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" usebox="none">
37681 \begin_layout Standard
37684 IC_LEFT() IC_RIGHT() IC_RESULT()
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37692 \begin_layout Standard
37700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37703 \begin_layout Standard
37706 IC_RESULT = IC_LEFT + IC_RIGHT
37712 <row topline="true">
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" usebox="none">
37727 \begin_layout Standard
37730 IC_LEFT() IC_RIGHT() IC_RESULT()
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37738 \begin_layout Standard
37746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37749 \begin_layout Standard
37752 IC_RESULT = IC_LEFT - IC_RIGHT
37758 <row topline="true">
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" usebox="none">
37773 \begin_layout Standard
37776 IC_LEFT() IC_RIGHT() IC_RESULT()
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37784 \begin_layout Standard
37792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37795 \begin_layout Standard
37798 IC_RESULT = IC_LEFT * IC_RIGHT;
37804 <row topline="true">
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" usebox="none">
37819 \begin_layout Standard
37822 IC_LEFT() IC_RIGHT() IC_RESULT()
37827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37830 \begin_layout Standard
37838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37841 \begin_layout Standard
37844 IC_RESULT = IC_LEFT / IC_RIGHT;
37850 <row topline="true">
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" usebox="none">
37865 \begin_layout Standard
37868 IC_LEFT() IC_RIGHT() IC_RESULT()
37873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37876 \begin_layout Standard
37884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37887 \begin_layout Standard
37890 IC_RESULT = IC_LEFT % IC_RIGHT;
37896 <row topline="true">
37897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37900 \begin_layout Standard
37908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37911 \begin_layout Standard
37914 IC_LEFT() IC_RIGHT() IC_RESULT()
37919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37922 \begin_layout Standard
37930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37933 \begin_layout Standard
37936 IC_RESULT = IC_LEFT < IC_RIGHT;
37942 <row topline="true">
37943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37946 \begin_layout Standard
37954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37957 \begin_layout Standard
37960 IC_LEFT() IC_RIGHT() IC_RESULT()
37965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37968 \begin_layout Standard
37976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37979 \begin_layout Standard
37982 IC_RESULT = IC_LEFT > IC_RIGHT;
37988 <row topline="true">
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" usebox="none">
38003 \begin_layout Standard
38006 IC_LEFT() IC_RIGHT() IC_RESULT()
38011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38014 \begin_layout Standard
38022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38025 \begin_layout Standard
38028 IC_RESULT = IC_LEFT == IC_RIGHT;
38034 <row topline="true">
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" usebox="none">
38049 \begin_layout Standard
38052 IC_LEFT() IC_RIGHT() IC_RESULT()
38057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38060 \begin_layout Standard
38063 Logical and operation
38068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38071 \begin_layout Standard
38074 IC_RESULT = IC_LEFT && IC_RIGHT;
38080 <row topline="true">
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" usebox="none">
38095 \begin_layout Standard
38098 IC_LEFT() IC_RIGHT() IC_RESULT()
38103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38106 \begin_layout Standard
38109 Logical or operation
38114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38117 \begin_layout Standard
38120 IC_RESULT = IC_LEFT || IC_RIGHT;
38126 <row topline="true">
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" usebox="none">
38141 \begin_layout Standard
38144 IC_LEFT() IC_RIGHT() IC_RESULT()
38149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38152 \begin_layout Standard
38160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38163 \begin_layout Standard
38166 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38172 <row topline="true">
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" usebox="none">
38187 \begin_layout Standard
38190 IC_LEFT() IC_RIGHT() IC_RESULT()
38195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38198 \begin_layout Standard
38206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38209 \begin_layout Standard
38212 IC_RESULT = IC_LEFT | IC_RIGHT;
38218 <row topline="true">
38219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38222 \begin_layout Standard
38230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38233 \begin_layout Standard
38236 IC_LEFT() IC_RIGHT() IC_RESULT()
38241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38244 \begin_layout Standard
38252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38255 \begin_layout Standard
38258 IC_RESULT = IC_LEFT & IC_RIGHT;
38264 <row topline="true">
38265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38268 \begin_layout Standard
38276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38279 \begin_layout Standard
38282 IC_LEFT() IC_RIGHT() IC_RESULT()
38287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38290 \begin_layout Standard
38298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38301 \begin_layout Standard
38304 IC_RESULT = IC_LEFT << IC_RIGHT
38310 <row topline="true">
38311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38314 \begin_layout Standard
38322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38325 \begin_layout Standard
38328 IC_LEFT() IC_RIGHT() IC_RESULT()
38333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38336 \begin_layout Standard
38344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38347 \begin_layout Standard
38350 IC_RESULT = IC_LEFT >> IC_RIGHT
38356 <row topline="true">
38357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38360 \begin_layout Standard
38370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38373 \begin_layout Standard
38376 IC_LEFT() IC_RESULT()
38381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38384 \begin_layout Standard
38392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38395 \begin_layout Standard
38398 IC_RESULT = (*IC_LEFT);
38404 <row topline="true">
38405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38408 \begin_layout Standard
38416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38419 \begin_layout Standard
38422 IC_RIGHT() IC_RESULT()
38427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38430 \begin_layout Standard
38438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38441 \begin_layout Standard
38444 (*IC_RESULT) = IC_RIGHT;
38450 <row topline="true">
38451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38454 \begin_layout Standard
38462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38465 \begin_layout Standard
38468 IC_RIGHT() IC_RESULT()
38473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38476 \begin_layout Standard
38484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38487 \begin_layout Standard
38490 IC_RESULT = IC_RIGHT;
38496 <row topline="true">
38497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38500 \begin_layout Standard
38508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38511 \begin_layout Standard
38514 IC_COND IC_TRUE IC_LABEL
38519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38522 \begin_layout Standard
38526 If true label is present then jump to true label if condition is true else
38527 jump to false label if condition is false
38532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38535 \begin_layout Standard
38538 if (IC_COND) goto IC_TRUE;
38544 If (!IC_COND) goto IC_FALSE;
38550 <row topline="true">
38551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38554 \begin_layout Standard
38562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38565 \begin_layout Standard
38568 IC_LEFT() IC_RESULT()
38573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38576 \begin_layout Standard
38584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38587 \begin_layout Standard
38590 IC_RESULT = &IC_LEFT();
38596 <row topline="true">
38597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38600 \begin_layout Standard
38608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38611 \begin_layout Standard
38614 IC_JTCOND IC_JTLABELS
38619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38622 \begin_layout Standard
38625 Jump to list of labels depending on the value of JTCOND
38630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38633 \begin_layout Standard
38642 <row topline="true">
38643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38646 \begin_layout Standard
38654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38657 \begin_layout Standard
38660 IC_RIGHT() IC_LEFT() IC_RESULT()
38665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38668 \begin_layout Standard
38676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38679 \begin_layout Standard
38682 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38688 <row topline="true">
38689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38692 \begin_layout Standard
38700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38703 \begin_layout Standard
38711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38714 \begin_layout Standard
38717 This is used for passing parameters in registers;
38719 move IC_LEFT to the next
38720 available parameter register.
38725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38728 \begin_layout Standard
38737 <row topline="true">
38738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38741 \begin_layout Standard
38749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38752 \begin_layout Standard
38760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38763 \begin_layout Standard
38766 This is used for receiving parameters passed in registers;
38769 in the next parameter register to IC_RESULT
38774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38777 \begin_layout Standard
38786 <row topline="true" bottomline="true">
38787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38790 \begin_layout Standard
38794 (some more have been added)
38799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38802 \begin_layout Standard
38808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38811 \begin_layout Standard
38817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38820 \begin_layout Standard
38844 \begin_layout Standard
38845 \begin_inset Note Note
38848 \begin_layout Standard
38849 In the original article Figure II was announced to be downloadable on
38854 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38862 \begin_layout Paragraph*
38864 \begin_inset LatexCommand \index{iCode}
38871 \begin_layout Standard
38872 This section shows some details of iCode.
38873 The example C code does not do anything useful; it is used as an example
38874 to illustrate the intermediate code generated by the compiler.
38877 \begin_layout Verse
38887 /* This function does nothing useful.
38894 for the purpose of explaining iCode */
38897 short function (data
38906 short i=10; \InsetSpace ~
38908 /* dead initialization eliminated */
38914 /* dead initialization eliminated */
38942 /* compiler detects i,j to be induction
38947 for (i = 0, j = 10 ; i < 10 ; i++, j
38953 \begin_layout Standard
38976 mul += i * 3; \InsetSpace ~
38978 /* this multiplication remains */
38985 j * 3;\InsetSpace ~
38987 /* this multiplication changed to addition */
39001 \begin_layout Standard
39002 In addition to the operands each iCode contains information about the filename
39003 and line it corresponds to in the source file.
39004 The first field in the listing should be interpreted as follows:
39009 Filename(linenumber: iCode Execution sequence number : ICode hash table
39010 key : loop depth of the iCode).
39015 Then follows the human readable form of the ICode operation.
39016 Each operand of this triplet form can be of three basic types a) compiler
39017 generated temporary b) user defined variable c) a constant value.
39018 Note that local variables and parameters are replaced by compiler generated
39021 \begin_inset LatexCommand \index{Live range analysis}
39025 are computed only for temporaries (i.e.
39026 live ranges are not computed for global variables).
39028 \begin_inset LatexCommand \index{Register allocation}
39032 are allocated for temporaries only.
39033 Operands are formatted in the following manner:
39038 Operand Name [lr live-from : live-to ] { type information } [ registers
39044 As mentioned earlier the live ranges are computed in terms of the execution
39045 sequence number of the iCodes, for example
39047 the iTemp0 is live from (i.e.
39048 first defined in iCode with execution sequence number 3, and is last used
39049 in the iCode with sequence number 5).
39050 For induction variables such as iTemp21 the live range computation extends
39051 the lifetime from the start to the end of the loop.
39053 The register allocator
39054 used the live range information to allocate registers, the same registers
39055 may be used for different temporaries if their live ranges do not overlap,
39056 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39057 ranges do not overlap.
39058 In addition the allocator also takes into consideration the type and usage
39059 of a temporary, for example itemp6 is a pointer to near space and is used
39060 as to fetch data from (i.e.
39061 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39062 Some short lived temporaries are allocated to special registers which have
39063 meaning to the code generator e.g.
39064 iTemp13 is allocated to a pseudo register CC which tells the back end that
39065 the temporary is used only for a conditional jump the code generation makes
39066 use of this information to optimize a compare and jump ICode.
39070 \begin_inset LatexCommand \index{Loop optimization}
39074 performed by the compiler.
39075 It can detect induction variables iTemp21(i) and iTemp23(j).
39076 Also note the compiler does selective strength reduction
39077 \begin_inset LatexCommand \index{Strength reduction}
39082 the multiplication of an induction variable in line 18 (gint = j * 3) is
39083 changed to addition, a new temporary iTemp17 is allocated and assigned
39084 a initial value, a constant 3 is then added for each iteration of the loop.
39085 The compiler does not change the multiplication
39086 \begin_inset LatexCommand \index{Multiplication}
39090 in line 17 however since the processor does support an 8 * 8 bit multiplication.
39093 Note the dead code elimination
39094 \begin_inset LatexCommand \index{Dead-code elimination}
39098 optimization eliminated the dead assignments in line 7 & 8 to I and sum
39104 \begin_layout Standard
39107 Sample.c (5:1:0:0) _entry($9) :
39110 \begin_layout Standard
39113 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39116 \begin_layout Standard
39119 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
39122 \begin_layout Standard
39125 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39128 \begin_layout Standard
39131 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39135 \begin_layout Standard
39138 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39141 \begin_layout Standard
39144 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39148 \begin_layout Standard
39151 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39154 \begin_layout Standard
39157 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39161 \begin_layout Standard
39164 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39168 \begin_layout Standard
39171 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39175 \begin_layout Standard
39178 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39182 \begin_layout Standard
39185 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39186 * int}[r0] + 0x2 {short}
39189 \begin_layout Standard
39192 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39195 \begin_layout Standard
39198 Sample.c(11:17:21:0)_whilebreak_0($3) :
39201 \begin_layout Standard
39204 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39207 \begin_layout Standard
39210 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39213 \begin_layout Standard
39216 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39219 \begin_layout Standard
39222 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39225 \begin_layout Standard
39228 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39231 \begin_layout Standard
39234 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39237 \begin_layout Standard
39240 Sample.c(15:24:26:1)_forcond_0($4) :
39243 \begin_layout Standard
39246 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39250 \begin_layout Standard
39253 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39256 \begin_layout Standard
39259 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39260 + ITemp21 [lr21:38]{short}[r4]
39263 \begin_layout Standard
39266 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39270 \begin_layout Standard
39273 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39274 + iTemp15 [lr29:30]{short}[r1]
39277 \begin_layout Standard
39280 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39284 \begin_layout Standard
39287 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39291 \begin_layout Standard
39294 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39298 \begin_layout Standard
39301 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39305 \begin_layout Standard
39308 Sample.c(19:38:47:1) goto _forcond_0($4)
39311 \begin_layout Standard
39314 Sample.c(19:39:48:0)_forbreak_0($7) :
39317 \begin_layout Standard
39320 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39321 + ITemp11 [lr19:40]{short}[r3]
39324 \begin_layout Standard
39327 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39330 \begin_layout Standard
39333 Sample.c(20:42:51:0)_return($8) :
39336 \begin_layout Standard
39339 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39345 Finally the code generated for this function:
39350 \begin_layout Standard
39356 \begin_layout Standard
39362 \begin_layout Standard
39370 \begin_layout Standard
39376 \begin_layout Standard
39384 \begin_layout Standard
39390 \begin_layout Standard
39393 ; ----------------------------------------------
39396 \begin_layout Standard
39399 ; function function
39402 \begin_layout Standard
39405 ; ----------------------------------------------
39408 \begin_layout Standard
39414 \begin_layout Standard
39417 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
39420 \begin_layout Standard
39428 \begin_layout Standard
39431 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39434 \begin_layout Standard
39442 \begin_layout Standard
39445 ;_whilecontinue_0($1) :
39448 \begin_layout Standard
39454 \begin_layout Standard
39457 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39460 \begin_layout Standard
39463 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39466 \begin_layout Standard
39474 \begin_layout Standard
39482 \begin_layout Standard
39490 \begin_layout Standard
39498 \begin_layout Standard
39506 \begin_layout Standard
39514 \begin_layout Standard
39522 \begin_layout Standard
39528 \begin_layout Standard
39531 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39534 \begin_layout Standard
39542 \begin_layout Standard
39550 \begin_layout Standard
39553 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39556 \begin_layout Standard
39564 \begin_layout Standard
39572 \begin_layout Standard
39580 \begin_layout Standard
39588 \begin_layout Standard
39596 \begin_layout Standard
39604 \begin_layout Standard
39607 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39610 \begin_layout Standard
39618 \begin_layout Standard
39626 \begin_layout Standard
39634 \begin_layout Standard
39642 \begin_layout Standard
39650 \begin_layout Standard
39653 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39656 \begin_layout Standard
39664 \begin_layout Standard
39672 \begin_layout Standard
39680 \begin_layout Standard
39683 ; iTemp6 [lr5:16]{_near * int}[r0] =
39686 \begin_layout Standard
39689 ; iTemp6 [lr5:16]{_near * int}[r0] +
39692 \begin_layout Standard
39698 \begin_layout Standard
39706 \begin_layout Standard
39709 ; goto _whilecontinue_0($1)
39712 \begin_layout Standard
39720 \begin_layout Standard
39723 ; _whilebreak_0($3) :
39726 \begin_layout Standard
39732 \begin_layout Standard
39735 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39738 \begin_layout Standard
39746 \begin_layout Standard
39749 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39752 \begin_layout Standard
39760 \begin_layout Standard
39763 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39766 \begin_layout Standard
39774 \begin_layout Standard
39777 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39780 \begin_layout Standard
39788 \begin_layout Standard
39796 \begin_layout Standard
39799 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39802 \begin_layout Standard
39810 \begin_layout Standard
39818 \begin_layout Standard
39824 \begin_layout Standard
39830 \begin_layout Standard
39833 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39836 \begin_layout Standard
39839 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39842 \begin_layout Standard
39850 \begin_layout Standard
39858 \begin_layout Standard
39866 \begin_layout Standard
39874 \begin_layout Standard
39882 \begin_layout Standard
39888 \begin_layout Standard
39891 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39894 \begin_layout Standard
39897 ; iTemp21 [lr21:38]{short}[r4]
39900 \begin_layout Standard
39908 \begin_layout Standard
39916 \begin_layout Standard
39924 \begin_layout Standard
39927 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39930 \begin_layout Standard
39938 \begin_layout Standard
39946 \begin_layout Standard
39954 \begin_layout Standard
39962 \begin_layout Standard
39965 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39968 \begin_layout Standard
39971 ; iTemp15 [lr29:30]{short}[r1]
39974 \begin_layout Standard
39982 \begin_layout Standard
39990 \begin_layout Standard
39993 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39996 \begin_layout Standard
40004 \begin_layout Standard
40012 \begin_layout Standard
40020 \begin_layout Standard
40028 \begin_layout Standard
40036 \begin_layout Standard
40044 \begin_layout Standard
40047 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40050 \begin_layout Standard
40058 \begin_layout Standard
40066 \begin_layout Standard
40074 \begin_layout Standard
40082 \begin_layout Standard
40090 \begin_layout Standard
40098 \begin_layout Standard
40101 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40104 \begin_layout Standard
40112 \begin_layout Standard
40115 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40118 \begin_layout Standard
40126 \begin_layout Standard
40131 cjne r5,#0xff,00104$
40134 \begin_layout Standard
40142 \begin_layout Standard
40145 ; goto _forcond_0($4)
40148 \begin_layout Standard
40156 \begin_layout Standard
40159 ; _forbreak_0($7) :
40162 \begin_layout Standard
40168 \begin_layout Standard
40171 ; ret iTemp24 [lr40:41]{short}
40174 \begin_layout Standard
40182 \begin_layout Standard
40190 \begin_layout Standard
40198 \begin_layout Standard
40204 \begin_layout Standard
40210 \begin_layout Standard
40220 \begin_layout Section
40221 A few words about basic block successors, predecessors and dominators
40224 \begin_layout Standard
40225 Successors are basic blocks
40226 \begin_inset LatexCommand \index{Basic blocks}
40230 that might execute after this basic block.
40232 Predecessors are basic blocks
40233 that might execute before reaching this basic block.
40235 Dominators are basic
40236 blocks that WILL execute before reaching this basic block.
40241 \begin_layout Standard
40245 \begin_layout Standard
40249 \begin_layout Standard
40257 \begin_layout Standard
40261 \begin_layout Standard
40269 \begin_layout Standard
40275 \begin_layout Standard
40276 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40279 \begin_layout Standard
40280 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40283 \begin_layout Standard
40284 c) domVect of [BB4] = BB1 ...
40285 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40289 \begin_layout Chapter
40293 \begin_layout Standard
40294 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40304 Thanks to all the other volunteer developers who have helped with coding,
40305 testing, web-page creation, distribution sets, etc.
40306 You know who you are :-)
40314 Thanks to Sourceforge
40315 \begin_inset LatexCommand \url{http://www.sf.net}
40319 which has hosted the project since 1999 and donates significant download
40328 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40329 cycles and bandwidth for snapshot builds.
40334 \begin_layout Standard
40335 This document was initially written by Sandeep Dutta
40338 \begin_layout Standard
40339 All product names mentioned herein may be trademarks
40340 \begin_inset LatexCommand \index{Trademarks}
40344 of their respective companies.
40348 \begin_layout Section*
40352 \begin_layout Standard
40353 To avoid confusion, the installation and building options for SDCC itself
40354 (chapter 2) are not part of the index.
40357 \begin_layout Standard
40358 \begin_inset LatexCommand \printindex{}