1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes 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 Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is 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://sdcc.svn.sourceforge.net/svnroot/
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 SDCC Distributed Compile
1568 \begin_layout Standard
1569 See the examples, how to pass the Win32 settings to 'configure'.
1570 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1571 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1581 \begin_layout Standard
1583 \begin_inset Tabular
1584 <lyxtabular version="3" rows="9" columns="3">
1586 <column alignment="block" valignment="top" leftline="true" width="0in">
1587 <column alignment="block" valignment="top" leftline="true" width="0in">
1588 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1589 <row topline="true" bottomline="true">
1590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1593 \begin_layout Standard
1599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1602 \begin_layout Standard
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1611 \begin_layout Standard
1618 <row topline="true">
1619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1622 \begin_layout Standard
1630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_layout Standard
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1642 \begin_layout Standard
1651 <row topline="true">
1652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1655 \begin_layout Standard
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1666 \begin_layout Standard
1674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1677 \begin_layout Standard
1686 <row topline="true">
1687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1690 \begin_layout Standard
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1701 \begin_layout Standard
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1714 \begin_layout Standard
1727 <row topline="true">
1728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1731 \begin_layout Standard
1739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1742 \begin_layout Standard
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1753 \begin_layout Standard
1762 <row topline="true">
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 \begin_layout Standard
1774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_layout Standard
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1790 \begin_layout Standard
1799 <row topline="true">
1800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1803 \begin_layout Standard
1811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_layout Standard
1824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1827 \begin_layout Standard
1840 <row topline="true">
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1844 \begin_layout Standard
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1855 \begin_layout Standard
1861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1864 \begin_layout Standard
1871 <row topline="true" bottomline="true">
1872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1875 \begin_layout Standard
1883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1886 \begin_layout Standard
1892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1895 \begin_layout Standard
1911 \begin_layout Standard
1913 'configure' also computes relative paths.
1914 This is needed for full relocatability of a binary package and to complete
1915 search paths (see section search paths below):
1920 \begin_layout Standard
1922 \begin_inset Tabular
1923 <lyxtabular version="3" rows="4" columns="3">
1925 <column alignment="block" valignment="top" leftline="true" width="0in">
1926 <column alignment="block" valignment="top" leftline="true" width="0in">
1927 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1928 <row topline="true" bottomline="true">
1929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1932 \begin_layout Standard
1938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1941 \begin_layout Standard
1947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1950 \begin_layout Standard
1957 <row topline="true" bottomline="true">
1958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1961 \begin_layout Standard
1969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1972 \begin_layout Standard
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1981 \begin_layout Standard
1988 <row bottomline="true">
1989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1992 \begin_layout Standard
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2003 \begin_layout Standard
2009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2012 \begin_layout Standard
2019 <row bottomline="true">
2020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2023 \begin_layout Standard
2031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2034 \begin_layout Standard
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2043 \begin_layout Standard
2059 \begin_layout Standard
2064 \begin_layout LyX-Code
2071 \begin_layout Standard
2081 \begin_inset Quotes srd
2085 \begin_inset Quotes srd
2092 \begin_layout Standard
2102 \begin_inset Quotes srd
2106 \begin_inset Quotes srd
2115 \begin_layout Standard
2128 \begin_layout Standard
2140 \begin_layout Standard
2141 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2145 \begin_layout LyX-Code
2151 \begin_inset Quotes srd
2154 i586-mingw32msvc-gcc
2155 \begin_inset Quotes srd
2159 \begin_inset Quotes srd
2162 i586-mingw32msvc-g++
2163 \begin_inset Quotes srd
2171 \begin_inset Quotes srd
2174 i586-mingw32msvc-ranlib
2175 \begin_inset Quotes srd
2183 \begin_inset Quotes srd
2186 i586-mingw32msvc-strip
2187 \begin_inset Quotes srd
2198 \begin_layout Standard
2208 \begin_inset Quotes srd
2212 \begin_inset Quotes srd
2223 \begin_layout Standard
2233 \begin_inset Quotes srd
2237 \begin_inset Quotes srd
2245 \begin_inset Quotes srd
2251 \begin_inset Quotes srd
2259 \begin_inset Quotes srd
2263 \begin_inset Quotes srd
2271 \begin_inset Quotes srd
2275 \begin_inset Quotes srd
2282 sdccconf_h_dir_separator=
2283 \begin_inset Quotes srd
2295 \begin_inset Quotes srd
2306 \begin_layout Standard
2323 \begin_layout Standard
2332 -host=i586-mingw32msvc
2340 \begin_layout Standard
2349 -build=unknown-unknown-linux-gnu
2352 \begin_layout Standard
2354 \begin_inset Quotes sld
2358 \begin_inset Quotes srd
2361 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2365 \begin_layout LyX-Code
2374 \begin_layout Standard
2384 \begin_inset Quotes srd
2388 \begin_inset Quotes srd
2399 \begin_layout Standard
2409 \begin_inset Quotes srd
2413 \begin_inset Quotes srd
2421 \begin_inset Quotes srd
2427 \begin_inset Quotes srd
2435 \begin_inset Quotes srd
2439 \begin_inset Quotes srd
2447 \begin_inset Quotes srd
2451 \begin_inset Quotes srd
2458 sdccconf_h_dir_separator=
2459 \begin_inset Quotes srd
2471 \begin_inset Quotes srd
2479 \begin_inset Quotes srd
2483 \begin_inset Quotes srd
2491 \begin_inset Quotes srd
2495 \begin_inset Quotes srd
2501 \begin_layout Standard
2502 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2507 \begin_layout Standard
2516 -C' turns on caching, which gives a little bit extra speed.
2517 However if options are changed, it can be necessary to delete the config.cache
2521 \begin_layout Section
2523 \begin_inset LatexCommand \label{sub:Install-paths}
2528 \begin_inset LatexCommand \index{Install paths}
2535 \begin_layout Standard
2536 \begin_inset VSpace medskip
2542 \begin_layout Standard
2544 \begin_inset Tabular
2545 <lyxtabular version="3" rows="5" columns="4">
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" width="0">
2550 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2551 <row topline="true" bottomline="true">
2552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2555 \begin_layout Standard
2563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2566 \begin_layout Standard
2574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2577 \begin_layout Standard
2585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2588 \begin_layout Standard
2597 <row topline="true">
2598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2601 \begin_layout Standard
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2610 \begin_layout Standard
2618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2621 \begin_layout Standard
2627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2630 \begin_layout Standard
2641 <row topline="true">
2642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2645 \begin_layout Standard
2651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2654 \begin_layout Standard
2657 $DATADIR/ $INCLUDE_DIR_SUFFIX
2662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2665 \begin_layout Standard
2666 /usr/local/share/sdcc/include
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2674 \begin_layout Standard
2685 <row topline="true">
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2689 \begin_layout Standard
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2698 \begin_layout Standard
2701 $DATADIR/$LIB_DIR_SUFFIX
2706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2709 \begin_layout Standard
2710 /usr/local/share/sdcc/lib
2715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2718 \begin_layout Standard
2729 <row topline="true" bottomline="true">
2730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2733 \begin_layout Standard
2739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2742 \begin_layout Standard
2750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2753 \begin_layout Standard
2754 /usr/local/share/sdcc/doc
2759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2762 \begin_layout Standard
2783 *compiler, preprocessor, assembler, and linker
2789 is auto-appended by the compiler, e.g.
2790 small, large, z80, ds390 etc
2793 \begin_layout Standard
2795 The install paths can still be changed during `make install` with e.g.:
2798 \begin_layout LyX-Code
2799 make install prefix=$(HOME)/local/sdcc
2802 \begin_layout Standard
2803 Of course this doesn't change the search paths compiled into the binaries.
2808 r the install path can be changed by defining DESTDIR
2809 \begin_inset LatexCommand \index{DESTDIR}
2816 \begin_layout LyX-Code
2817 make install DESTDIR=$(HOME)/sdcc.rpm/
2820 \begin_layout Standard
2821 Please note that DESTDIR must have a trailing slash!
2824 \begin_layout Section
2826 \begin_inset LatexCommand \label{sub:Search-Paths}
2831 \begin_inset LatexCommand \index{Search path}
2838 \begin_layout Standard
2839 Some search paths or parts of them are determined by configure variables
2844 , see section above).
2845 Further search paths are determined by environment variables during runtime.
2848 The paths searched when running the compiler are as follows (the first
2854 Binary files (preprocessor, assembler and linker)
2859 \begin_layout Standard
2861 \begin_inset Tabular
2862 <lyxtabular version="3" rows="4" columns="3">
2864 <column alignment="block" valignment="top" leftline="true" width="0in">
2865 <column alignment="block" valignment="top" leftline="true" width="0in">
2866 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2867 <row topline="true" bottomline="true">
2868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2871 \begin_layout Standard
2877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2880 \begin_layout Standard
2886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2889 \begin_layout Standard
2896 <row topline="true">
2897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2900 \begin_layout Standard
2908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2911 \begin_layout Standard
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2920 \begin_layout Standard
2929 <row topline="true">
2930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2933 \begin_layout Standard
2934 Path of argv[0] (if available)
2939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2942 \begin_layout Standard
2948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2951 \begin_layout Standard
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_layout Standard
2968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2971 \begin_layout Standard
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2980 \begin_layout Standard
2996 \begin_layout Standard
3004 \begin_layout Standard
3006 \begin_inset Tabular
3007 <lyxtabular version="3" rows="6" columns="3">
3009 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3010 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3011 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3012 <row topline="true" bottomline="true">
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3016 \begin_layout Standard
3022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3025 \begin_layout Standard
3031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3034 \begin_layout Standard
3041 <row topline="true">
3042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3045 \begin_layout Standard
3050 \begin_layout Standard
3064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3067 \begin_layout Standard
3072 \begin_layout Standard
3086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3089 \begin_layout Standard
3094 \begin_layout Standard
3109 <row topline="true">
3110 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3113 \begin_layout Standard
3119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3122 \begin_layout Standard
3128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3131 \begin_layout Standard
3138 <row topline="true">
3139 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3142 \begin_layout Standard
3154 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3157 \begin_layout Standard
3167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3170 \begin_layout Standard
3179 <row topline="true">
3180 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3183 \begin_layout Standard
3199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3202 \begin_layout Standard
3250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3253 \begin_layout Standard
3264 <row topline="true" bottomline="true">
3265 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3268 \begin_layout Standard
3282 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3285 \begin_layout Standard
3286 /usr/local/share/sdcc/
3293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3296 \begin_layout Standard
3312 \begin_layout Standard
3318 \begin_layout Standard
3327 -nostdinc disables the last two search paths.
3337 \begin_layout Standard
3338 With the exception of
3339 \begin_inset Quotes sld
3346 \begin_layout Standard
3356 \begin_inset Quotes srd
3363 is auto-appended by the compiler (e.g.
3364 small, large, z80, ds390 etc.).
3370 \begin_layout Standard
3372 \begin_inset Tabular
3373 <lyxtabular version="3" rows="6" columns="3">
3375 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3376 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3377 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3378 <row topline="true" bottomline="true">
3379 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3382 \begin_layout Standard
3388 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3391 \begin_layout Standard
3397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3400 \begin_layout Standard
3407 <row topline="true">
3408 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3411 \begin_layout Standard
3416 \begin_layout Standard
3430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3433 \begin_layout Standard
3438 \begin_layout Standard
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3455 \begin_layout Standard
3460 \begin_layout Standard
3475 <row topline="true">
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3479 \begin_layout Standard
3489 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3492 \begin_layout Standard
3502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3505 \begin_layout Standard
3518 <row topline="true">
3519 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3522 \begin_layout Standard
3529 $LIB_DIR_SUFFIX/<model>
3534 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3537 \begin_layout Standard
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3552 \begin_layout Standard
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_layout Standard
3582 $LIB_DIR_SUFFIX/<model>
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3590 \begin_layout Standard
3641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3644 \begin_layout Standard
3698 <row topline="true" bottomline="true">
3699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3702 \begin_layout Standard
3707 $LIB_DIR_SUFFIX/<model>
3712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3715 \begin_layout Standard
3716 /usr/local/share/sdcc/
3725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3728 \begin_layout Standard
3744 \begin_layout Standard
3745 \begin_inset Note Note
3748 \begin_layout Standard
3749 Don't delete any of the stray spaces in the table above without checking
3750 the HTML output (last line)!
3758 \begin_layout Standard
3766 \begin_layout Standard
3775 -nostdlib disables the last two search paths.
3778 \begin_layout Section
3780 \begin_inset LatexCommand \index{Building SDCC}
3787 \begin_layout Subsection
3788 Building SDCC on Linux
3789 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3796 \begin_layout Enumerate
3799 Download the source package
3801 either from the SDCC Subversion repository or from snapshot builds
3803 , it will be named something like sdcc
3814 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3821 \begin_layout Enumerate
3824 Bring up a command line terminal, such as xterm.
3827 \begin_layout Enumerate
3830 Unpack the file using a command like:
3833 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3834 \begin_inset Quotes srd
3840 , this will create a sub-directory called sdcc with all of the sources.
3843 \begin_layout Enumerate
3844 Change directory into the main SDCC directory, for example type:
3852 \begin_layout Enumerate
3862 This configures the package for compilation on your system.
3865 \begin_layout Enumerate
3879 All of the source packages will compile, this can take a while.
3882 \begin_layout Enumerate
3896 This copies the binary executables, the include files, the libraries and
3897 the documentation to the install directories.
3898 Proceed with section
3899 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3906 \begin_layout Subsection
3907 Building SDCC on OSX 2.x
3910 \begin_layout Standard
3911 Follow the instruction for Linux.
3915 On OSX 2.x it was reported, that the default
3916 gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3917 Fortunately there's also gcc 2.9.x installed, which works fine.
3918 This compiler can be selected by running 'configure' with:
3921 \begin_layout LyX-Code
3922 ./configure CC=gcc2 CXX=g++2
3925 \begin_layout Subsection
3926 Cross compiling SDCC on Linux for Windows
3929 \begin_layout Standard
3930 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3931 See section 'Configure Options'.
3934 \begin_layout Subsection
3935 Building SDCC using Cygwin and Mingw32
3938 \begin_layout Standard
3939 For building and installing a Cygwin executable follow the instructions
3945 \begin_inset Quotes sld
3949 \begin_inset Quotes srd
3952 Win32-binary can be built, which will not need the Cygwin-DLL.
3953 For the necessary 'configure' options see section 'configure options' or
3954 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3959 Cygwin on Windows download setup.exe from
3960 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3966 \begin_inset Quotes sld
3969 default text file type
3970 \begin_inset Quotes srd
3974 \begin_inset Quotes sld
3978 \begin_inset Quotes srd
3981 and download/install at least the following packages.
3982 Some packages are selected by default, others will be automatically selected
3983 because of dependencies with the manually selected packages.
3984 Never deselect these packages!
3987 \begin_layout Itemize
3991 \begin_layout Itemize
3995 \begin_layout Itemize
3996 gcc ; version 3.x is fine, no need to use the old 2.9x
3999 \begin_layout Itemize
4000 binutils ; selected with gcc
4003 \begin_layout Itemize
4007 \begin_layout Itemize
4008 rxvt ; a nice console, which makes life much easier under windoze (see below)
4011 \begin_layout Itemize
4012 man ; not really needed for building SDCC, but you'll miss it sooner or
4016 \begin_layout Itemize
4017 less ; not really needed for building SDCC, but you'll miss it sooner or
4021 \begin_layout Itemize
4022 svn ; only if you use Subversion access
4025 \begin_layout Standard
4026 If you want to develop something you'll need:
4029 \begin_layout Itemize
4030 python ; for the regression tests
4033 \begin_layout Itemize
4034 gdb ; the gnu debugger, together with the nice GUI
4035 \begin_inset Quotes sld
4039 \begin_inset Quotes srd
4045 \begin_layout Itemize
4046 openssh ; to access the CF or commit changes
4049 \begin_layout Itemize
4050 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4051 use autoconf-stable!
4054 \begin_layout Standard
4055 rxvt is a nice console with history.
4056 Replace in your cygwin.bat the line
4059 \begin_layout LyX-Code
4064 \begin_layout Standard
4076 \begin_layout Standard
4080 \begin_layout LyX-Code
4081 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4084 \begin_layout LyX-Code
4085 -bg black -fg white -geometry 100x65 -e bash -
4089 \begin_layout Standard
4101 \begin_layout Standard
4102 Text selected with the mouse is automatically copied to the clipboard, pasting
4103 works with shift-insert.
4107 The other good tip is to make sure you have no //c/-styl
4108 e paths anywhere, use /cygdrive/c/ instead.
4109 Using // invokes a network lookup which is very slow.
4111 \begin_inset Quotes sld
4115 \begin_inset Quotes srd
4118 is too long, you can change it with e.g.
4121 \begin_layout LyX-Code
4125 \begin_layout Standard
4126 SDCC sources use the unix line ending LF.
4127 Life is much easier, if you store the source tree on a drive which is mounted
4129 And use an editor which can handle LF-only line endings.
4130 Make sure not to commit files with windows line endings.
4131 The tabulator spacing
4132 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4136 used in the project is 8.
4137 Although a tabulator spacing of 8 is a sensible choice for programmers
4138 (it's a power of 2 and allows to display 8/16 bit signed variables without
4139 loosing columns) the plan is to move towards using only spaces in the source.
4142 \begin_layout Subsection
4143 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4146 \begin_layout Standard
4149 Download the source package
4151 either from the SDCC Subversion repository or from the
4152 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4158 , it will be named something like sdcc
4162 -yyyymmdd-rrrr.tar.bz2.
4165 SDCC is distributed with all the projects, workspaces, and files you need
4166 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4167 The workspace name is 'sdcc.dsw'.
4168 Please note that as it is now, all the executables are created in a folder
4172 Once built you need to copy the executables from sdcc
4176 bin before running SDCC.
4181 WARNING: Visual studio is very picky with line terminations; it expects
4182 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4183 When using the Subversion repository it's easiest to configure the svn
4184 client to convert automatically for you.
4185 If however you are getting a message such as "This makefile was not generated
4186 by Developer Studio etc.
4188 \begin_inset Quotes srd
4191 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4192 need to convert the Unix style line endings to DOS style line endings.
4193 To do so you can use the
4194 \begin_inset Quotes sld
4198 \begin_inset Quotes srd
4201 utility freely available on the internet.
4202 Doug Hawkins reported in the sdcc-user list that this works:
4210 SDCC> unix2dos sdcc.dsw
4216 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4220 In order to build SDCC with MSVC
4221 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4222 One good place to get them is
4223 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4231 Download the file UnxUtils
4232 \begin_inset LatexCommand \index{UnxUtils}
4237 Now you have to install the utilities and setup MSVC so it can locate the
4239 Here there are two alternatives (choose one!):
4242 \begin_layout Enumerate
4247 a) Extract UnxUtils.zip to your C:
4249 hard disk PRESERVING the original paths, otherwise bison won't work.
4250 (If you are using WinZip make certain that 'Use folder names' is selected)
4255 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4256 'Show directories for:' select 'Executable files', and in the directories
4257 window add a new path: 'C:
4267 (As a side effect, you get a bunch of Unix utilities that
4268 could be useful, such as diff and patch.)
4271 \begin_layout Enumerate
4276 This one avoids extracting a bunch of files you may not
4277 use, but requires some extra work:
4281 a) Create a directory were to put the
4282 tools needed, or use a directory already present.
4289 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4290 gawk.exe to such directory WITHOUT preserving the original paths.
4291 (If you are using WinZip make certain that 'Use folder names' is not selected)
4296 ) Rename bison.exe to '_bison.exe'.
4300 d) Create a batch file 'bison.bat' in 'C:
4304 ' and add these lines:
4324 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4328 Steps 'c' and 'd' are needed
4329 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4330 reside in some weird Unix directory, '/usr/local/share/' I think.
4331 So it is necessary to tell bison where those files are located if they
4332 are not in such directory.
4333 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4338 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4339 in 'Show directories for:' select 'Executable files', and in the directories
4340 window add a new path: 'c:
4343 Note that you can use any other path instead of 'c:
4345 util', even the path where the Visual C++ tools are, probably: 'C:
4349 Microsoft Visual Studio
4354 So you don't have to execute step 'e' :)
4357 \begin_layout Standard
4359 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4360 the executables from sdcc
4364 bin, and you can compile using SDCC.
4367 \begin_layout Subsection
4368 Building SDCC Using Borland
4371 \begin_layout Enumerate
4372 From the sdcc directory, run the command "make -f Makefile.bcc".
4373 This should regenerate all the .exe files in the bin directory except for
4377 \begin_layout Enumerate
4378 If you modify any source files and need to rebuild, be aware that the dependenci
4379 es may not be correctly calculated.
4380 The safest option is to delete all .obj files and run the build again.
4381 From a Cygwin BASH prompt, this can easily be done with the command (be
4382 sure you are in the sdcc directory):
4392 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4394 ) -print -exec rm {}
4403 or on Windows NT/2000/XP from the command prompt with the command:
4410 del /s *.obj *.lib *.rul
4413 from the sdcc directory.
4416 \begin_layout Subsection
4417 Windows Install Using a ZIP Package
4420 \begin_layout Enumerate
4421 Download the binary zip package from
4422 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4426 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4427 This should unpack to a group of sub-directories.
4428 An example directory structure after unpacking the mingw32 package is:
4433 bin for the executables, c:
4441 lib for the include and libraries.
4444 \begin_layout Enumerate
4445 Adjust your environment variable PATH to include the location of the bin
4446 directory or start sdcc using the full path.
4449 \begin_layout Subsection
4450 Windows Install Using the Setup Program
4451 \begin_inset LatexCommand \label{sub:Windows-Install}
4458 \begin_layout Standard
4459 Download the setup program
4461 sdcc-x.y.z-setup.exe
4463 for an official release from
4466 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4470 or a setup program for one of the snapshots
4472 sdcc-yyyymmdd-xxxx-setup.exe
4475 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4480 A windows typical installer will guide you through the installation process.
4483 \begin_layout Subsection
4485 \begin_inset LatexCommand \index{VPATH}
4492 \begin_layout Standard
4493 SDCC supports the VPATH feature provided by configure and make.
4494 It allows to separate the source and build trees.
4498 \begin_layout Standard
4525 \begin_layout Standard
4528 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4529 # extract source to directory sdcc
4532 \begin_layout Standard
4535 mkdir sdcc.build\InsetSpace ~
4544 # put output in sdcc.build
4547 \begin_layout Standard
4553 \begin_layout Standard
4556 ../sdcc/configure\InsetSpace ~
4564 # configure is doing all the magic!
4567 \begin_layout Standard
4573 \begin_layout Standard
4579 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4580 It automagically computes the variables srcdir, top_srcdir and top_buildir
4586 the generated files will be in ~/sdcc.build, while the source files stay
4589 This is not only usefull for building different binaries, e.g.
4590 when cross compiling.
4591 It also gives you a much better overview in the source tree when all the
4592 generated files are not scattered between the source files.
4593 And the best thing is: if you want to change a file you can leave the original
4594 file untouched in the source directory.
4595 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4596 Makefile.dep` and `make`.
4601 will do the rest for you!
4604 \begin_layout Section
4605 Building the Documentation
4608 \begin_layout Standard
4613 \begin_layout Standard
4622 -enable-doc to the configure arguments to build the documentation together
4623 with all the other stuff.
4624 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4625 dvips and makeindex) to get the job done.
4626 Another possibility is to change to the doc directory and to type
4630 \begin_inset Quotes srd
4634 \begin_inset Quotes srd
4641 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4644 \begin_inset LatexCommand \url{http://www.lyx.org}
4648 as editor is straightforward.
4649 Prebuilt documentation in html and pdf format is available from
4650 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4657 \begin_layout Section
4658 Reading the Documentation
4659 \begin_inset LatexCommand \index{Documentation}
4666 \begin_layout Standard
4667 Currently reading the document in pdf format is recommended, as for unknown
4668 reason the hyperlinks are working there whereas in the html version they
4673 \begin_layout Standard
4674 If you should know why please drop us a note
4682 You'll find the pdf version
4683 \begin_inset LatexCommand \index{PDF version of this document}
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4696 \begin_inset LatexCommand \index{HTML version of this document}
4701 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4707 This documentation is in some aspects different from a commercial documentation:
4711 \begin_layout Itemize
4712 It tries to document SDCC for several processor architectures in one document
4713 (commercially these probably would be separate documents/products).
4715 \begin_inset LatexCommand \index{Status of documentation}
4719 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4721 Z80, PIC14, PIC16 and HC08.
4724 \begin_layout Itemize
4725 There are many references pointing away from this documentation.
4726 Don't let this distract you.
4728 was a reference like
4729 \begin_inset LatexCommand \url{http://www.opencores.org}
4733 together with a statement
4734 \begin_inset Quotes sld
4737 some processors which are targetted by SDCC can be implemented in a
4754 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4759 \begin_inset Quotes srd
4763 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4768 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4773 \begin_inset Quotes sld
4776 have you ever heard of an open source compiler that compiles a subset of
4778 \begin_inset Quotes srd
4781 we expect you to have a quick look there and come back.
4782 If you read this you are on the right track.
4785 \begin_layout Itemize
4786 Some sections attribute more space to problems, restrictions and warnings
4787 than to the solution.
4790 \begin_layout Itemize
4791 The installation section and the section about the debugger is intimidating.
4794 \begin_layout Itemize
4795 There are still lots of typos and there are more different writing styles
4799 \begin_layout Section
4800 Testing the SDCC Compiler
4801 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4808 \begin_layout Standard
4809 The first thing you should do after installing your SDCC compiler is to
4818 \begin_layout Standard
4828 \begin_inset LatexCommand \index{version}
4835 at the prompt, and the program should run and output its version like:
4840 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4844 \begin_layout Standard
4845 If it doesn't run, or gives a message about not finding sdcc program, then
4846 you need to check over your installation.
4847 Make sure that the sdcc bin directory is in your executable search path
4848 defined by the PATH environment setting (
4853 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4860 Install trouble-shooting for suggestions
4863 Make sure that the sdcc program is in the bin folder, if not perhaps something
4864 did not install correctly.
4872 is commonly installed as described in section
4873 \begin_inset Quotes sld
4876 Install and search paths
4877 \begin_inset Quotes srd
4886 Make sure the compiler works on a very simple example.
4887 Type in the following test.c program using your favorite
4912 \begin_layout Standard
4915 Compile this using the following command:
4924 If all goes well, the compiler will generate a test.asm and test.rel file.
4925 Congratulations, you've just compiled your first program with SDCC.
4926 We used the -c option to tell SDCC not to link the generated code, just
4927 to keep things simple for this step.
4935 The next step is to try it with the linker.
4945 If all goes well the compiler will link with the libraries and produce
4946 a test.ihx output file.
4951 (no test.ihx, and the linker generates warnings), then the problem is most
4960 usr/local/share/sdcc/lib directory
4967 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4974 Install trouble-shooting for suggestions).
4982 The final test is to ensure
4990 header files and libraries.
4991 Edit test.c and change it to the following:
5009 strcpy(str1, "testing");
5014 \begin_layout Standard
5017 Compile this by typing
5024 This should generate a test.ihx output file, and it should give no warnings
5025 such as not finding the string.h file.
5026 If it cannot find the string.h file, then the problem is that
5030 cannot find the /usr/local/share/sdcc/include directory
5037 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5044 Install trouble-shooting section for suggestions).
5053 \begin_layout Standard
5065 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5069 to find exactly where SDCC is looking for the include and lib files.
5072 \begin_layout Section
5073 Install Trouble-shooting
5074 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5079 \begin_inset LatexCommand \index{Install trouble-shooting}
5086 \begin_layout Subsection
5087 If SDCC does not build correctly
5090 \begin_layout Standard
5091 A thing to try is starting from scratch by unpacking the .tgz source package
5092 again in an empty directory.
5100 ./configure 2>&1 | tee configure.log
5114 make 2>&1 | tee make.log
5121 If anything goes wrong, you can review the log files to locate the problem.
5122 Or a relevant part of this can be attached to an email that could be helpful
5123 when requesting help from the mailing list.
5126 \begin_layout Subsection
5128 \begin_inset Quotes sld
5132 \begin_inset Quotes srd
5138 \begin_layout Standard
5140 \begin_inset Quotes sld
5144 \begin_inset Quotes srd
5147 command is a script that analyzes your system and performs some configuration
5148 to ensure the source package compiles on your system.
5149 It will take a few minutes to run, and will compile a few tests to determine
5150 what compiler features are installed.
5153 \begin_layout Subsection
5155 \begin_inset Quotes sld
5159 \begin_inset Quotes srd
5165 \begin_layout Standard
5166 This runs the GNU make tool, which automatically compiles all the source
5167 packages into the final installed binary executables.
5170 \begin_layout Subsection
5172 \begin_inset Quotes sld
5176 \begin_inset Quotes erd
5182 \begin_layout Standard
5183 This will install the compiler, other executables libraries and include
5184 files into the appropriate directories.
5186 \begin_inset LatexCommand \ref{sub:Install-paths}
5192 \begin_inset LatexCommand \ref{sub:Search-Paths}
5197 about install and search paths.
5199 On most systems you will need super-user privilege
5203 \begin_layout Section
5207 \begin_layout Standard
5208 SDCC is not just a compiler, but a collection of tools by various developers.
5209 These include linkers, assemblers, simulators and other components.
5210 Here is a summary of some of the components.
5211 Note that the included simulator and assembler have separate documentation
5212 which you can find in the source package in their respective directories.
5213 As SDCC grows to include support for other processors, other packages from
5214 various developers are included and may have their own sets of documentation.
5219 might want to look at the files which are installed in <installdir>.
5220 At the time of this writing, we find the following programs for gcc-builds:
5225 In <installdir>/bin:
5228 \begin_layout Itemize
5229 sdcc - The compiler.
5232 \begin_layout Itemize
5233 sdcpp - The C preprocessor.
5236 \begin_layout Itemize
5237 asx8051 - The assembler for 8051 type processors.
5240 \begin_layout Itemize
5245 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5248 \begin_layout Itemize
5249 aslink -The linker for 8051 type processors.
5252 \begin_layout Itemize
5257 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5260 \begin_layout Itemize
5261 s51 - The ucSim 8051 simulator.
5264 \begin_layout Itemize
5265 sdcdb - The source debugger.
5268 \begin_layout Itemize
5269 packihx - A tool to pack (compress) Intel hex files.
5272 \begin_layout Standard
5273 In <installdir>/share/sdcc/include
5276 \begin_layout Itemize
5280 \begin_layout Standard
5281 In <installdir>/share/sdcc/lib
5284 \begin_layout Itemize
5285 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5289 \begin_layout Standard
5290 In <installdir>/share/sdcc/doc
5293 \begin_layout Itemize
5297 \begin_layout Standard
5298 As development for other processors proceeds, this list will expand to include
5299 executables to support processors like AVR, PIC, etc.
5302 \begin_layout Subsection
5306 \begin_layout Standard
5307 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5308 the assembler and linkage editor.
5311 \begin_layout Subsection
5312 sdcpp - The C-Preprocessor
5315 \begin_layout Standard
5317 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5321 is a modified version of the GNU cpp
5322 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5327 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5332 The C preprocessor is used to pull in #include sources, process #ifdef
5333 statements, #defines and so on.
5336 \begin_layout Subsection
5345 - The Assemblers and Linkage Editors
5348 \begin_layout Standard
5349 This is retargettable assembler & linkage editor, it was developed by Alan
5351 John Hartman created the version for 8051, and I (Sandeep) have made some
5352 enhancements and bug fixes for it to work properly with SDCC.
5355 \begin_layout Subsection
5359 \begin_layout Standard
5361 \begin_inset LatexCommand \index{s51}
5365 is a freeware, opensource simulator developed by Daniel Drotos.
5366 The simulator is built as part of the build process.
5367 For more information visit Daniel's web site at:
5368 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5373 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5377 \begin_layout Subsection
5378 sdcdb - Source Level Debugger
5381 \begin_layout Standard
5383 \begin_inset LatexCommand \index{SDCDB (debugger)}
5387 is the companion source level debugger.
5388 More about SDCDB in section
5389 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5394 The current version of the debugger uses Daniel's Simulator S51
5395 \begin_inset LatexCommand \index{s51}
5399 , but can be easily changed to use other simulators.
5402 \begin_layout Chapter
5406 \begin_layout Section
5410 \begin_layout Subsection
5411 Single Source File Projects
5414 \begin_layout Standard
5415 For single source file 8051 projects the process is very simple.
5416 Compile your programs with the following command
5419 "sdcc sourcefile.c".
5423 This will compile, assemble and link your source file.
5424 Output files are as follows:
5427 \begin_layout Itemize
5429 \begin_inset LatexCommand \index{<file>.asm}
5434 \begin_inset LatexCommand \index{Assembler source}
5438 file created by the compiler
5441 \begin_layout Itemize
5443 \begin_inset LatexCommand \index{<file>.lst}
5448 \begin_inset LatexCommand \index{Assembler listing}
5452 file created by the Assembler
5455 \begin_layout Itemize
5457 \begin_inset LatexCommand \index{<file>.rst}
5462 \begin_inset LatexCommand \index{Assembler listing}
5466 file updated with linkedit information, created by linkage editor
5469 \begin_layout Itemize
5471 \begin_inset LatexCommand \index{<file>.sym}
5476 \begin_inset LatexCommand \index{Symbol listing}
5480 for the sourcefile, created by the assembler
5483 \begin_layout Itemize
5485 \begin_inset LatexCommand \index{<file>.rel}
5490 \begin_inset LatexCommand \index{<file>.o}
5495 \begin_inset LatexCommand \index{Object file}
5499 created by the assembler, input to Linkage editor
5502 \begin_layout Itemize
5504 \begin_inset LatexCommand \index{<file>.map}
5509 \begin_inset LatexCommand \index{Memory map}
5513 for the load module, created by the Linker
5516 \begin_layout Itemize
5518 \begin_inset LatexCommand \index{<file>.mem}
5522 - A file with a summary of the memory usage
5525 \begin_layout Itemize
5527 \begin_inset LatexCommand \index{<file>.ihx}
5531 - The load module in Intel hex format
5532 \begin_inset LatexCommand \index{Intel hex format}
5536 (you can select the Motorola S19 format
5537 \begin_inset LatexCommand \index{Motorola S19 format}
5545 \begin_layout Standard
5555 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5560 If you need another format you might want to use
5567 \begin_inset LatexCommand \index{objdump (tool)}
5578 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5583 Both formats are documented in the documentation of srecord
5584 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5591 \begin_layout Itemize
5593 \begin_inset LatexCommand \index{<file>.adb}
5597 - An intermediate file containing debug information needed to create the
5602 \begin_layout Standard
5612 \begin_inset LatexCommand \index{-\/-debug}
5619 \begin_layout Itemize
5621 \begin_inset LatexCommand \index{<file>.cdb}
5625 - An optional file (with -
5629 \begin_layout Standard
5638 -debug) containing debug information.
5639 The format is documented in cdbfileformat.pdf
5642 \begin_layout Itemize
5645 \begin_inset LatexCommand \index{<file> (no extension)}
5649 An optional AOMF or AOMF51
5650 \begin_inset LatexCommand \index{AOMF, AOMF51}
5655 \begin_inset LatexCommand \label{OMF file}
5659 file containing debug information (generated with option -
5663 \begin_layout Standard
5689 ormat is commonly used by third party tools (debuggers
5690 \begin_inset LatexCommand \index{Debugger}
5694 , simulators, emulators)
5697 \begin_layout Itemize
5699 \begin_inset LatexCommand \index{<file>.dump*}
5703 - Dump file to debug the compiler it self (generated with option -
5707 \begin_layout Standard
5716 -dumpall) (see section
5717 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5723 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5729 \begin_inset Quotes sld
5732 Anatomy of the compiler
5733 \begin_inset Quotes srd
5739 \begin_layout Subsection
5740 Postprocessing the Intel Hex
5741 \begin_inset LatexCommand \index{Intel hex format}
5748 \begin_layout Standard
5749 In most cases this won't be needed but the Intel Hex file
5750 \begin_inset LatexCommand \index{<file>.ihx}
5754 which is generated by SDCC might include lines of varying length and the
5755 addresses within the file are not guaranteed to be strictly ascending.
5756 If your toolchain or a bootloader does not like this you can use the tool
5762 \begin_inset LatexCommand \index{packihx (tool)}
5766 which is part of the SDCC distribution:
5773 packihx sourcefile.ihx >sourcefile.hex
5780 The separately available
5785 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5789 package additionally allows to set undefined locations to a predefined
5790 value, to insert checksums
5791 \begin_inset LatexCommand \index{checksum}
5795 of various flavours (crc, add, xor) and to perform other manipulations
5796 (convert, split, crop, offset, ...).
5804 srec_cat\InsetSpace ~
5806 sourcefile.ihx -intel\InsetSpace ~
5808 -o sourcefile.hex -intel
5815 An example for a more complex command line
5819 \begin_layout Standard
5820 the command backfills
5821 \begin_inset LatexCommand \index{backfill unused memory}
5825 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5827 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5828 will be interpreted as an
5836 (where an emergency routine could sit).
5849 srec_cat\InsetSpace ~
5850 sourcefile.ihx -intel\InsetSpace ~
5852 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5853 -little-endian-checksum-nega
5854 tive 0xfffe 0x02 0x02\InsetSpace ~
5856 -o sourcefile.hex -intel
5865 The srecord package is available at
5866 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5873 \begin_layout Subsection
5874 Projects with Multiple Source Files
5877 \begin_layout Standard
5878 SDCC can compile only ONE file at a time.
5879 Let us for example assume that you have a project containing the following
5884 foo1.c (contains some functions)
5886 foo2.c (contains some more functions)
5889 n.c (contains more functions and the function main)
5897 The first two files will need to be compiled separately with the commands:
5929 Then compile the source file containing the
5934 \begin_inset LatexCommand \index{Linker}
5938 the files together with the following command:
5946 foomain.c\InsetSpace ~
5947 foo1.rel\InsetSpace ~
5952 \begin_inset LatexCommand \index{<file>.rel}
5964 can be separately compiled as well:
5975 sdcc foomain.rel foo1.rel foo2.rel
5982 The file containing the
5997 file specified in the command line, since the linkage editor processes
5998 file in the order they are presented to it.
5999 The linker is invoked from SDCC using a script file with extension .lnk
6000 \begin_inset LatexCommand \index{<file>.lnk}
6005 You can view this file to troubleshoot linking problems such as those arising
6006 from missing libraries.
6009 \begin_layout Subsection
6010 Projects with Additional Libraries
6011 \begin_inset LatexCommand \index{Libraries}
6018 \begin_layout Standard
6019 Some reusable routines may be compiled into a library, see the documentation
6020 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6024 \begin_inset LatexCommand \index{<file>.lib}
6031 Libraries created in this manner can be included in the command line.
6032 Make sure you include the -L <library-path> option to tell the linker where
6033 to look for these files if they are not in the current directory.
6034 Here is an example, assuming you have the source file
6046 (if that is not the same as your current project):
6053 sdcc foomain.c foolib.lib -L mylib
6064 must be an absolute path name.
6068 The most efficient way to use libraries is
6069 to keep separate modules in separate source files.
6070 The lib file now should name all the modules.rel
6071 \begin_inset LatexCommand \index{<file>.rel}
6076 For an example see the standard library file
6080 in the directory <installdir>/share/lib/small.
6083 \begin_layout Subsection
6084 Using sdcclib to Create and Manage Libraries
6085 \begin_inset LatexCommand \index{sdcclib}
6092 \begin_layout Standard
6093 Alternatively, instead of having a .rel file for each entry on the library
6094 file as described in the preceding section, sdcclib can be used to embed
6095 all the modules belonging to such library in the library file itself.
6096 This results in a larger library file, but it greatly reduces the number
6097 of disk files accessed by the linker.
6098 Additionally, the packed library file contains an index of all include
6099 modules and symbols that significantly speeds up the linking process.
6100 To display a list of options supported by sdcclib type:
6105 \begin_layout Standard
6110 \begin_inset LatexCommand \index{sdcclib}
6121 To create a new library file, start by compiling all the required modules.
6127 \begin_layout Standard
6134 \begin_layout Standard
6141 \begin_layout Standard
6148 \begin_layout Standard
6155 \begin_layout Standard
6164 \begin_layout Standard
6165 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6167 The next step is to add the .rel files to the library file:
6172 \begin_layout Standard
6176 sdcclib libint.lib _divsint.rel
6179 \begin_inset LatexCommand \index{sdcclib}
6186 \begin_layout Standard
6190 sdcclib libint.lib _divuint.rel
6193 \begin_layout Standard
6197 sdcclib libint.lib _modsint.rel
6200 \begin_layout Standard
6204 sdcclib libint.lib _moduint.rel
6207 \begin_layout Standard
6211 sdcclib libint.lib _mulint.rel
6218 \begin_layout Standard
6219 If the file already exists in the library, it will be replaced.
6220 To see what modules and symbols are included in the library, options -s
6221 and -m are available.
6229 sdcclib -s libint.lib
6232 \begin_inset LatexCommand \index{sdcclib}
6244 \begin_layout Standard
6250 \begin_layout Standard
6256 \begin_layout Standard
6264 \begin_layout Standard
6270 \begin_layout Standard
6276 \begin_layout Standard
6282 \begin_layout Standard
6288 \begin_layout Standard
6296 \begin_layout Standard
6302 \begin_layout Standard
6308 \begin_layout Standard
6316 \begin_layout Standard
6322 \begin_layout Standard
6328 \begin_layout Standard
6334 \begin_layout Standard
6342 \begin_layout Standard
6348 \begin_layout Standard
6359 \begin_layout Standard
6360 If the source files are compiled using -
6364 \begin_layout Standard
6374 \begin_inset LatexCommand \index{-\/-debug}
6378 , the corresponding debug information file .adb will be include in the library
6380 The library files created with sdcclib are plain text files, so they can
6381 be viewed with a text editor.
6382 It is not recomended to modify a library file created with sdcclib using
6383 a text editor, as there are file indexes numbers located accross the file
6384 used by the linker to quickly locate the required module to link.
6385 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6386 it can be safely deleted, since all the information required for linking
6387 is embedded in the library file itself.
6388 Library files created using sdcclib are used as described in the preceding
6390 \begin_inset VSpace bigskip
6396 \begin_layout Section
6397 Command Line Options
6398 \begin_inset LatexCommand \index{Command Line Options}
6405 \begin_layout Subsection
6406 Processor Selection Options
6407 \begin_inset LatexCommand \index{Options processor selection}
6412 \begin_inset LatexCommand \index{Processor selection options}
6420 \labelwidthstring 00.00.0000
6424 \begin_inset LatexCommand \index{-mmcs51}
6430 Generate code for the Intel MCS51
6431 \begin_inset LatexCommand \index{MCS51}
6435 family of processors.
6436 This is the default processor target.
6440 \labelwidthstring 00.00.0000
6444 \begin_inset LatexCommand \index{-mds390}
6450 Generate code for the Dallas DS80C390
6451 \begin_inset LatexCommand \index{DS80C390}
6459 \labelwidthstring 00.00.0000
6463 \begin_inset LatexCommand \index{-mds400}
6469 Generate code for the Dallas DS80C400
6470 \begin_inset LatexCommand \index{DS80C400}
6478 \labelwidthstring 00.00.0000
6482 \begin_inset LatexCommand \index{-mhc08}
6488 Generate code for the Freescale/Motorola HC08
6489 \begin_inset LatexCommand \index{HC08}
6493 family of processors.
6497 \labelwidthstring 00.00.0000
6501 \begin_inset LatexCommand \index{-mz80}
6507 Generate code for the Zilog Z80
6508 \begin_inset LatexCommand \index{Z80}
6512 family of processors.
6516 \labelwidthstring 00.00.0000
6520 \begin_inset LatexCommand \index{-mgbz80}
6526 Generate code for the GameBoy Z80
6527 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6531 processor (Not actively maintained).
6535 \labelwidthstring 00.00.0000
6539 \begin_inset LatexCommand \index{-mavr}
6545 Generate code for the Atmel AVR
6546 \begin_inset LatexCommand \index{AVR}
6550 processor (Not maintained, not complete).
6551 AVR users should probably have a look at winavr
6552 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6557 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6564 \begin_layout Standard
6565 \begin_inset Note Note
6568 \begin_layout Standard
6569 I think it is fair to direct users there for now.
6570 Open source is also about avoiding unnecessary work .
6571 But I didn't find the 'official' link.
6580 \labelwidthstring 00.00.0000
6584 \begin_inset LatexCommand \index{-mpic14}
6590 Generate code for the Microchip PIC 14
6591 \begin_inset LatexCommand \index{PIC14}
6595 -bit processors (p16f84 and variants.
6596 In development, not complete).
6599 \begin_layout Standard
6600 \begin_inset Note Note
6603 \begin_layout Standard
6604 p16f627 p16f628 p16f84 p16f873 p16f877?
6613 \labelwidthstring 00.00.0000
6617 \begin_inset LatexCommand \index{-mpic16}
6623 Generate code for the Microchip PIC 16
6624 \begin_inset LatexCommand \index{PIC16}
6628 -bit processors (p18f452 and variants.
6629 In development, not complete).
6633 \labelwidthstring 00.00.0000
6638 Generate code for the Toshiba TLCS-900H
6639 \begin_inset LatexCommand \index{TLCS-900H}
6643 processor (Not maintained, not complete).
6647 \labelwidthstring 00.00.0000
6651 \begin_inset LatexCommand \index{-mxa51}
6657 Generate code for the Phillips XA51
6658 \begin_inset LatexCommand \index{XA51}
6662 processor (Not maintained, not complete).
6665 \begin_layout Standard
6666 \begin_inset VSpace bigskip
6672 \begin_layout Subsection
6673 Preprocessor Options
6674 \begin_inset LatexCommand \index{Options preprocessor}
6679 \begin_inset LatexCommand \index{Preprocessor options}
6684 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6692 \labelwidthstring 00.00.0000
6696 \begin_inset LatexCommand \index{-I<path>}
6702 The additional location where the pre processor will look for <..h> or
6703 \begin_inset Quotes eld
6707 \begin_inset Quotes erd
6714 \labelwidthstring 00.00.0000
6718 \begin_inset LatexCommand \index{-D<macro[=value]>}
6724 Command line definition of macros.
6725 Passed to the preprocessor.
6729 \labelwidthstring 00.00.0000
6733 \begin_inset LatexCommand \index{-M}
6739 Tell the preprocessor to output a rule suitable for make describing the
6740 dependencies of each object file.
6741 For each source file, the preprocessor outputs one make-rule whose target
6742 is the object file name for that source file and whose dependencies are
6743 all the files `#include'd in it.
6744 This rule may be a single line or may be continued with `
6746 '-newline if it is long.
6747 The list of rules is printed on standard output instead of the preprocessed
6750 \begin_inset LatexCommand \index{-E}
6758 \labelwidthstring 00.00.0000
6762 \begin_inset LatexCommand \index{-C}
6768 Tell the preprocessor not to discard comments.
6769 Used with the `-E' option.
6773 \labelwidthstring 00.00.0000
6777 \begin_inset LatexCommand \index{-MM}
6788 Like `-M' but the output mentions only the user header files included with
6790 \begin_inset Quotes eld
6794 System header files included with `#include <file>' are omitted.
6798 \labelwidthstring 00.00.0000
6802 \begin_inset LatexCommand \index{-Aquestion(answer)}
6808 Assert the answer answer for question, in case it is tested with a preprocessor
6809 conditional such as `#if #question(answer)'.
6810 `-A-' disables the standard assertions that normally describe the target
6815 \labelwidthstring 00.00.0000
6819 \begin_inset LatexCommand \index{-Umacro}
6825 Undefine macro macro.
6826 `-U' options are evaluated after all `-D' options, but before any `-include'
6827 and `-imacros' options.
6831 \labelwidthstring 00.00.0000
6835 \begin_inset LatexCommand \index{-dM}
6841 Tell the preprocessor to output only a list of the macro definitions that
6842 are in effect at the end of preprocessing.
6843 Used with the `-E' option.
6847 \labelwidthstring 00.00.0000
6851 \begin_inset LatexCommand \index{-dD}
6857 Tell the preprocessor to pass all macro definitions into the output, in
6858 their proper sequence in the rest of the output.
6862 \labelwidthstring 00.00.0000
6866 \begin_inset LatexCommand \index{-dN}
6877 Like `-dD' except that the macro arguments and contents are omitted.
6878 Only `#define name' is included in the output.
6882 \labelwidthstring 00.00.0000
6885 -pedantic-parse-number
6886 \begin_inset LatexCommand \index{-pedantic-parse-number}
6897 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6898 and the macro LO_B(3) gets expanded.
6899 See also #pragma pedantic_parse_number in section
6900 \begin_inset LatexCommand \ref{sec:Pragmas}
6906 Note: this functionality is not in conformance with standard!
6910 \labelwidthstring 00.00.0000
6914 preprocessorOption[,preprocessorOption]
6917 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6922 Pass the preprocessorOption to the preprocessor
6927 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6932 SDCC uses an adapted version of the preprocessor
6936 of the GNU Compiler Collection
6937 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6946 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6950 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
6955 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6962 \begin_layout Standard
6963 \begin_inset VSpace bigskip
6969 \begin_layout Subsection
6971 \begin_inset LatexCommand \index{Options linker}
6976 \begin_inset LatexCommand \index{Linker options}
6984 \labelwidthstring 00.00.0000
6994 \begin_layout Standard
7006 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7011 \begin_inset LatexCommand \index{-L -\/-lib-path}
7018 <absolute path to additional libraries> This option is passed to the linkage
7019 editor's additional libraries
7020 \begin_inset LatexCommand \index{Libraries}
7025 The path name must be absolute.
7026 Additional library files may be specified in the command line.
7027 See section Compiling programs for more details.
7031 \labelwidthstring 00.00.0000
7038 \begin_layout Standard
7050 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7055 <Value> The start location of the external ram
7056 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7060 , default value is 0.
7061 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7065 \begin_layout Standard
7074 -xram-loc 0x8000 or -
7078 \begin_layout Standard
7091 \labelwidthstring 00.00.0000
7098 \begin_layout Standard
7110 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7115 <Value> The start location of the code
7116 \begin_inset LatexCommand \index{code}
7120 segment, default value 0.
7121 Note when this option is used the interrupt vector table
7122 \begin_inset LatexCommand \index{interrupt vector table}
7126 is also relocated to the given address.
7127 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7131 \begin_layout Standard
7140 -code-loc 0x8000 or -
7144 \begin_layout Standard
7157 \labelwidthstring 00.00.0000
7164 \begin_layout Standard
7176 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7181 <Value> By default the stack
7182 \begin_inset LatexCommand \index{stack}
7186 is placed after the data segment.
7187 Using this option the stack can be placed anywhere in the internal memory
7189 The value entered can be in Hexadecimal or Decimal format, e.g.
7194 \begin_layout Standard
7203 -stack-loc 0x20 or -
7207 \begin_layout Standard
7217 Since the sp register is incremented before a push or call, the initial
7218 sp will be set to one byte prior the provided value.
7219 The provided value should not overlap any other memory areas such as used
7220 register banks or the data segment and with enough space for the current
7228 \begin_layout Standard
7241 \begin_inset LatexCommand \index{-\/-pack-iram}
7245 option (which is now a default setting) will override this setting, so
7246 you should also specify the
7252 \begin_layout Standard
7265 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7269 option if you need to manually place the stack.
7273 \labelwidthstring 00.00.0000
7280 \begin_layout Standard
7292 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7297 <Value> By default the external stack
7298 \begin_inset LatexCommand \index{xstack}
7302 is placed after the pdata
7303 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7308 Using this option the xstack can be placed anywhere in the external memory
7310 The value entered can be in Hexadecimal or Decimal format, e.g.
7315 \begin_layout Standard
7324 -xstack-loc 0x8000 or -
7328 \begin_layout Standard
7338 The provided value should not overlap any other memory areas such as the
7339 pdata or xdata segment and with enough space for the current application.
7343 \labelwidthstring 00.00.0000
7350 \begin_layout Standard
7362 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7367 <Value> The start location of the internal ram data
7368 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7373 The value entered can be in Hexadecimal or Decimal format, eg.
7378 \begin_layout Standard
7391 \begin_layout Standard
7401 (By default, the start location of the internal ram data segment is set
7402 as low as possible in memory, taking into account the used register banks
7403 and the bit segment at address 0x20.
7404 For example if register banks 0 and 1 are used without bit variables, the
7405 data segment will be set, if -
7409 \begin_layout Standard
7418 -data-loc is not used, to location 0x10.)
7422 \labelwidthstring 00.00.0000
7429 \begin_layout Standard
7441 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7446 <Value> The start location of the indirectly addressable internal ram
7447 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7451 of the 8051, default value is 0x80.
7452 The value entered can be in Hexadecimal or Decimal format, eg.
7457 \begin_layout Standard
7466 -idata-loc 0x88 or -
7470 \begin_layout Standard
7483 \labelwidthstring 00.00.0000
7490 \begin_layout Standard
7502 <Value> The start location of the bit
7503 \begin_inset LatexCommand \index{bit}
7507 addressable internal ram of the 8051.
7513 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7518 \labelwidthstring 00.00.0000
7525 \begin_layout Standard
7535 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7544 The linker output (final object code) is in Intel Hex format.
7545 \begin_inset LatexCommand \index{Intel hex format}
7549 This is the default option.
7550 The format itself is documented in the documentation of srecord
7551 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7559 \labelwidthstring 00.00.0000
7566 \begin_layout Standard
7576 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7585 The linker output (final object code) is in Motorola S19 format
7586 \begin_inset LatexCommand \index{Motorola S19 format}
7591 The format itself is documented in the documentation of srecord.
7595 \labelwidthstring 00.00.0000
7602 \begin_layout Standard
7612 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7617 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7626 The linker output (final object code) is in ELF format
7627 \begin_inset LatexCommand \index{ELF format}
7632 (Currently only supported for the HC08
7633 \begin_inset LatexCommand \index{HC08}
7641 \labelwidthstring 00.00.0000
7645 linkOption[,linkOption]
7648 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7653 Pass the linkOption to the linker.
7654 If a bootloader is used an option like
7655 \begin_inset Quotes sld
7660 \begin_inset Quotes srd
7663 would be typical to set the start of the code segment.
7664 See also #pragma constseg and #pragma codeseg in section
7665 \begin_inset LatexCommand \ref{sec:Pragmas}
7670 File sdcc/as/doc/asxhtm.html has more on linker options.
7673 \begin_layout Standard
7674 \begin_inset VSpace bigskip
7680 \begin_layout Subsection
7682 \begin_inset LatexCommand \index{Options MCS51}
7687 \begin_inset LatexCommand \index{MCS51 options}
7695 \labelwidthstring 00.00.0000
7702 \begin_layout Standard
7712 \begin_inset LatexCommand \index{-\/-model-small}
7723 Generate code for Small Model programs, see section Memory Models for more
7725 This is the default model.
7729 \labelwidthstring 00.00.0000
7736 \begin_layout Standard
7746 \begin_inset LatexCommand \index{-\/-model-medium}
7752 Generate code for Medium model programs, see section Memory Models for
7754 If this option is used all source files in the project have to be compiled
7756 It must also be used when invoking the linker.
7760 \labelwidthstring 00.00.0000
7767 \begin_layout Standard
7777 \begin_inset LatexCommand \index{-\/-model-large}
7783 Generate code for Large model programs, see section Memory Models for more
7785 If this option is used all source files in the project have to be compiled
7787 It must also be used when invoking the linker.
7791 \labelwidthstring 00.00.0000
7798 \begin_layout Standard
7808 \begin_inset LatexCommand \index{-\/-xstack}
7814 Uses a pseudo stack in the pdata
7815 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7819 area (usually the first 256 bytes in the external ram) for allocating variables
7820 and passing parameters.
7822 \begin_inset LatexCommand \ref{sub:External-Stack}
7827 External Stack for more details.
7831 \labelwidthstring 00.00.0000
7838 \begin_layout Standard
7851 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7855 Causes the linker to check if the internal ram usage is within limits of
7860 \labelwidthstring 00.00.0000
7867 \begin_layout Standard
7880 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7884 Causes the linker to check if the external ram usage is within limits of
7889 \labelwidthstring 00.00.0000
7896 \begin_layout Standard
7909 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7913 Causes the linker to check if the code memory usage is within limits of
7918 \labelwidthstring 00.00.0000
7925 \begin_layout Standard
7938 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7942 Causes the linker to check if there is at minimum <Value> bytes for stack.
7946 \labelwidthstring 00.00.0000
7953 \begin_layout Standard
7966 \begin_inset LatexCommand \index{-\/-pack-iram}
7970 Causes the linker to use unused register banks for data variables and pack
7971 data, idata and stack together.
7972 This is the default now.
7976 \labelwidthstring 00.00.0000
7983 \begin_layout Standard
7996 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8000 Causes the linker to use old style for allocating memory areas.
8003 \begin_layout Standard
8004 \begin_inset VSpace bigskip
8010 \begin_layout Subsection
8011 DS390 / DS400 Options
8012 \begin_inset LatexCommand \index{Options DS390}
8017 \begin_inset LatexCommand \index{DS390}
8025 \labelwidthstring 00.00.0000
8032 \begin_layout Standard
8044 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8054 Generate 24-bit flat mode code.
8055 This is the one and only that the ds390 code generator supports right now
8056 and is default when using
8061 See section Memory Models for more details.
8065 \labelwidthstring 00.00.0000
8072 \begin_layout Standard
8082 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8088 disable interrupts during ESP:SP updates.
8092 \labelwidthstring 00.00.0000
8099 \begin_layout Standard
8111 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8115 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8116 This is the one and only that the ds390 code generator supports right now
8117 and is default when using
8122 In this mode, the stack is located in the lower 1K of the internal RAM,
8123 which is mapped to 0x400000.
8124 Note that the support is incomplete, since it still uses a single byte
8125 as the stack pointer.
8126 This means that only the lower 256 bytes of the potential 1K stack space
8127 will actually be used.
8128 However, this does allow you to reclaim the precious 256 bytes of low RAM
8129 for use for the DATA and IDATA segments.
8130 The compiler will not generate any code to put the processor into 10 bit
8132 It is important to ensure that the processor is in this mode before calling
8133 any re-entrant functions compiled with this option.
8134 In principle, this should work with the
8140 \begin_layout Standard
8150 \begin_inset LatexCommand \index{-\/-stack-auto}
8156 option, but that has not been tested.
8157 It is incompatible with the
8163 \begin_layout Standard
8173 \begin_inset LatexCommand \index{-\/-xstack}
8180 It also only makes sense if the processor is in 24 bit contiguous addressing
8187 \begin_layout Standard
8196 -model-flat24 option
8202 \labelwidthstring 00.00.0000
8209 \begin_layout Standard
8219 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8225 insert call to function __stack_probe at each function prologue.
8229 \labelwidthstring 00.00.0000
8236 \begin_layout Standard
8246 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8252 <nnnn> LibraryID used in -mTININative.
8257 \labelwidthstring 00.00.0000
8264 \begin_layout Standard
8274 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8280 generate code for DS390 Arithmetic Accelerator.
8284 \begin_layout Standard
8285 \begin_inset VSpace bigskip
8291 \begin_layout Subsection
8293 \begin_inset LatexCommand \index{Options Z80}
8298 \begin_inset LatexCommand \index{Z80}
8306 \labelwidthstring 00.00.0000
8313 \begin_layout Standard
8325 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8335 Force a called function to always save BC.
8339 \labelwidthstring 00.00.0000
8346 \begin_layout Standard
8358 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8362 When linking, skip the standard crt0.o object file.
8363 You must provide your own crt0.o for your system when linking.
8367 \begin_layout Standard
8368 \begin_inset VSpace bigskip
8374 \begin_layout Subsection
8375 Optimization Options
8376 \begin_inset LatexCommand \index{Options optimization}
8381 \begin_inset LatexCommand \index{Optimization options}
8389 \labelwidthstring 00.00.0000
8396 \begin_layout Standard
8406 \begin_inset LatexCommand \index{-\/-nogcse}
8412 Will not do global subexpression elimination, this option may be used when
8413 the compiler creates undesirably large stack/data spaces to store compiler
8423 \begin_inset LatexCommand \index{sloc (spill location)}
8428 A warning message will be generated when this happens and the compiler
8429 will indicate the number of extra bytes it allocated.
8430 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8432 \begin_inset LatexCommand \index{\#pragma nogcse}
8436 can be used to turn off global subexpression elimination
8437 \begin_inset LatexCommand \index{Subexpression elimination}
8441 for a given function only.
8445 \labelwidthstring 00.00.0000
8452 \begin_layout Standard
8462 \begin_inset LatexCommand \index{-\/-noinvariant}
8468 Will not do loop invariant optimizations, this may be turned off for reasons
8469 explained for the previous option.
8470 For more details of loop optimizations performed see Loop Invariants in
8472 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8477 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8479 \begin_inset LatexCommand \index{\#pragma noinvariant}
8483 can be used to turn off invariant optimizations for a given function only.
8487 \labelwidthstring 00.00.0000
8494 \begin_layout Standard
8504 \begin_inset LatexCommand \index{-\/-noinduction}
8510 Will not do loop induction optimizations, see section strength reduction
8512 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8514 \begin_inset LatexCommand \index{\#pragma noinduction}
8518 can be used to turn off induction optimizations for a given function only.
8522 \labelwidthstring 00.00.0000
8529 \begin_layout Standard
8539 \begin_inset LatexCommand \index{-\/-nojtbound}
8550 Will not generate boundary condition check when switch statements
8551 \begin_inset LatexCommand \index{switch statement}
8555 are implemented using jump-tables.
8557 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8562 Switch Statements for more details.
8563 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8565 \begin_inset LatexCommand \index{\#pragma nojtbound}
8569 can be used to turn off boundary checking for jump tables for a given function
8574 \labelwidthstring 00.00.0000
8581 \begin_layout Standard
8591 \begin_inset LatexCommand \index{-\/-noloopreverse}
8600 Will not do loop reversal
8601 \begin_inset LatexCommand \index{Loop reversing}
8609 \labelwidthstring 00.00.0000
8614 \begin_layout Standard
8628 \begin_inset LatexCommand \index{-\/-nolabelopt }
8632 Will not optimize labels (makes the dumpfiles more readable).
8636 \labelwidthstring 00.00.0000
8643 \begin_layout Standard
8653 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8659 Will not memcpy initialized data from code space into xdata space.
8660 This saves a few bytes in code space if you don't have initialized data
8661 \begin_inset LatexCommand \index{Variable initialization}
8669 \labelwidthstring 00.00.0000
8676 \begin_layout Standard
8686 \begin_inset LatexCommand \index{-\/-nooverlay}
8692 The compiler will not overlay parameters and local variables of any function,
8693 see section Parameters and local variables for more details.
8697 \labelwidthstring 00.00.0000
8704 \begin_layout Standard
8714 \begin_inset LatexCommand \index{-\/-no-peep}
8720 Disable peep-hole optimization with built-in rules.
8724 \labelwidthstring 00.00.0000
8731 \begin_layout Standard
8743 \begin_inset LatexCommand \index{-\/-peep-file}
8748 <filename> This option can be used to use additional rules to be used by
8749 the peep hole optimizer.
8751 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8756 Peep Hole optimizations for details on how to write these rules.
8760 \labelwidthstring 00.00.0000
8767 \begin_layout Standard
8777 \begin_inset LatexCommand \index{-\/-peep-asm}
8783 Pass the inline assembler code through the peep hole optimizer.
8784 This can cause unexpected changes to inline assembler code, please go through
8785 the peephole optimizer
8786 \begin_inset LatexCommand \index{Peephole optimizer}
8790 rules defined in the source file tree '<target>/peeph.def' before using
8795 \labelwidthstring 00.00.0000
8802 \begin_layout Standard
8812 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8818 The compiler will optimize code generation towards fast code, possibly
8819 at the expense of code size.
8823 \labelwidthstring 00.00.0000
8830 \begin_layout Standard
8840 \begin_inset LatexCommand \index{-\/-opt-code-size}
8846 The compiler will optimize code generation towards compact code, possibly
8847 at the expense of code speed.
8850 \begin_layout Standard
8851 \begin_inset VSpace bigskip
8857 \begin_layout Subsection
8859 \begin_inset LatexCommand \index{Options other}
8867 \labelwidthstring 00.00.0000
8875 \begin_layout Standard
8885 \begin_inset LatexCommand \index{-\/-compile-only}
8890 \begin_inset LatexCommand \index{-c -\/-compile-only}
8896 will compile and assemble the source, but will not call the linkage editor.
8900 \labelwidthstring 00.00.0000
8909 \begin_layout Standard
8921 \begin_inset LatexCommand \index{-\/-c1mode}
8927 reads the preprocessed source from standard input and compiles it.
8928 The file name for the assembler output must be specified using the -o option.
8932 \labelwidthstring 00.00.0000
8936 \begin_inset LatexCommand \index{-E}
8942 Run only the C preprocessor.
8943 Preprocess all the C source files specified and output the results to standard
8948 \labelwidthstring 00.00.0000
8953 \begin_inset LatexCommand \index{-o <path/file>}
8959 The output path resp.
8960 file where everything will be placed.
8961 If the parameter is a path, it must have a trailing slash (or backslash
8962 for the Windows binaries) to be recognized as a path.
8967 \labelwidthstring 00.00.0000
8974 \begin_layout Standard
8984 \begin_inset LatexCommand \index{-\/-stack-auto}
8995 All functions in the source file will be compiled as
9000 \begin_inset LatexCommand \index{reentrant}
9005 the parameters and local variables will be allocated on the stack
9006 \begin_inset LatexCommand \index{stack}
9012 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9016 Parameters and Local Variables for more details.
9017 If this option is used all source files in the project should be compiled
9019 It automatically implies --int-long-reent and --float-reent.
9024 \labelwidthstring 00.00.0000
9031 \begin_layout Standard
9041 \begin_inset LatexCommand \index{-\/-callee-saves}
9045 function1[,function2][,function3]....
9048 The compiler by default uses a caller saves convention for register saving
9049 across function calls, however this can cause unnecessary register pushing
9050 & popping when calling small functions from larger functions.
9051 This option can be used to switch the register saving convention for the
9052 function names specified.
9053 The compiler will not save registers when calling these functions, no extra
9054 code will be generated at the entry & exit (function prologue
9057 \begin_inset LatexCommand \index{function prologue}
9066 \begin_inset LatexCommand \index{function epilogue}
9072 ) for these functions to save & restore the registers used by these functions,
9073 this can SUBSTANTIALLY reduce code & improve run time performance of the
9075 In the future the compiler (with inter procedural analysis) will be able
9076 to determine the appropriate scheme to use for each function call.
9077 DO NOT use this option for built-in functions such as _mulint..., if this
9078 option is used for a library function the appropriate library function
9079 needs to be recompiled with the same option.
9080 If the project consists of multiple source files then all the source file
9081 should be compiled with the same -
9085 \begin_layout Standard
9094 -callee-saves option string.
9095 Also see #pragma\InsetSpace ~
9097 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9105 \labelwidthstring 00.00.0000
9112 \begin_layout Standard
9122 \begin_inset LatexCommand \index{-\/-debug}
9131 When this option is used the compiler will generate debug information.
9132 The debug information collected in a file with .cdb extension can be used
9134 For more information see documentation for SDCDB.
9135 Another file with no extension contains debug information in AOMF or AOMF51
9136 \begin_inset LatexCommand \index{AOMF, AOMF51}
9140 format which is commonly used by third party tools.
9144 \labelwidthstring 00.00.0000
9148 \begin_inset LatexCommand \index{-S}
9159 Stop after the stage of compilation proper; do not assemble.
9160 The output is an assembler code file for the input file specified.
9164 \labelwidthstring 00.00.0000
9171 \begin_layout Standard
9181 \begin_inset LatexCommand \index{-\/-int-long-reent}
9187 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9188 Note by default these libraries are compiled as non-reentrant.
9189 See section Installation for more details.
9193 \labelwidthstring 00.00.0000
9200 \begin_layout Standard
9210 \begin_inset LatexCommand \index{-\/-cyclomatic}
9219 This option will cause the compiler to generate an information message for
9220 each function in the source file.
9221 The message contains some
9225 information about the function.
9226 The number of edges and nodes the compiler detected in the control flow
9227 graph of the function, and most importantly the
9229 cyclomatic complexity
9230 \begin_inset LatexCommand \index{Cyclomatic complexity}
9236 see section on Cyclomatic Complexity for more details.
9240 \labelwidthstring 00.00.0000
9247 \begin_layout Standard
9257 \begin_inset LatexCommand \index{-\/-float-reent}
9263 Floating point library is compiled as reentrant
9264 \begin_inset LatexCommand \index{reentrant}
9269 See section Installation for more details.
9273 \labelwidthstring 00.00.0000
9280 \begin_layout Standard
9290 \begin_inset LatexCommand \index{-\/-funsigned-char}
9296 The default signedness for every type is
9301 In some embedded environments the default signedness of
9310 To set the signess for characters to unsigned, use the option --funsigned-char.
9311 If this option is set and no signedness keyword (unsigned/signed) is given,
9312 a char will be signed.
9313 All other types are unaffected.
9317 \labelwidthstring 00.00.0000
9324 \begin_layout Standard
9334 \begin_inset LatexCommand \index{-\/-main-return}
9340 This option can be used if the code generated is called by a monitor program
9341 or if the main routine includes an endless loop.
9342 This option results in slightly smaller code and saves two bytes of stack
9344 The return from the 'main'
9345 \begin_inset LatexCommand \index{main return}
9349 function will return to the function calling main.
9350 The default setting is to lock up i.e.
9359 \labelwidthstring 00.00.0000
9366 \begin_layout Standard
9376 \begin_inset LatexCommand \index{-\/-nostdinc}
9382 This will prevent the compiler from passing on the default include path
9383 to the preprocessor.
9387 \labelwidthstring 00.00.0000
9394 \begin_layout Standard
9404 \begin_inset LatexCommand \index{-\/-nostdlib}
9410 This will prevent the compiler from passing on the default library
9411 \begin_inset LatexCommand \index{Libraries}
9419 \labelwidthstring 00.00.0000
9426 \begin_layout Standard
9436 \begin_inset LatexCommand \index{-\/-verbose}
9442 Shows the various actions the compiler is performing.
9446 \labelwidthstring 00.00.0000
9450 \begin_inset LatexCommand \index{-V}
9456 Shows the actual commands the compiler is executing.
9460 \labelwidthstring 00.00.0000
9467 \begin_layout Standard
9477 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9483 Hides your ugly and inefficient c-code from the asm file, so you can always
9484 blame the compiler :)
9488 \labelwidthstring 00.00.0000
9495 \begin_layout Standard
9505 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9511 Will not include peep-hole comments in the generated files.
9515 \labelwidthstring 00.00.0000
9522 \begin_layout Standard
9532 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9538 Will not include code generator comments in the generated files.
9542 \labelwidthstring 00.00.0000
9549 \begin_layout Standard
9559 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9565 Include i-codes in the asm file.
9566 Sounds like noise but is most helpful for debugging the compiler itself.
9570 \labelwidthstring 00.00.0000
9577 \begin_layout Standard
9587 \begin_inset LatexCommand \index{-\/-less-pedantic}
9593 Disable some of the more pedantic warnings
9594 \begin_inset LatexCommand \index{Warnings}
9598 (jwk burps: please be more specific here, please!).
9602 \labelwidthstring 00.00.0000
9609 \begin_layout Standard
9618 -disable-warning\InsetSpace ~
9620 \begin_inset LatexCommand \index{-\/-disable-warning}
9626 Disable specific warning with number <nnnn>.
9630 \labelwidthstring 00.00.0000
9637 \begin_layout Standard
9647 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9653 Display the directories in the compiler's search path
9657 \labelwidthstring 00.00.0000
9664 \begin_layout Standard
9674 \begin_inset LatexCommand \index{-\/-vc}
9680 Display errors and warnings using MSVC style, so you can use SDCC with
9681 the visual studio IDE
9682 \begin_inset LatexCommand \index{IDE}
9687 With SDCC both offering a GCC-like (the default) and a MSVC-like
9688 \begin_inset LatexCommand \index{MSVC output style}
9692 output style, integration into most programming editors should be straightforwa
9697 \labelwidthstring 00.00.0000
9704 \begin_layout Standard
9714 \begin_inset LatexCommand \index{-\/-use-stdout}
9720 Send errors and warnings to stdout instead of stderr.
9724 \labelwidthstring 00.00.0000
9728 asmOption[,asmOption]
9731 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9736 Pass the asmOption to the assembler
9737 \begin_inset LatexCommand \index{Options assembler}
9742 \begin_inset LatexCommand \index{Assembler options}
9747 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9751 \labelwidthstring 00.00.0000
9758 \begin_layout Standard
9768 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9774 Generally follow the C89 standard, but allow SDCC features that conflict
9775 with the standard (default).
9779 \labelwidthstring 00.00.0000
9786 \begin_layout Standard
9796 \begin_inset LatexCommand \index{-\/-std-c89}
9802 Follow the C89 standard and disable SDCC features that conflict with the
9807 \labelwidthstring 00.00.0000
9814 \begin_layout Standard
9824 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9830 Generally follow the C99 standard, but allow SDCC features that conflict
9831 with the standard (incomplete support).
9835 \labelwidthstring 00.00.0000
9842 \begin_layout Standard
9852 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9858 Follow the C99 standard and disable SDCC features that conflict with the
9859 standard (incomplete support).
9863 \labelwidthstring 00.00.0000
9870 \begin_layout Standard
9882 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9887 <Name> The name to be used for the code
9888 \begin_inset LatexCommand \index{code}
9892 segment, default CSEG.
9893 This is useful if you need to tell the compiler to put the code in a special
9894 segment so you can later on tell the linker to put this segment in a special
9896 Can be used for instance when using bank switching to put the code in a
9901 \labelwidthstring 00.00.0000
9908 \begin_layout Standard
9920 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9925 <Name> The name to be used for the const
9926 \begin_inset LatexCommand \index{code}
9930 segment, default CONST.
9931 This is useful if you need to tell the compiler to put the const data in
9932 a special segment so you can later on tell the linker to put this segment
9933 in a special place in memory.
9934 Can be used for instance when using bank switching to put the const data
9939 \labelwidthstring 00.00.0000
9946 \begin_layout Standard
9955 -fdollars-in-identifiers
9956 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9962 Permit '$' as an identifier character
9966 \labelwidthstring 00.00.0000
9977 a SDCC compiler option but if you want
9981 warnings you can use a separate tool dedicated to syntax checking like
9983 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9988 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9993 \begin_inset LatexCommand \url{http://www.splint.org}
9998 To make your source files parseable by splint you will have to include
10004 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10008 in your source file and add brackets around extended keywords (like
10011 \begin_inset Quotes sld
10024 \begin_inset Quotes srd
10032 \begin_inset Quotes sld
10035 __interrupt\InsetSpace ~
10037 \begin_inset Quotes srd
10045 Splint has an excellent on line manual at
10046 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10050 and it's capabilities go beyond pure syntax checking.
10051 You'll need to tell splint the location of SDCC's include files so a typical
10052 command line could look like this:
10056 splint\InsetSpace ~
10058 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10063 \begin_layout Standard
10064 \begin_inset VSpace bigskip
10070 \begin_layout Subsection
10071 Intermediate Dump Options
10072 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10077 \begin_inset LatexCommand \index{Options intermediate dump}
10082 \begin_inset LatexCommand \index{Intermediate dump options}
10089 \begin_layout Standard
10090 The following options are provided for the purpose of retargetting and debugging
10092 They provide a means to dump the intermediate code (iCode
10093 \begin_inset LatexCommand \index{iCode}
10097 ) generated by the compiler in human readable form at various stages of
10098 the compilation process.
10099 More on iCodes see chapter
10100 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10105 \begin_inset Quotes srd
10108 The anatomy of the compiler
10109 \begin_inset Quotes srd
10116 \labelwidthstring 00.00.0000
10123 \begin_layout Standard
10133 \begin_inset LatexCommand \index{-\/-dumpraw}
10139 This option will cause the compiler to dump the intermediate code into
10142 <source filename>.dumpraw
10144 just after the intermediate code has been generated for a function, i.e.
10145 before any optimizations are done.
10147 \begin_inset LatexCommand \index{Basic blocks}
10151 at this stage ordered in the depth first number, so they may not be in
10152 sequence of execution.
10156 \labelwidthstring 00.00.0000
10163 \begin_layout Standard
10173 \begin_inset LatexCommand \index{-\/-dumpgcse}
10179 Will create a dump of iCode's, after global subexpression elimination
10180 \begin_inset LatexCommand \index{Global subexpression elimination}
10184 , into a file named
10186 <source filename>.dumpgcse.
10190 \labelwidthstring 00.00.0000
10197 \begin_layout Standard
10207 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10213 Will create a dump of iCode's, after deadcode elimination
10214 \begin_inset LatexCommand \index{Dead-code elimination}
10218 , into a file named
10220 <source filename>.dumpdeadcode.
10224 \labelwidthstring 00.00.0000
10231 \begin_layout Standard
10241 \begin_inset LatexCommand \index{-\/-dumploop}
10250 Will create a dump of iCode's, after loop optimizations
10251 \begin_inset LatexCommand \index{Loop optimization}
10255 , into a file named
10257 <source filename>.dumploop.
10261 \labelwidthstring 00.00.0000
10268 \begin_layout Standard
10278 \begin_inset LatexCommand \index{-\/-dumprange}
10287 Will create a dump of iCode's, after live range analysis
10288 \begin_inset LatexCommand \index{Live range analysis}
10292 , into a file named
10294 <source filename>.dumprange.
10298 \labelwidthstring 00.00.0000
10305 \begin_layout Standard
10315 \begin_inset LatexCommand \index{-\/-dumlrange}
10321 Will dump the life ranges
10322 \begin_inset LatexCommand \index{Live range analysis}
10330 \labelwidthstring 00.00.0000
10337 \begin_layout Standard
10347 \begin_inset LatexCommand \index{-\/-dumpregassign}
10356 Will create a dump of iCode's, after register assignment
10357 \begin_inset LatexCommand \index{Register assignment}
10361 , into a file named
10363 <source filename>.dumprassgn.
10367 \labelwidthstring 00.00.0000
10374 \begin_layout Standard
10384 \begin_inset LatexCommand \index{-\/-dumplrange}
10390 Will create a dump of the live ranges of iTemp's
10394 \labelwidthstring 00.00.0000
10401 \begin_layout Standard
10411 \begin_inset LatexCommand \index{-\/-dumpall}
10422 Will cause all the above mentioned dumps to be created.
10425 \begin_layout Standard
10426 \begin_inset VSpace bigskip
10432 \begin_layout Subsection
10433 Redirecting output on Windows Shells
10436 \begin_layout Standard
10437 By default SDCC writes it's error messages to
10438 \begin_inset Quotes sld
10442 \begin_inset Quotes srd
10446 To force all messages to
10447 \begin_inset Quotes sld
10451 \begin_inset Quotes srd
10463 \begin_layout Standard
10478 \begin_inset LatexCommand \index{-\/-use-stdout}
10483 Additionally, if you happen to have visual studio installed in your windows
10484 machine, you can use it to compile your sources using a custom build and
10491 \begin_layout Standard
10503 \begin_inset LatexCommand \index{-\/-vc}
10508 Something like this should work:
10527 \begin_layout Standard
10546 \begin_layout Standard
10558 -model-large -c $(InputPath)
10561 \begin_inset VSpace bigskip
10567 \begin_layout Section
10568 Environment variables
10569 \begin_inset LatexCommand \index{Environment variables}
10576 \begin_layout Standard
10577 SDCC recognizes the following environment variables:
10581 \labelwidthstring 00.00.0000
10585 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10591 SDCC installs a signal handler
10592 \begin_inset LatexCommand \index{signal handler}
10596 to be able to delete temporary files after an user break (^C) or an exception.
10597 If this environment variable is set, SDCC won't install the signal handler
10598 in order to be able to debug SDCC.
10602 \labelwidthstring 00.00.0000
10608 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10614 Path, where temporary files will be created.
10615 The order of the variables is the search order.
10616 In a standard *nix environment these variables are not set, and there's
10617 no need to set them.
10618 On Windows it's recommended to set one of them.
10622 \labelwidthstring 00.00.0000
10626 \begin_inset LatexCommand \index{SDCC\_HOME}
10633 \begin_inset LatexCommand \ref{sub:Install-paths}
10639 \begin_inset Quotes sld
10643 \begin_inset Quotes srd
10650 \labelwidthstring 00.00.0000
10654 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10661 \begin_inset LatexCommand \ref{sub:Search-Paths}
10667 \begin_inset Quotes sld
10671 \begin_inset Quotes srd
10678 \labelwidthstring 00.00.0000
10682 \begin_inset LatexCommand \index{SDCC\_LIB}
10689 \begin_inset LatexCommand \ref{sub:Search-Paths}
10695 \begin_inset Quotes sld
10699 \begin_inset Quotes srd
10705 \begin_layout Standard
10706 There are some more environment variables recognized by SDCC, but these
10707 are solely used for debugging purposes.
10708 They can change or disappear very quickly, and will never be documented.
10709 \begin_inset VSpace bigskip
10715 \begin_layout Section
10716 Storage Class Language Extensions
10719 \begin_layout Subsection
10720 MCS51/DS390 Storage Class
10721 \begin_inset LatexCommand \index{Storage class}
10725 Language Extensions
10728 \begin_layout Standard
10729 In addition to the ANSI storage classes SDCC allows the following MCS51
10730 specific storage classes:
10733 \begin_layout Subsubsection
10735 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10740 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10745 \begin_inset LatexCommand \index{near (storage class)}
10750 \begin_inset LatexCommand \index{\_\_near (storage class)}
10757 \begin_layout Standard
10762 storage class for the Small Memory model (
10770 or the more ANSI-C compliant forms
10778 can be used synonymously).
10779 Variables declared with this storage class will be allocated in the directly
10780 addressable portion of the internal RAM of a 8051, e.g.:
10783 \begin_layout Verse
10786 __data unsigned char test_data;
10789 \begin_layout Standard
10790 Writing 0x01 to this variable generates the assembly code:
10793 \begin_layout Verse
10796 75*00 01\InsetSpace ~
10804 \begin_layout Subsubsection
10806 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10811 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10816 \begin_inset LatexCommand \index{far (storage class)}
10821 \begin_inset LatexCommand \index{\_\_far (storage class)}
10828 \begin_layout Standard
10829 Variables declared with this storage class will be placed in the external
10835 storage class for the Large Memory model, e.g.:
10838 \begin_layout Verse
10841 __xdata unsigned char test_xdata;
10844 \begin_layout Standard
10845 Writing 0x01 to this variable generates the assembly code:
10848 \begin_layout Verse
10851 90s00r00\InsetSpace ~
10882 \begin_layout Subsubsection
10884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10889 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10896 \begin_layout Standard
10897 Variables declared with this storage class will be allocated into the indirectly
10898 addressable portion of the internal ram of a 8051, e.g.:
10901 \begin_layout Verse
10904 __idata unsigned char test_idata;
10907 \begin_layout Standard
10908 Writing 0x01 to this variable generates the assembly code:
10911 \begin_layout Verse
10938 \begin_layout Standard
10939 Please note, the first 128 byte of idata physically access the same RAM
10940 as the data memory.
10941 The original 8051 had 128 byte idata memory, nowadays most devices have
10942 256 byte idata memory.
10944 \begin_inset LatexCommand \index{stack}
10948 is located in idata memory.
10951 \begin_layout Subsubsection
10953 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10958 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10965 \begin_layout Standard
10966 Paged xdata access is just as straightforward as using the other addressing
10968 It is typically located at the start of xdata and has a maximum size of
10970 The following example writes 0x01 to the pdata variable.
10971 Please note, pdata access physically accesses xdata memory.
10972 The high byte of the address is determined by port P2
10973 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10977 (or in case of some 8051 variants by a separate Special Function Register,
10979 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10988 storage class for the Medium Memory model, e.g.:
10991 \begin_layout Verse
10994 __pdata unsigned char test_pdata;
10997 \begin_layout Standard
10998 Writing 0x01 to this variable generates the assembly code:
11001 \begin_layout Verse
11010 mov r0,#_test_pdata
11032 \begin_layout Standard
11037 \begin_layout Standard
11047 \begin_inset LatexCommand \index{-\/-xstack}
11051 option is used the pdata memory area is followed by the xstack memory area
11052 and the sum of their sizes is limited to 256 bytes.
11055 \begin_layout Subsubsection
11057 \begin_inset LatexCommand \index{code}
11062 \begin_inset LatexCommand \index{\_\_code}
11069 \begin_layout Standard
11070 'Variables' declared with this storage class will be placed in the code
11074 \begin_layout Verse
11077 __code unsigned char test_code;
11080 \begin_layout Standard
11081 Read access to this variable generates the assembly code:
11084 \begin_layout Verse
11087 90s00r6F\InsetSpace ~
11090 mov dptr,#_test_code
11115 \begin_layout Standard
11120 indexed arrays of characters in code memory can be accessed efficiently:
11123 \begin_layout Verse
11126 __code char test_array[] = {'c','h','e','a','p'};
11129 \begin_layout Standard
11130 Read access to this array using an 8-bit unsigned index generates the assembly
11134 \begin_layout Verse
11146 \begin_layout Verse
11149 90s00r41\InsetSpace ~
11152 mov dptr,#_test_array
11155 \begin_layout Verse
11170 \begin_layout Subsubsection
11172 \begin_inset LatexCommand \index{bit}
11177 \begin_inset LatexCommand \index{\_\_bit}
11184 \begin_layout Standard
11185 This is a data-type and a storage class specifier.
11186 When a variable is declared as a bit, it is allocated into the bit addressable
11187 memory of 8051, e.g.:
11190 \begin_layout Verse
11196 \begin_layout Standard
11197 Writing 1 to this variable generates the assembly code:
11200 \begin_layout Verse
11214 \begin_layout Standard
11215 The bit addressable memory consists of 128 bits which are located from 0x20
11216 to 0x2f in data memory.
11219 Apart from this 8051 specific storage class most architectures support
11221 \begin_inset LatexCommand \index{bitfields}
11229 \begin_layout Standard
11230 Not really meant as examples, but nevertheless showing what bitfields are
11231 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11237 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11238 signed modifier are implemented as unsigned.
11241 \begin_layout Subsubsection
11243 \begin_inset LatexCommand \index{sfr}
11248 \begin_inset LatexCommand \index{\_\_sfr}
11253 \begin_inset LatexCommand \index{sfr16}
11258 \begin_inset LatexCommand \index{\_\_sfr16}
11263 \begin_inset LatexCommand \index{sfr32}
11268 \begin_inset LatexCommand \index{\_\_sfr32}
11273 \begin_inset LatexCommand \index{\_\_sbit}
11278 \begin_inset LatexCommand \index{sbit}
11285 \begin_layout Standard
11286 Like the bit keyword,
11288 sfr / sfr16 / sfr32 / sbit
11290 signify both a data-type and storage class, they are used to describe the
11311 variables of a 8051, eg:
11314 \begin_layout Verse
11318 \begin_inset LatexCommand \index{at}
11323 \begin_inset LatexCommand \index{\_\_at}
11327 (0x80) P0;\InsetSpace ~
11328 /* special function register P0 at location 0x80 */
11333 special function register combination for timer 0
11337 with the high byte at
11338 location 0x8C and the low byte at location 0x8A */
11340 __sfr16 __at (0x8C8A)
11346 \begin_inset LatexCommand \index{at}
11351 \begin_inset LatexCommand \index{\_\_at}
11355 (0xd7) CY;\InsetSpace ~
11357 \begin_inset LatexCommand \index{Flags}
11362 \begin_inset LatexCommand \index{Carry flag}
11369 \begin_layout Standard
11370 Special function registers which are located on an address dividable by
11371 8 are bit-addressable, an
11375 addresses a specific bit within these sfr.
11377 16 Bit and 32 bit special function
11378 register combinations which require a certain access order are better not
11388 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11389 this is not guaranteed.
11394 \begin_layout Standard
11395 Please note, if you use a header file which was written for another compiler
11396 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11402 Specifically the syntax
11405 sfr P0 = 0x80;\InsetSpace ~
11412 by SDCC to an assignment of 0x80 to a variable called P0
11415 \begin_inset Marginal
11418 \begin_layout Standard
11430 Nevertheless it is possible to write header files
11431 \begin_inset LatexCommand \index{Header files}
11436 \begin_inset LatexCommand \index{Include files}
11440 which can be shared among different compilers (see section
11441 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11449 \begin_layout Subsubsection
11451 \begin_inset LatexCommand \index{Pointer}
11455 to MCS51/DS390 specific memory spaces
11458 \begin_layout Standard
11459 SDCC allows (via language extensions) pointers to explicitly point to any
11460 of the memory spaces
11461 \begin_inset LatexCommand \index{Memory model}
11466 In addition to the explicit pointers, the compiler uses (by default) generic
11467 pointers which can be used to point to any of the memory spaces.
11472 declaration examples:
11475 \begin_layout Verse
11478 /* pointer physically in internal ram pointing to object in external ram
11481 __xdata unsigned char * __data p;
11485 /* pointer physically in external ram
11486 pointing to object in internal ram */
11488 __data unsigned char * __xdata p;
11493 pointer physically in code rom pointing to data in xdata space */
11496 unsigned char * __code p;
11500 /* pointer physically in code space pointing to
11501 data in code space */
11503 __code unsigned char * __code p;
11508 physically located in xdata space */
11510 unsigned char * __xdata p;
11515 pointer physically located in default memory space */
11522 the following is a function pointer
11523 \begin_inset LatexCommand \index{function pointer}
11527 physically located in data space */
11529 char (* __data fp)(void);
11532 \begin_layout Standard
11533 Well you get the idea.
11538 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11551 The highest order byte of the
11555 pointers contains the data space information.
11556 Assembler support routines are called whenever data is stored or retrieved
11562 These are useful for developing reusable library
11563 \begin_inset LatexCommand \index{Libraries}
11568 Explicitly specifying the pointer
11569 \begin_inset LatexCommand \index{pointer}
11573 type will generate the most efficient code.
11576 \begin_layout Subsubsection
11577 Notes on MCS51 memory
11578 \begin_inset LatexCommand \index{MCS51 memory}
11585 \begin_layout Standard
11586 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11587 RAM memory which is structured as follows:
11591 - Bytes 00-1F - 32 bytes to hold
11592 up to 4 banks of the registers R0 to R7,
11594 - Bytes 20-2F - 16 bytes to hold
11596 \begin_inset LatexCommand \index{bit}
11602 - Bytes 30-7F - 80 bytes for general purpose use.
11607 \begin_layout Standard
11608 Additionally some members of the MCS51 family may have up to 128 bytes of
11609 additional, indirectly addressable, internal RAM memory (
11614 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11619 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11624 Furthermore, some chips may have some built in external memory (
11629 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11634 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11638 ) which should not be confused with the internal, directly addressable RAM
11644 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11649 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11654 Sometimes this built in
11658 memory has to be activated before using it (you can probably find this
11659 information on the datasheet of the microcontroller your are using, see
11661 \begin_inset LatexCommand \ref{sub:Startup-Code}
11669 \begin_layout Standard
11670 Normally SDCC will only use the first bank
11671 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11675 of registers (register bank 0), but it is possible to specify that other
11676 banks of registers (keyword
11683 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11688 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11694 ) should be used in interrupt
11695 \begin_inset LatexCommand \index{interrupt}
11700 \begin_inset LatexCommand \index{\_\_interrupt}
11705 By default, the compiler will place the stack after the last byte of allocated
11706 memory for variables.
11707 For example, if the first 2 banks of registers are used, and only four
11712 variables, it will position the base of the internal stack at address 20
11714 This implies that as the stack
11715 \begin_inset LatexCommand \index{stack}
11719 grows, it will use up the remaining register banks, and the 16 bytes used
11720 by the 128 bit variables, and 80 bytes for general purpose use.
11721 If any bit variables are used, the data variables will be placed in unused
11722 register banks and after the byte holding the last bit variable.
11723 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11728 variables will be placed starting from address 0x10 to 0x20 and continue
11734 \begin_layout Standard
11744 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11748 to specify the start address of the
11756 \begin_layout Standard
11766 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11770 to specify the size of the total internal RAM (
11784 \begin_layout Standard
11785 By default the 8051 linker will place the stack after the last byte of (i)data
11791 \begin_layout Standard
11801 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
11805 allows you to specify the start of the stack, i.e.
11806 you could start it after any data in the general purpose area.
11807 If your microcontroller has additional indirectly addressable internal
11812 ) you can place the stack on it.
11813 You may also need to use -
11817 \begin_layout Standard
11827 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
11831 to set the start address of the external RAM (
11839 \begin_layout Standard
11849 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11853 to specify its size.
11854 Same goes for the code memory, using -
11858 \begin_layout Standard
11868 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11876 \begin_layout Standard
11886 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11891 If in doubt, don't specify any options and see if the resulting memory
11892 layout is appropriate, then you can adjust it.
11895 \begin_layout Standard
11896 The linker generates two files with memory allocation information.
11897 The first, with extension .map
11898 \begin_inset LatexCommand \index{<file>.map}
11902 shows all the variables and segments.
11903 The second with extension .mem
11904 \begin_inset LatexCommand \index{<file>.mem}
11908 shows the final memory layout.
11909 The linker will complain either if memory segments overlap, there is not
11910 enough memory, or there is not enough space for stack.
11911 If you get any linking warnings and/or errors related to stack or segments
11912 allocation, take a look at either the .map or .mem files to find out what
11914 The .mem file may even suggest a solution to the problem.
11915 \begin_inset VSpace bigskip
11921 \begin_layout Subsection
11922 Z80/Z180 Storage Class
11923 \begin_inset LatexCommand \index{Z80!Storage class}
11927 Language Extensions
11930 \begin_layout Subsubsection
11932 \begin_inset LatexCommand \index{sfr}
11937 \begin_inset LatexCommand \index{\_\_sfr}
11941 (in/out to 8-bit addresses)
11944 \begin_layout Standard
11946 \begin_inset LatexCommand \index{Z80}
11950 family has separate address spaces for memory and
11960 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11965 \begin_inset LatexCommand \index{Z80!I/O memory}
11970 \begin_inset LatexCommand \index{Z180!I/O memory}
11974 is accessed with special instructions, e.g.:
11977 \begin_layout Verse
11980 sfr at 0x78 IoPort;\InsetSpace ~
11982 /* define a var in I/O space at 78h called IoPort */
11986 \begin_layout Standard
11987 Writing 0x01 to this variable generates the assembly code:
11990 \begin_layout Verse
12010 \begin_layout Subsubsection
12012 \begin_inset LatexCommand \index{sfr}
12017 \begin_inset LatexCommand \index{\_\_sfr}
12021 (in/out to 16-bit addresses)
12024 \begin_layout Standard
12029 is used to support 16 bit addresses in I/O memory e.g.:
12032 \begin_layout Verse
12036 \begin_inset LatexCommand \index{at}
12041 \begin_inset LatexCommand \index{\_\_at}
12048 \begin_layout Standard
12049 Writing 0x01 to this variable generates the assembly code:
12052 \begin_layout Verse
12055 01 23 01\InsetSpace ~
12077 \begin_layout Subsubsection
12079 \begin_inset LatexCommand \index{sfr}
12084 \begin_inset LatexCommand \index{\_\_sfr}
12088 (in0/out0 to 8 bit addresses on Z180
12089 \begin_inset LatexCommand \index{Z180}
12094 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12101 \begin_layout Standard
12102 The compiler option -
12106 \begin_layout Standard
12116 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12120 =180 (80) and a compiler #pragma\InsetSpace ~
12122 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12126 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12136 If you include the file z180.h this will be set automatically.
12137 \begin_inset VSpace bigskip
12143 \begin_layout Subsection
12145 \begin_inset LatexCommand \index{HC08!Storage class}
12149 Language Extensions
12152 \begin_layout Subsubsection
12154 \begin_inset LatexCommand \index{data (hc08 storage class)}
12159 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12166 \begin_layout Standard
12167 The data storage class declares a variable that resides in the first 256
12168 bytes of memory (the direct page).
12170 \begin_inset LatexCommand \index{HC08}
12174 is most efficient at accessing variables (especially pointers) stored here.
12177 \begin_layout Subsubsection
12179 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12184 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12191 \begin_layout Standard
12192 The xdata storage class declares a variable that can reside anywhere in
12194 This is the default if no storage class is specified.
12196 \begin_inset VSpace bigskip
12202 \begin_layout Section
12203 Absolute Addressing
12204 \begin_inset LatexCommand \index{Absolute addressing}
12211 \begin_layout Standard
12212 Data items can be assigned an absolute address with the
12215 \begin_inset LatexCommand \index{at}
12220 \begin_inset LatexCommand \index{\_\_at}
12226 keyword, in addition to a storage class, e.g.:
12229 \begin_layout Verse
12233 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12238 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12243 \begin_inset LatexCommand \index{at}
12248 \begin_inset LatexCommand \index{\_\_at}
12252 0x7ffe unsigned int chksum;
12255 \begin_layout Standard
12256 or, better conforming to ISO/IEC 9899 C:
12259 \begin_layout Verse
12262 __xdata __at (0x7ffe) unsigned int chksum;
12265 \begin_layout Standard
12266 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12267 of the external ram.
12272 reserve any space for variables declared in this way
12273 \begin_inset Marginal
12276 \begin_layout Standard
12285 (they are implemented with an equate in the assembler).
12286 Thus it is left to the programmer to make sure there are no overlaps with
12287 other variables that are declared without the absolute address.
12288 The assembler listing file (.lst
12289 \begin_inset LatexCommand \index{<file>.lst}
12293 ) and the linker output files (.rst
12294 \begin_inset LatexCommand \index{<file>.rst}
12299 \begin_inset LatexCommand \index{<file>.map}
12303 ) are good places to look for such overlaps.
12304 Variables with an absolute address are
12307 \begin_inset Marginal
12310 \begin_layout Standard
12322 \begin_inset LatexCommand \index{Variable initialization}
12329 \begin_layout Standard
12330 In case of memory mapped I/O devices the keyword
12334 has to be used to tell the compiler that accesses might not be removed:
12337 \begin_layout Verse
12341 \begin_inset LatexCommand \index{volatile}
12346 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12351 \begin_inset LatexCommand \index{at}
12355 (0x8000) unsigned char PORTA_8255;
12358 \begin_layout Standard
12359 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12364 \begin_inset LatexCommand \index{Aligned array}
12371 starts at a block (256 byte) boundary
12372 \begin_inset LatexCommand \index{block boundary}
12377 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12383 Absolute addresses can be specified for variables in all
12384 storage classes, e.g.:
12387 \begin_layout Verse
12391 \begin_inset LatexCommand \index{bit}
12396 \begin_inset LatexCommand \index{at}
12403 \begin_layout Standard
12404 The above example will allocate the variable at offset 0x02 in the bit-addressab
12406 There is no real advantage to assigning absolute addresses to variables
12407 in this manner, unless you want strict control over all the variables allocated.
12408 One possible use would be to write hardware portable code.
12409 For example, if you have a routine that uses one or more of the microcontroller
12410 I/O pins, and such pins are different for two different hardwares, you
12411 can declare the I/O pins in your routine using:
12414 \begin_layout Verse
12418 \begin_inset LatexCommand \index{volatile}
12422 __bit MOSI;\InsetSpace ~
12426 /* master out, slave in */
12428 extern volatile __bit MISO;\InsetSpace ~
12435 extern volatile __bit MCLK;\InsetSpace ~
12444 Output of a byte on a 3-wire serial bus.
12449 If needed adapt polarity of clock,
12450 polarity of data and bit order
12455 unsigned char spi_io(unsigned char out_byte)
12480 MOSI = out_byte & 0x80;
12511 /* _asm nop _endasm; */\InsetSpace ~
12519 /* for slow peripherals */
12571 \begin_layout Standard
12572 Then, someplace in the code for the first hardware you would use
12575 \begin_layout Verse
12579 \begin_inset LatexCommand \index{at}
12584 \begin_inset LatexCommand \index{\_\_at}
12588 (0x80) MOSI;\InsetSpace ~
12592 /* I/O port 0, bit 0 */
12594 __bit __at (0x81) MISO;\InsetSpace ~
12601 __bit __at (0x82) MCLK;\InsetSpace ~
12605 /* I/O port 0, bit 2 */
12608 \begin_layout Standard
12609 Similarly, for the second hardware you would use
12612 \begin_layout Verse
12615 __bit __at (0x83) MOSI;\InsetSpace ~
12619 /* I/O port 0, bit 3 */
12621 __bit __at (0x91) MISO;\InsetSpace ~
12626 I/O port 1, bit 1 */
12629 \begin_inset LatexCommand \index{bit}
12633 __at (0x92) MCLK;\InsetSpace ~
12637 /* I/O port 1, bit 2 */
12640 \begin_layout Standard
12641 and you can use the same hardware dependent routine without changes, as
12642 for example in a library.
12643 This is somehow similar to sbit, but only one absolute address has to be
12644 specified in the whole project.
12645 \begin_inset VSpace bigskip
12651 \begin_layout Section
12653 \begin_inset LatexCommand \index{Parameters}
12658 \begin_inset LatexCommand \index{function parameter}
12663 \begin_inset LatexCommand \index{local variables}
12668 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12675 \begin_layout Standard
12676 Automatic (local) variables and parameters to functions can either be placed
12677 on the stack or in data-space.
12678 The default action of the compiler is to place these variables in the internal
12679 RAM (for small model) or external RAM (for large model).
12680 This in fact makes them similar to
12683 \begin_inset LatexCommand \index{static}
12689 so by default functions are non-reentrant
12690 \begin_inset LatexCommand \index{reentrant}
12699 They can be placed on the stack
12700 \begin_inset LatexCommand \index{stack}
12710 \begin_layout Standard
12720 \begin_inset LatexCommand \index{-\/-stack-auto}
12728 #pragma\InsetSpace ~
12732 \begin_inset LatexCommand \index{\#pragma stackauto}
12739 \begin_inset LatexCommand \index{reentrant}
12745 keyword in the function declaration, e.g.:
12748 \begin_layout Verse
12751 unsigned char foo(char i) __reentrant
12765 \begin_layout Standard
12766 Since stack space on 8051 is limited, the
12776 \begin_layout Standard
12787 option should be used sparingly.
12788 Note that the reentrant keyword just means that the parameters & local
12789 variables will be allocated to the stack, it
12793 mean that the function is register bank
12794 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12803 \begin_inset LatexCommand \index{local variables}
12807 can be assigned storage classes and absolute
12808 \begin_inset LatexCommand \index{Absolute addressing}
12815 \begin_layout Verse
12818 unsigned char foo()
12826 __xdata unsigned char i;
12839 \begin_inset LatexCommand \index{at}
12843 (0x31) unsigned char j;
12855 \begin_layout Standard
12856 In the above example the variable
12860 will be allocated in the external ram,
12864 in bit addressable space and
12875 \begin_layout Standard
12886 or when a function is declared as
12890 this should only be done for static variables.
12893 \begin_layout Standard
12895 \begin_inset LatexCommand \index{function parameter}
12899 however are not allowed any storage class
12900 \begin_inset LatexCommand \index{Storage class}
12904 , (storage classes for parameters will be ignored), their allocation is
12905 governed by the memory model in use, and the reentrancy options.
12908 \begin_layout Standard
12909 It is however allowed to use bit parameters in reentrant functions and also
12910 non-static local bit variables are supported.
12911 Efficient use is limited to 8 semi-bitregisters in bit space.
12912 They are pushed and popped to stack
12913 \begin_inset LatexCommand \index{stack}
12917 as a single byte just like the normal registers.
12920 \begin_layout Section
12922 \begin_inset LatexCommand \label{sub:Overlaying}
12927 \begin_inset LatexCommand \index{Overlaying}
12934 \begin_layout Standard
12936 \begin_inset LatexCommand \index{reentrant}
12940 functions SDCC will try to reduce internal ram space usage by overlaying
12941 parameters and local variables of a function (if possible).
12942 Parameters and local variables
12943 \begin_inset LatexCommand \index{local variables}
12947 of a function will be allocated to an overlayable segment if the function
12950 no other function calls and the function is non-reentrant and the memory
12952 \begin_inset LatexCommand \index{Memory model}
12959 If an explicit storage class
12960 \begin_inset LatexCommand \index{Storage class}
12964 is specified for a local variable, it will NOT be overlayed.
12967 \begin_layout Standard
12968 Note that the compiler (not the linkage editor) makes the decision for overlayin
12970 Functions that are called from an interrupt service routine
12971 \begin_inset Marginal
12974 \begin_layout Standard
12982 should be preceded by a #pragma\InsetSpace ~
12984 \begin_inset LatexCommand \index{\#pragma nooverlay}
12988 if they are not reentrant.
12991 \begin_layout Standard
12992 Also note that the compiler does not do any processing of inline assembler
12993 code, so the compiler might incorrectly assign local variables and parameters
12994 of a function into the overlay segment if the inline assembler code calls
12995 other c-functions that might use the overlay.
12996 In that case the #pragma\InsetSpace ~
12997 nooverlay should be used.
13000 \begin_layout Standard
13001 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13003 \begin_inset LatexCommand \index{Multiplication}
13008 \begin_inset LatexCommand \index{Division}
13012 will NOT be overlayed since these are implemented using external functions,
13016 \begin_layout Verse
13022 \begin_inset LatexCommand \index{\#pragma nooverlay}
13028 void set_error(unsigned char errcd)
13045 some_isr () __interrupt
13046 \begin_inset LatexCommand \index{interrupt}
13076 \begin_layout Standard
13077 In the above example the parameter
13085 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13087 not present, this could cause unpredictable runtime behavior when called
13088 from an interrupt service routine.
13089 The #pragma\InsetSpace ~
13090 nooverlay ensures that the parameters and local variables for
13091 the function are NOT overlayed.
13092 \begin_inset VSpace bigskip
13098 \begin_layout Section
13099 Interrupt Service Routines
13100 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13107 \begin_layout Subsection
13108 General Information
13111 \begin_layout Standard
13124 outines to be coded in C, with some extended keywords.
13127 \begin_layout Verse
13130 void timer_isr (void) __interrupt (1) __using (1)
13144 \begin_layout Standard
13145 The optional number following the
13148 \begin_inset LatexCommand \index{interrupt}
13153 \begin_inset LatexCommand \index{\_\_interrupt}
13159 keyword is the interrupt number this routine will service.
13160 When present, the compiler will insert a call to this routine in the interrupt
13162 \begin_inset LatexCommand \index{interrupt vector table}
13166 for the interrupt number specified.
13167 If you have multiple source files in your project, interrupt service routines
13168 can be present in any of them, but a prototype of the isr MUST be present
13169 or included in the file that contains the function
13174 The optional (8051 specific) keyword
13177 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13182 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13188 can be used to tell the compiler to use the specified register bank when
13189 generating code for this function.
13192 Interrupt service routines open the door for some very interesting bugs:
13195 \begin_layout Subsubsection
13196 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13200 Common interrupt pitfall: variable not declared
13205 \begin_layout Standard
13206 If an interrupt service routine changes variables which are accessed by
13207 other functions these variables have to be declared
13212 \begin_inset LatexCommand \index{volatile}
13218 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13225 \begin_layout Subsubsection
13226 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13230 Common interrupt pitfall:
13235 \begin_layout Standard
13236 If the access to these variables is not
13239 \begin_inset LatexCommand \index{atomic}
13246 the processor needs more than one instruction for the access and could
13247 be interrupted while accessing the variable) the interrupt must be disabled
13248 during the access to avoid inconsistent data.
13251 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13252 and should be protected by disabling interrupts.
13253 You're not automatically on the safe side if you use 8 bit variables though.
13254 We need an example here: f.e.
13255 on the 8051 the harmless looking
13256 \begin_inset Quotes srd
13266 \begin_inset Quotes sld
13275 \begin_inset Quotes srd
13285 \begin_inset Quotes sld
13288 from within an interrupt routine might get lost if the interrupt occurs
13291 \begin_inset Quotes sld
13296 counter\InsetSpace ~
13301 \begin_inset Quotes srd
13304 is not atomic on the 8051 even if
13308 is located in data memory.
13310 Bugs like these are hard to reproduce and can
13311 cause a lot of trouble.
13315 \begin_layout Subsubsection
13316 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13320 Common interrupt pitfall:
13325 \begin_layout Standard
13326 The return address and the registers used in the interrupt service routine
13327 are saved on the stack
13328 \begin_inset LatexCommand \index{stack}
13332 so there must be sufficient stack space.
13333 If there isn't variables or registers (or even the return address itself)
13340 \begin_inset LatexCommand \index{stack overflow}
13344 is most likely to happen if the interrupt occurs during the
13345 \begin_inset Quotes sld
13349 \begin_inset Quotes srd
13352 subroutine when the stack is already in use for f.e.
13353 many return addresses.
13356 \begin_layout Subsubsection
13357 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13361 Common interrupt pitfall:
13363 use of non-reentrant functions
13366 \begin_layout Standard
13367 A special note here, int (16 bit) and long (32 bit) integer division
13368 \begin_inset LatexCommand \index{Division}
13373 \begin_inset LatexCommand \index{Multiplication}
13378 \begin_inset LatexCommand \index{Modulus}
13383 \begin_inset LatexCommand \index{Floating point support}
13387 operations are implemented using external support routines.
13388 If an interrupt service routine needs to do any of these operations then
13389 the support routines (as mentioned in a following section) will have to
13390 be recompiled using the
13396 \begin_layout Standard
13406 \begin_inset LatexCommand \index{-\/-stack-auto}
13412 option and the source file will need to be compiled using the
13418 \begin_layout Standard
13430 \begin_inset LatexCommand \index{-\/-int-long-reent}
13437 Note, the type promotion
13438 \begin_inset LatexCommand \index{type promotion}
13442 required by ANSI C can cause 16 bit routines to be used
13443 \begin_inset Marginal
13446 \begin_layout Standard
13455 without the programmer being aware of it.
13459 (unsigned char)(tail-1)
13461 within the if clause in section
13462 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13469 \begin_layout Standard
13470 Calling other functions from an interrupt service routine is not recommended,
13471 avoid it if possible.
13472 Note that when some function is called from an interrupt service routine
13473 it should be preceded by a #pragma\InsetSpace ~
13475 \begin_inset LatexCommand \index{\#pragma nooverlay}
13479 if it is not reentrant.
13480 Furthermore nonreentrant functions should not be called from the main program
13481 while the interrupt service routine might be active.
13482 They also must not be called from low priority interrupt service routines
13483 while a high priority interrupt service routine might be active.
13484 You could use semaphores or make the function
13488 if all parameters are passed in registers.
13491 \begin_inset LatexCommand \ref{sub:Overlaying}
13496 about Overlaying and section
13497 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13502 about Functions using private register banks.
13503 \begin_inset VSpace bigskip
13509 \begin_layout Subsection
13510 MCS51/DS390 Interrupt Service Routines
13513 \begin_layout Standard
13515 \begin_inset LatexCommand \index{interrupt}
13519 numbers and the corresponding address & descriptions for the Standard 8051/8052
13521 SDCC will automatically adjust the
13522 \begin_inset LatexCommand \index{interrupt vector table}
13526 to the maximum interrupt number specified.
13531 \begin_layout Standard
13533 \begin_inset Tabular
13534 <lyxtabular version="3" rows="9" columns="3">
13536 <column alignment="center" valignment="top" leftline="true" width="0in">
13537 <column alignment="left" valignment="top" leftline="true" width="0in">
13538 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13539 <row topline="true" bottomline="true">
13540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13543 \begin_layout Standard
13549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13552 \begin_layout Standard
13558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13561 \begin_layout Standard
13568 <row topline="true">
13569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13572 \begin_layout Standard
13578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13581 \begin_layout Standard
13587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13590 \begin_layout Standard
13597 <row topline="true">
13598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13601 \begin_layout Standard
13607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13610 \begin_layout Standard
13616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13619 \begin_layout Standard
13626 <row topline="true">
13627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13630 \begin_layout Standard
13636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13639 \begin_layout Standard
13645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13648 \begin_layout Standard
13655 <row topline="true">
13656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13659 \begin_layout Standard
13665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13668 \begin_layout Standard
13674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13677 \begin_layout Standard
13684 <row topline="true">
13685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13688 \begin_layout Standard
13694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13697 \begin_layout Standard
13703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13706 \begin_layout Standard
13713 <row topline="true">
13714 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13717 \begin_layout Standard
13723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13726 \begin_layout Standard
13732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13735 \begin_layout Standard
13742 <row topline="true">
13743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13746 \begin_layout Standard
13752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13755 \begin_layout Standard
13761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13764 \begin_layout Standard
13771 <row topline="true" bottomline="true">
13772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13775 \begin_layout Standard
13781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13784 \begin_layout Standard
13790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13793 \begin_layout Standard
13809 \begin_layout Standard
13810 If the interrupt service routine is defined without
13813 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13818 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13824 a register bank or with register bank 0 (
13828 0), the compiler will save the registers used by itself on the stack upon
13829 entry and restore them at exit, however if such an interrupt service routine
13830 calls another function then the entire register bank will be saved on the
13832 This scheme may be advantageous for small interrupt service routines which
13833 have low register usage.
13836 \begin_layout Standard
13837 If the interrupt service routine is defined to be using a specific register
13842 & psw are saved and restored, if such an interrupt service routine calls
13843 another function (using another register bank) then the entire register
13844 bank of the called function will be saved on the stack
13845 \begin_inset LatexCommand \index{stack}
13850 This scheme is recommended for larger interrupt service routines.
13851 \begin_inset VSpace bigskip
13857 \begin_layout Subsection
13859 \begin_inset LatexCommand \index{HC08}
13863 Interrupt Service Routines
13866 \begin_layout Standard
13867 Since the number of interrupts
13868 \begin_inset LatexCommand \index{HC08!interrupt}
13872 available is chip specific and the interrupt vector table always ends at
13873 the last byte of memory, the interrupt numbers corresponds to the interrupt
13874 vectors in reverse order of address.
13875 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
13876 2 will use the interrupt vector at 0xfffa, and so on.
13877 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
13878 this way; instead see section
13879 \begin_inset LatexCommand \ref{sub:Startup-Code}
13883 for details on customizing startup.
13884 \begin_inset VSpace bigskip
13890 \begin_layout Subsection
13891 Z80 Interrupt Service Routines
13894 \begin_layout Standard
13896 \begin_inset LatexCommand \index{Z80}
13900 uses several different methods for determining the correct interrupt
13901 \begin_inset LatexCommand \index{Z80!interrupt}
13905 vector depending on the hardware implementation.
13906 Therefore, SDCC ignores the optional interrupt number and does not attempt
13907 to generate an interrupt vector table.
13910 \begin_layout Standard
13911 By default, SDCC generates code for a maskable interrupt, which uses a RETI
13912 instruction to return from the interrupt.
13913 To write an interrupt handler for the non-maskable interrupt, which needs
13914 a RETN instruction instead, add the
13921 \begin_layout Verse
13924 void nmi_isr (void) critical interrupt
13938 \begin_layout Standard
13939 However if you need to create a non-interruptable interrupt service routine
13940 you would also require the
13945 To distinguish between this and an nmi_isr you must provide an interrupt
13947 \begin_inset VSpace bigskip
13953 \begin_layout Section
13954 Enabling and Disabling Interrupts
13957 \begin_layout Subsection
13958 Critical Functions and Critical Statements
13961 \begin_layout Standard
13962 A special keyword may be associated with a block or a function declaring
13968 SDCC will generate code to disable all interrupts
13969 \begin_inset LatexCommand \index{interrupt}
13973 upon entry to a critical function and restore the interrupt enable to the
13974 previous state before returning.
13975 Nesting critical functions will need one additional byte on the stack
13976 \begin_inset LatexCommand \index{stack}
13983 \begin_layout Verse
13986 int foo () __critical
13987 \begin_inset LatexCommand \index{critical}
13992 \begin_inset LatexCommand \index{\_\_critical}
14017 \begin_layout Standard
14018 The critical attribute maybe used with other attributes like
14028 may also be used to disable interrupts more locally:
14031 \begin_layout Verse
14037 \begin_layout Standard
14038 More than one statement could have been included in the block.
14041 \begin_layout Subsection
14042 Enabling and Disabling Interrupts directly
14045 \begin_layout Standard
14047 \begin_inset LatexCommand \index{interrupt}
14051 can also be disabled and enabled directly (8051):
14054 \begin_layout Verse
14057 EA = 0;\InsetSpace ~
14083 \begin_layout Verse
14119 \begin_layout Verse
14122 EA = 1;\InsetSpace ~
14151 \begin_layout Verse
14190 \begin_layout Standard
14191 On other architectures which have seperate opcodes for enabling and disabling
14192 interrupts you might want to make use of defines with inline assembly
14193 \begin_inset LatexCommand \index{Assembler routines}
14198 \begin_inset LatexCommand \index{HC08!interrupt}
14205 \begin_layout Verse
14209 \begin_inset LatexCommand \index{\_asm}
14218 \begin_inset LatexCommand \index{\_endasm}
14225 \begin_layout Verse
14228 #define SEI _asm\InsetSpace ~
14235 \begin_layout Verse
14241 \begin_layout Standard
14242 Note: it is sometimes sufficient to disable only a specific interrupt source
14244 a timer or serial interrupt by manipulating an
14247 \begin_inset LatexCommand \index{interrupt mask}
14257 \begin_layout Standard
14258 Usually the time during which interrupts are disabled should be kept as
14260 This minimizes both
14265 \begin_inset LatexCommand \index{interrupt latency}
14269 (the time between the occurrence of the interrupt and the execution of
14270 the first code in the interrupt routine) and
14275 \begin_inset LatexCommand \index{interrupt jitter}
14279 (the difference between the shortest and the longest interrupt latency).
14280 These really are something different, f.e.
14281 a serial interrupt has to be served before its buffer overruns so it cares
14282 for the maximum interrupt latency, whereas it does not care about jitter.
14283 On a loudspeaker driven via a digital to analog converter which is fed
14284 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14285 a much smaller jitter will be very audible.
14288 \begin_layout Standard
14289 You can reenable interrupts within an interrupt routine and on some architecture
14290 s you can make use of two (or more) levels of
14292 interrupt priorities
14295 \begin_inset LatexCommand \index{interrupt priority}
14300 On some architectures which don't support interrupt priorities these can
14301 be implemented by manipulating the interrupt mask and reenabling interrupts
14302 within the interrupt routine.
14303 Check there is sufficient space on the stack
14304 \begin_inset LatexCommand \index{stack}
14308 and don't add complexity unless you have to.
14312 \begin_layout Subsection
14314 \begin_inset LatexCommand \index{semaphore}
14318 locking (mcs51/ds390)
14321 \begin_layout Standard
14322 Some architectures (mcs51/ds390) have an atomic
14323 \begin_inset LatexCommand \index{atomic}
14336 These type of instructions are typically used in preemptive multitasking
14337 systems, where a routine f.e.
14338 claims the use of a data structure ('acquires a lock
14339 \begin_inset LatexCommand \index{lock}
14343 on it'), makes some modifications and then releases the lock when the data
14344 structure is consistent again.
14345 The instruction may also be used if interrupt and non-interrupt code have
14346 to compete for a resource.
14347 With the atomic bit test and clear instruction interrupts
14348 \begin_inset LatexCommand \index{interrupt}
14352 don't have to be disabled for the locking operation.
14356 \begin_layout Standard
14357 SDCC generates this instruction if the source follows this pattern:
14360 \begin_layout Verse
14364 \begin_inset LatexCommand \index{volatile}
14368 bit resource_is_free;
14372 if (resource_is_free)
14382 resource_is_free=0;
14395 resource_is_free=1;
14402 \begin_layout Standard
14403 Note, mcs51 and ds390 support only an atomic
14404 \begin_inset LatexCommand \index{atomic}
14412 instruction (as opposed to atomic bit test and
14417 \begin_layout Section
14418 Functions using private register banks
14419 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14426 \begin_layout Standard
14427 Some architectures have support for quickly changing register sets.
14428 SDCC supports this feature with the
14431 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14436 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14442 attribute (which tells the compiler to use a register bank
14443 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14447 other than the default bank zero).
14448 It should only be applied to
14451 \begin_inset LatexCommand \index{interrupt}
14457 functions (see footnote below).
14458 This will in most circumstances make the generated ISR code more efficient
14459 since it will not have to save registers on the stack.
14462 \begin_layout Standard
14467 attribute will have no effect on the generated code for a
14471 function (but may occasionally be useful anyway
14475 \begin_layout Standard
14476 possible exception: if a function is called ONLY from 'interrupt' functions
14477 using a particular bank, it can be declared with the same 'using' attribute
14478 as the calling 'interrupt' functions.
14479 For instance, if you have several ISRs using bank one, and all of them
14480 call memcpy(), it might make sense to create a specialized version of memcpy()
14481 'using 1', since this would prevent the ISR from having to save bank zero
14482 to the stack on entry and switch to bank zero before calling the function
14491 (pending: Note, nowadays the
14495 attribute has an effect on
14499 the generated code for a
14510 \begin_layout Standard
14515 function using a non-zero bank will assume that it can trash that register
14516 bank, and will not save it.
14517 Since high-priority interrupts
14518 \begin_inset LatexCommand \index{interrupts}
14523 \begin_inset LatexCommand \index{interrupt priority}
14527 can interrupt low-priority ones on the 8051 and friends, this means that
14528 if a high-priority ISR
14532 a particular bank occurs while processing a low-priority ISR
14536 the same bank, terrible and bad things can happen.
14537 To prevent this, no single register bank should be
14541 by both a high priority and a low priority ISR.
14542 This is probably most easily done by having all high priority ISRs use
14543 one bank and all low priority ISRs use another.
14544 If you have an ISR which can change priority at runtime, you're on your
14545 own: I suggest using the default bank zero and taking the small performance
14549 \begin_layout Standard
14550 It is most efficient if your ISR calls no other functions.
14551 If your ISR must call other functions, it is most efficient if those functions
14552 use the same bank as the ISR (see note 1 below); the next best is if the
14553 called functions use bank zero.
14554 It is very inefficient to call a function using a different, non-zero bank
14557 \begin_inset VSpace bigskip
14563 \begin_layout Section
14565 \begin_inset LatexCommand \label{sub:Startup-Code}
14570 \begin_inset LatexCommand \index{Startup code}
14577 \begin_layout Subsection
14578 MCS51/DS390 Startup Code
14581 \begin_layout Standard
14582 The compiler triggers the linker to link certain initialization modules
14583 from the runtime library
14584 \begin_inset LatexCommand \index{Runtime library}
14588 called crt<something>.
14589 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14590 GSINIT5) is not linked unless the --xstack option is used.
14591 These modules are highly entangled by the use of special segments/areas,
14592 but a common layout is shown below:
14595 \begin_layout Verse
14603 \begin_layout Verse
14627 ljmp __sdcc_gsinit_startup
14630 \begin_layout Verse
14638 \begin_layout Verse
14650 .area GSINIT0 (CODE)
14652 __sdcc_gsinit_startup::
14662 mov sp,#__start__stack - 1
14665 \begin_layout Verse
14673 \begin_layout Verse
14685 .area GSINIT1 (CODE)
14687 __sdcc_init_xstack::
14689 ; Need to initialize in GSINIT1 in
14690 case the user's __sdcc_external_startup uses the xstack.
14700 mov __XPAGE,#(__start__x
14711 mov _spx,#__start__xstack
14714 \begin_layout Verse
14722 \begin_layout Verse
14734 .area GSINIT2 (CODE)
14744 lcall __sdcc_external_startup
14764 jz __sdcc_init_data
14775 __sdcc_program_startup
14780 \begin_layout Verse
14788 \begin_layout Verse
14800 .area GSINIT3 (CODE)
14853 mov r2,#((l_XINIT+255) >> 8)
14884 __XPAGE,#(s_XISEG >> 8)
14886 00001$:\InsetSpace ~
14950 00002$:\InsetSpace ~
14977 \begin_layout Verse
14985 \begin_layout Verse
14997 .area GSINIT4 (CODE)
14999 __mcs51_genRAMCLEAR::
15021 00004$:\InsetSpace ~
15035 ; _mcs51_genRAMCLEAR() end
15038 \begin_layout Verse
15046 \begin_layout Verse
15058 .area GSINIT4 (CODE)
15060 __mcs51_genXRAMCLEAR::
15111 mov __XPAGE,#(s_PSEG >> 8)
15123 00005$:\InsetSpace ~
15177 orl a,#(l_XSEG >> 8)
15220 00007$:\InsetSpace ~
15257 \begin_layout Verse
15265 \begin_layout Verse
15277 .area GSINIT5 (CODE)
15279 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15282 ; and __mcs51_genRAMCLEAR modifies _spx.
15292 mov __XPAGE,#(__start__x
15303 mov _spx,#__start__xstack
15306 \begin_layout Verse
15311 (application modules)
15314 \begin_layout Verse
15326 .area GSINIT (CODE)
15329 \begin_layout Verse
15337 \begin_layout Verse
15349 .area GSFINAL (CODE)
15359 ljmp __sdcc_program_startup
15361 ;---------------------------------
15362 -----------------------
15366 ;--------------------------------------------------
15389 __sdcc_program_startup:
15402 return from main will lock up
15415 \begin_layout Standard
15416 One of these modules (crtstart.asm) contains a call to the C routine
15418 _sdcc_external_startup()
15419 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15428 at the start of the CODE area.
15429 This routine is also in the runtime library
15430 \begin_inset LatexCommand \index{Runtime library}
15434 and returns 0 by default.
15435 If this routine returns a non-zero value, the static & global variable
15436 initialization will be skipped and the function main will be invoked.
15437 Otherwise static & global variables will be initialized before the function
15441 _sdcc_external_startup()
15443 routine to your program to override the default if you need to setup hardware
15444 or perform some other critical operation prior to static & global variable
15446 \begin_inset LatexCommand \index{Variable initialization}
15451 On some mcs51 variants xdata
15452 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15456 memory has to be explicitly enabled before it can be accessed or if the
15458 \begin_inset LatexCommand \index{watchdog}
15462 needs to be disabled, this is the place to do it.
15463 The startup code clears all internal data memory, 256 bytes by default,
15464 but from 0 to n-1 if
15470 \begin_layout Standard
15480 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15487 (recommended for Chipcon CC1010).
15490 \begin_layout Standard
15491 See also the compiler options
15497 \begin_layout Standard
15513 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15523 \begin_layout Standard
15535 \begin_inset LatexCommand \index{-\/-main-return}
15540 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15544 about MCS51-variants.
15545 \begin_inset VSpace bigskip
15551 \begin_layout Subsection
15555 \begin_layout Standard
15557 \begin_inset LatexCommand \index{HC08}
15561 startup code follows the same scheme as the MCS51 startup code.
15562 \begin_inset VSpace bigskip
15568 \begin_layout Subsection
15572 \begin_layout Standard
15574 \begin_inset LatexCommand \index{Z80}
15578 the startup code is inserted by linking with crt0.o which is generated from
15579 sdcc/device/lib/z80/crt0.s.
15580 If you need a different startup code you can use the compiler option
15589 \begin_layout Standard
15604 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15608 and provide your own crt0.o.
15610 \begin_inset VSpace bigskip
15616 \begin_layout Section
15617 Inline Assembler Code
15618 \begin_inset LatexCommand \index{Assembler routines}
15625 \begin_layout Subsection
15626 A Step by Step Introduction
15627 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15634 \begin_layout Standard
15635 Starting from a small snippet of c-code this example shows for the MCS51
15636 how to use inline assembly, access variables, a function parameter and
15637 an array in xdata memory.
15638 The example uses an MCS51 here but is easily adapted for other architectures.
15639 This is a buffer routine which should be optimized:
15642 \begin_layout Verse
15646 unsigned char __far
15647 \begin_inset LatexCommand \index{far (storage class)}
15652 \begin_inset LatexCommand \index{\_\_far (storage class)}
15657 \begin_inset LatexCommand \index{at}
15662 \begin_inset LatexCommand \index{\_\_at}
15666 (0x7f00) buf[0x100];
15667 \begin_inset LatexCommand \index{Aligned array}
15673 unsigned char head, tail;\InsetSpace ~
15691 \begin_inset LatexCommand \index{interrupt}
15743 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15755 void to_buffer( unsigned char c )
15763 if( head != (unsigned char)(tail-1)
15770 \begin_inset LatexCommand \index{promotion to signed int}
15775 \begin_inset LatexCommand \index{type promotion}
15780 \begin_inset Marginal
15783 \begin_layout Standard
15802 buf[ head++ ] = c;\InsetSpace ~
15818 /* access to a 256 byte aligned array */
15823 \begin_layout Standard
15824 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
15825 then a corresponding buffer.asm file is generated.
15826 We define a new function
15830 in file buffer.c in which we cut and paste the generated code, removing
15831 unwanted comments and some ':'.
15833 \begin_inset Quotes sld
15837 \begin_inset Quotes srd
15841 \begin_inset Quotes sld
15845 \begin_inset Quotes srd
15848 to the beginning and the end of the function body:
15851 \begin_layout Verse
15855 /* With a cut and paste from the .asm file, we have something to start with.
15861 function is not yet OK! (registers aren't saved) */
15863 void to_buffer_asm(
15873 \begin_inset LatexCommand \index{\_asm}
15878 \begin_inset LatexCommand \index{\_\_asm}
15892 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
15898 \begin_inset LatexCommand \index{promotion to signed int}
15903 \begin_inset LatexCommand \index{type promotion}
15956 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
15957 \begin_inset LatexCommand \index{Aligned array}
16023 \begin_inset LatexCommand \index{\_endasm}
16028 \begin_inset LatexCommand \index{\_\_endasm}
16037 \begin_layout Standard
16038 The new file buffer.c should compile with only one warning about the unreferenced
16039 function argument 'c'.
16040 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16041 (1) and finally have:
16044 \begin_layout Verse
16048 unsigned char __far __at(0x7f00) buf[0x100];
16050 unsigned char head, tail;
16061 void to_buffer( unsigned char c )
16070 head != (unsigned char)(tail-1) )
16099 c; // to avoid warning: unreferenced function argument
16106 \begin_inset LatexCommand \index{\_asm}
16111 \begin_inset LatexCommand \index{\_\_asm}
16125 ; save used registers here.
16136 ; If we were still using r2,r3 we would have to push them here.
16139 ; if( head != (unsigned char)(tail-1) )
16183 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16219 a,dpl \InsetSpace ~
16226 ; dpl holds lower byte of function argument
16238 dpl,_head \InsetSpace ~
16241 ; buf is 0x100 byte aligned so head can be used directly
16284 ; we could do an ANL _head,#0x0f here to use a
16285 smaller buffer (see above)
16297 ; restore used registers here
16304 \begin_inset LatexCommand \index{\_endasm}
16309 \begin_inset LatexCommand \index{\_\_endasm}
16320 \begin_layout Standard
16321 The inline assembler code can contain any valid code understood by the assembler
16322 , this includes any assembler directives and comment lines.
16323 The assembler does not like some characters like ':' or ''' in comments.
16324 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16325 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16330 \begin_inset LatexCommand \index{Assembler documentation}
16335 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16343 \begin_layout Standard
16344 The compiler does not do any validation of the code within the
16347 \begin_inset LatexCommand \index{\_asm}
16352 \begin_inset LatexCommand \index{\_\_asm}
16360 \begin_inset LatexCommand \index{\_endasm}
16365 \begin_inset LatexCommand \index{\_\_endasm}
16374 Specifically it will not know which registers are used and thus register
16376 \begin_inset LatexCommand \index{push/pop}
16380 has to be done manually.
16384 \begin_layout Standard
16385 It is recommended that each assembly instruction (including labels) be placed
16386 in a separate line (as the example shows).
16391 \begin_layout Standard
16403 \begin_inset LatexCommand \index{-\/-peep-asm}
16409 command line option is used, the inline assembler code will be passed through
16410 the peephole optimizer
16411 \begin_inset LatexCommand \index{Peephole optimizer}
16416 There are only a few (if any) cases where this option makes sense, it might
16417 cause some unexpected changes in the inline assembler code.
16418 Please go through the peephole optimizer rules defined in file
16422 before using this option.
16425 \begin_layout Subsection
16427 \begin_inset LatexCommand \label{sub:Naked-Functions}
16432 \begin_inset LatexCommand \index{Naked functions}
16439 \begin_layout Standard
16440 A special keyword may be associated with a function declaring it as
16443 \begin_inset LatexCommand \index{\_naked}
16448 \begin_inset LatexCommand \index{\_\_naked}
16459 function modifier attribute prevents the compiler from generating prologue
16460 \begin_inset LatexCommand \index{function prologue}
16465 \begin_inset LatexCommand \index{function epilogue}
16469 code for that function.
16470 This means that the user is entirely responsible for such things as saving
16471 any registers that may need to be preserved, selecting the proper register
16472 bank, generating the
16476 instruction at the end, etc.
16477 Practically, this means that the contents of the function must be written
16478 in inline assembler.
16479 This is particularly useful for interrupt functions, which can have a large
16480 (and often unnecessary) prologue/epilogue.
16481 For example, compare the code generated by these two functions:
16484 \begin_layout Verse
16488 \begin_inset LatexCommand \index{volatile}
16492 data unsigned char counter;
16496 void simpleInterrupt(void) __interrupt
16497 \begin_inset LatexCommand \index{interrupt}
16502 \begin_inset LatexCommand \index{\_\_interrupt}
16520 void nakedInterrupt(void) __interrupt (2) __naked
16529 \begin_inset LatexCommand \index{\_asm}
16534 \begin_inset LatexCommand \index{\_\_asm}
16551 _counter ; does not change flags, no need to save psw
16564 include ret or reti in _naked function.
16571 \begin_inset LatexCommand \index{\_endasm}
16576 \begin_inset LatexCommand \index{\_\_endasm}
16585 \begin_layout Standard
16586 For an 8051 target, the generated simpleInterrupt looks like:
16589 \begin_layout Verse
16596 example, recent versions of SDCC generate
16602 code for simpleInterrupt() and nakedInterrupt()!
16743 \begin_layout Standard
16744 whereas nakedInterrupt looks like:
16747 \begin_layout Verse
16760 _counter ; does not change flags, no need to save psw
16779 MUST explicitly include ret or reti in _naked function
16782 \begin_layout Standard
16783 The related directive #pragma exclude
16784 \begin_inset LatexCommand \index{\#pragma exclude}
16788 allows a more fine grained control over pushing & popping
16789 \begin_inset LatexCommand \index{push/pop}
16796 \begin_layout Standard
16797 While there is nothing preventing you from writing C code inside a
16801 function, there are many ways to shoot yourself in the foot doing this,
16802 and it is recommended that you stick to inline assembler.
16805 \begin_layout Subsection
16806 Use of Labels within Inline Assembler
16809 \begin_layout Standard
16810 SDCC allows the use of in-line assembler with a few restrictions regarding
16812 In older versions of the compiler all labels defined within inline assembler
16821 where nnnn is a number less than 100 (which implies a limit of utmost 100
16822 inline assembler labels
16833 \begin_layout Verse
16837 \begin_inset LatexCommand \index{\_asm}
16842 \begin_inset LatexCommand \index{\_\_asm}
16872 \begin_inset LatexCommand \index{\_endasm}
16877 \begin_inset LatexCommand \index{\_\_endasm}
16884 \begin_layout Standard
16885 Inline assembler code cannot reference any C-Labels, however it can reference
16887 \begin_inset LatexCommand \index{Labels}
16891 defined by the inline assembler, e.g.:
16894 \begin_layout Verse
16917 ; some assembler code
16938 /* some more c code */
16940 clabel:\InsetSpace ~
16942 /* inline assembler cannot reference this
16955 $0003: ;label (can be referenced by inline assembler only)
16963 \begin_inset LatexCommand \index{\_endasm}
16968 \begin_inset LatexCommand \index{\_\_endasm}
16978 /* some more c code */
16983 \begin_layout Standard
16984 In other words inline assembly code can access labels defined in inline
16985 assembly within the scope of the function.
16986 The same goes the other way, i.e.
16987 labels defines in inline assembly can not be accessed by C statements.
16990 \begin_layout Section
16991 Interfacing with Assembler Code
16992 \begin_inset LatexCommand \index{Assembler routines}
16999 \begin_layout Subsection
17000 Global Registers used for Parameter Passing
17001 \begin_inset LatexCommand \index{Parameter passing}
17008 \begin_layout Standard
17009 The compiler always uses the global registers
17012 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17017 \begin_inset LatexCommand \index{DPTR}
17022 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17031 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17037 to pass the first parameter to a routine.
17038 The second parameter onwards is either allocated on the stack (for reentrant
17043 \begin_layout Standard
17052 -stack-auto is used) or in data / xdata memory (depending on the memory
17057 \begin_layout Subsection
17058 Assembler Routine (non-reentrant)
17061 \begin_layout Standard
17062 In the following example
17063 \begin_inset LatexCommand \index{reentrant}
17068 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17072 the function c_func calls an assembler routine asm_func, which takes two
17074 \begin_inset LatexCommand \index{function parameter}
17081 \begin_layout Verse
17084 extern int asm_func(unsigned char, unsigned char);
17088 int c_func (unsigned char
17089 i, unsigned char j)
17097 return asm_func(i,j);
17111 return c_func(10,9);
17116 \begin_layout Standard
17117 The corresponding assembler function is:
17120 \begin_layout Verse
17123 .globl _asm_func_PARM_2
17225 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17242 \begin_layout Standard
17243 Note here that the return values
17244 \begin_inset LatexCommand \index{return value}
17248 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
17250 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
17251 b' & 'acc' for four byte values.
17254 \begin_layout Standard
17255 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17256 the parameter number starting from 1, and counting from the left.
17257 The first parameter is passed in
17258 \begin_inset Quotes eld
17262 \begin_inset Quotes erd
17265 for a one byte parameter,
17266 \begin_inset Quotes eld
17270 \begin_inset Quotes erd
17274 \begin_inset Quotes eld
17278 \begin_inset Quotes erd
17281 for three bytes and
17282 \begin_inset Quotes eld
17286 \begin_inset Quotes erd
17289 for a four bytes parameter.
17290 The variable name for the second parameter will be _<function_name>_PARM_2.
17295 ble the assembler routine with the following command:
17302 asx8051 -losg asmfunc.asm
17309 Then compile and link the assembler routine to the C source file with the
17317 sdcc cfunc.c asmfunc.rel
17320 \begin_layout Subsection
17321 Assembler Routine (reentrant)
17324 \begin_layout Standard
17326 \begin_inset LatexCommand \index{reentrant}
17331 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17335 the second parameter
17336 \begin_inset LatexCommand \index{function parameter}
17340 onwards will be passed on the stack, the parameters are pushed from right
17342 after the call the leftmost parameter will be on the top of the stack.
17343 Here is an example:
17346 \begin_layout Verse
17349 extern int asm_func(unsigned char, unsigned char);
17353 int c_func (unsigned char
17354 i, unsigned char j) reentrant
17362 return asm_func(i,j);
17382 \begin_layout Standard
17383 The corresponding assembler routine is:
17386 \begin_layout Verse
17486 \begin_layout Standard
17487 The compiling and linking procedure remains the same, however note the extra
17488 entry & exit linkage required for the assembler code, _bp is the stack
17489 frame pointer and is used to compute the offset into the stack for parameters
17490 and local variables.
17491 \begin_inset VSpace bigskip
17497 \begin_layout Section
17499 \begin_inset LatexCommand \index{int (16 bit)}
17504 \begin_inset LatexCommand \index{long (32 bit)}
17511 \begin_layout Standard
17512 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17513 multiplication and modulus operations are implemented by support routines.
17514 These support routines are all developed in ANSI-C to facilitate porting
17515 to other MCUs, although some model specific assembler optimizations are
17517 The following files contain the described routines, all of them can be
17518 found in <installdir>/share/sdcc/lib.
17523 \begin_layout Standard
17525 \begin_inset Tabular
17526 <lyxtabular version="3" rows="11" columns="2">
17528 <column alignment="left" valignment="top" leftline="true" width="0">
17529 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17530 <row topline="true" bottomline="true">
17531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17534 \begin_layout Standard
17542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17545 \begin_layout Standard
17554 <row topline="true">
17555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17558 \begin_layout Standard
17564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17567 \begin_layout Standard
17568 16 bit multiplication
17574 <row topline="true">
17575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17578 \begin_layout Standard
17584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17587 \begin_layout Standard
17588 signed 16 bit division (calls _divuint)
17594 <row topline="true">
17595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17598 \begin_layout Standard
17604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17607 \begin_layout Standard
17608 unsigned 16 bit division
17614 <row topline="true">
17615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17618 \begin_layout Standard
17624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17627 \begin_layout Standard
17628 signed 16 bit modulus (calls _moduint)
17634 <row topline="true">
17635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17638 \begin_layout Standard
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17647 \begin_layout Standard
17648 unsigned 16 bit modulus
17654 <row topline="true">
17655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17658 \begin_layout Standard
17664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17667 \begin_layout Standard
17668 32 bit multiplication
17674 <row topline="true">
17675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17678 \begin_layout Standard
17684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17687 \begin_layout Standard
17688 signed 32 division (calls _divulong)
17694 <row topline="true">
17695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17698 \begin_layout Standard
17704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17707 \begin_layout Standard
17708 unsigned 32 division
17714 <row topline="true">
17715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17718 \begin_layout Standard
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17727 \begin_layout Standard
17728 signed 32 bit modulus (calls _modulong)
17734 <row topline="true" bottomline="true">
17735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17738 \begin_layout Standard
17744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17747 \begin_layout Standard
17748 unsigned 32 bit modulus
17763 \begin_layout Standard
17764 Since they are compiled as
17769 \begin_inset LatexCommand \index{reentrant}
17774 \begin_inset LatexCommand \index{interrupt}
17778 service routines should not do any of the above operations.
17779 If this is unavoidable then the above routines will need to be compiled
17786 \begin_layout Standard
17796 \begin_inset LatexCommand \index{-\/-stack-auto}
17802 option, after which the source program will have to be compiled with
17808 \begin_layout Standard
17818 \begin_inset LatexCommand \index{-\/-int-long-reent}
17825 Notice that you don't have to call these routines directly.
17826 The compiler will use them automatically every time an integer operation
17830 \begin_layout Section
17831 Floating Point Support
17832 \begin_inset LatexCommand \index{Floating point support}
17839 \begin_layout Standard
17840 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
17841 The floating point support routines are derived from gcc's floatlib.c and
17842 consist of the following routines:
17847 \begin_layout Standard
17851 \begin_inset Tabular
17852 <lyxtabular version="3" rows="17" columns="2">
17854 <column alignment="left" valignment="top" leftline="true" width="0">
17855 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17856 <row topline="true" bottomline="true">
17857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17860 \begin_layout Standard
17875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17878 \begin_layout Standard
17885 <row topline="true">
17886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17889 \begin_layout Standard
17904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17907 \begin_layout Standard
17917 add floating point numbers
17923 <row topline="true">
17924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17927 \begin_layout Standard
17942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17945 \begin_layout Standard
17955 subtract floating point numbers
17961 <row topline="true">
17962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17965 \begin_layout Standard
17980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17983 \begin_layout Standard
17993 divide floating point numbers
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_layout Standard
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18021 \begin_layout Standard
18031 multiply floating point numbers
18037 <row topline="true">
18038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18041 \begin_layout Standard
18056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18059 \begin_layout Standard
18069 convert floating point to unsigned char
18075 <row topline="true">
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18079 \begin_layout Standard
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18097 \begin_layout Standard
18107 convert floating point to signed char
18113 <row topline="true">
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18117 \begin_layout Standard
18132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18135 \begin_layout Standard
18145 convert floating point to unsigned int
18151 <row topline="true">
18152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18155 \begin_layout Standard
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18173 \begin_layout Standard
18183 convert floating point to signed int
18189 <row topline="true">
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18193 \begin_layout Standard
18216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18219 \begin_layout Standard
18229 convert floating point to unsigned long
18235 <row topline="true">
18236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18239 \begin_layout Standard
18254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18257 \begin_layout Standard
18267 convert floating point to signed long
18273 <row topline="true">
18274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18277 \begin_layout Standard
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18295 \begin_layout Standard
18305 convert unsigned char to floating point
18311 <row topline="true">
18312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18315 \begin_layout Standard
18330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18333 \begin_layout Standard
18343 convert char to floating point number
18349 <row topline="true">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18353 \begin_layout Standard
18368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18371 \begin_layout Standard
18381 convert unsigned int to floating point
18387 <row topline="true">
18388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18391 \begin_layout Standard
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18409 \begin_layout Standard
18419 convert int to floating point numbers
18425 <row topline="true">
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18429 \begin_layout Standard
18444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18447 \begin_layout Standard
18457 convert unsigned long to floating point number
18463 <row topline="true" bottomline="true">
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18467 \begin_layout Standard
18482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18485 \begin_layout Standard
18495 convert long to floating point number
18510 \begin_layout Standard
18511 These support routines are developed in ANSI-C so there is room for space
18512 and speed improvement
18516 \begin_layout Standard
18517 These floating point routines (
18521 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18528 Note if all these routines are used simultaneously the data space might
18530 For serious floating point usage the large model might be needed.
18531 Also notice that you don't have to call this routines directly.
18532 The compiler will use them automatically every time a floating point operation
18534 \begin_inset VSpace bigskip
18540 \begin_layout Section
18542 \begin_inset LatexCommand \index{Libraries}
18549 \begin_layout Standard
18552 <pending: this is messy and incomplete - a little more information is in
18553 sdcc/doc/libdoc.txt
18558 \begin_layout Subsection
18559 Compiler support routines (_gptrget, _mulint etc.)
18562 \begin_layout Subsection
18563 Stdclib functions (puts, printf, strcat etc.)
18566 \begin_layout Subsubsection
18570 \begin_layout Paragraph
18571 getchar(), putchar()
18574 \begin_layout Standard
18575 \begin_inset LatexCommand \index{<stdio.h>}
18579 As usual on embedded systems you have to provide your own
18582 \begin_inset LatexCommand \index{getchar()}
18591 \begin_inset LatexCommand \index{putchar()}
18598 SDCC does not know whether the system connects to a serial line with or
18599 without handshake, LCD, keyboard or other device.
18613 You'll find examples for serial routines f.e.
18614 in sdcc/device/lib.
18615 For the mcs51 this minimalistic polling
18619 routine might be a start:
18622 \begin_layout Verse
18625 void putchar (char c) {
18631 while (!TI)\InsetSpace ~
18634 /* assumes UART is initialized */
18662 \begin_layout Paragraph
18666 \begin_layout Standard
18670 \begin_inset LatexCommand \index{printf()}
18680 does not support float (except on ds390).
18681 To enable this recompile it with the option
18687 \begin_layout Standard
18697 \begin_inset LatexCommand \index{USE\_FLOATS}
18703 on the command line.
18710 \begin_layout Standard
18720 \begin_inset LatexCommand \index{-\/-model-large}
18726 for the mcs51 port, since this uses a lot of memory.
18729 \begin_layout Standard
18730 If you're short on code memory you might want to use
18733 \begin_inset LatexCommand \index{printf\_small()}
18748 For the mcs51 there additionally are assembly versions
18751 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
18757 (subset of printf using less than 270 bytes) and
18760 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
18769 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
18775 (floating-point aware version of printf_fast) which should fit the requirements
18776 of many embedded systems (printf_fast() can be customized by unsetting
18781 support long variables and field widths).
18782 Be sure to use only one of these printf options within a project.
18787 \begin_layout Standard
18788 Feature matrix of different
18795 \begin_layout Standard
18796 \begin_inset Tabular
18797 <lyxtabular version="3" rows="14" columns="7">
18798 <features islongtable="true">
18799 <column alignment="left" valignment="middle" leftline="true" width="14col%">
18800 <column alignment="center" valignment="top" leftline="true" width="0">
18801 <column alignment="center" valignment="top" leftline="true" width="12col%">
18802 <column alignment="center" valignment="top" leftline="true" width="10col%">
18803 <column alignment="center" valignment="top" leftline="true" width="0">
18804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
18805 <column alignment="center" valignment="top" rightline="true" width="0">
18806 <row topline="true" bottomline="true" endhead="true">
18807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18810 \begin_layout Standard
18819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18822 \begin_layout Standard
18824 \begin_inset LatexCommand \index{printf}
18833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18836 \begin_layout Standard
18844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18847 \begin_layout Standard
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18856 \begin_layout Standard
18862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18865 \begin_layout Standard
18871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18874 \begin_layout Standard
18881 <row topline="true" endhead="true">
18882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18885 \begin_layout Standard
18891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18894 \begin_layout Standard
18902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18905 \begin_layout Standard
18913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18916 \begin_layout Standard
18924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18927 \begin_layout Standard
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18938 \begin_layout Standard
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18949 \begin_layout Standard
18958 <row topline="true" endhead="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18962 \begin_layout Standard
18963 \begin_inset Quotes sld
18967 \begin_inset Quotes srd
18973 \begin_layout Standard
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18982 \begin_layout Standard
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18991 \begin_layout Standard
18997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19000 \begin_layout Standard
19006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19009 \begin_layout Standard
19015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19018 \begin_layout Standard
19024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19027 \begin_layout Standard
19034 <row topline="true" endhead="true">
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19038 \begin_layout Standard
19042 \begin_layout Standard
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19051 \begin_layout Standard
19057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19060 \begin_layout Standard
19066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19069 \begin_layout Standard
19070 0.45k / 0.47k (+ _ltoa)
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19078 \begin_layout Standard
19084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19087 \begin_layout Standard
19093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19096 \begin_layout Standard
19103 <row topline="true">
19104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19107 \begin_layout Standard
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19116 \begin_layout Standard
19126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19129 \begin_layout Standard
19176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19179 \begin_layout Standard
19218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19221 \begin_layout Standard
19227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19230 \begin_layout Standard
19236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19239 \begin_layout Standard
19246 <row topline="true">
19247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19250 \begin_layout Standard
19251 long (32 bit) support
19256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19259 \begin_layout Standard
19265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19268 \begin_layout Standard
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19277 \begin_layout Standard
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19286 \begin_layout Standard
19292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19295 \begin_layout Standard
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19313 \begin_layout Standard
19320 <row topline="true">
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19324 \begin_layout Standard
19325 byte arguments on stack
19330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19333 \begin_layout Standard
19339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19342 \begin_layout Standard
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19351 \begin_layout Standard
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_layout Standard
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19369 \begin_layout Standard
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19378 \begin_layout Standard
19385 <row topline="true">
19386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19389 \begin_layout Standard
19391 \begin_inset LatexCommand \index{Floating point support}
19400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19403 \begin_layout Standard
19409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19412 \begin_layout Standard
19418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19421 \begin_layout Standard
19427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19430 \begin_layout Standard
19436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19439 \begin_layout Standard
19444 \begin_layout Standard
19445 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19458 \begin_layout Standard
19465 <row topline="true">
19466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19469 \begin_layout Standard
19470 float formats %e %g
19475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19478 \begin_layout Standard
19484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19487 \begin_layout Standard
19493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19496 \begin_layout Standard
19502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19505 \begin_layout Standard
19511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19514 \begin_layout Standard
19520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19523 \begin_layout Standard
19530 <row topline="true" bottomline="true">
19531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19534 \begin_layout Standard
19540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19543 \begin_layout Standard
19549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19552 \begin_layout Standard
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19561 \begin_layout Standard
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19570 \begin_layout Standard
19576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19579 \begin_layout Standard
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19588 \begin_layout Standard
19595 <row bottomline="true">
19596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19599 \begin_layout Standard
19604 \begin_layout Standard
19605 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
19609 n'); standard 8051 @ 22.1184 MHz, empty putchar()
19617 \begin_layout Standard
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19626 \begin_layout Standard
19632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19635 \begin_layout Standard
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19644 \begin_layout Standard
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19653 \begin_layout Standard
19659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19662 \begin_layout Standard
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19671 \begin_layout Standard
19678 <row bottomline="true">
19679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19682 \begin_layout Standard
19687 \begin_layout Standard
19688 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
19697 \begin_layout Standard
19703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19706 \begin_layout Standard
19712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19715 \begin_layout Standard
19721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19724 \begin_layout Standard
19730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19733 \begin_layout Standard
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19742 \begin_layout Standard
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19751 \begin_layout Standard
19756 \begin_layout Standard
19757 printf_tiny integer speed is data dependent, worst case is 0.33 ms
19768 <row bottomline="true">
19769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19772 \begin_layout Standard
19777 \begin_layout Standard
19778 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
19787 \begin_layout Standard
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19796 \begin_layout Standard
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19805 \begin_layout Standard
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19814 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19823 \begin_layout Standard
19829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19832 \begin_layout Standard
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19841 \begin_layout Standard
19848 <row bottomline="true">
19849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 \begin_layout Standard
19857 \begin_layout Standard
19858 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
19867 \begin_layout Standard
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19876 \begin_layout Standard
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19885 \begin_layout Standard
19891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19894 \begin_layout Standard
19900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19903 \begin_layout Standard
19909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19912 \begin_layout Standard
19918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19921 \begin_layout Standard
19935 \begin_layout Subsubsection
19937 \begin_inset LatexCommand \index{malloc.h}
19944 \begin_layout Standard
19945 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19946 using dynamic memory allocation
19947 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19952 \begin_inset LatexCommand \index{heap (malloc)}
19956 space of 1024 bytes is provided for malloc to allocate memory from.
19957 If you need a different heap size you need to recompile _heap.c with the
19958 required size defined in HEAP_SIZE.
19959 It is recommended to make a copy of this file into your project directory
19960 and compile it there with:
19963 \begin_layout Verse
19966 sdcc -c _heap.c -D HEAD_SIZE=2048
19969 \begin_layout Standard
19970 And then link it with:
19973 \begin_layout Verse
19976 sdcc main.rel _heap.rel
19979 \begin_layout Subsection
19980 Math functions (sinf, powf, sqrtf etc.)
19983 \begin_layout Subsubsection
19987 \begin_layout Standard
19988 See definitions in file <math.h>.
19991 \begin_layout Subsection
19995 \begin_layout Standard
19997 \begin_inset LatexCommand \index{Libraries}
20001 included in SDCC should have a license at least as liberal as the GNU Lesser
20002 General Public License
20003 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20014 \begin_layout Standard
20015 \begin_inset Note Note
20018 \begin_layout Standard
20019 license statements for the libraries are missing.
20020 sdcc/device/lib/ser_ir.c
20023 \begin_layout Standard
20025 come with a GPL (as opposed to LGPL) License - this will not be liberal
20026 enough for many embedded programmers.
20034 \begin_layout Standard
20035 If you have ported some library or want to share experience about some code
20037 falls into any of these categories Busses (I
20038 \begin_inset Formula $^{\textrm{2}}$
20041 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20042 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20043 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20044 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20049 would certainly like to hear about it.
20052 \begin_layout Standard
20053 Programmers coding for embedded systems are not especially famous for being
20054 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20055 e these references are very valuable.
20056 Let's help to create a climate where information is shared.
20057 \begin_inset VSpace bigskip
20063 \begin_layout Section
20067 \begin_layout Subsection
20068 MCS51 Memory Models
20069 \begin_inset LatexCommand \index{Memory model}
20074 \begin_inset LatexCommand \index{MCS51 memory model}
20081 \begin_layout Subsubsection
20082 Small, Medium and Large
20085 \begin_layout Standard
20086 SDCC allows three memory models for MCS51 code,
20095 Modules compiled with different memory models should
20099 be combined together or the results would be unpredictable.
20100 The library routines supplied with the compiler are compiled as small,
20102 The compiled library modules are contained in separate directories as small,
20103 medium and large so that you can link to the appropriate set.
20106 \begin_layout Standard
20107 When the medium or large model is used all variables declared without a
20108 storage class will be allocated into the external ram, this includes all
20109 parameters and local variables (for non-reentrant
20110 \begin_inset LatexCommand \index{reentrant}
20115 When the small model is used variables without storage class are allocated
20116 in the internal ram.
20119 \begin_layout Standard
20120 Judicious usage of the processor specific storage classes
20121 \begin_inset LatexCommand \index{Storage class}
20125 and the 'reentrant' function type will yield much more efficient code,
20126 than using the large model.
20127 Several optimizations are disabled when the program is compiled using the
20128 large model, it is therefore recommended that the small model be used unless
20129 absolutely required.
20132 \begin_layout Subsubsection
20134 \begin_inset LatexCommand \label{sub:External-Stack}
20139 \begin_inset LatexCommand \index{stack}
20144 \begin_inset LatexCommand \index{External stack (mcs51)}
20151 \begin_layout Standard
20152 The external stack (-
20156 \begin_layout Standard
20166 \begin_inset LatexCommand \index{-\/-xstack}
20170 ) is located in pdata
20171 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20175 memory (usually at the start of the external ram segment) and uses all
20176 unused space in pdata (max.
20182 \begin_layout Standard
20191 -xstack option is used to compile the program, the parameters and local
20193 \begin_inset LatexCommand \index{local variables}
20197 of all reentrant functions are allocated in this area.
20198 This option is provided for programs with large stack space requirements.
20199 When used with the -
20203 \begin_layout Standard
20213 \begin_inset LatexCommand \index{-\/-stack-auto}
20217 option, all parameters and local variables are allocated on the external
20218 stack (note: support libraries will need to be recompiled with the same
20220 There is a predefined target in the library makefile).
20223 \begin_layout Standard
20224 The compiler outputs the higher order address byte of the external ram segment
20226 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20231 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20235 ), therefore when using the External Stack option, this port
20239 be used by the application program.
20242 \begin_layout Subsection
20244 \begin_inset LatexCommand \index{Memory model}
20249 \begin_inset LatexCommand \index{DS390 memory model}
20256 \begin_layout Standard
20257 The only model supported is Flat 24
20258 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20263 This generates code for the 24 bit contiguous addressing mode of the Dallas
20265 In this mode, up to four meg of external RAM or code space can be directly
20267 See the data sheets at www.dalsemi.com for further information on this part.
20272 that the compiler does not generate any code to place the processor into
20273 24 bitmode (although
20277 in the ds390 libraries will do that for you).
20283 \begin_inset LatexCommand \index{Tinibios (DS390)}
20287 , the boot loader or similar code must ensure that the processor is in 24
20288 bit contiguous addressing mode before calling the SDCC startup code.
20299 \begin_layout Standard
20310 option, variables will by default be placed into the XDATA segment.
20315 Segments may be placed anywhere in the 4 meg address space using the usual
20320 \begin_layout Standard
20330 Note that if any segments are located above 64K, the -r flag must be passed
20331 to the linker to generate the proper segment relocations, and the Intel
20332 HEX output format must be used.
20333 The -r flag can be passed to the linker by using the option
20337 on the SDCC command line.
20338 However, currently the linker can not handle code segments > 64k.
20341 \begin_layout Section
20343 \begin_inset LatexCommand \label{sec:Pragmas}
20348 \begin_inset LatexCommand \index{Pragmas}
20355 \begin_layout Standard
20356 SDCC supports the following #pragma directives:
20359 \begin_layout Itemize
20365 \begin_inset LatexCommand \index{\#pragma save}
20369 - this will save most current options to the save/restore stack.
20370 See #pragma\InsetSpace ~
20374 \begin_layout Itemize
20380 \begin_inset LatexCommand \index{\#pragma restore}
20384 - will restore saved options from the last save.
20385 saves & restores can be nested.
20386 SDCC uses a save/restore stack: save pushes current options to the stack,
20387 restore pulls current options from the stack.
20388 See #pragma\InsetSpace ~
20394 \begin_layout Itemize
20400 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20405 \begin_inset LatexCommand \index{function prologue}
20409 function1[,function2[,function3...]] - The compiler by default uses a caller
20410 saves convention for register saving across function calls, however this
20411 can cause unnecessary register pushing & popping
20412 \begin_inset LatexCommand \index{push/pop}
20416 when calling small functions from larger functions.
20417 This option can be used to switch off the register saving convention for
20418 the function names specified.
20419 The compiler will not save registers when calling these functions, extra
20420 code need to be manually inserted at the entry & exit for these functions
20421 to save & restore the registers used by these functions, this can SUBSTANTIALLY
20422 reduce code & improve run time performance of the generated code.
20423 In the future the compiler (with inter procedural analysis) may be able
20424 to determine the appropriate scheme to use for each function call.
20429 \begin_layout Standard
20438 -callee-saves command line option is used, the function names specified
20439 in #pragma\InsetSpace ~
20441 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20445 is appended to the list of functions specified in the command line.
20448 \begin_layout Itemize
20454 \begin_inset LatexCommand \index{\#pragma exclude}
20458 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20459 of pairs of push/pop
20460 \begin_inset LatexCommand \index{push/pop}
20469 \begin_inset LatexCommand \index{interrupt}
20482 The directive should be placed immediately before the ISR function definition
20483 and it affects ALL ISR functions following it.
20484 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20485 exclude\InsetSpace ~
20487 \begin_inset LatexCommand \index{\#pragma exclude}
20492 See also the related keyword _naked
20493 \begin_inset LatexCommand \index{\_naked}
20498 \begin_inset LatexCommand \index{\_\_naked}
20505 \begin_layout Itemize
20511 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20515 - the compiler will not warn you anymore for obvious mistakes, you'r on
20519 \begin_layout Itemize
20525 \begin_inset LatexCommand \index{\#pragma disable\_warning}
20529 - the compiler will not warn you anymore about warning number <nnnn>.
20532 \begin_layout Itemize
20538 \begin_inset LatexCommand \index{\#pragma nogcse}
20542 - will stop global common subexpression elimination.
20545 \begin_layout Itemize
20551 \begin_inset LatexCommand \index{\#pragma noinduction}
20555 - will stop loop induction optimizations.
20558 \begin_layout Itemize
20564 \begin_inset LatexCommand \index{\#pragma noinvariant}
20568 - will not do loop invariant optimizations.
20569 For more details see Loop Invariants in section
20570 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
20577 \begin_layout Itemize
20583 \begin_inset LatexCommand \index{\#pragma noiv}
20587 - Do not generate interrupt
20588 \begin_inset LatexCommand \index{interrupt}
20593 \begin_inset LatexCommand \index{interrupt vector table}
20597 entries for all ISR functions defined after the pragma.
20598 This is useful in cases where the interrupt vector table must be defined
20599 manually, or when there is a secondary, manually defined interrupt vector
20601 for the autovector feature of the Cypress EZ-USB FX2).
20602 More elegantly this can be achieved by obmitting the optional interrupt
20603 number after the interrupt keyword, see section
20604 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
20612 \begin_layout Itemize
20618 \begin_inset LatexCommand \index{\#pragma nojtbound}
20622 - will not generate code for boundary value checking, when switch statements
20623 are turned into jump-tables (dangerous).
20624 For more details see section
20625 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
20632 \begin_layout Itemize
20638 \begin_inset LatexCommand \index{\#pragma noloopreverse}
20642 - Will not do loop reversal optimization
20645 \begin_layout Itemize
20651 \begin_inset LatexCommand \index{\#pragma nooverlay}
20655 - the compiler will not overlay the parameters and local variables of a
20659 \begin_layout Itemize
20665 \begin_inset LatexCommand \index{\#pragma stackauto}
20673 \begin_layout Standard
20683 \begin_inset LatexCommand \index{-\/-stack-auto}
20688 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
20692 Parameters and Local Variables.
20695 \begin_layout Itemize
20701 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
20705 - The compiler will optimize code generation towards fast code, possibly
20706 at the expense of code size.
20707 Currently this has little effect.
20710 \begin_layout Itemize
20716 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
20720 - The compiler will optimize code generation towards compact code, possibly
20721 at the expense of code speed.
20722 Currently this has little effect.
20725 \begin_layout Itemize
20731 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
20735 - The compiler will attempt to generate code that is both compact and fast,
20736 as long as meeting one goal is not a detriment to the other (this is the
20741 \begin_layout Itemize
20747 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
20751 - Generally follow the C89 standard, but allow SDCC features that conflict
20752 with the standard (default).
20755 \begin_layout Itemize
20761 \begin_inset LatexCommand \index{\#pragma std\_c89}
20765 - Follow the C89 standard and disable SDCC features that conflict with the
20769 \begin_layout Itemize
20775 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
20779 - Generally follow the C99 standard, but allow SDCC features that conflict
20780 with the standard (incomplete support).
20783 \begin_layout Itemize
20789 \begin_inset LatexCommand \index{\#pragma std\_c99}
20793 - Follow the C99 standard and disable SDCC features that conflict with the
20794 standard (incomplete support).
20797 \begin_layout Itemize
20803 \begin_inset LatexCommand \index{\#pragma codeseg}
20807 - Use this name (max.
20808 8 characters) for the code segment.
20813 \begin_layout Standard
20825 \begin_layout Itemize
20831 \begin_inset LatexCommand \index{\#pragma constseg}
20835 - Use this name (max.
20836 8 characters) for the const segment.
20841 \begin_layout Standard
20853 \begin_layout Standard
20854 The preprocessor SDCPP
20855 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
20859 supports the following #pragma directives:
20862 \begin_layout Itemize
20865 pedantic_parse_number
20868 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
20872 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
20873 parsed properly and the macro LO_B(3) gets expanded.
20875 Below is an example on how to use this pragma.
20878 Note: this functionality is not in conformance with standard!
20881 \begin_layout Verse
20884 #pragma pedantic_parse_number +
20885 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
20893 #define LO_B(x) ((x) & 0xff)
20897 unsigned char foo(void)
20904 unsigned char c=0xfe-LO_B(3)
20919 \begin_layout Itemize
20925 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20929 (+ | -) - switch _asm _endasm block preprocessing on / off.
20931 You use this prama to define multilines of assembly code.
20932 This will prevent the preprocessor from changing the formating required
20934 Below is an example on how to use this pragma.
20937 \begin_layout Verse
20940 #pragma preproc_asm -
20941 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20947 #define MYDELAY _asm
20952 nop ;my assembly comment...
20966 #pragma preproc_asm
20997 \begin_layout Itemize
21003 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21007 (+ | -) - Allow "naked" hash in macro definition, for example:
21011 #define DIR_LO(x) #(x & 0xff)
21016 Below is an example on how to use this pragma.
21019 \begin_layout Verse
21022 #pragma preproc_asm +
21024 #pragma sdcc_hash +
21025 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21040 mov R6_B3, #(x & 0xff)
21047 mov R7_B3, #((x >> 8) & 0xff)
21071 \begin_layout Standard
21072 The pragma's are intended to be used to turn-on or off certain optimizations
21073 which might cause the compiler to generate extra stack / data space to
21074 store compiler generated temporary variables.
21075 This usually happens in large functions.
21076 Pragma directives should be used as shown in the following example, they
21077 are used to control options & optimizations for a given function; pragmas
21078 should be placed before and/or after a function, placing pragma's inside
21079 a function body could have unpredictable results.
21082 \begin_layout Verse
21086 \begin_inset LatexCommand \index{\#pragma save}
21097 /* save the current settings */
21100 \begin_inset LatexCommand \index{\#pragma nogcse}
21109 /* turnoff global subexpression elimination */
21111 #pragma noinduction
21112 \begin_inset LatexCommand \index{\#pragma noinduction}
21116 /* turn off induction optimizations */
21139 \begin_inset LatexCommand \index{\#pragma restore}
21143 /* turn the optimizations back on */
21146 \begin_layout Standard
21147 The compiler will generate a warning message when extra space is allocated.
21148 It is strongly recommended that the save and restore pragma's be used when
21149 changing options for a function.
21158 \begin_layout Section
21159 Defines Created by the Compiler
21162 \begin_layout Standard
21163 The compiler creates the following #defines
21164 \begin_inset LatexCommand \index{\#defines}
21169 \begin_inset LatexCommand \index{Defines created by the compiler}
21178 \begin_layout Standard
21179 \begin_inset Tabular
21180 <lyxtabular version="3" rows="11" columns="2">
21182 <column alignment="left" valignment="top" leftline="true" width="3in">
21183 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21184 <row topline="true" bottomline="true">
21185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21188 \begin_layout Standard
21196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21199 \begin_layout Standard
21208 <row topline="true">
21209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21212 \begin_layout Standard
21214 \begin_inset LatexCommand \index{SDCC}
21223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21226 \begin_layout Standard
21228 Since version 2.5.6 the version number as an int (ex.
21235 <row topline="true">
21236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21239 \begin_layout Standard
21241 \begin_inset LatexCommand \index{SDCC\_mcs51}
21246 \begin_inset LatexCommand \index{SDCC\_ds390}
21251 \begin_inset LatexCommand \index{SDCC\_z80}
21260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21263 \begin_layout Standard
21264 depending on the model used (e.g.: -mds390)
21270 <row topline="true">
21271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21274 \begin_layout Standard
21276 \begin_inset LatexCommand \index{\_\_mcs51}
21281 \begin_inset LatexCommand \index{\_\_ds390}
21286 \begin_inset LatexCommand \index{\_\_hc08}
21291 \begin_inset LatexCommand \index{\_\_z80}
21300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21303 \begin_layout Standard
21304 depending on the model used (e.g.
21311 <row topline="true">
21312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21315 \begin_layout Standard
21317 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21329 \begin_layout Standard
21336 \begin_layout Standard
21353 <row topline="true">
21354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21357 \begin_layout Standard
21359 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21371 \begin_layout Standard
21378 \begin_layout Standard
21395 <row topline="true">
21396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21399 \begin_layout Standard
21401 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
21410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21413 \begin_layout Standard
21420 \begin_layout Standard
21437 <row topline="true">
21438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21441 \begin_layout Standard
21443 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
21452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21455 \begin_layout Standard
21462 \begin_layout Standard
21479 <row topline="true">
21480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21483 \begin_layout Standard
21485 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
21494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21497 \begin_layout Standard
21504 \begin_layout Standard
21521 <row topline="true">
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21525 \begin_layout Standard
21527 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
21536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21539 \begin_layout Standard
21550 <row topline="true" bottomline="true">
21551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21554 \begin_layout Standard
21556 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
21565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21568 \begin_layout Standard
21586 \begin_layout Chapter
21587 Notes on supported Processors
21590 \begin_layout Section
21592 \begin_inset LatexCommand \label{sub:MCS51-variants}
21597 \begin_inset LatexCommand \index{MCS51 variants}
21604 \begin_layout Standard
21605 MCS51 processors are available from many vendors and come in many different
21607 While they might differ considerably in respect to Special Function Registers
21608 the core MCS51 is usually not modified or is kept compatible.
21612 \begin_layout Subsection
21613 pdata access by SFR
21616 \begin_layout Standard
21617 With the upcome of devices with internal xdata and flash memory devices
21619 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21623 as dedicated I/O port is becoming more popular.
21624 Switching the high byte for pdata
21625 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21629 access which was formerly done by port P2 is then achieved by a Special
21631 \begin_inset LatexCommand \index{sfr}
21636 In well-established MCS51 tradition the address of this
21640 is where the chip designers decided to put it.
21641 Needless to say that they didn't agree on a common name either.
21642 So that the startup code can correctly initialize xdata variables, you
21643 should define an sfr with the name _XPAGE
21646 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
21652 at the appropriate location if the default, port P2, is not used for this.
21656 \begin_layout Verse
21659 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
21663 \begin_layout Verse
21666 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
21671 \begin_layout Verse
21674 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
21678 \begin_layout Verse
21681 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
21685 \begin_layout Verse
21688 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
21692 \begin_layout Standard
21693 For more exotic implementations further customizations may be needed.
21695 \begin_inset LatexCommand \ref{sub:Startup-Code}
21699 for other possibilities.
21702 \begin_layout Subsection
21703 Other Features available by SFR
21706 \begin_layout Standard
21707 Some MCS51 variants offer features like Double DPTR
21708 \begin_inset LatexCommand \index{DPTR}
21712 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
21713 These are currently not used for the MCS51 port.
21714 If you absolutely need them you can fall back to inline assembly or submit
21716 \begin_inset VSpace bigskip
21722 \begin_layout Section
21726 \begin_layout Standard
21728 \begin_inset LatexCommand \index{DS80C400}
21733 \begin_inset LatexCommand \index{DS400}
21737 microcontroller has a rich set of peripherals.
21738 In its built-in ROM library it includes functions to access some of the
21739 features, among them is a TCP stack with IP4 and IP6 support.
21740 Library headers (currently in beta status) and other files are provided
21744 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
21750 \begin_inset VSpace bigskip
21756 \begin_layout Section
21757 The Z80 and gbz80 port
21760 \begin_layout Standard
21761 SDCC can target both the Zilog Z80
21762 \begin_inset LatexCommand \index{Z80}
21766 and the Nintendo Gameboy's Z80-like gbz80
21767 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
21772 The Z80 port is passed through the same
21775 \begin_inset LatexCommand \index{Regression test}
21782 \begin_inset LatexCommand \ref{sec:Quality-control}
21786 ) as the MCS51 and DS390 ports, so floating point support, support for long
21787 variables and bitfield support is fine.
21788 See mailing lists and forums about interrupt routines.
21791 \begin_layout Standard
21792 As always, the code is the authoritative reference - see z80/ralloc.c and
21795 \begin_inset LatexCommand \index{Z80!stack}
21799 frame is similar to that generated by the IAR Z80 compiler.
21800 IX is used as the base pointer, HL and IY are used as a temporary registers,
21801 and BC and DE are available for holding variables.
21803 \begin_inset LatexCommand \index{Z80!return value}
21807 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
21809 The gbz80 port use the same set of registers for the return values, but
21810 in a different order of significance: E (one byte), DE (two bytes), or
21812 \begin_inset VSpace bigskip
21818 \begin_layout Section
21822 \begin_layout Standard
21823 The port to the Freescale/Motorola HC08
21824 \begin_inset LatexCommand \index{HC08}
21828 family has been added in October 2003, and is still undergoing some basic
21830 The code generator is complete, but the register allocation is still quite
21832 Some of the SDCC's standard C library functions have embedded non-HC08
21833 inline assembly and so are not yet usable.
21836 \begin_layout Standard
21837 The HC08 port passes the regression test suite (see section
21838 \begin_inset LatexCommand \ref{sec:Quality-control}
21843 \begin_inset VSpace bigskip
21851 \begin_layout Section
21855 \begin_layout Standard
21857 \begin_inset LatexCommand \index{PIC14}
21861 port still requires a major effort from the development community.
21862 However it can work for simple code.
21863 It passes its (smaller set of) regression tests
21864 \begin_inset LatexCommand \index{Regression test (PIC14)}
21870 sdcc/src/regression
21875 \begin_layout Subsection
21876 C code and 14bit PIC code page
21877 \begin_inset LatexCommand \index{code page (pic14)}
21882 \begin_inset LatexCommand \index{RAM bank (pic14)}
21889 \begin_layout Standard
21890 The linker organizes allocation for the code page and RAM banks.
21891 It does not have intimate knowledge of the code flow.
21892 It will put all the code section of a single asm file into a single code
21894 In order to make use of multiple code pages, separate asm files must be
21896 The compiler treats all functions of a single C file as being in the same
21897 code page unless it is non static.
21901 To get the best follow these guide lines:
21904 \begin_layout Enumerate
21905 Make local functions static, as non static functions require code page selection
21909 \begin_layout Enumerate
21910 For devices that have multiple code pages it is more efficient to use the
21911 same number of files as pages, i.e.
21912 for the 16F877 use 4 separate files and i.e.
21913 for the 16F874 use 2 separate files.
21914 This way the linker can put the code for each file into different code
21915 pages and there's less page selection overhead.
21918 \begin_layout Enumerate
21919 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
21920 instruction set), use 'unsigned char' whereever possible instead of 'int'.
21923 \begin_layout Subsection
21924 Creating a device include file
21927 \begin_layout Standard
21928 For generating a device include file
21929 \begin_inset LatexCommand \index{PIC14!Header files}
21933 use the support perl script inc2h.pl kept in directory support/script.
21936 \begin_layout Subsection
21940 \begin_layout Standard
21941 For the interrupt function, use the keyword '__interrupt'
21942 \begin_inset LatexCommand \index{PIC14!interrupt}
21946 with level number of 0 (PIC14 only has 1 interrupt so this number is only
21947 there to avoid a syntax error - it ought to be fixed).
21951 \begin_layout Verse
21954 void Intr(void) __interrupt 0
21960 T0IF = 0; /* Clear timer interrupt */
21965 \begin_layout Subsection
21966 Linking and assembling
21969 \begin_layout Standard
21970 For assembling you can use either GPUTILS'
21971 \begin_inset LatexCommand \index{gputils (pic tools)}
21975 gpasm.exe or MPLAB's mpasmwin.exe.
21976 GPUTILS is available from
21977 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21982 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21983 If you use MPLAB and an interrupt function then the linker script file
21984 vectors section will need to be enlarged to link with mplink.
21995 \begin_layout Verse
22008 sdcc -S -V -mpic14 -p16F877 $<
22022 $(PRJ).hex: $(OBJS)
22033 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22036 \begin_layout Standard
22044 \begin_layout Verse
22057 sdcc -S -V -mpic14 -p16F877 $<
22067 mpasmwin /q /o $*.asm
22071 $(PRJ).hex: $(OBJS)
22082 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22085 \begin_layout Standard
22086 Please note that indentations within a
22090 have to be done with a tabulator character.
22093 \begin_layout Subsection
22094 Command-line options
22097 \begin_layout Standard
22098 Besides the switches common to all SDCC backends, the PIC14 port accepts
22099 the following options (for an updated list see sdcc -
22103 \begin_layout Standard
22116 \labelwidthstring 00.00.0000
22121 \begin_layout Standard
22131 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22135 emit debug info in assembly output
22139 \labelwidthstring 00.00.0000
22144 \begin_layout Standard
22154 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22158 disable (slightly faulty) optimization on pCode
22162 \labelwidthstring 00.00.0000
22167 \begin_layout Standard
22177 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22181 sets the lowest address of the argument passing stack (defaults to a suitably
22182 large shared databank to reduce BANKSEL overhead)
22186 \labelwidthstring 00.00.0000
22191 \begin_layout Standard
22201 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22205 sets the size if the argument passing stack (default: 16, minimum: 4)
22208 \begin_layout Subsection
22212 \begin_layout Subsubsection
22213 error: missing definition for symbol
22214 \begin_inset Quotes sld
22218 \begin_inset Quotes srd
22224 \begin_layout Standard
22225 The PIC14 port uses library routines to provide more complex operations
22226 like multiplication, division/modulus and (generic) pointer dereferencing.
22227 In order to add these routines to your project, you must link with PIC14's
22233 For single source file projects this is done automatically, more complex
22238 to the linker's arguments.
22239 Make sure you also add an include path for the library (using the -I switch
22243 \begin_layout Subsubsection
22244 Processor mismatch in file
22245 \begin_inset Quotes sld
22249 \begin_inset Quotes srd
22255 \begin_layout Standard
22256 This warning can usually be ignored due to the very good compatibility amongst
22258 \begin_inset LatexCommand \index{PIC14}
22265 \begin_layout Standard
22266 You might also consider recompiling the library for your specific device
22267 by changing the ARCH=p16f877 (default target) entry in
22269 device/lib/pic/Makefile.in
22273 device/lib/pic/Makefile
22275 to reflect your device.
22276 This might even improve performance for smaller devices as unneccesary
22277 BANKSELs migth be removed.
22280 \begin_layout Subsection
22284 \begin_layout Subsubsection
22288 \begin_layout Standard
22289 Currently, data can only be initialized if it resides in the source file
22295 Data in other source files will silently
22303 \begin_inset Marginal
22306 \begin_layout Standard
22322 \begin_layout Section
22324 \begin_inset LatexCommand \index{PIC16}
22331 \begin_layout Standard
22333 \begin_inset LatexCommand \index{PIC16}
22337 port is the portion of SDCC that is responsible to produce code for the
22339 \begin_inset LatexCommand \index{Microchip}
22343 (TM) microcontrollers with 16 bit core.
22344 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22345 Currently supported devices are:
22348 \begin_layout Standard
22350 \begin_inset Tabular
22351 <lyxtabular version="3" rows="4" columns="6">
22353 <column alignment="center" valignment="top" leftline="true" width="0">
22354 <column alignment="center" valignment="top" leftline="true" width="0">
22355 <column alignment="center" valignment="top" leftline="true" width="0">
22356 <column alignment="center" valignment="top" leftline="true" width="0">
22357 <column alignment="center" valignment="top" leftline="true" width="0">
22358 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22359 <row topline="true">
22360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22363 \begin_layout Standard
22369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22372 \begin_layout Standard
22378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22381 \begin_layout Standard
22387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22390 \begin_layout Standard
22396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22399 \begin_layout Standard
22405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22408 \begin_layout Standard
22415 <row topline="true">
22416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22419 \begin_layout Standard
22425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22428 \begin_layout Standard
22434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22437 \begin_layout Standard
22443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22446 \begin_layout Standard
22452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22455 \begin_layout Standard
22461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22464 \begin_layout Standard
22471 <row topline="true">
22472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22475 \begin_layout Standard
22481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22484 \begin_layout Standard
22490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22493 \begin_layout Standard
22499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22502 \begin_layout Standard
22508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22511 \begin_layout Standard
22517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22520 \begin_layout Standard
22527 <row topline="true" bottomline="true">
22528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22531 \begin_layout Standard
22537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22540 \begin_layout Standard
22546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22549 \begin_layout Standard
22555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22558 \begin_layout Standard
22564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22567 \begin_layout Standard
22573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22576 \begin_layout Standard
22590 \begin_layout Subsection
22594 \begin_layout Standard
22595 PIC16 port supports the standard command line arguments as supposed, with
22596 the exception of certain cases that will be mentioned in the following
22601 \labelwidthstring 00.00.0000
22606 \begin_layout Standard
22616 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
22624 \begin_layout Standard
22637 \labelwidthstring 00.00.0000
22642 \begin_layout Standard
22652 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
22656 All function arguments are passed on stack by default.
22659 There is no need to specify this in the command line.
22663 \labelwidthstring 00.00.0000
22668 \begin_layout Standard
22677 -fommit-frame-pointer
22678 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
22682 Frame pointer will be omitted when the function uses no local variables.
22685 \begin_layout Subsection
22686 Port Specific Options
22687 \begin_inset LatexCommand \index{Options PIC16}
22694 \begin_layout Standard
22695 The port specific options appear after the global options in the sdcc --help
22699 \begin_layout Subsubsection
22703 \begin_layout Standard
22704 General options enable certain port features and optimizations.
22708 \labelwidthstring 00.00.0000
22713 \begin_layout Standard
22722 -pstack-model=[model] Used in conjuction with the command above.
22723 Defines the stack model to be used, valid stack models are :
22728 \labelwidthstring 00.00.0000
22733 Selects small stack model.
22734 8 bit stack and frame pointers.
22735 Supports 256 bytes stack size.
22739 \labelwidthstring 00.00.0000
22744 Selects large stack model.
22745 16 bit stack and frame pointers.
22746 Supports 65536 bytes stack size.
22751 \labelwidthstring 00.00.0000
22756 \begin_layout Standard
22765 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
22766 unitialized data variables with [kword].
22767 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
22771 \labelwidthstring 00.00.0000
22776 \begin_layout Standard
22785 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
22786 Useful for bootloaders.
22790 \labelwidthstring 00.00.0000
22795 \begin_layout Standard
22804 -asm= sets the full path and name of an external assembler to call.
22808 \labelwidthstring 00.00.0000
22813 \begin_layout Standard
22822 -link= sets the full path and name of an external linker to call.
22826 \labelwidthstring 00.00.0000
22831 \begin_layout Standard
22841 \begin_inset LatexCommand \index{PIC16!MPLAB}
22845 compatibility option.
22846 Currently only suppresses special gpasm directives.
22849 \begin_layout Subsubsection
22850 Optimization Options
22854 \labelwidthstring 00.00.0000
22859 \begin_layout Standard
22868 -optimize-goto Try to use (conditional) BRA instead of GOTO
22872 \labelwidthstring 00.00.0000
22877 \begin_layout Standard
22886 -optimize-cmp Try to optimize some compares.
22890 \labelwidthstring 00.00.0000
22895 \begin_layout Standard
22904 -optimize-df Analyze the dataflow of the generated code and improve it.
22908 \labelwidthstring 00.00.0000
22913 \begin_layout Standard
22922 -obanksel=nn Set optimization level for inserting BANKSELs.
22929 \labelwidthstring 00.00.0000
22934 \labelwidthstring 00.00.0000
22935 1 checks previous used register and if it is the same then does not emit
22936 BANKSEL, accounts only for labels.
22940 \labelwidthstring 00.00.0000
22941 2 tries to check the location of (even different) symbols and removes BANKSELs
22942 if they are in the same bank.
22947 Important: There might be problems if the linker script has data sections
22948 across bank borders!
22952 \begin_layout Subsubsection
22957 \labelwidthstring 00.00.0000
22962 \begin_layout Standard
22971 -nodefaultlibs do not link default libraries when linking
22975 \labelwidthstring 00.00.0000
22980 \begin_layout Standard
22989 -no-crt Don't link the default run-time modules
22993 \labelwidthstring 00.00.0000
22998 \begin_layout Standard
23007 -use-crt= Use a custom run-time module instead of the defaults.
23010 \begin_layout Subsubsection
23014 \begin_layout Standard
23015 Debugging options enable extra debugging information in the output files.
23019 \labelwidthstring 00.00.0000
23024 \begin_layout Standard
23033 -debug-xtra Similar to -
23037 \begin_layout Standard
23047 \begin_inset LatexCommand \index{-\/-debug}
23051 , but dumps more information.
23055 \labelwidthstring 00.00.0000
23060 \begin_layout Standard
23069 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23071 <source> is the name of the file compiled.
23075 \labelwidthstring 00.00.0000
23080 \begin_layout Standard
23089 -pcode-verbose Enable pcode debugging information in translation.
23093 \labelwidthstring 00.00.0000
23098 \begin_layout Standard
23107 -denable-peeps Force the usage of peepholes.
23112 \labelwidthstring 00.00.0000
23117 \begin_layout Standard
23126 -gstack Trace push/pops for stack pointer overflow
23130 \labelwidthstring 00.00.0000
23135 \begin_layout Standard
23144 -call-tree dump call tree in .calltree file
23147 \begin_layout Subsection
23148 Enviromental Variables
23151 \begin_layout Standard
23152 There is a number of enviromental variables that can be used when running
23153 SDCC to enable certain optimizations or force a specific program behaviour.
23154 these variables are primarily for debugging purposes so they can be enabled/dis
23158 \begin_layout Standard
23159 Currently there is only two such variables available:
23163 \labelwidthstring 00.00.0000
23164 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23165 bitfields is optimized by directly loading FSR0 with the address of the
23166 bitfield structure.
23167 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23169 This step saves data ram and code space for functions that perform heavy
23172 80 bytes of code space are saved when compiling malloc.c with this option).
23177 \labelwidthstring 00.00.0000
23178 NO_REG_OPT do not perform pCode registers optimization.
23179 This should be used for debugging purposes.
23180 In some where bugs in the pcode optimizer are found, users can benefit
23181 from temporarily disabling the optimizer until the bug is fixed.
23184 \begin_layout Subsection
23185 Preprocessor Macros
23188 \begin_layout Standard
23190 \begin_inset LatexCommand \index{PIC16}
23194 port defines the following preprocessor macros while translating a source.
23197 \begin_layout Standard
23199 \begin_inset Tabular
23200 <lyxtabular version="3" rows="6" columns="2">
23202 <column alignment="center" valignment="top" leftline="true" width="0">
23203 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23204 <row topline="true" bottomline="true">
23205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23208 \begin_layout Standard
23214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23217 \begin_layout Standard
23224 <row topline="true">
23225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23228 \begin_layout Standard
23234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23237 \begin_layout Standard
23238 Port identification
23244 <row topline="true">
23245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23248 \begin_layout Standard
23253 \begin_layout Standard
23267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23270 \begin_layout Standard
23271 Port identification (same as above)
23277 <row topline="true">
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23281 \begin_layout Standard
23287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23290 \begin_layout Standard
23291 MCU Identification.
23296 is the microcontrol identification number, i.e.
23303 <row topline="true">
23304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23307 \begin_layout Standard
23312 \begin_layout Standard
23326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23329 \begin_layout Standard
23330 MCU Identification (same as above)
23336 <row topline="true" bottomline="true">
23337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23340 \begin_layout Standard
23346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23349 \begin_layout Standard
23350 nnn = SMALL or LARGE respectively according to the stack model used
23363 \begin_layout Standard
23364 In addition the following macros are defined when calling assembler:
23367 \begin_layout Standard
23369 \begin_inset Tabular
23370 <lyxtabular version="3" rows="4" columns="2">
23372 <column alignment="center" valignment="top" leftline="true" width="0">
23373 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23374 <row topline="true" bottomline="true">
23375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23378 \begin_layout Standard
23384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23387 \begin_layout Standard
23394 <row topline="true">
23395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23398 \begin_layout Standard
23404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23407 \begin_layout Standard
23408 MCU Identification.
23413 is the microcontrol identification number, i.e.
23420 <row topline="true">
23421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23424 \begin_layout Standard
23430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23433 \begin_layout Standard
23434 nnn = SMALL or LARGE respectively according to the memory model used for
23441 <row topline="true" bottomline="true">
23442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23445 \begin_layout Standard
23451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23454 \begin_layout Standard
23455 nnn = SMALL or LARGE respectively according to the stack model used
23468 \begin_layout Subsection
23472 \begin_layout Standard
23474 \begin_inset LatexCommand \index{PIC16}
23478 port uses the following directories for searching header files and libraries.
23481 \begin_layout Standard
23483 \begin_inset Tabular
23484 <lyxtabular version="3" rows="3" columns="4">
23486 <column alignment="center" valignment="top" leftline="true" width="0">
23487 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23488 <column alignment="center" valignment="top" width="0">
23489 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23490 <row topline="true" bottomline="true">
23491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23494 \begin_layout Standard
23500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23503 \begin_layout Standard
23509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23512 \begin_layout Standard
23518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23521 \begin_layout Standard
23528 <row topline="true">
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23532 \begin_layout Standard
23533 PREFIX/sdcc/include/pic16
23538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23541 \begin_layout Standard
23542 PIC16 specific headers
23547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23550 \begin_layout Standard
23556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23559 \begin_layout Standard
23566 <row topline="true" bottomline="true">
23567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23570 \begin_layout Standard
23571 PREFIX/sdcc/lib/pic16
23576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23579 \begin_layout Standard
23580 PIC16 specific libraries
23585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23588 \begin_layout Standard
23594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23597 \begin_layout Standard
23611 \begin_layout Subsection
23613 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
23620 \begin_layout Standard
23622 \begin_inset LatexCommand \index{PIC16}
23626 port currently supports the following pragmas:
23630 \labelwidthstring 00.00.0000
23632 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
23637 \begin_inset LatexCommand \index{PIC16!stack}
23641 forces the code generator to initialize the stack & frame pointers at a
23643 This is an adhoc solution for cases where no STACK directive is available
23644 in the linker script or gplink is not instructed to create a stack section.
23647 stack pragma should be used only once in a project.
23648 Multiple pragmas may result in indeterminate behaviour of the program.
23652 \begin_layout Standard
23653 The old format (ie.
23654 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
23655 cross page boundaries (or even exceed the available data RAM) and crash
23657 Make sure that stack does not cross page boundaries when using the SMALL
23665 The format is as follows:
23668 \begin_layout LyX-Code
23669 #pragma stack bottom_address [stack_size]
23672 \begin_layout Standard
23677 is the lower bound of the stack section.
23678 The stack pointer initially will point at address (bottom_address+stack_size-1).
23681 \begin_layout LyX-Code
23685 \begin_layout LyX-Code
23689 \begin_layout LyX-Code
23690 /* initializes stack of 100 bytes at RAM address 0x200 */
23693 \begin_layout LyX-Code
23694 #pragma stack 0x200 100
23697 \begin_layout Standard
23698 If the stack_size field is omitted then a stack is created with the default
23700 This size might be enough for most programs, but its not enough for operations
23701 with deep function nesting or excessive stack usage.
23705 \labelwidthstring 00.00.0000
23707 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
23711 place a function symbol at static FLASH address
23714 \begin_layout LyX-Code
23718 \begin_layout LyX-Code
23722 \begin_layout LyX-Code
23723 /* place function test_func at 0x4000 */
23726 \begin_layout LyX-Code
23727 #pragma code test_func 0x4000
23730 \begin_layout LyX-Code
23735 \labelwidthstring 00.00.0000
23736 library instructs the linker to use a library module.
23741 \begin_layout LyX-Code
23742 #pragma library module_name
23745 \begin_layout Standard
23750 can be any library or object file (including its path).
23751 Note that there are four reserved keywords which have special meaning.
23755 \begin_layout Standard
23757 \begin_inset Tabular
23758 <lyxtabular version="3" rows="6" columns="3">
23760 <column alignment="center" valignment="top" leftline="true" width="0">
23761 <column alignment="block" valignment="top" leftline="true" width="20page%">
23762 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
23763 <row topline="true" bottomline="true">
23764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23767 \begin_layout Standard
23773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23776 \begin_layout Standard
23782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23785 \begin_layout Standard
23792 <row topline="true">
23793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23796 \begin_layout Standard
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23807 \begin_layout Standard
23808 ignore all library pragmas
23813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23816 \begin_layout Standard
23825 <row topline="true">
23826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23829 \begin_layout Standard
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23840 \begin_layout Standard
23846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23849 \begin_layout Standard
23860 <row topline="true">
23861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23864 \begin_layout Standard
23872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23875 \begin_layout Standard
23876 link the Math libarary
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23884 \begin_layout Standard
23895 <row topline="true">
23896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23899 \begin_layout Standard
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 \begin_layout Standard
23911 link the I/O library
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23919 \begin_layout Standard
23930 <row topline="true" bottomline="true">
23931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23934 \begin_layout Standard
23942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23945 \begin_layout Standard
23946 link the debug library
23951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23954 \begin_layout Standard
23971 * is the device number, i.e.
23972 452 for PIC18F452 MCU.
23975 \begin_layout Standard
23976 This feature allows for linking with specific libraries withoug having to
23977 explicit name them in the command line.
23982 keyword will reject all modules specified by the library pragma.
23986 \labelwidthstring 00.00.0000
23987 udata pragma udata instructs the compiler to emit code so that linker will
23988 place a variable at a specific memory bank
23991 \begin_layout LyX-Code
23995 \begin_layout LyX-Code
23999 \begin_layout LyX-Code
24000 /* places variable foo at bank2 */
24003 \begin_layout LyX-Code
24004 #pragma udata bank2 foo
24007 \begin_layout LyX-Code
24011 \begin_layout Standard
24012 In order for this pragma to work extra SECTION directives should be added
24013 in the .lkr script.
24014 In the following example a sample .lkr file is shown:
24017 \begin_layout LyX-Code
24021 \begin_layout LyX-Code
24022 // Sample linker script for the PIC18F452 processor
24025 \begin_layout LyX-Code
24029 \begin_layout LyX-Code
24030 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24033 \begin_layout LyX-Code
24034 CODEPAGE NAME=page START=0x2A END=0x7FFF
24037 \begin_layout LyX-Code
24038 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24041 \begin_layout LyX-Code
24042 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24045 \begin_layout LyX-Code
24046 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24049 \begin_layout LyX-Code
24050 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24053 \begin_layout LyX-Code
24054 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24057 \begin_layout LyX-Code
24061 \begin_layout LyX-Code
24062 DATABANK NAME=gpr0 START=0x80 END=0xFF
24065 \begin_layout LyX-Code
24066 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24069 \begin_layout LyX-Code
24070 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24073 \begin_layout LyX-Code
24074 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24077 \begin_layout LyX-Code
24078 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24081 \begin_layout LyX-Code
24082 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24085 \begin_layout LyX-Code
24086 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24089 \begin_layout LyX-Code
24093 \begin_layout LyX-Code
24094 SECTION NAME=CONFIG ROM=config
24097 \begin_layout LyX-Code
24101 \begin_layout LyX-Code
24102 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24105 \begin_layout LyX-Code
24106 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24109 \begin_layout LyX-Code
24110 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24113 \begin_layout LyX-Code
24114 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24117 \begin_layout LyX-Code
24118 SECTION NAME=bank4 RAM=gpr4
24121 \begin_layout LyX-Code
24122 SECTION NAME=bank5 RAM=gpr5
24125 \begin_layout Standard
24126 The linker will recognise the section name set in the pragma statement and
24127 will position the variable at the memory bank set with the RAM field at
24128 the SECTION line in the linker script file.
24131 \begin_layout Subsection
24133 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24140 \begin_layout Standard
24141 There is one main header file
24142 \begin_inset LatexCommand \index{PIC16!Header files}
24146 that can be included to the source files using the pic16
24147 \begin_inset LatexCommand \index{PIC16}
24157 This header file contains the definitions for the processor special registers,
24158 so it is necessary if the source accesses them.
24159 It can be included by adding the following line in the beginning of the
24163 \begin_layout LyX-Code
24164 #include <pic18fregs.h>
24167 \begin_layout Standard
24168 The specific microcontroller is selected within the pic18fregs.h automatically,
24169 so the same source can be used with a variety of devices.
24172 \begin_layout Subsection
24176 \begin_layout Standard
24178 \begin_inset LatexCommand \index{PIC16!Libraries}
24183 \begin_inset LatexCommand \index{PIC16}
24187 port depends on are the microcontroller device libraries which contain
24188 the symbol definitions for the microcontroller special function registers.
24189 These libraries have the format pic18fxxxx.lib, where
24193 is the microcontroller identification number.
24194 The specific library is selected automatically by the compiler at link
24195 stage according to the selected device.
24198 \begin_layout Standard
24199 Libraries are created with gplib which is part of the gputils package
24200 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24207 \begin_layout Subsubsection*
24208 Building the libraries
24211 \begin_layout Standard
24212 Before using SDCC/pic16 there are some libraries that need to be compiled.
24213 This process is not done automatically by SDCC since not all users use
24214 SDCC for pic16 projects.
24215 So each user should compile the libraries separately.
24218 \begin_layout Standard
24219 The steps to compile the pic16 libraries under Linux are:
24222 \begin_layout LyX-Code
24223 cd device/lib/pic16
24226 \begin_layout LyX-Code
24230 \begin_layout LyX-Code
24234 \begin_layout LyX-Code
24238 \begin_layout LyX-Code
24242 \begin_layout LyX-Code
24243 su -c 'make install' # install the libraries, you need the root password
24246 \begin_layout Standard
24247 If you need to install the headers too, do:
24250 \begin_layout LyX-Code
24254 \begin_layout LyX-Code
24255 su -c 'make install' # install the headers, you need the root password
24258 \begin_layout Standard
24259 There exist a special target to build the I/O libraries.
24260 This target is not automatically build because it will build the I/O library
24266 This way building will take quite a lot of time.
24267 Users are advised to edit the
24269 device/lib/pic16/pics.build
24271 file and then execute:
24274 \begin_layout LyX-Code
24278 \begin_layout Subsection
24282 \begin_layout Standard
24283 The following memory models are supported by the PIC16 port:
24286 \begin_layout Itemize
24290 \begin_layout Itemize
24294 \begin_layout Standard
24295 Memory model affects the default size of pointers within the source.
24296 The sizes are shown in the next table:
24299 \begin_layout Standard
24301 \begin_inset Tabular
24302 <lyxtabular version="3" rows="3" columns="3">
24304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24305 <column alignment="center" valignment="top" leftline="true" width="0">
24306 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24307 <row topline="true" bottomline="true">
24308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24311 \begin_layout Standard
24312 Pointer sizes according to memory model
24317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24320 \begin_layout Standard
24326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24329 \begin_layout Standard
24336 <row topline="true" bottomline="true">
24337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24340 \begin_layout Standard
24346 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24349 \begin_layout Standard
24355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24358 \begin_layout Standard
24365 <row topline="true" bottomline="true">
24366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24369 \begin_layout Standard
24375 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24378 \begin_layout Standard
24384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24387 \begin_layout Standard
24401 \begin_layout Standard
24402 It is advisable that all sources within a project are compiled with the
24404 If one wants to override the default memory model, this can be done by
24405 declaring a pointer as
24414 Far selects large memory model's pointers, while near selects small memory
24418 \begin_layout Standard
24419 The standard device libraries (see
24420 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
24424 ) contain no reference to pointers, so they can be used with both memory
24428 \begin_layout Subsection
24432 \begin_layout Standard
24434 \begin_inset LatexCommand \index{PIC16!stack}
24438 implementation for the PIC16 port uses two indirect registers, FSR1 and
24443 \labelwidthstring 00.00.0000
24444 FSR1 is assigned as stack pointer
24448 \labelwidthstring 00.00.0000
24449 FSR2 is assigned as frame pointer
24452 \begin_layout Standard
24453 The following stack models are supported by the PIC16 port
24456 \begin_layout Itemize
24464 \begin_layout Itemize
24472 \begin_layout Standard
24477 model means that only the FSRxL byte is used to access stack and frame,
24484 uses both FSRxL and FSRxH registers.
24485 The following table shows the stack/frame pointers sizes according to stack
24486 model and the maximum space they can address:
24489 \begin_layout Standard
24491 \begin_inset Tabular
24492 <lyxtabular version="3" rows="3" columns="3">
24494 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24495 <column alignment="center" valignment="top" leftline="true" width="0">
24496 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24497 <row topline="true" bottomline="true">
24498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24501 \begin_layout Standard
24502 Stack & Frame pointer sizes according to stack model
24507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24510 \begin_layout Standard
24516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24519 \begin_layout Standard
24526 <row topline="true">
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24530 \begin_layout Standard
24536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24539 \begin_layout Standard
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24548 \begin_layout Standard
24555 <row topline="true" bottomline="true">
24556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24559 \begin_layout Standard
24565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24568 \begin_layout Standard
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24577 \begin_layout Standard
24591 \begin_layout Standard
24596 stack model is currently not working properly throughout the code generator.
24597 So its use is not advised.
24598 Also there are some other points that need special care:
24603 \begin_layout Enumerate
24604 Do not create stack sections with size more than one physical bank (that
24608 \begin_layout Enumerate
24609 Stack sections should no cross physical bank limits (i.e.
24610 #pragma stack 0x50 0x100)
24613 \begin_layout Standard
24614 These limitations are caused by the fact that only FSRxL is modified when
24615 using SMALL stack model, so no more than 256 bytes of stack can be used.
24616 This problem will disappear after LARGE model is fully implemented.
24619 \begin_layout Subsection
24623 \begin_layout Standard
24624 In addition to the standard SDCC function keywords, PIC16
24625 \begin_inset LatexCommand \index{PIC16}
24629 port makes available two more:
24633 \labelwidthstring 00.00.0000
24635 \begin_inset LatexCommand \index{PIC16!wparam}
24639 Use the WREG to pass one byte of the first function argument.
24640 This improves speed but you may not use this for functions with arguments
24641 that are called via function pointers, otherwise the first byte of the
24642 first parameter will get lost.
24646 \begin_layout LyX-Code
24647 void func_wparam(int a) wparam
24650 \begin_layout LyX-Code
24654 \begin_layout LyX-Code
24655 /* WREG hold the lower part of a */
24658 \begin_layout LyX-Code
24659 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
24663 \begin_layout LyX-Code
24667 \begin_layout LyX-Code
24672 \labelwidthstring 00.00.0000
24674 \begin_inset LatexCommand \index{PIC16!shadowregs}
24678 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
24679 hardware shadow registers which hold the values of WREG, STATUS and BSR
24681 This can be done by adding the keyword
24689 keyword in the function's header.
24692 \begin_layout LyX-Code
24693 void isr_shadow(void) shadowregs interrupt 1
24696 \begin_layout LyX-Code
24700 \begin_layout LyX-Code
24704 \begin_layout LyX-Code
24708 \begin_layout Standard
24713 instructs the code generator not to store/restore WREG, STATUS, BSR when
24714 entering/exiting the ISR.
24717 \begin_layout Subsection
24718 Function return values
24721 \begin_layout Standard
24722 Return values from functions are placed to the appropriate registers following
24723 a modified Microchip policy optimized for SDCC.
24724 The following table shows these registers:
24727 \begin_layout Standard
24729 \begin_inset Tabular
24730 <lyxtabular version="3" rows="6" columns="2">
24732 <column alignment="center" valignment="top" leftline="true" width="0">
24733 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24734 <row topline="true" bottomline="true">
24735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24738 \begin_layout Standard
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24747 \begin_layout Standard
24748 destination register
24754 <row topline="true">
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24758 \begin_layout Standard
24764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24767 \begin_layout Standard
24774 <row topline="true">
24775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24778 \begin_layout Standard
24784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24787 \begin_layout Standard
24794 <row topline="true">
24795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24798 \begin_layout Standard
24804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24807 \begin_layout Standard
24814 <row topline="true">
24815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24818 \begin_layout Standard
24824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24827 \begin_layout Standard
24828 FSR0L:PRODH:PRODL:WREG
24834 <row topline="true" bottomline="true">
24835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24838 \begin_layout Standard
24844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24847 \begin_layout Standard
24848 on stack, FSR0 points to the beginning
24861 \begin_layout Subsection
24865 \begin_layout Standard
24867 \begin_inset LatexCommand \index{PIC16!interrupt}
24871 service routine (ISR) is declared using the
24878 \begin_layout LyX-Code
24879 void isr(void) interrupt
24884 \begin_layout LyX-Code
24888 \begin_layout LyX-Code
24892 \begin_layout LyX-Code
24896 \begin_layout Standard
24901 is the interrupt number, which for PIC18F devices can be:
24904 \begin_layout Standard
24906 \begin_inset Tabular
24907 <lyxtabular version="3" rows="4" columns="3">
24909 <column alignment="center" valignment="top" leftline="true" width="0">
24910 <column alignment="center" valignment="top" leftline="true" width="0">
24911 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24912 <row topline="true" bottomline="true">
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24916 \begin_layout Standard
24924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24927 \begin_layout Standard
24933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24936 \begin_layout Standard
24937 Interrupt Vector Address
24943 <row topline="true">
24944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24947 \begin_layout Standard
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24956 \begin_layout Standard
24962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24965 \begin_layout Standard
24972 <row topline="true">
24973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24976 \begin_layout Standard
24991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24994 \begin_layout Standard
25004 HIGH priority interrupts
25009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25012 \begin_layout Standard
25019 <row topline="true" bottomline="true">
25020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25023 \begin_layout Standard
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25032 \begin_layout Standard
25033 LOW priority interrupts
25038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25041 \begin_layout Standard
25055 \begin_layout Standard
25056 When generating assembly code for ISR the code generator places a
25062 Interrupt Vector Address
25064 which points at the genetated ISR.
25065 This single GOTO instruction is part of an automatically generated
25067 interrupt entry point
25070 The actuall ISR code is placed as normally would in the code space.
25071 Upon interrupt request, the GOTO instruction is executed which jumps to
25073 When declaring interrupt functions as _naked this GOTO instruction is
25078 The whole interrupt functions is therefore placed at the Interrupt Vector
25079 Address of the specific interrupt.
25080 This is not a problem for the LOW priority interrupts, but it is a problem
25081 for the RESET and the HIGH priority interrupts because code may be written
25082 at the next interrupt´s vector address and cause undeterminate program
25083 behaviour if that interrupt is raised.
25087 \begin_layout Standard
25088 This is not a problem when
25091 \begin_layout Enumerate
25092 this is a HIGH interrupt ISR and LOW interrupts are
25099 \begin_layout Enumerate
25100 when the ISR is small enough not to reach the next interrupt´s vector address.
25108 \begin_layout Standard
25113 is possible to be omitted.
25114 This way a function is generated similar to an ISR, but it is not assigned
25118 \begin_layout Standard
25119 When entering an interrupt, currently the PIC16
25120 \begin_inset LatexCommand \index{PIC16}
25124 port automatically saves the following registers:
25127 \begin_layout Itemize
25131 \begin_layout Itemize
25135 \begin_layout Itemize
25139 \begin_layout Itemize
25140 PROD (PRODL and PRODH)
25143 \begin_layout Itemize
25144 FSR0 (FSR0L and FSR0H)
25147 \begin_layout Standard
25148 These registers are restored upon return from the interrupt routine.
25152 \begin_layout Standard
25153 NOTE that when the _naked attribute is specified for an interrupt routine,
25154 then NO registers are stored or restored.
25162 \begin_layout Subsection
25166 \begin_layout Standard
25167 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25168 There are 3 types of generic pointers currently implemented data, code
25169 and eeprom pointers.
25170 They are differentiated by the value of the 7th and 6th bits of the upper
25174 \begin_layout Standard
25176 \begin_inset Tabular
25177 <lyxtabular version="3" rows="5" columns="5">
25179 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25180 <column alignment="center" valignment="top" width="0">
25181 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25182 <column alignment="center" valignment="top" width="0">
25183 <column alignment="left" valignment="top" rightline="true" width="0">
25184 <row topline="true" bottomline="true">
25185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25188 \begin_layout Standard
25194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25197 \begin_layout Standard
25203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25206 \begin_layout Standard
25212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25215 \begin_layout Standard
25216 rest of the pointer
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25224 \begin_layout Standard
25231 <row topline="true" bottomline="true">
25232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25235 \begin_layout Standard
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25244 \begin_layout Standard
25250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
25267 uuuuuu uuuuxxxx xxxxxxxx
25272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25275 \begin_layout Standard
25276 a 12-bit data pointer in data RAM memory
25282 <row bottomline="true">
25283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25286 \begin_layout Standard
25292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25295 \begin_layout Standard
25301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25304 \begin_layout Standard
25310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25313 \begin_layout Standard
25318 uxxxxx xxxxxxxx xxxxxxxx
25323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25326 \begin_layout Standard
25327 a 21-bit code pointer in FLASH memory
25333 <row bottomline="true">
25334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25337 \begin_layout Standard
25343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25346 \begin_layout Standard
25352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25355 \begin_layout Standard
25361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25364 \begin_layout Standard
25369 uuuuuu uuuuuuxx xxxxxxxx
25374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25377 \begin_layout Standard
25378 a 10-bit eeprom pointer in EEPROM memory
25384 <row bottomline="true">
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25388 \begin_layout Standard
25394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25397 \begin_layout Standard
25403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25406 \begin_layout Standard
25412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25415 \begin_layout Standard
25420 xxxxxx xxxxxxxx xxxxxxxx
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25428 \begin_layout Standard
25429 unimplemented pointer type
25442 \begin_layout Standard
25443 Generic pointer are read and written with a set of library functions which
25444 read/write 1, 2, 3, 4 bytes.
25447 \begin_layout Subsection
25451 \begin_layout Subsubsection
25452 Standard I/O Streams
25455 \begin_layout Standard
25460 the type FILE is defined as:
25463 \begin_layout LyX-Code
25464 typedef char * FILE;
25467 \begin_layout Standard
25468 This type is the stream type implemented I/O in the PIC18F devices.
25469 Also the standard input and output streams are declared in stdio.h:
25472 \begin_layout LyX-Code
25473 extern FILE * stdin;
25476 \begin_layout LyX-Code
25477 extern FILE * stdout;
25480 \begin_layout Standard
25481 The FILE type is actually a generic pointer which defines one more type
25482 of generic pointers, the
25487 This new type has the format:
25490 \begin_layout Standard
25492 \begin_inset Tabular
25493 <lyxtabular version="3" rows="2" columns="7">
25495 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25496 <column alignment="center" valignment="top" width="0">
25497 <column alignment="center" valignment="top" leftline="true" width="0">
25498 <column alignment="center" valignment="top" leftline="true" width="0">
25499 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25500 <column alignment="center" valignment="top" width="0">
25501 <column alignment="left" valignment="top" rightline="true" width="0">
25502 <row topline="true" bottomline="true">
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25506 \begin_layout Standard
25512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25515 \begin_layout Standard
25521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25524 \begin_layout Standard
25530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25533 \begin_layout Standard
25539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25542 \begin_layout Standard
25548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25551 \begin_layout Standard
25552 rest of the pointer
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25560 \begin_layout Standard
25567 <row topline="true" bottomline="true">
25568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25571 \begin_layout Standard
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25580 \begin_layout Standard
25586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25589 \begin_layout Standard
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25598 \begin_layout Standard
25604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25607 \begin_layout Standard
25613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25616 \begin_layout Standard
25626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25629 \begin_layout Standard
25630 upper byte high nubble is 0x2n, the rest are zeroes
25643 \begin_layout Standard
25644 Currently implemented there are 3 types of streams defined:
25647 \begin_layout Standard
25649 \begin_inset Tabular
25650 <lyxtabular version="3" rows="4" columns="4">
25652 <column alignment="center" valignment="top" leftline="true" width="0">
25653 <column alignment="center" valignment="top" leftline="true" width="0">
25654 <column alignment="center" valignment="top" leftline="true" width="0">
25655 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25656 <row topline="true" bottomline="true">
25657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25660 \begin_layout Standard
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25669 \begin_layout Standard
25675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25678 \begin_layout Standard
25684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25687 \begin_layout Standard
25694 <row topline="true">
25695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25698 \begin_layout Standard
25704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25707 \begin_layout Standard
25715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25718 \begin_layout Standard
25724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25727 \begin_layout Standard
25728 Writes/Reads characters via the USART peripheral
25734 <row topline="true">
25735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25738 \begin_layout Standard
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25747 \begin_layout Standard
25755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25758 \begin_layout Standard
25764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25767 \begin_layout Standard
25768 Writes/Reads characters via the MSSP peripheral
25774 <row topline="true" bottomline="true">
25775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25778 \begin_layout Standard
25784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25787 \begin_layout Standard
25795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25798 \begin_layout Standard
25804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25807 \begin_layout Standard
25808 Writes/Reads characters via used defined functions
25821 \begin_layout Standard
25822 The stream identifiers are declared as macros in the stdio.h header.
25825 \begin_layout Standard
25826 In the libc library there exist the functions that are used to write to
25827 each of the above streams.
25832 \labelwidthstring 00.00.0000
25837 \begin_layout Standard
25846 _stream_usart_putchar writes a character at the USART stream
25850 \labelwidthstring 00.00.0000
25855 \begin_layout Standard
25864 _stream_mssp_putchar writes a character at the MSSP stream
25868 \labelwidthstring 00.00.0000
25869 putchar dummy function.
25870 This writes a character to a user specified manner.
25873 \begin_layout Standard
25874 In order to increase performance
25878 is declared in stdio.h as having its parameter in WREG (it has the wparam
25880 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
25881 in a user-friendly way.
25886 is the name of the variable that holds the character to print.
25887 An example follows:
25890 \begin_layout LyX-Code
25891 #include <pic18fregs.h>
25900 \begin_layout LyX-Code
25904 \begin_layout LyX-Code
25905 PORTA = c; /* dump character c to PORTA */
25908 \begin_layout LyX-Code
25916 \begin_layout LyX-Code
25920 \begin_layout LyX-Code
25921 stdout = STREAM_USER; /* this is not necessary, since stdout points
25924 \begin_layout LyX-Code
25925 * by default to STREAM_USER */
25928 \begin_layout LyX-Code
25929 printf (¨This is a printf test
25934 \begin_layout LyX-Code
25938 \begin_layout LyX-Code
25942 \begin_layout Subsubsection
25946 \begin_layout Standard
25947 PIC16 contains an implementation of the printf-family of functions.
25948 There exist the following functions:
25951 \begin_layout LyX-Code
25952 extern unsigned int sprintf(char *buf, char *fmt, ...);
25955 \begin_layout LyX-Code
25956 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25959 \begin_layout LyX-Code
25963 \begin_layout LyX-Code
25964 extern unsigned int printf(char *fmt, ...);
25967 \begin_layout LyX-Code
25968 extern unsigned int vprintf(char *fmt, va_lista ap);
25971 \begin_layout LyX-Code
25975 \begin_layout LyX-Code
25976 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25979 \begin_layout LyX-Code
25980 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25983 \begin_layout Standard
25984 For sprintf and vsprintf
25988 should normally be a data pointer where the resulting string will be placed.
25989 No range checking is done so the user should allocate the necessery buffer.
25990 For fprintf and vfprintf
25994 should be a stream pointer (i.e.
25995 stdout, STREAM_MSSP, etc...).
25998 \begin_layout Subsubsection
26002 \begin_layout Standard
26003 The PIC18F family of microcontrollers supports a number of interrupt sources.
26004 A list of these interrupts is shown in the following table:
26007 \begin_layout Standard
26009 \begin_inset Tabular
26010 <lyxtabular version="3" rows="11" columns="4">
26012 <column alignment="left" valignment="top" leftline="true" width="0">
26013 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26014 <column alignment="left" valignment="top" leftline="true" width="0">
26015 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26016 <row topline="true" bottomline="true">
26017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26020 \begin_layout Standard
26026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26029 \begin_layout Standard
26035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26038 \begin_layout Standard
26044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26047 \begin_layout Standard
26054 <row topline="true">
26055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26058 \begin_layout Standard
26064 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26067 \begin_layout Standard
26068 PORTB change interrupt
26073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26076 \begin_layout Standard
26082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26085 \begin_layout Standard
26086 EEPROM/FLASH write complete interrupt
26092 <row topline="true">
26093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26096 \begin_layout Standard
26102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26105 \begin_layout Standard
26106 INT0 external interrupt
26111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26114 \begin_layout Standard
26120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26123 \begin_layout Standard
26124 Bus collision interrupt
26130 <row topline="true">
26131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26134 \begin_layout Standard
26140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26143 \begin_layout Standard
26144 INT1 external interrupt
26149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26152 \begin_layout Standard
26158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26161 \begin_layout Standard
26162 Low voltage detect interrupt
26168 <row topline="true">
26169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26172 \begin_layout Standard
26178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26181 \begin_layout Standard
26182 INT2 external interrupt
26187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26190 \begin_layout Standard
26196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26199 \begin_layout Standard
26200 Parallel slave port interrupt
26206 <row topline="true">
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26210 \begin_layout Standard
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26219 \begin_layout Standard
26220 CCP1 module interrupt
26225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26228 \begin_layout Standard
26234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26237 \begin_layout Standard
26238 AD convertion complete interrupt
26244 <row topline="true">
26245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26248 \begin_layout Standard
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26257 \begin_layout Standard
26258 CCP2 module interrupt
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26266 \begin_layout Standard
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26275 \begin_layout Standard
26276 USART receive interrupt
26282 <row topline="true">
26283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26286 \begin_layout Standard
26292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26295 \begin_layout Standard
26296 TMR0 overflow interrupt
26301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26304 \begin_layout Standard
26310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26313 \begin_layout Standard
26314 USART transmit interrupt
26320 <row topline="true">
26321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26324 \begin_layout Standard
26330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26333 \begin_layout Standard
26334 TMR1 overflow interrupt
26339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26342 \begin_layout Standard
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26351 \begin_layout Standard
26352 SSP receive/transmit interrupt
26358 <row topline="true">
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26362 \begin_layout Standard
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26371 \begin_layout Standard
26372 TMR2 matches PR2 interrupt
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26380 \begin_layout Standard
26386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26389 \begin_layout Standard
26396 <row topline="true" bottomline="true">
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26400 \begin_layout Standard
26406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26409 \begin_layout Standard
26410 TMR3 overflow interrupt
26415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26418 \begin_layout Standard
26424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26427 \begin_layout Standard
26441 \begin_layout Standard
26442 The prototypes for these names are defined in the header file
26449 \begin_layout Standard
26450 In order to simplify signal handling, a number of macros is provided:
26454 \labelwidthstring 00.00.0000
26455 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
26456 high priority interrupts.
26461 is the function name to use.
26465 \labelwidthstring 00.00.0000
26466 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
26467 low priority interrupt.
26472 is the function name to use.
26476 \labelwidthstring 00.00.0000
26477 DEF_HANDLER(sig,handler) define a handler for signal
26483 \labelwidthstring 00.00.0000
26484 END_DEF end the declaration of the dispatch table.
26487 \begin_layout Standard
26488 Additionally there are two more macros to simplify the declaration of the
26493 \labelwidthstring 00.00.0000
26496 SIGHANDLER(handler)
26498 this declares the function prototype for the
26506 \labelwidthstring 00.00.0000
26507 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
26510 \begin_layout Standard
26511 An example of using the macros above is shown below:
26514 \begin_layout LyX-Code
26515 #include <pic18fregs.h>
26518 \begin_layout LyX-Code
26519 #include <signal.h>
26523 DEF_INTHIGH(high_int)
26526 \begin_layout LyX-Code
26527 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
26530 \begin_layout LyX-Code
26531 DEF_HANDLER(SIG_BCOL, _bcol_handler)
26534 \begin_layout LyX-Code
26539 SIGHANDLER(_tmr0_handler)
26542 \begin_layout LyX-Code
26546 \begin_layout LyX-Code
26547 /* action to be taken when timer 0 overflows */
26550 \begin_layout LyX-Code
26555 SIGHANDLERNAKED(_bcol_handler)
26558 \begin_layout LyX-Code
26562 \begin_layout LyX-Code
26566 \begin_layout LyX-Code
26567 /* action to be taken when bus collision occurs */
26570 \begin_layout LyX-Code
26574 \begin_layout LyX-Code
26578 \begin_layout LyX-Code
26582 \begin_layout Standard
26587 Special care should be taken when using the above scheme:
26590 \begin_layout Itemize
26591 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
26594 \begin_layout Itemize
26595 when declaring SIGHANDLERNAKED handler never forget to use
26599 for proper returning.
26602 \begin_layout Subsection
26606 \begin_layout Standard
26607 Here you can find some general tips for compiling programs with SDCC/pic16.
26610 \begin_layout Subsubsection
26614 \begin_layout Standard
26616 \begin_inset LatexCommand \index{PIC16!stack}
26620 size (that is 64 bytes) probably is enough for many programs.
26621 One must take care that when there are many levels of function nesting,
26622 or there is excessive usage of stack, its size should be extended.
26623 An example of such a case is the printf/sprintf family of functions.
26624 If you encounter problems like not being able to print integers, then you
26625 need to set the stack size around the maximum (256 for small stack model).
26626 The following diagram shows what happens when calling printf to print an
26630 \begin_layout LyX-Code
26631 printf () --> ltoa () --> ultoa () --> divschar ()
26634 \begin_layout Standard
26635 It is should be understood that stack is easily consumed when calling complicate
26637 Using command line arguments like -
26641 \begin_layout Standard
26650 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
26652 Other ways to reduce stack usage may exist.
26655 \begin_layout Subsection
26659 \begin_layout Standard
26660 The PIC16 Port currently does not pass SDCC's regression test
26661 \begin_inset LatexCommand \index{Regression test (PIC16)}
26666 \begin_inset LatexCommand \ref{sec:Quality-control}
26670 ) and thus the snapshot build regression tests for the PIC16 target are
26671 currently disabled for all hosts
26676 \begin_layout Chapter
26680 \begin_layout Standard
26681 There are several approaches to debugging your code.
26682 This chapter is meant to show your options and to give detail on some of
26687 When writing your code:
26690 \begin_layout Itemize
26691 write your code with debugging in mind (avoid duplicating code, put conceptually
26692 similar variables into structs, use structured code, have strategic points
26693 within your code where all variables are consistent, ...)
26696 \begin_layout Itemize
26697 run a syntax-checking tool like splint
26698 \begin_inset LatexCommand \index{splint (syntax checking tool)}
26703 \begin_inset LatexCommand \index{lint (syntax checking tool)}
26711 \begin_layout Standard
26721 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
26728 \begin_layout Itemize
26729 for the high level code use a C-compiler (like f.e.
26730 GCC) to compile run and debug the code on your host.
26735 \begin_layout Standard
26745 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
26749 ) on howto handle syntax extensions like __xdata, __at(), ...
26753 \begin_layout Itemize
26754 use another C-compiler to compile code for your target.
26755 Always an option but not recommended:) And not very likely to help you.
26756 If you seriously consider walking this path you should at least occasionally
26757 check portability of your code.
26758 Most commercial compiler vendors will offer an evaluation version so you
26759 can test compile your code or snippets of your code.
26762 \begin_layout Standard
26763 Debugging on a simulator:
26766 \begin_layout Itemize
26767 there is a separate section about SDCDB (section
26768 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
26775 \begin_layout Itemize
26776 or (8051 specific) use a freeware/commercial simulator which interfaces
26778 \begin_inset LatexCommand \index{AOMF, AOMF51}
26783 \begin_inset LatexCommand \ref{OMF file}
26787 ) optionally generated by SDCC.
26790 \begin_layout Standard
26791 Debugging On-target:
26794 \begin_layout Itemize
26795 use a MCU port pin to serially output debug data to the RS232 port of your
26797 You'll probably want some level shifting device typically involving a MAX232
26799 If the hardware serial port of the MCU is not available search for 'Software
26800 UART' in your favourite search machine.
26803 \begin_layout Itemize
26804 use an on-target monitor.
26805 In this context a monitor is a small program which usually accepts commands
26806 via a serial line and allows to set program counter, to single step through
26807 a program and read/write memory locations.
26808 For the 8051 good examples of monitors are paulmon and cmon51 (see section
26810 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
26817 \begin_layout Itemize
26818 toggle MCU port pins at strategic points within your code and use an oscilloscop
26822 digital oscilloscope
26825 \begin_inset LatexCommand \index{Oscilloscope}
26829 with deep trace memory is really helpful especially if you have to debug
26830 a realtime application.
26831 If you need to monitor more pins than your oscilloscope provides you can
26832 sometimes get away with a small R-2R network.
26833 On a single channel oscilloscope you could f.e.
26834 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
26836 \begin_inset Formula $\Omega$
26839 resistor and the other one by a 5\InsetSpace ~
26841 \begin_inset Formula $\Omega$
26844 resistor to the oscilloscope probe (check output drive capability of the
26845 pins you want to monitor).
26846 If you need to monitor many more pins a
26853 \begin_layout Itemize
26867 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
26872 Usually very expensive.
26873 And very nice to have too.
26874 And usually locks you (for years...) to the devices the ICE can emulate.
26878 \begin_layout Itemize
26879 use a remote debugger.
26880 In most 8-bit systems the symbol information is not available on the target,
26881 and a complete debugger is too bulky for the target system.
26882 Therefore usually a debugger on the host system connects to an on-target
26883 debugging stub which accepts only primitive commands.
26886 Terms to enter into your favourite search engine could be 'remote debugging',
26887 'gdb stub' or 'inferior debugger'.
26891 \begin_layout Itemize
26892 use an on target hardware debugger.
26893 Some of the more modern MCUs include hardware support for setting break
26894 points and monitoring/changing variables by using dedicated hardware pins.
26895 This facility doesn't require additional code to run on the target and
26900 doesn't affect runtime behaviour until a breakpoint is hit.
26901 For the mcs51 most hardware debuggers use the AOMF
26902 \begin_inset LatexCommand \index{AOMF, AOMF51}
26907 \begin_inset LatexCommand \ref{OMF file}
26915 \begin_layout Standard
26919 \begin_layout Itemize
26920 if you are not familiar with any of the following terms you're likely to
26921 run into problems rather sooner than later:
26938 As an embedded programmer you
26942 to know them so why not look them up
26946 you have problems?)
26949 \begin_layout Itemize
26950 tell someone else about your problem (actually this is a surprisingly effective
26951 means to hunt down the bug even if the listener is not familiar with your
26953 As 'failure to communicate' is probably one of the job-induced deformations
26954 of an embedded programmer this is highly encouraged.
26957 \begin_layout Section
26958 Debugging with SDCDB
26959 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26964 \begin_inset LatexCommand \index{SDCDB (debugger)}
26971 \begin_layout Standard
26972 SDCC is distributed with a source level debugger
26973 \begin_inset LatexCommand \index{Debugger}
26978 The debugger uses a command line interface, the command repertoire of the
26979 debugger has been kept as close to gdb
26980 \begin_inset LatexCommand \index{gdb}
26984 (the GNU debugger) as possible.
26985 The configuration and build process is part of the standard compiler installati
26986 on, which also builds and installs the debugger in the target directory
26987 specified during configuration.
26988 The debugger allows you debug BOTH at the C source and at the ASM source
26992 \begin_layout Subsection
26993 Compiling for Debugging
26996 \begin_layout Standard
27001 \begin_layout Standard
27011 \begin_inset LatexCommand \index{-\/-debug}
27015 option must be specified for all files for which debug information is to
27017 The compiler generates a .adb file for each of these files.
27018 The linker creates the .cdb
27019 \begin_inset LatexCommand \index{<file>.cdb}
27024 \begin_inset LatexCommand \index{<file>.adb}
27028 files and the address information.
27029 This .cdb is used by the debugger.
27032 \begin_layout Subsection
27033 How the Debugger Works
27036 \begin_layout Standard
27041 \begin_layout Standard
27050 -debug option is specified the compiler generates extra symbol information
27051 some of which are put into the assembler source and some are put into the
27053 Then the linker creates the .cdb file from the individual .adb files with
27054 the address information for the symbols.
27055 The debugger reads the symbolic information generated by the compiler &
27056 the address information generated by the linker.
27057 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27058 execution is controlled by the debugger.
27059 When a command is issued for the debugger, it translates it into appropriate
27060 commands for the simulator.
27061 (Currently SDCDM only connects to the simulator but
27066 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27070 is an effort to connect directly to the hardware.)
27073 \begin_layout Subsection
27074 Starting the Debugger SDCDB
27077 \begin_layout Standard
27078 The debugger can be started using the following command line.
27079 (Assume the file you are debugging has the file name foo).
27093 The debugger will look for the following files.
27096 \begin_layout Itemize
27097 foo.c - the source file.
27100 \begin_layout Itemize
27101 foo.cdb - the debugger symbol information file.
27104 \begin_layout Itemize
27105 foo.ihx - the Intel hex format
27106 \begin_inset LatexCommand \index{Intel hex format}
27113 \begin_layout Subsection
27114 SDCDB Command Line Options
27117 \begin_layout Itemize
27122 \begin_layout Standard
27131 -directory=<source file directory> this option can used to specify the directory
27133 The debugger will look into the directory list specified for source, cdb
27135 The items in the directory list must be separated by ':', e.g.
27136 if the source files can be in the directories /home/src1 and /home/src2,
27141 \begin_layout Standard
27150 -directory option should be -
27154 \begin_layout Standard
27163 -directory=/home/src1:/home/src2.
27164 Note there can be no spaces in the option.
27168 \begin_layout Itemize
27169 -cd <directory> - change to the <directory>.
27172 \begin_layout Itemize
27173 -fullname - used by GUI front ends.
27176 \begin_layout Itemize
27177 -cpu <cpu-type> - this argument is passed to the simulator please see the
27178 simulator docs for details.
27181 \begin_layout Itemize
27182 -X <Clock frequency > this options is passed to the simulator please see
27183 the simulator docs for details.
27186 \begin_layout Itemize
27187 -s <serial port file> passed to simulator see the simulator docs for details.
27190 \begin_layout Itemize
27191 -S <serial in,out> passed to simulator see the simulator docs for details.
27194 \begin_layout Itemize
27195 -k <port number> passed to simulator see the simulator docs for details.
27198 \begin_layout Subsection
27199 SDCDB Debugger Commands
27202 \begin_layout Standard
27203 As mentioned earlier the command interface for the debugger has been deliberatel
27204 y kept as close the GNU debugger gdb, as possible.
27205 This will help the integration with existing graphical user interfaces
27206 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27207 If you use a graphical user interface for the debugger you can skip this
27211 \begin_layout Subsubsection*
27212 break [line | file:line | function | file:function]
27215 \begin_layout Standard
27216 Set breakpoint at specified line or function:
27225 sdcdb>break foo.c:100
27227 sdcdb>break funcfoo
27229 sdcdb>break foo.c:funcfoo
27232 \begin_layout Subsubsection*
27233 clear [line | file:line | function | file:function ]
27236 \begin_layout Standard
27237 Clear breakpoint at specified line or function:
27246 sdcdb>clear foo.c:100
27248 sdcdb>clear funcfoo
27250 sdcdb>clear foo.c:funcfoo
27253 \begin_layout Subsubsection*
27257 \begin_layout Standard
27258 Continue program being debugged, after breakpoint.
27261 \begin_layout Subsubsection*
27265 \begin_layout Standard
27266 Execute till the end of the current function.
27269 \begin_layout Subsubsection*
27273 \begin_layout Standard
27274 Delete breakpoint number 'n'.
27275 If used without any option clear ALL user defined break points.
27278 \begin_layout Subsubsection*
27279 info [break | stack | frame | registers ]
27282 \begin_layout Itemize
27283 info break - list all breakpoints
27286 \begin_layout Itemize
27287 info stack - show the function call stack.
27290 \begin_layout Itemize
27291 info frame - show information about the current execution frame.
27294 \begin_layout Itemize
27295 info registers - show content of all registers.
27298 \begin_layout Subsubsection*
27302 \begin_layout Standard
27303 Step program until it reaches a different source line.
27304 Note: pressing <return> repeats the last command.
27307 \begin_layout Subsubsection*
27311 \begin_layout Standard
27312 Step program, proceeding through subroutine calls.
27315 \begin_layout Subsubsection*
27319 \begin_layout Standard
27320 Start debugged program.
27323 \begin_layout Subsubsection*
27327 \begin_layout Standard
27328 Print type information of the variable.
27331 \begin_layout Subsubsection*
27335 \begin_layout Standard
27336 print value of variable.
27339 \begin_layout Subsubsection*
27343 \begin_layout Standard
27344 load the given file name.
27345 Note this is an alternate method of loading file for debugging.
27348 \begin_layout Subsubsection*
27352 \begin_layout Standard
27353 print information about current frame.
27356 \begin_layout Subsubsection*
27360 \begin_layout Standard
27361 Toggle between C source & assembly source.
27364 \begin_layout Subsubsection*
27365 ! simulator command
27368 \begin_layout Standard
27369 Send the string following '!' to the simulator, the simulator response is
27371 Note the debugger does not interpret the command being sent to the simulator,
27372 so if a command like 'go' is sent the debugger can loose its execution
27373 context and may display incorrect values.
27376 \begin_layout Subsubsection*
27380 \begin_layout Standard
27383 My name is Bobby Brown"
27386 \begin_layout Subsection
27387 Interfacing SDCDB with DDD
27390 \begin_layout Standard
27391 \begin_inset Note Note
27394 \begin_layout Standard
27395 The screenshot was converted from png to eps with:
27396 \begin_inset Quotes sld
27399 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
27400 \begin_inset Quotes srd
27403 which produces a pretty compact eps file which is free from compression
27407 \begin_layout Standard
27408 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
27409 as this broke the build system on Sourceforge (pdf-file was broken.
27410 pdflatex does not accept eps files).
27418 \begin_layout Standard
27434 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
27440 shows a screenshot of a debugging session with DDD
27441 \begin_inset LatexCommand \index{DDD (debugger)}
27445 (Unix only) on a simulated 8032.
27446 The debugging session might not run as smoothly as the screenshot suggests.
27447 The debugger allows setting of breakpoints, displaying and changing variables,
27448 single stepping through C and assembler code.
27451 The source was compiled with
27465 \begin_layout Standard
27477 -debug ddd_example.c
27490 and DDD was invoked with
27497 ddd -debugger "sdcdb -cpu 8032 ddd_example"
27500 \begin_layout Standard
27501 \begin_inset Note Note
27504 \begin_layout Standard
27505 Check that the double quotes or an apostroph within the command line survive
27506 the LyX tool chain.
27507 Previously the apostrophs got slanted in the PDF output so a cut and paste
27516 \begin_layout Subsection
27517 Interfacing SDCDB with XEmacs
27518 \begin_inset LatexCommand \index{XEmacs}
27523 \begin_inset LatexCommand \index{Emacs}
27530 \begin_layout Standard
27531 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
27532 sdcdb.el and sdcdbsrc.el.
27533 These two files can be found in the $(prefix)/bin directory after the installat
27535 These files need to be loaded into XEmacs for the interface to work.
27536 This can be done at XEmacs startup time by inserting the following into
27537 your '.xemacs' file (which can be found in your HOME directory):
27543 (load-file sdcdbsrc.el)
27549 .xemacs is a lisp file so the () around the command is REQUIRED.
27550 The files can also be loaded dynamically while XEmacs is running, set the
27551 environment variable 'EMACSLOADPATH' to the installation bin directory
27552 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
27553 To start the interface enter the following command:
27567 You will prompted to enter the file name to be debugged.
27572 The command line options that are passed to the simulator directly are
27573 bound to default values in the file sdcdbsrc.el.
27574 The variables are listed below, these values maybe changed as required.
27577 \begin_layout Itemize
27578 sdcdbsrc-cpu-type '51
27581 \begin_layout Itemize
27582 sdcdbsrc-frequency '11059200
27585 \begin_layout Itemize
27586 sdcdbsrc-serial nil
27589 \begin_layout Standard
27590 The following is a list of key mapping for the debugger interface.
27593 \begin_layout Standard
27616 binding\InsetSpace ~
27654 -------\InsetSpace ~
27725 sdcdb-back-from-src\InsetSpace ~
27754 rom-src\InsetSpace ~
27764 SDCDB continue command
27782 sdcdb-step-from-src\InsetSpace ~
27811 hatis-c-sexp\InsetSpace ~
27821 SDCDB ptypecommand for data at
27888 sdcdbsrc-delete\InsetSpace ~
27903 B Delete all breakpoints if no arg
27952 given or delete arg (C-u arg x)
27971 -frame\InsetSpace ~
27986 SDCDB Display current frame if no arg,
28035 given or display frame arg
28103 sdcdbsrc-goto-sdcdb\InsetSpace ~
28113 Goto the SDCDB output buffer
28132 t-c-sexp\InsetSpace ~
28143 SDCDB print command for data at
28210 sdcdbsrc-goto-sdcdb\InsetSpace ~
28221 o the SDCDB output buffer
28239 sdcdbsrc-mode\InsetSpace ~
28255 Toggles Sdcdbsrc mode (turns it
28271 sdcdb-finish-from-src\InsetSpace ~
28279 SDCDB finish command
28313 Set break for line with point
28328 sdcdbsrc-mode\InsetSpace ~
28344 Toggle Sdcdbsrc mode
28360 dbsrc-srcmode\InsetSpace ~
28384 \begin_layout Chapter
28388 \begin_layout Standard
28389 Here are a few guidelines that will help the compiler generate more efficient
28390 code, some of the tips are specific to this compiler others are generally
28391 good programming practice.
28394 \begin_layout Itemize
28395 Use the smallest data type to represent your data-value.
28396 If it is known in advance that the value is going to be less than 256 then
28397 use an 'unsigned char' instead of a 'short' or 'int'.
28398 Please note, that ANSI C requires both signed and unsigned chars to be
28399 promoted to 'signed int'
28400 \begin_inset LatexCommand \index{promotion to signed int}
28405 \begin_inset Marginal
28408 \begin_layout Standard
28417 before doing any operation.
28419 \begin_inset LatexCommand \index{type promotion}
28424 \begin_inset LatexCommand \label{type promotion}
28428 can be omitted, if the result is the same.
28429 The effect of the promotion rules together with the sign-extension is often
28434 \begin_layout Verse
28437 unsigned char uc = 0xfe;
28439 if (uc * uc < 0) /* this is true! */
28452 \begin_layout Standard
28459 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
28467 \begin_layout Verse
28470 (unsigned char) -12 / (signed char) -3 = ...
28473 \begin_layout Standard
28474 No, the result is not 4:
28477 \begin_layout Verse
28480 (int) (unsigned char) -12 / (int) (signed char) -3 =
28482 (int) (unsigned char)
28483 0xf4 / (int) (signed char) 0xfd =
28485 (int) 0x00f4 / (int) 0xfffd =
28490 (int) 244 / (int) -3 =
28492 (int) -81 = (int) 0xffaf;
28495 \begin_layout Standard
28496 Don't complain, that gcc gives you a different result.
28497 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
28498 Therefore the results are different.
28501 \begin_inset Quotes sld
28505 \begin_inset Quotes srd
28511 \begin_layout Quote
28514 If well-defined overflow characteristics are important and negative values
28515 are not, or if you want to steer clear of sign-extension problems when
28516 manipulating bits or bytes, use one of the corresponding unsigned types.
28517 (Beware when mixing signed and unsigned values in expressions, though.)
28520 character types (especially unsigned char) can be used as "tiny" integers,
28521 doing so is sometimes more trouble than it's worth, due to unpredictable
28522 sign extension and increased code size.
28526 \begin_layout Itemize
28527 Use unsigned when it is known in advance that the value is not going to
28529 This helps especially if you are doing division or multiplication, bit-shifting
28530 or are using an array index.
28533 \begin_layout Itemize
28534 NEVER jump into a LOOP.
28537 \begin_layout Itemize
28538 Declare the variables to be local
28539 \begin_inset LatexCommand \index{local variables}
28543 whenever possible, especially loop control variables (induction).
28546 \begin_layout Itemize
28547 Have a look at the assembly listing to get a
28548 \begin_inset Quotes sld
28552 \begin_inset Quotes srd
28555 for the code generation.
28558 \begin_layout Section
28559 Porting code from or to other compilers
28560 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
28567 \begin_layout Itemize
28568 check whether endianness of the compilers differs and adapt where needed.
28571 \begin_layout Itemize
28572 check the device specific header files
28573 \begin_inset LatexCommand \index{Header files}
28578 \begin_inset LatexCommand \index{Include files}
28582 for compiler specific syntax.
28583 Eventually include the file <compiler.h
28584 \begin_inset LatexCommand \index{compiler.h (include file)}
28589 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
28593 to allow using common header files.
28596 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
28603 \begin_layout Itemize
28604 check whether the startup code contains the correct initialization (watchdog,
28608 \begin_layout Itemize
28609 check whether the sizes of short, int, long match.
28612 \begin_layout Itemize
28613 check if some 16 or 32 bit hardware registers require a specific addressing
28614 order (least significant or most significant byte first) and adapt if needed
28623 relate to time and not to lower/upper memory location here, so this is
28628 the same as endianness).
28631 \begin_layout Itemize
28632 check whether the keyword
28636 is used where needed.
28637 The compilers might differ in their optimization characteristics (as different
28638 versions of the same compiler might also use more clever optimizations
28639 this is good idea anyway).
28641 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
28648 \begin_layout Itemize
28649 check that the compilers are not told to supress warnings.
28652 \begin_layout Itemize
28653 check and convert compiler specific extensions (interrupts, memory areas,
28657 \begin_layout Itemize
28658 check for differences in type promotion.
28659 Especially check for math operations on
28668 For the sake of C99 compatibility SDCC will probably promote these to
28672 more often than other compilers.
28673 Eventually insert explicit casts to
28682 Also check that the ~\InsetSpace ~
28684 \begin_inset LatexCommand \index{\~\/ Operator}
28691 \begin_inset LatexCommand \index{bit}
28697 variables, use the !\InsetSpace ~
28700 \begin_inset LatexCommand \ref{type promotion}
28705 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
28712 \begin_layout Itemize
28713 check the assembly code generated for interrupt routines (f.e.
28714 for calls to possibly non-reentrant library functions).
28717 \begin_layout Itemize
28718 check whether timing loops result in proper timing (or preferably consider
28719 a rewrite of the code with timer based delays instead).
28722 \begin_layout Itemize
28723 check for differences in printf parameters (some compilers push (va_arg
28724 \begin_inset LatexCommand \index{vararg, va\_arg}
28728 ) char variables as
28732 others push them as
28738 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
28745 \begin_layout Itemize
28746 check the resulting memory map
28747 \begin_inset LatexCommand \index{Memory map}
28752 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
28753 ly idata, pdata, xdata).
28754 Eventually check if unexpected library functions are included.
28757 \begin_layout Section
28759 \begin_inset LatexCommand \index{Tools}
28763 included in the distribution
28766 \begin_layout Standard
28768 \begin_inset Tabular
28769 <lyxtabular version="3" rows="12" columns="3">
28771 <column alignment="left" valignment="top" leftline="true" width="0pt">
28772 <column alignment="left" valignment="top" leftline="true" width="0pt">
28773 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28774 <row topline="true" bottomline="true">
28775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28778 \begin_layout Standard
28786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28789 \begin_layout Standard
28797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28800 \begin_layout Standard
28809 <row topline="true">
28810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28813 \begin_layout Standard
28815 \begin_inset LatexCommand \index{uCsim}
28824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28827 \begin_layout Standard
28828 Simulator for various architectures
28833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28836 \begin_layout Standard
28843 <row topline="true">
28844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28847 \begin_layout Standard
28853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28856 \begin_layout Standard
28858 \begin_inset LatexCommand \index{Header files}
28863 \begin_inset LatexCommand \index{Include files}
28872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28875 \begin_layout Standard
28876 sdcc/support/scripts
28882 <row topline="true">
28883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28886 \begin_layout Standard
28892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28895 \begin_layout Standard
28896 header file conversion
28901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28904 \begin_layout Standard
28905 sdcc/support/scripts
28911 <row topline="true">
28912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28915 \begin_layout Standard
28921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28924 \begin_layout Standard
28930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28933 \begin_layout Standard
28949 <row topline="true">
28950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28953 \begin_layout Standard
28959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28962 \begin_layout Standard
28968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28971 \begin_layout Standard
28987 <row topline="true">
28988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28991 \begin_layout Standard
28997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29000 \begin_layout Standard
29006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29009 \begin_layout Standard
29025 <row topline="true">
29026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29029 \begin_layout Standard
29035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29038 \begin_layout Standard
29044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29047 \begin_layout Standard
29063 <row topline="true">
29064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29067 \begin_layout Standard
29073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29076 \begin_layout Standard
29082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29085 \begin_layout Standard
29101 <row topline="true">
29102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29105 \begin_layout Standard
29111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29114 \begin_layout Standard
29120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29123 \begin_layout Standard
29139 <row topline="true">
29140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29143 \begin_layout Standard
29149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29152 \begin_layout Standard
29158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29161 \begin_layout Standard
29177 <row topline="true" bottomline="true">
29178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29181 \begin_layout Standard
29187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29190 \begin_layout Standard
29192 \begin_inset LatexCommand \index{packihx (tool)}
29201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29204 \begin_layout Standard
29229 \begin_layout Section
29231 \begin_inset LatexCommand \index{Documentation}
29235 included in the distribution
29238 \begin_layout Standard
29240 \begin_inset Tabular
29241 <lyxtabular version="3" rows="10" columns="2">
29243 <column alignment="block" valignment="top" leftline="true" width="40col%">
29244 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29245 <row topline="true" bottomline="true" endhead="true">
29246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29249 \begin_layout Standard
29257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29260 \begin_layout Standard
29263 Filename / Where to get
29269 <row topline="true">
29270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29273 \begin_layout Standard
29274 SDCC Compiler User Guide
29279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29282 \begin_layout Standard
29283 You're reading it right now
29295 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29305 <row topline="true">
29306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29309 \begin_layout Standard
29315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29318 \begin_layout Standard
29331 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29341 <row topline="true">
29342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29345 \begin_layout Standard
29347 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29352 \begin_inset LatexCommand \index{Assembler documentation}
29359 \begin_inset LatexCommand \index{aslink}
29364 \begin_inset LatexCommand \index{Linker documentation}
29373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29376 \begin_layout Standard
29377 sdcc/as/doc/asxhtm.html
29389 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29399 <row topline="true">
29400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29403 \begin_layout Standard
29404 SDCC regression test
29405 \begin_inset LatexCommand \index{Regression test}
29414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29417 \begin_layout Standard
29418 sdcc/doc/test_suite_spec.pdf
29430 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
29440 <row topline="true">
29441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29444 \begin_layout Standard
29450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29453 \begin_layout Standard
29466 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
29476 <row topline="true">
29477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29480 \begin_layout Standard
29481 Notes on debugging with SDCDB
29482 \begin_inset LatexCommand \index{SDCDB (debugger)}
29491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29494 \begin_layout Standard
29495 sdcc/debugger/README
29507 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
29517 <row topline="true">
29518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29521 \begin_layout Standard
29523 \begin_inset LatexCommand \index{uCsim}
29527 Software simulator for microcontrollers
29532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29535 \begin_layout Standard
29565 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
29575 <row topline="true">
29576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29579 \begin_layout Standard
29580 Temporary notes on the pic16
29581 \begin_inset LatexCommand \index{PIC16}
29590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29593 \begin_layout Standard
29594 sdcc/src/pic16/NOTES
29606 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
29616 <row topline="true" bottomline="true">
29617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29620 \begin_layout Standard
29621 SDCC internal documentation (debugging file format)
29626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29629 \begin_layout Standard
29659 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
29678 \begin_layout Section
29679 Related open source tools
29680 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
29685 \begin_inset LatexCommand \index{Related tools}
29692 \begin_layout Standard
29694 \begin_inset Tabular
29695 <lyxtabular version="3" rows="14" columns="3">
29697 <column alignment="left" valignment="top" leftline="true" width="0pt">
29698 <column alignment="block" valignment="top" leftline="true" width="30line%">
29699 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29700 <row topline="true" bottomline="true">
29701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29704 \begin_layout Standard
29712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29715 \begin_layout Standard
29723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29726 \begin_layout Standard
29735 <row topline="true">
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29739 \begin_layout Standard
29741 \begin_inset LatexCommand \index{gpsim (pic simulator)}
29750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29753 \begin_layout Standard
29759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29762 \begin_layout Standard
29763 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
29773 <row topline="true">
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29777 \begin_layout Standard
29779 \begin_inset LatexCommand \index{gputils (pic tools)}
29788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29791 \begin_layout Standard
29797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29800 \begin_layout Standard
29801 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
29811 <row topline="true">
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29815 \begin_layout Standard
29821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29824 \begin_layout Standard
29830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29833 \begin_layout Standard
29834 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
29844 <row topline="true">
29845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29848 \begin_layout Standard
29854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29857 \begin_layout Standard
29858 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
29864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29867 \begin_layout Standard
29868 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
29878 <row topline="true">
29879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29882 \begin_layout Standard
29884 \begin_inset LatexCommand \index{indent (source formatting tool)}
29893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29896 \begin_layout Standard
29897 Formats C source - Master of the white spaces
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29905 \begin_layout Standard
29906 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
29916 <row topline="true">
29917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29920 \begin_layout Standard
29922 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29934 \begin_layout Standard
29935 Object file conversion, checksumming, ...
29940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29943 \begin_layout Standard
29944 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29954 <row topline="true">
29955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29958 \begin_layout Standard
29960 \begin_inset LatexCommand \index{objdump (tool)}
29969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29972 \begin_layout Standard
29973 Object file conversion, ...
29978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29981 \begin_layout Standard
29982 Part of binutils (should be there anyway)
29988 <row topline="true">
29989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29992 \begin_layout Standard
29998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30001 \begin_layout Standard
30002 8051 monitor (hex up-/download, single step, disassemble)
30007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30010 \begin_layout Standard
30011 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30021 <row topline="true">
30022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30025 \begin_layout Standard
30027 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30039 \begin_layout Standard
30040 Source code documentation system
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30048 \begin_layout Standard
30049 \begin_inset LatexCommand \url{http://www.doxygen.org}
30059 <row topline="true">
30060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30063 \begin_layout Standard
30069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30072 \begin_layout Standard
30073 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30081 \begin_layout Standard
30082 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30092 <row topline="true">
30093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30096 \begin_layout Standard
30102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30105 \begin_layout Standard
30106 8051 monitor (hex up-/download, single step, disassemble)
30111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30114 \begin_layout Standard
30115 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30125 <row topline="true">
30126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30129 \begin_layout Standard
30131 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30143 \begin_layout Standard
30144 Statically checks c sources (see
30145 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30157 \begin_layout Standard
30158 \begin_inset LatexCommand \url{http://www.splint.org}
30168 <row topline="true" bottomline="true">
30169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30172 \begin_layout Standard
30174 \begin_inset LatexCommand \index{DDD (debugger)}
30183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30186 \begin_layout Standard
30187 Debugger, serves nicely as GUI to SDCDB
30188 \begin_inset LatexCommand \index{SDCDB (debugger)}
30197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30200 \begin_layout Standard
30201 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30220 \begin_layout Section
30221 Related documentation / recommended reading
30224 \begin_layout Standard
30226 \begin_inset Tabular
30227 <lyxtabular version="3" rows="7" columns="3">
30229 <column alignment="left" valignment="top" leftline="true" width="0pt">
30230 <column alignment="left" valignment="top" leftline="true" width="0">
30231 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30232 <row topline="true" bottomline="true">
30233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30236 \begin_layout Standard
30244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30247 \begin_layout Standard
30255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30258 \begin_layout Standard
30267 <row topline="true">
30268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30271 \begin_layout Standard
30286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30289 \begin_layout Standard
30291 \begin_inset LatexCommand \index{C Reference card}
30300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30303 \begin_layout Standard
30304 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30314 <row topline="true">
30315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30318 \begin_layout Standard
30324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30327 \begin_layout Standard
30329 \begin_inset LatexCommand \index{C FAQ}
30338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30341 \begin_layout Standard
30342 \begin_inset LatexCommand \url{http://www.c-faq.com}
30352 <row topline="true">
30353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30356 \begin_layout Standard
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30365 \begin_layout Standard
30366 \begin_inset Quotes sld
30370 \begin_inset Quotes srd
30378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30381 \begin_layout Standard
30384 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30394 <row topline="true">
30395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30398 \begin_layout Standard
30404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30407 \begin_layout Standard
30408 \begin_inset Quotes sld
30411 Extensions for Embedded C
30412 \begin_inset Quotes srd
30420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30423 \begin_layout Standard
30426 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
30436 <row topline="true">
30437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30440 \begin_layout Standard
30446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30449 \begin_layout Standard
30450 Latest datasheet of target CPU
30455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30458 \begin_layout Standard
30465 <row topline="true" bottomline="true">
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30469 \begin_layout Standard
30475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30478 \begin_layout Standard
30479 Revision history of datasheet
30484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30487 \begin_layout Standard
30503 \begin_layout Section
30504 Application notes specifically for SDCC
30507 \begin_layout Standard
30508 SDCC makes no claims about the completeness of this list and about up-to-datenes
30509 s or correctness of the application notes
30510 \begin_inset LatexCommand \index{Application notes}
30517 \begin_layout Standard
30521 \begin_inset Tabular
30522 <lyxtabular version="3" rows="7" columns="3">
30524 <column alignment="block" valignment="top" leftline="true" width="17col%">
30525 <column alignment="block" valignment="top" leftline="true" width="27col%">
30526 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
30527 <row topline="true" bottomline="true">
30528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30531 \begin_layout Standard
30540 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
30543 \begin_layout Standard
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30555 \begin_layout Standard
30565 <row topline="true">
30566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30569 \begin_layout Standard
30577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30580 \begin_layout Standard
30583 Using the SDCC Compiler for the DS80C400
30584 \begin_inset LatexCommand \index{DS80C400}
30593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30596 \begin_layout Standard
30599 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
30609 <row topline="true">
30610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30613 \begin_layout Standard
30621 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
30624 \begin_layout Standard
30627 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
30628 \begin_inset LatexCommand \index{DS89C4x0}
30632 Family of Microcontrollers
30637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30640 \begin_layout Standard
30643 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
30653 <row topline="true">
30654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30657 \begin_layout Standard
30660 Silicon Laboratories / Cygnal
30665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30668 \begin_layout Standard
30671 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
30672 \begin_inset LatexCommand \index{IDE}
30681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30684 \begin_layout Standard
30687 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
30697 <row topline="true">
30698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30701 \begin_layout Standard
30704 Ramtron / Goal Semiconductor
30709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30712 \begin_layout Standard
30715 Interfacing SDCC to Syn and Textpad
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30723 \begin_layout Standard
30726 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
30736 <row topline="true">
30737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30740 \begin_layout Standard
30743 Ramtron / Goal Semiconductor
30748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30751 \begin_layout Standard
30754 Installing and Configuring SDCC and Crimson Editor
30759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30762 \begin_layout Standard
30765 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
30775 <row topline="true" bottomline="true">
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30779 \begin_layout Standard
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30790 \begin_layout Standard
30793 MSC12xx Programming with SDCC
30798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30801 \begin_layout Standard
30804 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
30821 \begin_layout Section
30825 \begin_layout Standard
30826 Some questions answered, some pointers given - it might be time to in turn
30834 \begin_layout Itemize
30835 can you solve your project with the selected microcontroller? Would you
30836 find out early or rather late that your target is too small/slow/whatever?
30837 Can you switch to a slightly better device if it doesn't fit?
30840 \begin_layout Itemize
30841 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
30842 and/or another programming language be more adequate? Would an operating
30843 system on the target device help?
30846 \begin_layout Itemize
30847 if you solved the problem, will the marketing department be happy?
30850 \begin_layout Itemize
30851 if the marketing department is happy, will customers be happy?
30854 \begin_layout Itemize
30855 if you're the project manager, marketing department and maybe even the customer
30856 in one person, have you tried to see the project from the outside?
30859 \begin_layout Itemize
30860 is the project done if you think it is done? Or is just that other interface/pro
30861 tocol/feature/configuration/option missing? How about website, manual(s),
30862 internationali(z|s)ation, packaging, labels, 2nd source for components,
30863 electromagnetic compatability/interference, documentation for production,
30864 production test software, update mechanism, patent issues?
30867 \begin_layout Itemize
30868 is your project adequately positioned in that magic triangle: fame, fortune,
30872 \begin_layout Standard
30873 Maybe not all answers to these questions are known and some answers may
30878 , nevertheless knowing these questions may help you to avoid burnout
30882 \begin_layout Standard
30883 burnout is bad for electronic devices, programmers and motorcycle tyres
30889 Chances are you didn't want to hear some of them...
30892 \begin_layout Chapter
30894 \begin_inset LatexCommand \index{Support}
30901 \begin_layout Standard
30902 SDCC has grown to be a large project.
30903 The compiler alone (without the preprocessor, assembler and linker) is
30904 well over 150,000 lines of code (blank stripped).
30905 The open source nature of this project is a key to its continued growth
30907 You gain the benefit and support of many active software developers and
30909 Is SDCC perfect? No, that's why we need your help.
30910 The developers take pride in fixing reported bugs.
30911 You can help by reporting the bugs and helping other SDCC users.
30912 There are lots of ways to contribute, and we encourage you to take part
30913 in making SDCC a great software package.
30917 \begin_layout Standard
30918 The SDCC project is hosted on the SDCC sourceforge site at
30919 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30924 You'll find the complete set of mailing lists
30925 \begin_inset LatexCommand \index{Mailing list(s)}
30929 , forums, bug reporting system, patch submission
30930 \begin_inset LatexCommand \index{Patch submission}
30935 \begin_inset LatexCommand \index{download}
30939 area and Subversion code repository
30940 \begin_inset LatexCommand \index{Subversion code repository}
30947 \begin_layout Section
30949 \begin_inset LatexCommand \index{Bug reporting}
30954 \begin_inset LatexCommand \index{Reporting bugs}
30961 \begin_layout Standard
30962 The recommended way of reporting bugs is using the infrastructure of the
30964 You can follow the status of bug reports there and have an overview about
30968 \begin_layout Standard
30969 Bug reports are automatically forwarded to the developer mailing list and
30970 will be fixed ASAP.
30971 When reporting a bug, it is very useful to include a small test program
30972 (the smaller the better) which reproduces the problem.
30973 If you can isolate the problem by looking at the generated assembly code,
30974 this can be very helpful.
30975 Compiling your program with the -
30979 \begin_layout Standard
30989 \begin_inset LatexCommand \index{-\/-dumpall}
30993 option can sometimes be useful in locating optimization problems.
30994 When reporting a bug please make sure you:
30997 \begin_layout Enumerate
30998 Attach the code you are compiling with SDCC.
31002 \begin_layout Enumerate
31003 Specify the exact command you use to run SDCC, or attach your Makefile.
31007 \begin_layout Enumerate
31008 Specify the SDCC version (type "
31014 "), your platform, and operating system.
31018 \begin_layout Enumerate
31019 Provide an exact copy of any error message or incorrect output.
31023 \begin_layout Enumerate
31024 Put something meaningful in the subject of your message.
31027 \begin_layout Standard
31028 Please attempt to include these 5 important parts, as applicable, in all
31029 requests for support or when reporting any problems or bugs with SDCC.
31030 Though this will make your message lengthy, it will greatly improve your
31031 chance that SDCC users and developers will be able to help you.
31032 Some SDCC developers are frustrated by bug reports without code provided
31033 that they can use to reproduce and ultimately fix the problem, so please
31034 be sure to provide sample code if you are reporting a bug!
31037 \begin_layout Standard
31038 Please have a short check that you are using a recent version of SDCC and
31039 the bug is not yet known.
31040 This is the link for reporting bugs:
31041 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31046 With SDCC on average having more than 200 downloads
31047 \begin_inset LatexCommand \index{download}
31051 on sourceforge per day
31055 \begin_layout Standard
31056 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31057 between 2002 and 2005.
31058 This does not include other methods of distribution.
31063 there must be some users.
31064 So it's not exactly easy to find a new bug.
31065 If you find one we need it:
31067 reporting bugs is good
31072 \begin_layout Section
31073 Requesting Features
31074 \begin_inset LatexCommand \label{sub:Requesting-Features}
31079 \begin_inset LatexCommand \index{Feature request}
31084 \begin_inset LatexCommand \index{Requesting features}
31091 \begin_layout Standard
31092 Like bug reports feature requests are forwarded to the developer mailing
31094 This is the link for requesting features:
31095 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31102 \begin_layout Section
31106 \begin_layout Standard
31107 Like bug reports contributed patches are forwarded to the developer mailing
31109 This is the link for submitting patches
31110 \begin_inset LatexCommand \index{Patch submission}
31115 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31122 \begin_layout Standard
31123 You need to specify some parameters to the
31127 command for the patches to be useful.
31128 If you modified more than one file a patch created f.e.
31133 \begin_inset Quotes sld
31136 diff -Naur unmodified_directory modified_directory >my_changes.patch
31137 \begin_inset Quotes srd
31143 will be fine, otherwise
31147 \begin_inset Quotes sld
31150 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31151 \begin_inset Quotes srd
31161 \begin_layout Section
31165 \begin_layout Standard
31166 These links should take you directly to the
31167 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31175 \begin_layout Standard
31176 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31177 automated messages (mid 2003)
31183 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31188 \begin_inset LatexCommand \index{Mailing list(s)}
31192 and forums are archived and searchable so if you are lucky someone already
31193 had a similar problem.
31194 While mails to the lists themselves are delivered promptly their web front
31195 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31196 if you're seriously using SDCC please consider subscribing to the lists.
31199 \begin_layout Section
31203 \begin_layout Standard
31204 You can follow the status of the Subversion version
31205 \begin_inset LatexCommand \index{version}
31209 of SDCC by watching the Changelog
31210 \begin_inset LatexCommand \index{Changelog}
31214 in the Subversion repository
31217 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31224 \begin_layout Section
31225 Subversion Source Code Repository
31228 \begin_layout Standard
31235 or the filenames of the snapshot versions of SDCC include date and its
31237 \begin_inset LatexCommand \index{Subversion code repository}
31242 Subversion allows to download the source of recent or previous versions
31244 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31248 (by number or by date).
31249 An on-line source code browser and detailled instructions are also available
31251 SDCC versions starting from 1999 up to now are available (currently the
31252 versions prior to the conversion from cvs
31253 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31257 to Subversion (April 2006) are either by accessible by Subversion or by
31261 \begin_layout Section
31263 \begin_inset LatexCommand \index{Release policy}
31270 \begin_layout Standard
31271 Historically there often were long delays between official releases and
31272 the sourceforge download area tends to get not updated at all.
31273 Excuses in the past might have referred to problems with live range analysis,
31274 but as this was fixed a while ago, the current problem is that another
31275 excuse has to be found.
31276 Kidding aside, we have to get better there! On the other hand there are
31277 daily snapshots available at
31278 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31282 , and you can always build the very last version (hopefully with many bugs
31283 fixed, and features added) from the source code available at
31284 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31290 \begin_inset LatexCommand \index{wiki}
31295 \begin_inset LatexCommand \index{Release wiki}
31300 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31304 also holds some information about past and future releases.
31307 \begin_layout Section
31309 \begin_inset LatexCommand \index{Examples}
31316 \begin_layout Standard
31317 You'll find some small examples in the directory
31319 sdcc/device/examples/.
31322 More examples and libraries are available at
31324 The SDCC Open Knowledge Resource
31325 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31332 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31339 \begin_layout Standard
31340 \begin_inset Note Note
31343 \begin_layout Standard
31344 I did insert a reference to Paul's web site here although it seems rather
31345 dedicated to a specific 8032 board (I think it's okay because it f.e.
31346 shows LCD/Harddisc interface and has a free 8051 monitor.
31347 Independent 8032 board vendors face hard competition of heavily subsidized
31348 development boards anyway).
31351 \begin_layout Standard
31352 Maybe we should include some links to real world applications.
31353 Preferably pointer to pointers (one for each architecture) so this stays
31362 \begin_layout Section
31364 \begin_inset LatexCommand \label{sec:Quality-control}
31369 \begin_inset LatexCommand \index{Quality control}
31376 \begin_layout Standard
31377 The compiler is passed through snaphot build compile and build checks.
31383 \begin_inset LatexCommand \index{Regression test}
31387 check that SDCC itself compiles flawlessly on several host platforms (i386,
31388 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
31389 the quality of the code generated by SDCC by running the code for several
31390 target platforms through simulators.
31391 The regression test suite comprises more than 100 files which expand to
31392 more than 500 test cases which include more than 4500 tests.
31393 The results of these tests are published daily on SDCC's snapshot page
31394 (click on the red or green symbols on the right side of
31395 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
31402 \begin_layout Standard
31403 There is a separate document
31406 \begin_inset LatexCommand \index{Test suite}
31413 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31417 about the regression test suite.
31420 \begin_layout Standard
31421 You'll find the test code in the directory
31423 sdcc/support/regression
31426 You can run these tests manually by running
31430 in this directory (or f.e.
31435 \begin_inset Quotes sld
31439 \begin_inset Quotes srd
31445 if you don't want to run the complete tests).
31446 The test code might also be interesting if you want to look for examples
31447 \begin_inset LatexCommand \index{Examples}
31451 checking corner cases of SDCC or if you plan to submit patches
31452 \begin_inset LatexCommand \index{Patch submission}
31459 \begin_layout Standard
31460 The 14bit pic port uses a different set of regression tests
31461 \begin_inset LatexCommand \index{Regression test (PIC14)}
31465 , you'll find them in the directory
31467 sdcc/src/regression
31472 \begin_layout Section
31473 Use of SDCC in Education
31476 \begin_layout Standard
31485 \begin_layout Standard
31486 the phrase "use in education" might evoke the association "
31490 fit for use in education".
31491 This connotation is not intended but nevertheless risked as the licensing
31492 of SDCC makes it difficult to offer educational discounts
31498 If your rationales are to:
31501 \begin_layout Enumerate
31502 give students a chance to understand the
31506 steps of code generation
31509 \begin_layout Enumerate
31510 have a curriculum that can be extended for years.
31511 Then you could use an fpga board as target and your curriculum will seamlessly
31512 extend from logic synthesis (
31513 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
31518 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
31522 ), over assembly programming, to C to FPGA compilers (
31523 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
31530 \begin_layout Enumerate
31531 be able to insert excursions about skills like using a revision control
31532 system, submitting/applying patches, using a type-setting (as opposed to
31533 word-processing) engine LyX/LaTeX, using
31534 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
31539 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
31543 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
31544 Source Software, CPU simulation, compiler regression tests
31545 \begin_inset LatexCommand \index{Regression test}
31552 And if there should be a shortage of ideas then you can always point students
31553 to the ever-growing feature request list
31554 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31561 \begin_layout Enumerate
31562 not tie students to a specific host platform and instead allow them to use
31567 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
31569 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
31576 \begin_layout Enumerate
31577 not encourage students to use illegal copies of educational software
31580 \begin_layout Enumerate
31581 be immune to licensing/availability/price changes of the chosen tool chain
31584 \begin_layout Enumerate
31585 be able to change to a new target platform without having to adopt a new
31589 \begin_layout Enumerate
31590 have complete control over and insight into the tool chain
31593 \begin_layout Enumerate
31594 make your students aware about the pros and cons of open source software
31598 \begin_layout Enumerate
31599 give back to the public as you are probably at least partially publically
31603 \begin_layout Enumerate
31604 give students a chance to publically prove their skills and to possibly
31605 see a world wide impact
31608 \begin_layout Standard
31609 then SDCC is probably among the first choices.
31610 Well, probably SDCC might be the only choice.
31615 \begin_layout Chapter
31616 SDCC Technical Data
31619 \begin_layout Section
31621 \begin_inset LatexCommand \index{Optimizations}
31628 \begin_layout Standard
31629 SDCC performs a host of standard optimizations in addition to some MCU specific
31634 \begin_layout Subsection
31635 Sub-expression Elimination
31636 \begin_inset LatexCommand \index{Subexpression elimination}
31643 \begin_layout Standard
31644 The compiler does local and
31663 \begin_layout Verse
31671 \begin_layout Standard
31672 will be translated to
31675 \begin_layout Verse
31685 \begin_layout Standard
31686 Some subexpressions are not as obvious as the above example, e.g.:
31689 \begin_layout Verse
31697 \begin_layout Standard
31698 In this case the address arithmetic a->b[i] will be computed only once;
31699 the equivalent code in C would be.
31702 \begin_layout Verse
31712 \begin_layout Standard
31713 The compiler will try to keep these temporary variables in registers.
31716 \begin_layout Subsection
31717 Dead-Code Elimination
31718 \begin_inset LatexCommand \index{Dead-code elimination}
31725 \begin_layout Verse
31740 i = 1; \InsetSpace ~
31749 global = 1;\InsetSpace ~
31763 global = 3;\InsetSpace ~
31769 \begin_layout Standard
31773 \begin_layout Verse
31789 \begin_layout Subsection
31791 \begin_inset LatexCommand \index{Copy propagation}
31798 \begin_layout Verse
31822 \begin_layout Standard
31826 \begin_layout Verse
31850 \begin_layout Standard
31851 Note: the dead stores created by this copy propagation will be eliminated
31852 by dead-code elimination.
31855 \begin_layout Subsection
31857 \begin_inset LatexCommand \index{Loop optimization}
31862 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
31869 \begin_layout Standard
31870 Two types of loop optimizations are done by SDCC
31878 of loop induction variables.
31879 In addition to the strength reduction the optimizer marks the induction
31880 variables and the register allocator tries to keep the induction variables
31881 in registers for the duration of the loop.
31882 Because of this preference of the register allocator
31883 \begin_inset LatexCommand \index{Register allocation}
31887 , loop induction optimization causes an increase in register pressure, which
31888 may cause unwanted spilling of other temporary variables into the stack
31889 \begin_inset LatexCommand \index{stack}
31894 The compiler will generate a warning message when it is forced to allocate
31895 extra space either on the stack or data space.
31896 If this extra space allocation is undesirable then induction optimization
31897 can be eliminated either for the entire source file (with -
31901 \begin_layout Standard
31910 -noinduction option) or for a given function only using #pragma\InsetSpace ~
31912 \begin_inset LatexCommand \index{\#pragma noinduction}
31923 \begin_layout Verse
31926 for (i = 0 ; i < 100 ; i ++)
31935 \begin_layout Standard
31939 \begin_layout Verse
31944 for (i = 0; i < 100; i++)
31953 \begin_layout Standard
31954 As mentioned previously some loop invariants are not as apparent, all static
31955 address computations are also moved out of the loop.
31960 \begin_inset LatexCommand \index{Strength reduction}
31964 , this optimization substitutes an expression by a cheaper expression:
31967 \begin_layout Verse
31970 for (i=0;i < 100; i++)
31979 \begin_layout Standard
31983 \begin_layout Verse
31990 for (i=0;i< 100;i++) {
31996 ar[itemp1] = itemp2;
32014 \begin_layout Standard
32015 The more expensive multiplication
32016 \begin_inset LatexCommand \index{Multiplication}
32020 is changed to a less expensive addition.
32023 \begin_layout Subsection
32025 \begin_inset LatexCommand \index{Loop reversing}
32032 \begin_layout Standard
32033 This optimization is done to reduce the overhead of checking loop boundaries
32034 for every iteration.
32035 Some simple loops can be reversed and implemented using a
32036 \begin_inset Quotes eld
32039 decrement and jump if not zero
32040 \begin_inset Quotes erd
32044 SDCC checks for the following criterion to determine if a loop is reversible
32045 (note: more sophisticated compilers use data-dependency analysis to make
32046 this determination, SDCC uses a more simple minded analysis).
32049 \begin_layout Itemize
32050 The 'for' loop is of the form
32056 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32066 \begin_layout Itemize
32067 The <for body> does not contain
32068 \begin_inset Quotes eld
32072 \begin_inset Quotes erd
32076 \begin_inset Quotes erd
32082 \begin_layout Itemize
32083 All goto's are contained within the loop.
32086 \begin_layout Itemize
32087 No function calls within the loop.
32090 \begin_layout Itemize
32091 The loop control variable <sym> is not assigned any value within the loop
32094 \begin_layout Itemize
32095 The loop control variable does NOT participate in any arithmetic operation
32099 \begin_layout Itemize
32100 There are NO switch statements in the loop.
32103 \begin_layout Subsection
32104 Algebraic Simplifications
32107 \begin_layout Standard
32108 SDCC does numerous algebraic simplifications, the following is a small sub-set
32109 of these optimizations.
32112 \begin_layout Verse
32115 i = j + 0;\InsetSpace ~
32119 /* changed to: */\InsetSpace ~
32125 i /= 2;\InsetSpace ~
32132 /* changed to: */\InsetSpace ~
32139 = j - j;\InsetSpace ~
32143 /* changed to: */\InsetSpace ~
32149 i = j / 1;\InsetSpace ~
32153 /* changed to: */\InsetSpace ~
32160 \begin_layout Standard
32161 Note the subexpressions
32162 \begin_inset LatexCommand \index{Subexpression}
32166 given above are generally introduced by macro expansions or as a result
32167 of copy/constant propagation.
32170 \begin_layout Subsection
32171 'switch' Statements
32172 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32177 \begin_inset LatexCommand \index{switch statement}
32184 \begin_layout Standard
32185 SDCC can optimize switch statements to jump tables
32186 \begin_inset LatexCommand \index{jump tables}
32191 It makes the decision based on an estimate of the generated code size.
32192 SDCC is quite liberal in the requirements for jump table generation:
32195 \begin_layout Itemize
32196 The labels need not be in order, and the starting number need not be one
32197 or zero, the case labels are in numerical sequence or not too many case
32198 labels are missing.
32202 \begin_layout Verse
32205 switch(i) {\InsetSpace ~
32236 case 4: ...\InsetSpace ~
32268 case 5: ...\InsetSpace ~
32300 case 3: ...\InsetSpace ~
32331 case 6: ...\InsetSpace ~
32363 case 7: ...\InsetSpace ~
32395 case 8: ...\InsetSpace ~
32427 case 9: ...\InsetSpace ~
32459 case 10: ...\InsetSpace ~
32490 case 11: ...\InsetSpace ~
32557 \begin_layout Standard
32558 Both the above switch statements will be implemented using a jump-table.
32559 The example to the right side is slightly more efficient as the check for
32560 the lower boundary of the jump-table is not needed.
32564 \begin_layout Itemize
32565 The number of case labels is not larger than supported by the target architectur
32569 \begin_layout Itemize
32570 If the case labels are not in numerical sequence ('gaps' between cases)
32571 SDCC checks whether a jump table with additionally inserted dummy cases
32572 is still attractive.
32576 \begin_layout Itemize
32577 If the starting number is not zero and a check for the lower boundary of
32578 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
32583 \begin_layout Standard
32584 Switch statements which have large gaps in the numeric sequence or those
32585 that have too many case labels can be split into more than one switch statement
32586 for efficient code generation, e.g.:
32589 \begin_layout Verse
32667 \begin_layout Standard
32668 If the above switch statement is broken down into two switch statements
32671 \begin_layout Verse
32714 \begin_layout Standard
32718 \begin_layout Verse
32761 \begin_layout Standard
32762 then both the switch statements will be implemented using jump-tables whereas
32763 the unmodified switch statement will not be.
32766 \begin_layout Standard
32767 \begin_inset Note Note
32770 \begin_layout Standard
32771 There might be reasons which SDCC cannot know about to either favour or
32772 not favour jump tables.
32773 If the target system has to be as quick for the last switch case as for
32774 the first (pro jump table), or if the switch argument is known to be zero
32775 in the majority of the cases (contra jump table).
32783 \begin_layout Standard
32784 The pragma nojtbound
32785 \begin_inset LatexCommand \index{\#pragma nojtbound}
32789 can be used to turn off checking the
32802 It has no effect if a default label is supplied.
32803 Use of this pragma is dangerous: if the switch
32804 \begin_inset LatexCommand \index{switch statement}
32808 argument is not matched by a case statement the processor will happily
32812 \begin_layout Subsection
32813 Bit-shifting Operations
32814 \begin_inset LatexCommand \index{Bit shifting}
32821 \begin_layout Standard
32822 Bit shifting is one of the most frequently used operation in embedded programmin
32824 SDCC tries to implement bit-shift operations in the most efficient way
32828 \begin_layout Verse
32841 \begin_layout Standard
32842 generates the following code:
32845 \begin_layout Verse
32860 \begin_layout Standard
32861 In general SDCC will never setup a loop if the shift count is known.
32865 \begin_layout Verse
32878 \begin_layout Standard
32882 \begin_layout Verse
32906 \begin_layout Subsection
32908 \begin_inset LatexCommand \index{Bit rotation}
32915 \begin_layout Standard
32916 A special case of the bit-shift operation is bit rotation
32917 \begin_inset LatexCommand \index{rotating bits}
32921 , SDCC recognizes the following expression to be a left bit-rotation:
32924 \begin_layout Verse
32932 char i;\InsetSpace ~
32943 /* unsigned is needed for rotation */
32948 i = ((i << 1) | (i >> 7));
32957 \begin_layout Standard
32958 will generate the following code:
32961 \begin_layout Verse
32978 \begin_layout Standard
32979 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32980 ns of this case will also be recognized as bit-rotation, i.e.:
32983 \begin_layout Verse
32986 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32989 \begin_layout Subsection
32990 Nibble and Byte Swapping
32993 \begin_layout Standard
32994 Other special cases of the bit-shift operations are nibble or byte swapping
32995 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32999 , SDCC recognizes the following expressions:
33002 \begin_layout Verse
33023 i = ((i << 4) | (i >> 4));
33029 j = ((j << 8) | (j >> 8));
33032 \begin_layout Standard
33033 and generates a swap instruction for the nibble swapping
33034 \begin_inset LatexCommand \index{Nibble swapping}
33038 or move instructions for the byte swapping
33039 \begin_inset LatexCommand \index{Byte swapping}
33045 \begin_inset Quotes sld
33049 \begin_inset Quotes srd
33052 example can be used to convert from little to big-endian or vice versa.
33053 If you want to change the endianness of a
33057 integer you have to cast to
33064 \begin_layout Standard
33065 Note that SDCC stores numbers in little-endian
33069 \begin_layout Standard
33070 Usually 8-bit processors don't care much about endianness.
33071 This is not the case for the standard 8051 which only has an instruction
33077 \begin_inset LatexCommand \index{DPTR}
33085 so little-endian is the more efficient byte order.
33091 \begin_inset LatexCommand \index{little-endian}
33096 \begin_inset LatexCommand \index{Endianness}
33101 lowest order first).
33104 \begin_layout Subsection
33106 \begin_inset LatexCommand \index{Highest Order Bit}
33111 \begin_inset LatexCommand \index{Any Order Bit}
33118 \begin_layout Standard
33119 It is frequently required to obtain the highest order bit of an integral
33120 type (long, int, short or char types).
33121 Also obtaining any other order bit is not uncommon.
33122 SDCC recognizes the following expressions to yield the highest order bit
33123 and generates optimized code for it, e.g.:
33126 \begin_layout Verse
33137 unsigned char hob1, aob1;
33141 bit hob2, hob3, aob2,
33151 hob1 = (gint >> 15) & 1;
33155 hob2 = (gint >> 15) & 1;
33159 hob3 = gint & 0x8000;
33164 aob1 = (gint >> 9) & 1;
33168 aob2 = (gint >> 8) & 1;
33172 aob3 = gint & 0x0800;
33182 \begin_layout Standard
33183 will generate the following code:
33186 \begin_layout Verse
33217 000A E5*01\InsetSpace ~
33244 000C 23\InsetSpace ~
33275 000D 54 01\InsetSpace ~
33303 000F F5*02\InsetSpace ~
33358 0011 E5*01\InsetSpace ~
33386 0013 33\InsetSpace ~
33416 0014 92*00\InsetSpace ~
33472 0016 E5*01\InsetSpace ~
33499 0018 33\InsetSpace ~
33529 0019 92*01\InsetSpace ~
33585 001B E5*01\InsetSpace ~
33644 001E 54 01\InsetSpace ~
33671 0020 F5*03\InsetSpace ~
33727 0022 E5*01\InsetSpace ~
33754 0024 13\InsetSpace ~
33784 0025 92*02\InsetSpace ~
33840 0027 E5*01\InsetSpace ~
33895 002B 92*03\InsetSpace ~
33923 \begin_layout Standard
33924 Other variations of these cases however will
33929 They are standard C expressions, so I heartily recommend these be the only
33930 way to get the highest order bit, (it is portable).
33931 Of course it will be recognized even if it is embedded in other expressions,
33935 \begin_layout Verse
33938 xyz = gint + ((gint >> 15) & 1);
33941 \begin_layout Standard
33942 will still be recognized.
33945 \begin_layout Subsection
33947 \begin_inset LatexCommand \index{Higher Order Byte}
33951 / Higher Order Word
33952 \begin_inset LatexCommand \index{Higher Order Word}
33959 \begin_layout Standard
33960 It is also frequently required to obtain a higher order byte or word of
33961 a larger integral type (long, int or short types).
33962 SDCC recognizes the following expressions to yield the higher order byte
33963 or word and generates optimized code for it, e.g.:
33966 \begin_layout Verse
33971 unsigned long int glong;
33979 unsigned char hob1,
33984 unsigned int how1, how2;
33993 hob1 = (gint >> 8) & 0xFF;
33997 hob2 = glong >> 24;
34001 how1 = (glong >> 16) & 0xFFFF;
34016 \begin_layout Standard
34017 will generate the following code:
34020 \begin_layout Verse
34051 0037 85*01*06\InsetSpace ~
34073 _foo_hob1_1_1,(_gint + 1)
34104 003A 85*05*07\InsetSpace ~
34126 _foo_hob2_1_1,(_glong + 3)
34156 003D 85*04*08\InsetSpace ~
34179 _foo_how1_1_1,(_glong + 2)
34181 0040 85*05*09\InsetSpace ~
34206 0043 85*03*0A\InsetSpace ~
34228 _foo_how2_1_1,(_glong + 1)
34230 0046 85*04*0B\InsetSpace ~
34253 (_foo_how2_1_1 + 1),(_glong + 2)
34256 \begin_layout Standard
34257 Again, variations of these cases may
34262 They are standard C expressions, so I heartily recommend these be the only
34263 way to get the higher order byte/word, (it is portable).
34264 Of course it will be recognized even if it is embedded in other expressions,
34268 \begin_layout Verse
34271 xyz = gint + ((gint >> 8) & 0xFF);
34274 \begin_layout Standard
34275 will still be recognized.
34278 \begin_layout Subsection
34280 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34285 \begin_inset LatexCommand \index{Peephole optimizer}
34292 \begin_layout Standard
34293 The compiler uses a rule based, pattern matching and re-writing mechanism
34294 for peep-hole optimization.
34299 a peep-hole optimizer by Christopher W.
34300 Fraser (cwfraser\InsetSpace ~
34303 A default set of rules are compiled into the compiler, additional rules
34304 may be added with the
34310 \begin_layout Standard
34320 \begin_inset LatexCommand \index{-\/-peep-file}
34327 The rule language is best illustrated with examples.
34330 \begin_layout Verse
34352 \begin_layout Standard
34353 The above rule will change the following assembly
34354 \begin_inset LatexCommand \index{Assembler routines}
34361 \begin_layout Verse
34369 \begin_layout Standard
34373 \begin_layout Verse
34379 \begin_layout Standard
34380 Note: All occurrences of a
34384 (pattern variable) must denote the same string.
34385 With the above rule, the assembly sequence:
34388 \begin_layout Verse
34396 \begin_layout Standard
34397 will remain unmodified.
34401 Other special case optimizations may be added by the
34408 \begin_layout Standard
34421 some variants of the 8051 MCU
34422 \begin_inset LatexCommand \index{MCS51 variants}
34435 The following two rules will change all
34452 \begin_layout Verse
34455 replace { lcall %1 } by { acall %1 }
34457 replace { ljmp %1 } by { ajmp %1 }
34460 \begin_layout Standard
34463 inline-assembler code
34465 is also passed through the peep hole optimizer, thus the peephole optimizer
34466 can also be used as an assembly level macro expander.
34467 The rules themselves are MCU dependent whereas the rule language infra-structur
34468 e is MCU independent.
34469 Peephole optimization rules for other MCU can be easily programmed using
34474 The syntax for a rule is as follows:
34477 \begin_layout Verse
34480 rule := replace [ restart ] '{' <assembly sequence> '
34518 <assembly sequence> '
34536 '}' [if <functionName> ] '
34541 \begin_layout Standard
34542 <assembly sequence> := assembly instruction (each instruction including
34543 labels must be on a separate line).
34547 The optimizer will apply to the rules
34548 one by one from the top in the sequence of their appearance, it will terminate
34549 when all rules are exhausted.
34550 If the 'restart' option is specified, then the optimizer will start matching
34551 the rules again from the top, this option for a rule is expensive (performance)
34552 , it is intended to be used in situations where a transformation will trigger
34553 the same rule again.
34554 An example of this (not a good one, it has side effects) is the following
34558 \begin_layout Verse
34578 \begin_layout Standard
34579 Note that the replace pattern cannot be a blank, but can be a comment line.
34580 Without the 'restart' option only the innermost 'pop' 'push' pair would
34581 be eliminated, i.e.:
34584 \begin_layout Verse
34596 \begin_layout Standard
34600 \begin_layout Verse
34610 \begin_layout Standard
34615 the restart option the rule will be applied again to the resulting code
34616 and then all the pop-push pairs will be eliminated to yield:
34619 \begin_layout Verse
34627 \begin_layout Standard
34628 A conditional function can be attached to a rule.
34629 Attaching rules are somewhat more involved, let me illustrate this with
34633 \begin_layout Verse
34657 \begin_layout Standard
34658 The optimizer does a look-up of a function name table defined in function
34663 in the source file SDCCpeeph.c, with the name
34668 If it finds a corresponding entry the function is called.
34669 Note there can be no parameters specified for these functions, in this
34674 is crucial, since the function
34678 expects to find the label in that particular variable (the hash table containin
34679 g the variable bindings is passed as a parameter).
34680 If you want to code more such functions, take a close look at the function
34681 labelInRange and the calling mechanism in source file SDCCpeeph.c.
34682 Currently implemented are
34684 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
34685 24bitMode, portIsDS390, 24bitModeAndPortDS390
34694 \begin_layout Standard
34695 I know this whole thing is a little kludgey, but maybe some day we will
34696 have some better means.
34697 If you are looking at this file, you will see the default rules that are
34698 compiled into the compiler, you can add your own rules in the default set
34699 there if you get tired of specifying the -
34703 \begin_layout Standard
34715 \begin_layout Section
34717 \begin_inset LatexCommand \index{ANSI-compliance}
34722 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
34729 \begin_layout Standard
34730 The latest publically available version of the standard
34732 ISO/IEC 9899 - Programming languages - C
34734 should be available at:
34735 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
34744 \begin_layout Standard
34745 Deviations from the compliance:
34748 \begin_layout Itemize
34749 functions are not reentrant
34750 \begin_inset LatexCommand \index{reentrant}
34754 unless explicitly declared as such or the
34760 \begin_layout Standard
34770 \begin_inset LatexCommand \index{-\/-stack-auto}
34776 command line option is specified.
34779 \begin_layout Itemize
34781 \begin_inset LatexCommand \index{struct}
34786 \begin_inset LatexCommand \index{union}
34790 cannot be assigned values directly, cannot be passed as function parameters
34791 or assigned to each other and cannot be a return value
34792 \begin_inset LatexCommand \index{return value}
34796 from a function, e.g.:
34800 \begin_layout Verse
34823 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
34842 s parms) /* invalid in SDCC although allowed in ANSI */
34864 return rets; /* is invalid in SDCC although allowed in ANSI */
34870 \begin_layout Itemize
34871 initialization of structure arrays must be fully braced.
34875 \begin_layout Verse
34878 struct s { char x } a[] = {1, 2};\InsetSpace ~
34883 /* invalid in SDCC */
34886 } a[] = {{1}, {2}}; /* OK */
34890 \begin_layout Itemize
34892 \begin_inset LatexCommand \index{long long (not supported)}
34897 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
34904 \begin_layout Itemize
34906 \begin_inset LatexCommand \index{double (not supported)}
34910 ' precision floating point
34911 \begin_inset LatexCommand \index{Floating point support}
34918 \begin_layout Itemize
34920 \begin_inset LatexCommand \index{K\&R style}
34924 function declarations are NOT allowed.
34928 \begin_layout Verse
34931 foo(i,j) /* this old style of function declarations */
34933 int i,j; /* are valid
34934 in ANSI but not valid in SDCC */
34949 \begin_layout Itemize
34950 Most enhancements in C99 are not supported, f.e.:
34954 \begin_layout Verse
34959 \begin_inset LatexCommand \index{inline (not supported)}
34965 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34971 can be used as a work around */
34979 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34983 \begin_layout Itemize
34984 Certain words that are valid identifiers in the standard may be reserved
34985 words in SDCC unless the
34991 \begin_layout Standard
35001 \begin_inset LatexCommand \index{-\/-std-c89}
35009 \begin_layout Standard
35019 \begin_inset LatexCommand \index{-\/-std-c99}
35025 command line options are used.
35026 These may include (depending on the selected processor): 'at', 'banked',
35027 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35028 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35029 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35031 Compliant equivalents of these keywords are always available in a form
35032 that begin with two underscores
35033 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35038 '__data' instead of 'data'.
35041 \begin_layout Section
35042 Cyclomatic Complexity
35043 \begin_inset LatexCommand \index{Cyclomatic complexity}
35050 \begin_layout Standard
35051 Cyclomatic complexity of a function is defined as the number of independent
35052 paths the program can take during execution of the function.
35053 This is an important number since it defines the number test cases you
35054 have to generate to validate the function.
35055 The accepted industry standard for complexity number is 10, if the cyclomatic
35056 complexity reported by SDCC exceeds 10 you should think about simplification
35057 of the function logic.
35058 Note that the complexity level is not related to the number of lines of
35059 code in a function.
35060 Large functions can have low complexity, and small functions can have large
35066 SDCC uses the following formula to compute the complexity:
35071 \begin_layout Standard
35072 complexity = (number of edges in control flow graph) - (number of nodes
35073 in control flow graph) + 2;
35077 Having said that the industry standard is 10,
35078 you should be aware that in some cases it be may unavoidable to have a
35079 complexity level of less than 10.
35080 For example if you have switch statement with more than 10 case labels,
35081 each case label adds one to the complexity level.
35082 The complexity level is by no means an absolute measure of the algorithmic
35083 complexity of the function, it does however provide a good starting point
35084 for which functions you might look at for further optimization.
35087 \begin_layout Section
35088 Retargetting for other Processors
35091 \begin_layout Standard
35092 The issues for retargetting the compiler are far too numerous to be covered
35094 What follows is a brief description of each of the seven phases of the
35095 compiler and its MCU dependency.
35098 \begin_layout Itemize
35099 Parsing the source and building the annotated parse tree.
35100 This phase is largely MCU independent (except for the language extensions).
35101 Syntax & semantic checks are also done in this phase, along with some initial
35102 optimizations like back patching labels and the pattern matching optimizations
35103 like bit-rotation etc.
35106 \begin_layout Itemize
35107 The second phase involves generating an intermediate code which can be easy
35108 manipulated during the later phases.
35109 This phase is entirely MCU independent.
35110 The intermediate code generation assumes the target machine has unlimited
35111 number of registers, and designates them with the name iTemp.
35112 The compiler can be made to dump a human readable form of the code generated
35117 \begin_layout Standard
35129 \begin_layout Itemize
35130 This phase does the bulk of the standard optimizations and is also MCU independe
35132 This phase can be broken down into several sub-phases:
35136 Break down intermediate
35137 code (iCode) into basic blocks.
35139 Do control flow & data flow analysis on the
35142 Do local common subexpression elimination, then global subexpressio
35145 Dead code elimination
35149 If loop optimizations
35150 caused any changes then do 'global subexpression elimination' and 'dead
35151 code elimination' again.
35154 \begin_layout Itemize
35155 This phase determines the live-ranges; by live range I mean those iTemp
35156 variables defined by the compiler that still survive after all the optimization
35158 Live range analysis
35159 \begin_inset LatexCommand \index{Live range analysis}
35163 is essential for register allocation, since these computation determines
35164 which of these iTemps will be assigned to registers, and for how long.
35167 \begin_layout Itemize
35168 Phase five is register allocation.
35169 There are two parts to this process.
35173 The first part I call 'register packing'
35174 (for lack of a better term).
35175 In this case several MCU specific expression folding is done to reduce
35180 The second part is more MCU independent and deals with
35181 allocating registers to the remaining live ranges.
35182 A lot of MCU specific code does creep into this phase because of the limited
35183 number of index registers available in the 8051.
35186 \begin_layout Itemize
35187 The Code generation phase is (unhappily), entirely MCU dependent and very
35188 little (if any at all) of this code can be reused for other MCU.
35189 However the scheme for allocating a homogenized assembler operand for each
35190 iCode operand may be reused.
35193 \begin_layout Itemize
35194 As mentioned in the optimization section the peep-hole optimizer is rule
35195 based system, which can reprogrammed for other MCUs.
35198 \begin_layout Standard
35199 More information is available in a wiki
35200 \begin_inset LatexCommand \index{wiki}
35205 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35209 ) and in the thread
35210 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35217 \begin_layout Chapter
35219 \begin_inset LatexCommand \index{Compiler internals}
35226 \begin_layout Section
35227 The anatomy of the compiler
35228 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35235 \begin_layout Standard
35238 This is an excerpt from an article published in Circuit Cellar Magazine
35244 It's a little outdated (the compiler is much more efficient now and user/develo
35245 per friendly), but pretty well exposes the guts of it all.
35251 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35252 It is fairly easy to retarget for other 8-bit MCU.
35253 Here we take a look at some of the internals of the compiler.
35257 \begin_layout Paragraph*
35259 \begin_inset LatexCommand \index{Parsing}
35266 \begin_layout Standard
35267 Parsing the input source file and creating an AST (Annotated Syntax Tree
35268 \begin_inset LatexCommand \index{Annotated syntax tree}
35273 This phase also involves propagating types (annotating each node of the
35274 parse tree with type information) and semantic analysis.
35275 There are some MCU specific parsing rules.
35276 For example the storage classes, the extended storage classes are MCU specific
35277 while there may be a xdata storage class for 8051 there is no such storage
35278 class for z80 or Atmel AVR.
35279 SDCC allows MCU specific storage class extensions, i.e.
35280 xdata will be treated as a storage class specifier when parsing 8051 C
35281 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35285 \begin_layout Paragraph*
35287 \begin_inset LatexCommand \index{iCode}
35294 \begin_layout Standard
35295 Intermediate code generation.
35296 In this phase the AST is broken down into three-operand form (iCode).
35297 These three operand forms are represented as doubly linked lists.
35298 ICode is the term given to the intermediate form generated by the compiler.
35299 ICode example section shows some examples of iCode generated for some simple
35300 C source functions.
35303 \begin_layout Paragraph*
35305 \begin_inset LatexCommand \index{Optimizations}
35312 \begin_layout Standard
35313 Bulk of the target independent optimizations is performed in this phase.
35314 The optimizations include constant propagation, common sub-expression eliminati
35315 on, loop invariant code movement, strength reduction of loop induction variables
35316 and dead-code elimination.
35319 \begin_layout Paragraph*
35320 Live range analysis
35321 \begin_inset LatexCommand \index{Live range analysis}
35328 \begin_layout Standard
35329 During intermediate code generation phase, the compiler assumes the target
35330 machine has infinite number of registers and generates a lot of temporary
35332 The live range computation determines the lifetime of each of these compiler-ge
35333 nerated temporaries.
35334 A picture speaks a thousand words.
35335 ICode example sections show the live range annotations for each of the
35337 It is important to note here, each iCode is assigned a number in the order
35338 of its execution in the function.
35339 The live ranges are computed in terms of these numbers.
35340 The from number is the number of the iCode which first defines the operand
35341 and the to number signifies the iCode which uses this operand last.
35344 \begin_layout Paragraph*
35345 Register Allocation
35346 \begin_inset LatexCommand \index{Register allocation}
35353 \begin_layout Standard
35354 The register allocation determines the type and number of registers needed
35356 In most MCUs only a few registers can be used for indirect addressing.
35357 In case of 8051 for example the registers R0 & R1 can be used to indirectly
35358 address the internal ram and DPTR to indirectly address the external ram.
35359 The compiler will try to allocate the appropriate register to pointer variables
35361 ICode example section shows the operands annotated with the registers assigned
35363 The compiler will try to keep operands in registers as much as possible;
35364 there are several schemes the compiler uses to do achieve this.
35365 When the compiler runs out of registers the compiler will check to see
35366 if there are any live operands which is not used or defined in the current
35367 basic block being processed, if there are any found then it will push that
35368 operand and use the registers in this block, the operand will then be popped
35369 at the end of the basic block.
35373 \begin_layout Standard
35374 There are other MCU specific considerations in this phase.
35375 Some MCUs have an accumulator; very short-lived operands could be assigned
35376 to the accumulator instead of a general-purpose register.
35379 \begin_layout Paragraph*
35383 \begin_layout Standard
35384 Figure II gives a table of iCode
35385 \begin_inset LatexCommand \index{iCode}
35389 operations supported by the compiler.
35390 The code generation involves translating these operations into corresponding
35391 assembly code for the processor.
35392 This sounds overly simple but that is the essence of code generation.
35393 Some of the iCode operations are generated on a MCU specific manner for
35394 example, the z80 port does not use registers to pass parameters so the
35395 SEND and RECV iCode operations will not be generated, and it also does
35396 not support JUMPTABLES.
35402 \begin_layout Standard
35406 \begin_inset Tabular
35407 <lyxtabular version="3" rows="39" columns="4">
35408 <features islongtable="true" headBottomDL="true">
35409 <column alignment="block" valignment="top" leftline="true" width="13col%">
35410 <column alignment="left" valignment="top" leftline="true" width="13col%">
35411 <column alignment="block" valignment="top" leftline="true" width="22col%">
35412 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
35413 <row topline="true" bottomline="true" endhead="true">
35414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35417 \begin_layout Standard
35423 \begin_inset LatexCommand \index{iCode}
35432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35435 \begin_layout Standard
35443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35446 \begin_layout Standard
35454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35457 \begin_layout Standard
35466 <row topline="true">
35467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35470 \begin_layout Standard
35478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35481 \begin_layout Standard
35484 IC_LEFT() IC_RESULT()
35489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35492 \begin_layout Standard
35500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35503 \begin_layout Standard
35506 IC_RESULT = ! IC_LEFT;
35512 <row topline="true">
35513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35516 \begin_layout Standard
35524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35527 \begin_layout Standard
35530 IC_LEFT() IC_RESULT()
35535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35538 \begin_layout Standard
35541 Bitwise complement of
35546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35549 \begin_layout Standard
35552 IC_RESULT = ~IC_LEFT;
35558 <row topline="true">
35559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35562 \begin_layout Standard
35570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35573 \begin_layout Standard
35576 IC_LEFT() IC_RESULT()
35581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35584 \begin_layout Standard
35587 Rotate right with carry
35592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35595 \begin_layout Standard
35598 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
35604 <row topline="true">
35605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35608 \begin_layout Standard
35616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35619 \begin_layout Standard
35622 IC_LEFT() IC_RESULT()
35627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35630 \begin_layout Standard
35633 Rotate left with carry
35638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35641 \begin_layout Standard
35644 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
35650 <row topline="true">
35651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35654 \begin_layout Standard
35662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35665 \begin_layout Standard
35668 IC_LEFT() IC_RESULT()
35673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35676 \begin_layout Standard
35679 Get the highest order bit of IC_LEFT
35684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35687 \begin_layout Standard
35690 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
35696 <row topline="true">
35697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35700 \begin_layout Standard
35708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35711 \begin_layout Standard
35714 IC_LEFT() IC_RESULT()
35719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35722 \begin_layout Standard
35730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35733 \begin_layout Standard
35736 IC_RESULT = - IC_LEFT;
35742 <row topline="true">
35743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35746 \begin_layout Standard
35754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35757 \begin_layout Standard
35765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35768 \begin_layout Standard
35771 Push the operand into stack
35776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35779 \begin_layout Standard
35788 <row topline="true">
35789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35792 \begin_layout Standard
35800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35803 \begin_layout Standard
35811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35814 \begin_layout Standard
35817 Pop the operand from the stack
35822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35825 \begin_layout Standard
35834 <row topline="true">
35835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35838 \begin_layout Standard
35846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35849 \begin_layout Standard
35852 IC_LEFT() IC_RESULT()
35857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35860 \begin_layout Standard
35863 Call the function represented by IC_LEFT
35868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35871 \begin_layout Standard
35874 IC_RESULT = IC_LEFT();
35880 <row topline="true">
35881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35884 \begin_layout Standard
35892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35895 \begin_layout Standard
35898 IC_LEFT() IC_RESULT()
35903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35906 \begin_layout Standard
35909 Call via function pointer
35914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35917 \begin_layout Standard
35920 IC_RESULT = (*IC_LEFT)();
35926 <row topline="true">
35927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35930 \begin_layout Standard
35938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35941 \begin_layout Standard
35949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35952 \begin_layout Standard
35955 Return the value in operand IC_LEFT
35960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35963 \begin_layout Standard
35972 <row topline="true">
35973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35976 \begin_layout Standard
35984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35987 \begin_layout Standard
35995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35998 \begin_layout Standard
36006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36009 \begin_layout Standard
36018 <row topline="true">
36019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36022 \begin_layout Standard
36030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36033 \begin_layout Standard
36041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36044 \begin_layout Standard
36052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36055 \begin_layout Standard
36064 <row topline="true">
36065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36068 \begin_layout Standard
36076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36079 \begin_layout Standard
36082 IC_LEFT() IC_RIGHT() IC_RESULT()
36087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36090 \begin_layout Standard
36098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36101 \begin_layout Standard
36104 IC_RESULT = IC_LEFT + IC_RIGHT
36110 <row topline="true">
36111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36114 \begin_layout Standard
36122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36125 \begin_layout Standard
36128 IC_LEFT() IC_RIGHT() IC_RESULT()
36133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36136 \begin_layout Standard
36144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36147 \begin_layout Standard
36150 IC_RESULT = IC_LEFT - IC_RIGHT
36156 <row topline="true">
36157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36160 \begin_layout Standard
36168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36171 \begin_layout Standard
36174 IC_LEFT() IC_RIGHT() IC_RESULT()
36179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36182 \begin_layout Standard
36190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36193 \begin_layout Standard
36196 IC_RESULT = IC_LEFT * IC_RIGHT;
36202 <row topline="true">
36203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36206 \begin_layout Standard
36214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36217 \begin_layout Standard
36220 IC_LEFT() IC_RIGHT() IC_RESULT()
36225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36228 \begin_layout Standard
36236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36239 \begin_layout Standard
36242 IC_RESULT = IC_LEFT / IC_RIGHT;
36248 <row topline="true">
36249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36252 \begin_layout Standard
36260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36263 \begin_layout Standard
36266 IC_LEFT() IC_RIGHT() IC_RESULT()
36271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36274 \begin_layout Standard
36282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36285 \begin_layout Standard
36288 IC_RESULT = IC_LEFT % IC_RIGHT;
36294 <row topline="true">
36295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36298 \begin_layout Standard
36306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36309 \begin_layout Standard
36312 IC_LEFT() IC_RIGHT() IC_RESULT()
36317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36320 \begin_layout Standard
36328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36331 \begin_layout Standard
36334 IC_RESULT = IC_LEFT < IC_RIGHT;
36340 <row topline="true">
36341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36344 \begin_layout Standard
36352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36355 \begin_layout Standard
36358 IC_LEFT() IC_RIGHT() IC_RESULT()
36363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36366 \begin_layout Standard
36374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36377 \begin_layout Standard
36380 IC_RESULT = IC_LEFT > IC_RIGHT;
36386 <row topline="true">
36387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36390 \begin_layout Standard
36398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36401 \begin_layout Standard
36404 IC_LEFT() IC_RIGHT() IC_RESULT()
36409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36412 \begin_layout Standard
36420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36423 \begin_layout Standard
36426 IC_RESULT = IC_LEFT == IC_RIGHT;
36432 <row topline="true">
36433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36436 \begin_layout Standard
36444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36447 \begin_layout Standard
36450 IC_LEFT() IC_RIGHT() IC_RESULT()
36455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36458 \begin_layout Standard
36461 Logical and operation
36466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36469 \begin_layout Standard
36472 IC_RESULT = IC_LEFT && IC_RIGHT;
36478 <row topline="true">
36479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36482 \begin_layout Standard
36490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36493 \begin_layout Standard
36496 IC_LEFT() IC_RIGHT() IC_RESULT()
36501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36504 \begin_layout Standard
36507 Logical or operation
36512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36515 \begin_layout Standard
36518 IC_RESULT = IC_LEFT || IC_RIGHT;
36524 <row topline="true">
36525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36528 \begin_layout Standard
36536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36539 \begin_layout Standard
36542 IC_LEFT() IC_RIGHT() IC_RESULT()
36547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36550 \begin_layout Standard
36558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36561 \begin_layout Standard
36564 IC_RESULT = IC_LEFT ^ IC_RIGHT;
36570 <row topline="true">
36571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36574 \begin_layout Standard
36582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36585 \begin_layout Standard
36588 IC_LEFT() IC_RIGHT() IC_RESULT()
36593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36596 \begin_layout Standard
36604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36607 \begin_layout Standard
36610 IC_RESULT = IC_LEFT | IC_RIGHT;
36616 <row topline="true">
36617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36620 \begin_layout Standard
36628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36631 \begin_layout Standard
36634 IC_LEFT() IC_RIGHT() IC_RESULT()
36639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36642 \begin_layout Standard
36650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36653 \begin_layout Standard
36656 IC_RESULT = IC_LEFT & IC_RIGHT;
36662 <row topline="true">
36663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36666 \begin_layout Standard
36674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36677 \begin_layout Standard
36680 IC_LEFT() IC_RIGHT() IC_RESULT()
36685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36688 \begin_layout Standard
36696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36699 \begin_layout Standard
36702 IC_RESULT = IC_LEFT << IC_RIGHT
36708 <row topline="true">
36709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36712 \begin_layout Standard
36720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36723 \begin_layout Standard
36726 IC_LEFT() IC_RIGHT() IC_RESULT()
36731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36734 \begin_layout Standard
36742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36745 \begin_layout Standard
36748 IC_RESULT = IC_LEFT >> IC_RIGHT
36754 <row topline="true">
36755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36758 \begin_layout Standard
36768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36771 \begin_layout Standard
36774 IC_LEFT() IC_RESULT()
36779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36782 \begin_layout Standard
36790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36793 \begin_layout Standard
36796 IC_RESULT = (*IC_LEFT);
36802 <row topline="true">
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36806 \begin_layout Standard
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36817 \begin_layout Standard
36820 IC_RIGHT() IC_RESULT()
36825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36828 \begin_layout Standard
36836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36839 \begin_layout Standard
36842 (*IC_RESULT) = IC_RIGHT;
36848 <row topline="true">
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36852 \begin_layout Standard
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36863 \begin_layout Standard
36866 IC_RIGHT() IC_RESULT()
36871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36874 \begin_layout Standard
36882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36885 \begin_layout Standard
36888 IC_RESULT = IC_RIGHT;
36894 <row topline="true">
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36898 \begin_layout Standard
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36909 \begin_layout Standard
36912 IC_COND IC_TRUE IC_LABEL
36917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36920 \begin_layout Standard
36924 If true label is present then jump to true label if condition is true else
36925 jump to false label if condition is false
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36933 \begin_layout Standard
36936 if (IC_COND) goto IC_TRUE;
36942 If (!IC_COND) goto IC_FALSE;
36948 <row topline="true">
36949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36952 \begin_layout Standard
36960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36963 \begin_layout Standard
36966 IC_LEFT() IC_RESULT()
36971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36974 \begin_layout Standard
36982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36985 \begin_layout Standard
36988 IC_RESULT = &IC_LEFT();
36994 <row topline="true">
36995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36998 \begin_layout Standard
37006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37009 \begin_layout Standard
37012 IC_JTCOND IC_JTLABELS
37017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37020 \begin_layout Standard
37023 Jump to list of labels depending on the value of JTCOND
37028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37031 \begin_layout Standard
37040 <row topline="true">
37041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37044 \begin_layout Standard
37052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37055 \begin_layout Standard
37058 IC_RIGHT() IC_LEFT() IC_RESULT()
37063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37066 \begin_layout Standard
37074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37077 \begin_layout Standard
37080 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37086 <row topline="true">
37087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37090 \begin_layout Standard
37098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37101 \begin_layout Standard
37109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37112 \begin_layout Standard
37115 This is used for passing parameters in registers;
37117 move IC_LEFT to the next
37118 available parameter register.
37123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37126 \begin_layout Standard
37135 <row topline="true">
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37139 \begin_layout Standard
37147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37150 \begin_layout Standard
37158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37161 \begin_layout Standard
37164 This is used for receiving parameters passed in registers;
37167 in the next parameter register to IC_RESULT
37172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37175 \begin_layout Standard
37184 <row topline="true" bottomline="true">
37185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37188 \begin_layout Standard
37192 (some more have been added)
37197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37200 \begin_layout Standard
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37209 \begin_layout Standard
37215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37218 \begin_layout Standard
37242 \begin_layout Standard
37243 \begin_inset Note Note
37246 \begin_layout Standard
37247 In the original article Figure II was announced to be downloadable on
37252 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37260 \begin_layout Paragraph*
37262 \begin_inset LatexCommand \index{iCode}
37269 \begin_layout Standard
37270 This section shows some details of iCode.
37271 The example C code does not do anything useful; it is used as an example
37272 to illustrate the intermediate code generated by the compiler.
37275 \begin_layout Verse
37285 /* This function does nothing useful.
37292 for the purpose of explaining iCode */
37295 short function (data
37304 short i=10; \InsetSpace ~
37306 /* dead initialization eliminated */
37312 /* dead initialization eliminated */
37340 /* compiler detects i,j to be induction
37345 for (i = 0, j = 10 ; i < 10 ; i++, j
37351 \begin_layout Standard
37374 mul += i * 3; \InsetSpace ~
37376 /* this multiplication remains */
37383 j * 3;\InsetSpace ~
37385 /* this multiplication changed to addition */
37399 \begin_layout Standard
37400 In addition to the operands each iCode contains information about the filename
37401 and line it corresponds to in the source file.
37402 The first field in the listing should be interpreted as follows:
37407 Filename(linenumber: iCode Execution sequence number : ICode hash table
37408 key : loop depth of the iCode).
37413 Then follows the human readable form of the ICode operation.
37414 Each operand of this triplet form can be of three basic types a) compiler
37415 generated temporary b) user defined variable c) a constant value.
37416 Note that local variables and parameters are replaced by compiler generated
37419 \begin_inset LatexCommand \index{Live range analysis}
37423 are computed only for temporaries (i.e.
37424 live ranges are not computed for global variables).
37426 \begin_inset LatexCommand \index{Register allocation}
37430 are allocated for temporaries only.
37431 Operands are formatted in the following manner:
37436 Operand Name [lr live-from : live-to ] { type information } [ registers
37442 As mentioned earlier the live ranges are computed in terms of the execution
37443 sequence number of the iCodes, for example
37445 the iTemp0 is live from (i.e.
37446 first defined in iCode with execution sequence number 3, and is last used
37447 in the iCode with sequence number 5).
37448 For induction variables such as iTemp21 the live range computation extends
37449 the lifetime from the start to the end of the loop.
37451 The register allocator
37452 used the live range information to allocate registers, the same registers
37453 may be used for different temporaries if their live ranges do not overlap,
37454 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
37455 ranges do not overlap.
37456 In addition the allocator also takes into consideration the type and usage
37457 of a temporary, for example itemp6 is a pointer to near space and is used
37458 as to fetch data from (i.e.
37459 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
37460 Some short lived temporaries are allocated to special registers which have
37461 meaning to the code generator e.g.
37462 iTemp13 is allocated to a pseudo register CC which tells the back end that
37463 the temporary is used only for a conditional jump the code generation makes
37464 use of this information to optimize a compare and jump ICode.
37468 \begin_inset LatexCommand \index{Loop optimization}
37472 performed by the compiler.
37473 It can detect induction variables iTemp21(i) and iTemp23(j).
37474 Also note the compiler does selective strength reduction
37475 \begin_inset LatexCommand \index{Strength reduction}
37480 the multiplication of an induction variable in line 18 (gint = j * 3) is
37481 changed to addition, a new temporary iTemp17 is allocated and assigned
37482 a initial value, a constant 3 is then added for each iteration of the loop.
37483 The compiler does not change the multiplication
37484 \begin_inset LatexCommand \index{Multiplication}
37488 in line 17 however since the processor does support an 8 * 8 bit multiplication.
37491 Note the dead code elimination
37492 \begin_inset LatexCommand \index{Dead-code elimination}
37496 optimization eliminated the dead assignments in line 7 & 8 to I and sum
37502 \begin_layout Standard
37505 Sample.c (5:1:0:0) _entry($9) :
37508 \begin_layout Standard
37511 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
37514 \begin_layout Standard
37517 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
37520 \begin_layout Standard
37523 Sample.c(11:4:53:0) preHeaderLbl0($11) :
37526 \begin_layout Standard
37529 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
37533 \begin_layout Standard
37536 Sample.c(11:6:5:1) _whilecontinue_0($1) :
37539 \begin_layout Standard
37542 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
37546 \begin_layout Standard
37549 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
37552 \begin_layout Standard
37555 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
37559 \begin_layout Standard
37562 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
37566 \begin_layout Standard
37569 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
37573 \begin_layout Standard
37576 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
37580 \begin_layout Standard
37583 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
37584 * int}[r0] + 0x2 {short}
37587 \begin_layout Standard
37590 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
37593 \begin_layout Standard
37596 Sample.c(11:17:21:0)_whilebreak_0($3) :
37599 \begin_layout Standard
37602 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37605 \begin_layout Standard
37608 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37611 \begin_layout Standard
37614 Sample.c(15:20:54:0)preHeaderLbl1($13) :
37617 \begin_layout Standard
37620 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37623 \begin_layout Standard
37626 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37629 \begin_layout Standard
37632 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37635 \begin_layout Standard
37638 Sample.c(15:24:26:1)_forcond_0($4) :
37641 \begin_layout Standard
37644 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
37648 \begin_layout Standard
37651 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37654 \begin_layout Standard
37657 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
37658 + ITemp21 [lr21:38]{short}[r4]
37661 \begin_layout Standard
37664 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
37668 \begin_layout Standard
37671 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
37672 + iTemp15 [lr29:30]{short}[r1]
37675 \begin_layout Standard
37678 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
37682 \begin_layout Standard
37685 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
37689 \begin_layout Standard
37692 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
37696 \begin_layout Standard
37699 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
37703 \begin_layout Standard
37706 Sample.c(19:38:47:1) goto _forcond_0($4)
37709 \begin_layout Standard
37712 Sample.c(19:39:48:0)_forbreak_0($7) :
37715 \begin_layout Standard
37718 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
37719 + ITemp11 [lr19:40]{short}[r3]
37722 \begin_layout Standard
37725 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
37728 \begin_layout Standard
37731 Sample.c(20:42:51:0)_return($8) :
37734 \begin_layout Standard
37737 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
37743 Finally the code generated for this function:
37748 \begin_layout Standard
37754 \begin_layout Standard
37760 \begin_layout Standard
37768 \begin_layout Standard
37774 \begin_layout Standard
37782 \begin_layout Standard
37788 \begin_layout Standard
37791 ; ----------------------------------------------
37794 \begin_layout Standard
37797 ; function function
37800 \begin_layout Standard
37803 ; ----------------------------------------------
37806 \begin_layout Standard
37812 \begin_layout Standard
37815 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
37818 \begin_layout Standard
37826 \begin_layout Standard
37829 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
37832 \begin_layout Standard
37840 \begin_layout Standard
37843 ;_whilecontinue_0($1) :
37846 \begin_layout Standard
37852 \begin_layout Standard
37855 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
37858 \begin_layout Standard
37861 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
37864 \begin_layout Standard
37872 \begin_layout Standard
37880 \begin_layout Standard
37888 \begin_layout Standard
37896 \begin_layout Standard
37904 \begin_layout Standard
37912 \begin_layout Standard
37920 \begin_layout Standard
37926 \begin_layout Standard
37929 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37932 \begin_layout Standard
37940 \begin_layout Standard
37948 \begin_layout Standard
37951 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37954 \begin_layout Standard
37962 \begin_layout Standard
37970 \begin_layout Standard
37978 \begin_layout Standard
37986 \begin_layout Standard
37994 \begin_layout Standard
38002 \begin_layout Standard
38005 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38008 \begin_layout Standard
38016 \begin_layout Standard
38024 \begin_layout Standard
38032 \begin_layout Standard
38040 \begin_layout Standard
38048 \begin_layout Standard
38051 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38054 \begin_layout Standard
38062 \begin_layout Standard
38070 \begin_layout Standard
38078 \begin_layout Standard
38081 ; iTemp6 [lr5:16]{_near * int}[r0] =
38084 \begin_layout Standard
38087 ; iTemp6 [lr5:16]{_near * int}[r0] +
38090 \begin_layout Standard
38096 \begin_layout Standard
38104 \begin_layout Standard
38107 ; goto _whilecontinue_0($1)
38110 \begin_layout Standard
38118 \begin_layout Standard
38121 ; _whilebreak_0($3) :
38124 \begin_layout Standard
38130 \begin_layout Standard
38133 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38136 \begin_layout Standard
38144 \begin_layout Standard
38147 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38150 \begin_layout Standard
38158 \begin_layout Standard
38161 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38164 \begin_layout Standard
38172 \begin_layout Standard
38175 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38178 \begin_layout Standard
38186 \begin_layout Standard
38194 \begin_layout Standard
38197 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38200 \begin_layout Standard
38208 \begin_layout Standard
38216 \begin_layout Standard
38222 \begin_layout Standard
38228 \begin_layout Standard
38231 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38234 \begin_layout Standard
38237 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38240 \begin_layout Standard
38248 \begin_layout Standard
38256 \begin_layout Standard
38264 \begin_layout Standard
38272 \begin_layout Standard
38280 \begin_layout Standard
38286 \begin_layout Standard
38289 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38292 \begin_layout Standard
38295 ; iTemp21 [lr21:38]{short}[r4]
38298 \begin_layout Standard
38306 \begin_layout Standard
38314 \begin_layout Standard
38322 \begin_layout Standard
38325 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38328 \begin_layout Standard
38336 \begin_layout Standard
38344 \begin_layout Standard
38352 \begin_layout Standard
38360 \begin_layout Standard
38363 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
38366 \begin_layout Standard
38369 ; iTemp15 [lr29:30]{short}[r1]
38372 \begin_layout Standard
38380 \begin_layout Standard
38388 \begin_layout Standard
38391 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38394 \begin_layout Standard
38402 \begin_layout Standard
38410 \begin_layout Standard
38418 \begin_layout Standard
38426 \begin_layout Standard
38434 \begin_layout Standard
38442 \begin_layout Standard
38445 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
38448 \begin_layout Standard
38456 \begin_layout Standard
38464 \begin_layout Standard
38472 \begin_layout Standard
38480 \begin_layout Standard
38488 \begin_layout Standard
38496 \begin_layout Standard
38499 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
38502 \begin_layout Standard
38510 \begin_layout Standard
38513 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
38516 \begin_layout Standard
38524 \begin_layout Standard
38529 cjne r5,#0xff,00104$
38532 \begin_layout Standard
38540 \begin_layout Standard
38543 ; goto _forcond_0($4)
38546 \begin_layout Standard
38554 \begin_layout Standard
38557 ; _forbreak_0($7) :
38560 \begin_layout Standard
38566 \begin_layout Standard
38569 ; ret iTemp24 [lr40:41]{short}
38572 \begin_layout Standard
38580 \begin_layout Standard
38588 \begin_layout Standard
38596 \begin_layout Standard
38602 \begin_layout Standard
38608 \begin_layout Standard
38618 \begin_layout Section
38619 A few words about basic block successors, predecessors and dominators
38622 \begin_layout Standard
38623 Successors are basic blocks
38624 \begin_inset LatexCommand \index{Basic blocks}
38628 that might execute after this basic block.
38630 Predecessors are basic blocks
38631 that might execute before reaching this basic block.
38633 Dominators are basic
38634 blocks that WILL execute before reaching this basic block.
38639 \begin_layout Standard
38643 \begin_layout Standard
38647 \begin_layout Standard
38655 \begin_layout Standard
38659 \begin_layout Standard
38667 \begin_layout Standard
38673 \begin_layout Standard
38674 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
38677 \begin_layout Standard
38678 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
38681 \begin_layout Standard
38682 c) domVect of [BB4] = BB1 ...
38683 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
38687 \begin_layout Chapter
38691 \begin_layout Standard
38692 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
38702 Thanks to all the other volunteer developers who have helped with coding,
38703 testing, web-page creation, distribution sets, etc.
38704 You know who you are :-)
38712 Also thanks to Sourceforge
38713 \begin_inset LatexCommand \url{http://www.sf.net}
38717 which has hosted the project since 1999 and donates significant download
38718 bandwidth and probably more than
38722 \begin_layout Standard
38729 CPU cycles per day.
38732 \begin_inset Note Note
38735 \begin_layout Standard
38736 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
38737 minutes for (configure+make+regression test), and there is (i386, amd64,
38738 alpha, ppc64, (mingw32), sparc, macosx).
38747 \begin_layout Standard
38748 This document was initially written by Sandeep Dutta
38751 \begin_layout Standard
38752 All product names mentioned herein may be trademarks
38753 \begin_inset LatexCommand \index{Trademarks}
38757 of their respective companies.
38761 \begin_layout Section*
38765 \begin_layout Standard
38766 To avoid confusion, the installation and building options for SDCC itself
38767 (chapter 2) are not part of the index.
38770 \begin_layout Standard
38771 \begin_inset LatexCommand \printindex{}