1 #LyX 1.4.2 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the --short-is-8b
840 its commandline option (see
841 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
848 \begin_layout Itemize
849 the default directory for gcc-builds where include, library and documentation
850 files are stored is now in /usr/local/share.
853 \begin_layout Itemize
854 char type parameters to vararg
855 \begin_inset LatexCommand \index{vararg, va\_arg}
859 functions are casted to int unless explicitly casted
860 \begin_inset Marginal
863 \begin_layout Standard
888 will push a as an int and as a char resp.
891 \begin_layout Itemize
896 \begin_layout Standard
905 -regextend has been removed.
908 \begin_layout Itemize
913 \begin_layout Standard
922 -noregparms has been removed.
925 \begin_layout Itemize
930 \begin_layout Standard
939 -stack-after-data has been removed.
942 \begin_layout Itemize
944 \begin_inset LatexCommand \index{bit}
949 \begin_inset LatexCommand \index{sbit}
954 \begin_inset LatexCommand \index{\_\_sbit}
958 types now consistently behave like the C99 _Bool type with respect to type
960 \begin_inset LatexCommand \index{type conversion}
965 \begin_inset LatexCommand \index{type promotion}
970 The most common incompatibility resulting from this change is related to
972 \begin_inset LatexCommand \index{Bit toggling}
987 \begin_inset LatexCommand \index{\~\/ Operator}
991 b; /* equivalent to b=1 instead of toggling b */
992 \begin_inset Marginal
995 \begin_layout Standard
1008 b = !b; /* toggles b */
1012 In previous versions, both forms would have toggled the bit.
1015 \begin_layout Standard
1018 <pending: more incompatibilities?>
1021 \begin_layout Section
1025 \begin_layout Standard
1026 What do you need before you start installation of SDCC? A computer, and
1027 a desire to compute.
1028 The preferred method of installation is to compile SDCC from source using
1030 For Windows some pre-compiled binary distributions are available for your
1032 You should have some experience with command line tools and compiler use.
1035 \begin_layout Section
1039 \begin_layout Standard
1040 The SDCC home page at
1041 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1045 is a great place to find distribution sets.
1046 You can also find links to the user mailing lists that offer help or discuss
1047 SDCC with other SDCC users.
1048 Web links to other SDCC related sites can also be found here.
1049 This document can be found in the DOC directory of the source package as
1050 a text or HTML file.
1051 A pdf version of this document is available at
1052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1057 Some of the other tools (simulator and assembler) included with SDCC contain
1058 their own documentation and can be found in the source distribution.
1059 If you want the latest unreleased software, the complete source package
1060 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1064 \begin_layout Section
1065 Wishes for the future
1068 \begin_layout Standard
1069 There are (and always will be) some things that could be done.
1070 Here are some I can think of:
1075 \begin_layout Standard
1078 char KernelFunction3(char p) at 0x340;
1083 \begin_layout Standard
1087 \begin_inset LatexCommand \index{code banking (limited support)}
1097 If you can think of some more, please see the section
1098 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1102 about filing feature requests
1103 \begin_inset LatexCommand \index{Requesting features}
1108 \begin_inset LatexCommand \index{Feature request}
1117 \begin_layout Chapter
1119 \begin_inset LatexCommand \index{Installation}
1126 \begin_layout Standard
1127 For most users it is sufficient to skip to either section
1128 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1133 \begin_inset LatexCommand \ref{sub:Windows-Install}
1138 More detailed instructions follow below.
1141 \begin_layout Section
1143 \begin_inset LatexCommand \index{Options SDCC configuration}
1150 \begin_layout Standard
1151 The install paths, search paths and other options are defined when running
1153 The defaults can be overridden by:
1157 \labelwidthstring 00.00.0000
1162 \begin_layout Standard
1171 -prefix see table below
1175 \labelwidthstring 00.00.0000
1180 \begin_layout Standard
1189 -exec_prefix see table below
1193 \labelwidthstring 00.00.0000
1198 \begin_layout Standard
1207 -bindir see table below
1211 \labelwidthstring 00.00.0000
1216 \begin_layout Standard
1225 -datadir see table below
1229 \labelwidthstring 00.00.0000
1234 \begin_layout Standard
1243 -datarootdir see table below
1249 \labelwidthstring 00.00.0000
1252 docdir environment variable, see table below
1256 \labelwidthstring 00.00.0000
1259 include_dir_suffix environment variable, see table below
1263 \labelwidthstring 00.00.0000
1266 lib_dir_suffix environment variable, see table below
1270 \labelwidthstring 00.00.0000
1273 sdccconf_h_dir_separator environment variable, either / or
1278 This character will only be used in sdccconf.h; don't forget it's a C-header,
1279 therefore a double-backslash is needed there.
1285 \labelwidthstring 00.00.0000
1290 \begin_layout Standard
1299 -disable-mcs51-port Excludes the Intel mcs51 port
1303 \labelwidthstring 00.00.0000
1308 \begin_layout Standard
1317 -disable-gbz80-port Excludes the Gameboy gbz80 port
1321 \labelwidthstring 00.00.0000
1326 \begin_layout Standard
1335 -disable-z80-port Excludes the z80 port
1339 \labelwidthstring 00.00.0000
1344 \begin_layout Standard
1353 -disable-avr-port Excludes the AVR port
1357 \labelwidthstring 00.00.0000
1362 \begin_layout Standard
1371 -disable-ds390-port Excludes the DS390 port
1375 \labelwidthstring 00.00.0000
1380 \begin_layout Standard
1389 -disable-hc08-port Excludes the HC08 port
1393 \labelwidthstring 00.00.0000
1398 \begin_layout Standard
1407 -disable-pic-port Excludes the PIC port
1411 \labelwidthstring 00.00.0000
1416 \begin_layout Standard
1425 -disable-xa51-port Excludes the XA51 port
1429 \labelwidthstring 00.00.0000
1434 \begin_layout Standard
1443 -disable-ucsim Disables configuring and building of ucsim
1447 \labelwidthstring 00.00.0000
1452 \begin_layout Standard
1461 -disable-device-lib Disables automatically building device libraries
1465 \labelwidthstring 00.00.0000
1470 \begin_layout Standard
1479 -disable-packihx Disables building packihx
1485 \labelwidthstring 00.00.0000
1490 \begin_layout Standard
1499 -enable-doc Build pdf, html and txt files from the lyx sources
1503 \labelwidthstring 00.00.0000
1508 \begin_layout Standard
1517 -enable-libgc Use the Bohem memory allocator.
1518 Lower runtime footprint.
1521 \begin_layout Standard
1522 Furthermore the environment variables CC, CFLAGS, ...
1523 the tools and their arguments can be influenced.
1524 Please see `configure -
1528 \begin_layout Standard
1537 -help` and the man/info pages of `configure` for details.
1542 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1543 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1544 SDCC_LIB_NAME are defined by `configure` too.
1545 At the moment it's not possible to change the default settings (it was
1546 simply never required).
1550 These configure options are compiled into the binaries,
1551 and can only be changed by rerunning 'configure' and recompiling SDCC.
1552 The configure options are written in
1556 to distinguish them from run time environment variables (see section search
1562 \begin_inset Quotes sld
1566 \begin_inset Quotes srd
1569 are used by the SDCC team to build the official Win32 binaries.
1570 The SDCC team uses Mingw32 to build the official Windows binaries, because
1574 \begin_layout Enumerate
1578 \begin_layout Enumerate
1579 a gcc compiler and last but not least
1582 \begin_layout Enumerate
1583 the binaries can be built by cross compiling on SDCC Distributed Compile
1587 \begin_layout Standard
1588 See the examples, how to pass the Win32 settings to 'configure'.
1589 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1590 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1600 \begin_layout Standard
1602 \begin_inset Tabular
1603 <lyxtabular version="3" rows="9" columns="3">
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" width="0in">
1607 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1608 <row topline="true" bottomline="true">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1612 \begin_layout Standard
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1621 \begin_layout Standard
1627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1630 \begin_layout Standard
1637 <row topline="true">
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1641 \begin_layout Standard
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1652 \begin_layout Standard
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1661 \begin_layout Standard
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1674 \begin_layout Standard
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1685 \begin_layout Standard
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1696 \begin_layout Standard
1705 <row topline="true">
1706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 \begin_layout Standard
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_layout Standard
1730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1733 \begin_layout Standard
1746 <row topline="true">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1761 \begin_layout Standard
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1772 \begin_layout Standard
1781 <row topline="true">
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1785 \begin_layout Standard
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1796 \begin_layout Standard
1806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1809 \begin_layout Standard
1818 <row topline="true">
1819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1822 \begin_layout Standard
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 \begin_layout Standard
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1846 \begin_layout Standard
1859 <row topline="true">
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1874 \begin_layout Standard
1880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1883 \begin_layout Standard
1890 <row topline="true" bottomline="true">
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1894 \begin_layout Standard
1902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1905 \begin_layout Standard
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1914 \begin_layout Standard
1930 \begin_layout Standard
1932 'configure' also computes relative paths.
1933 This is needed for full relocatability of a binary package and to complete
1934 search paths (see section search paths below):
1939 \begin_layout Standard
1941 \begin_inset Tabular
1942 <lyxtabular version="3" rows="4" columns="3">
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" width="0in">
1946 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1947 <row topline="true" bottomline="true">
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1951 \begin_layout Standard
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1960 \begin_layout Standard
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1969 \begin_layout Standard
1976 <row topline="true" bottomline="true">
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1980 \begin_layout Standard
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1991 \begin_layout Standard
1997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2000 \begin_layout Standard
2007 <row bottomline="true">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2011 \begin_layout Standard
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2022 \begin_layout Standard
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2031 \begin_layout Standard
2038 <row bottomline="true">
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2042 \begin_layout Standard
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2053 \begin_layout Standard
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2062 \begin_layout Standard
2078 \begin_layout Standard
2083 \begin_layout LyX-Code
2090 \begin_layout Standard
2100 \begin_inset Quotes srd
2104 \begin_inset Quotes srd
2111 \begin_layout Standard
2121 \begin_inset Quotes srd
2125 \begin_inset Quotes srd
2134 \begin_layout Standard
2147 \begin_layout Standard
2159 \begin_layout Standard
2160 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2164 \begin_layout LyX-Code
2170 \begin_inset Quotes srd
2173 i586-mingw32msvc-gcc
2174 \begin_inset Quotes srd
2178 \begin_inset Quotes srd
2181 i586-mingw32msvc-g++
2182 \begin_inset Quotes srd
2190 \begin_inset Quotes srd
2193 i586-mingw32msvc-ranlib
2194 \begin_inset Quotes srd
2202 \begin_inset Quotes srd
2205 i586-mingw32msvc-strip
2206 \begin_inset Quotes srd
2217 \begin_layout Standard
2227 \begin_inset Quotes srd
2231 \begin_inset Quotes srd
2242 \begin_layout Standard
2252 \begin_inset Quotes srd
2256 \begin_inset Quotes srd
2264 \begin_inset Quotes srd
2270 \begin_inset Quotes srd
2278 \begin_inset Quotes srd
2282 \begin_inset Quotes srd
2290 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2301 sdccconf_h_dir_separator=
2302 \begin_inset Quotes srd
2314 \begin_inset Quotes srd
2325 \begin_layout Standard
2342 \begin_layout Standard
2351 -host=i586-mingw32msvc
2359 \begin_layout Standard
2368 -build=unknown-unknown-linux-gnu
2371 \begin_layout Standard
2373 \begin_inset Quotes sld
2377 \begin_inset Quotes srd
2380 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2384 \begin_layout LyX-Code
2393 \begin_layout Standard
2403 \begin_inset Quotes srd
2407 \begin_inset Quotes srd
2418 \begin_layout Standard
2428 \begin_inset Quotes srd
2432 \begin_inset Quotes srd
2440 \begin_inset Quotes srd
2446 \begin_inset Quotes srd
2454 \begin_inset Quotes srd
2458 \begin_inset Quotes srd
2466 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2477 sdccconf_h_dir_separator=
2478 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2498 \begin_inset Quotes srd
2502 \begin_inset Quotes srd
2510 \begin_inset Quotes srd
2514 \begin_inset Quotes srd
2520 \begin_layout Standard
2521 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2526 \begin_layout Standard
2535 -C' turns on caching, which gives a little bit extra speed.
2536 However if options are changed, it can be necessary to delete the config.cache
2540 \begin_layout Section
2542 \begin_inset LatexCommand \label{sub:Install-paths}
2547 \begin_inset LatexCommand \index{Install paths}
2554 \begin_layout Standard
2555 \begin_inset VSpace medskip
2561 \begin_layout Standard
2563 \begin_inset Tabular
2564 <lyxtabular version="3" rows="5" columns="4">
2566 <column alignment="left" valignment="top" leftline="true" width="0">
2567 <column alignment="left" valignment="top" leftline="true" width="0">
2568 <column alignment="left" valignment="top" leftline="true" width="0">
2569 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2570 <row topline="true" bottomline="true">
2571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2574 \begin_layout Standard
2582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2585 \begin_layout Standard
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2596 \begin_layout Standard
2604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2607 \begin_layout Standard
2616 <row topline="true">
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2620 \begin_layout Standard
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2629 \begin_layout Standard
2637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2640 \begin_layout Standard
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2649 \begin_layout Standard
2660 <row topline="true">
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_layout Standard
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2673 \begin_layout Standard
2676 $DATADIR/ $INCLUDE_DIR_SUFFIX
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2684 \begin_layout Standard
2685 /usr/local/share/sdcc/include
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2693 \begin_layout Standard
2704 <row topline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2708 \begin_layout Standard
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2717 \begin_layout Standard
2720 $DATADIR/$LIB_DIR_SUFFIX
2725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2728 \begin_layout Standard
2729 /usr/local/share/sdcc/lib
2734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2737 \begin_layout Standard
2748 <row topline="true" bottomline="true">
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_layout Standard
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2761 \begin_layout Standard
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2772 \begin_layout Standard
2773 /usr/local/share/sdcc/doc
2778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2781 \begin_layout Standard
2802 *compiler, preprocessor, assembler, and linker
2808 is auto-appended by the compiler, e.g.
2809 small, large, z80, ds390 etc
2812 \begin_layout Standard
2814 The install paths can still be changed during `make install` with e.g.:
2817 \begin_layout LyX-Code
2818 make install prefix=$(HOME)/local/sdcc
2821 \begin_layout Standard
2822 Of course this doesn't change the search paths compiled into the binaries.
2827 r the install path can be changed by defining DESTDIR
2828 \begin_inset LatexCommand \index{DESTDIR}
2835 \begin_layout LyX-Code
2836 make install DESTDIR=$(HOME)/sdcc.rpm/
2839 \begin_layout Standard
2840 Please note that DESTDIR must have a trailing slash!
2843 \begin_layout Section
2845 \begin_inset LatexCommand \label{sub:Search-Paths}
2850 \begin_inset LatexCommand \index{Search path}
2857 \begin_layout Standard
2858 Some search paths or parts of them are determined by configure variables
2863 , see section above).
2864 Further search paths are determined by environment variables during runtime.
2867 The paths searched when running the compiler are as follows (the first
2873 Binary files (preprocessor, assembler and linker)
2878 \begin_layout Standard
2880 \begin_inset Tabular
2881 <lyxtabular version="3" rows="4" columns="3">
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" width="0in">
2885 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2886 <row topline="true" bottomline="true">
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_layout Standard
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2899 \begin_layout Standard
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2908 \begin_layout Standard
2915 <row topline="true">
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2919 \begin_layout Standard
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2930 \begin_layout Standard
2936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2939 \begin_layout Standard
2948 <row topline="true">
2949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2952 \begin_layout Standard
2953 Path of argv[0] (if available)
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_layout Standard
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2970 \begin_layout Standard
2977 <row topline="true" bottomline="true">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2981 \begin_layout Standard
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2990 \begin_layout Standard
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2999 \begin_layout Standard
3015 \begin_layout Standard
3023 \begin_layout Standard
3025 \begin_inset Tabular
3026 <lyxtabular version="3" rows="6" columns="3">
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3030 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3031 <row topline="true" bottomline="true">
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3035 \begin_layout Standard
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3044 \begin_layout Standard
3050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3053 \begin_layout Standard
3060 <row topline="true">
3061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3064 \begin_layout Standard
3069 \begin_layout Standard
3083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3086 \begin_layout Standard
3091 \begin_layout Standard
3105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3108 \begin_layout Standard
3113 \begin_layout Standard
3128 <row topline="true">
3129 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3132 \begin_layout Standard
3138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3141 \begin_layout Standard
3147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3150 \begin_layout Standard
3157 <row topline="true">
3158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3161 \begin_layout Standard
3173 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3176 \begin_layout Standard
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3189 \begin_layout Standard
3198 <row topline="true">
3199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3202 \begin_layout Standard
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3221 \begin_layout Standard
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3272 \begin_layout Standard
3283 <row topline="true" bottomline="true">
3284 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3287 \begin_layout Standard
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3304 \begin_layout Standard
3305 /usr/local/share/sdcc/
3312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3315 \begin_layout Standard
3331 \begin_layout Standard
3337 \begin_layout Standard
3346 -nostdinc disables the last two search paths.
3356 \begin_layout Standard
3357 With the exception of
3358 \begin_inset Quotes sld
3365 \begin_layout Standard
3375 \begin_inset Quotes srd
3382 is auto-appended by the compiler (e.g.
3383 small, large, z80, ds390 etc.).
3389 \begin_layout Standard
3391 \begin_inset Tabular
3392 <lyxtabular version="3" rows="6" columns="3">
3394 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3395 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3396 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3397 <row topline="true" bottomline="true">
3398 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3401 \begin_layout Standard
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3410 \begin_layout Standard
3416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3419 \begin_layout Standard
3426 <row topline="true">
3427 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3430 \begin_layout Standard
3435 \begin_layout Standard
3449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3452 \begin_layout Standard
3457 \begin_layout Standard
3471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3474 \begin_layout Standard
3479 \begin_layout Standard
3494 <row topline="true">
3495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3498 \begin_layout Standard
3508 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3511 \begin_layout Standard
3521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3524 \begin_layout Standard
3537 <row topline="true">
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3548 $LIB_DIR_SUFFIX/<model>
3553 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3556 \begin_layout Standard
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3571 \begin_layout Standard
3586 <row topline="true">
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3590 \begin_layout Standard
3601 $LIB_DIR_SUFFIX/<model>
3606 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3609 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3717 <row topline="true" bottomline="true">
3718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3721 \begin_layout Standard
3726 $LIB_DIR_SUFFIX/<model>
3731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3734 \begin_layout Standard
3735 /usr/local/share/sdcc/
3744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3747 \begin_layout Standard
3763 \begin_layout Standard
3764 \begin_inset Note Note
3767 \begin_layout Standard
3768 Don't delete any of the stray spaces in the table above without checking
3769 the HTML output (last line)!
3777 \begin_layout Standard
3785 \begin_layout Standard
3794 -nostdlib disables the last two search paths.
3797 \begin_layout Section
3799 \begin_inset LatexCommand \index{Building SDCC}
3806 \begin_layout Subsection
3807 Building SDCC on Linux
3808 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3815 \begin_layout Enumerate
3818 Download the source package
3820 either from the SDCC Subversion repository or from snapshot builds
3822 , it will be named something like sdcc
3833 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3840 \begin_layout Enumerate
3843 Bring up a command line terminal, such as xterm.
3846 \begin_layout Enumerate
3849 Unpack the file using a command like:
3852 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3853 \begin_inset Quotes srd
3859 , this will create a sub-directory called sdcc with all of the sources.
3862 \begin_layout Enumerate
3863 Change directory into the main SDCC directory, for example type:
3871 \begin_layout Enumerate
3881 This configures the package for compilation on your system.
3884 \begin_layout Enumerate
3898 All of the source packages will compile, this can take a while.
3901 \begin_layout Enumerate
3915 This copies the binary executables, the include files, the libraries and
3916 the documentation to the install directories.
3917 Proceed with section
3918 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3925 \begin_layout Subsection
3926 Building SDCC on Mac OS X
3929 \begin_layout Standard
3930 Follow the instruction for Linux.
3934 On Mac OS X 10.2.x it was reported, that the
3935 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3936 Fortunately there's also gcc 2.9.x installed, which works fine.
3937 This compiler can be selected by running 'configure' with:
3940 \begin_layout LyX-Code
3941 ./configure CC=gcc2 CXX=g++2
3944 \begin_layout Subsection
3945 Cross compiling SDCC on Linux for Windows
3948 \begin_layout Standard
3949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3950 See section 'Configure Options'.
3953 \begin_layout Subsection
3954 Building SDCC using Cygwin and Mingw32
3957 \begin_layout Standard
3958 For building and installing a Cygwin executable follow the instructions
3964 \begin_inset Quotes sld
3968 \begin_inset Quotes srd
3971 Win32-binary can be built, which will not need the Cygwin-DLL.
3972 For the necessary 'configure' options see section 'configure options' or
3973 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3978 Cygwin on Windows download setup.exe from
3979 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3985 \begin_inset Quotes sld
3988 default text file type
3989 \begin_inset Quotes srd
3993 \begin_inset Quotes sld
3997 \begin_inset Quotes srd
4000 and download/install at least the following packages.
4001 Some packages are selected by default, others will be automatically selected
4002 because of dependencies with the manually selected packages.
4003 Never deselect these packages!
4006 \begin_layout Itemize
4010 \begin_layout Itemize
4014 \begin_layout Itemize
4015 gcc ; version 3.x is fine, no need to use the old 2.9x
4018 \begin_layout Itemize
4019 binutils ; selected with gcc
4022 \begin_layout Itemize
4026 \begin_layout Itemize
4027 rxvt ; a nice console, which makes life much easier under windoze (see below)
4030 \begin_layout Itemize
4031 man ; not really needed for building SDCC, but you'll miss it sooner or
4035 \begin_layout Itemize
4036 less ; not really needed for building SDCC, but you'll miss it sooner or
4040 \begin_layout Itemize
4041 svn ; only if you use Subversion access
4044 \begin_layout Standard
4045 If you want to develop something you'll need:
4048 \begin_layout Itemize
4049 python ; for the regression tests
4052 \begin_layout Itemize
4053 gdb ; the gnu debugger, together with the nice GUI
4054 \begin_inset Quotes sld
4058 \begin_inset Quotes srd
4064 \begin_layout Itemize
4065 openssh ; to access the CF or commit changes
4068 \begin_layout Itemize
4069 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4070 use autoconf-stable!
4073 \begin_layout Standard
4074 rxvt is a nice console with history.
4075 Replace in your cygwin.bat the line
4078 \begin_layout LyX-Code
4083 \begin_layout Standard
4095 \begin_layout Standard
4099 \begin_layout LyX-Code
4100 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4103 \begin_layout LyX-Code
4104 -bg black -fg white -geometry 100x65 -e bash -
4108 \begin_layout Standard
4120 \begin_layout Standard
4121 Text selected with the mouse is automatically copied to the clipboard, pasting
4122 works with shift-insert.
4126 The other good tip is to make sure you have no //c/-styl
4127 e paths anywhere, use /cygdrive/c/ instead.
4128 Using // invokes a network lookup which is very slow.
4130 \begin_inset Quotes sld
4134 \begin_inset Quotes srd
4137 is too long, you can change it with e.g.
4140 \begin_layout LyX-Code
4144 \begin_layout Standard
4145 SDCC sources use the unix line ending LF.
4146 Life is much easier, if you store the source tree on a drive which is mounted
4148 And use an editor which can handle LF-only line endings.
4149 Make sure not to commit files with windows line endings.
4150 The tabulator spacing
4151 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4155 used in the project is 8.
4156 Although a tabulator spacing of 8 is a sensible choice for programmers
4157 (it's a power of 2 and allows to display 8/16 bit signed variables without
4158 loosing columns) the plan is to move towards using only spaces in the source.
4161 \begin_layout Subsection
4162 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4165 \begin_layout Standard
4168 Download the source package
4170 either from the SDCC Subversion repository or from the
4171 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4177 , it will be named something like sdcc
4181 -yyyymmdd-rrrr.tar.bz2.
4184 SDCC is distributed with all the projects, workspaces, and files you need
4185 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4186 The workspace name is 'sdcc.dsw'.
4187 Please note that as it is now, all the executables are created in a folder
4191 Once built you need to copy the executables from sdcc
4195 bin before running SDCC.
4200 WARNING: Visual studio is very picky with line terminations; it expects
4201 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4202 When using the Subversion repository it's easiest to configure the svn
4203 client to convert automatically for you.
4204 If however you are getting a message such as "This makefile was not generated
4205 by Developer Studio etc.
4207 \begin_inset Quotes srd
4210 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4211 need to convert the Unix style line endings to DOS style line endings.
4212 To do so you can use the
4213 \begin_inset Quotes sld
4217 \begin_inset Quotes srd
4220 utility freely available on the internet.
4221 Doug Hawkins reported in the sdcc-user list that this works:
4229 SDCC> unix2dos sdcc.dsw
4235 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4239 In order to build SDCC with MSVC
4240 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4241 One good place to get them is
4242 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4250 Download the file UnxUtils
4251 \begin_inset LatexCommand \index{UnxUtils}
4256 Now you have to install the utilities and setup MSVC so it can locate the
4258 Here there are two alternatives (choose one!):
4261 \begin_layout Enumerate
4266 a) Extract UnxUtils.zip to your C:
4268 hard disk PRESERVING the original paths, otherwise bison won't work.
4269 (If you are using WinZip make certain that 'Use folder names' is selected)
4274 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4275 'Show directories for:' select 'Executable files', and in the directories
4276 window add a new path: 'C:
4286 (As a side effect, you get a bunch of Unix utilities that
4287 could be useful, such as diff and patch.)
4290 \begin_layout Enumerate
4295 This one avoids extracting a bunch of files you may not
4296 use, but requires some extra work:
4300 a) Create a directory were to put the
4301 tools needed, or use a directory already present.
4308 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4309 gawk.exe to such directory WITHOUT preserving the original paths.
4310 (If you are using WinZip make certain that 'Use folder names' is not selected)
4315 ) Rename bison.exe to '_bison.exe'.
4319 d) Create a batch file 'bison.bat' in 'C:
4323 ' and add these lines:
4343 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4347 Steps 'c' and 'd' are needed
4348 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4349 reside in some weird Unix directory, '/usr/local/share/' I think.
4350 So it is necessary to tell bison where those files are located if they
4351 are not in such directory.
4352 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4357 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4358 in 'Show directories for:' select 'Executable files', and in the directories
4359 window add a new path: 'c:
4362 Note that you can use any other path instead of 'c:
4364 util', even the path where the Visual C++ tools are, probably: 'C:
4368 Microsoft Visual Studio
4373 So you don't have to execute step 'e' :)
4376 \begin_layout Standard
4378 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4379 the executables from sdcc
4383 bin, and you can compile using SDCC.
4386 \begin_layout Subsection
4387 Building SDCC Using Borland
4390 \begin_layout Enumerate
4391 From the sdcc directory, run the command "make -f Makefile.bcc".
4392 This should regenerate all the .exe files in the bin directory except for
4396 \begin_layout Enumerate
4397 If you modify any source files and need to rebuild, be aware that the dependenci
4398 es may not be correctly calculated.
4399 The safest option is to delete all .obj files and run the build again.
4400 From a Cygwin BASH prompt, this can easily be done with the command (be
4401 sure you are in the sdcc directory):
4411 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4413 ) -print -exec rm {}
4422 or on Windows NT/2000/XP from the command prompt with the command:
4429 del /s *.obj *.lib *.rul
4432 from the sdcc directory.
4435 \begin_layout Subsection
4436 Windows Install Using a ZIP Package
4439 \begin_layout Enumerate
4440 Download the binary zip package from
4441 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4445 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4446 This should unpack to a group of sub-directories.
4447 An example directory structure after unpacking the mingw32 package is:
4452 bin for the executables, c:
4460 lib for the include and libraries.
4463 \begin_layout Enumerate
4464 Adjust your environment variable PATH to include the location of the bin
4465 directory or start sdcc using the full path.
4468 \begin_layout Subsection
4469 Windows Install Using the Setup Program
4470 \begin_inset LatexCommand \label{sub:Windows-Install}
4477 \begin_layout Standard
4478 Download the setup program
4480 sdcc-x.y.z-setup.exe
4482 for an official release from
4485 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4489 or a setup program for one of the snapshots
4491 sdcc-yyyymmdd-xxxx-setup.exe
4494 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4499 A windows typical installer will guide you through the installation process.
4502 \begin_layout Subsection
4504 \begin_inset LatexCommand \index{VPATH}
4511 \begin_layout Standard
4512 SDCC supports the VPATH feature provided by configure and make.
4513 It allows to separate the source and build trees.
4517 \begin_layout Standard
4544 \begin_layout Standard
4547 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4548 # extract source to directory sdcc
4551 \begin_layout Standard
4554 mkdir sdcc.build\InsetSpace ~
4563 # put output in sdcc.build
4566 \begin_layout Standard
4572 \begin_layout Standard
4575 ../sdcc/configure\InsetSpace ~
4583 # configure is doing all the magic!
4586 \begin_layout Standard
4592 \begin_layout Standard
4598 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4599 It automagically computes the variables srcdir, top_srcdir and top_buildir
4605 the generated files will be in ~/sdcc.build, while the source files stay
4608 This is not only usefull for building different binaries, e.g.
4609 when cross compiling.
4610 It also gives you a much better overview in the source tree when all the
4611 generated files are not scattered between the source files.
4612 And the best thing is: if you want to change a file you can leave the original
4613 file untouched in the source directory.
4614 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4615 Makefile.dep` and `make`.
4620 will do the rest for you!
4623 \begin_layout Section
4624 Building the Documentation
4627 \begin_layout Standard
4632 \begin_layout Standard
4641 -enable-doc to the configure arguments to build the documentation together
4642 with all the other stuff.
4643 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4644 dvips and makeindex) to get the job done.
4645 Another possibility is to change to the doc directory and to type
4649 \begin_inset Quotes srd
4653 \begin_inset Quotes srd
4660 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4663 \begin_inset LatexCommand \url{http://www.lyx.org}
4667 as editor is straightforward.
4668 Prebuilt documentation in html and pdf format is available from
4669 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4676 \begin_layout Section
4677 Reading the Documentation
4678 \begin_inset LatexCommand \index{Documentation}
4685 \begin_layout Standard
4686 Currently reading the document in pdf format is recommended, as for unknown
4687 reason the hyperlinks are working there whereas in the html version they
4692 \begin_layout Standard
4693 If you should know why please drop us a note
4701 You'll find the pdf version
4702 \begin_inset LatexCommand \index{PDF version of this document}
4707 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4715 \begin_inset LatexCommand \index{HTML version of this document}
4720 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4726 This documentation is in some aspects different from a commercial documentation:
4730 \begin_layout Itemize
4731 It tries to document SDCC for several processor architectures in one document
4732 (commercially these probably would be separate documents/products).
4734 \begin_inset LatexCommand \index{Status of documentation}
4738 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4740 Z80, PIC14, PIC16 and HC08.
4743 \begin_layout Itemize
4744 There are many references pointing away from this documentation.
4745 Don't let this distract you.
4747 was a reference like
4748 \begin_inset LatexCommand \url{http://www.opencores.org}
4752 together with a statement
4753 \begin_inset Quotes sld
4756 some processors which are targetted by SDCC can be implemented in a
4773 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4778 \begin_inset Quotes srd
4782 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4787 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4792 \begin_inset Quotes sld
4795 have you ever heard of an open source compiler that compiles a subset of
4797 \begin_inset Quotes srd
4800 we expect you to have a quick look there and come back.
4801 If you read this you are on the right track.
4804 \begin_layout Itemize
4805 Some sections attribute more space to problems, restrictions and warnings
4806 than to the solution.
4809 \begin_layout Itemize
4810 The installation section and the section about the debugger is intimidating.
4813 \begin_layout Itemize
4814 There are still lots of typos and there are more different writing styles
4818 \begin_layout Section
4819 Testing the SDCC Compiler
4820 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4827 \begin_layout Standard
4828 The first thing you should do after installing your SDCC compiler is to
4837 \begin_layout Standard
4847 \begin_inset LatexCommand \index{version}
4854 at the prompt, and the program should run and output its version like:
4859 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4863 \begin_layout Standard
4864 If it doesn't run, or gives a message about not finding sdcc program, then
4865 you need to check over your installation.
4866 Make sure that the sdcc bin directory is in your executable search path
4867 defined by the PATH environment setting (
4872 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4879 Install trouble-shooting for suggestions
4882 Make sure that the sdcc program is in the bin folder, if not perhaps something
4883 did not install correctly.
4891 is commonly installed as described in section
4892 \begin_inset Quotes sld
4895 Install and search paths
4896 \begin_inset Quotes srd
4905 Make sure the compiler works on a very simple example.
4906 Type in the following test.c program using your favorite
4931 \begin_layout Standard
4934 Compile this using the following command:
4943 If all goes well, the compiler will generate a test.asm and test.rel file.
4944 Congratulations, you've just compiled your first program with SDCC.
4945 We used the -c option to tell SDCC not to link the generated code, just
4946 to keep things simple for this step.
4954 The next step is to try it with the linker.
4964 If all goes well the compiler will link with the libraries and produce
4965 a test.ihx output file.
4970 (no test.ihx, and the linker generates warnings), then the problem is most
4979 usr/local/share/sdcc/lib directory
4986 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4993 Install trouble-shooting for suggestions).
5001 The final test is to ensure
5009 header files and libraries.
5010 Edit test.c and change it to the following:
5028 strcpy(str1, "testing");
5033 \begin_layout Standard
5036 Compile this by typing
5043 This should generate a test.ihx output file, and it should give no warnings
5044 such as not finding the string.h file.
5045 If it cannot find the string.h file, then the problem is that
5049 cannot find the /usr/local/share/sdcc/include directory
5056 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5063 Install trouble-shooting section for suggestions).
5072 \begin_layout Standard
5084 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5088 to find exactly where SDCC is looking for the include and lib files.
5091 \begin_layout Section
5092 Install Trouble-shooting
5093 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5098 \begin_inset LatexCommand \index{Install trouble-shooting}
5105 \begin_layout Subsection
5106 If SDCC does not build correctly
5109 \begin_layout Standard
5110 A thing to try is starting from scratch by unpacking the .tgz source package
5111 again in an empty directory.
5119 ./configure 2>&1 | tee configure.log
5133 make 2>&1 | tee make.log
5140 If anything goes wrong, you can review the log files to locate the problem.
5141 Or a relevant part of this can be attached to an email that could be helpful
5142 when requesting help from the mailing list.
5145 \begin_layout Subsection
5147 \begin_inset Quotes sld
5151 \begin_inset Quotes srd
5157 \begin_layout Standard
5159 \begin_inset Quotes sld
5163 \begin_inset Quotes srd
5166 command is a script that analyzes your system and performs some configuration
5167 to ensure the source package compiles on your system.
5168 It will take a few minutes to run, and will compile a few tests to determine
5169 what compiler features are installed.
5172 \begin_layout Subsection
5174 \begin_inset Quotes sld
5178 \begin_inset Quotes srd
5184 \begin_layout Standard
5185 This runs the GNU make tool, which automatically compiles all the source
5186 packages into the final installed binary executables.
5189 \begin_layout Subsection
5191 \begin_inset Quotes sld
5195 \begin_inset Quotes erd
5201 \begin_layout Standard
5202 This will install the compiler, other executables libraries and include
5203 files into the appropriate directories.
5205 \begin_inset LatexCommand \ref{sub:Install-paths}
5211 \begin_inset LatexCommand \ref{sub:Search-Paths}
5216 about install and search paths.
5218 On most systems you will need super-user privilege
5222 \begin_layout Section
5226 \begin_layout Standard
5227 SDCC is not just a compiler, but a collection of tools by various developers.
5228 These include linkers, assemblers, simulators and other components.
5229 Here is a summary of some of the components.
5230 Note that the included simulator and assembler have separate documentation
5231 which you can find in the source package in their respective directories.
5232 As SDCC grows to include support for other processors, other packages from
5233 various developers are included and may have their own sets of documentation.
5238 might want to look at the files which are installed in <installdir>.
5239 At the time of this writing, we find the following programs for gcc-builds:
5244 In <installdir>/bin:
5247 \begin_layout Itemize
5248 sdcc - The compiler.
5251 \begin_layout Itemize
5252 sdcpp - The C preprocessor.
5255 \begin_layout Itemize
5256 asx8051 - The assembler for 8051 type processors.
5259 \begin_layout Itemize
5264 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5267 \begin_layout Itemize
5268 aslink -The linker for 8051 type processors.
5271 \begin_layout Itemize
5276 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5279 \begin_layout Itemize
5280 s51 - The ucSim 8051 simulator.
5283 \begin_layout Itemize
5284 sdcdb - The source debugger.
5287 \begin_layout Itemize
5288 packihx - A tool to pack (compress) Intel hex files.
5291 \begin_layout Standard
5292 In <installdir>/share/sdcc/include
5295 \begin_layout Itemize
5299 \begin_layout Standard
5300 In <installdir>/share/sdcc/lib
5303 \begin_layout Itemize
5304 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5308 \begin_layout Standard
5309 In <installdir>/share/sdcc/doc
5312 \begin_layout Itemize
5316 \begin_layout Standard
5317 As development for other processors proceeds, this list will expand to include
5318 executables to support processors like AVR, PIC, etc.
5321 \begin_layout Subsection
5325 \begin_layout Standard
5326 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5327 the assembler and linkage editor.
5330 \begin_layout Subsection
5331 sdcpp - The C-Preprocessor
5334 \begin_layout Standard
5336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5340 is a modified version of the GNU cpp
5341 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5346 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5351 The C preprocessor is used to pull in #include sources, process #ifdef
5352 statements, #defines and so on.
5355 \begin_layout Subsection
5364 - The Assemblers and Linkage Editors
5367 \begin_layout Standard
5368 This is retargettable assembler & linkage editor, it was developed by Alan
5370 John Hartman created the version for 8051, and I (Sandeep) have made some
5371 enhancements and bug fixes for it to work properly with SDCC.
5374 \begin_layout Subsection
5378 \begin_layout Standard
5380 \begin_inset LatexCommand \index{s51}
5384 is a free open source simulator developed by Daniel Drotos.
5385 The simulator is built as part of the build process.
5386 For more information visit Daniel's web site at:
5387 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5392 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5396 \begin_layout Subsection
5397 sdcdb - Source Level Debugger
5400 \begin_layout Standard
5402 \begin_inset LatexCommand \index{SDCDB (debugger)}
5406 is the companion source level debugger.
5407 More about SDCDB in section
5408 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5413 The current version of the debugger uses Daniel's Simulator S51
5414 \begin_inset LatexCommand \index{s51}
5418 , but can be easily changed to use other simulators.
5421 \begin_layout Chapter
5425 \begin_layout Section
5429 \begin_layout Subsection
5430 Single Source File Projects
5433 \begin_layout Standard
5434 For single source file 8051 projects the process is very simple.
5435 Compile your programs with the following command
5438 "sdcc sourcefile.c".
5442 This will compile, assemble and link your source file.
5443 Output files are as follows:
5446 \begin_layout Itemize
5448 \begin_inset LatexCommand \index{<file>.asm}
5453 \begin_inset LatexCommand \index{Assembler source}
5457 file created by the compiler
5460 \begin_layout Itemize
5462 \begin_inset LatexCommand \index{<file>.lst}
5467 \begin_inset LatexCommand \index{Assembler listing}
5471 file created by the Assembler
5474 \begin_layout Itemize
5476 \begin_inset LatexCommand \index{<file>.rst}
5481 \begin_inset LatexCommand \index{Assembler listing}
5485 file updated with linkedit information, created by linkage editor
5488 \begin_layout Itemize
5490 \begin_inset LatexCommand \index{<file>.sym}
5495 \begin_inset LatexCommand \index{Symbol listing}
5499 for the sourcefile, created by the assembler
5502 \begin_layout Itemize
5504 \begin_inset LatexCommand \index{<file>.rel}
5509 \begin_inset LatexCommand \index{<file>.o}
5514 \begin_inset LatexCommand \index{Object file}
5518 created by the assembler, input to Linkage editor
5521 \begin_layout Itemize
5523 \begin_inset LatexCommand \index{<file>.map}
5528 \begin_inset LatexCommand \index{Memory map}
5532 for the load module, created by the Linker
5535 \begin_layout Itemize
5537 \begin_inset LatexCommand \index{<file>.mem}
5541 - A file with a summary of the memory usage
5544 \begin_layout Itemize
5546 \begin_inset LatexCommand \index{<file>.ihx}
5550 - The load module in Intel hex format
5551 \begin_inset LatexCommand \index{Intel hex format}
5555 (you can select the Motorola S19 format
5556 \begin_inset LatexCommand \index{Motorola S19 format}
5564 \begin_layout Standard
5574 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5579 If you need another format you might want to use
5586 \begin_inset LatexCommand \index{objdump (tool)}
5597 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5602 \begin_inset Note Note
5605 \begin_layout Standard
5612 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5617 Both formats are documented in the documentation of srecord
5618 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5625 \begin_layout Itemize
5627 \begin_inset LatexCommand \index{<file>.adb}
5631 - An intermediate file containing debug information needed to create the
5636 \begin_layout Standard
5646 \begin_inset LatexCommand \index{-\/-debug}
5653 \begin_layout Itemize
5655 \begin_inset LatexCommand \index{<file>.cdb}
5659 - An optional file (with -
5663 \begin_layout Standard
5672 -debug) containing debug information.
5673 The format is documented in cdbfileformat.pdf
5676 \begin_layout Itemize
5679 \begin_inset LatexCommand \index{<file> (no extension)}
5683 An optional AOMF or AOMF51
5684 \begin_inset LatexCommand \index{AOMF, AOMF51}
5689 \begin_inset LatexCommand \label{OMF file}
5693 file containing debug information (generated with option -
5697 \begin_layout Standard
5723 ormat is a subformat of the OMF51 format and is commonly used by third party
5725 \begin_inset LatexCommand \index{Debugger}
5729 , simulators, emulators).
5732 \begin_layout Itemize
5734 \begin_inset LatexCommand \index{<file>.dump*}
5738 - Dump file to debug the compiler it self (generated with option -
5742 \begin_layout Standard
5751 -dumpall) (see section
5752 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5758 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5764 \begin_inset Quotes sld
5767 Anatomy of the compiler
5768 \begin_inset Quotes srd
5774 \begin_layout Subsection
5775 Postprocessing the Intel Hex
5776 \begin_inset LatexCommand \index{Intel hex format}
5781 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5788 \begin_layout Standard
5789 In most cases this won't be needed but the Intel Hex file
5790 \begin_inset LatexCommand \index{<file>.ihx}
5794 which is generated by SDCC might include lines of varying length and the
5795 addresses within the file are not guaranteed to be strictly ascending.
5796 If your toolchain or a bootloader does not like this you can use the tool
5802 \begin_inset LatexCommand \index{packihx (tool)}
5806 which is part of the SDCC distribution:
5813 packihx sourcefile.ihx >sourcefile.hex
5820 The separately available
5825 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5829 package additionally allows to set undefined locations to a predefined
5830 value, to insert checksums
5831 \begin_inset LatexCommand \index{checksum}
5835 of various flavours (crc, add, xor) and to perform other manipulations
5836 (convert, split, crop, offset, ...).
5844 srec_cat\InsetSpace ~
5846 sourcefile.ihx -intel\InsetSpace ~
5848 -o sourcefile.hex -intel
5855 An example for a more complex command line
5859 \begin_layout Standard
5860 the command backfills
5861 \begin_inset LatexCommand \index{backfill unused memory}
5865 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5867 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5868 will be interpreted as an
5876 (where an emergency routine could sit).
5889 srec_cat\InsetSpace ~
5890 sourcefile.ihx -intel\InsetSpace ~
5892 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5893 -little-endian-checksum-nega
5894 tive 0xfffe 0x02 0x02\InsetSpace ~
5896 -o sourcefile.hex -intel
5905 The srecord package is available at
5906 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5913 \begin_layout Subsection
5914 Projects with Multiple Source Files
5917 \begin_layout Standard
5918 SDCC can compile only ONE file at a time.
5919 Let us for example assume that you have a project containing the following
5924 foo1.c (contains some functions)
5926 foo2.c (contains some more functions)
5929 n.c (contains more functions and the function main)
5937 The first two files will need to be compiled separately with the commands:
5969 Then compile the source file containing the
5974 \begin_inset LatexCommand \index{Linker}
5978 the files together with the following command:
5986 foomain.c\InsetSpace ~
5987 foo1.rel\InsetSpace ~
5992 \begin_inset LatexCommand \index{<file>.rel}
6004 can be separately compiled as well:
6015 sdcc foomain.rel foo1.rel foo2.rel
6022 The file containing the
6037 file specified in the command line, since the linkage editor processes
6038 file in the order they are presented to it.
6039 The linker is invoked from SDCC using a script file with extension .lnk
6040 \begin_inset LatexCommand \index{<file>.lnk}
6045 You can view this file to troubleshoot linking problems such as those arising
6046 from missing libraries.
6049 \begin_layout Subsection
6050 Projects with Additional Libraries
6051 \begin_inset LatexCommand \index{Libraries}
6058 \begin_layout Standard
6059 Some reusable routines may be compiled into a library, see the documentation
6060 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6064 \begin_inset LatexCommand \index{<file>.lib}
6071 Libraries created in this manner can be included in the command line.
6072 Make sure you include the -L <library-path> option to tell the linker where
6073 to look for these files if they are not in the current directory.
6074 Here is an example, assuming you have the source file
6086 (if that is not the same as your current project):
6093 sdcc foomain.c foolib.lib -L mylib
6104 must be an absolute path name.
6108 The most efficient way to use libraries is
6109 to keep separate modules in separate source files.
6110 The lib file now should name all the modules.rel
6111 \begin_inset LatexCommand \index{<file>.rel}
6116 For an example see the standard library file
6120 in the directory <installdir>/share/lib/small.
6123 \begin_layout Subsection
6124 Using sdcclib to Create and Manage Libraries
6125 \begin_inset LatexCommand \index{sdcclib}
6132 \begin_layout Standard
6133 Alternatively, instead of having a .rel file for each entry on the library
6134 file as described in the preceding section, sdcclib can be used to embed
6135 all the modules belonging to such library in the library file itself.
6136 This results in a larger library file, but it greatly reduces the number
6137 of disk files accessed by the linker.
6138 Additionally, the packed library file contains an index of all include
6139 modules and symbols that significantly speeds up the linking process.
6140 To display a list of options supported by sdcclib type:
6145 \begin_layout Standard
6150 \begin_inset LatexCommand \index{sdcclib}
6161 To create a new library file, start by compiling all the required modules.
6167 \begin_layout Standard
6174 \begin_layout Standard
6181 \begin_layout Standard
6188 \begin_layout Standard
6195 \begin_layout Standard
6204 \begin_layout Standard
6205 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6207 The next step is to add the .rel files to the library file:
6212 \begin_layout Standard
6216 sdcclib libint.lib _divsint.rel
6219 \begin_inset LatexCommand \index{sdcclib}
6226 \begin_layout Standard
6230 sdcclib libint.lib _divuint.rel
6233 \begin_layout Standard
6237 sdcclib libint.lib _modsint.rel
6240 \begin_layout Standard
6244 sdcclib libint.lib _moduint.rel
6247 \begin_layout Standard
6251 sdcclib libint.lib _mulint.rel
6258 \begin_layout Standard
6259 If the file already exists in the library, it will be replaced.
6260 To see what modules and symbols are included in the library, options -s
6261 and -m are available.
6269 sdcclib -s libint.lib
6272 \begin_inset LatexCommand \index{sdcclib}
6284 \begin_layout Standard
6290 \begin_layout Standard
6296 \begin_layout Standard
6304 \begin_layout Standard
6310 \begin_layout Standard
6316 \begin_layout Standard
6322 \begin_layout Standard
6328 \begin_layout Standard
6336 \begin_layout Standard
6342 \begin_layout Standard
6348 \begin_layout Standard
6356 \begin_layout Standard
6362 \begin_layout Standard
6368 \begin_layout Standard
6374 \begin_layout Standard
6382 \begin_layout Standard
6388 \begin_layout Standard
6399 \begin_layout Standard
6400 If the source files are compiled using -
6404 \begin_layout Standard
6414 \begin_inset LatexCommand \index{-\/-debug}
6418 , the corresponding debug information file .adb will be include in the library
6420 The library files created with sdcclib are plain text files, so they can
6421 be viewed with a text editor.
6422 It is not recomended to modify a library file created with sdcclib using
6423 a text editor, as there are file indexes numbers located accross the file
6424 used by the linker to quickly locate the required module to link.
6425 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6426 it can be safely deleted, since all the information required for linking
6427 is embedded in the library file itself.
6428 Library files created using sdcclib are used as described in the preceding
6430 \begin_inset VSpace bigskip
6436 \begin_layout Section
6437 Command Line Options
6438 \begin_inset LatexCommand \index{Command Line Options}
6443 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6450 \begin_layout Subsection
6451 Processor Selection Options
6452 \begin_inset LatexCommand \index{Options processor selection}
6457 \begin_inset LatexCommand \index{Processor selection options}
6465 \labelwidthstring 00.00.0000
6469 \begin_inset LatexCommand \index{-mmcs51}
6475 Generate code for the Intel MCS51
6476 \begin_inset LatexCommand \index{MCS51}
6480 family of processors.
6481 This is the default processor target.
6485 \labelwidthstring 00.00.0000
6489 \begin_inset LatexCommand \index{-mds390}
6495 Generate code for the Dallas DS80C390
6496 \begin_inset LatexCommand \index{DS80C390}
6504 \labelwidthstring 00.00.0000
6508 \begin_inset LatexCommand \index{-mds400}
6514 Generate code for the Dallas DS80C400
6515 \begin_inset LatexCommand \index{DS80C400}
6523 \labelwidthstring 00.00.0000
6527 \begin_inset LatexCommand \index{-mhc08}
6533 Generate code for the Freescale/Motorola HC08
6534 \begin_inset LatexCommand \index{HC08}
6538 family of processors.
6542 \labelwidthstring 00.00.0000
6546 \begin_inset LatexCommand \index{-mz80}
6552 Generate code for the Zilog Z80
6553 \begin_inset LatexCommand \index{Z80}
6557 family of processors.
6561 \labelwidthstring 00.00.0000
6565 \begin_inset LatexCommand \index{-mgbz80}
6571 Generate code for the GameBoy Z80
6572 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6576 processor (Not actively maintained).
6580 \labelwidthstring 00.00.0000
6584 \begin_inset LatexCommand \index{-mavr}
6590 Generate code for the Atmel AVR
6591 \begin_inset LatexCommand \index{AVR}
6595 processor (Not maintained, not complete).
6596 AVR users should probably have a look at winavr
6597 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6602 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6606 , which is based on AVR-port of the gcc compiler.
6609 \begin_layout Standard
6610 \begin_inset Note Note
6613 \begin_layout Standard
6614 I think it is fair to direct users there for now.
6615 Open source is also about avoiding unnecessary work .
6616 But I didn't find the 'official' link.
6625 \labelwidthstring 00.00.0000
6629 \begin_inset LatexCommand \index{-mpic14}
6635 Generate code for the Microchip PIC 14
6636 \begin_inset LatexCommand \index{PIC14}
6640 -bit processors (p16f84 and variants.
6641 In development, not complete).
6644 \begin_layout Standard
6645 \begin_inset Note Note
6648 \begin_layout Standard
6649 p16f627 p16f628 p16f84 p16f873 p16f877?
6658 \labelwidthstring 00.00.0000
6662 \begin_inset LatexCommand \index{-mpic16}
6668 Generate code for the Microchip PIC 16
6669 \begin_inset LatexCommand \index{PIC16}
6673 -bit processors (p18f452 and variants.
6674 In development, not complete).
6678 \labelwidthstring 00.00.0000
6683 Generate code for the Toshiba TLCS-900H
6684 \begin_inset LatexCommand \index{TLCS-900H}
6688 processor (Not maintained, not complete).
6692 \labelwidthstring 00.00.0000
6696 \begin_inset LatexCommand \index{-mxa51}
6702 Generate code for the Phillips XA51
6703 \begin_inset LatexCommand \index{XA51}
6707 processor (Not maintained, not complete).
6710 \begin_layout Standard
6711 \begin_inset VSpace bigskip
6717 \begin_layout Subsection
6718 Preprocessor Options
6719 \begin_inset LatexCommand \index{Options preprocessor}
6724 \begin_inset LatexCommand \index{Preprocessor options}
6729 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6737 \labelwidthstring 00.00.0000
6741 \begin_inset LatexCommand \index{-I<path>}
6747 The additional location where the preprocessor will look for <..h> or
6748 \begin_inset Quotes eld
6752 \begin_inset Quotes erd
6759 \labelwidthstring 00.00.0000
6763 \begin_inset LatexCommand \index{-D<macro[=value]>}
6769 Command line definition of macros.
6770 Passed to the preprocessor.
6774 \labelwidthstring 00.00.0000
6778 \begin_inset LatexCommand \index{-M}
6784 Tell the preprocessor to output a rule suitable for make describing the
6785 dependencies of each object file.
6786 For each source file, the preprocessor outputs one make-rule whose target
6787 is the object file name for that source file and whose dependencies are
6788 all the files `#include'd in it.
6789 This rule may be a single line or may be continued with `
6791 '-newline if it is long.
6792 The list of rules is printed on standard output instead of the preprocessed
6795 \begin_inset LatexCommand \index{-E}
6803 \labelwidthstring 00.00.0000
6807 \begin_inset LatexCommand \index{-C}
6813 Tell the preprocessor not to discard comments.
6814 Used with the `-E' option.
6818 \labelwidthstring 00.00.0000
6822 \begin_inset LatexCommand \index{-MM}
6833 Like `-M' but the output mentions only the user header files included with
6835 \begin_inset Quotes eld
6839 System header files included with `#include <file>' are omitted.
6843 \labelwidthstring 00.00.0000
6847 \begin_inset LatexCommand \index{-Aquestion(answer)}
6853 Assert the answer answer for question, in case it is tested with a preprocessor
6854 conditional such as `#if #question(answer)'.
6855 `-A-' disables the standard assertions that normally describe the target
6860 \labelwidthstring 00.00.0000
6864 \begin_inset LatexCommand \index{-Umacro}
6870 Undefine macro macro.
6871 `-U' options are evaluated after all `-D' options, but before any `-include'
6872 and `-imacros' options.
6876 \labelwidthstring 00.00.0000
6880 \begin_inset LatexCommand \index{-dM}
6886 Tell the preprocessor to output only a list of the macro definitions that
6887 are in effect at the end of preprocessing.
6888 Used with the `-E' option.
6892 \labelwidthstring 00.00.0000
6896 \begin_inset LatexCommand \index{-dD}
6902 Tell the preprocessor to pass all macro definitions into the output, in
6903 their proper sequence in the rest of the output.
6907 \labelwidthstring 00.00.0000
6911 \begin_inset LatexCommand \index{-dN}
6922 Like `-dD' except that the macro arguments and contents are omitted.
6923 Only `#define name' is included in the output.
6927 \labelwidthstring 00.00.0000
6930 -pedantic-parse-number
6931 \begin_inset LatexCommand \index{pedantic}
6936 \begin_inset LatexCommand \index{-pedantic-parse-number}
6944 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6952 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6953 and the macro LO_B(3) gets expanded.
6954 See also #pragma pedantic_parse_number
6955 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6960 \begin_inset LatexCommand \ref{sec:Pragmas}
6966 Note: this functionality is not in conformance with C99 standard!
6970 \labelwidthstring 00.00.0000
6974 preprocessorOption[,preprocessorOption]
6977 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6982 Pass the preprocessorOption to the preprocessor
6987 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6992 SDCC uses an adapted version of the preprocessor
6996 of the GNU Compiler Collection
6997 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7006 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7010 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7015 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7022 \begin_layout Standard
7023 \begin_inset VSpace bigskip
7029 \begin_layout Subsection
7031 \begin_inset LatexCommand \index{Options linker}
7036 \begin_inset LatexCommand \index{Linker options}
7044 \labelwidthstring 00.00.0000
7054 \begin_layout Standard
7066 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7071 \begin_inset LatexCommand \index{-L -\/-lib-path}
7078 <absolute path to additional libraries> This option is passed to the linkage
7079 editor's additional libraries
7080 \begin_inset LatexCommand \index{Libraries}
7085 The path name must be absolute.
7086 Additional library files may be specified in the command line.
7087 See section Compiling programs for more details.
7091 \labelwidthstring 00.00.0000
7098 \begin_layout Standard
7110 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7115 <Value> The start location of the external ram
7116 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7120 , default value is 0.
7121 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7125 \begin_layout Standard
7134 -xram-loc 0x8000 or -
7138 \begin_layout Standard
7151 \labelwidthstring 00.00.0000
7158 \begin_layout Standard
7170 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7175 <Value> The start location of the code
7176 \begin_inset LatexCommand \index{code}
7180 segment, default value 0.
7181 Note when this option is used the interrupt vector table
7182 \begin_inset LatexCommand \index{interrupt vector table}
7186 is also relocated to the given address.
7187 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7191 \begin_layout Standard
7200 -code-loc 0x8000 or -
7204 \begin_layout Standard
7217 \labelwidthstring 00.00.0000
7224 \begin_layout Standard
7236 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7241 <Value> By default the stack
7242 \begin_inset LatexCommand \index{stack}
7246 is placed after the data segment.
7247 Using this option the stack can be placed anywhere in the internal memory
7249 The value entered can be in Hexadecimal or Decimal format, e.g.
7254 \begin_layout Standard
7263 -stack-loc 0x20 or -
7267 \begin_layout Standard
7277 Since the sp register is incremented before a push or call, the initial
7278 sp will be set to one byte prior the provided value.
7279 The provided value should not overlap any other memory areas such as used
7280 register banks or the data segment and with enough space for the current
7288 \begin_layout Standard
7301 \begin_inset LatexCommand \index{-\/-pack-iram}
7305 option (which is now a default setting) will override this setting, so
7306 you should also specify the
7312 \begin_layout Standard
7325 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7329 option if you need to manually place the stack.
7333 \labelwidthstring 00.00.0000
7340 \begin_layout Standard
7352 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7357 <Value> By default the external stack
7358 \begin_inset LatexCommand \index{xstack}
7362 is placed after the pdata
7363 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7368 Using this option the xstack can be placed anywhere in the external memory
7370 The value entered can be in Hexadecimal or Decimal format, e.g.
7375 \begin_layout Standard
7384 -xstack-loc 0x8000 or -
7388 \begin_layout Standard
7398 The provided value should not overlap any other memory areas such as the
7399 pdata or xdata segment and with enough space for the current application.
7403 \labelwidthstring 00.00.0000
7410 \begin_layout Standard
7422 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7427 <Value> The start location of the internal ram data
7428 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7433 The value entered can be in Hexadecimal or Decimal format, eg.
7438 \begin_layout Standard
7451 \begin_layout Standard
7461 (By default, the start location of the internal ram data segment is set
7462 as low as possible in memory, taking into account the used register banks
7463 and the bit segment at address 0x20.
7464 For example if register banks 0 and 1 are used without bit variables, the
7465 data segment will be set, if -
7469 \begin_layout Standard
7478 -data-loc is not used, to location 0x10.)
7482 \labelwidthstring 00.00.0000
7489 \begin_layout Standard
7501 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7506 <Value> The start location of the indirectly addressable internal ram
7507 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7511 of the 8051, default value is 0x80.
7512 The value entered can be in Hexadecimal or Decimal format, eg.
7517 \begin_layout Standard
7526 -idata-loc 0x88 or -
7530 \begin_layout Standard
7543 \labelwidthstring 00.00.0000
7550 \begin_layout Standard
7562 <Value> The start location of the bit
7563 \begin_inset LatexCommand \index{bit}
7567 addressable internal ram of the 8051.
7573 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7578 \labelwidthstring 00.00.0000
7585 \begin_layout Standard
7595 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7604 The linker output (final object code) is in Intel Hex format.
7605 \begin_inset LatexCommand \index{Intel hex format}
7609 This is the default option.
7610 The format itself is documented in the documentation of srecord
7611 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7619 \labelwidthstring 00.00.0000
7626 \begin_layout Standard
7636 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7645 The linker output (final object code) is in Motorola S19 format
7646 \begin_inset LatexCommand \index{Motorola S19 format}
7651 The format itself is documented in the documentation of srecord.
7655 \labelwidthstring 00.00.0000
7662 \begin_layout Standard
7672 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7677 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7686 The linker output (final object code) is in ELF format
7687 \begin_inset LatexCommand \index{ELF format}
7692 (Currently only supported for the HC08
7693 \begin_inset LatexCommand \index{HC08}
7701 \labelwidthstring 00.00.0000
7705 linkOption[,linkOption]
7708 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7713 Pass the linkOption to the linker.
7714 If a bootloader is used an option like
7715 \begin_inset Quotes sld
7720 \begin_inset Quotes srd
7723 would be typical to set the start of the code segment.
7724 See also #pragma constseg and #pragma codeseg in section
7725 \begin_inset LatexCommand \ref{sec:Pragmas}
7730 File sdcc/as/doc/asxhtm.html has more on linker options.
7733 \begin_layout Standard
7734 \begin_inset VSpace bigskip
7740 \begin_layout Subsection
7742 \begin_inset LatexCommand \index{Options MCS51}
7747 \begin_inset LatexCommand \index{MCS51 options}
7755 \labelwidthstring 00.00.0000
7762 \begin_layout Standard
7772 \begin_inset LatexCommand \index{-\/-model-small}
7783 Generate code for Small Model programs, see section Memory Models for more
7785 This is the default model.
7789 \labelwidthstring 00.00.0000
7796 \begin_layout Standard
7806 \begin_inset LatexCommand \index{-\/-model-medium}
7812 Generate code for Medium model programs, see section Memory Models for
7814 If this option is used all source files in the project have to be compiled
7816 It must also be used when invoking the linker.
7820 \labelwidthstring 00.00.0000
7827 \begin_layout Standard
7837 \begin_inset LatexCommand \index{-\/-model-large}
7843 Generate code for Large model programs, see section Memory Models for more
7845 If this option is used all source files in the project have to be compiled
7847 It must also be used when invoking the linker.
7851 \labelwidthstring 00.00.0000
7858 \begin_layout Standard
7868 \begin_inset LatexCommand \index{-\/-xstack}
7874 Uses a pseudo stack in the pdata
7875 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7879 area (usually the first 256 bytes in the external ram) for allocating variables
7880 and passing parameters.
7882 \begin_inset LatexCommand \ref{sub:External-Stack}
7887 External Stack for more details.
7891 \labelwidthstring 00.00.0000
7898 \begin_layout Standard
7911 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7915 Causes the linker to check if the internal ram usage is within limits of
7920 \labelwidthstring 00.00.0000
7927 \begin_layout Standard
7940 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7944 Causes the linker to check if the external ram usage is within limits of
7949 \labelwidthstring 00.00.0000
7956 \begin_layout Standard
7969 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7973 Causes the linker to check if the code memory usage is within limits of
7978 \labelwidthstring 00.00.0000
7985 \begin_layout Standard
7998 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8002 Causes the linker to check if there is at minimum <Value> bytes for stack.
8006 \labelwidthstring 00.00.0000
8013 \begin_layout Standard
8026 \begin_inset LatexCommand \index{-\/-pack-iram}
8030 Causes the linker to use unused register banks for data variables and pack
8031 data, idata and stack together.
8032 This is the default now.
8036 \labelwidthstring 00.00.0000
8043 \begin_layout Standard
8056 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8060 Causes the linker to use old style for allocating memory areas.
8063 \begin_layout Standard
8064 \begin_inset VSpace bigskip
8070 \begin_layout Subsection
8071 DS390 / DS400 Options
8072 \begin_inset LatexCommand \index{Options DS390}
8077 \begin_inset LatexCommand \index{DS390}
8085 \labelwidthstring 00.00.0000
8092 \begin_layout Standard
8104 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8114 Generate 24-bit flat mode code.
8115 This is the one and only that the ds390 code generator supports right now
8116 and is default when using
8121 See section Memory Models for more details.
8125 \labelwidthstring 00.00.0000
8132 \begin_layout Standard
8142 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8148 disable interrupts during ESP:SP updates.
8152 \labelwidthstring 00.00.0000
8159 \begin_layout Standard
8171 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8175 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8176 This is the one and only that the ds390 code generator supports right now
8177 and is default when using
8182 In this mode, the stack is located in the lower 1K of the internal RAM,
8183 which is mapped to 0x400000.
8184 Note that the support is incomplete, since it still uses a single byte
8185 as the stack pointer.
8186 This means that only the lower 256 bytes of the potential 1K stack space
8187 will actually be used.
8188 However, this does allow you to reclaim the precious 256 bytes of low RAM
8189 for use for the DATA and IDATA segments.
8190 The compiler will not generate any code to put the processor into 10 bit
8192 It is important to ensure that the processor is in this mode before calling
8193 any re-entrant functions compiled with this option.
8194 In principle, this should work with the
8200 \begin_layout Standard
8210 \begin_inset LatexCommand \index{-\/-stack-auto}
8216 option, but that has not been tested.
8217 It is incompatible with the
8223 \begin_layout Standard
8233 \begin_inset LatexCommand \index{-\/-xstack}
8240 It also only makes sense if the processor is in 24 bit contiguous addressing
8247 \begin_layout Standard
8256 -model-flat24 option
8261 \begin_inset Note Note
8265 \labelwidthstring 00.00.0000
8268 --stack-8-bit - switches off the 10-bit mode
8277 \labelwidthstring 00.00.0000
8284 \begin_layout Standard
8294 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8300 insert call to function __stack_probe at each function prologue.
8304 \labelwidthstring 00.00.0000
8311 \begin_layout Standard
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8327 <nnnn> LibraryID used in -mTININative.
8332 \labelwidthstring 00.00.0000
8339 \begin_layout Standard
8349 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8355 generate code for DS390 Arithmetic Accelerator.
8359 \begin_layout Standard
8360 \begin_inset VSpace bigskip
8366 \begin_layout Subsection
8368 \begin_inset LatexCommand \index{Options Z80}
8373 \begin_inset LatexCommand \index{Z80}
8381 \labelwidthstring 00.00.0000
8388 \begin_layout Standard
8400 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8410 Force a called function to always save BC.
8414 \labelwidthstring 00.00.0000
8421 \begin_layout Standard
8433 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8437 When linking, skip the standard crt0.o object file.
8438 You must provide your own crt0.o for your system when linking.
8442 \begin_layout Standard
8443 \begin_inset VSpace bigskip
8449 \begin_layout Subsection
8450 Optimization Options
8451 \begin_inset LatexCommand \index{Options optimization}
8456 \begin_inset LatexCommand \index{Optimization options}
8464 \labelwidthstring 00.00.0000
8471 \begin_layout Standard
8481 \begin_inset LatexCommand \index{-\/-nogcse}
8487 Will not do global subexpression elimination, this option may be used when
8488 the compiler creates undesirably large stack/data spaces to store compiler
8498 \begin_inset LatexCommand \index{sloc (spill location)}
8503 A warning message will be generated when this happens and the compiler
8504 will indicate the number of extra bytes it allocated.
8505 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8507 \begin_inset LatexCommand \index{\#pragma nogcse}
8511 can be used to turn off global subexpression elimination
8512 \begin_inset LatexCommand \index{Subexpression elimination}
8516 for a given function only.
8520 \labelwidthstring 00.00.0000
8527 \begin_layout Standard
8537 \begin_inset LatexCommand \index{-\/-noinvariant}
8543 Will not do loop invariant optimizations, this may be turned off for reasons
8544 explained for the previous option.
8545 For more details of loop optimizations performed see Loop Invariants in
8547 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8552 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8554 \begin_inset LatexCommand \index{\#pragma noinvariant}
8558 can be used to turn off invariant optimizations for a given function only.
8562 \labelwidthstring 00.00.0000
8569 \begin_layout Standard
8579 \begin_inset LatexCommand \index{-\/-noinduction}
8585 Will not do loop induction optimizations, see section strength reduction
8587 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8589 \begin_inset LatexCommand \index{\#pragma noinduction}
8593 can be used to turn off induction optimizations for a given function only.
8597 \labelwidthstring 00.00.0000
8604 \begin_layout Standard
8614 \begin_inset LatexCommand \index{-\/-nojtbound}
8625 Will not generate boundary condition check when switch statements
8626 \begin_inset LatexCommand \index{switch statement}
8630 are implemented using jump-tables.
8632 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8637 Switch Statements for more details.
8638 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8640 \begin_inset LatexCommand \index{\#pragma nojtbound}
8644 can be used to turn off boundary checking for jump tables for a given function
8649 \labelwidthstring 00.00.0000
8656 \begin_layout Standard
8666 \begin_inset LatexCommand \index{-\/-noloopreverse}
8675 Will not do loop reversal
8676 \begin_inset LatexCommand \index{Loop reversing}
8684 \labelwidthstring 00.00.0000
8689 \begin_layout Standard
8703 \begin_inset LatexCommand \index{-\/-nolabelopt }
8707 Will not optimize labels (makes the dumpfiles more readable).
8711 \labelwidthstring 00.00.0000
8718 \begin_layout Standard
8728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8734 Will not memcpy initialized data from code space into xdata space.
8735 This saves a few bytes in code space if you don't have initialized data
8736 \begin_inset LatexCommand \index{Variable initialization}
8744 \labelwidthstring 00.00.0000
8751 \begin_layout Standard
8761 \begin_inset LatexCommand \index{-\/-nooverlay}
8767 The compiler will not overlay parameters and local variables of any function,
8768 see section Parameters and local variables for more details.
8772 \labelwidthstring 00.00.0000
8779 \begin_layout Standard
8789 \begin_inset LatexCommand \index{-\/-no-peep}
8795 Disable peep-hole optimization with built-in rules.
8799 \labelwidthstring 00.00.0000
8806 \begin_layout Standard
8818 \begin_inset LatexCommand \index{-\/-peep-file}
8823 <filename> This option can be used to use additional rules to be used by
8824 the peep hole optimizer.
8826 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8831 Peep Hole optimizations for details on how to write these rules.
8835 \labelwidthstring 00.00.0000
8842 \begin_layout Standard
8852 \begin_inset LatexCommand \index{-\/-peep-asm}
8858 Pass the inline assembler code through the peep hole optimizer.
8859 This can cause unexpected changes to inline assembler code, please go through
8860 the peephole optimizer
8861 \begin_inset LatexCommand \index{Peephole optimizer}
8865 rules defined in the source file tree '<target>/peeph.def' before using
8870 \labelwidthstring 00.00.0000
8877 \begin_layout Standard
8887 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8893 The compiler will optimize code generation towards fast code, possibly
8894 at the expense of code size.
8898 \labelwidthstring 00.00.0000
8905 \begin_layout Standard
8915 \begin_inset LatexCommand \index{-\/-opt-code-size}
8921 The compiler will optimize code generation towards compact code, possibly
8922 at the expense of code speed.
8925 \begin_layout Standard
8926 \begin_inset VSpace bigskip
8932 \begin_layout Subsection
8934 \begin_inset LatexCommand \index{Options other}
8942 \labelwidthstring 00.00.0000
8950 \begin_layout Standard
8960 \begin_inset LatexCommand \index{-\/-compile-only}
8965 \begin_inset LatexCommand \index{-c -\/-compile-only}
8971 will compile and assemble the source, but will not call the linkage editor.
8975 \labelwidthstring 00.00.0000
8984 \begin_layout Standard
8996 \begin_inset LatexCommand \index{-\/-c1mode}
9002 reads the preprocessed source from standard input and compiles it.
9003 The file name for the assembler output must be specified using the -o option.
9007 \labelwidthstring 00.00.0000
9011 \begin_inset LatexCommand \index{-E}
9017 Run only the C preprocessor.
9018 Preprocess all the C source files specified and output the results to standard
9023 \labelwidthstring 00.00.0000
9028 \begin_inset LatexCommand \index{-o <path/file>}
9034 The output path where everything will be placed or the file name used for
9035 all generated output files.
9036 If the parameter is a path, it must have a trailing slash (or backslash
9037 for the Windows binaries) to be recognized as a path.
9042 Note for Windows users: if the path contains spaces, it should be surrounded
9044 The trailing backslash should be doubled in order to prevent escaping the
9045 final quote, for example:
9048 \begin_inset Quotes sld
9062 \begin_inset Quotes srd
9067 or put after the final quote, for example:
9070 \begin_inset Quotes sld
9080 \begin_inset Quotes srd
9088 The path using slashes for directory delimiters can be used too, for example:
9092 \begin_inset Quotes sld
9095 F:/Projects/test3/output 1/
9096 \begin_inset Quotes srd
9105 \labelwidthstring 00.00.0000
9112 \begin_layout Standard
9122 \begin_inset LatexCommand \index{-\/-stack-auto}
9133 All functions in the source file will be compiled as
9138 \begin_inset LatexCommand \index{reentrant}
9143 the parameters and local variables will be allocated on the stack
9144 \begin_inset LatexCommand \index{stack}
9150 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9154 Parameters and Local Variables for more details.
9155 If this option is used all source files in the project should be compiled
9157 It automatically implies --int-long-reent and --float-reent.
9162 \labelwidthstring 00.00.0000
9169 \begin_layout Standard
9179 \begin_inset LatexCommand \index{-\/-callee-saves}
9184 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9188 function1[,function2][,function3]....
9191 The compiler by default uses a caller saves convention for register saving
9192 across function calls, however this can cause unnecessary register pushing
9193 and popping when calling small functions from larger functions.
9194 This option can be used to switch the register saving convention for the
9195 function names specified.
9196 The compiler will not save registers when calling these functions, no extra
9197 code will be generated at the entry and exit (function prologue
9200 \begin_inset LatexCommand \index{function prologue}
9209 \begin_inset LatexCommand \index{function epilogue}
9215 ) for these functions to save and restore the registers used by these functions,
9216 this can SUBSTANTIALLY reduce code and improve run time performance of
9218 In the future the compiler (with inter procedural analysis) will be able
9219 to determine the appropriate scheme to use for each function call.
9220 DO NOT use this option for built-in functions such as _mulint..., if this
9221 option is used for a library function the appropriate library function
9222 needs to be recompiled with the same option.
9223 If the project consists of multiple source files then all the source file
9224 should be compiled with the same -
9228 \begin_layout Standard
9237 -callee-saves option string.
9238 Also see #pragma\InsetSpace ~
9240 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9245 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9253 \labelwidthstring 00.00.0000
9260 \begin_layout Standard
9270 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9284 \begin_layout Standard
9293 -callee-saves will be applied to all functions by default.
9297 \labelwidthstring 00.00.0000
9304 \begin_layout Standard
9314 \begin_inset LatexCommand \index{-\/-debug}
9323 When this option is used the compiler will generate debug information.
9324 The debug information collected in a file with .cdb extension can be used
9326 For more information see documentation for SDCDB.
9327 Another file with no extension contains debug information in AOMF or AOMF51
9328 \begin_inset LatexCommand \index{AOMF, AOMF51}
9332 format which is commonly used by third party tools.
9336 \labelwidthstring 00.00.0000
9340 \begin_inset LatexCommand \index{-S}
9351 Stop after the stage of compilation proper; do not assemble.
9352 The output is an assembler code file for the input file specified.
9356 \labelwidthstring 00.00.0000
9363 \begin_layout Standard
9373 \begin_inset LatexCommand \index{-\/-int-long-reent}
9379 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9380 Note by default these libraries are compiled as non-reentrant.
9381 See section Installation for more details.
9385 \labelwidthstring 00.00.0000
9392 \begin_layout Standard
9402 \begin_inset LatexCommand \index{-\/-cyclomatic}
9411 This option will cause the compiler to generate an information message for
9412 each function in the source file.
9413 The message contains some
9417 information about the function.
9418 The number of edges and nodes the compiler detected in the control flow
9419 graph of the function, and most importantly the
9421 cyclomatic complexity
9422 \begin_inset LatexCommand \index{Cyclomatic complexity}
9428 see section on Cyclomatic Complexity for more details.
9432 \labelwidthstring 00.00.0000
9439 \begin_layout Standard
9449 \begin_inset LatexCommand \index{-\/-float-reent}
9455 Floating point library is compiled as reentrant
9456 \begin_inset LatexCommand \index{reentrant}
9461 See section Installation for more details.
9465 \labelwidthstring 00.00.0000
9472 \begin_layout Standard
9482 \begin_inset LatexCommand \index{-\/-funsigned-char}
9488 The default signedness for every type is
9493 In some embedded environments the default signedness of
9502 To set the signess for characters to unsigned, use the option --funsigned-char.
9503 If this option is set and no signedness keyword (unsigned/signed) is given,
9504 a char will be signed.
9505 All other types are unaffected.
9509 \labelwidthstring 00.00.0000
9516 \begin_layout Standard
9526 \begin_inset LatexCommand \index{-\/-main-return}
9532 This option can be used if the code generated is called by a monitor program
9533 or if the main routine includes an endless loop.
9534 This option results in slightly smaller code and saves two bytes of stack
9536 The return from the 'main'
9537 \begin_inset LatexCommand \index{main return}
9541 function will return to the function calling main.
9542 The default setting is to lock up i.e.
9551 \labelwidthstring 00.00.0000
9558 \begin_layout Standard
9568 \begin_inset LatexCommand \index{-\/-nostdinc}
9574 This will prevent the compiler from passing on the default include path
9575 to the preprocessor.
9579 \labelwidthstring 00.00.0000
9586 \begin_layout Standard
9596 \begin_inset LatexCommand \index{-\/-nostdlib}
9602 This will prevent the compiler from passing on the default library
9603 \begin_inset LatexCommand \index{Libraries}
9611 \labelwidthstring 00.00.0000
9618 \begin_layout Standard
9628 \begin_inset LatexCommand \index{-\/-verbose}
9634 Shows the various actions the compiler is performing.
9638 \labelwidthstring 00.00.0000
9642 \begin_inset LatexCommand \index{-V}
9648 Shows the actual commands the compiler is executing.
9652 \labelwidthstring 00.00.0000
9659 \begin_layout Standard
9669 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9675 Hides your ugly and inefficient c-code from the asm file, so you can always
9676 blame the compiler :)
9680 \labelwidthstring 00.00.0000
9687 \begin_layout Standard
9697 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9703 Include code generator and peep-hole comments in the generated asm files.
9707 \labelwidthstring 00.00.0000
9714 \begin_layout Standard
9724 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9730 Don't include peep-hole comments in the generated asm files even if --fverbose-
9731 asm option is specified.
9735 \labelwidthstring 00.00.0000
9742 \begin_layout Standard
9752 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9758 Include i-codes in the asm file.
9759 Sounds like noise but is most helpful for debugging the compiler itself.
9763 \labelwidthstring 00.00.0000
9770 \begin_layout Standard
9780 \begin_inset LatexCommand \index{pedantic}
9785 \begin_inset LatexCommand \index{-\/-less-pedantic}
9792 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9796 Disable some of the more pedantic warnings
9797 \begin_inset LatexCommand \index{Warnings}
9802 For more details, see the less_pedantic pragma
9803 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9811 \labelwidthstring 00.00.0000
9818 \begin_layout Standard
9827 -disable-warning\InsetSpace ~
9829 \begin_inset LatexCommand \index{-\/-disable-warning}
9835 Disable specific warning with number <nnnn>.
9839 \labelwidthstring 00.00.0000
9846 \begin_layout Standard
9856 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9862 Display the directories in the compiler's search path
9866 \labelwidthstring 00.00.0000
9873 \begin_layout Standard
9883 \begin_inset LatexCommand \index{-\/-vc}
9889 Display errors and warnings using MSVC style, so you can use SDCC with
9890 the visual studio IDE
9891 \begin_inset LatexCommand \index{IDE}
9896 With SDCC both offering a GCC-like (the default) and a MSVC-like
9897 \begin_inset LatexCommand \index{MSVC output style}
9901 output style, integration into most programming editors should be straightforwa
9906 \labelwidthstring 00.00.0000
9913 \begin_layout Standard
9923 \begin_inset LatexCommand \index{-\/-use-stdout}
9929 Send errors and warnings to stdout instead of stderr.
9933 \labelwidthstring 00.00.0000
9937 asmOption[,asmOption]
9940 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9945 Pass the asmOption to the assembler
9946 \begin_inset LatexCommand \index{Options assembler}
9951 \begin_inset LatexCommand \index{Assembler options}
9956 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9960 \labelwidthstring 00.00.0000
9967 \begin_layout Standard
9977 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9983 Generally follow the C89 standard, but allow SDCC features that conflict
9984 with the standard (default).
9988 \labelwidthstring 00.00.0000
9995 \begin_layout Standard
10005 \begin_inset LatexCommand \index{-\/-std-c89}
10011 Follow the C89 standard and disable SDCC features that conflict with the
10016 \labelwidthstring 00.00.0000
10023 \begin_layout Standard
10033 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10039 Generally follow the C99 standard, but allow SDCC features that conflict
10040 with the standard (incomplete support).
10044 \labelwidthstring 00.00.0000
10051 \begin_layout Standard
10061 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10067 Follow the C99 standard and disable SDCC features that conflict with the
10068 standard (incomplete support).
10072 \labelwidthstring 00.00.0000
10079 \begin_layout Standard
10091 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10096 <Name> The name to be used for the code
10097 \begin_inset LatexCommand \index{code}
10101 segment, default CSEG.
10102 This is useful if you need to tell the compiler to put the code in a special
10103 segment so you can later on tell the linker to put this segment in a special
10105 Can be used for instance when using bank switching to put the code in a
10110 \labelwidthstring 00.00.0000
10117 \begin_layout Standard
10129 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10134 <Name> The name to be used for the const
10135 \begin_inset LatexCommand \index{const}
10139 segment, default CONST.
10140 This is useful if you need to tell the compiler to put the const data in
10141 a special segment so you can later on tell the linker to put this segment
10142 in a special place in memory.
10143 Can be used for instance when using bank switching to put the const data
10148 \labelwidthstring 00.00.0000
10155 \begin_layout Standard
10164 -fdollars-in-identifiers
10165 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10171 Permit '$' as an identifier character.
10175 \labelwidthstring 00.00.0000
10182 \begin_layout Standard
10194 \begin_inset LatexCommand \index{-\/-more-pedantic}
10199 \begin_inset LatexCommand \index{pedantic}
10209 a SDCC compiler option but if you want
10213 warnings you can use a separate tool dedicated to syntax checking like
10215 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10220 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10225 \begin_inset LatexCommand \url{http://www.splint.org}
10230 To make your source files parseable by splint you will have to include
10236 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10240 in your source file and add brackets around extended keywords (like
10243 \begin_inset Quotes sld
10256 \begin_inset Quotes srd
10264 \begin_inset Quotes sld
10267 __interrupt\InsetSpace ~
10269 \begin_inset Quotes srd
10277 Splint has an excellent on line manual at
10278 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10282 and it's capabilities go beyond pure syntax checking.
10283 You'll need to tell splint the location of SDCC's include files so a typical
10284 command line could look like this:
10288 splint\InsetSpace ~
10290 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10296 \labelwidthstring 00.00.0000
10303 \begin_layout Standard
10315 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10320 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10324 Treat short as 8-bit (for backward compatibility with older versions of
10325 compiler - see section
10326 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10333 \begin_layout Standard
10334 \begin_inset VSpace bigskip
10340 \begin_layout Subsection
10341 Intermediate Dump Options
10342 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10347 \begin_inset LatexCommand \index{Options intermediate dump}
10352 \begin_inset LatexCommand \index{Intermediate dump options}
10359 \begin_layout Standard
10360 The following options are provided for the purpose of retargetting and debugging
10362 They provide a means to dump the intermediate code (iCode
10363 \begin_inset LatexCommand \index{iCode}
10367 ) generated by the compiler in human readable form at various stages of
10368 the compilation process.
10369 More on iCodes see chapter
10370 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10375 \begin_inset Quotes srd
10378 The anatomy of the compiler
10379 \begin_inset Quotes srd
10386 \labelwidthstring 00.00.0000
10393 \begin_layout Standard
10403 \begin_inset LatexCommand \index{-\/-dumpraw}
10409 This option will cause the compiler to dump the intermediate code into
10412 <source filename>.dumpraw
10414 just after the intermediate code has been generated for a function, i.e.
10415 before any optimizations are done.
10417 \begin_inset LatexCommand \index{Basic blocks}
10421 at this stage ordered in the depth first number, so they may not be in
10422 sequence of execution.
10426 \labelwidthstring 00.00.0000
10433 \begin_layout Standard
10443 \begin_inset LatexCommand \index{-\/-dumpgcse}
10449 Will create a dump of iCode's, after global subexpression elimination
10450 \begin_inset LatexCommand \index{Global subexpression elimination}
10454 , into a file named
10456 <source filename>.dumpgcse.
10460 \labelwidthstring 00.00.0000
10467 \begin_layout Standard
10477 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10483 Will create a dump of iCode's, after deadcode elimination
10484 \begin_inset LatexCommand \index{Dead-code elimination}
10488 , into a file named
10490 <source filename>.dumpdeadcode.
10494 \labelwidthstring 00.00.0000
10501 \begin_layout Standard
10511 \begin_inset LatexCommand \index{-\/-dumploop}
10520 Will create a dump of iCode's, after loop optimizations
10521 \begin_inset LatexCommand \index{Loop optimization}
10525 , into a file named
10527 <source filename>.dumploop.
10531 \labelwidthstring 00.00.0000
10538 \begin_layout Standard
10548 \begin_inset LatexCommand \index{-\/-dumprange}
10557 Will create a dump of iCode's, after live range analysis
10558 \begin_inset LatexCommand \index{Live range analysis}
10562 , into a file named
10564 <source filename>.dumprange.
10568 \labelwidthstring 00.00.0000
10575 \begin_layout Standard
10585 \begin_inset LatexCommand \index{-\/-dumlrange}
10591 Will dump the life ranges
10592 \begin_inset LatexCommand \index{Live range analysis}
10600 \labelwidthstring 00.00.0000
10607 \begin_layout Standard
10617 \begin_inset LatexCommand \index{-\/-dumpregassign}
10626 Will create a dump of iCode's, after register assignment
10627 \begin_inset LatexCommand \index{Register assignment}
10631 , into a file named
10633 <source filename>.dumprassgn.
10637 \labelwidthstring 00.00.0000
10644 \begin_layout Standard
10654 \begin_inset LatexCommand \index{-\/-dumplrange}
10660 Will create a dump of the live ranges of iTemp's
10664 \labelwidthstring 00.00.0000
10671 \begin_layout Standard
10681 \begin_inset LatexCommand \index{-\/-dumpall}
10692 Will cause all the above mentioned dumps to be created.
10695 \begin_layout Standard
10696 \begin_inset VSpace bigskip
10702 \begin_layout Subsection
10703 Redirecting output on Windows Shells
10706 \begin_layout Standard
10707 By default SDCC writes it's error messages to
10708 \begin_inset Quotes sld
10712 \begin_inset Quotes srd
10716 To force all messages to
10717 \begin_inset Quotes sld
10721 \begin_inset Quotes srd
10733 \begin_layout Standard
10748 \begin_inset LatexCommand \index{-\/-use-stdout}
10753 Additionally, if you happen to have visual studio installed in your windows
10754 machine, you can use it to compile your sources using a custom build and
10761 \begin_layout Standard
10773 \begin_inset LatexCommand \index{-\/-vc}
10778 Something like this should work:
10797 \begin_layout Standard
10816 \begin_layout Standard
10828 -model-large -c $(InputPath)
10831 \begin_inset VSpace bigskip
10837 \begin_layout Section
10838 Environment variables
10839 \begin_inset LatexCommand \index{Environment variables}
10846 \begin_layout Standard
10847 SDCC recognizes the following environment variables:
10851 \labelwidthstring 00.00.0000
10855 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10861 SDCC installs a signal handler
10862 \begin_inset LatexCommand \index{signal handler}
10866 to be able to delete temporary files after an user break (^C) or an exception.
10867 If this environment variable is set, SDCC won't install the signal handler
10868 in order to be able to debug SDCC.
10872 \labelwidthstring 00.00.0000
10878 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10884 Path, where temporary files will be created.
10885 The order of the variables is the search order.
10886 In a standard *nix environment these variables are not set, and there's
10887 no need to set them.
10888 On Windows it's recommended to set one of them.
10892 \labelwidthstring 00.00.0000
10896 \begin_inset LatexCommand \index{SDCC\_HOME}
10903 \begin_inset LatexCommand \ref{sub:Install-paths}
10909 \begin_inset Quotes sld
10913 \begin_inset Quotes srd
10920 \labelwidthstring 00.00.0000
10924 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10931 \begin_inset LatexCommand \ref{sub:Search-Paths}
10937 \begin_inset Quotes sld
10941 \begin_inset Quotes srd
10948 \labelwidthstring 00.00.0000
10952 \begin_inset LatexCommand \index{SDCC\_LIB}
10959 \begin_inset LatexCommand \ref{sub:Search-Paths}
10965 \begin_inset Quotes sld
10969 \begin_inset Quotes srd
10975 \begin_layout Standard
10976 There are some more environment variables recognized by SDCC, but these
10977 are solely used for debugging purposes.
10978 They can change or disappear very quickly, and will never be documented.
10979 \begin_inset VSpace bigskip
10985 \begin_layout Section
10986 Storage Class Language Extensions
10989 \begin_layout Subsection
10990 MCS51/DS390 Storage Class
10991 \begin_inset LatexCommand \index{Storage class}
10995 Language Extensions
10998 \begin_layout Standard
10999 In addition to the ANSI storage classes SDCC allows the following MCS51
11000 specific storage classes:
11003 \begin_layout Subsubsection
11005 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11010 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11015 \begin_inset LatexCommand \index{near (storage class)}
11020 \begin_inset LatexCommand \index{\_\_near (storage class)}
11027 \begin_layout Standard
11032 storage class for the Small Memory model (
11040 or the more ANSI-C compliant forms
11048 can be used synonymously).
11049 Variables declared with this storage class will be allocated in the directly
11050 addressable portion of the internal RAM of a 8051, e.g.:
11053 \begin_layout Verse
11056 __data unsigned char test_data;
11059 \begin_layout Standard
11060 Writing 0x01 to this variable generates the assembly code:
11063 \begin_layout Verse
11066 75*00 01\InsetSpace ~
11074 \begin_layout Subsubsection
11076 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11081 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11086 \begin_inset LatexCommand \index{far (storage class)}
11091 \begin_inset LatexCommand \index{\_\_far (storage class)}
11098 \begin_layout Standard
11099 Variables declared with this storage class will be placed in the external
11105 storage class for the Large Memory model, e.g.:
11108 \begin_layout Verse
11111 __xdata unsigned char test_xdata;
11114 \begin_layout Standard
11115 Writing 0x01 to this variable generates the assembly code:
11118 \begin_layout Verse
11121 90s00r00\InsetSpace ~
11152 \begin_layout Subsubsection
11154 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11159 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11166 \begin_layout Standard
11167 Variables declared with this storage class will be allocated into the indirectly
11168 addressable portion of the internal ram of a 8051, e.g.:
11171 \begin_layout Verse
11174 __idata unsigned char test_idata;
11177 \begin_layout Standard
11178 Writing 0x01 to this variable generates the assembly code:
11181 \begin_layout Verse
11208 \begin_layout Standard
11209 Please note, the first 128 byte of idata physically access the same RAM
11210 as the data memory.
11211 The original 8051 had 128 byte idata memory, nowadays most devices have
11212 256 byte idata memory.
11214 \begin_inset LatexCommand \index{stack}
11218 is located in idata memory.
11221 \begin_layout Subsubsection
11223 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11228 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11235 \begin_layout Standard
11236 Paged xdata access is just as straightforward as using the other addressing
11238 It is typically located at the start of xdata and has a maximum size of
11240 The following example writes 0x01 to the pdata variable.
11241 Please note, pdata access physically accesses xdata memory.
11242 The high byte of the address is determined by port P2
11243 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11247 (or in case of some 8051 variants by a separate Special Function Register,
11249 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11258 storage class for the Medium Memory model, e.g.:
11261 \begin_layout Verse
11264 __pdata unsigned char test_pdata;
11267 \begin_layout Standard
11268 Writing 0x01 to this variable generates the assembly code:
11271 \begin_layout Verse
11280 mov r0,#_test_pdata
11302 \begin_layout Standard
11307 \begin_layout Standard
11317 \begin_inset LatexCommand \index{-\/-xstack}
11321 option is used the pdata memory area is followed by the xstack memory area
11322 and the sum of their sizes is limited to 256 bytes.
11325 \begin_layout Subsubsection
11327 \begin_inset LatexCommand \index{code}
11332 \begin_inset LatexCommand \index{\_\_code}
11339 \begin_layout Standard
11340 'Variables' declared with this storage class will be placed in the code
11344 \begin_layout Verse
11347 __code unsigned char test_code;
11350 \begin_layout Standard
11351 Read access to this variable generates the assembly code:
11354 \begin_layout Verse
11357 90s00r6F\InsetSpace ~
11360 mov dptr,#_test_code
11385 \begin_layout Standard
11390 indexed arrays of characters in code memory can be accessed efficiently:
11393 \begin_layout Verse
11396 __code char test_array[] = {'c','h','e','a','p'};
11399 \begin_layout Standard
11400 Read access to this array using an 8-bit unsigned index generates the assembly
11404 \begin_layout Verse
11416 \begin_layout Verse
11419 90s00r41\InsetSpace ~
11422 mov dptr,#_test_array
11425 \begin_layout Verse
11440 \begin_layout Subsubsection
11442 \begin_inset LatexCommand \index{bit}
11447 \begin_inset LatexCommand \index{\_\_bit}
11454 \begin_layout Standard
11455 This is a data-type and a storage class specifier.
11456 When a variable is declared as a bit, it is allocated into the bit addressable
11457 memory of 8051, e.g.:
11460 \begin_layout Verse
11466 \begin_layout Standard
11467 Writing 1 to this variable generates the assembly code:
11470 \begin_layout Verse
11484 \begin_layout Standard
11485 The bit addressable memory consists of 128 bits which are located from 0x20
11486 to 0x2f in data memory.
11489 Apart from this 8051 specific storage class most architectures support
11491 \begin_inset LatexCommand \index{bitfields}
11499 \begin_layout Standard
11500 Not really meant as examples, but nevertheless showing what bitfields are
11501 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11507 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11508 signed modifier are implemented as unsigned.
11511 \begin_layout Subsubsection
11513 \begin_inset LatexCommand \index{sfr}
11518 \begin_inset LatexCommand \index{\_\_sfr}
11523 \begin_inset LatexCommand \index{sfr16}
11528 \begin_inset LatexCommand \index{\_\_sfr16}
11533 \begin_inset LatexCommand \index{sfr32}
11538 \begin_inset LatexCommand \index{\_\_sfr32}
11543 \begin_inset LatexCommand \index{\_\_sbit}
11548 \begin_inset LatexCommand \index{sbit}
11555 \begin_layout Standard
11556 Like the bit keyword,
11558 sfr / sfr16 / sfr32 / sbit
11560 signify both a data-type and storage class, they are used to describe the
11581 variables of a 8051, eg:
11584 \begin_layout Verse
11588 \begin_inset LatexCommand \index{at}
11593 \begin_inset LatexCommand \index{\_\_at}
11597 (0x80) P0;\InsetSpace ~
11598 /* special function register P0 at location 0x80 */
11603 special function register combination for timer 0
11607 with the high byte at
11608 location 0x8C and the low byte at location 0x8A */
11610 __sfr16 __at (0x8C8A)
11616 \begin_inset LatexCommand \index{at}
11621 \begin_inset LatexCommand \index{\_\_at}
11625 (0xd7) CY;\InsetSpace ~
11627 \begin_inset LatexCommand \index{Flags}
11632 \begin_inset LatexCommand \index{Carry flag}
11639 \begin_layout Standard
11640 Special function registers which are located on an address dividable by
11641 8 are bit-addressable, an
11645 addresses a specific bit within these sfr.
11647 16 Bit and 32 bit special function
11648 register combinations which require a certain access order are better not
11658 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11659 this is not guaranteed.
11664 \begin_layout Standard
11665 Please note, if you use a header file which was written for another compiler
11666 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11672 Specifically the syntax
11675 sfr P0 = 0x80;\InsetSpace ~
11682 by SDCC to an assignment of 0x80 to a variable called P0
11685 \begin_inset Marginal
11688 \begin_layout Standard
11700 Nevertheless it is possible to write header files
11701 \begin_inset LatexCommand \index{Header files}
11706 \begin_inset LatexCommand \index{Include files}
11710 which can be shared among different compilers (see section
11711 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11719 \begin_layout Subsubsection
11721 \begin_inset LatexCommand \index{Pointer}
11725 to MCS51/DS390 specific memory spaces
11728 \begin_layout Standard
11729 SDCC allows (via language extensions) pointers to explicitly point to any
11730 of the memory spaces
11731 \begin_inset LatexCommand \index{Memory model}
11736 In addition to the explicit pointers, the compiler uses (by default) generic
11737 pointers which can be used to point to any of the memory spaces.
11742 declaration examples:
11745 \begin_layout Verse
11748 /* pointer physically in internal ram pointing to object in external ram
11751 __xdata unsigned char * __data p;
11755 /* pointer physically in external ram
11756 pointing to object in internal ram */
11758 __data unsigned char * __xdata p;
11763 pointer physically in code rom pointing to data in xdata space */
11766 unsigned char * __code p;
11770 /* pointer physically in code space pointing to
11771 data in code space */
11773 __code unsigned char * __code p;
11778 physically located in xdata space */
11780 unsigned char * __xdata p;
11785 pointer physically located in default memory space */
11792 the following is a function pointer
11793 \begin_inset LatexCommand \index{function pointer}
11797 physically located in data space */
11799 char (* __data fp)(void);
11802 \begin_layout Standard
11803 Well you get the idea.
11808 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11821 The highest order byte of the
11825 pointers contains the data space information.
11826 Assembler support routines are called whenever data is stored or retrieved
11832 These are useful for developing reusable library
11833 \begin_inset LatexCommand \index{Libraries}
11838 Explicitly specifying the pointer
11839 \begin_inset LatexCommand \index{pointer}
11843 type will generate the most efficient code.
11846 \begin_layout Subsubsection
11847 Notes on MCS51 memory
11848 \begin_inset LatexCommand \index{MCS51 memory}
11855 \begin_layout Standard
11856 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11857 RAM memory which is structured as follows:
11861 - Bytes 00-1F - 32 bytes to hold
11862 up to 4 banks of the registers R0 to R7,
11864 - Bytes 20-2F - 16 bytes to hold
11866 \begin_inset LatexCommand \index{bit}
11872 - Bytes 30-7F - 80 bytes for general purpose use.
11877 \begin_layout Standard
11878 Additionally some members of the MCS51 family may have up to 128 bytes of
11879 additional, indirectly addressable, internal RAM memory (
11884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11889 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11894 Furthermore, some chips may have some built in external memory (
11899 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11904 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11908 ) which should not be confused with the internal, directly addressable RAM
11914 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11919 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11924 Sometimes this built in
11928 memory has to be activated before using it (you can probably find this
11929 information on the datasheet of the microcontroller your are using, see
11931 \begin_inset LatexCommand \ref{sub:Startup-Code}
11939 \begin_layout Standard
11940 Normally SDCC will only use the first bank
11941 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11945 of registers (register bank 0), but it is possible to specify that other
11946 banks of registers (keyword
11953 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11958 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11964 ) should be used for example in interrupt
11965 \begin_inset LatexCommand \index{interrupt}
11970 \begin_inset LatexCommand \index{\_\_interrupt}
11975 By default, the compiler will place the stack after the last byte of allocated
11976 memory for variables.
11977 For example, if the first 2 banks of registers are used, and only four
11982 variables, it will position the base of the internal stack at address 20
11984 This implies that as the stack
11985 \begin_inset LatexCommand \index{stack}
11989 grows, it will use up the remaining register banks, and the 16 bytes used
11990 by the 128 bit variables, and 80 bytes for general purpose use.
11991 If any bit variables are used, the data variables will be placed in unused
11992 register banks and after the byte holding the last bit variable.
11993 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11998 variables will be placed starting from address 0x10 to 0x20 and continue
12004 \begin_layout Standard
12014 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12018 to specify the start address of the
12026 \begin_layout Standard
12036 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12040 to specify the size of the total internal RAM (
12054 \begin_layout Standard
12055 By default the 8051 linker will place the stack after the last byte of (i)data
12061 \begin_layout Standard
12071 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12075 allows you to specify the start of the stack, i.e.
12076 you could start it after any data in the general purpose area.
12077 If your microcontroller has additional indirectly addressable internal
12082 ) you can place the stack on it.
12083 You may also need to use -
12087 \begin_layout Standard
12097 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12101 to set the start address of the external RAM (
12109 \begin_layout Standard
12119 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12123 to specify its size.
12124 Same goes for the code memory, using -
12128 \begin_layout Standard
12138 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12146 \begin_layout Standard
12156 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12161 If in doubt, don't specify any options and see if the resulting memory
12162 layout is appropriate, then you can adjust it.
12165 \begin_layout Standard
12166 The linker generates two files with memory allocation information.
12167 The first, with extension .map
12168 \begin_inset LatexCommand \index{<file>.map}
12172 shows all the variables and segments.
12173 The second with extension .mem
12174 \begin_inset LatexCommand \index{<file>.mem}
12178 shows the final memory layout.
12179 The linker will complain either if memory segments overlap, there is not
12180 enough memory, or there is not enough space for stack.
12181 If you get any linking warnings and/or errors related to stack or segments
12182 allocation, take a look at either the .map or .mem files to find out what
12184 The .mem file may even suggest a solution to the problem.
12185 \begin_inset VSpace bigskip
12191 \begin_layout Subsection
12192 Z80/Z180 Storage Class
12193 \begin_inset LatexCommand \index{Z80!Storage class}
12197 Language Extensions
12200 \begin_layout Subsubsection
12202 \begin_inset LatexCommand \index{sfr}
12207 \begin_inset LatexCommand \index{\_\_sfr}
12211 (in/out to 8-bit addresses)
12214 \begin_layout Standard
12216 \begin_inset LatexCommand \index{Z80}
12220 family has separate address spaces for memory and
12230 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12235 \begin_inset LatexCommand \index{Z80!I/O memory}
12240 \begin_inset LatexCommand \index{Z180!I/O memory}
12244 is accessed with special instructions, e.g.:
12247 \begin_layout Verse
12250 sfr at 0x78 IoPort;\InsetSpace ~
12252 /* define a var in I/O space at 78h called IoPort */
12256 \begin_layout Standard
12257 Writing 0x01 to this variable generates the assembly code:
12260 \begin_layout Verse
12280 \begin_layout Subsubsection
12282 \begin_inset LatexCommand \index{sfr}
12287 \begin_inset LatexCommand \index{\_\_sfr}
12291 (in/out to 16-bit addresses)
12294 \begin_layout Standard
12299 is used to support 16 bit addresses in I/O memory e.g.:
12302 \begin_layout Verse
12306 \begin_inset LatexCommand \index{at}
12311 \begin_inset LatexCommand \index{\_\_at}
12318 \begin_layout Standard
12319 Writing 0x01 to this variable generates the assembly code:
12322 \begin_layout Verse
12325 01 23 01\InsetSpace ~
12347 \begin_layout Subsubsection
12349 \begin_inset LatexCommand \index{sfr}
12354 \begin_inset LatexCommand \index{\_\_sfr}
12358 (in0/out0 to 8 bit addresses on Z180
12359 \begin_inset LatexCommand \index{Z180}
12364 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12371 \begin_layout Standard
12372 The compiler option -
12376 \begin_layout Standard
12386 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12390 =180 (80) and a compiler #pragma\InsetSpace ~
12392 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12396 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12406 If you include the file z180.h this will be set automatically.
12407 \begin_inset VSpace bigskip
12413 \begin_layout Subsection
12415 \begin_inset LatexCommand \index{HC08!Storage class}
12419 Language Extensions
12422 \begin_layout Subsubsection
12424 \begin_inset LatexCommand \index{data (hc08 storage class)}
12429 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12436 \begin_layout Standard
12437 The data storage class declares a variable that resides in the first 256
12438 bytes of memory (the direct page).
12440 \begin_inset LatexCommand \index{HC08}
12444 is most efficient at accessing variables (especially pointers) stored here.
12447 \begin_layout Subsubsection
12449 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12454 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12461 \begin_layout Standard
12462 The xdata storage class declares a variable that can reside anywhere in
12464 This is the default if no storage class is specified.
12466 \begin_inset VSpace bigskip
12472 \begin_layout Section
12473 Absolute Addressing
12474 \begin_inset LatexCommand \index{Absolute addressing}
12481 \begin_layout Standard
12482 Data items can be assigned an absolute address with the
12485 \begin_inset LatexCommand \index{at}
12490 \begin_inset LatexCommand \index{\_\_at}
12496 keyword, in addition to a storage class, e.g.:
12499 \begin_layout Verse
12503 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12508 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12513 \begin_inset LatexCommand \index{at}
12518 \begin_inset LatexCommand \index{\_\_at}
12522 0x7ffe unsigned int chksum;
12525 \begin_layout Standard
12526 or, better conforming to ISO/IEC 9899 C:
12529 \begin_layout Verse
12532 __xdata __at (0x7ffe) unsigned int chksum;
12535 \begin_layout Standard
12536 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12537 of the external ram.
12542 reserve any space for variables declared in this way
12543 \begin_inset Marginal
12546 \begin_layout Standard
12555 (they are implemented with an equate in the assembler).
12556 Thus it is left to the programmer to make sure there are no overlaps with
12557 other variables that are declared without the absolute address.
12558 The assembler listing file (.lst
12559 \begin_inset LatexCommand \index{<file>.lst}
12563 ) and the linker output files (.rst
12564 \begin_inset LatexCommand \index{<file>.rst}
12569 \begin_inset LatexCommand \index{<file>.map}
12573 ) are good places to look for such overlaps.
12574 Variables with an absolute address are
12577 \begin_inset Marginal
12580 \begin_layout Standard
12592 \begin_inset LatexCommand \index{Variable initialization}
12599 \begin_layout Standard
12600 In case of memory mapped I/O devices the keyword
12604 has to be used to tell the compiler that accesses might not be removed:
12607 \begin_layout Verse
12611 \begin_inset LatexCommand \index{volatile}
12616 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12621 \begin_inset LatexCommand \index{at}
12625 (0x8000) unsigned char PORTA_8255;
12628 \begin_layout Standard
12629 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12634 \begin_inset LatexCommand \index{Aligned array}
12641 starts at a block (256 byte) boundary
12642 \begin_inset LatexCommand \index{block boundary}
12647 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12653 Absolute addresses can be specified for variables in all
12654 storage classes, e.g.:
12657 \begin_layout Verse
12661 \begin_inset LatexCommand \index{bit}
12666 \begin_inset LatexCommand \index{at}
12673 \begin_layout Standard
12674 The above example will allocate the variable at offset 0x02 in the bit-addressab
12676 There is no real advantage to assigning absolute addresses to variables
12677 in this manner, unless you want strict control over all the variables allocated.
12678 One possible use would be to write hardware portable code.
12679 For example, if you have a routine that uses one or more of the microcontroller
12680 I/O pins, and such pins are different for two different hardwares, you
12681 can declare the I/O pins in your routine using:
12684 \begin_layout Verse
12688 \begin_inset LatexCommand \index{volatile}
12692 __bit MOSI;\InsetSpace ~
12696 /* master out, slave in */
12698 extern volatile __bit MISO;\InsetSpace ~
12705 extern volatile __bit MCLK;\InsetSpace ~
12714 Output of a byte on a 3-wire serial bus.
12719 If needed adapt polarity of clock,
12720 polarity of data and bit order
12725 unsigned char spi_io(unsigned char out_byte)
12750 MOSI = out_byte & 0x80;
12781 /* _asm nop _endasm; */\InsetSpace ~
12789 /* for slow peripherals */
12841 \begin_layout Standard
12842 Then, someplace in the code for the first hardware you would use
12845 \begin_layout Verse
12849 \begin_inset LatexCommand \index{at}
12854 \begin_inset LatexCommand \index{\_\_at}
12858 (0x80) MOSI;\InsetSpace ~
12862 /* I/O port 0, bit 0 */
12864 __bit __at (0x81) MISO;\InsetSpace ~
12871 __bit __at (0x82) MCLK;\InsetSpace ~
12875 /* I/O port 0, bit 2 */
12878 \begin_layout Standard
12879 Similarly, for the second hardware you would use
12882 \begin_layout Verse
12885 __bit __at (0x83) MOSI;\InsetSpace ~
12889 /* I/O port 0, bit 3 */
12891 __bit __at (0x91) MISO;\InsetSpace ~
12896 I/O port 1, bit 1 */
12899 \begin_inset LatexCommand \index{bit}
12903 __at (0x92) MCLK;\InsetSpace ~
12907 /* I/O port 1, bit 2 */
12910 \begin_layout Standard
12911 and you can use the same hardware dependent routine without changes, as
12912 for example in a library.
12913 This is somehow similar to sbit, but only one absolute address has to be
12914 specified in the whole project.
12915 \begin_inset VSpace bigskip
12921 \begin_layout Section
12923 \begin_inset LatexCommand \index{Parameters}
12928 \begin_inset LatexCommand \index{function parameter}
12933 \begin_inset LatexCommand \index{local variables}
12938 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12945 \begin_layout Standard
12946 Automatic (local) variables and parameters to functions can either be placed
12947 on the stack or in data-space.
12948 The default action of the compiler is to place these variables in the internal
12949 RAM (for small model) or external RAM (for large model).
12950 This in fact makes them similar to
12953 \begin_inset LatexCommand \index{static}
12959 so by default functions are non-reentrant
12960 \begin_inset LatexCommand \index{reentrant}
12969 They can be placed on the stack
12970 \begin_inset LatexCommand \index{stack}
12980 \begin_layout Standard
12990 \begin_inset LatexCommand \index{-\/-stack-auto}
12998 #pragma\InsetSpace ~
13002 \begin_inset LatexCommand \index{\#pragma stackauto}
13009 \begin_inset LatexCommand \index{reentrant}
13015 keyword in the function declaration, e.g.:
13018 \begin_layout Verse
13021 unsigned char foo(char i) __reentrant
13035 \begin_layout Standard
13036 Since stack space on 8051 is limited, the
13046 \begin_layout Standard
13057 option should be used sparingly.
13058 Note that the reentrant keyword just means that the parameters & local
13059 variables will be allocated to the stack, it
13063 mean that the function is register bank
13064 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13073 \begin_inset LatexCommand \index{local variables}
13077 can be assigned storage classes and absolute
13078 \begin_inset LatexCommand \index{Absolute addressing}
13085 \begin_layout Verse
13088 unsigned char foo()
13096 __xdata unsigned char i;
13109 \begin_inset LatexCommand \index{at}
13113 (0x31) unsigned char j;
13125 \begin_layout Standard
13126 In the above example the variable
13130 will be allocated in the external ram,
13134 in bit addressable space and
13145 \begin_layout Standard
13156 or when a function is declared as
13160 this should only be done for static variables.
13163 \begin_layout Standard
13165 \begin_inset LatexCommand \index{function parameter}
13169 however are not allowed any storage class
13170 \begin_inset LatexCommand \index{Storage class}
13174 , (storage classes for parameters will be ignored), their allocation is
13175 governed by the memory model in use, and the reentrancy options.
13178 \begin_layout Standard
13179 It is however allowed to use bit parameters in reentrant functions and also
13180 non-static local bit variables are supported.
13181 Efficient use is limited to 8 semi-bitregisters in bit space.
13182 They are pushed and popped to stack
13183 \begin_inset LatexCommand \index{stack}
13187 as a single byte just like the normal registers.
13190 \begin_layout Section
13192 \begin_inset LatexCommand \label{sub:Overlaying}
13197 \begin_inset LatexCommand \index{Overlaying}
13204 \begin_layout Standard
13206 \begin_inset LatexCommand \index{reentrant}
13210 functions SDCC will try to reduce internal ram space usage by overlaying
13211 parameters and local variables of a function (if possible).
13212 Parameters and local variables
13213 \begin_inset LatexCommand \index{local variables}
13217 of a function will be allocated to an overlayable segment if the function
13220 no other function calls and the function is non-reentrant and the memory
13222 \begin_inset LatexCommand \index{Memory model}
13229 If an explicit storage class
13230 \begin_inset LatexCommand \index{Storage class}
13234 is specified for a local variable, it will NOT be overlayed.
13237 \begin_layout Standard
13238 Note that the compiler (not the linkage editor) makes the decision for overlayin
13240 Functions that are called from an interrupt service routine
13241 \begin_inset Marginal
13244 \begin_layout Standard
13252 should be preceded by a #pragma\InsetSpace ~
13254 \begin_inset LatexCommand \index{\#pragma nooverlay}
13258 if they are not reentrant.
13261 \begin_layout Standard
13262 Also note that the compiler does not do any processing of inline assembler
13263 code, so the compiler might incorrectly assign local variables and parameters
13264 of a function into the overlay segment if the inline assembler code calls
13265 other c-functions that might use the overlay.
13266 In that case the #pragma\InsetSpace ~
13267 nooverlay should be used.
13270 \begin_layout Standard
13271 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13273 \begin_inset LatexCommand \index{Multiplication}
13278 \begin_inset LatexCommand \index{Division}
13282 will NOT be overlayed since these are implemented using external functions,
13286 \begin_layout Verse
13292 \begin_inset LatexCommand \index{\#pragma nooverlay}
13298 void set_error(unsigned char errcd)
13315 some_isr () __interrupt
13316 \begin_inset LatexCommand \index{interrupt}
13346 \begin_layout Standard
13347 In the above example the parameter
13355 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13357 not present, this could cause unpredictable runtime behavior when called
13358 from an interrupt service routine.
13359 The #pragma\InsetSpace ~
13360 nooverlay ensures that the parameters and local variables for
13361 the function are NOT overlayed.
13362 \begin_inset VSpace bigskip
13368 \begin_layout Section
13369 Interrupt Service Routines
13370 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13377 \begin_layout Subsection
13378 General Information
13381 \begin_layout Standard
13394 outines to be coded in C, with some extended keywords.
13397 \begin_layout Verse
13400 void timer_isr (void) __interrupt (1) __using (1)
13414 \begin_layout Standard
13415 The optional number following the
13418 \begin_inset LatexCommand \index{interrupt}
13423 \begin_inset LatexCommand \index{\_\_interrupt}
13429 keyword is the interrupt number this routine will service.
13430 When present, the compiler will insert a call to this routine in the interrupt
13432 \begin_inset LatexCommand \index{interrupt vector table}
13436 for the interrupt number specified.
13437 If you have multiple source files in your project, interrupt service routines
13438 can be present in any of them, but a prototype of the isr MUST be present
13439 or included in the file that contains the function
13444 The optional (8051 specific) keyword
13447 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13452 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13458 can be used to tell the compiler to use the specified register bank when
13459 generating code for this function.
13462 Interrupt service routines open the door for some very interesting bugs:
13465 \begin_layout Subsubsection
13466 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13470 Common interrupt pitfall: variable not declared
13475 \begin_layout Standard
13476 If an interrupt service routine changes variables which are accessed by
13477 other functions these variables have to be declared
13482 \begin_inset LatexCommand \index{volatile}
13488 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13495 \begin_layout Subsubsection
13496 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13500 Common interrupt pitfall:
13505 \begin_layout Standard
13506 If the access to these variables is not
13509 \begin_inset LatexCommand \index{atomic}
13516 the processor needs more than one instruction for the access and could
13517 be interrupted while accessing the variable) the interrupt must be disabled
13518 during the access to avoid inconsistent data.
13521 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13522 and should be protected by disabling interrupts.
13523 You're not automatically on the safe side if you use 8 bit variables though.
13524 We need an example here: f.e.
13525 on the 8051 the harmless looking
13526 \begin_inset Quotes srd
13536 \begin_inset Quotes sld
13545 \begin_inset Quotes srd
13555 \begin_inset Quotes sld
13558 from within an interrupt routine might get lost if the interrupt occurs
13561 \begin_inset Quotes sld
13566 counter\InsetSpace ~
13571 \begin_inset Quotes srd
13574 is not atomic on the 8051 even if
13578 is located in data memory.
13580 Bugs like these are hard to reproduce and can
13581 cause a lot of trouble.
13585 \begin_layout Subsubsection
13586 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13590 Common interrupt pitfall:
13595 \begin_layout Standard
13596 The return address and the registers used in the interrupt service routine
13597 are saved on the stack
13598 \begin_inset LatexCommand \index{stack}
13602 so there must be sufficient stack space.
13603 If there isn't variables or registers (or even the return address itself)
13610 \begin_inset LatexCommand \index{stack overflow}
13614 is most likely to happen if the interrupt occurs during the
13615 \begin_inset Quotes sld
13619 \begin_inset Quotes srd
13622 subroutine when the stack is already in use for f.e.
13623 many return addresses.
13626 \begin_layout Subsubsection
13627 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13631 Common interrupt pitfall:
13633 use of non-reentrant functions
13636 \begin_layout Standard
13637 A special note here, int (16 bit) and long (32 bit) integer division
13638 \begin_inset LatexCommand \index{Division}
13643 \begin_inset LatexCommand \index{Multiplication}
13648 \begin_inset LatexCommand \index{Modulus}
13653 \begin_inset LatexCommand \index{Floating point support}
13657 operations are implemented using external support routines.
13658 If an interrupt service routine needs to do any of these operations then
13659 the support routines (as mentioned in a following section) will have to
13660 be recompiled using the
13666 \begin_layout Standard
13676 \begin_inset LatexCommand \index{-\/-stack-auto}
13682 option and the source file will need to be compiled using the
13688 \begin_layout Standard
13700 \begin_inset LatexCommand \index{-\/-int-long-reent}
13707 Note, the type promotion
13708 \begin_inset LatexCommand \index{type promotion}
13712 required by ANSI C can cause 16 bit routines to be used
13713 \begin_inset Marginal
13716 \begin_layout Standard
13725 without the programmer being aware of it.
13729 (unsigned char)(tail-1)
13731 within the if clause in section
13732 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13739 \begin_layout Standard
13740 Calling other functions from an interrupt service routine is not recommended,
13741 avoid it if possible.
13742 Note that when some function is called from an interrupt service routine
13743 it should be preceded by a #pragma\InsetSpace ~
13745 \begin_inset LatexCommand \index{\#pragma nooverlay}
13749 if it is not reentrant.
13750 Furthermore nonreentrant functions should not be called from the main program
13751 while the interrupt service routine might be active.
13752 They also must not be called from low priority interrupt service routines
13753 while a high priority interrupt service routine might be active.
13754 You could use semaphores or make the function
13758 if all parameters are passed in registers.
13761 \begin_inset LatexCommand \ref{sub:Overlaying}
13766 about Overlaying and section
13767 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13772 about Functions using private register banks.
13773 \begin_inset VSpace bigskip
13779 \begin_layout Subsection
13780 MCS51/DS390 Interrupt Service Routines
13783 \begin_layout Standard
13785 \begin_inset LatexCommand \index{interrupt}
13789 numbers and the corresponding address & descriptions for the Standard 8051/8052
13791 SDCC will automatically adjust the
13792 \begin_inset LatexCommand \index{interrupt vector table}
13796 to the maximum interrupt number specified.
13801 \begin_layout Standard
13803 \begin_inset Tabular
13804 <lyxtabular version="3" rows="9" columns="3">
13806 <column alignment="center" valignment="top" leftline="true" width="0in">
13807 <column alignment="left" valignment="top" leftline="true" width="0in">
13808 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13809 <row topline="true" bottomline="true">
13810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13813 \begin_layout Standard
13819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13822 \begin_layout Standard
13828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13831 \begin_layout Standard
13838 <row topline="true">
13839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13842 \begin_layout Standard
13848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13851 \begin_layout Standard
13857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13860 \begin_layout Standard
13867 <row topline="true">
13868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13871 \begin_layout Standard
13877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13880 \begin_layout Standard
13886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13889 \begin_layout Standard
13896 <row topline="true">
13897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13900 \begin_layout Standard
13906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13909 \begin_layout Standard
13915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13918 \begin_layout Standard
13925 <row topline="true">
13926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13929 \begin_layout Standard
13935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13938 \begin_layout Standard
13944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13947 \begin_layout Standard
13954 <row topline="true">
13955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13958 \begin_layout Standard
13964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13967 \begin_layout Standard
13973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13976 \begin_layout Standard
13983 <row topline="true">
13984 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13987 \begin_layout Standard
13993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13996 \begin_layout Standard
14002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14005 \begin_layout Standard
14012 <row topline="true">
14013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14016 \begin_layout Standard
14022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14025 \begin_layout Standard
14031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14034 \begin_layout Standard
14041 <row topline="true" bottomline="true">
14042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14045 \begin_layout Standard
14051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14054 \begin_layout Standard
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14063 \begin_layout Standard
14079 \begin_layout Standard
14080 If the interrupt service routine is defined without
14083 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14088 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14094 a register bank or with register bank 0 (
14098 0), the compiler will save the registers used by itself on the stack upon
14099 entry and restore them at exit, however if such an interrupt service routine
14100 calls another function then the entire register bank will be saved on the
14102 This scheme may be advantageous for small interrupt service routines which
14103 have low register usage.
14106 \begin_layout Standard
14107 If the interrupt service routine is defined to be using a specific register
14112 & psw are saved and restored, if such an interrupt service routine calls
14113 another function (using another register bank) then the entire register
14114 bank of the called function will be saved on the stack
14115 \begin_inset LatexCommand \index{stack}
14120 This scheme is recommended for larger interrupt service routines.
14121 \begin_inset VSpace bigskip
14127 \begin_layout Subsection
14129 \begin_inset LatexCommand \index{HC08}
14133 Interrupt Service Routines
14136 \begin_layout Standard
14137 Since the number of interrupts
14138 \begin_inset LatexCommand \index{HC08!interrupt}
14142 available is chip specific and the interrupt vector table always ends at
14143 the last byte of memory, the interrupt numbers corresponds to the interrupt
14144 vectors in reverse order of address.
14145 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14146 2 will use the interrupt vector at 0xfffa, and so on.
14147 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14148 this way; instead see section
14149 \begin_inset LatexCommand \ref{sub:Startup-Code}
14153 for details on customizing startup.
14154 \begin_inset VSpace bigskip
14160 \begin_layout Subsection
14161 Z80 Interrupt Service Routines
14164 \begin_layout Standard
14166 \begin_inset LatexCommand \index{Z80}
14170 uses several different methods for determining the correct interrupt
14171 \begin_inset LatexCommand \index{Z80!interrupt}
14175 vector depending on the hardware implementation.
14176 Therefore, SDCC ignores the optional interrupt number and does not attempt
14177 to generate an interrupt vector table.
14180 \begin_layout Standard
14181 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14182 instruction to return from the interrupt.
14183 To write an interrupt handler for the non-maskable interrupt, which needs
14184 a RETN instruction instead, add the
14191 \begin_layout Verse
14194 void nmi_isr (void) critical interrupt
14208 \begin_layout Standard
14209 However if you need to create a non-interruptable interrupt service routine
14210 you would also require the
14215 To distinguish between this and an nmi_isr you must provide an interrupt
14217 \begin_inset VSpace bigskip
14223 \begin_layout Section
14224 Enabling and Disabling Interrupts
14227 \begin_layout Subsection
14228 Critical Functions and Critical Statements
14231 \begin_layout Standard
14232 A special keyword may be associated with a block or a function declaring
14238 SDCC will generate code to disable all interrupts
14239 \begin_inset LatexCommand \index{interrupt}
14243 upon entry to a critical function and restore the interrupt enable to the
14244 previous state before returning.
14245 Nesting critical functions will need one additional byte on the stack
14246 \begin_inset LatexCommand \index{stack}
14253 \begin_layout Verse
14256 int foo () __critical
14257 \begin_inset LatexCommand \index{critical}
14262 \begin_inset LatexCommand \index{\_\_critical}
14287 \begin_layout Standard
14288 The critical attribute maybe used with other attributes like
14298 may also be used to disable interrupts more locally:
14301 \begin_layout Verse
14307 \begin_layout Standard
14308 More than one statement could have been included in the block.
14311 \begin_layout Subsection
14312 Enabling and Disabling Interrupts directly
14315 \begin_layout Standard
14317 \begin_inset LatexCommand \index{interrupt}
14321 can also be disabled and enabled directly (8051):
14324 \begin_layout Verse
14327 EA = 0;\InsetSpace ~
14353 \begin_layout Verse
14389 \begin_layout Verse
14392 EA = 1;\InsetSpace ~
14421 \begin_layout Verse
14460 \begin_layout Standard
14461 On other architectures which have seperate opcodes for enabling and disabling
14462 interrupts you might want to make use of defines with inline assembly
14463 \begin_inset LatexCommand \index{Assembler routines}
14468 \begin_inset LatexCommand \index{HC08!interrupt}
14475 \begin_layout Verse
14479 \begin_inset LatexCommand \index{\_asm}
14488 \begin_inset LatexCommand \index{\_endasm}
14495 \begin_layout Verse
14498 #define SEI _asm\InsetSpace ~
14505 \begin_layout Verse
14511 \begin_layout Standard
14512 Note: it is sometimes sufficient to disable only a specific interrupt source
14514 a timer or serial interrupt by manipulating an
14517 \begin_inset LatexCommand \index{interrupt mask}
14527 \begin_layout Standard
14528 Usually the time during which interrupts are disabled should be kept as
14530 This minimizes both
14535 \begin_inset LatexCommand \index{interrupt latency}
14539 (the time between the occurrence of the interrupt and the execution of
14540 the first code in the interrupt routine) and
14545 \begin_inset LatexCommand \index{interrupt jitter}
14549 (the difference between the shortest and the longest interrupt latency).
14550 These really are something different, f.e.
14551 a serial interrupt has to be served before its buffer overruns so it cares
14552 for the maximum interrupt latency, whereas it does not care about jitter.
14553 On a loudspeaker driven via a digital to analog converter which is fed
14554 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14555 a much smaller jitter will be very audible.
14558 \begin_layout Standard
14559 You can reenable interrupts within an interrupt routine and on some architecture
14560 s you can make use of two (or more) levels of
14562 interrupt priorities
14565 \begin_inset LatexCommand \index{interrupt priority}
14570 On some architectures which don't support interrupt priorities these can
14571 be implemented by manipulating the interrupt mask and reenabling interrupts
14572 within the interrupt routine.
14573 Check there is sufficient space on the stack
14574 \begin_inset LatexCommand \index{stack}
14578 and don't add complexity unless you have to.
14582 \begin_layout Subsection
14584 \begin_inset LatexCommand \index{semaphore}
14588 locking (mcs51/ds390)
14591 \begin_layout Standard
14592 Some architectures (mcs51/ds390) have an atomic
14593 \begin_inset LatexCommand \index{atomic}
14606 These type of instructions are typically used in preemptive multitasking
14607 systems, where a routine f.e.
14608 claims the use of a data structure ('acquires a lock
14609 \begin_inset LatexCommand \index{lock}
14613 on it'), makes some modifications and then releases the lock when the data
14614 structure is consistent again.
14615 The instruction may also be used if interrupt and non-interrupt code have
14616 to compete for a resource.
14617 With the atomic bit test and clear instruction interrupts
14618 \begin_inset LatexCommand \index{interrupt}
14622 don't have to be disabled for the locking operation.
14626 \begin_layout Standard
14627 SDCC generates this instruction if the source follows this pattern:
14630 \begin_layout Verse
14634 \begin_inset LatexCommand \index{volatile}
14638 bit resource_is_free;
14642 if (resource_is_free)
14652 resource_is_free=0;
14665 resource_is_free=1;
14672 \begin_layout Standard
14673 Note, mcs51 and ds390 support only an atomic
14674 \begin_inset LatexCommand \index{atomic}
14682 instruction (as opposed to atomic bit test and
14687 \begin_layout Section
14688 Functions using private register banks
14689 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14696 \begin_layout Standard
14697 Some architectures have support for quickly changing register sets.
14698 SDCC supports this feature with the
14701 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14706 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14712 attribute (which tells the compiler to use a register bank
14713 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14717 other than the default bank zero).
14718 It should only be applied to
14721 \begin_inset LatexCommand \index{interrupt}
14727 functions (see footnote below).
14728 This will in most circumstances make the generated ISR code more efficient
14729 since it will not have to save registers on the stack.
14732 \begin_layout Standard
14737 attribute will have no effect on the generated code for a
14741 function (but may occasionally be useful anyway
14745 \begin_layout Standard
14746 possible exception: if a function is called ONLY from 'interrupt' functions
14747 using a particular bank, it can be declared with the same 'using' attribute
14748 as the calling 'interrupt' functions.
14749 For instance, if you have several ISRs using bank one, and all of them
14750 call memcpy(), it might make sense to create a specialized version of memcpy()
14751 'using 1', since this would prevent the ISR from having to save bank zero
14752 to the stack on entry and switch to bank zero before calling the function
14761 (pending: Note, nowadays the
14765 attribute has an effect on
14769 the generated code for a
14780 \begin_layout Standard
14785 function using a non-zero bank will assume that it can trash that register
14786 bank, and will not save it.
14787 Since high-priority interrupts
14788 \begin_inset LatexCommand \index{interrupts}
14793 \begin_inset LatexCommand \index{interrupt priority}
14797 can interrupt low-priority ones on the 8051 and friends, this means that
14798 if a high-priority ISR
14802 a particular bank occurs while processing a low-priority ISR
14806 the same bank, terrible and bad things can happen.
14807 To prevent this, no single register bank should be
14811 by both a high priority and a low priority ISR.
14812 This is probably most easily done by having all high priority ISRs use
14813 one bank and all low priority ISRs use another.
14814 If you have an ISR which can change priority at runtime, you're on your
14815 own: I suggest using the default bank zero and taking the small performance
14819 \begin_layout Standard
14820 It is most efficient if your ISR calls no other functions.
14821 If your ISR must call other functions, it is most efficient if those functions
14822 use the same bank as the ISR (see note 1 below); the next best is if the
14823 called functions use bank zero.
14824 It is very inefficient to call a function using a different, non-zero bank
14827 \begin_inset VSpace bigskip
14833 \begin_layout Section
14835 \begin_inset LatexCommand \label{sub:Startup-Code}
14840 \begin_inset LatexCommand \index{Startup code}
14847 \begin_layout Subsection
14848 MCS51/DS390 Startup Code
14851 \begin_layout Standard
14852 The compiler triggers the linker to link certain initialization modules
14853 from the runtime library
14854 \begin_inset LatexCommand \index{Runtime library}
14858 called crt<something>.
14859 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14860 GSINIT5) is not linked unless the --xstack option is used.
14861 These modules are highly entangled by the use of special segments/areas,
14862 but a common layout is shown below:
14865 \begin_layout Verse
14873 \begin_layout Verse
14897 ljmp __sdcc_gsinit_startup
14900 \begin_layout Verse
14908 \begin_layout Verse
14920 .area GSINIT0 (CODE)
14922 __sdcc_gsinit_startup::
14932 mov sp,#__start__stack - 1
14935 \begin_layout Verse
14943 \begin_layout Verse
14955 .area GSINIT1 (CODE)
14957 __sdcc_init_xstack::
14959 ; Need to initialize in GSINIT1 in
14960 case the user's __sdcc_external_startup uses the xstack.
14970 mov __XPAGE,#(__start__x
14981 mov _spx,#__start__xstack
14984 \begin_layout Verse
14992 \begin_layout Verse
15004 .area GSINIT2 (CODE)
15014 lcall __sdcc_external_startup
15034 jz __sdcc_init_data
15045 __sdcc_program_startup
15050 \begin_layout Verse
15058 \begin_layout Verse
15070 .area GSINIT3 (CODE)
15123 mov r2,#((l_XINIT+255) >> 8)
15154 __XPAGE,#(s_XISEG >> 8)
15156 00001$:\InsetSpace ~
15220 00002$:\InsetSpace ~
15247 \begin_layout Verse
15255 \begin_layout Verse
15267 .area GSINIT4 (CODE)
15269 __mcs51_genRAMCLEAR::
15291 00004$:\InsetSpace ~
15305 ; _mcs51_genRAMCLEAR() end
15308 \begin_layout Verse
15316 \begin_layout Verse
15328 .area GSINIT4 (CODE)
15330 __mcs51_genXRAMCLEAR::
15381 mov __XPAGE,#(s_PSEG >> 8)
15393 00005$:\InsetSpace ~
15447 orl a,#(l_XSEG >> 8)
15490 00007$:\InsetSpace ~
15527 \begin_layout Verse
15535 \begin_layout Verse
15547 .area GSINIT5 (CODE)
15549 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15552 ; and __mcs51_genRAMCLEAR modifies _spx.
15562 mov __XPAGE,#(__start__x
15573 mov _spx,#__start__xstack
15576 \begin_layout Verse
15581 (application modules)
15584 \begin_layout Verse
15596 .area GSINIT (CODE)
15599 \begin_layout Verse
15607 \begin_layout Verse
15619 .area GSFINAL (CODE)
15629 ljmp __sdcc_program_startup
15631 ;---------------------------------
15632 -----------------------
15636 ;--------------------------------------------------
15659 __sdcc_program_startup:
15672 return from main will lock up
15685 \begin_layout Standard
15686 One of these modules (crtstart.asm) contains a call to the C routine
15688 _sdcc_external_startup()
15689 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15698 at the start of the CODE area.
15699 This routine is also in the runtime library
15700 \begin_inset LatexCommand \index{Runtime library}
15704 and returns 0 by default.
15705 If this routine returns a non-zero value, the static & global variable
15706 initialization will be skipped and the function main will be invoked.
15707 Otherwise static & global variables will be initialized before the function
15711 _sdcc_external_startup()
15713 routine to your program to override the default if you need to setup hardware
15714 or perform some other critical operation prior to static & global variable
15716 \begin_inset LatexCommand \index{Variable initialization}
15721 On some mcs51 variants xdata
15722 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15726 memory has to be explicitly enabled before it can be accessed or if the
15728 \begin_inset LatexCommand \index{watchdog}
15732 needs to be disabled, this is the place to do it.
15733 The startup code clears all internal data memory, 256 bytes by default,
15734 but from 0 to n-1 if
15740 \begin_layout Standard
15750 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15757 (recommended for Chipcon CC1010).
15760 \begin_layout Standard
15761 See also the compiler options
15767 \begin_layout Standard
15783 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15793 \begin_layout Standard
15805 \begin_inset LatexCommand \index{-\/-main-return}
15810 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15814 about MCS51-variants.
15815 \begin_inset VSpace bigskip
15821 \begin_layout Subsection
15825 \begin_layout Standard
15827 \begin_inset LatexCommand \index{HC08}
15831 startup code follows the same scheme as the MCS51 startup code.
15832 \begin_inset VSpace bigskip
15838 \begin_layout Subsection
15842 \begin_layout Standard
15844 \begin_inset LatexCommand \index{Z80}
15848 the startup code is inserted by linking with crt0.o which is generated from
15849 sdcc/device/lib/z80/crt0.s.
15850 If you need a different startup code you can use the compiler option
15859 \begin_layout Standard
15874 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15878 and provide your own crt0.o.
15880 \begin_inset VSpace bigskip
15886 \begin_layout Section
15887 Inline Assembler Code
15888 \begin_inset LatexCommand \index{Assembler routines}
15895 \begin_layout Subsection
15896 A Step by Step Introduction
15897 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15904 \begin_layout Standard
15905 Starting from a small snippet of c-code this example shows for the MCS51
15906 how to use inline assembly, access variables, a function parameter and
15907 an array in xdata memory.
15908 The example uses an MCS51 here but is easily adapted for other architectures.
15909 This is a buffer routine which should be optimized:
15912 \begin_layout Verse
15916 unsigned char __far
15917 \begin_inset LatexCommand \index{far (storage class)}
15922 \begin_inset LatexCommand \index{\_\_far (storage class)}
15927 \begin_inset LatexCommand \index{at}
15932 \begin_inset LatexCommand \index{\_\_at}
15936 (0x7f00) buf[0x100];
15937 \begin_inset LatexCommand \index{Aligned array}
15943 unsigned char head, tail;\InsetSpace ~
15961 \begin_inset LatexCommand \index{interrupt}
16013 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16025 void to_buffer( unsigned char c )
16033 if( head != (unsigned char)(tail-1)
16040 \begin_inset LatexCommand \index{promotion to signed int}
16045 \begin_inset LatexCommand \index{type promotion}
16050 \begin_inset Marginal
16053 \begin_layout Standard
16072 buf[ head++ ] = c;\InsetSpace ~
16088 /* access to a 256 byte aligned array */
16093 \begin_layout Standard
16094 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16095 then a corresponding buffer.asm file is generated.
16096 We define a new function
16100 in file buffer.c in which we cut and paste the generated code, removing
16101 unwanted comments and some ':'.
16103 \begin_inset Quotes sld
16111 \begin_inset Quotes srd
16115 \begin_inset Quotes sld
16123 \begin_inset Quotes srd
16130 \begin_layout Standard
16131 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16132 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16134 The latter is also used in the library functions.
16139 to the beginning and the end of the function body:
16142 \begin_layout Verse
16146 /* With a cut and paste from the .asm file, we have something to start with.
16152 function is not yet OK! (registers aren't saved) */
16154 void to_buffer_asm(
16164 \begin_inset LatexCommand \index{\_asm}
16169 \begin_inset LatexCommand \index{\_\_asm}
16183 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16189 \begin_inset LatexCommand \index{promotion to signed int}
16194 \begin_inset LatexCommand \index{type promotion}
16247 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16248 \begin_inset LatexCommand \index{Aligned array}
16314 \begin_inset LatexCommand \index{\_endasm}
16319 \begin_inset LatexCommand \index{\_\_endasm}
16328 \begin_layout Standard
16329 The new file buffer.c should compile with only one warning about the unreferenced
16330 function argument 'c'.
16331 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16332 (1) and finally have:
16335 \begin_layout Verse
16339 unsigned char __far __at(0x7f00) buf[0x100];
16341 unsigned char head, tail;
16352 void to_buffer( unsigned char c )
16361 head != (unsigned char)(tail-1) )
16390 c; // to avoid warning: unreferenced function argument
16397 \begin_inset LatexCommand \index{\_asm}
16402 \begin_inset LatexCommand \index{\_\_asm}
16416 ; save used registers here.
16427 ; If we were still using r2,r3 we would have to push them here.
16430 ; if( head != (unsigned char)(tail-1) )
16474 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16510 a,dpl \InsetSpace ~
16517 ; dpl holds lower byte of function argument
16529 dpl,_head \InsetSpace ~
16532 ; buf is 0x100 byte aligned so head can be used directly
16575 ; we could do an ANL _head,#0x0f here to use a
16576 smaller buffer (see above)
16588 ; restore used registers here
16595 \begin_inset LatexCommand \index{\_endasm}
16600 \begin_inset LatexCommand \index{\_\_endasm}
16611 \begin_layout Standard
16612 The inline assembler code can contain any valid code understood by the assembler
16613 , this includes any assembler directives and comment lines.
16614 The assembler does not like some characters like ':' or ''' in comments.
16615 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16616 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16621 \begin_inset LatexCommand \index{Assembler documentation}
16626 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16634 \begin_layout Standard
16635 The compiler does not do any validation of the code within the
16638 \begin_inset LatexCommand \index{\_asm}
16643 \begin_inset LatexCommand \index{\_\_asm}
16651 \begin_inset LatexCommand \index{\_endasm}
16656 \begin_inset LatexCommand \index{\_\_endasm}
16665 Specifically it will not know which registers are used and thus register
16667 \begin_inset LatexCommand \index{push/pop}
16671 has to be done manually.
16675 \begin_layout Standard
16676 It is recommended that each assembly instruction (including labels) be placed
16677 in a separate line (as the example shows).
16682 \begin_layout Standard
16694 \begin_inset LatexCommand \index{-\/-peep-asm}
16700 command line option is used, the inline assembler code will be passed through
16701 the peephole optimizer
16702 \begin_inset LatexCommand \index{Peephole optimizer}
16707 There are only a few (if any) cases where this option makes sense, it might
16708 cause some unexpected changes in the inline assembler code.
16709 Please go through the peephole optimizer rules defined in file
16713 before using this option.
16716 \begin_layout Subsection
16718 \begin_inset LatexCommand \label{sub:Naked-Functions}
16723 \begin_inset LatexCommand \index{Naked functions}
16730 \begin_layout Standard
16731 A special keyword may be associated with a function declaring it as
16734 \begin_inset LatexCommand \index{\_naked}
16739 \begin_inset LatexCommand \index{\_\_naked}
16750 function modifier attribute prevents the compiler from generating prologue
16751 \begin_inset LatexCommand \index{function prologue}
16756 \begin_inset LatexCommand \index{function epilogue}
16760 code for that function.
16761 This means that the user is entirely responsible for such things as saving
16762 any registers that may need to be preserved, selecting the proper register
16763 bank, generating the
16767 instruction at the end, etc.
16768 Practically, this means that the contents of the function must be written
16769 in inline assembler.
16770 This is particularly useful for interrupt functions, which can have a large
16771 (and often unnecessary) prologue/epilogue.
16772 For example, compare the code generated by these two functions:
16775 \begin_layout Verse
16779 \begin_inset LatexCommand \index{volatile}
16783 data unsigned char counter;
16787 void simpleInterrupt(void) __interrupt
16788 \begin_inset LatexCommand \index{interrupt}
16793 \begin_inset LatexCommand \index{\_\_interrupt}
16811 void nakedInterrupt(void) __interrupt (2) __naked
16820 \begin_inset LatexCommand \index{\_asm}
16825 \begin_inset LatexCommand \index{\_\_asm}
16842 _counter ; does not change flags, no need to save psw
16855 include ret or reti in _naked function.
16862 \begin_inset LatexCommand \index{\_endasm}
16867 \begin_inset LatexCommand \index{\_\_endasm}
16876 \begin_layout Standard
16877 For an 8051 target, the generated simpleInterrupt looks like:
16880 \begin_layout Verse
16887 example, recent versions of SDCC generate
16893 code for simpleInterrupt() and nakedInterrupt()!
17034 \begin_layout Standard
17035 whereas nakedInterrupt looks like:
17038 \begin_layout Verse
17051 _counter ; does not change flags, no need to save psw
17070 MUST explicitly include ret or reti in _naked function
17073 \begin_layout Standard
17074 The related directive #pragma exclude
17075 \begin_inset LatexCommand \index{\#pragma exclude}
17079 allows a more fine grained control over pushing & popping
17080 \begin_inset LatexCommand \index{push/pop}
17087 \begin_layout Standard
17088 While there is nothing preventing you from writing C code inside a
17092 function, there are many ways to shoot yourself in the foot doing this,
17093 and it is recommended that you stick to inline assembler.
17096 \begin_layout Subsection
17097 Use of Labels within Inline Assembler
17100 \begin_layout Standard
17101 SDCC allows the use of in-line assembler with a few restrictions regarding
17103 In older versions of the compiler all labels defined within inline assembler
17104 code had to be of the form
17108 where nnnnn is a number less than 100 (which implies a limit of utmost
17109 100 inline assembler labels
17120 \begin_layout Verse
17124 \begin_inset LatexCommand \index{\_asm}
17129 \begin_inset LatexCommand \index{\_\_asm}
17159 \begin_inset LatexCommand \index{\_endasm}
17164 \begin_inset LatexCommand \index{\_\_endasm}
17171 \begin_layout Standard
17172 Inline assembler code cannot reference any C-labels, however it can reference
17174 \begin_inset LatexCommand \index{Labels}
17178 defined by the inline assembler, e.g.:
17181 \begin_layout Verse
17204 ; some assembler code
17225 /* some more c code */
17227 clabel:\InsetSpace ~
17229 /* inline assembler cannot reference this
17242 $0003: ;label (can be referenced by inline assembler only)
17250 \begin_inset LatexCommand \index{\_endasm}
17255 \begin_inset LatexCommand \index{\_\_endasm}
17265 /* some more c code */
17270 \begin_layout Standard
17271 In other words inline assembly code can access labels defined in inline
17272 assembly within the scope of the function.
17273 The same goes the other way, i.e.
17274 labels defines in inline assembly can not be accessed by C statements.
17277 \begin_layout Section
17278 Interfacing with Assembler Code
17279 \begin_inset LatexCommand \index{Assembler routines}
17286 \begin_layout Subsection
17287 Global Registers used for Parameter Passing
17288 \begin_inset LatexCommand \index{Parameter passing}
17295 \begin_layout Standard
17296 The compiler always uses the global registers
17299 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17304 \begin_inset LatexCommand \index{DPTR}
17309 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17318 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17324 to pass the first parameter to a function, and also to pass the return
17326 \begin_inset LatexCommand \index{return value}
17330 of function; according to the following scheme: one byte return value in
17335 , two byte value in
17344 three byte values (generic pointers) in
17356 , and four byte values in
17374 \begin_inset LatexCommand \index{generic pointer}
17378 contain type of accessed memory in
17399 \begin_inset Note Note
17402 \begin_layout Standard
17403 This might not be the case of certain memory models (medium???)
17411 \begin_layout Standard
17412 The second parameter onwards is either allocated on the stack (for reentrant
17417 \begin_layout Standard
17426 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17430 \begin_layout Subsection
17434 \begin_layout Standard
17435 Unless the called function is declared as
17440 \begin_inset LatexCommand \index{naked}
17448 \begin_layout Standard
17458 \begin_inset LatexCommand \index{-\/-callee-saves}
17466 \begin_layout Standard
17475 -all-callee-saves command line option or the corresponding callee_saves
17476 pragma are used, the caller will save the registers (
17480 ) around the call, so the called function can destroy they content freely.
17483 \begin_layout Standard
17484 If the called function is not declared as
17488 , the caller will swap register banks around the call, if caller and callee
17489 use different register banks (having them defined by the
17497 \begin_layout Standard
17498 The called function can also use
17514 observing that they are used for parameter/return value passing.
17517 \begin_layout Subsection
17518 Assembler Routine (non-reentrant)
17521 \begin_layout Standard
17522 In the following example
17523 \begin_inset LatexCommand \index{reentrant}
17528 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17532 the function c_func calls an assembler routine asm_func, which takes two
17534 \begin_inset LatexCommand \index{function parameter}
17541 \begin_layout Verse
17544 extern int asm_func(unsigned char, unsigned char);
17548 int c_func (unsigned char
17549 i, unsigned char j)
17557 return asm_func(i,j);
17571 return c_func(10,9);
17576 \begin_layout Standard
17577 The corresponding assembler function is:
17580 \begin_layout Verse
17583 .globl _asm_func_PARM_2
17685 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17702 \begin_layout Standard
17703 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17704 the parameter number starting from 1, and counting from the left.
17705 The first parameter is passed in
17721 according to the description above.
17722 The variable name for the second parameter will be _<function_name>_PARM_2.
17727 ble the assembler routine with the following command:
17734 asx8051 -losg asmfunc.asm
17741 Then compile and link the assembler routine to the C source file with the
17749 sdcc cfunc.c asmfunc.rel
17752 \begin_layout Subsection
17753 Assembler Routine (reentrant)
17756 \begin_layout Standard
17758 \begin_inset LatexCommand \index{reentrant}
17763 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17767 the second parameter
17768 \begin_inset LatexCommand \index{function parameter}
17772 onwards will be passed on the stack, the parameters are pushed from right
17774 before the call the second leftmost parameter will be on the top of the
17775 stack (the leftmost parameter is passed in registers).
17776 Here is an example:
17779 \begin_layout Verse
17782 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17787 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
17796 return asm_func(i,j,k);
17810 return c_func(10,9,8);
17815 \begin_layout Standard
17816 The corresponding (unoptimized) assembler routine is:
17819 \begin_layout Verse
17839 _bp,sp\InsetSpace ~
17845 ;stack contains: _bp, return
17846 address, second parameter, third parameter
17870 a,#0xfd\InsetSpace ~
17876 pointer to the second parameter
17900 a,#0xfc\InsetSpace ~
17906 to the rightmost parameter
17947 result (= sum of all three parameters)
17962 ;return value goes into dptr
17996 \begin_layout Standard
17997 The compiling and linking procedure remains the same, however note the extra
17998 entry & exit linkage required for the assembler code, _bp is the stack
17999 frame pointer and is used to compute the offset into the stack for parameters
18000 and local variables.
18001 \begin_inset VSpace bigskip
18007 \begin_layout Section
18009 \begin_inset LatexCommand \index{int (16 bit)}
18014 \begin_inset LatexCommand \index{long (32 bit)}
18021 \begin_layout Standard
18022 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18023 multiplication and modulus operations are implemented by support routines.
18024 These support routines are all developed in ANSI-C to facilitate porting
18025 to other MCUs, although some model specific assembler optimizations are
18027 The following files contain the described routines, all of them can be
18028 found in <installdir>/share/sdcc/lib.
18033 \begin_layout Standard
18035 \begin_inset Tabular
18036 <lyxtabular version="3" rows="11" columns="2">
18038 <column alignment="left" valignment="top" leftline="true" width="0">
18039 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18040 <row topline="true" bottomline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18044 \begin_layout Standard
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18055 \begin_layout Standard
18064 <row topline="true">
18065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18068 \begin_layout Standard
18074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18077 \begin_layout Standard
18078 16 bit multiplication
18084 <row topline="true">
18085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18088 \begin_layout Standard
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18097 \begin_layout Standard
18098 signed 16 bit division (calls _divuint)
18104 <row topline="true">
18105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18108 \begin_layout Standard
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18117 \begin_layout Standard
18118 unsigned 16 bit division
18124 <row topline="true">
18125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18128 \begin_layout Standard
18134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18137 \begin_layout Standard
18138 signed 16 bit modulus (calls _moduint)
18144 <row topline="true">
18145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18148 \begin_layout Standard
18154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18157 \begin_layout Standard
18158 unsigned 16 bit modulus
18164 <row topline="true">
18165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18168 \begin_layout Standard
18174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18177 \begin_layout Standard
18178 32 bit multiplication
18184 <row topline="true">
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18188 \begin_layout Standard
18194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18197 \begin_layout Standard
18198 signed 32 division (calls _divulong)
18204 <row topline="true">
18205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18208 \begin_layout Standard
18214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18217 \begin_layout Standard
18218 unsigned 32 division
18224 <row topline="true">
18225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18228 \begin_layout Standard
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18237 \begin_layout Standard
18238 signed 32 bit modulus (calls _modulong)
18244 <row topline="true" bottomline="true">
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18248 \begin_layout Standard
18254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18257 \begin_layout Standard
18258 unsigned 32 bit modulus
18273 \begin_layout Standard
18274 Since they are compiled as
18279 \begin_inset LatexCommand \index{reentrant}
18284 \begin_inset LatexCommand \index{interrupt}
18288 service routines should not do any of the above operations.
18289 If this is unavoidable then the above routines will need to be compiled
18296 \begin_layout Standard
18306 \begin_inset LatexCommand \index{-\/-stack-auto}
18312 option, after which the source program will have to be compiled with
18318 \begin_layout Standard
18328 \begin_inset LatexCommand \index{-\/-int-long-reent}
18335 Notice that you don't have to call these routines directly.
18336 The compiler will use them automatically every time an integer operation
18340 \begin_layout Section
18341 Floating Point Support
18342 \begin_inset LatexCommand \index{Floating point support}
18349 \begin_layout Standard
18350 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18351 The floating point support routines are derived from gcc's floatlib.c and
18352 consist of the following routines:
18357 \begin_layout Standard
18361 \begin_inset Tabular
18362 <lyxtabular version="3" rows="17" columns="2">
18364 <column alignment="left" valignment="top" leftline="true" width="0">
18365 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18366 <row topline="true" bottomline="true">
18367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18370 \begin_layout Standard
18385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18388 \begin_layout Standard
18395 <row topline="true">
18396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18399 \begin_layout Standard
18414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18417 \begin_layout Standard
18427 add floating point numbers
18433 <row topline="true">
18434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18437 \begin_layout Standard
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18455 \begin_layout Standard
18465 subtract floating point numbers
18471 <row topline="true">
18472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18475 \begin_layout Standard
18490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18493 \begin_layout Standard
18503 divide floating point numbers
18509 <row topline="true">
18510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18513 \begin_layout Standard
18528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18531 \begin_layout Standard
18541 multiply floating point numbers
18547 <row topline="true">
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18551 \begin_layout Standard
18566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18569 \begin_layout Standard
18579 convert floating point to unsigned char
18585 <row topline="true">
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18589 \begin_layout Standard
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18607 \begin_layout Standard
18617 convert floating point to signed char
18623 <row topline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 \begin_layout Standard
18642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18645 \begin_layout Standard
18655 convert floating point to unsigned int
18661 <row topline="true">
18662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18665 \begin_layout Standard
18680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18683 \begin_layout Standard
18693 convert floating point to signed int
18699 <row topline="true">
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18703 \begin_layout Standard
18726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18729 \begin_layout Standard
18739 convert floating point to unsigned long
18745 <row topline="true">
18746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18749 \begin_layout Standard
18764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18767 \begin_layout Standard
18777 convert floating point to signed long
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18787 \begin_layout Standard
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18805 \begin_layout Standard
18815 convert unsigned char to floating point
18821 <row topline="true">
18822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18825 \begin_layout Standard
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18843 \begin_layout Standard
18853 convert char to floating point number
18859 <row topline="true">
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18863 \begin_layout Standard
18878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18881 \begin_layout Standard
18891 convert unsigned int to floating point
18897 <row topline="true">
18898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18901 \begin_layout Standard
18916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18919 \begin_layout Standard
18929 convert int to floating point numbers
18935 <row topline="true">
18936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18939 \begin_layout Standard
18954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18957 \begin_layout Standard
18967 convert unsigned long to floating point number
18973 <row topline="true" bottomline="true">
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18977 \begin_layout Standard
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18995 \begin_layout Standard
19005 convert long to floating point number
19020 \begin_layout Standard
19021 These support routines are developed in ANSI-C so there is room for space
19022 and speed improvement
19026 \begin_layout Standard
19027 These floating point routines (
19031 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19038 Note if all these routines are used simultaneously the data space might
19040 For serious floating point usage the large model might be needed.
19041 Also notice that you don't have to call this routines directly.
19042 The compiler will use them automatically every time a floating point operation
19044 \begin_inset VSpace bigskip
19050 \begin_layout Section
19052 \begin_inset LatexCommand \index{Libraries}
19059 \begin_layout Standard
19062 <pending: this is messy and incomplete - a little more information is in
19063 sdcc/doc/libdoc.txt
19068 \begin_layout Subsection
19069 Compiler support routines (_gptrget, _mulint etc.)
19072 \begin_layout Subsection
19073 Stdclib functions (puts, printf, strcat etc.)
19076 \begin_layout Subsubsection
19080 \begin_layout Paragraph
19081 getchar(), putchar()
19084 \begin_layout Standard
19085 \begin_inset LatexCommand \index{<stdio.h>}
19089 As usual on embedded systems you have to provide your own
19092 \begin_inset LatexCommand \index{getchar()}
19101 \begin_inset LatexCommand \index{putchar()}
19108 SDCC does not know whether the system connects to a serial line with or
19109 without handshake, LCD, keyboard or other device.
19123 You'll find examples for serial routines f.e.
19124 in sdcc/device/lib.
19125 For the mcs51 this minimalistic polling
19129 routine might be a start:
19132 \begin_layout Verse
19135 void putchar (char c) {
19141 while (!TI)\InsetSpace ~
19144 /* assumes UART is initialized */
19172 \begin_layout Paragraph
19176 \begin_layout Standard
19180 \begin_inset LatexCommand \index{printf()}
19190 does not support float (except on ds390).
19191 To enable this recompile it with the option
19197 \begin_layout Standard
19207 \begin_inset LatexCommand \index{USE\_FLOATS}
19213 on the command line.
19220 \begin_layout Standard
19230 \begin_inset LatexCommand \index{-\/-model-large}
19236 for the mcs51 port, since this uses a lot of memory.
19239 \begin_layout Standard
19240 If you're short on code memory you might want to use
19243 \begin_inset LatexCommand \index{printf\_small()}
19258 For the mcs51 there additionally are assembly versions
19261 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19267 (subset of printf using less than 270 bytes) and
19270 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19279 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19285 (floating-point aware version of printf_fast) which should fit the requirements
19286 of many embedded systems (printf_fast() can be customized by unsetting
19291 support long variables and field widths).
19292 Be sure to use only one of these printf options within a project.
19297 \begin_layout Standard
19298 Feature matrix of different
19305 \begin_layout Standard
19306 \begin_inset Tabular
19307 <lyxtabular version="3" rows="14" columns="7">
19308 <features islongtable="true">
19309 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19310 <column alignment="center" valignment="top" leftline="true" width="0">
19311 <column alignment="center" valignment="top" leftline="true" width="12col%">
19312 <column alignment="center" valignment="top" leftline="true" width="10col%">
19313 <column alignment="center" valignment="top" leftline="true" width="0">
19314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19315 <column alignment="center" valignment="top" rightline="true" width="0">
19316 <row topline="true" bottomline="true" endhead="true">
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19320 \begin_layout Standard
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19332 \begin_layout Standard
19334 \begin_inset LatexCommand \index{printf}
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19346 \begin_layout Standard
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19357 \begin_layout Standard
19363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19366 \begin_layout Standard
19372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19375 \begin_layout Standard
19381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19384 \begin_layout Standard
19391 <row topline="true" endhead="true">
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19395 \begin_layout Standard
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19404 \begin_layout Standard
19412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19415 \begin_layout Standard
19423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19426 \begin_layout Standard
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19437 \begin_layout Standard
19445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19448 \begin_layout Standard
19456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19459 \begin_layout Standard
19468 <row topline="true" endhead="true">
19469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19472 \begin_layout Standard
19473 \begin_inset Quotes sld
19477 \begin_inset Quotes srd
19483 \begin_layout Standard
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19492 \begin_layout Standard
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 \begin_layout Standard
19507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19510 \begin_layout Standard
19516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_layout Standard
19525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19528 \begin_layout Standard
19534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_layout Standard
19544 <row topline="true" endhead="true">
19545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19548 \begin_layout Standard
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" usebox="none">
19579 \begin_layout Standard
19580 0.45k / 0.47k (+ _ltoa)
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19588 \begin_layout Standard
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19597 \begin_layout Standard
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19606 \begin_layout Standard
19613 <row topline="true">
19614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19617 \begin_layout Standard
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19626 \begin_layout Standard
19636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19639 \begin_layout Standard
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19689 \begin_layout Standard
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19731 \begin_layout Standard
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19740 \begin_layout Standard
19746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19749 \begin_layout Standard
19756 <row topline="true">
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19760 \begin_layout Standard
19761 long (32 bit) support
19766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19769 \begin_layout Standard
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19778 \begin_layout Standard
19784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
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" rightline="true" usebox="none">
19805 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_layout Standard
19830 <row topline="true">
19831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 \begin_layout Standard
19835 byte arguments on stack
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19843 \begin_layout Standard
19849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 \begin_layout Standard
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19861 \begin_layout Standard
19867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19870 \begin_layout Standard
19876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19879 \begin_layout Standard
19885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19888 \begin_layout Standard
19895 <row topline="true">
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19899 \begin_layout Standard
19901 \begin_inset LatexCommand \index{Floating point support}
19910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19913 \begin_layout Standard
19919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19922 \begin_layout Standard
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_layout Standard
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_layout Standard
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19949 \begin_layout Standard
19954 \begin_layout Standard
19955 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19968 \begin_layout Standard
19975 <row topline="true">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_layout Standard
19980 float formats %e %g
19985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19988 \begin_layout Standard
19994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19997 \begin_layout Standard
20003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20006 \begin_layout Standard
20012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_layout Standard
20021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20024 \begin_layout Standard
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20033 \begin_layout Standard
20040 <row topline="true" bottomline="true">
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20044 \begin_layout Standard
20050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20053 \begin_layout Standard
20059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20062 \begin_layout Standard
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20071 \begin_layout Standard
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20080 \begin_layout Standard
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20098 \begin_layout Standard
20105 <row bottomline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_layout Standard
20114 \begin_layout Standard
20115 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20119 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20127 \begin_layout Standard
20133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20136 \begin_layout Standard
20142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20145 \begin_layout Standard
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20154 \begin_layout Standard
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20163 \begin_layout Standard
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20172 \begin_layout Standard
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20181 \begin_layout Standard
20188 <row bottomline="true">
20189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20192 \begin_layout Standard
20197 \begin_layout Standard
20198 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20207 \begin_layout Standard
20213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20216 \begin_layout Standard
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20225 \begin_layout Standard
20231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20234 \begin_layout Standard
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20243 \begin_layout Standard
20249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20252 \begin_layout Standard
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20261 \begin_layout Standard
20266 \begin_layout Standard
20267 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20278 <row bottomline="true">
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20282 \begin_layout Standard
20287 \begin_layout Standard
20288 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20297 \begin_layout Standard
20303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20306 \begin_layout Standard
20312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20315 \begin_layout Standard
20321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20324 \begin_layout Standard
20330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20333 \begin_layout Standard
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20342 \begin_layout Standard
20348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20351 \begin_layout Standard
20358 <row bottomline="true">
20359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20362 \begin_layout Standard
20367 \begin_layout Standard
20368 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20377 \begin_layout Standard
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20386 \begin_layout Standard
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_layout Standard
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20404 \begin_layout Standard
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20413 \begin_layout Standard
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20422 \begin_layout Standard
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20431 \begin_layout Standard
20445 \begin_layout Subsubsection
20447 \begin_inset LatexCommand \index{malloc.h}
20454 \begin_layout Standard
20455 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20456 using dynamic memory allocation
20457 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20462 \begin_inset LatexCommand \index{heap (malloc)}
20466 space of 1024 bytes is provided for malloc to allocate memory from.
20467 If you need a different heap size you need to recompile _heap.c with the
20468 required size defined in HEAP_SIZE.
20469 It is recommended to make a copy of this file into your project directory
20470 and compile it there with:
20473 \begin_layout Verse
20476 sdcc -c _heap.c -D HEAD_SIZE=2048
20479 \begin_layout Standard
20480 And then link it with:
20483 \begin_layout Verse
20486 sdcc main.rel _heap.rel
20489 \begin_layout Subsection
20490 Math functions (sinf, powf, sqrtf etc.)
20493 \begin_layout Subsubsection
20497 \begin_layout Standard
20498 See definitions in file <math.h>.
20501 \begin_layout Subsection
20505 \begin_layout Standard
20507 \begin_inset LatexCommand \index{Libraries}
20511 included in SDCC should have a license at least as liberal as the GNU Lesser
20512 General Public License
20513 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20524 \begin_layout Standard
20525 \begin_inset Note Note
20528 \begin_layout Standard
20529 license statements for the libraries are missing.
20530 sdcc/device/lib/ser_ir.c
20533 \begin_layout Standard
20535 come with a GPL (as opposed to LGPL) License - this will not be liberal
20536 enough for many embedded programmers.
20544 \begin_layout Standard
20545 If you have ported some library or want to share experience about some code
20547 falls into any of these categories Busses (I
20548 \begin_inset Formula $^{\textrm{2}}$
20551 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20552 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20553 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20554 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20559 would certainly like to hear about it.
20562 \begin_layout Standard
20563 Programmers coding for embedded systems are not especially famous for being
20564 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20565 e these references are very valuable.
20566 Let's help to create a climate where information is shared.
20567 \begin_inset VSpace bigskip
20573 \begin_layout Section
20577 \begin_layout Subsection
20578 MCS51 Memory Models
20579 \begin_inset LatexCommand \index{Memory model}
20584 \begin_inset LatexCommand \index{MCS51 memory model}
20591 \begin_layout Subsubsection
20592 Small, Medium and Large
20595 \begin_layout Standard
20596 SDCC allows three memory models for MCS51 code,
20605 Modules compiled with different memory models should
20609 be combined together or the results would be unpredictable.
20610 The library routines supplied with the compiler are compiled as small,
20612 The compiled library modules are contained in separate directories as small,
20613 medium and large so that you can link to the appropriate set.
20616 \begin_layout Standard
20617 When the medium or large model is used all variables declared without a
20618 storage class will be allocated into the external ram, this includes all
20619 parameters and local variables (for non-reentrant
20620 \begin_inset LatexCommand \index{reentrant}
20625 When the small model is used variables without storage class are allocated
20626 in the internal ram.
20629 \begin_layout Standard
20630 Judicious usage of the processor specific storage classes
20631 \begin_inset LatexCommand \index{Storage class}
20635 and the 'reentrant' function type will yield much more efficient code,
20636 than using the large model.
20637 Several optimizations are disabled when the program is compiled using the
20638 large model, it is therefore recommended that the small model be used unless
20639 absolutely required.
20642 \begin_layout Subsubsection
20644 \begin_inset LatexCommand \label{sub:External-Stack}
20649 \begin_inset LatexCommand \index{stack}
20654 \begin_inset LatexCommand \index{External stack (mcs51)}
20661 \begin_layout Standard
20662 The external stack (-
20666 \begin_layout Standard
20676 \begin_inset LatexCommand \index{-\/-xstack}
20680 ) is located in pdata
20681 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20685 memory (usually at the start of the external ram segment) and uses all
20686 unused space in pdata (max.
20692 \begin_layout Standard
20701 -xstack option is used to compile the program, the parameters and local
20703 \begin_inset LatexCommand \index{local variables}
20707 of all reentrant functions are allocated in this area.
20708 This option is provided for programs with large stack space requirements.
20709 When used with the -
20713 \begin_layout Standard
20723 \begin_inset LatexCommand \index{-\/-stack-auto}
20727 option, all parameters and local variables are allocated on the external
20728 stack (note: support libraries will need to be recompiled with the same
20730 There is a predefined target in the library makefile).
20733 \begin_layout Standard
20734 The compiler outputs the higher order address byte of the external ram segment
20736 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20741 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20745 ), therefore when using the External Stack option, this port
20749 be used by the application program.
20752 \begin_layout Subsection
20754 \begin_inset LatexCommand \index{Memory model}
20759 \begin_inset LatexCommand \index{DS390 memory model}
20766 \begin_layout Standard
20767 The only model supported is Flat 24
20768 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20773 This generates code for the 24 bit contiguous addressing mode of the Dallas
20775 In this mode, up to four meg of external RAM or code space can be directly
20777 See the data sheets at www.dalsemi.com for further information on this part.
20782 that the compiler does not generate any code to place the processor into
20783 24 bitmode (although
20787 in the ds390 libraries will do that for you).
20793 \begin_inset LatexCommand \index{Tinibios (DS390)}
20797 , the boot loader or similar code must ensure that the processor is in 24
20798 bit contiguous addressing mode before calling the SDCC startup code.
20809 \begin_layout Standard
20820 option, variables will by default be placed into the XDATA segment.
20825 Segments may be placed anywhere in the 4 meg address space using the usual
20830 \begin_layout Standard
20840 Note that if any segments are located above 64K, the -r flag must be passed
20841 to the linker to generate the proper segment relocations, and the Intel
20842 HEX output format must be used.
20843 The -r flag can be passed to the linker by using the option
20847 on the SDCC command line.
20848 However, currently the linker can not handle code segments > 64k.
20851 \begin_layout Section
20853 \begin_inset LatexCommand \label{sec:Pragmas}
20858 \begin_inset LatexCommand \index{Pragmas}
20865 \begin_layout Standard
20866 Pragmas are used to turn on and/or off certain compiler options.
20867 Some of them are closely related to corresponding command-line options
20869 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20875 Pragmas should be placed before and/or after a function, placing pragmas
20876 inside a function body could have unpredictable results.
20881 following #pragma directives:
20884 \begin_layout Itemize
20890 \begin_inset LatexCommand \index{\#pragma save}
20894 - this will save most current options to the save/restore stack.
20895 See #pragma\InsetSpace ~
20899 \begin_layout Itemize
20905 \begin_inset LatexCommand \index{\#pragma restore}
20909 - will restore saved options from the last save.
20910 saves & restores can be nested.
20911 SDCC uses a save/restore stack: save pushes current options to the stack,
20912 restore pulls current options from the stack.
20913 See #pragma\InsetSpace ~
20919 \begin_layout Itemize
20925 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20930 \begin_inset LatexCommand \index{function prologue}
20934 function1[,function2[,function3...]]
20935 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20939 - The compiler by default uses a caller saves convention for register saving
20940 across function calls, however this can cause unnecessary register pushing
20942 \begin_inset LatexCommand \index{push/pop}
20946 when calling small functions from larger functions.
20947 This option can be used to switch off the register saving convention for
20948 the function names specified.
20949 The compiler will not save registers when calling these functions, extra
20950 code need to be manually inserted at the entry and exit for these functions
20951 to save and restore the registers used by these functions, this can SUBSTANTIAL
20952 LY reduce code and improve run time performance of the generated code.
20953 In the future the compiler (with inter procedural analysis) may be able
20954 to determine the appropriate scheme to use for each function call.
20959 \begin_layout Standard
20968 -callee-saves command line option is used (see page
20969 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20973 ), the function names specified in #pragma\InsetSpace ~
20975 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20979 is appended to the list of functions specified in the command line.
20982 \begin_layout Itemize
20988 \begin_inset LatexCommand \index{\#pragma exclude}
20992 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20993 of pairs of push/pop
20994 \begin_inset LatexCommand \index{push/pop}
21003 \begin_inset LatexCommand \index{interrupt}
21016 The directive should be placed immediately before the ISR function definition
21017 and it affects ALL ISR functions following it.
21018 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21019 exclude\InsetSpace ~
21021 \begin_inset LatexCommand \index{\#pragma exclude}
21026 See also the related keyword _naked
21027 \begin_inset LatexCommand \index{\_naked}
21032 \begin_inset LatexCommand \index{\_\_naked}
21039 \begin_layout Itemize
21045 \begin_inset LatexCommand \index{pedantic}
21050 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21055 \begin_inset LatexCommand \label{ite:less_pedantic}
21059 - the compiler will not warn you anymore for obvious mistakes, you'r on
21061 See also the command line option -
21065 \begin_layout Standard
21075 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21082 More specifically, the following warnings will be disabled:
21084 comparison is always [true/false] due to limited range of data type
21088 overflow in implicit constant conversion
21090 (158); [the (in)famous]
21092 conditional flow changed by optimizer: so said EVELYN the modified DOG
21096 function '[function name]' must return value
21101 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21102 level) are disabled, too, namely:
21105 \begin_inset Note Note
21108 \begin_layout Standard
21109 dunno what comes here - this warning appears to be unused altogether
21118 [left/right] shifting more than size of object changed to zero
21126 integer overflow in expression
21130 unmatched #pragma save and #pragma restore
21134 comparison of 'signed char' with 'unsigned char' requires promotion to int
21138 ISO C90 does not support flexible array members
21142 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21146 \begin_inset Note Note
21149 \begin_layout Standard
21150 appears to be always blank - what was supposed to be here?
21159 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21160 complexity [number]
21165 \begin_layout Itemize
21171 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21175 - the compiler will not warn you anymore about warning number <nnnn>.
21178 \begin_layout Itemize
21184 \begin_inset LatexCommand \index{\#pragma nogcse}
21188 - will stop global common subexpression elimination.
21191 \begin_layout Itemize
21197 \begin_inset LatexCommand \index{\#pragma noinduction}
21201 - will stop loop induction optimizations.
21204 \begin_layout Itemize
21210 \begin_inset LatexCommand \index{\#pragma noinvariant}
21214 - will not do loop invariant optimizations.
21215 For more details see Loop Invariants in section
21216 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21223 \begin_layout Itemize
21229 \begin_inset LatexCommand \index{\#pragma noiv}
21233 - Do not generate interrupt
21234 \begin_inset LatexCommand \index{interrupt}
21239 \begin_inset LatexCommand \index{interrupt vector table}
21243 entries for all ISR functions defined after the pragma.
21244 This is useful in cases where the interrupt vector table must be defined
21245 manually, or when there is a secondary, manually defined interrupt vector
21247 for the autovector feature of the Cypress EZ-USB FX2).
21248 More elegantly this can be achieved by obmitting the optional interrupt
21249 number after the interrupt keyword, see section
21250 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21258 \begin_layout Itemize
21264 \begin_inset LatexCommand \index{\#pragma nojtbound}
21268 - will not generate code for boundary value checking, when switch statements
21269 are turned into jump-tables (dangerous).
21270 For more details see section
21271 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21278 \begin_layout Itemize
21284 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21288 - Will not do loop reversal optimization
21291 \begin_layout Itemize
21297 \begin_inset LatexCommand \index{\#pragma nooverlay}
21301 - the compiler will not overlay the parameters and local variables of a
21305 \begin_layout Itemize
21311 \begin_inset LatexCommand \index{\#pragma stackauto}
21319 \begin_layout Standard
21329 \begin_inset LatexCommand \index{-\/-stack-auto}
21334 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21338 Parameters and Local Variables.
21341 \begin_layout Itemize
21347 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21351 - The compiler will optimize code generation towards fast code, possibly
21352 at the expense of code size.
21353 Currently this has little effect.
21356 \begin_layout Itemize
21362 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21366 - The compiler will optimize code generation towards compact code, possibly
21367 at the expense of code speed.
21368 Currently this has little effect.
21371 \begin_layout Itemize
21377 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21381 - The compiler will attempt to generate code that is both compact and fast,
21382 as long as meeting one goal is not a detriment to the other (this is the
21387 \begin_layout Itemize
21393 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21397 - Generally follow the C89 standard, but allow SDCC features that conflict
21398 with the standard (default).
21401 \begin_layout Itemize
21407 \begin_inset LatexCommand \index{\#pragma std\_c89}
21411 - Follow the C89 standard and disable SDCC features that conflict with the
21415 \begin_layout Itemize
21421 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21425 - Generally follow the C99 standard, but allow SDCC features that conflict
21426 with the standard (incomplete support).
21429 \begin_layout Itemize
21435 \begin_inset LatexCommand \index{\#pragma std\_c99}
21439 - Follow the C99 standard and disable SDCC features that conflict with the
21440 standard (incomplete support).
21443 \begin_layout Itemize
21449 \begin_inset LatexCommand \index{\#pragma codeseg}
21453 - Use this name (max.
21454 8 characters) for the code segment.
21459 \begin_layout Standard
21471 \begin_layout Itemize
21477 \begin_inset LatexCommand \index{\#pragma constseg}
21481 - Use this name (max.
21482 8 characters) for the const segment.
21487 \begin_layout Standard
21499 \begin_layout Standard
21500 The preprocessor SDCPP
21501 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21505 supports the following #pragma directives:
21508 \begin_layout Itemize
21511 pedantic_parse_number
21514 \begin_inset LatexCommand \index{pedantic}
21519 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21524 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21528 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21529 properly and the macro LO_B(3) gets expanded.
21535 \begin_layout Standard
21544 -pedantic-parse-number command line option
21545 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21552 Below is an example on how to use this pragma.
21555 Note: this functionality is not in conformance with standard!
21558 \begin_layout Verse
21561 #pragma pedantic_parse_number +
21562 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21570 #define LO_B(x) ((x) & 0xff)
21574 unsigned char foo(void)
21581 unsigned char c=0xfe-LO_B(3)
21596 \begin_layout Itemize
21602 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21606 (+ | -) - switch _asm _endasm block preprocessing on / off.
21608 You use this prama to define multilines of assembly code.
21609 This will prevent the preprocessor from changing the formating required
21611 Below is an example on how to use this pragma.
21614 \begin_layout Verse
21617 #pragma preproc_asm -
21618 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21624 #define MYDELAY _asm
21629 nop ;my assembly comment...
21643 #pragma preproc_asm
21674 \begin_layout Itemize
21680 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21684 (+ | -) - Allow "naked" hash in macro definition, for example:
21688 #define DIR_LO(x) #(x & 0xff)
21693 Below is an example on how to use this pragma.
21696 \begin_layout Verse
21699 #pragma preproc_asm +
21701 #pragma sdcc_hash +
21702 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21717 mov R6_B3, #(x & 0xff)
21724 mov R7_B3, #((x >> 8) & 0xff)
21748 \begin_layout Standard
21749 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21750 ons which might cause the compiler to generate extra stack and/or data space
21751 to store compiler generated temporary variables.
21752 This usually happens in large functions.
21753 Pragma directives should be used as shown in the following example, they
21754 are used to control options and optimizations for a given function.
21758 \begin_layout Verse
21762 \begin_inset LatexCommand \index{\#pragma save}
21773 /* save the current settings */
21776 \begin_inset LatexCommand \index{\#pragma nogcse}
21785 /* turnoff global subexpression elimination */
21787 #pragma noinduction
21788 \begin_inset LatexCommand \index{\#pragma noinduction}
21792 /* turn off induction optimizations */
21815 \begin_inset LatexCommand \index{\#pragma restore}
21819 /* turn the optimizations back on */
21822 \begin_layout Standard
21823 The compiler will generate a warning message when extra space is allocated.
21824 It is strongly recommended that the save and restore pragma's be used when
21825 changing options for a function.
21834 \begin_layout Section
21835 Defines Created by the Compiler
21838 \begin_layout Standard
21839 The compiler creates the following #defines
21840 \begin_inset LatexCommand \index{\#defines}
21845 \begin_inset LatexCommand \index{Defines created by the compiler}
21854 \begin_layout Standard
21855 \begin_inset Tabular
21856 <lyxtabular version="3" rows="11" columns="2">
21858 <column alignment="left" valignment="top" leftline="true" width="3in">
21859 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21860 <row topline="true" bottomline="true">
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21864 \begin_layout Standard
21872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21875 \begin_layout Standard
21884 <row topline="true">
21885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21888 \begin_layout Standard
21890 \begin_inset LatexCommand \index{SDCC}
21899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21902 \begin_layout Standard
21904 Since version 2.5.6 the version number as an int (ex.
21911 <row topline="true">
21912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21915 \begin_layout Standard
21917 \begin_inset LatexCommand \index{SDCC\_mcs51}
21922 \begin_inset LatexCommand \index{SDCC\_ds390}
21927 \begin_inset LatexCommand \index{SDCC\_z80}
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21939 \begin_layout Standard
21940 depending on the model used (e.g.: -mds390)
21946 <row topline="true">
21947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21950 \begin_layout Standard
21952 \begin_inset LatexCommand \index{\_\_mcs51}
21957 \begin_inset LatexCommand \index{\_\_ds390}
21962 \begin_inset LatexCommand \index{\_\_hc08}
21967 \begin_inset LatexCommand \index{\_\_z80}
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21979 \begin_layout Standard
21980 depending on the model used (e.g.
21987 <row topline="true">
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21991 \begin_layout Standard
21993 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22005 \begin_layout Standard
22012 \begin_layout Standard
22029 <row topline="true">
22030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22033 \begin_layout Standard
22035 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22047 \begin_layout Standard
22054 \begin_layout Standard
22071 <row topline="true">
22072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22075 \begin_layout Standard
22077 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22089 \begin_layout Standard
22096 \begin_layout Standard
22113 <row topline="true">
22114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22117 \begin_layout Standard
22119 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22131 \begin_layout Standard
22138 \begin_layout Standard
22155 <row topline="true">
22156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22159 \begin_layout Standard
22161 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22173 \begin_layout Standard
22180 \begin_layout Standard
22197 <row topline="true">
22198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22201 \begin_layout Standard
22203 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22215 \begin_layout Standard
22226 <row topline="true" bottomline="true">
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22230 \begin_layout Standard
22232 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22244 \begin_layout Standard
22262 \begin_layout Chapter
22263 Notes on supported Processors
22266 \begin_layout Section
22268 \begin_inset LatexCommand \label{sub:MCS51-variants}
22273 \begin_inset LatexCommand \index{MCS51 variants}
22280 \begin_layout Standard
22281 MCS51 processors are available from many vendors and come in many different
22283 While they might differ considerably in respect to Special Function Registers
22284 the core MCS51 is usually not modified or is kept compatible.
22288 \begin_layout Subsection
22289 pdata access by SFR
22292 \begin_layout Standard
22293 With the upcome of devices with internal xdata and flash memory devices
22295 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22299 as dedicated I/O port is becoming more popular.
22300 Switching the high byte for pdata
22301 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22305 access which was formerly done by port P2 is then achieved by a Special
22307 \begin_inset LatexCommand \index{sfr}
22312 In well-established MCS51 tradition the address of this
22316 is where the chip designers decided to put it.
22317 Needless to say that they didn't agree on a common name either.
22318 So that the startup code can correctly initialize xdata variables, you
22319 should define an sfr with the name _XPAGE
22322 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22328 at the appropriate location if the default, port P2, is not used for this.
22332 \begin_layout Verse
22335 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22339 \begin_layout Verse
22342 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22347 \begin_layout Verse
22350 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22354 \begin_layout Verse
22357 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22361 \begin_layout Verse
22364 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22368 \begin_layout Standard
22369 For more exotic implementations further customizations may be needed.
22371 \begin_inset LatexCommand \ref{sub:Startup-Code}
22375 for other possibilities.
22378 \begin_layout Subsection
22379 Other Features available by SFR
22382 \begin_layout Standard
22383 Some MCS51 variants offer features like Double DPTR
22384 \begin_inset LatexCommand \index{DPTR}
22388 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22389 These are currently not used for the MCS51 port.
22390 If you absolutely need them you can fall back to inline assembly or submit
22392 \begin_inset VSpace bigskip
22398 \begin_layout Section
22402 \begin_layout Standard
22404 \begin_inset LatexCommand \index{DS80C400}
22409 \begin_inset LatexCommand \index{DS400}
22413 microcontroller has a rich set of peripherals.
22414 In its built-in ROM library it includes functions to access some of the
22415 features, among them is a TCP stack with IP4 and IP6 support.
22416 Library headers (currently in beta status) and other files are provided
22420 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22426 \begin_inset VSpace bigskip
22432 \begin_layout Section
22433 The Z80 and gbz80 port
22436 \begin_layout Standard
22437 SDCC can target both the Zilog Z80
22438 \begin_inset LatexCommand \index{Z80}
22442 and the Nintendo Gameboy's Z80-like gbz80
22443 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22448 The Z80 port is passed through the same
22451 \begin_inset LatexCommand \index{Regression test}
22458 \begin_inset LatexCommand \ref{sec:Quality-control}
22462 ) as the MCS51 and DS390 ports, so floating point support, support for long
22463 variables and bitfield support is fine.
22464 See mailing lists and forums about interrupt routines.
22467 \begin_layout Standard
22468 As always, the code is the authoritative reference - see z80/ralloc.c and
22471 \begin_inset LatexCommand \index{Z80!stack}
22475 frame is similar to that generated by the IAR Z80 compiler.
22476 IX is used as the base pointer, HL and IY are used as a temporary registers,
22477 and BC and DE are available for holding variables.
22479 \begin_inset LatexCommand \index{Z80!return value}
22483 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22485 The gbz80 port use the same set of registers for the return values, but
22486 in a different order of significance: E (one byte), DE (two bytes), or
22488 \begin_inset VSpace bigskip
22494 \begin_layout Section
22498 \begin_layout Standard
22499 The port to the Freescale/Motorola HC08
22500 \begin_inset LatexCommand \index{HC08}
22504 family has been added in October 2003, and is still undergoing some basic
22506 The code generator is complete, but the register allocation is still quite
22508 Some of the SDCC's standard C library functions have embedded non-HC08
22509 inline assembly and so are not yet usable.
22512 \begin_layout Standard
22513 The HC08 port passes the regression test suite (see section
22514 \begin_inset LatexCommand \ref{sec:Quality-control}
22519 \begin_inset VSpace bigskip
22527 \begin_layout Section
22531 \begin_layout Standard
22532 The PIC14 port adds support for Microchip(TM)'s 14
22536 \begin_layout Standard
22546 \begin_inset LatexCommand \index{PIC14}
22551 This port is not yet mature and still lacks many features.
22552 However, it can work for simple code.
22555 \begin_layout Standard
22556 Currently supported devices include:
22559 \begin_layout Standard
22560 12F: 629, 635, 675, 683
22563 \begin_layout Standard
22567 \begin_layout Standard
22571 \begin_layout Standard
22572 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22575 \begin_layout Standard
22576 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22580 \begin_layout Standard
22584 \begin_layout Standard
22585 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22589 \begin_layout Standard
22590 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22593 \begin_layout Standard
22594 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22598 \begin_layout Standard
22599 16F: 913, 914, 916, 917
22602 \begin_layout Standard
22603 An up-to-date list of currently supported devices can be obtained via
22605 sdcc -mpic14 -phelp foo.c
22607 (foo.c must exist...).
22610 \begin_layout Subsection
22612 \begin_inset LatexCommand \index{code page (pic14)}
22617 \begin_inset LatexCommand \index{Memory bank (pic14)}
22624 \begin_layout Standard
22625 The linker organizes allocation for the code page and RAM banks.
22626 It does not have intimate knowledge of the code flow.
22627 It will put all the code section of a single .asm file into a single code
22629 In order to make use of multiple code pages, separate asm files must be
22631 The compiler assigns all
22635 functions of a single .c file into the same code page.
22639 To get the best results,
22640 follow these guidelines:
22643 \begin_layout Enumerate
22644 Make local functions static, as non static functions require code page selection
22647 Due to the way sdcc handles functions, place called functions prior
22648 to calling functions in the file wherever possible: Otherwise sdcc will
22649 insert unneccessary pagesel directives around the call, believing that
22650 the called function is externally defined.
22653 \begin_layout Enumerate
22654 For devices that have multiple code pages it is more efficient to use the
22655 same number of files as pages: Use up to 4 separate .c files for the 16F877,
22656 but only 2 files for the 16F874.
22657 This way the linker can put the code for each file into different code
22658 pages and there will be less page selection overhead.
22661 \begin_layout Enumerate
22662 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22663 instruction set), use 'unsigned char' wherever possible instead of 'int'.
22666 \begin_layout Subsection
22667 Adding New Devices to the Port
22670 \begin_layout Standard
22671 Adding support for a new 14
22675 \begin_layout Standard
22684 bit PIC MCU requires the following steps:
22687 \begin_layout Enumerate
22688 Create a new device description.
22690 Each device is described in two files: pic16f*.h
22692 These files primarily define SFRs, structs to access their bits, and symbolic
22693 configuration options.
22694 Both files can be generated from gputils' .inc files using the perl script
22697 support/scripts/inc2h.pl
22700 This file also contains further instructions on how to proceed.
22703 \begin_layout Enumerate
22704 Copy the .h file into SDCC's include path and either add the .c file to your
22705 project or copy it to
22707 device/lib/pic/libdev
22710 Afterwards, rebuild and install the libraries.
22713 \begin_layout Enumerate
22714 Edit pic14devices.txt in SDCC's include path (
22716 device/include/pic/
22718 in the source tree or
22720 /usr/local/share/sdcc/include/pic
22722 after installation).
22724 You need to add a device specification here to make
22725 the memory layout (code banks, RAM, aliased memory regions, ...) known to
22727 Probably you can copy and modify an existing entry.
22728 The file format is documented at the top of the file.
22731 \begin_layout Subsection
22735 \begin_layout Standard
22736 For the interrupt function, use the keyword '__interrupt'
22737 \begin_inset LatexCommand \index{PIC14!interrupt}
22741 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22742 there to avoid a syntax error - it ought to be fixed).
22746 \begin_layout Verse
22749 void Intr(void) __interrupt 0
22755 T0IF = 0; /* Clear timer interrupt */
22760 \begin_layout Subsection
22761 Linking and Assembling
22764 \begin_layout Standard
22765 For assembling you can use either GPUTILS'
22766 \begin_inset LatexCommand \index{gputils (pic tools)}
22770 gpasm.exe or MPLAB's mpasmwin.exe.
22771 GPUTILS are available from
22772 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22777 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
22778 If you use MPLAB and an interrupt function then the linker script file
22779 vectors section will need to be enlarged to link with mplink.
22790 \begin_layout Verse
22803 sdcc -V -mpic14 -p16f877 -c $<
22807 $(PRJ).hex: $(OBJS)
22817 gplink -m -s $(PRJ).lkr
22818 -o $(PRJ).hex $(OBJS) libsdcc.lib
22821 \begin_layout Standard
22829 \begin_layout Verse
22842 sdcc -S -V -mpic14 -p16f877 $<
22852 mpasmwin /q /o $*.asm
22856 $(PRJ).hex: $(OBJS)
22867 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22870 \begin_layout Standard
22871 Please note that indentations within a
22875 have to be done with a tabulator character.
22878 \begin_layout Subsection
22879 Command-Line Options
22882 \begin_layout Standard
22883 Besides the switches common to all SDCC backends, the PIC14 port accepts
22884 the following options (for an updated list see sdcc -
22888 \begin_layout Standard
22900 \begin_layout Description
22905 \begin_layout Standard
22915 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22919 emit debug info in assembly output
22922 \begin_layout Description
22927 \begin_layout Standard
22937 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22941 disable (slightly faulty) optimization on pCode
22944 \begin_layout Description
22949 \begin_layout Standard
22959 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22963 sets the lowest address of the argument passing stack (defaults to a suitably
22964 large shared databank to reduce BANKSEL overhead)
22967 \begin_layout Description
22972 \begin_layout Standard
22982 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22986 sets the size if the argument passing stack (default: 16, minimum: 4)
22989 \begin_layout Subsection
22990 Environment Variables
22993 \begin_layout Standard
22994 The PIC14 port recognizes the following environment variables:
22997 \begin_layout Description
22998 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
22999 register (the ones called r0xNNNN) in a section of its own.
23000 By default (if this variable is unset), sdcc tries to cluster registers
23001 in sections in order to reduce the BANKSEL overhead when accessing them.
23004 \begin_layout Subsection
23008 \begin_layout Standard
23009 The PIC14 library currently only contains support routines required by the
23010 compiler to implement multiplication, division, and floating point support.
23011 No libc-like replacement is available at the moment, though many of the
23012 common sdcc library sources (in
23016 ) should also compile with the PIC14 port.
23019 \begin_layout Subsubsection
23020 error: missing definition for symbol
23021 \begin_inset Quotes sld
23025 \begin_inset Quotes srd
23031 \begin_layout Standard
23032 The PIC14 port uses library routines to provide more complex operations
23033 like multiplication, division/modulus and (generic) pointer dereferencing.
23034 In order to add these routines to your project, you must link with PIC14's
23040 For single source file projects this is done automatically, more complex
23045 to the linker's arguments.
23046 Make sure you also add an include path for the library (using the -I switch
23050 \begin_layout Subsubsection
23051 Processor mismatch in file
23052 \begin_inset Quotes sld
23056 \begin_inset Quotes srd
23062 \begin_layout Standard
23063 This warning can usually be ignored due to the very good compatibility amongst
23068 \begin_layout Standard
23078 \begin_inset LatexCommand \index{PIC14}
23085 \begin_layout Standard
23086 You might also consider recompiling the library for your specific device
23087 by changing the ARCH=p16f877 (default target) entry in
23089 device/lib/pic/Makefile.in
23093 device/lib/pic/Makefile
23095 to reflect your device.
23096 This might even improve performance for smaller devices as unneccesary
23097 BANKSELs might be removed.
23100 \begin_layout Subsection
23104 \begin_layout Subsubsection
23108 \begin_layout Standard
23109 Functions with variable argument lists (like printf) are not yet supported.
23110 Similarly, taking the argument of the first argument passed into a function
23111 does not work: It is currently passed in WREG and has no address...
23114 \begin_layout Subsubsection
23115 Regression tests fail
23118 \begin_layout Standard
23119 Though the small subset of regression tests in src/regression passes, SDCC
23120 regression test suite does not, indicating that there are still major bugs
23122 However, many smaller projects have successfully used SDCC in the past...
23125 \begin_layout Standard
23133 \begin_layout Section
23135 \begin_inset LatexCommand \index{PIC16}
23142 \begin_layout Standard
23144 \begin_inset LatexCommand \index{PIC16}
23148 port is the portion of SDCC that is responsible to produce code for the
23150 \begin_inset LatexCommand \index{Microchip}
23154 (TM) microcontrollers with 16 bit core.
23155 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23156 Currently supported devices are:
23159 \begin_layout Standard
23160 18F: 242, 248, 252, 258, 442, 448, 452, 458
23163 \begin_layout Standard
23167 \begin_layout Standard
23168 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23171 \begin_layout Standard
23172 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23175 \begin_layout Standard
23176 18F: 6520, 6620, 6680, 6720
23179 \begin_layout Standard
23180 18F: 8520, 8620, 8680, 8720
23183 \begin_layout Subsection
23187 \begin_layout Standard
23188 PIC16 port supports the standard command line arguments as supposed, with
23189 the exception of certain cases that will be mentioned in the following
23193 \begin_layout Description
23198 \begin_layout Standard
23208 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23216 \begin_layout Standard
23228 \begin_layout Description
23233 \begin_layout Standard
23242 -fommit-frame-pointer
23243 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23247 Frame pointer will be omitted when the function uses no local variables.
23250 \begin_layout Subsection
23251 Port Specific Options
23252 \begin_inset LatexCommand \index{Options PIC16}
23259 \begin_layout Standard
23260 The port specific options appear after the global options in the sdcc -
23264 \begin_layout Standard
23276 \begin_layout Subsubsection
23277 Code Generation Options
23280 \begin_layout Standard
23281 These options influence the generated assembler code.
23284 \begin_layout Description
23289 \begin_layout Standard
23298 -pstack-model=[model] Used in conjuction with the command above.
23299 Defines the stack model to be used, valid stack models are:
23304 \labelwidthstring 00.00.0000
23309 Selects small stack model.
23310 8 bit stack and frame pointers.
23311 Supports 256 bytes stack size.
23315 \labelwidthstring 00.00.0000
23320 Selects large stack model.
23321 16 bit stack and frame pointers.
23322 Supports 65536 bytes stack size.
23326 \begin_layout Description
23331 \begin_layout Standard
23340 -pno-banksel Do not generate BANKSEL assembler directives.
23343 \begin_layout Description
23348 \begin_layout Standard
23357 -extended Enable extended instruction set/literal offset addressing mode.
23361 \begin_layout Subsubsection
23362 Optimization Options
23365 \begin_layout Description
23370 \begin_layout Standard
23379 -obanksel=n Set optimization level for inserting BANKSELs.
23386 \labelwidthstring 00.00.0000
23391 \labelwidthstring 00.00.0000
23392 1 checks previous used register and if it is the same then does not emit
23393 BANKSEL, accounts only for labels.
23397 \labelwidthstring 00.00.0000
23398 2 tries to check the location of (even different) symbols and removes BANKSELs
23399 if they are in the same bank.
23404 Important: There might be problems if the linker script has data sections
23405 across bank borders!
23409 \begin_layout Description
23414 \begin_layout Standard
23423 -denable-peeps Force the usage of peepholes.
23427 \begin_layout Description
23432 \begin_layout Standard
23441 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23444 \begin_layout Description
23449 \begin_layout Standard
23458 -optimize-cmp Try to optimize some compares.
23461 \begin_layout Description
23466 \begin_layout Standard
23475 -optimize-df Analyze the dataflow of the generated code and improve it.
23478 \begin_layout Subsubsection
23482 \begin_layout Description
23487 \begin_layout Standard
23496 -asm= Sets the full path and name of an external assembler to call.
23499 \begin_layout Description
23504 \begin_layout Standard
23514 \begin_inset LatexCommand \index{PIC16!MPLAB}
23518 compatibility option.
23519 Currently only suppresses special gpasm directives.
23522 \begin_layout Subsubsection
23526 \begin_layout Description
23531 \begin_layout Standard
23540 -link= Sets the full path and name of an external linker to call.
23543 \begin_layout Description
23548 \begin_layout Standard
23557 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23558 unitialized data variables with [kword].
23559 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23562 \begin_layout Description
23567 \begin_layout Standard
23576 -ivt-loc=n Place the interrupt vector table at address
23581 Useful for bootloaders.
23584 \begin_layout Description
23589 \begin_layout Standard
23598 -nodefaultlibs Do not link default libraries when linking.
23601 \begin_layout Description
23606 \begin_layout Standard
23615 -use-crt= Use a custom run-time module instead of the defaults.
23618 \begin_layout Description
23623 \begin_layout Standard
23632 -no-crt Don't link the default run-time modules
23635 \begin_layout Subsubsection
23639 \begin_layout Standard
23640 Debugging options enable extra debugging information in the output files.
23643 \begin_layout Description
23648 \begin_layout Standard
23657 -debug-xtra Similar to -
23661 \begin_layout Standard
23671 \begin_inset LatexCommand \index{-\/-debug}
23675 , but dumps more information.
23678 \begin_layout Description
23683 \begin_layout Standard
23692 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23694 <source> is the name of the file being compiled.
23697 \begin_layout Description
23702 \begin_layout Standard
23711 -pcode-verbose Enable pcode debugging information in translation.
23714 \begin_layout Description
23719 \begin_layout Standard
23728 -calltree Dump call tree in .calltree file.
23731 \begin_layout Description
23736 \begin_layout Standard
23745 -gstack Trace push/pops for stack pointer overflow.
23748 \begin_layout Subsection
23749 Enviroment Variables
23752 \begin_layout Standard
23753 There is a number of enviromental variables that can be used when running
23754 SDCC to enable certain optimizations or force a specific program behaviour.
23755 these variables are primarily for debugging purposes so they can be enabled/dis
23759 \begin_layout Standard
23760 Currently there is only two such variables available:
23763 \begin_layout Description
23764 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
23765 bitfields is optimized by directly loading FSR0 with the address of the
23766 bitfield structure.
23767 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23769 This step saves data ram and code space for functions that make heavy use
23771 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
23776 \begin_layout Description
23777 NO_REG_OPT Do not perform pCode registers optimization.
23778 This should be used for debugging purposes.
23779 If bugs in the pcode optimizer are found, users can benefit from temporarily
23780 disabling the optimizer until the bug is fixed.
23783 \begin_layout Subsection
23784 Preprocessor Macros
23787 \begin_layout Standard
23789 \begin_inset LatexCommand \index{PIC16}
23793 port defines the following preprocessor macros while translating a source.
23796 \begin_layout Standard
23798 \begin_inset Tabular
23799 <lyxtabular version="3" rows="6" columns="2">
23801 <column alignment="center" valignment="top" leftline="true" width="0">
23802 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23803 <row topline="true" bottomline="true">
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23807 \begin_layout Standard
23813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23816 \begin_layout Standard
23823 <row topline="true">
23824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23827 \begin_layout Standard
23833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23836 \begin_layout Standard
23837 Port identification
23843 <row topline="true">
23844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23847 \begin_layout Standard
23852 \begin_layout Standard
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23869 \begin_layout Standard
23870 Port identification (same as above)
23876 <row topline="true">
23877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23880 \begin_layout Standard
23886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23889 \begin_layout Standard
23890 MCU Identification.
23895 is the microcontrol identification number, i.e.
23902 <row topline="true">
23903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23906 \begin_layout Standard
23911 \begin_layout Standard
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23928 \begin_layout Standard
23929 MCU Identification (same as above)
23935 <row topline="true" bottomline="true">
23936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23939 \begin_layout Standard
23945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23948 \begin_layout Standard
23949 nnn = SMALL or LARGE respectively according to the stack model used
23962 \begin_layout Standard
23963 In addition the following macros are defined when calling assembler:
23966 \begin_layout Standard
23968 \begin_inset Tabular
23969 <lyxtabular version="3" rows="4" columns="2">
23971 <column alignment="center" valignment="top" leftline="true" width="0">
23972 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23973 <row topline="true" bottomline="true">
23974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23977 \begin_layout Standard
23983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23986 \begin_layout Standard
23993 <row topline="true">
23994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23997 \begin_layout Standard
24003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24006 \begin_layout Standard
24007 MCU Identification.
24012 is the microcontrol identification number, i.e.
24019 <row topline="true">
24020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24023 \begin_layout Standard
24029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24032 \begin_layout Standard
24033 nnn = SMALL or LARGE respectively according to the memory model used for
24040 <row topline="true" bottomline="true">
24041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24044 \begin_layout Standard
24050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24053 \begin_layout Standard
24054 nnn = SMALL or LARGE respectively according to the stack model used
24067 \begin_layout Subsection
24071 \begin_layout Standard
24073 \begin_inset LatexCommand \index{PIC16}
24077 port uses the following directories for searching header files and libraries.
24080 \begin_layout Standard
24082 \begin_inset Tabular
24083 <lyxtabular version="3" rows="3" columns="4">
24085 <column alignment="center" valignment="top" leftline="true" width="0">
24086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24087 <column alignment="center" valignment="top" width="0">
24088 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24089 <row topline="true" bottomline="true">
24090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24093 \begin_layout Standard
24099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24102 \begin_layout Standard
24108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24111 \begin_layout Standard
24117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24120 \begin_layout Standard
24127 <row topline="true">
24128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24131 \begin_layout Standard
24132 PREFIX/sdcc/include/pic16
24137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24140 \begin_layout Standard
24141 PIC16 specific headers
24146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24149 \begin_layout Standard
24155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24158 \begin_layout Standard
24165 <row topline="true" bottomline="true">
24166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24169 \begin_layout Standard
24170 PREFIX/sdcc/lib/pic16
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24178 \begin_layout Standard
24179 PIC16 specific libraries
24184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24187 \begin_layout Standard
24193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24196 \begin_layout Standard
24210 \begin_layout Subsection
24212 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24219 \begin_layout Standard
24221 \begin_inset LatexCommand \index{PIC16}
24225 port currently supports the following pragmas:
24228 \begin_layout Description
24230 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24234 This forces the code generator to initialize the stack & frame pointers
24235 at a specific address.
24236 This is an ad hoc solution for cases where no STACK directive is available
24237 in the linker script or gplink is not instructed to create a stack section.
24240 stack pragma should be used only once in a project.
24241 Multiple pragmas may result in indeterminate behaviour of the program.
24245 \begin_layout Standard
24246 The old format (ie.
24247 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24248 cross page boundaries (or even exceed the available data RAM) and crash
24250 Make sure that stack does not cross page boundaries when using the SMALL
24258 The format is as follows:
24263 \begin_layout LyX-Code
24264 #pragma stack bottom_address [stack_size]
24269 \begin_layout Standard
24274 is the lower bound of the stack section.
24275 The stack pointer initially will point at address (bottom_address+stack_size-1).
24278 \begin_layout LyX-Code
24282 \begin_layout LyX-Code
24286 \begin_layout LyX-Code
24287 /* initializes stack of 100 bytes at RAM address 0x200 */
24290 \begin_layout LyX-Code
24291 #pragma stack 0x200 100
24294 \begin_layout Standard
24295 If the stack_size field is omitted then a stack is created with the default
24297 This size might be enough for most programs, but its not enough for operations
24298 with deep function nesting or excessive stack usage.
24301 \begin_layout Description
24303 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24307 Force a function to a static FLASH address.
24310 \begin_layout LyX-Code
24314 \begin_layout LyX-Code
24318 \begin_layout LyX-Code
24319 /* place function test_func at 0x4000 */
24322 \begin_layout LyX-Code
24323 #pragma code test_func 0x4000
24326 \begin_layout LyX-Code
24330 \begin_layout Description
24331 library instructs the linker to use a library module.
24336 \begin_layout LyX-Code
24337 #pragma library module_name
24340 \begin_layout Standard
24345 can be any library or object file (including its path).
24346 Note that there are four reserved keywords which have special meaning.
24350 \begin_layout Standard
24352 \begin_inset Tabular
24353 <lyxtabular version="3" rows="6" columns="3">
24355 <column alignment="center" valignment="top" leftline="true" width="0">
24356 <column alignment="block" valignment="top" leftline="true" width="20page%">
24357 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24358 <row topline="true" bottomline="true">
24359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24362 \begin_layout Standard
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24371 \begin_layout Standard
24377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24380 \begin_layout Standard
24387 <row topline="true">
24388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24391 \begin_layout Standard
24399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24402 \begin_layout Standard
24403 ignore all library pragmas
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24411 \begin_layout Standard
24420 <row topline="true">
24421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24424 \begin_layout Standard
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24435 \begin_layout Standard
24441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24444 \begin_layout Standard
24455 <row topline="true">
24456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24459 \begin_layout Standard
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24470 \begin_layout Standard
24471 link the Math libarary
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24479 \begin_layout Standard
24490 <row topline="true">
24491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24494 \begin_layout Standard
24502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24505 \begin_layout Standard
24506 link the I/O library
24511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24514 \begin_layout Standard
24525 <row topline="true" bottomline="true">
24526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24529 \begin_layout Standard
24537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24540 \begin_layout Standard
24541 link the debug library
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24549 \begin_layout Standard
24566 * is the device number, i.e.
24567 452 for PIC18F452 MCU.
24570 \begin_layout Standard
24571 This feature allows for linking with specific libraries withoug having to
24572 explicit name them in the command line.
24577 keyword will reject all modules specified by the library pragma.
24580 \begin_layout Description
24581 udata The pragma udata instructs the compiler to emit code so that linker
24582 will place a variable at a specific memory bank.
24585 \begin_layout LyX-Code
24589 \begin_layout LyX-Code
24593 \begin_layout LyX-Code
24594 /* places variable foo at bank2 */
24597 \begin_layout LyX-Code
24598 #pragma udata bank2 foo
24601 \begin_layout LyX-Code
24605 \begin_layout Standard
24606 In order for this pragma to work extra SECTION directives should be added
24607 in the .lkr script.
24608 In the following example a sample .lkr file is shown:
24611 \begin_layout LyX-Code
24615 \begin_layout LyX-Code
24616 // Sample linker script for the PIC18F452 processor
24619 \begin_layout LyX-Code
24623 \begin_layout LyX-Code
24624 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24627 \begin_layout LyX-Code
24628 CODEPAGE NAME=page START=0x2A END=0x7FFF
24631 \begin_layout LyX-Code
24632 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24635 \begin_layout LyX-Code
24636 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24639 \begin_layout LyX-Code
24640 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24643 \begin_layout LyX-Code
24644 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24647 \begin_layout LyX-Code
24648 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24651 \begin_layout LyX-Code
24655 \begin_layout LyX-Code
24656 DATABANK NAME=gpr0 START=0x80 END=0xFF
24659 \begin_layout LyX-Code
24660 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24663 \begin_layout LyX-Code
24664 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24667 \begin_layout LyX-Code
24668 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24671 \begin_layout LyX-Code
24672 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24675 \begin_layout LyX-Code
24676 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24679 \begin_layout LyX-Code
24680 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24683 \begin_layout LyX-Code
24687 \begin_layout LyX-Code
24688 SECTION NAME=CONFIG ROM=config
24691 \begin_layout LyX-Code
24695 \begin_layout LyX-Code
24696 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24699 \begin_layout LyX-Code
24700 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24703 \begin_layout LyX-Code
24704 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24707 \begin_layout LyX-Code
24708 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24711 \begin_layout LyX-Code
24712 SECTION NAME=bank4 RAM=gpr4
24715 \begin_layout LyX-Code
24716 SECTION NAME=bank5 RAM=gpr5
24719 \begin_layout Standard
24720 The linker will recognise the section name set in the pragma statement and
24721 will position the variable at the memory bank set with the RAM field at
24722 the SECTION line in the linker script file.
24725 \begin_layout Subsection
24727 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24734 \begin_layout Standard
24735 There is one main header file
24736 \begin_inset LatexCommand \index{PIC16!Header files}
24740 that can be included to the source files using the pic16
24741 \begin_inset LatexCommand \index{PIC16}
24751 This header file contains the definitions for the processor special registers,
24752 so it is necessary if the source accesses them.
24753 It can be included by adding the following line in the beginning of the
24757 \begin_layout LyX-Code
24758 #include <pic18fregs.h>
24761 \begin_layout Standard
24762 The specific microcontroller is selected within the pic18fregs.h automatically,
24763 so the same source can be used with a variety of devices.
24766 \begin_layout Subsection
24770 \begin_layout Standard
24772 \begin_inset LatexCommand \index{PIC16!Libraries}
24777 \begin_inset LatexCommand \index{PIC16}
24781 port depends on are the microcontroller device libraries which contain
24782 the symbol definitions for the microcontroller special function registers.
24783 These libraries have the format pic18fxxxx.lib, where
24787 is the microcontroller identification number.
24788 The specific library is selected automatically by the compiler at link
24789 stage according to the selected device.
24792 \begin_layout Standard
24793 Libraries are created with gplib which is part of the gputils package
24794 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24801 \begin_layout Subsubsection*
24802 Building the libraries
24805 \begin_layout Standard
24806 Before using SDCC/pic16 there are some libraries that need to be compiled.
24807 This process is not done automatically by SDCC since not all users use
24808 SDCC for pic16 projects.
24809 So each user should compile the libraries separately.
24812 \begin_layout Standard
24813 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24816 \begin_layout LyX-Code
24817 cd device/lib/pic16
24820 \begin_layout LyX-Code
24824 \begin_layout LyX-Code
24828 \begin_layout LyX-Code
24832 \begin_layout LyX-Code
24836 \begin_layout LyX-Code
24837 su -c 'make install' # install the libraries, you need the root password
24840 \begin_layout Standard
24841 If you need to install the headers too, do:
24844 \begin_layout LyX-Code
24848 \begin_layout LyX-Code
24849 su -c 'make install' # install the headers, you need the root password
24852 \begin_layout Standard
24853 There exist a special target to build the I/O libraries.
24854 This target is not automatically build because it will build the I/O library
24860 This way building will take quite a lot of time.
24861 Users are advised to edit the
24863 device/lib/pic16/pics.build
24865 file and then execute:
24868 \begin_layout LyX-Code
24872 \begin_layout Subsection
24873 Adding New Devices to the Port
24876 \begin_layout Standard
24877 Adding support for a new 16
24881 \begin_layout Standard
24890 bit PIC MCU requires the following steps:
24893 \begin_layout Enumerate
24894 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
24898 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
24902 \begin_layout Enumerate
24905 mv picDEVICE.h /path/to/sdcc/device/include/pic16
24908 \begin_layout Enumerate
24911 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
24914 \begin_layout Enumerate
24917 /path/to/sdcc/device/lib/pics.all
24925 Note: No 18f prefix here!
24928 \begin_layout Enumerate
24931 /path/to/sdcc/device/lib/pic16/libio/*.ignore
24935 Add your DEVICE if it does not compile in
24950 \begin_layout Enumerate
24953 /path/to/sdcc/device/include/pic16/pic18fregs.h
24956 The file format is self-explanatory, just add
24960 #elif defined(picDEVICE)
24962 # include <picDEVICE.h>
24966 at the right place (keep it sorted).
24969 \begin_layout Enumerate
24972 /path/to/sdcc/src/pic16/devices.inc
24975 Copy and modify an existing entry and insert it at the correct place (keep
24977 The file is hardly documented, look at the entries for the 18f2221...
24980 \begin_layout Enumerate
24981 Recompile SDCC, including the pic16 libraries.
24984 \begin_layout Subsection
24988 \begin_layout Standard
24989 The following memory models are supported by the PIC16 port:
24992 \begin_layout Itemize
24996 \begin_layout Itemize
25000 \begin_layout Standard
25001 Memory model affects the default size of pointers within the source.
25002 The sizes are shown in the next table:
25005 \begin_layout Standard
25007 \begin_inset Tabular
25008 <lyxtabular version="3" rows="3" columns="3">
25010 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25011 <column alignment="center" valignment="top" leftline="true" width="0">
25012 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25013 <row topline="true" bottomline="true">
25014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25017 \begin_layout Standard
25018 Pointer sizes according to memory model
25023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25026 \begin_layout Standard
25032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25035 \begin_layout Standard
25042 <row topline="true" bottomline="true">
25043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25046 \begin_layout Standard
25052 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25055 \begin_layout Standard
25061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25064 \begin_layout Standard
25071 <row topline="true" bottomline="true">
25072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25075 \begin_layout Standard
25081 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25084 \begin_layout Standard
25090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25093 \begin_layout Standard
25107 \begin_layout Standard
25108 It is advisable that all sources within a project are compiled with the
25110 If one wants to override the default memory model, this can be done by
25111 declaring a pointer as
25120 Far selects large memory model's pointers, while near selects small memory
25124 \begin_layout Standard
25125 The standard device libraries (see
25126 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25130 ) contain no reference to pointers, so they can be used with both memory
25134 \begin_layout Subsection
25138 \begin_layout Standard
25140 \begin_inset LatexCommand \index{PIC16!stack}
25144 implementation for the PIC16 port uses two indirect registers, FSR1 and
25148 \begin_layout Description
25149 FSR1 is assigned as stack pointer
25152 \begin_layout Description
25153 FSR2 is assigned as frame pointer
25156 \begin_layout Standard
25157 The following stack models are supported by the PIC16 port
25160 \begin_layout Itemize
25168 \begin_layout Itemize
25176 \begin_layout Standard
25181 model means that only the FSRxL byte is used to access stack and frame,
25188 uses both FSRxL and FSRxH registers.
25189 The following table shows the stack/frame pointers sizes according to stack
25190 model and the maximum space they can address:
25193 \begin_layout Standard
25195 \begin_inset Tabular
25196 <lyxtabular version="3" rows="3" columns="3">
25198 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25199 <column alignment="center" valignment="top" leftline="true" width="0">
25200 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25201 <row topline="true" bottomline="true">
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25205 \begin_layout Standard
25206 Stack & Frame pointer sizes according to stack model
25211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25214 \begin_layout Standard
25220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25223 \begin_layout Standard
25230 <row topline="true">
25231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25234 \begin_layout Standard
25240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25243 \begin_layout Standard
25249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25252 \begin_layout Standard
25259 <row topline="true" bottomline="true">
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25263 \begin_layout Standard
25269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25272 \begin_layout Standard
25278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25281 \begin_layout Standard
25295 \begin_layout Standard
25300 stack model is currently not working properly throughout the code generator.
25301 So its use is not advised.
25302 Also there are some other points that need special care:
25307 \begin_layout Enumerate
25308 Do not create stack sections with size more than one physical bank (that
25312 \begin_layout Enumerate
25313 Stack sections should no cross physical bank limits (i.e.
25314 #pragma stack 0x50 0x100)
25317 \begin_layout Standard
25318 These limitations are caused by the fact that only FSRxL is modified when
25319 using SMALL stack model, so no more than 256 bytes of stack can be used.
25320 This problem will disappear after LARGE model is fully implemented.
25323 \begin_layout Subsection
25327 \begin_layout Standard
25328 In addition to the standard SDCC function keywords, PIC16
25329 \begin_inset LatexCommand \index{PIC16}
25333 port makes available two more:
25336 \begin_layout Description
25338 \begin_inset LatexCommand \index{PIC16!wparam}
25342 Use the WREG to pass one byte of the first function argument.
25343 This improves speed but you may not use this for functions with arguments
25344 that are called via function pointers, otherwise the first byte of the
25345 first parameter will get lost.
25349 \begin_layout LyX-Code
25350 void func_wparam(int a) wparam
25353 \begin_layout LyX-Code
25357 \begin_layout LyX-Code
25358 /* WREG hold the lower part of a */
25361 \begin_layout LyX-Code
25362 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25366 \begin_layout LyX-Code
25370 \begin_layout LyX-Code
25374 \begin_layout Description
25376 \begin_inset LatexCommand \index{PIC16!shadowregs}
25380 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25381 hardware shadow registers which hold the values of WREG, STATUS and BSR
25383 This can be done by adding the keyword
25391 keyword in the function's header.
25394 \begin_layout LyX-Code
25395 void isr_shadow(void) shadowregs interrupt 1
25398 \begin_layout LyX-Code
25402 \begin_layout LyX-Code
25406 \begin_layout LyX-Code
25410 \begin_layout Standard
25415 instructs the code generator not to store/restore WREG, STATUS, BSR when
25416 entering/exiting the ISR.
25419 \begin_layout Subsection
25420 Function return values
25423 \begin_layout Standard
25424 Return values from functions are placed to the appropriate registers following
25425 a modified Microchip policy optimized for SDCC.
25426 The following table shows these registers:
25429 \begin_layout Standard
25431 \begin_inset Tabular
25432 <lyxtabular version="3" rows="6" columns="2">
25434 <column alignment="center" valignment="top" leftline="true" width="0">
25435 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25436 <row topline="true" bottomline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25440 \begin_layout Standard
25446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25449 \begin_layout Standard
25450 destination register
25456 <row topline="true">
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25460 \begin_layout Standard
25466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25469 \begin_layout Standard
25476 <row topline="true">
25477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25480 \begin_layout Standard
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25489 \begin_layout Standard
25496 <row topline="true">
25497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25500 \begin_layout Standard
25506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25509 \begin_layout Standard
25516 <row topline="true">
25517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25520 \begin_layout Standard
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25529 \begin_layout Standard
25530 FSR0L:PRODH:PRODL:WREG
25536 <row topline="true" bottomline="true">
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25540 \begin_layout Standard
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25549 \begin_layout Standard
25550 on stack, FSR0 points to the beginning
25563 \begin_layout Subsection
25567 \begin_layout Standard
25569 \begin_inset LatexCommand \index{PIC16!interrupt}
25573 service routine (ISR) is declared using the
25580 \begin_layout LyX-Code
25581 void isr(void) interrupt
25586 \begin_layout LyX-Code
25590 \begin_layout LyX-Code
25594 \begin_layout LyX-Code
25598 \begin_layout Standard
25603 is the interrupt number, which for PIC18F devices can be:
25606 \begin_layout Standard
25608 \begin_inset Tabular
25609 <lyxtabular version="3" rows="4" columns="3">
25611 <column alignment="center" valignment="top" leftline="true" width="0">
25612 <column alignment="center" valignment="top" leftline="true" width="0">
25613 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25614 <row topline="true" bottomline="true">
25615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25618 \begin_layout Standard
25626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25629 \begin_layout Standard
25635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25638 \begin_layout Standard
25639 Interrupt Vector Address
25645 <row topline="true">
25646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25649 \begin_layout Standard
25655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25658 \begin_layout Standard
25664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25667 \begin_layout Standard
25674 <row topline="true">
25675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25678 \begin_layout Standard
25693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25696 \begin_layout Standard
25706 HIGH priority interrupts
25711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25714 \begin_layout Standard
25721 <row topline="true" bottomline="true">
25722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25725 \begin_layout Standard
25731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25734 \begin_layout Standard
25735 LOW priority interrupts
25740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25743 \begin_layout Standard
25757 \begin_layout Standard
25758 When generating assembly code for ISR the code generator places a
25764 Interrupt Vector Address
25766 which points at the genetated ISR.
25767 This single GOTO instruction is part of an automatically generated
25769 interrupt entry point
25772 The actuall ISR code is placed as normally would in the code space.
25773 Upon interrupt request, the GOTO instruction is executed which jumps to
25775 When declaring interrupt functions as _naked this GOTO instruction is
25780 The whole interrupt functions is therefore placed at the Interrupt Vector
25781 Address of the specific interrupt.
25782 This is not a problem for the LOW priority interrupts, but it is a problem
25783 for the RESET and the HIGH priority interrupts because code may be written
25784 at the next interrupt´s vector address and cause undeterminate program
25785 behaviour if that interrupt is raised.
25789 \begin_layout Standard
25790 This is not a problem when
25793 \begin_layout Enumerate
25794 this is a HIGH interrupt ISR and LOW interrupts are
25801 \begin_layout Enumerate
25802 when the ISR is small enough not to reach the next interrupt´s vector address.
25810 \begin_layout Standard
25815 is possible to be omitted.
25816 This way a function is generated similar to an ISR, but it is not assigned
25820 \begin_layout Standard
25821 When entering an interrupt, currently the PIC16
25822 \begin_inset LatexCommand \index{PIC16}
25826 port automatically saves the following registers:
25829 \begin_layout Itemize
25833 \begin_layout Itemize
25837 \begin_layout Itemize
25841 \begin_layout Itemize
25842 PROD (PRODL and PRODH)
25845 \begin_layout Itemize
25846 FSR0 (FSR0L and FSR0H)
25849 \begin_layout Standard
25850 These registers are restored upon return from the interrupt routine.
25854 \begin_layout Standard
25855 NOTE that when the _naked attribute is specified for an interrupt routine,
25856 then NO registers are stored or restored.
25864 \begin_layout Subsection
25868 \begin_layout Standard
25869 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25870 There are 3 types of generic pointers currently implemented data, code
25871 and eeprom pointers.
25872 They are differentiated by the value of the 7th and 6th bits of the upper
25876 \begin_layout Standard
25878 \begin_inset Tabular
25879 <lyxtabular version="3" rows="5" columns="5">
25881 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25882 <column alignment="center" valignment="top" width="0">
25883 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25884 <column alignment="center" valignment="top" width="0">
25885 <column alignment="left" valignment="top" rightline="true" width="0">
25886 <row topline="true" bottomline="true">
25887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25890 \begin_layout Standard
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25899 \begin_layout Standard
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25908 \begin_layout Standard
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25917 \begin_layout Standard
25918 rest of the pointer
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25926 \begin_layout Standard
25933 <row topline="true" bottomline="true">
25934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25937 \begin_layout Standard
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25946 \begin_layout Standard
25952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25955 \begin_layout Standard
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25964 \begin_layout Standard
25969 uuuuuu uuuuxxxx xxxxxxxx
25974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25977 \begin_layout Standard
25978 a 12-bit data pointer in data RAM memory
25984 <row bottomline="true">
25985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25988 \begin_layout Standard
25994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25997 \begin_layout Standard
26003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26006 \begin_layout Standard
26012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26015 \begin_layout Standard
26020 uxxxxx xxxxxxxx xxxxxxxx
26025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26028 \begin_layout Standard
26029 a 21-bit code pointer in FLASH memory
26035 <row bottomline="true">
26036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26039 \begin_layout Standard
26045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26048 \begin_layout Standard
26054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26057 \begin_layout Standard
26063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26066 \begin_layout Standard
26071 uuuuuu uuuuuuxx xxxxxxxx
26076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26079 \begin_layout Standard
26080 a 10-bit eeprom pointer in EEPROM memory
26086 <row bottomline="true">
26087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26090 \begin_layout Standard
26096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26099 \begin_layout Standard
26105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26108 \begin_layout Standard
26114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26117 \begin_layout Standard
26122 xxxxxx xxxxxxxx xxxxxxxx
26127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26130 \begin_layout Standard
26131 unimplemented pointer type
26144 \begin_layout Standard
26145 Generic pointer are read and written with a set of library functions which
26146 read/write 1, 2, 3, 4 bytes.
26149 \begin_layout Subsection
26153 \begin_layout Subsubsection
26154 Standard I/O Streams
26157 \begin_layout Standard
26162 the type FILE is defined as:
26165 \begin_layout LyX-Code
26166 typedef char * FILE;
26169 \begin_layout Standard
26170 This type is the stream type implemented I/O in the PIC18F devices.
26171 Also the standard input and output streams are declared in stdio.h:
26174 \begin_layout LyX-Code
26175 extern FILE * stdin;
26178 \begin_layout LyX-Code
26179 extern FILE * stdout;
26182 \begin_layout Standard
26183 The FILE type is actually a generic pointer which defines one more type
26184 of generic pointers, the
26189 This new type has the format:
26192 \begin_layout Standard
26194 \begin_inset Tabular
26195 <lyxtabular version="3" rows="2" columns="7">
26197 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26198 <column alignment="center" valignment="top" width="0">
26199 <column alignment="center" valignment="top" leftline="true" width="0">
26200 <column alignment="center" valignment="top" leftline="true" width="0">
26201 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26202 <column alignment="center" valignment="top" width="0">
26203 <column alignment="left" valignment="top" rightline="true" width="0">
26204 <row topline="true" bottomline="true">
26205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26208 \begin_layout Standard
26214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26217 \begin_layout Standard
26223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26226 \begin_layout Standard
26232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26235 \begin_layout Standard
26241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26244 \begin_layout Standard
26250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26253 \begin_layout Standard
26254 rest of the pointer
26259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26262 \begin_layout Standard
26269 <row topline="true" bottomline="true">
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26273 \begin_layout Standard
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 \begin_layout Standard
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26291 \begin_layout Standard
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26300 \begin_layout Standard
26306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26309 \begin_layout Standard
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26318 \begin_layout Standard
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26331 \begin_layout Standard
26332 upper byte high nubble is 0x2n, the rest are zeroes
26345 \begin_layout Standard
26346 Currently implemented there are 3 types of streams defined:
26349 \begin_layout Standard
26351 \begin_inset Tabular
26352 <lyxtabular version="3" rows="4" columns="4">
26354 <column alignment="center" valignment="top" leftline="true" width="0">
26355 <column alignment="center" valignment="top" leftline="true" width="0">
26356 <column alignment="center" valignment="top" leftline="true" width="0">
26357 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26358 <row topline="true" bottomline="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" usebox="none">
26371 \begin_layout Standard
26377 <cell alignment="center" valignment="top" topline="true" leftline="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">
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" usebox="none">
26409 \begin_layout Standard
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26420 \begin_layout Standard
26426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26429 \begin_layout Standard
26430 Writes/Reads characters via the USART peripheral
26436 <row topline="true">
26437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26440 \begin_layout Standard
26446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26449 \begin_layout Standard
26457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26460 \begin_layout Standard
26466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26469 \begin_layout Standard
26470 Writes/Reads characters via the MSSP peripheral
26476 <row topline="true" bottomline="true">
26477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26480 \begin_layout Standard
26486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26489 \begin_layout Standard
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26500 \begin_layout Standard
26506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26509 \begin_layout Standard
26510 Writes/Reads characters via used defined functions
26523 \begin_layout Standard
26524 The stream identifiers are declared as macros in the stdio.h header.
26527 \begin_layout Standard
26528 In the libc library there exist the functions that are used to write to
26529 each of the above streams.
26533 \begin_layout Description
26538 \begin_layout Standard
26547 _stream_usart_putchar writes a character at the USART stream
26550 \begin_layout Description
26555 \begin_layout Standard
26564 _stream_mssp_putchar writes a character at the MSSP stream
26567 \begin_layout Description
26568 putchar dummy function.
26569 This writes a character to a user specified manner.
26572 \begin_layout Standard
26573 In order to increase performance
26577 is declared in stdio.h as having its parameter in WREG (it has the wparam
26579 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26580 in a user-friendly way.
26585 is the name of the variable that holds the character to print.
26586 An example follows:
26589 \begin_layout LyX-Code
26590 #include <pic18fregs.h>
26599 \begin_layout LyX-Code
26603 \begin_layout LyX-Code
26604 PORTA = c; /* dump character c to PORTA */
26607 \begin_layout LyX-Code
26615 \begin_layout LyX-Code
26619 \begin_layout LyX-Code
26620 stdout = STREAM_USER; /* this is not necessary, since stdout points
26623 \begin_layout LyX-Code
26624 * by default to STREAM_USER */
26627 \begin_layout LyX-Code
26629 \begin_inset Quotes sld
26632 This is a printf test
26635 \begin_inset Quotes srd
26641 \begin_layout LyX-Code
26645 \begin_layout LyX-Code
26649 \begin_layout Subsubsection
26653 \begin_layout Standard
26654 PIC16 contains an implementation of the printf-family of functions.
26655 There exist the following functions:
26658 \begin_layout LyX-Code
26659 extern unsigned int sprintf(char *buf, char *fmt, ...);
26662 \begin_layout LyX-Code
26663 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26666 \begin_layout LyX-Code
26670 \begin_layout LyX-Code
26671 extern unsigned int printf(char *fmt, ...);
26674 \begin_layout LyX-Code
26675 extern unsigned int vprintf(char *fmt, va_lista ap);
26678 \begin_layout LyX-Code
26682 \begin_layout LyX-Code
26683 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26686 \begin_layout LyX-Code
26687 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26690 \begin_layout Standard
26691 For sprintf and vsprintf
26695 should normally be a data pointer where the resulting string will be placed.
26696 No range checking is done so the user should allocate the necessery buffer.
26697 For fprintf and vfprintf
26701 should be a stream pointer (i.e.
26702 stdout, STREAM_MSSP, etc...).
26705 \begin_layout Subsubsection
26709 \begin_layout Standard
26710 The PIC18F family of microcontrollers supports a number of interrupt sources.
26711 A list of these interrupts is shown in the following table:
26714 \begin_layout Standard
26716 \begin_inset Tabular
26717 <lyxtabular version="3" rows="11" columns="4">
26719 <column alignment="left" valignment="top" leftline="true" width="0">
26720 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26721 <column alignment="left" valignment="top" leftline="true" width="0">
26722 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26723 <row topline="true" bottomline="true">
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26727 \begin_layout Standard
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26736 \begin_layout Standard
26742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26745 \begin_layout Standard
26751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26754 \begin_layout Standard
26761 <row topline="true">
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26765 \begin_layout Standard
26771 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26774 \begin_layout Standard
26775 PORTB change interrupt
26780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26783 \begin_layout Standard
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26792 \begin_layout Standard
26793 EEPROM/FLASH write complete interrupt
26799 <row topline="true">
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26803 \begin_layout Standard
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26812 \begin_layout Standard
26813 INT0 external interrupt
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26821 \begin_layout Standard
26827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26830 \begin_layout Standard
26831 Bus collision interrupt
26837 <row topline="true">
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26841 \begin_layout Standard
26847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26850 \begin_layout Standard
26851 INT1 external interrupt
26856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26859 \begin_layout Standard
26865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26868 \begin_layout Standard
26869 Low voltage detect interrupt
26875 <row topline="true">
26876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26879 \begin_layout Standard
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26888 \begin_layout Standard
26889 INT2 external interrupt
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26897 \begin_layout Standard
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26906 \begin_layout Standard
26907 Parallel slave port interrupt
26913 <row topline="true">
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26917 \begin_layout Standard
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26926 \begin_layout Standard
26927 CCP1 module interrupt
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26935 \begin_layout Standard
26941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26944 \begin_layout Standard
26945 AD convertion complete interrupt
26951 <row topline="true">
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26955 \begin_layout Standard
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26964 \begin_layout Standard
26965 CCP2 module interrupt
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26973 \begin_layout Standard
26979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26982 \begin_layout Standard
26983 USART receive interrupt
26989 <row topline="true">
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26993 \begin_layout Standard
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27002 \begin_layout Standard
27003 TMR0 overflow interrupt
27008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27011 \begin_layout Standard
27017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27020 \begin_layout Standard
27021 USART transmit interrupt
27027 <row topline="true">
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27031 \begin_layout Standard
27037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27040 \begin_layout Standard
27041 TMR1 overflow interrupt
27046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27049 \begin_layout Standard
27055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27058 \begin_layout Standard
27059 SSP receive/transmit interrupt
27065 <row topline="true">
27066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27069 \begin_layout Standard
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27078 \begin_layout Standard
27079 TMR2 matches PR2 interrupt
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27087 \begin_layout Standard
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27096 \begin_layout Standard
27103 <row topline="true" bottomline="true">
27104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27107 \begin_layout Standard
27113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27116 \begin_layout Standard
27117 TMR3 overflow interrupt
27122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27125 \begin_layout Standard
27131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27134 \begin_layout Standard
27148 \begin_layout Standard
27149 The prototypes for these names are defined in the header file
27156 \begin_layout Standard
27157 In order to simplify signal handling, a number of macros is provided:
27161 \labelwidthstring 00.00.0000
27162 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27163 high priority interrupts.
27168 is the function name to use.
27172 \labelwidthstring 00.00.0000
27173 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27174 low priority interrupt.
27179 is the function name to use.
27183 \labelwidthstring 00.00.0000
27184 DEF_HANDLER(sig,handler) define a handler for signal
27190 \labelwidthstring 00.00.0000
27191 END_DEF end the declaration of the dispatch table.
27194 \begin_layout Standard
27195 Additionally there are two more macros to simplify the declaration of the
27200 \labelwidthstring 00.00.0000
27203 SIGHANDLER(handler)
27205 this declares the function prototype for the
27213 \labelwidthstring 00.00.0000
27214 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27217 \begin_layout Standard
27218 An example of using the macros above is shown below:
27221 \begin_layout LyX-Code
27222 #include <pic18fregs.h>
27225 \begin_layout LyX-Code
27226 #include <signal.h>
27230 DEF_INTHIGH(high_int)
27233 \begin_layout LyX-Code
27234 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27237 \begin_layout LyX-Code
27238 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27241 \begin_layout LyX-Code
27246 SIGHANDLER(_tmr0_handler)
27249 \begin_layout LyX-Code
27253 \begin_layout LyX-Code
27254 /* action to be taken when timer 0 overflows */
27257 \begin_layout LyX-Code
27262 SIGHANDLERNAKED(_bcol_handler)
27265 \begin_layout LyX-Code
27269 \begin_layout LyX-Code
27273 \begin_layout LyX-Code
27274 /* action to be taken when bus collision occurs */
27277 \begin_layout LyX-Code
27281 \begin_layout LyX-Code
27285 \begin_layout LyX-Code
27289 \begin_layout Standard
27294 Special care should be taken when using the above scheme:
27297 \begin_layout Itemize
27298 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27301 \begin_layout Itemize
27302 when declaring SIGHANDLERNAKED handler never forget to use
27306 for proper returning.
27309 \begin_layout Subsection
27313 \begin_layout Standard
27314 Here you can find some general tips for compiling programs with SDCC/pic16.
27317 \begin_layout Subsubsection
27321 \begin_layout Standard
27323 \begin_inset LatexCommand \index{PIC16!stack}
27327 size (that is 64 bytes) probably is enough for many programs.
27328 One must take care that when there are many levels of function nesting,
27329 or there is excessive usage of stack, its size should be extended.
27330 An example of such a case is the printf/sprintf family of functions.
27331 If you encounter problems like not being able to print integers, then you
27332 need to set the stack size around the maximum (256 for small stack model).
27333 The following diagram shows what happens when calling printf to print an
27337 \begin_layout LyX-Code
27338 printf () --> ltoa () --> ultoa () --> divschar ()
27341 \begin_layout Standard
27342 It is should be understood that stack is easily consumed when calling complicate
27344 Using command line arguments like -
27348 \begin_layout Standard
27357 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27359 Other ways to reduce stack usage may exist.
27362 \begin_layout Subsection
27366 \begin_layout Standard
27367 The PIC16 Port currently does not pass SDCC's regression test
27368 \begin_inset LatexCommand \index{Regression test (PIC16)}
27373 \begin_inset LatexCommand \ref{sec:Quality-control}
27377 ) and thus the snapshot build regression tests for the PIC16 target are
27378 currently disabled for all hosts
27383 \begin_layout Chapter
27387 \begin_layout Standard
27388 There are several approaches to debugging your code.
27389 This chapter is meant to show your options and to give detail on some of
27394 When writing your code:
27397 \begin_layout Itemize
27398 write your code with debugging in mind (avoid duplicating code, put conceptually
27399 similar variables into structs, use structured code, have strategic points
27400 within your code where all variables are consistent, ...)
27403 \begin_layout Itemize
27404 run a syntax-checking tool like splint
27405 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27410 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27418 \begin_layout Standard
27428 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27435 \begin_layout Itemize
27436 for the high level code use a C-compiler (like f.e.
27437 GCC) to compile run and debug the code on your host.
27442 \begin_layout Standard
27452 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27456 ) on how to handle syntax extensions like __xdata, __at(), ...
27460 \begin_layout Itemize
27461 use another C-compiler to compile code for your target.
27462 Always an option but not recommended:) And not very likely to help you.
27463 If you seriously consider walking this path you should at least occasionally
27464 check portability of your code.
27465 Most commercial compiler vendors will offer an evaluation version so you
27466 can test compile your code or snippets of your code.
27469 \begin_layout Standard
27470 Debugging on a simulator:
27473 \begin_layout Itemize
27474 there is a separate section about SDCDB (section
27475 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27482 \begin_layout Itemize
27483 or (8051 specific) use a freeware/commercial simulator which interfaces
27485 \begin_inset LatexCommand \index{AOMF, AOMF51}
27490 \begin_inset LatexCommand \ref{OMF file}
27494 ) optionally generated by SDCC.
27497 \begin_layout Standard
27498 Debugging On-target:
27501 \begin_layout Itemize
27502 use a MCU port pin to serially output debug data to the RS232 port of your
27504 You'll probably want some level shifting device typically involving a MAX232
27506 If the hardware serial port of the MCU is not available search for 'Software
27507 UART' in your favourite search machine.
27510 \begin_layout Itemize
27511 use an on-target monitor.
27512 In this context a monitor is a small program which usually accepts commands
27513 via a serial line and allows to set program counter, to single step through
27514 a program and read/write memory locations.
27515 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27517 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27524 \begin_layout Itemize
27525 toggle MCU port pins at strategic points within your code and use an oscilloscop
27529 digital oscilloscope
27532 \begin_inset LatexCommand \index{Oscilloscope}
27536 with deep trace memory is really helpful especially if you have to debug
27537 a realtime application.
27538 If you need to monitor more pins than your oscilloscope provides you can
27539 sometimes get away with a small R-2R network.
27540 On a single channel oscilloscope you could f.e.
27541 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27543 \begin_inset Formula $\Omega$
27546 resistor and the other one by a 5\InsetSpace ~
27548 \begin_inset Formula $\Omega$
27551 resistor to the oscilloscope probe (check output drive capability of the
27552 pins you want to monitor).
27553 If you need to monitor many more pins a
27560 \begin_layout Itemize
27574 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27579 Usually very expensive.
27580 And very nice to have too.
27581 And usually locks you (for years...) to the devices the ICE can emulate.
27585 \begin_layout Itemize
27586 use a remote debugger.
27587 In most 8-bit systems the symbol information is not available on the target,
27588 and a complete debugger is too bulky for the target system.
27589 Therefore usually a debugger on the host system connects to an on-target
27590 debugging stub which accepts only primitive commands.
27593 Terms to enter into your favourite search engine could be 'remote debugging',
27594 'gdb stub' or 'inferior debugger'.
27598 \begin_layout Itemize
27599 use an on target hardware debugger.
27600 Some of the more modern MCUs include hardware support for setting break
27601 points and monitoring/changing variables by using dedicated hardware pins.
27602 This facility doesn't require additional code to run on the target and
27607 doesn't affect runtime behaviour until a breakpoint is hit.
27608 For the mcs51 most hardware debuggers use the AOMF
27609 \begin_inset LatexCommand \index{AOMF, AOMF51}
27614 \begin_inset LatexCommand \ref{OMF file}
27622 \begin_layout Standard
27626 \begin_layout Itemize
27627 if you are not familiar with any of the following terms you're likely to
27628 run into problems rather sooner than later:
27645 As an embedded programmer you
27649 to know them so why not look them up
27653 you have problems?)
27656 \begin_layout Itemize
27657 tell someone else about your problem (actually this is a surprisingly effective
27658 means to hunt down the bug even if the listener is not familiar with your
27660 As 'failure to communicate' is probably one of the job-induced deformations
27661 of an embedded programmer this is highly encouraged.
27664 \begin_layout Section
27665 Debugging with SDCDB
27666 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27671 \begin_inset LatexCommand \index{SDCDB (debugger)}
27678 \begin_layout Standard
27679 SDCC is distributed with a source level debugger
27680 \begin_inset LatexCommand \index{Debugger}
27685 The debugger uses a command line interface, the command repertoire of the
27686 debugger has been kept as close to gdb
27687 \begin_inset LatexCommand \index{gdb}
27691 (the GNU debugger) as possible.
27692 The configuration and build process is part of the standard compiler installati
27693 on, which also builds and installs the debugger in the target directory
27694 specified during configuration.
27695 The debugger allows you debug BOTH at the C source and at the ASM source
27699 \begin_layout Subsection
27700 Compiling for Debugging
27703 \begin_layout Standard
27708 \begin_layout Standard
27718 \begin_inset LatexCommand \index{-\/-debug}
27722 option must be specified for all files for which debug information is to
27724 The compiler generates a .adb file for each of these files.
27725 The linker creates the .cdb
27726 \begin_inset LatexCommand \index{<file>.cdb}
27731 \begin_inset LatexCommand \index{<file>.adb}
27735 files and the address information.
27736 This .cdb is used by the debugger.
27739 \begin_layout Subsection
27740 How the Debugger Works
27743 \begin_layout Standard
27748 \begin_layout Standard
27757 -debug option is specified the compiler generates extra symbol information
27758 some of which are put into the assembler source and some are put into the
27760 Then the linker creates the .cdb file from the individual .adb files with
27761 the address information for the symbols.
27762 The debugger reads the symbolic information generated by the compiler &
27763 the address information generated by the linker.
27764 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27765 execution is controlled by the debugger.
27766 When a command is issued for the debugger, it translates it into appropriate
27767 commands for the simulator.
27768 (Currently SDCDM only connects to the simulator but
27773 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27777 is an effort to connect directly to the hardware.)
27780 \begin_layout Subsection
27781 Starting the Debugger SDCDB
27784 \begin_layout Standard
27785 The debugger can be started using the following command line.
27786 (Assume the file you are debugging has the file name foo).
27800 The debugger will look for the following files.
27803 \begin_layout Itemize
27804 foo.c - the source file.
27807 \begin_layout Itemize
27808 foo.cdb - the debugger symbol information file.
27811 \begin_layout Itemize
27812 foo.ihx - the Intel hex format
27813 \begin_inset LatexCommand \index{Intel hex format}
27820 \begin_layout Subsection
27821 SDCDB Command Line Options
27824 \begin_layout Itemize
27829 \begin_layout Standard
27838 -directory=<source file directory> this option can used to specify the directory
27840 The debugger will look into the directory list specified for source, cdb
27842 The items in the directory list must be separated by ':', e.g.
27843 if the source files can be in the directories /home/src1 and /home/src2,
27848 \begin_layout Standard
27857 -directory option should be -
27861 \begin_layout Standard
27870 -directory=/home/src1:/home/src2.
27871 Note there can be no spaces in the option.
27875 \begin_layout Itemize
27876 -cd <directory> - change to the <directory>.
27879 \begin_layout Itemize
27880 -fullname - used by GUI front ends.
27883 \begin_layout Itemize
27884 -cpu <cpu-type> - this argument is passed to the simulator please see the
27885 simulator docs for details.
27888 \begin_layout Itemize
27889 -X <Clock frequency > this options is passed to the simulator please see
27890 the simulator docs for details.
27893 \begin_layout Itemize
27894 -s <serial port file> passed to simulator see the simulator docs for details.
27897 \begin_layout Itemize
27898 -S <serial in,out> passed to simulator see the simulator docs for details.
27901 \begin_layout Itemize
27902 -k <port number> passed to simulator see the simulator docs for details.
27905 \begin_layout Subsection
27906 SDCDB Debugger Commands
27909 \begin_layout Standard
27910 As mentioned earlier the command interface for the debugger has been deliberatel
27911 y kept as close the GNU debugger gdb, as possible.
27912 This will help the integration with existing graphical user interfaces
27913 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27914 If you use a graphical user interface for the debugger you can skip this
27918 \begin_layout Subsubsection*
27919 break [line | file:line | function | file:function]
27922 \begin_layout Standard
27923 Set breakpoint at specified line or function:
27932 sdcdb>break foo.c:100
27934 sdcdb>break funcfoo
27936 sdcdb>break foo.c:funcfoo
27939 \begin_layout Subsubsection*
27940 clear [line | file:line | function | file:function ]
27943 \begin_layout Standard
27944 Clear breakpoint at specified line or function:
27953 sdcdb>clear foo.c:100
27955 sdcdb>clear funcfoo
27957 sdcdb>clear foo.c:funcfoo
27960 \begin_layout Subsubsection*
27964 \begin_layout Standard
27965 Continue program being debugged, after breakpoint.
27968 \begin_layout Subsubsection*
27972 \begin_layout Standard
27973 Execute till the end of the current function.
27976 \begin_layout Subsubsection*
27980 \begin_layout Standard
27981 Delete breakpoint number 'n'.
27982 If used without any option clear ALL user defined break points.
27985 \begin_layout Subsubsection*
27986 info [break | stack | frame | registers ]
27989 \begin_layout Itemize
27990 info break - list all breakpoints
27993 \begin_layout Itemize
27994 info stack - show the function call stack.
27997 \begin_layout Itemize
27998 info frame - show information about the current execution frame.
28001 \begin_layout Itemize
28002 info registers - show content of all registers.
28005 \begin_layout Subsubsection*
28009 \begin_layout Standard
28010 Step program until it reaches a different source line.
28011 Note: pressing <return> repeats the last command.
28014 \begin_layout Subsubsection*
28018 \begin_layout Standard
28019 Step program, proceeding through subroutine calls.
28022 \begin_layout Subsubsection*
28026 \begin_layout Standard
28027 Start debugged program.
28030 \begin_layout Subsubsection*
28034 \begin_layout Standard
28035 Print type information of the variable.
28038 \begin_layout Subsubsection*
28042 \begin_layout Standard
28043 print value of variable.
28046 \begin_layout Subsubsection*
28050 \begin_layout Standard
28051 load the given file name.
28052 Note this is an alternate method of loading file for debugging.
28055 \begin_layout Subsubsection*
28059 \begin_layout Standard
28060 print information about current frame.
28063 \begin_layout Subsubsection*
28067 \begin_layout Standard
28068 Toggle between C source & assembly source.
28071 \begin_layout Subsubsection*
28072 ! simulator command
28075 \begin_layout Standard
28076 Send the string following '!' to the simulator, the simulator response is
28078 Note the debugger does not interpret the command being sent to the simulator,
28079 so if a command like 'go' is sent the debugger can loose its execution
28080 context and may display incorrect values.
28083 \begin_layout Subsubsection*
28087 \begin_layout Standard
28090 My name is Bobby Brown"
28093 \begin_layout Subsection
28094 Interfacing SDCDB with DDD
28097 \begin_layout Standard
28098 \begin_inset Note Note
28101 \begin_layout Standard
28102 The screenshot was converted from png to eps with:
28103 \begin_inset Quotes sld
28106 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28107 \begin_inset Quotes srd
28110 which produces a pretty compact eps file which is free from compression
28114 \begin_layout Standard
28115 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28116 as this broke the build system on Sourceforge (pdf-file was broken.
28117 pdflatex does not accept eps files).
28125 \begin_layout Standard
28141 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28147 shows a screenshot of a debugging session with DDD
28148 \begin_inset LatexCommand \index{DDD (debugger)}
28152 (Unix only) on a simulated 8032.
28153 The debugging session might not run as smoothly as the screenshot suggests.
28154 The debugger allows setting of breakpoints, displaying and changing variables,
28155 single stepping through C and assembler code.
28158 The source was compiled with
28172 \begin_layout Standard
28184 -debug ddd_example.c
28197 and DDD was invoked with
28204 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28207 \begin_layout Standard
28208 \begin_inset Note Note
28211 \begin_layout Standard
28212 Check that the double quotes or an apostroph within the command line survive
28213 the LyX tool chain.
28214 Previously the apostrophs got slanted in the PDF output so a cut and paste
28223 \begin_layout Subsection
28224 Interfacing SDCDB with XEmacs
28225 \begin_inset LatexCommand \index{XEmacs}
28230 \begin_inset LatexCommand \index{Emacs}
28237 \begin_layout Standard
28238 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28239 sdcdb.el and sdcdbsrc.el.
28240 These two files can be found in the $(prefix)/bin directory after the installat
28242 These files need to be loaded into XEmacs for the interface to work.
28243 This can be done at XEmacs startup time by inserting the following into
28244 your '.xemacs' file (which can be found in your HOME directory):
28250 (load-file sdcdbsrc.el)
28256 .xemacs is a lisp file so the () around the command is REQUIRED.
28257 The files can also be loaded dynamically while XEmacs is running, set the
28258 environment variable 'EMACSLOADPATH' to the installation bin directory
28259 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28260 To start the interface enter the following command:
28274 You will prompted to enter the file name to be debugged.
28279 The command line options that are passed to the simulator directly are
28280 bound to default values in the file sdcdbsrc.el.
28281 The variables are listed below, these values maybe changed as required.
28284 \begin_layout Itemize
28285 sdcdbsrc-cpu-type '51
28288 \begin_layout Itemize
28289 sdcdbsrc-frequency '11059200
28292 \begin_layout Itemize
28293 sdcdbsrc-serial nil
28296 \begin_layout Standard
28297 The following is a list of key mapping for the debugger interface.
28300 \begin_layout Standard
28323 binding\InsetSpace ~
28361 -------\InsetSpace ~
28432 sdcdb-back-from-src\InsetSpace ~
28461 rom-src\InsetSpace ~
28471 SDCDB continue command
28489 sdcdb-step-from-src\InsetSpace ~
28518 hatis-c-sexp\InsetSpace ~
28528 SDCDB ptypecommand for data at
28595 sdcdbsrc-delete\InsetSpace ~
28610 B Delete all breakpoints if no arg
28659 given or delete arg (C-u arg x)
28678 -frame\InsetSpace ~
28693 SDCDB Display current frame if no arg,
28742 given or display frame arg
28810 sdcdbsrc-goto-sdcdb\InsetSpace ~
28820 Goto the SDCDB output buffer
28839 t-c-sexp\InsetSpace ~
28850 SDCDB print command for data at
28917 sdcdbsrc-goto-sdcdb\InsetSpace ~
28928 o the SDCDB output buffer
28946 sdcdbsrc-mode\InsetSpace ~
28962 Toggles Sdcdbsrc mode (turns it
28978 sdcdb-finish-from-src\InsetSpace ~
28986 SDCDB finish command
29020 Set break for line with point
29035 sdcdbsrc-mode\InsetSpace ~
29051 Toggle Sdcdbsrc mode
29067 dbsrc-srcmode\InsetSpace ~
29091 \begin_layout Chapter
29095 \begin_layout Standard
29096 Here are a few guidelines that will help the compiler generate more efficient
29097 code, some of the tips are specific to this compiler others are generally
29098 good programming practice.
29101 \begin_layout Itemize
29102 Use the smallest data type to represent your data-value.
29103 If it is known in advance that the value is going to be less than 256 then
29104 use an 'unsigned char' instead of a 'short' or 'int'.
29105 Please note, that ANSI C requires both signed and unsigned chars to be
29106 promoted to 'signed int'
29107 \begin_inset LatexCommand \index{promotion to signed int}
29112 \begin_inset Marginal
29115 \begin_layout Standard
29124 before doing any operation.
29126 \begin_inset LatexCommand \index{type promotion}
29131 \begin_inset LatexCommand \label{type promotion}
29135 can be omitted, if the result is the same.
29136 The effect of the promotion rules together with the sign-extension is often
29141 \begin_layout Verse
29144 unsigned char uc = 0xfe;
29146 if (uc * uc < 0) /* this is true! */
29159 \begin_layout Standard
29166 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29174 \begin_layout Verse
29177 (unsigned char) -12 / (signed char) -3 = ...
29180 \begin_layout Standard
29181 No, the result is not 4:
29184 \begin_layout Verse
29187 (int) (unsigned char) -12 / (int) (signed char) -3 =
29189 (int) (unsigned char)
29190 0xf4 / (int) (signed char) 0xfd =
29192 (int) 0x00f4 / (int) 0xfffd =
29197 (int) 244 / (int) -3 =
29199 (int) -81 = (int) 0xffaf;
29202 \begin_layout Standard
29203 Don't complain, that gcc gives you a different result.
29204 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29205 Therefore the results are different.
29208 \begin_inset Quotes sld
29212 \begin_inset Quotes srd
29218 \begin_layout Quote
29221 If well-defined overflow characteristics are important and negative values
29222 are not, or if you want to steer clear of sign-extension problems when
29223 manipulating bits or bytes, use one of the corresponding unsigned types.
29224 (Beware when mixing signed and unsigned values in expressions, though.)
29227 character types (especially unsigned char) can be used as "tiny" integers,
29228 doing so is sometimes more trouble than it's worth, due to unpredictable
29229 sign extension and increased code size.
29233 \begin_layout Itemize
29234 Use unsigned when it is known in advance that the value is not going to
29236 This helps especially if you are doing division or multiplication, bit-shifting
29237 or are using an array index.
29240 \begin_layout Itemize
29241 NEVER jump into a LOOP.
29244 \begin_layout Itemize
29245 Declare the variables to be local
29246 \begin_inset LatexCommand \index{local variables}
29250 whenever possible, especially loop control variables (induction).
29253 \begin_layout Itemize
29254 Have a look at the assembly listing to get a
29255 \begin_inset Quotes sld
29259 \begin_inset Quotes srd
29262 for the code generation.
29265 \begin_layout Section
29266 Porting code from or to other compilers
29267 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29274 \begin_layout Itemize
29275 check whether endianness of the compilers differs and adapt where needed.
29278 \begin_layout Itemize
29279 check the device specific header files
29280 \begin_inset LatexCommand \index{Header files}
29285 \begin_inset LatexCommand \index{Include files}
29289 for compiler specific syntax.
29290 Eventually include the file <compiler.h
29291 \begin_inset LatexCommand \index{compiler.h (include file)}
29296 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29300 to allow using common header files.
29303 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29310 \begin_layout Itemize
29311 check whether the startup code contains the correct initialization (watchdog,
29315 \begin_layout Itemize
29316 check whether the sizes of short, int, long match.
29319 \begin_layout Itemize
29320 check if some 16 or 32 bit hardware registers require a specific addressing
29321 order (least significant or most significant byte first) and adapt if needed
29330 relate to time and not to lower/upper memory location here, so this is
29335 the same as endianness).
29338 \begin_layout Itemize
29339 check whether the keyword
29343 is used where needed.
29344 The compilers might differ in their optimization characteristics (as different
29345 versions of the same compiler might also use more clever optimizations
29346 this is good idea anyway).
29348 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29355 \begin_layout Itemize
29356 check that the compilers are not told to supress warnings.
29359 \begin_layout Itemize
29360 check and convert compiler specific extensions (interrupts, memory areas,
29364 \begin_layout Itemize
29365 check for differences in type promotion.
29366 Especially check for math operations on
29375 For the sake of C99 compatibility SDCC will probably promote these to
29379 more often than other compilers.
29380 Eventually insert explicit casts to
29389 Also check that the ~\InsetSpace ~
29391 \begin_inset LatexCommand \index{\~\/ Operator}
29398 \begin_inset LatexCommand \index{bit}
29404 variables, use the !\InsetSpace ~
29407 \begin_inset LatexCommand \ref{type promotion}
29412 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29419 \begin_layout Itemize
29420 check the assembly code generated for interrupt routines (f.e.
29421 for calls to possibly non-reentrant library functions).
29424 \begin_layout Itemize
29425 check whether timing loops result in proper timing (or preferably consider
29426 a rewrite of the code with timer based delays instead).
29429 \begin_layout Itemize
29430 check for differences in printf parameters (some compilers push (va_arg
29431 \begin_inset LatexCommand \index{vararg, va\_arg}
29435 ) char variables as
29439 others push them as
29445 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29452 \begin_layout Itemize
29453 check the resulting memory map
29454 \begin_inset LatexCommand \index{Memory map}
29459 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29460 ly idata, pdata, xdata).
29461 Eventually check if unexpected library functions are included.
29464 \begin_layout Section
29466 \begin_inset LatexCommand \index{Tools}
29470 included in the distribution
29473 \begin_layout Standard
29475 \begin_inset Tabular
29476 <lyxtabular version="3" rows="12" columns="3">
29478 <column alignment="left" valignment="top" leftline="true" width="0pt">
29479 <column alignment="left" valignment="top" leftline="true" width="0pt">
29480 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29481 <row topline="true" bottomline="true">
29482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29485 \begin_layout Standard
29493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29496 \begin_layout Standard
29504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29507 \begin_layout Standard
29516 <row topline="true">
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29520 \begin_layout Standard
29522 \begin_inset LatexCommand \index{uCsim}
29531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29534 \begin_layout Standard
29535 Simulator for various architectures
29540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29543 \begin_layout Standard
29550 <row topline="true">
29551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29554 \begin_layout Standard
29560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29563 \begin_layout Standard
29565 \begin_inset LatexCommand \index{Header files}
29570 \begin_inset LatexCommand \index{Include files}
29579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29582 \begin_layout Standard
29583 sdcc/support/scripts
29589 <row topline="true">
29590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29593 \begin_layout Standard
29599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29602 \begin_layout Standard
29603 header file conversion
29608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29611 \begin_layout Standard
29612 sdcc/support/scripts
29618 <row topline="true">
29619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29622 \begin_layout Standard
29628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29631 \begin_layout Standard
29637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29640 \begin_layout Standard
29656 <row topline="true">
29657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29660 \begin_layout Standard
29666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29669 \begin_layout Standard
29675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29678 \begin_layout Standard
29694 <row topline="true">
29695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29698 \begin_layout Standard
29704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29707 \begin_layout Standard
29713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29716 \begin_layout Standard
29732 <row topline="true">
29733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29736 \begin_layout Standard
29742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29745 \begin_layout Standard
29751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29754 \begin_layout Standard
29770 <row topline="true">
29771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29774 \begin_layout Standard
29780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29783 \begin_layout Standard
29789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29792 \begin_layout Standard
29808 <row topline="true">
29809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29812 \begin_layout Standard
29818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29821 \begin_layout Standard
29827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29830 \begin_layout Standard
29846 <row topline="true">
29847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29850 \begin_layout Standard
29856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29859 \begin_layout Standard
29865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29868 \begin_layout Standard
29884 <row topline="true" bottomline="true">
29885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29888 \begin_layout Standard
29894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29897 \begin_layout Standard
29899 \begin_inset LatexCommand \index{packihx (tool)}
29908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29911 \begin_layout Standard
29936 \begin_layout Section
29938 \begin_inset LatexCommand \index{Documentation}
29942 included in the distribution
29945 \begin_layout Standard
29947 \begin_inset Tabular
29948 <lyxtabular version="3" rows="10" columns="2">
29950 <column alignment="block" valignment="top" leftline="true" width="40col%">
29951 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29952 <row topline="true" bottomline="true" endhead="true">
29953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29956 \begin_layout Standard
29964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29967 \begin_layout Standard
29970 Filename / Where to get
29976 <row topline="true">
29977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29980 \begin_layout Standard
29981 SDCC Compiler User Guide
29986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29989 \begin_layout Standard
29990 You're reading it right now
30002 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30012 <row topline="true">
30013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30016 \begin_layout Standard
30022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30025 \begin_layout Standard
30038 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30048 <row topline="true">
30049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30052 \begin_layout Standard
30054 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30059 \begin_inset LatexCommand \index{Assembler documentation}
30066 \begin_inset LatexCommand \index{aslink}
30071 \begin_inset LatexCommand \index{Linker documentation}
30080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30083 \begin_layout Standard
30084 sdcc/as/doc/asxhtm.html
30096 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30106 <row topline="true">
30107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30110 \begin_layout Standard
30111 SDCC regression test
30112 \begin_inset LatexCommand \index{Regression test}
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30124 \begin_layout Standard
30125 sdcc/doc/test_suite_spec.pdf
30137 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30147 <row topline="true">
30148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30151 \begin_layout Standard
30157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30160 \begin_layout Standard
30173 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30183 <row topline="true">
30184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30187 \begin_layout Standard
30188 Notes on debugging with SDCDB
30189 \begin_inset LatexCommand \index{SDCDB (debugger)}
30198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30201 \begin_layout Standard
30202 sdcc/debugger/README
30214 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30224 <row topline="true">
30225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30228 \begin_layout Standard
30230 \begin_inset LatexCommand \index{uCsim}
30234 Software simulator for microcontrollers
30239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30242 \begin_layout Standard
30272 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30282 <row topline="true">
30283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30286 \begin_layout Standard
30287 Temporary notes on the pic16
30288 \begin_inset LatexCommand \index{PIC16}
30297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30300 \begin_layout Standard
30301 sdcc/src/pic16/NOTES
30313 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30323 <row topline="true" bottomline="true">
30324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30327 \begin_layout Standard
30328 SDCC internal documentation (debugging file format)
30333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30336 \begin_layout Standard
30366 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30385 \begin_layout Section
30386 Related open source tools
30387 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30392 \begin_inset LatexCommand \index{Related tools}
30399 \begin_layout Standard
30401 \begin_inset Tabular
30402 <lyxtabular version="3" rows="14" columns="3">
30404 <column alignment="left" valignment="top" leftline="true" width="0pt">
30405 <column alignment="block" valignment="top" leftline="true" width="30line%">
30406 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30407 <row topline="true" bottomline="true">
30408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30411 \begin_layout Standard
30419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30422 \begin_layout Standard
30430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30433 \begin_layout Standard
30442 <row topline="true">
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30446 \begin_layout Standard
30448 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30460 \begin_layout Standard
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30469 \begin_layout Standard
30470 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30480 <row topline="true">
30481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30484 \begin_layout Standard
30486 \begin_inset LatexCommand \index{gputils (pic tools)}
30495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30498 \begin_layout Standard
30504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30507 \begin_layout Standard
30508 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30518 <row topline="true">
30519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30522 \begin_layout Standard
30528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30531 \begin_layout Standard
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30540 \begin_layout Standard
30541 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30551 <row topline="true">
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30555 \begin_layout Standard
30561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30564 \begin_layout Standard
30565 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30574 \begin_layout Standard
30575 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30585 <row topline="true">
30586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30589 \begin_layout Standard
30591 \begin_inset LatexCommand \index{indent (source formatting tool)}
30600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30603 \begin_layout Standard
30604 Formats C source - Master of the white spaces
30609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30612 \begin_layout Standard
30613 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30623 <row topline="true">
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30627 \begin_layout Standard
30629 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30641 \begin_layout Standard
30642 Object file conversion, checksumming, ...
30647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30650 \begin_layout Standard
30651 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30661 <row topline="true">
30662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30665 \begin_layout Standard
30667 \begin_inset LatexCommand \index{objdump (tool)}
30676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30679 \begin_layout Standard
30680 Object file conversion, ...
30685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30688 \begin_layout Standard
30689 Part of binutils (should be there anyway)
30695 <row topline="true">
30696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30699 \begin_layout Standard
30705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30708 \begin_layout Standard
30709 8051 monitor (hex up-/download, single step, disassemble)
30714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30717 \begin_layout Standard
30718 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30728 <row topline="true">
30729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30732 \begin_layout Standard
30734 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30746 \begin_layout Standard
30747 Source code documentation system
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30755 \begin_layout Standard
30756 \begin_inset LatexCommand \url{http://www.doxygen.org}
30766 <row topline="true">
30767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30770 \begin_layout Standard
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30779 \begin_layout Standard
30780 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30788 \begin_layout Standard
30789 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30799 <row topline="true">
30800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30803 \begin_layout Standard
30809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30812 \begin_layout Standard
30813 8051 monitor (hex up-/download, single step, disassemble)
30818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30821 \begin_layout Standard
30822 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30832 <row topline="true">
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30836 \begin_layout Standard
30838 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30850 \begin_layout Standard
30851 Statically checks c sources (see
30852 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30864 \begin_layout Standard
30865 \begin_inset LatexCommand \url{http://www.splint.org}
30875 <row topline="true" bottomline="true">
30876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30879 \begin_layout Standard
30881 \begin_inset LatexCommand \index{DDD (debugger)}
30890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30893 \begin_layout Standard
30894 Debugger, serves nicely as GUI to SDCDB
30895 \begin_inset LatexCommand \index{SDCDB (debugger)}
30904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30907 \begin_layout Standard
30908 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30927 \begin_layout Section
30928 Related documentation / recommended reading
30931 \begin_layout Standard
30933 \begin_inset Tabular
30934 <lyxtabular version="3" rows="7" columns="3">
30936 <column alignment="left" valignment="top" leftline="true" width="0pt">
30937 <column alignment="left" valignment="top" leftline="true" width="0">
30938 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30939 <row topline="true" bottomline="true">
30940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30943 \begin_layout Standard
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30954 \begin_layout Standard
30962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30965 \begin_layout Standard
30974 <row topline="true">
30975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30978 \begin_layout Standard
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30996 \begin_layout Standard
30998 \begin_inset LatexCommand \index{C Reference card}
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31010 \begin_layout Standard
31011 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31021 <row topline="true">
31022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31025 \begin_layout Standard
31031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31034 \begin_layout Standard
31036 \begin_inset LatexCommand \index{C FAQ}
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31048 \begin_layout Standard
31049 \begin_inset LatexCommand \url{http://www.c-faq.com}
31059 <row topline="true">
31060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31063 \begin_layout Standard
31069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31072 \begin_layout Standard
31073 \begin_inset Quotes sld
31077 \begin_inset Quotes srd
31085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31088 \begin_layout Standard
31091 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31101 <row topline="true">
31102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31105 \begin_layout Standard
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31114 \begin_layout Standard
31115 \begin_inset Quotes sld
31118 Extensions for Embedded C
31119 \begin_inset Quotes srd
31127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31130 \begin_layout Standard
31133 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31143 <row topline="true">
31144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31147 \begin_layout Standard
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31156 \begin_layout Standard
31157 Latest datasheet of target CPU
31162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31165 \begin_layout Standard
31172 <row topline="true" bottomline="true">
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31176 \begin_layout Standard
31182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31185 \begin_layout Standard
31186 Revision history of datasheet
31191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31194 \begin_layout Standard
31210 \begin_layout Section
31211 Application notes specifically for SDCC
31214 \begin_layout Standard
31215 SDCC makes no claims about the completeness of this list and about up-to-datenes
31216 s or correctness of the application notes
31217 \begin_inset LatexCommand \index{Application notes}
31224 \begin_layout Standard
31228 \begin_inset Tabular
31229 <lyxtabular version="3" rows="7" columns="3">
31231 <column alignment="block" valignment="top" leftline="true" width="17col%">
31232 <column alignment="block" valignment="top" leftline="true" width="27col%">
31233 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31234 <row topline="true" bottomline="true">
31235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31238 \begin_layout Standard
31247 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31250 \begin_layout Standard
31259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31262 \begin_layout Standard
31272 <row topline="true">
31273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31276 \begin_layout Standard
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31287 \begin_layout Standard
31290 Using the SDCC Compiler for the DS80C400
31291 \begin_inset LatexCommand \index{DS80C400}
31300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31303 \begin_layout Standard
31306 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31316 <row topline="true">
31317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31320 \begin_layout Standard
31328 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31331 \begin_layout Standard
31334 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31335 \begin_inset LatexCommand \index{DS89C4x0}
31339 Family of Microcontrollers
31344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31347 \begin_layout Standard
31350 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31360 <row topline="true">
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31364 \begin_layout Standard
31367 Silicon Laboratories / Cygnal
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31375 \begin_layout Standard
31378 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31379 \begin_inset LatexCommand \index{IDE}
31388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31391 \begin_layout Standard
31394 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31404 <row topline="true">
31405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31408 \begin_layout Standard
31411 Ramtron / Goal Semiconductor
31416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31419 \begin_layout Standard
31422 Interfacing SDCC to Syn and Textpad
31427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31430 \begin_layout Standard
31433 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31443 <row topline="true">
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31447 \begin_layout Standard
31450 Ramtron / Goal Semiconductor
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31458 \begin_layout Standard
31461 Installing and Configuring SDCC and Crimson Editor
31466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31469 \begin_layout Standard
31472 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31482 <row topline="true" bottomline="true">
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31486 \begin_layout Standard
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31497 \begin_layout Standard
31500 MSC12xx Programming with SDCC
31505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31508 \begin_layout Standard
31511 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31528 \begin_layout Section
31532 \begin_layout Standard
31533 Some questions answered, some pointers given - it might be time to in turn
31541 \begin_layout Itemize
31542 can you solve your project with the selected microcontroller? Would you
31543 find out early or rather late that your target is too small/slow/whatever?
31544 Can you switch to a slightly better device if it doesn't fit?
31547 \begin_layout Itemize
31548 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31549 and/or another programming language be more adequate? Would an operating
31550 system on the target device help?
31553 \begin_layout Itemize
31554 if you solved the problem, will the marketing department be happy?
31557 \begin_layout Itemize
31558 if the marketing department is happy, will customers be happy?
31561 \begin_layout Itemize
31562 if you're the project manager, marketing department and maybe even the customer
31563 in one person, have you tried to see the project from the outside?
31566 \begin_layout Itemize
31567 is the project done if you think it is done? Or is just that other interface/pro
31568 tocol/feature/configuration/option missing? How about website, manual(s),
31569 internationali(z|s)ation, packaging, labels, 2nd source for components,
31570 electromagnetic compatability/interference, documentation for production,
31571 production test software, update mechanism, patent issues?
31574 \begin_layout Itemize
31575 is your project adequately positioned in that magic triangle: fame, fortune,
31579 \begin_layout Standard
31580 Maybe not all answers to these questions are known and some answers may
31585 , nevertheless knowing these questions may help you to avoid burnout
31589 \begin_layout Standard
31590 burnout is bad for electronic devices, programmers and motorcycle tyres
31596 Chances are you didn't want to hear some of them...
31599 \begin_layout Chapter
31601 \begin_inset LatexCommand \index{Support}
31608 \begin_layout Standard
31609 SDCC has grown to be a large project.
31610 The compiler alone (without the preprocessor, assembler and linker) is
31611 well over 150,000 lines of code (blank stripped).
31612 The open source nature of this project is a key to its continued growth
31614 You gain the benefit and support of many active software developers and
31616 Is SDCC perfect? No, that's why we need your help.
31617 The developers take pride in fixing reported bugs.
31618 You can help by reporting the bugs and helping other SDCC users.
31619 There are lots of ways to contribute, and we encourage you to take part
31620 in making SDCC a great software package.
31624 \begin_layout Standard
31625 The SDCC project is hosted on the SDCC sourceforge site at
31626 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31631 You'll find the complete set of mailing lists
31632 \begin_inset LatexCommand \index{Mailing list(s)}
31636 , forums, bug reporting system, patch submission
31637 \begin_inset LatexCommand \index{Patch submission}
31642 \begin_inset LatexCommand \index{download}
31646 area and Subversion code repository
31647 \begin_inset LatexCommand \index{Subversion code repository}
31654 \begin_layout Section
31656 \begin_inset LatexCommand \index{Bug reporting}
31661 \begin_inset LatexCommand \index{Reporting bugs}
31668 \begin_layout Standard
31669 The recommended way of reporting bugs is using the infrastructure of the
31671 You can follow the status of bug reports there and have an overview about
31675 \begin_layout Standard
31676 Bug reports are automatically forwarded to the developer mailing list and
31677 will be fixed ASAP.
31678 When reporting a bug, it is very useful to include a small test program
31679 (the smaller the better) which reproduces the problem.
31680 If you can isolate the problem by looking at the generated assembly code,
31681 this can be very helpful.
31682 Compiling your program with the -
31686 \begin_layout Standard
31696 \begin_inset LatexCommand \index{-\/-dumpall}
31700 option can sometimes be useful in locating optimization problems.
31701 When reporting a bug please make sure you:
31704 \begin_layout Enumerate
31705 Attach the code you are compiling with SDCC.
31709 \begin_layout Enumerate
31710 Specify the exact command you use to run SDCC, or attach your Makefile.
31714 \begin_layout Enumerate
31715 Specify the SDCC version (type "
31721 "), your platform, and operating system.
31725 \begin_layout Enumerate
31726 Provide an exact copy of any error message or incorrect output.
31730 \begin_layout Enumerate
31731 Put something meaningful in the subject of your message.
31734 \begin_layout Standard
31735 Please attempt to include these 5 important parts, as applicable, in all
31736 requests for support or when reporting any problems or bugs with SDCC.
31737 Though this will make your message lengthy, it will greatly improve your
31738 chance that SDCC users and developers will be able to help you.
31739 Some SDCC developers are frustrated by bug reports without code provided
31740 that they can use to reproduce and ultimately fix the problem, so please
31741 be sure to provide sample code if you are reporting a bug!
31744 \begin_layout Standard
31745 Please have a short check that you are using a recent version of SDCC and
31746 the bug is not yet known.
31747 This is the link for reporting bugs:
31748 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31753 With SDCC on average having more than 200 downloads
31754 \begin_inset LatexCommand \index{download}
31758 on sourceforge per day
31762 \begin_layout Standard
31763 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31764 between 2002 and 2005.
31765 This does not include other methods of distribution.
31770 there must be some users.
31771 So it's not exactly easy to find a new bug.
31772 If you find one we need it:
31774 reporting bugs is good
31779 \begin_layout Section
31780 Requesting Features
31781 \begin_inset LatexCommand \label{sub:Requesting-Features}
31786 \begin_inset LatexCommand \index{Feature request}
31791 \begin_inset LatexCommand \index{Requesting features}
31798 \begin_layout Standard
31799 Like bug reports feature requests are forwarded to the developer mailing
31801 This is the link for requesting features:
31802 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31809 \begin_layout Section
31813 \begin_layout Standard
31814 Like bug reports contributed patches are forwarded to the developer mailing
31816 This is the link for submitting patches
31817 \begin_inset LatexCommand \index{Patch submission}
31822 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31829 \begin_layout Standard
31830 You need to specify some parameters to the
31834 command for the patches to be useful.
31835 If you modified more than one file a patch created f.e.
31840 \begin_inset Quotes sld
31843 diff -Naur unmodified_directory modified_directory >my_changes.patch
31844 \begin_inset Quotes srd
31850 will be fine, otherwise
31854 \begin_inset Quotes sld
31857 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31858 \begin_inset Quotes srd
31868 \begin_layout Section
31872 \begin_layout Standard
31873 These links should take you directly to the
31874 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31882 \begin_layout Standard
31883 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31884 automated messages (mid 2003)
31890 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31895 \begin_inset LatexCommand \index{Mailing list(s)}
31899 and forums are archived and searchable so if you are lucky someone already
31900 had a similar problem.
31901 While mails to the lists themselves are delivered promptly their web front
31902 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31903 if you're seriously using SDCC please consider subscribing to the lists.
31906 \begin_layout Section
31910 \begin_layout Standard
31911 You can follow the status of the Subversion version
31912 \begin_inset LatexCommand \index{version}
31916 of SDCC by watching the Changelog
31917 \begin_inset LatexCommand \index{Changelog}
31921 in the Subversion repository
31924 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31931 \begin_layout Section
31932 Subversion Source Code Repository
31935 \begin_layout Standard
31942 or the filenames of the snapshot versions of SDCC include date and its
31944 \begin_inset LatexCommand \index{Subversion code repository}
31949 Subversion allows to download the source of recent or previous versions
31951 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31955 (by number or by date).
31956 An on-line source code browser and detailled instructions are also available
31958 SDCC versions starting from 1999 up to now are available (currently the
31959 versions prior to the conversion from cvs
31960 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31964 to Subversion (April 2006) are either by accessible by Subversion or by
31968 \begin_layout Section
31970 \begin_inset LatexCommand \index{Release policy}
31977 \begin_layout Standard
31978 Historically there often were long delays between official releases and
31979 the sourceforge download area tends to get not updated at all.
31980 Excuses in the past might have referred to problems with live range analysis,
31981 but as this was fixed a while ago, the current problem is that another
31982 excuse has to be found.
31983 Kidding aside, we have to get better there! On the other hand there are
31984 daily snapshots available at
31985 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31989 , and you can always build the very last version (hopefully with many bugs
31990 fixed, and features added) from the source code available at
31991 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31997 \begin_inset LatexCommand \index{wiki}
32002 \begin_inset LatexCommand \index{Release wiki}
32007 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32011 also holds some information about past and future releases.
32014 \begin_layout Section
32016 \begin_inset LatexCommand \index{Examples}
32023 \begin_layout Standard
32024 You'll find some small examples in the directory
32026 sdcc/device/examples/.
32029 More examples and libraries are available at
32031 The SDCC Open Knowledge Resource
32032 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32039 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32046 \begin_layout Standard
32047 \begin_inset Note Note
32050 \begin_layout Standard
32051 I did insert a reference to Paul's web site here although it seems rather
32052 dedicated to a specific 8032 board (I think it's okay because it f.e.
32053 shows LCD/Harddisc interface and has a free 8051 monitor.
32054 Independent 8032 board vendors face hard competition of heavily subsidized
32055 development boards anyway).
32058 \begin_layout Standard
32059 Maybe we should include some links to real world applications.
32060 Preferably pointer to pointers (one for each architecture) so this stays
32069 \begin_layout Section
32071 \begin_inset LatexCommand \label{sec:Quality-control}
32076 \begin_inset LatexCommand \index{Quality control}
32083 \begin_layout Standard
32084 The compiler is passed through snaphot build compile and build checks.
32090 \begin_inset LatexCommand \index{Regression test}
32094 check that SDCC itself compiles flawlessly on several host platforms (i386,
32095 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32096 the quality of the code generated by SDCC by running the code for several
32097 target platforms through simulators.
32098 The regression test suite comprises more than 100 files which expand to
32099 more than 500 test cases which include more than 4500 tests.
32100 The results of these tests are published daily on SDCC's snapshot page
32101 (click on the red or green symbols on the right side of
32102 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32109 \begin_layout Standard
32110 There is a separate document
32113 \begin_inset LatexCommand \index{Test suite}
32120 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32124 about the regression test suite.
32127 \begin_layout Standard
32128 You'll find the test code in the directory
32130 sdcc/support/regression
32133 You can run these tests manually by running
32137 in this directory (or f.e.
32142 \begin_inset Quotes sld
32146 \begin_inset Quotes srd
32152 if you don't want to run the complete tests).
32153 The test code might also be interesting if you want to look for examples
32154 \begin_inset LatexCommand \index{Examples}
32158 checking corner cases of SDCC or if you plan to submit patches
32159 \begin_inset LatexCommand \index{Patch submission}
32166 \begin_layout Standard
32167 The PIC14 port uses a different set of regression tests
32168 \begin_inset LatexCommand \index{Regression test (PIC14)}
32172 , you'll find them in the directory
32174 sdcc/src/regression
32179 \begin_layout Section
32180 Use of SDCC in Education
32183 \begin_layout Standard
32192 \begin_layout Standard
32193 the phrase "use in education" might evoke the association "
32197 fit for use in education".
32198 This connotation is not intended but nevertheless risked as the licensing
32199 of SDCC makes it difficult to offer educational discounts
32205 If your rationales are to:
32208 \begin_layout Enumerate
32209 give students a chance to understand the
32213 steps of code generation
32216 \begin_layout Enumerate
32217 have a curriculum that can be extended for years.
32218 Then you could use an fpga board as target and your curriculum will seamlessly
32219 extend from logic synthesis (
32220 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32225 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32229 ), over assembly programming, to C to FPGA compilers (
32230 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32237 \begin_layout Enumerate
32238 be able to insert excursions about skills like using a revision control
32239 system, submitting/applying patches, using a type-setting (as opposed to
32240 word-processing) engine LyX/LaTeX, using
32241 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32246 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32250 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32251 Source Software, CPU simulation, compiler regression tests
32252 \begin_inset LatexCommand \index{Regression test}
32259 And if there should be a shortage of ideas then you can always point students
32260 to the ever-growing feature request list
32261 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32268 \begin_layout Enumerate
32269 not tie students to a specific host platform and instead allow them to use
32274 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32276 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32283 \begin_layout Enumerate
32284 not encourage students to use illegal copies of educational software
32287 \begin_layout Enumerate
32288 be immune to licensing/availability/price changes of the chosen tool chain
32291 \begin_layout Enumerate
32292 be able to change to a new target platform without having to adopt a new
32296 \begin_layout Enumerate
32297 have complete control over and insight into the tool chain
32300 \begin_layout Enumerate
32301 make your students aware about the pros and cons of open source software
32305 \begin_layout Enumerate
32306 give back to the public as you are probably at least partially publically
32310 \begin_layout Enumerate
32311 give students a chance to publically prove their skills and to possibly
32312 see a world wide impact
32315 \begin_layout Standard
32316 then SDCC is probably among the first choices.
32317 Well, probably SDCC might be the only choice.
32322 \begin_layout Chapter
32323 SDCC Technical Data
32326 \begin_layout Section
32328 \begin_inset LatexCommand \index{Optimizations}
32335 \begin_layout Standard
32336 SDCC performs a host of standard optimizations in addition to some MCU specific
32341 \begin_layout Subsection
32342 Sub-expression Elimination
32343 \begin_inset LatexCommand \index{Subexpression elimination}
32350 \begin_layout Standard
32351 The compiler does local and
32370 \begin_layout Verse
32378 \begin_layout Standard
32379 will be translated to
32382 \begin_layout Verse
32392 \begin_layout Standard
32393 Some subexpressions are not as obvious as the above example, e.g.:
32396 \begin_layout Verse
32404 \begin_layout Standard
32405 In this case the address arithmetic a->b[i] will be computed only once;
32406 the equivalent code in C would be.
32409 \begin_layout Verse
32419 \begin_layout Standard
32420 The compiler will try to keep these temporary variables in registers.
32423 \begin_layout Subsection
32424 Dead-Code Elimination
32425 \begin_inset LatexCommand \index{Dead-code elimination}
32432 \begin_layout Verse
32447 i = 1; \InsetSpace ~
32456 global = 1;\InsetSpace ~
32470 global = 3;\InsetSpace ~
32476 \begin_layout Standard
32480 \begin_layout Verse
32496 \begin_layout Subsection
32498 \begin_inset LatexCommand \index{Copy propagation}
32505 \begin_layout Verse
32529 \begin_layout Standard
32533 \begin_layout Verse
32557 \begin_layout Standard
32558 Note: the dead stores created by this copy propagation will be eliminated
32559 by dead-code elimination.
32562 \begin_layout Subsection
32564 \begin_inset LatexCommand \index{Loop optimization}
32569 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32576 \begin_layout Standard
32577 Two types of loop optimizations are done by SDCC
32585 of loop induction variables.
32586 In addition to the strength reduction the optimizer marks the induction
32587 variables and the register allocator tries to keep the induction variables
32588 in registers for the duration of the loop.
32589 Because of this preference of the register allocator
32590 \begin_inset LatexCommand \index{Register allocation}
32594 , loop induction optimization causes an increase in register pressure, which
32595 may cause unwanted spilling of other temporary variables into the stack
32596 \begin_inset LatexCommand \index{stack}
32601 The compiler will generate a warning message when it is forced to allocate
32602 extra space either on the stack or data space.
32603 If this extra space allocation is undesirable then induction optimization
32604 can be eliminated either for the entire source file (with -
32608 \begin_layout Standard
32617 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32619 \begin_inset LatexCommand \index{\#pragma noinduction}
32630 \begin_layout Verse
32633 for (i = 0 ; i < 100 ; i ++)
32642 \begin_layout Standard
32646 \begin_layout Verse
32651 for (i = 0; i < 100; i++)
32660 \begin_layout Standard
32661 As mentioned previously some loop invariants are not as apparent, all static
32662 address computations are also moved out of the loop.
32667 \begin_inset LatexCommand \index{Strength reduction}
32671 , this optimization substitutes an expression by a cheaper expression:
32674 \begin_layout Verse
32677 for (i=0;i < 100; i++)
32686 \begin_layout Standard
32690 \begin_layout Verse
32697 for (i=0;i< 100;i++) {
32703 ar[itemp1] = itemp2;
32721 \begin_layout Standard
32722 The more expensive multiplication
32723 \begin_inset LatexCommand \index{Multiplication}
32727 is changed to a less expensive addition.
32730 \begin_layout Subsection
32732 \begin_inset LatexCommand \index{Loop reversing}
32739 \begin_layout Standard
32740 This optimization is done to reduce the overhead of checking loop boundaries
32741 for every iteration.
32742 Some simple loops can be reversed and implemented using a
32743 \begin_inset Quotes eld
32746 decrement and jump if not zero
32747 \begin_inset Quotes erd
32751 SDCC checks for the following criterion to determine if a loop is reversible
32752 (note: more sophisticated compilers use data-dependency analysis to make
32753 this determination, SDCC uses a more simple minded analysis).
32756 \begin_layout Itemize
32757 The 'for' loop is of the form
32763 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32773 \begin_layout Itemize
32774 The <for body> does not contain
32775 \begin_inset Quotes eld
32779 \begin_inset Quotes erd
32783 \begin_inset Quotes erd
32789 \begin_layout Itemize
32790 All goto's are contained within the loop.
32793 \begin_layout Itemize
32794 No function calls within the loop.
32797 \begin_layout Itemize
32798 The loop control variable <sym> is not assigned any value within the loop
32801 \begin_layout Itemize
32802 The loop control variable does NOT participate in any arithmetic operation
32806 \begin_layout Itemize
32807 There are NO switch statements in the loop.
32810 \begin_layout Subsection
32811 Algebraic Simplifications
32814 \begin_layout Standard
32815 SDCC does numerous algebraic simplifications, the following is a small sub-set
32816 of these optimizations.
32819 \begin_layout Verse
32822 i = j + 0;\InsetSpace ~
32826 /* changed to: */\InsetSpace ~
32832 i /= 2;\InsetSpace ~
32839 /* changed to: */\InsetSpace ~
32846 = j - j;\InsetSpace ~
32850 /* changed to: */\InsetSpace ~
32856 i = j / 1;\InsetSpace ~
32860 /* changed to: */\InsetSpace ~
32867 \begin_layout Standard
32868 Note the subexpressions
32869 \begin_inset LatexCommand \index{Subexpression}
32873 given above are generally introduced by macro expansions or as a result
32874 of copy/constant propagation.
32877 \begin_layout Subsection
32878 'switch' Statements
32879 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32884 \begin_inset LatexCommand \index{switch statement}
32891 \begin_layout Standard
32892 SDCC can optimize switch statements to jump tables
32893 \begin_inset LatexCommand \index{jump tables}
32898 It makes the decision based on an estimate of the generated code size.
32899 SDCC is quite liberal in the requirements for jump table generation:
32902 \begin_layout Itemize
32903 The labels need not be in order, and the starting number need not be one
32904 or zero, the case labels are in numerical sequence or not too many case
32905 labels are missing.
32909 \begin_layout Verse
32912 switch(i) {\InsetSpace ~
32943 case 4: ...\InsetSpace ~
32975 case 5: ...\InsetSpace ~
33007 case 3: ...\InsetSpace ~
33038 case 6: ...\InsetSpace ~
33070 case 7: ...\InsetSpace ~
33102 case 8: ...\InsetSpace ~
33134 case 9: ...\InsetSpace ~
33166 case 10: ...\InsetSpace ~
33197 case 11: ...\InsetSpace ~
33264 \begin_layout Standard
33265 Both the above switch statements will be implemented using a jump-table.
33266 The example to the right side is slightly more efficient as the check for
33267 the lower boundary of the jump-table is not needed.
33271 \begin_layout Itemize
33272 The number of case labels is not larger than supported by the target architectur
33276 \begin_layout Itemize
33277 If the case labels are not in numerical sequence ('gaps' between cases)
33278 SDCC checks whether a jump table with additionally inserted dummy cases
33279 is still attractive.
33283 \begin_layout Itemize
33284 If the starting number is not zero and a check for the lower boundary of
33285 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33290 \begin_layout Standard
33291 Switch statements which have large gaps in the numeric sequence or those
33292 that have too many case labels can be split into more than one switch statement
33293 for efficient code generation, e.g.:
33296 \begin_layout Verse
33374 \begin_layout Standard
33375 If the above switch statement is broken down into two switch statements
33378 \begin_layout Verse
33421 \begin_layout Standard
33425 \begin_layout Verse
33468 \begin_layout Standard
33469 then both the switch statements will be implemented using jump-tables whereas
33470 the unmodified switch statement will not be.
33473 \begin_layout Standard
33474 \begin_inset Note Note
33477 \begin_layout Standard
33478 There might be reasons which SDCC cannot know about to either favour or
33479 not favour jump tables.
33480 If the target system has to be as quick for the last switch case as for
33481 the first (pro jump table), or if the switch argument is known to be zero
33482 in the majority of the cases (contra jump table).
33490 \begin_layout Standard
33491 The pragma nojtbound
33492 \begin_inset LatexCommand \index{\#pragma nojtbound}
33496 can be used to turn off checking the
33509 It has no effect if a default label is supplied.
33510 Use of this pragma is dangerous: if the switch
33511 \begin_inset LatexCommand \index{switch statement}
33515 argument is not matched by a case statement the processor will happily
33519 \begin_layout Subsection
33520 Bit-shifting Operations
33521 \begin_inset LatexCommand \index{Bit shifting}
33528 \begin_layout Standard
33529 Bit shifting is one of the most frequently used operation in embedded programmin
33531 SDCC tries to implement bit-shift operations in the most efficient way
33535 \begin_layout Verse
33548 \begin_layout Standard
33549 generates the following code:
33552 \begin_layout Verse
33567 \begin_layout Standard
33568 In general SDCC will never setup a loop if the shift count is known.
33572 \begin_layout Verse
33585 \begin_layout Standard
33589 \begin_layout Verse
33613 \begin_layout Subsection
33615 \begin_inset LatexCommand \index{Bit rotation}
33622 \begin_layout Standard
33623 A special case of the bit-shift operation is bit rotation
33624 \begin_inset LatexCommand \index{rotating bits}
33628 , SDCC recognizes the following expression to be a left bit-rotation:
33631 \begin_layout Verse
33639 char i;\InsetSpace ~
33650 /* unsigned is needed for rotation */
33655 i = ((i << 1) | (i >> 7));
33664 \begin_layout Standard
33665 will generate the following code:
33668 \begin_layout Verse
33685 \begin_layout Standard
33686 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33687 ns of this case will also be recognized as bit-rotation, i.e.:
33690 \begin_layout Verse
33693 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33696 \begin_layout Subsection
33697 Nibble and Byte Swapping
33700 \begin_layout Standard
33701 Other special cases of the bit-shift operations are nibble or byte swapping
33702 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33706 , SDCC recognizes the following expressions:
33709 \begin_layout Verse
33730 i = ((i << 4) | (i >> 4));
33736 j = ((j << 8) | (j >> 8));
33739 \begin_layout Standard
33740 and generates a swap instruction for the nibble swapping
33741 \begin_inset LatexCommand \index{Nibble swapping}
33745 or move instructions for the byte swapping
33746 \begin_inset LatexCommand \index{Byte swapping}
33752 \begin_inset Quotes sld
33756 \begin_inset Quotes srd
33759 example can be used to convert from little to big-endian or vice versa.
33760 If you want to change the endianness of a
33764 integer you have to cast to
33771 \begin_layout Standard
33772 Note that SDCC stores numbers in little-endian
33776 \begin_layout Standard
33777 Usually 8-bit processors don't care much about endianness.
33778 This is not the case for the standard 8051 which only has an instruction
33784 \begin_inset LatexCommand \index{DPTR}
33792 so little-endian is the more efficient byte order.
33798 \begin_inset LatexCommand \index{little-endian}
33803 \begin_inset LatexCommand \index{Endianness}
33808 lowest order first).
33811 \begin_layout Subsection
33813 \begin_inset LatexCommand \index{Highest Order Bit}
33818 \begin_inset LatexCommand \index{Any Order Bit}
33825 \begin_layout Standard
33826 It is frequently required to obtain the highest order bit of an integral
33827 type (long, int, short or char types).
33828 Also obtaining any other order bit is not uncommon.
33829 SDCC recognizes the following expressions to yield the highest order bit
33830 and generates optimized code for it, e.g.:
33833 \begin_layout Verse
33844 unsigned char hob1, aob1;
33848 bit hob2, hob3, aob2,
33858 hob1 = (gint >> 15) & 1;
33862 hob2 = (gint >> 15) & 1;
33866 hob3 = gint & 0x8000;
33871 aob1 = (gint >> 9) & 1;
33875 aob2 = (gint >> 8) & 1;
33879 aob3 = gint & 0x0800;
33889 \begin_layout Standard
33890 will generate the following code:
33893 \begin_layout Verse
33924 000A E5*01\InsetSpace ~
33951 000C 23\InsetSpace ~
33982 000D 54 01\InsetSpace ~
34010 000F F5*02\InsetSpace ~
34065 0011 E5*01\InsetSpace ~
34093 0013 33\InsetSpace ~
34123 0014 92*00\InsetSpace ~
34179 0016 E5*01\InsetSpace ~
34206 0018 33\InsetSpace ~
34236 0019 92*01\InsetSpace ~
34292 001B E5*01\InsetSpace ~
34351 001E 54 01\InsetSpace ~
34378 0020 F5*03\InsetSpace ~
34434 0022 E5*01\InsetSpace ~
34461 0024 13\InsetSpace ~
34491 0025 92*02\InsetSpace ~
34547 0027 E5*01\InsetSpace ~
34602 002B 92*03\InsetSpace ~
34630 \begin_layout Standard
34631 Other variations of these cases however will
34636 They are standard C expressions, so I heartily recommend these be the only
34637 way to get the highest order bit, (it is portable).
34638 Of course it will be recognized even if it is embedded in other expressions,
34642 \begin_layout Verse
34645 xyz = gint + ((gint >> 15) & 1);
34648 \begin_layout Standard
34649 will still be recognized.
34652 \begin_layout Subsection
34654 \begin_inset LatexCommand \index{Higher Order Byte}
34658 / Higher Order Word
34659 \begin_inset LatexCommand \index{Higher Order Word}
34666 \begin_layout Standard
34667 It is also frequently required to obtain a higher order byte or word of
34668 a larger integral type (long, int or short types).
34669 SDCC recognizes the following expressions to yield the higher order byte
34670 or word and generates optimized code for it, e.g.:
34673 \begin_layout Verse
34678 unsigned long int glong;
34686 unsigned char hob1,
34691 unsigned int how1, how2;
34700 hob1 = (gint >> 8) & 0xFF;
34704 hob2 = glong >> 24;
34708 how1 = (glong >> 16) & 0xFFFF;
34723 \begin_layout Standard
34724 will generate the following code:
34727 \begin_layout Verse
34758 0037 85*01*06\InsetSpace ~
34780 _foo_hob1_1_1,(_gint + 1)
34811 003A 85*05*07\InsetSpace ~
34833 _foo_hob2_1_1,(_glong + 3)
34863 003D 85*04*08\InsetSpace ~
34886 _foo_how1_1_1,(_glong + 2)
34888 0040 85*05*09\InsetSpace ~
34913 0043 85*03*0A\InsetSpace ~
34935 _foo_how2_1_1,(_glong + 1)
34937 0046 85*04*0B\InsetSpace ~
34960 (_foo_how2_1_1 + 1),(_glong + 2)
34963 \begin_layout Standard
34964 Again, variations of these cases may
34969 They are standard C expressions, so I heartily recommend these be the only
34970 way to get the higher order byte/word, (it is portable).
34971 Of course it will be recognized even if it is embedded in other expressions,
34975 \begin_layout Verse
34978 xyz = gint + ((gint >> 8) & 0xFF);
34981 \begin_layout Standard
34982 will still be recognized.
34985 \begin_layout Subsection
34987 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34992 \begin_inset LatexCommand \index{Peephole optimizer}
34999 \begin_layout Standard
35000 The compiler uses a rule based, pattern matching and re-writing mechanism
35001 for peep-hole optimization.
35006 a peep-hole optimizer by Christopher W.
35007 Fraser (cwfraser\InsetSpace ~
35010 A default set of rules are compiled into the compiler, additional rules
35011 may be added with the
35017 \begin_layout Standard
35027 \begin_inset LatexCommand \index{-\/-peep-file}
35034 The rule language is best illustrated with examples.
35037 \begin_layout Verse
35059 \begin_layout Standard
35060 The above rule will change the following assembly
35061 \begin_inset LatexCommand \index{Assembler routines}
35068 \begin_layout Verse
35076 \begin_layout Standard
35080 \begin_layout Verse
35086 \begin_layout Standard
35087 Note: All occurrences of a
35091 (pattern variable) must denote the same string.
35092 With the above rule, the assembly sequence:
35095 \begin_layout Verse
35103 \begin_layout Standard
35104 will remain unmodified.
35108 Other special case optimizations may be added by the
35115 \begin_layout Standard
35128 some variants of the 8051 MCU
35129 \begin_inset LatexCommand \index{MCS51 variants}
35142 The following two rules will change all
35159 \begin_layout Verse
35162 replace { lcall %1 } by { acall %1 }
35164 replace { ljmp %1 } by { ajmp %1 }
35167 \begin_layout Standard
35170 inline-assembler code
35172 is also passed through the peep hole optimizer, thus the peephole optimizer
35173 can also be used as an assembly level macro expander.
35174 The rules themselves are MCU dependent whereas the rule language infra-structur
35175 e is MCU independent.
35176 Peephole optimization rules for other MCU can be easily programmed using
35181 The syntax for a rule is as follows:
35184 \begin_layout Verse
35187 rule := replace [ restart ] '{' <assembly sequence> '
35225 <assembly sequence> '
35243 '}' [if <functionName> ] '
35248 \begin_layout Standard
35249 <assembly sequence> := assembly instruction (each instruction including
35250 labels must be on a separate line).
35254 The optimizer will apply to the rules
35255 one by one from the top in the sequence of their appearance, it will terminate
35256 when all rules are exhausted.
35257 If the 'restart' option is specified, then the optimizer will start matching
35258 the rules again from the top, this option for a rule is expensive (performance)
35259 , it is intended to be used in situations where a transformation will trigger
35260 the same rule again.
35261 An example of this (not a good one, it has side effects) is the following
35265 \begin_layout Verse
35285 \begin_layout Standard
35286 Note that the replace pattern cannot be a blank, but can be a comment line.
35287 Without the 'restart' option only the innermost 'pop' 'push' pair would
35288 be eliminated, i.e.:
35291 \begin_layout Verse
35303 \begin_layout Standard
35307 \begin_layout Verse
35317 \begin_layout Standard
35322 the restart option the rule will be applied again to the resulting code
35323 and then all the pop-push pairs will be eliminated to yield:
35326 \begin_layout Verse
35334 \begin_layout Standard
35335 A conditional function can be attached to a rule.
35336 Attaching rules are somewhat more involved, let me illustrate this with
35340 \begin_layout Verse
35364 \begin_layout Standard
35365 The optimizer does a look-up of a function name table defined in function
35370 in the source file SDCCpeeph.c, with the name
35375 If it finds a corresponding entry the function is called.
35376 Note there can be no parameters specified for these functions, in this
35381 is crucial, since the function
35385 expects to find the label in that particular variable (the hash table containin
35386 g the variable bindings is passed as a parameter).
35387 If you want to code more such functions, take a close look at the function
35388 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35389 Currently implemented are
35391 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35392 24bitMode, portIsDS390, 24bitModeAndPortDS390
35401 \begin_layout Standard
35402 I know this whole thing is a little kludgey, but maybe some day we will
35403 have some better means.
35404 If you are looking at this file, you will see the default rules that are
35405 compiled into the compiler, you can add your own rules in the default set
35406 there if you get tired of specifying the -
35410 \begin_layout Standard
35422 \begin_layout Section
35424 \begin_inset LatexCommand \index{ANSI-compliance}
35429 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35436 \begin_layout Standard
35437 The latest publically available version of the standard
35439 ISO/IEC 9899 - Programming languages - C
35441 should be available at:
35442 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35451 \begin_layout Standard
35452 Deviations from the compliance:
35455 \begin_layout Itemize
35456 functions are not reentrant
35457 \begin_inset LatexCommand \index{reentrant}
35461 unless explicitly declared as such or the
35467 \begin_layout Standard
35477 \begin_inset LatexCommand \index{-\/-stack-auto}
35483 command line option is specified.
35486 \begin_layout Itemize
35488 \begin_inset LatexCommand \index{struct}
35493 \begin_inset LatexCommand \index{union}
35497 cannot be assigned values directly, cannot be passed as function parameters
35498 or assigned to each other and cannot be a return value
35499 \begin_inset LatexCommand \index{return value}
35503 from a function, e.g.:
35507 \begin_layout Verse
35530 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35549 s parms) /* invalid in SDCC although allowed in ANSI */
35571 return rets; /* is invalid in SDCC although allowed in ANSI */
35577 \begin_layout Itemize
35578 initialization of structure arrays must be fully braced.
35582 \begin_layout Verse
35585 struct s { char x } a[] = {1, 2};\InsetSpace ~
35590 /* invalid in SDCC */
35593 } a[] = {{1}, {2}}; /* OK */
35597 \begin_layout Itemize
35599 \begin_inset LatexCommand \index{long long (not supported)}
35604 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35611 \begin_layout Itemize
35613 \begin_inset LatexCommand \index{double (not supported)}
35617 ' precision floating point
35618 \begin_inset LatexCommand \index{Floating point support}
35625 \begin_layout Itemize
35627 \begin_inset LatexCommand \index{K\&R style}
35631 function declarations are NOT allowed.
35635 \begin_layout Verse
35638 foo(i,j) /* this old style of function declarations */
35640 int i,j; /* are valid
35641 in ANSI but not valid in SDCC */
35656 \begin_layout Itemize
35657 Most enhancements in C99 are not supported, f.e.:
35661 \begin_layout Verse
35666 \begin_inset LatexCommand \index{inline (not supported)}
35672 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35678 can be used as a work around */
35686 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35690 \begin_layout Itemize
35691 Certain words that are valid identifiers in the standard may be reserved
35692 words in SDCC unless the
35698 \begin_layout Standard
35708 \begin_inset LatexCommand \index{-\/-std-c89}
35716 \begin_layout Standard
35726 \begin_inset LatexCommand \index{-\/-std-c99}
35732 command line options are used.
35733 These may include (depending on the selected processor): 'at', 'banked',
35734 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35735 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35736 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35738 Compliant equivalents of these keywords are always available in a form
35739 that begin with two underscores
35740 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35745 '__data' instead of 'data'.
35748 \begin_layout Section
35749 Cyclomatic Complexity
35750 \begin_inset LatexCommand \index{Cyclomatic complexity}
35757 \begin_layout Standard
35758 Cyclomatic complexity of a function is defined as the number of independent
35759 paths the program can take during execution of the function.
35760 This is an important number since it defines the number test cases you
35761 have to generate to validate the function.
35762 The accepted industry standard for complexity number is 10, if the cyclomatic
35763 complexity reported by SDCC exceeds 10 you should think about simplification
35764 of the function logic.
35765 Note that the complexity level is not related to the number of lines of
35766 code in a function.
35767 Large functions can have low complexity, and small functions can have large
35773 SDCC uses the following formula to compute the complexity:
35778 \begin_layout Standard
35779 complexity = (number of edges in control flow graph) - (number of nodes
35780 in control flow graph) + 2;
35784 Having said that the industry standard is 10,
35785 you should be aware that in some cases it be may unavoidable to have a
35786 complexity level of less than 10.
35787 For example if you have switch statement with more than 10 case labels,
35788 each case label adds one to the complexity level.
35789 The complexity level is by no means an absolute measure of the algorithmic
35790 complexity of the function, it does however provide a good starting point
35791 for which functions you might look at for further optimization.
35794 \begin_layout Section
35795 Retargetting for other Processors
35798 \begin_layout Standard
35799 The issues for retargetting the compiler are far too numerous to be covered
35801 What follows is a brief description of each of the seven phases of the
35802 compiler and its MCU dependency.
35805 \begin_layout Itemize
35806 Parsing the source and building the annotated parse tree.
35807 This phase is largely MCU independent (except for the language extensions).
35808 Syntax & semantic checks are also done in this phase, along with some initial
35809 optimizations like back patching labels and the pattern matching optimizations
35810 like bit-rotation etc.
35813 \begin_layout Itemize
35814 The second phase involves generating an intermediate code which can be easy
35815 manipulated during the later phases.
35816 This phase is entirely MCU independent.
35817 The intermediate code generation assumes the target machine has unlimited
35818 number of registers, and designates them with the name iTemp.
35819 The compiler can be made to dump a human readable form of the code generated
35824 \begin_layout Standard
35836 \begin_layout Itemize
35837 This phase does the bulk of the standard optimizations and is also MCU independe
35839 This phase can be broken down into several sub-phases:
35843 Break down intermediate
35844 code (iCode) into basic blocks.
35846 Do control flow & data flow analysis on the
35849 Do local common subexpression elimination, then global subexpressio
35852 Dead code elimination
35856 If loop optimizations
35857 caused any changes then do 'global subexpression elimination' and 'dead
35858 code elimination' again.
35861 \begin_layout Itemize
35862 This phase determines the live-ranges; by live range I mean those iTemp
35863 variables defined by the compiler that still survive after all the optimization
35865 Live range analysis
35866 \begin_inset LatexCommand \index{Live range analysis}
35870 is essential for register allocation, since these computation determines
35871 which of these iTemps will be assigned to registers, and for how long.
35874 \begin_layout Itemize
35875 Phase five is register allocation.
35876 There are two parts to this process.
35880 The first part I call 'register packing'
35881 (for lack of a better term).
35882 In this case several MCU specific expression folding is done to reduce
35887 The second part is more MCU independent and deals with
35888 allocating registers to the remaining live ranges.
35889 A lot of MCU specific code does creep into this phase because of the limited
35890 number of index registers available in the 8051.
35893 \begin_layout Itemize
35894 The Code generation phase is (unhappily), entirely MCU dependent and very
35895 little (if any at all) of this code can be reused for other MCU.
35896 However the scheme for allocating a homogenized assembler operand for each
35897 iCode operand may be reused.
35900 \begin_layout Itemize
35901 As mentioned in the optimization section the peep-hole optimizer is rule
35902 based system, which can reprogrammed for other MCUs.
35905 \begin_layout Standard
35906 More information is available in a wiki
35907 \begin_inset LatexCommand \index{wiki}
35912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35916 ) and in the thread
35917 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35924 \begin_layout Chapter
35926 \begin_inset LatexCommand \index{Compiler internals}
35933 \begin_layout Section
35934 The anatomy of the compiler
35935 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35942 \begin_layout Standard
35945 This is an excerpt from an article published in Circuit Cellar Magazine
35951 It's a little outdated (the compiler is much more efficient now and user/develo
35952 per friendly), but pretty well exposes the guts of it all.
35958 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35959 It is fairly easy to retarget for other 8-bit MCU.
35960 Here we take a look at some of the internals of the compiler.
35964 \begin_layout Paragraph*
35966 \begin_inset LatexCommand \index{Parsing}
35973 \begin_layout Standard
35974 Parsing the input source file and creating an AST (Annotated Syntax Tree
35975 \begin_inset LatexCommand \index{Annotated syntax tree}
35980 This phase also involves propagating types (annotating each node of the
35981 parse tree with type information) and semantic analysis.
35982 There are some MCU specific parsing rules.
35983 For example the storage classes, the extended storage classes are MCU specific
35984 while there may be a xdata storage class for 8051 there is no such storage
35985 class for z80 or Atmel AVR.
35986 SDCC allows MCU specific storage class extensions, i.e.
35987 xdata will be treated as a storage class specifier when parsing 8051 C
35988 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35992 \begin_layout Paragraph*
35994 \begin_inset LatexCommand \index{iCode}
36001 \begin_layout Standard
36002 Intermediate code generation.
36003 In this phase the AST is broken down into three-operand form (iCode).
36004 These three operand forms are represented as doubly linked lists.
36005 ICode is the term given to the intermediate form generated by the compiler.
36006 ICode example section shows some examples of iCode generated for some simple
36007 C source functions.
36010 \begin_layout Paragraph*
36012 \begin_inset LatexCommand \index{Optimizations}
36019 \begin_layout Standard
36020 Bulk of the target independent optimizations is performed in this phase.
36021 The optimizations include constant propagation, common sub-expression eliminati
36022 on, loop invariant code movement, strength reduction of loop induction variables
36023 and dead-code elimination.
36026 \begin_layout Paragraph*
36027 Live range analysis
36028 \begin_inset LatexCommand \index{Live range analysis}
36035 \begin_layout Standard
36036 During intermediate code generation phase, the compiler assumes the target
36037 machine has infinite number of registers and generates a lot of temporary
36039 The live range computation determines the lifetime of each of these compiler-ge
36040 nerated temporaries.
36041 A picture speaks a thousand words.
36042 ICode example sections show the live range annotations for each of the
36044 It is important to note here, each iCode is assigned a number in the order
36045 of its execution in the function.
36046 The live ranges are computed in terms of these numbers.
36047 The from number is the number of the iCode which first defines the operand
36048 and the to number signifies the iCode which uses this operand last.
36051 \begin_layout Paragraph*
36052 Register Allocation
36053 \begin_inset LatexCommand \index{Register allocation}
36060 \begin_layout Standard
36061 The register allocation determines the type and number of registers needed
36063 In most MCUs only a few registers can be used for indirect addressing.
36064 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36065 address the internal ram and DPTR to indirectly address the external ram.
36066 The compiler will try to allocate the appropriate register to pointer variables
36068 ICode example section shows the operands annotated with the registers assigned
36070 The compiler will try to keep operands in registers as much as possible;
36071 there are several schemes the compiler uses to do achieve this.
36072 When the compiler runs out of registers the compiler will check to see
36073 if there are any live operands which is not used or defined in the current
36074 basic block being processed, if there are any found then it will push that
36075 operand and use the registers in this block, the operand will then be popped
36076 at the end of the basic block.
36080 \begin_layout Standard
36081 There are other MCU specific considerations in this phase.
36082 Some MCUs have an accumulator; very short-lived operands could be assigned
36083 to the accumulator instead of a general-purpose register.
36086 \begin_layout Paragraph*
36090 \begin_layout Standard
36091 Figure II gives a table of iCode
36092 \begin_inset LatexCommand \index{iCode}
36096 operations supported by the compiler.
36097 The code generation involves translating these operations into corresponding
36098 assembly code for the processor.
36099 This sounds overly simple but that is the essence of code generation.
36100 Some of the iCode operations are generated on a MCU specific manner for
36101 example, the z80 port does not use registers to pass parameters so the
36102 SEND and RECV iCode operations will not be generated, and it also does
36103 not support JUMPTABLES.
36109 \begin_layout Standard
36113 \begin_inset Tabular
36114 <lyxtabular version="3" rows="39" columns="4">
36115 <features islongtable="true" headBottomDL="true">
36116 <column alignment="block" valignment="top" leftline="true" width="13col%">
36117 <column alignment="left" valignment="top" leftline="true" width="13col%">
36118 <column alignment="block" valignment="top" leftline="true" width="22col%">
36119 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36120 <row topline="true" bottomline="true" endhead="true">
36121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36124 \begin_layout Standard
36130 \begin_inset LatexCommand \index{iCode}
36139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36142 \begin_layout Standard
36150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36153 \begin_layout Standard
36161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36164 \begin_layout Standard
36173 <row topline="true">
36174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36177 \begin_layout Standard
36185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36188 \begin_layout Standard
36191 IC_LEFT() IC_RESULT()
36196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36199 \begin_layout Standard
36207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36210 \begin_layout Standard
36213 IC_RESULT = ! IC_LEFT;
36219 <row topline="true">
36220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36223 \begin_layout Standard
36231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36234 \begin_layout Standard
36237 IC_LEFT() IC_RESULT()
36242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36245 \begin_layout Standard
36248 Bitwise complement of
36253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36256 \begin_layout Standard
36259 IC_RESULT = ~IC_LEFT;
36265 <row topline="true">
36266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36269 \begin_layout Standard
36277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36280 \begin_layout Standard
36283 IC_LEFT() IC_RESULT()
36288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36291 \begin_layout Standard
36294 Rotate right with carry
36299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36302 \begin_layout Standard
36305 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36311 <row topline="true">
36312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36315 \begin_layout Standard
36323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36326 \begin_layout Standard
36329 IC_LEFT() IC_RESULT()
36334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36337 \begin_layout Standard
36340 Rotate left with carry
36345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36348 \begin_layout Standard
36351 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36357 <row topline="true">
36358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36361 \begin_layout Standard
36369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36372 \begin_layout Standard
36375 IC_LEFT() IC_RESULT()
36380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36383 \begin_layout Standard
36386 Get the highest order bit of IC_LEFT
36391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36394 \begin_layout Standard
36397 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36403 <row topline="true">
36404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36407 \begin_layout Standard
36415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36418 \begin_layout Standard
36421 IC_LEFT() IC_RESULT()
36426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36429 \begin_layout Standard
36437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36440 \begin_layout Standard
36443 IC_RESULT = - IC_LEFT;
36449 <row topline="true">
36450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36453 \begin_layout Standard
36461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36464 \begin_layout Standard
36472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36475 \begin_layout Standard
36478 Push the operand into stack
36483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36486 \begin_layout Standard
36495 <row topline="true">
36496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36499 \begin_layout Standard
36507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36510 \begin_layout Standard
36518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36521 \begin_layout Standard
36524 Pop the operand from the stack
36529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36532 \begin_layout Standard
36541 <row topline="true">
36542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36545 \begin_layout Standard
36553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36556 \begin_layout Standard
36559 IC_LEFT() IC_RESULT()
36564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36567 \begin_layout Standard
36570 Call the function represented by IC_LEFT
36575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36578 \begin_layout Standard
36581 IC_RESULT = IC_LEFT();
36587 <row topline="true">
36588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36591 \begin_layout Standard
36599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36602 \begin_layout Standard
36605 IC_LEFT() IC_RESULT()
36610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36613 \begin_layout Standard
36616 Call via function pointer
36621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36624 \begin_layout Standard
36627 IC_RESULT = (*IC_LEFT)();
36633 <row topline="true">
36634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36637 \begin_layout Standard
36645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36648 \begin_layout Standard
36656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36659 \begin_layout Standard
36662 Return the value in operand IC_LEFT
36667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36670 \begin_layout Standard
36679 <row topline="true">
36680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36683 \begin_layout Standard
36691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36694 \begin_layout Standard
36702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36705 \begin_layout Standard
36713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36716 \begin_layout Standard
36725 <row topline="true">
36726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36729 \begin_layout Standard
36737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36740 \begin_layout Standard
36748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36751 \begin_layout Standard
36759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36762 \begin_layout Standard
36771 <row topline="true">
36772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36775 \begin_layout Standard
36783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36786 \begin_layout Standard
36789 IC_LEFT() IC_RIGHT() IC_RESULT()
36794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36797 \begin_layout Standard
36805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36808 \begin_layout Standard
36811 IC_RESULT = IC_LEFT + IC_RIGHT
36817 <row topline="true">
36818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36821 \begin_layout Standard
36829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36832 \begin_layout Standard
36835 IC_LEFT() IC_RIGHT() IC_RESULT()
36840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36843 \begin_layout Standard
36851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36854 \begin_layout Standard
36857 IC_RESULT = IC_LEFT - IC_RIGHT
36863 <row topline="true">
36864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36867 \begin_layout Standard
36875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36878 \begin_layout Standard
36881 IC_LEFT() IC_RIGHT() IC_RESULT()
36886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36889 \begin_layout Standard
36897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36900 \begin_layout Standard
36903 IC_RESULT = IC_LEFT * IC_RIGHT;
36909 <row topline="true">
36910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36913 \begin_layout Standard
36921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36924 \begin_layout Standard
36927 IC_LEFT() IC_RIGHT() IC_RESULT()
36932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36935 \begin_layout Standard
36943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36946 \begin_layout Standard
36949 IC_RESULT = IC_LEFT / IC_RIGHT;
36955 <row topline="true">
36956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36959 \begin_layout Standard
36967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36970 \begin_layout Standard
36973 IC_LEFT() IC_RIGHT() IC_RESULT()
36978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36981 \begin_layout Standard
36989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36992 \begin_layout Standard
36995 IC_RESULT = IC_LEFT % IC_RIGHT;
37001 <row topline="true">
37002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37005 \begin_layout Standard
37013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37016 \begin_layout Standard
37019 IC_LEFT() IC_RIGHT() IC_RESULT()
37024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37027 \begin_layout Standard
37035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37038 \begin_layout Standard
37041 IC_RESULT = IC_LEFT < IC_RIGHT;
37047 <row topline="true">
37048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37051 \begin_layout Standard
37059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37062 \begin_layout Standard
37065 IC_LEFT() IC_RIGHT() IC_RESULT()
37070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37073 \begin_layout Standard
37081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37084 \begin_layout Standard
37087 IC_RESULT = IC_LEFT > IC_RIGHT;
37093 <row topline="true">
37094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37097 \begin_layout Standard
37105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37108 \begin_layout Standard
37111 IC_LEFT() IC_RIGHT() IC_RESULT()
37116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37119 \begin_layout Standard
37127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37130 \begin_layout Standard
37133 IC_RESULT = IC_LEFT == IC_RIGHT;
37139 <row topline="true">
37140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37143 \begin_layout Standard
37151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37154 \begin_layout Standard
37157 IC_LEFT() IC_RIGHT() IC_RESULT()
37162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37165 \begin_layout Standard
37168 Logical and operation
37173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37176 \begin_layout Standard
37179 IC_RESULT = IC_LEFT && IC_RIGHT;
37185 <row topline="true">
37186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37189 \begin_layout Standard
37197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37200 \begin_layout Standard
37203 IC_LEFT() IC_RIGHT() IC_RESULT()
37208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37211 \begin_layout Standard
37214 Logical or operation
37219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37222 \begin_layout Standard
37225 IC_RESULT = IC_LEFT || IC_RIGHT;
37231 <row topline="true">
37232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37235 \begin_layout Standard
37243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37246 \begin_layout Standard
37249 IC_LEFT() IC_RIGHT() IC_RESULT()
37254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37257 \begin_layout Standard
37265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37268 \begin_layout Standard
37271 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37277 <row topline="true">
37278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37281 \begin_layout Standard
37289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37292 \begin_layout Standard
37295 IC_LEFT() IC_RIGHT() IC_RESULT()
37300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37303 \begin_layout Standard
37311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37314 \begin_layout Standard
37317 IC_RESULT = IC_LEFT | IC_RIGHT;
37323 <row topline="true">
37324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37327 \begin_layout Standard
37335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37338 \begin_layout Standard
37341 IC_LEFT() IC_RIGHT() IC_RESULT()
37346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37349 \begin_layout Standard
37357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37360 \begin_layout Standard
37363 IC_RESULT = IC_LEFT & IC_RIGHT;
37369 <row topline="true">
37370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37373 \begin_layout Standard
37381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37384 \begin_layout Standard
37387 IC_LEFT() IC_RIGHT() IC_RESULT()
37392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37395 \begin_layout Standard
37403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37406 \begin_layout Standard
37409 IC_RESULT = IC_LEFT << IC_RIGHT
37415 <row topline="true">
37416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37419 \begin_layout Standard
37427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37430 \begin_layout Standard
37433 IC_LEFT() IC_RIGHT() IC_RESULT()
37438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37441 \begin_layout Standard
37449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37452 \begin_layout Standard
37455 IC_RESULT = IC_LEFT >> IC_RIGHT
37461 <row topline="true">
37462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37465 \begin_layout Standard
37475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37478 \begin_layout Standard
37481 IC_LEFT() IC_RESULT()
37486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37489 \begin_layout Standard
37497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37500 \begin_layout Standard
37503 IC_RESULT = (*IC_LEFT);
37509 <row topline="true">
37510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37513 \begin_layout Standard
37521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37524 \begin_layout Standard
37527 IC_RIGHT() IC_RESULT()
37532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37535 \begin_layout Standard
37543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37546 \begin_layout Standard
37549 (*IC_RESULT) = IC_RIGHT;
37555 <row topline="true">
37556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37559 \begin_layout Standard
37567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37570 \begin_layout Standard
37573 IC_RIGHT() IC_RESULT()
37578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37581 \begin_layout Standard
37589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37592 \begin_layout Standard
37595 IC_RESULT = IC_RIGHT;
37601 <row topline="true">
37602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37605 \begin_layout Standard
37613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37616 \begin_layout Standard
37619 IC_COND IC_TRUE IC_LABEL
37624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37627 \begin_layout Standard
37631 If true label is present then jump to true label if condition is true else
37632 jump to false label if condition is false
37637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37640 \begin_layout Standard
37643 if (IC_COND) goto IC_TRUE;
37649 If (!IC_COND) goto IC_FALSE;
37655 <row topline="true">
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37659 \begin_layout Standard
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37670 \begin_layout Standard
37673 IC_LEFT() IC_RESULT()
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37681 \begin_layout Standard
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37692 \begin_layout Standard
37695 IC_RESULT = &IC_LEFT();
37701 <row topline="true">
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37705 \begin_layout Standard
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37716 \begin_layout Standard
37719 IC_JTCOND IC_JTLABELS
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37727 \begin_layout Standard
37730 Jump to list of labels depending on the value of JTCOND
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37738 \begin_layout Standard
37747 <row topline="true">
37748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37751 \begin_layout Standard
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_layout Standard
37765 IC_RIGHT() IC_LEFT() IC_RESULT()
37770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37773 \begin_layout Standard
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37784 \begin_layout Standard
37787 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37793 <row topline="true">
37794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37797 \begin_layout Standard
37805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37808 \begin_layout Standard
37816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37819 \begin_layout Standard
37822 This is used for passing parameters in registers;
37824 move IC_LEFT to the next
37825 available parameter register.
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37833 \begin_layout Standard
37842 <row topline="true">
37843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37846 \begin_layout Standard
37854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37857 \begin_layout Standard
37865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37868 \begin_layout Standard
37871 This is used for receiving parameters passed in registers;
37874 in the next parameter register to IC_RESULT
37879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37882 \begin_layout Standard
37891 <row topline="true" bottomline="true">
37892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37895 \begin_layout Standard
37899 (some more have been added)
37904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37907 \begin_layout Standard
37913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37916 \begin_layout Standard
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37925 \begin_layout Standard
37949 \begin_layout Standard
37950 \begin_inset Note Note
37953 \begin_layout Standard
37954 In the original article Figure II was announced to be downloadable on
37959 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37967 \begin_layout Paragraph*
37969 \begin_inset LatexCommand \index{iCode}
37976 \begin_layout Standard
37977 This section shows some details of iCode.
37978 The example C code does not do anything useful; it is used as an example
37979 to illustrate the intermediate code generated by the compiler.
37982 \begin_layout Verse
37992 /* This function does nothing useful.
37999 for the purpose of explaining iCode */
38002 short function (data
38011 short i=10; \InsetSpace ~
38013 /* dead initialization eliminated */
38019 /* dead initialization eliminated */
38047 /* compiler detects i,j to be induction
38052 for (i = 0, j = 10 ; i < 10 ; i++, j
38058 \begin_layout Standard
38081 mul += i * 3; \InsetSpace ~
38083 /* this multiplication remains */
38090 j * 3;\InsetSpace ~
38092 /* this multiplication changed to addition */
38106 \begin_layout Standard
38107 In addition to the operands each iCode contains information about the filename
38108 and line it corresponds to in the source file.
38109 The first field in the listing should be interpreted as follows:
38114 Filename(linenumber: iCode Execution sequence number : ICode hash table
38115 key : loop depth of the iCode).
38120 Then follows the human readable form of the ICode operation.
38121 Each operand of this triplet form can be of three basic types a) compiler
38122 generated temporary b) user defined variable c) a constant value.
38123 Note that local variables and parameters are replaced by compiler generated
38126 \begin_inset LatexCommand \index{Live range analysis}
38130 are computed only for temporaries (i.e.
38131 live ranges are not computed for global variables).
38133 \begin_inset LatexCommand \index{Register allocation}
38137 are allocated for temporaries only.
38138 Operands are formatted in the following manner:
38143 Operand Name [lr live-from : live-to ] { type information } [ registers
38149 As mentioned earlier the live ranges are computed in terms of the execution
38150 sequence number of the iCodes, for example
38152 the iTemp0 is live from (i.e.
38153 first defined in iCode with execution sequence number 3, and is last used
38154 in the iCode with sequence number 5).
38155 For induction variables such as iTemp21 the live range computation extends
38156 the lifetime from the start to the end of the loop.
38158 The register allocator
38159 used the live range information to allocate registers, the same registers
38160 may be used for different temporaries if their live ranges do not overlap,
38161 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38162 ranges do not overlap.
38163 In addition the allocator also takes into consideration the type and usage
38164 of a temporary, for example itemp6 is a pointer to near space and is used
38165 as to fetch data from (i.e.
38166 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38167 Some short lived temporaries are allocated to special registers which have
38168 meaning to the code generator e.g.
38169 iTemp13 is allocated to a pseudo register CC which tells the back end that
38170 the temporary is used only for a conditional jump the code generation makes
38171 use of this information to optimize a compare and jump ICode.
38175 \begin_inset LatexCommand \index{Loop optimization}
38179 performed by the compiler.
38180 It can detect induction variables iTemp21(i) and iTemp23(j).
38181 Also note the compiler does selective strength reduction
38182 \begin_inset LatexCommand \index{Strength reduction}
38187 the multiplication of an induction variable in line 18 (gint = j * 3) is
38188 changed to addition, a new temporary iTemp17 is allocated and assigned
38189 a initial value, a constant 3 is then added for each iteration of the loop.
38190 The compiler does not change the multiplication
38191 \begin_inset LatexCommand \index{Multiplication}
38195 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38198 Note the dead code elimination
38199 \begin_inset LatexCommand \index{Dead-code elimination}
38203 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38209 \begin_layout Standard
38212 Sample.c (5:1:0:0) _entry($9) :
38215 \begin_layout Standard
38218 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38221 \begin_layout Standard
38224 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38227 \begin_layout Standard
38230 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38233 \begin_layout Standard
38236 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38240 \begin_layout Standard
38243 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38246 \begin_layout Standard
38249 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38253 \begin_layout Standard
38256 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38259 \begin_layout Standard
38262 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38266 \begin_layout Standard
38269 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38273 \begin_layout Standard
38276 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38280 \begin_layout Standard
38283 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38287 \begin_layout Standard
38290 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38291 * int}[r0] + 0x2 {short}
38294 \begin_layout Standard
38297 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38300 \begin_layout Standard
38303 Sample.c(11:17:21:0)_whilebreak_0($3) :
38306 \begin_layout Standard
38309 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38312 \begin_layout Standard
38315 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38318 \begin_layout Standard
38321 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38324 \begin_layout Standard
38327 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38330 \begin_layout Standard
38333 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38336 \begin_layout Standard
38339 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38342 \begin_layout Standard
38345 Sample.c(15:24:26:1)_forcond_0($4) :
38348 \begin_layout Standard
38351 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38355 \begin_layout Standard
38358 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38361 \begin_layout Standard
38364 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38365 + ITemp21 [lr21:38]{short}[r4]
38368 \begin_layout Standard
38371 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38375 \begin_layout Standard
38378 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38379 + iTemp15 [lr29:30]{short}[r1]
38382 \begin_layout Standard
38385 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38389 \begin_layout Standard
38392 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38396 \begin_layout Standard
38399 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38403 \begin_layout Standard
38406 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38410 \begin_layout Standard
38413 Sample.c(19:38:47:1) goto _forcond_0($4)
38416 \begin_layout Standard
38419 Sample.c(19:39:48:0)_forbreak_0($7) :
38422 \begin_layout Standard
38425 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38426 + ITemp11 [lr19:40]{short}[r3]
38429 \begin_layout Standard
38432 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38435 \begin_layout Standard
38438 Sample.c(20:42:51:0)_return($8) :
38441 \begin_layout Standard
38444 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38450 Finally the code generated for this function:
38455 \begin_layout Standard
38461 \begin_layout Standard
38467 \begin_layout Standard
38475 \begin_layout Standard
38481 \begin_layout Standard
38489 \begin_layout Standard
38495 \begin_layout Standard
38498 ; ----------------------------------------------
38501 \begin_layout Standard
38504 ; function function
38507 \begin_layout Standard
38510 ; ----------------------------------------------
38513 \begin_layout Standard
38519 \begin_layout Standard
38522 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38525 \begin_layout Standard
38533 \begin_layout Standard
38536 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38539 \begin_layout Standard
38547 \begin_layout Standard
38550 ;_whilecontinue_0($1) :
38553 \begin_layout Standard
38559 \begin_layout Standard
38562 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38565 \begin_layout Standard
38568 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38571 \begin_layout Standard
38579 \begin_layout Standard
38587 \begin_layout Standard
38595 \begin_layout Standard
38603 \begin_layout Standard
38611 \begin_layout Standard
38619 \begin_layout Standard
38627 \begin_layout Standard
38633 \begin_layout Standard
38636 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38639 \begin_layout Standard
38647 \begin_layout Standard
38655 \begin_layout Standard
38658 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38661 \begin_layout Standard
38669 \begin_layout Standard
38677 \begin_layout Standard
38685 \begin_layout Standard
38693 \begin_layout Standard
38701 \begin_layout Standard
38709 \begin_layout Standard
38712 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38715 \begin_layout Standard
38723 \begin_layout Standard
38731 \begin_layout Standard
38739 \begin_layout Standard
38747 \begin_layout Standard
38755 \begin_layout Standard
38758 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38761 \begin_layout Standard
38769 \begin_layout Standard
38777 \begin_layout Standard
38785 \begin_layout Standard
38788 ; iTemp6 [lr5:16]{_near * int}[r0] =
38791 \begin_layout Standard
38794 ; iTemp6 [lr5:16]{_near * int}[r0] +
38797 \begin_layout Standard
38803 \begin_layout Standard
38811 \begin_layout Standard
38814 ; goto _whilecontinue_0($1)
38817 \begin_layout Standard
38825 \begin_layout Standard
38828 ; _whilebreak_0($3) :
38831 \begin_layout Standard
38837 \begin_layout Standard
38840 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38843 \begin_layout Standard
38851 \begin_layout Standard
38854 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38857 \begin_layout Standard
38865 \begin_layout Standard
38868 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38871 \begin_layout Standard
38879 \begin_layout Standard
38882 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38885 \begin_layout Standard
38893 \begin_layout Standard
38901 \begin_layout Standard
38904 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38907 \begin_layout Standard
38915 \begin_layout Standard
38923 \begin_layout Standard
38929 \begin_layout Standard
38935 \begin_layout Standard
38938 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38941 \begin_layout Standard
38944 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38947 \begin_layout Standard
38955 \begin_layout Standard
38963 \begin_layout Standard
38971 \begin_layout Standard
38979 \begin_layout Standard
38987 \begin_layout Standard
38993 \begin_layout Standard
38996 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38999 \begin_layout Standard
39002 ; iTemp21 [lr21:38]{short}[r4]
39005 \begin_layout Standard
39013 \begin_layout Standard
39021 \begin_layout Standard
39029 \begin_layout Standard
39032 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39035 \begin_layout Standard
39043 \begin_layout Standard
39051 \begin_layout Standard
39059 \begin_layout Standard
39067 \begin_layout Standard
39070 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39073 \begin_layout Standard
39076 ; iTemp15 [lr29:30]{short}[r1]
39079 \begin_layout Standard
39087 \begin_layout Standard
39095 \begin_layout Standard
39098 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39101 \begin_layout Standard
39109 \begin_layout Standard
39117 \begin_layout Standard
39125 \begin_layout Standard
39133 \begin_layout Standard
39141 \begin_layout Standard
39149 \begin_layout Standard
39152 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39155 \begin_layout Standard
39163 \begin_layout Standard
39171 \begin_layout Standard
39179 \begin_layout Standard
39187 \begin_layout Standard
39195 \begin_layout Standard
39203 \begin_layout Standard
39206 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39209 \begin_layout Standard
39217 \begin_layout Standard
39220 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39223 \begin_layout Standard
39231 \begin_layout Standard
39236 cjne r5,#0xff,00104$
39239 \begin_layout Standard
39247 \begin_layout Standard
39250 ; goto _forcond_0($4)
39253 \begin_layout Standard
39261 \begin_layout Standard
39264 ; _forbreak_0($7) :
39267 \begin_layout Standard
39273 \begin_layout Standard
39276 ; ret iTemp24 [lr40:41]{short}
39279 \begin_layout Standard
39287 \begin_layout Standard
39295 \begin_layout Standard
39303 \begin_layout Standard
39309 \begin_layout Standard
39315 \begin_layout Standard
39325 \begin_layout Section
39326 A few words about basic block successors, predecessors and dominators
39329 \begin_layout Standard
39330 Successors are basic blocks
39331 \begin_inset LatexCommand \index{Basic blocks}
39335 that might execute after this basic block.
39337 Predecessors are basic blocks
39338 that might execute before reaching this basic block.
39340 Dominators are basic
39341 blocks that WILL execute before reaching this basic block.
39346 \begin_layout Standard
39350 \begin_layout Standard
39354 \begin_layout Standard
39362 \begin_layout Standard
39366 \begin_layout Standard
39374 \begin_layout Standard
39380 \begin_layout Standard
39381 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39384 \begin_layout Standard
39385 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39388 \begin_layout Standard
39389 c) domVect of [BB4] = BB1 ...
39390 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39394 \begin_layout Chapter
39398 \begin_layout Standard
39399 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39409 Thanks to all the other volunteer developers who have helped with coding,
39410 testing, web-page creation, distribution sets, etc.
39411 You know who you are :-)
39419 Also thanks to Sourceforge
39420 \begin_inset LatexCommand \url{http://www.sf.net}
39424 which has hosted the project since 1999 and donates significant download
39425 bandwidth and probably more than
39429 \begin_layout Standard
39436 CPU cycles per day.
39439 \begin_inset Note Note
39442 \begin_layout Standard
39443 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39444 minutes for (configure+make+regression test), and there is (i386, amd64,
39445 alpha, ppc64, (mingw32), sparc, Mac OS X).
39454 \begin_layout Standard
39455 This document was initially written by Sandeep Dutta
39458 \begin_layout Standard
39459 All product names mentioned herein may be trademarks
39460 \begin_inset LatexCommand \index{Trademarks}
39464 of their respective companies.
39468 \begin_layout Section*
39472 \begin_layout Standard
39473 To avoid confusion, the installation and building options for SDCC itself
39474 (chapter 2) are not part of the index.
39477 \begin_layout Standard
39478 \begin_inset LatexCommand \printindex{}