1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes 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 \labelwidthstring 00.00.0000
8449 \begin_layout Standard
8461 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8465 Determinate PORT I/O mode (<Value> is z80 or z180).
8469 \labelwidthstring 00.00.0000
8476 \begin_layout Standard
8488 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8492 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8496 \labelwidthstring 00.00.0000
8503 \begin_layout Standard
8516 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8520 Use <Value> for the code segment name.
8524 \labelwidthstring 00.00.0000
8531 \begin_layout Standard
8544 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8548 Use <Value> for the const segment name.
8552 \labelwidthstring 00.00.0000
8553 \begin_inset VSpace bigskip
8559 \begin_layout Subsection
8561 \begin_inset LatexCommand \index{Options GBZ80}
8566 \begin_inset LatexCommand \index{GBZ80}
8574 \labelwidthstring 00.00.0000
8581 \begin_layout Standard
8593 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8603 Force a called function to always save BC.
8607 \labelwidthstring 00.00.0000
8614 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8618 Use code bank <Num>.
8622 \labelwidthstring 00.00.0000
8629 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8633 Use data bank <Num>.
8637 \labelwidthstring 00.00.0000
8644 \begin_layout Standard
8657 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8661 Use <Value> for the code segment name.
8665 \labelwidthstring 00.00.0000
8672 \begin_layout Standard
8685 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8689 Use <Value> for the const segment name.
8692 \begin_layout Standard
8693 \begin_inset VSpace bigskip
8699 \begin_layout Subsection
8700 Optimization Options
8701 \begin_inset LatexCommand \index{Options optimization}
8706 \begin_inset LatexCommand \index{Optimization options}
8714 \labelwidthstring 00.00.0000
8721 \begin_layout Standard
8731 \begin_inset LatexCommand \index{-\/-nogcse}
8737 Will not do global subexpression elimination, this option may be used when
8738 the compiler creates undesirably large stack/data spaces to store compiler
8748 \begin_inset LatexCommand \index{sloc (spill location)}
8753 A warning message will be generated when this happens and the compiler
8754 will indicate the number of extra bytes it allocated.
8755 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8757 \begin_inset LatexCommand \index{\#pragma nogcse}
8761 can be used to turn off global subexpression elimination
8762 \begin_inset LatexCommand \index{Subexpression elimination}
8766 for a given function only.
8770 \labelwidthstring 00.00.0000
8777 \begin_layout Standard
8787 \begin_inset LatexCommand \index{-\/-noinvariant}
8793 Will not do loop invariant optimizations, this may be turned off for reasons
8794 explained for the previous option.
8795 For more details of loop optimizations performed see Loop Invariants in
8797 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8802 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8804 \begin_inset LatexCommand \index{\#pragma noinvariant}
8808 can be used to turn off invariant optimizations for a given function only.
8812 \labelwidthstring 00.00.0000
8819 \begin_layout Standard
8829 \begin_inset LatexCommand \index{-\/-noinduction}
8835 Will not do loop induction optimizations, see section strength reduction
8837 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8839 \begin_inset LatexCommand \index{\#pragma noinduction}
8843 can be used to turn off induction optimizations for a given function only.
8847 \labelwidthstring 00.00.0000
8854 \begin_layout Standard
8864 \begin_inset LatexCommand \index{-\/-nojtbound}
8875 Will not generate boundary condition check when switch statements
8876 \begin_inset LatexCommand \index{switch statement}
8880 are implemented using jump-tables.
8882 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8887 Switch Statements for more details.
8888 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8890 \begin_inset LatexCommand \index{\#pragma nojtbound}
8894 can be used to turn off boundary checking for jump tables for a given function
8899 \labelwidthstring 00.00.0000
8906 \begin_layout Standard
8916 \begin_inset LatexCommand \index{-\/-noloopreverse}
8925 Will not do loop reversal
8926 \begin_inset LatexCommand \index{Loop reversing}
8934 \labelwidthstring 00.00.0000
8939 \begin_layout Standard
8953 \begin_inset LatexCommand \index{-\/-nolabelopt }
8957 Will not optimize labels (makes the dumpfiles more readable).
8961 \labelwidthstring 00.00.0000
8968 \begin_layout Standard
8978 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8984 Will not memcpy initialized data from code space into xdata space.
8985 This saves a few bytes in code space if you don't have initialized data
8986 \begin_inset LatexCommand \index{Variable initialization}
8994 \labelwidthstring 00.00.0000
9001 \begin_layout Standard
9011 \begin_inset LatexCommand \index{-\/-nooverlay}
9017 The compiler will not overlay parameters and local variables of any function,
9018 see section Parameters and local variables for more details.
9022 \labelwidthstring 00.00.0000
9029 \begin_layout Standard
9039 \begin_inset LatexCommand \index{-\/-no-peep}
9045 Disable peep-hole optimization with built-in rules.
9049 \labelwidthstring 00.00.0000
9056 \begin_layout Standard
9068 \begin_inset LatexCommand \index{-\/-peep-file}
9073 <filename> This option can be used to use additional rules to be used by
9074 the peep hole optimizer.
9076 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9081 Peep Hole optimizations for details on how to write these rules.
9085 \labelwidthstring 00.00.0000
9092 \begin_layout Standard
9102 \begin_inset LatexCommand \index{-\/-peep-asm}
9108 Pass the inline assembler code through the peep hole optimizer.
9109 This can cause unexpected changes to inline assembler code, please go through
9110 the peephole optimizer
9111 \begin_inset LatexCommand \index{Peephole optimizer}
9115 rules defined in the source file tree '<target>/peeph.def' before using
9120 \labelwidthstring 00.00.0000
9127 \begin_layout Standard
9137 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9143 The compiler will optimize code generation towards fast code, possibly
9144 at the expense of code size.
9148 \labelwidthstring 00.00.0000
9155 \begin_layout Standard
9165 \begin_inset LatexCommand \index{-\/-opt-code-size}
9171 The compiler will optimize code generation towards compact code, possibly
9172 at the expense of code speed.
9175 \begin_layout Standard
9176 \begin_inset VSpace bigskip
9182 \begin_layout Subsection
9184 \begin_inset LatexCommand \index{Options other}
9192 \labelwidthstring 00.00.0000
9200 \begin_layout Standard
9210 \begin_inset LatexCommand \index{-\/-compile-only}
9215 \begin_inset LatexCommand \index{-c -\/-compile-only}
9221 will compile and assemble the source, but will not call the linkage editor.
9225 \labelwidthstring 00.00.0000
9234 \begin_layout Standard
9246 \begin_inset LatexCommand \index{-\/-c1mode}
9252 reads the preprocessed source from standard input and compiles it.
9253 The file name for the assembler output must be specified using the -o option.
9257 \labelwidthstring 00.00.0000
9261 \begin_inset LatexCommand \index{-E}
9267 Run only the C preprocessor.
9268 Preprocess all the C source files specified and output the results to standard
9273 \labelwidthstring 00.00.0000
9278 \begin_inset LatexCommand \index{-o <path/file>}
9284 The output path where everything will be placed or the file name used for
9285 all generated output files.
9286 If the parameter is a path, it must have a trailing slash (or backslash
9287 for the Windows binaries) to be recognized as a path.
9292 Note for Windows users: if the path contains spaces, it should be surrounded
9294 The trailing backslash should be doubled in order to prevent escaping the
9295 final quote, for example:
9298 \begin_inset Quotes sld
9312 \begin_inset Quotes srd
9317 or put after the final quote, for example:
9320 \begin_inset Quotes sld
9330 \begin_inset Quotes srd
9338 The path using slashes for directory delimiters can be used too, for example:
9342 \begin_inset Quotes sld
9345 F:/Projects/test3/output 1/
9346 \begin_inset Quotes srd
9355 \labelwidthstring 00.00.0000
9362 \begin_layout Standard
9372 \begin_inset LatexCommand \index{-\/-stack-auto}
9383 All functions in the source file will be compiled as
9388 \begin_inset LatexCommand \index{reentrant}
9393 the parameters and local variables will be allocated on the stack
9394 \begin_inset LatexCommand \index{stack}
9400 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9404 Parameters and Local Variables for more details.
9405 If this option is used all source files in the project should be compiled
9407 It automatically implies --int-long-reent and --float-reent.
9412 \labelwidthstring 00.00.0000
9419 \begin_layout Standard
9429 \begin_inset LatexCommand \index{-\/-callee-saves}
9434 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9438 function1[,function2][,function3]....
9441 The compiler by default uses a caller saves convention for register saving
9442 across function calls, however this can cause unnecessary register pushing
9443 and popping when calling small functions from larger functions.
9444 This option can be used to switch the register saving convention for the
9445 function names specified.
9446 The compiler will not save registers when calling these functions, no extra
9447 code will be generated at the entry and exit (function prologue
9450 \begin_inset LatexCommand \index{function prologue}
9459 \begin_inset LatexCommand \index{function epilogue}
9465 ) for these functions to save and restore the registers used by these functions,
9466 this can SUBSTANTIALLY reduce code and improve run time performance of
9468 In the future the compiler (with inter procedural analysis) will be able
9469 to determine the appropriate scheme to use for each function call.
9470 DO NOT use this option for built-in functions such as _mulint..., if this
9471 option is used for a library function the appropriate library function
9472 needs to be recompiled with the same option.
9473 If the project consists of multiple source files then all the source file
9474 should be compiled with the same -
9478 \begin_layout Standard
9487 -callee-saves option string.
9488 Also see #pragma\InsetSpace ~
9490 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9495 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9503 \labelwidthstring 00.00.0000
9510 \begin_layout Standard
9520 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9534 \begin_layout Standard
9543 -callee-saves will be applied to all functions by default.
9547 \labelwidthstring 00.00.0000
9554 \begin_layout Standard
9564 \begin_inset LatexCommand \index{-\/-debug}
9573 When this option is used the compiler will generate debug information.
9574 The debug information collected in a file with .cdb extension can be used
9576 For more information see documentation for SDCDB.
9577 Another file with no extension contains debug information in AOMF or AOMF51
9578 \begin_inset LatexCommand \index{AOMF, AOMF51}
9582 format which is commonly used by third party tools.
9586 \labelwidthstring 00.00.0000
9590 \begin_inset LatexCommand \index{-S}
9601 Stop after the stage of compilation proper; do not assemble.
9602 The output is an assembler code file for the input file specified.
9606 \labelwidthstring 00.00.0000
9613 \begin_layout Standard
9623 \begin_inset LatexCommand \index{-\/-int-long-reent}
9629 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9630 Note by default these libraries are compiled as non-reentrant.
9631 See section Installation for more details.
9635 \labelwidthstring 00.00.0000
9642 \begin_layout Standard
9652 \begin_inset LatexCommand \index{-\/-cyclomatic}
9661 This option will cause the compiler to generate an information message for
9662 each function in the source file.
9663 The message contains some
9667 information about the function.
9668 The number of edges and nodes the compiler detected in the control flow
9669 graph of the function, and most importantly the
9671 cyclomatic complexity
9672 \begin_inset LatexCommand \index{Cyclomatic complexity}
9678 see section on Cyclomatic Complexity for more details.
9682 \labelwidthstring 00.00.0000
9689 \begin_layout Standard
9699 \begin_inset LatexCommand \index{-\/-float-reent}
9705 Floating point library is compiled as reentrant
9706 \begin_inset LatexCommand \index{reentrant}
9711 See section Installation for more details.
9715 \labelwidthstring 00.00.0000
9722 \begin_layout Standard
9732 \begin_inset LatexCommand \index{-\/-funsigned-char}
9738 The default signedness for every type is
9743 In some embedded environments the default signedness of
9752 To set the signess for characters to unsigned, use the option --funsigned-char.
9753 If this option is set and no signedness keyword (unsigned/signed) is given,
9754 a char will be signed.
9755 All other types are unaffected.
9759 \labelwidthstring 00.00.0000
9766 \begin_layout Standard
9776 \begin_inset LatexCommand \index{-\/-main-return}
9782 This option can be used if the code generated is called by a monitor program
9783 or if the main routine includes an endless loop.
9784 This option results in slightly smaller code and saves two bytes of stack
9786 The return from the 'main'
9787 \begin_inset LatexCommand \index{main return}
9791 function will return to the function calling main.
9792 The default setting is to lock up i.e.
9801 \labelwidthstring 00.00.0000
9808 \begin_layout Standard
9818 \begin_inset LatexCommand \index{-\/-nostdinc}
9824 This will prevent the compiler from passing on the default include path
9825 to the preprocessor.
9829 \labelwidthstring 00.00.0000
9836 \begin_layout Standard
9846 \begin_inset LatexCommand \index{-\/-nostdlib}
9852 This will prevent the compiler from passing on the default library
9853 \begin_inset LatexCommand \index{Libraries}
9861 \labelwidthstring 00.00.0000
9868 \begin_layout Standard
9878 \begin_inset LatexCommand \index{-\/-verbose}
9884 Shows the various actions the compiler is performing.
9888 \labelwidthstring 00.00.0000
9892 \begin_inset LatexCommand \index{-V}
9898 Shows the actual commands the compiler is executing.
9902 \labelwidthstring 00.00.0000
9909 \begin_layout Standard
9919 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9925 Hides your ugly and inefficient c-code from the asm file, so you can always
9926 blame the compiler :)
9930 \labelwidthstring 00.00.0000
9937 \begin_layout Standard
9947 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9953 Include code generator and peep-hole comments in the generated asm files.
9957 \labelwidthstring 00.00.0000
9964 \begin_layout Standard
9974 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9980 Don't include peep-hole comments in the generated asm files even if --fverbose-
9981 asm option is specified.
9985 \labelwidthstring 00.00.0000
9992 \begin_layout Standard
10002 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10008 Include i-codes in the asm file.
10009 Sounds like noise but is most helpful for debugging the compiler itself.
10013 \labelwidthstring 00.00.0000
10020 \begin_layout Standard
10030 \begin_inset LatexCommand \index{pedantic}
10035 \begin_inset LatexCommand \index{-\/-less-pedantic}
10042 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10046 Disable some of the more pedantic warnings
10047 \begin_inset LatexCommand \index{Warnings}
10052 For more details, see the less_pedantic pragma
10053 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10061 \labelwidthstring 00.00.0000
10068 \begin_layout Standard
10077 -disable-warning\InsetSpace ~
10079 \begin_inset LatexCommand \index{-\/-disable-warning}
10085 Disable specific warning with number <nnnn>.
10089 \labelwidthstring 00.00.0000
10096 \begin_layout Standard
10106 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10112 Display the directories in the compiler's search path
10116 \labelwidthstring 00.00.0000
10123 \begin_layout Standard
10133 \begin_inset LatexCommand \index{-\/-vc}
10139 Display errors and warnings using MSVC style, so you can use SDCC with
10140 the visual studio IDE
10141 \begin_inset LatexCommand \index{IDE}
10146 With SDCC both offering a GCC-like (the default) and a MSVC-like
10147 \begin_inset LatexCommand \index{MSVC output style}
10151 output style, integration into most programming editors should be straightforwa
10156 \labelwidthstring 00.00.0000
10163 \begin_layout Standard
10173 \begin_inset LatexCommand \index{-\/-use-stdout}
10179 Send errors and warnings to stdout instead of stderr.
10183 \labelwidthstring 00.00.0000
10187 asmOption[,asmOption]
10190 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10195 Pass the asmOption to the assembler
10196 \begin_inset LatexCommand \index{Options assembler}
10201 \begin_inset LatexCommand \index{Assembler options}
10206 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10210 \labelwidthstring 00.00.0000
10217 \begin_layout Standard
10227 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10233 Generally follow the C89 standard, but allow SDCC features that conflict
10234 with the standard (default).
10238 \labelwidthstring 00.00.0000
10245 \begin_layout Standard
10255 \begin_inset LatexCommand \index{-\/-std-c89}
10261 Follow the C89 standard and disable SDCC features that conflict with the
10266 \labelwidthstring 00.00.0000
10273 \begin_layout Standard
10283 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10289 Generally follow the C99 standard, but allow SDCC features that conflict
10290 with the standard (incomplete support).
10294 \labelwidthstring 00.00.0000
10301 \begin_layout Standard
10311 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10317 Follow the C99 standard and disable SDCC features that conflict with the
10318 standard (incomplete support).
10322 \labelwidthstring 00.00.0000
10329 \begin_layout Standard
10341 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10346 <Name> The name to be used for the code
10347 \begin_inset LatexCommand \index{code}
10351 segment, default CSEG.
10352 This is useful if you need to tell the compiler to put the code in a special
10353 segment so you can later on tell the linker to put this segment in a special
10355 Can be used for instance when using bank switching to put the code in a
10360 \labelwidthstring 00.00.0000
10367 \begin_layout Standard
10379 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10384 <Name> The name to be used for the const
10385 \begin_inset LatexCommand \index{const}
10389 segment, default CONST.
10390 This is useful if you need to tell the compiler to put the const data in
10391 a special segment so you can later on tell the linker to put this segment
10392 in a special place in memory.
10393 Can be used for instance when using bank switching to put the const data
10398 \labelwidthstring 00.00.0000
10405 \begin_layout Standard
10414 -fdollars-in-identifiers
10415 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10421 Permit '$' as an identifier character.
10425 \labelwidthstring 00.00.0000
10432 \begin_layout Standard
10444 \begin_inset LatexCommand \index{-\/-more-pedantic}
10449 \begin_inset LatexCommand \index{pedantic}
10459 a SDCC compiler option but if you want
10463 warnings you can use a separate tool dedicated to syntax checking like
10465 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10470 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10475 \begin_inset LatexCommand \url{http://www.splint.org}
10480 To make your source files parseable by splint you will have to include
10486 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10490 in your source file and add brackets around extended keywords (like
10493 \begin_inset Quotes sld
10506 \begin_inset Quotes srd
10514 \begin_inset Quotes sld
10517 __interrupt\InsetSpace ~
10519 \begin_inset Quotes srd
10527 Splint has an excellent on line manual at
10528 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10532 and it's capabilities go beyond pure syntax checking.
10533 You'll need to tell splint the location of SDCC's include files so a typical
10534 command line could look like this:
10538 splint\InsetSpace ~
10540 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10546 \labelwidthstring 00.00.0000
10553 \begin_layout Standard
10565 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10570 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10574 Treat short as 8-bit (for backward compatibility with older versions of
10575 compiler - see section
10576 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10583 \begin_layout Standard
10584 \begin_inset VSpace bigskip
10590 \begin_layout Subsection
10591 Intermediate Dump Options
10592 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10597 \begin_inset LatexCommand \index{Options intermediate dump}
10602 \begin_inset LatexCommand \index{Intermediate dump options}
10609 \begin_layout Standard
10610 The following options are provided for the purpose of retargetting and debugging
10612 They provide a means to dump the intermediate code (iCode
10613 \begin_inset LatexCommand \index{iCode}
10617 ) generated by the compiler in human readable form at various stages of
10618 the compilation process.
10619 More on iCodes see chapter
10620 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10625 \begin_inset Quotes srd
10628 The anatomy of the compiler
10629 \begin_inset Quotes srd
10636 \labelwidthstring 00.00.0000
10643 \begin_layout Standard
10653 \begin_inset LatexCommand \index{-\/-dumpraw}
10659 This option will cause the compiler to dump the intermediate code into
10662 <source filename>.dumpraw
10664 just after the intermediate code has been generated for a function, i.e.
10665 before any optimizations are done.
10667 \begin_inset LatexCommand \index{Basic blocks}
10671 at this stage ordered in the depth first number, so they may not be in
10672 sequence of execution.
10676 \labelwidthstring 00.00.0000
10683 \begin_layout Standard
10693 \begin_inset LatexCommand \index{-\/-dumpgcse}
10699 Will create a dump of iCode's, after global subexpression elimination
10700 \begin_inset LatexCommand \index{Global subexpression elimination}
10704 , into a file named
10706 <source filename>.dumpgcse.
10710 \labelwidthstring 00.00.0000
10717 \begin_layout Standard
10727 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10733 Will create a dump of iCode's, after deadcode elimination
10734 \begin_inset LatexCommand \index{Dead-code elimination}
10738 , into a file named
10740 <source filename>.dumpdeadcode.
10744 \labelwidthstring 00.00.0000
10751 \begin_layout Standard
10761 \begin_inset LatexCommand \index{-\/-dumploop}
10770 Will create a dump of iCode's, after loop optimizations
10771 \begin_inset LatexCommand \index{Loop optimization}
10775 , into a file named
10777 <source filename>.dumploop.
10781 \labelwidthstring 00.00.0000
10788 \begin_layout Standard
10798 \begin_inset LatexCommand \index{-\/-dumprange}
10807 Will create a dump of iCode's, after live range analysis
10808 \begin_inset LatexCommand \index{Live range analysis}
10812 , into a file named
10814 <source filename>.dumprange.
10818 \labelwidthstring 00.00.0000
10825 \begin_layout Standard
10835 \begin_inset LatexCommand \index{-\/-dumlrange}
10841 Will dump the life ranges
10842 \begin_inset LatexCommand \index{Live range analysis}
10850 \labelwidthstring 00.00.0000
10857 \begin_layout Standard
10867 \begin_inset LatexCommand \index{-\/-dumpregassign}
10876 Will create a dump of iCode's, after register assignment
10877 \begin_inset LatexCommand \index{Register assignment}
10881 , into a file named
10883 <source filename>.dumprassgn.
10887 \labelwidthstring 00.00.0000
10894 \begin_layout Standard
10904 \begin_inset LatexCommand \index{-\/-dumplrange}
10910 Will create a dump of the live ranges of iTemp's
10914 \labelwidthstring 00.00.0000
10921 \begin_layout Standard
10931 \begin_inset LatexCommand \index{-\/-dumpall}
10942 Will cause all the above mentioned dumps to be created.
10945 \begin_layout Standard
10946 \begin_inset VSpace bigskip
10952 \begin_layout Subsection
10953 Redirecting output on Windows Shells
10956 \begin_layout Standard
10957 By default SDCC writes it's error messages to
10958 \begin_inset Quotes sld
10962 \begin_inset Quotes srd
10966 To force all messages to
10967 \begin_inset Quotes sld
10971 \begin_inset Quotes srd
10983 \begin_layout Standard
10998 \begin_inset LatexCommand \index{-\/-use-stdout}
11003 Additionally, if you happen to have visual studio installed in your windows
11004 machine, you can use it to compile your sources using a custom build and
11011 \begin_layout Standard
11023 \begin_inset LatexCommand \index{-\/-vc}
11028 Something like this should work:
11047 \begin_layout Standard
11066 \begin_layout Standard
11078 -model-large -c $(InputPath)
11081 \begin_inset VSpace bigskip
11087 \begin_layout Section
11088 Environment variables
11089 \begin_inset LatexCommand \index{Environment variables}
11096 \begin_layout Standard
11097 SDCC recognizes the following environment variables:
11101 \labelwidthstring 00.00.0000
11105 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11111 SDCC installs a signal handler
11112 \begin_inset LatexCommand \index{signal handler}
11116 to be able to delete temporary files after an user break (^C) or an exception.
11117 If this environment variable is set, SDCC won't install the signal handler
11118 in order to be able to debug SDCC.
11122 \labelwidthstring 00.00.0000
11128 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11134 Path, where temporary files will be created.
11135 The order of the variables is the search order.
11136 In a standard *nix environment these variables are not set, and there's
11137 no need to set them.
11138 On Windows it's recommended to set one of them.
11142 \labelwidthstring 00.00.0000
11146 \begin_inset LatexCommand \index{SDCC\_HOME}
11153 \begin_inset LatexCommand \ref{sub:Install-paths}
11159 \begin_inset Quotes sld
11163 \begin_inset Quotes srd
11170 \labelwidthstring 00.00.0000
11174 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11181 \begin_inset LatexCommand \ref{sub:Search-Paths}
11187 \begin_inset Quotes sld
11191 \begin_inset Quotes srd
11198 \labelwidthstring 00.00.0000
11202 \begin_inset LatexCommand \index{SDCC\_LIB}
11209 \begin_inset LatexCommand \ref{sub:Search-Paths}
11215 \begin_inset Quotes sld
11219 \begin_inset Quotes srd
11225 \begin_layout Standard
11226 There are some more environment variables recognized by SDCC, but these
11227 are solely used for debugging purposes.
11228 They can change or disappear very quickly, and will never be documented.
11229 \begin_inset VSpace bigskip
11235 \begin_layout Section
11236 Storage Class Language Extensions
11239 \begin_layout Subsection
11240 MCS51/DS390 Storage Class
11241 \begin_inset LatexCommand \index{Storage class}
11245 Language Extensions
11248 \begin_layout Standard
11249 In addition to the ANSI storage classes SDCC allows the following MCS51
11250 specific storage classes:
11253 \begin_layout Subsubsection
11255 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11260 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11265 \begin_inset LatexCommand \index{near (storage class)}
11270 \begin_inset LatexCommand \index{\_\_near (storage class)}
11277 \begin_layout Standard
11282 storage class for the Small Memory model (
11290 or the more ANSI-C compliant forms
11298 can be used synonymously).
11299 Variables declared with this storage class will be allocated in the directly
11300 addressable portion of the internal RAM of a 8051, e.g.:
11303 \begin_layout Verse
11306 __data unsigned char test_data;
11309 \begin_layout Standard
11310 Writing 0x01 to this variable generates the assembly code:
11313 \begin_layout Verse
11316 75*00 01\InsetSpace ~
11324 \begin_layout Subsubsection
11326 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11331 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11336 \begin_inset LatexCommand \index{far (storage class)}
11341 \begin_inset LatexCommand \index{\_\_far (storage class)}
11348 \begin_layout Standard
11349 Variables declared with this storage class will be placed in the external
11355 storage class for the Large Memory model, e.g.:
11358 \begin_layout Verse
11361 __xdata unsigned char test_xdata;
11364 \begin_layout Standard
11365 Writing 0x01 to this variable generates the assembly code:
11368 \begin_layout Verse
11371 90s00r00\InsetSpace ~
11402 \begin_layout Subsubsection
11404 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11409 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11416 \begin_layout Standard
11417 Variables declared with this storage class will be allocated into the indirectly
11418 addressable portion of the internal ram of a 8051, e.g.:
11421 \begin_layout Verse
11424 __idata unsigned char test_idata;
11427 \begin_layout Standard
11428 Writing 0x01 to this variable generates the assembly code:
11431 \begin_layout Verse
11458 \begin_layout Standard
11459 Please note, the first 128 byte of idata physically access the same RAM
11460 as the data memory.
11461 The original 8051 had 128 byte idata memory, nowadays most devices have
11462 256 byte idata memory.
11464 \begin_inset LatexCommand \index{stack}
11468 is located in idata memory.
11471 \begin_layout Subsubsection
11473 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11478 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11485 \begin_layout Standard
11486 Paged xdata access is just as straightforward as using the other addressing
11488 It is typically located at the start of xdata and has a maximum size of
11490 The following example writes 0x01 to the pdata variable.
11491 Please note, pdata access physically accesses xdata memory.
11492 The high byte of the address is determined by port P2
11493 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11497 (or in case of some 8051 variants by a separate Special Function Register,
11499 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11508 storage class for the Medium Memory model, e.g.:
11511 \begin_layout Verse
11514 __pdata unsigned char test_pdata;
11517 \begin_layout Standard
11518 Writing 0x01 to this variable generates the assembly code:
11521 \begin_layout Verse
11530 mov r0,#_test_pdata
11552 \begin_layout Standard
11557 \begin_layout Standard
11567 \begin_inset LatexCommand \index{-\/-xstack}
11571 option is used the pdata memory area is followed by the xstack memory area
11572 and the sum of their sizes is limited to 256 bytes.
11575 \begin_layout Subsubsection
11577 \begin_inset LatexCommand \index{code}
11582 \begin_inset LatexCommand \index{\_\_code}
11589 \begin_layout Standard
11590 'Variables' declared with this storage class will be placed in the code
11594 \begin_layout Verse
11597 __code unsigned char test_code;
11600 \begin_layout Standard
11601 Read access to this variable generates the assembly code:
11604 \begin_layout Verse
11607 90s00r6F\InsetSpace ~
11610 mov dptr,#_test_code
11635 \begin_layout Standard
11640 indexed arrays of characters in code memory can be accessed efficiently:
11643 \begin_layout Verse
11646 __code char test_array[] = {'c','h','e','a','p'};
11649 \begin_layout Standard
11650 Read access to this array using an 8-bit unsigned index generates the assembly
11654 \begin_layout Verse
11666 \begin_layout Verse
11669 90s00r41\InsetSpace ~
11672 mov dptr,#_test_array
11675 \begin_layout Verse
11690 \begin_layout Subsubsection
11692 \begin_inset LatexCommand \index{bit}
11697 \begin_inset LatexCommand \index{\_\_bit}
11704 \begin_layout Standard
11705 This is a data-type and a storage class specifier.
11706 When a variable is declared as a bit, it is allocated into the bit addressable
11707 memory of 8051, e.g.:
11710 \begin_layout Verse
11716 \begin_layout Standard
11717 Writing 1 to this variable generates the assembly code:
11720 \begin_layout Verse
11734 \begin_layout Standard
11735 The bit addressable memory consists of 128 bits which are located from 0x20
11736 to 0x2f in data memory.
11739 Apart from this 8051 specific storage class most architectures support
11741 \begin_inset LatexCommand \index{bitfields}
11749 \begin_layout Standard
11750 Not really meant as examples, but nevertheless showing what bitfields are
11751 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11757 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11758 signed modifier are implemented as unsigned.
11761 \begin_layout Subsubsection
11763 \begin_inset LatexCommand \index{sfr}
11768 \begin_inset LatexCommand \index{\_\_sfr}
11773 \begin_inset LatexCommand \index{sfr16}
11778 \begin_inset LatexCommand \index{\_\_sfr16}
11783 \begin_inset LatexCommand \index{sfr32}
11788 \begin_inset LatexCommand \index{\_\_sfr32}
11793 \begin_inset LatexCommand \index{\_\_sbit}
11798 \begin_inset LatexCommand \index{sbit}
11805 \begin_layout Standard
11806 Like the bit keyword,
11808 sfr / sfr16 / sfr32 / sbit
11810 signify both a data-type and storage class, they are used to describe the
11831 variables of a 8051, eg:
11834 \begin_layout Verse
11838 \begin_inset LatexCommand \index{at}
11843 \begin_inset LatexCommand \index{\_\_at}
11847 (0x80) P0;\InsetSpace ~
11848 /* special function register P0 at location 0x80 */
11853 special function register combination for timer 0
11857 with the high byte at
11858 location 0x8C and the low byte at location 0x8A */
11860 __sfr16 __at (0x8C8A)
11866 \begin_inset LatexCommand \index{at}
11871 \begin_inset LatexCommand \index{\_\_at}
11875 (0xd7) CY;\InsetSpace ~
11877 \begin_inset LatexCommand \index{Flags}
11882 \begin_inset LatexCommand \index{Carry flag}
11889 \begin_layout Standard
11890 Special function registers which are located on an address dividable by
11891 8 are bit-addressable, an
11895 addresses a specific bit within these sfr.
11897 16 Bit and 32 bit special function
11898 register combinations which require a certain access order are better not
11908 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11909 this is not guaranteed.
11914 \begin_layout Standard
11915 Please note, if you use a header file which was written for another compiler
11916 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11922 Specifically the syntax
11925 sfr P0 = 0x80;\InsetSpace ~
11932 by SDCC to an assignment of 0x80 to a variable called P0
11935 \begin_inset Marginal
11938 \begin_layout Standard
11950 Nevertheless it is possible to write header files
11951 \begin_inset LatexCommand \index{Header files}
11956 \begin_inset LatexCommand \index{Include files}
11960 which can be shared among different compilers (see section
11961 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11969 \begin_layout Subsubsection
11971 \begin_inset LatexCommand \index{Pointer}
11975 to MCS51/DS390 specific memory spaces
11978 \begin_layout Standard
11979 SDCC allows (via language extensions) pointers to explicitly point to any
11980 of the memory spaces
11981 \begin_inset LatexCommand \index{Memory model}
11986 In addition to the explicit pointers, the compiler uses (by default) generic
11987 pointers which can be used to point to any of the memory spaces.
11992 declaration examples:
11995 \begin_layout Verse
11998 /* pointer physically in internal ram pointing to object in external ram
12001 __xdata unsigned char * __data p;
12005 /* pointer physically in external ram
12006 pointing to object in internal ram */
12008 __data unsigned char * __xdata p;
12013 pointer physically in code rom pointing to data in xdata space */
12016 unsigned char * __code p;
12020 /* pointer physically in code space pointing to
12021 data in code space */
12023 __code unsigned char * __code p;
12028 physically located in xdata space */
12030 unsigned char * __xdata p;
12035 pointer physically located in default memory space */
12042 the following is a function pointer
12043 \begin_inset LatexCommand \index{function pointer}
12047 physically located in data space */
12049 char (* __data fp)(void);
12052 \begin_layout Standard
12053 Well you get the idea.
12058 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12071 The highest order byte of the
12075 pointers contains the data space information.
12076 Assembler support routines are called whenever data is stored or retrieved
12082 These are useful for developing reusable library
12083 \begin_inset LatexCommand \index{Libraries}
12088 Explicitly specifying the pointer
12089 \begin_inset LatexCommand \index{pointer}
12093 type will generate the most efficient code.
12096 \begin_layout Subsubsection
12097 Notes on MCS51 memory
12098 \begin_inset LatexCommand \index{MCS51 memory}
12105 \begin_layout Standard
12106 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12107 RAM memory which is structured as follows:
12111 - Bytes 00-1F - 32 bytes to hold
12112 up to 4 banks of the registers R0 to R7,
12114 - Bytes 20-2F - 16 bytes to hold
12116 \begin_inset LatexCommand \index{bit}
12122 - Bytes 30-7F - 80 bytes for general purpose use.
12127 \begin_layout Standard
12128 Additionally some members of the MCS51 family may have up to 128 bytes of
12129 additional, indirectly addressable, internal RAM memory (
12134 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12139 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12144 Furthermore, some chips may have some built in external memory (
12149 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12154 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12158 ) which should not be confused with the internal, directly addressable RAM
12164 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12169 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12174 Sometimes this built in
12178 memory has to be activated before using it (you can probably find this
12179 information on the datasheet of the microcontroller your are using, see
12181 \begin_inset LatexCommand \ref{sub:Startup-Code}
12189 \begin_layout Standard
12190 Normally SDCC will only use the first bank
12191 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12195 of registers (register bank 0), but it is possible to specify that other
12196 banks of registers (keyword
12203 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12208 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12214 ) should be used for example in interrupt
12215 \begin_inset LatexCommand \index{interrupt}
12220 \begin_inset LatexCommand \index{\_\_interrupt}
12225 By default, the compiler will place the stack after the last byte of allocated
12226 memory for variables.
12227 For example, if the first 2 banks of registers are used, and only four
12232 variables, it will position the base of the internal stack at address 20
12234 This implies that as the stack
12235 \begin_inset LatexCommand \index{stack}
12239 grows, it will use up the remaining register banks, and the 16 bytes used
12240 by the 128 bit variables, and 80 bytes for general purpose use.
12241 If any bit variables are used, the data variables will be placed in unused
12242 register banks and after the byte holding the last bit variable.
12243 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12248 variables will be placed starting from address 0x10 to 0x20 and continue
12254 \begin_layout Standard
12264 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12268 to specify the start address of the
12276 \begin_layout Standard
12286 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12290 to specify the size of the total internal RAM (
12304 \begin_layout Standard
12305 By default the 8051 linker will place the stack after the last byte of (i)data
12311 \begin_layout Standard
12321 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12325 allows you to specify the start of the stack, i.e.
12326 you could start it after any data in the general purpose area.
12327 If your microcontroller has additional indirectly addressable internal
12332 ) you can place the stack on it.
12333 You may also need to use -
12337 \begin_layout Standard
12347 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12351 to set the start address of the external RAM (
12359 \begin_layout Standard
12369 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12373 to specify its size.
12374 Same goes for the code memory, using -
12378 \begin_layout Standard
12388 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12396 \begin_layout Standard
12406 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12411 If in doubt, don't specify any options and see if the resulting memory
12412 layout is appropriate, then you can adjust it.
12415 \begin_layout Standard
12416 The linker generates two files with memory allocation information.
12417 The first, with extension .map
12418 \begin_inset LatexCommand \index{<file>.map}
12422 shows all the variables and segments.
12423 The second with extension .mem
12424 \begin_inset LatexCommand \index{<file>.mem}
12428 shows the final memory layout.
12429 The linker will complain either if memory segments overlap, there is not
12430 enough memory, or there is not enough space for stack.
12431 If you get any linking warnings and/or errors related to stack or segments
12432 allocation, take a look at either the .map or .mem files to find out what
12434 The .mem file may even suggest a solution to the problem.
12435 \begin_inset VSpace bigskip
12441 \begin_layout Subsection
12442 Z80/Z180 Storage Class
12443 \begin_inset LatexCommand \index{Z80!Storage class}
12447 Language Extensions
12450 \begin_layout Subsubsection
12452 \begin_inset LatexCommand \index{sfr}
12457 \begin_inset LatexCommand \index{\_\_sfr}
12461 (in/out to 8-bit addresses)
12464 \begin_layout Standard
12466 \begin_inset LatexCommand \index{Z80}
12470 family has separate address spaces for memory and
12480 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12485 \begin_inset LatexCommand \index{Z80!I/O memory}
12490 \begin_inset LatexCommand \index{Z180!I/O memory}
12494 is accessed with special instructions, e.g.:
12497 \begin_layout Verse
12500 sfr at 0x78 IoPort;\InsetSpace ~
12502 /* define a var in I/O space at 78h called IoPort */
12506 \begin_layout Standard
12507 Writing 0x01 to this variable generates the assembly code:
12510 \begin_layout Verse
12530 \begin_layout Subsubsection
12532 \begin_inset LatexCommand \index{sfr}
12537 \begin_inset LatexCommand \index{\_\_sfr}
12541 (in/out to 16-bit addresses)
12544 \begin_layout Standard
12549 is used to support 16 bit addresses in I/O memory e.g.:
12552 \begin_layout Verse
12556 \begin_inset LatexCommand \index{at}
12561 \begin_inset LatexCommand \index{\_\_at}
12568 \begin_layout Standard
12569 Writing 0x01 to this variable generates the assembly code:
12572 \begin_layout Verse
12575 01 23 01\InsetSpace ~
12597 \begin_layout Subsubsection
12599 \begin_inset LatexCommand \index{sfr}
12604 \begin_inset LatexCommand \index{\_\_sfr}
12608 (in0/out0 to 8 bit addresses on Z180
12609 \begin_inset LatexCommand \index{Z180}
12614 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12621 \begin_layout Standard
12622 The compiler option -
12626 \begin_layout Standard
12636 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12640 =180 (80) and a compiler #pragma\InsetSpace ~
12642 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12646 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12656 If you include the file z180.h this will be set automatically.
12657 \begin_inset VSpace bigskip
12663 \begin_layout Subsection
12665 \begin_inset LatexCommand \index{HC08!Storage class}
12669 Language Extensions
12672 \begin_layout Subsubsection
12674 \begin_inset LatexCommand \index{data (hc08 storage class)}
12679 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12686 \begin_layout Standard
12687 The data storage class declares a variable that resides in the first 256
12688 bytes of memory (the direct page).
12690 \begin_inset LatexCommand \index{HC08}
12694 is most efficient at accessing variables (especially pointers) stored here.
12697 \begin_layout Subsubsection
12699 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12704 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12711 \begin_layout Standard
12712 The xdata storage class declares a variable that can reside anywhere in
12714 This is the default if no storage class is specified.
12716 \begin_inset VSpace bigskip
12722 \begin_layout Section
12723 Absolute Addressing
12724 \begin_inset LatexCommand \index{Absolute addressing}
12731 \begin_layout Standard
12732 Data items can be assigned an absolute address with the
12735 \begin_inset LatexCommand \index{at}
12740 \begin_inset LatexCommand \index{\_\_at}
12746 keyword, in addition to a storage class, e.g.:
12749 \begin_layout Verse
12753 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12758 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12763 \begin_inset LatexCommand \index{at}
12768 \begin_inset LatexCommand \index{\_\_at}
12772 0x7ffe unsigned int chksum;
12775 \begin_layout Standard
12776 or, better conforming to ISO/IEC 9899 C:
12779 \begin_layout Verse
12782 __xdata __at (0x7ffe) unsigned int chksum;
12785 \begin_layout Standard
12786 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12787 of the external ram.
12792 reserve any space for variables declared in this way
12793 \begin_inset Marginal
12796 \begin_layout Standard
12805 (they are implemented with an equate in the assembler).
12806 Thus it is left to the programmer to make sure there are no overlaps with
12807 other variables that are declared without the absolute address.
12808 The assembler listing file (.lst
12809 \begin_inset LatexCommand \index{<file>.lst}
12813 ) and the linker output files (.rst
12814 \begin_inset LatexCommand \index{<file>.rst}
12819 \begin_inset LatexCommand \index{<file>.map}
12823 ) are good places to look for such overlaps.
12824 Variables with an absolute address are
12827 \begin_inset Marginal
12830 \begin_layout Standard
12842 \begin_inset LatexCommand \index{Variable initialization}
12849 \begin_layout Standard
12850 In case of memory mapped I/O devices the keyword
12854 has to be used to tell the compiler that accesses might not be removed:
12857 \begin_layout Verse
12861 \begin_inset LatexCommand \index{volatile}
12866 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12871 \begin_inset LatexCommand \index{at}
12875 (0x8000) unsigned char PORTA_8255;
12878 \begin_layout Standard
12879 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12884 \begin_inset LatexCommand \index{Aligned array}
12891 starts at a block (256 byte) boundary
12892 \begin_inset LatexCommand \index{block boundary}
12897 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12903 Absolute addresses can be specified for variables in all
12904 storage classes, e.g.:
12907 \begin_layout Verse
12911 \begin_inset LatexCommand \index{bit}
12916 \begin_inset LatexCommand \index{at}
12923 \begin_layout Standard
12924 The above example will allocate the variable at offset 0x02 in the bit-addressab
12926 There is no real advantage to assigning absolute addresses to variables
12927 in this manner, unless you want strict control over all the variables allocated.
12928 One possible use would be to write hardware portable code.
12929 For example, if you have a routine that uses one or more of the microcontroller
12930 I/O pins, and such pins are different for two different hardwares, you
12931 can declare the I/O pins in your routine using:
12934 \begin_layout Verse
12938 \begin_inset LatexCommand \index{volatile}
12942 __bit MOSI;\InsetSpace ~
12946 /* master out, slave in */
12948 extern volatile __bit MISO;\InsetSpace ~
12955 extern volatile __bit MCLK;\InsetSpace ~
12964 Output of a byte on a 3-wire serial bus.
12969 If needed adapt polarity of clock,
12970 polarity of data and bit order
12975 unsigned char spi_io(unsigned char out_byte)
13000 MOSI = out_byte & 0x80;
13031 /* _asm nop _endasm; */\InsetSpace ~
13039 /* for slow peripherals */
13091 \begin_layout Standard
13092 Then, someplace in the code for the first hardware you would use
13095 \begin_layout Verse
13099 \begin_inset LatexCommand \index{at}
13104 \begin_inset LatexCommand \index{\_\_at}
13108 (0x80) MOSI;\InsetSpace ~
13112 /* I/O port 0, bit 0 */
13114 __bit __at (0x81) MISO;\InsetSpace ~
13121 __bit __at (0x82) MCLK;\InsetSpace ~
13125 /* I/O port 0, bit 2 */
13128 \begin_layout Standard
13129 Similarly, for the second hardware you would use
13132 \begin_layout Verse
13135 __bit __at (0x83) MOSI;\InsetSpace ~
13139 /* I/O port 0, bit 3 */
13141 __bit __at (0x91) MISO;\InsetSpace ~
13146 I/O port 1, bit 1 */
13149 \begin_inset LatexCommand \index{bit}
13153 __at (0x92) MCLK;\InsetSpace ~
13157 /* I/O port 1, bit 2 */
13160 \begin_layout Standard
13161 and you can use the same hardware dependent routine without changes, as
13162 for example in a library.
13163 This is somehow similar to sbit, but only one absolute address has to be
13164 specified in the whole project.
13165 \begin_inset VSpace bigskip
13171 \begin_layout Section
13173 \begin_inset LatexCommand \index{Parameters}
13178 \begin_inset LatexCommand \index{function parameter}
13183 \begin_inset LatexCommand \index{local variables}
13188 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13195 \begin_layout Standard
13196 Automatic (local) variables and parameters to functions can either be placed
13197 on the stack or in data-space.
13198 The default action of the compiler is to place these variables in the internal
13199 RAM (for small model) or external RAM (for large model).
13200 This in fact makes them similar to
13203 \begin_inset LatexCommand \index{static}
13209 so by default functions are non-reentrant
13210 \begin_inset LatexCommand \index{reentrant}
13219 They can be placed on the stack
13220 \begin_inset LatexCommand \index{stack}
13230 \begin_layout Standard
13240 \begin_inset LatexCommand \index{-\/-stack-auto}
13248 #pragma\InsetSpace ~
13252 \begin_inset LatexCommand \index{\#pragma stackauto}
13259 \begin_inset LatexCommand \index{reentrant}
13265 keyword in the function declaration, e.g.:
13268 \begin_layout Verse
13271 unsigned char foo(char i) __reentrant
13285 \begin_layout Standard
13286 Since stack space on 8051 is limited, the
13296 \begin_layout Standard
13307 option should be used sparingly.
13308 Note that the reentrant keyword just means that the parameters & local
13309 variables will be allocated to the stack, it
13313 mean that the function is register bank
13314 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13323 \begin_inset LatexCommand \index{local variables}
13327 can be assigned storage classes and absolute
13328 \begin_inset LatexCommand \index{Absolute addressing}
13335 \begin_layout Verse
13338 unsigned char foo()
13346 __xdata unsigned char i;
13359 \begin_inset LatexCommand \index{at}
13363 (0x31) unsigned char j;
13375 \begin_layout Standard
13376 In the above example the variable
13380 will be allocated in the external ram,
13384 in bit addressable space and
13395 \begin_layout Standard
13406 or when a function is declared as
13410 this should only be done for static variables.
13413 \begin_layout Standard
13415 \begin_inset LatexCommand \index{function parameter}
13419 however are not allowed any storage class
13420 \begin_inset LatexCommand \index{Storage class}
13424 , (storage classes for parameters will be ignored), their allocation is
13425 governed by the memory model in use, and the reentrancy options.
13428 \begin_layout Standard
13429 It is however allowed to use bit parameters in reentrant functions and also
13430 non-static local bit variables are supported.
13431 Efficient use is limited to 8 semi-bitregisters in bit space.
13432 They are pushed and popped to stack
13433 \begin_inset LatexCommand \index{stack}
13437 as a single byte just like the normal registers.
13440 \begin_layout Section
13442 \begin_inset LatexCommand \label{sub:Overlaying}
13447 \begin_inset LatexCommand \index{Overlaying}
13454 \begin_layout Standard
13456 \begin_inset LatexCommand \index{reentrant}
13460 functions SDCC will try to reduce internal ram space usage by overlaying
13461 parameters and local variables of a function (if possible).
13462 Parameters and local variables
13463 \begin_inset LatexCommand \index{local variables}
13467 of a function will be allocated to an overlayable segment if the function
13470 no other function calls and the function is non-reentrant and the memory
13472 \begin_inset LatexCommand \index{Memory model}
13479 If an explicit storage class
13480 \begin_inset LatexCommand \index{Storage class}
13484 is specified for a local variable, it will NOT be overlayed.
13487 \begin_layout Standard
13488 Note that the compiler (not the linkage editor) makes the decision for overlayin
13490 Functions that are called from an interrupt service routine
13491 \begin_inset Marginal
13494 \begin_layout Standard
13502 should be preceded by a #pragma\InsetSpace ~
13504 \begin_inset LatexCommand \index{\#pragma nooverlay}
13508 if they are not reentrant.
13511 \begin_layout Standard
13512 Also note that the compiler does not do any processing of inline assembler
13513 code, so the compiler might incorrectly assign local variables and parameters
13514 of a function into the overlay segment if the inline assembler code calls
13515 other c-functions that might use the overlay.
13516 In that case the #pragma\InsetSpace ~
13517 nooverlay should be used.
13520 \begin_layout Standard
13521 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13523 \begin_inset LatexCommand \index{Multiplication}
13528 \begin_inset LatexCommand \index{Division}
13532 will NOT be overlayed since these are implemented using external functions,
13536 \begin_layout Verse
13542 \begin_inset LatexCommand \index{\#pragma nooverlay}
13548 void set_error(unsigned char errcd)
13565 some_isr () __interrupt
13566 \begin_inset LatexCommand \index{interrupt}
13596 \begin_layout Standard
13597 In the above example the parameter
13605 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13607 not present, this could cause unpredictable runtime behavior when called
13608 from an interrupt service routine.
13609 The #pragma\InsetSpace ~
13610 nooverlay ensures that the parameters and local variables for
13611 the function are NOT overlayed.
13612 \begin_inset VSpace bigskip
13618 \begin_layout Section
13619 Interrupt Service Routines
13620 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13627 \begin_layout Subsection
13628 General Information
13631 \begin_layout Standard
13644 outines to be coded in C, with some extended keywords.
13647 \begin_layout Verse
13650 void timer_isr (void) __interrupt (1) __using (1)
13664 \begin_layout Standard
13665 The optional number following the
13668 \begin_inset LatexCommand \index{interrupt}
13673 \begin_inset LatexCommand \index{\_\_interrupt}
13679 keyword is the interrupt number this routine will service.
13680 When present, the compiler will insert a call to this routine in the interrupt
13682 \begin_inset LatexCommand \index{interrupt vector table}
13686 for the interrupt number specified.
13687 If you have multiple source files in your project, interrupt service routines
13688 can be present in any of them, but a prototype of the isr MUST be present
13689 or included in the file that contains the function
13694 The optional (8051 specific) keyword
13697 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13702 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13708 can be used to tell the compiler to use the specified register bank when
13709 generating code for this function.
13712 Interrupt service routines open the door for some very interesting bugs:
13715 \begin_layout Subsubsection
13716 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13720 Common interrupt pitfall: variable not declared
13725 \begin_layout Standard
13726 If an interrupt service routine changes variables which are accessed by
13727 other functions these variables have to be declared
13732 \begin_inset LatexCommand \index{volatile}
13738 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13745 \begin_layout Subsubsection
13746 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13750 Common interrupt pitfall:
13755 \begin_layout Standard
13756 If the access to these variables is not
13759 \begin_inset LatexCommand \index{atomic}
13766 the processor needs more than one instruction for the access and could
13767 be interrupted while accessing the variable) the interrupt must be disabled
13768 during the access to avoid inconsistent data.
13771 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13772 and should be protected by disabling interrupts.
13773 You're not automatically on the safe side if you use 8 bit variables though.
13774 We need an example here: f.e.
13775 on the 8051 the harmless looking
13776 \begin_inset Quotes srd
13786 \begin_inset Quotes sld
13795 \begin_inset Quotes srd
13805 \begin_inset Quotes sld
13808 from within an interrupt routine might get lost if the interrupt occurs
13811 \begin_inset Quotes sld
13816 counter\InsetSpace ~
13821 \begin_inset Quotes srd
13824 is not atomic on the 8051 even if
13828 is located in data memory.
13830 Bugs like these are hard to reproduce and can
13831 cause a lot of trouble.
13835 \begin_layout Subsubsection
13836 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13840 Common interrupt pitfall:
13845 \begin_layout Standard
13846 The return address and the registers used in the interrupt service routine
13847 are saved on the stack
13848 \begin_inset LatexCommand \index{stack}
13852 so there must be sufficient stack space.
13853 If there isn't variables or registers (or even the return address itself)
13860 \begin_inset LatexCommand \index{stack overflow}
13864 is most likely to happen if the interrupt occurs during the
13865 \begin_inset Quotes sld
13869 \begin_inset Quotes srd
13872 subroutine when the stack is already in use for f.e.
13873 many return addresses.
13876 \begin_layout Subsubsection
13877 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13881 Common interrupt pitfall:
13883 use of non-reentrant functions
13886 \begin_layout Standard
13887 A special note here, int (16 bit) and long (32 bit) integer division
13888 \begin_inset LatexCommand \index{Division}
13893 \begin_inset LatexCommand \index{Multiplication}
13898 \begin_inset LatexCommand \index{Modulus}
13903 \begin_inset LatexCommand \index{Floating point support}
13907 operations are implemented using external support routines.
13908 If an interrupt service routine needs to do any of these operations then
13909 the support routines (as mentioned in a following section) will have to
13910 be recompiled using the
13916 \begin_layout Standard
13926 \begin_inset LatexCommand \index{-\/-stack-auto}
13932 option and the source file will need to be compiled using the
13938 \begin_layout Standard
13950 \begin_inset LatexCommand \index{-\/-int-long-reent}
13957 Note, the type promotion
13958 \begin_inset LatexCommand \index{type promotion}
13962 required by ANSI C can cause 16 bit routines to be used
13963 \begin_inset Marginal
13966 \begin_layout Standard
13975 without the programmer being aware of it.
13979 (unsigned char)(tail-1)
13981 within the if clause in section
13982 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13989 \begin_layout Standard
13990 Calling other functions from an interrupt service routine is not recommended,
13991 avoid it if possible.
13992 Note that when some function is called from an interrupt service routine
13993 it should be preceded by a #pragma\InsetSpace ~
13995 \begin_inset LatexCommand \index{\#pragma nooverlay}
13999 if it is not reentrant.
14000 Furthermore nonreentrant functions should not be called from the main program
14001 while the interrupt service routine might be active.
14002 They also must not be called from low priority interrupt service routines
14003 while a high priority interrupt service routine might be active.
14004 You could use semaphores or make the function
14008 if all parameters are passed in registers.
14011 \begin_inset LatexCommand \ref{sub:Overlaying}
14016 about Overlaying and section
14017 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14022 about Functions using private register banks.
14023 \begin_inset VSpace bigskip
14029 \begin_layout Subsection
14030 MCS51/DS390 Interrupt Service Routines
14033 \begin_layout Standard
14035 \begin_inset LatexCommand \index{interrupt}
14039 numbers and the corresponding address & descriptions for the Standard 8051/8052
14041 SDCC will automatically adjust the
14042 \begin_inset LatexCommand \index{interrupt vector table}
14046 to the maximum interrupt number specified.
14051 \begin_layout Standard
14053 \begin_inset Tabular
14054 <lyxtabular version="3" rows="9" columns="3">
14056 <column alignment="center" valignment="top" leftline="true" width="0in">
14057 <column alignment="left" valignment="top" leftline="true" width="0in">
14058 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14059 <row topline="true" bottomline="true">
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14063 \begin_layout Standard
14069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14072 \begin_layout Standard
14078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14081 \begin_layout Standard
14088 <row topline="true">
14089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14092 \begin_layout Standard
14098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14101 \begin_layout Standard
14107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14110 \begin_layout Standard
14117 <row topline="true">
14118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14121 \begin_layout Standard
14127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14130 \begin_layout Standard
14136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14139 \begin_layout Standard
14146 <row topline="true">
14147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14150 \begin_layout Standard
14156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14159 \begin_layout Standard
14165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14168 \begin_layout Standard
14175 <row topline="true">
14176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14179 \begin_layout Standard
14185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14188 \begin_layout Standard
14194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14197 \begin_layout Standard
14204 <row topline="true">
14205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14208 \begin_layout Standard
14214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14217 \begin_layout Standard
14223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14226 \begin_layout Standard
14233 <row topline="true">
14234 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14237 \begin_layout Standard
14243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14246 \begin_layout Standard
14252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14255 \begin_layout Standard
14262 <row topline="true">
14263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14266 \begin_layout Standard
14272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14275 \begin_layout Standard
14281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14284 \begin_layout Standard
14291 <row topline="true" bottomline="true">
14292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14295 \begin_layout Standard
14301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14304 \begin_layout Standard
14310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14313 \begin_layout Standard
14329 \begin_layout Standard
14330 If the interrupt service routine is defined without
14333 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14338 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14344 a register bank or with register bank 0 (
14348 0), the compiler will save the registers used by itself on the stack upon
14349 entry and restore them at exit, however if such an interrupt service routine
14350 calls another function then the entire register bank will be saved on the
14352 This scheme may be advantageous for small interrupt service routines which
14353 have low register usage.
14356 \begin_layout Standard
14357 If the interrupt service routine is defined to be using a specific register
14362 & psw are saved and restored, if such an interrupt service routine calls
14363 another function (using another register bank) then the entire register
14364 bank of the called function will be saved on the stack
14365 \begin_inset LatexCommand \index{stack}
14370 This scheme is recommended for larger interrupt service routines.
14371 \begin_inset VSpace bigskip
14377 \begin_layout Subsection
14379 \begin_inset LatexCommand \index{HC08}
14383 Interrupt Service Routines
14386 \begin_layout Standard
14387 Since the number of interrupts
14388 \begin_inset LatexCommand \index{HC08!interrupt}
14392 available is chip specific and the interrupt vector table always ends at
14393 the last byte of memory, the interrupt numbers corresponds to the interrupt
14394 vectors in reverse order of address.
14395 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14396 2 will use the interrupt vector at 0xfffa, and so on.
14397 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14398 this way; instead see section
14399 \begin_inset LatexCommand \ref{sub:Startup-Code}
14403 for details on customizing startup.
14404 \begin_inset VSpace bigskip
14410 \begin_layout Subsection
14411 Z80 Interrupt Service Routines
14414 \begin_layout Standard
14416 \begin_inset LatexCommand \index{Z80}
14420 uses several different methods for determining the correct interrupt
14421 \begin_inset LatexCommand \index{Z80!interrupt}
14425 vector depending on the hardware implementation.
14426 Therefore, SDCC ignores the optional interrupt number and does not attempt
14427 to generate an interrupt vector table.
14430 \begin_layout Standard
14431 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14432 instruction to return from the interrupt.
14433 To write an interrupt handler for the non-maskable interrupt, which needs
14434 a RETN instruction instead, add the
14441 \begin_layout Verse
14444 void nmi_isr (void) critical interrupt
14458 \begin_layout Standard
14459 However if you need to create a non-interruptable interrupt service routine
14460 you would also require the
14465 To distinguish between this and an nmi_isr you must provide an interrupt
14467 \begin_inset VSpace bigskip
14473 \begin_layout Section
14474 Enabling and Disabling Interrupts
14477 \begin_layout Subsection
14478 Critical Functions and Critical Statements
14481 \begin_layout Standard
14482 A special keyword may be associated with a block or a function declaring
14488 SDCC will generate code to disable all interrupts
14489 \begin_inset LatexCommand \index{interrupt}
14493 upon entry to a critical function and restore the interrupt enable to the
14494 previous state before returning.
14495 Nesting critical functions will need one additional byte on the stack
14496 \begin_inset LatexCommand \index{stack}
14503 \begin_layout Verse
14506 int foo () __critical
14507 \begin_inset LatexCommand \index{critical}
14512 \begin_inset LatexCommand \index{\_\_critical}
14537 \begin_layout Standard
14538 The critical attribute maybe used with other attributes like
14548 may also be used to disable interrupts more locally:
14551 \begin_layout Verse
14557 \begin_layout Standard
14558 More than one statement could have been included in the block.
14561 \begin_layout Subsection
14562 Enabling and Disabling Interrupts directly
14565 \begin_layout Standard
14567 \begin_inset LatexCommand \index{interrupt}
14571 can also be disabled and enabled directly (8051):
14574 \begin_layout Verse
14577 EA = 0;\InsetSpace ~
14603 \begin_layout Verse
14639 \begin_layout Verse
14642 EA = 1;\InsetSpace ~
14671 \begin_layout Verse
14710 \begin_layout Standard
14711 On other architectures which have seperate opcodes for enabling and disabling
14712 interrupts you might want to make use of defines with inline assembly
14713 \begin_inset LatexCommand \index{Assembler routines}
14718 \begin_inset LatexCommand \index{HC08!interrupt}
14725 \begin_layout Verse
14729 \begin_inset LatexCommand \index{\_asm}
14738 \begin_inset LatexCommand \index{\_endasm}
14745 \begin_layout Verse
14748 #define SEI _asm\InsetSpace ~
14755 \begin_layout Verse
14761 \begin_layout Standard
14762 Note: it is sometimes sufficient to disable only a specific interrupt source
14764 a timer or serial interrupt by manipulating an
14767 \begin_inset LatexCommand \index{interrupt mask}
14777 \begin_layout Standard
14778 Usually the time during which interrupts are disabled should be kept as
14780 This minimizes both
14785 \begin_inset LatexCommand \index{interrupt latency}
14789 (the time between the occurrence of the interrupt and the execution of
14790 the first code in the interrupt routine) and
14795 \begin_inset LatexCommand \index{interrupt jitter}
14799 (the difference between the shortest and the longest interrupt latency).
14800 These really are something different, f.e.
14801 a serial interrupt has to be served before its buffer overruns so it cares
14802 for the maximum interrupt latency, whereas it does not care about jitter.
14803 On a loudspeaker driven via a digital to analog converter which is fed
14804 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14805 a much smaller jitter will be very audible.
14808 \begin_layout Standard
14809 You can reenable interrupts within an interrupt routine and on some architecture
14810 s you can make use of two (or more) levels of
14812 interrupt priorities
14815 \begin_inset LatexCommand \index{interrupt priority}
14820 On some architectures which don't support interrupt priorities these can
14821 be implemented by manipulating the interrupt mask and reenabling interrupts
14822 within the interrupt routine.
14823 Check there is sufficient space on the stack
14824 \begin_inset LatexCommand \index{stack}
14828 and don't add complexity unless you have to.
14832 \begin_layout Subsection
14834 \begin_inset LatexCommand \index{semaphore}
14838 locking (mcs51/ds390)
14841 \begin_layout Standard
14842 Some architectures (mcs51/ds390) have an atomic
14843 \begin_inset LatexCommand \index{atomic}
14856 These type of instructions are typically used in preemptive multitasking
14857 systems, where a routine f.e.
14858 claims the use of a data structure ('acquires a lock
14859 \begin_inset LatexCommand \index{lock}
14863 on it'), makes some modifications and then releases the lock when the data
14864 structure is consistent again.
14865 The instruction may also be used if interrupt and non-interrupt code have
14866 to compete for a resource.
14867 With the atomic bit test and clear instruction interrupts
14868 \begin_inset LatexCommand \index{interrupt}
14872 don't have to be disabled for the locking operation.
14876 \begin_layout Standard
14877 SDCC generates this instruction if the source follows this pattern:
14880 \begin_layout Verse
14884 \begin_inset LatexCommand \index{volatile}
14888 bit resource_is_free;
14892 if (resource_is_free)
14902 resource_is_free=0;
14915 resource_is_free=1;
14922 \begin_layout Standard
14923 Note, mcs51 and ds390 support only an atomic
14924 \begin_inset LatexCommand \index{atomic}
14932 instruction (as opposed to atomic bit test and
14937 \begin_layout Section
14938 Functions using private register banks
14939 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14946 \begin_layout Standard
14947 Some architectures have support for quickly changing register sets.
14948 SDCC supports this feature with the
14951 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14956 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14962 attribute (which tells the compiler to use a register bank
14963 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14967 other than the default bank zero).
14968 It should only be applied to
14971 \begin_inset LatexCommand \index{interrupt}
14977 functions (see footnote below).
14978 This will in most circumstances make the generated ISR code more efficient
14979 since it will not have to save registers on the stack.
14982 \begin_layout Standard
14987 attribute will have no effect on the generated code for a
14991 function (but may occasionally be useful anyway
14995 \begin_layout Standard
14996 possible exception: if a function is called ONLY from 'interrupt' functions
14997 using a particular bank, it can be declared with the same 'using' attribute
14998 as the calling 'interrupt' functions.
14999 For instance, if you have several ISRs using bank one, and all of them
15000 call memcpy(), it might make sense to create a specialized version of memcpy()
15001 'using 1', since this would prevent the ISR from having to save bank zero
15002 to the stack on entry and switch to bank zero before calling the function
15011 (pending: Note, nowadays the
15015 attribute has an effect on
15019 the generated code for a
15030 \begin_layout Standard
15035 function using a non-zero bank will assume that it can trash that register
15036 bank, and will not save it.
15037 Since high-priority interrupts
15038 \begin_inset LatexCommand \index{interrupts}
15043 \begin_inset LatexCommand \index{interrupt priority}
15047 can interrupt low-priority ones on the 8051 and friends, this means that
15048 if a high-priority ISR
15052 a particular bank occurs while processing a low-priority ISR
15056 the same bank, terrible and bad things can happen.
15057 To prevent this, no single register bank should be
15061 by both a high priority and a low priority ISR.
15062 This is probably most easily done by having all high priority ISRs use
15063 one bank and all low priority ISRs use another.
15064 If you have an ISR which can change priority at runtime, you're on your
15065 own: I suggest using the default bank zero and taking the small performance
15069 \begin_layout Standard
15070 It is most efficient if your ISR calls no other functions.
15071 If your ISR must call other functions, it is most efficient if those functions
15072 use the same bank as the ISR (see note 1 below); the next best is if the
15073 called functions use bank zero.
15074 It is very inefficient to call a function using a different, non-zero bank
15077 \begin_inset VSpace bigskip
15083 \begin_layout Section
15085 \begin_inset LatexCommand \label{sub:Startup-Code}
15090 \begin_inset LatexCommand \index{Startup code}
15097 \begin_layout Subsection
15098 MCS51/DS390 Startup Code
15101 \begin_layout Standard
15102 The compiler triggers the linker to link certain initialization modules
15103 from the runtime library
15104 \begin_inset LatexCommand \index{Runtime library}
15108 called crt<something>.
15109 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15110 GSINIT5) is not linked unless the --xstack option is used.
15111 These modules are highly entangled by the use of special segments/areas,
15112 but a common layout is shown below:
15115 \begin_layout Verse
15123 \begin_layout Verse
15147 ljmp __sdcc_gsinit_startup
15150 \begin_layout Verse
15158 \begin_layout Verse
15170 .area GSINIT0 (CODE)
15172 __sdcc_gsinit_startup::
15182 mov sp,#__start__stack - 1
15185 \begin_layout Verse
15193 \begin_layout Verse
15205 .area GSINIT1 (CODE)
15207 __sdcc_init_xstack::
15209 ; Need to initialize in GSINIT1 in
15210 case the user's __sdcc_external_startup uses the xstack.
15220 mov __XPAGE,#(__start__x
15231 mov _spx,#__start__xstack
15234 \begin_layout Verse
15242 \begin_layout Verse
15254 .area GSINIT2 (CODE)
15264 lcall __sdcc_external_startup
15284 jz __sdcc_init_data
15295 __sdcc_program_startup
15300 \begin_layout Verse
15308 \begin_layout Verse
15320 .area GSINIT3 (CODE)
15373 mov r2,#((l_XINIT+255) >> 8)
15404 __XPAGE,#(s_XISEG >> 8)
15406 00001$:\InsetSpace ~
15470 00002$:\InsetSpace ~
15497 \begin_layout Verse
15505 \begin_layout Verse
15517 .area GSINIT4 (CODE)
15519 __mcs51_genRAMCLEAR::
15541 00004$:\InsetSpace ~
15555 ; _mcs51_genRAMCLEAR() end
15558 \begin_layout Verse
15566 \begin_layout Verse
15578 .area GSINIT4 (CODE)
15580 __mcs51_genXRAMCLEAR::
15631 mov __XPAGE,#(s_PSEG >> 8)
15643 00005$:\InsetSpace ~
15697 orl a,#(l_XSEG >> 8)
15740 00007$:\InsetSpace ~
15777 \begin_layout Verse
15785 \begin_layout Verse
15797 .area GSINIT5 (CODE)
15799 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15802 ; and __mcs51_genRAMCLEAR modifies _spx.
15812 mov __XPAGE,#(__start__x
15823 mov _spx,#__start__xstack
15826 \begin_layout Verse
15831 (application modules)
15834 \begin_layout Verse
15846 .area GSINIT (CODE)
15849 \begin_layout Verse
15857 \begin_layout Verse
15869 .area GSFINAL (CODE)
15879 ljmp __sdcc_program_startup
15881 ;---------------------------------
15882 -----------------------
15886 ;--------------------------------------------------
15909 __sdcc_program_startup:
15922 return from main will lock up
15935 \begin_layout Standard
15936 One of these modules (crtstart.asm) contains a call to the C routine
15938 _sdcc_external_startup()
15939 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15948 at the start of the CODE area.
15949 This routine is also in the runtime library
15950 \begin_inset LatexCommand \index{Runtime library}
15954 and returns 0 by default.
15955 If this routine returns a non-zero value, the static & global variable
15956 initialization will be skipped and the function main will be invoked.
15957 Otherwise static & global variables will be initialized before the function
15961 _sdcc_external_startup()
15963 routine to your program to override the default if you need to setup hardware
15964 or perform some other critical operation prior to static & global variable
15966 \begin_inset LatexCommand \index{Variable initialization}
15971 On some mcs51 variants xdata
15972 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15976 memory has to be explicitly enabled before it can be accessed or if the
15978 \begin_inset LatexCommand \index{watchdog}
15982 needs to be disabled, this is the place to do it.
15983 The startup code clears all internal data memory, 256 bytes by default,
15984 but from 0 to n-1 if
15990 \begin_layout Standard
16000 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16007 (recommended for Chipcon CC1010).
16010 \begin_layout Standard
16011 See also the compiler options
16017 \begin_layout Standard
16033 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16043 \begin_layout Standard
16055 \begin_inset LatexCommand \index{-\/-main-return}
16060 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16064 about MCS51-variants.
16065 \begin_inset VSpace bigskip
16071 \begin_layout Subsection
16075 \begin_layout Standard
16077 \begin_inset LatexCommand \index{HC08}
16081 startup code follows the same scheme as the MCS51 startup code.
16082 \begin_inset VSpace bigskip
16088 \begin_layout Subsection
16092 \begin_layout Standard
16094 \begin_inset LatexCommand \index{Z80}
16098 the startup code is inserted by linking with crt0.o which is generated from
16099 sdcc/device/lib/z80/crt0.s.
16100 If you need a different startup code you can use the compiler option
16109 \begin_layout Standard
16124 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16128 and provide your own crt0.o.
16130 \begin_inset VSpace bigskip
16136 \begin_layout Section
16137 Inline Assembler Code
16138 \begin_inset LatexCommand \index{Assembler routines}
16145 \begin_layout Subsection
16146 A Step by Step Introduction
16147 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16154 \begin_layout Standard
16155 Starting from a small snippet of c-code this example shows for the MCS51
16156 how to use inline assembly, access variables, a function parameter and
16157 an array in xdata memory.
16158 The example uses an MCS51 here but is easily adapted for other architectures.
16159 This is a buffer routine which should be optimized:
16162 \begin_layout Verse
16166 unsigned char __far
16167 \begin_inset LatexCommand \index{far (storage class)}
16172 \begin_inset LatexCommand \index{\_\_far (storage class)}
16177 \begin_inset LatexCommand \index{at}
16182 \begin_inset LatexCommand \index{\_\_at}
16186 (0x7f00) buf[0x100];
16187 \begin_inset LatexCommand \index{Aligned array}
16193 unsigned char head, tail;\InsetSpace ~
16211 \begin_inset LatexCommand \index{interrupt}
16263 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16275 void to_buffer( unsigned char c )
16283 if( head != (unsigned char)(tail-1)
16290 \begin_inset LatexCommand \index{promotion to signed int}
16295 \begin_inset LatexCommand \index{type promotion}
16300 \begin_inset Marginal
16303 \begin_layout Standard
16322 buf[ head++ ] = c;\InsetSpace ~
16338 /* access to a 256 byte aligned array */
16343 \begin_layout Standard
16344 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16345 then a corresponding buffer.asm file is generated.
16346 We define a new function
16350 in file buffer.c in which we cut and paste the generated code, removing
16351 unwanted comments and some ':'.
16353 \begin_inset Quotes sld
16361 \begin_inset Quotes srd
16365 \begin_inset Quotes sld
16373 \begin_inset Quotes srd
16380 \begin_layout Standard
16381 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16382 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16384 The latter is also used in the library functions.
16389 to the beginning and the end of the function body:
16392 \begin_layout Verse
16396 /* With a cut and paste from the .asm file, we have something to start with.
16402 function is not yet OK! (registers aren't saved) */
16404 void to_buffer_asm(
16414 \begin_inset LatexCommand \index{\_asm}
16419 \begin_inset LatexCommand \index{\_\_asm}
16433 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16439 \begin_inset LatexCommand \index{promotion to signed int}
16444 \begin_inset LatexCommand \index{type promotion}
16497 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16498 \begin_inset LatexCommand \index{Aligned array}
16564 \begin_inset LatexCommand \index{\_endasm}
16569 \begin_inset LatexCommand \index{\_\_endasm}
16578 \begin_layout Standard
16579 The new file buffer.c should compile with only one warning about the unreferenced
16580 function argument 'c'.
16581 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16582 (1) and finally have:
16585 \begin_layout Verse
16589 unsigned char __far __at(0x7f00) buf[0x100];
16591 unsigned char head, tail;
16602 void to_buffer( unsigned char c )
16611 head != (unsigned char)(tail-1) )
16640 c; // to avoid warning: unreferenced function argument
16647 \begin_inset LatexCommand \index{\_asm}
16652 \begin_inset LatexCommand \index{\_\_asm}
16666 ; save used registers here.
16677 ; If we were still using r2,r3 we would have to push them here.
16680 ; if( head != (unsigned char)(tail-1) )
16724 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16760 a,dpl \InsetSpace ~
16767 ; dpl holds lower byte of function argument
16779 dpl,_head \InsetSpace ~
16782 ; buf is 0x100 byte aligned so head can be used directly
16825 ; we could do an ANL _head,#0x0f here to use a
16826 smaller buffer (see above)
16838 ; restore used registers here
16845 \begin_inset LatexCommand \index{\_endasm}
16850 \begin_inset LatexCommand \index{\_\_endasm}
16861 \begin_layout Standard
16862 The inline assembler code can contain any valid code understood by the assembler
16863 , this includes any assembler directives and comment lines.
16864 The assembler does not like some characters like ':' or ''' in comments.
16865 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16866 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16871 \begin_inset LatexCommand \index{Assembler documentation}
16876 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16884 \begin_layout Standard
16885 The compiler does not do any validation of the code within the
16888 \begin_inset LatexCommand \index{\_asm}
16893 \begin_inset LatexCommand \index{\_\_asm}
16901 \begin_inset LatexCommand \index{\_endasm}
16906 \begin_inset LatexCommand \index{\_\_endasm}
16915 Specifically it will not know which registers are used and thus register
16917 \begin_inset LatexCommand \index{push/pop}
16921 has to be done manually.
16925 \begin_layout Standard
16926 It is recommended that each assembly instruction (including labels) be placed
16927 in a separate line (as the example shows).
16932 \begin_layout Standard
16944 \begin_inset LatexCommand \index{-\/-peep-asm}
16950 command line option is used, the inline assembler code will be passed through
16951 the peephole optimizer
16952 \begin_inset LatexCommand \index{Peephole optimizer}
16957 There are only a few (if any) cases where this option makes sense, it might
16958 cause some unexpected changes in the inline assembler code.
16959 Please go through the peephole optimizer rules defined in file
16963 before using this option.
16966 \begin_layout Subsection
16968 \begin_inset LatexCommand \label{sub:Naked-Functions}
16973 \begin_inset LatexCommand \index{Naked functions}
16980 \begin_layout Standard
16981 A special keyword may be associated with a function declaring it as
16984 \begin_inset LatexCommand \index{\_naked}
16989 \begin_inset LatexCommand \index{\_\_naked}
17000 function modifier attribute prevents the compiler from generating prologue
17001 \begin_inset LatexCommand \index{function prologue}
17006 \begin_inset LatexCommand \index{function epilogue}
17010 code for that function.
17011 This means that the user is entirely responsible for such things as saving
17012 any registers that may need to be preserved, selecting the proper register
17013 bank, generating the
17017 instruction at the end, etc.
17018 Practically, this means that the contents of the function must be written
17019 in inline assembler.
17020 This is particularly useful for interrupt functions, which can have a large
17021 (and often unnecessary) prologue/epilogue.
17022 For example, compare the code generated by these two functions:
17025 \begin_layout Verse
17029 \begin_inset LatexCommand \index{volatile}
17033 data unsigned char counter;
17037 void simpleInterrupt(void) __interrupt
17038 \begin_inset LatexCommand \index{interrupt}
17043 \begin_inset LatexCommand \index{\_\_interrupt}
17061 void nakedInterrupt(void) __interrupt (2) __naked
17070 \begin_inset LatexCommand \index{\_asm}
17075 \begin_inset LatexCommand \index{\_\_asm}
17092 _counter ; does not change flags, no need to save psw
17105 include ret or reti in _naked function.
17112 \begin_inset LatexCommand \index{\_endasm}
17117 \begin_inset LatexCommand \index{\_\_endasm}
17126 \begin_layout Standard
17127 For an 8051 target, the generated simpleInterrupt looks like:
17130 \begin_layout Verse
17137 example, recent versions of SDCC generate
17143 code for simpleInterrupt() and nakedInterrupt()!
17284 \begin_layout Standard
17285 whereas nakedInterrupt looks like:
17288 \begin_layout Verse
17301 _counter ; does not change flags, no need to save psw
17320 MUST explicitly include ret or reti in _naked function
17323 \begin_layout Standard
17324 The related directive #pragma exclude
17325 \begin_inset LatexCommand \index{\#pragma exclude}
17329 allows a more fine grained control over pushing & popping
17330 \begin_inset LatexCommand \index{push/pop}
17337 \begin_layout Standard
17338 While there is nothing preventing you from writing C code inside a
17342 function, there are many ways to shoot yourself in the foot doing this,
17343 and it is recommended that you stick to inline assembler.
17346 \begin_layout Subsection
17347 Use of Labels within Inline Assembler
17350 \begin_layout Standard
17351 SDCC allows the use of in-line assembler with a few restrictions regarding
17353 In older versions of the compiler all labels defined within inline assembler
17354 code had to be of the form
17358 where nnnnn is a number less than 100 (which implies a limit of utmost
17359 100 inline assembler labels
17370 \begin_layout Verse
17374 \begin_inset LatexCommand \index{\_asm}
17379 \begin_inset LatexCommand \index{\_\_asm}
17409 \begin_inset LatexCommand \index{\_endasm}
17414 \begin_inset LatexCommand \index{\_\_endasm}
17421 \begin_layout Standard
17422 Inline assembler code cannot reference any C-labels, however it can reference
17424 \begin_inset LatexCommand \index{Labels}
17428 defined by the inline assembler, e.g.:
17431 \begin_layout Verse
17454 ; some assembler code
17475 /* some more c code */
17477 clabel:\InsetSpace ~
17479 /* inline assembler cannot reference this
17492 $0003: ;label (can be referenced by inline assembler only)
17500 \begin_inset LatexCommand \index{\_endasm}
17505 \begin_inset LatexCommand \index{\_\_endasm}
17515 /* some more c code */
17520 \begin_layout Standard
17521 In other words inline assembly code can access labels defined in inline
17522 assembly within the scope of the function.
17523 The same goes the other way, i.e.
17524 labels defines in inline assembly can not be accessed by C statements.
17527 \begin_layout Section
17528 Interfacing with Assembler Code
17529 \begin_inset LatexCommand \index{Assembler routines}
17536 \begin_layout Subsection
17537 Global Registers used for Parameter Passing
17538 \begin_inset LatexCommand \index{Parameter passing}
17545 \begin_layout Standard
17546 The compiler always uses the global registers
17549 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17554 \begin_inset LatexCommand \index{DPTR}
17559 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17568 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17574 to pass the first parameter to a function, and also to pass the return
17576 \begin_inset LatexCommand \index{return value}
17580 of function; according to the following scheme: one byte return value in
17585 , two byte value in
17594 three byte values (generic pointers) in
17606 , and four byte values in
17624 \begin_inset LatexCommand \index{generic pointer}
17628 contain type of accessed memory in
17649 \begin_inset Note Note
17652 \begin_layout Standard
17653 This might not be the case of certain memory models (medium???)
17661 \begin_layout Standard
17662 The second parameter onwards is either allocated on the stack (for reentrant
17667 \begin_layout Standard
17676 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17680 \begin_layout Subsection
17684 \begin_layout Standard
17685 Unless the called function is declared as
17690 \begin_inset LatexCommand \index{naked}
17698 \begin_layout Standard
17708 \begin_inset LatexCommand \index{-\/-callee-saves}
17716 \begin_layout Standard
17725 -all-callee-saves command line option or the corresponding callee_saves
17726 pragma are used, the caller will save the registers (
17730 ) around the call, so the called function can destroy they content freely.
17733 \begin_layout Standard
17734 If the called function is not declared as
17738 , the caller will swap register banks around the call, if caller and callee
17739 use different register banks (having them defined by the
17747 \begin_layout Standard
17748 The called function can also use
17764 observing that they are used for parameter/return value passing.
17767 \begin_layout Subsection
17768 Assembler Routine (non-reentrant)
17771 \begin_layout Standard
17772 In the following example
17773 \begin_inset LatexCommand \index{reentrant}
17778 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17782 the function c_func calls an assembler routine asm_func, which takes two
17784 \begin_inset LatexCommand \index{function parameter}
17791 \begin_layout Verse
17794 extern int asm_func(unsigned char, unsigned char);
17798 int c_func (unsigned char
17799 i, unsigned char j)
17807 return asm_func(i,j);
17821 return c_func(10,9);
17826 \begin_layout Standard
17827 The corresponding assembler function is:
17830 \begin_layout Verse
17833 .globl _asm_func_PARM_2
17935 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17952 \begin_layout Standard
17953 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17954 the parameter number starting from 1, and counting from the left.
17955 The first parameter is passed in
17971 according to the description above.
17972 The variable name for the second parameter will be _<function_name>_PARM_2.
17977 ble the assembler routine with the following command:
17984 asx8051 -losg asmfunc.asm
17991 Then compile and link the assembler routine to the C source file with the
17999 sdcc cfunc.c asmfunc.rel
18002 \begin_layout Subsection
18003 Assembler Routine (reentrant)
18006 \begin_layout Standard
18008 \begin_inset LatexCommand \index{reentrant}
18013 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18017 the second parameter
18018 \begin_inset LatexCommand \index{function parameter}
18022 onwards will be passed on the stack, the parameters are pushed from right
18024 before the call the second leftmost parameter will be on the top of the
18025 stack (the leftmost parameter is passed in registers).
18026 Here is an example:
18029 \begin_layout Verse
18032 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18037 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18046 return asm_func(i,j,k);
18060 return c_func(10,9,8);
18065 \begin_layout Standard
18066 The corresponding (unoptimized) assembler routine is:
18069 \begin_layout Verse
18089 _bp,sp\InsetSpace ~
18095 ;stack contains: _bp, return
18096 address, second parameter, third parameter
18120 a,#0xfd\InsetSpace ~
18126 pointer to the second parameter
18150 a,#0xfc\InsetSpace ~
18156 to the rightmost parameter
18197 result (= sum of all three parameters)
18212 ;return value goes into dptr
18246 \begin_layout Standard
18247 The compiling and linking procedure remains the same, however note the extra
18248 entry & exit linkage required for the assembler code, _bp is the stack
18249 frame pointer and is used to compute the offset into the stack for parameters
18250 and local variables.
18251 \begin_inset VSpace bigskip
18257 \begin_layout Section
18259 \begin_inset LatexCommand \index{int (16 bit)}
18264 \begin_inset LatexCommand \index{long (32 bit)}
18271 \begin_layout Standard
18272 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18273 multiplication and modulus operations are implemented by support routines.
18274 These support routines are all developed in ANSI-C to facilitate porting
18275 to other MCUs, although some model specific assembler optimizations are
18277 The following files contain the described routines, all of them can be
18278 found in <installdir>/share/sdcc/lib.
18283 \begin_layout Standard
18285 \begin_inset Tabular
18286 <lyxtabular version="3" rows="11" columns="2">
18288 <column alignment="left" valignment="top" leftline="true" width="0">
18289 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18290 <row topline="true" bottomline="true">
18291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18294 \begin_layout Standard
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18305 \begin_layout Standard
18314 <row topline="true">
18315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18318 \begin_layout Standard
18324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18327 \begin_layout Standard
18328 16 bit multiplication
18334 <row topline="true">
18335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18338 \begin_layout Standard
18344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18347 \begin_layout Standard
18348 signed 16 bit division (calls _divuint)
18354 <row topline="true">
18355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18358 \begin_layout Standard
18364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18367 \begin_layout Standard
18368 unsigned 16 bit division
18374 <row topline="true">
18375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18378 \begin_layout Standard
18384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18387 \begin_layout Standard
18388 signed 16 bit modulus (calls _moduint)
18394 <row topline="true">
18395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18398 \begin_layout Standard
18404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18407 \begin_layout Standard
18408 unsigned 16 bit modulus
18414 <row topline="true">
18415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18418 \begin_layout Standard
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18427 \begin_layout Standard
18428 32 bit multiplication
18434 <row topline="true">
18435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18438 \begin_layout Standard
18444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18447 \begin_layout Standard
18448 signed 32 division (calls _divulong)
18454 <row topline="true">
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18458 \begin_layout Standard
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18467 \begin_layout Standard
18468 unsigned 32 division
18474 <row topline="true">
18475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18478 \begin_layout Standard
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18487 \begin_layout Standard
18488 signed 32 bit modulus (calls _modulong)
18494 <row topline="true" bottomline="true">
18495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18498 \begin_layout Standard
18504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18507 \begin_layout Standard
18508 unsigned 32 bit modulus
18523 \begin_layout Standard
18524 Since they are compiled as
18529 \begin_inset LatexCommand \index{reentrant}
18534 \begin_inset LatexCommand \index{interrupt}
18538 service routines should not do any of the above operations.
18539 If this is unavoidable then the above routines will need to be compiled
18546 \begin_layout Standard
18556 \begin_inset LatexCommand \index{-\/-stack-auto}
18562 option, after which the source program will have to be compiled with
18568 \begin_layout Standard
18578 \begin_inset LatexCommand \index{-\/-int-long-reent}
18585 Notice that you don't have to call these routines directly.
18586 The compiler will use them automatically every time an integer operation
18590 \begin_layout Section
18591 Floating Point Support
18592 \begin_inset LatexCommand \index{Floating point support}
18599 \begin_layout Standard
18600 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18601 The floating point support routines are derived from gcc's floatlib.c and
18602 consist of the following routines:
18607 \begin_layout Standard
18611 \begin_inset Tabular
18612 <lyxtabular version="3" rows="17" columns="2">
18614 <column alignment="left" valignment="top" leftline="true" width="0">
18615 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18616 <row topline="true" bottomline="true">
18617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18620 \begin_layout Standard
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18638 \begin_layout Standard
18645 <row topline="true">
18646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18649 \begin_layout Standard
18664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18667 \begin_layout Standard
18677 add floating point numbers
18683 <row topline="true">
18684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18687 \begin_layout Standard
18702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18705 \begin_layout Standard
18715 subtract floating point numbers
18721 <row topline="true">
18722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18725 \begin_layout Standard
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18743 \begin_layout Standard
18753 divide floating point numbers
18759 <row topline="true">
18760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18763 \begin_layout Standard
18778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18781 \begin_layout Standard
18791 multiply floating point numbers
18797 <row topline="true">
18798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18801 \begin_layout Standard
18816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18819 \begin_layout Standard
18829 convert floating point to unsigned char
18835 <row topline="true">
18836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18839 \begin_layout Standard
18854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18857 \begin_layout Standard
18867 convert floating point to signed char
18873 <row topline="true">
18874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18877 \begin_layout Standard
18892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18895 \begin_layout Standard
18905 convert floating point to unsigned int
18911 <row topline="true">
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18915 \begin_layout Standard
18930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18933 \begin_layout Standard
18943 convert floating point to signed int
18949 <row topline="true">
18950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18953 \begin_layout Standard
18976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18979 \begin_layout Standard
18989 convert floating point to unsigned long
18995 <row topline="true">
18996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18999 \begin_layout Standard
19014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19017 \begin_layout Standard
19027 convert floating point to signed long
19033 <row topline="true">
19034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19037 \begin_layout Standard
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19055 \begin_layout Standard
19065 convert unsigned char to floating point
19071 <row topline="true">
19072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19075 \begin_layout Standard
19090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19093 \begin_layout Standard
19103 convert char to floating point number
19109 <row topline="true">
19110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19113 \begin_layout Standard
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19131 \begin_layout Standard
19141 convert unsigned int to floating point
19147 <row topline="true">
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19151 \begin_layout Standard
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19169 \begin_layout Standard
19179 convert int to floating point numbers
19185 <row topline="true">
19186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19189 \begin_layout Standard
19204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19207 \begin_layout Standard
19217 convert unsigned long to floating point number
19223 <row topline="true" bottomline="true">
19224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19227 \begin_layout Standard
19242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19245 \begin_layout Standard
19255 convert long to floating point number
19270 \begin_layout Standard
19271 These support routines are developed in ANSI-C so there is room for space
19272 and speed improvement
19276 \begin_layout Standard
19277 These floating point routines (
19281 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19288 Note if all these routines are used simultaneously the data space might
19290 For serious floating point usage the large model might be needed.
19291 Also notice that you don't have to call this routines directly.
19292 The compiler will use them automatically every time a floating point operation
19294 \begin_inset VSpace bigskip
19300 \begin_layout Section
19302 \begin_inset LatexCommand \index{Libraries}
19309 \begin_layout Standard
19312 <pending: this is messy and incomplete - a little more information is in
19313 sdcc/doc/libdoc.txt
19318 \begin_layout Subsection
19319 Compiler support routines (_gptrget, _mulint etc.)
19322 \begin_layout Subsection
19323 Stdclib functions (puts, printf, strcat etc.)
19326 \begin_layout Subsubsection
19330 \begin_layout Paragraph
19331 getchar(), putchar()
19334 \begin_layout Standard
19335 \begin_inset LatexCommand \index{<stdio.h>}
19339 As usual on embedded systems you have to provide your own
19342 \begin_inset LatexCommand \index{getchar()}
19351 \begin_inset LatexCommand \index{putchar()}
19358 SDCC does not know whether the system connects to a serial line with or
19359 without handshake, LCD, keyboard or other device.
19373 You'll find examples for serial routines f.e.
19374 in sdcc/device/lib.
19375 For the mcs51 this minimalistic polling
19379 routine might be a start:
19382 \begin_layout Verse
19385 void putchar (char c) {
19391 while (!TI)\InsetSpace ~
19394 /* assumes UART is initialized */
19422 \begin_layout Paragraph
19426 \begin_layout Standard
19430 \begin_inset LatexCommand \index{printf()}
19440 does not support float (except on ds390).
19441 To enable this recompile it with the option
19447 \begin_layout Standard
19457 \begin_inset LatexCommand \index{USE\_FLOATS}
19463 on the command line.
19470 \begin_layout Standard
19480 \begin_inset LatexCommand \index{-\/-model-large}
19486 for the mcs51 port, since this uses a lot of memory.
19489 \begin_layout Standard
19490 If you're short on code memory you might want to use
19493 \begin_inset LatexCommand \index{printf\_small()}
19508 For the mcs51 there additionally are assembly versions
19511 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19517 (subset of printf using less than 270 bytes) and
19520 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19529 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19535 (floating-point aware version of printf_fast) which should fit the requirements
19536 of many embedded systems (printf_fast() can be customized by unsetting
19541 support long variables and field widths).
19542 Be sure to use only one of these printf options within a project.
19547 \begin_layout Standard
19548 Feature matrix of different
19555 \begin_layout Standard
19556 \begin_inset Tabular
19557 <lyxtabular version="3" rows="14" columns="7">
19558 <features islongtable="true">
19559 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19560 <column alignment="center" valignment="top" leftline="true" width="0">
19561 <column alignment="center" valignment="top" leftline="true" width="12col%">
19562 <column alignment="center" valignment="top" leftline="true" width="10col%">
19563 <column alignment="center" valignment="top" leftline="true" width="0">
19564 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19565 <column alignment="center" valignment="top" rightline="true" width="0">
19566 <row topline="true" bottomline="true" endhead="true">
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19570 \begin_layout Standard
19579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19582 \begin_layout Standard
19584 \begin_inset LatexCommand \index{printf}
19593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19596 \begin_layout Standard
19604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19607 \begin_layout Standard
19613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19616 \begin_layout Standard
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19625 \begin_layout Standard
19631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19634 \begin_layout Standard
19641 <row topline="true" endhead="true">
19642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19645 \begin_layout Standard
19651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19654 \begin_layout Standard
19662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19665 \begin_layout Standard
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19676 \begin_layout Standard
19684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19687 \begin_layout Standard
19695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19698 \begin_layout Standard
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19709 \begin_layout Standard
19718 <row topline="true" endhead="true">
19719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19722 \begin_layout Standard
19723 \begin_inset Quotes sld
19727 \begin_inset Quotes srd
19733 \begin_layout Standard
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19742 \begin_layout Standard
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19751 \begin_layout Standard
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19760 \begin_layout Standard
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" rightline="true" usebox="none">
19787 \begin_layout Standard
19794 <row topline="true" endhead="true">
19795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19798 \begin_layout Standard
19802 \begin_layout Standard
19808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19811 \begin_layout Standard
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19820 \begin_layout Standard
19826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19829 \begin_layout Standard
19830 0.45k / 0.47k (+ _ltoa)
19835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19838 \begin_layout Standard
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19847 \begin_layout Standard
19853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19856 \begin_layout Standard
19863 <row topline="true">
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19867 \begin_layout Standard
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19876 \begin_layout Standard
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19889 \begin_layout Standard
19936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19939 \begin_layout Standard
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19981 \begin_layout Standard
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19990 \begin_layout Standard
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19999 \begin_layout Standard
20006 <row topline="true">
20007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20010 \begin_layout Standard
20011 long (32 bit) support
20016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20019 \begin_layout Standard
20025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20028 \begin_layout Standard
20034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20037 \begin_layout Standard
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20046 \begin_layout Standard
20052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20055 \begin_layout Standard
20070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20073 \begin_layout Standard
20080 <row topline="true">
20081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20084 \begin_layout Standard
20085 byte arguments on stack
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20093 \begin_layout Standard
20099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20102 \begin_layout Standard
20108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20111 \begin_layout Standard
20117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20120 \begin_layout Standard
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20129 \begin_layout Standard
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20138 \begin_layout Standard
20145 <row topline="true">
20146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20149 \begin_layout Standard
20151 \begin_inset LatexCommand \index{Floating point support}
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" usebox="none">
20181 \begin_layout Standard
20187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20190 \begin_layout Standard
20196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20199 \begin_layout Standard
20204 \begin_layout Standard
20205 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20218 \begin_layout Standard
20225 <row topline="true">
20226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20229 \begin_layout Standard
20230 float formats %e %g
20235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20238 \begin_layout Standard
20244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20247 \begin_layout Standard
20253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20256 \begin_layout Standard
20262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20265 \begin_layout Standard
20271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20274 \begin_layout Standard
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20283 \begin_layout Standard
20290 <row topline="true" bottomline="true">
20291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20294 \begin_layout Standard
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20303 \begin_layout Standard
20309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20312 \begin_layout Standard
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20321 \begin_layout Standard
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_layout Standard
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20339 \begin_layout Standard
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20348 \begin_layout Standard
20355 <row bottomline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20359 \begin_layout Standard
20364 \begin_layout Standard
20365 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20369 n'); standard 8051 @ 22.1184 MHz, empty putchar()
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
20438 <row bottomline="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20442 \begin_layout Standard
20447 \begin_layout Standard
20448 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20457 \begin_layout Standard
20463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20466 \begin_layout Standard
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20475 \begin_layout Standard
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20484 \begin_layout Standard
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20493 \begin_layout Standard
20499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20502 \begin_layout Standard
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20511 \begin_layout Standard
20516 \begin_layout Standard
20517 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20528 <row bottomline="true">
20529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20532 \begin_layout Standard
20537 \begin_layout Standard
20538 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20547 \begin_layout Standard
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20556 \begin_layout Standard
20562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20565 \begin_layout Standard
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20574 \begin_layout Standard
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20583 \begin_layout Standard
20589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20592 \begin_layout Standard
20598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20601 \begin_layout Standard
20608 <row bottomline="true">
20609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20612 \begin_layout Standard
20617 \begin_layout Standard
20618 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20627 \begin_layout Standard
20633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20636 \begin_layout Standard
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20645 \begin_layout Standard
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20663 \begin_layout Standard
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_layout Standard
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20681 \begin_layout Standard
20695 \begin_layout Subsubsection
20697 \begin_inset LatexCommand \index{malloc.h}
20704 \begin_layout Standard
20705 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20706 using dynamic memory allocation
20707 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20712 \begin_inset LatexCommand \index{heap (malloc)}
20716 space of 1024 bytes is provided for malloc to allocate memory from.
20717 If you need a different heap size you need to recompile _heap.c with the
20718 required size defined in HEAP_SIZE.
20719 It is recommended to make a copy of this file into your project directory
20720 and compile it there with:
20723 \begin_layout Verse
20726 sdcc -c _heap.c -D HEAD_SIZE=2048
20729 \begin_layout Standard
20730 And then link it with:
20733 \begin_layout Verse
20736 sdcc main.rel _heap.rel
20739 \begin_layout Subsection
20740 Math functions (sinf, powf, sqrtf etc.)
20743 \begin_layout Subsubsection
20747 \begin_layout Standard
20748 See definitions in file <math.h>.
20751 \begin_layout Subsection
20755 \begin_layout Standard
20757 \begin_inset LatexCommand \index{Libraries}
20761 included in SDCC should have a license at least as liberal as the GNU Lesser
20762 General Public License
20763 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20774 \begin_layout Standard
20775 \begin_inset Note Note
20778 \begin_layout Standard
20779 license statements for the libraries are missing.
20780 sdcc/device/lib/ser_ir.c
20783 \begin_layout Standard
20785 come with a GPL (as opposed to LGPL) License - this will not be liberal
20786 enough for many embedded programmers.
20794 \begin_layout Standard
20795 If you have ported some library or want to share experience about some code
20797 falls into any of these categories Busses (I
20798 \begin_inset Formula $^{\textrm{2}}$
20801 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20802 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20803 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20804 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20809 would certainly like to hear about it.
20812 \begin_layout Standard
20813 Programmers coding for embedded systems are not especially famous for being
20814 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20815 e these references are very valuable.
20816 Let's help to create a climate where information is shared.
20817 \begin_inset VSpace bigskip
20823 \begin_layout Section
20827 \begin_layout Subsection
20828 MCS51 Memory Models
20829 \begin_inset LatexCommand \index{Memory model}
20834 \begin_inset LatexCommand \index{MCS51 memory model}
20841 \begin_layout Subsubsection
20842 Small, Medium and Large
20845 \begin_layout Standard
20846 SDCC allows three memory models for MCS51 code,
20855 Modules compiled with different memory models should
20859 be combined together or the results would be unpredictable.
20860 The library routines supplied with the compiler are compiled as small,
20862 The compiled library modules are contained in separate directories as small,
20863 medium and large so that you can link to the appropriate set.
20866 \begin_layout Standard
20867 When the medium or large model is used all variables declared without a
20868 storage class will be allocated into the external ram, this includes all
20869 parameters and local variables (for non-reentrant
20870 \begin_inset LatexCommand \index{reentrant}
20875 When the small model is used variables without storage class are allocated
20876 in the internal ram.
20879 \begin_layout Standard
20880 Judicious usage of the processor specific storage classes
20881 \begin_inset LatexCommand \index{Storage class}
20885 and the 'reentrant' function type will yield much more efficient code,
20886 than using the large model.
20887 Several optimizations are disabled when the program is compiled using the
20888 large model, it is therefore recommended that the small model be used unless
20889 absolutely required.
20892 \begin_layout Subsubsection
20894 \begin_inset LatexCommand \label{sub:External-Stack}
20899 \begin_inset LatexCommand \index{stack}
20904 \begin_inset LatexCommand \index{External stack (mcs51)}
20911 \begin_layout Standard
20912 The external stack (-
20916 \begin_layout Standard
20926 \begin_inset LatexCommand \index{-\/-xstack}
20930 ) is located in pdata
20931 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20935 memory (usually at the start of the external ram segment) and uses all
20936 unused space in pdata (max.
20942 \begin_layout Standard
20951 -xstack option is used to compile the program, the parameters and local
20953 \begin_inset LatexCommand \index{local variables}
20957 of all reentrant functions are allocated in this area.
20958 This option is provided for programs with large stack space requirements.
20959 When used with the -
20963 \begin_layout Standard
20973 \begin_inset LatexCommand \index{-\/-stack-auto}
20977 option, all parameters and local variables are allocated on the external
20978 stack (note: support libraries will need to be recompiled with the same
20980 There is a predefined target in the library makefile).
20983 \begin_layout Standard
20984 The compiler outputs the higher order address byte of the external ram segment
20986 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20991 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20995 ), therefore when using the External Stack option, this port
20999 be used by the application program.
21002 \begin_layout Subsection
21004 \begin_inset LatexCommand \index{Memory model}
21009 \begin_inset LatexCommand \index{DS390 memory model}
21016 \begin_layout Standard
21017 The only model supported is Flat 24
21018 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21023 This generates code for the 24 bit contiguous addressing mode of the Dallas
21025 In this mode, up to four meg of external RAM or code space can be directly
21027 See the data sheets at www.dalsemi.com for further information on this part.
21032 that the compiler does not generate any code to place the processor into
21033 24 bitmode (although
21037 in the ds390 libraries will do that for you).
21043 \begin_inset LatexCommand \index{Tinibios (DS390)}
21047 , the boot loader or similar code must ensure that the processor is in 24
21048 bit contiguous addressing mode before calling the SDCC startup code.
21059 \begin_layout Standard
21070 option, variables will by default be placed into the XDATA segment.
21075 Segments may be placed anywhere in the 4 meg address space using the usual
21080 \begin_layout Standard
21090 Note that if any segments are located above 64K, the -r flag must be passed
21091 to the linker to generate the proper segment relocations, and the Intel
21092 HEX output format must be used.
21093 The -r flag can be passed to the linker by using the option
21097 on the SDCC command line.
21098 However, currently the linker can not handle code segments > 64k.
21101 \begin_layout Section
21103 \begin_inset LatexCommand \label{sec:Pragmas}
21108 \begin_inset LatexCommand \index{Pragmas}
21115 \begin_layout Standard
21116 Pragmas are used to turn on and/or off certain compiler options.
21117 Some of them are closely related to corresponding command-line options
21119 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21125 Pragmas should be placed before and/or after a function, placing pragmas
21126 inside a function body could have unpredictable results.
21131 following #pragma directives:
21134 \begin_layout Itemize
21140 \begin_inset LatexCommand \index{\#pragma save}
21144 - this will save most current options to the save/restore stack.
21145 See #pragma\InsetSpace ~
21149 \begin_layout Itemize
21155 \begin_inset LatexCommand \index{\#pragma restore}
21159 - will restore saved options from the last save.
21160 saves & restores can be nested.
21161 SDCC uses a save/restore stack: save pushes current options to the stack,
21162 restore pulls current options from the stack.
21163 See #pragma\InsetSpace ~
21169 \begin_layout Itemize
21175 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21180 \begin_inset LatexCommand \index{function prologue}
21184 function1[,function2[,function3...]]
21185 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21189 - The compiler by default uses a caller saves convention for register saving
21190 across function calls, however this can cause unnecessary register pushing
21192 \begin_inset LatexCommand \index{push/pop}
21196 when calling small functions from larger functions.
21197 This option can be used to switch off the register saving convention for
21198 the function names specified.
21199 The compiler will not save registers when calling these functions, extra
21200 code need to be manually inserted at the entry and exit for these functions
21201 to save and restore the registers used by these functions, this can SUBSTANTIAL
21202 LY reduce code and improve run time performance of the generated code.
21203 In the future the compiler (with inter procedural analysis) may be able
21204 to determine the appropriate scheme to use for each function call.
21209 \begin_layout Standard
21218 -callee-saves command line option is used (see page
21219 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21223 ), the function names specified in #pragma\InsetSpace ~
21225 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21229 is appended to the list of functions specified in the command line.
21232 \begin_layout Itemize
21238 \begin_inset LatexCommand \index{\#pragma exclude}
21242 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21243 of pairs of push/pop
21244 \begin_inset LatexCommand \index{push/pop}
21253 \begin_inset LatexCommand \index{interrupt}
21266 The directive should be placed immediately before the ISR function definition
21267 and it affects ALL ISR functions following it.
21268 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21269 exclude\InsetSpace ~
21271 \begin_inset LatexCommand \index{\#pragma exclude}
21276 See also the related keyword _naked
21277 \begin_inset LatexCommand \index{\_naked}
21282 \begin_inset LatexCommand \index{\_\_naked}
21289 \begin_layout Itemize
21295 \begin_inset LatexCommand \index{pedantic}
21300 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21305 \begin_inset LatexCommand \label{ite:less_pedantic}
21309 - the compiler will not warn you anymore for obvious mistakes, you'r on
21311 See also the command line option -
21315 \begin_layout Standard
21325 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21332 More specifically, the following warnings will be disabled:
21334 comparison is always [true/false] due to limited range of data type
21338 overflow in implicit constant conversion
21340 (158); [the (in)famous]
21342 conditional flow changed by optimizer: so said EVELYN the modified DOG
21346 function '[function name]' must return value
21351 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21352 level) are disabled, too, namely:
21355 \begin_inset Note Note
21358 \begin_layout Standard
21359 dunno what comes here - this warning appears to be unused altogether
21368 [left/right] shifting more than size of object changed to zero
21376 integer overflow in expression
21380 unmatched #pragma save and #pragma restore
21384 comparison of 'signed char' with 'unsigned char' requires promotion to int
21388 ISO C90 does not support flexible array members
21392 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21396 \begin_inset Note Note
21399 \begin_layout Standard
21400 appears to be always blank - what was supposed to be here?
21409 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21410 complexity [number]
21415 \begin_layout Itemize
21421 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21425 - the compiler will not warn you anymore about warning number <nnnn>.
21428 \begin_layout Itemize
21434 \begin_inset LatexCommand \index{\#pragma nogcse}
21438 - will stop global common subexpression elimination.
21441 \begin_layout Itemize
21447 \begin_inset LatexCommand \index{\#pragma noinduction}
21451 - will stop loop induction optimizations.
21454 \begin_layout Itemize
21460 \begin_inset LatexCommand \index{\#pragma noinvariant}
21464 - will not do loop invariant optimizations.
21465 For more details see Loop Invariants in section
21466 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21473 \begin_layout Itemize
21479 \begin_inset LatexCommand \index{\#pragma noiv}
21483 - Do not generate interrupt
21484 \begin_inset LatexCommand \index{interrupt}
21489 \begin_inset LatexCommand \index{interrupt vector table}
21493 entries for all ISR functions defined after the pragma.
21494 This is useful in cases where the interrupt vector table must be defined
21495 manually, or when there is a secondary, manually defined interrupt vector
21497 for the autovector feature of the Cypress EZ-USB FX2).
21498 More elegantly this can be achieved by obmitting the optional interrupt
21499 number after the interrupt keyword, see section
21500 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21508 \begin_layout Itemize
21514 \begin_inset LatexCommand \index{\#pragma nojtbound}
21518 - will not generate code for boundary value checking, when switch statements
21519 are turned into jump-tables (dangerous).
21520 For more details see section
21521 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21528 \begin_layout Itemize
21534 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21538 - Will not do loop reversal optimization
21541 \begin_layout Itemize
21547 \begin_inset LatexCommand \index{\#pragma nooverlay}
21551 - the compiler will not overlay the parameters and local variables of a
21555 \begin_layout Itemize
21561 \begin_inset LatexCommand \index{\#pragma stackauto}
21569 \begin_layout Standard
21579 \begin_inset LatexCommand \index{-\/-stack-auto}
21584 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21588 Parameters and Local Variables.
21591 \begin_layout Itemize
21597 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21601 - The compiler will optimize code generation towards fast code, possibly
21602 at the expense of code size.
21603 Currently this has little effect.
21606 \begin_layout Itemize
21612 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21616 - The compiler will optimize code generation towards compact code, possibly
21617 at the expense of code speed.
21618 Currently this has little effect.
21621 \begin_layout Itemize
21627 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21631 - The compiler will attempt to generate code that is both compact and fast,
21632 as long as meeting one goal is not a detriment to the other (this is the
21637 \begin_layout Itemize
21643 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21647 - Generally follow the C89 standard, but allow SDCC features that conflict
21648 with the standard (default).
21651 \begin_layout Itemize
21657 \begin_inset LatexCommand \index{\#pragma std\_c89}
21661 - Follow the C89 standard and disable SDCC features that conflict with the
21665 \begin_layout Itemize
21671 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21675 - Generally follow the C99 standard, but allow SDCC features that conflict
21676 with the standard (incomplete support).
21679 \begin_layout Itemize
21685 \begin_inset LatexCommand \index{\#pragma std\_c99}
21689 - Follow the C99 standard and disable SDCC features that conflict with the
21690 standard (incomplete support).
21693 \begin_layout Itemize
21699 \begin_inset LatexCommand \index{\#pragma codeseg}
21703 - Use this name (max.
21704 8 characters) for the code segment.
21709 \begin_layout Standard
21721 \begin_layout Itemize
21727 \begin_inset LatexCommand \index{\#pragma constseg}
21731 - Use this name (max.
21732 8 characters) for the const segment.
21737 \begin_layout Standard
21749 \begin_layout Standard
21750 The preprocessor SDCPP
21751 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21755 supports the following #pragma directives:
21758 \begin_layout Itemize
21761 pedantic_parse_number
21764 \begin_inset LatexCommand \index{pedantic}
21769 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21774 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21778 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21779 properly and the macro LO_B(3) gets expanded.
21785 \begin_layout Standard
21794 -pedantic-parse-number command line option
21795 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21802 Below is an example on how to use this pragma.
21805 Note: this functionality is not in conformance with standard!
21808 \begin_layout Verse
21811 #pragma pedantic_parse_number +
21812 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21820 #define LO_B(x) ((x) & 0xff)
21824 unsigned char foo(void)
21831 unsigned char c=0xfe-LO_B(3)
21846 \begin_layout Itemize
21852 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21856 (+ | -) - switch _asm _endasm block preprocessing on / off.
21858 You use this prama to define multilines of assembly code.
21859 This will prevent the preprocessor from changing the formating required
21861 Below is an example on how to use this pragma.
21864 \begin_layout Verse
21867 #pragma preproc_asm -
21868 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21874 #define MYDELAY _asm
21879 nop ;my assembly comment...
21893 #pragma preproc_asm
21924 \begin_layout Itemize
21930 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21934 (+ | -) - Allow "naked" hash in macro definition, for example:
21938 #define DIR_LO(x) #(x & 0xff)
21943 Below is an example on how to use this pragma.
21946 \begin_layout Verse
21949 #pragma preproc_asm +
21951 #pragma sdcc_hash +
21952 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21967 mov R6_B3, #(x & 0xff)
21974 mov R7_B3, #((x >> 8) & 0xff)
21998 \begin_layout Standard
21999 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22000 ons which might cause the compiler to generate extra stack and/or data space
22001 to store compiler generated temporary variables.
22002 This usually happens in large functions.
22003 Pragma directives should be used as shown in the following example, they
22004 are used to control options and optimizations for a given function.
22008 \begin_layout Verse
22012 \begin_inset LatexCommand \index{\#pragma save}
22023 /* save the current settings */
22026 \begin_inset LatexCommand \index{\#pragma nogcse}
22035 /* turnoff global subexpression elimination */
22037 #pragma noinduction
22038 \begin_inset LatexCommand \index{\#pragma noinduction}
22042 /* turn off induction optimizations */
22065 \begin_inset LatexCommand \index{\#pragma restore}
22069 /* turn the optimizations back on */
22072 \begin_layout Standard
22073 The compiler will generate a warning message when extra space is allocated.
22074 It is strongly recommended that the save and restore pragma's be used when
22075 changing options for a function.
22084 \begin_layout Section
22085 Defines Created by the Compiler
22088 \begin_layout Standard
22089 The compiler creates the following #defines
22090 \begin_inset LatexCommand \index{\#defines}
22095 \begin_inset LatexCommand \index{Defines created by the compiler}
22104 \begin_layout Standard
22105 \begin_inset Tabular
22106 <lyxtabular version="3" rows="11" columns="2">
22108 <column alignment="left" valignment="top" leftline="true" width="3in">
22109 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22110 <row topline="true" bottomline="true">
22111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22114 \begin_layout Standard
22122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22125 \begin_layout Standard
22134 <row topline="true">
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22138 \begin_layout Standard
22140 \begin_inset LatexCommand \index{SDCC}
22149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22152 \begin_layout Standard
22154 Since version 2.5.6 the version number as an int (ex.
22161 <row topline="true">
22162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22165 \begin_layout Standard
22167 \begin_inset LatexCommand \index{SDCC\_mcs51}
22172 \begin_inset LatexCommand \index{SDCC\_ds390}
22177 \begin_inset LatexCommand \index{SDCC\_z80}
22186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22189 \begin_layout Standard
22190 depending on the model used (e.g.: -mds390)
22196 <row topline="true">
22197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22200 \begin_layout Standard
22202 \begin_inset LatexCommand \index{\_\_mcs51}
22207 \begin_inset LatexCommand \index{\_\_ds390}
22212 \begin_inset LatexCommand \index{\_\_hc08}
22217 \begin_inset LatexCommand \index{\_\_z80}
22226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22229 \begin_layout Standard
22230 depending on the model used (e.g.
22237 <row topline="true">
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22241 \begin_layout Standard
22243 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22255 \begin_layout Standard
22262 \begin_layout Standard
22279 <row topline="true">
22280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22283 \begin_layout Standard
22285 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22297 \begin_layout Standard
22304 \begin_layout Standard
22321 <row topline="true">
22322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22325 \begin_layout Standard
22327 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22339 \begin_layout Standard
22346 \begin_layout Standard
22363 <row topline="true">
22364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22367 \begin_layout Standard
22369 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22381 \begin_layout Standard
22388 \begin_layout Standard
22405 <row topline="true">
22406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22409 \begin_layout Standard
22411 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22423 \begin_layout Standard
22430 \begin_layout Standard
22447 <row topline="true">
22448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22451 \begin_layout Standard
22453 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22465 \begin_layout Standard
22476 <row topline="true" bottomline="true">
22477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22480 \begin_layout Standard
22482 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22494 \begin_layout Standard
22512 \begin_layout Chapter
22513 Notes on supported Processors
22516 \begin_layout Section
22518 \begin_inset LatexCommand \label{sub:MCS51-variants}
22523 \begin_inset LatexCommand \index{MCS51 variants}
22530 \begin_layout Standard
22531 MCS51 processors are available from many vendors and come in many different
22533 While they might differ considerably in respect to Special Function Registers
22534 the core MCS51 is usually not modified or is kept compatible.
22538 \begin_layout Subsection
22539 pdata access by SFR
22542 \begin_layout Standard
22543 With the upcome of devices with internal xdata and flash memory devices
22545 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22549 as dedicated I/O port is becoming more popular.
22550 Switching the high byte for pdata
22551 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22555 access which was formerly done by port P2 is then achieved by a Special
22557 \begin_inset LatexCommand \index{sfr}
22562 In well-established MCS51 tradition the address of this
22566 is where the chip designers decided to put it.
22567 Needless to say that they didn't agree on a common name either.
22568 So that the startup code can correctly initialize xdata variables, you
22569 should define an sfr with the name _XPAGE
22572 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22578 at the appropriate location if the default, port P2, is not used for this.
22582 \begin_layout Verse
22585 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22589 \begin_layout Verse
22592 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22597 \begin_layout Verse
22600 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22604 \begin_layout Verse
22607 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22611 \begin_layout Verse
22614 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22618 \begin_layout Standard
22619 For more exotic implementations further customizations may be needed.
22621 \begin_inset LatexCommand \ref{sub:Startup-Code}
22625 for other possibilities.
22628 \begin_layout Subsection
22629 Other Features available by SFR
22632 \begin_layout Standard
22633 Some MCS51 variants offer features like Double DPTR
22634 \begin_inset LatexCommand \index{DPTR}
22638 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22639 These are currently not used for the MCS51 port.
22640 If you absolutely need them you can fall back to inline assembly or submit
22642 \begin_inset VSpace bigskip
22648 \begin_layout Section
22652 \begin_layout Standard
22654 \begin_inset LatexCommand \index{DS80C400}
22659 \begin_inset LatexCommand \index{DS400}
22663 microcontroller has a rich set of peripherals.
22664 In its built-in ROM library it includes functions to access some of the
22665 features, among them is a TCP stack with IP4 and IP6 support.
22666 Library headers (currently in beta status) and other files are provided
22670 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22676 \begin_inset VSpace bigskip
22682 \begin_layout Section
22683 The Z80 and gbz80 port
22686 \begin_layout Standard
22687 SDCC can target both the Zilog Z80
22688 \begin_inset LatexCommand \index{Z80}
22692 and the Nintendo Gameboy's Z80-like gbz80
22693 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22698 The Z80 port is passed through the same
22701 \begin_inset LatexCommand \index{Regression test}
22708 \begin_inset LatexCommand \ref{sec:Quality-control}
22712 ) as the MCS51 and DS390 ports, so floating point support, support for long
22713 variables and bitfield support is fine.
22714 See mailing lists and forums about interrupt routines.
22717 \begin_layout Standard
22718 As always, the code is the authoritative reference - see z80/ralloc.c and
22721 \begin_inset LatexCommand \index{Z80!stack}
22725 frame is similar to that generated by the IAR Z80 compiler.
22726 IX is used as the base pointer, HL and IY are used as a temporary registers,
22727 and BC and DE are available for holding variables.
22729 \begin_inset LatexCommand \index{Z80!return value}
22733 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22735 The gbz80 port use the same set of registers for the return values, but
22736 in a different order of significance: E (one byte), DE (two bytes), or
22738 \begin_inset VSpace bigskip
22744 \begin_layout Section
22748 \begin_layout Standard
22749 The port to the Freescale/Motorola HC08
22750 \begin_inset LatexCommand \index{HC08}
22754 family has been added in October 2003, and is still undergoing some basic
22756 The code generator is complete, but the register allocation is still quite
22758 Some of the SDCC's standard C library functions have embedded non-HC08
22759 inline assembly and so are not yet usable.
22762 \begin_layout Standard
22763 The HC08 port passes the regression test suite (see section
22764 \begin_inset LatexCommand \ref{sec:Quality-control}
22769 \begin_inset VSpace bigskip
22777 \begin_layout Section
22781 \begin_layout Standard
22782 The PIC14 port adds support for Microchip(TM)'s 14
22786 \begin_layout Standard
22796 \begin_inset LatexCommand \index{PIC14}
22801 This port is not yet mature and still lacks many features.
22802 However, it can work for simple code.
22805 \begin_layout Standard
22806 Currently supported devices include:
22809 \begin_layout Standard
22810 12F: 629, 635, 675, 683
22813 \begin_layout Standard
22817 \begin_layout Standard
22821 \begin_layout Standard
22822 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22825 \begin_layout Standard
22826 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22830 \begin_layout Standard
22834 \begin_layout Standard
22835 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22839 \begin_layout Standard
22840 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22843 \begin_layout Standard
22844 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22848 \begin_layout Standard
22849 16F: 913, 914, 916, 917
22852 \begin_layout Standard
22853 An up-to-date list of currently supported devices can be obtained via
22855 sdcc -mpic14 -phelp foo.c
22857 (foo.c must exist...).
22860 \begin_layout Subsection
22862 \begin_inset LatexCommand \index{code page (pic14)}
22867 \begin_inset LatexCommand \index{Memory bank (pic14)}
22874 \begin_layout Standard
22875 The linker organizes allocation for the code page and RAM banks.
22876 It does not have intimate knowledge of the code flow.
22877 It will put all the code section of a single .asm file into a single code
22879 In order to make use of multiple code pages, separate asm files must be
22881 The compiler assigns all
22885 functions of a single .c file into the same code page.
22889 To get the best results,
22890 follow these guidelines:
22893 \begin_layout Enumerate
22894 Make local functions static, as non static functions require code page selection
22897 Due to the way sdcc handles functions, place called functions prior
22898 to calling functions in the file wherever possible: Otherwise sdcc will
22899 insert unneccessary pagesel directives around the call, believing that
22900 the called function is externally defined.
22903 \begin_layout Enumerate
22904 For devices that have multiple code pages it is more efficient to use the
22905 same number of files as pages: Use up to 4 separate .c files for the 16F877,
22906 but only 2 files for the 16F874.
22907 This way the linker can put the code for each file into different code
22908 pages and there will be less page selection overhead.
22911 \begin_layout Enumerate
22912 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22913 instruction set), use 'unsigned char' wherever possible instead of 'int'.
22916 \begin_layout Subsection
22917 Adding New Devices to the Port
22920 \begin_layout Standard
22921 Adding support for a new 14
22925 \begin_layout Standard
22934 bit PIC MCU requires the following steps:
22937 \begin_layout Enumerate
22938 Create a new device description.
22940 Each device is described in two files: pic16f*.h
22942 These files primarily define SFRs, structs to access their bits, and symbolic
22943 configuration options.
22944 Both files can be generated from gputils' .inc files using the perl script
22947 support/scripts/inc2h.pl
22950 This file also contains further instructions on how to proceed.
22953 \begin_layout Enumerate
22954 Copy the .h file into SDCC's include path and either add the .c file to your
22955 project or copy it to
22957 device/lib/pic/libdev
22960 Afterwards, rebuild and install the libraries.
22963 \begin_layout Enumerate
22964 Edit pic14devices.txt in SDCC's include path (
22966 device/include/pic/
22968 in the source tree or
22970 /usr/local/share/sdcc/include/pic
22972 after installation).
22974 You need to add a device specification here to make
22975 the memory layout (code banks, RAM, aliased memory regions, ...) known to
22977 Probably you can copy and modify an existing entry.
22978 The file format is documented at the top of the file.
22981 \begin_layout Subsection
22985 \begin_layout Standard
22986 For the interrupt function, use the keyword '__interrupt'
22987 \begin_inset LatexCommand \index{PIC14!interrupt}
22991 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22992 there to avoid a syntax error - it ought to be fixed).
22996 \begin_layout Verse
22999 void Intr(void) __interrupt 0
23005 T0IF = 0; /* Clear timer interrupt */
23010 \begin_layout Subsection
23011 Linking and Assembling
23014 \begin_layout Standard
23015 For assembling you can use either GPUTILS'
23016 \begin_inset LatexCommand \index{gputils (pic tools)}
23020 gpasm.exe or MPLAB's mpasmwin.exe.
23021 GPUTILS are available from
23022 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23027 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23028 If you use MPLAB and an interrupt function then the linker script file
23029 vectors section will need to be enlarged to link with mplink.
23040 \begin_layout Verse
23053 sdcc -V -mpic14 -p16f877 -c $<
23057 $(PRJ).hex: $(OBJS)
23067 gplink -m -s $(PRJ).lkr
23068 -o $(PRJ).hex $(OBJS) libsdcc.lib
23071 \begin_layout Standard
23079 \begin_layout Verse
23092 sdcc -S -V -mpic14 -p16f877 $<
23102 mpasmwin /q /o $*.asm
23106 $(PRJ).hex: $(OBJS)
23117 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23120 \begin_layout Standard
23121 Please note that indentations within a
23125 have to be done with a tabulator character.
23128 \begin_layout Subsection
23129 Command-Line Options
23132 \begin_layout Standard
23133 Besides the switches common to all SDCC backends, the PIC14 port accepts
23134 the following options (for an updated list see sdcc -
23138 \begin_layout Standard
23150 \begin_layout Description
23155 \begin_layout Standard
23165 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23169 emit debug info in assembly output
23172 \begin_layout Description
23177 \begin_layout Standard
23187 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23191 disable (slightly faulty) optimization on pCode
23194 \begin_layout Description
23199 \begin_layout Standard
23209 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23213 sets the lowest address of the argument passing stack (defaults to a suitably
23214 large shared databank to reduce BANKSEL overhead)
23217 \begin_layout Description
23222 \begin_layout Standard
23232 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23236 sets the size if the argument passing stack (default: 16, minimum: 4)
23239 \begin_layout Subsection
23240 Environment Variables
23243 \begin_layout Standard
23244 The PIC14 port recognizes the following environment variables:
23247 \begin_layout Description
23248 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23249 register (the ones called r0xNNNN) in a section of its own.
23250 By default (if this variable is unset), sdcc tries to cluster registers
23251 in sections in order to reduce the BANKSEL overhead when accessing them.
23254 \begin_layout Subsection
23258 \begin_layout Standard
23259 The PIC14 library currently only contains support routines required by the
23260 compiler to implement multiplication, division, and floating point support.
23261 No libc-like replacement is available at the moment, though many of the
23262 common sdcc library sources (in
23266 ) should also compile with the PIC14 port.
23269 \begin_layout Subsubsection
23270 error: missing definition for symbol
23271 \begin_inset Quotes sld
23275 \begin_inset Quotes srd
23281 \begin_layout Standard
23282 The PIC14 port uses library routines to provide more complex operations
23283 like multiplication, division/modulus and (generic) pointer dereferencing.
23284 In order to add these routines to your project, you must link with PIC14's
23290 For single source file projects this is done automatically, more complex
23295 to the linker's arguments.
23296 Make sure you also add an include path for the library (using the -I switch
23300 \begin_layout Subsubsection
23301 Processor mismatch in file
23302 \begin_inset Quotes sld
23306 \begin_inset Quotes srd
23312 \begin_layout Standard
23313 This warning can usually be ignored due to the very good compatibility amongst
23318 \begin_layout Standard
23328 \begin_inset LatexCommand \index{PIC14}
23335 \begin_layout Standard
23336 You might also consider recompiling the library for your specific device
23337 by changing the ARCH=p16f877 (default target) entry in
23339 device/lib/pic/Makefile.in
23343 device/lib/pic/Makefile
23345 to reflect your device.
23346 This might even improve performance for smaller devices as unneccesary
23347 BANKSELs might be removed.
23350 \begin_layout Subsection
23354 \begin_layout Subsubsection
23358 \begin_layout Standard
23359 Functions with variable argument lists (like printf) are not yet supported.
23360 Similarly, taking the argument of the first argument passed into a function
23361 does not work: It is currently passed in WREG and has no address...
23364 \begin_layout Subsubsection
23365 Regression tests fail
23368 \begin_layout Standard
23369 Though the small subset of regression tests in src/regression passes, SDCC
23370 regression test suite does not, indicating that there are still major bugs
23372 However, many smaller projects have successfully used SDCC in the past...
23375 \begin_layout Standard
23383 \begin_layout Section
23385 \begin_inset LatexCommand \index{PIC16}
23392 \begin_layout Standard
23394 \begin_inset LatexCommand \index{PIC16}
23398 port is the portion of SDCC that is responsible to produce code for the
23400 \begin_inset LatexCommand \index{Microchip}
23404 (TM) microcontrollers with 16 bit core.
23405 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23406 Currently supported devices are:
23409 \begin_layout Standard
23410 18F: 242, 248, 252, 258, 442, 448, 452, 458
23413 \begin_layout Standard
23417 \begin_layout Standard
23418 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23421 \begin_layout Standard
23422 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23425 \begin_layout Standard
23426 18F: 6520, 6620, 6680, 6720
23429 \begin_layout Standard
23430 18F: 8520, 8620, 8680, 8720
23433 \begin_layout Subsection
23437 \begin_layout Standard
23438 PIC16 port supports the standard command line arguments as supposed, with
23439 the exception of certain cases that will be mentioned in the following
23443 \begin_layout Description
23448 \begin_layout Standard
23458 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23466 \begin_layout Standard
23478 \begin_layout Description
23483 \begin_layout Standard
23492 -fommit-frame-pointer
23493 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23497 Frame pointer will be omitted when the function uses no local variables.
23500 \begin_layout Subsection
23501 Port Specific Options
23502 \begin_inset LatexCommand \index{Options PIC16}
23509 \begin_layout Standard
23510 The port specific options appear after the global options in the sdcc -
23514 \begin_layout Standard
23526 \begin_layout Subsubsection
23527 Code Generation Options
23530 \begin_layout Standard
23531 These options influence the generated assembler code.
23534 \begin_layout Description
23539 \begin_layout Standard
23548 -pstack-model=[model] Used in conjuction with the command above.
23549 Defines the stack model to be used, valid stack models are:
23554 \labelwidthstring 00.00.0000
23559 Selects small stack model.
23560 8 bit stack and frame pointers.
23561 Supports 256 bytes stack size.
23565 \labelwidthstring 00.00.0000
23570 Selects large stack model.
23571 16 bit stack and frame pointers.
23572 Supports 65536 bytes stack size.
23576 \begin_layout Description
23581 \begin_layout Standard
23590 -pno-banksel Do not generate BANKSEL assembler directives.
23593 \begin_layout Description
23598 \begin_layout Standard
23607 -extended Enable extended instruction set/literal offset addressing mode.
23611 \begin_layout Subsubsection
23612 Optimization Options
23615 \begin_layout Description
23620 \begin_layout Standard
23629 -obanksel=n Set optimization level for inserting BANKSELs.
23636 \labelwidthstring 00.00.0000
23641 \labelwidthstring 00.00.0000
23642 1 checks previous used register and if it is the same then does not emit
23643 BANKSEL, accounts only for labels.
23647 \labelwidthstring 00.00.0000
23648 2 tries to check the location of (even different) symbols and removes BANKSELs
23649 if they are in the same bank.
23654 Important: There might be problems if the linker script has data sections
23655 across bank borders!
23659 \begin_layout Description
23664 \begin_layout Standard
23673 -denable-peeps Force the usage of peepholes.
23677 \begin_layout Description
23682 \begin_layout Standard
23691 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23694 \begin_layout Description
23699 \begin_layout Standard
23708 -optimize-cmp Try to optimize some compares.
23711 \begin_layout Description
23716 \begin_layout Standard
23725 -optimize-df Analyze the dataflow of the generated code and improve it.
23728 \begin_layout Subsubsection
23732 \begin_layout Description
23737 \begin_layout Standard
23746 -asm= Sets the full path and name of an external assembler to call.
23749 \begin_layout Description
23754 \begin_layout Standard
23764 \begin_inset LatexCommand \index{PIC16!MPLAB}
23768 compatibility option.
23769 Currently only suppresses special gpasm directives.
23772 \begin_layout Subsubsection
23776 \begin_layout Description
23781 \begin_layout Standard
23790 -link= Sets the full path and name of an external linker to call.
23793 \begin_layout Description
23798 \begin_layout Standard
23807 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23808 unitialized data variables with [kword].
23809 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23812 \begin_layout Description
23817 \begin_layout Standard
23826 -ivt-loc=n Place the interrupt vector table at address
23831 Useful for bootloaders.
23834 \begin_layout Description
23839 \begin_layout Standard
23848 -nodefaultlibs Do not link default libraries when linking.
23851 \begin_layout Description
23856 \begin_layout Standard
23865 -use-crt= Use a custom run-time module instead of the defaults.
23868 \begin_layout Description
23873 \begin_layout Standard
23882 -no-crt Don't link the default run-time modules
23885 \begin_layout Subsubsection
23889 \begin_layout Standard
23890 Debugging options enable extra debugging information in the output files.
23893 \begin_layout Description
23898 \begin_layout Standard
23907 -debug-xtra Similar to -
23911 \begin_layout Standard
23921 \begin_inset LatexCommand \index{-\/-debug}
23925 , but dumps more information.
23928 \begin_layout Description
23933 \begin_layout Standard
23942 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23944 <source> is the name of the file being compiled.
23947 \begin_layout Description
23952 \begin_layout Standard
23961 -pcode-verbose Enable pcode debugging information in translation.
23964 \begin_layout Description
23969 \begin_layout Standard
23978 -calltree Dump call tree in .calltree file.
23981 \begin_layout Description
23986 \begin_layout Standard
23995 -gstack Trace push/pops for stack pointer overflow.
23998 \begin_layout Subsection
23999 Enviroment Variables
24002 \begin_layout Standard
24003 There is a number of enviromental variables that can be used when running
24004 SDCC to enable certain optimizations or force a specific program behaviour.
24005 these variables are primarily for debugging purposes so they can be enabled/dis
24009 \begin_layout Standard
24010 Currently there is only two such variables available:
24013 \begin_layout Description
24014 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24015 bitfields is optimized by directly loading FSR0 with the address of the
24016 bitfield structure.
24017 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24019 This step saves data ram and code space for functions that make heavy use
24021 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24026 \begin_layout Description
24027 NO_REG_OPT Do not perform pCode registers optimization.
24028 This should be used for debugging purposes.
24029 If bugs in the pcode optimizer are found, users can benefit from temporarily
24030 disabling the optimizer until the bug is fixed.
24033 \begin_layout Subsection
24034 Preprocessor Macros
24037 \begin_layout Standard
24039 \begin_inset LatexCommand \index{PIC16}
24043 port defines the following preprocessor macros while translating a source.
24046 \begin_layout Standard
24048 \begin_inset Tabular
24049 <lyxtabular version="3" rows="6" columns="2">
24051 <column alignment="center" valignment="top" leftline="true" width="0">
24052 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24053 <row topline="true" bottomline="true">
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24057 \begin_layout Standard
24063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24066 \begin_layout Standard
24073 <row topline="true">
24074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24077 \begin_layout Standard
24083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24086 \begin_layout Standard
24087 Port identification
24093 <row topline="true">
24094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24097 \begin_layout Standard
24102 \begin_layout Standard
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24119 \begin_layout Standard
24120 Port identification (same as above)
24126 <row topline="true">
24127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24130 \begin_layout Standard
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24139 \begin_layout Standard
24140 MCU Identification.
24145 is the microcontrol identification number, i.e.
24152 <row topline="true">
24153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24156 \begin_layout Standard
24161 \begin_layout Standard
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24178 \begin_layout Standard
24179 MCU Identification (same as above)
24185 <row topline="true" bottomline="true">
24186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24189 \begin_layout Standard
24195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24198 \begin_layout Standard
24199 nnn = SMALL or LARGE respectively according to the stack model used
24212 \begin_layout Standard
24213 In addition the following macros are defined when calling assembler:
24216 \begin_layout Standard
24218 \begin_inset Tabular
24219 <lyxtabular version="3" rows="4" columns="2">
24221 <column alignment="center" valignment="top" leftline="true" width="0">
24222 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24223 <row topline="true" bottomline="true">
24224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24227 \begin_layout Standard
24233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24236 \begin_layout Standard
24243 <row topline="true">
24244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24247 \begin_layout Standard
24253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24256 \begin_layout Standard
24257 MCU Identification.
24262 is the microcontrol identification number, i.e.
24269 <row topline="true">
24270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24273 \begin_layout Standard
24279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24282 \begin_layout Standard
24283 nnn = SMALL or LARGE respectively according to the memory model used for
24290 <row topline="true" bottomline="true">
24291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24294 \begin_layout Standard
24300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24303 \begin_layout Standard
24304 nnn = SMALL or LARGE respectively according to the stack model used
24317 \begin_layout Subsection
24321 \begin_layout Standard
24323 \begin_inset LatexCommand \index{PIC16}
24327 port uses the following directories for searching header files and libraries.
24330 \begin_layout Standard
24332 \begin_inset Tabular
24333 <lyxtabular version="3" rows="3" columns="4">
24335 <column alignment="center" valignment="top" leftline="true" width="0">
24336 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24337 <column alignment="center" valignment="top" width="0">
24338 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24339 <row topline="true" bottomline="true">
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24343 \begin_layout Standard
24349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24352 \begin_layout Standard
24358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24361 \begin_layout Standard
24367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24370 \begin_layout Standard
24377 <row topline="true">
24378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24381 \begin_layout Standard
24382 PREFIX/sdcc/include/pic16
24387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24390 \begin_layout Standard
24391 PIC16 specific headers
24396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24399 \begin_layout Standard
24405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24408 \begin_layout Standard
24415 <row topline="true" bottomline="true">
24416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24419 \begin_layout Standard
24420 PREFIX/sdcc/lib/pic16
24425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24428 \begin_layout Standard
24429 PIC16 specific libraries
24434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24437 \begin_layout Standard
24443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24446 \begin_layout Standard
24460 \begin_layout Subsection
24462 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24469 \begin_layout Standard
24471 \begin_inset LatexCommand \index{PIC16}
24475 port currently supports the following pragmas:
24478 \begin_layout Description
24480 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24484 This forces the code generator to initialize the stack & frame pointers
24485 at a specific address.
24486 This is an ad hoc solution for cases where no STACK directive is available
24487 in the linker script or gplink is not instructed to create a stack section.
24490 stack pragma should be used only once in a project.
24491 Multiple pragmas may result in indeterminate behaviour of the program.
24495 \begin_layout Standard
24496 The old format (ie.
24497 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24498 cross page boundaries (or even exceed the available data RAM) and crash
24500 Make sure that stack does not cross page boundaries when using the SMALL
24508 The format is as follows:
24513 \begin_layout LyX-Code
24514 #pragma stack bottom_address [stack_size]
24519 \begin_layout Standard
24524 is the lower bound of the stack section.
24525 The stack pointer initially will point at address (bottom_address+stack_size-1).
24528 \begin_layout LyX-Code
24532 \begin_layout LyX-Code
24536 \begin_layout LyX-Code
24537 /* initializes stack of 100 bytes at RAM address 0x200 */
24540 \begin_layout LyX-Code
24541 #pragma stack 0x200 100
24544 \begin_layout Standard
24545 If the stack_size field is omitted then a stack is created with the default
24547 This size might be enough for most programs, but its not enough for operations
24548 with deep function nesting or excessive stack usage.
24551 \begin_layout Description
24553 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24557 Force a function to a static FLASH address.
24560 \begin_layout LyX-Code
24564 \begin_layout LyX-Code
24568 \begin_layout LyX-Code
24569 /* place function test_func at 0x4000 */
24572 \begin_layout LyX-Code
24573 #pragma code test_func 0x4000
24576 \begin_layout LyX-Code
24580 \begin_layout Description
24581 library instructs the linker to use a library module.
24586 \begin_layout LyX-Code
24587 #pragma library module_name
24590 \begin_layout Standard
24595 can be any library or object file (including its path).
24596 Note that there are four reserved keywords which have special meaning.
24600 \begin_layout Standard
24602 \begin_inset Tabular
24603 <lyxtabular version="3" rows="6" columns="3">
24605 <column alignment="center" valignment="top" leftline="true" width="0">
24606 <column alignment="block" valignment="top" leftline="true" width="20page%">
24607 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24608 <row topline="true" bottomline="true">
24609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24612 \begin_layout Standard
24618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24621 \begin_layout Standard
24627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24630 \begin_layout Standard
24637 <row topline="true">
24638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24641 \begin_layout Standard
24649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24652 \begin_layout Standard
24653 ignore all library pragmas
24658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24661 \begin_layout Standard
24670 <row topline="true">
24671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24674 \begin_layout Standard
24682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24685 \begin_layout Standard
24691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24694 \begin_layout Standard
24705 <row topline="true">
24706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24709 \begin_layout Standard
24717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24720 \begin_layout Standard
24721 link the Math libarary
24726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24729 \begin_layout Standard
24740 <row topline="true">
24741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24744 \begin_layout Standard
24752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24755 \begin_layout Standard
24756 link the I/O library
24761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24764 \begin_layout Standard
24775 <row topline="true" bottomline="true">
24776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24779 \begin_layout Standard
24787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24790 \begin_layout Standard
24791 link the debug library
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24799 \begin_layout Standard
24816 * is the device number, i.e.
24817 452 for PIC18F452 MCU.
24820 \begin_layout Standard
24821 This feature allows for linking with specific libraries withoug having to
24822 explicit name them in the command line.
24827 keyword will reject all modules specified by the library pragma.
24830 \begin_layout Description
24831 udata The pragma udata instructs the compiler to emit code so that linker
24832 will place a variable at a specific memory bank.
24835 \begin_layout LyX-Code
24839 \begin_layout LyX-Code
24843 \begin_layout LyX-Code
24844 /* places variable foo at bank2 */
24847 \begin_layout LyX-Code
24848 #pragma udata bank2 foo
24851 \begin_layout LyX-Code
24855 \begin_layout Standard
24856 In order for this pragma to work extra SECTION directives should be added
24857 in the .lkr script.
24858 In the following example a sample .lkr file is shown:
24861 \begin_layout LyX-Code
24865 \begin_layout LyX-Code
24866 // Sample linker script for the PIC18F452 processor
24869 \begin_layout LyX-Code
24873 \begin_layout LyX-Code
24874 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24877 \begin_layout LyX-Code
24878 CODEPAGE NAME=page START=0x2A END=0x7FFF
24881 \begin_layout LyX-Code
24882 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24885 \begin_layout LyX-Code
24886 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24889 \begin_layout LyX-Code
24890 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24893 \begin_layout LyX-Code
24894 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24897 \begin_layout LyX-Code
24898 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24901 \begin_layout LyX-Code
24905 \begin_layout LyX-Code
24906 DATABANK NAME=gpr0 START=0x80 END=0xFF
24909 \begin_layout LyX-Code
24910 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24913 \begin_layout LyX-Code
24914 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24917 \begin_layout LyX-Code
24918 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24921 \begin_layout LyX-Code
24922 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24925 \begin_layout LyX-Code
24926 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24929 \begin_layout LyX-Code
24930 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24933 \begin_layout LyX-Code
24937 \begin_layout LyX-Code
24938 SECTION NAME=CONFIG ROM=config
24941 \begin_layout LyX-Code
24945 \begin_layout LyX-Code
24946 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24949 \begin_layout LyX-Code
24950 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24953 \begin_layout LyX-Code
24954 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24957 \begin_layout LyX-Code
24958 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24961 \begin_layout LyX-Code
24962 SECTION NAME=bank4 RAM=gpr4
24965 \begin_layout LyX-Code
24966 SECTION NAME=bank5 RAM=gpr5
24969 \begin_layout Standard
24970 The linker will recognise the section name set in the pragma statement and
24971 will position the variable at the memory bank set with the RAM field at
24972 the SECTION line in the linker script file.
24975 \begin_layout Subsection
24977 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24984 \begin_layout Standard
24985 There is one main header file
24986 \begin_inset LatexCommand \index{PIC16!Header files}
24990 that can be included to the source files using the pic16
24991 \begin_inset LatexCommand \index{PIC16}
25001 This header file contains the definitions for the processor special registers,
25002 so it is necessary if the source accesses them.
25003 It can be included by adding the following line in the beginning of the
25007 \begin_layout LyX-Code
25008 #include <pic18fregs.h>
25011 \begin_layout Standard
25012 The specific microcontroller is selected within the pic18fregs.h automatically,
25013 so the same source can be used with a variety of devices.
25016 \begin_layout Subsection
25020 \begin_layout Standard
25022 \begin_inset LatexCommand \index{PIC16!Libraries}
25027 \begin_inset LatexCommand \index{PIC16}
25031 port depends on are the microcontroller device libraries which contain
25032 the symbol definitions for the microcontroller special function registers.
25033 These libraries have the format pic18fxxxx.lib, where
25037 is the microcontroller identification number.
25038 The specific library is selected automatically by the compiler at link
25039 stage according to the selected device.
25042 \begin_layout Standard
25043 Libraries are created with gplib which is part of the gputils package
25044 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25051 \begin_layout Subsubsection*
25052 Building the libraries
25055 \begin_layout Standard
25056 Before using SDCC/pic16 there are some libraries that need to be compiled.
25057 This process is not done automatically by SDCC since not all users use
25058 SDCC for pic16 projects.
25059 So each user should compile the libraries separately.
25062 \begin_layout Standard
25063 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25066 \begin_layout LyX-Code
25067 cd device/lib/pic16
25070 \begin_layout LyX-Code
25074 \begin_layout LyX-Code
25078 \begin_layout LyX-Code
25082 \begin_layout LyX-Code
25086 \begin_layout LyX-Code
25087 su -c 'make install' # install the libraries, you need the root password
25090 \begin_layout Standard
25091 If you need to install the headers too, do:
25094 \begin_layout LyX-Code
25098 \begin_layout LyX-Code
25099 su -c 'make install' # install the headers, you need the root password
25102 \begin_layout Standard
25103 There exist a special target to build the I/O libraries.
25104 This target is not automatically build because it will build the I/O library
25110 This way building will take quite a lot of time.
25111 Users are advised to edit the
25113 device/lib/pic16/pics.build
25115 file and then execute:
25118 \begin_layout LyX-Code
25122 \begin_layout Subsection
25123 Adding New Devices to the Port
25126 \begin_layout Standard
25127 Adding support for a new 16
25131 \begin_layout Standard
25140 bit PIC MCU requires the following steps:
25143 \begin_layout Enumerate
25144 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25148 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25152 \begin_layout Enumerate
25155 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25158 \begin_layout Enumerate
25161 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25164 \begin_layout Enumerate
25167 /path/to/sdcc/device/lib/pics.all
25175 Note: No 18f prefix here!
25178 \begin_layout Enumerate
25181 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25185 Add your DEVICE if it does not compile in
25200 \begin_layout Enumerate
25203 /path/to/sdcc/device/include/pic16/pic18fregs.h
25206 The file format is self-explanatory, just add
25210 #elif defined(picDEVICE)
25212 # include <picDEVICE.h>
25216 at the right place (keep it sorted).
25219 \begin_layout Enumerate
25222 /path/to/sdcc/src/pic16/devices.inc
25225 Copy and modify an existing entry and insert it at the correct place (keep
25227 The file is hardly documented, look at the entries for the 18f2221...
25230 \begin_layout Enumerate
25231 Recompile SDCC, including the pic16 libraries.
25234 \begin_layout Subsection
25238 \begin_layout Standard
25239 The following memory models are supported by the PIC16 port:
25242 \begin_layout Itemize
25246 \begin_layout Itemize
25250 \begin_layout Standard
25251 Memory model affects the default size of pointers within the source.
25252 The sizes are shown in the next table:
25255 \begin_layout Standard
25257 \begin_inset Tabular
25258 <lyxtabular version="3" rows="3" columns="3">
25260 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25261 <column alignment="center" valignment="top" leftline="true" width="0">
25262 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25263 <row topline="true" bottomline="true">
25264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25267 \begin_layout Standard
25268 Pointer sizes according to memory model
25273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25276 \begin_layout Standard
25282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25285 \begin_layout Standard
25292 <row topline="true" bottomline="true">
25293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25296 \begin_layout Standard
25302 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25305 \begin_layout Standard
25311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25314 \begin_layout Standard
25321 <row topline="true" bottomline="true">
25322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25325 \begin_layout Standard
25331 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25334 \begin_layout Standard
25340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25343 \begin_layout Standard
25357 \begin_layout Standard
25358 It is advisable that all sources within a project are compiled with the
25360 If one wants to override the default memory model, this can be done by
25361 declaring a pointer as
25370 Far selects large memory model's pointers, while near selects small memory
25374 \begin_layout Standard
25375 The standard device libraries (see
25376 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25380 ) contain no reference to pointers, so they can be used with both memory
25384 \begin_layout Subsection
25388 \begin_layout Standard
25390 \begin_inset LatexCommand \index{PIC16!stack}
25394 implementation for the PIC16 port uses two indirect registers, FSR1 and
25398 \begin_layout Description
25399 FSR1 is assigned as stack pointer
25402 \begin_layout Description
25403 FSR2 is assigned as frame pointer
25406 \begin_layout Standard
25407 The following stack models are supported by the PIC16 port
25410 \begin_layout Itemize
25418 \begin_layout Itemize
25426 \begin_layout Standard
25431 model means that only the FSRxL byte is used to access stack and frame,
25438 uses both FSRxL and FSRxH registers.
25439 The following table shows the stack/frame pointers sizes according to stack
25440 model and the maximum space they can address:
25443 \begin_layout Standard
25445 \begin_inset Tabular
25446 <lyxtabular version="3" rows="3" columns="3">
25448 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25449 <column alignment="center" valignment="top" leftline="true" width="0">
25450 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25451 <row topline="true" bottomline="true">
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25455 \begin_layout Standard
25456 Stack & Frame pointer sizes according to stack model
25461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25464 \begin_layout Standard
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25473 \begin_layout Standard
25480 <row topline="true">
25481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25484 \begin_layout Standard
25490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25493 \begin_layout Standard
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25502 \begin_layout Standard
25509 <row topline="true" bottomline="true">
25510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25513 \begin_layout Standard
25519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25522 \begin_layout Standard
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25531 \begin_layout Standard
25545 \begin_layout Standard
25550 stack model is currently not working properly throughout the code generator.
25551 So its use is not advised.
25552 Also there are some other points that need special care:
25557 \begin_layout Enumerate
25558 Do not create stack sections with size more than one physical bank (that
25562 \begin_layout Enumerate
25563 Stack sections should no cross physical bank limits (i.e.
25564 #pragma stack 0x50 0x100)
25567 \begin_layout Standard
25568 These limitations are caused by the fact that only FSRxL is modified when
25569 using SMALL stack model, so no more than 256 bytes of stack can be used.
25570 This problem will disappear after LARGE model is fully implemented.
25573 \begin_layout Subsection
25577 \begin_layout Standard
25578 In addition to the standard SDCC function keywords, PIC16
25579 \begin_inset LatexCommand \index{PIC16}
25583 port makes available two more:
25586 \begin_layout Description
25588 \begin_inset LatexCommand \index{PIC16!wparam}
25592 Use the WREG to pass one byte of the first function argument.
25593 This improves speed but you may not use this for functions with arguments
25594 that are called via function pointers, otherwise the first byte of the
25595 first parameter will get lost.
25599 \begin_layout LyX-Code
25600 void func_wparam(int a) wparam
25603 \begin_layout LyX-Code
25607 \begin_layout LyX-Code
25608 /* WREG hold the lower part of a */
25611 \begin_layout LyX-Code
25612 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25616 \begin_layout LyX-Code
25620 \begin_layout LyX-Code
25624 \begin_layout Description
25626 \begin_inset LatexCommand \index{PIC16!shadowregs}
25630 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25631 hardware shadow registers which hold the values of WREG, STATUS and BSR
25633 This can be done by adding the keyword
25641 keyword in the function's header.
25644 \begin_layout LyX-Code
25645 void isr_shadow(void) shadowregs interrupt 1
25648 \begin_layout LyX-Code
25652 \begin_layout LyX-Code
25656 \begin_layout LyX-Code
25660 \begin_layout Standard
25665 instructs the code generator not to store/restore WREG, STATUS, BSR when
25666 entering/exiting the ISR.
25669 \begin_layout Subsection
25670 Function return values
25673 \begin_layout Standard
25674 Return values from functions are placed to the appropriate registers following
25675 a modified Microchip policy optimized for SDCC.
25676 The following table shows these registers:
25679 \begin_layout Standard
25681 \begin_inset Tabular
25682 <lyxtabular version="3" rows="6" columns="2">
25684 <column alignment="center" valignment="top" leftline="true" width="0">
25685 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25686 <row topline="true" bottomline="true">
25687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25690 \begin_layout Standard
25696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25699 \begin_layout Standard
25700 destination register
25706 <row topline="true">
25707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25710 \begin_layout Standard
25716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25719 \begin_layout Standard
25726 <row topline="true">
25727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25730 \begin_layout Standard
25736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25739 \begin_layout Standard
25746 <row topline="true">
25747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25750 \begin_layout Standard
25756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25759 \begin_layout Standard
25766 <row topline="true">
25767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25770 \begin_layout Standard
25776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25779 \begin_layout Standard
25780 FSR0L:PRODH:PRODL:WREG
25786 <row topline="true" bottomline="true">
25787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25790 \begin_layout Standard
25796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25799 \begin_layout Standard
25800 on stack, FSR0 points to the beginning
25813 \begin_layout Subsection
25817 \begin_layout Standard
25819 \begin_inset LatexCommand \index{PIC16!interrupt}
25823 service routine (ISR) is declared using the
25830 \begin_layout LyX-Code
25831 void isr(void) interrupt
25836 \begin_layout LyX-Code
25840 \begin_layout LyX-Code
25844 \begin_layout LyX-Code
25848 \begin_layout Standard
25853 is the interrupt number, which for PIC18F devices can be:
25856 \begin_layout Standard
25858 \begin_inset Tabular
25859 <lyxtabular version="3" rows="4" columns="3">
25861 <column alignment="center" valignment="top" leftline="true" width="0">
25862 <column alignment="center" valignment="top" leftline="true" width="0">
25863 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25864 <row topline="true" bottomline="true">
25865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25868 \begin_layout Standard
25876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25879 \begin_layout Standard
25885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25888 \begin_layout Standard
25889 Interrupt Vector Address
25895 <row topline="true">
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" usebox="none">
25908 \begin_layout Standard
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25917 \begin_layout Standard
25924 <row topline="true">
25925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25928 \begin_layout Standard
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25946 \begin_layout Standard
25956 HIGH priority interrupts
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25964 \begin_layout Standard
25971 <row topline="true" bottomline="true">
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25975 \begin_layout Standard
25981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25984 \begin_layout Standard
25985 LOW priority interrupts
25990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25993 \begin_layout Standard
26007 \begin_layout Standard
26008 When generating assembly code for ISR the code generator places a
26014 Interrupt Vector Address
26016 which points at the genetated ISR.
26017 This single GOTO instruction is part of an automatically generated
26019 interrupt entry point
26022 The actuall ISR code is placed as normally would in the code space.
26023 Upon interrupt request, the GOTO instruction is executed which jumps to
26025 When declaring interrupt functions as _naked this GOTO instruction is
26030 The whole interrupt functions is therefore placed at the Interrupt Vector
26031 Address of the specific interrupt.
26032 This is not a problem for the LOW priority interrupts, but it is a problem
26033 for the RESET and the HIGH priority interrupts because code may be written
26034 at the next interrupt´s vector address and cause undeterminate program
26035 behaviour if that interrupt is raised.
26039 \begin_layout Standard
26040 This is not a problem when
26043 \begin_layout Enumerate
26044 this is a HIGH interrupt ISR and LOW interrupts are
26051 \begin_layout Enumerate
26052 when the ISR is small enough not to reach the next interrupt´s vector address.
26060 \begin_layout Standard
26065 is possible to be omitted.
26066 This way a function is generated similar to an ISR, but it is not assigned
26070 \begin_layout Standard
26071 When entering an interrupt, currently the PIC16
26072 \begin_inset LatexCommand \index{PIC16}
26076 port automatically saves the following registers:
26079 \begin_layout Itemize
26083 \begin_layout Itemize
26087 \begin_layout Itemize
26091 \begin_layout Itemize
26092 PROD (PRODL and PRODH)
26095 \begin_layout Itemize
26096 FSR0 (FSR0L and FSR0H)
26099 \begin_layout Standard
26100 These registers are restored upon return from the interrupt routine.
26104 \begin_layout Standard
26105 NOTE that when the _naked attribute is specified for an interrupt routine,
26106 then NO registers are stored or restored.
26114 \begin_layout Subsection
26118 \begin_layout Standard
26119 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26120 There are 3 types of generic pointers currently implemented data, code
26121 and eeprom pointers.
26122 They are differentiated by the value of the 7th and 6th bits of the upper
26126 \begin_layout Standard
26128 \begin_inset Tabular
26129 <lyxtabular version="3" rows="5" columns="5">
26131 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26132 <column alignment="center" valignment="top" width="0">
26133 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26134 <column alignment="center" valignment="top" width="0">
26135 <column alignment="left" valignment="top" rightline="true" width="0">
26136 <row topline="true" bottomline="true">
26137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26140 \begin_layout Standard
26146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26149 \begin_layout Standard
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26158 \begin_layout Standard
26164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26167 \begin_layout Standard
26168 rest of the pointer
26173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26176 \begin_layout Standard
26183 <row topline="true" bottomline="true">
26184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26187 \begin_layout Standard
26193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26196 \begin_layout Standard
26202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26205 \begin_layout Standard
26211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26214 \begin_layout Standard
26219 uuuuuu uuuuxxxx xxxxxxxx
26224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26227 \begin_layout Standard
26228 a 12-bit data pointer in data RAM memory
26234 <row bottomline="true">
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26238 \begin_layout Standard
26244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26247 \begin_layout Standard
26253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26256 \begin_layout Standard
26262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26265 \begin_layout Standard
26270 uxxxxx xxxxxxxx xxxxxxxx
26275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26278 \begin_layout Standard
26279 a 21-bit code pointer in FLASH memory
26285 <row bottomline="true">
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26289 \begin_layout Standard
26295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 \begin_layout Standard
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26307 \begin_layout Standard
26313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26316 \begin_layout Standard
26321 uuuuuu uuuuuuxx xxxxxxxx
26326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26329 \begin_layout Standard
26330 a 10-bit eeprom pointer in EEPROM memory
26336 <row bottomline="true">
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26340 \begin_layout Standard
26346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26349 \begin_layout Standard
26355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26358 \begin_layout Standard
26364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26367 \begin_layout Standard
26372 xxxxxx xxxxxxxx xxxxxxxx
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26380 \begin_layout Standard
26381 unimplemented pointer type
26394 \begin_layout Standard
26395 Generic pointer are read and written with a set of library functions which
26396 read/write 1, 2, 3, 4 bytes.
26399 \begin_layout Subsection
26403 \begin_layout Subsubsection
26404 Standard I/O Streams
26407 \begin_layout Standard
26412 the type FILE is defined as:
26415 \begin_layout LyX-Code
26416 typedef char * FILE;
26419 \begin_layout Standard
26420 This type is the stream type implemented I/O in the PIC18F devices.
26421 Also the standard input and output streams are declared in stdio.h:
26424 \begin_layout LyX-Code
26425 extern FILE * stdin;
26428 \begin_layout LyX-Code
26429 extern FILE * stdout;
26432 \begin_layout Standard
26433 The FILE type is actually a generic pointer which defines one more type
26434 of generic pointers, the
26439 This new type has the format:
26442 \begin_layout Standard
26444 \begin_inset Tabular
26445 <lyxtabular version="3" rows="2" columns="7">
26447 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26448 <column alignment="center" valignment="top" width="0">
26449 <column alignment="center" valignment="top" leftline="true" width="0">
26450 <column alignment="center" valignment="top" leftline="true" width="0">
26451 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26452 <column alignment="center" valignment="top" width="0">
26453 <column alignment="left" valignment="top" rightline="true" width="0">
26454 <row topline="true" bottomline="true">
26455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26458 \begin_layout Standard
26464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26467 \begin_layout Standard
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26476 \begin_layout Standard
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26485 \begin_layout Standard
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26494 \begin_layout Standard
26500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26503 \begin_layout Standard
26504 rest of the pointer
26509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26512 \begin_layout Standard
26519 <row topline="true" bottomline="true">
26520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26523 \begin_layout Standard
26529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26532 \begin_layout Standard
26538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26541 \begin_layout Standard
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26550 \begin_layout Standard
26556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26559 \begin_layout Standard
26565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26568 \begin_layout Standard
26578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26581 \begin_layout Standard
26582 upper byte high nubble is 0x2n, the rest are zeroes
26595 \begin_layout Standard
26596 Currently implemented there are 3 types of streams defined:
26599 \begin_layout Standard
26601 \begin_inset Tabular
26602 <lyxtabular version="3" rows="4" columns="4">
26604 <column alignment="center" valignment="top" leftline="true" width="0">
26605 <column alignment="center" valignment="top" leftline="true" width="0">
26606 <column alignment="center" valignment="top" leftline="true" width="0">
26607 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26608 <row topline="true" bottomline="true">
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26612 \begin_layout Standard
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26621 \begin_layout Standard
26627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26630 \begin_layout Standard
26636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26639 \begin_layout Standard
26646 <row topline="true">
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26650 \begin_layout Standard
26656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26659 \begin_layout Standard
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26670 \begin_layout Standard
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_layout Standard
26680 Writes/Reads characters via the USART peripheral
26686 <row topline="true">
26687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26690 \begin_layout Standard
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26699 \begin_layout Standard
26707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_layout Standard
26716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26719 \begin_layout Standard
26720 Writes/Reads characters via the MSSP peripheral
26726 <row topline="true" bottomline="true">
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26730 \begin_layout Standard
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26739 \begin_layout Standard
26747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26750 \begin_layout Standard
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26759 \begin_layout Standard
26760 Writes/Reads characters via used defined functions
26773 \begin_layout Standard
26774 The stream identifiers are declared as macros in the stdio.h header.
26777 \begin_layout Standard
26778 In the libc library there exist the functions that are used to write to
26779 each of the above streams.
26783 \begin_layout Description
26788 \begin_layout Standard
26797 _stream_usart_putchar writes a character at the USART stream
26800 \begin_layout Description
26805 \begin_layout Standard
26814 _stream_mssp_putchar writes a character at the MSSP stream
26817 \begin_layout Description
26818 putchar dummy function.
26819 This writes a character to a user specified manner.
26822 \begin_layout Standard
26823 In order to increase performance
26827 is declared in stdio.h as having its parameter in WREG (it has the wparam
26829 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26830 in a user-friendly way.
26835 is the name of the variable that holds the character to print.
26836 An example follows:
26839 \begin_layout LyX-Code
26840 #include <pic18fregs.h>
26849 \begin_layout LyX-Code
26853 \begin_layout LyX-Code
26854 PORTA = c; /* dump character c to PORTA */
26857 \begin_layout LyX-Code
26865 \begin_layout LyX-Code
26869 \begin_layout LyX-Code
26870 stdout = STREAM_USER; /* this is not necessary, since stdout points
26873 \begin_layout LyX-Code
26874 * by default to STREAM_USER */
26877 \begin_layout LyX-Code
26879 \begin_inset Quotes sld
26882 This is a printf test
26885 \begin_inset Quotes srd
26891 \begin_layout LyX-Code
26895 \begin_layout LyX-Code
26899 \begin_layout Subsubsection
26903 \begin_layout Standard
26904 PIC16 contains an implementation of the printf-family of functions.
26905 There exist the following functions:
26908 \begin_layout LyX-Code
26909 extern unsigned int sprintf(char *buf, char *fmt, ...);
26912 \begin_layout LyX-Code
26913 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26916 \begin_layout LyX-Code
26920 \begin_layout LyX-Code
26921 extern unsigned int printf(char *fmt, ...);
26924 \begin_layout LyX-Code
26925 extern unsigned int vprintf(char *fmt, va_lista ap);
26928 \begin_layout LyX-Code
26932 \begin_layout LyX-Code
26933 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26936 \begin_layout LyX-Code
26937 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26940 \begin_layout Standard
26941 For sprintf and vsprintf
26945 should normally be a data pointer where the resulting string will be placed.
26946 No range checking is done so the user should allocate the necessery buffer.
26947 For fprintf and vfprintf
26951 should be a stream pointer (i.e.
26952 stdout, STREAM_MSSP, etc...).
26955 \begin_layout Subsubsection
26959 \begin_layout Standard
26960 The PIC18F family of microcontrollers supports a number of interrupt sources.
26961 A list of these interrupts is shown in the following table:
26964 \begin_layout Standard
26966 \begin_inset Tabular
26967 <lyxtabular version="3" rows="11" columns="4">
26969 <column alignment="left" valignment="top" leftline="true" width="0">
26970 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26971 <column alignment="left" valignment="top" leftline="true" width="0">
26972 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26973 <row topline="true" bottomline="true">
26974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26977 \begin_layout Standard
26983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26986 \begin_layout Standard
26992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26995 \begin_layout Standard
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27004 \begin_layout Standard
27011 <row topline="true">
27012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27015 \begin_layout Standard
27021 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27024 \begin_layout Standard
27025 PORTB change interrupt
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27033 \begin_layout Standard
27039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27042 \begin_layout Standard
27043 EEPROM/FLASH write complete interrupt
27049 <row topline="true">
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27053 \begin_layout Standard
27059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27062 \begin_layout Standard
27063 INT0 external interrupt
27068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27071 \begin_layout Standard
27077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27080 \begin_layout Standard
27081 Bus collision interrupt
27087 <row topline="true">
27088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27091 \begin_layout Standard
27097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27100 \begin_layout Standard
27101 INT1 external interrupt
27106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27109 \begin_layout Standard
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27118 \begin_layout Standard
27119 Low voltage detect interrupt
27125 <row topline="true">
27126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27129 \begin_layout Standard
27135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27138 \begin_layout Standard
27139 INT2 external interrupt
27144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27147 \begin_layout Standard
27153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27156 \begin_layout Standard
27157 Parallel slave port interrupt
27163 <row topline="true">
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27167 \begin_layout Standard
27173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27176 \begin_layout Standard
27177 CCP1 module interrupt
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27185 \begin_layout Standard
27191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27194 \begin_layout Standard
27195 AD convertion complete interrupt
27201 <row topline="true">
27202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27205 \begin_layout Standard
27211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27214 \begin_layout Standard
27215 CCP2 module interrupt
27220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27223 \begin_layout Standard
27229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27232 \begin_layout Standard
27233 USART receive interrupt
27239 <row topline="true">
27240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27243 \begin_layout Standard
27249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27252 \begin_layout Standard
27253 TMR0 overflow interrupt
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27261 \begin_layout Standard
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27270 \begin_layout Standard
27271 USART transmit interrupt
27277 <row topline="true">
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27281 \begin_layout Standard
27287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27290 \begin_layout Standard
27291 TMR1 overflow interrupt
27296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27299 \begin_layout Standard
27305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27308 \begin_layout Standard
27309 SSP receive/transmit interrupt
27315 <row topline="true">
27316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27319 \begin_layout Standard
27325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27328 \begin_layout Standard
27329 TMR2 matches PR2 interrupt
27334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27337 \begin_layout Standard
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27346 \begin_layout Standard
27353 <row topline="true" bottomline="true">
27354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27357 \begin_layout Standard
27363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27366 \begin_layout Standard
27367 TMR3 overflow interrupt
27372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27375 \begin_layout Standard
27381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27384 \begin_layout Standard
27398 \begin_layout Standard
27399 The prototypes for these names are defined in the header file
27406 \begin_layout Standard
27407 In order to simplify signal handling, a number of macros is provided:
27411 \labelwidthstring 00.00.0000
27412 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27413 high priority interrupts.
27418 is the function name to use.
27422 \labelwidthstring 00.00.0000
27423 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27424 low priority interrupt.
27429 is the function name to use.
27433 \labelwidthstring 00.00.0000
27434 DEF_HANDLER(sig,handler) define a handler for signal
27440 \labelwidthstring 00.00.0000
27441 END_DEF end the declaration of the dispatch table.
27444 \begin_layout Standard
27445 Additionally there are two more macros to simplify the declaration of the
27450 \labelwidthstring 00.00.0000
27453 SIGHANDLER(handler)
27455 this declares the function prototype for the
27463 \labelwidthstring 00.00.0000
27464 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27467 \begin_layout Standard
27468 An example of using the macros above is shown below:
27471 \begin_layout LyX-Code
27472 #include <pic18fregs.h>
27475 \begin_layout LyX-Code
27476 #include <signal.h>
27480 DEF_INTHIGH(high_int)
27483 \begin_layout LyX-Code
27484 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27487 \begin_layout LyX-Code
27488 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27491 \begin_layout LyX-Code
27496 SIGHANDLER(_tmr0_handler)
27499 \begin_layout LyX-Code
27503 \begin_layout LyX-Code
27504 /* action to be taken when timer 0 overflows */
27507 \begin_layout LyX-Code
27512 SIGHANDLERNAKED(_bcol_handler)
27515 \begin_layout LyX-Code
27519 \begin_layout LyX-Code
27523 \begin_layout LyX-Code
27524 /* action to be taken when bus collision occurs */
27527 \begin_layout LyX-Code
27531 \begin_layout LyX-Code
27535 \begin_layout LyX-Code
27539 \begin_layout Standard
27544 Special care should be taken when using the above scheme:
27547 \begin_layout Itemize
27548 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27551 \begin_layout Itemize
27552 when declaring SIGHANDLERNAKED handler never forget to use
27556 for proper returning.
27559 \begin_layout Subsection
27563 \begin_layout Standard
27564 Here you can find some general tips for compiling programs with SDCC/pic16.
27567 \begin_layout Subsubsection
27571 \begin_layout Standard
27573 \begin_inset LatexCommand \index{PIC16!stack}
27577 size (that is 64 bytes) probably is enough for many programs.
27578 One must take care that when there are many levels of function nesting,
27579 or there is excessive usage of stack, its size should be extended.
27580 An example of such a case is the printf/sprintf family of functions.
27581 If you encounter problems like not being able to print integers, then you
27582 need to set the stack size around the maximum (256 for small stack model).
27583 The following diagram shows what happens when calling printf to print an
27587 \begin_layout LyX-Code
27588 printf () --> ltoa () --> ultoa () --> divschar ()
27591 \begin_layout Standard
27592 It is should be understood that stack is easily consumed when calling complicate
27594 Using command line arguments like -
27598 \begin_layout Standard
27607 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27609 Other ways to reduce stack usage may exist.
27612 \begin_layout Subsection
27616 \begin_layout Standard
27617 The PIC16 Port currently does not pass SDCC's regression test
27618 \begin_inset LatexCommand \index{Regression test (PIC16)}
27623 \begin_inset LatexCommand \ref{sec:Quality-control}
27627 ) and thus the snapshot build regression tests for the PIC16 target are
27628 currently disabled for all hosts
27633 \begin_layout Chapter
27637 \begin_layout Standard
27638 There are several approaches to debugging your code.
27639 This chapter is meant to show your options and to give detail on some of
27644 When writing your code:
27647 \begin_layout Itemize
27648 write your code with debugging in mind (avoid duplicating code, put conceptually
27649 similar variables into structs, use structured code, have strategic points
27650 within your code where all variables are consistent, ...)
27653 \begin_layout Itemize
27654 run a syntax-checking tool like splint
27655 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27660 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27668 \begin_layout Standard
27678 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27685 \begin_layout Itemize
27686 for the high level code use a C-compiler (like f.e.
27687 GCC) to compile run and debug the code on your host.
27692 \begin_layout Standard
27702 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27706 ) on how to handle syntax extensions like __xdata, __at(), ...
27710 \begin_layout Itemize
27711 use another C-compiler to compile code for your target.
27712 Always an option but not recommended:) And not very likely to help you.
27713 If you seriously consider walking this path you should at least occasionally
27714 check portability of your code.
27715 Most commercial compiler vendors will offer an evaluation version so you
27716 can test compile your code or snippets of your code.
27719 \begin_layout Standard
27720 Debugging on a simulator:
27723 \begin_layout Itemize
27724 there is a separate section about SDCDB (section
27725 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27732 \begin_layout Itemize
27733 or (8051 specific) use a freeware/commercial simulator which interfaces
27735 \begin_inset LatexCommand \index{AOMF, AOMF51}
27740 \begin_inset LatexCommand \ref{OMF file}
27744 ) optionally generated by SDCC.
27747 \begin_layout Standard
27748 Debugging On-target:
27751 \begin_layout Itemize
27752 use a MCU port pin to serially output debug data to the RS232 port of your
27754 You'll probably want some level shifting device typically involving a MAX232
27756 If the hardware serial port of the MCU is not available search for 'Software
27757 UART' in your favourite search machine.
27760 \begin_layout Itemize
27761 use an on-target monitor.
27762 In this context a monitor is a small program which usually accepts commands
27763 via a serial line and allows to set program counter, to single step through
27764 a program and read/write memory locations.
27765 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27767 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27774 \begin_layout Itemize
27775 toggle MCU port pins at strategic points within your code and use an oscilloscop
27779 digital oscilloscope
27782 \begin_inset LatexCommand \index{Oscilloscope}
27786 with deep trace memory is really helpful especially if you have to debug
27787 a realtime application.
27788 If you need to monitor more pins than your oscilloscope provides you can
27789 sometimes get away with a small R-2R network.
27790 On a single channel oscilloscope you could f.e.
27791 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27793 \begin_inset Formula $\Omega$
27796 resistor and the other one by a 5\InsetSpace ~
27798 \begin_inset Formula $\Omega$
27801 resistor to the oscilloscope probe (check output drive capability of the
27802 pins you want to monitor).
27803 If you need to monitor many more pins a
27810 \begin_layout Itemize
27824 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27829 Usually very expensive.
27830 And very nice to have too.
27831 And usually locks you (for years...) to the devices the ICE can emulate.
27835 \begin_layout Itemize
27836 use a remote debugger.
27837 In most 8-bit systems the symbol information is not available on the target,
27838 and a complete debugger is too bulky for the target system.
27839 Therefore usually a debugger on the host system connects to an on-target
27840 debugging stub which accepts only primitive commands.
27843 Terms to enter into your favourite search engine could be 'remote debugging',
27844 'gdb stub' or 'inferior debugger'.
27848 \begin_layout Itemize
27849 use an on target hardware debugger.
27850 Some of the more modern MCUs include hardware support for setting break
27851 points and monitoring/changing variables by using dedicated hardware pins.
27852 This facility doesn't require additional code to run on the target and
27857 doesn't affect runtime behaviour until a breakpoint is hit.
27858 For the mcs51 most hardware debuggers use the AOMF
27859 \begin_inset LatexCommand \index{AOMF, AOMF51}
27864 \begin_inset LatexCommand \ref{OMF file}
27872 \begin_layout Standard
27876 \begin_layout Itemize
27877 if you are not familiar with any of the following terms you're likely to
27878 run into problems rather sooner than later:
27895 As an embedded programmer you
27899 to know them so why not look them up
27903 you have problems?)
27906 \begin_layout Itemize
27907 tell someone else about your problem (actually this is a surprisingly effective
27908 means to hunt down the bug even if the listener is not familiar with your
27910 As 'failure to communicate' is probably one of the job-induced deformations
27911 of an embedded programmer this is highly encouraged.
27914 \begin_layout Section
27915 Debugging with SDCDB
27916 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27921 \begin_inset LatexCommand \index{SDCDB (debugger)}
27928 \begin_layout Standard
27929 SDCC is distributed with a source level debugger
27930 \begin_inset LatexCommand \index{Debugger}
27935 The debugger uses a command line interface, the command repertoire of the
27936 debugger has been kept as close to gdb
27937 \begin_inset LatexCommand \index{gdb}
27941 (the GNU debugger) as possible.
27942 The configuration and build process is part of the standard compiler installati
27943 on, which also builds and installs the debugger in the target directory
27944 specified during configuration.
27945 The debugger allows you debug BOTH at the C source and at the ASM source
27949 \begin_layout Subsection
27950 Compiling for Debugging
27953 \begin_layout Standard
27958 \begin_layout Standard
27968 \begin_inset LatexCommand \index{-\/-debug}
27972 option must be specified for all files for which debug information is to
27974 The compiler generates a .adb file for each of these files.
27975 The linker creates the .cdb
27976 \begin_inset LatexCommand \index{<file>.cdb}
27981 \begin_inset LatexCommand \index{<file>.adb}
27985 files and the address information.
27986 This .cdb is used by the debugger.
27989 \begin_layout Subsection
27990 How the Debugger Works
27993 \begin_layout Standard
27998 \begin_layout Standard
28007 -debug option is specified the compiler generates extra symbol information
28008 some of which are put into the assembler source and some are put into the
28010 Then the linker creates the .cdb file from the individual .adb files with
28011 the address information for the symbols.
28012 The debugger reads the symbolic information generated by the compiler &
28013 the address information generated by the linker.
28014 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28015 execution is controlled by the debugger.
28016 When a command is issued for the debugger, it translates it into appropriate
28017 commands for the simulator.
28018 (Currently SDCDM only connects to the simulator but
28023 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28027 is an effort to connect directly to the hardware.)
28030 \begin_layout Subsection
28031 Starting the Debugger SDCDB
28034 \begin_layout Standard
28035 The debugger can be started using the following command line.
28036 (Assume the file you are debugging has the file name foo).
28050 The debugger will look for the following files.
28053 \begin_layout Itemize
28054 foo.c - the source file.
28057 \begin_layout Itemize
28058 foo.cdb - the debugger symbol information file.
28061 \begin_layout Itemize
28062 foo.ihx - the Intel hex format
28063 \begin_inset LatexCommand \index{Intel hex format}
28070 \begin_layout Subsection
28071 SDCDB Command Line Options
28074 \begin_layout Itemize
28079 \begin_layout Standard
28088 -directory=<source file directory> this option can used to specify the directory
28090 The debugger will look into the directory list specified for source, cdb
28092 The items in the directory list must be separated by ':', e.g.
28093 if the source files can be in the directories /home/src1 and /home/src2,
28098 \begin_layout Standard
28107 -directory option should be -
28111 \begin_layout Standard
28120 -directory=/home/src1:/home/src2.
28121 Note there can be no spaces in the option.
28125 \begin_layout Itemize
28126 -cd <directory> - change to the <directory>.
28129 \begin_layout Itemize
28130 -fullname - used by GUI front ends.
28133 \begin_layout Itemize
28134 -cpu <cpu-type> - this argument is passed to the simulator please see the
28135 simulator docs for details.
28138 \begin_layout Itemize
28139 -X <Clock frequency > this options is passed to the simulator please see
28140 the simulator docs for details.
28143 \begin_layout Itemize
28144 -s <serial port file> passed to simulator see the simulator docs for details.
28147 \begin_layout Itemize
28148 -S <serial in,out> passed to simulator see the simulator docs for details.
28151 \begin_layout Itemize
28152 -k <port number> passed to simulator see the simulator docs for details.
28155 \begin_layout Subsection
28156 SDCDB Debugger Commands
28159 \begin_layout Standard
28160 As mentioned earlier the command interface for the debugger has been deliberatel
28161 y kept as close the GNU debugger gdb, as possible.
28162 This will help the integration with existing graphical user interfaces
28163 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28164 If you use a graphical user interface for the debugger you can skip this
28168 \begin_layout Subsubsection*
28169 break [line | file:line | function | file:function]
28172 \begin_layout Standard
28173 Set breakpoint at specified line or function:
28182 sdcdb>break foo.c:100
28184 sdcdb>break funcfoo
28186 sdcdb>break foo.c:funcfoo
28189 \begin_layout Subsubsection*
28190 clear [line | file:line | function | file:function ]
28193 \begin_layout Standard
28194 Clear breakpoint at specified line or function:
28203 sdcdb>clear foo.c:100
28205 sdcdb>clear funcfoo
28207 sdcdb>clear foo.c:funcfoo
28210 \begin_layout Subsubsection*
28214 \begin_layout Standard
28215 Continue program being debugged, after breakpoint.
28218 \begin_layout Subsubsection*
28222 \begin_layout Standard
28223 Execute till the end of the current function.
28226 \begin_layout Subsubsection*
28230 \begin_layout Standard
28231 Delete breakpoint number 'n'.
28232 If used without any option clear ALL user defined break points.
28235 \begin_layout Subsubsection*
28236 info [break | stack | frame | registers ]
28239 \begin_layout Itemize
28240 info break - list all breakpoints
28243 \begin_layout Itemize
28244 info stack - show the function call stack.
28247 \begin_layout Itemize
28248 info frame - show information about the current execution frame.
28251 \begin_layout Itemize
28252 info registers - show content of all registers.
28255 \begin_layout Subsubsection*
28259 \begin_layout Standard
28260 Step program until it reaches a different source line.
28261 Note: pressing <return> repeats the last command.
28264 \begin_layout Subsubsection*
28268 \begin_layout Standard
28269 Step program, proceeding through subroutine calls.
28272 \begin_layout Subsubsection*
28276 \begin_layout Standard
28277 Start debugged program.
28280 \begin_layout Subsubsection*
28284 \begin_layout Standard
28285 Print type information of the variable.
28288 \begin_layout Subsubsection*
28292 \begin_layout Standard
28293 print value of variable.
28296 \begin_layout Subsubsection*
28300 \begin_layout Standard
28301 load the given file name.
28302 Note this is an alternate method of loading file for debugging.
28305 \begin_layout Subsubsection*
28309 \begin_layout Standard
28310 print information about current frame.
28313 \begin_layout Subsubsection*
28317 \begin_layout Standard
28318 Toggle between C source & assembly source.
28321 \begin_layout Subsubsection*
28322 ! simulator command
28325 \begin_layout Standard
28326 Send the string following '!' to the simulator, the simulator response is
28328 Note the debugger does not interpret the command being sent to the simulator,
28329 so if a command like 'go' is sent the debugger can loose its execution
28330 context and may display incorrect values.
28333 \begin_layout Subsubsection*
28337 \begin_layout Standard
28340 My name is Bobby Brown"
28343 \begin_layout Subsection
28344 Interfacing SDCDB with DDD
28347 \begin_layout Standard
28348 \begin_inset Note Note
28351 \begin_layout Standard
28352 The screenshot was converted from png to eps with:
28353 \begin_inset Quotes sld
28356 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28357 \begin_inset Quotes srd
28360 which produces a pretty compact eps file which is free from compression
28364 \begin_layout Standard
28365 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28366 as this broke the build system on Sourceforge (pdf-file was broken.
28367 pdflatex does not accept eps files).
28375 \begin_layout Standard
28391 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28397 shows a screenshot of a debugging session with DDD
28398 \begin_inset LatexCommand \index{DDD (debugger)}
28402 (Unix only) on a simulated 8032.
28403 The debugging session might not run as smoothly as the screenshot suggests.
28404 The debugger allows setting of breakpoints, displaying and changing variables,
28405 single stepping through C and assembler code.
28408 The source was compiled with
28422 \begin_layout Standard
28434 -debug ddd_example.c
28447 and DDD was invoked with
28454 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28457 \begin_layout Standard
28458 \begin_inset Note Note
28461 \begin_layout Standard
28462 Check that the double quotes or an apostroph within the command line survive
28463 the LyX tool chain.
28464 Previously the apostrophs got slanted in the PDF output so a cut and paste
28473 \begin_layout Subsection
28474 Interfacing SDCDB with XEmacs
28475 \begin_inset LatexCommand \index{XEmacs}
28480 \begin_inset LatexCommand \index{Emacs}
28487 \begin_layout Standard
28488 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28489 sdcdb.el and sdcdbsrc.el.
28490 These two files can be found in the $(prefix)/bin directory after the installat
28492 These files need to be loaded into XEmacs for the interface to work.
28493 This can be done at XEmacs startup time by inserting the following into
28494 your '.xemacs' file (which can be found in your HOME directory):
28500 (load-file sdcdbsrc.el)
28506 .xemacs is a lisp file so the () around the command is REQUIRED.
28507 The files can also be loaded dynamically while XEmacs is running, set the
28508 environment variable 'EMACSLOADPATH' to the installation bin directory
28509 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28510 To start the interface enter the following command:
28524 You will prompted to enter the file name to be debugged.
28529 The command line options that are passed to the simulator directly are
28530 bound to default values in the file sdcdbsrc.el.
28531 The variables are listed below, these values maybe changed as required.
28534 \begin_layout Itemize
28535 sdcdbsrc-cpu-type '51
28538 \begin_layout Itemize
28539 sdcdbsrc-frequency '11059200
28542 \begin_layout Itemize
28543 sdcdbsrc-serial nil
28546 \begin_layout Standard
28547 The following is a list of key mapping for the debugger interface.
28550 \begin_layout Standard
28573 binding\InsetSpace ~
28611 -------\InsetSpace ~
28682 sdcdb-back-from-src\InsetSpace ~
28711 rom-src\InsetSpace ~
28721 SDCDB continue command
28739 sdcdb-step-from-src\InsetSpace ~
28768 hatis-c-sexp\InsetSpace ~
28778 SDCDB ptypecommand for data at
28845 sdcdbsrc-delete\InsetSpace ~
28860 B Delete all breakpoints if no arg
28909 given or delete arg (C-u arg x)
28928 -frame\InsetSpace ~
28943 SDCDB Display current frame if no arg,
28992 given or display frame arg
29060 sdcdbsrc-goto-sdcdb\InsetSpace ~
29070 Goto the SDCDB output buffer
29089 t-c-sexp\InsetSpace ~
29100 SDCDB print command for data at
29167 sdcdbsrc-goto-sdcdb\InsetSpace ~
29178 o the SDCDB output buffer
29196 sdcdbsrc-mode\InsetSpace ~
29212 Toggles Sdcdbsrc mode (turns it
29228 sdcdb-finish-from-src\InsetSpace ~
29236 SDCDB finish command
29270 Set break for line with point
29285 sdcdbsrc-mode\InsetSpace ~
29301 Toggle Sdcdbsrc mode
29317 dbsrc-srcmode\InsetSpace ~
29341 \begin_layout Chapter
29345 \begin_layout Standard
29346 Here are a few guidelines that will help the compiler generate more efficient
29347 code, some of the tips are specific to this compiler others are generally
29348 good programming practice.
29351 \begin_layout Itemize
29352 Use the smallest data type to represent your data-value.
29353 If it is known in advance that the value is going to be less than 256 then
29354 use an 'unsigned char' instead of a 'short' or 'int'.
29355 Please note, that ANSI C requires both signed and unsigned chars to be
29356 promoted to 'signed int'
29357 \begin_inset LatexCommand \index{promotion to signed int}
29362 \begin_inset Marginal
29365 \begin_layout Standard
29374 before doing any operation.
29376 \begin_inset LatexCommand \index{type promotion}
29381 \begin_inset LatexCommand \label{type promotion}
29385 can be omitted, if the result is the same.
29386 The effect of the promotion rules together with the sign-extension is often
29391 \begin_layout Verse
29394 unsigned char uc = 0xfe;
29396 if (uc * uc < 0) /* this is true! */
29409 \begin_layout Standard
29416 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29424 \begin_layout Verse
29427 (unsigned char) -12 / (signed char) -3 = ...
29430 \begin_layout Standard
29431 No, the result is not 4:
29434 \begin_layout Verse
29437 (int) (unsigned char) -12 / (int) (signed char) -3 =
29439 (int) (unsigned char)
29440 0xf4 / (int) (signed char) 0xfd =
29442 (int) 0x00f4 / (int) 0xfffd =
29447 (int) 244 / (int) -3 =
29449 (int) -81 = (int) 0xffaf;
29452 \begin_layout Standard
29453 Don't complain, that gcc gives you a different result.
29454 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29455 Therefore the results are different.
29458 \begin_inset Quotes sld
29462 \begin_inset Quotes srd
29468 \begin_layout Quote
29471 If well-defined overflow characteristics are important and negative values
29472 are not, or if you want to steer clear of sign-extension problems when
29473 manipulating bits or bytes, use one of the corresponding unsigned types.
29474 (Beware when mixing signed and unsigned values in expressions, though.)
29477 character types (especially unsigned char) can be used as "tiny" integers,
29478 doing so is sometimes more trouble than it's worth, due to unpredictable
29479 sign extension and increased code size.
29483 \begin_layout Itemize
29484 Use unsigned when it is known in advance that the value is not going to
29486 This helps especially if you are doing division or multiplication, bit-shifting
29487 or are using an array index.
29490 \begin_layout Itemize
29491 NEVER jump into a LOOP.
29494 \begin_layout Itemize
29495 Declare the variables to be local
29496 \begin_inset LatexCommand \index{local variables}
29500 whenever possible, especially loop control variables (induction).
29503 \begin_layout Itemize
29504 Have a look at the assembly listing to get a
29505 \begin_inset Quotes sld
29509 \begin_inset Quotes srd
29512 for the code generation.
29515 \begin_layout Section
29516 Porting code from or to other compilers
29517 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29524 \begin_layout Itemize
29525 check whether endianness of the compilers differs and adapt where needed.
29528 \begin_layout Itemize
29529 check the device specific header files
29530 \begin_inset LatexCommand \index{Header files}
29535 \begin_inset LatexCommand \index{Include files}
29539 for compiler specific syntax.
29540 Eventually include the file <compiler.h
29541 \begin_inset LatexCommand \index{compiler.h (include file)}
29546 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29550 to allow using common header files.
29553 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29560 \begin_layout Itemize
29561 check whether the startup code contains the correct initialization (watchdog,
29565 \begin_layout Itemize
29566 check whether the sizes of short, int, long match.
29569 \begin_layout Itemize
29570 check if some 16 or 32 bit hardware registers require a specific addressing
29571 order (least significant or most significant byte first) and adapt if needed
29580 relate to time and not to lower/upper memory location here, so this is
29585 the same as endianness).
29588 \begin_layout Itemize
29589 check whether the keyword
29593 is used where needed.
29594 The compilers might differ in their optimization characteristics (as different
29595 versions of the same compiler might also use more clever optimizations
29596 this is good idea anyway).
29598 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29605 \begin_layout Itemize
29606 check that the compilers are not told to supress warnings.
29609 \begin_layout Itemize
29610 check and convert compiler specific extensions (interrupts, memory areas,
29614 \begin_layout Itemize
29615 check for differences in type promotion.
29616 Especially check for math operations on
29625 For the sake of C99 compatibility SDCC will probably promote these to
29629 more often than other compilers.
29630 Eventually insert explicit casts to
29639 Also check that the ~\InsetSpace ~
29641 \begin_inset LatexCommand \index{\~\/ Operator}
29648 \begin_inset LatexCommand \index{bit}
29654 variables, use the !\InsetSpace ~
29657 \begin_inset LatexCommand \ref{type promotion}
29662 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29669 \begin_layout Itemize
29670 check the assembly code generated for interrupt routines (f.e.
29671 for calls to possibly non-reentrant library functions).
29674 \begin_layout Itemize
29675 check whether timing loops result in proper timing (or preferably consider
29676 a rewrite of the code with timer based delays instead).
29679 \begin_layout Itemize
29680 check for differences in printf parameters (some compilers push (va_arg
29681 \begin_inset LatexCommand \index{vararg, va\_arg}
29685 ) char variables as
29689 others push them as
29695 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29702 \begin_layout Itemize
29703 check the resulting memory map
29704 \begin_inset LatexCommand \index{Memory map}
29709 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29710 ly idata, pdata, xdata).
29711 Eventually check if unexpected library functions are included.
29714 \begin_layout Section
29716 \begin_inset LatexCommand \index{Tools}
29720 included in the distribution
29723 \begin_layout Standard
29725 \begin_inset Tabular
29726 <lyxtabular version="3" rows="12" columns="3">
29728 <column alignment="left" valignment="top" leftline="true" width="0pt">
29729 <column alignment="left" valignment="top" leftline="true" width="0pt">
29730 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29731 <row topline="true" bottomline="true">
29732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29735 \begin_layout Standard
29743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29746 \begin_layout Standard
29754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29757 \begin_layout Standard
29766 <row topline="true">
29767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29770 \begin_layout Standard
29772 \begin_inset LatexCommand \index{uCsim}
29781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29784 \begin_layout Standard
29785 Simulator for various architectures
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29793 \begin_layout Standard
29800 <row topline="true">
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29804 \begin_layout Standard
29810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29813 \begin_layout Standard
29815 \begin_inset LatexCommand \index{Header files}
29820 \begin_inset LatexCommand \index{Include files}
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29832 \begin_layout Standard
29833 sdcc/support/scripts
29839 <row topline="true">
29840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29843 \begin_layout Standard
29849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29852 \begin_layout Standard
29853 header file conversion
29858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29861 \begin_layout Standard
29862 sdcc/support/scripts
29868 <row topline="true">
29869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29872 \begin_layout Standard
29878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29881 \begin_layout Standard
29887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29890 \begin_layout Standard
29906 <row topline="true">
29907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29910 \begin_layout Standard
29916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29919 \begin_layout Standard
29925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29928 \begin_layout Standard
29944 <row topline="true">
29945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29948 \begin_layout Standard
29954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29957 \begin_layout Standard
29963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29966 \begin_layout Standard
29982 <row topline="true">
29983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29986 \begin_layout Standard
29992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29995 \begin_layout Standard
30001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30004 \begin_layout Standard
30020 <row topline="true">
30021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30024 \begin_layout Standard
30030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30033 \begin_layout Standard
30039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30042 \begin_layout Standard
30058 <row topline="true">
30059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30062 \begin_layout Standard
30068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30071 \begin_layout Standard
30077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30080 \begin_layout Standard
30096 <row topline="true">
30097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30100 \begin_layout Standard
30106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30109 \begin_layout Standard
30115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30118 \begin_layout Standard
30134 <row topline="true" bottomline="true">
30135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30138 \begin_layout Standard
30144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30147 \begin_layout Standard
30149 \begin_inset LatexCommand \index{packihx (tool)}
30158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30161 \begin_layout Standard
30186 \begin_layout Section
30188 \begin_inset LatexCommand \index{Documentation}
30192 included in the distribution
30195 \begin_layout Standard
30197 \begin_inset Tabular
30198 <lyxtabular version="3" rows="10" columns="2">
30200 <column alignment="block" valignment="top" leftline="true" width="40col%">
30201 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30202 <row topline="true" bottomline="true" endhead="true">
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30206 \begin_layout Standard
30214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30217 \begin_layout Standard
30220 Filename / Where to get
30226 <row topline="true">
30227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30230 \begin_layout Standard
30231 SDCC Compiler User Guide
30236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30239 \begin_layout Standard
30240 You're reading it right now
30252 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30262 <row topline="true">
30263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30266 \begin_layout Standard
30272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30275 \begin_layout Standard
30288 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30298 <row topline="true">
30299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30302 \begin_layout Standard
30304 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30309 \begin_inset LatexCommand \index{Assembler documentation}
30316 \begin_inset LatexCommand \index{aslink}
30321 \begin_inset LatexCommand \index{Linker documentation}
30330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30333 \begin_layout Standard
30334 sdcc/as/doc/asxhtm.html
30346 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30356 <row topline="true">
30357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30360 \begin_layout Standard
30361 SDCC regression test
30362 \begin_inset LatexCommand \index{Regression test}
30371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30374 \begin_layout Standard
30375 sdcc/doc/test_suite_spec.pdf
30387 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30397 <row topline="true">
30398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30401 \begin_layout Standard
30407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30410 \begin_layout Standard
30423 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30433 <row topline="true">
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30437 \begin_layout Standard
30438 Notes on debugging with SDCDB
30439 \begin_inset LatexCommand \index{SDCDB (debugger)}
30448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30451 \begin_layout Standard
30452 sdcc/debugger/README
30464 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30474 <row topline="true">
30475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30478 \begin_layout Standard
30480 \begin_inset LatexCommand \index{uCsim}
30484 Software simulator for microcontrollers
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30492 \begin_layout Standard
30522 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30532 <row topline="true">
30533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30536 \begin_layout Standard
30537 Temporary notes on the pic16
30538 \begin_inset LatexCommand \index{PIC16}
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30550 \begin_layout Standard
30551 sdcc/src/pic16/NOTES
30563 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30573 <row topline="true" bottomline="true">
30574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30577 \begin_layout Standard
30578 SDCC internal documentation (debugging file format)
30583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30586 \begin_layout Standard
30616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30635 \begin_layout Section
30636 Related open source tools
30637 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30642 \begin_inset LatexCommand \index{Related tools}
30649 \begin_layout Standard
30651 \begin_inset Tabular
30652 <lyxtabular version="3" rows="14" columns="3">
30654 <column alignment="left" valignment="top" leftline="true" width="0pt">
30655 <column alignment="block" valignment="top" leftline="true" width="30line%">
30656 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30657 <row topline="true" bottomline="true">
30658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30661 \begin_layout Standard
30669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30672 \begin_layout Standard
30680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30683 \begin_layout Standard
30692 <row topline="true">
30693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30696 \begin_layout Standard
30698 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30710 \begin_layout Standard
30716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30719 \begin_layout Standard
30720 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30730 <row topline="true">
30731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30734 \begin_layout Standard
30736 \begin_inset LatexCommand \index{gputils (pic tools)}
30745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30748 \begin_layout Standard
30754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30757 \begin_layout Standard
30758 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30768 <row topline="true">
30769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30772 \begin_layout Standard
30778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30781 \begin_layout Standard
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30790 \begin_layout Standard
30791 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30801 <row topline="true">
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30805 \begin_layout Standard
30811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30814 \begin_layout Standard
30815 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30824 \begin_layout Standard
30825 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30835 <row topline="true">
30836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30839 \begin_layout Standard
30841 \begin_inset LatexCommand \index{indent (source formatting tool)}
30850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30853 \begin_layout Standard
30854 Formats C source - Master of the white spaces
30859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30862 \begin_layout Standard
30863 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30873 <row topline="true">
30874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30877 \begin_layout Standard
30879 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30891 \begin_layout Standard
30892 Object file conversion, checksumming, ...
30897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30900 \begin_layout Standard
30901 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30911 <row topline="true">
30912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30915 \begin_layout Standard
30917 \begin_inset LatexCommand \index{objdump (tool)}
30926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30929 \begin_layout Standard
30930 Object file conversion, ...
30935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30938 \begin_layout Standard
30939 Part of binutils (should be there anyway)
30945 <row topline="true">
30946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30949 \begin_layout Standard
30955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30958 \begin_layout Standard
30959 8051 monitor (hex up-/download, single step, disassemble)
30964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30967 \begin_layout Standard
30968 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30978 <row topline="true">
30979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30982 \begin_layout Standard
30984 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30996 \begin_layout Standard
30997 Source code documentation system
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31005 \begin_layout Standard
31006 \begin_inset LatexCommand \url{http://www.doxygen.org}
31016 <row topline="true">
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31020 \begin_layout Standard
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31029 \begin_layout Standard
31030 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31038 \begin_layout Standard
31039 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31049 <row topline="true">
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31053 \begin_layout Standard
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_layout Standard
31063 8051 monitor (hex up-/download, single step, disassemble)
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_layout Standard
31072 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31082 <row topline="true">
31083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31086 \begin_layout Standard
31088 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_layout Standard
31101 Statically checks c sources (see
31102 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31114 \begin_layout Standard
31115 \begin_inset LatexCommand \url{http://www.splint.org}
31125 <row topline="true" bottomline="true">
31126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31129 \begin_layout Standard
31131 \begin_inset LatexCommand \index{DDD (debugger)}
31140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31143 \begin_layout Standard
31144 Debugger, serves nicely as GUI to SDCDB
31145 \begin_inset LatexCommand \index{SDCDB (debugger)}
31154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31157 \begin_layout Standard
31158 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31177 \begin_layout Section
31178 Related documentation / recommended reading
31181 \begin_layout Standard
31183 \begin_inset Tabular
31184 <lyxtabular version="3" rows="7" columns="3">
31186 <column alignment="left" valignment="top" leftline="true" width="0pt">
31187 <column alignment="left" valignment="top" leftline="true" width="0">
31188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31189 <row topline="true" bottomline="true">
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31193 \begin_layout Standard
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31204 \begin_layout Standard
31212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31215 \begin_layout Standard
31224 <row topline="true">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_layout Standard
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31246 \begin_layout Standard
31248 \begin_inset LatexCommand \index{C Reference card}
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31260 \begin_layout Standard
31261 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31271 <row topline="true">
31272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31275 \begin_layout Standard
31281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31284 \begin_layout Standard
31286 \begin_inset LatexCommand \index{C FAQ}
31295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31298 \begin_layout Standard
31299 \begin_inset LatexCommand \url{http://www.c-faq.com}
31309 <row topline="true">
31310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31313 \begin_layout Standard
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31322 \begin_layout Standard
31323 \begin_inset Quotes sld
31327 \begin_inset Quotes srd
31335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31338 \begin_layout Standard
31341 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31351 <row topline="true">
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31355 \begin_layout Standard
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31364 \begin_layout Standard
31365 \begin_inset Quotes sld
31368 Extensions for Embedded C
31369 \begin_inset Quotes srd
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31380 \begin_layout Standard
31383 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31393 <row topline="true">
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31397 \begin_layout Standard
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31406 \begin_layout Standard
31407 Latest datasheet of target CPU
31412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31415 \begin_layout Standard
31422 <row topline="true" bottomline="true">
31423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31426 \begin_layout Standard
31432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31435 \begin_layout Standard
31436 Revision history of datasheet
31441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31444 \begin_layout Standard
31460 \begin_layout Section
31461 Application notes specifically for SDCC
31464 \begin_layout Standard
31465 SDCC makes no claims about the completeness of this list and about up-to-datenes
31466 s or correctness of the application notes
31467 \begin_inset LatexCommand \index{Application notes}
31474 \begin_layout Standard
31478 \begin_inset Tabular
31479 <lyxtabular version="3" rows="7" columns="3">
31481 <column alignment="block" valignment="top" leftline="true" width="17col%">
31482 <column alignment="block" valignment="top" leftline="true" width="27col%">
31483 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31484 <row topline="true" bottomline="true">
31485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_layout Standard
31497 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31500 \begin_layout Standard
31509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31512 \begin_layout Standard
31522 <row topline="true">
31523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31526 \begin_layout Standard
31534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31537 \begin_layout Standard
31540 Using the SDCC Compiler for the DS80C400
31541 \begin_inset LatexCommand \index{DS80C400}
31550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31553 \begin_layout Standard
31556 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31566 <row topline="true">
31567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31570 \begin_layout Standard
31578 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31581 \begin_layout Standard
31584 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31585 \begin_inset LatexCommand \index{DS89C4x0}
31589 Family of Microcontrollers
31594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31597 \begin_layout Standard
31600 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31610 <row topline="true">
31611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31614 \begin_layout Standard
31617 Silicon Laboratories / Cygnal
31622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31625 \begin_layout Standard
31628 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31629 \begin_inset LatexCommand \index{IDE}
31638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31641 \begin_layout Standard
31644 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31654 <row topline="true">
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31658 \begin_layout Standard
31661 Ramtron / Goal Semiconductor
31666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31669 \begin_layout Standard
31672 Interfacing SDCC to Syn and Textpad
31677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31680 \begin_layout Standard
31683 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31693 <row topline="true">
31694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31697 \begin_layout Standard
31700 Ramtron / Goal Semiconductor
31705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31708 \begin_layout Standard
31711 Installing and Configuring SDCC and Crimson Editor
31716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31719 \begin_layout Standard
31722 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31732 <row topline="true" bottomline="true">
31733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31736 \begin_layout Standard
31744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31747 \begin_layout Standard
31750 MSC12xx Programming with SDCC
31755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31758 \begin_layout Standard
31761 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31778 \begin_layout Section
31782 \begin_layout Standard
31783 Some questions answered, some pointers given - it might be time to in turn
31791 \begin_layout Itemize
31792 can you solve your project with the selected microcontroller? Would you
31793 find out early or rather late that your target is too small/slow/whatever?
31794 Can you switch to a slightly better device if it doesn't fit?
31797 \begin_layout Itemize
31798 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31799 and/or another programming language be more adequate? Would an operating
31800 system on the target device help?
31803 \begin_layout Itemize
31804 if you solved the problem, will the marketing department be happy?
31807 \begin_layout Itemize
31808 if the marketing department is happy, will customers be happy?
31811 \begin_layout Itemize
31812 if you're the project manager, marketing department and maybe even the customer
31813 in one person, have you tried to see the project from the outside?
31816 \begin_layout Itemize
31817 is the project done if you think it is done? Or is just that other interface/pro
31818 tocol/feature/configuration/option missing? How about website, manual(s),
31819 internationali(z|s)ation, packaging, labels, 2nd source for components,
31820 electromagnetic compatability/interference, documentation for production,
31821 production test software, update mechanism, patent issues?
31824 \begin_layout Itemize
31825 is your project adequately positioned in that magic triangle: fame, fortune,
31829 \begin_layout Standard
31830 Maybe not all answers to these questions are known and some answers may
31835 , nevertheless knowing these questions may help you to avoid burnout
31839 \begin_layout Standard
31840 burnout is bad for electronic devices, programmers and motorcycle tyres
31846 Chances are you didn't want to hear some of them...
31849 \begin_layout Chapter
31851 \begin_inset LatexCommand \index{Support}
31858 \begin_layout Standard
31859 SDCC has grown to be a large project.
31860 The compiler alone (without the preprocessor, assembler and linker) is
31861 well over 150,000 lines of code (blank stripped).
31862 The open source nature of this project is a key to its continued growth
31864 You gain the benefit and support of many active software developers and
31866 Is SDCC perfect? No, that's why we need your help.
31867 The developers take pride in fixing reported bugs.
31868 You can help by reporting the bugs and helping other SDCC users.
31869 There are lots of ways to contribute, and we encourage you to take part
31870 in making SDCC a great software package.
31874 \begin_layout Standard
31875 The SDCC project is hosted on the SDCC sourceforge site at
31876 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31881 You'll find the complete set of mailing lists
31882 \begin_inset LatexCommand \index{Mailing list(s)}
31886 , forums, bug reporting system, patch submission
31887 \begin_inset LatexCommand \index{Patch submission}
31892 \begin_inset LatexCommand \index{download}
31896 area and Subversion code repository
31897 \begin_inset LatexCommand \index{Subversion code repository}
31904 \begin_layout Section
31906 \begin_inset LatexCommand \index{Bug reporting}
31911 \begin_inset LatexCommand \index{Reporting bugs}
31918 \begin_layout Standard
31919 The recommended way of reporting bugs is using the infrastructure of the
31921 You can follow the status of bug reports there and have an overview about
31925 \begin_layout Standard
31926 Bug reports are automatically forwarded to the developer mailing list and
31927 will be fixed ASAP.
31928 When reporting a bug, it is very useful to include a small test program
31929 (the smaller the better) which reproduces the problem.
31930 If you can isolate the problem by looking at the generated assembly code,
31931 this can be very helpful.
31932 Compiling your program with the -
31936 \begin_layout Standard
31946 \begin_inset LatexCommand \index{-\/-dumpall}
31950 option can sometimes be useful in locating optimization problems.
31951 When reporting a bug please make sure you:
31954 \begin_layout Enumerate
31955 Attach the code you are compiling with SDCC.
31959 \begin_layout Enumerate
31960 Specify the exact command you use to run SDCC, or attach your Makefile.
31964 \begin_layout Enumerate
31965 Specify the SDCC version (type "
31971 "), your platform, and operating system.
31975 \begin_layout Enumerate
31976 Provide an exact copy of any error message or incorrect output.
31980 \begin_layout Enumerate
31981 Put something meaningful in the subject of your message.
31984 \begin_layout Standard
31985 Please attempt to include these 5 important parts, as applicable, in all
31986 requests for support or when reporting any problems or bugs with SDCC.
31987 Though this will make your message lengthy, it will greatly improve your
31988 chance that SDCC users and developers will be able to help you.
31989 Some SDCC developers are frustrated by bug reports without code provided
31990 that they can use to reproduce and ultimately fix the problem, so please
31991 be sure to provide sample code if you are reporting a bug!
31994 \begin_layout Standard
31995 Please have a short check that you are using a recent version of SDCC and
31996 the bug is not yet known.
31997 This is the link for reporting bugs:
31998 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32003 With SDCC on average having more than 200 downloads
32004 \begin_inset LatexCommand \index{download}
32008 on sourceforge per day
32012 \begin_layout Standard
32013 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32014 between 2002 and 2005.
32015 This does not include other methods of distribution.
32020 there must be some users.
32021 So it's not exactly easy to find a new bug.
32022 If you find one we need it:
32024 reporting bugs is good
32029 \begin_layout Section
32030 Requesting Features
32031 \begin_inset LatexCommand \label{sub:Requesting-Features}
32036 \begin_inset LatexCommand \index{Feature request}
32041 \begin_inset LatexCommand \index{Requesting features}
32048 \begin_layout Standard
32049 Like bug reports feature requests are forwarded to the developer mailing
32051 This is the link for requesting features:
32052 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32059 \begin_layout Section
32063 \begin_layout Standard
32064 Like bug reports contributed patches are forwarded to the developer mailing
32066 This is the link for submitting patches
32067 \begin_inset LatexCommand \index{Patch submission}
32072 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32079 \begin_layout Standard
32080 You need to specify some parameters to the
32084 command for the patches to be useful.
32085 If you modified more than one file a patch created f.e.
32090 \begin_inset Quotes sld
32093 diff -Naur unmodified_directory modified_directory >my_changes.patch
32094 \begin_inset Quotes srd
32100 will be fine, otherwise
32104 \begin_inset Quotes sld
32107 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32108 \begin_inset Quotes srd
32118 \begin_layout Section
32122 \begin_layout Standard
32123 These links should take you directly to the
32124 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32132 \begin_layout Standard
32133 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32134 automated messages (mid 2003)
32140 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32145 \begin_inset LatexCommand \index{Mailing list(s)}
32149 and forums are archived and searchable so if you are lucky someone already
32150 had a similar problem.
32151 While mails to the lists themselves are delivered promptly their web front
32152 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32153 if you're seriously using SDCC please consider subscribing to the lists.
32156 \begin_layout Section
32160 \begin_layout Standard
32161 You can follow the status of the Subversion version
32162 \begin_inset LatexCommand \index{version}
32166 of SDCC by watching the Changelog
32167 \begin_inset LatexCommand \index{Changelog}
32171 in the Subversion repository
32174 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32181 \begin_layout Section
32182 Subversion Source Code Repository
32185 \begin_layout Standard
32192 or the filenames of the snapshot versions of SDCC include date and its
32194 \begin_inset LatexCommand \index{Subversion code repository}
32199 Subversion allows to download the source of recent or previous versions
32201 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32205 (by number or by date).
32206 An on-line source code browser and detailled instructions are also available
32208 SDCC versions starting from 1999 up to now are available (currently the
32209 versions prior to the conversion from cvs
32210 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32214 to Subversion (April 2006) are either by accessible by Subversion or by
32218 \begin_layout Section
32220 \begin_inset LatexCommand \index{Release policy}
32227 \begin_layout Standard
32228 Historically there often were long delays between official releases and
32229 the sourceforge download area tends to get not updated at all.
32230 Excuses in the past might have referred to problems with live range analysis,
32231 but as this was fixed a while ago, the current problem is that another
32232 excuse has to be found.
32233 Kidding aside, we have to get better there! On the other hand there are
32234 daily snapshots available at
32235 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32239 , and you can always build the very last version (hopefully with many bugs
32240 fixed, and features added) from the source code available at
32241 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32247 \begin_inset LatexCommand \index{wiki}
32252 \begin_inset LatexCommand \index{Release wiki}
32257 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32261 also holds some information about past and future releases.
32264 \begin_layout Section
32266 \begin_inset LatexCommand \index{Examples}
32273 \begin_layout Standard
32274 You'll find some small examples in the directory
32276 sdcc/device/examples/.
32279 More examples and libraries are available at
32281 The SDCC Open Knowledge Resource
32282 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32289 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32296 \begin_layout Standard
32297 \begin_inset Note Note
32300 \begin_layout Standard
32301 I did insert a reference to Paul's web site here although it seems rather
32302 dedicated to a specific 8032 board (I think it's okay because it f.e.
32303 shows LCD/Harddisc interface and has a free 8051 monitor.
32304 Independent 8032 board vendors face hard competition of heavily subsidized
32305 development boards anyway).
32308 \begin_layout Standard
32309 Maybe we should include some links to real world applications.
32310 Preferably pointer to pointers (one for each architecture) so this stays
32319 \begin_layout Section
32321 \begin_inset LatexCommand \label{sec:Quality-control}
32326 \begin_inset LatexCommand \index{Quality control}
32333 \begin_layout Standard
32334 The compiler is passed through snaphot build compile and build checks.
32340 \begin_inset LatexCommand \index{Regression test}
32344 check that SDCC itself compiles flawlessly on several host platforms (i386,
32345 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32346 the quality of the code generated by SDCC by running the code for several
32347 target platforms through simulators.
32348 The regression test suite comprises more than 100 files which expand to
32349 more than 500 test cases which include more than 4500 tests.
32350 The results of these tests are published daily on SDCC's snapshot page
32351 (click on the red or green symbols on the right side of
32352 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32359 \begin_layout Standard
32360 There is a separate document
32363 \begin_inset LatexCommand \index{Test suite}
32370 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32374 about the regression test suite.
32377 \begin_layout Standard
32378 You'll find the test code in the directory
32380 sdcc/support/regression
32383 You can run these tests manually by running
32387 in this directory (or f.e.
32392 \begin_inset Quotes sld
32396 \begin_inset Quotes srd
32402 if you don't want to run the complete tests).
32403 The test code might also be interesting if you want to look for examples
32404 \begin_inset LatexCommand \index{Examples}
32408 checking corner cases of SDCC or if you plan to submit patches
32409 \begin_inset LatexCommand \index{Patch submission}
32416 \begin_layout Standard
32417 The PIC14 port uses a different set of regression tests
32418 \begin_inset LatexCommand \index{Regression test (PIC14)}
32422 , you'll find them in the directory
32424 sdcc/src/regression
32429 \begin_layout Section
32430 Use of SDCC in Education
32433 \begin_layout Standard
32442 \begin_layout Standard
32443 the phrase "use in education" might evoke the association "
32447 fit for use in education".
32448 This connotation is not intended but nevertheless risked as the licensing
32449 of SDCC makes it difficult to offer educational discounts
32455 If your rationales are to:
32458 \begin_layout Enumerate
32459 give students a chance to understand the
32463 steps of code generation
32466 \begin_layout Enumerate
32467 have a curriculum that can be extended for years.
32468 Then you could use an fpga board as target and your curriculum will seamlessly
32469 extend from logic synthesis (
32470 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32475 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32479 ), over assembly programming, to C to FPGA compilers (
32480 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32487 \begin_layout Enumerate
32488 be able to insert excursions about skills like using a revision control
32489 system, submitting/applying patches, using a type-setting (as opposed to
32490 word-processing) engine LyX/LaTeX, using
32491 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32496 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32500 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32501 Source Software, CPU simulation, compiler regression tests
32502 \begin_inset LatexCommand \index{Regression test}
32509 And if there should be a shortage of ideas then you can always point students
32510 to the ever-growing feature request list
32511 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32518 \begin_layout Enumerate
32519 not tie students to a specific host platform and instead allow them to use
32524 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32526 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32533 \begin_layout Enumerate
32534 not encourage students to use illegal copies of educational software
32537 \begin_layout Enumerate
32538 be immune to licensing/availability/price changes of the chosen tool chain
32541 \begin_layout Enumerate
32542 be able to change to a new target platform without having to adopt a new
32546 \begin_layout Enumerate
32547 have complete control over and insight into the tool chain
32550 \begin_layout Enumerate
32551 make your students aware about the pros and cons of open source software
32555 \begin_layout Enumerate
32556 give back to the public as you are probably at least partially publically
32560 \begin_layout Enumerate
32561 give students a chance to publically prove their skills and to possibly
32562 see a world wide impact
32565 \begin_layout Standard
32566 then SDCC is probably among the first choices.
32567 Well, probably SDCC might be the only choice.
32572 \begin_layout Chapter
32573 SDCC Technical Data
32576 \begin_layout Section
32578 \begin_inset LatexCommand \index{Optimizations}
32585 \begin_layout Standard
32586 SDCC performs a host of standard optimizations in addition to some MCU specific
32591 \begin_layout Subsection
32592 Sub-expression Elimination
32593 \begin_inset LatexCommand \index{Subexpression elimination}
32600 \begin_layout Standard
32601 The compiler does local and
32620 \begin_layout Verse
32628 \begin_layout Standard
32629 will be translated to
32632 \begin_layout Verse
32642 \begin_layout Standard
32643 Some subexpressions are not as obvious as the above example, e.g.:
32646 \begin_layout Verse
32654 \begin_layout Standard
32655 In this case the address arithmetic a->b[i] will be computed only once;
32656 the equivalent code in C would be.
32659 \begin_layout Verse
32669 \begin_layout Standard
32670 The compiler will try to keep these temporary variables in registers.
32673 \begin_layout Subsection
32674 Dead-Code Elimination
32675 \begin_inset LatexCommand \index{Dead-code elimination}
32682 \begin_layout Verse
32697 i = 1; \InsetSpace ~
32706 global = 1;\InsetSpace ~
32720 global = 3;\InsetSpace ~
32726 \begin_layout Standard
32730 \begin_layout Verse
32746 \begin_layout Subsection
32748 \begin_inset LatexCommand \index{Copy propagation}
32755 \begin_layout Verse
32779 \begin_layout Standard
32783 \begin_layout Verse
32807 \begin_layout Standard
32808 Note: the dead stores created by this copy propagation will be eliminated
32809 by dead-code elimination.
32812 \begin_layout Subsection
32814 \begin_inset LatexCommand \index{Loop optimization}
32819 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32826 \begin_layout Standard
32827 Two types of loop optimizations are done by SDCC
32835 of loop induction variables.
32836 In addition to the strength reduction the optimizer marks the induction
32837 variables and the register allocator tries to keep the induction variables
32838 in registers for the duration of the loop.
32839 Because of this preference of the register allocator
32840 \begin_inset LatexCommand \index{Register allocation}
32844 , loop induction optimization causes an increase in register pressure, which
32845 may cause unwanted spilling of other temporary variables into the stack
32846 \begin_inset LatexCommand \index{stack}
32851 The compiler will generate a warning message when it is forced to allocate
32852 extra space either on the stack or data space.
32853 If this extra space allocation is undesirable then induction optimization
32854 can be eliminated either for the entire source file (with -
32858 \begin_layout Standard
32867 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32869 \begin_inset LatexCommand \index{\#pragma noinduction}
32880 \begin_layout Verse
32883 for (i = 0 ; i < 100 ; i ++)
32892 \begin_layout Standard
32896 \begin_layout Verse
32901 for (i = 0; i < 100; i++)
32910 \begin_layout Standard
32911 As mentioned previously some loop invariants are not as apparent, all static
32912 address computations are also moved out of the loop.
32917 \begin_inset LatexCommand \index{Strength reduction}
32921 , this optimization substitutes an expression by a cheaper expression:
32924 \begin_layout Verse
32927 for (i=0;i < 100; i++)
32936 \begin_layout Standard
32940 \begin_layout Verse
32947 for (i=0;i< 100;i++) {
32953 ar[itemp1] = itemp2;
32971 \begin_layout Standard
32972 The more expensive multiplication
32973 \begin_inset LatexCommand \index{Multiplication}
32977 is changed to a less expensive addition.
32980 \begin_layout Subsection
32982 \begin_inset LatexCommand \index{Loop reversing}
32989 \begin_layout Standard
32990 This optimization is done to reduce the overhead of checking loop boundaries
32991 for every iteration.
32992 Some simple loops can be reversed and implemented using a
32993 \begin_inset Quotes eld
32996 decrement and jump if not zero
32997 \begin_inset Quotes erd
33001 SDCC checks for the following criterion to determine if a loop is reversible
33002 (note: more sophisticated compilers use data-dependency analysis to make
33003 this determination, SDCC uses a more simple minded analysis).
33006 \begin_layout Itemize
33007 The 'for' loop is of the form
33013 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33023 \begin_layout Itemize
33024 The <for body> does not contain
33025 \begin_inset Quotes eld
33029 \begin_inset Quotes erd
33033 \begin_inset Quotes erd
33039 \begin_layout Itemize
33040 All goto's are contained within the loop.
33043 \begin_layout Itemize
33044 No function calls within the loop.
33047 \begin_layout Itemize
33048 The loop control variable <sym> is not assigned any value within the loop
33051 \begin_layout Itemize
33052 The loop control variable does NOT participate in any arithmetic operation
33056 \begin_layout Itemize
33057 There are NO switch statements in the loop.
33060 \begin_layout Subsection
33061 Algebraic Simplifications
33064 \begin_layout Standard
33065 SDCC does numerous algebraic simplifications, the following is a small sub-set
33066 of these optimizations.
33069 \begin_layout Verse
33072 i = j + 0;\InsetSpace ~
33076 /* changed to: */\InsetSpace ~
33082 i /= 2;\InsetSpace ~
33089 /* changed to: */\InsetSpace ~
33096 = j - j;\InsetSpace ~
33100 /* changed to: */\InsetSpace ~
33106 i = j / 1;\InsetSpace ~
33110 /* changed to: */\InsetSpace ~
33117 \begin_layout Standard
33118 Note the subexpressions
33119 \begin_inset LatexCommand \index{Subexpression}
33123 given above are generally introduced by macro expansions or as a result
33124 of copy/constant propagation.
33127 \begin_layout Subsection
33128 'switch' Statements
33129 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33134 \begin_inset LatexCommand \index{switch statement}
33141 \begin_layout Standard
33142 SDCC can optimize switch statements to jump tables
33143 \begin_inset LatexCommand \index{jump tables}
33148 It makes the decision based on an estimate of the generated code size.
33149 SDCC is quite liberal in the requirements for jump table generation:
33152 \begin_layout Itemize
33153 The labels need not be in order, and the starting number need not be one
33154 or zero, the case labels are in numerical sequence or not too many case
33155 labels are missing.
33159 \begin_layout Verse
33162 switch(i) {\InsetSpace ~
33193 case 4: ...\InsetSpace ~
33225 case 5: ...\InsetSpace ~
33257 case 3: ...\InsetSpace ~
33288 case 6: ...\InsetSpace ~
33320 case 7: ...\InsetSpace ~
33352 case 8: ...\InsetSpace ~
33384 case 9: ...\InsetSpace ~
33416 case 10: ...\InsetSpace ~
33447 case 11: ...\InsetSpace ~
33514 \begin_layout Standard
33515 Both the above switch statements will be implemented using a jump-table.
33516 The example to the right side is slightly more efficient as the check for
33517 the lower boundary of the jump-table is not needed.
33521 \begin_layout Itemize
33522 The number of case labels is not larger than supported by the target architectur
33526 \begin_layout Itemize
33527 If the case labels are not in numerical sequence ('gaps' between cases)
33528 SDCC checks whether a jump table with additionally inserted dummy cases
33529 is still attractive.
33533 \begin_layout Itemize
33534 If the starting number is not zero and a check for the lower boundary of
33535 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33540 \begin_layout Standard
33541 Switch statements which have large gaps in the numeric sequence or those
33542 that have too many case labels can be split into more than one switch statement
33543 for efficient code generation, e.g.:
33546 \begin_layout Verse
33624 \begin_layout Standard
33625 If the above switch statement is broken down into two switch statements
33628 \begin_layout Verse
33671 \begin_layout Standard
33675 \begin_layout Verse
33718 \begin_layout Standard
33719 then both the switch statements will be implemented using jump-tables whereas
33720 the unmodified switch statement will not be.
33723 \begin_layout Standard
33724 \begin_inset Note Note
33727 \begin_layout Standard
33728 There might be reasons which SDCC cannot know about to either favour or
33729 not favour jump tables.
33730 If the target system has to be as quick for the last switch case as for
33731 the first (pro jump table), or if the switch argument is known to be zero
33732 in the majority of the cases (contra jump table).
33740 \begin_layout Standard
33741 The pragma nojtbound
33742 \begin_inset LatexCommand \index{\#pragma nojtbound}
33746 can be used to turn off checking the
33759 It has no effect if a default label is supplied.
33760 Use of this pragma is dangerous: if the switch
33761 \begin_inset LatexCommand \index{switch statement}
33765 argument is not matched by a case statement the processor will happily
33769 \begin_layout Subsection
33770 Bit-shifting Operations
33771 \begin_inset LatexCommand \index{Bit shifting}
33778 \begin_layout Standard
33779 Bit shifting is one of the most frequently used operation in embedded programmin
33781 SDCC tries to implement bit-shift operations in the most efficient way
33785 \begin_layout Verse
33798 \begin_layout Standard
33799 generates the following code:
33802 \begin_layout Verse
33817 \begin_layout Standard
33818 In general SDCC will never setup a loop if the shift count is known.
33822 \begin_layout Verse
33835 \begin_layout Standard
33839 \begin_layout Verse
33863 \begin_layout Subsection
33865 \begin_inset LatexCommand \index{Bit rotation}
33872 \begin_layout Standard
33873 A special case of the bit-shift operation is bit rotation
33874 \begin_inset LatexCommand \index{rotating bits}
33878 , SDCC recognizes the following expression to be a left bit-rotation:
33881 \begin_layout Verse
33889 char i;\InsetSpace ~
33900 /* unsigned is needed for rotation */
33905 i = ((i << 1) | (i >> 7));
33914 \begin_layout Standard
33915 will generate the following code:
33918 \begin_layout Verse
33935 \begin_layout Standard
33936 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33937 ns of this case will also be recognized as bit-rotation, i.e.:
33940 \begin_layout Verse
33943 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33946 \begin_layout Subsection
33947 Nibble and Byte Swapping
33950 \begin_layout Standard
33951 Other special cases of the bit-shift operations are nibble or byte swapping
33952 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33956 , SDCC recognizes the following expressions:
33959 \begin_layout Verse
33980 i = ((i << 4) | (i >> 4));
33986 j = ((j << 8) | (j >> 8));
33989 \begin_layout Standard
33990 and generates a swap instruction for the nibble swapping
33991 \begin_inset LatexCommand \index{Nibble swapping}
33995 or move instructions for the byte swapping
33996 \begin_inset LatexCommand \index{Byte swapping}
34002 \begin_inset Quotes sld
34006 \begin_inset Quotes srd
34009 example can be used to convert from little to big-endian or vice versa.
34010 If you want to change the endianness of a
34014 integer you have to cast to
34021 \begin_layout Standard
34022 Note that SDCC stores numbers in little-endian
34026 \begin_layout Standard
34027 Usually 8-bit processors don't care much about endianness.
34028 This is not the case for the standard 8051 which only has an instruction
34034 \begin_inset LatexCommand \index{DPTR}
34042 so little-endian is the more efficient byte order.
34048 \begin_inset LatexCommand \index{little-endian}
34053 \begin_inset LatexCommand \index{Endianness}
34058 lowest order first).
34061 \begin_layout Subsection
34063 \begin_inset LatexCommand \index{Highest Order Bit}
34068 \begin_inset LatexCommand \index{Any Order Bit}
34075 \begin_layout Standard
34076 It is frequently required to obtain the highest order bit of an integral
34077 type (long, int, short or char types).
34078 Also obtaining any other order bit is not uncommon.
34079 SDCC recognizes the following expressions to yield the highest order bit
34080 and generates optimized code for it, e.g.:
34083 \begin_layout Verse
34094 unsigned char hob1, aob1;
34098 bit hob2, hob3, aob2,
34108 hob1 = (gint >> 15) & 1;
34112 hob2 = (gint >> 15) & 1;
34116 hob3 = gint & 0x8000;
34121 aob1 = (gint >> 9) & 1;
34125 aob2 = (gint >> 8) & 1;
34129 aob3 = gint & 0x0800;
34139 \begin_layout Standard
34140 will generate the following code:
34143 \begin_layout Verse
34174 000A E5*01\InsetSpace ~
34201 000C 23\InsetSpace ~
34232 000D 54 01\InsetSpace ~
34260 000F F5*02\InsetSpace ~
34315 0011 E5*01\InsetSpace ~
34343 0013 33\InsetSpace ~
34373 0014 92*00\InsetSpace ~
34429 0016 E5*01\InsetSpace ~
34456 0018 33\InsetSpace ~
34486 0019 92*01\InsetSpace ~
34542 001B E5*01\InsetSpace ~
34601 001E 54 01\InsetSpace ~
34628 0020 F5*03\InsetSpace ~
34684 0022 E5*01\InsetSpace ~
34711 0024 13\InsetSpace ~
34741 0025 92*02\InsetSpace ~
34797 0027 E5*01\InsetSpace ~
34852 002B 92*03\InsetSpace ~
34880 \begin_layout Standard
34881 Other variations of these cases however will
34886 They are standard C expressions, so I heartily recommend these be the only
34887 way to get the highest order bit, (it is portable).
34888 Of course it will be recognized even if it is embedded in other expressions,
34892 \begin_layout Verse
34895 xyz = gint + ((gint >> 15) & 1);
34898 \begin_layout Standard
34899 will still be recognized.
34902 \begin_layout Subsection
34904 \begin_inset LatexCommand \index{Higher Order Byte}
34908 / Higher Order Word
34909 \begin_inset LatexCommand \index{Higher Order Word}
34916 \begin_layout Standard
34917 It is also frequently required to obtain a higher order byte or word of
34918 a larger integral type (long, int or short types).
34919 SDCC recognizes the following expressions to yield the higher order byte
34920 or word and generates optimized code for it, e.g.:
34923 \begin_layout Verse
34928 unsigned long int glong;
34936 unsigned char hob1,
34941 unsigned int how1, how2;
34950 hob1 = (gint >> 8) & 0xFF;
34954 hob2 = glong >> 24;
34958 how1 = (glong >> 16) & 0xFFFF;
34973 \begin_layout Standard
34974 will generate the following code:
34977 \begin_layout Verse
35008 0037 85*01*06\InsetSpace ~
35030 _foo_hob1_1_1,(_gint + 1)
35061 003A 85*05*07\InsetSpace ~
35083 _foo_hob2_1_1,(_glong + 3)
35113 003D 85*04*08\InsetSpace ~
35136 _foo_how1_1_1,(_glong + 2)
35138 0040 85*05*09\InsetSpace ~
35163 0043 85*03*0A\InsetSpace ~
35185 _foo_how2_1_1,(_glong + 1)
35187 0046 85*04*0B\InsetSpace ~
35210 (_foo_how2_1_1 + 1),(_glong + 2)
35213 \begin_layout Standard
35214 Again, variations of these cases may
35219 They are standard C expressions, so I heartily recommend these be the only
35220 way to get the higher order byte/word, (it is portable).
35221 Of course it will be recognized even if it is embedded in other expressions,
35225 \begin_layout Verse
35228 xyz = gint + ((gint >> 8) & 0xFF);
35231 \begin_layout Standard
35232 will still be recognized.
35235 \begin_layout Subsection
35237 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35242 \begin_inset LatexCommand \index{Peephole optimizer}
35249 \begin_layout Standard
35250 The compiler uses a rule based, pattern matching and re-writing mechanism
35251 for peep-hole optimization.
35256 a peep-hole optimizer by Christopher W.
35257 Fraser (cwfraser\InsetSpace ~
35260 A default set of rules are compiled into the compiler, additional rules
35261 may be added with the
35267 \begin_layout Standard
35277 \begin_inset LatexCommand \index{-\/-peep-file}
35284 The rule language is best illustrated with examples.
35287 \begin_layout Verse
35309 \begin_layout Standard
35310 The above rule will change the following assembly
35311 \begin_inset LatexCommand \index{Assembler routines}
35318 \begin_layout Verse
35326 \begin_layout Standard
35330 \begin_layout Verse
35336 \begin_layout Standard
35337 Note: All occurrences of a
35341 (pattern variable) must denote the same string.
35342 With the above rule, the assembly sequence:
35345 \begin_layout Verse
35353 \begin_layout Standard
35354 will remain unmodified.
35358 Other special case optimizations may be added by the
35365 \begin_layout Standard
35378 some variants of the 8051 MCU
35379 \begin_inset LatexCommand \index{MCS51 variants}
35392 The following two rules will change all
35409 \begin_layout Verse
35412 replace { lcall %1 } by { acall %1 }
35414 replace { ljmp %1 } by { ajmp %1 }
35417 \begin_layout Standard
35420 inline-assembler code
35422 is also passed through the peep hole optimizer, thus the peephole optimizer
35423 can also be used as an assembly level macro expander.
35424 The rules themselves are MCU dependent whereas the rule language infra-structur
35425 e is MCU independent.
35426 Peephole optimization rules for other MCU can be easily programmed using
35431 The syntax for a rule is as follows:
35434 \begin_layout Verse
35437 rule := replace [ restart ] '{' <assembly sequence> '
35475 <assembly sequence> '
35493 '}' [if <functionName> ] '
35498 \begin_layout Standard
35499 <assembly sequence> := assembly instruction (each instruction including
35500 labels must be on a separate line).
35504 The optimizer will apply to the rules
35505 one by one from the top in the sequence of their appearance, it will terminate
35506 when all rules are exhausted.
35507 If the 'restart' option is specified, then the optimizer will start matching
35508 the rules again from the top, this option for a rule is expensive (performance)
35509 , it is intended to be used in situations where a transformation will trigger
35510 the same rule again.
35511 An example of this (not a good one, it has side effects) is the following
35515 \begin_layout Verse
35535 \begin_layout Standard
35536 Note that the replace pattern cannot be a blank, but can be a comment line.
35537 Without the 'restart' option only the innermost 'pop' 'push' pair would
35538 be eliminated, i.e.:
35541 \begin_layout Verse
35553 \begin_layout Standard
35557 \begin_layout Verse
35567 \begin_layout Standard
35572 the restart option the rule will be applied again to the resulting code
35573 and then all the pop-push pairs will be eliminated to yield:
35576 \begin_layout Verse
35584 \begin_layout Standard
35585 A conditional function can be attached to a rule.
35586 Attaching rules are somewhat more involved, let me illustrate this with
35590 \begin_layout Verse
35614 \begin_layout Standard
35615 The optimizer does a look-up of a function name table defined in function
35620 in the source file SDCCpeeph.c, with the name
35625 If it finds a corresponding entry the function is called.
35626 Note there can be no parameters specified for these functions, in this
35631 is crucial, since the function
35635 expects to find the label in that particular variable (the hash table containin
35636 g the variable bindings is passed as a parameter).
35637 If you want to code more such functions, take a close look at the function
35638 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35639 Currently implemented are
35641 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35642 24bitMode, portIsDS390, 24bitModeAndPortDS390
35651 \begin_layout Standard
35652 I know this whole thing is a little kludgey, but maybe some day we will
35653 have some better means.
35654 If you are looking at this file, you will see the default rules that are
35655 compiled into the compiler, you can add your own rules in the default set
35656 there if you get tired of specifying the -
35660 \begin_layout Standard
35672 \begin_layout Section
35674 \begin_inset LatexCommand \index{ANSI-compliance}
35679 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35686 \begin_layout Standard
35687 The latest publically available version of the standard
35689 ISO/IEC 9899 - Programming languages - C
35691 should be available at:
35692 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35701 \begin_layout Standard
35702 Deviations from the compliance:
35705 \begin_layout Itemize
35706 functions are not reentrant
35707 \begin_inset LatexCommand \index{reentrant}
35711 unless explicitly declared as such or the
35717 \begin_layout Standard
35727 \begin_inset LatexCommand \index{-\/-stack-auto}
35733 command line option is specified.
35736 \begin_layout Itemize
35738 \begin_inset LatexCommand \index{struct}
35743 \begin_inset LatexCommand \index{union}
35747 cannot be assigned values directly, cannot be passed as function parameters
35748 or assigned to each other and cannot be a return value
35749 \begin_inset LatexCommand \index{return value}
35753 from a function, e.g.:
35757 \begin_layout Verse
35780 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35799 s parms) /* invalid in SDCC although allowed in ANSI */
35821 return rets; /* is invalid in SDCC although allowed in ANSI */
35827 \begin_layout Itemize
35828 initialization of structure arrays must be fully braced.
35832 \begin_layout Verse
35835 struct s { char x } a[] = {1, 2};\InsetSpace ~
35840 /* invalid in SDCC */
35843 } a[] = {{1}, {2}}; /* OK */
35847 \begin_layout Itemize
35849 \begin_inset LatexCommand \index{long long (not supported)}
35854 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35861 \begin_layout Itemize
35863 \begin_inset LatexCommand \index{double (not supported)}
35867 ' precision floating point
35868 \begin_inset LatexCommand \index{Floating point support}
35875 \begin_layout Itemize
35877 \begin_inset LatexCommand \index{K\&R style}
35881 function declarations are NOT allowed.
35885 \begin_layout Verse
35888 foo(i,j) /* this old style of function declarations */
35890 int i,j; /* are valid
35891 in ANSI but not valid in SDCC */
35906 \begin_layout Itemize
35907 Most enhancements in C99 are not supported, f.e.:
35911 \begin_layout Verse
35916 \begin_inset LatexCommand \index{inline (not supported)}
35922 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35928 can be used as a work around */
35936 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35940 \begin_layout Itemize
35941 Certain words that are valid identifiers in the standard may be reserved
35942 words in SDCC unless the
35948 \begin_layout Standard
35958 \begin_inset LatexCommand \index{-\/-std-c89}
35966 \begin_layout Standard
35976 \begin_inset LatexCommand \index{-\/-std-c99}
35982 command line options are used.
35983 These may include (depending on the selected processor): 'at', 'banked',
35984 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35985 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35986 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35988 Compliant equivalents of these keywords are always available in a form
35989 that begin with two underscores
35990 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35995 '__data' instead of 'data'.
35998 \begin_layout Section
35999 Cyclomatic Complexity
36000 \begin_inset LatexCommand \index{Cyclomatic complexity}
36007 \begin_layout Standard
36008 Cyclomatic complexity of a function is defined as the number of independent
36009 paths the program can take during execution of the function.
36010 This is an important number since it defines the number test cases you
36011 have to generate to validate the function.
36012 The accepted industry standard for complexity number is 10, if the cyclomatic
36013 complexity reported by SDCC exceeds 10 you should think about simplification
36014 of the function logic.
36015 Note that the complexity level is not related to the number of lines of
36016 code in a function.
36017 Large functions can have low complexity, and small functions can have large
36023 SDCC uses the following formula to compute the complexity:
36028 \begin_layout Standard
36029 complexity = (number of edges in control flow graph) - (number of nodes
36030 in control flow graph) + 2;
36034 Having said that the industry standard is 10,
36035 you should be aware that in some cases it be may unavoidable to have a
36036 complexity level of less than 10.
36037 For example if you have switch statement with more than 10 case labels,
36038 each case label adds one to the complexity level.
36039 The complexity level is by no means an absolute measure of the algorithmic
36040 complexity of the function, it does however provide a good starting point
36041 for which functions you might look at for further optimization.
36044 \begin_layout Section
36045 Retargetting for other Processors
36048 \begin_layout Standard
36049 The issues for retargetting the compiler are far too numerous to be covered
36051 What follows is a brief description of each of the seven phases of the
36052 compiler and its MCU dependency.
36055 \begin_layout Itemize
36056 Parsing the source and building the annotated parse tree.
36057 This phase is largely MCU independent (except for the language extensions).
36058 Syntax & semantic checks are also done in this phase, along with some initial
36059 optimizations like back patching labels and the pattern matching optimizations
36060 like bit-rotation etc.
36063 \begin_layout Itemize
36064 The second phase involves generating an intermediate code which can be easy
36065 manipulated during the later phases.
36066 This phase is entirely MCU independent.
36067 The intermediate code generation assumes the target machine has unlimited
36068 number of registers, and designates them with the name iTemp.
36069 The compiler can be made to dump a human readable form of the code generated
36074 \begin_layout Standard
36086 \begin_layout Itemize
36087 This phase does the bulk of the standard optimizations and is also MCU independe
36089 This phase can be broken down into several sub-phases:
36093 Break down intermediate
36094 code (iCode) into basic blocks.
36096 Do control flow & data flow analysis on the
36099 Do local common subexpression elimination, then global subexpressio
36102 Dead code elimination
36106 If loop optimizations
36107 caused any changes then do 'global subexpression elimination' and 'dead
36108 code elimination' again.
36111 \begin_layout Itemize
36112 This phase determines the live-ranges; by live range I mean those iTemp
36113 variables defined by the compiler that still survive after all the optimization
36115 Live range analysis
36116 \begin_inset LatexCommand \index{Live range analysis}
36120 is essential for register allocation, since these computation determines
36121 which of these iTemps will be assigned to registers, and for how long.
36124 \begin_layout Itemize
36125 Phase five is register allocation.
36126 There are two parts to this process.
36130 The first part I call 'register packing'
36131 (for lack of a better term).
36132 In this case several MCU specific expression folding is done to reduce
36137 The second part is more MCU independent and deals with
36138 allocating registers to the remaining live ranges.
36139 A lot of MCU specific code does creep into this phase because of the limited
36140 number of index registers available in the 8051.
36143 \begin_layout Itemize
36144 The Code generation phase is (unhappily), entirely MCU dependent and very
36145 little (if any at all) of this code can be reused for other MCU.
36146 However the scheme for allocating a homogenized assembler operand for each
36147 iCode operand may be reused.
36150 \begin_layout Itemize
36151 As mentioned in the optimization section the peep-hole optimizer is rule
36152 based system, which can reprogrammed for other MCUs.
36155 \begin_layout Standard
36156 More information is available in a wiki
36157 \begin_inset LatexCommand \index{wiki}
36162 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36166 ) and in the thread
36167 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36174 \begin_layout Chapter
36176 \begin_inset LatexCommand \index{Compiler internals}
36183 \begin_layout Section
36184 The anatomy of the compiler
36185 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36192 \begin_layout Standard
36195 This is an excerpt from an article published in Circuit Cellar Magazine
36201 It's a little outdated (the compiler is much more efficient now and user/develo
36202 per friendly), but pretty well exposes the guts of it all.
36208 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36209 It is fairly easy to retarget for other 8-bit MCU.
36210 Here we take a look at some of the internals of the compiler.
36214 \begin_layout Paragraph*
36216 \begin_inset LatexCommand \index{Parsing}
36223 \begin_layout Standard
36224 Parsing the input source file and creating an AST (Annotated Syntax Tree
36225 \begin_inset LatexCommand \index{Annotated syntax tree}
36230 This phase also involves propagating types (annotating each node of the
36231 parse tree with type information) and semantic analysis.
36232 There are some MCU specific parsing rules.
36233 For example the storage classes, the extended storage classes are MCU specific
36234 while there may be a xdata storage class for 8051 there is no such storage
36235 class for z80 or Atmel AVR.
36236 SDCC allows MCU specific storage class extensions, i.e.
36237 xdata will be treated as a storage class specifier when parsing 8051 C
36238 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36242 \begin_layout Paragraph*
36244 \begin_inset LatexCommand \index{iCode}
36251 \begin_layout Standard
36252 Intermediate code generation.
36253 In this phase the AST is broken down into three-operand form (iCode).
36254 These three operand forms are represented as doubly linked lists.
36255 ICode is the term given to the intermediate form generated by the compiler.
36256 ICode example section shows some examples of iCode generated for some simple
36257 C source functions.
36260 \begin_layout Paragraph*
36262 \begin_inset LatexCommand \index{Optimizations}
36269 \begin_layout Standard
36270 Bulk of the target independent optimizations is performed in this phase.
36271 The optimizations include constant propagation, common sub-expression eliminati
36272 on, loop invariant code movement, strength reduction of loop induction variables
36273 and dead-code elimination.
36276 \begin_layout Paragraph*
36277 Live range analysis
36278 \begin_inset LatexCommand \index{Live range analysis}
36285 \begin_layout Standard
36286 During intermediate code generation phase, the compiler assumes the target
36287 machine has infinite number of registers and generates a lot of temporary
36289 The live range computation determines the lifetime of each of these compiler-ge
36290 nerated temporaries.
36291 A picture speaks a thousand words.
36292 ICode example sections show the live range annotations for each of the
36294 It is important to note here, each iCode is assigned a number in the order
36295 of its execution in the function.
36296 The live ranges are computed in terms of these numbers.
36297 The from number is the number of the iCode which first defines the operand
36298 and the to number signifies the iCode which uses this operand last.
36301 \begin_layout Paragraph*
36302 Register Allocation
36303 \begin_inset LatexCommand \index{Register allocation}
36310 \begin_layout Standard
36311 The register allocation determines the type and number of registers needed
36313 In most MCUs only a few registers can be used for indirect addressing.
36314 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36315 address the internal ram and DPTR to indirectly address the external ram.
36316 The compiler will try to allocate the appropriate register to pointer variables
36318 ICode example section shows the operands annotated with the registers assigned
36320 The compiler will try to keep operands in registers as much as possible;
36321 there are several schemes the compiler uses to do achieve this.
36322 When the compiler runs out of registers the compiler will check to see
36323 if there are any live operands which is not used or defined in the current
36324 basic block being processed, if there are any found then it will push that
36325 operand and use the registers in this block, the operand will then be popped
36326 at the end of the basic block.
36330 \begin_layout Standard
36331 There are other MCU specific considerations in this phase.
36332 Some MCUs have an accumulator; very short-lived operands could be assigned
36333 to the accumulator instead of a general-purpose register.
36336 \begin_layout Paragraph*
36340 \begin_layout Standard
36341 Figure II gives a table of iCode
36342 \begin_inset LatexCommand \index{iCode}
36346 operations supported by the compiler.
36347 The code generation involves translating these operations into corresponding
36348 assembly code for the processor.
36349 This sounds overly simple but that is the essence of code generation.
36350 Some of the iCode operations are generated on a MCU specific manner for
36351 example, the z80 port does not use registers to pass parameters so the
36352 SEND and RECV iCode operations will not be generated, and it also does
36353 not support JUMPTABLES.
36359 \begin_layout Standard
36363 \begin_inset Tabular
36364 <lyxtabular version="3" rows="39" columns="4">
36365 <features islongtable="true" headBottomDL="true">
36366 <column alignment="block" valignment="top" leftline="true" width="13col%">
36367 <column alignment="left" valignment="top" leftline="true" width="13col%">
36368 <column alignment="block" valignment="top" leftline="true" width="22col%">
36369 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36370 <row topline="true" bottomline="true" endhead="true">
36371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36374 \begin_layout Standard
36380 \begin_inset LatexCommand \index{iCode}
36389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36392 \begin_layout Standard
36400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36403 \begin_layout Standard
36411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36414 \begin_layout Standard
36423 <row topline="true">
36424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36427 \begin_layout Standard
36435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36438 \begin_layout Standard
36441 IC_LEFT() IC_RESULT()
36446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36449 \begin_layout Standard
36457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36460 \begin_layout Standard
36463 IC_RESULT = ! IC_LEFT;
36469 <row topline="true">
36470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36473 \begin_layout Standard
36481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36484 \begin_layout Standard
36487 IC_LEFT() IC_RESULT()
36492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36495 \begin_layout Standard
36498 Bitwise complement of
36503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36506 \begin_layout Standard
36509 IC_RESULT = ~IC_LEFT;
36515 <row topline="true">
36516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36519 \begin_layout Standard
36527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36530 \begin_layout Standard
36533 IC_LEFT() IC_RESULT()
36538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36541 \begin_layout Standard
36544 Rotate right with carry
36549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36552 \begin_layout Standard
36555 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36561 <row topline="true">
36562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36565 \begin_layout Standard
36573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36576 \begin_layout Standard
36579 IC_LEFT() IC_RESULT()
36584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36587 \begin_layout Standard
36590 Rotate left with carry
36595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36598 \begin_layout Standard
36601 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36607 <row topline="true">
36608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36611 \begin_layout Standard
36619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36622 \begin_layout Standard
36625 IC_LEFT() IC_RESULT()
36630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36633 \begin_layout Standard
36636 Get the highest order bit of IC_LEFT
36641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36644 \begin_layout Standard
36647 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36653 <row topline="true">
36654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36657 \begin_layout Standard
36665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36668 \begin_layout Standard
36671 IC_LEFT() IC_RESULT()
36676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36679 \begin_layout Standard
36687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36690 \begin_layout Standard
36693 IC_RESULT = - IC_LEFT;
36699 <row topline="true">
36700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36703 \begin_layout Standard
36711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36714 \begin_layout Standard
36722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36725 \begin_layout Standard
36728 Push the operand into stack
36733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36736 \begin_layout Standard
36745 <row topline="true">
36746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36749 \begin_layout Standard
36757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36760 \begin_layout Standard
36768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36771 \begin_layout Standard
36774 Pop the operand from the stack
36779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36782 \begin_layout Standard
36791 <row topline="true">
36792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36795 \begin_layout Standard
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36806 \begin_layout Standard
36809 IC_LEFT() IC_RESULT()
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36817 \begin_layout Standard
36820 Call the function represented by IC_LEFT
36825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36828 \begin_layout Standard
36831 IC_RESULT = IC_LEFT();
36837 <row topline="true">
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36841 \begin_layout Standard
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36852 \begin_layout Standard
36855 IC_LEFT() IC_RESULT()
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36863 \begin_layout Standard
36866 Call via function pointer
36871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36874 \begin_layout Standard
36877 IC_RESULT = (*IC_LEFT)();
36883 <row topline="true">
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36887 \begin_layout Standard
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36898 \begin_layout Standard
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36909 \begin_layout Standard
36912 Return the value in operand IC_LEFT
36917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36920 \begin_layout Standard
36929 <row topline="true">
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36933 \begin_layout Standard
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36944 \begin_layout Standard
36952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36955 \begin_layout Standard
36963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36966 \begin_layout Standard
36975 <row topline="true">
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36979 \begin_layout Standard
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36990 \begin_layout Standard
36998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37001 \begin_layout Standard
37009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37012 \begin_layout Standard
37021 <row topline="true">
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37025 \begin_layout Standard
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37036 \begin_layout Standard
37039 IC_LEFT() IC_RIGHT() IC_RESULT()
37044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37047 \begin_layout Standard
37055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37058 \begin_layout Standard
37061 IC_RESULT = IC_LEFT + IC_RIGHT
37067 <row topline="true">
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37071 \begin_layout Standard
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37082 \begin_layout Standard
37085 IC_LEFT() IC_RIGHT() IC_RESULT()
37090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37093 \begin_layout Standard
37101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37104 \begin_layout Standard
37107 IC_RESULT = IC_LEFT - IC_RIGHT
37113 <row topline="true">
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37117 \begin_layout Standard
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37128 \begin_layout Standard
37131 IC_LEFT() IC_RIGHT() IC_RESULT()
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37139 \begin_layout Standard
37147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37150 \begin_layout Standard
37153 IC_RESULT = IC_LEFT * IC_RIGHT;
37159 <row topline="true">
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37163 \begin_layout Standard
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37174 \begin_layout Standard
37177 IC_LEFT() IC_RIGHT() IC_RESULT()
37182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37185 \begin_layout Standard
37193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37196 \begin_layout Standard
37199 IC_RESULT = IC_LEFT / IC_RIGHT;
37205 <row topline="true">
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37209 \begin_layout Standard
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37220 \begin_layout Standard
37223 IC_LEFT() IC_RIGHT() IC_RESULT()
37228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37231 \begin_layout Standard
37239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37242 \begin_layout Standard
37245 IC_RESULT = IC_LEFT % IC_RIGHT;
37251 <row topline="true">
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37255 \begin_layout Standard
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37266 \begin_layout Standard
37269 IC_LEFT() IC_RIGHT() IC_RESULT()
37274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37277 \begin_layout Standard
37285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37288 \begin_layout Standard
37291 IC_RESULT = IC_LEFT < IC_RIGHT;
37297 <row topline="true">
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37301 \begin_layout Standard
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37312 \begin_layout Standard
37315 IC_LEFT() IC_RIGHT() IC_RESULT()
37320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37323 \begin_layout Standard
37331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37334 \begin_layout Standard
37337 IC_RESULT = IC_LEFT > IC_RIGHT;
37343 <row topline="true">
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37347 \begin_layout Standard
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37358 \begin_layout Standard
37361 IC_LEFT() IC_RIGHT() IC_RESULT()
37366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37369 \begin_layout Standard
37377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37380 \begin_layout Standard
37383 IC_RESULT = IC_LEFT == IC_RIGHT;
37389 <row topline="true">
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37393 \begin_layout Standard
37401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37404 \begin_layout Standard
37407 IC_LEFT() IC_RIGHT() IC_RESULT()
37412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37415 \begin_layout Standard
37418 Logical and operation
37423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37426 \begin_layout Standard
37429 IC_RESULT = IC_LEFT && IC_RIGHT;
37435 <row topline="true">
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37439 \begin_layout Standard
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37450 \begin_layout Standard
37453 IC_LEFT() IC_RIGHT() IC_RESULT()
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37461 \begin_layout Standard
37464 Logical or operation
37469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37472 \begin_layout Standard
37475 IC_RESULT = IC_LEFT || IC_RIGHT;
37481 <row topline="true">
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37485 \begin_layout Standard
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37496 \begin_layout Standard
37499 IC_LEFT() IC_RIGHT() IC_RESULT()
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37507 \begin_layout Standard
37515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37518 \begin_layout Standard
37521 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37527 <row topline="true">
37528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37531 \begin_layout Standard
37539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37542 \begin_layout Standard
37545 IC_LEFT() IC_RIGHT() IC_RESULT()
37550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37553 \begin_layout Standard
37561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37564 \begin_layout Standard
37567 IC_RESULT = IC_LEFT | IC_RIGHT;
37573 <row topline="true">
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37577 \begin_layout Standard
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37588 \begin_layout Standard
37591 IC_LEFT() IC_RIGHT() IC_RESULT()
37596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37599 \begin_layout Standard
37607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37610 \begin_layout Standard
37613 IC_RESULT = IC_LEFT & IC_RIGHT;
37619 <row topline="true">
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37623 \begin_layout Standard
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37634 \begin_layout Standard
37637 IC_LEFT() IC_RIGHT() IC_RESULT()
37642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37645 \begin_layout Standard
37653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37656 \begin_layout Standard
37659 IC_RESULT = IC_LEFT << IC_RIGHT
37665 <row topline="true">
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37669 \begin_layout Standard
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37680 \begin_layout Standard
37683 IC_LEFT() IC_RIGHT() IC_RESULT()
37688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37691 \begin_layout Standard
37699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37702 \begin_layout Standard
37705 IC_RESULT = IC_LEFT >> IC_RIGHT
37711 <row topline="true">
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37715 \begin_layout Standard
37725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37728 \begin_layout Standard
37731 IC_LEFT() IC_RESULT()
37736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37739 \begin_layout Standard
37747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37750 \begin_layout Standard
37753 IC_RESULT = (*IC_LEFT);
37759 <row topline="true">
37760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37763 \begin_layout Standard
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37774 \begin_layout Standard
37777 IC_RIGHT() IC_RESULT()
37782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37785 \begin_layout Standard
37793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37796 \begin_layout Standard
37799 (*IC_RESULT) = IC_RIGHT;
37805 <row topline="true">
37806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37809 \begin_layout Standard
37817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37820 \begin_layout Standard
37823 IC_RIGHT() IC_RESULT()
37828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37831 \begin_layout Standard
37839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37842 \begin_layout Standard
37845 IC_RESULT = IC_RIGHT;
37851 <row topline="true">
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37855 \begin_layout Standard
37863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37866 \begin_layout Standard
37869 IC_COND IC_TRUE IC_LABEL
37874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37877 \begin_layout Standard
37881 If true label is present then jump to true label if condition is true else
37882 jump to false label if condition is false
37887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37890 \begin_layout Standard
37893 if (IC_COND) goto IC_TRUE;
37899 If (!IC_COND) goto IC_FALSE;
37905 <row topline="true">
37906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37909 \begin_layout Standard
37917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37920 \begin_layout Standard
37923 IC_LEFT() IC_RESULT()
37928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37931 \begin_layout Standard
37939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37942 \begin_layout Standard
37945 IC_RESULT = &IC_LEFT();
37951 <row topline="true">
37952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37955 \begin_layout Standard
37963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37966 \begin_layout Standard
37969 IC_JTCOND IC_JTLABELS
37974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37977 \begin_layout Standard
37980 Jump to list of labels depending on the value of JTCOND
37985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37988 \begin_layout Standard
37997 <row topline="true">
37998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38001 \begin_layout Standard
38009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38012 \begin_layout Standard
38015 IC_RIGHT() IC_LEFT() IC_RESULT()
38020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38023 \begin_layout Standard
38031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38034 \begin_layout Standard
38037 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38043 <row topline="true">
38044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38047 \begin_layout Standard
38055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38058 \begin_layout Standard
38066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38069 \begin_layout Standard
38072 This is used for passing parameters in registers;
38074 move IC_LEFT to the next
38075 available parameter register.
38080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38083 \begin_layout Standard
38092 <row topline="true">
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38096 \begin_layout Standard
38104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38107 \begin_layout Standard
38115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38118 \begin_layout Standard
38121 This is used for receiving parameters passed in registers;
38124 in the next parameter register to IC_RESULT
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38132 \begin_layout Standard
38141 <row topline="true" bottomline="true">
38142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38145 \begin_layout Standard
38149 (some more have been added)
38154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38157 \begin_layout Standard
38163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38166 \begin_layout Standard
38172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38175 \begin_layout Standard
38199 \begin_layout Standard
38200 \begin_inset Note Note
38203 \begin_layout Standard
38204 In the original article Figure II was announced to be downloadable on
38209 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38217 \begin_layout Paragraph*
38219 \begin_inset LatexCommand \index{iCode}
38226 \begin_layout Standard
38227 This section shows some details of iCode.
38228 The example C code does not do anything useful; it is used as an example
38229 to illustrate the intermediate code generated by the compiler.
38232 \begin_layout Verse
38242 /* This function does nothing useful.
38249 for the purpose of explaining iCode */
38252 short function (data
38261 short i=10; \InsetSpace ~
38263 /* dead initialization eliminated */
38269 /* dead initialization eliminated */
38297 /* compiler detects i,j to be induction
38302 for (i = 0, j = 10 ; i < 10 ; i++, j
38308 \begin_layout Standard
38331 mul += i * 3; \InsetSpace ~
38333 /* this multiplication remains */
38340 j * 3;\InsetSpace ~
38342 /* this multiplication changed to addition */
38356 \begin_layout Standard
38357 In addition to the operands each iCode contains information about the filename
38358 and line it corresponds to in the source file.
38359 The first field in the listing should be interpreted as follows:
38364 Filename(linenumber: iCode Execution sequence number : ICode hash table
38365 key : loop depth of the iCode).
38370 Then follows the human readable form of the ICode operation.
38371 Each operand of this triplet form can be of three basic types a) compiler
38372 generated temporary b) user defined variable c) a constant value.
38373 Note that local variables and parameters are replaced by compiler generated
38376 \begin_inset LatexCommand \index{Live range analysis}
38380 are computed only for temporaries (i.e.
38381 live ranges are not computed for global variables).
38383 \begin_inset LatexCommand \index{Register allocation}
38387 are allocated for temporaries only.
38388 Operands are formatted in the following manner:
38393 Operand Name [lr live-from : live-to ] { type information } [ registers
38399 As mentioned earlier the live ranges are computed in terms of the execution
38400 sequence number of the iCodes, for example
38402 the iTemp0 is live from (i.e.
38403 first defined in iCode with execution sequence number 3, and is last used
38404 in the iCode with sequence number 5).
38405 For induction variables such as iTemp21 the live range computation extends
38406 the lifetime from the start to the end of the loop.
38408 The register allocator
38409 used the live range information to allocate registers, the same registers
38410 may be used for different temporaries if their live ranges do not overlap,
38411 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38412 ranges do not overlap.
38413 In addition the allocator also takes into consideration the type and usage
38414 of a temporary, for example itemp6 is a pointer to near space and is used
38415 as to fetch data from (i.e.
38416 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38417 Some short lived temporaries are allocated to special registers which have
38418 meaning to the code generator e.g.
38419 iTemp13 is allocated to a pseudo register CC which tells the back end that
38420 the temporary is used only for a conditional jump the code generation makes
38421 use of this information to optimize a compare and jump ICode.
38425 \begin_inset LatexCommand \index{Loop optimization}
38429 performed by the compiler.
38430 It can detect induction variables iTemp21(i) and iTemp23(j).
38431 Also note the compiler does selective strength reduction
38432 \begin_inset LatexCommand \index{Strength reduction}
38437 the multiplication of an induction variable in line 18 (gint = j * 3) is
38438 changed to addition, a new temporary iTemp17 is allocated and assigned
38439 a initial value, a constant 3 is then added for each iteration of the loop.
38440 The compiler does not change the multiplication
38441 \begin_inset LatexCommand \index{Multiplication}
38445 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38448 Note the dead code elimination
38449 \begin_inset LatexCommand \index{Dead-code elimination}
38453 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38459 \begin_layout Standard
38462 Sample.c (5:1:0:0) _entry($9) :
38465 \begin_layout Standard
38468 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38471 \begin_layout Standard
38474 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38477 \begin_layout Standard
38480 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38483 \begin_layout Standard
38486 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38490 \begin_layout Standard
38493 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38496 \begin_layout Standard
38499 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38503 \begin_layout Standard
38506 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38509 \begin_layout Standard
38512 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38516 \begin_layout Standard
38519 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38523 \begin_layout Standard
38526 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38530 \begin_layout Standard
38533 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38537 \begin_layout Standard
38540 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38541 * int}[r0] + 0x2 {short}
38544 \begin_layout Standard
38547 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38550 \begin_layout Standard
38553 Sample.c(11:17:21:0)_whilebreak_0($3) :
38556 \begin_layout Standard
38559 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38562 \begin_layout Standard
38565 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38568 \begin_layout Standard
38571 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38574 \begin_layout Standard
38577 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38580 \begin_layout Standard
38583 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38586 \begin_layout Standard
38589 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38592 \begin_layout Standard
38595 Sample.c(15:24:26:1)_forcond_0($4) :
38598 \begin_layout Standard
38601 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38605 \begin_layout Standard
38608 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38611 \begin_layout Standard
38614 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38615 + ITemp21 [lr21:38]{short}[r4]
38618 \begin_layout Standard
38621 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38625 \begin_layout Standard
38628 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38629 + iTemp15 [lr29:30]{short}[r1]
38632 \begin_layout Standard
38635 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38639 \begin_layout Standard
38642 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38646 \begin_layout Standard
38649 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38653 \begin_layout Standard
38656 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38660 \begin_layout Standard
38663 Sample.c(19:38:47:1) goto _forcond_0($4)
38666 \begin_layout Standard
38669 Sample.c(19:39:48:0)_forbreak_0($7) :
38672 \begin_layout Standard
38675 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38676 + ITemp11 [lr19:40]{short}[r3]
38679 \begin_layout Standard
38682 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38685 \begin_layout Standard
38688 Sample.c(20:42:51:0)_return($8) :
38691 \begin_layout Standard
38694 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38700 Finally the code generated for this function:
38705 \begin_layout Standard
38711 \begin_layout Standard
38717 \begin_layout Standard
38725 \begin_layout Standard
38731 \begin_layout Standard
38739 \begin_layout Standard
38745 \begin_layout Standard
38748 ; ----------------------------------------------
38751 \begin_layout Standard
38754 ; function function
38757 \begin_layout Standard
38760 ; ----------------------------------------------
38763 \begin_layout Standard
38769 \begin_layout Standard
38772 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38775 \begin_layout Standard
38783 \begin_layout Standard
38786 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38789 \begin_layout Standard
38797 \begin_layout Standard
38800 ;_whilecontinue_0($1) :
38803 \begin_layout Standard
38809 \begin_layout Standard
38812 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38815 \begin_layout Standard
38818 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38821 \begin_layout Standard
38829 \begin_layout Standard
38837 \begin_layout Standard
38845 \begin_layout Standard
38853 \begin_layout Standard
38861 \begin_layout Standard
38869 \begin_layout Standard
38877 \begin_layout Standard
38883 \begin_layout Standard
38886 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38889 \begin_layout Standard
38897 \begin_layout Standard
38905 \begin_layout Standard
38908 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38911 \begin_layout Standard
38919 \begin_layout Standard
38927 \begin_layout Standard
38935 \begin_layout Standard
38943 \begin_layout Standard
38951 \begin_layout Standard
38959 \begin_layout Standard
38962 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38965 \begin_layout Standard
38973 \begin_layout Standard
38981 \begin_layout Standard
38989 \begin_layout Standard
38997 \begin_layout Standard
39005 \begin_layout Standard
39008 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39011 \begin_layout Standard
39019 \begin_layout Standard
39027 \begin_layout Standard
39035 \begin_layout Standard
39038 ; iTemp6 [lr5:16]{_near * int}[r0] =
39041 \begin_layout Standard
39044 ; iTemp6 [lr5:16]{_near * int}[r0] +
39047 \begin_layout Standard
39053 \begin_layout Standard
39061 \begin_layout Standard
39064 ; goto _whilecontinue_0($1)
39067 \begin_layout Standard
39075 \begin_layout Standard
39078 ; _whilebreak_0($3) :
39081 \begin_layout Standard
39087 \begin_layout Standard
39090 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39093 \begin_layout Standard
39101 \begin_layout Standard
39104 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39107 \begin_layout Standard
39115 \begin_layout Standard
39118 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39121 \begin_layout Standard
39129 \begin_layout Standard
39132 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39135 \begin_layout Standard
39143 \begin_layout Standard
39151 \begin_layout Standard
39154 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39157 \begin_layout Standard
39165 \begin_layout Standard
39173 \begin_layout Standard
39179 \begin_layout Standard
39185 \begin_layout Standard
39188 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39191 \begin_layout Standard
39194 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39197 \begin_layout Standard
39205 \begin_layout Standard
39213 \begin_layout Standard
39221 \begin_layout Standard
39229 \begin_layout Standard
39237 \begin_layout Standard
39243 \begin_layout Standard
39246 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39249 \begin_layout Standard
39252 ; iTemp21 [lr21:38]{short}[r4]
39255 \begin_layout Standard
39263 \begin_layout Standard
39271 \begin_layout Standard
39279 \begin_layout Standard
39282 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39285 \begin_layout Standard
39293 \begin_layout Standard
39301 \begin_layout Standard
39309 \begin_layout Standard
39317 \begin_layout Standard
39320 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39323 \begin_layout Standard
39326 ; iTemp15 [lr29:30]{short}[r1]
39329 \begin_layout Standard
39337 \begin_layout Standard
39345 \begin_layout Standard
39348 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39351 \begin_layout Standard
39359 \begin_layout Standard
39367 \begin_layout Standard
39375 \begin_layout Standard
39383 \begin_layout Standard
39391 \begin_layout Standard
39399 \begin_layout Standard
39402 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39405 \begin_layout Standard
39413 \begin_layout Standard
39421 \begin_layout Standard
39429 \begin_layout Standard
39437 \begin_layout Standard
39445 \begin_layout Standard
39453 \begin_layout Standard
39456 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39459 \begin_layout Standard
39467 \begin_layout Standard
39470 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39473 \begin_layout Standard
39481 \begin_layout Standard
39486 cjne r5,#0xff,00104$
39489 \begin_layout Standard
39497 \begin_layout Standard
39500 ; goto _forcond_0($4)
39503 \begin_layout Standard
39511 \begin_layout Standard
39514 ; _forbreak_0($7) :
39517 \begin_layout Standard
39523 \begin_layout Standard
39526 ; ret iTemp24 [lr40:41]{short}
39529 \begin_layout Standard
39537 \begin_layout Standard
39545 \begin_layout Standard
39553 \begin_layout Standard
39559 \begin_layout Standard
39565 \begin_layout Standard
39575 \begin_layout Section
39576 A few words about basic block successors, predecessors and dominators
39579 \begin_layout Standard
39580 Successors are basic blocks
39581 \begin_inset LatexCommand \index{Basic blocks}
39585 that might execute after this basic block.
39587 Predecessors are basic blocks
39588 that might execute before reaching this basic block.
39590 Dominators are basic
39591 blocks that WILL execute before reaching this basic block.
39596 \begin_layout Standard
39600 \begin_layout Standard
39604 \begin_layout Standard
39612 \begin_layout Standard
39616 \begin_layout Standard
39624 \begin_layout Standard
39630 \begin_layout Standard
39631 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39634 \begin_layout Standard
39635 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39638 \begin_layout Standard
39639 c) domVect of [BB4] = BB1 ...
39640 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39644 \begin_layout Chapter
39648 \begin_layout Standard
39649 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39659 Thanks to all the other volunteer developers who have helped with coding,
39660 testing, web-page creation, distribution sets, etc.
39661 You know who you are :-)
39669 Thanks to Sourceforge
39670 \begin_inset LatexCommand \url{http://www.sf.net}
39674 which has hosted the project since 1999 and donates significant download
39683 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39684 cycles and bandwidth for snapshot builds.
39689 \begin_layout Standard
39690 This document was initially written by Sandeep Dutta
39693 \begin_layout Standard
39694 All product names mentioned herein may be trademarks
39695 \begin_inset LatexCommand \index{Trademarks}
39699 of their respective companies.
39703 \begin_layout Section*
39707 \begin_layout Standard
39708 To avoid confusion, the installation and building options for SDCC itself
39709 (chapter 2) are not part of the index.
39712 \begin_layout Standard
39713 \begin_inset LatexCommand \printindex{}