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 sure 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
18849 \begin_layout Standard
18850 printf_tiny integer speed is data dependent, worst case is 0.33 ms
18861 <row bottomline="true">
18862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18865 \begin_layout Standard
18870 \begin_layout Standard
18871 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18880 \begin_layout Standard
18886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18889 \begin_layout Standard
18895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18898 \begin_layout Standard
18904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18907 \begin_layout Standard
18913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18916 \begin_layout Standard
18922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18925 \begin_layout Standard
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18934 \begin_layout Standard
18941 <row bottomline="true">
18942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18945 \begin_layout Standard
18950 \begin_layout Standard
18951 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18960 \begin_layout Standard
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18969 \begin_layout Standard
18975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18978 \begin_layout Standard
18984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18987 \begin_layout Standard
18993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18996 \begin_layout Standard
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19005 \begin_layout Standard
19011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19014 \begin_layout Standard
19028 \begin_layout Subsubsection
19030 \begin_inset LatexCommand \index{malloc.h}
19037 \begin_layout Standard
19038 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19039 using dynamic memory allocation
19040 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19045 \begin_inset LatexCommand \index{heap (malloc)}
19049 space of 1024 bytes is provided for malloc to allocate memory from.
19050 If you need a different heap size you need to recompile _heap.c with the
19051 required size defined in HEAP_SIZE.
19052 It is recommended to make a copy of this file into your project directory
19053 and compile it there with:
19056 \begin_layout Verse
19059 sdcc -c _heap.c -D HEAD_SIZE=2048
19062 \begin_layout Standard
19063 And then link it with:
19066 \begin_layout Verse
19069 sdcc main.rel _heap.rel
19072 \begin_layout Subsection
19073 Math functions (sinf, powf, sqrtf etc.)
19076 \begin_layout Subsubsection
19080 \begin_layout Standard
19081 See definitions in file <math.h>.
19084 \begin_layout Subsection
19088 \begin_layout Standard
19090 \begin_inset LatexCommand \index{Libraries}
19094 included in SDCC should have a license at least as liberal as the GNU Lesser
19095 General Public License
19096 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
19107 \begin_layout Standard
19108 \begin_inset Note Comment
19111 \begin_layout Standard
19112 license statements for the libraries are missing.
19113 sdcc/device/lib/ser_ir.c
19116 \begin_layout Standard
19118 come with a GPL (as opposed to LGPL) License - this will not be liberal
19119 enough for many embedded programmers.
19127 \begin_layout Standard
19128 If you have ported some library or want to share experience about some code
19130 falls into any of these categories Busses (I
19131 \begin_inset Formula $^{\textrm{2}}$
19134 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
19135 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
19136 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
19137 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
19142 would certainly like to hear about it.
19145 \begin_layout Standard
19146 Programmers coding for embedded systems are not especially famous for being
19147 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
19148 e these references are very valuable.
19149 Let's help to create a climate where information is shared.
19150 \begin_inset VSpace bigskip
19156 \begin_layout Section
19160 \begin_layout Subsection
19161 MCS51 Memory Models
19162 \begin_inset LatexCommand \index{Memory model}
19167 \begin_inset LatexCommand \index{MCS51 memory model}
19174 \begin_layout Subsubsection
19175 Small, Medium and Large
19178 \begin_layout Standard
19179 SDCC allows three memory models for MCS51 code,
19188 Modules compiled with different memory models should
19192 be combined together or the results would be unpredictable.
19193 The library routines supplied with the compiler are compiled as small,
19195 The compiled library modules are contained in separate directories as small,
19196 medium and large so that you can link to the appropriate set.
19199 \begin_layout Standard
19200 When the medium or large model is used all variables declared without a
19201 storage class will be allocated into the external ram, this includes all
19202 parameters and local variables (for non-reentrant
19203 \begin_inset LatexCommand \index{reentrant}
19208 When the small model is used variables without storage class are allocated
19209 in the internal ram.
19212 \begin_layout Standard
19213 Judicious usage of the processor specific storage classes
19214 \begin_inset LatexCommand \index{Storage class}
19218 and the 'reentrant' function type will yield much more efficient code,
19219 than using the large model.
19220 Several optimizations are disabled when the program is compiled using the
19221 large model, it is therefore recommended that the small model be used unless
19222 absolutely required.
19225 \begin_layout Subsubsection
19227 \begin_inset LatexCommand \label{sub:External-Stack}
19232 \begin_inset LatexCommand \index{stack}
19237 \begin_inset LatexCommand \index{External stack (mcs51)}
19244 \begin_layout Standard
19245 The external stack (-
19249 \begin_layout Standard
19259 \begin_inset LatexCommand \index{-\/-xstack}
19263 ) is located in pdata
19264 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19268 memory (usually at the start of the external ram segment) and uses all
19269 unused space in pdata (max.
19275 \begin_layout Standard
19284 -xstack option is used to compile the program, the parameters and local
19286 \begin_inset LatexCommand \index{local variables}
19290 of all reentrant functions are allocated in this area.
19291 This option is provided for programs with large stack space requirements.
19292 When used with the -
19296 \begin_layout Standard
19306 \begin_inset LatexCommand \index{-\/-stack-auto}
19310 option, all parameters and local variables are allocated on the external
19311 stack (note: support libraries will need to be recompiled with the same
19313 There is a predefined target in the library makefile).
19316 \begin_layout Standard
19317 The compiler outputs the higher order address byte of the external ram segment
19319 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19324 \begin_inset LatexCommand \ref{sub:MCS51-variants}
19328 ), therefore when using the External Stack option, this port
19332 be used by the application program.
19335 \begin_layout Subsection
19337 \begin_inset LatexCommand \index{Memory model}
19342 \begin_inset LatexCommand \index{DS390 memory model}
19349 \begin_layout Standard
19350 The only model supported is Flat 24
19351 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
19356 This generates code for the 24 bit contiguous addressing mode of the Dallas
19358 In this mode, up to four meg of external RAM or code space can be directly
19360 See the data sheets at www.dalsemi.com for further information on this part.
19365 that the compiler does not generate any code to place the processor into
19366 24 bitmode (although
19370 in the ds390 libraries will do that for you).
19376 \begin_inset LatexCommand \index{Tinibios (DS390)}
19380 , the boot loader or similar code must ensure that the processor is in 24
19381 bit contiguous addressing mode before calling the SDCC startup code.
19392 \begin_layout Standard
19403 option, variables will by default be placed into the XDATA segment.
19408 Segments may be placed anywhere in the 4 meg address space using the usual
19413 \begin_layout Standard
19423 Note that if any segments are located above 64K, the -r flag must be passed
19424 to the linker to generate the proper segment relocations, and the Intel
19425 HEX output format must be used.
19426 The -r flag can be passed to the linker by using the option
19430 on the SDCC command line.
19431 However, currently the linker can not handle code segments > 64k.
19434 \begin_layout Section
19436 \begin_inset LatexCommand \label{sec:Pragmas}
19441 \begin_inset LatexCommand \index{Pragmas}
19448 \begin_layout Standard
19449 SDCC supports the following #pragma directives:
19452 \begin_layout Itemize
19458 \begin_inset LatexCommand \index{\#pragma save}
19462 - this will save most current options to the save/restore stack.
19463 See #pragma\InsetSpace ~
19467 \begin_layout Itemize
19473 \begin_inset LatexCommand \index{\#pragma restore}
19477 - will restore saved options from the last save.
19478 saves & restores can be nested.
19479 SDCC uses a save/restore stack: save pushes current options to the stack,
19480 restore pulls current options from the stack.
19481 See #pragma\InsetSpace ~
19487 \begin_layout Itemize
19493 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19498 \begin_inset LatexCommand \index{function prologue}
19502 function1[,function2[,function3...]] - The compiler by default uses a caller
19503 saves convention for register saving across function calls, however this
19504 can cause unnecessary register pushing & popping
19505 \begin_inset LatexCommand \index{push/pop}
19509 when calling small functions from larger functions.
19510 This option can be used to switch off the register saving convention for
19511 the function names specified.
19512 The compiler will not save registers when calling these functions, extra
19513 code need to be manually inserted at the entry & exit for these functions
19514 to save & restore the registers used by these functions, this can SUBSTANTIALLY
19515 reduce code & improve run time performance of the generated code.
19516 In the future the compiler (with inter procedural analysis) may be able
19517 to determine the appropriate scheme to use for each function call.
19522 \begin_layout Standard
19531 -callee-saves command line option is used, the function names specified
19532 in #pragma\InsetSpace ~
19534 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19538 is appended to the list of functions specified in the command line.
19541 \begin_layout Itemize
19547 \begin_inset LatexCommand \index{\#pragma exclude}
19551 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19552 of pairs of push/pop
19553 \begin_inset LatexCommand \index{push/pop}
19562 \begin_inset LatexCommand \index{interrupt}
19575 The directive should be placed immediately before the ISR function definition
19576 and it affects ALL ISR functions following it.
19577 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
19578 exclude\InsetSpace ~
19580 \begin_inset LatexCommand \index{\#pragma exclude}
19585 See also the related keyword _naked
19586 \begin_inset LatexCommand \index{\_naked}
19591 \begin_inset LatexCommand \index{\_\_naked}
19598 \begin_layout Itemize
19604 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19608 - the compiler will not warn you anymore for obvious mistakes, you'r on
19612 \begin_layout Itemize
19618 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19622 - the compiler will not warn you anymore about warning number <nnnn>.
19625 \begin_layout Itemize
19631 \begin_inset LatexCommand \index{\#pragma nogcse}
19635 - will stop global common subexpression elimination.
19638 \begin_layout Itemize
19644 \begin_inset LatexCommand \index{\#pragma noinduction}
19648 - will stop loop induction optimizations.
19651 \begin_layout Itemize
19657 \begin_inset LatexCommand \index{\#pragma noinvariant}
19661 - will not do loop invariant optimizations.
19662 For more details see Loop Invariants in section
19663 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19670 \begin_layout Itemize
19676 \begin_inset LatexCommand \index{\#pragma noiv}
19680 - Do not generate interrupt
19681 \begin_inset LatexCommand \index{interrupt}
19686 \begin_inset LatexCommand \index{interrupt vector table}
19690 entries for all ISR functions defined after the pragma.
19691 This is useful in cases where the interrupt vector table must be defined
19692 manually, or when there is a secondary, manually defined interrupt vector
19694 for the autovector feature of the Cypress EZ-USB FX2).
19695 More elegantly this can be achieved by obmitting the optional interrupt
19696 number after the interrupt keyword, see section
19697 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19705 \begin_layout Itemize
19711 \begin_inset LatexCommand \index{\#pragma nojtbound}
19715 - will not generate code for boundary value checking, when switch statements
19716 are turned into jump-tables (dangerous).
19717 For more details see section
19718 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19725 \begin_layout Itemize
19731 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19735 - Will not do loop reversal optimization
19738 \begin_layout Itemize
19744 \begin_inset LatexCommand \index{\#pragma nooverlay}
19748 - the compiler will not overlay the parameters and local variables of a
19752 \begin_layout Itemize
19758 \begin_inset LatexCommand \index{\#pragma stackauto}
19766 \begin_layout Standard
19776 \begin_inset LatexCommand \index{-\/-stack-auto}
19781 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19785 Parameters and Local Variables.
19788 \begin_layout Itemize
19794 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19798 - The compiler will optimize code generation towards fast code, possibly
19799 at the expense of code size.
19800 Currently this has little effect.
19803 \begin_layout Itemize
19809 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19813 - The compiler will optimize code generation towards compact code, possibly
19814 at the expense of code speed.
19815 Currently this has little effect.
19818 \begin_layout Itemize
19824 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19828 - The compiler will attempt to generate code that is both compact and fast,
19829 as long as meeting one goal is not a detriment to the other (this is the
19834 \begin_layout Itemize
19840 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19844 - Generally follow the C89 standard, but allow SDCC features that conflict
19845 with the standard (default).
19848 \begin_layout Itemize
19854 \begin_inset LatexCommand \index{\#pragma std\_c89}
19858 - Follow the C89 standard and disable SDCC features that conflict with the
19862 \begin_layout Itemize
19868 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19872 - Generally follow the C99 standard, but allow SDCC features that conflict
19873 with the standard (incomplete support).
19876 \begin_layout Itemize
19882 \begin_inset LatexCommand \index{\#pragma std\_c99}
19886 - Follow the C99 standard and disable SDCC features that conflict with the
19887 standard (incomplete support).
19890 \begin_layout Itemize
19896 \begin_inset LatexCommand \index{\#pragma codeseg}
19900 - Use this name (max.
19901 8 characters) for the code segment.
19906 \begin_layout Standard
19918 \begin_layout Itemize
19924 \begin_inset LatexCommand \index{\#pragma constseg}
19928 - Use this name (max.
19929 8 characters) for the const segment.
19934 \begin_layout Standard
19946 \begin_layout Standard
19947 The preprocessor SDCPP
19948 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19952 supports the following #pragma directives:
19955 \begin_layout Itemize
19958 pedantic_parse_number
19961 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19965 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19966 parsed properly and the macro LO_B(3) gets expanded.
19968 Below is an example on how to use this pragma.
19971 Note: this functionality is not in conformance with standard!
19974 \begin_layout Verse
19977 #pragma pedantic_parse_number +
19978 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19986 #define LO_B(x) ((x) & 0xff)
19990 unsigned char foo(void)
19997 unsigned char c=0xfe-LO_B(3)
20012 \begin_layout Itemize
20018 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20022 (+ | -) - switch _asm _endasm block preprocessing on / off.
20024 You use this prama to define multilines of assembly code.
20025 This will prevent the preprocessor from changing the formating required
20027 Below is an example on how to use this pragma.
20030 \begin_layout Verse
20033 #pragma preproc_asm -
20034 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20040 #define MYDELAY _asm
20045 nop ;my assembly comment...
20059 #pragma preproc_asm
20090 \begin_layout Itemize
20096 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20100 (+ | -) - Allow "naked" hash in macro definition, for example:
20104 #define DIR_LO(x) #(x & 0xff)
20109 Below is an example on how to use this pragma.
20112 \begin_layout Verse
20115 #pragma preproc_asm +
20117 #pragma sdcc_hash +
20118 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20133 mov R6_B3, #(x & 0xff)
20140 mov R7_B3, #((x >> 8) & 0xff)
20164 \begin_layout Standard
20165 The pragma's are intended to be used to turn-on or off certain optimizations
20166 which might cause the compiler to generate extra stack / data space to
20167 store compiler generated temporary variables.
20168 This usually happens in large functions.
20169 Pragma directives should be used as shown in the following example, they
20170 are used to control options & optimizations for a given function; pragmas
20171 should be placed before and/or after a function, placing pragma's inside
20172 a function body could have unpredictable results.
20175 \begin_layout Verse
20179 \begin_inset LatexCommand \index{\#pragma save}
20190 /* save the current settings */
20193 \begin_inset LatexCommand \index{\#pragma nogcse}
20202 /* turnoff global subexpression elimination */
20204 #pragma noinduction
20205 \begin_inset LatexCommand \index{\#pragma noinduction}
20209 /* turn off induction optimizations */
20232 \begin_inset LatexCommand \index{\#pragma restore}
20236 /* turn the optimizations back on */
20239 \begin_layout Standard
20240 The compiler will generate a warning message when extra space is allocated.
20241 It is strongly recommended that the save and restore pragma's be used when
20242 changing options for a function.
20251 \begin_layout Section
20252 Defines Created by the Compiler
20255 \begin_layout Standard
20256 The compiler creates the following #defines
20257 \begin_inset LatexCommand \index{\#defines}
20262 \begin_inset LatexCommand \index{Defines created by the compiler}
20271 \begin_layout Standard
20272 \begin_inset Tabular
20273 <lyxtabular version="3" rows="11" columns="2">
20275 <column alignment="left" valignment="top" leftline="true" width="3in">
20276 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
20277 <row topline="true" bottomline="true">
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20281 \begin_layout Standard
20289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20292 \begin_layout Standard
20301 <row topline="true">
20302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20305 \begin_layout Standard
20307 \begin_inset LatexCommand \index{SDCC}
20316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20319 \begin_layout Standard
20321 Since version 2.5.6 the version number as an int (ex.
20328 <row topline="true">
20329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20332 \begin_layout Standard
20334 \begin_inset LatexCommand \index{SDCC\_mcs51}
20339 \begin_inset LatexCommand \index{SDCC\_ds390}
20344 \begin_inset LatexCommand \index{SDCC\_z80}
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20356 \begin_layout Standard
20357 depending on the model used (e.g.: -mds390)
20363 <row topline="true">
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20367 \begin_layout Standard
20369 \begin_inset LatexCommand \index{\_\_mcs51}
20374 \begin_inset LatexCommand \index{\_\_ds390}
20379 \begin_inset LatexCommand \index{\_\_hc08}
20384 \begin_inset LatexCommand \index{\_\_z80}
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20396 \begin_layout Standard
20397 depending on the model used (e.g.
20404 <row topline="true">
20405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20408 \begin_layout Standard
20410 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20422 \begin_layout Standard
20429 \begin_layout Standard
20446 <row topline="true">
20447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20450 \begin_layout Standard
20452 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20464 \begin_layout Standard
20471 \begin_layout Standard
20488 <row topline="true">
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20492 \begin_layout Standard
20494 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20506 \begin_layout Standard
20513 \begin_layout Standard
20530 <row topline="true">
20531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20534 \begin_layout Standard
20536 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20548 \begin_layout Standard
20555 \begin_layout Standard
20572 <row topline="true">
20573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20576 \begin_layout Standard
20578 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20590 \begin_layout Standard
20597 \begin_layout Standard
20614 <row topline="true">
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20618 \begin_layout Standard
20620 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20632 \begin_layout Standard
20643 <row topline="true" bottomline="true">
20644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20647 \begin_layout Standard
20649 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20661 \begin_layout Standard
20679 \begin_layout Chapter
20680 Notes on supported Processors
20683 \begin_layout Section
20685 \begin_inset LatexCommand \label{sub:MCS51-variants}
20690 \begin_inset LatexCommand \index{MCS51 variants}
20697 \begin_layout Standard
20698 MCS51 processors are available from many vendors and come in many different
20700 While they might differ considerably in respect to Special Function Registers
20701 the core MCS51 is usually not modified or is kept compatible.
20705 \begin_layout Subsection
20706 pdata access by SFR
20709 \begin_layout Standard
20710 With the upcome of devices with internal xdata and flash memory devices
20712 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20716 as dedicated I/O port is becoming more popular.
20717 Switching the high byte for pdata
20718 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20722 access which was formerly done by port P2 is then achieved by a Special
20724 \begin_inset LatexCommand \index{sfr}
20729 In well-established MCS51 tradition the address of this
20733 is where the chip designers decided to put it.
20734 Needless to say that they didn't agree on a common name either.
20735 So that the startup code can correctly initialize xdata variables, you
20736 should define an sfr with the name _XPAGE
20739 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20745 at the appropriate location if the default, port P2, is not used for this.
20749 \begin_layout Verse
20752 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
20755 \begin_layout Verse
20758 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20761 \begin_layout Verse
20764 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20767 \begin_layout Standard
20768 For more exotic implementations further customizations may be needed.
20770 \begin_inset LatexCommand \ref{sub:Startup-Code}
20774 for other possibilities.
20777 \begin_layout Subsection
20778 Other Features available by SFR
20781 \begin_layout Standard
20782 Some MCS51 variants offer features like Double DPTR
20783 \begin_inset LatexCommand \index{DPTR}
20787 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20788 These are currently not used for the MCS51 port.
20789 If you absolutely need them you can fall back to inline assembly or submit
20791 \begin_inset VSpace bigskip
20797 \begin_layout Section
20801 \begin_layout Standard
20803 \begin_inset LatexCommand \index{DS80C400}
20808 \begin_inset LatexCommand \index{DS400}
20812 microcontroller has a rich set of peripherals.
20813 In its built-in ROM library it includes functions to access some of the
20814 features, among them is a TCP stack with IP4 and IP6 support.
20815 Library headers (currently in beta status) and other files are provided
20819 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20825 \begin_inset VSpace bigskip
20831 \begin_layout Section
20832 The Z80 and gbz80 port
20835 \begin_layout Standard
20836 SDCC can target both the Zilog Z80
20837 \begin_inset LatexCommand \index{Z80}
20841 and the Nintendo Gameboy's Z80-like gbz80
20842 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20847 The Z80 port is passed through the same
20850 \begin_inset LatexCommand \index{Regression test}
20857 \begin_inset LatexCommand \ref{sec:Quality-control}
20861 ) as the MCS51 and DS390 ports, so floating point support, support for long
20862 variables and bitfield support is fine.
20863 See mailing lists and forums about interrupt routines.
20866 \begin_layout Standard
20867 As always, the code is the authoritative reference - see z80/ralloc.c and
20870 \begin_inset LatexCommand \index{Z80!stack}
20874 frame is similar to that generated by the IAR Z80 compiler.
20875 IX is used as the base pointer, HL and IY are used as a temporary registers,
20876 and BC and DE are available for holding variables.
20878 \begin_inset LatexCommand \index{Z80!return value}
20882 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20884 The gbz80 port use the same set of registers for the return values, but
20885 in a different order of significance: E (one byte), DE (two bytes), or
20887 \begin_inset VSpace bigskip
20893 \begin_layout Section
20897 \begin_layout Standard
20898 The port to the Freescale/Motorola HC08
20899 \begin_inset LatexCommand \index{HC08}
20903 family has been added in October 2003, and is still undergoing some basic
20905 The code generator is complete, but the register allocation is still quite
20907 Some of the SDCC's standard C library functions have embedded non-HC08
20908 inline assembly and so are not yet usable.
20911 \begin_layout Standard
20912 The HC08 port passes the regression test suite (see section
20913 \begin_inset LatexCommand \ref{sec:Quality-control}
20918 \begin_inset VSpace bigskip
20924 \begin_layout Standard
20930 \begin_layout Section
20934 \begin_layout Standard
20936 \begin_inset LatexCommand \index{PIC14}
20940 port still requires a major effort from the development community.
20941 However it can work for simple code.
20942 It passes its (smaller set of) regression tests
20943 \begin_inset LatexCommand \index{Regression test (PIC14)}
20949 sdcc/src/regression
20954 \begin_layout Subsection
20955 C code and 14bit PIC code page
20956 \begin_inset LatexCommand \index{code page (pic14)}
20961 \begin_inset LatexCommand \index{RAM bank (pic14)}
20968 \begin_layout Standard
20969 The linker organizes allocation for the code page and RAM banks.
20970 It does not have intimate knowledge of the code flow.
20971 It will put all the code section of a single asm file into a single code
20973 In order to make use of multiple code pages, separate asm files must be
20975 The compiler treats all functions of a single C file as being in the same
20976 code page unless it is non static.
20980 To get the best follow these guide lines:
20983 \begin_layout Enumerate
20984 Make local functions static, as non static functions require code page selection
20988 \begin_layout Enumerate
20989 For devices that have multiple code pages it is more efficient to use the
20990 same number of files as pages, i.e.
20991 for the 16F877 use 4 separate files and i.e.
20992 for the 16F874 use 2 separate files.
20993 This way the linker can put the code for each file into different code
20994 pages and there's less page selection overhead.
20997 \begin_layout Enumerate
20998 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20999 instruction set), use 'unsigned char' whereever possible instead of 'int'.
21002 \begin_layout Subsection
21003 Creating a device include file
21006 \begin_layout Standard
21007 For generating a device include file
21008 \begin_inset LatexCommand \index{PIC14!Header files}
21012 use the support perl script inc2h.pl kept in directory support/script.
21015 \begin_layout Subsection
21019 \begin_layout Standard
21020 For the interrupt function, use the keyword '__interrupt'
21021 \begin_inset LatexCommand \index{PIC14!interrupt}
21025 with level number of 0 (PIC14 only has 1 interrupt so this number is only
21026 there to avoid a syntax error - it ought to be fixed).
21030 \begin_layout Verse
21033 void Intr(void) __interrupt 0
21039 T0IF = 0; /* Clear timer interrupt */
21044 \begin_layout Subsection
21045 Linking and assembling
21048 \begin_layout Standard
21049 For assembling you can use either GPUTILS'
21050 \begin_inset LatexCommand \index{gputils (pic tools)}
21054 gpasm.exe or MPLAB's mpasmwin.exe.
21055 GPUTILS is available from
21056 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21061 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21062 If you use MPLAB and an interrupt function then the linker script file
21063 vectors section will need to be enlarged to link with mplink.
21074 \begin_layout Verse
21087 sdcc -S -V -mpic14 -p16F877 $<
21101 $(PRJ).hex: $(OBJS)
21112 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
21115 \begin_layout Standard
21123 \begin_layout Verse
21136 sdcc -S -V -mpic14 -p16F877 $<
21146 mpasmwin /q /o $*.asm
21150 $(PRJ).hex: $(OBJS)
21161 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
21164 \begin_layout Standard
21165 Please note that indentations within a
21169 have to be done with a tabulator character.
21172 \begin_layout Subsection
21173 Command-line options
21176 \begin_layout Standard
21177 Besides the switches common to all SDCC backends, the PIC14 port accepts
21178 the following options (for an updated list see sdcc -
21182 \begin_layout Standard
21195 \labelwidthstring 00.00.0000
21200 \begin_layout Standard
21210 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
21214 emit debug info in assembly output
21218 \labelwidthstring 00.00.0000
21223 \begin_layout Standard
21233 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
21237 disable (slightly faulty) optimization on pCode
21241 \labelwidthstring 00.00.0000
21246 \begin_layout Standard
21256 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
21260 sets the lowest address of the argument passing stack (defaults to a suitably
21261 large shared databank to reduce BANKSEL overhead)
21265 \labelwidthstring 00.00.0000
21270 \begin_layout Standard
21280 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
21284 sets the size if the argument passing stack (default: 16, minimum: 4)
21287 \begin_layout Subsection
21291 \begin_layout Subsubsection
21292 error: missing definition for symbol
21293 \begin_inset Quotes sld
21297 \begin_inset Quotes srd
21303 \begin_layout Standard
21304 The PIC14 port uses library routines to provide more complex operations
21305 like multiplication, division/modulus and (generic) pointer dereferencing.
21306 In order to add these routines to your project, you must link with PIC14's
21312 For single source file projects this is done automatically, more complex
21317 to the linker's arguments.
21318 Make sure you also add an include path for the library (using the -I switch
21322 \begin_layout Subsubsection
21323 Processor mismatch in file
21324 \begin_inset Quotes sld
21328 \begin_inset Quotes srd
21334 \begin_layout Standard
21335 This warning can usually be ignored due to the very good compatibility amongst
21337 \begin_inset LatexCommand \index{PIC14}
21344 \begin_layout Standard
21345 You might also consider recompiling the library for your specific device
21346 by changing the ARCH=p16f877 (default target) entry in
21348 device/lib/pic/Makefile.in
21352 device/lib/pic/Makefile
21354 to reflect your device.
21355 This might even improve performance for smaller devices as unneccesary
21356 BANKSELs migth be removed.
21359 \begin_layout Subsection
21363 \begin_layout Subsubsection
21367 \begin_layout Standard
21368 Currently, data can only be initialized if it resides in the source file
21374 Data in other source files will silently
21382 \begin_inset Marginal
21385 \begin_layout Standard
21397 \begin_layout Standard
21403 \begin_layout Section
21405 \begin_inset LatexCommand \index{PIC16}
21412 \begin_layout Standard
21414 \begin_inset LatexCommand \index{PIC16}
21418 port is the portion of SDCC that is responsible to produce code for the
21420 \begin_inset LatexCommand \index{Microchip}
21424 (TM) microcontrollers with 16 bit core.
21425 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
21426 Currently supported devices are:
21429 \begin_layout Standard
21431 \begin_inset Tabular
21432 <lyxtabular version="3" rows="4" columns="6">
21434 <column alignment="center" valignment="top" leftline="true" width="0">
21435 <column alignment="center" valignment="top" leftline="true" width="0">
21436 <column alignment="center" valignment="top" leftline="true" width="0">
21437 <column alignment="center" valignment="top" leftline="true" width="0">
21438 <column alignment="center" valignment="top" leftline="true" width="0">
21439 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21440 <row topline="true">
21441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21444 \begin_layout Standard
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21453 \begin_layout Standard
21459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21462 \begin_layout Standard
21468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21471 \begin_layout Standard
21477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21480 \begin_layout Standard
21486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21489 \begin_layout Standard
21496 <row topline="true">
21497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21500 \begin_layout Standard
21506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21509 \begin_layout Standard
21515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21518 \begin_layout Standard
21524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21527 \begin_layout Standard
21533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21536 \begin_layout Standard
21542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21545 \begin_layout Standard
21552 <row topline="true">
21553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21556 \begin_layout Standard
21562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21565 \begin_layout Standard
21571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21574 \begin_layout Standard
21580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21583 \begin_layout Standard
21589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21592 \begin_layout Standard
21598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21601 \begin_layout Standard
21608 <row topline="true" bottomline="true">
21609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21612 \begin_layout Standard
21618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21621 \begin_layout Standard
21627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21630 \begin_layout Standard
21636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21639 \begin_layout Standard
21645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21648 \begin_layout Standard
21654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21657 \begin_layout Standard
21671 \begin_layout Subsection
21675 \begin_layout Standard
21676 PIC16 port supports the standard command line arguments as supposed, with
21677 the exception of certain cases that will be mentioned in the following
21682 \labelwidthstring 00.00.0000
21687 \begin_layout Standard
21697 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21705 \begin_layout Standard
21718 \labelwidthstring 00.00.0000
21723 \begin_layout Standard
21733 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21737 All function arguments are passed on stack by default.
21740 There is no need to specify this in the command line.
21744 \labelwidthstring 00.00.0000
21749 \begin_layout Standard
21758 -fommit-frame-pointer
21759 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21763 Frame pointer will be omitted when the function uses no local variables.
21766 \begin_layout Subsection
21767 Port Specific Options
21768 \begin_inset LatexCommand \index{Options PIC16}
21775 \begin_layout Standard
21776 The port specific options appear after the global options in the sdcc --help
21780 \begin_layout Subsubsection
21784 \begin_layout Standard
21785 General options enable certain port features and optimizations.
21789 \labelwidthstring 00.00.0000
21794 \begin_layout Standard
21803 -pstack-model=[model] Used in conjuction with the command above.
21804 Defines the stack model to be used, valid stack models are :
21809 \labelwidthstring 00.00.0000
21814 Selects small stack model.
21815 8 bit stack and frame pointers.
21816 Supports 256 bytes stack size.
21820 \labelwidthstring 00.00.0000
21825 Selects large stack model.
21826 16 bit stack and frame pointers.
21827 Supports 65536 bytes stack size.
21832 \labelwidthstring 00.00.0000
21837 \begin_layout Standard
21846 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21847 unitialized data variables with [kword].
21848 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21852 \labelwidthstring 00.00.0000
21857 \begin_layout Standard
21866 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21867 Useful for bootloaders.
21871 \labelwidthstring 00.00.0000
21876 \begin_layout Standard
21885 -asm= sets the full path and name of an external assembler to call.
21889 \labelwidthstring 00.00.0000
21894 \begin_layout Standard
21903 -link= sets the full path and name of an external linker to call.
21907 \labelwidthstring 00.00.0000
21912 \begin_layout Standard
21922 \begin_inset LatexCommand \index{PIC16!MPLAB}
21926 compatibility option.
21927 Currently only suppresses special gpasm directives.
21930 \begin_layout Subsubsection
21931 Optimization Options
21935 \labelwidthstring 00.00.0000
21940 \begin_layout Standard
21949 -optimize-goto Try to use (conditional) BRA instead of GOTO
21953 \labelwidthstring 00.00.0000
21958 \begin_layout Standard
21967 -optimize-cmp Try to optimize some compares.
21971 \labelwidthstring 00.00.0000
21976 \begin_layout Standard
21985 -optimize-df Analyze the dataflow of the generated code and improve it.
21989 \labelwidthstring 00.00.0000
21994 \begin_layout Standard
22003 -obanksel=nn Set optimization level for inserting BANKSELs.
22010 \labelwidthstring 00.00.0000
22015 \labelwidthstring 00.00.0000
22016 1 checks previous used register and if it is the same then does not emit
22017 BANKSEL, accounts only for labels.
22021 \labelwidthstring 00.00.0000
22022 2 tries to check the location of (even different) symbols and removes BANKSELs
22023 if they are in the same bank.
22028 Important: There might be problems if the linker script has data sections
22029 across bank borders!
22033 \begin_layout Subsubsection
22038 \labelwidthstring 00.00.0000
22043 \begin_layout Standard
22052 -nodefaultlibs do not link default libraries when linking
22056 \labelwidthstring 00.00.0000
22061 \begin_layout Standard
22070 -no-crt Don't link the default run-time modules
22074 \labelwidthstring 00.00.0000
22079 \begin_layout Standard
22088 -use-crt= Use a custom run-time module instead of the defaults.
22091 \begin_layout Subsubsection
22095 \begin_layout Standard
22096 Debugging options enable extra debugging information in the output files.
22100 \labelwidthstring 00.00.0000
22105 \begin_layout Standard
22114 -debug-xtra Similar to -
22118 \begin_layout Standard
22128 \begin_inset LatexCommand \index{-\/-debug}
22132 , but dumps more information.
22136 \labelwidthstring 00.00.0000
22141 \begin_layout Standard
22150 -debug-ralloc Force register allocator to dump <source>.d file with debugging
22152 <source> is the name of the file compiled.
22156 \labelwidthstring 00.00.0000
22161 \begin_layout Standard
22170 -pcode-verbose Enable pcode debugging information in translation.
22174 \labelwidthstring 00.00.0000
22179 \begin_layout Standard
22188 -denable-peeps Force the usage of peepholes.
22193 \labelwidthstring 00.00.0000
22198 \begin_layout Standard
22207 -gstack Trace push/pops for stack pointer overflow
22211 \labelwidthstring 00.00.0000
22216 \begin_layout Standard
22225 -call-tree dump call tree in .calltree file
22228 \begin_layout Subsection
22229 Enviromental Variables
22232 \begin_layout Standard
22233 There is a number of enviromental variables that can be used when running
22234 SDCC to enable certain optimizations or force a specific program behaviour.
22235 these variables are primarily for debugging purposes so they can be enabled/dis
22239 \begin_layout Standard
22240 Currently there is only two such variables available:
22244 \labelwidthstring 00.00.0000
22245 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
22246 bitfields is optimized by directly loading FSR0 with the address of the
22247 bitfield structure.
22248 Normally SDCC will cast the bitfield structure to a bitfield pointer and
22250 This step saves data ram and code space for functions that perform heavy
22253 80 bytes of code space are saved when compiling malloc.c with this option).
22258 \labelwidthstring 00.00.0000
22259 NO_REG_OPT do not perform pCode registers optimization.
22260 This should be used for debugging purposes.
22261 In some where bugs in the pcode optimizer are found, users can benefit
22262 from temporarily disabling the optimizer until the bug is fixed.
22265 \begin_layout Subsection
22266 Preprocessor Macros
22269 \begin_layout Standard
22271 \begin_inset LatexCommand \index{PIC16}
22275 port defines the following preprocessor macros while translating a source.
22278 \begin_layout Standard
22280 \begin_inset Tabular
22281 <lyxtabular version="3" rows="6" columns="2">
22283 <column alignment="center" valignment="top" leftline="true" width="0">
22284 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22285 <row topline="true" bottomline="true">
22286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22289 \begin_layout Standard
22295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22298 \begin_layout Standard
22305 <row topline="true">
22306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22309 \begin_layout Standard
22315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22318 \begin_layout Standard
22319 Port identification
22325 <row topline="true">
22326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22329 \begin_layout Standard
22334 \begin_layout Standard
22348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22351 \begin_layout Standard
22352 Port identification (same as above)
22358 <row topline="true">
22359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22362 \begin_layout Standard
22368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22371 \begin_layout Standard
22372 MCU Identification.
22377 is the microcontrol identification number, i.e.
22384 <row topline="true">
22385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22388 \begin_layout Standard
22393 \begin_layout Standard
22407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22410 \begin_layout Standard
22411 MCU Identification (same as above)
22417 <row topline="true" bottomline="true">
22418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22421 \begin_layout Standard
22427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22430 \begin_layout Standard
22431 nnn = SMALL or LARGE respectively according to the stack model used
22444 \begin_layout Standard
22445 In addition the following macros are defined when calling assembler:
22448 \begin_layout Standard
22450 \begin_inset Tabular
22451 <lyxtabular version="3" rows="4" columns="2">
22453 <column alignment="center" valignment="top" leftline="true" width="0">
22454 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22455 <row topline="true" bottomline="true">
22456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22459 \begin_layout Standard
22465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22468 \begin_layout Standard
22475 <row topline="true">
22476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22479 \begin_layout Standard
22485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22488 \begin_layout Standard
22489 MCU Identification.
22494 is the microcontrol identification number, i.e.
22501 <row topline="true">
22502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22505 \begin_layout Standard
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22514 \begin_layout Standard
22515 nnn = SMALL or LARGE respectively according to the memory model used for
22522 <row topline="true" bottomline="true">
22523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22526 \begin_layout Standard
22532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22535 \begin_layout Standard
22536 nnn = SMALL or LARGE respectively according to the stack model used
22549 \begin_layout Subsection
22553 \begin_layout Standard
22555 \begin_inset LatexCommand \index{PIC16}
22559 port uses the following directories for searching header files and libraries.
22562 \begin_layout Standard
22564 \begin_inset Tabular
22565 <lyxtabular version="3" rows="3" columns="4">
22567 <column alignment="center" valignment="top" leftline="true" width="0">
22568 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22569 <column alignment="center" valignment="top" width="0">
22570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22571 <row topline="true" bottomline="true">
22572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22575 \begin_layout Standard
22581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22584 \begin_layout Standard
22590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22593 \begin_layout Standard
22599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22602 \begin_layout Standard
22609 <row topline="true">
22610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22613 \begin_layout Standard
22614 PREFIX/sdcc/include/pic16
22619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22622 \begin_layout Standard
22623 PIC16 specific headers
22628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22631 \begin_layout Standard
22637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22640 \begin_layout Standard
22647 <row topline="true" bottomline="true">
22648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22651 \begin_layout Standard
22652 PREFIX/sdcc/lib/pic16
22657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22660 \begin_layout Standard
22661 PIC16 specific libraries
22666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22669 \begin_layout Standard
22675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22678 \begin_layout Standard
22692 \begin_layout Subsection
22694 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22701 \begin_layout Standard
22703 \begin_inset LatexCommand \index{PIC16}
22707 port currently supports the following pragmas:
22711 \labelwidthstring 00.00.0000
22713 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22718 \begin_inset LatexCommand \index{PIC16!stack}
22722 forces the code generator to initialize the stack & frame pointers at a
22724 This is an adhoc solution for cases where no STACK directive is available
22725 in the linker script or gplink is not instructed to create a stack section.
22728 stack pragma should be used only once in a project.
22729 Multiple pragmas may result in indeterminate behaviour of the program.
22733 \begin_layout Standard
22734 The old format (ie.
22735 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22736 cross page boundaries (or even exceed the available data RAM) and crash
22738 Make sure that stack does not cross page boundaries when using the SMALL
22746 The format is as follows:
22749 \begin_layout LyX-Code
22750 #pragma stack bottom_address [stack_size]
22753 \begin_layout Standard
22758 is the lower bound of the stack section.
22759 The stack pointer initially will point at address (bottom_address+stack_size-1).
22762 \begin_layout LyX-Code
22766 \begin_layout LyX-Code
22770 \begin_layout LyX-Code
22771 /* initializes stack of 100 bytes at RAM address 0x200 */
22774 \begin_layout LyX-Code
22775 #pragma stack 0x200 100
22778 \begin_layout Standard
22779 If the stack_size field is omitted then a stack is created with the default
22781 This size might be enough for most programs, but its not enough for operations
22782 with deep function nesting or excessive stack usage.
22786 \labelwidthstring 00.00.0000
22788 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22792 place a function symbol at static FLASH address
22795 \begin_layout LyX-Code
22799 \begin_layout LyX-Code
22803 \begin_layout LyX-Code
22804 /* place function test_func at 0x4000 */
22807 \begin_layout LyX-Code
22808 #pragma code test_func 0x4000
22811 \begin_layout LyX-Code
22816 \labelwidthstring 00.00.0000
22817 library instructs the linker to use a library module.
22822 \begin_layout LyX-Code
22823 #pragma library module_name
22826 \begin_layout Standard
22831 can be any library or object file (including its path).
22832 Note that there are four reserved keywords which have special meaning.
22836 \begin_layout Standard
22838 \begin_inset Tabular
22839 <lyxtabular version="3" rows="6" columns="3">
22841 <column alignment="center" valignment="top" leftline="true" width="0">
22842 <column alignment="block" valignment="top" leftline="true" width="20page%">
22843 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22844 <row topline="true" bottomline="true">
22845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22848 \begin_layout Standard
22854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22857 \begin_layout Standard
22863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22866 \begin_layout Standard
22873 <row topline="true">
22874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22877 \begin_layout Standard
22885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22888 \begin_layout Standard
22889 ignore all library pragmas
22894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22897 \begin_layout Standard
22906 <row topline="true">
22907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22910 \begin_layout Standard
22918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22921 \begin_layout Standard
22927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22930 \begin_layout Standard
22941 <row topline="true">
22942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22945 \begin_layout Standard
22953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22956 \begin_layout Standard
22957 link the Math libarary
22962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22965 \begin_layout Standard
22976 <row topline="true">
22977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22980 \begin_layout Standard
22988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22991 \begin_layout Standard
22992 link the I/O library
22997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23000 \begin_layout Standard
23011 <row topline="true" bottomline="true">
23012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23015 \begin_layout Standard
23023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23026 \begin_layout Standard
23027 link the debug library
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23035 \begin_layout Standard
23052 * is the device number, i.e.
23053 452 for PIC18F452 MCU.
23056 \begin_layout Standard
23057 This feature allows for linking with specific libraries withoug having to
23058 explicit name them in the command line.
23063 keyword will reject all modules specified by the library pragma.
23067 \labelwidthstring 00.00.0000
23068 udata pragma udata instructs the compiler to emit code so that linker will
23069 place a variable at a specific memory bank
23072 \begin_layout LyX-Code
23076 \begin_layout LyX-Code
23080 \begin_layout LyX-Code
23081 /* places variable foo at bank2 */
23084 \begin_layout LyX-Code
23085 #pragma udata bank2 foo
23088 \begin_layout LyX-Code
23092 \begin_layout Standard
23093 In order for this pragma to work extra SECTION directives should be added
23094 in the .lkr script.
23095 In the following example a sample .lkr file is shown:
23098 \begin_layout LyX-Code
23102 \begin_layout LyX-Code
23103 // Sample linker script for the PIC18F452 processor
23106 \begin_layout LyX-Code
23110 \begin_layout LyX-Code
23111 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
23114 \begin_layout LyX-Code
23115 CODEPAGE NAME=page START=0x2A END=0x7FFF
23118 \begin_layout LyX-Code
23119 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
23122 \begin_layout LyX-Code
23123 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
23126 \begin_layout LyX-Code
23127 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
23130 \begin_layout LyX-Code
23131 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
23134 \begin_layout LyX-Code
23135 ACCESSBANK NAME=accessram START=0x0 END=0x7F
23138 \begin_layout LyX-Code
23142 \begin_layout LyX-Code
23143 DATABANK NAME=gpr0 START=0x80 END=0xFF
23146 \begin_layout LyX-Code
23147 DATABANK NAME=gpr1 START=0x100 END=0x1FF
23150 \begin_layout LyX-Code
23151 DATABANK NAME=gpr2 START=0x200 END=0x2FF
23154 \begin_layout LyX-Code
23155 DATABANK NAME=gpr3 START=0x300 END=0x3FF
23158 \begin_layout LyX-Code
23159 DATABANK NAME=gpr4 START=0x400 END=0x4FF
23162 \begin_layout LyX-Code
23163 DATABANK NAME=gpr5 START=0x500 END=0x5FF
23166 \begin_layout LyX-Code
23167 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
23170 \begin_layout LyX-Code
23174 \begin_layout LyX-Code
23175 SECTION NAME=CONFIG ROM=config
23178 \begin_layout LyX-Code
23182 \begin_layout LyX-Code
23183 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
23186 \begin_layout LyX-Code
23187 SECTION NAME=bank1 RAM=gpr1 # should be added to link
23190 \begin_layout LyX-Code
23191 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
23194 \begin_layout LyX-Code
23195 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
23198 \begin_layout LyX-Code
23199 SECTION NAME=bank4 RAM=gpr4
23202 \begin_layout LyX-Code
23203 SECTION NAME=bank5 RAM=gpr5
23206 \begin_layout Standard
23207 The linker will recognise the section name set in the pragma statement and
23208 will position the variable at the memory bank set with the RAM field at
23209 the SECTION line in the linker script file.
23212 \begin_layout Subsection
23214 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
23221 \begin_layout Standard
23222 There is one main header file
23223 \begin_inset LatexCommand \index{PIC16!Header files}
23227 that can be included to the source files using the pic16
23228 \begin_inset LatexCommand \index{PIC16}
23238 This header file contains the definitions for the processor special registers,
23239 so it is necessary if the source accesses them.
23240 It can be included by adding the following line in the beginning of the
23244 \begin_layout LyX-Code
23245 #include <pic18fregs.h>
23248 \begin_layout Standard
23249 The specific microcontroller is selected within the pic18fregs.h automatically,
23250 so the same source can be used with a variety of devices.
23253 \begin_layout Subsection
23257 \begin_layout Standard
23259 \begin_inset LatexCommand \index{PIC16!Libraries}
23264 \begin_inset LatexCommand \index{PIC16}
23268 port depends on are the microcontroller device libraries which contain
23269 the symbol definitions for the microcontroller special function registers.
23270 These libraries have the format pic18fxxxx.lib, where
23274 is the microcontroller identification number.
23275 The specific library is selected automatically by the compiler at link
23276 stage according to the selected device.
23279 \begin_layout Standard
23280 Libraries are created with gplib which is part of the gputils package
23281 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23288 \begin_layout Subsubsection*
23289 Building the libraries
23292 \begin_layout Standard
23293 Before using SDCC/pic16 there are some libraries that need to be compiled.
23294 This process is not done automatically by SDCC since not all users use
23295 SDCC for pic16 projects.
23296 So each user should compile the libraries separately.
23299 \begin_layout Standard
23300 The steps to compile the pic16 libraries under Linux are:
23303 \begin_layout LyX-Code
23304 cd device/lib/pic16
23307 \begin_layout LyX-Code
23311 \begin_layout LyX-Code
23315 \begin_layout LyX-Code
23319 \begin_layout LyX-Code
23323 \begin_layout LyX-Code
23324 su -c 'make install' # install the libraries, you need the root password
23327 \begin_layout Standard
23328 If you need to install the headers too, do:
23331 \begin_layout LyX-Code
23335 \begin_layout LyX-Code
23336 su -c 'make install' # install the headers, you need the root password
23339 \begin_layout Standard
23340 There exist a special target to build the I/O libraries.
23341 This target is not automatically build because it will build the I/O library
23347 This way building will take quite a lot of time.
23348 Users are advised to edit the
23350 device/lib/pic16/pics.build
23352 file and then execute:
23355 \begin_layout LyX-Code
23359 \begin_layout Subsection
23363 \begin_layout Standard
23364 The following memory models are supported by the PIC16 port:
23367 \begin_layout Itemize
23371 \begin_layout Itemize
23375 \begin_layout Standard
23376 Memory model affects the default size of pointers within the source.
23377 The sizes are shown in the next table:
23380 \begin_layout Standard
23382 \begin_inset Tabular
23383 <lyxtabular version="3" rows="3" columns="3">
23385 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23386 <column alignment="center" valignment="top" leftline="true" width="0">
23387 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23388 <row topline="true" bottomline="true">
23389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23392 \begin_layout Standard
23393 Pointer sizes according to memory model
23398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23401 \begin_layout Standard
23407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23410 \begin_layout Standard
23417 <row topline="true" bottomline="true">
23418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23421 \begin_layout Standard
23427 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23430 \begin_layout Standard
23436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23439 \begin_layout Standard
23446 <row topline="true" bottomline="true">
23447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23450 \begin_layout Standard
23456 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
23459 \begin_layout Standard
23465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23468 \begin_layout Standard
23482 \begin_layout Standard
23483 It is advisable that all sources within a project are compiled with the
23485 If one wants to override the default memory model, this can be done by
23486 declaring a pointer as
23495 Far selects large memory model's pointers, while near selects small memory
23499 \begin_layout Standard
23500 The standard device libraries (see
23501 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
23505 ) contain no reference to pointers, so they can be used with both memory
23509 \begin_layout Subsection
23513 \begin_layout Standard
23515 \begin_inset LatexCommand \index{PIC16!stack}
23519 implementation for the PIC16 port uses two indirect registers, FSR1 and
23524 \labelwidthstring 00.00.0000
23525 FSR1 is assigned as stack pointer
23529 \labelwidthstring 00.00.0000
23530 FSR2 is assigned as frame pointer
23533 \begin_layout Standard
23534 The following stack models are supported by the PIC16 port
23537 \begin_layout Itemize
23545 \begin_layout Itemize
23553 \begin_layout Standard
23558 model means that only the FSRxL byte is used to access stack and frame,
23565 uses both FSRxL and FSRxH registers.
23566 The following table shows the stack/frame pointers sizes according to stack
23567 model and the maximum space they can address:
23570 \begin_layout Standard
23572 \begin_inset Tabular
23573 <lyxtabular version="3" rows="3" columns="3">
23575 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23576 <column alignment="center" valignment="top" leftline="true" width="0">
23577 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23578 <row topline="true" bottomline="true">
23579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23582 \begin_layout Standard
23583 Stack & Frame pointer sizes according to stack model
23588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23591 \begin_layout Standard
23597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23600 \begin_layout Standard
23607 <row topline="true">
23608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23611 \begin_layout Standard
23617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23620 \begin_layout Standard
23626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23629 \begin_layout Standard
23636 <row topline="true" bottomline="true">
23637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23640 \begin_layout Standard
23646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23649 \begin_layout Standard
23655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23658 \begin_layout Standard
23672 \begin_layout Standard
23677 stack model is currently not working properly throughout the code generator.
23678 So its use is not advised.
23679 Also there are some other points that need special care:
23684 \begin_layout Enumerate
23685 Do not create stack sections with size more than one physical bank (that
23689 \begin_layout Enumerate
23690 Stack sections should no cross physical bank limits (i.e.
23691 #pragma stack 0x50 0x100)
23694 \begin_layout Standard
23695 These limitations are caused by the fact that only FSRxL is modified when
23696 using SMALL stack model, so no more than 256 bytes of stack can be used.
23697 This problem will disappear after LARGE model is fully implemented.
23700 \begin_layout Subsection
23704 \begin_layout Standard
23705 In addition to the standard SDCC function keywords, PIC16
23706 \begin_inset LatexCommand \index{PIC16}
23710 port makes available two more:
23714 \labelwidthstring 00.00.0000
23716 \begin_inset LatexCommand \index{PIC16!wparam}
23720 Use the WREG to pass one byte of the first function argument.
23721 This improves speed but you may not use this for functions with arguments
23722 that are called via function pointers, otherwise the first byte of the
23723 first parameter will get lost.
23727 \begin_layout LyX-Code
23728 void func_wparam(int a) wparam
23731 \begin_layout LyX-Code
23735 \begin_layout LyX-Code
23736 /* WREG hold the lower part of a */
23739 \begin_layout LyX-Code
23740 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
23744 \begin_layout LyX-Code
23748 \begin_layout LyX-Code
23753 \labelwidthstring 00.00.0000
23755 \begin_inset LatexCommand \index{PIC16!shadowregs}
23759 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
23760 hardware shadow registers which hold the values of WREG, STATUS and BSR
23762 This can be done by adding the keyword
23770 keyword in the function's header.
23773 \begin_layout LyX-Code
23774 void isr_shadow(void) shadowregs interrupt 1
23777 \begin_layout LyX-Code
23781 \begin_layout LyX-Code
23785 \begin_layout LyX-Code
23789 \begin_layout Standard
23794 instructs the code generator not to store/restore WREG, STATUS, BSR when
23795 entering/exiting the ISR.
23798 \begin_layout Subsection
23799 Function return values
23802 \begin_layout Standard
23803 Return values from functions are placed to the appropriate registers following
23804 a modified Microchip policy optimized for SDCC.
23805 The following table shows these registers:
23808 \begin_layout Standard
23810 \begin_inset Tabular
23811 <lyxtabular version="3" rows="6" columns="2">
23813 <column alignment="center" valignment="top" leftline="true" width="0">
23814 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23815 <row topline="true" bottomline="true">
23816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23819 \begin_layout Standard
23825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23828 \begin_layout Standard
23829 destination register
23835 <row topline="true">
23836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23839 \begin_layout Standard
23845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23848 \begin_layout Standard
23855 <row topline="true">
23856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23859 \begin_layout Standard
23865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23868 \begin_layout Standard
23875 <row topline="true">
23876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23879 \begin_layout Standard
23885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23888 \begin_layout Standard
23895 <row topline="true">
23896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23899 \begin_layout Standard
23905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23908 \begin_layout Standard
23909 FSR0L:PRODH:PRODL:WREG
23915 <row topline="true" bottomline="true">
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23919 \begin_layout Standard
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23928 \begin_layout Standard
23929 on stack, FSR0 points to the beginning
23942 \begin_layout Subsection
23946 \begin_layout Standard
23948 \begin_inset LatexCommand \index{PIC16!interrupt}
23952 service routine (ISR) is declared using the
23959 \begin_layout LyX-Code
23960 void isr(void) interrupt
23965 \begin_layout LyX-Code
23969 \begin_layout LyX-Code
23973 \begin_layout LyX-Code
23977 \begin_layout Standard
23982 is the interrupt number, which for PIC18F devices can be:
23985 \begin_layout Standard
23987 \begin_inset Tabular
23988 <lyxtabular version="3" rows="4" columns="3">
23990 <column alignment="center" valignment="top" leftline="true" width="0">
23991 <column alignment="center" valignment="top" leftline="true" width="0">
23992 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23993 <row topline="true" bottomline="true">
23994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23997 \begin_layout Standard
24005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24008 \begin_layout Standard
24014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24017 \begin_layout Standard
24018 Interrupt Vector Address
24024 <row topline="true">
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24028 \begin_layout Standard
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24037 \begin_layout Standard
24043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24046 \begin_layout Standard
24053 <row topline="true">
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24057 \begin_layout Standard
24072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24075 \begin_layout Standard
24085 HIGH priority interrupts
24090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24093 \begin_layout Standard
24100 <row topline="true" bottomline="true">
24101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24104 \begin_layout Standard
24110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24113 \begin_layout Standard
24114 LOW priority interrupts
24119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24122 \begin_layout Standard
24136 \begin_layout Standard
24137 When generating assembly code for ISR the code generator places a
24143 Interrupt Vector Address
24145 which points at the genetated ISR.
24146 This single GOTO instruction is part of an automatically generated
24148 interrupt entry point
24151 The actuall ISR code is placed as normally would in the code space.
24152 Upon interrupt request, the GOTO instruction is executed which jumps to
24154 When declaring interrupt functions as _naked this GOTO instruction is
24159 The whole interrupt functions is therefore placed at the Interrupt Vector
24160 Address of the specific interrupt.
24161 This is not a problem for the LOW priority interrupts, but it is a problem
24162 for the RESET and the HIGH priority interrupts because code may be written
24163 at the next interrupt´s vector address and cause undeterminate program
24164 behaviour if that interrupt is raised.
24168 \begin_layout Standard
24169 This is not a problem when
24172 \begin_layout Enumerate
24173 this is a HIGH interrupt ISR and LOW interrupts are
24180 \begin_layout Enumerate
24181 when the ISR is small enough not to reach the next interrupt´s vector address.
24189 \begin_layout Standard
24194 is possible to be omitted.
24195 This way a function is generated similar to an ISR, but it is not assigned
24199 \begin_layout Standard
24200 When entering an interrupt, currently the PIC16
24201 \begin_inset LatexCommand \index{PIC16}
24205 port automatically saves the following registers:
24208 \begin_layout Itemize
24212 \begin_layout Itemize
24216 \begin_layout Itemize
24220 \begin_layout Itemize
24221 PROD (PRODL and PRODH)
24224 \begin_layout Itemize
24225 FSR0 (FSR0L and FSR0H)
24228 \begin_layout Standard
24229 These registers are restored upon return from the interrupt routine.
24233 \begin_layout Standard
24234 NOTE that when the _naked attribute is specified for an interrupt routine,
24235 then NO registers are stored or restored.
24243 \begin_layout Subsection
24247 \begin_layout Standard
24248 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
24249 There are 3 types of generic pointers currently implemented data, code
24250 and eeprom pointers.
24251 They are differentiated by the value of the 7th and 6th bits of the upper
24255 \begin_layout Standard
24257 \begin_inset Tabular
24258 <lyxtabular version="3" rows="5" columns="5">
24260 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24261 <column alignment="center" valignment="top" width="0">
24262 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24263 <column alignment="center" valignment="top" width="0">
24264 <column alignment="left" valignment="top" rightline="true" width="0">
24265 <row topline="true" bottomline="true">
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24269 \begin_layout Standard
24275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24278 \begin_layout Standard
24284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24287 \begin_layout Standard
24293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24296 \begin_layout Standard
24297 rest of the pointer
24302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24305 \begin_layout Standard
24312 <row topline="true" bottomline="true">
24313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24316 \begin_layout Standard
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24325 \begin_layout Standard
24331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24334 \begin_layout Standard
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24343 \begin_layout Standard
24348 uuuuuu uuuuxxxx xxxxxxxx
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24356 \begin_layout Standard
24357 a 12-bit data pointer in data RAM memory
24363 <row bottomline="true">
24364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24367 \begin_layout Standard
24373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24376 \begin_layout Standard
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24385 \begin_layout Standard
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24394 \begin_layout Standard
24399 uxxxxx xxxxxxxx xxxxxxxx
24404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24407 \begin_layout Standard
24408 a 21-bit code pointer in FLASH memory
24414 <row bottomline="true">
24415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24418 \begin_layout Standard
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24427 \begin_layout Standard
24433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24436 \begin_layout Standard
24442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24445 \begin_layout Standard
24450 uuuuuu uuuuuuxx xxxxxxxx
24455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24458 \begin_layout Standard
24459 a 10-bit eeprom pointer in EEPROM memory
24465 <row bottomline="true">
24466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24469 \begin_layout Standard
24475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24478 \begin_layout Standard
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24487 \begin_layout Standard
24493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24496 \begin_layout Standard
24501 xxxxxx xxxxxxxx xxxxxxxx
24506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24509 \begin_layout Standard
24510 unimplemented pointer type
24523 \begin_layout Standard
24524 Generic pointer are read and written with a set of library functions which
24525 read/write 1, 2, 3, 4 bytes.
24528 \begin_layout Subsection
24532 \begin_layout Subsubsection
24533 Standard I/O Streams
24536 \begin_layout Standard
24541 the type FILE is defined as:
24544 \begin_layout LyX-Code
24545 typedef char * FILE;
24548 \begin_layout Standard
24549 This type is the stream type implemented I/O in the PIC18F devices.
24550 Also the standard input and output streams are declared in stdio.h:
24553 \begin_layout LyX-Code
24554 extern FILE * stdin;
24557 \begin_layout LyX-Code
24558 extern FILE * stdout;
24561 \begin_layout Standard
24562 The FILE type is actually a generic pointer which defines one more type
24563 of generic pointers, the
24568 This new type has the format:
24571 \begin_layout Standard
24573 \begin_inset Tabular
24574 <lyxtabular version="3" rows="2" columns="7">
24576 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24577 <column alignment="center" valignment="top" width="0">
24578 <column alignment="center" valignment="top" leftline="true" width="0">
24579 <column alignment="center" valignment="top" leftline="true" width="0">
24580 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24581 <column alignment="center" valignment="top" width="0">
24582 <column alignment="left" valignment="top" rightline="true" width="0">
24583 <row topline="true" bottomline="true">
24584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24587 \begin_layout Standard
24593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24596 \begin_layout Standard
24602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24605 \begin_layout Standard
24611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24614 \begin_layout Standard
24620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24623 \begin_layout Standard
24629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24632 \begin_layout Standard
24633 rest of the pointer
24638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24641 \begin_layout Standard
24648 <row topline="true" bottomline="true">
24649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24652 \begin_layout Standard
24658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24661 \begin_layout Standard
24667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24670 \begin_layout Standard
24676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24679 \begin_layout Standard
24685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24688 \begin_layout Standard
24694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24697 \begin_layout Standard
24707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24710 \begin_layout Standard
24711 upper byte high nubble is 0x2n, the rest are zeroes
24724 \begin_layout Standard
24725 Currently implemented there are 3 types of streams defined:
24728 \begin_layout Standard
24730 \begin_inset Tabular
24731 <lyxtabular version="3" rows="4" columns="4">
24733 <column alignment="center" valignment="top" leftline="true" width="0">
24734 <column alignment="center" valignment="top" leftline="true" width="0">
24735 <column alignment="center" valignment="top" leftline="true" width="0">
24736 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24737 <row topline="true" bottomline="true">
24738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24741 \begin_layout Standard
24747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24750 \begin_layout Standard
24756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24759 \begin_layout Standard
24765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24768 \begin_layout Standard
24775 <row topline="true">
24776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24779 \begin_layout Standard
24785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24788 \begin_layout Standard
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24799 \begin_layout Standard
24805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24808 \begin_layout Standard
24809 Writes/Reads characters via the USART peripheral
24815 <row topline="true">
24816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24819 \begin_layout Standard
24825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24828 \begin_layout Standard
24836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24839 \begin_layout Standard
24845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24848 \begin_layout Standard
24849 Writes/Reads characters via the MSSP peripheral
24855 <row topline="true" bottomline="true">
24856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24859 \begin_layout Standard
24865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24868 \begin_layout Standard
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24879 \begin_layout Standard
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24888 \begin_layout Standard
24889 Writes/Reads characters via used defined functions
24902 \begin_layout Standard
24903 The stream identifiers are declared as macros in the stdio.h header.
24906 \begin_layout Standard
24907 In the libc library there exist the functions that are used to write to
24908 each of the above streams.
24913 \labelwidthstring 00.00.0000
24918 \begin_layout Standard
24927 _stream_usart_putchar writes a character at the USART stream
24931 \labelwidthstring 00.00.0000
24936 \begin_layout Standard
24945 _stream_mssp_putchar writes a character at the MSSP stream
24949 \labelwidthstring 00.00.0000
24950 putchar dummy function.
24951 This writes a character to a user specified manner.
24954 \begin_layout Standard
24955 In order to increase performance
24959 is declared in stdio.h as having its parameter in WREG (it has the wparam
24961 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24962 in a user-friendly way.
24967 is the name of the variable that holds the character to print.
24968 An example follows:
24971 \begin_layout LyX-Code
24972 #include <pic18fregs.h>
24981 \begin_layout LyX-Code
24985 \begin_layout LyX-Code
24986 PORTA = c; /* dump character c to PORTA */
24989 \begin_layout LyX-Code
24997 \begin_layout LyX-Code
25001 \begin_layout LyX-Code
25002 stdout = STREAM_USER; /* this is not necessary, since stdout points
25005 \begin_layout LyX-Code
25006 * by default to STREAM_USER */
25009 \begin_layout LyX-Code
25010 printf (¨This is a printf test
25015 \begin_layout LyX-Code
25019 \begin_layout LyX-Code
25023 \begin_layout Subsubsection
25027 \begin_layout Standard
25028 PIC16 contains an implementation of the printf-family of functions.
25029 There exist the following functions:
25032 \begin_layout LyX-Code
25033 extern unsigned int sprintf(char *buf, char *fmt, ...);
25036 \begin_layout LyX-Code
25037 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25040 \begin_layout LyX-Code
25044 \begin_layout LyX-Code
25045 extern unsigned int printf(char *fmt, ...);
25048 \begin_layout LyX-Code
25049 extern unsigned int vprintf(char *fmt, va_lista ap);
25052 \begin_layout LyX-Code
25056 \begin_layout LyX-Code
25057 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25060 \begin_layout LyX-Code
25061 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25064 \begin_layout Standard
25065 For sprintf and vsprintf
25069 should normally be a data pointer where the resulting string will be placed.
25070 No range checking is done so the user should allocate the necessery buffer.
25071 For fprintf and vfprintf
25075 should be a stream pointer (i.e.
25076 stdout, STREAM_MSSP, etc...).
25079 \begin_layout Subsubsection
25083 \begin_layout Standard
25084 The PIC18F family of microcontrollers supports a number of interrupt sources.
25085 A list of these interrupts is shown in the following table:
25088 \begin_layout Standard
25090 \begin_inset Tabular
25091 <lyxtabular version="3" rows="11" columns="4">
25093 <column alignment="left" valignment="top" leftline="true" width="0">
25094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25095 <column alignment="left" valignment="top" leftline="true" width="0">
25096 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25097 <row topline="true" bottomline="true">
25098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25101 \begin_layout Standard
25107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25110 \begin_layout Standard
25116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25119 \begin_layout Standard
25125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25128 \begin_layout Standard
25135 <row topline="true">
25136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25139 \begin_layout Standard
25145 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25148 \begin_layout Standard
25149 PORTB change interrupt
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25157 \begin_layout Standard
25163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25166 \begin_layout Standard
25167 EEPROM/FLASH write complete interrupt
25173 <row topline="true">
25174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25177 \begin_layout Standard
25183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25186 \begin_layout Standard
25187 INT0 external interrupt
25192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25195 \begin_layout Standard
25201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25204 \begin_layout Standard
25205 Bus collision interrupt
25211 <row topline="true">
25212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25215 \begin_layout Standard
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25224 \begin_layout Standard
25225 INT1 external interrupt
25230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25233 \begin_layout Standard
25239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25242 \begin_layout Standard
25243 Low voltage detect interrupt
25249 <row topline="true">
25250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25253 \begin_layout Standard
25259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25262 \begin_layout Standard
25263 INT2 external interrupt
25268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25271 \begin_layout Standard
25277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25280 \begin_layout Standard
25281 Parallel slave port interrupt
25287 <row topline="true">
25288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25291 \begin_layout Standard
25297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25300 \begin_layout Standard
25301 CCP1 module interrupt
25306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25309 \begin_layout Standard
25315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25318 \begin_layout Standard
25319 AD convertion complete interrupt
25325 <row topline="true">
25326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25329 \begin_layout Standard
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25338 \begin_layout Standard
25339 CCP2 module interrupt
25344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25347 \begin_layout Standard
25353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25356 \begin_layout Standard
25357 USART receive interrupt
25363 <row topline="true">
25364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25367 \begin_layout Standard
25373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25376 \begin_layout Standard
25377 TMR0 overflow interrupt
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25385 \begin_layout Standard
25391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25394 \begin_layout Standard
25395 USART transmit interrupt
25401 <row topline="true">
25402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25405 \begin_layout Standard
25411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25414 \begin_layout Standard
25415 TMR1 overflow interrupt
25420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25423 \begin_layout Standard
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25432 \begin_layout Standard
25433 SSP receive/transmit interrupt
25439 <row topline="true">
25440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25443 \begin_layout Standard
25449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25452 \begin_layout Standard
25453 TMR2 matches PR2 interrupt
25458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25461 \begin_layout Standard
25467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25470 \begin_layout Standard
25477 <row topline="true" bottomline="true">
25478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25481 \begin_layout Standard
25487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25490 \begin_layout Standard
25491 TMR3 overflow interrupt
25496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25499 \begin_layout Standard
25505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25508 \begin_layout Standard
25522 \begin_layout Standard
25523 The prototypes for these names are defined in the header file
25530 \begin_layout Standard
25531 In order to simplify signal handling, a number of macros is provided:
25535 \labelwidthstring 00.00.0000
25536 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
25537 high priority interrupts.
25542 is the function name to use.
25546 \labelwidthstring 00.00.0000
25547 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
25548 low priority interrupt.
25553 is the function name to use.
25557 \labelwidthstring 00.00.0000
25558 DEF_HANDLER(sig,handler) define a handler for signal
25564 \labelwidthstring 00.00.0000
25565 END_DEF end the declaration of the dispatch table.
25568 \begin_layout Standard
25569 Additionally there are two more macros to simplify the declaration of the
25574 \labelwidthstring 00.00.0000
25577 SIGHANDLER(handler)
25579 this declares the function prototype for the
25587 \labelwidthstring 00.00.0000
25588 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
25591 \begin_layout Standard
25592 An example of using the macros above is shown below:
25595 \begin_layout LyX-Code
25596 #include <pic18fregs.h>
25599 \begin_layout LyX-Code
25600 #include <signal.h>
25604 DEF_INTHIGH(high_int)
25607 \begin_layout LyX-Code
25608 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
25611 \begin_layout LyX-Code
25612 DEF_HANDLER(SIG_BCOL, _bcol_handler)
25615 \begin_layout LyX-Code
25620 SIGHANDLER(_tmr0_handler)
25623 \begin_layout LyX-Code
25627 \begin_layout LyX-Code
25628 /* action to be taken when timer 0 overflows */
25631 \begin_layout LyX-Code
25636 SIGHANDLERNAKED(_bcol_handler)
25639 \begin_layout LyX-Code
25643 \begin_layout LyX-Code
25647 \begin_layout LyX-Code
25648 /* action to be taken when bus collision occurs */
25651 \begin_layout LyX-Code
25655 \begin_layout LyX-Code
25659 \begin_layout LyX-Code
25663 \begin_layout Standard
25668 Special care should be taken when using the above scheme:
25671 \begin_layout Itemize
25672 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
25675 \begin_layout Itemize
25676 when declaring SIGHANDLERNAKED handler never forget to use
25680 for proper returning.
25683 \begin_layout Subsection
25687 \begin_layout Standard
25688 Here you can find some general tips for compiling programs with SDCC/pic16.
25691 \begin_layout Subsubsection
25695 \begin_layout Standard
25697 \begin_inset LatexCommand \index{PIC16!stack}
25701 size (that is 64 bytes) probably is enough for many programs.
25702 One must take care that when there are many levels of function nesting,
25703 or there is excessive usage of stack, its size should be extended.
25704 An example of such a case is the printf/sprintf family of functions.
25705 If you encounter problems like not being able to print integers, then you
25706 need to set the stack size around the maximum (256 for small stack model).
25707 The following diagram shows what happens when calling printf to print an
25711 \begin_layout LyX-Code
25712 printf () --> ltoa () --> ultoa () --> divschar ()
25715 \begin_layout Standard
25716 It is should be understood that stack is easily consumed when calling complicate
25718 Using command line arguments like -
25722 \begin_layout Standard
25731 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
25733 Other ways to reduce stack usage may exist.
25736 \begin_layout Subsection
25740 \begin_layout Standard
25741 The PIC16 Port currently does not pass SDCC's regression test
25742 \begin_inset LatexCommand \index{Regression test (PIC16)}
25747 \begin_inset LatexCommand \ref{sec:Quality-control}
25751 ) and thus the nightly regression tests for the PIC16 target are currently
25752 disabled for all hosts except for
25757 This means you can see the result of the PIC16 regression tests f.e.
25758 by checking the log files in
25759 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
25763 (pick the most up to date file there, scroll down, lend a hand).
25766 \begin_layout Chapter
25770 \begin_layout Standard
25771 There are several approaches to debugging your code.
25772 This chapter is meant to show your options and to give detail on some of
25777 When writing your code:
25780 \begin_layout Itemize
25781 write your code with debugging in mind (avoid duplicating code, put conceptually
25782 similar variables into structs, use structured code, have strategic points
25783 within your code where all variables are consistent, ...)
25786 \begin_layout Itemize
25787 run a syntax-checking tool like splint
25788 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25793 \begin_inset LatexCommand \index{lint (syntax checking tool)}
25801 \begin_layout Standard
25811 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25818 \begin_layout Itemize
25819 for the high level code use a C-compiler (like f.e.
25820 GCC) to compile run and debug the code on your host.
25825 \begin_layout Standard
25835 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25839 ) on howto handle syntax extensions like __xdata, __at(), ...
25843 \begin_layout Itemize
25844 use another C-compiler to compile code for your target.
25845 Always an option but not recommended:) And not very likely to help you.
25846 If you seriously consider walking this path you should at least occasionally
25847 check portability of your code.
25848 Most commercial compiler vendors will offer an evaluation version so you
25849 can test compile your code or snippets of your code.
25852 \begin_layout Standard
25853 Debugging on a simulator:
25856 \begin_layout Itemize
25857 there is a separate section about SDCDB (section
25858 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
25865 \begin_layout Itemize
25866 or (8051 specific) use a freeware/commercial simulator which interfaces
25868 \begin_inset LatexCommand \index{AOMF, AOMF51}
25873 \begin_inset LatexCommand \ref{OMF file}
25877 ) optionally generated by SDCC.
25880 \begin_layout Standard
25881 Debugging On-target:
25884 \begin_layout Itemize
25885 use a MCU port pin to serially output debug data to the RS232 port of your
25887 You'll probably want some level shifting device typically involving a MAX232
25889 If the hardware serial port of the MCU is not available search for 'Software
25890 UART' in your favourite search machine.
25893 \begin_layout Itemize
25894 use an on-target monitor.
25895 In this context a monitor is a small program which usually accepts commands
25896 via a serial line and allows to set program counter, to single step through
25897 a program and read/write memory locations.
25898 For the 8051 good examples of monitors are paulmon and cmon51 (see section
25900 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
25907 \begin_layout Itemize
25908 toggle MCU port pins at strategic points within your code and use an oscilloscop
25912 digital oscilloscope
25915 \begin_inset LatexCommand \index{Oscilloscope}
25919 with deep trace memory is really helpful especially if you have to debug
25920 a realtime application.
25921 If you need to monitor more pins than your oscilloscope provides you can
25922 sometimes get away with a small R-2R network.
25923 On a single channel oscilloscope you could f.e.
25924 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
25926 \begin_inset Formula $\Omega$
25929 resistor and the other one by a 5\InsetSpace ~
25931 \begin_inset Formula $\Omega$
25934 resistor to the oscilloscope probe (check output drive capability of the
25935 pins you want to monitor).
25936 If you need to monitor many more pins a
25943 \begin_layout Itemize
25957 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
25962 Usually very expensive.
25963 And very nice to have too.
25964 And usually locks you (for years...) to the devices the ICE can emulate.
25968 \begin_layout Itemize
25969 use a remote debugger.
25970 In most 8-bit systems the symbol information is not available on the target,
25971 and a complete debugger is too bulky for the target system.
25972 Therefore usually a debugger on the host system connects to an on-target
25973 debugging stub which accepts only primitive commands.
25976 Terms to enter into your favourite search engine could be 'remote debugging',
25977 'gdb stub' or 'inferior debugger'.
25981 \begin_layout Itemize
25982 use an on target hardware debugger.
25983 Some of the more modern MCUs include hardware support for setting break
25984 points and monitoring/changing variables by using dedicated hardware pins.
25985 This facility doesn't require additional code to run on the target and
25990 doesn't affect runtime behaviour until a breakpoint is hit.
25991 For the mcs51 most hardware debuggers use the AOMF
25992 \begin_inset LatexCommand \index{AOMF, AOMF51}
25997 \begin_inset LatexCommand \ref{OMF file}
26005 \begin_layout Standard
26009 \begin_layout Itemize
26010 if you are not familiar with any of the following terms you're likely to
26011 run into problems rather sooner than later:
26028 As an embedded programmer you
26032 to know them so why not look them up
26036 you have problems?)
26039 \begin_layout Itemize
26040 tell someone else about your problem (actually this is a surprisingly effective
26041 means to hunt down the bug even if the listener is not familiar with your
26043 As 'failure to communicate' is probably one of the job-induced deformations
26044 of an embedded programmer this is highly encouraged.
26047 \begin_layout Section
26048 Debugging with SDCDB
26049 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26054 \begin_inset LatexCommand \index{SDCDB (debugger)}
26061 \begin_layout Standard
26062 SDCC is distributed with a source level debugger
26063 \begin_inset LatexCommand \index{Debugger}
26068 The debugger uses a command line interface, the command repertoire of the
26069 debugger has been kept as close to gdb
26070 \begin_inset LatexCommand \index{gdb}
26074 (the GNU debugger) as possible.
26075 The configuration and build process is part of the standard compiler installati
26076 on, which also builds and installs the debugger in the target directory
26077 specified during configuration.
26078 The debugger allows you debug BOTH at the C source and at the ASM source
26082 \begin_layout Subsection
26083 Compiling for Debugging
26086 \begin_layout Standard
26091 \begin_layout Standard
26101 \begin_inset LatexCommand \index{-\/-debug}
26105 option must be specified for all files for which debug information is to
26107 The compiler generates a .adb file for each of these files.
26108 The linker creates the .cdb
26109 \begin_inset LatexCommand \index{<file>.cdb}
26114 \begin_inset LatexCommand \index{<file>.adb}
26118 files and the address information.
26119 This .cdb is used by the debugger.
26122 \begin_layout Subsection
26123 How the Debugger Works
26126 \begin_layout Standard
26131 \begin_layout Standard
26140 -debug option is specified the compiler generates extra symbol information
26141 some of which are put into the assembler source and some are put into the
26143 Then the linker creates the .cdb file from the individual .adb files with
26144 the address information for the symbols.
26145 The debugger reads the symbolic information generated by the compiler &
26146 the address information generated by the linker.
26147 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
26148 execution is controlled by the debugger.
26149 When a command is issued for the debugger, it translates it into appropriate
26150 commands for the simulator.
26151 (Currently SDCDM only connects to the simulator but
26156 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
26160 is an effort to connect directly to the hardware.)
26163 \begin_layout Subsection
26164 Starting the Debugger SDCDB
26167 \begin_layout Standard
26168 The debugger can be started using the following command line.
26169 (Assume the file you are debugging has the file name foo).
26183 The debugger will look for the following files.
26186 \begin_layout Itemize
26187 foo.c - the source file.
26190 \begin_layout Itemize
26191 foo.cdb - the debugger symbol information file.
26194 \begin_layout Itemize
26195 foo.ihx - the Intel hex format
26196 \begin_inset LatexCommand \index{Intel hex format}
26203 \begin_layout Subsection
26204 SDCDB Command Line Options
26207 \begin_layout Itemize
26212 \begin_layout Standard
26221 -directory=<source file directory> this option can used to specify the directory
26223 The debugger will look into the directory list specified for source, cdb
26225 The items in the directory list must be separated by ':', e.g.
26226 if the source files can be in the directories /home/src1 and /home/src2,
26231 \begin_layout Standard
26240 -directory option should be -
26244 \begin_layout Standard
26253 -directory=/home/src1:/home/src2.
26254 Note there can be no spaces in the option.
26258 \begin_layout Itemize
26259 -cd <directory> - change to the <directory>.
26262 \begin_layout Itemize
26263 -fullname - used by GUI front ends.
26266 \begin_layout Itemize
26267 -cpu <cpu-type> - this argument is passed to the simulator please see the
26268 simulator docs for details.
26271 \begin_layout Itemize
26272 -X <Clock frequency > this options is passed to the simulator please see
26273 the simulator docs for details.
26276 \begin_layout Itemize
26277 -s <serial port file> passed to simulator see the simulator docs for details.
26280 \begin_layout Itemize
26281 -S <serial in,out> passed to simulator see the simulator docs for details.
26284 \begin_layout Itemize
26285 -k <port number> passed to simulator see the simulator docs for details.
26288 \begin_layout Subsection
26289 SDCDB Debugger Commands
26292 \begin_layout Standard
26293 As mentioned earlier the command interface for the debugger has been deliberatel
26294 y kept as close the GNU debugger gdb, as possible.
26295 This will help the integration with existing graphical user interfaces
26296 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
26297 If you use a graphical user interface for the debugger you can skip this
26301 \begin_layout Subsubsection*
26302 break [line | file:line | function | file:function]
26305 \begin_layout Standard
26306 Set breakpoint at specified line or function:
26315 sdcdb>break foo.c:100
26317 sdcdb>break funcfoo
26319 sdcdb>break foo.c:funcfoo
26322 \begin_layout Subsubsection*
26323 clear [line | file:line | function | file:function ]
26326 \begin_layout Standard
26327 Clear breakpoint at specified line or function:
26336 sdcdb>clear foo.c:100
26338 sdcdb>clear funcfoo
26340 sdcdb>clear foo.c:funcfoo
26343 \begin_layout Subsubsection*
26347 \begin_layout Standard
26348 Continue program being debugged, after breakpoint.
26351 \begin_layout Subsubsection*
26355 \begin_layout Standard
26356 Execute till the end of the current function.
26359 \begin_layout Subsubsection*
26363 \begin_layout Standard
26364 Delete breakpoint number 'n'.
26365 If used without any option clear ALL user defined break points.
26368 \begin_layout Subsubsection*
26369 info [break | stack | frame | registers ]
26372 \begin_layout Itemize
26373 info break - list all breakpoints
26376 \begin_layout Itemize
26377 info stack - show the function call stack.
26380 \begin_layout Itemize
26381 info frame - show information about the current execution frame.
26384 \begin_layout Itemize
26385 info registers - show content of all registers.
26388 \begin_layout Subsubsection*
26392 \begin_layout Standard
26393 Step program until it reaches a different source line.
26394 Note: pressing <return> repeats the last command.
26397 \begin_layout Subsubsection*
26401 \begin_layout Standard
26402 Step program, proceeding through subroutine calls.
26405 \begin_layout Subsubsection*
26409 \begin_layout Standard
26410 Start debugged program.
26413 \begin_layout Subsubsection*
26417 \begin_layout Standard
26418 Print type information of the variable.
26421 \begin_layout Subsubsection*
26425 \begin_layout Standard
26426 print value of variable.
26429 \begin_layout Subsubsection*
26433 \begin_layout Standard
26434 load the given file name.
26435 Note this is an alternate method of loading file for debugging.
26438 \begin_layout Subsubsection*
26442 \begin_layout Standard
26443 print information about current frame.
26446 \begin_layout Subsubsection*
26450 \begin_layout Standard
26451 Toggle between C source & assembly source.
26454 \begin_layout Subsubsection*
26455 ! simulator command
26458 \begin_layout Standard
26459 Send the string following '!' to the simulator, the simulator response is
26461 Note the debugger does not interpret the command being sent to the simulator,
26462 so if a command like 'go' is sent the debugger can loose its execution
26463 context and may display incorrect values.
26466 \begin_layout Subsubsection*
26470 \begin_layout Standard
26473 My name is Bobby Brown"
26476 \begin_layout Subsection
26477 Interfacing SDCDB with DDD
26480 \begin_layout Standard
26481 \begin_inset Note Comment
26484 \begin_layout Standard
26485 The screenshot was converted from png to eps with:
26486 \begin_inset Quotes sld
26489 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
26490 \begin_inset Quotes srd
26493 which produces a pretty compact eps file which is free from compression
26497 \begin_layout Standard
26498 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
26499 as this broke the build system on Sourceforge (pdf-file was broken.
26500 pdflatex does not accept eps files).
26508 \begin_layout Standard
26524 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
26530 shows a screenshot of a debugging session with DDD
26531 \begin_inset LatexCommand \index{DDD (debugger)}
26535 (Unix only) on a simulated 8032.
26536 The debugging session might not run as smoothly as the screenshot suggests.
26537 The debugger allows setting of breakpoints, displaying and changing variables,
26538 single stepping through C and assembler code.
26541 The source was compiled with
26555 \begin_layout Standard
26567 -debug ddd_example.c
26580 and DDD was invoked with
26587 ddd -debugger "sdcdb -cpu 8032 ddd_example"
26590 \begin_layout Standard
26591 \begin_inset Note Note
26594 \begin_layout Standard
26595 Check that the double quotes or an apostroph within the command line survive
26596 the LyX tool chain.
26597 Previously the apostrophs got slanted in the PDF output so a cut and paste
26606 \begin_layout Subsection
26607 Interfacing SDCDB with XEmacs
26608 \begin_inset LatexCommand \index{XEmacs}
26613 \begin_inset LatexCommand \index{Emacs}
26620 \begin_layout Standard
26621 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
26622 sdcdb.el and sdcdbsrc.el.
26623 These two files can be found in the $(prefix)/bin directory after the installat
26625 These files need to be loaded into XEmacs for the interface to work.
26626 This can be done at XEmacs startup time by inserting the following into
26627 your '.xemacs' file (which can be found in your HOME directory):
26633 (load-file sdcdbsrc.el)
26639 .xemacs is a lisp file so the () around the command is REQUIRED.
26640 The files can also be loaded dynamically while XEmacs is running, set the
26641 environment variable 'EMACSLOADPATH' to the installation bin directory
26642 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
26643 To start the interface enter the following command:
26657 You will prompted to enter the file name to be debugged.
26662 The command line options that are passed to the simulator directly are
26663 bound to default values in the file sdcdbsrc.el.
26664 The variables are listed below, these values maybe changed as required.
26667 \begin_layout Itemize
26668 sdcdbsrc-cpu-type '51
26671 \begin_layout Itemize
26672 sdcdbsrc-frequency '11059200
26675 \begin_layout Itemize
26676 sdcdbsrc-serial nil
26679 \begin_layout Standard
26680 The following is a list of key mapping for the debugger interface.
26683 \begin_layout Standard
26706 binding\InsetSpace ~
26744 -------\InsetSpace ~
26815 sdcdb-back-from-src\InsetSpace ~
26844 rom-src\InsetSpace ~
26854 SDCDB continue command
26872 sdcdb-step-from-src\InsetSpace ~
26901 hatis-c-sexp\InsetSpace ~
26911 SDCDB ptypecommand for data at
26978 sdcdbsrc-delete\InsetSpace ~
26993 B Delete all breakpoints if no arg
27042 given or delete arg (C-u arg x)
27061 -frame\InsetSpace ~
27076 SDCDB Display current frame if no arg,
27125 given or display frame arg
27193 sdcdbsrc-goto-sdcdb\InsetSpace ~
27203 Goto the SDCDB output buffer
27222 t-c-sexp\InsetSpace ~
27233 SDCDB print command for data at
27300 sdcdbsrc-goto-sdcdb\InsetSpace ~
27311 o the SDCDB output buffer
27329 sdcdbsrc-mode\InsetSpace ~
27345 Toggles Sdcdbsrc mode (turns it
27361 sdcdb-finish-from-src\InsetSpace ~
27369 SDCDB finish command
27403 Set break for line with point
27418 sdcdbsrc-mode\InsetSpace ~
27434 Toggle Sdcdbsrc mode
27450 dbsrc-srcmode\InsetSpace ~
27470 \begin_layout Standard
27476 \begin_layout Chapter
27480 \begin_layout Standard
27481 Here are a few guidelines that will help the compiler generate more efficient
27482 code, some of the tips are specific to this compiler others are generally
27483 good programming practice.
27486 \begin_layout Itemize
27487 Use the smallest data type to represent your data-value.
27488 If it is known in advance that the value is going to be less than 256 then
27489 use an 'unsigned char' instead of a 'short' or 'int'.
27490 Please note, that ANSI C requires both signed and unsigned chars to be
27491 promoted to 'signed int'
27492 \begin_inset LatexCommand \index{promotion to signed int}
27497 \begin_inset Marginal
27500 \begin_layout Standard
27509 before doing any operation.
27511 \begin_inset LatexCommand \index{type promotion}
27516 \begin_inset LatexCommand \label{type promotion}
27520 can be omitted, if the result is the same.
27521 The effect of the promotion rules together with the sign-extension is often
27526 \begin_layout Verse
27529 unsigned char uc = 0xfe;
27531 if (uc * uc < 0) /* this is true! */
27544 \begin_layout Standard
27551 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
27559 \begin_layout Verse
27562 (unsigned char) -12 / (signed char) -3 = ...
27565 \begin_layout Standard
27566 No, the result is not 4:
27569 \begin_layout Verse
27572 (int) (unsigned char) -12 / (int) (signed char) -3 =
27574 (int) (unsigned char)
27575 0xf4 / (int) (signed char) 0xfd =
27577 (int) 0x00f4 / (int) 0xfffd =
27582 (int) 244 / (int) -3 =
27584 (int) -81 = (int) 0xffaf;
27587 \begin_layout Standard
27588 Don't complain, that gcc gives you a different result.
27589 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
27590 Therefore the results are different.
27593 \begin_inset Quotes sld
27597 \begin_inset Quotes srd
27603 \begin_layout Quote
27606 If well-defined overflow characteristics are important and negative values
27607 are not, or if you want to steer clear of sign-extension problems when
27608 manipulating bits or bytes, use one of the corresponding unsigned types.
27609 (Beware when mixing signed and unsigned values in expressions, though.)
27612 character types (especially unsigned char) can be used as "tiny" integers,
27613 doing so is sometimes more trouble than it's worth, due to unpredictable
27614 sign extension and increased code size.
27618 \begin_layout Itemize
27619 Use unsigned when it is known in advance that the value is not going to
27621 This helps especially if you are doing division or multiplication, bit-shifting
27622 or are using an array index.
27625 \begin_layout Itemize
27626 NEVER jump into a LOOP.
27629 \begin_layout Itemize
27630 Declare the variables to be local
27631 \begin_inset LatexCommand \index{local variables}
27635 whenever possible, especially loop control variables (induction).
27638 \begin_layout Itemize
27639 Have a look at the assembly listing to get a
27640 \begin_inset Quotes sld
27644 \begin_inset Quotes srd
27647 for the code generation.
27650 \begin_layout Section
27651 Porting code from or to other compilers
27652 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
27659 \begin_layout Itemize
27660 check whether endianness of the compilers differs and adapt where needed.
27663 \begin_layout Itemize
27664 check the device specific header files
27665 \begin_inset LatexCommand \index{Header files}
27670 \begin_inset LatexCommand \index{Include files}
27674 for compiler specific syntax.
27675 Eventually include the file <compiler.h
27676 \begin_inset LatexCommand \index{compiler.h (include file)}
27681 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
27685 to allow using common header files.
27688 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
27695 \begin_layout Itemize
27696 check whether the startup code contains the correct initialization (watchdog,
27700 \begin_layout Itemize
27701 check whether the sizes of short, int, long match.
27704 \begin_layout Itemize
27705 check if some 16 or 32 bit hardware registers require a specific addressing
27706 order (least significant or most significant byte first) and adapt if needed
27715 relate to time and not to lower/upper memory location here, so this is
27720 the same as endianness).
27723 \begin_layout Itemize
27724 check whether the keyword
27728 is used where needed.
27729 The compilers might differ in their optimization characteristics (as different
27730 versions of the same compiler might also use more clever optimizations
27731 this is good idea anyway).
27733 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
27740 \begin_layout Itemize
27741 check that the compilers are not told to supress warnings.
27744 \begin_layout Itemize
27745 check and convert compiler specific extensions (interrupts, memory areas,
27749 \begin_layout Itemize
27750 check for differences in type promotion.
27751 Especially check for math operations on
27760 For the sake of C99 compatibility SDCC will probably promote these to
27764 more often than other compilers.
27765 Eventually insert explicit casts to
27774 Also check that the ~\InsetSpace ~
27776 \begin_inset LatexCommand \index{\~\/ Operator}
27783 \begin_inset LatexCommand \index{bit}
27789 variables, use the !\InsetSpace ~
27792 \begin_inset LatexCommand \ref{type promotion}
27797 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27804 \begin_layout Itemize
27805 check the assembly code generated for interrupt routines (f.e.
27806 for calls to possibly non-reentrant library functions).
27809 \begin_layout Itemize
27810 check whether timing loops result in proper timing (or preferably consider
27811 a rewrite of the code with timer based delays instead).
27814 \begin_layout Itemize
27815 check for differences in printf parameters (some compilers push (va_arg
27816 \begin_inset LatexCommand \index{vararg, va\_arg}
27820 ) char variables as
27824 others push them as
27830 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27837 \begin_layout Itemize
27838 check the resulting memory map
27839 \begin_inset LatexCommand \index{Memory map}
27844 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
27845 ly idata, pdata, xdata).
27846 Eventually check if unexpected library functions are included.
27849 \begin_layout Section
27851 \begin_inset LatexCommand \index{Tools}
27855 included in the distribution
27858 \begin_layout Standard
27860 \begin_inset Tabular
27861 <lyxtabular version="3" rows="12" columns="3">
27863 <column alignment="left" valignment="top" leftline="true" width="0pt">
27864 <column alignment="left" valignment="top" leftline="true" width="0pt">
27865 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27866 <row topline="true" bottomline="true">
27867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27870 \begin_layout Standard
27878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27881 \begin_layout Standard
27889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27892 \begin_layout Standard
27901 <row topline="true">
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27905 \begin_layout Standard
27907 \begin_inset LatexCommand \index{uCsim}
27916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27919 \begin_layout Standard
27920 Simulator for various architectures
27925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27928 \begin_layout Standard
27935 <row topline="true">
27936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27939 \begin_layout Standard
27945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27948 \begin_layout Standard
27950 \begin_inset LatexCommand \index{Header files}
27955 \begin_inset LatexCommand \index{Include files}
27964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27967 \begin_layout Standard
27968 sdcc/support/scripts
27974 <row topline="true">
27975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27978 \begin_layout Standard
27984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27987 \begin_layout Standard
27988 header file conversion
27993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27996 \begin_layout Standard
27997 sdcc/support/scripts
28003 <row topline="true">
28004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28007 \begin_layout Standard
28013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28016 \begin_layout Standard
28022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28025 \begin_layout Standard
28041 <row topline="true">
28042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28045 \begin_layout Standard
28051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28054 \begin_layout Standard
28060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28063 \begin_layout Standard
28079 <row topline="true">
28080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28083 \begin_layout Standard
28089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28092 \begin_layout Standard
28098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28101 \begin_layout Standard
28117 <row topline="true">
28118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28121 \begin_layout Standard
28127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28130 \begin_layout Standard
28136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28139 \begin_layout Standard
28155 <row topline="true">
28156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28159 \begin_layout Standard
28165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28168 \begin_layout Standard
28174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28177 \begin_layout Standard
28193 <row topline="true">
28194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28197 \begin_layout Standard
28203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28206 \begin_layout Standard
28212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28215 \begin_layout Standard
28231 <row topline="true">
28232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28235 \begin_layout Standard
28241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28244 \begin_layout Standard
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28253 \begin_layout Standard
28269 <row topline="true" bottomline="true">
28270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28273 \begin_layout Standard
28279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28282 \begin_layout Standard
28284 \begin_inset LatexCommand \index{packihx (tool)}
28293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28296 \begin_layout Standard
28321 \begin_layout Section
28323 \begin_inset LatexCommand \index{Documentation}
28327 included in the distribution
28330 \begin_layout Standard
28332 \begin_inset Tabular
28333 <lyxtabular version="3" rows="10" columns="2">
28335 <column alignment="block" valignment="top" leftline="true" width="40col%">
28336 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
28337 <row topline="true" bottomline="true" endhead="true">
28338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28341 \begin_layout Standard
28349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28352 \begin_layout Standard
28355 Filename / Where to get
28361 <row topline="true">
28362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28365 \begin_layout Standard
28366 SDCC Compiler User Guide
28371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28374 \begin_layout Standard
28375 You're reading it right now
28387 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
28397 <row topline="true">
28398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28401 \begin_layout Standard
28407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28410 \begin_layout Standard
28423 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28433 <row topline="true">
28434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28437 \begin_layout Standard
28439 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
28444 \begin_inset LatexCommand \index{Assembler documentation}
28451 \begin_inset LatexCommand \index{aslink}
28456 \begin_inset LatexCommand \index{Linker documentation}
28465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28468 \begin_layout Standard
28469 sdcc/as/doc/asxhtm.html
28481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
28491 <row topline="true">
28492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28495 \begin_layout Standard
28496 SDCC regression test
28497 \begin_inset LatexCommand \index{Regression test}
28506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28509 \begin_layout Standard
28510 sdcc/doc/test_suite_spec.pdf
28522 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28532 <row topline="true">
28533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28536 \begin_layout Standard
28542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28545 \begin_layout Standard
28558 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
28568 <row topline="true">
28569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28572 \begin_layout Standard
28573 Notes on debugging with SDCDB
28574 \begin_inset LatexCommand \index{SDCDB (debugger)}
28583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28586 \begin_layout Standard
28587 sdcc/debugger/README
28599 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
28609 <row topline="true">
28610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28613 \begin_layout Standard
28615 \begin_inset LatexCommand \index{uCsim}
28619 Software simulator for microcontrollers
28624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28627 \begin_layout Standard
28657 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
28667 <row topline="true">
28668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28671 \begin_layout Standard
28672 Temporary notes on the pic16
28673 \begin_inset LatexCommand \index{PIC16}
28682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28685 \begin_layout Standard
28686 sdcc/src/pic16/NOTES
28698 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
28708 <row topline="true" bottomline="true">
28709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28712 \begin_layout Standard
28713 SDCC internal documentation (debugging file format)
28718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28721 \begin_layout Standard
28751 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
28770 \begin_layout Section
28771 Related open source tools
28772 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
28777 \begin_inset LatexCommand \index{Related tools}
28784 \begin_layout Standard
28786 \begin_inset Tabular
28787 <lyxtabular version="3" rows="14" columns="3">
28789 <column alignment="left" valignment="top" leftline="true" width="0pt">
28790 <column alignment="block" valignment="top" leftline="true" width="30line%">
28791 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28792 <row topline="true" bottomline="true">
28793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28796 \begin_layout Standard
28804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28807 \begin_layout Standard
28815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28818 \begin_layout Standard
28827 <row topline="true">
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28831 \begin_layout Standard
28833 \begin_inset LatexCommand \index{gpsim (pic simulator)}
28842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28845 \begin_layout Standard
28851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28854 \begin_layout Standard
28855 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
28865 <row topline="true">
28866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28869 \begin_layout Standard
28871 \begin_inset LatexCommand \index{gputils (pic tools)}
28880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28883 \begin_layout Standard
28889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28892 \begin_layout Standard
28893 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
28903 <row topline="true">
28904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28907 \begin_layout Standard
28913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28916 \begin_layout Standard
28922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28925 \begin_layout Standard
28926 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
28936 <row topline="true">
28937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28940 \begin_layout Standard
28946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28949 \begin_layout Standard
28950 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
28956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28959 \begin_layout Standard
28960 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
28970 <row topline="true">
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28974 \begin_layout Standard
28976 \begin_inset LatexCommand \index{indent (source formatting tool)}
28985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28988 \begin_layout Standard
28989 Formats C source - Master of the white spaces
28994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28997 \begin_layout Standard
28998 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
29008 <row topline="true">
29009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29012 \begin_layout Standard
29014 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29026 \begin_layout Standard
29027 Object file conversion, checksumming, ...
29032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29035 \begin_layout Standard
29036 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29046 <row topline="true">
29047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29050 \begin_layout Standard
29052 \begin_inset LatexCommand \index{objdump (tool)}
29061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29064 \begin_layout Standard
29065 Object file conversion, ...
29070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29073 \begin_layout Standard
29074 Part of binutils (should be there anyway)
29080 <row topline="true">
29081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29084 \begin_layout Standard
29090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29093 \begin_layout Standard
29094 8051 monitor (hex up-/download, single step, disassemble)
29099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29102 \begin_layout Standard
29103 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
29113 <row topline="true">
29114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29117 \begin_layout Standard
29119 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
29128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29131 \begin_layout Standard
29132 Source code documentation system
29137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29140 \begin_layout Standard
29141 \begin_inset LatexCommand \url{http://www.doxygen.org}
29151 <row topline="true">
29152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29155 \begin_layout Standard
29161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29164 \begin_layout Standard
29165 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
29170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29173 \begin_layout Standard
29174 \begin_inset LatexCommand \url{http://www.kdevelop.org}
29184 <row topline="true">
29185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29188 \begin_layout Standard
29194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29197 \begin_layout Standard
29198 8051 monitor (hex up-/download, single step, disassemble)
29203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29206 \begin_layout Standard
29207 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
29217 <row topline="true">
29218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29221 \begin_layout Standard
29223 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29235 \begin_layout Standard
29236 Statically checks c sources (see
29237 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29249 \begin_layout Standard
29250 \begin_inset LatexCommand \url{http://www.splint.org}
29260 <row topline="true" bottomline="true">
29261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29264 \begin_layout Standard
29266 \begin_inset LatexCommand \index{DDD (debugger)}
29275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29278 \begin_layout Standard
29279 Debugger, serves nicely as GUI to SDCDB
29280 \begin_inset LatexCommand \index{SDCDB (debugger)}
29289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29292 \begin_layout Standard
29293 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
29312 \begin_layout Section
29313 Related documentation / recommended reading
29316 \begin_layout Standard
29318 \begin_inset Tabular
29319 <lyxtabular version="3" rows="7" columns="3">
29321 <column alignment="left" valignment="top" leftline="true" width="0pt">
29322 <column alignment="left" valignment="top" leftline="true" width="0">
29323 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29324 <row topline="true" bottomline="true">
29325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29328 \begin_layout Standard
29336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29339 \begin_layout Standard
29347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29350 \begin_layout Standard
29359 <row topline="true">
29360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29363 \begin_layout Standard
29378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29381 \begin_layout Standard
29383 \begin_inset LatexCommand \index{C Reference card}
29392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29395 \begin_layout Standard
29396 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
29406 <row topline="true">
29407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29410 \begin_layout Standard
29416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29419 \begin_layout Standard
29421 \begin_inset LatexCommand \index{C FAQ}
29430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29433 \begin_layout Standard
29434 \begin_inset LatexCommand \url{http://www.c-faq.com}
29444 <row topline="true">
29445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29448 \begin_layout Standard
29454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29457 \begin_layout Standard
29458 \begin_inset Quotes sld
29462 \begin_inset Quotes srd
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29473 \begin_layout Standard
29476 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29486 <row topline="true">
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29490 \begin_layout Standard
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29499 \begin_layout Standard
29500 \begin_inset Quotes sld
29503 Extensions for Embedded C
29504 \begin_inset Quotes srd
29512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29515 \begin_layout Standard
29518 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
29528 <row topline="true">
29529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29532 \begin_layout Standard
29538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29541 \begin_layout Standard
29542 Latest datasheet of target CPU
29547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29550 \begin_layout Standard
29557 <row topline="true" bottomline="true">
29558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29561 \begin_layout Standard
29567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29570 \begin_layout Standard
29571 Revision history of datasheet
29576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29579 \begin_layout Standard
29595 \begin_layout Section
29596 Application notes specifically for SDCC
29599 \begin_layout Standard
29600 SDCC makes no claims about the completeness of this list and about up-to-datenes
29601 s or correctness of the application notes
29602 \begin_inset LatexCommand \index{Application notes}
29609 \begin_layout Standard
29613 \begin_inset Tabular
29614 <lyxtabular version="3" rows="7" columns="3">
29616 <column alignment="block" valignment="top" leftline="true" width="17col%">
29617 <column alignment="block" valignment="top" leftline="true" width="27col%">
29618 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
29619 <row topline="true" bottomline="true">
29620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29623 \begin_layout Standard
29632 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
29635 \begin_layout Standard
29644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29647 \begin_layout Standard
29657 <row topline="true">
29658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29661 \begin_layout Standard
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29672 \begin_layout Standard
29675 Using the SDCC Compiler for the DS80C400
29676 \begin_inset LatexCommand \index{DS80C400}
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29688 \begin_layout Standard
29691 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
29701 <row topline="true">
29702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29705 \begin_layout Standard
29713 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
29716 \begin_layout Standard
29719 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
29720 \begin_inset LatexCommand \index{DS89C4x0}
29724 Family of Microcontrollers
29729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29732 \begin_layout Standard
29735 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
29745 <row topline="true">
29746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29749 \begin_layout Standard
29752 Silicon Laboratories / Cygnal
29757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29760 \begin_layout Standard
29763 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
29764 \begin_inset LatexCommand \index{IDE}
29773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29776 \begin_layout Standard
29779 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
29789 <row topline="true">
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29793 \begin_layout Standard
29796 Ramtron / Goal Semiconductor
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29804 \begin_layout Standard
29807 Interfacing SDCC to Syn and Textpad
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29815 \begin_layout Standard
29818 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29828 <row topline="true">
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29832 \begin_layout Standard
29835 Ramtron / Goal Semiconductor
29840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29843 \begin_layout Standard
29846 Installing and Configuring SDCC and Crimson Editor
29851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29854 \begin_layout Standard
29857 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29867 <row topline="true" bottomline="true">
29868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29871 \begin_layout Standard
29879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29882 \begin_layout Standard
29885 MSC12xx Programming with SDCC
29890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29893 \begin_layout Standard
29896 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
29913 \begin_layout Section
29917 \begin_layout Standard
29918 Some questions answered, some pointers given - it might be time to in turn
29926 \begin_layout Itemize
29927 can you solve your project with the selected microcontroller? Would you
29928 find out early or rather late that your target is too small/slow/whatever?
29929 Can you switch to a slightly better device if it doesn't fit?
29932 \begin_layout Itemize
29933 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
29934 and/or another programming language be more adequate? Would an operating
29935 system on the target device help?
29938 \begin_layout Itemize
29939 if you solved the problem, will the marketing department be happy?
29942 \begin_layout Itemize
29943 if the marketing department is happy, will customers be happy?
29946 \begin_layout Itemize
29947 if you're the project manager, marketing department and maybe even the customer
29948 in one person, have you tried to see the project from the outside?
29951 \begin_layout Itemize
29952 is the project done if you think it is done? Or is just that other interface/pro
29953 tocol/feature/configuration/option missing? How about website, manual(s),
29954 internationali(z|s)ation, packaging, labels, 2nd source for components,
29955 electromagnetic compatability/interference, documentation for production,
29956 production test software, update mechanism, patent issues?
29959 \begin_layout Itemize
29960 is your project adequately positioned in that magic triangle: fame, fortune,
29964 \begin_layout Standard
29965 Maybe not all answers to these questions are known and some answers may
29970 , nevertheless knowing these questions may help you to avoid burnout
29974 \begin_layout Standard
29975 burnout is bad for electronic devices, programmers and motorcycle tyres
29981 Chances are you didn't want to hear some of them...
29984 \begin_layout Chapter
29986 \begin_inset LatexCommand \index{Support}
29993 \begin_layout Standard
29994 SDCC has grown to be a large project.
29995 The compiler alone (without the preprocessor, assembler and linker) is
29996 well over 150,000 lines of code (blank stripped).
29997 The open source nature of this project is a key to its continued growth
29999 You gain the benefit and support of many active software developers and
30001 Is SDCC perfect? No, that's why we need your help.
30002 The developers take pride in fixing reported bugs.
30003 You can help by reporting the bugs and helping other SDCC users.
30004 There are lots of ways to contribute, and we encourage you to take part
30005 in making SDCC a great software package.
30009 \begin_layout Standard
30010 The SDCC project is hosted on the SDCC sourceforge site at
30011 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30016 You'll find the complete set of mailing lists
30017 \begin_inset LatexCommand \index{Mailing list(s)}
30021 , forums, bug reporting system, patch submission
30022 \begin_inset LatexCommand \index{Patch submission}
30027 \begin_inset LatexCommand \index{download}
30031 area and Subversion code repository
30032 \begin_inset LatexCommand \index{Subversion code repository}
30039 \begin_layout Section
30041 \begin_inset LatexCommand \index{Bug reporting}
30046 \begin_inset LatexCommand \index{Reporting bugs}
30053 \begin_layout Standard
30054 The recommended way of reporting bugs is using the infrastructure of the
30056 You can follow the status of bug reports there and have an overview about
30060 \begin_layout Standard
30061 Bug reports are automatically forwarded to the developer mailing list and
30062 will be fixed ASAP.
30063 When reporting a bug, it is very useful to include a small test program
30064 (the smaller the better) which reproduces the problem.
30065 If you can isolate the problem by looking at the generated assembly code,
30066 this can be very helpful.
30067 Compiling your program with the -
30071 \begin_layout Standard
30081 \begin_inset LatexCommand \index{-\/-dumpall}
30085 option can sometimes be useful in locating optimization problems.
30086 When reporting a bug please make sure you:
30089 \begin_layout Enumerate
30090 Attach the code you are compiling with SDCC.
30094 \begin_layout Enumerate
30095 Specify the exact command you use to run SDCC, or attach your Makefile.
30099 \begin_layout Enumerate
30100 Specify the SDCC version (type "
30106 "), your platform, and operating system.
30110 \begin_layout Enumerate
30111 Provide an exact copy of any error message or incorrect output.
30115 \begin_layout Enumerate
30116 Put something meaningful in the subject of your message.
30119 \begin_layout Standard
30120 Please attempt to include these 5 important parts, as applicable, in all
30121 requests for support or when reporting any problems or bugs with SDCC.
30122 Though this will make your message lengthy, it will greatly improve your
30123 chance that SDCC users and developers will be able to help you.
30124 Some SDCC developers are frustrated by bug reports without code provided
30125 that they can use to reproduce and ultimately fix the problem, so please
30126 be sure to provide sample code if you are reporting a bug!
30129 \begin_layout Standard
30130 Please have a short check that you are using a recent version of SDCC and
30131 the bug is not yet known.
30132 This is the link for reporting bugs:
30133 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
30138 With SDCC on average having more than 200 downloads
30139 \begin_inset LatexCommand \index{download}
30143 on sourceforge per day
30147 \begin_layout Standard
30148 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
30149 between 2002 and 2005.
30150 This does not include other methods of distribution.
30155 there must be some users.
30156 So it's not exactly easy to find a new bug.
30157 If you find one we need it:
30159 reporting bugs is good
30164 \begin_layout Section
30165 Requesting Features
30166 \begin_inset LatexCommand \label{sub:Requesting-Features}
30171 \begin_inset LatexCommand \index{Feature request}
30176 \begin_inset LatexCommand \index{Requesting features}
30183 \begin_layout Standard
30184 Like bug reports feature requests are forwarded to the developer mailing
30186 This is the link for requesting features:
30187 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30194 \begin_layout Section
30198 \begin_layout Standard
30199 Like bug reports contributed patches are forwarded to the developer mailing
30201 This is the link for submitting patches
30202 \begin_inset LatexCommand \index{Patch submission}
30207 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
30214 \begin_layout Standard
30215 You need to specify some parameters to the
30219 command for the patches to be useful.
30220 If you modified more than one file a patch created f.e.
30225 \begin_inset Quotes sld
30228 diff -Naur unmodified_directory modified_directory >my_changes.patch
30229 \begin_inset Quotes srd
30235 will be fine, otherwise
30239 \begin_inset Quotes sld
30242 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
30243 \begin_inset Quotes srd
30253 \begin_layout Section
30257 \begin_layout Standard
30258 These links should take you directly to the
30259 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
30267 \begin_layout Standard
30268 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
30269 automated messages (mid 2003)
30275 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
30280 \begin_inset LatexCommand \index{Mailing list(s)}
30284 and forums are archived and searchable so if you are lucky someone already
30285 had a similar problem.
30286 While mails to the lists themselves are delivered promptly their web front
30287 end on sourceforge sometimes shows a severe time lag (up to several weeks),
30288 if you're seriously using SDCC please consider subscribing to the lists.
30291 \begin_layout Section
30295 \begin_layout Standard
30296 You can follow the status of the Subversion version
30297 \begin_inset LatexCommand \index{version}
30301 of SDCC by watching the Changelog
30302 \begin_inset LatexCommand \index{Changelog}
30306 in the Subversion repository
30309 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30316 \begin_layout Section
30317 Subversion Source Code Repository
30320 \begin_layout Standard
30327 or the filenames of the snapshot versions of SDCC include date and its
30329 \begin_inset LatexCommand \index{Subversion code repository}
30334 Subversion allows to download the source of recent or previous versions
30336 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
30340 (by number or by date).
30341 An on-line source code browser and detailled instructions are also available
30343 SDCC versions starting from 1999 up to now are available (currently the
30344 versions prior to the conversion from cvs
30345 \begin_inset LatexCommand \index{cvs|see{Subversion}}
30349 to Subversion (April 2006) are either by accessible by Subversion or by
30353 \begin_layout Section
30355 \begin_inset LatexCommand \index{Release policy}
30362 \begin_layout Standard
30363 Historically there often were long delays between official releases and
30364 the sourceforge download area tends to get not updated at all.
30365 Excuses in the past might have referred to problems with live range analysis,
30366 but as this was fixed a while ago, the current problem is that another
30367 excuse has to be found.
30368 Kidding aside, we have to get better there! On the other hand there are
30369 daily snapshots available at
30370 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
30374 , and you can always build the very last version (hopefully with many bugs
30375 fixed, and features added) from the source code available at
30376 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
30382 \begin_inset LatexCommand \index{wiki}
30387 \begin_inset LatexCommand \index{Release wiki}
30392 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
30396 also holds some information about past and future releases.
30399 \begin_layout Section
30401 \begin_inset LatexCommand \index{Examples}
30408 \begin_layout Standard
30409 You'll find some small examples in the directory
30411 sdcc/device/examples/.
30414 More examples and libraries are available at
30416 The SDCC Open Knowledge Resource
30417 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
30424 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
30431 \begin_layout Standard
30432 \begin_inset Note Comment
30435 \begin_layout Standard
30436 I did insert a reference to Paul's web site here although it seems rather
30437 dedicated to a specific 8032 board (I think it's okay because it f.e.
30438 shows LCD/Harddisc interface and has a free 8051 monitor.
30439 Independent 8032 board vendors face hard competition of heavily subsidized
30440 development boards anyway).
30443 \begin_layout Standard
30444 Maybe we should include some links to real world applications.
30445 Preferably pointer to pointers (one for each architecture) so this stays
30454 \begin_layout Section
30456 \begin_inset LatexCommand \label{sec:Quality-control}
30461 \begin_inset LatexCommand \index{Quality control}
30468 \begin_layout Standard
30469 The compiler is passed through nightly compile and build checks.
30475 \begin_inset LatexCommand \index{Regression test}
30479 check that SDCC itself compiles flawlessly on several host platforms (i386,
30480 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
30481 the quality of the code generated by SDCC by running the code for several
30482 target platforms through simulators.
30483 The regression test suite comprises more than 100 files which expand to
30484 more than 500 test cases which include more than 4500 tests.
30485 The results of these tests are published daily on SDCC's snapshot page
30486 (click on the red or green symbols on the right side of
30487 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
30494 \begin_layout Standard
30495 There is a separate document
30498 \begin_inset LatexCommand \index{Test suite}
30505 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30509 about the regression test suite.
30512 \begin_layout Standard
30513 You'll find the test code in the directory
30515 sdcc/support/regression
30518 You can run these tests manually by running
30522 in this directory (or f.e.
30527 \begin_inset Quotes sld
30531 \begin_inset Quotes srd
30537 if you don't want to run the complete tests).
30538 The test code might also be interesting if you want to look for examples
30539 \begin_inset LatexCommand \index{Examples}
30543 checking corner cases of SDCC or if you plan to submit patches
30544 \begin_inset LatexCommand \index{Patch submission}
30551 \begin_layout Standard
30552 The 14bit pic port uses a different set of regression tests
30553 \begin_inset LatexCommand \index{Regression test (PIC14)}
30557 , you'll find them in the directory
30559 sdcc/src/regression
30564 \begin_layout Section
30565 Use of SDCC in Education
30568 \begin_layout Standard
30577 \begin_layout Standard
30578 the phrase "use in education" might evoke the association "
30582 fit for use in education".
30583 This connotation is not intended but nevertheless risked as the licensing
30584 of SDCC makes it difficult to offer educational discounts
30590 If your rationales are to:
30593 \begin_layout Enumerate
30594 give students a chance to understand the
30598 steps of code generation
30601 \begin_layout Enumerate
30602 have a curriculum that can be extended for years.
30603 Then you could use an fpga board as target and your curriculum will seamlessly
30604 extend from logic synthesis (
30605 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
30610 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
30614 ), over assembly programming, to C to FPGA compilers (
30615 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
30622 \begin_layout Enumerate
30623 be able to insert excursions about skills like using a revision control
30624 system, submitting/applying patches, using a type-setting (as opposed to
30625 word-processing) engine LyX/LaTeX, using
30626 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
30631 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
30635 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
30636 Source Software, CPU simulation, compiler regression tests
30637 \begin_inset LatexCommand \index{Regression test}
30644 And if there should be a shortage of ideas then you can always point students
30645 to the ever-growing feature request list
30646 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30653 \begin_layout Enumerate
30654 not tie students to a specific host platform and instead allow them to use
30659 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
30661 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
30668 \begin_layout Enumerate
30669 not encourage students to use illegal copies of educational software
30672 \begin_layout Enumerate
30673 be immune to licensing/availability/price changes of the chosen tool chain
30676 \begin_layout Enumerate
30677 be able to change to a new target platform without having to adopt a new
30681 \begin_layout Enumerate
30682 have complete control over and insight into the tool chain
30685 \begin_layout Enumerate
30686 make your students aware about the pros and cons of open source software
30690 \begin_layout Enumerate
30691 give back to the public as you are probably at least partially publically
30695 \begin_layout Enumerate
30696 give students a chance to publically prove their skills and to possibly
30697 see a world wide impact
30700 \begin_layout Standard
30701 then SDCC is probably among the first choices.
30702 Well, probably SDCC might be the only choice.
30705 \begin_layout Standard
30711 \begin_layout Chapter
30712 SDCC Technical Data
30715 \begin_layout Section
30717 \begin_inset LatexCommand \index{Optimizations}
30724 \begin_layout Standard
30725 SDCC performs a host of standard optimizations in addition to some MCU specific
30730 \begin_layout Subsection
30731 Sub-expression Elimination
30732 \begin_inset LatexCommand \index{Subexpression elimination}
30739 \begin_layout Standard
30740 The compiler does local and
30759 \begin_layout Verse
30767 \begin_layout Standard
30768 will be translated to
30771 \begin_layout Verse
30781 \begin_layout Standard
30782 Some subexpressions are not as obvious as the above example, e.g.:
30785 \begin_layout Verse
30793 \begin_layout Standard
30794 In this case the address arithmetic a->b[i] will be computed only once;
30795 the equivalent code in C would be.
30798 \begin_layout Verse
30808 \begin_layout Standard
30809 The compiler will try to keep these temporary variables in registers.
30812 \begin_layout Subsection
30813 Dead-Code Elimination
30814 \begin_inset LatexCommand \index{Dead-code elimination}
30821 \begin_layout Verse
30836 i = 1; \InsetSpace ~
30845 global = 1;\InsetSpace ~
30859 global = 3;\InsetSpace ~
30865 \begin_layout Standard
30869 \begin_layout Verse
30885 \begin_layout Subsection
30887 \begin_inset LatexCommand \index{Copy propagation}
30894 \begin_layout Verse
30918 \begin_layout Standard
30922 \begin_layout Verse
30946 \begin_layout Standard
30947 Note: the dead stores created by this copy propagation will be eliminated
30948 by dead-code elimination.
30951 \begin_layout Subsection
30953 \begin_inset LatexCommand \index{Loop optimization}
30958 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
30965 \begin_layout Standard
30966 Two types of loop optimizations are done by SDCC
30974 of loop induction variables.
30975 In addition to the strength reduction the optimizer marks the induction
30976 variables and the register allocator tries to keep the induction variables
30977 in registers for the duration of the loop.
30978 Because of this preference of the register allocator
30979 \begin_inset LatexCommand \index{Register allocation}
30983 , loop induction optimization causes an increase in register pressure, which
30984 may cause unwanted spilling of other temporary variables into the stack
30985 \begin_inset LatexCommand \index{stack}
30990 The compiler will generate a warning message when it is forced to allocate
30991 extra space either on the stack or data space.
30992 If this extra space allocation is undesirable then induction optimization
30993 can be eliminated either for the entire source file (with -
30997 \begin_layout Standard
31006 -noinduction option) or for a given function only using #pragma\InsetSpace ~
31008 \begin_inset LatexCommand \index{\#pragma noinduction}
31019 \begin_layout Verse
31022 for (i = 0 ; i < 100 ; i ++)
31031 \begin_layout Standard
31035 \begin_layout Verse
31040 for (i = 0; i < 100; i++)
31049 \begin_layout Standard
31050 As mentioned previously some loop invariants are not as apparent, all static
31051 address computations are also moved out of the loop.
31056 \begin_inset LatexCommand \index{Strength reduction}
31060 , this optimization substitutes an expression by a cheaper expression:
31063 \begin_layout Verse
31066 for (i=0;i < 100; i++)
31075 \begin_layout Standard
31079 \begin_layout Verse
31086 for (i=0;i< 100;i++) {
31092 ar[itemp1] = itemp2;
31110 \begin_layout Standard
31111 The more expensive multiplication
31112 \begin_inset LatexCommand \index{Multiplication}
31116 is changed to a less expensive addition.
31119 \begin_layout Subsection
31121 \begin_inset LatexCommand \index{Loop reversing}
31128 \begin_layout Standard
31129 This optimization is done to reduce the overhead of checking loop boundaries
31130 for every iteration.
31131 Some simple loops can be reversed and implemented using a
31132 \begin_inset Quotes eld
31135 decrement and jump if not zero
31136 \begin_inset Quotes erd
31140 SDCC checks for the following criterion to determine if a loop is reversible
31141 (note: more sophisticated compilers use data-dependency analysis to make
31142 this determination, SDCC uses a more simple minded analysis).
31145 \begin_layout Itemize
31146 The 'for' loop is of the form
31152 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
31162 \begin_layout Itemize
31163 The <for body> does not contain
31164 \begin_inset Quotes eld
31168 \begin_inset Quotes erd
31172 \begin_inset Quotes erd
31178 \begin_layout Itemize
31179 All goto's are contained within the loop.
31182 \begin_layout Itemize
31183 No function calls within the loop.
31186 \begin_layout Itemize
31187 The loop control variable <sym> is not assigned any value within the loop
31190 \begin_layout Itemize
31191 The loop control variable does NOT participate in any arithmetic operation
31195 \begin_layout Itemize
31196 There are NO switch statements in the loop.
31199 \begin_layout Subsection
31200 Algebraic Simplifications
31203 \begin_layout Standard
31204 SDCC does numerous algebraic simplifications, the following is a small sub-set
31205 of these optimizations.
31208 \begin_layout Verse
31211 i = j + 0;\InsetSpace ~
31215 /* changed to: */\InsetSpace ~
31221 i /= 2;\InsetSpace ~
31228 /* changed to: */\InsetSpace ~
31235 = j - j;\InsetSpace ~
31239 /* changed to: */\InsetSpace ~
31245 i = j / 1;\InsetSpace ~
31249 /* changed to: */\InsetSpace ~
31256 \begin_layout Standard
31257 Note the subexpressions
31258 \begin_inset LatexCommand \index{Subexpression}
31262 given above are generally introduced by macro expansions or as a result
31263 of copy/constant propagation.
31266 \begin_layout Subsection
31267 'switch' Statements
31268 \begin_inset LatexCommand \label{sub:'switch'-Statements}
31273 \begin_inset LatexCommand \index{switch statement}
31280 \begin_layout Standard
31281 SDCC can optimize switch statements to jump tables
31282 \begin_inset LatexCommand \index{jump tables}
31287 It makes the decision based on an estimate of the generated code size.
31288 SDCC is quite liberal in the requirements for jump table generation:
31291 \begin_layout Itemize
31292 The labels need not be in order, and the starting number need not be one
31293 or zero, the case labels are in numerical sequence or not too many case
31294 labels are missing.
31298 \begin_layout Verse
31301 switch(i) {\InsetSpace ~
31332 case 4: ...\InsetSpace ~
31364 case 5: ...\InsetSpace ~
31396 case 3: ...\InsetSpace ~
31427 case 6: ...\InsetSpace ~
31459 case 7: ...\InsetSpace ~
31491 case 8: ...\InsetSpace ~
31523 case 9: ...\InsetSpace ~
31555 case 10: ...\InsetSpace ~
31586 case 11: ...\InsetSpace ~
31653 \begin_layout Standard
31654 Both the above switch statements will be implemented using a jump-table.
31655 The example to the right side is slightly more efficient as the check for
31656 the lower boundary of the jump-table is not needed.
31660 \begin_layout Itemize
31661 The number of case labels is not larger than supported by the target architectur
31665 \begin_layout Itemize
31666 If the case labels are not in numerical sequence ('gaps' between cases)
31667 SDCC checks whether a jump table with additionally inserted dummy cases
31668 is still attractive.
31672 \begin_layout Itemize
31673 If the starting number is not zero and a check for the lower boundary of
31674 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
31679 \begin_layout Standard
31680 Switch statements which have large gaps in the numeric sequence or those
31681 that have too many case labels can be split into more than one switch statement
31682 for efficient code generation, e.g.:
31685 \begin_layout Verse
31763 \begin_layout Standard
31764 If the above switch statement is broken down into two switch statements
31767 \begin_layout Verse
31810 \begin_layout Standard
31814 \begin_layout Verse
31857 \begin_layout Standard
31858 then both the switch statements will be implemented using jump-tables whereas
31859 the unmodified switch statement will not be.
31862 \begin_layout Standard
31863 \begin_inset Note Comment
31866 \begin_layout Standard
31867 There might be reasons which SDCC cannot know about to either favour or
31868 not favour jump tables.
31869 If the target system has to be as quick for the last switch case as for
31870 the first (pro jump table), or if the switch argument is known to be zero
31871 in the majority of the cases (contra jump table).
31879 \begin_layout Standard
31880 The pragma nojtbound
31881 \begin_inset LatexCommand \index{\#pragma nojtbound}
31885 can be used to turn off checking the
31898 It has no effect if a default label is supplied.
31899 Use of this pragma is dangerous: if the switch
31900 \begin_inset LatexCommand \index{switch statement}
31904 argument is not matched by a case statement the processor will happily
31908 \begin_layout Subsection
31909 Bit-shifting Operations
31910 \begin_inset LatexCommand \index{Bit shifting}
31917 \begin_layout Standard
31918 Bit shifting is one of the most frequently used operation in embedded programmin
31920 SDCC tries to implement bit-shift operations in the most efficient way
31924 \begin_layout Verse
31937 \begin_layout Standard
31938 generates the following code:
31941 \begin_layout Verse
31956 \begin_layout Standard
31957 In general SDCC will never setup a loop if the shift count is known.
31961 \begin_layout Verse
31974 \begin_layout Standard
31978 \begin_layout Verse
32002 \begin_layout Subsection
32004 \begin_inset LatexCommand \index{Bit rotation}
32011 \begin_layout Standard
32012 A special case of the bit-shift operation is bit rotation
32013 \begin_inset LatexCommand \index{rotating bits}
32017 , SDCC recognizes the following expression to be a left bit-rotation:
32020 \begin_layout Verse
32028 char i;\InsetSpace ~
32039 /* unsigned is needed for rotation */
32044 i = ((i << 1) | (i >> 7));
32053 \begin_layout Standard
32054 will generate the following code:
32057 \begin_layout Verse
32074 \begin_layout Standard
32075 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32076 ns of this case will also be recognized as bit-rotation, i.e.:
32079 \begin_layout Verse
32082 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32085 \begin_layout Subsection
32086 Nibble and Byte Swapping
32089 \begin_layout Standard
32090 Other special cases of the bit-shift operations are nibble or byte swapping
32091 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32095 , SDCC recognizes the following expressions:
32098 \begin_layout Verse
32119 i = ((i << 4) | (i >> 4));
32125 j = ((j << 8) | (j >> 8));
32128 \begin_layout Standard
32129 and generates a swap instruction for the nibble swapping
32130 \begin_inset LatexCommand \index{Nibble swapping}
32134 or move instructions for the byte swapping
32135 \begin_inset LatexCommand \index{Byte swapping}
32141 \begin_inset Quotes sld
32145 \begin_inset Quotes srd
32148 example can be used to convert from little to big-endian or vice versa.
32149 If you want to change the endianness of a
32153 integer you have to cast to
32160 \begin_layout Standard
32161 Note that SDCC stores numbers in little-endian
32165 \begin_layout Standard
32166 Usually 8-bit processors don't care much about endianness.
32167 This is not the case for the standard 8051 which only has an instruction
32173 \begin_inset LatexCommand \index{DPTR}
32181 so little-endian is the more efficient byte order.
32187 \begin_inset LatexCommand \index{little-endian}
32192 \begin_inset LatexCommand \index{Endianness}
32197 lowest order first).
32200 \begin_layout Subsection
32202 \begin_inset LatexCommand \index{Highest Order Bit}
32207 \begin_inset LatexCommand \index{Any Order Bit}
32214 \begin_layout Standard
32215 It is frequently required to obtain the highest order bit of an integral
32216 type (long, int, short or char types).
32217 Also obtaining any other order bit is not uncommon.
32218 SDCC recognizes the following expressions to yield the highest order bit
32219 and generates optimized code for it, e.g.:
32222 \begin_layout Verse
32233 unsigned char hob1, aob1;
32237 bit hob2, hob3, aob2,
32247 hob1 = (gint >> 15) & 1;
32251 hob2 = (gint >> 15) & 1;
32255 hob3 = gint & 0x8000;
32260 aob1 = (gint >> 9) & 1;
32264 aob2 = (gint >> 8) & 1;
32268 aob3 = gint & 0x0800;
32278 \begin_layout Standard
32279 will generate the following code:
32282 \begin_layout Verse
32313 000A E5*01\InsetSpace ~
32340 000C 23\InsetSpace ~
32371 000D 54 01\InsetSpace ~
32399 000F F5*02\InsetSpace ~
32454 0011 E5*01\InsetSpace ~
32482 0013 33\InsetSpace ~
32512 0014 92*00\InsetSpace ~
32568 0016 E5*01\InsetSpace ~
32595 0018 33\InsetSpace ~
32625 0019 92*01\InsetSpace ~
32681 001B E5*01\InsetSpace ~
32740 001E 54 01\InsetSpace ~
32767 0020 F5*03\InsetSpace ~
32823 0022 E5*01\InsetSpace ~
32850 0024 13\InsetSpace ~
32880 0025 92*02\InsetSpace ~
32936 0027 E5*01\InsetSpace ~
32991 002B 92*03\InsetSpace ~
33019 \begin_layout Standard
33020 Other variations of these cases however will
33025 They are standard C expressions, so I heartily recommend these be the only
33026 way to get the highest order bit, (it is portable).
33027 Of course it will be recognized even if it is embedded in other expressions,
33031 \begin_layout Verse
33034 xyz = gint + ((gint >> 15) & 1);
33037 \begin_layout Standard
33038 will still be recognized.
33041 \begin_layout Subsection
33043 \begin_inset LatexCommand \index{Higher Order Byte}
33047 / Higher Order Word
33048 \begin_inset LatexCommand \index{Higher Order Word}
33055 \begin_layout Standard
33056 It is also frequently required to obtain a higher order byte or word of
33057 a larger integral type (long, int or short types).
33058 SDCC recognizes the following expressions to yield the higher order byte
33059 or word and generates optimized code for it, e.g.:
33062 \begin_layout Verse
33067 unsigned long int glong;
33075 unsigned char hob1,
33080 unsigned int how1, how2;
33089 hob1 = (gint >> 8) & 0xFF;
33093 hob2 = glong >> 24;
33097 how1 = (glong >> 16) & 0xFFFF;
33112 \begin_layout Standard
33113 will generate the following code:
33116 \begin_layout Verse
33147 0037 85*01*06\InsetSpace ~
33169 _foo_hob1_1_1,(_gint + 1)
33200 003A 85*05*07\InsetSpace ~
33222 _foo_hob2_1_1,(_glong + 3)
33252 003D 85*04*08\InsetSpace ~
33275 _foo_how1_1_1,(_glong + 2)
33277 0040 85*05*09\InsetSpace ~
33302 0043 85*03*0A\InsetSpace ~
33324 _foo_how2_1_1,(_glong + 1)
33326 0046 85*04*0B\InsetSpace ~
33349 (_foo_how2_1_1 + 1),(_glong + 2)
33352 \begin_layout Standard
33353 Again, variations of these cases may
33358 They are standard C expressions, so I heartily recommend these be the only
33359 way to get the higher order byte/word, (it is portable).
33360 Of course it will be recognized even if it is embedded in other expressions,
33364 \begin_layout Verse
33367 xyz = gint + ((gint >> 8) & 0xFF);
33370 \begin_layout Standard
33371 will still be recognized.
33374 \begin_layout Subsection
33376 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
33381 \begin_inset LatexCommand \index{Peephole optimizer}
33388 \begin_layout Standard
33389 The compiler uses a rule based, pattern matching and re-writing mechanism
33390 for peep-hole optimization.
33395 a peep-hole optimizer by Christopher W.
33396 Fraser (cwfraser\InsetSpace ~
33399 A default set of rules are compiled into the compiler, additional rules
33400 may be added with the
33406 \begin_layout Standard
33416 \begin_inset LatexCommand \index{-\/-peep-file}
33423 The rule language is best illustrated with examples.
33426 \begin_layout Verse
33448 \begin_layout Standard
33449 The above rule will change the following assembly
33450 \begin_inset LatexCommand \index{Assembler routines}
33457 \begin_layout Verse
33465 \begin_layout Standard
33469 \begin_layout Verse
33475 \begin_layout Standard
33476 Note: All occurrences of a
33480 (pattern variable) must denote the same string.
33481 With the above rule, the assembly sequence:
33484 \begin_layout Verse
33492 \begin_layout Standard
33493 will remain unmodified.
33497 Other special case optimizations may be added by the
33504 \begin_layout Standard
33517 some variants of the 8051 MCU
33518 \begin_inset LatexCommand \index{MCS51 variants}
33531 The following two rules will change all
33548 \begin_layout Verse
33551 replace { lcall %1 } by { acall %1 }
33553 replace { ljmp %1 } by { ajmp %1 }
33556 \begin_layout Standard
33559 inline-assembler code
33561 is also passed through the peep hole optimizer, thus the peephole optimizer
33562 can also be used as an assembly level macro expander.
33563 The rules themselves are MCU dependent whereas the rule language infra-structur
33564 e is MCU independent.
33565 Peephole optimization rules for other MCU can be easily programmed using
33570 The syntax for a rule is as follows:
33573 \begin_layout Verse
33576 rule := replace [ restart ] '{' <assembly sequence> '
33614 <assembly sequence> '
33632 '}' [if <functionName> ] '
33637 \begin_layout Standard
33638 <assembly sequence> := assembly instruction (each instruction including
33639 labels must be on a separate line).
33643 The optimizer will apply to the rules
33644 one by one from the top in the sequence of their appearance, it will terminate
33645 when all rules are exhausted.
33646 If the 'restart' option is specified, then the optimizer will start matching
33647 the rules again from the top, this option for a rule is expensive (performance)
33648 , it is intended to be used in situations where a transformation will trigger
33649 the same rule again.
33650 An example of this (not a good one, it has side effects) is the following
33654 \begin_layout Verse
33674 \begin_layout Standard
33675 Note that the replace pattern cannot be a blank, but can be a comment line.
33676 Without the 'restart' option only the innermost 'pop' 'push' pair would
33677 be eliminated, i.e.:
33680 \begin_layout Verse
33692 \begin_layout Standard
33696 \begin_layout Verse
33706 \begin_layout Standard
33711 the restart option the rule will be applied again to the resulting code
33712 and then all the pop-push pairs will be eliminated to yield:
33715 \begin_layout Verse
33723 \begin_layout Standard
33724 A conditional function can be attached to a rule.
33725 Attaching rules are somewhat more involved, let me illustrate this with
33729 \begin_layout Verse
33753 \begin_layout Standard
33754 The optimizer does a look-up of a function name table defined in function
33759 in the source file SDCCpeeph.c, with the name
33764 If it finds a corresponding entry the function is called.
33765 Note there can be no parameters specified for these functions, in this
33770 is crucial, since the function
33774 expects to find the label in that particular variable (the hash table containin
33775 g the variable bindings is passed as a parameter).
33776 If you want to code more such functions, take a close look at the function
33777 labelInRange and the calling mechanism in source file SDCCpeeph.c.
33778 Currently implemented are
33780 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
33781 24bitMode, portIsDS390, 24bitModeAndPortDS390
33790 \begin_layout Standard
33791 I know this whole thing is a little kludgey, but maybe some day we will
33792 have some better means.
33793 If you are looking at this file, you will see the default rules that are
33794 compiled into the compiler, you can add your own rules in the default set
33795 there if you get tired of specifying the -
33799 \begin_layout Standard
33811 \begin_layout Section
33813 \begin_inset LatexCommand \index{ANSI-compliance}
33818 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
33825 \begin_layout Standard
33826 The latest publically available version of the standard
33828 ISO/IEC 9899 - Programming languages - C
33830 should be available at:
33831 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
33840 \begin_layout Standard
33841 Deviations from the compliance:
33844 \begin_layout Itemize
33845 functions are not reentrant
33846 \begin_inset LatexCommand \index{reentrant}
33850 unless explicitly declared as such or the
33856 \begin_layout Standard
33866 \begin_inset LatexCommand \index{-\/-stack-auto}
33872 command line option is specified.
33875 \begin_layout Itemize
33877 \begin_inset LatexCommand \index{struct}
33882 \begin_inset LatexCommand \index{union}
33886 cannot be assigned values directly, cannot be passed as function parameters
33887 or assigned to each other and cannot be a return value
33888 \begin_inset LatexCommand \index{return value}
33892 from a function, e.g.:
33896 \begin_layout Verse
33919 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
33938 s parms) /* invalid in SDCC although allowed in ANSI */
33960 return rets; /* is invalid in SDCC although allowed in ANSI */
33966 \begin_layout Itemize
33967 initialization of structure arrays must be fully braced.
33971 \begin_layout Verse
33974 struct s { char x } a[] = {1, 2};\InsetSpace ~
33979 /* invalid in SDCC */
33982 } a[] = {{1}, {2}}; /* OK */
33986 \begin_layout Itemize
33988 \begin_inset LatexCommand \index{long long (not supported)}
33993 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
34000 \begin_layout Itemize
34002 \begin_inset LatexCommand \index{double (not supported)}
34006 ' precision floating point
34007 \begin_inset LatexCommand \index{Floating point support}
34014 \begin_layout Itemize
34016 \begin_inset LatexCommand \index{K\&R style}
34020 function declarations are NOT allowed.
34024 \begin_layout Verse
34027 foo(i,j) /* this old style of function declarations */
34029 int i,j; /* are valid
34030 in ANSI but not valid in SDCC */
34045 \begin_layout Itemize
34046 Most enhancements in C99 are not supported, f.e.:
34050 \begin_layout Verse
34055 \begin_inset LatexCommand \index{inline (not supported)}
34061 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34067 can be used as a work around */
34075 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34079 \begin_layout Itemize
34080 Certain words that are valid identifiers in the standard may be reserved
34081 words in SDCC unless the
34087 \begin_layout Standard
34097 \begin_inset LatexCommand \index{-\/-std-c89}
34105 \begin_layout Standard
34115 \begin_inset LatexCommand \index{-\/-std-c99}
34121 command line options are used.
34122 These may include (depending on the selected processor): 'at', 'banked',
34123 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
34124 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
34125 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
34127 Compliant equivalents of these keywords are always available in a form
34128 that begin with two underscores
34129 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
34134 '__data' instead of 'data'.
34137 \begin_layout Section
34138 Cyclomatic Complexity
34139 \begin_inset LatexCommand \index{Cyclomatic complexity}
34146 \begin_layout Standard
34147 Cyclomatic complexity of a function is defined as the number of independent
34148 paths the program can take during execution of the function.
34149 This is an important number since it defines the number test cases you
34150 have to generate to validate the function.
34151 The accepted industry standard for complexity number is 10, if the cyclomatic
34152 complexity reported by SDCC exceeds 10 you should think about simplification
34153 of the function logic.
34154 Note that the complexity level is not related to the number of lines of
34155 code in a function.
34156 Large functions can have low complexity, and small functions can have large
34162 SDCC uses the following formula to compute the complexity:
34167 \begin_layout Standard
34168 complexity = (number of edges in control flow graph) - (number of nodes
34169 in control flow graph) + 2;
34173 Having said that the industry standard is 10,
34174 you should be aware that in some cases it be may unavoidable to have a
34175 complexity level of less than 10.
34176 For example if you have switch statement with more than 10 case labels,
34177 each case label adds one to the complexity level.
34178 The complexity level is by no means an absolute measure of the algorithmic
34179 complexity of the function, it does however provide a good starting point
34180 for which functions you might look at for further optimization.
34183 \begin_layout Section
34184 Retargetting for other Processors
34187 \begin_layout Standard
34188 The issues for retargetting the compiler are far too numerous to be covered
34190 What follows is a brief description of each of the seven phases of the
34191 compiler and its MCU dependency.
34194 \begin_layout Itemize
34195 Parsing the source and building the annotated parse tree.
34196 This phase is largely MCU independent (except for the language extensions).
34197 Syntax & semantic checks are also done in this phase, along with some initial
34198 optimizations like back patching labels and the pattern matching optimizations
34199 like bit-rotation etc.
34202 \begin_layout Itemize
34203 The second phase involves generating an intermediate code which can be easy
34204 manipulated during the later phases.
34205 This phase is entirely MCU independent.
34206 The intermediate code generation assumes the target machine has unlimited
34207 number of registers, and designates them with the name iTemp.
34208 The compiler can be made to dump a human readable form of the code generated
34213 \begin_layout Standard
34225 \begin_layout Itemize
34226 This phase does the bulk of the standard optimizations and is also MCU independe
34228 This phase can be broken down into several sub-phases:
34232 Break down intermediate
34233 code (iCode) into basic blocks.
34235 Do control flow & data flow analysis on the
34238 Do local common subexpression elimination, then global subexpressio
34241 Dead code elimination
34245 If loop optimizations
34246 caused any changes then do 'global subexpression elimination' and 'dead
34247 code elimination' again.
34250 \begin_layout Itemize
34251 This phase determines the live-ranges; by live range I mean those iTemp
34252 variables defined by the compiler that still survive after all the optimization
34254 Live range analysis
34255 \begin_inset LatexCommand \index{Live range analysis}
34259 is essential for register allocation, since these computation determines
34260 which of these iTemps will be assigned to registers, and for how long.
34263 \begin_layout Itemize
34264 Phase five is register allocation.
34265 There are two parts to this process.
34269 The first part I call 'register packing'
34270 (for lack of a better term).
34271 In this case several MCU specific expression folding is done to reduce
34276 The second part is more MCU independent and deals with
34277 allocating registers to the remaining live ranges.
34278 A lot of MCU specific code does creep into this phase because of the limited
34279 number of index registers available in the 8051.
34282 \begin_layout Itemize
34283 The Code generation phase is (unhappily), entirely MCU dependent and very
34284 little (if any at all) of this code can be reused for other MCU.
34285 However the scheme for allocating a homogenized assembler operand for each
34286 iCode operand may be reused.
34289 \begin_layout Itemize
34290 As mentioned in the optimization section the peep-hole optimizer is rule
34291 based system, which can reprogrammed for other MCUs.
34294 \begin_layout Standard
34295 More information is available in a wiki
34296 \begin_inset LatexCommand \index{wiki}
34301 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
34305 ) and in the thread
34306 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
34313 \begin_layout Chapter
34315 \begin_inset LatexCommand \index{Compiler internals}
34322 \begin_layout Section
34323 The anatomy of the compiler
34324 \begin_inset LatexCommand \label{sub:The-anatomy-of}
34331 \begin_layout Standard
34334 This is an excerpt from an article published in Circuit Cellar Magazine
34340 It's a little outdated (the compiler is much more efficient now and user/develo
34341 per friendly), but pretty well exposes the guts of it all.
34347 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
34348 It is fairly easy to retarget for other 8-bit MCU.
34349 Here we take a look at some of the internals of the compiler.
34353 \begin_layout Paragraph*
34355 \begin_inset LatexCommand \index{Parsing}
34362 \begin_layout Standard
34363 Parsing the input source file and creating an AST (Annotated Syntax Tree
34364 \begin_inset LatexCommand \index{Annotated syntax tree}
34369 This phase also involves propagating types (annotating each node of the
34370 parse tree with type information) and semantic analysis.
34371 There are some MCU specific parsing rules.
34372 For example the storage classes, the extended storage classes are MCU specific
34373 while there may be a xdata storage class for 8051 there is no such storage
34374 class for z80 or Atmel AVR.
34375 SDCC allows MCU specific storage class extensions, i.e.
34376 xdata will be treated as a storage class specifier when parsing 8051 C
34377 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
34381 \begin_layout Paragraph*
34383 \begin_inset LatexCommand \index{iCode}
34390 \begin_layout Standard
34391 Intermediate code generation.
34392 In this phase the AST is broken down into three-operand form (iCode).
34393 These three operand forms are represented as doubly linked lists.
34394 ICode is the term given to the intermediate form generated by the compiler.
34395 ICode example section shows some examples of iCode generated for some simple
34396 C source functions.
34399 \begin_layout Paragraph*
34401 \begin_inset LatexCommand \index{Optimizations}
34408 \begin_layout Standard
34409 Bulk of the target independent optimizations is performed in this phase.
34410 The optimizations include constant propagation, common sub-expression eliminati
34411 on, loop invariant code movement, strength reduction of loop induction variables
34412 and dead-code elimination.
34415 \begin_layout Paragraph*
34416 Live range analysis
34417 \begin_inset LatexCommand \index{Live range analysis}
34424 \begin_layout Standard
34425 During intermediate code generation phase, the compiler assumes the target
34426 machine has infinite number of registers and generates a lot of temporary
34428 The live range computation determines the lifetime of each of these compiler-ge
34429 nerated temporaries.
34430 A picture speaks a thousand words.
34431 ICode example sections show the live range annotations for each of the
34433 It is important to note here, each iCode is assigned a number in the order
34434 of its execution in the function.
34435 The live ranges are computed in terms of these numbers.
34436 The from number is the number of the iCode which first defines the operand
34437 and the to number signifies the iCode which uses this operand last.
34440 \begin_layout Paragraph*
34441 Register Allocation
34442 \begin_inset LatexCommand \index{Register allocation}
34449 \begin_layout Standard
34450 The register allocation determines the type and number of registers needed
34452 In most MCUs only a few registers can be used for indirect addressing.
34453 In case of 8051 for example the registers R0 & R1 can be used to indirectly
34454 address the internal ram and DPTR to indirectly address the external ram.
34455 The compiler will try to allocate the appropriate register to pointer variables
34457 ICode example section shows the operands annotated with the registers assigned
34459 The compiler will try to keep operands in registers as much as possible;
34460 there are several schemes the compiler uses to do achieve this.
34461 When the compiler runs out of registers the compiler will check to see
34462 if there are any live operands which is not used or defined in the current
34463 basic block being processed, if there are any found then it will push that
34464 operand and use the registers in this block, the operand will then be popped
34465 at the end of the basic block.
34469 \begin_layout Standard
34470 There are other MCU specific considerations in this phase.
34471 Some MCUs have an accumulator; very short-lived operands could be assigned
34472 to the accumulator instead of a general-purpose register.
34475 \begin_layout Paragraph*
34479 \begin_layout Standard
34480 Figure II gives a table of iCode
34481 \begin_inset LatexCommand \index{iCode}
34485 operations supported by the compiler.
34486 The code generation involves translating these operations into corresponding
34487 assembly code for the processor.
34488 This sounds overly simple but that is the essence of code generation.
34489 Some of the iCode operations are generated on a MCU specific manner for
34490 example, the z80 port does not use registers to pass parameters so the
34491 SEND and RECV iCode operations will not be generated, and it also does
34492 not support JUMPTABLES.
34498 \begin_layout Standard
34502 \begin_inset Tabular
34503 <lyxtabular version="3" rows="39" columns="4">
34504 <features islongtable="true" headBottomDL="true">
34505 <column alignment="block" valignment="top" leftline="true" width="13col%">
34506 <column alignment="left" valignment="top" leftline="true" width="13col%">
34507 <column alignment="block" valignment="top" leftline="true" width="22col%">
34508 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
34509 <row topline="true" bottomline="true" endhead="true">
34510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34513 \begin_layout Standard
34519 \begin_inset LatexCommand \index{iCode}
34528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34531 \begin_layout Standard
34539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34542 \begin_layout Standard
34550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34553 \begin_layout Standard
34562 <row topline="true">
34563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34566 \begin_layout Standard
34574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34577 \begin_layout Standard
34580 IC_LEFT() IC_RESULT()
34585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34588 \begin_layout Standard
34596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34599 \begin_layout Standard
34602 IC_RESULT = ! IC_LEFT;
34608 <row topline="true">
34609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34612 \begin_layout Standard
34620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34623 \begin_layout Standard
34626 IC_LEFT() IC_RESULT()
34631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34634 \begin_layout Standard
34637 Bitwise complement of
34642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34645 \begin_layout Standard
34648 IC_RESULT = ~IC_LEFT;
34654 <row topline="true">
34655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34658 \begin_layout Standard
34666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34669 \begin_layout Standard
34672 IC_LEFT() IC_RESULT()
34677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34680 \begin_layout Standard
34683 Rotate right with carry
34688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34691 \begin_layout Standard
34694 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
34700 <row topline="true">
34701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34704 \begin_layout Standard
34712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34715 \begin_layout Standard
34718 IC_LEFT() IC_RESULT()
34723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34726 \begin_layout Standard
34729 Rotate left with carry
34734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34737 \begin_layout Standard
34740 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
34746 <row topline="true">
34747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34750 \begin_layout Standard
34758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34761 \begin_layout Standard
34764 IC_LEFT() IC_RESULT()
34769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34772 \begin_layout Standard
34775 Get the highest order bit of IC_LEFT
34780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34783 \begin_layout Standard
34786 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
34792 <row topline="true">
34793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34796 \begin_layout Standard
34804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34807 \begin_layout Standard
34810 IC_LEFT() IC_RESULT()
34815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34818 \begin_layout Standard
34826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34829 \begin_layout Standard
34832 IC_RESULT = - IC_LEFT;
34838 <row topline="true">
34839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34842 \begin_layout Standard
34850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34853 \begin_layout Standard
34861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34864 \begin_layout Standard
34867 Push the operand into stack
34872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34875 \begin_layout Standard
34884 <row topline="true">
34885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34888 \begin_layout Standard
34896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34899 \begin_layout Standard
34907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34910 \begin_layout Standard
34913 Pop the operand from the stack
34918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34921 \begin_layout Standard
34930 <row topline="true">
34931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34934 \begin_layout Standard
34942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34945 \begin_layout Standard
34948 IC_LEFT() IC_RESULT()
34953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34956 \begin_layout Standard
34959 Call the function represented by IC_LEFT
34964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34967 \begin_layout Standard
34970 IC_RESULT = IC_LEFT();
34976 <row topline="true">
34977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34980 \begin_layout Standard
34988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34991 \begin_layout Standard
34994 IC_LEFT() IC_RESULT()
34999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35002 \begin_layout Standard
35005 Call via function pointer
35010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35013 \begin_layout Standard
35016 IC_RESULT = (*IC_LEFT)();
35022 <row topline="true">
35023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35026 \begin_layout Standard
35034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35037 \begin_layout Standard
35045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35048 \begin_layout Standard
35051 Return the value in operand IC_LEFT
35056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35059 \begin_layout Standard
35068 <row topline="true">
35069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35072 \begin_layout Standard
35080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35083 \begin_layout Standard
35091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35094 \begin_layout Standard
35102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35105 \begin_layout Standard
35114 <row topline="true">
35115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35118 \begin_layout Standard
35126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35129 \begin_layout Standard
35137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35140 \begin_layout Standard
35148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35151 \begin_layout Standard
35160 <row topline="true">
35161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35164 \begin_layout Standard
35172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35175 \begin_layout Standard
35178 IC_LEFT() IC_RIGHT() IC_RESULT()
35183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35186 \begin_layout Standard
35194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35197 \begin_layout Standard
35200 IC_RESULT = IC_LEFT + IC_RIGHT
35206 <row topline="true">
35207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35210 \begin_layout Standard
35218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35221 \begin_layout Standard
35224 IC_LEFT() IC_RIGHT() IC_RESULT()
35229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35232 \begin_layout Standard
35240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35243 \begin_layout Standard
35246 IC_RESULT = IC_LEFT - IC_RIGHT
35252 <row topline="true">
35253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35256 \begin_layout Standard
35264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35267 \begin_layout Standard
35270 IC_LEFT() IC_RIGHT() IC_RESULT()
35275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35278 \begin_layout Standard
35286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35289 \begin_layout Standard
35292 IC_RESULT = IC_LEFT * IC_RIGHT;
35298 <row topline="true">
35299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35302 \begin_layout Standard
35310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35313 \begin_layout Standard
35316 IC_LEFT() IC_RIGHT() IC_RESULT()
35321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35324 \begin_layout Standard
35332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35335 \begin_layout Standard
35338 IC_RESULT = IC_LEFT / IC_RIGHT;
35344 <row topline="true">
35345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35348 \begin_layout Standard
35356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35359 \begin_layout Standard
35362 IC_LEFT() IC_RIGHT() IC_RESULT()
35367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35370 \begin_layout Standard
35378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35381 \begin_layout Standard
35384 IC_RESULT = IC_LEFT % IC_RIGHT;
35390 <row topline="true">
35391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35394 \begin_layout Standard
35402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35405 \begin_layout Standard
35408 IC_LEFT() IC_RIGHT() IC_RESULT()
35413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35416 \begin_layout Standard
35424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35427 \begin_layout Standard
35430 IC_RESULT = IC_LEFT < IC_RIGHT;
35436 <row topline="true">
35437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35440 \begin_layout Standard
35448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35451 \begin_layout Standard
35454 IC_LEFT() IC_RIGHT() IC_RESULT()
35459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35462 \begin_layout Standard
35470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35473 \begin_layout Standard
35476 IC_RESULT = IC_LEFT > IC_RIGHT;
35482 <row topline="true">
35483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35486 \begin_layout Standard
35494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35497 \begin_layout Standard
35500 IC_LEFT() IC_RIGHT() IC_RESULT()
35505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35508 \begin_layout Standard
35516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35519 \begin_layout Standard
35522 IC_RESULT = IC_LEFT == IC_RIGHT;
35528 <row topline="true">
35529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35532 \begin_layout Standard
35540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35543 \begin_layout Standard
35546 IC_LEFT() IC_RIGHT() IC_RESULT()
35551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35554 \begin_layout Standard
35557 Logical and operation
35562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35565 \begin_layout Standard
35568 IC_RESULT = IC_LEFT && IC_RIGHT;
35574 <row topline="true">
35575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35578 \begin_layout Standard
35586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35589 \begin_layout Standard
35592 IC_LEFT() IC_RIGHT() IC_RESULT()
35597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35600 \begin_layout Standard
35603 Logical or operation
35608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35611 \begin_layout Standard
35614 IC_RESULT = IC_LEFT || IC_RIGHT;
35620 <row topline="true">
35621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35624 \begin_layout Standard
35632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35635 \begin_layout Standard
35638 IC_LEFT() IC_RIGHT() IC_RESULT()
35643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35646 \begin_layout Standard
35654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35657 \begin_layout Standard
35660 IC_RESULT = IC_LEFT ^ IC_RIGHT;
35666 <row topline="true">
35667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35670 \begin_layout Standard
35678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35681 \begin_layout Standard
35684 IC_LEFT() IC_RIGHT() IC_RESULT()
35689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35692 \begin_layout Standard
35700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35703 \begin_layout Standard
35706 IC_RESULT = IC_LEFT | IC_RIGHT;
35712 <row topline="true">
35713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35716 \begin_layout Standard
35724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35727 \begin_layout Standard
35730 IC_LEFT() IC_RIGHT() IC_RESULT()
35735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35738 \begin_layout Standard
35746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35749 \begin_layout Standard
35752 IC_RESULT = IC_LEFT & IC_RIGHT;
35758 <row topline="true">
35759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35762 \begin_layout Standard
35770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35773 \begin_layout Standard
35776 IC_LEFT() IC_RIGHT() IC_RESULT()
35781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35784 \begin_layout Standard
35792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35795 \begin_layout Standard
35798 IC_RESULT = IC_LEFT << IC_RIGHT
35804 <row topline="true">
35805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35808 \begin_layout Standard
35816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35819 \begin_layout Standard
35822 IC_LEFT() IC_RIGHT() IC_RESULT()
35827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35830 \begin_layout Standard
35838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35841 \begin_layout Standard
35844 IC_RESULT = IC_LEFT >> IC_RIGHT
35850 <row topline="true">
35851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35854 \begin_layout Standard
35864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35867 \begin_layout Standard
35870 IC_LEFT() IC_RESULT()
35875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35878 \begin_layout Standard
35886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35889 \begin_layout Standard
35892 IC_RESULT = (*IC_LEFT);
35898 <row topline="true">
35899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35902 \begin_layout Standard
35910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35913 \begin_layout Standard
35916 IC_RIGHT() IC_RESULT()
35921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35924 \begin_layout Standard
35932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35935 \begin_layout Standard
35938 (*IC_RESULT) = IC_RIGHT;
35944 <row topline="true">
35945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35948 \begin_layout Standard
35956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35959 \begin_layout Standard
35962 IC_RIGHT() IC_RESULT()
35967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35970 \begin_layout Standard
35978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35981 \begin_layout Standard
35984 IC_RESULT = IC_RIGHT;
35990 <row topline="true">
35991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35994 \begin_layout Standard
36002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36005 \begin_layout Standard
36008 IC_COND IC_TRUE IC_LABEL
36013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36016 \begin_layout Standard
36020 If true label is present then jump to true label if condition is true else
36021 jump to false label if condition is false
36026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36029 \begin_layout Standard
36032 if (IC_COND) goto IC_TRUE;
36038 If (!IC_COND) goto IC_FALSE;
36044 <row topline="true">
36045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36048 \begin_layout Standard
36056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36059 \begin_layout Standard
36062 IC_LEFT() IC_RESULT()
36067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36070 \begin_layout Standard
36078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36081 \begin_layout Standard
36084 IC_RESULT = &IC_LEFT();
36090 <row topline="true">
36091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36094 \begin_layout Standard
36102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36105 \begin_layout Standard
36108 IC_JTCOND IC_JTLABELS
36113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36116 \begin_layout Standard
36119 Jump to list of labels depending on the value of JTCOND
36124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36127 \begin_layout Standard
36136 <row topline="true">
36137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36140 \begin_layout Standard
36148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36151 \begin_layout Standard
36154 IC_RIGHT() IC_LEFT() IC_RESULT()
36159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36162 \begin_layout Standard
36170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36173 \begin_layout Standard
36176 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
36182 <row topline="true">
36183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36186 \begin_layout Standard
36194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36197 \begin_layout Standard
36205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36208 \begin_layout Standard
36211 This is used for passing parameters in registers;
36213 move IC_LEFT to the next
36214 available parameter register.
36219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36222 \begin_layout Standard
36231 <row topline="true">
36232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36235 \begin_layout Standard
36243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36246 \begin_layout Standard
36254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36257 \begin_layout Standard
36260 This is used for receiving parameters passed in registers;
36263 in the next parameter register to IC_RESULT
36268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36271 \begin_layout Standard
36280 <row topline="true" bottomline="true">
36281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36284 \begin_layout Standard
36288 (some more have been added)
36293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36296 \begin_layout Standard
36302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36305 \begin_layout Standard
36311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36314 \begin_layout Standard
36338 \begin_layout Standard
36339 \begin_inset Note Comment
36342 \begin_layout Standard
36343 In the original article Figure II was announced to be downloadable on
36348 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
36356 \begin_layout Paragraph*
36358 \begin_inset LatexCommand \index{iCode}
36365 \begin_layout Standard
36366 This section shows some details of iCode.
36367 The example C code does not do anything useful; it is used as an example
36368 to illustrate the intermediate code generated by the compiler.
36371 \begin_layout Verse
36381 /* This function does nothing useful.
36388 for the purpose of explaining iCode */
36391 short function (data
36400 short i=10; \InsetSpace ~
36402 /* dead initialization eliminated */
36408 /* dead initialization eliminated */
36436 /* compiler detects i,j to be induction
36441 for (i = 0, j = 10 ; i < 10 ; i++, j
36447 \begin_layout Standard
36470 mul += i * 3; \InsetSpace ~
36472 /* this multiplication remains */
36479 j * 3;\InsetSpace ~
36481 /* this multiplication changed to addition */
36495 \begin_layout Standard
36496 In addition to the operands each iCode contains information about the filename
36497 and line it corresponds to in the source file.
36498 The first field in the listing should be interpreted as follows:
36503 Filename(linenumber: iCode Execution sequence number : ICode hash table
36504 key : loop depth of the iCode).
36509 Then follows the human readable form of the ICode operation.
36510 Each operand of this triplet form can be of three basic types a) compiler
36511 generated temporary b) user defined variable c) a constant value.
36512 Note that local variables and parameters are replaced by compiler generated
36515 \begin_inset LatexCommand \index{Live range analysis}
36519 are computed only for temporaries (i.e.
36520 live ranges are not computed for global variables).
36522 \begin_inset LatexCommand \index{Register allocation}
36526 are allocated for temporaries only.
36527 Operands are formatted in the following manner:
36532 Operand Name [lr live-from : live-to ] { type information } [ registers
36538 As mentioned earlier the live ranges are computed in terms of the execution
36539 sequence number of the iCodes, for example
36541 the iTemp0 is live from (i.e.
36542 first defined in iCode with execution sequence number 3, and is last used
36543 in the iCode with sequence number 5).
36544 For induction variables such as iTemp21 the live range computation extends
36545 the lifetime from the start to the end of the loop.
36547 The register allocator
36548 used the live range information to allocate registers, the same registers
36549 may be used for different temporaries if their live ranges do not overlap,
36550 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
36551 ranges do not overlap.
36552 In addition the allocator also takes into consideration the type and usage
36553 of a temporary, for example itemp6 is a pointer to near space and is used
36554 as to fetch data from (i.e.
36555 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
36556 Some short lived temporaries are allocated to special registers which have
36557 meaning to the code generator e.g.
36558 iTemp13 is allocated to a pseudo register CC which tells the back end that
36559 the temporary is used only for a conditional jump the code generation makes
36560 use of this information to optimize a compare and jump ICode.
36564 \begin_inset LatexCommand \index{Loop optimization}
36568 performed by the compiler.
36569 It can detect induction variables iTemp21(i) and iTemp23(j).
36570 Also note the compiler does selective strength reduction
36571 \begin_inset LatexCommand \index{Strength reduction}
36576 the multiplication of an induction variable in line 18 (gint = j * 3) is
36577 changed to addition, a new temporary iTemp17 is allocated and assigned
36578 a initial value, a constant 3 is then added for each iteration of the loop.
36579 The compiler does not change the multiplication
36580 \begin_inset LatexCommand \index{Multiplication}
36584 in line 17 however since the processor does support an 8 * 8 bit multiplication.
36587 Note the dead code elimination
36588 \begin_inset LatexCommand \index{Dead-code elimination}
36592 optimization eliminated the dead assignments in line 7 & 8 to I and sum
36598 \begin_layout Standard
36601 Sample.c (5:1:0:0) _entry($9) :
36604 \begin_layout Standard
36607 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
36610 \begin_layout Standard
36613 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
36616 \begin_layout Standard
36619 Sample.c(11:4:53:0) preHeaderLbl0($11) :
36622 \begin_layout Standard
36625 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
36629 \begin_layout Standard
36632 Sample.c(11:6:5:1) _whilecontinue_0($1) :
36635 \begin_layout Standard
36638 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
36642 \begin_layout Standard
36645 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36648 \begin_layout Standard
36651 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
36655 \begin_layout Standard
36658 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
36662 \begin_layout Standard
36665 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
36669 \begin_layout Standard
36672 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
36676 \begin_layout Standard
36679 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
36680 * int}[r0] + 0x2 {short}
36683 \begin_layout Standard
36686 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
36689 \begin_layout Standard
36692 Sample.c(11:17:21:0)_whilebreak_0($3) :
36695 \begin_layout Standard
36698 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
36701 \begin_layout Standard
36704 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
36707 \begin_layout Standard
36710 Sample.c(15:20:54:0)preHeaderLbl1($13) :
36713 \begin_layout Standard
36716 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
36719 \begin_layout Standard
36722 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
36725 \begin_layout Standard
36728 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
36731 \begin_layout Standard
36734 Sample.c(15:24:26:1)_forcond_0($4) :
36737 \begin_layout Standard
36740 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
36744 \begin_layout Standard
36747 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
36750 \begin_layout Standard
36753 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
36754 + ITemp21 [lr21:38]{short}[r4]
36757 \begin_layout Standard
36760 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
36764 \begin_layout Standard
36767 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
36768 + iTemp15 [lr29:30]{short}[r1]
36771 \begin_layout Standard
36774 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
36778 \begin_layout Standard
36781 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
36785 \begin_layout Standard
36788 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
36792 \begin_layout Standard
36795 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
36799 \begin_layout Standard
36802 Sample.c(19:38:47:1) goto _forcond_0($4)
36805 \begin_layout Standard
36808 Sample.c(19:39:48:0)_forbreak_0($7) :
36811 \begin_layout Standard
36814 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
36815 + ITemp11 [lr19:40]{short}[r3]
36818 \begin_layout Standard
36821 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
36824 \begin_layout Standard
36827 Sample.c(20:42:51:0)_return($8) :
36830 \begin_layout Standard
36833 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
36839 Finally the code generated for this function:
36844 \begin_layout Standard
36850 \begin_layout Standard
36856 \begin_layout Standard
36864 \begin_layout Standard
36870 \begin_layout Standard
36878 \begin_layout Standard
36884 \begin_layout Standard
36887 ; ----------------------------------------------
36890 \begin_layout Standard
36893 ; function function
36896 \begin_layout Standard
36899 ; ----------------------------------------------
36902 \begin_layout Standard
36908 \begin_layout Standard
36911 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
36914 \begin_layout Standard
36922 \begin_layout Standard
36925 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
36928 \begin_layout Standard
36936 \begin_layout Standard
36939 ;_whilecontinue_0($1) :
36942 \begin_layout Standard
36948 \begin_layout Standard
36951 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
36954 \begin_layout Standard
36957 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36960 \begin_layout Standard
36968 \begin_layout Standard
36976 \begin_layout Standard
36984 \begin_layout Standard
36992 \begin_layout Standard
37000 \begin_layout Standard
37008 \begin_layout Standard
37016 \begin_layout Standard
37022 \begin_layout Standard
37025 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37028 \begin_layout Standard
37036 \begin_layout Standard
37044 \begin_layout Standard
37047 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37050 \begin_layout Standard
37058 \begin_layout Standard
37066 \begin_layout Standard
37074 \begin_layout Standard
37082 \begin_layout Standard
37090 \begin_layout Standard
37098 \begin_layout Standard
37101 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
37104 \begin_layout Standard
37112 \begin_layout Standard
37120 \begin_layout Standard
37128 \begin_layout Standard
37136 \begin_layout Standard
37144 \begin_layout Standard
37147 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
37150 \begin_layout Standard
37158 \begin_layout Standard
37166 \begin_layout Standard
37174 \begin_layout Standard
37177 ; iTemp6 [lr5:16]{_near * int}[r0] =
37180 \begin_layout Standard
37183 ; iTemp6 [lr5:16]{_near * int}[r0] +
37186 \begin_layout Standard
37192 \begin_layout Standard
37200 \begin_layout Standard
37203 ; goto _whilecontinue_0($1)
37206 \begin_layout Standard
37214 \begin_layout Standard
37217 ; _whilebreak_0($3) :
37220 \begin_layout Standard
37226 \begin_layout Standard
37229 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37232 \begin_layout Standard
37240 \begin_layout Standard
37243 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37246 \begin_layout Standard
37254 \begin_layout Standard
37257 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37260 \begin_layout Standard
37268 \begin_layout Standard
37271 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37274 \begin_layout Standard
37282 \begin_layout Standard
37290 \begin_layout Standard
37293 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37296 \begin_layout Standard
37304 \begin_layout Standard
37312 \begin_layout Standard
37318 \begin_layout Standard
37324 \begin_layout Standard
37327 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
37330 \begin_layout Standard
37333 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37336 \begin_layout Standard
37344 \begin_layout Standard
37352 \begin_layout Standard
37360 \begin_layout Standard
37368 \begin_layout Standard
37376 \begin_layout Standard
37382 \begin_layout Standard
37385 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
37388 \begin_layout Standard
37391 ; iTemp21 [lr21:38]{short}[r4]
37394 \begin_layout Standard
37402 \begin_layout Standard
37410 \begin_layout Standard
37418 \begin_layout Standard
37421 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
37424 \begin_layout Standard
37432 \begin_layout Standard
37440 \begin_layout Standard
37448 \begin_layout Standard
37456 \begin_layout Standard
37459 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
37462 \begin_layout Standard
37465 ; iTemp15 [lr29:30]{short}[r1]
37468 \begin_layout Standard
37476 \begin_layout Standard
37484 \begin_layout Standard
37487 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
37490 \begin_layout Standard
37498 \begin_layout Standard
37506 \begin_layout Standard
37514 \begin_layout Standard
37522 \begin_layout Standard
37530 \begin_layout Standard
37538 \begin_layout Standard
37541 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
37544 \begin_layout Standard
37552 \begin_layout Standard
37560 \begin_layout Standard
37568 \begin_layout Standard
37576 \begin_layout Standard
37584 \begin_layout Standard
37592 \begin_layout Standard
37595 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
37598 \begin_layout Standard
37606 \begin_layout Standard
37609 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
37612 \begin_layout Standard
37620 \begin_layout Standard
37625 cjne r5,#0xff,00104$
37628 \begin_layout Standard
37636 \begin_layout Standard
37639 ; goto _forcond_0($4)
37642 \begin_layout Standard
37650 \begin_layout Standard
37653 ; _forbreak_0($7) :
37656 \begin_layout Standard
37662 \begin_layout Standard
37665 ; ret iTemp24 [lr40:41]{short}
37668 \begin_layout Standard
37676 \begin_layout Standard
37684 \begin_layout Standard
37692 \begin_layout Standard
37698 \begin_layout Standard
37704 \begin_layout Standard
37714 \begin_layout Section
37715 A few words about basic block successors, predecessors and dominators
37718 \begin_layout Standard
37719 Successors are basic blocks
37720 \begin_inset LatexCommand \index{Basic blocks}
37724 that might execute after this basic block.
37726 Predecessors are basic blocks
37727 that might execute before reaching this basic block.
37729 Dominators are basic
37730 blocks that WILL execute before reaching this basic block.
37735 \begin_layout Standard
37739 \begin_layout Standard
37743 \begin_layout Standard
37751 \begin_layout Standard
37755 \begin_layout Standard
37763 \begin_layout Standard
37769 \begin_layout Standard
37770 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
37773 \begin_layout Standard
37774 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
37777 \begin_layout Standard
37778 c) domVect of [BB4] = BB1 ...
37779 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
37783 \begin_layout Chapter
37787 \begin_layout Standard
37788 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
37798 Thanks to all the other volunteer developers who have helped with coding,
37799 testing, web-page creation, distribution sets, etc.
37800 You know who you are :-)
37808 Also thanks to Sourceforge
37809 \begin_inset LatexCommand \url{http://www.sf.net}
37813 which has hosted the project since 1999 and donates significant download
37814 bandwidth and probably more than
37818 \begin_layout Standard
37825 CPU cycles per day.
37828 \begin_inset Note Note
37831 \begin_layout Standard
37832 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
37833 minutes for (configure+make+regression test), and there is (i386, amd64,
37834 alpha, ppc64, (mingw32), sparc, macosx).
37843 \begin_layout Standard
37844 This document was initially written by Sandeep Dutta
37847 \begin_layout Standard
37848 All product names mentioned herein may be trademarks
37849 \begin_inset LatexCommand \index{Trademarks}
37853 of their respective companies.
37857 \begin_layout Section*
37861 \begin_layout Standard
37862 To avoid confusion, the installation and building options for SDCC itself
37863 (chapter 2) are not part of the index.
37866 \begin_layout Standard
37867 \begin_inset LatexCommand \printindex{}