1 #LyX 1.4.3 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 Comment
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 simply 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 Comment
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 an open source, retargettable, optimizing ANSI-C compiler by
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, the debugger
680 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
685 The latest version can be downloaded from
686 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
696 Please note: the compiler will probably always be some steps ahead of this
701 \begin_inset LatexCommand \index{Status of documentation}
709 \begin_layout Standard
710 Obviously this has pros and cons
718 \begin_layout Section
722 \begin_layout Standard
723 All packages used in this compiler system are
731 ; source code for all the sub-packages (pre-processor, assemblers, linkers
732 etc) is distributed with the package.
733 This documentation is maintained using a freeware word processor (LyX).
736 program is free software; you can redistribute it and/or modify it under
737 the terms of the GNU General Public License
738 \begin_inset LatexCommand \index{GNU General Public License, GPL}
742 as published by the Free Software Foundation; either version 2, or (at
743 your option) any later version.
744 This program is distributed in the hope that it will be useful, but WITHOUT
745 ANY WARRANTY; without even the implied warranty
746 \begin_inset LatexCommand \index{warranty}
750 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
751 See the GNU General Public License for more details.
752 You should have received a copy of the GNU General Public License along
753 with this program; if not, write to the Free Software Foundation, 59 Temple
754 Place - Suite 330, Boston, MA 02111-1307, USA.
755 In other words, you are welcome to use, share and improve this program.
756 You are forbidden to forbid anyone else to use, share and improve what
758 Help stamp out software-hoarding!
761 \begin_layout Section
762 Typographic conventions
763 \begin_inset LatexCommand \index{Typographic conventions}
770 \begin_layout Standard
771 Throughout this manual, we will use the following convention.
772 Commands you have to type in are printed in
780 Code samples are printed in
785 Interesting items and new terms are printed in
790 \begin_layout Section
792 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
796 with previous versions
797 \begin_inset LatexCommand \index{Compatibility with previous versions}
804 \begin_layout Standard
805 This version has numerous bug fixes compared with the previous version.
806 But we also introduced some incompatibilities with older versions.
807 Not just for the fun of it, but to make the compiler more stable, efficient
809 \begin_inset LatexCommand \index{ANSI-compliance}
814 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
818 for ANSI-Compliance).
824 \begin_layout Itemize
825 short is now equivalent to int (16 bits), it used to be equivalent to char
826 (8 bits) which is not ANSI compliant.
829 \begin_layout Itemize
830 the default directory for gcc-builds where include, library and documentation
831 files are stored is now in /usr/local/share.
834 \begin_layout Itemize
835 char type parameters to vararg
836 \begin_inset LatexCommand \index{vararg, va\_arg}
840 functions are casted to int unless explicitly casted
841 \begin_inset Marginal
844 \begin_layout Standard
869 will push a as an int and as a char resp.
872 \begin_layout Itemize
877 \begin_layout Standard
886 -regextend has been removed.
889 \begin_layout Itemize
894 \begin_layout Standard
903 -noregparms has been removed.
906 \begin_layout Itemize
911 \begin_layout Standard
920 -stack-after-data has been removed.
923 \begin_layout Itemize
925 \begin_inset LatexCommand \index{bit}
930 \begin_inset LatexCommand \index{sbit}
935 \begin_inset LatexCommand \index{\_\_sbit}
939 types now consistently behave like the C99 _Bool type with respect to type
941 \begin_inset LatexCommand \index{type conversion}
946 \begin_inset LatexCommand \index{type promotion}
951 The most common incompatibility resulting from this change is related to
953 \begin_inset LatexCommand \index{Bit toggling}
968 \begin_inset LatexCommand \index{\~\/ Operator}
972 b; /* equivalent to b=1 instead of toggling b */
973 \begin_inset Marginal
976 \begin_layout Standard
989 b = !b; /* toggles b */
993 In previous versions, both forms would have toggled the bit.
996 \begin_layout Standard
999 <pending: more incompatibilities?>
1002 \begin_layout Section
1006 \begin_layout Standard
1007 What do you need before you start installation of SDCC? A computer, and
1008 a desire to compute.
1009 The preferred method of installation is to compile SDCC from source using
1011 For Windows some pre-compiled binary distributions are available for your
1013 You should have some experience with command line tools and compiler use.
1016 \begin_layout Section
1020 \begin_layout Standard
1021 The SDCC home page at
1022 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1026 is a great place to find distribution sets.
1027 You can also find links to the user mailing lists that offer help or discuss
1028 SDCC with other SDCC users.
1029 Web links to other SDCC related sites can also be found here.
1030 This document can be found in the DOC directory of the source package as
1031 a text or HTML file.
1032 A pdf version of this document is available at
1033 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1038 Some of the other tools (simulator and assembler) included with SDCC contain
1039 their own documentation and can be found in the source distribution.
1040 If you want the latest unreleased software, the complete source package
1041 is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
1045 \begin_layout Section
1046 Wishes for the future
1049 \begin_layout Standard
1050 There are (and always will be) some things that could be done.
1051 Here are some I can think of:
1056 \begin_layout Standard
1059 char KernelFunction3(char p) at 0x340;
1064 \begin_layout Standard
1068 \begin_inset LatexCommand \index{code banking (limited support)}
1078 If you can think of some more, please see the section
1079 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1083 about filing feature requests
1084 \begin_inset LatexCommand \index{Requesting features}
1089 \begin_inset LatexCommand \index{Feature request}
1098 \begin_layout Chapter
1100 \begin_inset LatexCommand \index{Installation}
1107 \begin_layout Standard
1108 For most users it is sufficient to skip to either section
1109 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1114 \begin_inset LatexCommand \ref{sub:Windows-Install}
1119 More detailed instructions follow below.
1122 \begin_layout Section
1124 \begin_inset LatexCommand \index{Options SDCC configuration}
1131 \begin_layout Standard
1132 The install paths, search paths and other options are defined when running
1134 The defaults can be overridden by:
1138 \labelwidthstring 00.00.0000
1143 \begin_layout Standard
1152 -prefix see table below
1156 \labelwidthstring 00.00.0000
1161 \begin_layout Standard
1170 -exec_prefix see table below
1174 \labelwidthstring 00.00.0000
1179 \begin_layout Standard
1188 -bindir see table below
1192 \labelwidthstring 00.00.0000
1197 \begin_layout Standard
1206 -datadir see table below
1210 \labelwidthstring 00.00.0000
1215 \begin_layout Standard
1224 -datarootdir see table below
1230 \labelwidthstring 00.00.0000
1233 docdir environment variable, see table below
1237 \labelwidthstring 00.00.0000
1240 include_dir_suffix environment variable, see table below
1244 \labelwidthstring 00.00.0000
1247 lib_dir_suffix environment variable, see table below
1251 \labelwidthstring 00.00.0000
1254 sdccconf_h_dir_separator environment variable, either / or
1259 This character will only be used in sdccconf.h; don't forget it's a C-header,
1260 therefore a double-backslash is needed there.
1266 \labelwidthstring 00.00.0000
1271 \begin_layout Standard
1280 -disable-mcs51-port Excludes the Intel mcs51 port
1284 \labelwidthstring 00.00.0000
1289 \begin_layout Standard
1298 -disable-gbz80-port Excludes the Gameboy gbz80 port
1302 \labelwidthstring 00.00.0000
1307 \begin_layout Standard
1316 -disable-z80-port Excludes the z80 port
1320 \labelwidthstring 00.00.0000
1325 \begin_layout Standard
1334 -disable-avr-port Excludes the AVR port
1338 \labelwidthstring 00.00.0000
1343 \begin_layout Standard
1352 -disable-ds390-port Excludes the DS390 port
1356 \labelwidthstring 00.00.0000
1361 \begin_layout Standard
1370 -disable-hc08-port Excludes the HC08 port
1374 \labelwidthstring 00.00.0000
1379 \begin_layout Standard
1388 -disable-pic-port Excludes the PIC port
1392 \labelwidthstring 00.00.0000
1397 \begin_layout Standard
1406 -disable-xa51-port Excludes the XA51 port
1410 \labelwidthstring 00.00.0000
1415 \begin_layout Standard
1424 -disable-ucsim Disables configuring and building of ucsim
1428 \labelwidthstring 00.00.0000
1433 \begin_layout Standard
1442 -disable-device-lib Disables automatically building device libraries
1446 \labelwidthstring 00.00.0000
1451 \begin_layout Standard
1460 -disable-packihx Disables building packihx
1466 \labelwidthstring 00.00.0000
1471 \begin_layout Standard
1480 -enable-doc Build pdf, html and txt files from the lyx sources
1484 \labelwidthstring 00.00.0000
1489 \begin_layout Standard
1498 -enable-libgc Use the Bohem memory allocator.
1499 Lower runtime footprint.
1502 \begin_layout Standard
1503 Furthermore the environment variables CC, CFLAGS, ...
1504 the tools and their arguments can be influenced.
1505 Please see `configure -
1509 \begin_layout Standard
1518 -help` and the man/info pages of `configure` for details.
1523 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1524 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1525 SDCC_LIB_NAME are defined by `configure` too.
1526 At the moment it's not possible to change the default settings (it was
1527 simply never required).
1531 These configure options are compiled into the binaries,
1532 and can only be changed by rerunning 'configure' and recompiling SDCC.
1533 The configure options are written in
1537 to distinguish them from run time environment variables (see section search
1543 \begin_inset Quotes sld
1547 \begin_inset Quotes srd
1550 are used by the SDCC team to build the official Win32 binaries.
1551 The SDCC team uses Mingw32 to build the official Windows binaries, because
1555 \begin_layout Enumerate
1559 \begin_layout Enumerate
1560 a gcc compiler and last but not least
1563 \begin_layout Enumerate
1564 the binaries can be built by cross compiling on Sourceforge's compile farm.
1567 \begin_layout Standard
1568 See the examples, how to pass the Win32 settings to 'configure'.
1569 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1570 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1580 \begin_layout Standard
1582 \begin_inset Tabular
1583 <lyxtabular version="3" rows="9" columns="3">
1585 <column alignment="block" valignment="top" leftline="true" width="0in">
1586 <column alignment="block" valignment="top" leftline="true" width="0in">
1587 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1588 <row topline="true" bottomline="true">
1589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1592 \begin_layout Standard
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1601 \begin_layout Standard
1607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1610 \begin_layout Standard
1617 <row topline="true">
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1621 \begin_layout Standard
1629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1632 \begin_layout Standard
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1641 \begin_layout Standard
1650 <row topline="true">
1651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1654 \begin_layout Standard
1662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1665 \begin_layout Standard
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1676 \begin_layout Standard
1685 <row topline="true">
1686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1689 \begin_layout Standard
1697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1700 \begin_layout Standard
1710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1713 \begin_layout Standard
1726 <row topline="true">
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1730 \begin_layout Standard
1738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1741 \begin_layout Standard
1749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1752 \begin_layout Standard
1761 <row topline="true">
1762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1765 \begin_layout Standard
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_layout Standard
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1789 \begin_layout Standard
1798 <row topline="true">
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1802 \begin_layout Standard
1810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1813 \begin_layout Standard
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1826 \begin_layout Standard
1839 <row topline="true">
1840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1843 \begin_layout Standard
1851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1854 \begin_layout Standard
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1863 \begin_layout Standard
1870 <row topline="true" bottomline="true">
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1874 \begin_layout Standard
1882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1885 \begin_layout Standard
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1894 \begin_layout Standard
1910 \begin_layout Standard
1912 'configure' also computes relative paths.
1913 This is needed for full relocatability of a binary package and to complete
1914 search paths (see section search paths below):
1919 \begin_layout Standard
1921 \begin_inset Tabular
1922 <lyxtabular version="3" rows="4" columns="3">
1924 <column alignment="block" valignment="top" leftline="true" width="0in">
1925 <column alignment="block" valignment="top" leftline="true" width="0in">
1926 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1927 <row topline="true" bottomline="true">
1928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1931 \begin_layout Standard
1937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1940 \begin_layout Standard
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1949 \begin_layout Standard
1956 <row topline="true" bottomline="true">
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1960 \begin_layout Standard
1968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1971 \begin_layout Standard
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1980 \begin_layout Standard
1987 <row bottomline="true">
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1991 \begin_layout Standard
1999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2002 \begin_layout Standard
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2011 \begin_layout Standard
2018 <row bottomline="true">
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2022 \begin_layout Standard
2030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2033 \begin_layout Standard
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2042 \begin_layout Standard
2058 \begin_layout Standard
2063 \begin_layout LyX-Code
2070 \begin_layout Standard
2080 \begin_inset Quotes srd
2084 \begin_inset Quotes srd
2091 \begin_layout Standard
2101 \begin_inset Quotes srd
2105 \begin_inset Quotes srd
2114 \begin_layout Standard
2127 \begin_layout Standard
2139 \begin_layout Standard
2140 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2144 \begin_layout LyX-Code
2150 \begin_inset Quotes srd
2153 i586-mingw32msvc-gcc
2154 \begin_inset Quotes srd
2158 \begin_inset Quotes srd
2161 i586-mingw32msvc-g++
2162 \begin_inset Quotes srd
2170 \begin_inset Quotes srd
2173 i586-mingw32msvc-ranlib
2174 \begin_inset Quotes srd
2182 \begin_inset Quotes srd
2185 i586-mingw32msvc-strip
2186 \begin_inset Quotes srd
2197 \begin_layout Standard
2207 \begin_inset Quotes srd
2211 \begin_inset Quotes srd
2222 \begin_layout Standard
2232 \begin_inset Quotes srd
2236 \begin_inset Quotes srd
2244 \begin_inset Quotes srd
2250 \begin_inset Quotes srd
2258 \begin_inset Quotes srd
2262 \begin_inset Quotes srd
2270 \begin_inset Quotes srd
2274 \begin_inset Quotes srd
2281 sdccconf_h_dir_separator=
2282 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2305 \begin_layout Standard
2322 \begin_layout Standard
2331 -host=i586-mingw32msvc
2339 \begin_layout Standard
2348 -build=unknown-unknown-linux-gnu
2351 \begin_layout Standard
2353 \begin_inset Quotes sld
2357 \begin_inset Quotes srd
2360 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2364 \begin_layout LyX-Code
2373 \begin_layout Standard
2383 \begin_inset Quotes srd
2387 \begin_inset Quotes srd
2398 \begin_layout Standard
2408 \begin_inset Quotes srd
2412 \begin_inset Quotes srd
2420 \begin_inset Quotes srd
2426 \begin_inset Quotes srd
2434 \begin_inset Quotes srd
2438 \begin_inset Quotes srd
2446 \begin_inset Quotes srd
2450 \begin_inset Quotes srd
2457 sdccconf_h_dir_separator=
2458 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2478 \begin_inset Quotes srd
2482 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2494 \begin_inset Quotes srd
2500 \begin_layout Standard
2501 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2506 \begin_layout Standard
2515 -C' turns on caching, which gives a little bit extra speed.
2516 However if options are changed, it can be necessary to delete the config.cache
2520 \begin_layout Section
2522 \begin_inset LatexCommand \label{sub:Install-paths}
2527 \begin_inset LatexCommand \index{Install paths}
2534 \begin_layout Standard
2535 \begin_inset VSpace medskip
2541 \begin_layout Standard
2543 \begin_inset Tabular
2544 <lyxtabular version="3" rows="5" columns="4">
2546 <column alignment="left" valignment="top" leftline="true" width="0">
2547 <column alignment="left" valignment="top" leftline="true" width="0">
2548 <column alignment="left" valignment="top" leftline="true" width="0">
2549 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2550 <row topline="true" bottomline="true">
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2554 \begin_layout Standard
2562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2565 \begin_layout Standard
2573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2576 \begin_layout Standard
2584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2587 \begin_layout Standard
2596 <row topline="true">
2597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2600 \begin_layout Standard
2606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2609 \begin_layout Standard
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2620 \begin_layout Standard
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2629 \begin_layout Standard
2640 <row topline="true">
2641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2644 \begin_layout Standard
2650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2653 \begin_layout Standard
2656 $DATADIR/ $INCLUDE_DIR_SUFFIX
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_layout Standard
2665 /usr/local/share/sdcc/include
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2673 \begin_layout Standard
2684 <row topline="true">
2685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2688 \begin_layout Standard
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2697 \begin_layout Standard
2700 $DATADIR/$LIB_DIR_SUFFIX
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2708 \begin_layout Standard
2709 /usr/local/share/sdcc/lib
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2717 \begin_layout Standard
2728 <row topline="true" bottomline="true">
2729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2732 \begin_layout Standard
2738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2741 \begin_layout Standard
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_layout Standard
2753 /usr/local/share/sdcc/doc
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2761 \begin_layout Standard
2782 *compiler, preprocessor, assembler, and linker
2788 is auto-appended by the compiler, e.g.
2789 small, large, z80, ds390 etc
2792 \begin_layout Standard
2794 The install paths can still be changed during `make install` with e.g.:
2797 \begin_layout LyX-Code
2798 make install prefix=$(HOME)/local/sdcc
2801 \begin_layout Standard
2802 Of course this doesn't change the search paths compiled into the binaries.
2807 r the install path can be changed by defining DESTDIR
2808 \begin_inset LatexCommand \index{DESTDIR}
2815 \begin_layout LyX-Code
2816 make install DESTDIR=$(HOME)/sdcc.rpm/
2819 \begin_layout Standard
2820 Please note that DESTDIR must have a trailing slash!
2823 \begin_layout Section
2825 \begin_inset LatexCommand \label{sub:Search-Paths}
2830 \begin_inset LatexCommand \index{Search path}
2837 \begin_layout Standard
2838 Some search paths or parts of them are determined by configure variables
2843 , see section above).
2844 Further search paths are determined by environment variables during runtime.
2847 The paths searched when running the compiler are as follows (the first
2853 Binary files (preprocessor, assembler and linker)
2858 \begin_layout Standard
2860 \begin_inset Tabular
2861 <lyxtabular version="3" rows="4" columns="3">
2863 <column alignment="block" valignment="top" leftline="true" width="0in">
2864 <column alignment="block" valignment="top" leftline="true" width="0in">
2865 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2866 <row topline="true" bottomline="true">
2867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2870 \begin_layout Standard
2876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2879 \begin_layout Standard
2885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2888 \begin_layout Standard
2895 <row topline="true">
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2899 \begin_layout Standard
2907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2910 \begin_layout Standard
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2919 \begin_layout Standard
2928 <row topline="true">
2929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2932 \begin_layout Standard
2933 Path of argv[0] (if available)
2938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2941 \begin_layout Standard
2947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2950 \begin_layout Standard
2957 <row topline="true" bottomline="true">
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_layout Standard
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2970 \begin_layout Standard
2976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2979 \begin_layout Standard
2995 \begin_layout Standard
3003 \begin_layout Standard
3005 \begin_inset Tabular
3006 <lyxtabular version="3" rows="6" columns="3">
3008 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3009 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3010 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3011 <row topline="true" bottomline="true">
3012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3015 \begin_layout Standard
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3024 \begin_layout Standard
3030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3033 \begin_layout Standard
3040 <row topline="true">
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3044 \begin_layout Standard
3049 \begin_layout Standard
3063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3066 \begin_layout Standard
3071 \begin_layout Standard
3085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3088 \begin_layout Standard
3093 \begin_layout Standard
3108 <row topline="true">
3109 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3112 \begin_layout Standard
3118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3121 \begin_layout Standard
3127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3130 \begin_layout Standard
3137 <row topline="true">
3138 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3141 \begin_layout Standard
3153 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3156 \begin_layout Standard
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_layout Standard
3178 <row topline="true">
3179 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3182 \begin_layout Standard
3198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3201 \begin_layout Standard
3249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3252 \begin_layout Standard
3263 <row topline="true" bottomline="true">
3264 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3267 \begin_layout Standard
3281 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3284 \begin_layout Standard
3285 /usr/local/share/sdcc/
3292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3295 \begin_layout Standard
3311 \begin_layout Standard
3317 \begin_layout Standard
3326 -nostdinc disables the last two search paths.
3336 \begin_layout Standard
3337 With the exception of
3338 \begin_inset Quotes sld
3345 \begin_layout Standard
3355 \begin_inset Quotes srd
3362 is auto-appended by the compiler (e.g.
3363 small, large, z80, ds390 etc.).
3369 \begin_layout Standard
3371 \begin_inset Tabular
3372 <lyxtabular version="3" rows="6" columns="3">
3374 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3375 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3376 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3377 <row topline="true" bottomline="true">
3378 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3381 \begin_layout Standard
3387 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3390 \begin_layout Standard
3396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3399 \begin_layout Standard
3406 <row topline="true">
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3410 \begin_layout Standard
3415 \begin_layout Standard
3429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3432 \begin_layout Standard
3437 \begin_layout Standard
3451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3454 \begin_layout Standard
3459 \begin_layout Standard
3474 <row topline="true">
3475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3478 \begin_layout Standard
3488 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3491 \begin_layout Standard
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3504 \begin_layout Standard
3517 <row topline="true">
3518 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3521 \begin_layout Standard
3528 $LIB_DIR_SUFFIX/<model>
3533 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3536 \begin_layout Standard
3548 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3551 \begin_layout Standard
3566 <row topline="true">
3567 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3570 \begin_layout Standard
3581 $LIB_DIR_SUFFIX/<model>
3586 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3589 \begin_layout Standard
3640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3643 \begin_layout Standard
3697 <row topline="true" bottomline="true">
3698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3701 \begin_layout Standard
3706 $LIB_DIR_SUFFIX/<model>
3711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3714 \begin_layout Standard
3715 /usr/local/share/sdcc/
3724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3727 \begin_layout Standard
3743 \begin_layout Standard
3744 \begin_inset Note Comment
3747 \begin_layout Standard
3748 Don't delete any of the stray spaces in the table above without checking
3749 the HTML output (last line)!
3757 \begin_layout Standard
3765 \begin_layout Standard
3774 -nostdlib disables the last two search paths.
3777 \begin_layout Section
3779 \begin_inset LatexCommand \index{Building SDCC}
3786 \begin_layout Subsection
3787 Building SDCC on Linux
3788 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3795 \begin_layout Enumerate
3798 Download the source package
3800 either from the SDCC Subversion repository or from the nightly snapshots
3802 , it will be named something like sdcc
3813 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3820 \begin_layout Enumerate
3823 Bring up a command line terminal, such as xterm.
3826 \begin_layout Enumerate
3829 Unpack the file using a command like:
3832 "tar -xvzf sdcc.src.tar.gz
3837 , this will create a sub-directory called sdcc with all of the sources.
3840 \begin_layout Enumerate
3841 Change directory into the main SDCC directory, for example type:
3849 \begin_layout Enumerate
3859 This configures the package for compilation on your system.
3862 \begin_layout Enumerate
3876 All of the source packages will compile, this can take a while.
3879 \begin_layout Enumerate
3893 This copies the binary executables, the include files, the libraries and
3894 the documentation to the install directories.
3895 Proceed with section
3896 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3903 \begin_layout Subsection
3904 Building SDCC on OSX 2.x
3907 \begin_layout Standard
3908 Follow the instruction for Linux.
3912 On OSX 2.x it was reported, that the default
3913 gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3914 Fortunately there's also gcc 2.9.x installed, which works fine.
3915 This compiler can be selected by running 'configure' with:
3918 \begin_layout LyX-Code
3919 ./configure CC=gcc2 CXX=g++2
3922 \begin_layout Subsection
3923 Cross compiling SDCC on Linux for Windows
3926 \begin_layout Standard
3927 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3928 See section 'Configure Options'.
3931 \begin_layout Subsection
3932 Building SDCC using Cygwin and Mingw32
3935 \begin_layout Standard
3936 For building and installing a Cygwin executable follow the instructions
3942 \begin_inset Quotes sld
3946 \begin_inset Quotes srd
3949 Win32-binary can be built, which will not need the Cygwin-DLL.
3950 For the necessary 'configure' options see section 'configure options' or
3951 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3956 Cygwin on Windows download setup.exe from
3957 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3963 \begin_inset Quotes sld
3966 default text file type
3967 \begin_inset Quotes srd
3971 \begin_inset Quotes sld
3975 \begin_inset Quotes srd
3978 and download/install at least the following packages.
3979 Some packages are selected by default, others will be automatically selected
3980 because of dependencies with the manually selected packages.
3981 Never deselect these packages!
3984 \begin_layout Itemize
3988 \begin_layout Itemize
3992 \begin_layout Itemize
3993 gcc ; version 3.x is fine, no need to use the old 2.9x
3996 \begin_layout Itemize
3997 binutils ; selected with gcc
4000 \begin_layout Itemize
4004 \begin_layout Itemize
4005 rxvt ; a nice console, which makes life much easier under windoze (see below)
4008 \begin_layout Itemize
4009 man ; not really needed for building SDCC, but you'll miss it sooner or
4013 \begin_layout Itemize
4014 less ; not really needed for building SDCC, but you'll miss it sooner or
4018 \begin_layout Itemize
4019 svn ; only if you use Subversion access
4022 \begin_layout Standard
4023 If you want to develop something you'll need:
4026 \begin_layout Itemize
4027 python ; for the regression tests
4030 \begin_layout Itemize
4031 gdb ; the gnu debugger, together with the nice GUI
4032 \begin_inset Quotes sld
4036 \begin_inset Quotes srd
4042 \begin_layout Itemize
4043 openssh ; to access the CF or commit changes
4046 \begin_layout Itemize
4047 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4048 use autoconf-stable!
4051 \begin_layout Standard
4052 rxvt is a nice console with history.
4053 Replace in your cygwin.bat the line
4056 \begin_layout LyX-Code
4061 \begin_layout Standard
4073 \begin_layout Standard
4077 \begin_layout LyX-Code
4078 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4081 \begin_layout LyX-Code
4082 -bg black -fg white -geometry 100x65 -e bash -
4086 \begin_layout Standard
4098 \begin_layout Standard
4099 Text selected with the mouse is automatically copied to the clipboard, pasting
4100 works with shift-insert.
4104 The other good tip is to make sure you have no //c/-styl
4105 e paths anywhere, use /cygdrive/c/ instead.
4106 Using // invokes a network lookup which is very slow.
4108 \begin_inset Quotes sld
4112 \begin_inset Quotes srd
4115 is too long, you can change it with e.g.
4118 \begin_layout LyX-Code
4122 \begin_layout Standard
4123 SDCC sources use the unix line ending LF.
4124 Life is much easier, if you store the source tree on a drive which is mounted
4126 And use an editor which can handle LF-only line endings.
4127 Make sure not to commit files with windows line endings.
4128 The tabulator spacing
4129 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4133 used in the project is 8.
4134 Although a tabulator spacing of 8 is a sensible choice for programmers
4135 (it's a power of 2 and allows to display 8/16 bit signed variables without
4136 loosing columns) the plan is to move towards using only spaces in the source.
4139 \begin_layout Subsection
4140 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4143 \begin_layout Standard
4146 Download the source package
4148 either from the SDCC Subversion repository or from the
4149 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
4155 , it will be named something like sdcc
4162 SDCC is distributed with all the projects, workspaces, and files you need
4163 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4164 The workspace name is 'sdcc.dsw'.
4165 Please note that as it is now, all the executables are created in a folder
4169 Once built you need to copy the executables from sdcc
4173 bin before running SDCC.
4178 WARNING: Visual studio is very picky with line terminations; it expects
4179 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4180 When using the Subversion repository it's easiest to configure the svn
4181 client to convert automatically for you.
4182 If however you are getting a message such as "This makefile was not generated
4183 by Developer Studio etc.
4185 \begin_inset Quotes srd
4188 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4189 need to convert the Unix style line endings to DOS style line endings.
4190 To do so you can use the
4191 \begin_inset Quotes sld
4195 \begin_inset Quotes srd
4198 utility freely available on the internet.
4199 Doug Hawkins reported in the sdcc-user list that this works:
4207 SDCC> unix2dos sdcc.dsw
4213 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4217 In order to build SDCC with MSVC
4218 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4219 One good place to get them is
4220 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4228 Download the file UnxUtils
4229 \begin_inset LatexCommand \index{UnxUtils}
4234 Now you have to install the utilities and setup MSVC so it can locate the
4236 Here there are two alternatives (choose one!):
4239 \begin_layout Enumerate
4244 a) Extract UnxUtils.zip to your C:
4246 hard disk PRESERVING the original paths, otherwise bison won't work.
4247 (If you are using WinZip make certain that 'Use folder names' is selected)
4252 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4253 'Show directories for:' select 'Executable files', and in the directories
4254 window add a new path: 'C:
4264 (As a side effect, you get a bunch of Unix utilities that
4265 could be useful, such as diff and patch.)
4268 \begin_layout Enumerate
4273 This one avoids extracting a bunch of files you may not
4274 use, but requires some extra work:
4278 a) Create a directory were to put the
4279 tools needed, or use a directory already present.
4286 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4287 gawk.exe to such directory WITHOUT preserving the original paths.
4288 (If you are using WinZip make certain that 'Use folder names' is not selected)
4293 ) Rename bison.exe to '_bison.exe'.
4297 d) Create a batch file 'bison.bat' in 'C:
4301 ' and add these lines:
4321 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4325 Steps 'c' and 'd' are needed
4326 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4327 reside in some weird Unix directory, '/usr/local/share/' I think.
4328 So it is necessary to tell bison where those files are located if they
4329 are not in such directory.
4330 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4335 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4336 in 'Show directories for:' select 'Executable files', and in the directories
4337 window add a new path: 'c:
4340 Note that you can use any other path instead of 'c:
4342 util', even the path where the Visual C++ tools are, probably: 'C:
4346 Microsoft Visual Studio
4351 So you don't have to execute step 'e' :)
4354 \begin_layout Standard
4356 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4357 the executables from sdcc
4361 bin, and you can compile using SDCC.
4364 \begin_layout Subsection
4365 Building SDCC Using Borland
4368 \begin_layout Enumerate
4369 From the sdcc directory, run the command "make -f Makefile.bcc".
4370 This should regenerate all the .exe files in the bin directory except for
4374 \begin_layout Enumerate
4375 If you modify any source files and need to rebuild, be aware that the dependenci
4376 es may not be correctly calculated.
4377 The safest option is to delete all .obj files and run the build again.
4378 From a Cygwin BASH prompt, this can easily be done with the command (be
4379 sure you are in the sdcc directory):
4389 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4391 ) -print -exec rm {}
4400 or on Windows NT/2000/XP from the command prompt with the command:
4407 del /s *.obj *.lib *.rul
4410 from the sdcc directory.
4413 \begin_layout Subsection
4414 Windows Install Using a ZIP Package
4417 \begin_layout Enumerate
4418 Download the binary zip package from
4419 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4423 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4424 This should unpack to a group of sub-directories.
4425 An example directory structure after unpacking the mingw32 package is:
4430 bin for the executables, c:
4438 lib for the include and libraries.
4441 \begin_layout Enumerate
4442 Adjust your environment variable PATH to include the location of the bin
4443 directory or start sdcc using the full path.
4446 \begin_layout Subsection
4447 Windows Install Using the Setup Program
4448 \begin_inset LatexCommand \label{sub:Windows-Install}
4455 \begin_layout Standard
4456 Download the setup program
4458 sdcc-x.y.z-setup.exe
4460 for an official release from
4463 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4467 or a setup program for one of the snapshots
4469 sdcc-yyyymmdd-xxxx-setup.exe
4472 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4477 A windows typical installer will guide you through the installation process.
4480 \begin_layout Subsection
4482 \begin_inset LatexCommand \index{VPATH}
4489 \begin_layout Standard
4490 SDCC supports the VPATH feature provided by configure and make.
4491 It allows to separate the source and build trees.
4495 \begin_layout Standard
4522 \begin_layout Standard
4525 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4526 # extract source to directory sdcc
4529 \begin_layout Standard
4532 mkdir sdcc.build\InsetSpace ~
4541 # put output in sdcc.build
4544 \begin_layout Standard
4550 \begin_layout Standard
4553 ../sdcc/configure\InsetSpace ~
4561 # configure is doing all the magic!
4564 \begin_layout Standard
4570 \begin_layout Standard
4576 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4577 It automagically computes the variables srcdir, top_srcdir and top_buildir
4583 the generated files will be in ~/sdcc.build, while the source files stay
4586 This is not only usefull for building different binaries, e.g.
4587 when cross compiling.
4588 It also gives you a much better overview in the source tree when all the
4589 generated files are not scattered between the source files.
4590 And the best thing is: if you want to change a file you can leave the original
4591 file untouched in the source directory.
4592 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4593 Makefile.dep` and `make`.
4598 will do the rest for you!
4601 \begin_layout Section
4602 Building the Documentation
4605 \begin_layout Standard
4610 \begin_layout Standard
4619 -enable-doc to the configure arguments to build the documentation together
4620 with all the other stuff.
4621 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4622 dvips and makeindex) to get the job done.
4623 Another possibility is to change to the doc directory and to type
4627 \begin_inset Quotes srd
4631 \begin_inset Quotes srd
4638 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4641 \begin_inset LatexCommand \url{http://www.lyx.org}
4645 as editor is straightforward.
4646 Prebuilt documentation in html and pdf format is available from
4647 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4654 \begin_layout Section
4655 Reading the Documentation
4656 \begin_inset LatexCommand \index{Documentation}
4663 \begin_layout Standard
4664 Currently reading the document in pdf format is recommended, as for unknown
4665 reason the hyperlinks are working there whereas in the html version they
4670 \begin_layout Standard
4671 If you should know why please drop us a note
4679 You'll find the pdf version
4680 \begin_inset LatexCommand \index{PDF version of this document}
4685 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4693 \begin_inset LatexCommand \index{HTML version of this document}
4698 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4704 This documentation is in some aspects different from a commercial documentation:
4708 \begin_layout Itemize
4709 It tries to document SDCC for several processor architectures in one document
4710 (commercially these probably would be separate documents/products).
4712 \begin_inset LatexCommand \index{Status of documentation}
4716 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4718 Z80, PIC14, PIC16 and HC08.
4721 \begin_layout Itemize
4722 There are many references pointing away from this documentation.
4723 Don't let this distract you.
4725 was a reference like
4726 \begin_inset LatexCommand \url{http://www.opencores.org}
4730 together with a statement
4731 \begin_inset Quotes sld
4734 some processors which are targetted by SDCC can be implemented in a
4751 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4756 \begin_inset Quotes srd
4760 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4765 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4770 \begin_inset Quotes sld
4773 have you ever heard of an open source compiler that compiles a subset of
4775 \begin_inset Quotes srd
4778 we expect you to have a quick look there and come back.
4779 If you read this you are on the right track.
4782 \begin_layout Itemize
4783 Some sections attribute more space to problems, restrictions and warnings
4784 than to the solution.
4787 \begin_layout Itemize
4788 The installation section and the section about the debugger is intimidating.
4791 \begin_layout Itemize
4792 There are still lots of typos and there are more different writing styles
4796 \begin_layout Section
4797 Testing the SDCC Compiler
4798 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4805 \begin_layout Standard
4806 The first thing you should do after installing your SDCC compiler is to
4815 \begin_layout Standard
4825 \begin_inset LatexCommand \index{version}
4832 at the prompt, and the program should run and output its version like:
4837 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4841 \begin_layout Standard
4842 If it doesn't run, or gives a message about not finding sdcc program, then
4843 you need to check over your installation.
4844 Make sure that the sdcc bin directory is in your executable search path
4845 defined by the PATH environment setting (
4850 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4857 Install trouble-shooting for suggestions
4860 Make sure that the sdcc program is in the bin folder, if not perhaps something
4861 did not install correctly.
4869 is commonly installed as described in section
4870 \begin_inset Quotes sld
4873 Install and search paths
4874 \begin_inset Quotes srd
4883 Make sure the compiler works on a very simple example.
4884 Type in the following test.c program using your favorite
4909 \begin_layout Standard
4912 Compile this using the following command:
4921 If all goes well, the compiler will generate a test.asm and test.rel file.
4922 Congratulations, you've just compiled your first program with SDCC.
4923 We used the -c option to tell SDCC not to link the generated code, just
4924 to keep things simple for this step.
4932 The next step is to try it with the linker.
4942 If all goes well the compiler will link with the libraries and produce
4943 a test.ihx output file.
4948 (no test.ihx, and the linker generates warnings), then the problem is most
4957 usr/local/share/sdcc/lib directory
4964 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4971 Install trouble-shooting for suggestions).
4979 The final test is to ensure
4987 header files and libraries.
4988 Edit test.c and change it to the following:
5006 strcpy(str1, "testing");
5011 \begin_layout Standard
5014 Compile this by typing
5021 This should generate a test.ihx output file, and it should give no warnings
5022 such as not finding the string.h file.
5023 If it cannot find the string.h file, then the problem is that
5027 cannot find the /usr/local/share/sdcc/include directory
5034 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5041 Install trouble-shooting section for suggestions).
5050 \begin_layout Standard
5062 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5066 to find exactly where SDCC is looking for the include and lib files.
5069 \begin_layout Section
5070 Install Trouble-shooting
5071 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5076 \begin_inset LatexCommand \index{Install trouble-shooting}
5083 \begin_layout Subsection
5084 If SDCC does not build correctly
5087 \begin_layout Standard
5088 A thing to try is starting from scratch by unpacking the .tgz source package
5089 again in an empty directory.
5097 ./configure 2>&1 | tee configure.log
5111 make 2>&1 | tee make.log
5118 If anything goes wrong, you can review the log files to locate the problem.
5119 Or a relevant part of this can be attached to an email that could be helpful
5120 when requesting help from the mailing list.
5123 \begin_layout Subsection
5125 \begin_inset Quotes sld
5129 \begin_inset Quotes srd
5135 \begin_layout Standard
5137 \begin_inset Quotes sld
5141 \begin_inset Quotes srd
5144 command is a script that analyzes your system and performs some configuration
5145 to ensure the source package compiles on your system.
5146 It will take a few minutes to run, and will compile a few tests to determine
5147 what compiler features are installed.
5150 \begin_layout Subsection
5152 \begin_inset Quotes sld
5156 \begin_inset Quotes srd
5162 \begin_layout Standard
5163 This runs the GNU make tool, which automatically compiles all the source
5164 packages into the final installed binary executables.
5167 \begin_layout Subsection
5169 \begin_inset Quotes sld
5173 \begin_inset Quotes erd
5179 \begin_layout Standard
5180 This will install the compiler, other executables libraries and include
5181 files into the appropriate directories.
5183 \begin_inset LatexCommand \ref{sub:Install-paths}
5189 \begin_inset LatexCommand \ref{sub:Search-Paths}
5194 about install and search paths.
5196 On most systems you will need super-user privilege
5200 \begin_layout Section
5204 \begin_layout Standard
5205 SDCC is not just a compiler, but a collection of tools by various developers.
5206 These include linkers, assemblers, simulators and other components.
5207 Here is a summary of some of the components.
5208 Note that the included simulator and assembler have separate documentation
5209 which you can find in the source package in their respective directories.
5210 As SDCC grows to include support for other processors, other packages from
5211 various developers are included and may have their own sets of documentation.
5216 might want to look at the files which are installed in <installdir>.
5217 At the time of this writing, we find the following programs for gcc-builds:
5222 In <installdir>/bin:
5225 \begin_layout Itemize
5226 sdcc - The compiler.
5229 \begin_layout Itemize
5230 sdcpp - The C preprocessor.
5233 \begin_layout Itemize
5234 asx8051 - The assembler for 8051 type processors.
5237 \begin_layout Itemize
5242 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5245 \begin_layout Itemize
5246 aslink -The linker for 8051 type processors.
5249 \begin_layout Itemize
5254 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5257 \begin_layout Itemize
5258 s51 - The ucSim 8051 simulator.
5261 \begin_layout Itemize
5262 sdcdb - The source debugger.
5265 \begin_layout Itemize
5266 packihx - A tool to pack (compress) Intel hex files.
5269 \begin_layout Standard
5270 In <installdir>/share/sdcc/include
5273 \begin_layout Itemize
5277 \begin_layout Standard
5278 In <installdir>/share/sdcc/lib
5281 \begin_layout Itemize
5282 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5286 \begin_layout Standard
5287 In <installdir>/share/sdcc/doc
5290 \begin_layout Itemize
5294 \begin_layout Standard
5295 As development for other processors proceeds, this list will expand to include
5296 executables to support processors like AVR, PIC, etc.
5299 \begin_layout Subsection
5303 \begin_layout Standard
5304 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5305 the assembler and linkage editor.
5308 \begin_layout Subsection
5309 sdcpp - The C-Preprocessor
5312 \begin_layout Standard
5314 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5318 is a modified version of the GNU cpp
5319 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5324 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5329 The C preprocessor is used to pull in #include sources, process #ifdef
5330 statements, #defines and so on.
5333 \begin_layout Subsection
5342 - The Assemblers and Linkage Editors
5345 \begin_layout Standard
5346 This is retargettable assembler & linkage editor, it was developed by Alan
5348 John Hartman created the version for 8051, and I (Sandeep) have made some
5349 enhancements and bug fixes for it to work properly with SDCC.
5352 \begin_layout Subsection
5356 \begin_layout Standard
5358 \begin_inset LatexCommand \index{s51}
5362 is a freeware, opensource simulator developed by Daniel Drotos.
5363 The simulator is built as part of the build process.
5364 For more information visit Daniel's web site at:
5365 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5370 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5374 \begin_layout Subsection
5375 sdcdb - Source Level Debugger
5378 \begin_layout Standard
5380 \begin_inset LatexCommand \index{SDCDB (debugger)}
5384 is the companion source level debugger.
5385 More about SDCDB in section
5386 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5391 The current version of the debugger uses Daniel's Simulator S51
5392 \begin_inset LatexCommand \index{s51}
5396 , but can be easily changed to use other simulators.
5399 \begin_layout Chapter
5403 \begin_layout Section
5407 \begin_layout Subsection
5408 Single Source File Projects
5411 \begin_layout Standard
5412 For single source file 8051 projects the process is very simple.
5413 Compile your programs with the following command
5416 "sdcc sourcefile.c".
5420 This will compile, assemble and link your source file.
5421 Output files are as follows:
5424 \begin_layout Itemize
5426 \begin_inset LatexCommand \index{<file>.asm}
5431 \begin_inset LatexCommand \index{Assembler source}
5435 file created by the compiler
5438 \begin_layout Itemize
5440 \begin_inset LatexCommand \index{<file>.lst}
5445 \begin_inset LatexCommand \index{Assembler listing}
5449 file created by the Assembler
5452 \begin_layout Itemize
5454 \begin_inset LatexCommand \index{<file>.rst}
5459 \begin_inset LatexCommand \index{Assembler listing}
5463 file updated with linkedit information, created by linkage editor
5466 \begin_layout Itemize
5468 \begin_inset LatexCommand \index{<file>.sym}
5473 \begin_inset LatexCommand \index{Symbol listing}
5477 for the sourcefile, created by the assembler
5480 \begin_layout Itemize
5482 \begin_inset LatexCommand \index{<file>.rel}
5487 \begin_inset LatexCommand \index{<file>.o}
5492 \begin_inset LatexCommand \index{Object file}
5496 created by the assembler, input to Linkage editor
5499 \begin_layout Itemize
5501 \begin_inset LatexCommand \index{<file>.map}
5506 \begin_inset LatexCommand \index{Memory map}
5510 for the load module, created by the Linker
5513 \begin_layout Itemize
5515 \begin_inset LatexCommand \index{<file>.mem}
5519 - A file with a summary of the memory usage
5522 \begin_layout Itemize
5524 \begin_inset LatexCommand \index{<file>.ihx}
5528 - The load module in Intel hex format
5529 \begin_inset LatexCommand \index{Intel hex format}
5533 (you can select the Motorola S19 format
5534 \begin_inset LatexCommand \index{Motorola S19 format}
5542 \begin_layout Standard
5552 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5557 If you need another format you might want to use
5564 \begin_inset LatexCommand \index{objdump (tool)}
5575 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5580 Both formats are documented in the documentation of srecord
5581 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5588 \begin_layout Itemize
5590 \begin_inset LatexCommand \index{<file>.adb}
5594 - An intermediate file containing debug information needed to create the
5599 \begin_layout Standard
5609 \begin_inset LatexCommand \index{-\/-debug}
5616 \begin_layout Itemize
5618 \begin_inset LatexCommand \index{<file>.cdb}
5622 - An optional file (with -
5626 \begin_layout Standard
5635 -debug) containing debug information.
5636 The format is documented in cdbfileformat.pdf
5639 \begin_layout Itemize
5642 \begin_inset LatexCommand \index{<file> (no extension)}
5646 An optional AOMF or AOMF51
5647 \begin_inset LatexCommand \index{AOMF, AOMF51}
5652 \begin_inset LatexCommand \label{OMF file}
5656 file containing debug information (generated with option -
5660 \begin_layout Standard
5686 ormat is commonly used by third party tools (debuggers
5687 \begin_inset LatexCommand \index{Debugger}
5691 , simulators, emulators)
5694 \begin_layout Itemize
5696 \begin_inset LatexCommand \index{<file>.dump*}
5700 - Dump file to debug the compiler it self (generated with option -
5704 \begin_layout Standard
5713 -dumpall) (see section
5714 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5720 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5726 \begin_inset Quotes sld
5729 Anatomy of the compiler
5730 \begin_inset Quotes srd
5736 \begin_layout Subsection
5737 Postprocessing the Intel Hex
5738 \begin_inset LatexCommand \index{Intel hex format}
5745 \begin_layout Standard
5746 In most cases this won't be needed but the Intel Hex file
5747 \begin_inset LatexCommand \index{<file>.ihx}
5751 which is generated by SDCC might include lines of varying length and the
5752 addresses within the file are not guaranteed to be strictly ascending.
5753 If your toolchain or a bootloader does not like this you can use the tool
5759 \begin_inset LatexCommand \index{packihx (tool)}
5763 which is part of the SDCC distribution:
5770 packihx sourcefile.ihx >sourcefile.hex
5777 The separately available
5782 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5786 package additionally allows to set undefined locations to a predefined
5787 value, to insert checksums
5788 \begin_inset LatexCommand \index{checksum}
5792 of various flavours (crc, add, xor) and to perform other manipulations
5793 (convert, split, crop, offset, ...).
5801 srec_cat\InsetSpace ~
5803 sourcefile.ihx -intel\InsetSpace ~
5805 -o sourcefile.hex -intel
5812 An example for a more complex command line
5816 \begin_layout Standard
5817 the command backfills
5818 \begin_inset LatexCommand \index{backfill unused memory}
5822 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5824 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5825 will be interpreted as an
5833 (where an emergency routine could sit).
5846 srec_cat\InsetSpace ~
5847 sourcefile.ihx -intel\InsetSpace ~
5849 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5850 -little-endian-checksum-nega
5851 tive 0xfffe 0x02 0x02\InsetSpace ~
5853 -o sourcefile.hex -intel
5862 The srecord package is available at
5863 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5870 \begin_layout Subsection
5871 Projects with Multiple Source Files
5874 \begin_layout Standard
5875 SDCC can compile only ONE file at a time.
5876 Let us for example assume that you have a project containing the following
5881 foo1.c (contains some functions)
5883 foo2.c (contains some more functions)
5886 n.c (contains more functions and the function main)
5894 The first two files will need to be compiled separately with the commands:
5926 Then compile the source file containing the
5931 \begin_inset LatexCommand \index{Linker}
5935 the files together with the following command:
5943 foomain.c\InsetSpace ~
5944 foo1.rel\InsetSpace ~
5949 \begin_inset LatexCommand \index{<file>.rel}
5961 can be separately compiled as well:
5972 sdcc foomain.rel foo1.rel foo2.rel
5979 The file containing the
5994 file specified in the command line, since the linkage editor processes
5995 file in the order they are presented to it.
5996 The linker is invoked from SDCC using a script file with extension .lnk
5997 \begin_inset LatexCommand \index{<file>.lnk}
6002 You can view this file to troubleshoot linking problems such as those arising
6003 from missing libraries.
6006 \begin_layout Subsection
6007 Projects with Additional Libraries
6008 \begin_inset LatexCommand \index{Libraries}
6015 \begin_layout Standard
6016 Some reusable routines may be compiled into a library, see the documentation
6017 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6021 \begin_inset LatexCommand \index{<file>.lib}
6028 Libraries created in this manner can be included in the command line.
6029 Make sure you include the -L <library-path> option to tell the linker where
6030 to look for these files if they are not in the current directory.
6031 Here is an example, assuming you have the source file
6043 (if that is not the same as your current project):
6050 sdcc foomain.c foolib.lib -L mylib
6061 must be an absolute path name.
6065 The most efficient way to use libraries is
6066 to keep separate modules in separate source files.
6067 The lib file now should name all the modules.rel
6068 \begin_inset LatexCommand \index{<file>.rel}
6073 For an example see the standard library file
6077 in the directory <installdir>/share/lib/small.
6080 \begin_layout Subsection
6081 Using sdcclib to Create and Manage Libraries
6082 \begin_inset LatexCommand \index{sdcclib}
6089 \begin_layout Standard
6090 Alternatively, instead of having a .rel file for each entry on the library
6091 file as described in the preceding section, sdcclib can be used to embed
6092 all the modules belonging to such library in the library file itself.
6093 This results in a larger library file, but it greatly reduces the number
6094 of disk files accessed by the linker.
6095 Additionally, the packed library file contains an index of all include
6096 modules and symbols that significantly speeds up the linking process.
6097 To display a list of options supported by sdcclib type:
6102 \begin_layout Standard
6107 \begin_inset LatexCommand \index{sdcclib}
6118 To create a new library file, start by compiling all the required modules.
6124 \begin_layout Standard
6131 \begin_layout Standard
6138 \begin_layout Standard
6145 \begin_layout Standard
6152 \begin_layout Standard
6161 \begin_layout Standard
6162 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6164 The next step is to add the .rel files to the library file:
6169 \begin_layout Standard
6173 sdcclib libint.lib _divsint.rel
6176 \begin_inset LatexCommand \index{sdcclib}
6183 \begin_layout Standard
6187 sdcclib libint.lib _divuint.rel
6190 \begin_layout Standard
6194 sdcclib libint.lib _modsint.rel
6197 \begin_layout Standard
6201 sdcclib libint.lib _moduint.rel
6204 \begin_layout Standard
6208 sdcclib libint.lib _mulint.rel
6215 \begin_layout Standard
6216 If the file already exists in the library, it will be replaced.
6217 To see what modules and symbols are included in the library, options -s
6218 and -m are available.
6226 sdcclib -s libint.lib
6229 \begin_inset LatexCommand \index{sdcclib}
6241 \begin_layout Standard
6247 \begin_layout Standard
6253 \begin_layout Standard
6261 \begin_layout Standard
6267 \begin_layout Standard
6273 \begin_layout Standard
6279 \begin_layout Standard
6285 \begin_layout Standard
6293 \begin_layout Standard
6299 \begin_layout Standard
6305 \begin_layout Standard
6313 \begin_layout Standard
6319 \begin_layout Standard
6325 \begin_layout Standard
6331 \begin_layout Standard
6339 \begin_layout Standard
6345 \begin_layout Standard
6356 \begin_layout Standard
6357 If the source files are compiled using -
6361 \begin_layout Standard
6371 \begin_inset LatexCommand \index{-\/-debug}
6375 , the corresponding debug information file .adb will be include in the library
6377 The library files created with sdcclib are plain text files, so they can
6378 be viewed with a text editor.
6379 It is not recomended to modify a library file created with sdcclib using
6380 a text editor, as there are file indexes numbers located accross the file
6381 used by the linker to quickly locate the required module to link.
6382 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6383 it can be safely deleted, since all the information required for linking
6384 is embedded in the library file itself.
6385 Library files created using sdcclib are used as described in the preceding
6387 \begin_inset VSpace bigskip
6393 \begin_layout Section
6394 Command Line Options
6395 \begin_inset LatexCommand \index{Command Line Options}
6402 \begin_layout Subsection
6403 Processor Selection Options
6404 \begin_inset LatexCommand \index{Options processor selection}
6409 \begin_inset LatexCommand \index{Processor selection options}
6417 \labelwidthstring 00.00.0000
6421 \begin_inset LatexCommand \index{-mmcs51}
6427 Generate code for the Intel MCS51
6428 \begin_inset LatexCommand \index{MCS51}
6432 family of processors.
6433 This is the default processor target.
6437 \labelwidthstring 00.00.0000
6441 \begin_inset LatexCommand \index{-mds390}
6447 Generate code for the Dallas DS80C390
6448 \begin_inset LatexCommand \index{DS80C390}
6456 \labelwidthstring 00.00.0000
6460 \begin_inset LatexCommand \index{-mds400}
6466 Generate code for the Dallas DS80C400
6467 \begin_inset LatexCommand \index{DS80C400}
6475 \labelwidthstring 00.00.0000
6479 \begin_inset LatexCommand \index{-mhc08}
6485 Generate code for the Freescale/Motorola HC08
6486 \begin_inset LatexCommand \index{HC08}
6490 family of processors.
6494 \labelwidthstring 00.00.0000
6498 \begin_inset LatexCommand \index{-mz80}
6504 Generate code for the Zilog Z80
6505 \begin_inset LatexCommand \index{Z80}
6509 family of processors.
6513 \labelwidthstring 00.00.0000
6517 \begin_inset LatexCommand \index{-mgbz80}
6523 Generate code for the GameBoy Z80
6524 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6528 processor (Not actively maintained).
6532 \labelwidthstring 00.00.0000
6536 \begin_inset LatexCommand \index{-mavr}
6542 Generate code for the Atmel AVR
6543 \begin_inset LatexCommand \index{AVR}
6547 processor (Not maintained, not complete).
6548 AVR users should probably have a look at winavr
6549 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6554 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6561 \begin_layout Standard
6562 \begin_inset Note Comment
6565 \begin_layout Standard
6566 I think it is fair to direct users there for now.
6567 Open source is also about avoiding unnecessary work .
6568 But I didn't find the 'official' link.
6577 \labelwidthstring 00.00.0000
6581 \begin_inset LatexCommand \index{-mpic14}
6587 Generate code for the Microchip PIC 14
6588 \begin_inset LatexCommand \index{PIC14}
6592 -bit processors (p16f84 and variants.
6593 In development, not complete).
6596 \begin_layout Standard
6597 \begin_inset Note Comment
6600 \begin_layout Standard
6601 p16f627 p16f628 p16f84 p16f873 p16f877?
6610 \labelwidthstring 00.00.0000
6614 \begin_inset LatexCommand \index{-mpic16}
6620 Generate code for the Microchip PIC 16
6621 \begin_inset LatexCommand \index{PIC16}
6625 -bit processors (p18f452 and variants.
6626 In development, not complete).
6630 \labelwidthstring 00.00.0000
6635 Generate code for the Toshiba TLCS-900H
6636 \begin_inset LatexCommand \index{TLCS-900H}
6640 processor (Not maintained, not complete).
6644 \labelwidthstring 00.00.0000
6648 \begin_inset LatexCommand \index{-mxa51}
6654 Generate code for the Phillips XA51
6655 \begin_inset LatexCommand \index{XA51}
6659 processor (Not maintained, not complete).
6662 \begin_layout Standard
6663 \begin_inset VSpace bigskip
6669 \begin_layout Subsection
6670 Preprocessor Options
6671 \begin_inset LatexCommand \index{Options preprocessor}
6676 \begin_inset LatexCommand \index{Preprocessor options}
6681 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6689 \labelwidthstring 00.00.0000
6693 \begin_inset LatexCommand \index{-I<path>}
6699 The additional location where the pre processor will look for <..h> or
6700 \begin_inset Quotes eld
6704 \begin_inset Quotes erd
6711 \labelwidthstring 00.00.0000
6715 \begin_inset LatexCommand \index{-D<macro[=value]>}
6721 Command line definition of macros.
6722 Passed to the preprocessor.
6726 \labelwidthstring 00.00.0000
6730 \begin_inset LatexCommand \index{-M}
6736 Tell the preprocessor to output a rule suitable for make describing the
6737 dependencies of each object file.
6738 For each source file, the preprocessor outputs one make-rule whose target
6739 is the object file name for that source file and whose dependencies are
6740 all the files `#include'd in it.
6741 This rule may be a single line or may be continued with `
6743 '-newline if it is long.
6744 The list of rules is printed on standard output instead of the preprocessed
6747 \begin_inset LatexCommand \index{-E}
6755 \labelwidthstring 00.00.0000
6759 \begin_inset LatexCommand \index{-C}
6765 Tell the preprocessor not to discard comments.
6766 Used with the `-E' option.
6770 \labelwidthstring 00.00.0000
6774 \begin_inset LatexCommand \index{-MM}
6785 Like `-M' but the output mentions only the user header files included with
6787 \begin_inset Quotes eld
6791 System header files included with `#include <file>' are omitted.
6795 \labelwidthstring 00.00.0000
6799 \begin_inset LatexCommand \index{-Aquestion(answer)}
6805 Assert the answer answer for question, in case it is tested with a preprocessor
6806 conditional such as `#if #question(answer)'.
6807 `-A-' disables the standard assertions that normally describe the target
6812 \labelwidthstring 00.00.0000
6816 \begin_inset LatexCommand \index{-Umacro}
6822 Undefine macro macro.
6823 `-U' options are evaluated after all `-D' options, but before any `-include'
6824 and `-imacros' options.
6828 \labelwidthstring 00.00.0000
6832 \begin_inset LatexCommand \index{-dM}
6838 Tell the preprocessor to output only a list of the macro definitions that
6839 are in effect at the end of preprocessing.
6840 Used with the `-E' option.
6844 \labelwidthstring 00.00.0000
6848 \begin_inset LatexCommand \index{-dD}
6854 Tell the preprocessor to pass all macro definitions into the output, in
6855 their proper sequence in the rest of the output.
6859 \labelwidthstring 00.00.0000
6863 \begin_inset LatexCommand \index{-dN}
6874 Like `-dD' except that the macro arguments and contents are omitted.
6875 Only `#define name' is included in the output.
6879 \labelwidthstring 00.00.0000
6882 -pedantic-parse-number
6883 \begin_inset LatexCommand \index{-pedantic-parse-number}
6894 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6895 and the macro LO_B(3) gets expanded.
6896 See also #pragma pedantic_parse_number in section
6897 \begin_inset LatexCommand \ref{sec:Pragmas}
6903 Note: this functionality is not in conformance with standard!
6907 \labelwidthstring 00.00.0000
6911 preprocessorOption[,preprocessorOption]
6914 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6919 Pass the preprocessorOption to the preprocessor
6924 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6929 SDCC uses an adapted version of the preprocessor
6933 of the GNU Compiler Collection
6934 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6943 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6947 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
6952 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6959 \begin_layout Standard
6960 \begin_inset VSpace bigskip
6966 \begin_layout Subsection
6968 \begin_inset LatexCommand \index{Options linker}
6973 \begin_inset LatexCommand \index{Linker options}
6981 \labelwidthstring 00.00.0000
6991 \begin_layout Standard
7003 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7008 \begin_inset LatexCommand \index{-L -\/-lib-path}
7015 <absolute path to additional libraries> This option is passed to the linkage
7016 editor's additional libraries
7017 \begin_inset LatexCommand \index{Libraries}
7022 The path name must be absolute.
7023 Additional library files may be specified in the command line.
7024 See section Compiling programs for more details.
7028 \labelwidthstring 00.00.0000
7035 \begin_layout Standard
7047 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7052 <Value> The start location of the external ram
7053 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7057 , default value is 0.
7058 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7062 \begin_layout Standard
7071 -xram-loc 0x8000 or -
7075 \begin_layout Standard
7088 \labelwidthstring 00.00.0000
7095 \begin_layout Standard
7107 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7112 <Value> The start location of the code
7113 \begin_inset LatexCommand \index{code}
7117 segment, default value 0.
7118 Note when this option is used the interrupt vector table
7119 \begin_inset LatexCommand \index{interrupt vector table}
7123 is also relocated to the given address.
7124 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7128 \begin_layout Standard
7137 -code-loc 0x8000 or -
7141 \begin_layout Standard
7154 \labelwidthstring 00.00.0000
7161 \begin_layout Standard
7173 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7178 <Value> By default the stack
7179 \begin_inset LatexCommand \index{stack}
7183 is placed after the data segment.
7184 Using this option the stack can be placed anywhere in the internal memory
7186 The value entered can be in Hexadecimal or Decimal format, e.g.
7191 \begin_layout Standard
7200 -stack-loc 0x20 or -
7204 \begin_layout Standard
7214 Since the sp register is incremented before a push or call, the initial
7215 sp will be set to one byte prior the provided value.
7216 The provided value should not overlap any other memory areas such as used
7217 register banks or the data segment and with enough space for the current
7225 \begin_layout Standard
7238 \begin_inset LatexCommand \index{-\/-pack-iram}
7242 option (which is now a default setting) will override this setting, so
7243 you should also specify the
7249 \begin_layout Standard
7262 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7266 option if you need to manually place the stack.
7270 \labelwidthstring 00.00.0000
7277 \begin_layout Standard
7289 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7294 <Value> By default the external stack
7295 \begin_inset LatexCommand \index{xstack}
7299 is placed after the pdata
7300 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7305 Using this option the xstack can be placed anywhere in the external memory
7307 The value entered can be in Hexadecimal or Decimal format, e.g.
7312 \begin_layout Standard
7321 -xstack-loc 0x8000 or -
7325 \begin_layout Standard
7335 The provided value should not overlap any other memory areas such as the
7336 pdata or xdata segment and with enough space for the current application.
7340 \labelwidthstring 00.00.0000
7347 \begin_layout Standard
7359 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7364 <Value> The start location of the internal ram data
7365 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7370 The value entered can be in Hexadecimal or Decimal format, eg.
7375 \begin_layout Standard
7388 \begin_layout Standard
7398 (By default, the start location of the internal ram data segment is set
7399 as low as possible in memory, taking into account the used register banks
7400 and the bit segment at address 0x20.
7401 For example if register banks 0 and 1 are used without bit variables, the
7402 data segment will be set, if -
7406 \begin_layout Standard
7415 -data-loc is not used, to location 0x10.)
7419 \labelwidthstring 00.00.0000
7426 \begin_layout Standard
7438 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7443 <Value> The start location of the indirectly addressable internal ram
7444 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7448 of the 8051, default value is 0x80.
7449 The value entered can be in Hexadecimal or Decimal format, eg.
7454 \begin_layout Standard
7463 -idata-loc 0x88 or -
7467 \begin_layout Standard
7480 \labelwidthstring 00.00.0000
7487 \begin_layout Standard
7499 <Value> The start location of the bit
7500 \begin_inset LatexCommand \index{bit}
7504 addressable internal ram of the 8051.
7510 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7515 \labelwidthstring 00.00.0000
7522 \begin_layout Standard
7532 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7541 The linker output (final object code) is in Intel Hex format.
7542 \begin_inset LatexCommand \index{Intel hex format}
7546 This is the default option.
7547 The format itself is documented in the documentation of srecord
7548 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7556 \labelwidthstring 00.00.0000
7563 \begin_layout Standard
7573 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7582 The linker output (final object code) is in Motorola S19 format
7583 \begin_inset LatexCommand \index{Motorola S19 format}
7588 The format itself is documented in the documentation of srecord.
7592 \labelwidthstring 00.00.0000
7599 \begin_layout Standard
7609 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7614 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7623 The linker output (final object code) is in ELF format
7624 \begin_inset LatexCommand \index{ELF format}
7629 (Currently only supported for the HC08
7630 \begin_inset LatexCommand \index{HC08}
7638 \labelwidthstring 00.00.0000
7642 linkOption[,linkOption]
7645 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7650 Pass the linkOption to the linker.
7651 If a bootloader is used an option like
7652 \begin_inset Quotes sld
7657 \begin_inset Quotes srd
7660 would be typical to set the start of the code segment.
7661 See also #pragma constseg and #pragma codeseg in section
7662 \begin_inset LatexCommand \ref{sec:Pragmas}
7667 File sdcc/as/doc/asxhtm.html has more on linker options.
7670 \begin_layout Standard
7671 \begin_inset VSpace bigskip
7677 \begin_layout Subsection
7679 \begin_inset LatexCommand \index{Options MCS51}
7684 \begin_inset LatexCommand \index{MCS51 options}
7692 \labelwidthstring 00.00.0000
7699 \begin_layout Standard
7709 \begin_inset LatexCommand \index{-\/-model-small}
7720 Generate code for Small Model programs, see section Memory Models for more
7722 This is the default model.
7726 \labelwidthstring 00.00.0000
7733 \begin_layout Standard
7743 \begin_inset LatexCommand \index{-\/-model-medium}
7749 Generate code for Medium model programs, see section Memory Models for
7751 If this option is used all source files in the project have to be compiled
7753 It must also be used when invoking the linker.
7757 \labelwidthstring 00.00.0000
7764 \begin_layout Standard
7774 \begin_inset LatexCommand \index{-\/-model-large}
7780 Generate code for Large model programs, see section Memory Models for more
7782 If this option is used all source files in the project have to be compiled
7784 It must also be used when invoking the linker.
7788 \labelwidthstring 00.00.0000
7795 \begin_layout Standard
7805 \begin_inset LatexCommand \index{-\/-xstack}
7811 Uses a pseudo stack in the pdata
7812 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7816 area (usually the first 256 bytes in the external ram) for allocating variables
7817 and passing parameters.
7819 \begin_inset LatexCommand \ref{sub:External-Stack}
7824 External Stack for more details.
7828 \labelwidthstring 00.00.0000
7835 \begin_layout Standard
7848 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7852 Causes the linker to check if the internal ram usage is within limits of
7857 \labelwidthstring 00.00.0000
7864 \begin_layout Standard
7877 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7881 Causes the linker to check if the external ram usage is within limits of
7886 \labelwidthstring 00.00.0000
7893 \begin_layout Standard
7906 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7910 Causes the linker to check if the code memory usage is within limits of
7915 \labelwidthstring 00.00.0000
7922 \begin_layout Standard
7935 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7939 Causes the linker to check if there is at minimum <Value> bytes for stack.
7943 \labelwidthstring 00.00.0000
7950 \begin_layout Standard
7963 \begin_inset LatexCommand \index{-\/-pack-iram}
7967 Causes the linker to use unused register banks for data variables and pack
7968 data, idata and stack together.
7969 This is the default now.
7973 \labelwidthstring 00.00.0000
7980 \begin_layout Standard
7993 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7997 Causes the linker to use old style for allocating memory areas.
8000 \begin_layout Standard
8001 \begin_inset VSpace bigskip
8007 \begin_layout Subsection
8008 DS390 / DS400 Options
8009 \begin_inset LatexCommand \index{Options DS390}
8014 \begin_inset LatexCommand \index{DS390}
8022 \labelwidthstring 00.00.0000
8029 \begin_layout Standard
8041 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8051 Generate 24-bit flat mode code.
8052 This is the one and only that the ds390 code generator supports right now
8053 and is default when using
8058 See section Memory Models for more details.
8062 \labelwidthstring 00.00.0000
8069 \begin_layout Standard
8079 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8085 disable interrupts during ESP:SP updates.
8089 \labelwidthstring 00.00.0000
8096 \begin_layout Standard
8108 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8112 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8113 This is the one and only that the ds390 code generator supports right now
8114 and is default when using
8119 In this mode, the stack is located in the lower 1K of the internal RAM,
8120 which is mapped to 0x400000.
8121 Note that the support is incomplete, since it still uses a single byte
8122 as the stack pointer.
8123 This means that only the lower 256 bytes of the potential 1K stack space
8124 will actually be used.
8125 However, this does allow you to reclaim the precious 256 bytes of low RAM
8126 for use for the DATA and IDATA segments.
8127 The compiler will not generate any code to put the processor into 10 bit
8129 It is important to ensure that the processor is in this mode before calling
8130 any re-entrant functions compiled with this option.
8131 In principle, this should work with the
8137 \begin_layout Standard
8147 \begin_inset LatexCommand \index{-\/-stack-auto}
8153 option, but that has not been tested.
8154 It is incompatible with the
8160 \begin_layout Standard
8170 \begin_inset LatexCommand \index{-\/-xstack}
8177 It also only makes sense if the processor is in 24 bit contiguous addressing
8184 \begin_layout Standard
8193 -model-flat24 option
8199 \labelwidthstring 00.00.0000
8206 \begin_layout Standard
8216 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8222 insert call to function __stack_probe at each function prologue.
8226 \labelwidthstring 00.00.0000
8233 \begin_layout Standard
8243 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8249 <nnnn> LibraryID used in -mTININative.
8254 \labelwidthstring 00.00.0000
8261 \begin_layout Standard
8271 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8277 generate code for DS390 Arithmetic Accelerator.
8281 \begin_layout Standard
8282 \begin_inset VSpace bigskip
8288 \begin_layout Subsection
8290 \begin_inset LatexCommand \index{Options Z80}
8295 \begin_inset LatexCommand \index{Z80}
8303 \labelwidthstring 00.00.0000
8310 \begin_layout Standard
8322 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8332 Force a called function to always save BC.
8336 \labelwidthstring 00.00.0000
8343 \begin_layout Standard
8355 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8359 When linking, skip the standard crt0.o object file.
8360 You must provide your own crt0.o for your system when linking.
8364 \begin_layout Standard
8365 \begin_inset VSpace bigskip
8371 \begin_layout Subsection
8372 Optimization Options
8373 \begin_inset LatexCommand \index{Options optimization}
8378 \begin_inset LatexCommand \index{Optimization options}
8386 \labelwidthstring 00.00.0000
8393 \begin_layout Standard
8403 \begin_inset LatexCommand \index{-\/-nogcse}
8409 Will not do global subexpression elimination, this option may be used when
8410 the compiler creates undesirably large stack/data spaces to store compiler
8420 \begin_inset LatexCommand \index{sloc (spill location)}
8425 A warning message will be generated when this happens and the compiler
8426 will indicate the number of extra bytes it allocated.
8427 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8429 \begin_inset LatexCommand \index{\#pragma nogcse}
8433 can be used to turn off global subexpression elimination
8434 \begin_inset LatexCommand \index{Subexpression elimination}
8438 for a given function only.
8442 \labelwidthstring 00.00.0000
8449 \begin_layout Standard
8459 \begin_inset LatexCommand \index{-\/-noinvariant}
8465 Will not do loop invariant optimizations, this may be turned off for reasons
8466 explained for the previous option.
8467 For more details of loop optimizations performed see Loop Invariants in
8469 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8474 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8476 \begin_inset LatexCommand \index{\#pragma noinvariant}
8480 can be used to turn off invariant optimizations for a given function only.
8484 \labelwidthstring 00.00.0000
8491 \begin_layout Standard
8501 \begin_inset LatexCommand \index{-\/-noinduction}
8507 Will not do loop induction optimizations, see section strength reduction
8509 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8511 \begin_inset LatexCommand \index{\#pragma noinduction}
8515 can be used to turn off induction optimizations for a given function only.
8519 \labelwidthstring 00.00.0000
8526 \begin_layout Standard
8536 \begin_inset LatexCommand \index{-\/-nojtbound}
8547 Will not generate boundary condition check when switch statements
8548 \begin_inset LatexCommand \index{switch statement}
8552 are implemented using jump-tables.
8554 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8559 Switch Statements for more details.
8560 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8562 \begin_inset LatexCommand \index{\#pragma nojtbound}
8566 can be used to turn off boundary checking for jump tables for a given function
8571 \labelwidthstring 00.00.0000
8578 \begin_layout Standard
8588 \begin_inset LatexCommand \index{-\/-noloopreverse}
8597 Will not do loop reversal
8598 \begin_inset LatexCommand \index{Loop reversing}
8606 \labelwidthstring 00.00.0000
8611 \begin_layout Standard
8625 \begin_inset LatexCommand \index{-\/-nolabelopt }
8629 Will not optimize labels (makes the dumpfiles more readable).
8633 \labelwidthstring 00.00.0000
8640 \begin_layout Standard
8650 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8656 Will not memcpy initialized data from code space into xdata space.
8657 This saves a few bytes in code space if you don't have initialized data
8658 \begin_inset LatexCommand \index{Variable initialization}
8666 \labelwidthstring 00.00.0000
8673 \begin_layout Standard
8683 \begin_inset LatexCommand \index{-\/-nooverlay}
8689 The compiler will not overlay parameters and local variables of any function,
8690 see section Parameters and local variables for more details.
8694 \labelwidthstring 00.00.0000
8701 \begin_layout Standard
8711 \begin_inset LatexCommand \index{-\/-no-peep}
8717 Disable peep-hole optimization with built-in rules.
8721 \labelwidthstring 00.00.0000
8728 \begin_layout Standard
8740 \begin_inset LatexCommand \index{-\/-peep-file}
8745 <filename> This option can be used to use additional rules to be used by
8746 the peep hole optimizer.
8748 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8753 Peep Hole optimizations for details on how to write these rules.
8757 \labelwidthstring 00.00.0000
8764 \begin_layout Standard
8774 \begin_inset LatexCommand \index{-\/-peep-asm}
8780 Pass the inline assembler code through the peep hole optimizer.
8781 This can cause unexpected changes to inline assembler code, please go through
8782 the peephole optimizer
8783 \begin_inset LatexCommand \index{Peephole optimizer}
8787 rules defined in the source file tree '<target>/peeph.def' before using
8792 \labelwidthstring 00.00.0000
8799 \begin_layout Standard
8809 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8815 The compiler will optimize code generation towards fast code, possibly
8816 at the expense of code size.
8820 \labelwidthstring 00.00.0000
8827 \begin_layout Standard
8837 \begin_inset LatexCommand \index{-\/-opt-code-size}
8843 The compiler will optimize code generation towards compact code, possibly
8844 at the expense of code speed.
8847 \begin_layout Standard
8848 \begin_inset VSpace bigskip
8854 \begin_layout Subsection
8856 \begin_inset LatexCommand \index{Options other}
8864 \labelwidthstring 00.00.0000
8872 \begin_layout Standard
8882 \begin_inset LatexCommand \index{-\/-compile-only}
8887 \begin_inset LatexCommand \index{-c -\/-compile-only}
8893 will compile and assemble the source, but will not call the linkage editor.
8897 \labelwidthstring 00.00.0000
8906 \begin_layout Standard
8918 \begin_inset LatexCommand \index{-\/-c1mode}
8924 reads the preprocessed source from standard input and compiles it.
8925 The file name for the assembler output must be specified using the -o option.
8929 \labelwidthstring 00.00.0000
8933 \begin_inset LatexCommand \index{-E}
8939 Run only the C preprocessor.
8940 Preprocess all the C source files specified and output the results to standard
8945 \labelwidthstring 00.00.0000
8950 \begin_inset LatexCommand \index{-o <path/file>}
8956 The output path resp.
8957 file where everything will be placed.
8958 If the parameter is a path, it must have a trailing slash (or backslash
8959 for the Windows binaries) to be recognized as a path.
8964 \labelwidthstring 00.00.0000
8971 \begin_layout Standard
8981 \begin_inset LatexCommand \index{-\/-stack-auto}
8992 All functions in the source file will be compiled as
8997 \begin_inset LatexCommand \index{reentrant}
9002 the parameters and local variables will be allocated on the stack
9003 \begin_inset LatexCommand \index{stack}
9009 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9013 Parameters and Local Variables for more details.
9014 If this option is used all source files in the project should be compiled
9016 It automatically implies --int-long-reent and --float-reent.
9021 \labelwidthstring 00.00.0000
9028 \begin_layout Standard
9038 \begin_inset LatexCommand \index{-\/-callee-saves}
9042 function1[,function2][,function3]....
9045 The compiler by default uses a caller saves convention for register saving
9046 across function calls, however this can cause unnecessary register pushing
9047 & popping when calling small functions from larger functions.
9048 This option can be used to switch the register saving convention for the
9049 function names specified.
9050 The compiler will not save registers when calling these functions, no extra
9051 code will be generated at the entry & exit (function prologue
9054 \begin_inset LatexCommand \index{function prologue}
9063 \begin_inset LatexCommand \index{function epilogue}
9069 ) for these functions to save & restore the registers used by these functions,
9070 this can SUBSTANTIALLY reduce code & improve run time performance of the
9072 In the future the compiler (with inter procedural analysis) will be able
9073 to determine the appropriate scheme to use for each function call.
9074 DO NOT use this option for built-in functions such as _mulint..., if this
9075 option is used for a library function the appropriate library function
9076 needs to be recompiled with the same option.
9077 If the project consists of multiple source files then all the source file
9078 should be compiled with the same -
9082 \begin_layout Standard
9091 -callee-saves option string.
9092 Also see #pragma\InsetSpace ~
9094 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9102 \labelwidthstring 00.00.0000
9109 \begin_layout Standard
9119 \begin_inset LatexCommand \index{-\/-debug}
9128 When this option is used the compiler will generate debug information.
9129 The debug information collected in a file with .cdb extension can be used
9131 For more information see documentation for SDCDB.
9132 Another file with no extension contains debug information in AOMF or AOMF51
9133 \begin_inset LatexCommand \index{AOMF, AOMF51}
9137 format which is commonly used by third party tools.
9141 \labelwidthstring 00.00.0000
9145 \begin_inset LatexCommand \index{-S}
9156 Stop after the stage of compilation proper; do not assemble.
9157 The output is an assembler code file for the input file specified.
9161 \labelwidthstring 00.00.0000
9168 \begin_layout Standard
9178 \begin_inset LatexCommand \index{-\/-int-long-reent}
9184 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9185 Note by default these libraries are compiled as non-reentrant.
9186 See section Installation for more details.
9190 \labelwidthstring 00.00.0000
9197 \begin_layout Standard
9207 \begin_inset LatexCommand \index{-\/-cyclomatic}
9216 This option will cause the compiler to generate an information message for
9217 each function in the source file.
9218 The message contains some
9222 information about the function.
9223 The number of edges and nodes the compiler detected in the control flow
9224 graph of the function, and most importantly the
9226 cyclomatic complexity
9227 \begin_inset LatexCommand \index{Cyclomatic complexity}
9233 see section on Cyclomatic Complexity for more details.
9237 \labelwidthstring 00.00.0000
9244 \begin_layout Standard
9254 \begin_inset LatexCommand \index{-\/-float-reent}
9260 Floating point library is compiled as reentrant
9261 \begin_inset LatexCommand \index{reentrant}
9266 See section Installation for more details.
9270 \labelwidthstring 00.00.0000
9277 \begin_layout Standard
9287 \begin_inset LatexCommand \index{-\/-main-return}
9293 This option can be used if the code generated is called by a monitor program
9294 or if the main routine includes an endless loop.
9295 This option results in slightly smaller code and saves two bytes of stack
9297 The return from the 'main'
9298 \begin_inset LatexCommand \index{main return}
9302 function will return to the function calling main.
9303 The default setting is to lock up i.e.
9312 \labelwidthstring 00.00.0000
9319 \begin_layout Standard
9329 \begin_inset LatexCommand \index{-\/-nostdinc}
9335 This will prevent the compiler from passing on the default include path
9336 to the preprocessor.
9340 \labelwidthstring 00.00.0000
9347 \begin_layout Standard
9357 \begin_inset LatexCommand \index{-\/-nostdlib}
9363 This will prevent the compiler from passing on the default library
9364 \begin_inset LatexCommand \index{Libraries}
9372 \labelwidthstring 00.00.0000
9379 \begin_layout Standard
9389 \begin_inset LatexCommand \index{-\/-verbose}
9395 Shows the various actions the compiler is performing.
9399 \labelwidthstring 00.00.0000
9403 \begin_inset LatexCommand \index{-V}
9409 Shows the actual commands the compiler is executing.
9413 \labelwidthstring 00.00.0000
9420 \begin_layout Standard
9430 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9436 Hides your ugly and inefficient c-code from the asm file, so you can always
9437 blame the compiler :)
9441 \labelwidthstring 00.00.0000
9448 \begin_layout Standard
9458 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9464 Will not include peep-hole comments in the generated files.
9468 \labelwidthstring 00.00.0000
9475 \begin_layout Standard
9485 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9491 Include i-codes in the asm file.
9492 Sounds like noise but is most helpful for debugging the compiler itself.
9496 \labelwidthstring 00.00.0000
9503 \begin_layout Standard
9513 \begin_inset LatexCommand \index{-\/-less-pedantic}
9519 Disable some of the more pedantic warnings
9520 \begin_inset LatexCommand \index{Warnings}
9524 (jwk burps: please be more specific here, please!).
9528 \labelwidthstring 00.00.0000
9535 \begin_layout Standard
9544 -disable-warning\InsetSpace ~
9546 \begin_inset LatexCommand \index{-\/-disable-warning}
9552 Disable specific warning with number <nnnn>.
9556 \labelwidthstring 00.00.0000
9563 \begin_layout Standard
9573 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9579 Display the directories in the compiler's search path
9583 \labelwidthstring 00.00.0000
9590 \begin_layout Standard
9600 \begin_inset LatexCommand \index{-\/-vc}
9606 Display errors and warnings using MSVC style, so you can use SDCC with
9607 the visual studio IDE
9608 \begin_inset LatexCommand \index{IDE}
9613 With SDCC both offering a GCC-like (the default) and a MSVC-like
9614 \begin_inset LatexCommand \index{MSVC output style}
9618 output style, integration into most programming editors should be straightforwa
9623 \labelwidthstring 00.00.0000
9630 \begin_layout Standard
9640 \begin_inset LatexCommand \index{-\/-use-stdout}
9646 Send errors and warnings to stdout instead of stderr.
9650 \labelwidthstring 00.00.0000
9654 asmOption[,asmOption]
9657 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9662 Pass the asmOption to the assembler
9663 \begin_inset LatexCommand \index{Options assembler}
9668 \begin_inset LatexCommand \index{Assembler options}
9673 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9677 \labelwidthstring 00.00.0000
9684 \begin_layout Standard
9694 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9700 Generally follow the C89 standard, but allow SDCC features that conflict
9701 with the standard (default).
9705 \labelwidthstring 00.00.0000
9712 \begin_layout Standard
9722 \begin_inset LatexCommand \index{-\/-std-c89}
9728 Follow the C89 standard and disable SDCC features that conflict with the
9733 \labelwidthstring 00.00.0000
9740 \begin_layout Standard
9750 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9756 Generally follow the C99 standard, but allow SDCC features that conflict
9757 with the standard (incomplete support).
9761 \labelwidthstring 00.00.0000
9768 \begin_layout Standard
9778 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9784 Follow the C99 standard and disable SDCC features that conflict with the
9785 standard (incomplete support).
9789 \labelwidthstring 00.00.0000
9796 \begin_layout Standard
9808 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9813 <Name> The name to be used for the code
9814 \begin_inset LatexCommand \index{code}
9818 segment, default CSEG.
9819 This is useful if you need to tell the compiler to put the code in a special
9820 segment so you can later on tell the linker to put this segment in a special
9822 Can be used for instance when using bank switching to put the code in a
9827 \labelwidthstring 00.00.0000
9834 \begin_layout Standard
9846 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9851 <Name> The name to be used for the const
9852 \begin_inset LatexCommand \index{code}
9856 segment, default CONST.
9857 This is useful if you need to tell the compiler to put the const data in
9858 a special segment so you can later on tell the linker to put this segment
9859 in a special place in memory.
9860 Can be used for instance when using bank switching to put the const data
9865 \labelwidthstring 00.00.0000
9872 \begin_layout Standard
9881 -fdollars-in-identifiers
9882 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9888 Permit '$' as an identifier character
9892 \labelwidthstring 00.00.0000
9903 a SDCC compiler option but if you want
9907 warnings you can use a separate tool dedicated to syntax checking like
9909 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9914 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9919 \begin_inset LatexCommand \url{http://www.splint.org}
9924 To make your source files parseable by splint you will have to include
9930 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9934 in your source file and add brackets around extended keywords (like
9937 \begin_inset Quotes sld
9950 \begin_inset Quotes srd
9958 \begin_inset Quotes sld
9961 __interrupt\InsetSpace ~
9963 \begin_inset Quotes srd
9971 Splint has an excellent on line manual at
9972 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9976 and it's capabilities go beyond pure syntax checking.
9977 You'll need to tell splint the location of SDCC's include files so a typical
9978 command line could look like this:
9984 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
9989 \begin_layout Standard
9990 \begin_inset VSpace bigskip
9996 \begin_layout Subsection
9997 Intermediate Dump Options
9998 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10003 \begin_inset LatexCommand \index{Options intermediate dump}
10008 \begin_inset LatexCommand \index{Intermediate dump options}
10015 \begin_layout Standard
10016 The following options are provided for the purpose of retargetting and debugging
10018 They provide a means to dump the intermediate code (iCode
10019 \begin_inset LatexCommand \index{iCode}
10023 ) generated by the compiler in human readable form at various stages of
10024 the compilation process.
10025 More on iCodes see chapter
10026 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10031 \begin_inset Quotes srd
10034 The anatomy of the compiler
10035 \begin_inset Quotes srd
10042 \labelwidthstring 00.00.0000
10049 \begin_layout Standard
10059 \begin_inset LatexCommand \index{-\/-dumpraw}
10065 This option will cause the compiler to dump the intermediate code into
10068 <source filename>.dumpraw
10070 just after the intermediate code has been generated for a function, i.e.
10071 before any optimizations are done.
10073 \begin_inset LatexCommand \index{Basic blocks}
10077 at this stage ordered in the depth first number, so they may not be in
10078 sequence of execution.
10082 \labelwidthstring 00.00.0000
10089 \begin_layout Standard
10099 \begin_inset LatexCommand \index{-\/-dumpgcse}
10105 Will create a dump of iCode's, after global subexpression elimination
10106 \begin_inset LatexCommand \index{Global subexpression elimination}
10110 , into a file named
10112 <source filename>.dumpgcse.
10116 \labelwidthstring 00.00.0000
10123 \begin_layout Standard
10133 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10139 Will create a dump of iCode's, after deadcode elimination
10140 \begin_inset LatexCommand \index{Dead-code elimination}
10144 , into a file named
10146 <source filename>.dumpdeadcode.
10150 \labelwidthstring 00.00.0000
10157 \begin_layout Standard
10167 \begin_inset LatexCommand \index{-\/-dumploop}
10176 Will create a dump of iCode's, after loop optimizations
10177 \begin_inset LatexCommand \index{Loop optimization}
10181 , into a file named
10183 <source filename>.dumploop.
10187 \labelwidthstring 00.00.0000
10194 \begin_layout Standard
10204 \begin_inset LatexCommand \index{-\/-dumprange}
10213 Will create a dump of iCode's, after live range analysis
10214 \begin_inset LatexCommand \index{Live range analysis}
10218 , into a file named
10220 <source filename>.dumprange.
10224 \labelwidthstring 00.00.0000
10231 \begin_layout Standard
10241 \begin_inset LatexCommand \index{-\/-dumlrange}
10247 Will dump the life ranges
10248 \begin_inset LatexCommand \index{Live range analysis}
10256 \labelwidthstring 00.00.0000
10263 \begin_layout Standard
10273 \begin_inset LatexCommand \index{-\/-dumpregassign}
10282 Will create a dump of iCode's, after register assignment
10283 \begin_inset LatexCommand \index{Register assignment}
10287 , into a file named
10289 <source filename>.dumprassgn.
10293 \labelwidthstring 00.00.0000
10300 \begin_layout Standard
10310 \begin_inset LatexCommand \index{-\/-dumplrange}
10316 Will create a dump of the live ranges of iTemp's
10320 \labelwidthstring 00.00.0000
10327 \begin_layout Standard
10337 \begin_inset LatexCommand \index{-\/-dumpall}
10348 Will cause all the above mentioned dumps to be created.
10351 \begin_layout Standard
10352 \begin_inset VSpace bigskip
10358 \begin_layout Subsection
10359 Redirecting output on Windows Shells
10362 \begin_layout Standard
10363 By default SDCC writes it's error messages to
10364 \begin_inset Quotes sld
10368 \begin_inset Quotes srd
10372 To force all messages to
10373 \begin_inset Quotes sld
10377 \begin_inset Quotes srd
10389 \begin_layout Standard
10404 \begin_inset LatexCommand \index{-\/-use-stdout}
10409 Additionally, if you happen to have visual studio installed in your windows
10410 machine, you can use it to compile your sources using a custom build and
10417 \begin_layout Standard
10429 \begin_inset LatexCommand \index{-\/-vc}
10434 Something like this should work:
10453 \begin_layout Standard
10472 \begin_layout Standard
10484 -model-large -c $(InputPath)
10487 \begin_inset VSpace bigskip
10493 \begin_layout Section
10494 Environment variables
10495 \begin_inset LatexCommand \index{Environment variables}
10502 \begin_layout Standard
10503 SDCC recognizes the following environment variables:
10507 \labelwidthstring 00.00.0000
10511 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10517 SDCC installs a signal handler
10518 \begin_inset LatexCommand \index{signal handler}
10522 to be able to delete temporary files after an user break (^C) or an exception.
10523 If this environment variable is set, SDCC won't install the signal handler
10524 in order to be able to debug SDCC.
10528 \labelwidthstring 00.00.0000
10534 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10540 Path, where temporary files will be created.
10541 The order of the variables is the search order.
10542 In a standard *nix environment these variables are not set, and there's
10543 no need to set them.
10544 On Windows it's recommended to set one of them.
10548 \labelwidthstring 00.00.0000
10552 \begin_inset LatexCommand \index{SDCC\_HOME}
10559 \begin_inset LatexCommand \ref{sub:Install-paths}
10565 \begin_inset Quotes sld
10569 \begin_inset Quotes srd
10576 \labelwidthstring 00.00.0000
10580 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10587 \begin_inset LatexCommand \ref{sub:Search-Paths}
10593 \begin_inset Quotes sld
10597 \begin_inset Quotes srd
10604 \labelwidthstring 00.00.0000
10608 \begin_inset LatexCommand \index{SDCC\_LIB}
10615 \begin_inset LatexCommand \ref{sub:Search-Paths}
10621 \begin_inset Quotes sld
10625 \begin_inset Quotes srd
10631 \begin_layout Standard
10632 There are some more environment variables recognized by SDCC, but these
10633 are solely used for debugging purposes.
10634 They can change or disappear very quickly, and will never be documented.
10635 \begin_inset VSpace bigskip
10641 \begin_layout Section
10642 Storage Class Language Extensions
10645 \begin_layout Subsection
10646 MCS51/DS390 Storage Class
10647 \begin_inset LatexCommand \index{Storage class}
10651 Language Extensions
10654 \begin_layout Standard
10655 In addition to the ANSI storage classes SDCC allows the following MCS51
10656 specific storage classes:
10659 \begin_layout Subsubsection
10661 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10666 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10671 \begin_inset LatexCommand \index{near (storage class)}
10676 \begin_inset LatexCommand \index{\_\_near (storage class)}
10683 \begin_layout Standard
10688 storage class for the Small Memory model (
10696 or the more ANSI-C compliant forms
10704 can be used synonymously).
10705 Variables declared with this storage class will be allocated in the directly
10706 addressable portion of the internal RAM of a 8051, e.g.:
10709 \begin_layout Verse
10712 __data unsigned char test_data;
10715 \begin_layout Standard
10716 Writing 0x01 to this variable generates the assembly code:
10719 \begin_layout Verse
10722 75*00 01\InsetSpace ~
10730 \begin_layout Subsubsection
10732 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10737 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10742 \begin_inset LatexCommand \index{far (storage class)}
10747 \begin_inset LatexCommand \index{\_\_far (storage class)}
10754 \begin_layout Standard
10755 Variables declared with this storage class will be placed in the external
10761 storage class for the Large Memory model, e.g.:
10764 \begin_layout Verse
10767 __xdata unsigned char test_xdata;
10770 \begin_layout Standard
10771 Writing 0x01 to this variable generates the assembly code:
10774 \begin_layout Verse
10777 90s00r00\InsetSpace ~
10808 \begin_layout Subsubsection
10810 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10815 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10822 \begin_layout Standard
10823 Variables declared with this storage class will be allocated into the indirectly
10824 addressable portion of the internal ram of a 8051, e.g.:
10827 \begin_layout Verse
10830 __idata unsigned char test_idata;
10833 \begin_layout Standard
10834 Writing 0x01 to this variable generates the assembly code:
10837 \begin_layout Verse
10864 \begin_layout Standard
10865 Please note, the first 128 byte of idata physically access the same RAM
10866 as the data memory.
10867 The original 8051 had 128 byte idata memory, nowadays most devices have
10868 256 byte idata memory.
10870 \begin_inset LatexCommand \index{stack}
10874 is located in idata memory.
10877 \begin_layout Subsubsection
10879 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10884 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10891 \begin_layout Standard
10892 Paged xdata access is just as straightforward as using the other addressing
10894 It is typically located at the start of xdata and has a maximum size of
10896 The following example writes 0x01 to the pdata variable.
10897 Please note, pdata access physically accesses xdata memory.
10898 The high byte of the address is determined by port P2
10899 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10903 (or in case of some 8051 variants by a separate Special Function Register,
10905 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10914 storage class for the Medium Memory model, e.g.:
10917 \begin_layout Verse
10920 __pdata unsigned char test_pdata;
10923 \begin_layout Standard
10924 Writing 0x01 to this variable generates the assembly code:
10927 \begin_layout Verse
10936 mov r0,#_test_pdata
10958 \begin_layout Standard
10963 \begin_layout Standard
10973 \begin_inset LatexCommand \index{-\/-xstack}
10977 option is used the pdata memory area is followed by the xstack memory area
10978 and the sum of their sizes is limited to 256 bytes.
10981 \begin_layout Subsubsection
10983 \begin_inset LatexCommand \index{code}
10988 \begin_inset LatexCommand \index{\_\_code}
10995 \begin_layout Standard
10996 'Variables' declared with this storage class will be placed in the code
11000 \begin_layout Verse
11003 __code unsigned char test_code;
11006 \begin_layout Standard
11007 Read access to this variable generates the assembly code:
11010 \begin_layout Verse
11013 90s00r6F\InsetSpace ~
11016 mov dptr,#_test_code
11041 \begin_layout Standard
11046 indexed arrays of characters in code memory can be accessed efficiently:
11049 \begin_layout Verse
11052 __code char test_array[] = {'c','h','e','a','p'};
11055 \begin_layout Standard
11056 Read access to this array using an 8-bit unsigned index generates the assembly
11060 \begin_layout Verse
11072 \begin_layout Verse
11075 90s00r41\InsetSpace ~
11078 mov dptr,#_test_array
11081 \begin_layout Verse
11096 \begin_layout Subsubsection
11098 \begin_inset LatexCommand \index{bit}
11103 \begin_inset LatexCommand \index{\_\_bit}
11110 \begin_layout Standard
11111 This is a data-type and a storage class specifier.
11112 When a variable is declared as a bit, it is allocated into the bit addressable
11113 memory of 8051, e.g.:
11116 \begin_layout Verse
11122 \begin_layout Standard
11123 Writing 1 to this variable generates the assembly code:
11126 \begin_layout Verse
11140 \begin_layout Standard
11141 The bit addressable memory consists of 128 bits which are located from 0x20
11142 to 0x2f in data memory.
11145 Apart from this 8051 specific storage class most architectures support
11147 \begin_inset LatexCommand \index{bitfields}
11155 \begin_layout Standard
11156 Not really meant as examples, but nevertheless showing what bitfields are
11157 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11163 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11164 signed modifier are implemented as unsigned.
11167 \begin_layout Subsubsection
11169 \begin_inset LatexCommand \index{sfr}
11174 \begin_inset LatexCommand \index{\_\_sfr}
11179 \begin_inset LatexCommand \index{sfr16}
11184 \begin_inset LatexCommand \index{\_\_sfr16}
11189 \begin_inset LatexCommand \index{sfr32}
11194 \begin_inset LatexCommand \index{\_\_sfr32}
11199 \begin_inset LatexCommand \index{\_\_sbit}
11204 \begin_inset LatexCommand \index{sbit}
11211 \begin_layout Standard
11212 Like the bit keyword,
11214 sfr / sfr16 / sfr32 / sbit
11216 signify both a data-type and storage class, they are used to describe the
11237 variables of a 8051, eg:
11240 \begin_layout Verse
11244 \begin_inset LatexCommand \index{at}
11249 \begin_inset LatexCommand \index{\_\_at}
11253 (0x80) P0;\InsetSpace ~
11254 /* special function register P0 at location 0x80 */
11259 special function register combination for timer 0
11263 with the high byte at
11264 location 0x8C and the low byte at location 0x8A */
11266 __sfr16 __at (0x8C8A)
11272 \begin_inset LatexCommand \index{at}
11277 \begin_inset LatexCommand \index{\_\_at}
11281 (0xd7) CY;\InsetSpace ~
11283 \begin_inset LatexCommand \index{Flags}
11288 \begin_inset LatexCommand \index{Carry flag}
11295 \begin_layout Standard
11296 Special function registers which are located on an address dividable by
11297 8 are bit-addressable, an
11301 addresses a specific bit within these sfr.
11303 16 Bit and 32 bit special function
11304 register combinations which require a certain access order are better not
11314 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11315 this is not guaranteed.
11320 \begin_layout Standard
11321 Please note, if you use a header file which was written for another compiler
11322 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11328 Specifically the syntax
11331 sfr P0 = 0x80;\InsetSpace ~
11338 by SDCC to an assignment of 0x80 to a variable called P0
11341 \begin_inset Marginal
11344 \begin_layout Standard
11356 Nevertheless it is possible to write header files
11357 \begin_inset LatexCommand \index{Header files}
11362 \begin_inset LatexCommand \index{Include files}
11366 which can be shared among different compilers (see section
11367 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11375 \begin_layout Subsubsection
11377 \begin_inset LatexCommand \index{Pointer}
11381 to MCS51/DS390 specific memory spaces
11384 \begin_layout Standard
11385 SDCC allows (via language extensions) pointers to explicitly point to any
11386 of the memory spaces
11387 \begin_inset LatexCommand \index{Memory model}
11392 In addition to the explicit pointers, the compiler uses (by default) generic
11393 pointers which can be used to point to any of the memory spaces.
11398 declaration examples:
11401 \begin_layout Verse
11404 /* pointer physically in internal ram pointing to object in external ram
11407 __xdata unsigned char * __data p;
11411 /* pointer physically in external ram
11412 pointing to object in internal ram */
11414 __data unsigned char * __xdata p;
11419 pointer physically in code rom pointing to data in xdata space */
11422 unsigned char * __code p;
11426 /* pointer physically in code space pointing to
11427 data in code space */
11429 __code unsigned char * __code p;
11434 physically located in xdata space */
11436 unsigned char * __xdata p;
11441 pointer physically located in default memory space */
11448 the following is a function pointer
11449 \begin_inset LatexCommand \index{function pointer}
11453 physically located in data space */
11455 char (* __data fp)(void);
11458 \begin_layout Standard
11459 Well you get the idea.
11464 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11477 The highest order byte of the
11481 pointers contains the data space information.
11482 Assembler support routines are called whenever data is stored or retrieved
11488 These are useful for developing reusable library
11489 \begin_inset LatexCommand \index{Libraries}
11494 Explicitly specifying the pointer
11495 \begin_inset LatexCommand \index{pointer}
11499 type will generate the most efficient code.
11502 \begin_layout Subsubsection
11503 Notes on MCS51 memory
11504 \begin_inset LatexCommand \index{MCS51 memory}
11511 \begin_layout Standard
11512 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11513 RAM memory which is structured as follows:
11517 - Bytes 00-1F - 32 bytes to hold
11518 up to 4 banks of the registers R0 to R7,
11520 - Bytes 20-2F - 16 bytes to hold
11522 \begin_inset LatexCommand \index{bit}
11528 - Bytes 30-7F - 80 bytes for general purpose use.
11533 \begin_layout Standard
11534 Additionally some members of the MCS51 family may have up to 128 bytes of
11535 additional, indirectly addressable, internal RAM memory (
11540 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11545 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11550 Furthermore, some chips may have some built in external memory (
11555 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11560 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11564 ) which should not be confused with the internal, directly addressable RAM
11570 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11575 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11580 Sometimes this built in
11584 memory has to be activated before using it (you can probably find this
11585 information on the datasheet of the microcontroller your are using, see
11587 \begin_inset LatexCommand \ref{sub:Startup-Code}
11595 \begin_layout Standard
11596 Normally SDCC will only use the first bank
11597 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11601 of registers (register bank 0), but it is possible to specify that other
11602 banks of registers (keyword
11609 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11614 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11620 ) should be used in interrupt
11621 \begin_inset LatexCommand \index{interrupt}
11626 \begin_inset LatexCommand \index{\_\_interrupt}
11631 By default, the compiler will place the stack after the last byte of allocated
11632 memory for variables.
11633 For example, if the first 2 banks of registers are used, and only four
11638 variables, it will position the base of the internal stack at address 20
11640 This implies that as the stack
11641 \begin_inset LatexCommand \index{stack}
11645 grows, it will use up the remaining register banks, and the 16 bytes used
11646 by the 128 bit variables, and 80 bytes for general purpose use.
11647 If any bit variables are used, the data variables will be placed in unused
11648 register banks and after the byte holding the last bit variable.
11649 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11654 variables will be placed starting from address 0x10 to 0x20 and continue
11660 \begin_layout Standard
11670 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11674 to specify the start address of the
11682 \begin_layout Standard
11692 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11696 to specify the size of the total internal RAM (
11710 \begin_layout Standard
11711 By default the 8051 linker will place the stack after the last byte of (i)data
11717 \begin_layout Standard
11727 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
11731 allows you to specify the start of the stack, i.e.
11732 you could start it after any data in the general purpose area.
11733 If your microcontroller has additional indirectly addressable internal
11738 ) you can place the stack on it.
11739 You may also need to use -
11743 \begin_layout Standard
11753 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
11757 to set the start address of the external RAM (
11765 \begin_layout Standard
11775 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11779 to specify its size.
11780 Same goes for the code memory, using -
11784 \begin_layout Standard
11794 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11802 \begin_layout Standard
11812 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11817 If in doubt, don't specify any options and see if the resulting memory
11818 layout is appropriate, then you can adjust it.
11821 \begin_layout Standard
11822 The linker generates two files with memory allocation information.
11823 The first, with extension .map
11824 \begin_inset LatexCommand \index{<file>.map}
11828 shows all the variables and segments.
11829 The second with extension .mem
11830 \begin_inset LatexCommand \index{<file>.mem}
11834 shows the final memory layout.
11835 The linker will complain either if memory segments overlap, there is not
11836 enough memory, or there is not enough space for stack.
11837 If you get any linking warnings and/or errors related to stack or segments
11838 allocation, take a look at either the .map or .mem files to find out what
11840 The .mem file may even suggest a solution to the problem.
11841 \begin_inset VSpace bigskip
11847 \begin_layout Subsection
11848 Z80/Z180 Storage Class
11849 \begin_inset LatexCommand \index{Z80!Storage class}
11853 Language Extensions
11856 \begin_layout Subsubsection
11858 \begin_inset LatexCommand \index{sfr}
11863 \begin_inset LatexCommand \index{\_\_sfr}
11867 (in/out to 8-bit addresses)
11870 \begin_layout Standard
11872 \begin_inset LatexCommand \index{Z80}
11876 family has separate address spaces for memory and
11886 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11891 \begin_inset LatexCommand \index{Z80!I/O memory}
11896 \begin_inset LatexCommand \index{Z180!I/O memory}
11900 is accessed with special instructions, e.g.:
11903 \begin_layout Verse
11906 sfr at 0x78 IoPort;\InsetSpace ~
11908 /* define a var in I/O space at 78h called IoPort */
11912 \begin_layout Standard
11913 Writing 0x01 to this variable generates the assembly code:
11916 \begin_layout Verse
11936 \begin_layout Subsubsection
11938 \begin_inset LatexCommand \index{sfr}
11943 \begin_inset LatexCommand \index{\_\_sfr}
11947 (in/out to 16-bit addresses)
11950 \begin_layout Standard
11955 is used to support 16 bit addresses in I/O memory e.g.:
11958 \begin_layout Verse
11962 \begin_inset LatexCommand \index{at}
11967 \begin_inset LatexCommand \index{\_\_at}
11974 \begin_layout Standard
11975 Writing 0x01 to this variable generates the assembly code:
11978 \begin_layout Verse
11981 01 23 01\InsetSpace ~
12003 \begin_layout Subsubsection
12005 \begin_inset LatexCommand \index{sfr}
12010 \begin_inset LatexCommand \index{\_\_sfr}
12014 (in0/out0 to 8 bit addresses on Z180
12015 \begin_inset LatexCommand \index{Z180}
12020 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12027 \begin_layout Standard
12028 The compiler option -
12032 \begin_layout Standard
12042 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12046 =180 (80) and a compiler #pragma\InsetSpace ~
12048 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12052 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12062 If you include the file z180.h this will be set automatically.
12063 \begin_inset VSpace bigskip
12069 \begin_layout Subsection
12071 \begin_inset LatexCommand \index{HC08!Storage class}
12075 Language Extensions
12078 \begin_layout Subsubsection
12080 \begin_inset LatexCommand \index{data (hc08 storage class)}
12085 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12092 \begin_layout Standard
12093 The data storage class declares a variable that resides in the first 256
12094 bytes of memory (the direct page).
12096 \begin_inset LatexCommand \index{HC08}
12100 is most efficient at accessing variables (especially pointers) stored here.
12103 \begin_layout Subsubsection
12105 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12110 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12117 \begin_layout Standard
12118 The xdata storage class declares a variable that can reside anywhere in
12120 This is the default if no storage class is specified.
12122 \begin_inset VSpace bigskip
12128 \begin_layout Section
12129 Absolute Addressing
12130 \begin_inset LatexCommand \index{Absolute addressing}
12137 \begin_layout Standard
12138 Data items can be assigned an absolute address with the
12141 \begin_inset LatexCommand \index{at}
12146 \begin_inset LatexCommand \index{\_\_at}
12152 keyword, in addition to a storage class, e.g.:
12155 \begin_layout Verse
12159 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12164 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12169 \begin_inset LatexCommand \index{at}
12174 \begin_inset LatexCommand \index{\_\_at}
12178 0x7ffe unsigned int chksum;
12181 \begin_layout Standard
12182 or, better conforming to ISO/IEC 9899 C:
12185 \begin_layout Verse
12188 __xdata __at (0x7ffe) unsigned int chksum;
12191 \begin_layout Standard
12192 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12193 of the external ram.
12198 reserve any space for variables declared in this way
12199 \begin_inset Marginal
12202 \begin_layout Standard
12211 (they are implemented with an equate in the assembler).
12212 Thus it is left to the programmer to make sure there are no overlaps with
12213 other variables that are declared without the absolute address.
12214 The assembler listing file (.lst
12215 \begin_inset LatexCommand \index{<file>.lst}
12219 ) and the linker output files (.rst
12220 \begin_inset LatexCommand \index{<file>.rst}
12225 \begin_inset LatexCommand \index{<file>.map}
12229 ) are good places to look for such overlaps.
12230 Variables with an absolute address are
12233 \begin_inset Marginal
12236 \begin_layout Standard
12248 \begin_inset LatexCommand \index{Variable initialization}
12255 \begin_layout Standard
12256 In case of memory mapped I/O devices the keyword
12260 has to be used to tell the compiler that accesses might not be removed:
12263 \begin_layout Verse
12267 \begin_inset LatexCommand \index{volatile}
12272 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12277 \begin_inset LatexCommand \index{at}
12281 (0x8000) unsigned char PORTA_8255;
12284 \begin_layout Standard
12285 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12290 \begin_inset LatexCommand \index{Aligned array}
12297 starts at a block (256 byte) boundary
12298 \begin_inset LatexCommand \index{block boundary}
12303 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12309 Absolute addresses can be specified for variables in all
12310 storage classes, e.g.:
12313 \begin_layout Verse
12317 \begin_inset LatexCommand \index{bit}
12322 \begin_inset LatexCommand \index{at}
12329 \begin_layout Standard
12330 The above example will allocate the variable at offset 0x02 in the bit-addressab
12332 There is no real advantage to assigning absolute addresses to variables
12333 in this manner, unless you want strict control over all the variables allocated.
12334 One possible use would be to write hardware portable code.
12335 For example, if you have a routine that uses one or more of the microcontroller
12336 I/O pins, and such pins are different for two different hardwares, you
12337 can declare the I/O pins in your routine using:
12340 \begin_layout Verse
12344 \begin_inset LatexCommand \index{volatile}
12348 __bit MOSI;\InsetSpace ~
12352 /* master out, slave in */
12354 extern volatile __bit MISO;\InsetSpace ~
12361 extern volatile __bit MCLK;\InsetSpace ~
12370 Output of a byte on a 3-wire serial bus.
12375 If needed adapt polarity of clock,
12376 polarity of data and bit order
12381 unsigned char spi_io(unsigned char out_byte)
12406 MOSI = out_byte & 0x80;
12437 /* _asm nop _endasm; */\InsetSpace ~
12445 /* for slow peripherals */
12497 \begin_layout Standard
12498 Then, someplace in the code for the first hardware you would use
12501 \begin_layout Verse
12505 \begin_inset LatexCommand \index{at}
12510 \begin_inset LatexCommand \index{\_\_at}
12514 (0x80) MOSI;\InsetSpace ~
12518 /* I/O port 0, bit 0 */
12520 __bit __at (0x81) MISO;\InsetSpace ~
12527 __bit __at (0x82) MCLK;\InsetSpace ~
12531 /* I/O port 0, bit 2 */
12534 \begin_layout Standard
12535 Similarly, for the second hardware you would use
12538 \begin_layout Verse
12541 __bit __at (0x83) MOSI;\InsetSpace ~
12545 /* I/O port 0, bit 3 */
12547 __bit __at (0x91) MISO;\InsetSpace ~
12552 I/O port 1, bit 1 */
12555 \begin_inset LatexCommand \index{bit}
12559 __at (0x92) MCLK;\InsetSpace ~
12563 /* I/O port 1, bit 2 */
12566 \begin_layout Standard
12567 and you can use the same hardware dependent routine without changes, as
12568 for example in a library.
12569 This is somehow similar to sbit, but only one absolute address has to be
12570 specified in the whole project.
12571 \begin_inset VSpace bigskip
12577 \begin_layout Section
12579 \begin_inset LatexCommand \index{Parameters}
12584 \begin_inset LatexCommand \index{function parameter}
12589 \begin_inset LatexCommand \index{local variables}
12594 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12601 \begin_layout Standard
12602 Automatic (local) variables and parameters to functions can either be placed
12603 on the stack or in data-space.
12604 The default action of the compiler is to place these variables in the internal
12605 RAM (for small model) or external RAM (for large model).
12606 This in fact makes them similar to
12609 \begin_inset LatexCommand \index{static}
12615 so by default functions are non-reentrant
12616 \begin_inset LatexCommand \index{reentrant}
12625 They can be placed on the stack
12626 \begin_inset LatexCommand \index{stack}
12636 \begin_layout Standard
12646 \begin_inset LatexCommand \index{-\/-stack-auto}
12654 #pragma\InsetSpace ~
12658 \begin_inset LatexCommand \index{\#pragma stackauto}
12665 \begin_inset LatexCommand \index{reentrant}
12671 keyword in the function declaration, e.g.:
12674 \begin_layout Verse
12677 unsigned char foo(char i) __reentrant
12691 \begin_layout Standard
12692 Since stack space on 8051 is limited, the
12702 \begin_layout Standard
12713 option should be used sparingly.
12714 Note that the reentrant keyword just means that the parameters & local
12715 variables will be allocated to the stack, it
12719 mean that the function is register bank
12720 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12729 \begin_inset LatexCommand \index{local variables}
12733 can be assigned storage classes and absolute
12734 \begin_inset LatexCommand \index{Absolute addressing}
12741 \begin_layout Verse
12744 unsigned char foo()
12752 __xdata unsigned char i;
12765 \begin_inset LatexCommand \index{at}
12769 (0x31) unsigned char j;
12781 \begin_layout Standard
12782 In the above example the variable
12786 will be allocated in the external ram,
12790 in bit addressable space and
12801 \begin_layout Standard
12812 or when a function is declared as
12816 this should only be done for static variables.
12819 \begin_layout Standard
12821 \begin_inset LatexCommand \index{function parameter}
12825 however are not allowed any storage class
12826 \begin_inset LatexCommand \index{Storage class}
12830 , (storage classes for parameters will be ignored), their allocation is
12831 governed by the memory model in use, and the reentrancy options.
12834 \begin_layout Standard
12835 It is however allowed to use bit parameters in reentrant functions and also
12836 non-static local bit variables are supported.
12837 Efficient use is limited to 8 semi-bitregisters in bit space.
12838 They are pushed and popped to stack
12839 \begin_inset LatexCommand \index{stack}
12843 as a single byte just like the normal registers.
12846 \begin_layout Section
12848 \begin_inset LatexCommand \label{sub:Overlaying}
12853 \begin_inset LatexCommand \index{Overlaying}
12860 \begin_layout Standard
12862 \begin_inset LatexCommand \index{reentrant}
12866 functions SDCC will try to reduce internal ram space usage by overlaying
12867 parameters and local variables of a function (if possible).
12868 Parameters and local variables
12869 \begin_inset LatexCommand \index{local variables}
12873 of a function will be allocated to an overlayable segment if the function
12876 no other function calls and the function is non-reentrant and the memory
12878 \begin_inset LatexCommand \index{Memory model}
12885 If an explicit storage class
12886 \begin_inset LatexCommand \index{Storage class}
12890 is specified for a local variable, it will NOT be overlayed.
12893 \begin_layout Standard
12894 Note that the compiler (not the linkage editor) makes the decision for overlayin
12896 Functions that are called from an interrupt service routine
12897 \begin_inset Marginal
12900 \begin_layout Standard
12908 should be preceded by a #pragma\InsetSpace ~
12910 \begin_inset LatexCommand \index{\#pragma nooverlay}
12914 if they are not reentrant.
12917 \begin_layout Standard
12918 Also note that the compiler does not do any processing of inline assembler
12919 code, so the compiler might incorrectly assign local variables and parameters
12920 of a function into the overlay segment if the inline assembler code calls
12921 other c-functions that might use the overlay.
12922 In that case the #pragma\InsetSpace ~
12923 nooverlay should be used.
12926 \begin_layout Standard
12927 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12929 \begin_inset LatexCommand \index{Multiplication}
12934 \begin_inset LatexCommand \index{Division}
12938 will NOT be overlayed since these are implemented using external functions,
12942 \begin_layout Verse
12948 \begin_inset LatexCommand \index{\#pragma nooverlay}
12954 void set_error(unsigned char errcd)
12971 some_isr () __interrupt
12972 \begin_inset LatexCommand \index{interrupt}
13002 \begin_layout Standard
13003 In the above example the parameter
13011 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13013 not present, this could cause unpredictable runtime behavior when called
13014 from an interrupt service routine.
13015 The #pragma\InsetSpace ~
13016 nooverlay ensures that the parameters and local variables for
13017 the function are NOT overlayed.
13018 \begin_inset VSpace bigskip
13024 \begin_layout Section
13025 Interrupt Service Routines
13026 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13033 \begin_layout Subsection
13034 General Information
13037 \begin_layout Standard
13050 outines to be coded in C, with some extended keywords.
13053 \begin_layout Verse
13056 void timer_isr (void) __interrupt (1) __using (1)
13070 \begin_layout Standard
13071 The optional number following the
13074 \begin_inset LatexCommand \index{interrupt}
13079 \begin_inset LatexCommand \index{\_\_interrupt}
13085 keyword is the interrupt number this routine will service.
13086 When present, the compiler will insert a call to this routine in the interrupt
13088 \begin_inset LatexCommand \index{interrupt vector table}
13092 for the interrupt number specified.
13093 If you have multiple source files in your project, interrupt service routines
13094 can be present in any of them, but a prototype of the isr MUST be present
13095 or included in the file that contains the function
13100 The optional (8051 specific) keyword
13103 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13108 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13114 can be used to tell the compiler to use the specified register bank when
13115 generating code for this function.
13118 Interrupt service routines open the door for some very interesting bugs:
13121 \begin_layout Subsubsection
13122 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13126 Common interrupt pitfall: variable not declared
13131 \begin_layout Standard
13132 If an interrupt service routine changes variables which are accessed by
13133 other functions these variables have to be declared
13138 \begin_inset LatexCommand \index{volatile}
13144 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13151 \begin_layout Subsubsection
13152 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13156 Common interrupt pitfall:
13161 \begin_layout Standard
13162 If the access to these variables is not
13165 \begin_inset LatexCommand \index{atomic}
13172 the processor needs more than one instruction for the access and could
13173 be interrupted while accessing the variable) the interrupt must be disabled
13174 during the access to avoid inconsistent data.
13177 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13178 and should be protected by disabling interrupts.
13179 You're not automatically on the safe side if you use 8 bit variables though.
13180 We need an example here: f.e.
13181 on the 8051 the harmless looking
13182 \begin_inset Quotes srd
13192 \begin_inset Quotes sld
13201 \begin_inset Quotes srd
13211 \begin_inset Quotes sld
13214 from within an interrupt routine might get lost if the interrupt occurs
13217 \begin_inset Quotes sld
13222 counter\InsetSpace ~
13227 \begin_inset Quotes srd
13230 is not atomic on the 8051 even if
13234 is located in data memory.
13236 Bugs like these are hard to reproduce and can
13237 cause a lot of trouble.
13241 \begin_layout Subsubsection
13242 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13246 Common interrupt pitfall:
13251 \begin_layout Standard
13252 The return address and the registers used in the interrupt service routine
13253 are saved on the stack
13254 \begin_inset LatexCommand \index{stack}
13258 so there must be sufficient stack space.
13259 If there isn't variables or registers (or even the return address itself)
13266 \begin_inset LatexCommand \index{stack overflow}
13270 is most likely to happen if the interrupt occurs during the
13271 \begin_inset Quotes sld
13275 \begin_inset Quotes srd
13278 subroutine when the stack is already in use for f.e.
13279 many return addresses.
13282 \begin_layout Subsubsection
13283 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13287 Common interrupt pitfall:
13289 use of non-reentrant functions
13292 \begin_layout Standard
13293 A special note here, int (16 bit) and long (32 bit) integer division
13294 \begin_inset LatexCommand \index{Division}
13299 \begin_inset LatexCommand \index{Multiplication}
13304 \begin_inset LatexCommand \index{Modulus}
13309 \begin_inset LatexCommand \index{Floating point support}
13313 operations are implemented using external support routines.
13314 If an interrupt service routine needs to do any of these operations then
13315 the support routines (as mentioned in a following section) will have to
13316 be recompiled using the
13322 \begin_layout Standard
13332 \begin_inset LatexCommand \index{-\/-stack-auto}
13338 option and the source file will need to be compiled using the
13344 \begin_layout Standard
13356 \begin_inset LatexCommand \index{-\/-int-long-reent}
13363 Note, the type promotion
13364 \begin_inset LatexCommand \index{type promotion}
13368 required by ANSI C can cause 16 bit routines to be used
13369 \begin_inset Marginal
13372 \begin_layout Standard
13381 without the programmer being aware of it.
13385 (unsigned char)(tail-1)
13387 within the if clause in section
13388 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13395 \begin_layout Standard
13396 Calling other functions from an interrupt service routine is not recommended,
13397 avoid it if possible.
13398 Note that when some function is called from an interrupt service routine
13399 it should be preceded by a #pragma\InsetSpace ~
13401 \begin_inset LatexCommand \index{\#pragma nooverlay}
13405 if it is not reentrant.
13406 Furthermore nonreentrant functions should not be called from the main program
13407 while the interrupt service routine might be active.
13408 They also must not be called from low priority interrupt service routines
13409 while a high priority interrupt service routine might be active.
13410 You could use semaphores or make the function
13414 if all parameters are passed in registers.
13417 \begin_inset LatexCommand \ref{sub:Overlaying}
13422 about Overlaying and section
13423 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13428 about Functions using private register banks.
13429 \begin_inset VSpace bigskip
13435 \begin_layout Subsection
13436 MCS51/DS390 Interrupt Service Routines
13439 \begin_layout Standard
13441 \begin_inset LatexCommand \index{interrupt}
13445 numbers and the corresponding address & descriptions for the Standard 8051/8052
13447 SDCC will automatically adjust the
13448 \begin_inset LatexCommand \index{interrupt vector table}
13452 to the maximum interrupt number specified.
13457 \begin_layout Standard
13459 \begin_inset Tabular
13460 <lyxtabular version="3" rows="9" columns="3">
13462 <column alignment="center" valignment="top" leftline="true" width="0in">
13463 <column alignment="left" valignment="top" leftline="true" width="0in">
13464 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13465 <row topline="true" bottomline="true">
13466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13469 \begin_layout Standard
13475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13478 \begin_layout Standard
13484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13487 \begin_layout Standard
13494 <row topline="true">
13495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13498 \begin_layout Standard
13504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13507 \begin_layout Standard
13513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13516 \begin_layout Standard
13523 <row topline="true">
13524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13527 \begin_layout Standard
13533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13536 \begin_layout Standard
13542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13545 \begin_layout Standard
13552 <row topline="true">
13553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13556 \begin_layout Standard
13562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13565 \begin_layout Standard
13571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13574 \begin_layout Standard
13581 <row topline="true">
13582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13585 \begin_layout Standard
13591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13594 \begin_layout Standard
13600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13603 \begin_layout Standard
13610 <row topline="true">
13611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13614 \begin_layout Standard
13620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13623 \begin_layout Standard
13629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13632 \begin_layout Standard
13639 <row topline="true">
13640 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13643 \begin_layout Standard
13649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13652 \begin_layout Standard
13658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13661 \begin_layout Standard
13668 <row topline="true">
13669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13672 \begin_layout Standard
13678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13681 \begin_layout Standard
13687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13690 \begin_layout Standard
13697 <row topline="true" bottomline="true">
13698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13701 \begin_layout Standard
13707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13710 \begin_layout Standard
13716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13719 \begin_layout Standard
13735 \begin_layout Standard
13736 If the interrupt service routine is defined without
13739 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13744 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13750 a register bank or with register bank 0 (
13754 0), the compiler will save the registers used by itself on the stack upon
13755 entry and restore them at exit, however if such an interrupt service routine
13756 calls another function then the entire register bank will be saved on the
13758 This scheme may be advantageous for small interrupt service routines which
13759 have low register usage.
13762 \begin_layout Standard
13763 If the interrupt service routine is defined to be using a specific register
13768 & psw are saved and restored, if such an interrupt service routine calls
13769 another function (using another register bank) then the entire register
13770 bank of the called function will be saved on the stack
13771 \begin_inset LatexCommand \index{stack}
13776 This scheme is recommended for larger interrupt service routines.
13777 \begin_inset VSpace bigskip
13783 \begin_layout Subsection
13785 \begin_inset LatexCommand \index{HC08}
13789 Interrupt Service Routines
13792 \begin_layout Standard
13793 Since the number of interrupts
13794 \begin_inset LatexCommand \index{HC08!interrupt}
13798 available is chip specific and the interrupt vector table always ends at
13799 the last byte of memory, the interrupt numbers corresponds to the interrupt
13800 vectors in reverse order of address.
13801 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
13802 2 will use the interrupt vector at 0xfffa, and so on.
13803 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
13804 this way; instead see section
13805 \begin_inset LatexCommand \ref{sub:Startup-Code}
13809 for details on customizing startup.
13810 \begin_inset VSpace bigskip
13816 \begin_layout Subsection
13817 Z80 Interrupt Service Routines
13820 \begin_layout Standard
13822 \begin_inset LatexCommand \index{Z80}
13826 uses several different methods for determining the correct interrupt
13827 \begin_inset LatexCommand \index{Z80!interrupt}
13831 vector depending on the hardware implementation.
13832 Therefore, SDCC ignores the optional interrupt number and does not attempt
13833 to generate an interrupt vector table.
13836 \begin_layout Standard
13837 By default, SDCC generates code for a maskable interrupt, which uses a RETI
13838 instruction to return from the interrupt.
13839 To write an interrupt handler for the non-maskable interrupt, which needs
13840 a RETN instruction instead, add the
13847 \begin_layout Verse
13850 void nmi_isr (void) critical interrupt
13864 \begin_layout Standard
13865 However if you need to create a non-interruptable interrupt service routine
13866 you would also require the
13871 To distinguish between this and an nmi_isr you must provide an interrupt
13873 \begin_inset VSpace bigskip
13879 \begin_layout Section
13880 Enabling and Disabling Interrupts
13883 \begin_layout Subsection
13884 Critical Functions and Critical Statements
13887 \begin_layout Standard
13888 A special keyword may be associated with a block or a function declaring
13894 SDCC will generate code to disable all interrupts
13895 \begin_inset LatexCommand \index{interrupt}
13899 upon entry to a critical function and restore the interrupt enable to the
13900 previous state before returning.
13901 Nesting critical functions will need one additional byte on the stack
13902 \begin_inset LatexCommand \index{stack}
13909 \begin_layout Verse
13912 int foo () __critical
13913 \begin_inset LatexCommand \index{critical}
13918 \begin_inset LatexCommand \index{\_\_critical}
13943 \begin_layout Standard
13944 The critical attribute maybe used with other attributes like
13954 may also be used to disable interrupts more locally:
13957 \begin_layout Verse
13963 \begin_layout Standard
13964 More than one statement could have been included in the block.
13967 \begin_layout Subsection
13968 Enabling and Disabling Interrupts directly
13971 \begin_layout Standard
13973 \begin_inset LatexCommand \index{interrupt}
13977 can also be disabled and enabled directly (8051):
13980 \begin_layout Verse
13983 EA = 0;\InsetSpace ~
14009 \begin_layout Verse
14045 \begin_layout Verse
14048 EA = 1;\InsetSpace ~
14077 \begin_layout Verse
14116 \begin_layout Standard
14117 On other architectures which have seperate opcodes for enabling and disabling
14118 interrupts you might want to make use of defines with inline assembly
14119 \begin_inset LatexCommand \index{Assembler routines}
14124 \begin_inset LatexCommand \index{HC08!interrupt}
14131 \begin_layout Verse
14135 \begin_inset LatexCommand \index{\_asm}
14144 \begin_inset LatexCommand \index{\_endasm}
14151 \begin_layout Verse
14154 #define SEI _asm\InsetSpace ~
14161 \begin_layout Verse
14167 \begin_layout Standard
14168 Note: it is sometimes sufficient to disable only a specific interrupt source
14170 a timer or serial interrupt by manipulating an
14173 \begin_inset LatexCommand \index{interrupt mask}
14183 \begin_layout Standard
14184 Usually the time during which interrupts are disabled should be kept as
14186 This minimizes both
14191 \begin_inset LatexCommand \index{interrupt latency}
14195 (the time between the occurrence of the interrupt and the execution of
14196 the first code in the interrupt routine) and
14201 \begin_inset LatexCommand \index{interrupt jitter}
14205 (the difference between the shortest and the longest interrupt latency).
14206 These really are something different, f.e.
14207 a serial interrupt has to be served before its buffer overruns so it cares
14208 for the maximum interrupt latency, whereas it does not care about jitter.
14209 On a loudspeaker driven via a digital to analog converter which is fed
14210 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14211 a much smaller jitter will be very audible.
14214 \begin_layout Standard
14215 You can reenable interrupts within an interrupt routine and on some architecture
14216 s you can make use of two (or more) levels of
14218 interrupt priorities
14221 \begin_inset LatexCommand \index{interrupt priority}
14226 On some architectures which don't support interrupt priorities these can
14227 be implemented by manipulating the interrupt mask and reenabling interrupts
14228 within the interrupt routine.
14229 Check there is sufficient space on the stack
14230 \begin_inset LatexCommand \index{stack}
14234 and don't add complexity unless you have to.
14238 \begin_layout Subsection
14240 \begin_inset LatexCommand \index{semaphore}
14244 locking (mcs51/ds390)
14247 \begin_layout Standard
14248 Some architectures (mcs51/ds390) have an atomic
14249 \begin_inset LatexCommand \index{atomic}
14262 These type of instructions are typically used in preemptive multitasking
14263 systems, where a routine f.e.
14264 claims the use of a data structure ('acquires a lock
14265 \begin_inset LatexCommand \index{lock}
14269 on it'), makes some modifications and then releases the lock when the data
14270 structure is consistent again.
14271 The instruction may also be used if interrupt and non-interrupt code have
14272 to compete for a resource.
14273 With the atomic bit test and clear instruction interrupts
14274 \begin_inset LatexCommand \index{interrupt}
14278 don't have to be disabled for the locking operation.
14282 \begin_layout Standard
14283 SDCC generates this instruction if the source follows this pattern:
14286 \begin_layout Verse
14290 \begin_inset LatexCommand \index{volatile}
14294 bit resource_is_free;
14298 if (resource_is_free)
14308 resource_is_free=0;
14321 resource_is_free=1;
14328 \begin_layout Standard
14329 Note, mcs51 and ds390 support only an atomic
14330 \begin_inset LatexCommand \index{atomic}
14338 instruction (as opposed to atomic bit test and
14343 \begin_layout Section
14344 Functions using private register banks
14345 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14352 \begin_layout Standard
14353 Some architectures have support for quickly changing register sets.
14354 SDCC supports this feature with the
14357 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14362 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14368 attribute (which tells the compiler to use a register bank
14369 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14373 other than the default bank zero).
14374 It should only be applied to
14377 \begin_inset LatexCommand \index{interrupt}
14383 functions (see footnote below).
14384 This will in most circumstances make the generated ISR code more efficient
14385 since it will not have to save registers on the stack.
14388 \begin_layout Standard
14393 attribute will have no effect on the generated code for a
14397 function (but may occasionally be useful anyway
14401 \begin_layout Standard
14402 possible exception: if a function is called ONLY from 'interrupt' functions
14403 using a particular bank, it can be declared with the same 'using' attribute
14404 as the calling 'interrupt' functions.
14405 For instance, if you have several ISRs using bank one, and all of them
14406 call memcpy(), it might make sense to create a specialized version of memcpy()
14407 'using 1', since this would prevent the ISR from having to save bank zero
14408 to the stack on entry and switch to bank zero before calling the function
14417 (pending: Note, nowadays the
14421 attribute has an effect on
14425 the generated code for a
14436 \begin_layout Standard
14441 function using a non-zero bank will assume that it can trash that register
14442 bank, and will not save it.
14443 Since high-priority interrupts
14444 \begin_inset LatexCommand \index{interrupts}
14449 \begin_inset LatexCommand \index{interrupt priority}
14453 can interrupt low-priority ones on the 8051 and friends, this means that
14454 if a high-priority ISR
14458 a particular bank occurs while processing a low-priority ISR
14462 the same bank, terrible and bad things can happen.
14463 To prevent this, no single register bank should be
14467 by both a high priority and a low priority ISR.
14468 This is probably most easily done by having all high priority ISRs use
14469 one bank and all low priority ISRs use another.
14470 If you have an ISR which can change priority at runtime, you're on your
14471 own: I suggest using the default bank zero and taking the small performance
14475 \begin_layout Standard
14476 It is most efficient if your ISR calls no other functions.
14477 If your ISR must call other functions, it is most efficient if those functions
14478 use the same bank as the ISR (see note 1 below); the next best is if the
14479 called functions use bank zero.
14480 It is very inefficient to call a function using a different, non-zero bank
14483 \begin_inset VSpace bigskip
14489 \begin_layout Section
14491 \begin_inset LatexCommand \label{sub:Startup-Code}
14496 \begin_inset LatexCommand \index{Startup code}
14503 \begin_layout Subsection
14504 MCS51/DS390 Startup Code
14507 \begin_layout Standard
14508 The compiler inserts a call to the C routine
14510 _sdcc_external_startup()
14511 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
14520 at the start of the CODE area.
14521 This routine is in the runtime library
14522 \begin_inset LatexCommand \index{Runtime library}
14527 By default this routine returns 0, if this routine returns a non-zero value,
14528 the static & global variable initialization will be skipped and the function
14529 main will be invoked.
14530 Otherwise static & global variables will be initialized before the function
14534 _sdcc_external_startup()
14536 routine to your program to override the default if you need to setup hardware
14537 or perform some other critical operation prior to static & global variable
14539 \begin_inset LatexCommand \index{Variable initialization}
14544 On some mcs51 variants xdata
14545 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
14549 memory has to be explicitly enabled before it can be accessed or if the
14551 \begin_inset LatexCommand \index{watchdog}
14555 needs to be disabled, this is the place to do it.
14556 The startup code clears all internal data memory, 256 bytes by default,
14557 but from 0 to n-1 if
14563 \begin_layout Standard
14573 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
14580 (recommended for Chipcon CC1010).
14583 \begin_layout Standard
14584 See also the compiler options
14590 \begin_layout Standard
14606 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14616 \begin_layout Standard
14628 \begin_inset LatexCommand \index{-\/-main-return}
14633 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14637 about MCS51-variants.
14638 \begin_inset VSpace bigskip
14644 \begin_layout Subsection
14648 \begin_layout Standard
14650 \begin_inset LatexCommand \index{HC08}
14654 startup code follows the same scheme as the MCS51 startup code.
14655 \begin_inset VSpace bigskip
14661 \begin_layout Subsection
14665 \begin_layout Standard
14667 \begin_inset LatexCommand \index{Z80}
14671 the startup code is inserted by linking with crt0.o which is generated from
14672 sdcc/device/lib/z80/crt0.s.
14673 If you need a different startup code you can use the compiler option
14682 \begin_layout Standard
14697 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14701 and provide your own crt0.o.
14703 \begin_inset VSpace bigskip
14709 \begin_layout Section
14710 Inline Assembler Code
14711 \begin_inset LatexCommand \index{Assembler routines}
14718 \begin_layout Subsection
14719 A Step by Step Introduction
14720 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14727 \begin_layout Standard
14728 Starting from a small snippet of c-code this example shows for the MCS51
14729 how to use inline assembly, access variables, a function parameter and
14730 an array in xdata memory.
14731 The example uses an MCS51 here but is easily adapted for other architectures.
14732 This is a buffer routine which should be optimized:
14735 \begin_layout Verse
14739 unsigned char __far
14740 \begin_inset LatexCommand \index{far (storage class)}
14745 \begin_inset LatexCommand \index{\_\_far (storage class)}
14750 \begin_inset LatexCommand \index{at}
14755 \begin_inset LatexCommand \index{\_\_at}
14759 (0x7f00) buf[0x100];
14760 \begin_inset LatexCommand \index{Aligned array}
14766 unsigned char head, tail;\InsetSpace ~
14784 \begin_inset LatexCommand \index{interrupt}
14836 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14848 void to_buffer( unsigned char c )
14856 if( head != (unsigned char)(tail-1)
14863 \begin_inset LatexCommand \index{promotion to signed int}
14868 \begin_inset LatexCommand \index{type promotion}
14873 \begin_inset Marginal
14876 \begin_layout Standard
14895 buf[ head++ ] = c;\InsetSpace ~
14911 /* access to a 256 byte aligned array */
14916 \begin_layout Standard
14917 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14918 then a corresponding buffer.asm file is generated.
14919 We define a new function
14923 in file buffer.c in which we cut and paste the generated code, removing
14924 unwanted comments and some ':'.
14926 \begin_inset Quotes sld
14930 \begin_inset Quotes srd
14934 \begin_inset Quotes sld
14938 \begin_inset Quotes srd
14941 to the beginning and the end of the function body:
14944 \begin_layout Verse
14948 /* With a cut and paste from the .asm file, we have something to start with.
14954 function is not yet OK! (registers aren't saved) */
14956 void to_buffer_asm(
14966 \begin_inset LatexCommand \index{\_asm}
14971 \begin_inset LatexCommand \index{\_\_asm}
14985 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
14991 \begin_inset LatexCommand \index{promotion to signed int}
14996 \begin_inset LatexCommand \index{type promotion}
15049 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
15050 \begin_inset LatexCommand \index{Aligned array}
15116 \begin_inset LatexCommand \index{\_endasm}
15121 \begin_inset LatexCommand \index{\_\_endasm}
15130 \begin_layout Standard
15131 The new file buffer.c should compile with only one warning about the unreferenced
15132 function argument 'c'.
15133 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
15134 (1) and finally have:
15137 \begin_layout Verse
15141 unsigned char __far __at(0x7f00) buf[0x100];
15143 unsigned char head, tail;
15154 void to_buffer( unsigned char c )
15163 head != (unsigned char)(tail-1) )
15192 c; // to avoid warning: unreferenced function argument
15199 \begin_inset LatexCommand \index{\_asm}
15204 \begin_inset LatexCommand \index{\_\_asm}
15218 ; save used registers here.
15229 ; If we were still using r2,r3 we would have to push them here.
15232 ; if( head != (unsigned char)(tail-1) )
15276 could do an ANL a,#0x0f here to use a smaller buffer (see below)
15312 a,dpl \InsetSpace ~
15319 ; dpl holds lower byte of function argument
15331 dpl,_head \InsetSpace ~
15334 ; buf is 0x100 byte aligned so head can be used directly
15377 ; we could do an ANL _head,#0x0f here to use a
15378 smaller buffer (see above)
15390 ; restore used registers here
15397 \begin_inset LatexCommand \index{\_endasm}
15402 \begin_inset LatexCommand \index{\_\_endasm}
15413 \begin_layout Standard
15414 The inline assembler code can contain any valid code understood by the assembler
15415 , this includes any assembler directives and comment lines.
15416 The assembler does not like some characters like ':' or ''' in comments.
15417 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
15418 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
15423 \begin_inset LatexCommand \index{Assembler documentation}
15428 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
15436 \begin_layout Standard
15437 The compiler does not do any validation of the code within the
15440 \begin_inset LatexCommand \index{\_asm}
15445 \begin_inset LatexCommand \index{\_\_asm}
15453 \begin_inset LatexCommand \index{\_endasm}
15458 \begin_inset LatexCommand \index{\_\_endasm}
15467 Specifically it will not know which registers are used and thus register
15469 \begin_inset LatexCommand \index{push/pop}
15473 has to be done manually.
15477 \begin_layout Standard
15478 It is recommended that each assembly instruction (including labels) be placed
15479 in a separate line (as the example shows).
15484 \begin_layout Standard
15496 \begin_inset LatexCommand \index{-\/-peep-asm}
15502 command line option is used, the inline assembler code will be passed through
15503 the peephole optimizer
15504 \begin_inset LatexCommand \index{Peephole optimizer}
15509 There are only a few (if any) cases where this option makes sense, it might
15510 cause some unexpected changes in the inline assembler code.
15511 Please go through the peephole optimizer rules defined in file
15515 before using this option.
15518 \begin_layout Subsection
15520 \begin_inset LatexCommand \label{sub:Naked-Functions}
15525 \begin_inset LatexCommand \index{Naked functions}
15532 \begin_layout Standard
15533 A special keyword may be associated with a function declaring it as
15536 \begin_inset LatexCommand \index{\_naked}
15541 \begin_inset LatexCommand \index{\_\_naked}
15552 function modifier attribute prevents the compiler from generating prologue
15553 \begin_inset LatexCommand \index{function prologue}
15558 \begin_inset LatexCommand \index{function epilogue}
15562 code for that function.
15563 This means that the user is entirely responsible for such things as saving
15564 any registers that may need to be preserved, selecting the proper register
15565 bank, generating the
15569 instruction at the end, etc.
15570 Practically, this means that the contents of the function must be written
15571 in inline assembler.
15572 This is particularly useful for interrupt functions, which can have a large
15573 (and often unnecessary) prologue/epilogue.
15574 For example, compare the code generated by these two functions:
15577 \begin_layout Verse
15581 \begin_inset LatexCommand \index{volatile}
15585 data unsigned char counter;
15589 void simpleInterrupt(void) __interrupt
15590 \begin_inset LatexCommand \index{interrupt}
15595 \begin_inset LatexCommand \index{\_\_interrupt}
15613 void nakedInterrupt(void) __interrupt (2) __naked
15622 \begin_inset LatexCommand \index{\_asm}
15627 \begin_inset LatexCommand \index{\_\_asm}
15644 _counter ; does not change flags, no need to save psw
15657 include ret or reti in _naked function.
15664 \begin_inset LatexCommand \index{\_endasm}
15669 \begin_inset LatexCommand \index{\_\_endasm}
15678 \begin_layout Standard
15679 For an 8051 target, the generated simpleInterrupt looks like:
15682 \begin_layout Verse
15689 example, recent versions of SDCC generate
15695 code for simpleInterrupt() and nakedInterrupt()!
15836 \begin_layout Standard
15837 whereas nakedInterrupt looks like:
15840 \begin_layout Verse
15853 _counter ; does not change flags, no need to save psw
15872 MUST explicitly include ret or reti in _naked function
15875 \begin_layout Standard
15876 The related directive #pragma exclude
15877 \begin_inset LatexCommand \index{\#pragma exclude}
15881 allows a more fine grained control over pushing & popping
15882 \begin_inset LatexCommand \index{push/pop}
15889 \begin_layout Standard
15890 While there is nothing preventing you from writing C code inside a
15894 function, there are many ways to shoot yourself in the foot doing this,
15895 and it is recommended that you stick to inline assembler.
15898 \begin_layout Subsection
15899 Use of Labels within Inline Assembler
15902 \begin_layout Standard
15903 SDCC allows the use of in-line assembler with a few restrictions regarding
15905 In older versions of the compiler all labels defined within inline assembler
15914 where nnnn is a number less than 100 (which implies a limit of utmost 100
15915 inline assembler labels
15926 \begin_layout Verse
15930 \begin_inset LatexCommand \index{\_asm}
15935 \begin_inset LatexCommand \index{\_\_asm}
15965 \begin_inset LatexCommand \index{\_endasm}
15970 \begin_inset LatexCommand \index{\_\_endasm}
15977 \begin_layout Standard
15978 Inline assembler code cannot reference any C-Labels, however it can reference
15980 \begin_inset LatexCommand \index{Labels}
15984 defined by the inline assembler, e.g.:
15987 \begin_layout Verse
16010 ; some assembler code
16031 /* some more c code */
16033 clabel:\InsetSpace ~
16035 /* inline assembler cannot reference this
16048 $0003: ;label (can be referenced by inline assembler only)
16056 \begin_inset LatexCommand \index{\_endasm}
16061 \begin_inset LatexCommand \index{\_\_endasm}
16071 /* some more c code */
16076 \begin_layout Standard
16077 In other words inline assembly code can access labels defined in inline
16078 assembly within the scope of the function.
16079 The same goes the other way, i.e.
16080 labels defines in inline assembly can not be accessed by C statements.
16083 \begin_layout Section
16084 Interfacing with Assembler Code
16085 \begin_inset LatexCommand \index{Assembler routines}
16092 \begin_layout Subsection
16093 Global Registers used for Parameter Passing
16094 \begin_inset LatexCommand \index{Parameter passing}
16101 \begin_layout Standard
16102 The compiler always uses the global registers
16105 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16110 \begin_inset LatexCommand \index{DPTR}
16115 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
16124 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
16130 to pass the first parameter to a routine.
16131 The second parameter onwards is either allocated on the stack (for reentrant
16136 \begin_layout Standard
16145 -stack-auto is used) or in data / xdata memory (depending on the memory
16150 \begin_layout Subsection
16151 Assembler Routine (non-reentrant)
16154 \begin_layout Standard
16155 In the following example
16156 \begin_inset LatexCommand \index{reentrant}
16161 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
16165 the function c_func calls an assembler routine asm_func, which takes two
16167 \begin_inset LatexCommand \index{function parameter}
16174 \begin_layout Verse
16177 extern int asm_func(unsigned char, unsigned char);
16181 int c_func (unsigned char
16182 i, unsigned char j)
16190 return asm_func(i,j);
16204 return c_func(10,9);
16209 \begin_layout Standard
16210 The corresponding assembler function is:
16213 \begin_layout Verse
16216 .globl _asm_func_PARM_2
16318 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16335 \begin_layout Standard
16336 Note here that the return values
16337 \begin_inset LatexCommand \index{return value}
16341 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
16343 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
16344 b' & 'acc' for four byte values.
16347 \begin_layout Standard
16348 The parameter naming convention is _<function_name>_PARM_<n>, where n is
16349 the parameter number starting from 1, and counting from the left.
16350 The first parameter is passed in
16351 \begin_inset Quotes eld
16355 \begin_inset Quotes erd
16358 for a one byte parameter,
16359 \begin_inset Quotes eld
16363 \begin_inset Quotes erd
16367 \begin_inset Quotes eld
16371 \begin_inset Quotes erd
16374 for three bytes and
16375 \begin_inset Quotes eld
16379 \begin_inset Quotes erd
16382 for a four bytes parameter.
16383 The variable name for the second parameter will be _<function_name>_PARM_2.
16388 ble the assembler routine with the following command:
16395 asx8051 -losg asmfunc.asm
16402 Then compile and link the assembler routine to the C source file with the
16410 sdcc cfunc.c asmfunc.rel
16413 \begin_layout Subsection
16414 Assembler Routine (reentrant)
16417 \begin_layout Standard
16419 \begin_inset LatexCommand \index{reentrant}
16424 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
16428 the second parameter
16429 \begin_inset LatexCommand \index{function parameter}
16433 onwards will be passed on the stack, the parameters are pushed from right
16435 after the call the leftmost parameter will be on the top of the stack.
16436 Here is an example:
16439 \begin_layout Verse
16442 extern int asm_func(unsigned char, unsigned char);
16446 int c_func (unsigned char
16447 i, unsigned char j) reentrant
16455 return asm_func(i,j);
16475 \begin_layout Standard
16476 The corresponding assembler routine is:
16479 \begin_layout Verse
16579 \begin_layout Standard
16580 The compiling and linking procedure remains the same, however note the extra
16581 entry & exit linkage required for the assembler code, _bp is the stack
16582 frame pointer and is used to compute the offset into the stack for parameters
16583 and local variables.
16584 \begin_inset VSpace bigskip
16590 \begin_layout Section
16592 \begin_inset LatexCommand \index{int (16 bit)}
16597 \begin_inset LatexCommand \index{long (32 bit)}
16604 \begin_layout Standard
16605 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
16606 multiplication and modulus operations are implemented by support routines.
16607 These support routines are all developed in ANSI-C to facilitate porting
16608 to other MCUs, although some model specific assembler optimizations are
16610 The following files contain the described routines, all of them can be
16611 found in <installdir>/share/sdcc/lib.
16616 \begin_layout Standard
16618 \begin_inset Tabular
16619 <lyxtabular version="3" rows="11" columns="2">
16621 <column alignment="left" valignment="top" leftline="true" width="0">
16622 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16623 <row topline="true" bottomline="true">
16624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16627 \begin_layout Standard
16635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16638 \begin_layout Standard
16647 <row topline="true">
16648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16651 \begin_layout Standard
16657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16660 \begin_layout Standard
16661 16 bit multiplication
16667 <row topline="true">
16668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16671 \begin_layout Standard
16677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16680 \begin_layout Standard
16681 signed 16 bit division (calls _divuint)
16687 <row topline="true">
16688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16691 \begin_layout Standard
16697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16700 \begin_layout Standard
16701 unsigned 16 bit division
16707 <row topline="true">
16708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16711 \begin_layout Standard
16717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16720 \begin_layout Standard
16721 signed 16 bit modulus (calls _moduint)
16727 <row topline="true">
16728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16731 \begin_layout Standard
16737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16740 \begin_layout Standard
16741 unsigned 16 bit modulus
16747 <row topline="true">
16748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16751 \begin_layout Standard
16757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16760 \begin_layout Standard
16761 32 bit multiplication
16767 <row topline="true">
16768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16771 \begin_layout Standard
16777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16780 \begin_layout Standard
16781 signed 32 division (calls _divulong)
16787 <row topline="true">
16788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16791 \begin_layout Standard
16797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16800 \begin_layout Standard
16801 unsigned 32 division
16807 <row topline="true">
16808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16811 \begin_layout Standard
16817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16820 \begin_layout Standard
16821 signed 32 bit modulus (calls _modulong)
16827 <row topline="true" bottomline="true">
16828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16831 \begin_layout Standard
16837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16840 \begin_layout Standard
16841 unsigned 32 bit modulus
16856 \begin_layout Standard
16857 Since they are compiled as
16862 \begin_inset LatexCommand \index{reentrant}
16867 \begin_inset LatexCommand \index{interrupt}
16871 service routines should not do any of the above operations.
16872 If this is unavoidable then the above routines will need to be compiled
16879 \begin_layout Standard
16889 \begin_inset LatexCommand \index{-\/-stack-auto}
16895 option, after which the source program will have to be compiled with
16901 \begin_layout Standard
16911 \begin_inset LatexCommand \index{-\/-int-long-reent}
16918 Notice that you don't have to call these routines directly.
16919 The compiler will use them automatically every time an integer operation
16923 \begin_layout Section
16924 Floating Point Support
16925 \begin_inset LatexCommand \index{Floating point support}
16932 \begin_layout Standard
16933 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16934 The floating point support routines are derived from gcc's floatlib.c and
16935 consist of the following routines:
16940 \begin_layout Standard
16944 \begin_inset Tabular
16945 <lyxtabular version="3" rows="17" columns="2">
16947 <column alignment="left" valignment="top" leftline="true" width="0">
16948 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16949 <row topline="true" bottomline="true">
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16953 \begin_layout Standard
16968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16971 \begin_layout Standard
16978 <row topline="true">
16979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16982 \begin_layout Standard
16997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17000 \begin_layout Standard
17010 add floating point numbers
17016 <row topline="true">
17017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17020 \begin_layout Standard
17035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17038 \begin_layout Standard
17048 subtract floating point numbers
17054 <row topline="true">
17055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17058 \begin_layout Standard
17073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17076 \begin_layout Standard
17086 divide floating point numbers
17092 <row topline="true">
17093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17096 \begin_layout Standard
17111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17114 \begin_layout Standard
17124 multiply floating point numbers
17130 <row topline="true">
17131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17134 \begin_layout Standard
17149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17152 \begin_layout Standard
17162 convert floating point to unsigned char
17168 <row topline="true">
17169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17172 \begin_layout Standard
17187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17190 \begin_layout Standard
17200 convert floating point to signed char
17206 <row topline="true">
17207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17210 \begin_layout Standard
17225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17228 \begin_layout Standard
17238 convert floating point to unsigned int
17244 <row topline="true">
17245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17248 \begin_layout Standard
17263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17266 \begin_layout Standard
17276 convert floating point to signed int
17282 <row topline="true">
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17286 \begin_layout Standard
17309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17312 \begin_layout Standard
17322 convert floating point to unsigned long
17328 <row topline="true">
17329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17332 \begin_layout Standard
17347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17350 \begin_layout Standard
17360 convert floating point to signed long
17366 <row topline="true">
17367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17370 \begin_layout Standard
17385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17388 \begin_layout Standard
17398 convert unsigned char to floating point
17404 <row topline="true">
17405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17408 \begin_layout Standard
17423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17426 \begin_layout Standard
17436 convert char to floating point number
17442 <row topline="true">
17443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17446 \begin_layout Standard
17461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17464 \begin_layout Standard
17474 convert unsigned int to floating point
17480 <row topline="true">
17481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17484 \begin_layout Standard
17499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17502 \begin_layout Standard
17512 convert int to floating point numbers
17518 <row topline="true">
17519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17522 \begin_layout Standard
17537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17540 \begin_layout Standard
17550 convert unsigned long to floating point number
17556 <row topline="true" bottomline="true">
17557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17560 \begin_layout Standard
17575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17578 \begin_layout Standard
17588 convert long to floating point number
17603 \begin_layout Standard
17604 These support routines are developed in ANSI-C so there is room for space
17605 and speed improvement
17609 \begin_layout Standard
17610 These floating point routines (
17614 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17621 Note if all these routines are used simultaneously the data space might
17623 For serious floating point usage the large model might be needed.
17624 Also notice that you don't have to call this routines directly.
17625 The compiler will use them automatically every time a floating point operation
17627 \begin_inset VSpace bigskip
17633 \begin_layout Section
17635 \begin_inset LatexCommand \index{Libraries}
17642 \begin_layout Standard
17645 <pending: this is messy and incomplete - a little more information is in
17646 sdcc/doc/libdoc.txt
17651 \begin_layout Subsection
17652 Compiler support routines (_gptrget, _mulint etc.)
17655 \begin_layout Subsection
17656 Stdclib functions (puts, printf, strcat etc.)
17659 \begin_layout Subsubsection
17663 \begin_layout Paragraph
17664 getchar(), putchar()
17667 \begin_layout Standard
17668 \begin_inset LatexCommand \index{<stdio.h>}
17672 As usual on embedded systems you have to provide your own
17675 \begin_inset LatexCommand \index{getchar()}
17684 \begin_inset LatexCommand \index{putchar()}
17691 SDCC does not know whether the system connects to a serial line with or
17692 without handshake, LCD, keyboard or other device.
17706 You'll find examples for serial routines f.e.
17707 in sdcc/device/lib.
17708 For the mcs51 this minimalistic polling
17712 routine might be a start:
17715 \begin_layout Verse
17718 void putchar (char c) {
17724 while (!TI)\InsetSpace ~
17727 /* assumes UART is initialized */
17755 \begin_layout Paragraph
17759 \begin_layout Standard
17763 \begin_inset LatexCommand \index{printf()}
17773 does not support float (except on ds390).
17774 To enable this recompile it with the option
17780 \begin_layout Standard
17790 \begin_inset LatexCommand \index{USE\_FLOATS}
17796 on the command line.
17803 \begin_layout Standard
17813 \begin_inset LatexCommand \index{-\/-model-large}
17819 for the mcs51 port, since this uses a lot of memory.
17822 \begin_layout Standard
17823 If you're short on code memory you might want to use
17826 \begin_inset LatexCommand \index{printf\_small()}
17841 For the mcs51 there additionally are assembly versions
17844 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17850 (subset of printf using less than 270 bytes) and
17853 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17862 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17868 (floating-point aware version of printf_fast) which should fit the requirements
17869 of many embedded systems (printf_fast() can be customized by unsetting
17874 support long variables and field widths).
17875 Be shure to only use only one of these printf options within a project.
17880 \begin_layout Standard
17881 Feature matrix of different
17888 \begin_layout Standard
17889 \begin_inset Tabular
17890 <lyxtabular version="3" rows="14" columns="7">
17891 <features islongtable="true">
17892 <column alignment="left" valignment="middle" leftline="true" width="14col%">
17893 <column alignment="center" valignment="top" leftline="true" width="0">
17894 <column alignment="center" valignment="top" leftline="true" width="12col%">
17895 <column alignment="center" valignment="top" leftline="true" width="10col%">
17896 <column alignment="center" valignment="top" leftline="true" width="0">
17897 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17898 <column alignment="center" valignment="top" rightline="true" width="0">
17899 <row topline="true" bottomline="true" endhead="true">
17900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17903 \begin_layout Standard
17912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17915 \begin_layout Standard
17917 \begin_inset LatexCommand \index{printf}
17926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17929 \begin_layout Standard
17937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17940 \begin_layout Standard
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17949 \begin_layout Standard
17955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17958 \begin_layout Standard
17964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17967 \begin_layout Standard
17974 <row topline="true" endhead="true">
17975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17978 \begin_layout Standard
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17987 \begin_layout Standard
17995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17998 \begin_layout Standard
18006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18009 \begin_layout Standard
18017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18020 \begin_layout Standard
18028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18031 \begin_layout Standard
18039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18042 \begin_layout Standard
18051 <row topline="true" endhead="true">
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18055 \begin_layout Standard
18056 \begin_inset Quotes sld
18060 \begin_inset Quotes srd
18066 \begin_layout Standard
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18075 \begin_layout Standard
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18084 \begin_layout Standard
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18093 \begin_layout Standard
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18102 \begin_layout Standard
18108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18111 \begin_layout Standard
18117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18120 \begin_layout Standard
18127 <row topline="true" endhead="true">
18128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18131 \begin_layout Standard
18135 \begin_layout Standard
18141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18144 \begin_layout Standard
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18153 \begin_layout Standard
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18162 \begin_layout Standard
18163 0.45k / 0.47k (+ _ltoa)
18168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18171 \begin_layout Standard
18177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18180 \begin_layout Standard
18186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18189 \begin_layout Standard
18196 <row topline="true">
18197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18200 \begin_layout Standard
18206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18209 \begin_layout Standard
18219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18222 \begin_layout Standard
18269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18272 \begin_layout Standard
18311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18314 \begin_layout Standard
18320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18323 \begin_layout Standard
18329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18332 \begin_layout Standard
18339 <row topline="true">
18340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18343 \begin_layout Standard
18344 long (32 bit) support
18349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18352 \begin_layout Standard
18358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18361 \begin_layout Standard
18367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18370 \begin_layout Standard
18376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18379 \begin_layout Standard
18385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18388 \begin_layout Standard
18403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18406 \begin_layout Standard
18413 <row topline="true">
18414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18417 \begin_layout Standard
18418 byte arguments on stack
18423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18426 \begin_layout Standard
18432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18435 \begin_layout Standard
18441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18444 \begin_layout Standard
18450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18453 \begin_layout Standard
18459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18462 \begin_layout Standard
18468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18471 \begin_layout Standard
18478 <row topline="true">
18479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18482 \begin_layout Standard
18484 \begin_inset LatexCommand \index{Floating point support}
18493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18496 \begin_layout Standard
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18505 \begin_layout Standard
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18514 \begin_layout Standard
18520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18523 \begin_layout Standard
18529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18532 \begin_layout Standard
18537 \begin_layout Standard
18538 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18551 \begin_layout Standard
18558 <row topline="true">
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18562 \begin_layout Standard
18563 float formats %e %g
18568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18571 \begin_layout Standard
18577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18580 \begin_layout Standard
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18589 \begin_layout Standard
18595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18598 \begin_layout Standard
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18607 \begin_layout Standard
18613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18616 \begin_layout Standard
18623 <row topline="true" bottomline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 \begin_layout Standard
18633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18636 \begin_layout Standard
18642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18645 \begin_layout Standard
18651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18654 \begin_layout Standard
18660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18663 \begin_layout Standard
18669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18672 \begin_layout Standard
18678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18681 \begin_layout Standard
18688 <row bottomline="true">
18689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18692 \begin_layout Standard
18697 \begin_layout Standard
18698 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18702 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18710 \begin_layout Standard
18716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18719 \begin_layout Standard
18725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18728 \begin_layout Standard
18734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18737 \begin_layout Standard
18743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18746 \begin_layout Standard
18752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18755 \begin_layout Standard
18761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18764 \begin_layout Standard
18771 <row bottomline="true">
18772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18775 \begin_layout Standard
18780 \begin_layout Standard
18781 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18790 \begin_layout Standard
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18799 \begin_layout Standard
18805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18808 \begin_layout Standard
18814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18817 \begin_layout Standard
18823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18826 \begin_layout Standard
18832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18835 \begin_layout Standard
18841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18844 \begin_layout Standard
18851 <row bottomline="true">
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18855 \begin_layout Standard
18860 \begin_layout Standard
18861 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18870 \begin_layout Standard
18876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18879 \begin_layout Standard
18885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18888 \begin_layout Standard
18894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18897 \begin_layout Standard
18903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18906 \begin_layout Standard
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18915 \begin_layout Standard
18921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18924 \begin_layout Standard
18931 <row bottomline="true">
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18935 \begin_layout Standard
18940 \begin_layout Standard
18941 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18950 \begin_layout Standard
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18959 \begin_layout Standard
18965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18968 \begin_layout Standard
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18977 \begin_layout Standard
18983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18986 \begin_layout Standard
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18995 \begin_layout Standard
19001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19004 \begin_layout Standard
19018 \begin_layout Subsubsection
19020 \begin_inset LatexCommand \index{malloc.h}
19027 \begin_layout Standard
19028 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19029 using dynamic memory allocation
19030 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19035 \begin_inset LatexCommand \index{heap (malloc)}
19039 space of 1024 bytes is provided for malloc to allocate memory from.
19040 If you need a different heap size you need to recompile _heap.c with the
19041 required size defined in HEAP_SIZE.
19042 It is recommended to make a copy of this file into your project directory
19043 and compile it there with:
19046 \begin_layout Verse
19049 sdcc -c _heap.c -D HEAD_SIZE=2048
19052 \begin_layout Standard
19053 And then link it with:
19056 \begin_layout Verse
19059 sdcc main.rel _heap.rel
19062 \begin_layout Subsection
19063 Math functions (sinf, powf, sqrtf etc.)
19066 \begin_layout Subsubsection
19070 \begin_layout Standard
19071 See definitions in file <math.h>.
19074 \begin_layout Subsection
19078 \begin_layout Standard
19080 \begin_inset LatexCommand \index{Libraries}
19084 included in SDCC should have a license at least as liberal as the GNU Lesser
19085 General Public License
19086 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
19097 \begin_layout Standard
19098 \begin_inset Note Comment
19101 \begin_layout Standard
19102 license statements for the libraries are missing.
19103 sdcc/device/lib/ser_ir.c
19106 \begin_layout Standard
19108 come with a GPL (as opposed to LGPL) License - this will not be liberal
19109 enough for many embedded programmers.
19117 \begin_layout Standard
19118 If you have ported some library or want to share experience about some code
19120 falls into any of these categories Busses (I
19121 \begin_inset Formula $^{\textrm{2}}$
19124 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
19125 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
19126 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
19127 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
19132 would certainly like to hear about it.
19135 \begin_layout Standard
19136 Programmers coding for embedded systems are not especially famous for being
19137 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
19138 e these references are very valuable.
19139 Let's help to create a climate where information is shared.
19140 \begin_inset VSpace bigskip
19146 \begin_layout Section
19150 \begin_layout Subsection
19151 MCS51 Memory Models
19152 \begin_inset LatexCommand \index{Memory model}
19157 \begin_inset LatexCommand \index{MCS51 memory model}
19164 \begin_layout Subsubsection
19165 Small, Medium and Large
19168 \begin_layout Standard
19169 SDCC allows three memory models for MCS51 code,
19178 Modules compiled with different memory models should
19182 be combined together or the results would be unpredictable.
19183 The library routines supplied with the compiler are compiled as small,
19185 The compiled library modules are contained in separate directories as small,
19186 medium and large so that you can link to the appropriate set.
19189 \begin_layout Standard
19190 When the medium or large model is used all variables declared without a
19191 storage class will be allocated into the external ram, this includes all
19192 parameters and local variables (for non-reentrant
19193 \begin_inset LatexCommand \index{reentrant}
19198 When the small model is used variables without storage class are allocated
19199 in the internal ram.
19202 \begin_layout Standard
19203 Judicious usage of the processor specific storage classes
19204 \begin_inset LatexCommand \index{Storage class}
19208 and the 'reentrant' function type will yield much more efficient code,
19209 than using the large model.
19210 Several optimizations are disabled when the program is compiled using the
19211 large model, it is therefore recommended that the small model be used unless
19212 absolutely required.
19215 \begin_layout Subsubsection
19217 \begin_inset LatexCommand \label{sub:External-Stack}
19222 \begin_inset LatexCommand \index{stack}
19227 \begin_inset LatexCommand \index{External stack (mcs51)}
19234 \begin_layout Standard
19235 The external stack (-
19239 \begin_layout Standard
19249 \begin_inset LatexCommand \index{-\/-xstack}
19253 ) is located in pdata
19254 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19258 memory (usually at the start of the external ram segment) and uses all
19259 unused space in pdata (max.
19265 \begin_layout Standard
19274 -xstack option is used to compile the program, the parameters and local
19276 \begin_inset LatexCommand \index{local variables}
19280 of all reentrant functions are allocated in this area.
19281 This option is provided for programs with large stack space requirements.
19282 When used with the -
19286 \begin_layout Standard
19296 \begin_inset LatexCommand \index{-\/-stack-auto}
19300 option, all parameters and local variables are allocated on the external
19301 stack (note: support libraries will need to be recompiled with the same
19303 There is a predefined target in the library makefile).
19306 \begin_layout Standard
19307 The compiler outputs the higher order address byte of the external ram segment
19309 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19314 \begin_inset LatexCommand \ref{sub:MCS51-variants}
19318 ), therefore when using the External Stack option, this port
19322 be used by the application program.
19325 \begin_layout Subsection
19327 \begin_inset LatexCommand \index{Memory model}
19332 \begin_inset LatexCommand \index{DS390 memory model}
19339 \begin_layout Standard
19340 The only model supported is Flat 24
19341 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
19346 This generates code for the 24 bit contiguous addressing mode of the Dallas
19348 In this mode, up to four meg of external RAM or code space can be directly
19350 See the data sheets at www.dalsemi.com for further information on this part.
19355 that the compiler does not generate any code to place the processor into
19356 24 bitmode (although
19360 in the ds390 libraries will do that for you).
19366 \begin_inset LatexCommand \index{Tinibios (DS390)}
19370 , the boot loader or similar code must ensure that the processor is in 24
19371 bit contiguous addressing mode before calling the SDCC startup code.
19382 \begin_layout Standard
19393 option, variables will by default be placed into the XDATA segment.
19398 Segments may be placed anywhere in the 4 meg address space using the usual
19403 \begin_layout Standard
19413 Note that if any segments are located above 64K, the -r flag must be passed
19414 to the linker to generate the proper segment relocations, and the Intel
19415 HEX output format must be used.
19416 The -r flag can be passed to the linker by using the option
19420 on the SDCC command line.
19421 However, currently the linker can not handle code segments > 64k.
19424 \begin_layout Section
19426 \begin_inset LatexCommand \label{sec:Pragmas}
19431 \begin_inset LatexCommand \index{Pragmas}
19438 \begin_layout Standard
19439 SDCC supports the following #pragma directives:
19442 \begin_layout Itemize
19448 \begin_inset LatexCommand \index{\#pragma save}
19452 - this will save most current options to the save/restore stack.
19453 See #pragma\InsetSpace ~
19457 \begin_layout Itemize
19463 \begin_inset LatexCommand \index{\#pragma restore}
19467 - will restore saved options from the last save.
19468 saves & restores can be nested.
19469 SDCC uses a save/restore stack: save pushes current options to the stack,
19470 restore pulls current options from the stack.
19471 See #pragma\InsetSpace ~
19477 \begin_layout Itemize
19483 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19488 \begin_inset LatexCommand \index{function prologue}
19492 function1[,function2[,function3...]] - The compiler by default uses a caller
19493 saves convention for register saving across function calls, however this
19494 can cause unnecessary register pushing & popping
19495 \begin_inset LatexCommand \index{push/pop}
19499 when calling small functions from larger functions.
19500 This option can be used to switch off the register saving convention for
19501 the function names specified.
19502 The compiler will not save registers when calling these functions, extra
19503 code need to be manually inserted at the entry & exit for these functions
19504 to save & restore the registers used by these functions, this can SUBSTANTIALLY
19505 reduce code & improve run time performance of the generated code.
19506 In the future the compiler (with inter procedural analysis) may be able
19507 to determine the appropriate scheme to use for each function call.
19512 \begin_layout Standard
19521 -callee-saves command line option is used, the function names specified
19522 in #pragma\InsetSpace ~
19524 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19528 is appended to the list of functions specified in the command line.
19531 \begin_layout Itemize
19537 \begin_inset LatexCommand \index{\#pragma exclude}
19541 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19542 of pairs of push/pop
19543 \begin_inset LatexCommand \index{push/pop}
19552 \begin_inset LatexCommand \index{interrupt}
19565 The directive should be placed immediately before the ISR function definition
19566 and it affects ALL ISR functions following it.
19567 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
19568 exclude\InsetSpace ~
19570 \begin_inset LatexCommand \index{\#pragma exclude}
19575 See also the related keyword _naked
19576 \begin_inset LatexCommand \index{\_naked}
19581 \begin_inset LatexCommand \index{\_\_naked}
19588 \begin_layout Itemize
19594 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19598 - the compiler will not warn you anymore for obvious mistakes, you'r on
19602 \begin_layout Itemize
19608 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19612 - the compiler will not warn you anymore about warning number <nnnn>.
19615 \begin_layout Itemize
19621 \begin_inset LatexCommand \index{\#pragma nogcse}
19625 - will stop global common subexpression elimination.
19628 \begin_layout Itemize
19634 \begin_inset LatexCommand \index{\#pragma noinduction}
19638 - will stop loop induction optimizations.
19641 \begin_layout Itemize
19647 \begin_inset LatexCommand \index{\#pragma noinvariant}
19651 - will not do loop invariant optimizations.
19652 For more details see Loop Invariants in section
19653 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19660 \begin_layout Itemize
19666 \begin_inset LatexCommand \index{\#pragma noiv}
19670 - Do not generate interrupt
19671 \begin_inset LatexCommand \index{interrupt}
19676 \begin_inset LatexCommand \index{interrupt vector table}
19680 entries for all ISR functions defined after the pragma.
19681 This is useful in cases where the interrupt vector table must be defined
19682 manually, or when there is a secondary, manually defined interrupt vector
19684 for the autovector feature of the Cypress EZ-USB FX2).
19685 More elegantly this can be achieved by obmitting the optional interrupt
19686 number after the interrupt keyword, see section
19687 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19695 \begin_layout Itemize
19701 \begin_inset LatexCommand \index{\#pragma nojtbound}
19705 - will not generate code for boundary value checking, when switch statements
19706 are turned into jump-tables (dangerous).
19707 For more details see section
19708 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19715 \begin_layout Itemize
19721 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19725 - Will not do loop reversal optimization
19728 \begin_layout Itemize
19734 \begin_inset LatexCommand \index{\#pragma nooverlay}
19738 - the compiler will not overlay the parameters and local variables of a
19742 \begin_layout Itemize
19748 \begin_inset LatexCommand \index{\#pragma stackauto}
19756 \begin_layout Standard
19766 \begin_inset LatexCommand \index{-\/-stack-auto}
19771 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19775 Parameters and Local Variables.
19778 \begin_layout Itemize
19784 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19788 - The compiler will optimize code generation towards fast code, possibly
19789 at the expense of code size.
19790 Currently this has little effect.
19793 \begin_layout Itemize
19799 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19803 - The compiler will optimize code generation towards compact code, possibly
19804 at the expense of code speed.
19805 Currently this has little effect.
19808 \begin_layout Itemize
19814 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19818 - The compiler will attempt to generate code that is both compact and fast,
19819 as long as meeting one goal is not a detriment to the other (this is the
19824 \begin_layout Itemize
19830 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19834 - Generally follow the C89 standard, but allow SDCC features that conflict
19835 with the standard (default).
19838 \begin_layout Itemize
19844 \begin_inset LatexCommand \index{\#pragma std\_c89}
19848 - Follow the C89 standard and disable SDCC features that conflict with the
19852 \begin_layout Itemize
19858 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19862 - Generally follow the C99 standard, but allow SDCC features that conflict
19863 with the standard (incomplete support).
19866 \begin_layout Itemize
19872 \begin_inset LatexCommand \index{\#pragma std\_c99}
19876 - Follow the C99 standard and disable SDCC features that conflict with the
19877 standard (incomplete support).
19880 \begin_layout Itemize
19886 \begin_inset LatexCommand \index{\#pragma codeseg}
19890 - Use this name (max.
19891 8 characters) for the code segment.
19896 \begin_layout Standard
19908 \begin_layout Itemize
19914 \begin_inset LatexCommand \index{\#pragma constseg}
19918 - Use this name (max.
19919 8 characters) for the const segment.
19924 \begin_layout Standard
19936 \begin_layout Standard
19937 The preprocessor SDCPP
19938 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19942 supports the following #pragma directives:
19945 \begin_layout Itemize
19948 pedantic_parse_number
19951 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19955 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19956 parsed properly and the macro LO_B(3) gets expanded.
19958 Below is an example on how to use this pragma.
19961 Note: this functionality is not in conformance with standard!
19964 \begin_layout Verse
19967 #pragma pedantic_parse_number +
19968 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19976 #define LO_B(x) ((x) & 0xff)
19980 unsigned char foo(void)
19987 unsigned char c=0xfe-LO_B(3)
20002 \begin_layout Itemize
20008 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20012 (+ | -) - switch _asm _endasm block preprocessing on / off.
20014 You use this prama to define multilines of assembly code.
20015 This will prevent the preprocessor from changing the formating required
20017 Below is an example on how to use this pragma.
20020 \begin_layout Verse
20023 #pragma preproc_asm -
20024 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20030 #define MYDELAY _asm
20035 nop ;my assembly comment...
20049 #pragma preproc_asm
20080 \begin_layout Itemize
20086 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20090 (+ | -) - Allow "naked" hash in macro definition, for example:
20094 #define DIR_LO(x) #(x & 0xff)
20099 Below is an example on how to use this pragma.
20102 \begin_layout Verse
20105 #pragma preproc_asm +
20107 #pragma sdcc_hash +
20108 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20123 mov R6_B3, #(x & 0xff)
20130 mov R7_B3, #((x >> 8) & 0xff)
20154 \begin_layout Standard
20155 The pragma's are intended to be used to turn-on or off certain optimizations
20156 which might cause the compiler to generate extra stack / data space to
20157 store compiler generated temporary variables.
20158 This usually happens in large functions.
20159 Pragma directives should be used as shown in the following example, they
20160 are used to control options & optimizations for a given function; pragmas
20161 should be placed before and/or after a function, placing pragma's inside
20162 a function body could have unpredictable results.
20165 \begin_layout Verse
20169 \begin_inset LatexCommand \index{\#pragma save}
20180 /* save the current settings */
20183 \begin_inset LatexCommand \index{\#pragma nogcse}
20192 /* turnoff global subexpression elimination */
20194 #pragma noinduction
20195 \begin_inset LatexCommand \index{\#pragma noinduction}
20199 /* turn off induction optimizations */
20222 \begin_inset LatexCommand \index{\#pragma restore}
20226 /* turn the optimizations back on */
20229 \begin_layout Standard
20230 The compiler will generate a warning message when extra space is allocated.
20231 It is strongly recommended that the save and restore pragma's be used when
20232 changing options for a function.
20241 \begin_layout Section
20242 Defines Created by the Compiler
20245 \begin_layout Standard
20246 The compiler creates the following #defines
20247 \begin_inset LatexCommand \index{\#defines}
20252 \begin_inset LatexCommand \index{Defines created by the compiler}
20261 \begin_layout Standard
20262 \begin_inset Tabular
20263 <lyxtabular version="3" rows="11" columns="2">
20265 <column alignment="left" valignment="top" leftline="true" width="3in">
20266 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
20267 <row topline="true" bottomline="true">
20268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20271 \begin_layout Standard
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20282 \begin_layout Standard
20291 <row topline="true">
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20295 \begin_layout Standard
20297 \begin_inset LatexCommand \index{SDCC}
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20309 \begin_layout Standard
20311 Since version 2.5.6 the version number as an int (ex.
20318 <row topline="true">
20319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20322 \begin_layout Standard
20324 \begin_inset LatexCommand \index{SDCC\_mcs51}
20329 \begin_inset LatexCommand \index{SDCC\_ds390}
20334 \begin_inset LatexCommand \index{SDCC\_z80}
20343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20346 \begin_layout Standard
20347 depending on the model used (e.g.: -mds390)
20353 <row topline="true">
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_layout Standard
20359 \begin_inset LatexCommand \index{\_\_mcs51}
20364 \begin_inset LatexCommand \index{\_\_ds390}
20369 \begin_inset LatexCommand \index{\_\_hc08}
20374 \begin_inset LatexCommand \index{\_\_z80}
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20386 \begin_layout Standard
20387 depending on the model used (e.g.
20394 <row topline="true">
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20398 \begin_layout Standard
20400 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
20409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20412 \begin_layout Standard
20419 \begin_layout Standard
20436 <row topline="true">
20437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_layout Standard
20442 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20454 \begin_layout Standard
20461 \begin_layout Standard
20478 <row topline="true">
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_layout Standard
20484 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20496 \begin_layout Standard
20503 \begin_layout Standard
20520 <row topline="true">
20521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20524 \begin_layout Standard
20526 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20538 \begin_layout Standard
20545 \begin_layout Standard
20562 <row topline="true">
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20566 \begin_layout Standard
20568 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20580 \begin_layout Standard
20587 \begin_layout Standard
20604 <row topline="true">
20605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20608 \begin_layout Standard
20610 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20622 \begin_layout Standard
20633 <row topline="true" bottomline="true">
20634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20637 \begin_layout Standard
20639 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20651 \begin_layout Standard
20669 \begin_layout Chapter
20670 Notes on supported Processors
20673 \begin_layout Section
20675 \begin_inset LatexCommand \label{sub:MCS51-variants}
20680 \begin_inset LatexCommand \index{MCS51 variants}
20687 \begin_layout Standard
20688 MCS51 processors are available from many vendors and come in many different
20690 While they might differ considerably in respect to Special Function Registers
20691 the core MCS51 is usually not modified or is kept compatible.
20695 \begin_layout Subsection
20696 pdata access by SFR
20699 \begin_layout Standard
20700 With the upcome of devices with internal xdata and flash memory devices
20702 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20706 as dedicated I/O port is becoming more popular.
20707 Switching the high byte for pdata
20708 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20712 access which was formerly done by port P2 is then achieved by a Special
20714 \begin_inset LatexCommand \index{sfr}
20719 In well-established MCS51 tradition the address of this
20723 is where the chip designers decided to put it.
20724 Needless to say that they didn't agree on a common name either.
20725 So that the startup code can correctly initialize xdata variables, you
20726 should define an sfr with the name _XPAGE
20729 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20735 at the appropriate location if the default, port P2, is not used for this.
20739 \begin_layout Verse
20742 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
20745 \begin_layout Verse
20748 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20751 \begin_layout Verse
20754 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20757 \begin_layout Standard
20758 For more exotic implementations further customizations may be needed.
20760 \begin_inset LatexCommand \ref{sub:Startup-Code}
20764 for other possibilities.
20767 \begin_layout Subsection
20768 Other Features available by SFR
20771 \begin_layout Standard
20772 Some MCS51 variants offer features like Double DPTR
20773 \begin_inset LatexCommand \index{DPTR}
20777 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20778 These are currently not used for the MCS51 port.
20779 If you absolutely need them you can fall back to inline assembly or submit
20781 \begin_inset VSpace bigskip
20787 \begin_layout Section
20791 \begin_layout Standard
20793 \begin_inset LatexCommand \index{DS80C400}
20798 \begin_inset LatexCommand \index{DS400}
20802 microcontroller has a rich set of peripherals.
20803 In its built-in ROM library it includes functions to access some of the
20804 features, among them is a TCP stack with IP4 and IP6 support.
20805 Library headers (currently in beta status) and other files are provided
20809 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20815 \begin_inset VSpace bigskip
20821 \begin_layout Section
20822 The Z80 and gbz80 port
20825 \begin_layout Standard
20826 SDCC can target both the Zilog Z80
20827 \begin_inset LatexCommand \index{Z80}
20831 and the Nintendo Gameboy's Z80-like gbz80
20832 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20837 The Z80 port is passed through the same
20840 \begin_inset LatexCommand \index{Regression test}
20847 \begin_inset LatexCommand \ref{sec:Quality-control}
20851 ) as the MCS51 and DS390 ports, so floating point support, support for long
20852 variables and bitfield support is fine.
20853 See mailing lists and forums about interrupt routines.
20856 \begin_layout Standard
20857 As always, the code is the authoritative reference - see z80/ralloc.c and
20860 \begin_inset LatexCommand \index{Z80!stack}
20864 frame is similar to that generated by the IAR Z80 compiler.
20865 IX is used as the base pointer, HL and IY are used as a temporary registers,
20866 and BC and DE are available for holding variables.
20868 \begin_inset LatexCommand \index{Z80!return value}
20872 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20874 The gbz80 port use the same set of registers for the return values, but
20875 in a different order of significance: E (one byte), DE (two bytes), or
20877 \begin_inset VSpace bigskip
20883 \begin_layout Section
20887 \begin_layout Standard
20888 The port to the Freescale/Motorola HC08
20889 \begin_inset LatexCommand \index{HC08}
20893 family has been added in October 2003, and is still undergoing some basic
20895 The code generator is complete, but the register allocation is still quite
20897 Some of the SDCC's standard C library functions have embedded non-HC08
20898 inline assembly and so are not yet usable.
20901 \begin_layout Standard
20902 The HC08 port passes the regression test suite (see section
20903 \begin_inset LatexCommand \ref{sec:Quality-control}
20908 \begin_inset VSpace bigskip
20914 \begin_layout Standard
20920 \begin_layout Section
20924 \begin_layout Standard
20926 \begin_inset LatexCommand \index{PIC14}
20930 port still requires a major effort from the development community.
20931 However it can work for simple code.
20932 It passes its (smaller set of) regression tests
20933 \begin_inset LatexCommand \index{Regression test (PIC14)}
20939 sdcc/src/regression
20944 \begin_layout Subsection
20945 C code and 14bit PIC code page
20946 \begin_inset LatexCommand \index{code page (pic14)}
20951 \begin_inset LatexCommand \index{RAM bank (pic14)}
20958 \begin_layout Standard
20959 The linker organizes allocation for the code page and RAM banks.
20960 It does not have intimate knowledge of the code flow.
20961 It will put all the code section of a single asm file into a single code
20963 In order to make use of multiple code pages, separate asm files must be
20965 The compiler treats all functions of a single C file as being in the same
20966 code page unless it is non static.
20970 To get the best follow these guide lines:
20973 \begin_layout Enumerate
20974 Make local functions static, as non static functions require code page selection
20978 \begin_layout Enumerate
20979 For devices that have multiple code pages it is more efficient to use the
20980 same number of files as pages, i.e.
20981 for the 16F877 use 4 separate files and i.e.
20982 for the 16F874 use 2 separate files.
20983 This way the linker can put the code for each file into different code
20984 pages and there's less page selection overhead.
20987 \begin_layout Enumerate
20988 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20989 instruction set), use 'unsigned char' whereever possible instead of 'int'.
20992 \begin_layout Subsection
20993 Creating a device include file
20996 \begin_layout Standard
20997 For generating a device include file
20998 \begin_inset LatexCommand \index{PIC14!Header files}
21002 use the support perl script inc2h.pl kept in directory support/script.
21005 \begin_layout Subsection
21009 \begin_layout Standard
21010 For the interrupt function, use the keyword '__interrupt'
21011 \begin_inset LatexCommand \index{PIC14!interrupt}
21015 with level number of 0 (PIC14 only has 1 interrupt so this number is only
21016 there to avoid a syntax error - it ought to be fixed).
21020 \begin_layout Verse
21023 void Intr(void) __interrupt 0
21029 T0IF = 0; /* Clear timer interrupt */
21034 \begin_layout Subsection
21035 Linking and assembling
21038 \begin_layout Standard
21039 For assembling you can use either GPUTILS'
21040 \begin_inset LatexCommand \index{gputils (pic tools)}
21044 gpasm.exe or MPLAB's mpasmwin.exe.
21045 GPUTILS is available from
21046 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21051 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21052 If you use MPLAB and an interrupt function then the linker script file
21053 vectors section will need to be enlarged to link with mplink.
21064 \begin_layout Verse
21077 sdcc -S -V -mpic14 -p16F877 $<
21091 $(PRJ).hex: $(OBJS)
21102 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
21105 \begin_layout Standard
21113 \begin_layout Verse
21126 sdcc -S -V -mpic14 -p16F877 $<
21136 mpasmwin /q /o $*.asm
21140 $(PRJ).hex: $(OBJS)
21151 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
21154 \begin_layout Standard
21155 Please note that indentations within a
21159 have to be done with a tabulator character.
21162 \begin_layout Subsection
21163 Command-line options
21166 \begin_layout Standard
21167 Besides the switches common to all SDCC backends, the PIC14 port accepts
21168 the following options (for an updated list see sdcc -
21172 \begin_layout Standard
21185 \labelwidthstring 00.00.0000
21190 \begin_layout Standard
21200 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
21204 emit debug info in assembly output
21208 \labelwidthstring 00.00.0000
21213 \begin_layout Standard
21223 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
21227 disable (slightly faulty) optimization on pCode
21231 \labelwidthstring 00.00.0000
21236 \begin_layout Standard
21246 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
21250 sets the lowest address of the argument passing stack (defaults to a suitably
21251 large shared databank to reduce BANKSEL overhead)
21255 \labelwidthstring 00.00.0000
21260 \begin_layout Standard
21270 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
21274 sets the size if the argument passing stack (default: 16, minimum: 4)
21277 \begin_layout Subsection
21281 \begin_layout Subsubsection
21282 error: missing definition for symbol
21283 \begin_inset Quotes sld
21287 \begin_inset Quotes srd
21293 \begin_layout Standard
21294 The PIC14 port uses library routines to provide more complex operations
21295 like multiplication, division/modulus and (generic) pointer dereferencing.
21296 In order to add these routines to your project, you must link with PIC14's
21302 For single source file projects this is done automatically, more complex
21307 to the linker's arguments.
21308 Make sure you also add an include path for the library (using the -I switch
21312 \begin_layout Subsubsection
21313 Processor mismatch in file
21314 \begin_inset Quotes sld
21318 \begin_inset Quotes srd
21324 \begin_layout Standard
21325 This warning can usually be ignored due to the very good compatibility amongst
21327 \begin_inset LatexCommand \index{PIC14}
21334 \begin_layout Standard
21335 You might also consider recompiling the library for your specific device
21336 by changing the ARCH=p16f877 (default target) entry in
21338 device/lib/pic/Makefile.in
21342 device/lib/pic/Makefile
21344 to reflect your device.
21345 This might even improve performance for smaller devices as unneccesary
21346 BANKSELs migth be removed.
21349 \begin_layout Subsection
21353 \begin_layout Subsubsection
21357 \begin_layout Standard
21358 Currently, data can only be initialized if it resides in the source file
21364 Data in other source files will silently
21372 \begin_inset Marginal
21375 \begin_layout Standard
21387 \begin_layout Standard
21393 \begin_layout Section
21395 \begin_inset LatexCommand \index{PIC16}
21402 \begin_layout Standard
21404 \begin_inset LatexCommand \index{PIC16}
21408 port is the portion of SDCC that is responsible to produce code for the
21410 \begin_inset LatexCommand \index{Microchip}
21414 (TM) microcontrollers with 16 bit core.
21415 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
21416 Currently supported devices are:
21419 \begin_layout Standard
21421 \begin_inset Tabular
21422 <lyxtabular version="3" rows="4" columns="6">
21424 <column alignment="center" valignment="top" leftline="true" width="0">
21425 <column alignment="center" valignment="top" leftline="true" width="0">
21426 <column alignment="center" valignment="top" leftline="true" width="0">
21427 <column alignment="center" valignment="top" leftline="true" width="0">
21428 <column alignment="center" valignment="top" leftline="true" width="0">
21429 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21430 <row topline="true">
21431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21434 \begin_layout Standard
21440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21443 \begin_layout Standard
21449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21452 \begin_layout Standard
21458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21461 \begin_layout Standard
21467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21470 \begin_layout Standard
21476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21479 \begin_layout Standard
21486 <row topline="true">
21487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21490 \begin_layout Standard
21496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21499 \begin_layout Standard
21505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21508 \begin_layout Standard
21514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21517 \begin_layout Standard
21523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21526 \begin_layout Standard
21532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21535 \begin_layout Standard
21542 <row topline="true">
21543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21546 \begin_layout Standard
21552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21555 \begin_layout Standard
21561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21564 \begin_layout Standard
21570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21573 \begin_layout Standard
21579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21582 \begin_layout Standard
21588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21591 \begin_layout Standard
21598 <row topline="true" bottomline="true">
21599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21602 \begin_layout Standard
21608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21611 \begin_layout Standard
21617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21620 \begin_layout Standard
21626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21629 \begin_layout Standard
21635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21638 \begin_layout Standard
21644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21647 \begin_layout Standard
21661 \begin_layout Subsection
21665 \begin_layout Standard
21666 PIC16 port supports the standard command line arguments as supposed, with
21667 the exception of certain cases that will be mentioned in the following
21672 \labelwidthstring 00.00.0000
21677 \begin_layout Standard
21687 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21695 \begin_layout Standard
21708 \labelwidthstring 00.00.0000
21713 \begin_layout Standard
21723 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21727 All function arguments are passed on stack by default.
21730 There is no need to specify this in the command line.
21734 \labelwidthstring 00.00.0000
21739 \begin_layout Standard
21748 -fommit-frame-pointer
21749 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21753 Frame pointer will be omitted when the function uses no local variables.
21756 \begin_layout Subsection
21757 Port Specific Options
21758 \begin_inset LatexCommand \index{Options PIC16}
21765 \begin_layout Standard
21766 The port specific options appear after the global options in the sdcc --help
21770 \begin_layout Subsubsection
21774 \begin_layout Standard
21775 General options enable certain port features and optimizations.
21779 \labelwidthstring 00.00.0000
21784 \begin_layout Standard
21793 -pstack-model=[model] Used in conjuction with the command above.
21794 Defines the stack model to be used, valid stack models are :
21799 \labelwidthstring 00.00.0000
21804 Selects small stack model.
21805 8 bit stack and frame pointers.
21806 Supports 256 bytes stack size.
21810 \labelwidthstring 00.00.0000
21815 Selects large stack model.
21816 16 bit stack and frame pointers.
21817 Supports 65536 bytes stack size.
21822 \labelwidthstring 00.00.0000
21827 \begin_layout Standard
21836 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21837 unitialized data variables with [kword].
21838 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21842 \labelwidthstring 00.00.0000
21847 \begin_layout Standard
21856 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21857 Useful for bootloaders.
21861 \labelwidthstring 00.00.0000
21866 \begin_layout Standard
21875 -asm= sets the full path and name of an external assembler to call.
21879 \labelwidthstring 00.00.0000
21884 \begin_layout Standard
21893 -link= sets the full path and name of an external linker to call.
21897 \labelwidthstring 00.00.0000
21902 \begin_layout Standard
21912 \begin_inset LatexCommand \index{PIC16!MPLAB}
21916 compatibility option.
21917 Currently only suppresses special gpasm directives.
21920 \begin_layout Subsubsection
21921 Optimization Options
21925 \labelwidthstring 00.00.0000
21930 \begin_layout Standard
21939 -optimize-goto Try to use (conditional) BRA instead of GOTO
21943 \labelwidthstring 00.00.0000
21948 \begin_layout Standard
21957 -optimize-cmp Try to optimize some compares.
21961 \labelwidthstring 00.00.0000
21966 \begin_layout Standard
21975 -optimize-df Analyze the dataflow of the generated code and improve it.
21979 \labelwidthstring 00.00.0000
21984 \begin_layout Standard
21993 -obanksel=nn Set optimization level for inserting BANKSELs.
22000 \labelwidthstring 00.00.0000
22005 \labelwidthstring 00.00.0000
22006 1 checks previous used register and if it is the same then does not emit
22007 BANKSEL, accounts only for labels.
22011 \labelwidthstring 00.00.0000
22012 2 tries to check the location of (even different) symbols and removes BANKSELs
22013 if they are in the same bank.
22018 Important: There might be problems if the linker script has data sections
22019 across bank borders!
22023 \begin_layout Subsubsection
22028 \labelwidthstring 00.00.0000
22033 \begin_layout Standard
22042 -nodefaultlibs do not link default libraries when linking
22046 \labelwidthstring 00.00.0000
22051 \begin_layout Standard
22060 -no-crt Don't link the default run-time modules
22064 \labelwidthstring 00.00.0000
22069 \begin_layout Standard
22078 -use-crt= Use a custom run-time module instead of the defaults.
22081 \begin_layout Subsubsection
22085 \begin_layout Standard
22086 Debugging options enable extra debugging information in the output files.
22090 \labelwidthstring 00.00.0000
22095 \begin_layout Standard
22104 -debug-xtra Similar to -
22108 \begin_layout Standard
22118 \begin_inset LatexCommand \index{-\/-debug}
22122 , but dumps more information.
22126 \labelwidthstring 00.00.0000
22131 \begin_layout Standard
22140 -debug-ralloc Force register allocator to dump <source>.d file with debugging
22142 <source> is the name of the file compiled.
22146 \labelwidthstring 00.00.0000
22151 \begin_layout Standard
22160 -pcode-verbose Enable pcode debugging information in translation.
22164 \labelwidthstring 00.00.0000
22169 \begin_layout Standard
22178 -denable-peeps Force the usage of peepholes.
22183 \labelwidthstring 00.00.0000
22188 \begin_layout Standard
22197 -gstack Trace push/pops for stack pointer overflow
22201 \labelwidthstring 00.00.0000
22206 \begin_layout Standard
22215 -call-tree dump call tree in .calltree file
22218 \begin_layout Subsection
22219 Enviromental Variables
22222 \begin_layout Standard
22223 There is a number of enviromental variables that can be used when running
22224 SDCC to enable certain optimizations or force a specific program behaviour.
22225 these variables are primarily for debugging purposes so they can be enabled/dis
22229 \begin_layout Standard
22230 Currently there is only two such variables available:
22234 \labelwidthstring 00.00.0000
22235 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
22236 bitfields is optimized by directly loading FSR0 with the address of the
22237 bitfield structure.
22238 Normally SDCC will cast the bitfield structure to a bitfield pointer and
22240 This step saves data ram and code space for functions that perform heavy
22243 80 bytes of code space are saved when compiling malloc.c with this option).
22248 \labelwidthstring 00.00.0000
22249 NO_REG_OPT do not perform pCode registers optimization.
22250 This should be used for debugging purposes.
22251 In some where bugs in the pcode optimizer are found, users can benefit
22252 from temporarily disabling the optimizer until the bug is fixed.
22255 \begin_layout Subsection
22256 Preprocessor Macros
22259 \begin_layout Standard
22261 \begin_inset LatexCommand \index{PIC16}
22265 port defines the following preprocessor macros while translating a source.
22268 \begin_layout Standard
22270 \begin_inset Tabular
22271 <lyxtabular version="3" rows="6" columns="2">
22273 <column alignment="center" valignment="top" leftline="true" width="0">
22274 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22275 <row topline="true" bottomline="true">
22276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22279 \begin_layout Standard
22285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22288 \begin_layout Standard
22295 <row topline="true">
22296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22299 \begin_layout Standard
22305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22308 \begin_layout Standard
22309 Port identification
22315 <row topline="true">
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22319 \begin_layout Standard
22324 \begin_layout Standard
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22341 \begin_layout Standard
22342 Port identification (same as above)
22348 <row topline="true">
22349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22352 \begin_layout Standard
22358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22361 \begin_layout Standard
22362 MCU Identification.
22367 is the microcontrol identification number, i.e.
22374 <row topline="true">
22375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22378 \begin_layout Standard
22383 \begin_layout Standard
22397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22400 \begin_layout Standard
22401 MCU Identification (same as above)
22407 <row topline="true" bottomline="true">
22408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22411 \begin_layout Standard
22417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22420 \begin_layout Standard
22421 nnn = SMALL or LARGE respectively according to the stack model used
22434 \begin_layout Standard
22435 In addition the following macros are defined when calling assembler:
22438 \begin_layout Standard
22440 \begin_inset Tabular
22441 <lyxtabular version="3" rows="4" columns="2">
22443 <column alignment="center" valignment="top" leftline="true" width="0">
22444 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22445 <row topline="true" bottomline="true">
22446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22449 \begin_layout Standard
22455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22458 \begin_layout Standard
22465 <row topline="true">
22466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22469 \begin_layout Standard
22475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22478 \begin_layout Standard
22479 MCU Identification.
22484 is the microcontrol identification number, i.e.
22491 <row topline="true">
22492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22495 \begin_layout Standard
22501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22504 \begin_layout Standard
22505 nnn = SMALL or LARGE respectively according to the memory model used for
22512 <row topline="true" bottomline="true">
22513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22516 \begin_layout Standard
22522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22525 \begin_layout Standard
22526 nnn = SMALL or LARGE respectively according to the stack model used
22539 \begin_layout Subsection
22543 \begin_layout Standard
22545 \begin_inset LatexCommand \index{PIC16}
22549 port uses the following directories for searching header files and libraries.
22552 \begin_layout Standard
22554 \begin_inset Tabular
22555 <lyxtabular version="3" rows="3" columns="4">
22557 <column alignment="center" valignment="top" leftline="true" width="0">
22558 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22559 <column alignment="center" valignment="top" width="0">
22560 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22561 <row topline="true" bottomline="true">
22562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22565 \begin_layout Standard
22571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22574 \begin_layout Standard
22580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22583 \begin_layout Standard
22589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22592 \begin_layout Standard
22599 <row topline="true">
22600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22603 \begin_layout Standard
22604 PREFIX/sdcc/include/pic16
22609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22612 \begin_layout Standard
22613 PIC16 specific headers
22618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22621 \begin_layout Standard
22627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22630 \begin_layout Standard
22637 <row topline="true" bottomline="true">
22638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22641 \begin_layout Standard
22642 PREFIX/sdcc/lib/pic16
22647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22650 \begin_layout Standard
22651 PIC16 specific libraries
22656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22659 \begin_layout Standard
22665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22668 \begin_layout Standard
22682 \begin_layout Subsection
22684 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22691 \begin_layout Standard
22693 \begin_inset LatexCommand \index{PIC16}
22697 port currently supports the following pragmas:
22701 \labelwidthstring 00.00.0000
22703 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22708 \begin_inset LatexCommand \index{PIC16!stack}
22712 forces the code generator to initialize the stack & frame pointers at a
22714 This is an adhoc solution for cases where no STACK directive is available
22715 in the linker script or gplink is not instructed to create a stack section.
22718 stack pragma should be used only once in a project.
22719 Multiple pragmas may result in indeterminate behaviour of the program.
22723 \begin_layout Standard
22724 The old format (ie.
22725 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22726 cross page boundaries (or even exceed the available data RAM) and crash
22728 Make sure that stack does not cross page boundaries when using the SMALL
22736 The format is as follows:
22739 \begin_layout LyX-Code
22740 #pragma stack bottom_address [stack_size]
22743 \begin_layout Standard
22748 is the lower bound of the stack section.
22749 The stack pointer initially will point at address (bottom_address+stack_size-1).
22752 \begin_layout LyX-Code
22756 \begin_layout LyX-Code
22760 \begin_layout LyX-Code
22761 /* initializes stack of 100 bytes at RAM address 0x200 */
22764 \begin_layout LyX-Code
22765 #pragma stack 0x200 100
22768 \begin_layout Standard
22769 If the stack_size field is omitted then a stack is created with the default
22771 This size might be enough for most programs, but its not enough for operations
22772 with deep function nesting or excessive stack usage.
22776 \labelwidthstring 00.00.0000
22778 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22782 place a function symbol at static FLASH address
22785 \begin_layout LyX-Code
22789 \begin_layout LyX-Code
22793 \begin_layout LyX-Code
22794 /* place function test_func at 0x4000 */
22797 \begin_layout LyX-Code
22798 #pragma code test_func 0x4000
22801 \begin_layout LyX-Code
22806 \labelwidthstring 00.00.0000
22807 library instructs the linker to use a library module.
22812 \begin_layout LyX-Code
22813 #pragma library module_name
22816 \begin_layout Standard
22821 can be any library or object file (including its path).
22822 Note that there are four reserved keywords which have special meaning.
22826 \begin_layout Standard
22828 \begin_inset Tabular
22829 <lyxtabular version="3" rows="6" columns="3">
22831 <column alignment="center" valignment="top" leftline="true" width="0">
22832 <column alignment="block" valignment="top" leftline="true" width="20page%">
22833 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22834 <row topline="true" bottomline="true">
22835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22838 \begin_layout Standard
22844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22847 \begin_layout Standard
22853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22856 \begin_layout Standard
22863 <row topline="true">
22864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22867 \begin_layout Standard
22875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22878 \begin_layout Standard
22879 ignore all library pragmas
22884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22887 \begin_layout Standard
22896 <row topline="true">
22897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22900 \begin_layout Standard
22908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22911 \begin_layout Standard
22917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22920 \begin_layout Standard
22931 <row topline="true">
22932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22935 \begin_layout Standard
22943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22946 \begin_layout Standard
22947 link the Math libarary
22952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22955 \begin_layout Standard
22966 <row topline="true">
22967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22970 \begin_layout Standard
22978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22981 \begin_layout Standard
22982 link the I/O library
22987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22990 \begin_layout Standard
23001 <row topline="true" bottomline="true">
23002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23005 \begin_layout Standard
23013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23016 \begin_layout Standard
23017 link the debug library
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23025 \begin_layout Standard
23042 * is the device number, i.e.
23043 452 for PIC18F452 MCU.
23046 \begin_layout Standard
23047 This feature allows for linking with specific libraries withoug having to
23048 explicit name them in the command line.
23053 keyword will reject all modules specified by the library pragma.
23057 \labelwidthstring 00.00.0000
23058 udata pragma udata instructs the compiler to emit code so that linker will
23059 place a variable at a specific memory bank
23062 \begin_layout LyX-Code
23066 \begin_layout LyX-Code
23070 \begin_layout LyX-Code
23071 /* places variable foo at bank2 */
23074 \begin_layout LyX-Code
23075 #pragma udata bank2 foo
23078 \begin_layout LyX-Code
23082 \begin_layout Standard
23083 In order for this pragma to work extra SECTION directives should be added
23084 in the .lkr script.
23085 In the following example a sample .lkr file is shown:
23088 \begin_layout LyX-Code
23092 \begin_layout LyX-Code
23093 // Sample linker script for the PIC18F452 processor
23096 \begin_layout LyX-Code
23100 \begin_layout LyX-Code
23101 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
23104 \begin_layout LyX-Code
23105 CODEPAGE NAME=page START=0x2A END=0x7FFF
23108 \begin_layout LyX-Code
23109 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
23112 \begin_layout LyX-Code
23113 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
23116 \begin_layout LyX-Code
23117 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
23120 \begin_layout LyX-Code
23121 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
23124 \begin_layout LyX-Code
23125 ACCESSBANK NAME=accessram START=0x0 END=0x7F
23128 \begin_layout LyX-Code
23132 \begin_layout LyX-Code
23133 DATABANK NAME=gpr0 START=0x80 END=0xFF
23136 \begin_layout LyX-Code
23137 DATABANK NAME=gpr1 START=0x100 END=0x1FF
23140 \begin_layout LyX-Code
23141 DATABANK NAME=gpr2 START=0x200 END=0x2FF
23144 \begin_layout LyX-Code
23145 DATABANK NAME=gpr3 START=0x300 END=0x3FF
23148 \begin_layout LyX-Code
23149 DATABANK NAME=gpr4 START=0x400 END=0x4FF
23152 \begin_layout LyX-Code
23153 DATABANK NAME=gpr5 START=0x500 END=0x5FF
23156 \begin_layout LyX-Code
23157 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
23160 \begin_layout LyX-Code
23164 \begin_layout LyX-Code
23165 SECTION NAME=CONFIG ROM=config
23168 \begin_layout LyX-Code
23172 \begin_layout LyX-Code
23173 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
23176 \begin_layout LyX-Code
23177 SECTION NAME=bank1 RAM=gpr1 # should be added to link
23180 \begin_layout LyX-Code
23181 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
23184 \begin_layout LyX-Code
23185 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
23188 \begin_layout LyX-Code
23189 SECTION NAME=bank4 RAM=gpr4
23192 \begin_layout LyX-Code
23193 SECTION NAME=bank5 RAM=gpr5
23196 \begin_layout Standard
23197 The linker will recognise the section name set in the pragma statement and
23198 will position the variable at the memory bank set with the RAM field at
23199 the SECTION line in the linker script file.
23202 \begin_layout Subsection
23204 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
23211 \begin_layout Standard
23212 There is one main header file
23213 \begin_inset LatexCommand \index{PIC16!Header files}
23217 that can be included to the source files using the pic16
23218 \begin_inset LatexCommand \index{PIC16}
23228 This header file contains the definitions for the processor special registers,
23229 so it is necessary if the source accesses them.
23230 It can be included by adding the following line in the beginning of the
23234 \begin_layout LyX-Code
23235 #include <pic18fregs.h>
23238 \begin_layout Standard
23239 The specific microcontroller is selected within the pic18fregs.h automatically,
23240 so the same source can be used with a variety of devices.
23243 \begin_layout Subsection
23247 \begin_layout Standard
23249 \begin_inset LatexCommand \index{PIC16!Libraries}
23254 \begin_inset LatexCommand \index{PIC16}
23258 port depends on are the microcontroller device libraries which contain
23259 the symbol definitions for the microcontroller special function registers.
23260 These libraries have the format pic18fxxxx.lib, where
23264 is the microcontroller identification number.
23265 The specific library is selected automatically by the compiler at link
23266 stage according to the selected device.
23269 \begin_layout Standard
23270 Libraries are created with gplib which is part of the gputils package
23271 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23278 \begin_layout Subsubsection*
23279 Building the libraries
23282 \begin_layout Standard
23283 Before using SDCC/pic16 there are some libraries that need to be compiled.
23284 This process is not done automatically by SDCC since not all users use
23285 SDCC for pic16 projects.
23286 So each user should compile the libraries separately.
23289 \begin_layout Standard
23290 The steps to compile the pic16 libraries under Linux are:
23293 \begin_layout LyX-Code
23294 cd device/lib/pic16
23297 \begin_layout LyX-Code
23301 \begin_layout LyX-Code
23305 \begin_layout LyX-Code
23309 \begin_layout LyX-Code
23313 \begin_layout LyX-Code
23314 su -c 'make install' # install the libraries, you need the root password
23317 \begin_layout Standard
23318 If you need to install the headers too, do:
23321 \begin_layout LyX-Code
23325 \begin_layout LyX-Code
23326 su -c 'make install' # install the headers, you need the root password
23329 \begin_layout Standard
23330 There exist a special target to build the I/O libraries.
23331 This target is not automatically build because it will build the I/O library
23337 This way building will take quite a lot of time.
23338 Users are advised to edit the
23340 device/lib/pic16/pics.build
23342 file and then execute:
23345 \begin_layout LyX-Code
23349 \begin_layout Subsection
23353 \begin_layout Standard
23354 The following memory models are supported by the PIC16 port:
23357 \begin_layout Itemize
23361 \begin_layout Itemize
23365 \begin_layout Standard
23366 Memory model affects the default size of pointers within the source.
23367 The sizes are shown in the next table:
23370 \begin_layout Standard
23372 \begin_inset Tabular
23373 <lyxtabular version="3" rows="3" columns="3">
23375 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23376 <column alignment="center" valignment="top" leftline="true" width="0">
23377 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23378 <row topline="true" bottomline="true">
23379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23382 \begin_layout Standard
23383 Pointer sizes according to memory model
23388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23391 \begin_layout Standard
23397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23400 \begin_layout Standard
23407 <row topline="true" bottomline="true">
23408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23411 \begin_layout Standard
23417 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23420 \begin_layout Standard
23426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23429 \begin_layout Standard
23436 <row topline="true" bottomline="true">
23437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23440 \begin_layout Standard
23446 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
23449 \begin_layout Standard
23455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23458 \begin_layout Standard
23472 \begin_layout Standard
23473 It is advisable that all sources within a project are compiled with the
23475 If one wants to override the default memory model, this can be done by
23476 declaring a pointer as
23485 Far selects large memory model's pointers, while near selects small memory
23489 \begin_layout Standard
23490 The standard device libraries (see
23491 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
23495 ) contain no reference to pointers, so they can be used with both memory
23499 \begin_layout Subsection
23503 \begin_layout Standard
23505 \begin_inset LatexCommand \index{PIC16!stack}
23509 implementation for the PIC16 port uses two indirect registers, FSR1 and
23514 \labelwidthstring 00.00.0000
23515 FSR1 is assigned as stack pointer
23519 \labelwidthstring 00.00.0000
23520 FSR2 is assigned as frame pointer
23523 \begin_layout Standard
23524 The following stack models are supported by the PIC16 port
23527 \begin_layout Itemize
23535 \begin_layout Itemize
23543 \begin_layout Standard
23548 model means that only the FSRxL byte is used to access stack and frame,
23555 uses both FSRxL and FSRxH registers.
23556 The following table shows the stack/frame pointers sizes according to stack
23557 model and the maximum space they can address:
23560 \begin_layout Standard
23562 \begin_inset Tabular
23563 <lyxtabular version="3" rows="3" columns="3">
23565 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23566 <column alignment="center" valignment="top" leftline="true" width="0">
23567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23568 <row topline="true" bottomline="true">
23569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23572 \begin_layout Standard
23573 Stack & Frame pointer sizes according to stack model
23578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23581 \begin_layout Standard
23587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23590 \begin_layout Standard
23597 <row topline="true">
23598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23601 \begin_layout Standard
23607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23610 \begin_layout Standard
23616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23619 \begin_layout Standard
23626 <row topline="true" bottomline="true">
23627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23630 \begin_layout Standard
23636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23639 \begin_layout Standard
23645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23648 \begin_layout Standard
23662 \begin_layout Standard
23667 stack model is currently not working properly throughout the code generator.
23668 So its use is not advised.
23669 Also there are some other points that need special care:
23674 \begin_layout Enumerate
23675 Do not create stack sections with size more than one physical bank (that
23679 \begin_layout Enumerate
23680 Stack sections should no cross physical bank limits (i.e.
23681 #pragma stack 0x50 0x100)
23684 \begin_layout Standard
23685 These limitations are caused by the fact that only FSRxL is modified when
23686 using SMALL stack model, so no more than 256 bytes of stack can be used.
23687 This problem will disappear after LARGE model is fully implemented.
23690 \begin_layout Subsection
23694 \begin_layout Standard
23695 In addition to the standard SDCC function keywords, PIC16
23696 \begin_inset LatexCommand \index{PIC16}
23700 port makes available two more:
23704 \labelwidthstring 00.00.0000
23706 \begin_inset LatexCommand \index{PIC16!wparam}
23710 Use the WREG to pass one byte of the first function argument.
23711 This improves speed but you may not use this for functions with arguments
23712 that are called via function pointers, otherwise the first byte of the
23713 first parameter will get lost.
23717 \begin_layout LyX-Code
23718 void func_wparam(int a) wparam
23721 \begin_layout LyX-Code
23725 \begin_layout LyX-Code
23726 /* WREG hold the lower part of a */
23729 \begin_layout LyX-Code
23730 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
23734 \begin_layout LyX-Code
23738 \begin_layout LyX-Code
23743 \labelwidthstring 00.00.0000
23745 \begin_inset LatexCommand \index{PIC16!shadowregs}
23749 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
23750 hardware shadow registers which hold the values of WREG, STATUS and BSR
23752 This can be done by adding the keyword
23760 keyword in the function's header.
23763 \begin_layout LyX-Code
23764 void isr_shadow(void) shadowregs interrupt 1
23767 \begin_layout LyX-Code
23771 \begin_layout LyX-Code
23775 \begin_layout LyX-Code
23779 \begin_layout Standard
23784 instructs the code generator not to store/restore WREG, STATUS, BSR when
23785 entering/exiting the ISR.
23788 \begin_layout Subsection
23789 Function return values
23792 \begin_layout Standard
23793 Return values from functions are placed to the appropriate registers following
23794 a modified Microchip policy optimized for SDCC.
23795 The following table shows these registers:
23798 \begin_layout Standard
23800 \begin_inset Tabular
23801 <lyxtabular version="3" rows="6" columns="2">
23803 <column alignment="center" valignment="top" leftline="true" width="0">
23804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23805 <row topline="true" bottomline="true">
23806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23809 \begin_layout Standard
23815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23818 \begin_layout Standard
23819 destination register
23825 <row topline="true">
23826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23829 \begin_layout Standard
23835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23838 \begin_layout Standard
23845 <row topline="true">
23846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23849 \begin_layout Standard
23855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23858 \begin_layout Standard
23865 <row topline="true">
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23869 \begin_layout Standard
23875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23878 \begin_layout Standard
23885 <row topline="true">
23886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23889 \begin_layout Standard
23895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23898 \begin_layout Standard
23899 FSR0L:PRODH:PRODL:WREG
23905 <row topline="true" bottomline="true">
23906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23909 \begin_layout Standard
23915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23918 \begin_layout Standard
23919 on stack, FSR0 points to the beginning
23932 \begin_layout Subsection
23936 \begin_layout Standard
23938 \begin_inset LatexCommand \index{PIC16!interrupt}
23942 service routine (ISR) is declared using the
23949 \begin_layout LyX-Code
23950 void isr(void) interrupt
23955 \begin_layout LyX-Code
23959 \begin_layout LyX-Code
23963 \begin_layout LyX-Code
23967 \begin_layout Standard
23972 is the interrupt number, which for PIC18F devices can be:
23975 \begin_layout Standard
23977 \begin_inset Tabular
23978 <lyxtabular version="3" rows="4" columns="3">
23980 <column alignment="center" valignment="top" leftline="true" width="0">
23981 <column alignment="center" valignment="top" leftline="true" width="0">
23982 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23983 <row topline="true" bottomline="true">
23984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23987 \begin_layout Standard
23995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23998 \begin_layout Standard
24004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24007 \begin_layout Standard
24008 Interrupt Vector Address
24014 <row topline="true">
24015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24018 \begin_layout Standard
24024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24027 \begin_layout Standard
24033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24036 \begin_layout Standard
24043 <row topline="true">
24044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24047 \begin_layout Standard
24062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24065 \begin_layout Standard
24075 HIGH priority interrupts
24080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24083 \begin_layout Standard
24090 <row topline="true" bottomline="true">
24091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24094 \begin_layout Standard
24100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24103 \begin_layout Standard
24104 LOW priority interrupts
24109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24112 \begin_layout Standard
24126 \begin_layout Standard
24127 When generating assembly code for ISR the code generator places a
24133 Interrupt Vector Address
24135 which points at the genetated ISR.
24136 This single GOTO instruction is part of an automatically generated
24138 interrupt entry point
24141 The actuall ISR code is placed as normally would in the code space.
24142 Upon interrupt request, the GOTO instruction is executed which jumps to
24144 When declaring interrupt functions as _naked this GOTO instruction is
24149 The whole interrupt functions is therefore placed at the Interrupt Vector
24150 Address of the specific interrupt.
24151 This is not a problem for the LOW priority interrupts, but it is a problem
24152 for the RESET and the HIGH priority interrupts because code may be written
24153 at the next interrupt´s vector address and cause undeterminate program
24154 behaviour if that interrupt is raised.
24158 \begin_layout Standard
24159 This is not a problem when
24162 \begin_layout Enumerate
24163 this is a HIGH interrupt ISR and LOW interrupts are
24170 \begin_layout Enumerate
24171 when the ISR is small enough not to reach the next interrupt´s vector address.
24179 \begin_layout Standard
24184 is possible to be omitted.
24185 This way a function is generated similar to an ISR, but it is not assigned
24189 \begin_layout Standard
24190 When entering an interrupt, currently the PIC16
24191 \begin_inset LatexCommand \index{PIC16}
24195 port automatically saves the following registers:
24198 \begin_layout Itemize
24202 \begin_layout Itemize
24206 \begin_layout Itemize
24210 \begin_layout Itemize
24211 PROD (PRODL and PRODH)
24214 \begin_layout Itemize
24215 FSR0 (FSR0L and FSR0H)
24218 \begin_layout Standard
24219 These registers are restored upon return from the interrupt routine.
24223 \begin_layout Standard
24224 NOTE that when the _naked attribute is specified for an interrupt routine,
24225 then NO registers are stored or restored.
24233 \begin_layout Subsection
24237 \begin_layout Standard
24238 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
24239 There are 3 types of generic pointers currently implemented data, code
24240 and eeprom pointers.
24241 They are differentiated by the value of the 7th and 6th bits of the upper
24245 \begin_layout Standard
24247 \begin_inset Tabular
24248 <lyxtabular version="3" rows="5" columns="5">
24250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24251 <column alignment="center" valignment="top" width="0">
24252 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24253 <column alignment="center" valignment="top" width="0">
24254 <column alignment="left" valignment="top" rightline="true" width="0">
24255 <row topline="true" bottomline="true">
24256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24259 \begin_layout Standard
24265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24268 \begin_layout Standard
24274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24277 \begin_layout Standard
24283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24286 \begin_layout Standard
24287 rest of the pointer
24292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24295 \begin_layout Standard
24302 <row topline="true" bottomline="true">
24303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24306 \begin_layout Standard
24312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24315 \begin_layout Standard
24321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24324 \begin_layout Standard
24330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24333 \begin_layout Standard
24338 uuuuuu uuuuxxxx xxxxxxxx
24343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24346 \begin_layout Standard
24347 a 12-bit data pointer in data RAM memory
24353 <row bottomline="true">
24354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24357 \begin_layout Standard
24363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24366 \begin_layout Standard
24372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24375 \begin_layout Standard
24381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24384 \begin_layout Standard
24389 uxxxxx xxxxxxxx xxxxxxxx
24394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24397 \begin_layout Standard
24398 a 21-bit code pointer in FLASH memory
24404 <row bottomline="true">
24405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24408 \begin_layout Standard
24414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24417 \begin_layout Standard
24423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24426 \begin_layout Standard
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24435 \begin_layout Standard
24440 uuuuuu uuuuuuxx xxxxxxxx
24445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24448 \begin_layout Standard
24449 a 10-bit eeprom pointer in EEPROM memory
24455 <row bottomline="true">
24456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24459 \begin_layout Standard
24465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24468 \begin_layout Standard
24474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24477 \begin_layout Standard
24483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24486 \begin_layout Standard
24491 xxxxxx xxxxxxxx xxxxxxxx
24496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24499 \begin_layout Standard
24500 unimplemented pointer type
24513 \begin_layout Standard
24514 Generic pointer are read and written with a set of library functions which
24515 read/write 1, 2, 3, 4 bytes.
24518 \begin_layout Subsection
24522 \begin_layout Subsubsection
24523 Standard I/O Streams
24526 \begin_layout Standard
24531 the type FILE is defined as:
24534 \begin_layout LyX-Code
24535 typedef char * FILE;
24538 \begin_layout Standard
24539 This type is the stream type implemented I/O in the PIC18F devices.
24540 Also the standard input and output streams are declared in stdio.h:
24543 \begin_layout LyX-Code
24544 extern FILE * stdin;
24547 \begin_layout LyX-Code
24548 extern FILE * stdout;
24551 \begin_layout Standard
24552 The FILE type is actually a generic pointer which defines one more type
24553 of generic pointers, the
24558 This new type has the format:
24561 \begin_layout Standard
24563 \begin_inset Tabular
24564 <lyxtabular version="3" rows="2" columns="7">
24566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24567 <column alignment="center" valignment="top" width="0">
24568 <column alignment="center" valignment="top" leftline="true" width="0">
24569 <column alignment="center" valignment="top" leftline="true" width="0">
24570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24571 <column alignment="center" valignment="top" width="0">
24572 <column alignment="left" valignment="top" rightline="true" width="0">
24573 <row topline="true" bottomline="true">
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24577 \begin_layout Standard
24583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24586 \begin_layout Standard
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24595 \begin_layout Standard
24601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24604 \begin_layout Standard
24610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24613 \begin_layout Standard
24619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24622 \begin_layout Standard
24623 rest of the pointer
24628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24631 \begin_layout Standard
24638 <row topline="true" bottomline="true">
24639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24642 \begin_layout Standard
24648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24651 \begin_layout Standard
24657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24660 \begin_layout Standard
24666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
24684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24687 \begin_layout Standard
24697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24700 \begin_layout Standard
24701 upper byte high nubble is 0x2n, the rest are zeroes
24714 \begin_layout Standard
24715 Currently implemented there are 3 types of streams defined:
24718 \begin_layout Standard
24720 \begin_inset Tabular
24721 <lyxtabular version="3" rows="4" columns="4">
24723 <column alignment="center" valignment="top" leftline="true" width="0">
24724 <column alignment="center" valignment="top" leftline="true" width="0">
24725 <column alignment="center" valignment="top" leftline="true" width="0">
24726 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24727 <row topline="true" bottomline="true">
24728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24731 \begin_layout Standard
24737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24740 \begin_layout Standard
24746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24749 \begin_layout Standard
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24758 \begin_layout Standard
24765 <row topline="true">
24766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24769 \begin_layout Standard
24775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24778 \begin_layout Standard
24786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24789 \begin_layout Standard
24795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24798 \begin_layout Standard
24799 Writes/Reads characters via the USART peripheral
24805 <row topline="true">
24806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24809 \begin_layout Standard
24815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24818 \begin_layout Standard
24826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24829 \begin_layout Standard
24835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24838 \begin_layout Standard
24839 Writes/Reads characters via the MSSP peripheral
24845 <row topline="true" bottomline="true">
24846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24849 \begin_layout Standard
24855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24858 \begin_layout Standard
24866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24869 \begin_layout Standard
24875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24878 \begin_layout Standard
24879 Writes/Reads characters via used defined functions
24892 \begin_layout Standard
24893 The stream identifiers are declared as macros in the stdio.h header.
24896 \begin_layout Standard
24897 In the libc library there exist the functions that are used to write to
24898 each of the above streams.
24903 \labelwidthstring 00.00.0000
24908 \begin_layout Standard
24917 _stream_usart_putchar writes a character at the USART stream
24921 \labelwidthstring 00.00.0000
24926 \begin_layout Standard
24935 _stream_mssp_putchar writes a character at the MSSP stream
24939 \labelwidthstring 00.00.0000
24940 putchar dummy function.
24941 This writes a character to a user specified manner.
24944 \begin_layout Standard
24945 In order to increase performance
24949 is declared in stdio.h as having its parameter in WREG (it has the wparam
24951 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24952 in a user-friendly way.
24957 is the name of the variable that holds the character to print.
24958 An example follows:
24961 \begin_layout LyX-Code
24962 #include <pic18fregs.h>
24971 \begin_layout LyX-Code
24975 \begin_layout LyX-Code
24976 PORTA = c; /* dump character c to PORTA */
24979 \begin_layout LyX-Code
24987 \begin_layout LyX-Code
24991 \begin_layout LyX-Code
24992 stdout = STREAM_USER; /* this is not necessary, since stdout points
24995 \begin_layout LyX-Code
24996 * by default to STREAM_USER */
24999 \begin_layout LyX-Code
25000 printf (¨This is a printf test
25005 \begin_layout LyX-Code
25009 \begin_layout LyX-Code
25013 \begin_layout Subsubsection
25017 \begin_layout Standard
25018 PIC16 contains an implementation of the printf-family of functions.
25019 There exist the following functions:
25022 \begin_layout LyX-Code
25023 extern unsigned int sprintf(char *buf, char *fmt, ...);
25026 \begin_layout LyX-Code
25027 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25030 \begin_layout LyX-Code
25034 \begin_layout LyX-Code
25035 extern unsigned int printf(char *fmt, ...);
25038 \begin_layout LyX-Code
25039 extern unsigned int vprintf(char *fmt, va_lista ap);
25042 \begin_layout LyX-Code
25046 \begin_layout LyX-Code
25047 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25050 \begin_layout LyX-Code
25051 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25054 \begin_layout Standard
25055 For sprintf and vsprintf
25059 should normally be a data pointer where the resulting string will be placed.
25060 No range checking is done so the user should allocate the necessery buffer.
25061 For fprintf and vfprintf
25065 should be a stream pointer (i.e.
25066 stdout, STREAM_MSSP, etc...).
25069 \begin_layout Subsubsection
25073 \begin_layout Standard
25074 The PIC18F family of microcontrollers supports a number of interrupt sources.
25075 A list of these interrupts is shown in the following table:
25078 \begin_layout Standard
25080 \begin_inset Tabular
25081 <lyxtabular version="3" rows="11" columns="4">
25083 <column alignment="left" valignment="top" leftline="true" width="0">
25084 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25085 <column alignment="left" valignment="top" leftline="true" width="0">
25086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25087 <row topline="true" bottomline="true">
25088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25091 \begin_layout Standard
25097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25100 \begin_layout Standard
25106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25109 \begin_layout Standard
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25118 \begin_layout Standard
25125 <row topline="true">
25126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25129 \begin_layout Standard
25135 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25138 \begin_layout Standard
25139 PORTB change interrupt
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25147 \begin_layout Standard
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25156 \begin_layout Standard
25157 EEPROM/FLASH write complete interrupt
25163 <row topline="true">
25164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25167 \begin_layout Standard
25173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25176 \begin_layout Standard
25177 INT0 external interrupt
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25185 \begin_layout Standard
25191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25194 \begin_layout Standard
25195 Bus collision interrupt
25201 <row topline="true">
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25205 \begin_layout Standard
25211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25214 \begin_layout Standard
25215 INT1 external interrupt
25220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25223 \begin_layout Standard
25229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25232 \begin_layout Standard
25233 Low voltage detect interrupt
25239 <row topline="true">
25240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25243 \begin_layout Standard
25249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25252 \begin_layout Standard
25253 INT2 external interrupt
25258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25261 \begin_layout Standard
25267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25270 \begin_layout Standard
25271 Parallel slave port interrupt
25277 <row topline="true">
25278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25281 \begin_layout Standard
25287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25290 \begin_layout Standard
25291 CCP1 module interrupt
25296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25299 \begin_layout Standard
25305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25308 \begin_layout Standard
25309 AD convertion complete interrupt
25315 <row topline="true">
25316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25319 \begin_layout Standard
25325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25328 \begin_layout Standard
25329 CCP2 module interrupt
25334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25337 \begin_layout Standard
25343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25346 \begin_layout Standard
25347 USART receive interrupt
25353 <row topline="true">
25354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25357 \begin_layout Standard
25363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25366 \begin_layout Standard
25367 TMR0 overflow interrupt
25372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25375 \begin_layout Standard
25381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25384 \begin_layout Standard
25385 USART transmit interrupt
25391 <row topline="true">
25392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25395 \begin_layout Standard
25401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25404 \begin_layout Standard
25405 TMR1 overflow interrupt
25410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25413 \begin_layout Standard
25419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25422 \begin_layout Standard
25423 SSP receive/transmit interrupt
25429 <row topline="true">
25430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25433 \begin_layout Standard
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25442 \begin_layout Standard
25443 TMR2 matches PR2 interrupt
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25451 \begin_layout Standard
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25460 \begin_layout Standard
25467 <row topline="true" bottomline="true">
25468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25471 \begin_layout Standard
25477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25480 \begin_layout Standard
25481 TMR3 overflow interrupt
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25489 \begin_layout Standard
25495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25498 \begin_layout Standard
25512 \begin_layout Standard
25513 The prototypes for these names are defined in the header file
25520 \begin_layout Standard
25521 In order to simplify signal handling, a number of macros is provided:
25525 \labelwidthstring 00.00.0000
25526 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
25527 high priority interrupts.
25532 is the function name to use.
25536 \labelwidthstring 00.00.0000
25537 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
25538 low priority interrupt.
25543 is the function name to use.
25547 \labelwidthstring 00.00.0000
25548 DEF_HANDLER(sig,handler) define a handler for signal
25554 \labelwidthstring 00.00.0000
25555 END_DEF end the declaration of the dispatch table.
25558 \begin_layout Standard
25559 Additionally there are two more macros to simplify the declaration of the
25564 \labelwidthstring 00.00.0000
25567 SIGHANDLER(handler)
25569 this declares the function prototype for the
25577 \labelwidthstring 00.00.0000
25578 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
25581 \begin_layout Standard
25582 An example of using the macros above is shown below:
25585 \begin_layout LyX-Code
25586 #include <pic18fregs.h>
25589 \begin_layout LyX-Code
25590 #include <signal.h>
25594 DEF_INTHIGH(high_int)
25597 \begin_layout LyX-Code
25598 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
25601 \begin_layout LyX-Code
25602 DEF_HANDLER(SIG_BCOL, _bcol_handler)
25605 \begin_layout LyX-Code
25610 SIGHANDLER(_tmr0_handler)
25613 \begin_layout LyX-Code
25617 \begin_layout LyX-Code
25618 /* action to be taken when timer 0 overflows */
25621 \begin_layout LyX-Code
25626 SIGHANDLERNAKED(_bcol_handler)
25629 \begin_layout LyX-Code
25633 \begin_layout LyX-Code
25637 \begin_layout LyX-Code
25638 /* action to be taken when bus collision occurs */
25641 \begin_layout LyX-Code
25645 \begin_layout LyX-Code
25649 \begin_layout LyX-Code
25653 \begin_layout Standard
25658 Special care should be taken when using the above scheme:
25661 \begin_layout Itemize
25662 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
25665 \begin_layout Itemize
25666 when declaring SIGHANDLERNAKED handler never forget to use
25670 for proper returning.
25673 \begin_layout Subsection
25677 \begin_layout Standard
25678 Here you can find some general tips for compiling programs with SDCC/pic16.
25681 \begin_layout Subsubsection
25685 \begin_layout Standard
25687 \begin_inset LatexCommand \index{PIC16!stack}
25691 size (that is 64 bytes) probably is enough for many programs.
25692 One must take care that when there are many levels of function nesting,
25693 or there is excessive usage of stack, its size should be extended.
25694 An example of such a case is the printf/sprintf family of functions.
25695 If you encounter problems like not being able to print integers, then you
25696 need to set the stack size around the maximum (256 for small stack model).
25697 The following diagram shows what happens when calling printf to print an
25701 \begin_layout LyX-Code
25702 printf () --> ltoa () --> ultoa () --> divschar ()
25705 \begin_layout Standard
25706 It is should be understood that stack is easily consumed when calling complicate
25708 Using command line arguments like -
25712 \begin_layout Standard
25721 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
25723 Other ways to reduce stack usage may exist.
25726 \begin_layout Subsection
25730 \begin_layout Standard
25731 The PIC16 Port currently does not pass SDCC's regression test
25732 \begin_inset LatexCommand \index{Regression test (PIC16)}
25737 \begin_inset LatexCommand \ref{sec:Quality-control}
25741 ) and thus the nightly regression tests for the PIC16 target are currently
25742 disabled for all hosts except for
25747 This means you can see the result of the PIC16 regression tests f.e.
25748 by checking the log files in
25749 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
25753 (pick the most up to date file there, scroll down, lend a hand).
25756 \begin_layout Chapter
25760 \begin_layout Standard
25761 There are several approaches to debugging your code.
25762 This chapter is meant to show your options and to give detail on some of
25767 When writing your code:
25770 \begin_layout Itemize
25771 write your code with debugging in mind (avoid duplicating code, put conceptually
25772 similar variables into structs, use structured code, have strategic points
25773 within your code where all variables are consistent, ...)
25776 \begin_layout Itemize
25777 run a syntax-checking tool like splint
25778 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25783 \begin_inset LatexCommand \index{lint (syntax checking tool)}
25791 \begin_layout Standard
25801 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25808 \begin_layout Itemize
25809 for the high level code use a C-compiler (like f.e.
25810 GCC) to compile run and debug the code on your host.
25815 \begin_layout Standard
25825 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25829 ) on howto handle syntax extensions like __xdata, __at(), ...
25833 \begin_layout Itemize
25834 use another C-compiler to compile code for your target.
25835 Always an option but not recommended:) And not very likely to help you.
25836 If you seriously consider walking this path you should at least occasionally
25837 check portability of your code.
25838 Most commercial compiler vendors will offer an evaluation version so you
25839 can test compile your code or snippets of your code.
25842 \begin_layout Standard
25843 Debugging on a simulator:
25846 \begin_layout Itemize
25847 there is a separate section about SDCDB (section
25848 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
25855 \begin_layout Itemize
25856 or (8051 specific) use a freeware/commercial simulator which interfaces
25858 \begin_inset LatexCommand \index{AOMF, AOMF51}
25863 \begin_inset LatexCommand \ref{OMF file}
25867 ) optionally generated by SDCC.
25870 \begin_layout Standard
25871 Debugging On-target:
25874 \begin_layout Itemize
25875 use a MCU port pin to serially output debug data to the RS232 port of your
25877 You'll probably want some level shifting device typically involving a MAX232
25879 If the hardware serial port of the MCU is not available search for 'Software
25880 UART' in your favourite search machine.
25883 \begin_layout Itemize
25884 use an on-target monitor.
25885 In this context a monitor is a small program which usually accepts commands
25886 via a serial line and allows to set program counter, to single step through
25887 a program and read/write memory locations.
25888 For the 8051 good examples of monitors are paulmon and cmon51 (see section
25890 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
25897 \begin_layout Itemize
25898 toggle MCU port pins at strategic points within your code and use an oscilloscop
25902 digital oscilloscope
25905 \begin_inset LatexCommand \index{Oscilloscope}
25909 with deep trace memory is really helpful especially if you have to debug
25910 a realtime application.
25911 If you need to monitor more pins than your oscilloscope provides you can
25912 sometimes get away with a small R-2R network.
25913 On a single channel oscilloscope you could f.e.
25914 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
25916 \begin_inset Formula $\Omega$
25919 resistor and the other one by a 5\InsetSpace ~
25921 \begin_inset Formula $\Omega$
25924 resistor to the oscilloscope probe (check output drive capability of the
25925 pins you want to monitor).
25926 If you need to monitor many more pins a
25933 \begin_layout Itemize
25947 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
25952 Usually very expensive.
25953 And very nice to have too.
25954 And usually locks you (for years...) to the devices the ICE can emulate.
25958 \begin_layout Itemize
25959 use a remote debugger.
25960 In most 8-bit systems the symbol information is not available on the target,
25961 and a complete debugger is too bulky for the target system.
25962 Therefore usually a debugger on the host system connects to an on-target
25963 debugging stub which accepts only primitive commands.
25966 Terms to enter into your favourite search engine could be 'remote debugging',
25967 'gdb stub' or 'inferior debugger'.
25971 \begin_layout Itemize
25972 use an on target hardware debugger.
25973 Some of the more modern MCUs include hardware support for setting break
25974 points and monitoring/changing variables by using dedicated hardware pins.
25975 This facility doesn't require additional code to run on the target and
25980 doesn't affect runtime behaviour until a breakpoint is hit.
25981 For the mcs51 most hardware debuggers use the AOMF
25982 \begin_inset LatexCommand \index{AOMF, AOMF51}
25987 \begin_inset LatexCommand \ref{OMF file}
25995 \begin_layout Standard
25999 \begin_layout Itemize
26000 if you are not familiar with any of the following terms you're likely to
26001 run into problems rather sooner than later:
26018 As an embedded programmer you
26022 to know them so why not look them up
26026 you have problems?)
26029 \begin_layout Itemize
26030 tell someone else about your problem (actually this is a surprisingly effective
26031 means to hunt down the bug even if the listener is not familiar with your
26033 As 'failure to communicate' is probably one of the job-induced deformations
26034 of an embedded programmer this is highly encouraged.
26037 \begin_layout Section
26038 Debugging with SDCDB
26039 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26044 \begin_inset LatexCommand \index{SDCDB (debugger)}
26051 \begin_layout Standard
26052 SDCC is distributed with a source level debugger
26053 \begin_inset LatexCommand \index{Debugger}
26058 The debugger uses a command line interface, the command repertoire of the
26059 debugger has been kept as close to gdb
26060 \begin_inset LatexCommand \index{gdb}
26064 (the GNU debugger) as possible.
26065 The configuration and build process is part of the standard compiler installati
26066 on, which also builds and installs the debugger in the target directory
26067 specified during configuration.
26068 The debugger allows you debug BOTH at the C source and at the ASM source
26072 \begin_layout Subsection
26073 Compiling for Debugging
26076 \begin_layout Standard
26081 \begin_layout Standard
26091 \begin_inset LatexCommand \index{-\/-debug}
26095 option must be specified for all files for which debug information is to
26097 The compiler generates a .adb file for each of these files.
26098 The linker creates the .cdb
26099 \begin_inset LatexCommand \index{<file>.cdb}
26104 \begin_inset LatexCommand \index{<file>.adb}
26108 files and the address information.
26109 This .cdb is used by the debugger.
26112 \begin_layout Subsection
26113 How the Debugger Works
26116 \begin_layout Standard
26121 \begin_layout Standard
26130 -debug option is specified the compiler generates extra symbol information
26131 some of which are put into the assembler source and some are put into the
26133 Then the linker creates the .cdb file from the individual .adb files with
26134 the address information for the symbols.
26135 The debugger reads the symbolic information generated by the compiler &
26136 the address information generated by the linker.
26137 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
26138 execution is controlled by the debugger.
26139 When a command is issued for the debugger, it translates it into appropriate
26140 commands for the simulator.
26141 (Currently SDCDM only connects to the simulator but
26146 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
26150 is an effort to connect directly to the hardware.)
26153 \begin_layout Subsection
26154 Starting the Debugger SDCDB
26157 \begin_layout Standard
26158 The debugger can be started using the following command line.
26159 (Assume the file you are debugging has the file name foo).
26173 The debugger will look for the following files.
26176 \begin_layout Itemize
26177 foo.c - the source file.
26180 \begin_layout Itemize
26181 foo.cdb - the debugger symbol information file.
26184 \begin_layout Itemize
26185 foo.ihx - the Intel hex format
26186 \begin_inset LatexCommand \index{Intel hex format}
26193 \begin_layout Subsection
26194 SDCDB Command Line Options
26197 \begin_layout Itemize
26202 \begin_layout Standard
26211 -directory=<source file directory> this option can used to specify the directory
26213 The debugger will look into the directory list specified for source, cdb
26215 The items in the directory list must be separated by ':', e.g.
26216 if the source files can be in the directories /home/src1 and /home/src2,
26221 \begin_layout Standard
26230 -directory option should be -
26234 \begin_layout Standard
26243 -directory=/home/src1:/home/src2.
26244 Note there can be no spaces in the option.
26248 \begin_layout Itemize
26249 -cd <directory> - change to the <directory>.
26252 \begin_layout Itemize
26253 -fullname - used by GUI front ends.
26256 \begin_layout Itemize
26257 -cpu <cpu-type> - this argument is passed to the simulator please see the
26258 simulator docs for details.
26261 \begin_layout Itemize
26262 -X <Clock frequency > this options is passed to the simulator please see
26263 the simulator docs for details.
26266 \begin_layout Itemize
26267 -s <serial port file> passed to simulator see the simulator docs for details.
26270 \begin_layout Itemize
26271 -S <serial in,out> passed to simulator see the simulator docs for details.
26274 \begin_layout Itemize
26275 -k <port number> passed to simulator see the simulator docs for details.
26278 \begin_layout Subsection
26279 SDCDB Debugger Commands
26282 \begin_layout Standard
26283 As mentioned earlier the command interface for the debugger has been deliberatel
26284 y kept as close the GNU debugger gdb, as possible.
26285 This will help the integration with existing graphical user interfaces
26286 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
26287 If you use a graphical user interface for the debugger you can skip this
26291 \begin_layout Subsubsection*
26292 break [line | file:line | function | file:function]
26295 \begin_layout Standard
26296 Set breakpoint at specified line or function:
26305 sdcdb>break foo.c:100
26307 sdcdb>break funcfoo
26309 sdcdb>break foo.c:funcfoo
26312 \begin_layout Subsubsection*
26313 clear [line | file:line | function | file:function ]
26316 \begin_layout Standard
26317 Clear breakpoint at specified line or function:
26326 sdcdb>clear foo.c:100
26328 sdcdb>clear funcfoo
26330 sdcdb>clear foo.c:funcfoo
26333 \begin_layout Subsubsection*
26337 \begin_layout Standard
26338 Continue program being debugged, after breakpoint.
26341 \begin_layout Subsubsection*
26345 \begin_layout Standard
26346 Execute till the end of the current function.
26349 \begin_layout Subsubsection*
26353 \begin_layout Standard
26354 Delete breakpoint number 'n'.
26355 If used without any option clear ALL user defined break points.
26358 \begin_layout Subsubsection*
26359 info [break | stack | frame | registers ]
26362 \begin_layout Itemize
26363 info break - list all breakpoints
26366 \begin_layout Itemize
26367 info stack - show the function call stack.
26370 \begin_layout Itemize
26371 info frame - show information about the current execution frame.
26374 \begin_layout Itemize
26375 info registers - show content of all registers.
26378 \begin_layout Subsubsection*
26382 \begin_layout Standard
26383 Step program until it reaches a different source line.
26384 Note: pressing <return> repeats the last command.
26387 \begin_layout Subsubsection*
26391 \begin_layout Standard
26392 Step program, proceeding through subroutine calls.
26395 \begin_layout Subsubsection*
26399 \begin_layout Standard
26400 Start debugged program.
26403 \begin_layout Subsubsection*
26407 \begin_layout Standard
26408 Print type information of the variable.
26411 \begin_layout Subsubsection*
26415 \begin_layout Standard
26416 print value of variable.
26419 \begin_layout Subsubsection*
26423 \begin_layout Standard
26424 load the given file name.
26425 Note this is an alternate method of loading file for debugging.
26428 \begin_layout Subsubsection*
26432 \begin_layout Standard
26433 print information about current frame.
26436 \begin_layout Subsubsection*
26440 \begin_layout Standard
26441 Toggle between C source & assembly source.
26444 \begin_layout Subsubsection*
26445 ! simulator command
26448 \begin_layout Standard
26449 Send the string following '!' to the simulator, the simulator response is
26451 Note the debugger does not interpret the command being sent to the simulator,
26452 so if a command like 'go' is sent the debugger can loose its execution
26453 context and may display incorrect values.
26456 \begin_layout Subsubsection*
26460 \begin_layout Standard
26463 My name is Bobby Brown"
26466 \begin_layout Subsection
26467 Interfacing SDCDB with DDD
26470 \begin_layout Standard
26471 \begin_inset Note Comment
26474 \begin_layout Standard
26475 The screenshot was converted from png to eps with:
26476 \begin_inset Quotes sld
26479 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
26480 \begin_inset Quotes srd
26483 which produces a pretty compact eps file which is free from compression
26487 \begin_layout Standard
26488 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
26489 as this broke the build system on Sourceforge (pdf-file was broken.
26490 pdflatex does not accept eps files).
26498 \begin_layout Standard
26514 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
26520 shows a screenshot of a debugging session with DDD
26521 \begin_inset LatexCommand \index{DDD (debugger)}
26525 (Unix only) on a simulated 8032.
26526 The debugging session might not run as smoothly as the screenshot suggests.
26527 The debugger allows setting of breakpoints, displaying and changing variables,
26528 single stepping through C and assembler code.
26531 The source was compiled with
26545 \begin_layout Standard
26557 -debug ddd_example.c
26570 and DDD was invoked with
26577 ddd -debugger "sdcdb -cpu 8032 ddd_example"
26580 \begin_layout Standard
26581 \begin_inset Note Note
26584 \begin_layout Standard
26585 Check that the double quotes or an apostroph within the command line survive
26586 the LyX tool chain.
26587 Previously the apostrophs got slanted in the PDF output so a cut and paste
26596 \begin_layout Subsection
26597 Interfacing SDCDB with XEmacs
26598 \begin_inset LatexCommand \index{XEmacs}
26603 \begin_inset LatexCommand \index{Emacs}
26610 \begin_layout Standard
26611 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
26612 sdcdb.el and sdcdbsrc.el.
26613 These two files can be found in the $(prefix)/bin directory after the installat
26615 These files need to be loaded into XEmacs for the interface to work.
26616 This can be done at XEmacs startup time by inserting the following into
26617 your '.xemacs' file (which can be found in your HOME directory):
26623 (load-file sdcdbsrc.el)
26629 .xemacs is a lisp file so the () around the command is REQUIRED.
26630 The files can also be loaded dynamically while XEmacs is running, set the
26631 environment variable 'EMACSLOADPATH' to the installation bin directory
26632 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
26633 To start the interface enter the following command:
26647 You will prompted to enter the file name to be debugged.
26652 The command line options that are passed to the simulator directly are
26653 bound to default values in the file sdcdbsrc.el.
26654 The variables are listed below, these values maybe changed as required.
26657 \begin_layout Itemize
26658 sdcdbsrc-cpu-type '51
26661 \begin_layout Itemize
26662 sdcdbsrc-frequency '11059200
26665 \begin_layout Itemize
26666 sdcdbsrc-serial nil
26669 \begin_layout Standard
26670 The following is a list of key mapping for the debugger interface.
26673 \begin_layout Standard
26696 binding\InsetSpace ~
26734 -------\InsetSpace ~
26805 sdcdb-back-from-src\InsetSpace ~
26834 rom-src\InsetSpace ~
26844 SDCDB continue command
26862 sdcdb-step-from-src\InsetSpace ~
26891 hatis-c-sexp\InsetSpace ~
26901 SDCDB ptypecommand for data at
26968 sdcdbsrc-delete\InsetSpace ~
26983 B Delete all breakpoints if no arg
27032 given or delete arg (C-u arg x)
27051 -frame\InsetSpace ~
27066 SDCDB Display current frame if no arg,
27115 given or display frame arg
27183 sdcdbsrc-goto-sdcdb\InsetSpace ~
27193 Goto the SDCDB output buffer
27212 t-c-sexp\InsetSpace ~
27223 SDCDB print command for data at
27290 sdcdbsrc-goto-sdcdb\InsetSpace ~
27301 o the SDCDB output buffer
27319 sdcdbsrc-mode\InsetSpace ~
27335 Toggles Sdcdbsrc mode (turns it
27351 sdcdb-finish-from-src\InsetSpace ~
27359 SDCDB finish command
27393 Set break for line with point
27408 sdcdbsrc-mode\InsetSpace ~
27424 Toggle Sdcdbsrc mode
27440 dbsrc-srcmode\InsetSpace ~
27460 \begin_layout Standard
27466 \begin_layout Chapter
27470 \begin_layout Standard
27471 Here are a few guidelines that will help the compiler generate more efficient
27472 code, some of the tips are specific to this compiler others are generally
27473 good programming practice.
27476 \begin_layout Itemize
27477 Use the smallest data type to represent your data-value.
27478 If it is known in advance that the value is going to be less than 256 then
27479 use an 'unsigned char' instead of a 'short' or 'int'.
27480 Please note, that ANSI C requires both signed and unsigned chars to be
27481 promoted to 'signed int'
27482 \begin_inset LatexCommand \index{promotion to signed int}
27487 \begin_inset Marginal
27490 \begin_layout Standard
27499 before doing any operation.
27501 \begin_inset LatexCommand \index{type promotion}
27506 \begin_inset LatexCommand \label{type promotion}
27510 can be omitted, if the result is the same.
27511 The effect of the promotion rules together with the sign-extension is often
27516 \begin_layout Verse
27519 unsigned char uc = 0xfe;
27521 if (uc * uc < 0) /* this is true! */
27534 \begin_layout Standard
27541 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
27549 \begin_layout Verse
27552 (unsigned char) -12 / (signed char) -3 = ...
27555 \begin_layout Standard
27556 No, the result is not 4:
27559 \begin_layout Verse
27562 (int) (unsigned char) -12 / (int) (signed char) -3 =
27564 (int) (unsigned char)
27565 0xf4 / (int) (signed char) 0xfd =
27567 (int) 0x00f4 / (int) 0xfffd =
27572 (int) 244 / (int) -3 =
27574 (int) -81 = (int) 0xffaf;
27577 \begin_layout Standard
27578 Don't complain, that gcc gives you a different result.
27579 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
27580 Therefore the results are different.
27583 \begin_inset Quotes sld
27587 \begin_inset Quotes srd
27593 \begin_layout Quote
27596 If well-defined overflow characteristics are important and negative values
27597 are not, or if you want to steer clear of sign-extension problems when
27598 manipulating bits or bytes, use one of the corresponding unsigned types.
27599 (Beware when mixing signed and unsigned values in expressions, though.)
27602 character types (especially unsigned char) can be used as "tiny" integers,
27603 doing so is sometimes more trouble than it's worth, due to unpredictable
27604 sign extension and increased code size.
27608 \begin_layout Itemize
27609 Use unsigned when it is known in advance that the value is not going to
27611 This helps especially if you are doing division or multiplication, bit-shifting
27612 or are using an array index.
27615 \begin_layout Itemize
27616 NEVER jump into a LOOP.
27619 \begin_layout Itemize
27620 Declare the variables to be local
27621 \begin_inset LatexCommand \index{local variables}
27625 whenever possible, especially loop control variables (induction).
27628 \begin_layout Itemize
27629 Have a look at the assembly listing to get a
27630 \begin_inset Quotes sld
27634 \begin_inset Quotes srd
27637 for the code generation.
27640 \begin_layout Section
27641 Porting code from or to other compilers
27642 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
27649 \begin_layout Itemize
27650 check whether endianness of the compilers differs and adapt where needed.
27653 \begin_layout Itemize
27654 check the device specific header files
27655 \begin_inset LatexCommand \index{Header files}
27660 \begin_inset LatexCommand \index{Include files}
27664 for compiler specific syntax.
27665 Eventually include the file <compiler.h
27666 \begin_inset LatexCommand \index{compiler.h (include file)}
27671 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
27675 to allow using common header files.
27678 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
27685 \begin_layout Itemize
27686 check whether the startup code contains the correct initialization (watchdog,
27690 \begin_layout Itemize
27691 check whether the sizes of short, int, long match.
27694 \begin_layout Itemize
27695 check if some 16 or 32 bit hardware registers require a specific addressing
27696 order (least significant or most significant byte first) and adapt if needed
27705 relate to time and not to lower/upper memory location here, so this is
27710 the same as endianness).
27713 \begin_layout Itemize
27714 check whether the keyword
27718 is used where needed.
27719 The compilers might differ in their optimization characteristics (as different
27720 versions of the same compiler might also use more clever optimizations
27721 this is good idea anyway).
27723 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
27730 \begin_layout Itemize
27731 check that the compilers are not told to supress warnings.
27734 \begin_layout Itemize
27735 check and convert compiler specific extensions (interrupts, memory areas,
27739 \begin_layout Itemize
27740 check for differences in type promotion.
27741 Especially check for math operations on
27750 For the sake of C99 compatibility SDCC will probably promote these to
27754 more often than other compilers.
27755 Eventually insert explicit casts to
27764 Also check that the ~\InsetSpace ~
27766 \begin_inset LatexCommand \index{\~\/ Operator}
27773 \begin_inset LatexCommand \index{bit}
27779 variables, use the !\InsetSpace ~
27782 \begin_inset LatexCommand \ref{type promotion}
27787 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27794 \begin_layout Itemize
27795 check the assembly code generated for interrupt routines (f.e.
27796 for calls to possibly non-reentrant library functions).
27799 \begin_layout Itemize
27800 check whether timing loops result in proper timing (or preferably consider
27801 a rewrite of the code with timer based delays instead).
27804 \begin_layout Itemize
27805 check for differences in printf parameters (some compilers push (va_arg
27806 \begin_inset LatexCommand \index{vararg, va\_arg}
27810 ) char variables as
27814 others push them as
27820 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27827 \begin_layout Itemize
27828 check the resulting memory map
27829 \begin_inset LatexCommand \index{Memory map}
27834 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
27835 ly idata, pdata, xdata).
27836 Eventually check if unexpected library functions are included.
27839 \begin_layout Section
27841 \begin_inset LatexCommand \index{Tools}
27845 included in the distribution
27848 \begin_layout Standard
27850 \begin_inset Tabular
27851 <lyxtabular version="3" rows="12" columns="3">
27853 <column alignment="left" valignment="top" leftline="true" width="0pt">
27854 <column alignment="left" valignment="top" leftline="true" width="0pt">
27855 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27856 <row topline="true" bottomline="true">
27857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27860 \begin_layout Standard
27868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27871 \begin_layout Standard
27879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27882 \begin_layout Standard
27891 <row topline="true">
27892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27895 \begin_layout Standard
27897 \begin_inset LatexCommand \index{uCsim}
27906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27909 \begin_layout Standard
27910 Simulator for various architectures
27915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27918 \begin_layout Standard
27925 <row topline="true">
27926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27929 \begin_layout Standard
27935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27938 \begin_layout Standard
27940 \begin_inset LatexCommand \index{Header files}
27945 \begin_inset LatexCommand \index{Include files}
27954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27957 \begin_layout Standard
27958 sdcc/support/scripts
27964 <row topline="true">
27965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27968 \begin_layout Standard
27974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27977 \begin_layout Standard
27978 header file conversion
27983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27986 \begin_layout Standard
27987 sdcc/support/scripts
27993 <row topline="true">
27994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27997 \begin_layout Standard
28003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28006 \begin_layout Standard
28012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28015 \begin_layout Standard
28031 <row topline="true">
28032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28035 \begin_layout Standard
28041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28044 \begin_layout Standard
28050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28053 \begin_layout Standard
28069 <row topline="true">
28070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28073 \begin_layout Standard
28079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28082 \begin_layout Standard
28088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28091 \begin_layout Standard
28107 <row topline="true">
28108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28111 \begin_layout Standard
28117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28120 \begin_layout Standard
28126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28129 \begin_layout Standard
28145 <row topline="true">
28146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28149 \begin_layout Standard
28155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28158 \begin_layout Standard
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28167 \begin_layout Standard
28183 <row topline="true">
28184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28187 \begin_layout Standard
28193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28196 \begin_layout Standard
28202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28205 \begin_layout Standard
28221 <row topline="true">
28222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28225 \begin_layout Standard
28231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28234 \begin_layout Standard
28240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28243 \begin_layout Standard
28259 <row topline="true" bottomline="true">
28260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28263 \begin_layout Standard
28269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28272 \begin_layout Standard
28274 \begin_inset LatexCommand \index{packihx (tool)}
28283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28286 \begin_layout Standard
28311 \begin_layout Section
28313 \begin_inset LatexCommand \index{Documentation}
28317 included in the distribution
28320 \begin_layout Standard
28322 \begin_inset Tabular
28323 <lyxtabular version="3" rows="10" columns="2">
28325 <column alignment="block" valignment="top" leftline="true" width="40col%">
28326 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
28327 <row topline="true" bottomline="true" endhead="true">
28328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28331 \begin_layout Standard
28339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28342 \begin_layout Standard
28345 Filename / Where to get
28351 <row topline="true">
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28355 \begin_layout Standard
28356 SDCC Compiler User Guide
28361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28364 \begin_layout Standard
28365 You're reading it right now
28377 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
28387 <row topline="true">
28388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28391 \begin_layout Standard
28397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28400 \begin_layout Standard
28413 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28423 <row topline="true">
28424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28427 \begin_layout Standard
28429 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
28434 \begin_inset LatexCommand \index{Assembler documentation}
28441 \begin_inset LatexCommand \index{aslink}
28446 \begin_inset LatexCommand \index{Linker documentation}
28455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28458 \begin_layout Standard
28459 sdcc/as/doc/asxhtm.html
28471 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
28481 <row topline="true">
28482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28485 \begin_layout Standard
28486 SDCC regression test
28487 \begin_inset LatexCommand \index{Regression test}
28496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28499 \begin_layout Standard
28500 sdcc/doc/test_suite_spec.pdf
28512 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28522 <row topline="true">
28523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28526 \begin_layout Standard
28532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28535 \begin_layout Standard
28548 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
28558 <row topline="true">
28559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28562 \begin_layout Standard
28563 Notes on debugging with SDCDB
28564 \begin_inset LatexCommand \index{SDCDB (debugger)}
28573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28576 \begin_layout Standard
28577 sdcc/debugger/README
28589 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
28599 <row topline="true">
28600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28603 \begin_layout Standard
28605 \begin_inset LatexCommand \index{uCsim}
28609 Software simulator for microcontrollers
28614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28617 \begin_layout Standard
28647 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
28657 <row topline="true">
28658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28661 \begin_layout Standard
28662 Temporary notes on the pic16
28663 \begin_inset LatexCommand \index{PIC16}
28672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28675 \begin_layout Standard
28676 sdcc/src/pic16/NOTES
28688 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
28698 <row topline="true" bottomline="true">
28699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28702 \begin_layout Standard
28703 SDCC internal documentation (debugging file format)
28708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28711 \begin_layout Standard
28741 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
28760 \begin_layout Section
28761 Related open source tools
28762 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
28767 \begin_inset LatexCommand \index{Related tools}
28774 \begin_layout Standard
28776 \begin_inset Tabular
28777 <lyxtabular version="3" rows="14" columns="3">
28779 <column alignment="left" valignment="top" leftline="true" width="0pt">
28780 <column alignment="block" valignment="top" leftline="true" width="30line%">
28781 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28782 <row topline="true" bottomline="true">
28783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28786 \begin_layout Standard
28794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28797 \begin_layout Standard
28805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28808 \begin_layout Standard
28817 <row topline="true">
28818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28821 \begin_layout Standard
28823 \begin_inset LatexCommand \index{gpsim (pic simulator)}
28832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28835 \begin_layout Standard
28841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28844 \begin_layout Standard
28845 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
28855 <row topline="true">
28856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28859 \begin_layout Standard
28861 \begin_inset LatexCommand \index{gputils (pic tools)}
28870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28873 \begin_layout Standard
28879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28882 \begin_layout Standard
28883 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
28893 <row topline="true">
28894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28897 \begin_layout Standard
28903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28906 \begin_layout Standard
28912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28915 \begin_layout Standard
28916 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
28926 <row topline="true">
28927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28930 \begin_layout Standard
28936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28939 \begin_layout Standard
28940 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
28946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28949 \begin_layout Standard
28950 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
28960 <row topline="true">
28961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28964 \begin_layout Standard
28966 \begin_inset LatexCommand \index{indent (source formatting tool)}
28975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28978 \begin_layout Standard
28979 Formats C source - Master of the white spaces
28984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28987 \begin_layout Standard
28988 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
28998 <row topline="true">
28999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29002 \begin_layout Standard
29004 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29016 \begin_layout Standard
29017 Object file conversion, checksumming, ...
29022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29025 \begin_layout Standard
29026 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29036 <row topline="true">
29037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29040 \begin_layout Standard
29042 \begin_inset LatexCommand \index{objdump (tool)}
29051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29054 \begin_layout Standard
29055 Object file conversion, ...
29060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29063 \begin_layout Standard
29064 Part of binutils (should be there anyway)
29070 <row topline="true">
29071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29074 \begin_layout Standard
29080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29083 \begin_layout Standard
29084 8051 monitor (hex up-/download, single step, disassemble)
29089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29092 \begin_layout Standard
29093 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
29103 <row topline="true">
29104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29107 \begin_layout Standard
29109 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
29118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29121 \begin_layout Standard
29122 Source code documentation system
29127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29130 \begin_layout Standard
29131 \begin_inset LatexCommand \url{http://www.doxygen.org}
29141 <row topline="true">
29142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29145 \begin_layout Standard
29151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29154 \begin_layout Standard
29155 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
29160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29163 \begin_layout Standard
29164 \begin_inset LatexCommand \url{http://www.kdevelop.org}
29174 <row topline="true">
29175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29178 \begin_layout Standard
29184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29187 \begin_layout Standard
29188 8051 monitor (hex up-/download, single step, disassemble)
29193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29196 \begin_layout Standard
29197 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
29207 <row topline="true">
29208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29211 \begin_layout Standard
29213 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29225 \begin_layout Standard
29226 Statically checks c sources (see
29227 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29239 \begin_layout Standard
29240 \begin_inset LatexCommand \url{http://www.splint.org}
29250 <row topline="true" bottomline="true">
29251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29254 \begin_layout Standard
29256 \begin_inset LatexCommand \index{DDD (debugger)}
29265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29268 \begin_layout Standard
29269 Debugger, serves nicely as GUI to SDCDB
29270 \begin_inset LatexCommand \index{SDCDB (debugger)}
29279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29282 \begin_layout Standard
29283 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
29302 \begin_layout Section
29303 Related documentation / recommended reading
29306 \begin_layout Standard
29308 \begin_inset Tabular
29309 <lyxtabular version="3" rows="7" columns="3">
29311 <column alignment="left" valignment="top" leftline="true" width="0pt">
29312 <column alignment="left" valignment="top" leftline="true" width="0">
29313 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29314 <row topline="true" bottomline="true">
29315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29318 \begin_layout Standard
29326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29329 \begin_layout Standard
29337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29340 \begin_layout Standard
29349 <row topline="true">
29350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29353 \begin_layout Standard
29368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29371 \begin_layout Standard
29373 \begin_inset LatexCommand \index{C Reference card}
29382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29385 \begin_layout Standard
29386 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
29396 <row topline="true">
29397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29400 \begin_layout Standard
29406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29409 \begin_layout Standard
29411 \begin_inset LatexCommand \index{C FAQ}
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29423 \begin_layout Standard
29424 \begin_inset LatexCommand \url{http://www.c-faq.com}
29434 <row topline="true">
29435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29438 \begin_layout Standard
29444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29447 \begin_layout Standard
29448 \begin_inset Quotes sld
29452 \begin_inset Quotes srd
29460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29463 \begin_layout Standard
29466 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29476 <row topline="true">
29477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29480 \begin_layout Standard
29486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29489 \begin_layout Standard
29490 \begin_inset Quotes sld
29493 Extensions for Embedded C
29494 \begin_inset Quotes srd
29502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29505 \begin_layout Standard
29508 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
29518 <row topline="true">
29519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29522 \begin_layout Standard
29528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29531 \begin_layout Standard
29532 Latest datasheet of target CPU
29537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29540 \begin_layout Standard
29547 <row topline="true" bottomline="true">
29548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29551 \begin_layout Standard
29557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29560 \begin_layout Standard
29561 Revision history of datasheet
29566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29569 \begin_layout Standard
29585 \begin_layout Section
29586 Application notes specifically for SDCC
29589 \begin_layout Standard
29590 SDCC makes no claims about the completeness of this list and about up-to-datenes
29591 s or correctness of the application notes
29592 \begin_inset LatexCommand \index{Application notes}
29599 \begin_layout Standard
29603 \begin_inset Tabular
29604 <lyxtabular version="3" rows="7" columns="3">
29606 <column alignment="block" valignment="top" leftline="true" width="17col%">
29607 <column alignment="block" valignment="top" leftline="true" width="27col%">
29608 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
29609 <row topline="true" bottomline="true">
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29613 \begin_layout Standard
29622 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
29625 \begin_layout Standard
29634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29637 \begin_layout Standard
29647 <row topline="true">
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29651 \begin_layout Standard
29659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29662 \begin_layout Standard
29665 Using the SDCC Compiler for the DS80C400
29666 \begin_inset LatexCommand \index{DS80C400}
29675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29678 \begin_layout Standard
29681 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
29691 <row topline="true">
29692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29695 \begin_layout Standard
29703 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
29706 \begin_layout Standard
29709 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
29710 \begin_inset LatexCommand \index{DS89C4x0}
29714 Family of Microcontrollers
29719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29722 \begin_layout Standard
29725 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
29735 <row topline="true">
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29739 \begin_layout Standard
29742 Silicon Laboratories / Cygnal
29747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29750 \begin_layout Standard
29753 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
29754 \begin_inset LatexCommand \index{IDE}
29763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29766 \begin_layout Standard
29769 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
29779 <row topline="true">
29780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29783 \begin_layout Standard
29786 Ramtron / Goal Semiconductor
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29794 \begin_layout Standard
29797 Interfacing SDCC to Syn and Textpad
29802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29805 \begin_layout Standard
29808 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29818 <row topline="true">
29819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29822 \begin_layout Standard
29825 Ramtron / Goal Semiconductor
29830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29833 \begin_layout Standard
29836 Installing and Configuring SDCC and Crimson Editor
29841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29844 \begin_layout Standard
29847 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29857 <row topline="true" bottomline="true">
29858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29861 \begin_layout Standard
29869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29872 \begin_layout Standard
29875 MSC12xx Programming with SDCC
29880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29883 \begin_layout Standard
29886 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
29903 \begin_layout Section
29907 \begin_layout Standard
29908 Some questions answered, some pointers given - it might be time to in turn
29916 \begin_layout Itemize
29917 can you solve your project with the selected microcontroller? Would you
29918 find out early or rather late that your target is too small/slow/whatever?
29919 Can you switch to a slightly better device if it doesn't fit?
29922 \begin_layout Itemize
29923 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
29924 and/or another programming language be more adequate? Would an operating
29925 system on the target device help?
29928 \begin_layout Itemize
29929 if you solved the problem, will the marketing department be happy?
29932 \begin_layout Itemize
29933 if the marketing department is happy, will customers be happy?
29936 \begin_layout Itemize
29937 if you're the project manager, marketing department and maybe even the customer
29938 in one person, have you tried to see the project from the outside?
29941 \begin_layout Itemize
29942 is the project done if you think it is done? Or is just that other interface/pro
29943 tocol/feature/configuration/option missing? How about website, manual(s),
29944 internationali(z|s)ation, packaging, labels, 2nd source for components,
29945 electromagnetic compatability/interference, documentation for production,
29946 production test software, update mechanism, patent issues?
29949 \begin_layout Itemize
29950 is your project adequately positioned in that magic triangle: fame, fortune,
29954 \begin_layout Standard
29955 Maybe not all answers to these questions are known and some answers may
29960 , nevertheless knowing these questions may help you to avoid burnout
29964 \begin_layout Standard
29965 burnout is bad for electronic devices, programmers and motorcycle tyres
29971 Chances are you didn't want to hear some of them...
29974 \begin_layout Chapter
29976 \begin_inset LatexCommand \index{Support}
29983 \begin_layout Standard
29984 SDCC has grown to be a large project.
29985 The compiler alone (without the preprocessor, assembler and linker) is
29986 well over 150,000 lines of code (blank stripped).
29987 The open source nature of this project is a key to its continued growth
29989 You gain the benefit and support of many active software developers and
29991 Is SDCC perfect? No, that's why we need your help.
29992 The developers take pride in fixing reported bugs.
29993 You can help by reporting the bugs and helping other SDCC users.
29994 There are lots of ways to contribute, and we encourage you to take part
29995 in making SDCC a great software package.
29999 \begin_layout Standard
30000 The SDCC project is hosted on the SDCC sourceforge site at
30001 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30006 You'll find the complete set of mailing lists
30007 \begin_inset LatexCommand \index{Mailing list(s)}
30011 , forums, bug reporting system, patch submission
30012 \begin_inset LatexCommand \index{Patch submission}
30017 \begin_inset LatexCommand \index{download}
30021 area and Subversion code repository
30022 \begin_inset LatexCommand \index{Subversion code repository}
30029 \begin_layout Section
30031 \begin_inset LatexCommand \index{Bug reporting}
30036 \begin_inset LatexCommand \index{Reporting bugs}
30043 \begin_layout Standard
30044 The recommended way of reporting bugs is using the infrastructure of the
30046 You can follow the status of bug reports there and have an overview about
30050 \begin_layout Standard
30051 Bug reports are automatically forwarded to the developer mailing list and
30052 will be fixed ASAP.
30053 When reporting a bug, it is very useful to include a small test program
30054 (the smaller the better) which reproduces the problem.
30055 If you can isolate the problem by looking at the generated assembly code,
30056 this can be very helpful.
30057 Compiling your program with the -
30061 \begin_layout Standard
30071 \begin_inset LatexCommand \index{-\/-dumpall}
30075 option can sometimes be useful in locating optimization problems.
30076 When reporting a bug please make sure you:
30079 \begin_layout Enumerate
30080 Attach the code you are compiling with SDCC.
30084 \begin_layout Enumerate
30085 Specify the exact command you use to run SDCC, or attach your Makefile.
30089 \begin_layout Enumerate
30090 Specify the SDCC version (type "
30096 "), your platform, and operating system.
30100 \begin_layout Enumerate
30101 Provide an exact copy of any error message or incorrect output.
30105 \begin_layout Enumerate
30106 Put something meaningful in the subject of your message.
30109 \begin_layout Standard
30110 Please attempt to include these 5 important parts, as applicable, in all
30111 requests for support or when reporting any problems or bugs with SDCC.
30112 Though this will make your message lengthy, it will greatly improve your
30113 chance that SDCC users and developers will be able to help you.
30114 Some SDCC developers are frustrated by bug reports without code provided
30115 that they can use to reproduce and ultimately fix the problem, so please
30116 be sure to provide sample code if you are reporting a bug!
30119 \begin_layout Standard
30120 Please have a short check that you are using a recent version of SDCC and
30121 the bug is not yet known.
30122 This is the link for reporting bugs:
30123 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
30128 With SDCC on average having more than 200 downloads
30129 \begin_inset LatexCommand \index{download}
30133 on sourceforge per day
30137 \begin_layout Standard
30138 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
30139 between 2002 and 2005.
30140 This does not include other methods of distribution.
30145 there must be some users.
30146 So it's not exactly easy to find a new bug.
30147 If you find one we need it:
30149 reporting bugs is good
30154 \begin_layout Section
30155 Requesting Features
30156 \begin_inset LatexCommand \label{sub:Requesting-Features}
30161 \begin_inset LatexCommand \index{Feature request}
30166 \begin_inset LatexCommand \index{Requesting features}
30173 \begin_layout Standard
30174 Like bug reports feature requests are forwarded to the developer mailing
30176 This is the link for requesting features:
30177 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30184 \begin_layout Section
30188 \begin_layout Standard
30189 Like bug reports contributed patches are forwarded to the developer mailing
30191 This is the link for submitting patches
30192 \begin_inset LatexCommand \index{Patch submission}
30197 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
30204 \begin_layout Standard
30205 You need to specify some parameters to the
30209 command for the patches to be useful.
30210 If you modified more than one file a patch created f.e.
30215 \begin_inset Quotes sld
30218 diff -Naur unmodified_directory modified_directory >my_changes.patch
30219 \begin_inset Quotes srd
30225 will be fine, otherwise
30229 \begin_inset Quotes sld
30232 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
30233 \begin_inset Quotes srd
30243 \begin_layout Section
30247 \begin_layout Standard
30248 These links should take you directly to the
30249 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
30257 \begin_layout Standard
30258 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
30259 automated messages (mid 2003)
30265 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
30270 \begin_inset LatexCommand \index{Mailing list(s)}
30274 and forums are archived and searchable so if you are lucky someone already
30275 had a similar problem.
30276 While mails to the lists themselves are delivered promptly their web front
30277 end on sourceforge sometimes shows a severe time lag (up to several weeks),
30278 if you're seriously using SDCC please consider subscribing to the lists.
30281 \begin_layout Section
30285 \begin_layout Standard
30286 You can follow the status of the Subversion version
30287 \begin_inset LatexCommand \index{version}
30291 of SDCC by watching the Changelog
30292 \begin_inset LatexCommand \index{Changelog}
30296 in the Subversion repository
30299 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30306 \begin_layout Section
30307 Subversion Source Code Repository
30310 \begin_layout Standard
30317 or the filenames of the snapshot versions of SDCC include date and its
30319 \begin_inset LatexCommand \index{Subversion code repository}
30324 Subversion allows to download the source of recent or previous versions
30326 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
30330 (by number or by date).
30331 An on-line source code browser and detailled instructions are also available
30333 SDCC versions starting from 1999 up to now are available (currently the
30334 versions prior to the conversion from cvs
30335 \begin_inset LatexCommand \index{cvs|see{Subversion}}
30339 to Subversion (April 2006) are either by accessible by Subversion or by
30343 \begin_layout Section
30345 \begin_inset LatexCommand \index{Release policy}
30352 \begin_layout Standard
30353 Historically there often were long delays between official releases and
30354 the sourceforge download area tends to get not updated at all.
30355 Excuses in the past might have referred to problems with live range analysis,
30356 but as this was fixed a while ago, the current problem is that another
30357 excuse has to be found.
30358 Kidding aside, we have to get better there! On the other hand there are
30359 daily snapshots available at
30360 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
30364 , and you can always build the very last version (hopefully with many bugs
30365 fixed, and features added) from the source code available at
30366 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
30372 \begin_inset LatexCommand \index{wiki}
30377 \begin_inset LatexCommand \index{Release wiki}
30382 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
30386 also holds some information about past and future releases.
30389 \begin_layout Section
30391 \begin_inset LatexCommand \index{Examples}
30398 \begin_layout Standard
30399 You'll find some small examples in the directory
30401 sdcc/device/examples/.
30404 More examples and libraries are available at
30406 The SDCC Open Knowledge Resource
30407 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
30414 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
30421 \begin_layout Standard
30422 \begin_inset Note Comment
30425 \begin_layout Standard
30426 I did insert a reference to Paul's web site here although it seems rather
30427 dedicated to a specific 8032 board (I think it's okay because it f.e.
30428 shows LCD/Harddisc interface and has a free 8051 monitor.
30429 Independent 8032 board vendors face hard competition of heavily subsidized
30430 development boards anyway).
30433 \begin_layout Standard
30434 Maybe we should include some links to real world applications.
30435 Preferably pointer to pointers (one for each architecture) so this stays
30444 \begin_layout Section
30446 \begin_inset LatexCommand \label{sec:Quality-control}
30451 \begin_inset LatexCommand \index{Quality control}
30458 \begin_layout Standard
30459 The compiler is passed through nightly compile and build checks.
30465 \begin_inset LatexCommand \index{Regression test}
30469 check that SDCC itself compiles flawlessly on several host platforms (i386,
30470 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
30471 the quality of the code generated by SDCC by running the code for several
30472 target platforms through simulators.
30473 The regression test suite comprises more than 100 files which expand to
30474 more than 500 test cases which include more than 4500 tests.
30475 The results of these tests are published daily on SDCC's snapshot page
30476 (click on the red or green symbols on the right side of
30477 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
30484 \begin_layout Standard
30485 There is a separate document
30488 \begin_inset LatexCommand \index{Test suite}
30495 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30499 about the regression test suite.
30502 \begin_layout Standard
30503 You'll find the test code in the directory
30505 sdcc/support/regression
30508 You can run these tests manually by running
30512 in this directory (or f.e.
30517 \begin_inset Quotes sld
30521 \begin_inset Quotes srd
30527 if you don't want to run the complete tests).
30528 The test code might also be interesting if you want to look for examples
30529 \begin_inset LatexCommand \index{Examples}
30533 checking corner cases of SDCC or if you plan to submit patches
30534 \begin_inset LatexCommand \index{Patch submission}
30541 \begin_layout Standard
30542 The 14bit pic port uses a different set of regression tests
30543 \begin_inset LatexCommand \index{Regression test (PIC14)}
30547 , you'll find them in the directory
30549 sdcc/src/regression
30554 \begin_layout Section
30555 Use of SDCC in Education
30558 \begin_layout Standard
30567 \begin_layout Standard
30568 the phrase "use in education" might evoke the association "
30572 fit for use in education".
30573 This connotation is not intended but nevertheless risked as the licensing
30574 of SDCC makes it difficult to offer educational discounts
30580 If your rationales are to:
30583 \begin_layout Enumerate
30584 give students a chance to understand the
30588 steps of code generation
30591 \begin_layout Enumerate
30592 have a curriculum that can be extended for years.
30593 Then you could use an fpga board as target and your curriculum will seamlessly
30594 extend from logic synthesis (
30595 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
30600 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
30604 ), over assembly programming, to C to FPGA compilers (
30605 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
30612 \begin_layout Enumerate
30613 be able to insert excursions about skills like using a revision control
30614 system, submitting/applying patches, using a type-setting (as opposed to
30615 word-processing) engine LyX/LaTeX, using
30616 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
30621 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
30625 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
30626 Source Software, CPU simulation, compiler regression tests
30627 \begin_inset LatexCommand \index{Regression test}
30634 And if there should be a shortage of ideas then you can always point students
30635 to the ever-growing feature request list
30636 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30643 \begin_layout Enumerate
30644 not tie students to a specific host platform and instead allow them to use
30649 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
30651 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
30658 \begin_layout Enumerate
30659 not encourage students to use illegal copies of educational software
30662 \begin_layout Enumerate
30663 be immune to licensing/availability/price changes of the chosen tool chain
30666 \begin_layout Enumerate
30667 be able to change to a new target platform without having to adopt a new
30671 \begin_layout Enumerate
30672 have complete control over and insight into the tool chain
30675 \begin_layout Enumerate
30676 make your students aware about the pros and cons of open source software
30680 \begin_layout Enumerate
30681 give back to the public as you are probably at least partially publically
30685 \begin_layout Enumerate
30686 give students a chance to publically prove their skills and to possibly
30687 see a world wide impact
30690 \begin_layout Standard
30691 then SDCC is probably among the first choices.
30692 Well, probably SDCC might be the only choice.
30695 \begin_layout Standard
30701 \begin_layout Chapter
30702 SDCC Technical Data
30705 \begin_layout Section
30707 \begin_inset LatexCommand \index{Optimizations}
30714 \begin_layout Standard
30715 SDCC performs a host of standard optimizations in addition to some MCU specific
30720 \begin_layout Subsection
30721 Sub-expression Elimination
30722 \begin_inset LatexCommand \index{Subexpression elimination}
30729 \begin_layout Standard
30730 The compiler does local and
30749 \begin_layout Verse
30757 \begin_layout Standard
30758 will be translated to
30761 \begin_layout Verse
30771 \begin_layout Standard
30772 Some subexpressions are not as obvious as the above example, e.g.:
30775 \begin_layout Verse
30783 \begin_layout Standard
30784 In this case the address arithmetic a->b[i] will be computed only once;
30785 the equivalent code in C would be.
30788 \begin_layout Verse
30798 \begin_layout Standard
30799 The compiler will try to keep these temporary variables in registers.
30802 \begin_layout Subsection
30803 Dead-Code Elimination
30804 \begin_inset LatexCommand \index{Dead-code elimination}
30811 \begin_layout Verse
30826 i = 1; \InsetSpace ~
30835 global = 1;\InsetSpace ~
30849 global = 3;\InsetSpace ~
30855 \begin_layout Standard
30859 \begin_layout Verse
30875 \begin_layout Subsection
30877 \begin_inset LatexCommand \index{Copy propagation}
30884 \begin_layout Verse
30908 \begin_layout Standard
30912 \begin_layout Verse
30936 \begin_layout Standard
30937 Note: the dead stores created by this copy propagation will be eliminated
30938 by dead-code elimination.
30941 \begin_layout Subsection
30943 \begin_inset LatexCommand \index{Loop optimization}
30948 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
30955 \begin_layout Standard
30956 Two types of loop optimizations are done by SDCC
30964 of loop induction variables.
30965 In addition to the strength reduction the optimizer marks the induction
30966 variables and the register allocator tries to keep the induction variables
30967 in registers for the duration of the loop.
30968 Because of this preference of the register allocator
30969 \begin_inset LatexCommand \index{Register allocation}
30973 , loop induction optimization causes an increase in register pressure, which
30974 may cause unwanted spilling of other temporary variables into the stack
30975 \begin_inset LatexCommand \index{stack}
30980 The compiler will generate a warning message when it is forced to allocate
30981 extra space either on the stack or data space.
30982 If this extra space allocation is undesirable then induction optimization
30983 can be eliminated either for the entire source file (with -
30987 \begin_layout Standard
30996 -noinduction option) or for a given function only using #pragma\InsetSpace ~
30998 \begin_inset LatexCommand \index{\#pragma noinduction}
31009 \begin_layout Verse
31012 for (i = 0 ; i < 100 ; i ++)
31021 \begin_layout Standard
31025 \begin_layout Verse
31030 for (i = 0; i < 100; i++)
31039 \begin_layout Standard
31040 As mentioned previously some loop invariants are not as apparent, all static
31041 address computations are also moved out of the loop.
31046 \begin_inset LatexCommand \index{Strength reduction}
31050 , this optimization substitutes an expression by a cheaper expression:
31053 \begin_layout Verse
31056 for (i=0;i < 100; i++)
31065 \begin_layout Standard
31069 \begin_layout Verse
31076 for (i=0;i< 100;i++) {
31082 ar[itemp1] = itemp2;
31100 \begin_layout Standard
31101 The more expensive multiplication
31102 \begin_inset LatexCommand \index{Multiplication}
31106 is changed to a less expensive addition.
31109 \begin_layout Subsection
31111 \begin_inset LatexCommand \index{Loop reversing}
31118 \begin_layout Standard
31119 This optimization is done to reduce the overhead of checking loop boundaries
31120 for every iteration.
31121 Some simple loops can be reversed and implemented using a
31122 \begin_inset Quotes eld
31125 decrement and jump if not zero
31126 \begin_inset Quotes erd
31130 SDCC checks for the following criterion to determine if a loop is reversible
31131 (note: more sophisticated compilers use data-dependency analysis to make
31132 this determination, SDCC uses a more simple minded analysis).
31135 \begin_layout Itemize
31136 The 'for' loop is of the form
31142 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
31152 \begin_layout Itemize
31153 The <for body> does not contain
31154 \begin_inset Quotes eld
31158 \begin_inset Quotes erd
31162 \begin_inset Quotes erd
31168 \begin_layout Itemize
31169 All goto's are contained within the loop.
31172 \begin_layout Itemize
31173 No function calls within the loop.
31176 \begin_layout Itemize
31177 The loop control variable <sym> is not assigned any value within the loop
31180 \begin_layout Itemize
31181 The loop control variable does NOT participate in any arithmetic operation
31185 \begin_layout Itemize
31186 There are NO switch statements in the loop.
31189 \begin_layout Subsection
31190 Algebraic Simplifications
31193 \begin_layout Standard
31194 SDCC does numerous algebraic simplifications, the following is a small sub-set
31195 of these optimizations.
31198 \begin_layout Verse
31201 i = j + 0;\InsetSpace ~
31205 /* changed to: */\InsetSpace ~
31211 i /= 2;\InsetSpace ~
31218 /* changed to: */\InsetSpace ~
31225 = j - j;\InsetSpace ~
31229 /* changed to: */\InsetSpace ~
31235 i = j / 1;\InsetSpace ~
31239 /* changed to: */\InsetSpace ~
31246 \begin_layout Standard
31247 Note the subexpressions
31248 \begin_inset LatexCommand \index{Subexpression}
31252 given above are generally introduced by macro expansions or as a result
31253 of copy/constant propagation.
31256 \begin_layout Subsection
31257 'switch' Statements
31258 \begin_inset LatexCommand \label{sub:'switch'-Statements}
31263 \begin_inset LatexCommand \index{switch statement}
31270 \begin_layout Standard
31271 SDCC can optimize switch statements to jump tables
31272 \begin_inset LatexCommand \index{jump tables}
31277 It makes the decision based on an estimate of the generated code size.
31278 SDCC is quite liberal in the requirements for jump table generation:
31281 \begin_layout Itemize
31282 The labels need not be in order, and the starting number need not be one
31283 or zero, the case labels are in numerical sequence or not too many case
31284 labels are missing.
31288 \begin_layout Verse
31291 switch(i) {\InsetSpace ~
31322 case 4: ...\InsetSpace ~
31354 case 5: ...\InsetSpace ~
31386 case 3: ...\InsetSpace ~
31417 case 6: ...\InsetSpace ~
31449 case 7: ...\InsetSpace ~
31481 case 8: ...\InsetSpace ~
31513 case 9: ...\InsetSpace ~
31545 case 10: ...\InsetSpace ~
31576 case 11: ...\InsetSpace ~
31643 \begin_layout Standard
31644 Both the above switch statements will be implemented using a jump-table.
31645 The example to the right side is slightly more efficient as the check for
31646 the lower boundary of the jump-table is not needed.
31650 \begin_layout Itemize
31651 The number of case labels is not larger than supported by the target architectur
31655 \begin_layout Itemize
31656 If the case labels are not in numerical sequence ('gaps' between cases)
31657 SDCC checks whether a jump table with additionally inserted dummy cases
31658 is still attractive.
31662 \begin_layout Itemize
31663 If the starting number is not zero and a check for the lower boundary of
31664 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
31669 \begin_layout Standard
31670 Switch statements which have large gaps in the numeric sequence or those
31671 that have too many case labels can be split into more than one switch statement
31672 for efficient code generation, e.g.:
31675 \begin_layout Verse
31753 \begin_layout Standard
31754 If the above switch statement is broken down into two switch statements
31757 \begin_layout Verse
31800 \begin_layout Standard
31804 \begin_layout Verse
31847 \begin_layout Standard
31848 then both the switch statements will be implemented using jump-tables whereas
31849 the unmodified switch statement will not be.
31852 \begin_layout Standard
31853 \begin_inset Note Comment
31856 \begin_layout Standard
31857 There might be reasons which SDCC cannot know about to either favour or
31858 not favour jump tables.
31859 If the target system has to be as quick for the last switch case as for
31860 the first (pro jump table), or if the switch argument is known to be zero
31861 in the majority of the cases (contra jump table).
31869 \begin_layout Standard
31870 The pragma nojtbound
31871 \begin_inset LatexCommand \index{\#pragma nojtbound}
31875 can be used to turn off checking the
31888 It has no effect if a default label is supplied.
31889 Use of this pragma is dangerous: if the switch
31890 \begin_inset LatexCommand \index{switch statement}
31894 argument is not matched by a case statement the processor will happily
31898 \begin_layout Subsection
31899 Bit-shifting Operations
31900 \begin_inset LatexCommand \index{Bit shifting}
31907 \begin_layout Standard
31908 Bit shifting is one of the most frequently used operation in embedded programmin
31910 SDCC tries to implement bit-shift operations in the most efficient way
31914 \begin_layout Verse
31927 \begin_layout Standard
31928 generates the following code:
31931 \begin_layout Verse
31946 \begin_layout Standard
31947 In general SDCC will never setup a loop if the shift count is known.
31951 \begin_layout Verse
31964 \begin_layout Standard
31968 \begin_layout Verse
31992 \begin_layout Subsection
31994 \begin_inset LatexCommand \index{Bit rotation}
32001 \begin_layout Standard
32002 A special case of the bit-shift operation is bit rotation
32003 \begin_inset LatexCommand \index{rotating bits}
32007 , SDCC recognizes the following expression to be a left bit-rotation:
32010 \begin_layout Verse
32018 char i;\InsetSpace ~
32029 /* unsigned is needed for rotation */
32034 i = ((i << 1) | (i >> 7));
32043 \begin_layout Standard
32044 will generate the following code:
32047 \begin_layout Verse
32064 \begin_layout Standard
32065 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32066 ns of this case will also be recognized as bit-rotation, i.e.:
32069 \begin_layout Verse
32072 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32075 \begin_layout Subsection
32076 Nibble and Byte Swapping
32079 \begin_layout Standard
32080 Other special cases of the bit-shift operations are nibble or byte swapping
32081 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32085 , SDCC recognizes the following expressions:
32088 \begin_layout Verse
32109 i = ((i << 4) | (i >> 4));
32115 j = ((j << 8) | (j >> 8));
32118 \begin_layout Standard
32119 and generates a swap instruction for the nibble swapping
32120 \begin_inset LatexCommand \index{Nibble swapping}
32124 or move instructions for the byte swapping
32125 \begin_inset LatexCommand \index{Byte swapping}
32131 \begin_inset Quotes sld
32135 \begin_inset Quotes srd
32138 example can be used to convert from little to big-endian or vice versa.
32139 If you want to change the endianness of a
32143 integer you have to cast to
32150 \begin_layout Standard
32151 Note that SDCC stores numbers in little-endian
32155 \begin_layout Standard
32156 Usually 8-bit processors don't care much about endianness.
32157 This is not the case for the standard 8051 which only has an instruction
32163 \begin_inset LatexCommand \index{DPTR}
32171 so little-endian is the more efficient byte order.
32177 \begin_inset LatexCommand \index{little-endian}
32182 \begin_inset LatexCommand \index{Endianness}
32187 lowest order first).
32190 \begin_layout Subsection
32192 \begin_inset LatexCommand \index{Highest Order Bit}
32197 \begin_inset LatexCommand \index{Any Order Bit}
32204 \begin_layout Standard
32205 It is frequently required to obtain the highest order bit of an integral
32206 type (long, int, short or char types).
32207 Also obtaining any other order bit is not uncommon.
32208 SDCC recognizes the following expressions to yield the highest order bit
32209 and generates optimized code for it, e.g.:
32212 \begin_layout Verse
32223 unsigned char hob1, aob1;
32227 bit hob2, hob3, aob2,
32237 hob1 = (gint >> 15) & 1;
32241 hob2 = (gint >> 15) & 1;
32245 hob3 = gint & 0x8000;
32250 aob1 = (gint >> 9) & 1;
32254 aob2 = (gint >> 8) & 1;
32258 aob3 = gint & 0x0800;
32268 \begin_layout Standard
32269 will generate the following code:
32272 \begin_layout Verse
32303 000A E5*01\InsetSpace ~
32330 000C 23\InsetSpace ~
32361 000D 54 01\InsetSpace ~
32389 000F F5*02\InsetSpace ~
32444 0011 E5*01\InsetSpace ~
32472 0013 33\InsetSpace ~
32502 0014 92*00\InsetSpace ~
32558 0016 E5*01\InsetSpace ~
32585 0018 33\InsetSpace ~
32615 0019 92*01\InsetSpace ~
32671 001B E5*01\InsetSpace ~
32730 001E 54 01\InsetSpace ~
32757 0020 F5*03\InsetSpace ~
32813 0022 E5*01\InsetSpace ~
32840 0024 13\InsetSpace ~
32870 0025 92*02\InsetSpace ~
32926 0027 E5*01\InsetSpace ~
32981 002B 92*03\InsetSpace ~
33009 \begin_layout Standard
33010 Other variations of these cases however will
33015 They are standard C expressions, so I heartily recommend these be the only
33016 way to get the highest order bit, (it is portable).
33017 Of course it will be recognized even if it is embedded in other expressions,
33021 \begin_layout Verse
33024 xyz = gint + ((gint >> 15) & 1);
33027 \begin_layout Standard
33028 will still be recognized.
33031 \begin_layout Subsection
33033 \begin_inset LatexCommand \index{Higher Order Byte}
33037 / Higher Order Word
33038 \begin_inset LatexCommand \index{Higher Order Word}
33045 \begin_layout Standard
33046 It is also frequently required to obtain a higher order byte or word of
33047 a larger integral type (long, int or short types).
33048 SDCC recognizes the following expressions to yield the higher order byte
33049 or word and generates optimized code for it, e.g.:
33052 \begin_layout Verse
33057 unsigned long int glong;
33065 unsigned char hob1,
33070 unsigned int how1, how2;
33079 hob1 = (gint >> 8) & 0xFF;
33083 hob2 = glong >> 24;
33087 how1 = (glong >> 16) & 0xFFFF;
33102 \begin_layout Standard
33103 will generate the following code:
33106 \begin_layout Verse
33137 0037 85*01*06\InsetSpace ~
33159 _foo_hob1_1_1,(_gint + 1)
33190 003A 85*05*07\InsetSpace ~
33212 _foo_hob2_1_1,(_glong + 3)
33242 003D 85*04*08\InsetSpace ~
33265 _foo_how1_1_1,(_glong + 2)
33267 0040 85*05*09\InsetSpace ~
33292 0043 85*03*0A\InsetSpace ~
33314 _foo_how2_1_1,(_glong + 1)
33316 0046 85*04*0B\InsetSpace ~
33339 (_foo_how2_1_1 + 1),(_glong + 2)
33342 \begin_layout Standard
33343 Again, variations of these cases may
33348 They are standard C expressions, so I heartily recommend these be the only
33349 way to get the higher order byte/word, (it is portable).
33350 Of course it will be recognized even if it is embedded in other expressions,
33354 \begin_layout Verse
33357 xyz = gint + ((gint >> 8) & 0xFF);
33360 \begin_layout Standard
33361 will still be recognized.
33364 \begin_layout Subsection
33366 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
33371 \begin_inset LatexCommand \index{Peephole optimizer}
33378 \begin_layout Standard
33379 The compiler uses a rule based, pattern matching and re-writing mechanism
33380 for peep-hole optimization.
33385 a peep-hole optimizer by Christopher W.
33386 Fraser (cwfraser\InsetSpace ~
33389 A default set of rules are compiled into the compiler, additional rules
33390 may be added with the
33396 \begin_layout Standard
33406 \begin_inset LatexCommand \index{-\/-peep-file}
33413 The rule language is best illustrated with examples.
33416 \begin_layout Verse
33438 \begin_layout Standard
33439 The above rule will change the following assembly
33440 \begin_inset LatexCommand \index{Assembler routines}
33447 \begin_layout Verse
33455 \begin_layout Standard
33459 \begin_layout Verse
33465 \begin_layout Standard
33466 Note: All occurrences of a
33470 (pattern variable) must denote the same string.
33471 With the above rule, the assembly sequence:
33474 \begin_layout Verse
33482 \begin_layout Standard
33483 will remain unmodified.
33487 Other special case optimizations may be added by the
33494 \begin_layout Standard
33507 some variants of the 8051 MCU
33508 \begin_inset LatexCommand \index{MCS51 variants}
33521 The following two rules will change all
33538 \begin_layout Verse
33541 replace { lcall %1 } by { acall %1 }
33543 replace { ljmp %1 } by { ajmp %1 }
33546 \begin_layout Standard
33549 inline-assembler code
33551 is also passed through the peep hole optimizer, thus the peephole optimizer
33552 can also be used as an assembly level macro expander.
33553 The rules themselves are MCU dependent whereas the rule language infra-structur
33554 e is MCU independent.
33555 Peephole optimization rules for other MCU can be easily programmed using
33560 The syntax for a rule is as follows:
33563 \begin_layout Verse
33566 rule := replace [ restart ] '{' <assembly sequence> '
33604 <assembly sequence> '
33622 '}' [if <functionName> ] '
33627 \begin_layout Standard
33628 <assembly sequence> := assembly instruction (each instruction including
33629 labels must be on a separate line).
33633 The optimizer will apply to the rules
33634 one by one from the top in the sequence of their appearance, it will terminate
33635 when all rules are exhausted.
33636 If the 'restart' option is specified, then the optimizer will start matching
33637 the rules again from the top, this option for a rule is expensive (performance)
33638 , it is intended to be used in situations where a transformation will trigger
33639 the same rule again.
33640 An example of this (not a good one, it has side effects) is the following
33644 \begin_layout Verse
33664 \begin_layout Standard
33665 Note that the replace pattern cannot be a blank, but can be a comment line.
33666 Without the 'restart' option only the innermost 'pop' 'push' pair would
33667 be eliminated, i.e.:
33670 \begin_layout Verse
33682 \begin_layout Standard
33686 \begin_layout Verse
33696 \begin_layout Standard
33701 the restart option the rule will be applied again to the resulting code
33702 and then all the pop-push pairs will be eliminated to yield:
33705 \begin_layout Verse
33713 \begin_layout Standard
33714 A conditional function can be attached to a rule.
33715 Attaching rules are somewhat more involved, let me illustrate this with
33719 \begin_layout Verse
33743 \begin_layout Standard
33744 The optimizer does a look-up of a function name table defined in function
33749 in the source file SDCCpeeph.c, with the name
33754 If it finds a corresponding entry the function is called.
33755 Note there can be no parameters specified for these functions, in this
33760 is crucial, since the function
33764 expects to find the label in that particular variable (the hash table containin
33765 g the variable bindings is passed as a parameter).
33766 If you want to code more such functions, take a close look at the function
33767 labelInRange and the calling mechanism in source file SDCCpeeph.c.
33768 Currently implemented are
33770 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
33771 24bitMode, portIsDS390, 24bitModeAndPortDS390
33780 \begin_layout Standard
33781 I know this whole thing is a little kludgey, but maybe some day we will
33782 have some better means.
33783 If you are looking at this file, you will see the default rules that are
33784 compiled into the compiler, you can add your own rules in the default set
33785 there if you get tired of specifying the -
33789 \begin_layout Standard
33801 \begin_layout Section
33803 \begin_inset LatexCommand \index{ANSI-compliance}
33808 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
33815 \begin_layout Standard
33816 The latest publically available version of the standard
33818 ISO/IEC 9899 - Programming languages - C
33820 should be available at:
33821 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
33830 \begin_layout Standard
33831 Deviations from the compliance:
33834 \begin_layout Itemize
33835 functions are not reentrant
33836 \begin_inset LatexCommand \index{reentrant}
33840 unless explicitly declared as such or the
33846 \begin_layout Standard
33856 \begin_inset LatexCommand \index{-\/-stack-auto}
33862 command line option is specified.
33865 \begin_layout Itemize
33867 \begin_inset LatexCommand \index{struct}
33872 \begin_inset LatexCommand \index{union}
33876 cannot be assigned values directly, cannot be passed as function parameters
33877 or assigned to each other and cannot be a return value
33878 \begin_inset LatexCommand \index{return value}
33882 from a function, e.g.:
33886 \begin_layout Verse
33909 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
33928 s parms) /* invalid in SDCC although allowed in ANSI */
33950 return rets; /* is invalid in SDCC although allowed in ANSI */
33956 \begin_layout Itemize
33957 initialization of structure arrays must be fully braced.
33961 \begin_layout Verse
33964 struct s { char x } a[] = {1, 2};\InsetSpace ~
33969 /* invalid in SDCC */
33972 } a[] = {{1}, {2}}; /* OK */
33976 \begin_layout Itemize
33978 \begin_inset LatexCommand \index{long long (not supported)}
33983 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
33990 \begin_layout Itemize
33992 \begin_inset LatexCommand \index{double (not supported)}
33996 ' precision floating point
33997 \begin_inset LatexCommand \index{Floating point support}
34004 \begin_layout Itemize
34006 \begin_inset LatexCommand \index{K\&R style}
34010 function declarations are NOT allowed.
34014 \begin_layout Verse
34017 foo(i,j) /* this old style of function declarations */
34019 int i,j; /* are valid
34020 in ANSI but not valid in SDCC */
34035 \begin_layout Itemize
34036 Most enhancements in C99 are not supported, f.e.:
34040 \begin_layout Verse
34045 \begin_inset LatexCommand \index{inline (not supported)}
34051 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34057 can be used as a work around */
34065 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34069 \begin_layout Itemize
34070 Certain words that are valid identifiers in the standard may be reserved
34071 words in SDCC unless the
34077 \begin_layout Standard
34087 \begin_inset LatexCommand \index{-\/-std-c89}
34095 \begin_layout Standard
34105 \begin_inset LatexCommand \index{-\/-std-c99}
34111 command line options are used.
34112 These may include (depending on the selected processor): 'at', 'banked',
34113 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
34114 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
34115 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
34117 Compliant equivalents of these keywords are always available in a form
34118 that begin with two underscores
34119 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
34124 '__data' instead of 'data'.
34127 \begin_layout Section
34128 Cyclomatic Complexity
34129 \begin_inset LatexCommand \index{Cyclomatic complexity}
34136 \begin_layout Standard
34137 Cyclomatic complexity of a function is defined as the number of independent
34138 paths the program can take during execution of the function.
34139 This is an important number since it defines the number test cases you
34140 have to generate to validate the function.
34141 The accepted industry standard for complexity number is 10, if the cyclomatic
34142 complexity reported by SDCC exceeds 10 you should think about simplification
34143 of the function logic.
34144 Note that the complexity level is not related to the number of lines of
34145 code in a function.
34146 Large functions can have low complexity, and small functions can have large
34152 SDCC uses the following formula to compute the complexity:
34157 \begin_layout Standard
34158 complexity = (number of edges in control flow graph) - (number of nodes
34159 in control flow graph) + 2;
34163 Having said that the industry standard is 10,
34164 you should be aware that in some cases it be may unavoidable to have a
34165 complexity level of less than 10.
34166 For example if you have switch statement with more than 10 case labels,
34167 each case label adds one to the complexity level.
34168 The complexity level is by no means an absolute measure of the algorithmic
34169 complexity of the function, it does however provide a good starting point
34170 for which functions you might look at for further optimization.
34173 \begin_layout Section
34174 Retargetting for other Processors
34177 \begin_layout Standard
34178 The issues for retargetting the compiler are far too numerous to be covered
34180 What follows is a brief description of each of the seven phases of the
34181 compiler and its MCU dependency.
34184 \begin_layout Itemize
34185 Parsing the source and building the annotated parse tree.
34186 This phase is largely MCU independent (except for the language extensions).
34187 Syntax & semantic checks are also done in this phase, along with some initial
34188 optimizations like back patching labels and the pattern matching optimizations
34189 like bit-rotation etc.
34192 \begin_layout Itemize
34193 The second phase involves generating an intermediate code which can be easy
34194 manipulated during the later phases.
34195 This phase is entirely MCU independent.
34196 The intermediate code generation assumes the target machine has unlimited
34197 number of registers, and designates them with the name iTemp.
34198 The compiler can be made to dump a human readable form of the code generated
34203 \begin_layout Standard
34215 \begin_layout Itemize
34216 This phase does the bulk of the standard optimizations and is also MCU independe
34218 This phase can be broken down into several sub-phases:
34222 Break down intermediate
34223 code (iCode) into basic blocks.
34225 Do control flow & data flow analysis on the
34228 Do local common subexpression elimination, then global subexpressio
34231 Dead code elimination
34235 If loop optimizations
34236 caused any changes then do 'global subexpression elimination' and 'dead
34237 code elimination' again.
34240 \begin_layout Itemize
34241 This phase determines the live-ranges; by live range I mean those iTemp
34242 variables defined by the compiler that still survive after all the optimization
34244 Live range analysis
34245 \begin_inset LatexCommand \index{Live range analysis}
34249 is essential for register allocation, since these computation determines
34250 which of these iTemps will be assigned to registers, and for how long.
34253 \begin_layout Itemize
34254 Phase five is register allocation.
34255 There are two parts to this process.
34259 The first part I call 'register packing'
34260 (for lack of a better term).
34261 In this case several MCU specific expression folding is done to reduce
34266 The second part is more MCU independent and deals with
34267 allocating registers to the remaining live ranges.
34268 A lot of MCU specific code does creep into this phase because of the limited
34269 number of index registers available in the 8051.
34272 \begin_layout Itemize
34273 The Code generation phase is (unhappily), entirely MCU dependent and very
34274 little (if any at all) of this code can be reused for other MCU.
34275 However the scheme for allocating a homogenized assembler operand for each
34276 iCode operand may be reused.
34279 \begin_layout Itemize
34280 As mentioned in the optimization section the peep-hole optimizer is rule
34281 based system, which can reprogrammed for other MCUs.
34284 \begin_layout Standard
34285 More information is available in a wiki
34286 \begin_inset LatexCommand \index{wiki}
34291 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
34295 ) and in the thread
34296 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
34303 \begin_layout Chapter
34305 \begin_inset LatexCommand \index{Compiler internals}
34312 \begin_layout Section
34313 The anatomy of the compiler
34314 \begin_inset LatexCommand \label{sub:The-anatomy-of}
34321 \begin_layout Standard
34324 This is an excerpt from an article published in Circuit Cellar Magazine
34330 It's a little outdated (the compiler is much more efficient now and user/develo
34331 per friendly), but pretty well exposes the guts of it all.
34337 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
34338 It is fairly easy to retarget for other 8-bit MCU.
34339 Here we take a look at some of the internals of the compiler.
34343 \begin_layout Paragraph*
34345 \begin_inset LatexCommand \index{Parsing}
34352 \begin_layout Standard
34353 Parsing the input source file and creating an AST (Annotated Syntax Tree
34354 \begin_inset LatexCommand \index{Annotated syntax tree}
34359 This phase also involves propagating types (annotating each node of the
34360 parse tree with type information) and semantic analysis.
34361 There are some MCU specific parsing rules.
34362 For example the storage classes, the extended storage classes are MCU specific
34363 while there may be a xdata storage class for 8051 there is no such storage
34364 class for z80 or Atmel AVR.
34365 SDCC allows MCU specific storage class extensions, i.e.
34366 xdata will be treated as a storage class specifier when parsing 8051 C
34367 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
34371 \begin_layout Paragraph*
34373 \begin_inset LatexCommand \index{iCode}
34380 \begin_layout Standard
34381 Intermediate code generation.
34382 In this phase the AST is broken down into three-operand form (iCode).
34383 These three operand forms are represented as doubly linked lists.
34384 ICode is the term given to the intermediate form generated by the compiler.
34385 ICode example section shows some examples of iCode generated for some simple
34386 C source functions.
34389 \begin_layout Paragraph*
34391 \begin_inset LatexCommand \index{Optimizations}
34398 \begin_layout Standard
34399 Bulk of the target independent optimizations is performed in this phase.
34400 The optimizations include constant propagation, common sub-expression eliminati
34401 on, loop invariant code movement, strength reduction of loop induction variables
34402 and dead-code elimination.
34405 \begin_layout Paragraph*
34406 Live range analysis
34407 \begin_inset LatexCommand \index{Live range analysis}
34414 \begin_layout Standard
34415 During intermediate code generation phase, the compiler assumes the target
34416 machine has infinite number of registers and generates a lot of temporary
34418 The live range computation determines the lifetime of each of these compiler-ge
34419 nerated temporaries.
34420 A picture speaks a thousand words.
34421 ICode example sections show the live range annotations for each of the
34423 It is important to note here, each iCode is assigned a number in the order
34424 of its execution in the function.
34425 The live ranges are computed in terms of these numbers.
34426 The from number is the number of the iCode which first defines the operand
34427 and the to number signifies the iCode which uses this operand last.
34430 \begin_layout Paragraph*
34431 Register Allocation
34432 \begin_inset LatexCommand \index{Register allocation}
34439 \begin_layout Standard
34440 The register allocation determines the type and number of registers needed
34442 In most MCUs only a few registers can be used for indirect addressing.
34443 In case of 8051 for example the registers R0 & R1 can be used to indirectly
34444 address the internal ram and DPTR to indirectly address the external ram.
34445 The compiler will try to allocate the appropriate register to pointer variables
34447 ICode example section shows the operands annotated with the registers assigned
34449 The compiler will try to keep operands in registers as much as possible;
34450 there are several schemes the compiler uses to do achieve this.
34451 When the compiler runs out of registers the compiler will check to see
34452 if there are any live operands which is not used or defined in the current
34453 basic block being processed, if there are any found then it will push that
34454 operand and use the registers in this block, the operand will then be popped
34455 at the end of the basic block.
34459 \begin_layout Standard
34460 There are other MCU specific considerations in this phase.
34461 Some MCUs have an accumulator; very short-lived operands could be assigned
34462 to the accumulator instead of a general-purpose register.
34465 \begin_layout Paragraph*
34469 \begin_layout Standard
34470 Figure II gives a table of iCode
34471 \begin_inset LatexCommand \index{iCode}
34475 operations supported by the compiler.
34476 The code generation involves translating these operations into corresponding
34477 assembly code for the processor.
34478 This sounds overly simple but that is the essence of code generation.
34479 Some of the iCode operations are generated on a MCU specific manner for
34480 example, the z80 port does not use registers to pass parameters so the
34481 SEND and RECV iCode operations will not be generated, and it also does
34482 not support JUMPTABLES.
34488 \begin_layout Standard
34492 \begin_inset Tabular
34493 <lyxtabular version="3" rows="39" columns="4">
34494 <features islongtable="true" headBottomDL="true">
34495 <column alignment="block" valignment="top" leftline="true" width="13col%">
34496 <column alignment="left" valignment="top" leftline="true" width="13col%">
34497 <column alignment="block" valignment="top" leftline="true" width="22col%">
34498 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
34499 <row topline="true" bottomline="true" endhead="true">
34500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34503 \begin_layout Standard
34509 \begin_inset LatexCommand \index{iCode}
34518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34521 \begin_layout Standard
34529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34532 \begin_layout Standard
34540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34543 \begin_layout Standard
34552 <row topline="true">
34553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34556 \begin_layout Standard
34564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34567 \begin_layout Standard
34570 IC_LEFT() IC_RESULT()
34575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34578 \begin_layout Standard
34586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34589 \begin_layout Standard
34592 IC_RESULT = ! IC_LEFT;
34598 <row topline="true">
34599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34602 \begin_layout Standard
34610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34613 \begin_layout Standard
34616 IC_LEFT() IC_RESULT()
34621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34624 \begin_layout Standard
34627 Bitwise complement of
34632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34635 \begin_layout Standard
34638 IC_RESULT = ~IC_LEFT;
34644 <row topline="true">
34645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34648 \begin_layout Standard
34656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34659 \begin_layout Standard
34662 IC_LEFT() IC_RESULT()
34667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34670 \begin_layout Standard
34673 Rotate right with carry
34678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34681 \begin_layout Standard
34684 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
34690 <row topline="true">
34691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34694 \begin_layout Standard
34702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34705 \begin_layout Standard
34708 IC_LEFT() IC_RESULT()
34713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34716 \begin_layout Standard
34719 Rotate left with carry
34724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34727 \begin_layout Standard
34730 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
34736 <row topline="true">
34737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34740 \begin_layout Standard
34748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34751 \begin_layout Standard
34754 IC_LEFT() IC_RESULT()
34759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34762 \begin_layout Standard
34765 Get the highest order bit of IC_LEFT
34770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34773 \begin_layout Standard
34776 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
34782 <row topline="true">
34783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34786 \begin_layout Standard
34794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34797 \begin_layout Standard
34800 IC_LEFT() IC_RESULT()
34805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34808 \begin_layout Standard
34816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34819 \begin_layout Standard
34822 IC_RESULT = - IC_LEFT;
34828 <row topline="true">
34829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34832 \begin_layout Standard
34840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34843 \begin_layout Standard
34851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34854 \begin_layout Standard
34857 Push the operand into stack
34862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34865 \begin_layout Standard
34874 <row topline="true">
34875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34878 \begin_layout Standard
34886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34889 \begin_layout Standard
34897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34900 \begin_layout Standard
34903 Pop the operand from the stack
34908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34911 \begin_layout Standard
34920 <row topline="true">
34921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34924 \begin_layout Standard
34932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34935 \begin_layout Standard
34938 IC_LEFT() IC_RESULT()
34943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34946 \begin_layout Standard
34949 Call the function represented by IC_LEFT
34954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34957 \begin_layout Standard
34960 IC_RESULT = IC_LEFT();
34966 <row topline="true">
34967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34970 \begin_layout Standard
34978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34981 \begin_layout Standard
34984 IC_LEFT() IC_RESULT()
34989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34992 \begin_layout Standard
34995 Call via function pointer
35000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35003 \begin_layout Standard
35006 IC_RESULT = (*IC_LEFT)();
35012 <row topline="true">
35013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35016 \begin_layout Standard
35024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35027 \begin_layout Standard
35035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35038 \begin_layout Standard
35041 Return the value in operand IC_LEFT
35046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35049 \begin_layout Standard
35058 <row topline="true">
35059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35062 \begin_layout Standard
35070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35073 \begin_layout Standard
35081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35084 \begin_layout Standard
35092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35095 \begin_layout Standard
35104 <row topline="true">
35105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35108 \begin_layout Standard
35116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35119 \begin_layout Standard
35127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35130 \begin_layout Standard
35138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35141 \begin_layout Standard
35150 <row topline="true">
35151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35154 \begin_layout Standard
35162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35165 \begin_layout Standard
35168 IC_LEFT() IC_RIGHT() IC_RESULT()
35173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35176 \begin_layout Standard
35184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35187 \begin_layout Standard
35190 IC_RESULT = IC_LEFT + IC_RIGHT
35196 <row topline="true">
35197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35200 \begin_layout Standard
35208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35211 \begin_layout Standard
35214 IC_LEFT() IC_RIGHT() IC_RESULT()
35219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35222 \begin_layout Standard
35230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35233 \begin_layout Standard
35236 IC_RESULT = IC_LEFT - IC_RIGHT
35242 <row topline="true">
35243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35246 \begin_layout Standard
35254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35257 \begin_layout Standard
35260 IC_LEFT() IC_RIGHT() IC_RESULT()
35265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35268 \begin_layout Standard
35276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35279 \begin_layout Standard
35282 IC_RESULT = IC_LEFT * IC_RIGHT;
35288 <row topline="true">
35289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35292 \begin_layout Standard
35300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35303 \begin_layout Standard
35306 IC_LEFT() IC_RIGHT() IC_RESULT()
35311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35314 \begin_layout Standard
35322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35325 \begin_layout Standard
35328 IC_RESULT = IC_LEFT / IC_RIGHT;
35334 <row topline="true">
35335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35338 \begin_layout Standard
35346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35349 \begin_layout Standard
35352 IC_LEFT() IC_RIGHT() IC_RESULT()
35357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35360 \begin_layout Standard
35368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35371 \begin_layout Standard
35374 IC_RESULT = IC_LEFT % IC_RIGHT;
35380 <row topline="true">
35381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35384 \begin_layout Standard
35392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35395 \begin_layout Standard
35398 IC_LEFT() IC_RIGHT() IC_RESULT()
35403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35406 \begin_layout Standard
35414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35417 \begin_layout Standard
35420 IC_RESULT = IC_LEFT < IC_RIGHT;
35426 <row topline="true">
35427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35430 \begin_layout Standard
35438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35441 \begin_layout Standard
35444 IC_LEFT() IC_RIGHT() IC_RESULT()
35449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35452 \begin_layout Standard
35460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35463 \begin_layout Standard
35466 IC_RESULT = IC_LEFT > IC_RIGHT;
35472 <row topline="true">
35473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35476 \begin_layout Standard
35484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35487 \begin_layout Standard
35490 IC_LEFT() IC_RIGHT() IC_RESULT()
35495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35498 \begin_layout Standard
35506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35509 \begin_layout Standard
35512 IC_RESULT = IC_LEFT == IC_RIGHT;
35518 <row topline="true">
35519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35522 \begin_layout Standard
35530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35533 \begin_layout Standard
35536 IC_LEFT() IC_RIGHT() IC_RESULT()
35541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35544 \begin_layout Standard
35547 Logical and operation
35552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35555 \begin_layout Standard
35558 IC_RESULT = IC_LEFT && IC_RIGHT;
35564 <row topline="true">
35565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35568 \begin_layout Standard
35576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35579 \begin_layout Standard
35582 IC_LEFT() IC_RIGHT() IC_RESULT()
35587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35590 \begin_layout Standard
35593 Logical or operation
35598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35601 \begin_layout Standard
35604 IC_RESULT = IC_LEFT || IC_RIGHT;
35610 <row topline="true">
35611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35614 \begin_layout Standard
35622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35625 \begin_layout Standard
35628 IC_LEFT() IC_RIGHT() IC_RESULT()
35633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35636 \begin_layout Standard
35644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35647 \begin_layout Standard
35650 IC_RESULT = IC_LEFT ^ IC_RIGHT;
35656 <row topline="true">
35657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35660 \begin_layout Standard
35668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35671 \begin_layout Standard
35674 IC_LEFT() IC_RIGHT() IC_RESULT()
35679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35682 \begin_layout Standard
35690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35693 \begin_layout Standard
35696 IC_RESULT = IC_LEFT | IC_RIGHT;
35702 <row topline="true">
35703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35706 \begin_layout Standard
35714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35717 \begin_layout Standard
35720 IC_LEFT() IC_RIGHT() IC_RESULT()
35725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35728 \begin_layout Standard
35736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35739 \begin_layout Standard
35742 IC_RESULT = IC_LEFT & IC_RIGHT;
35748 <row topline="true">
35749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35752 \begin_layout Standard
35760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35763 \begin_layout Standard
35766 IC_LEFT() IC_RIGHT() IC_RESULT()
35771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35774 \begin_layout Standard
35782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35785 \begin_layout Standard
35788 IC_RESULT = IC_LEFT << IC_RIGHT
35794 <row topline="true">
35795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35798 \begin_layout Standard
35806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35809 \begin_layout Standard
35812 IC_LEFT() IC_RIGHT() IC_RESULT()
35817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35820 \begin_layout Standard
35828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35831 \begin_layout Standard
35834 IC_RESULT = IC_LEFT >> IC_RIGHT
35840 <row topline="true">
35841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35844 \begin_layout Standard
35854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35857 \begin_layout Standard
35860 IC_LEFT() IC_RESULT()
35865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35868 \begin_layout Standard
35876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35879 \begin_layout Standard
35882 IC_RESULT = (*IC_LEFT);
35888 <row topline="true">
35889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35892 \begin_layout Standard
35900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35903 \begin_layout Standard
35906 IC_RIGHT() IC_RESULT()
35911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35914 \begin_layout Standard
35922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35925 \begin_layout Standard
35928 (*IC_RESULT) = IC_RIGHT;
35934 <row topline="true">
35935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35938 \begin_layout Standard
35946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35949 \begin_layout Standard
35952 IC_RIGHT() IC_RESULT()
35957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35960 \begin_layout Standard
35968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35971 \begin_layout Standard
35974 IC_RESULT = IC_RIGHT;
35980 <row topline="true">
35981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35984 \begin_layout Standard
35992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35995 \begin_layout Standard
35998 IC_COND IC_TRUE IC_LABEL
36003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36006 \begin_layout Standard
36010 If true label is present then jump to true label if condition is true else
36011 jump to false label if condition is false
36016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36019 \begin_layout Standard
36022 if (IC_COND) goto IC_TRUE;
36028 If (!IC_COND) goto IC_FALSE;
36034 <row topline="true">
36035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36038 \begin_layout Standard
36046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36049 \begin_layout Standard
36052 IC_LEFT() IC_RESULT()
36057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36060 \begin_layout Standard
36068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36071 \begin_layout Standard
36074 IC_RESULT = &IC_LEFT();
36080 <row topline="true">
36081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36084 \begin_layout Standard
36092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36095 \begin_layout Standard
36098 IC_JTCOND IC_JTLABELS
36103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36106 \begin_layout Standard
36109 Jump to list of labels depending on the value of JTCOND
36114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36117 \begin_layout Standard
36126 <row topline="true">
36127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36130 \begin_layout Standard
36138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36141 \begin_layout Standard
36144 IC_RIGHT() IC_LEFT() IC_RESULT()
36149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36152 \begin_layout Standard
36160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36163 \begin_layout Standard
36166 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
36172 <row topline="true">
36173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36176 \begin_layout Standard
36184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36187 \begin_layout Standard
36195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36198 \begin_layout Standard
36201 This is used for passing parameters in registers;
36203 move IC_LEFT to the next
36204 available parameter register.
36209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36212 \begin_layout Standard
36221 <row topline="true">
36222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36225 \begin_layout Standard
36233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36236 \begin_layout Standard
36244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36247 \begin_layout Standard
36250 This is used for receiving parameters passed in registers;
36253 in the next parameter register to IC_RESULT
36258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36261 \begin_layout Standard
36270 <row topline="true" bottomline="true">
36271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36274 \begin_layout Standard
36278 (some more have been added)
36283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36286 \begin_layout Standard
36292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36295 \begin_layout Standard
36301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36304 \begin_layout Standard
36328 \begin_layout Standard
36329 \begin_inset Note Comment
36332 \begin_layout Standard
36333 In the original article Figure II was announced to be downloadable on
36338 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
36346 \begin_layout Paragraph*
36348 \begin_inset LatexCommand \index{iCode}
36355 \begin_layout Standard
36356 This section shows some details of iCode.
36357 The example C code does not do anything useful; it is used as an example
36358 to illustrate the intermediate code generated by the compiler.
36361 \begin_layout Verse
36371 /* This function does nothing useful.
36378 for the purpose of explaining iCode */
36381 short function (data
36390 short i=10; \InsetSpace ~
36392 /* dead initialization eliminated */
36398 /* dead initialization eliminated */
36426 /* compiler detects i,j to be induction
36431 for (i = 0, j = 10 ; i < 10 ; i++, j
36437 \begin_layout Standard
36460 mul += i * 3; \InsetSpace ~
36462 /* this multiplication remains */
36469 j * 3;\InsetSpace ~
36471 /* this multiplication changed to addition */
36485 \begin_layout Standard
36486 In addition to the operands each iCode contains information about the filename
36487 and line it corresponds to in the source file.
36488 The first field in the listing should be interpreted as follows:
36493 Filename(linenumber: iCode Execution sequence number : ICode hash table
36494 key : loop depth of the iCode).
36499 Then follows the human readable form of the ICode operation.
36500 Each operand of this triplet form can be of three basic types a) compiler
36501 generated temporary b) user defined variable c) a constant value.
36502 Note that local variables and parameters are replaced by compiler generated
36505 \begin_inset LatexCommand \index{Live range analysis}
36509 are computed only for temporaries (i.e.
36510 live ranges are not computed for global variables).
36512 \begin_inset LatexCommand \index{Register allocation}
36516 are allocated for temporaries only.
36517 Operands are formatted in the following manner:
36522 Operand Name [lr live-from : live-to ] { type information } [ registers
36528 As mentioned earlier the live ranges are computed in terms of the execution
36529 sequence number of the iCodes, for example
36531 the iTemp0 is live from (i.e.
36532 first defined in iCode with execution sequence number 3, and is last used
36533 in the iCode with sequence number 5).
36534 For induction variables such as iTemp21 the live range computation extends
36535 the lifetime from the start to the end of the loop.
36537 The register allocator
36538 used the live range information to allocate registers, the same registers
36539 may be used for different temporaries if their live ranges do not overlap,
36540 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
36541 ranges do not overlap.
36542 In addition the allocator also takes into consideration the type and usage
36543 of a temporary, for example itemp6 is a pointer to near space and is used
36544 as to fetch data from (i.e.
36545 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
36546 Some short lived temporaries are allocated to special registers which have
36547 meaning to the code generator e.g.
36548 iTemp13 is allocated to a pseudo register CC which tells the back end that
36549 the temporary is used only for a conditional jump the code generation makes
36550 use of this information to optimize a compare and jump ICode.
36554 \begin_inset LatexCommand \index{Loop optimization}
36558 performed by the compiler.
36559 It can detect induction variables iTemp21(i) and iTemp23(j).
36560 Also note the compiler does selective strength reduction
36561 \begin_inset LatexCommand \index{Strength reduction}
36566 the multiplication of an induction variable in line 18 (gint = j * 3) is
36567 changed to addition, a new temporary iTemp17 is allocated and assigned
36568 a initial value, a constant 3 is then added for each iteration of the loop.
36569 The compiler does not change the multiplication
36570 \begin_inset LatexCommand \index{Multiplication}
36574 in line 17 however since the processor does support an 8 * 8 bit multiplication.
36577 Note the dead code elimination
36578 \begin_inset LatexCommand \index{Dead-code elimination}
36582 optimization eliminated the dead assignments in line 7 & 8 to I and sum
36588 \begin_layout Standard
36591 Sample.c (5:1:0:0) _entry($9) :
36594 \begin_layout Standard
36597 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
36600 \begin_layout Standard
36603 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
36606 \begin_layout Standard
36609 Sample.c(11:4:53:0) preHeaderLbl0($11) :
36612 \begin_layout Standard
36615 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
36619 \begin_layout Standard
36622 Sample.c(11:6:5:1) _whilecontinue_0($1) :
36625 \begin_layout Standard
36628 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
36632 \begin_layout Standard
36635 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36638 \begin_layout Standard
36641 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
36645 \begin_layout Standard
36648 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
36652 \begin_layout Standard
36655 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
36659 \begin_layout Standard
36662 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
36666 \begin_layout Standard
36669 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
36670 * int}[r0] + 0x2 {short}
36673 \begin_layout Standard
36676 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
36679 \begin_layout Standard
36682 Sample.c(11:17:21:0)_whilebreak_0($3) :
36685 \begin_layout Standard
36688 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
36691 \begin_layout Standard
36694 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
36697 \begin_layout Standard
36700 Sample.c(15:20:54:0)preHeaderLbl1($13) :
36703 \begin_layout Standard
36706 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
36709 \begin_layout Standard
36712 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
36715 \begin_layout Standard
36718 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
36721 \begin_layout Standard
36724 Sample.c(15:24:26:1)_forcond_0($4) :
36727 \begin_layout Standard
36730 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
36734 \begin_layout Standard
36737 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
36740 \begin_layout Standard
36743 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
36744 + ITemp21 [lr21:38]{short}[r4]
36747 \begin_layout Standard
36750 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
36754 \begin_layout Standard
36757 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
36758 + iTemp15 [lr29:30]{short}[r1]
36761 \begin_layout Standard
36764 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
36768 \begin_layout Standard
36771 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
36775 \begin_layout Standard
36778 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
36782 \begin_layout Standard
36785 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
36789 \begin_layout Standard
36792 Sample.c(19:38:47:1) goto _forcond_0($4)
36795 \begin_layout Standard
36798 Sample.c(19:39:48:0)_forbreak_0($7) :
36801 \begin_layout Standard
36804 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
36805 + ITemp11 [lr19:40]{short}[r3]
36808 \begin_layout Standard
36811 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
36814 \begin_layout Standard
36817 Sample.c(20:42:51:0)_return($8) :
36820 \begin_layout Standard
36823 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
36829 Finally the code generated for this function:
36834 \begin_layout Standard
36840 \begin_layout Standard
36846 \begin_layout Standard
36854 \begin_layout Standard
36860 \begin_layout Standard
36868 \begin_layout Standard
36874 \begin_layout Standard
36877 ; ----------------------------------------------
36880 \begin_layout Standard
36883 ; function function
36886 \begin_layout Standard
36889 ; ----------------------------------------------
36892 \begin_layout Standard
36898 \begin_layout Standard
36901 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
36904 \begin_layout Standard
36912 \begin_layout Standard
36915 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
36918 \begin_layout Standard
36926 \begin_layout Standard
36929 ;_whilecontinue_0($1) :
36932 \begin_layout Standard
36938 \begin_layout Standard
36941 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
36944 \begin_layout Standard
36947 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36950 \begin_layout Standard
36958 \begin_layout Standard
36966 \begin_layout Standard
36974 \begin_layout Standard
36982 \begin_layout Standard
36990 \begin_layout Standard
36998 \begin_layout Standard
37006 \begin_layout Standard
37012 \begin_layout Standard
37015 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37018 \begin_layout Standard
37026 \begin_layout Standard
37034 \begin_layout Standard
37037 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37040 \begin_layout Standard
37048 \begin_layout Standard
37056 \begin_layout Standard
37064 \begin_layout Standard
37072 \begin_layout Standard
37080 \begin_layout Standard
37088 \begin_layout Standard
37091 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
37094 \begin_layout Standard
37102 \begin_layout Standard
37110 \begin_layout Standard
37118 \begin_layout Standard
37126 \begin_layout Standard
37134 \begin_layout Standard
37137 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
37140 \begin_layout Standard
37148 \begin_layout Standard
37156 \begin_layout Standard
37164 \begin_layout Standard
37167 ; iTemp6 [lr5:16]{_near * int}[r0] =
37170 \begin_layout Standard
37173 ; iTemp6 [lr5:16]{_near * int}[r0] +
37176 \begin_layout Standard
37182 \begin_layout Standard
37190 \begin_layout Standard
37193 ; goto _whilecontinue_0($1)
37196 \begin_layout Standard
37204 \begin_layout Standard
37207 ; _whilebreak_0($3) :
37210 \begin_layout Standard
37216 \begin_layout Standard
37219 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37222 \begin_layout Standard
37230 \begin_layout Standard
37233 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37236 \begin_layout Standard
37244 \begin_layout Standard
37247 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37250 \begin_layout Standard
37258 \begin_layout Standard
37261 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37264 \begin_layout Standard
37272 \begin_layout Standard
37280 \begin_layout Standard
37283 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37286 \begin_layout Standard
37294 \begin_layout Standard
37302 \begin_layout Standard
37308 \begin_layout Standard
37314 \begin_layout Standard
37317 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
37320 \begin_layout Standard
37323 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37326 \begin_layout Standard
37334 \begin_layout Standard
37342 \begin_layout Standard
37350 \begin_layout Standard
37358 \begin_layout Standard
37366 \begin_layout Standard
37372 \begin_layout Standard
37375 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
37378 \begin_layout Standard
37381 ; iTemp21 [lr21:38]{short}[r4]
37384 \begin_layout Standard
37392 \begin_layout Standard
37400 \begin_layout Standard
37408 \begin_layout Standard
37411 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
37414 \begin_layout Standard
37422 \begin_layout Standard
37430 \begin_layout Standard
37438 \begin_layout Standard
37446 \begin_layout Standard
37449 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
37452 \begin_layout Standard
37455 ; iTemp15 [lr29:30]{short}[r1]
37458 \begin_layout Standard
37466 \begin_layout Standard
37474 \begin_layout Standard
37477 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
37480 \begin_layout Standard
37488 \begin_layout Standard
37496 \begin_layout Standard
37504 \begin_layout Standard
37512 \begin_layout Standard
37520 \begin_layout Standard
37528 \begin_layout Standard
37531 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
37534 \begin_layout Standard
37542 \begin_layout Standard
37550 \begin_layout Standard
37558 \begin_layout Standard
37566 \begin_layout Standard
37574 \begin_layout Standard
37582 \begin_layout Standard
37585 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
37588 \begin_layout Standard
37596 \begin_layout Standard
37599 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
37602 \begin_layout Standard
37610 \begin_layout Standard
37615 cjne r5,#0xff,00104$
37618 \begin_layout Standard
37626 \begin_layout Standard
37629 ; goto _forcond_0($4)
37632 \begin_layout Standard
37640 \begin_layout Standard
37643 ; _forbreak_0($7) :
37646 \begin_layout Standard
37652 \begin_layout Standard
37655 ; ret iTemp24 [lr40:41]{short}
37658 \begin_layout Standard
37666 \begin_layout Standard
37674 \begin_layout Standard
37682 \begin_layout Standard
37688 \begin_layout Standard
37694 \begin_layout Standard
37704 \begin_layout Section
37705 A few words about basic block successors, predecessors and dominators
37708 \begin_layout Standard
37709 Successors are basic blocks
37710 \begin_inset LatexCommand \index{Basic blocks}
37714 that might execute after this basic block.
37716 Predecessors are basic blocks
37717 that might execute before reaching this basic block.
37719 Dominators are basic
37720 blocks that WILL execute before reaching this basic block.
37725 \begin_layout Standard
37729 \begin_layout Standard
37733 \begin_layout Standard
37741 \begin_layout Standard
37745 \begin_layout Standard
37753 \begin_layout Standard
37759 \begin_layout Standard
37760 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
37763 \begin_layout Standard
37764 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
37767 \begin_layout Standard
37768 c) domVect of [BB4] = BB1 ...
37769 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
37773 \begin_layout Chapter
37777 \begin_layout Standard
37778 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
37788 Thanks to all the other volunteer developers who have helped with coding,
37789 testing, web-page creation, distribution sets, etc.
37790 You know who you are :-)
37798 Also thanks to Sourceforge
37799 \begin_inset LatexCommand \url{http://www.sf.net}
37803 which has hosted the project since 1999 and donates significant download
37804 bandwidth and probably more than
37808 \begin_layout Standard
37815 CPU cycles per day.
37818 \begin_inset Note Note
37821 \begin_layout Standard
37822 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
37823 minutes for (configure+make+regression test), and there is (i386, amd64,
37824 alpha, ppc64, (mingw32), sparc, macosx).
37833 \begin_layout Standard
37834 This document was initially written by Sandeep Dutta
37837 \begin_layout Standard
37838 All product names mentioned herein may be trademarks
37839 \begin_inset LatexCommand \index{Trademarks}
37843 of their respective companies.
37847 \begin_layout Section*
37851 \begin_layout Standard
37852 To avoid confusion, the installation and building options for SDCC itself
37853 (chapter 2) are not part of the index.
37856 \begin_layout Standard
37857 \begin_inset LatexCommand \printindex{}