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 All labels defined within inline assembler code have 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 Standard
17371 This is a slightly more stringent rule than absolutely necessary, but stays
17372 always on the safe side.
17373 Labels in the form of nnnnn$ are local labels in the assembler, locality
17374 of which is confined within two labels of the standard form.
17375 The compiler uses the same form for labels within a function (but starting
17376 from nnnnn=00100); and places always a standard label at the beginning
17377 of a function, thus limiting the locality of labels within the scope of
17379 So, if the inline assembler part would be embedded into C-code, an improperly
17380 placed non-local label in the assembler would break up the reference space
17381 for labels created by the compiler for the C-code, leading to an assembling
17385 \begin_layout Standard
17386 The numeric part of local labels does not need to have 5 digits (although
17387 this is the form of labels output by the compiler), any valid integer will
17389 Please refer to the assemblers documentation for further details.
17397 \begin_layout Verse
17401 \begin_inset LatexCommand \index{\_asm}
17406 \begin_inset LatexCommand \index{\_\_asm}
17436 \begin_inset LatexCommand \index{\_endasm}
17441 \begin_inset LatexCommand \index{\_\_endasm}
17448 \begin_layout Standard
17449 Inline assembler code cannot reference any C-labels, however it can reference
17451 \begin_inset LatexCommand \index{Labels}
17455 defined by the inline assembler, e.g.:
17458 \begin_layout Verse
17481 ; some assembler code
17502 /* some more c code */
17504 clabel:\InsetSpace ~
17506 /* inline assembler cannot reference this
17511 \begin_layout Standard
17516 is translated by the compiler into a local label, so the locality of labels
17517 within the function is not broken.
17534 0003$: ;label (can be referenced by inline assembler only)
17542 \begin_inset LatexCommand \index{\_endasm}
17547 \begin_inset LatexCommand \index{\_\_endasm}
17557 /* some more c code */
17562 \begin_layout Standard
17563 In other words inline assembly code can access labels defined in inline
17564 assembly within the scope of the function.
17565 The same goes the other way, i.e.
17566 labels defines in inline assembly can not be accessed by C statements.
17569 \begin_layout Section
17570 Interfacing with Assembler Code
17571 \begin_inset LatexCommand \index{Assembler routines}
17578 \begin_layout Subsection
17579 Global Registers used for Parameter Passing
17580 \begin_inset LatexCommand \index{Parameter passing}
17587 \begin_layout Standard
17588 The compiler always uses the global registers
17591 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17596 \begin_inset LatexCommand \index{DPTR}
17601 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17610 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17616 to pass the first parameter to a function, and also to pass the return
17618 \begin_inset LatexCommand \index{return value}
17622 of function; according to the following scheme: one byte return value in
17627 , two byte value in
17636 three byte values (generic pointers) in
17648 , and four byte values in
17666 \begin_inset LatexCommand \index{generic pointer}
17670 contain type of accessed memory in
17691 \begin_inset Note Note
17694 \begin_layout Standard
17695 This might not be the case of certain memory models (medium???)
17703 \begin_layout Standard
17704 The second parameter onwards is either allocated on the stack (for reentrant
17709 \begin_layout Standard
17718 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17722 \begin_layout Subsection
17726 \begin_layout Standard
17727 Unless the called function is declared as
17732 \begin_inset LatexCommand \index{naked}
17740 \begin_layout Standard
17750 \begin_inset LatexCommand \index{-\/-callee-saves}
17758 \begin_layout Standard
17767 -all-callee-saves command line option or the corresponding callee_saves
17768 pragma are used, the caller will save the registers (
17772 ) around the call, so the called function can destroy they content freely.
17775 \begin_layout Standard
17776 If the called function is not declared as
17780 , the caller will swap register banks around the call, if caller and callee
17781 use different register banks (having them defined by the
17789 \begin_layout Standard
17790 The called function can also use
17806 observing that they are used for parameter/return value passing.
17809 \begin_layout Subsection
17810 Assembler Routine (non-reentrant)
17813 \begin_layout Standard
17814 In the following example
17815 \begin_inset LatexCommand \index{reentrant}
17820 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17824 the function c_func calls an assembler routine asm_func, which takes two
17826 \begin_inset LatexCommand \index{function parameter}
17833 \begin_layout Verse
17836 extern int asm_func(unsigned char, unsigned char);
17840 int c_func (unsigned char
17841 i, unsigned char j)
17849 return asm_func(i,j);
17863 return c_func(10,9);
17868 \begin_layout Standard
17869 The corresponding assembler function is:
17872 \begin_layout Verse
17875 .globl _asm_func_PARM_2
17977 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17994 \begin_layout Standard
17995 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17996 the parameter number starting from 1, and counting from the left.
17997 The first parameter is passed in
18013 according to the description above.
18014 The variable name for the second parameter will be _<function_name>_PARM_2.
18019 ble the assembler routine with the following command:
18026 asx8051 -losg asmfunc.asm
18033 Then compile and link the assembler routine to the C source file with the
18041 sdcc cfunc.c asmfunc.rel
18044 \begin_layout Subsection
18045 Assembler Routine (reentrant)
18048 \begin_layout Standard
18050 \begin_inset LatexCommand \index{reentrant}
18055 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18059 the second parameter
18060 \begin_inset LatexCommand \index{function parameter}
18064 onwards will be passed on the stack, the parameters are pushed from right
18066 before the call the second leftmost parameter will be on the top of the
18067 stack (the leftmost parameter is passed in registers).
18068 Here is an example:
18071 \begin_layout Verse
18074 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18079 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18088 return asm_func(i,j,k);
18102 return c_func(10,9,8);
18107 \begin_layout Standard
18108 The corresponding (unoptimized) assembler routine is:
18111 \begin_layout Verse
18131 _bp,sp\InsetSpace ~
18137 ;stack contains: _bp, return
18138 address, second parameter, third parameter
18162 a,#0xfd\InsetSpace ~
18168 pointer to the second parameter
18192 a,#0xfc\InsetSpace ~
18198 to the rightmost parameter
18239 result (= sum of all three parameters)
18254 ;return value goes into dptr
18288 \begin_layout Standard
18289 The compiling and linking procedure remains the same, however note the extra
18290 entry & exit linkage required for the assembler code, _bp is the stack
18291 frame pointer and is used to compute the offset into the stack for parameters
18292 and local variables.
18293 \begin_inset VSpace bigskip
18299 \begin_layout Section
18301 \begin_inset LatexCommand \index{int (16 bit)}
18306 \begin_inset LatexCommand \index{long (32 bit)}
18313 \begin_layout Standard
18314 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18315 multiplication and modulus operations are implemented by support routines.
18316 These support routines are all developed in ANSI-C to facilitate porting
18317 to other MCUs, although some model specific assembler optimizations are
18319 The following files contain the described routines, all of them can be
18320 found in <installdir>/share/sdcc/lib.
18325 \begin_layout Standard
18327 \begin_inset Tabular
18328 <lyxtabular version="3" rows="11" columns="2">
18330 <column alignment="left" valignment="top" leftline="true" width="0">
18331 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18332 <row topline="true" bottomline="true">
18333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18336 \begin_layout Standard
18344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18347 \begin_layout Standard
18356 <row topline="true">
18357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18360 \begin_layout Standard
18366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18369 \begin_layout Standard
18370 16 bit multiplication
18376 <row topline="true">
18377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18380 \begin_layout Standard
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18389 \begin_layout Standard
18390 signed 16 bit division (calls _divuint)
18396 <row topline="true">
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18400 \begin_layout Standard
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18409 \begin_layout Standard
18410 unsigned 16 bit division
18416 <row topline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18420 \begin_layout Standard
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18429 \begin_layout Standard
18430 signed 16 bit modulus (calls _moduint)
18436 <row topline="true">
18437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18440 \begin_layout Standard
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18449 \begin_layout Standard
18450 unsigned 16 bit modulus
18456 <row topline="true">
18457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18460 \begin_layout Standard
18466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18469 \begin_layout Standard
18470 32 bit multiplication
18476 <row topline="true">
18477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18480 \begin_layout Standard
18486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18489 \begin_layout Standard
18490 signed 32 division (calls _divulong)
18496 <row topline="true">
18497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18500 \begin_layout Standard
18506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18509 \begin_layout Standard
18510 unsigned 32 division
18516 <row topline="true">
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18520 \begin_layout Standard
18526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18529 \begin_layout Standard
18530 signed 32 bit modulus (calls _modulong)
18536 <row topline="true" bottomline="true">
18537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18540 \begin_layout Standard
18546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18549 \begin_layout Standard
18550 unsigned 32 bit modulus
18565 \begin_layout Standard
18566 Since they are compiled as
18571 \begin_inset LatexCommand \index{reentrant}
18576 \begin_inset LatexCommand \index{interrupt}
18580 service routines should not do any of the above operations.
18581 If this is unavoidable then the above routines will need to be compiled
18588 \begin_layout Standard
18598 \begin_inset LatexCommand \index{-\/-stack-auto}
18604 option, after which the source program will have to be compiled with
18610 \begin_layout Standard
18620 \begin_inset LatexCommand \index{-\/-int-long-reent}
18627 Notice that you don't have to call these routines directly.
18628 The compiler will use them automatically every time an integer operation
18632 \begin_layout Section
18633 Floating Point Support
18634 \begin_inset LatexCommand \index{Floating point support}
18641 \begin_layout Standard
18642 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18643 The floating point support routines are derived from gcc's floatlib.c and
18644 consist of the following routines:
18649 \begin_layout Standard
18653 \begin_inset Tabular
18654 <lyxtabular version="3" rows="17" columns="2">
18656 <column alignment="left" valignment="top" leftline="true" width="0">
18657 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18658 <row topline="true" bottomline="true">
18659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18662 \begin_layout Standard
18677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18680 \begin_layout Standard
18687 <row topline="true">
18688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18691 \begin_layout Standard
18706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18709 \begin_layout Standard
18719 add floating point numbers
18725 <row topline="true">
18726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18729 \begin_layout Standard
18744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18747 \begin_layout Standard
18757 subtract floating point numbers
18763 <row topline="true">
18764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18767 \begin_layout Standard
18782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18785 \begin_layout Standard
18795 divide floating point numbers
18801 <row topline="true">
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18805 \begin_layout Standard
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18823 \begin_layout Standard
18833 multiply floating point numbers
18839 <row topline="true">
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18843 \begin_layout Standard
18858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18861 \begin_layout Standard
18871 convert floating point to unsigned char
18877 <row topline="true">
18878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18881 \begin_layout Standard
18896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18899 \begin_layout Standard
18909 convert floating point to signed char
18915 <row topline="true">
18916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18919 \begin_layout Standard
18934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18937 \begin_layout Standard
18947 convert floating point to unsigned int
18953 <row topline="true">
18954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18957 \begin_layout Standard
18972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18975 \begin_layout Standard
18985 convert floating point to signed int
18991 <row topline="true">
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18995 \begin_layout Standard
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19021 \begin_layout Standard
19031 convert floating point to unsigned long
19037 <row topline="true">
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19041 \begin_layout Standard
19056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19059 \begin_layout Standard
19069 convert floating point to signed long
19075 <row topline="true">
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19079 \begin_layout Standard
19094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19097 \begin_layout Standard
19107 convert unsigned char to floating point
19113 <row topline="true">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19117 \begin_layout Standard
19132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19135 \begin_layout Standard
19145 convert char to floating point number
19151 <row topline="true">
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19155 \begin_layout Standard
19170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19173 \begin_layout Standard
19183 convert unsigned int to floating point
19189 <row topline="true">
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19193 \begin_layout Standard
19208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19211 \begin_layout Standard
19221 convert int to floating point numbers
19227 <row topline="true">
19228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19231 \begin_layout Standard
19246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19249 \begin_layout Standard
19259 convert unsigned long to floating point number
19265 <row topline="true" bottomline="true">
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19269 \begin_layout Standard
19284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19287 \begin_layout Standard
19297 convert long to floating point number
19312 \begin_layout Standard
19313 These support routines are developed in ANSI-C so there is room for space
19314 and speed improvement
19318 \begin_layout Standard
19319 These floating point routines (
19323 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19330 Note if all these routines are used simultaneously the data space might
19332 For serious floating point usage the large model might be needed.
19333 Also notice that you don't have to call this routines directly.
19334 The compiler will use them automatically every time a floating point operation
19336 \begin_inset VSpace bigskip
19342 \begin_layout Section
19344 \begin_inset LatexCommand \index{Libraries}
19351 \begin_layout Standard
19354 <pending: this is messy and incomplete - a little more information is in
19355 sdcc/doc/libdoc.txt
19360 \begin_layout Subsection
19361 Compiler support routines (_gptrget, _mulint etc.)
19364 \begin_layout Subsection
19365 Stdclib functions (puts, printf, strcat etc.)
19368 \begin_layout Subsubsection
19372 \begin_layout Paragraph
19373 getchar(), putchar()
19376 \begin_layout Standard
19377 \begin_inset LatexCommand \index{<stdio.h>}
19381 As usual on embedded systems you have to provide your own
19384 \begin_inset LatexCommand \index{getchar()}
19393 \begin_inset LatexCommand \index{putchar()}
19400 SDCC does not know whether the system connects to a serial line with or
19401 without handshake, LCD, keyboard or other device.
19415 You'll find examples for serial routines f.e.
19416 in sdcc/device/lib.
19417 For the mcs51 this minimalistic polling
19421 routine might be a start:
19424 \begin_layout Verse
19427 void putchar (char c) {
19433 while (!TI)\InsetSpace ~
19436 /* assumes UART is initialized */
19464 \begin_layout Paragraph
19468 \begin_layout Standard
19472 \begin_inset LatexCommand \index{printf()}
19482 does not support float (except on ds390).
19483 To enable this recompile it with the option
19489 \begin_layout Standard
19499 \begin_inset LatexCommand \index{USE\_FLOATS}
19505 on the command line.
19512 \begin_layout Standard
19522 \begin_inset LatexCommand \index{-\/-model-large}
19528 for the mcs51 port, since this uses a lot of memory.
19531 \begin_layout Standard
19532 If you're short on code memory you might want to use
19535 \begin_inset LatexCommand \index{printf\_small()}
19550 For the mcs51 there additionally are assembly versions
19553 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19559 (subset of printf using less than 270 bytes) and
19562 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19571 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19577 (floating-point aware version of printf_fast) which should fit the requirements
19578 of many embedded systems (printf_fast() can be customized by unsetting
19583 support long variables and field widths).
19584 Be sure to use only one of these printf options within a project.
19589 \begin_layout Standard
19590 Feature matrix of different
19597 \begin_layout Standard
19598 \begin_inset Tabular
19599 <lyxtabular version="3" rows="14" columns="7">
19600 <features islongtable="true">
19601 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19602 <column alignment="center" valignment="top" leftline="true" width="0">
19603 <column alignment="center" valignment="top" leftline="true" width="12col%">
19604 <column alignment="center" valignment="top" leftline="true" width="10col%">
19605 <column alignment="center" valignment="top" leftline="true" width="0">
19606 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19607 <column alignment="center" valignment="top" rightline="true" width="0">
19608 <row topline="true" bottomline="true" endhead="true">
19609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19612 \begin_layout Standard
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_layout Standard
19626 \begin_inset LatexCommand \index{printf}
19635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19638 \begin_layout Standard
19646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19649 \begin_layout Standard
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19658 \begin_layout Standard
19664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19667 \begin_layout Standard
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19676 \begin_layout Standard
19683 <row topline="true" endhead="true">
19684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19687 \begin_layout Standard
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19696 \begin_layout Standard
19704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19707 \begin_layout Standard
19715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19718 \begin_layout Standard
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19729 \begin_layout Standard
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19740 \begin_layout Standard
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19751 \begin_layout Standard
19760 <row topline="true" endhead="true">
19761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19764 \begin_layout Standard
19765 \begin_inset Quotes sld
19769 \begin_inset Quotes srd
19775 \begin_layout Standard
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19784 \begin_layout Standard
19790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19793 \begin_layout Standard
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
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" rightline="true" usebox="none">
19829 \begin_layout Standard
19836 <row topline="true" endhead="true">
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19840 \begin_layout Standard
19844 \begin_layout Standard
19850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19853 \begin_layout Standard
19859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19862 \begin_layout Standard
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19871 \begin_layout Standard
19872 0.45k / 0.47k (+ _ltoa)
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19880 \begin_layout Standard
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19889 \begin_layout Standard
19895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19898 \begin_layout Standard
19905 <row topline="true">
19906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19909 \begin_layout Standard
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19918 \begin_layout Standard
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_layout Standard
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19981 \begin_layout Standard
20020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20023 \begin_layout Standard
20029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20032 \begin_layout Standard
20038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20041 \begin_layout Standard
20048 <row topline="true">
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20052 \begin_layout Standard
20053 long (32 bit) support
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20061 \begin_layout Standard
20067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_layout Standard
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_layout Standard
20085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20088 \begin_layout Standard
20094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20097 \begin_layout Standard
20112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20115 \begin_layout Standard
20122 <row topline="true">
20123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20126 \begin_layout Standard
20127 byte arguments on stack
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20135 \begin_layout Standard
20141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20144 \begin_layout Standard
20150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20153 \begin_layout Standard
20159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20162 \begin_layout Standard
20168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20171 \begin_layout Standard
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20180 \begin_layout Standard
20187 <row topline="true">
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20191 \begin_layout Standard
20193 \begin_inset LatexCommand \index{Floating point support}
20202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20205 \begin_layout Standard
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20214 \begin_layout Standard
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_layout Standard
20229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20232 \begin_layout Standard
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20241 \begin_layout Standard
20246 \begin_layout Standard
20247 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20260 \begin_layout Standard
20267 <row topline="true">
20268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20271 \begin_layout Standard
20272 float formats %e %g
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20280 \begin_layout Standard
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20289 \begin_layout Standard
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20298 \begin_layout Standard
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_layout Standard
20313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20316 \begin_layout Standard
20322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20325 \begin_layout Standard
20332 <row topline="true" bottomline="true">
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20336 \begin_layout Standard
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20345 \begin_layout Standard
20351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20354 \begin_layout Standard
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_layout Standard
20369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20372 \begin_layout Standard
20378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20381 \begin_layout Standard
20387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20390 \begin_layout Standard
20397 <row bottomline="true">
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20401 \begin_layout Standard
20406 \begin_layout Standard
20407 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20411 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20419 \begin_layout Standard
20425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20428 \begin_layout Standard
20434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20437 \begin_layout Standard
20443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20446 \begin_layout Standard
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 \begin_layout Standard
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_layout Standard
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20473 \begin_layout Standard
20480 <row bottomline="true">
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20484 \begin_layout Standard
20489 \begin_layout Standard
20490 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20499 \begin_layout Standard
20505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20508 \begin_layout Standard
20514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20517 \begin_layout Standard
20523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20526 \begin_layout Standard
20532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20535 \begin_layout Standard
20541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20544 \begin_layout Standard
20550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20553 \begin_layout Standard
20558 \begin_layout Standard
20559 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20570 <row bottomline="true">
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20574 \begin_layout Standard
20579 \begin_layout Standard
20580 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20589 \begin_layout Standard
20595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20598 \begin_layout Standard
20604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20607 \begin_layout Standard
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20616 \begin_layout Standard
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20625 \begin_layout Standard
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20634 \begin_layout Standard
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20643 \begin_layout Standard
20650 <row bottomline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20659 \begin_layout Standard
20660 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20669 \begin_layout Standard
20675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20678 \begin_layout Standard
20684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20687 \begin_layout Standard
20693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20696 \begin_layout Standard
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20705 \begin_layout Standard
20711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20714 \begin_layout Standard
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20723 \begin_layout Standard
20737 \begin_layout Subsubsection
20739 \begin_inset LatexCommand \index{malloc.h}
20746 \begin_layout Standard
20747 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20748 using dynamic memory allocation
20749 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20754 \begin_inset LatexCommand \index{heap (malloc)}
20758 space of 1024 bytes is provided for malloc to allocate memory from.
20759 If you need a different heap size you need to recompile _heap.c with the
20760 required size defined in HEAP_SIZE.
20761 It is recommended to make a copy of this file into your project directory
20762 and compile it there with:
20765 \begin_layout Verse
20768 sdcc -c _heap.c -D HEAD_SIZE=2048
20771 \begin_layout Standard
20772 And then link it with:
20775 \begin_layout Verse
20778 sdcc main.rel _heap.rel
20781 \begin_layout Subsection
20782 Math functions (sinf, powf, sqrtf etc.)
20785 \begin_layout Subsubsection
20789 \begin_layout Standard
20790 See definitions in file <math.h>.
20793 \begin_layout Subsection
20797 \begin_layout Standard
20799 \begin_inset LatexCommand \index{Libraries}
20803 included in SDCC should have a license at least as liberal as the GNU Lesser
20804 General Public License
20805 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20816 \begin_layout Standard
20817 \begin_inset Note Note
20820 \begin_layout Standard
20821 license statements for the libraries are missing.
20822 sdcc/device/lib/ser_ir.c
20825 \begin_layout Standard
20827 come with a GPL (as opposed to LGPL) License - this will not be liberal
20828 enough for many embedded programmers.
20836 \begin_layout Standard
20837 If you have ported some library or want to share experience about some code
20839 falls into any of these categories Busses (I
20840 \begin_inset Formula $^{\textrm{2}}$
20843 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20844 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20845 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20846 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20851 would certainly like to hear about it.
20854 \begin_layout Standard
20855 Programmers coding for embedded systems are not especially famous for being
20856 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20857 e these references are very valuable.
20858 Let's help to create a climate where information is shared.
20859 \begin_inset VSpace bigskip
20865 \begin_layout Section
20869 \begin_layout Subsection
20870 MCS51 Memory Models
20871 \begin_inset LatexCommand \index{Memory model}
20876 \begin_inset LatexCommand \index{MCS51 memory model}
20883 \begin_layout Subsubsection
20884 Small, Medium and Large
20887 \begin_layout Standard
20888 SDCC allows three memory models for MCS51 code,
20897 Modules compiled with different memory models should
20901 be combined together or the results would be unpredictable.
20902 The library routines supplied with the compiler are compiled as small,
20904 The compiled library modules are contained in separate directories as small,
20905 medium and large so that you can link to the appropriate set.
20908 \begin_layout Standard
20909 When the medium or large model is used all variables declared without a
20910 storage class will be allocated into the external ram, this includes all
20911 parameters and local variables (for non-reentrant
20912 \begin_inset LatexCommand \index{reentrant}
20917 When the small model is used variables without storage class are allocated
20918 in the internal ram.
20921 \begin_layout Standard
20922 Judicious usage of the processor specific storage classes
20923 \begin_inset LatexCommand \index{Storage class}
20927 and the 'reentrant' function type will yield much more efficient code,
20928 than using the large model.
20929 Several optimizations are disabled when the program is compiled using the
20930 large model, it is therefore recommended that the small model be used unless
20931 absolutely required.
20934 \begin_layout Subsubsection
20936 \begin_inset LatexCommand \label{sub:External-Stack}
20941 \begin_inset LatexCommand \index{stack}
20946 \begin_inset LatexCommand \index{External stack (mcs51)}
20953 \begin_layout Standard
20954 The external stack (-
20958 \begin_layout Standard
20968 \begin_inset LatexCommand \index{-\/-xstack}
20972 ) is located in pdata
20973 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20977 memory (usually at the start of the external ram segment) and uses all
20978 unused space in pdata (max.
20984 \begin_layout Standard
20993 -xstack option is used to compile the program, the parameters and local
20995 \begin_inset LatexCommand \index{local variables}
20999 of all reentrant functions are allocated in this area.
21000 This option is provided for programs with large stack space requirements.
21001 When used with the -
21005 \begin_layout Standard
21015 \begin_inset LatexCommand \index{-\/-stack-auto}
21019 option, all parameters and local variables are allocated on the external
21020 stack (note: support libraries will need to be recompiled with the same
21022 There is a predefined target in the library makefile).
21025 \begin_layout Standard
21026 The compiler outputs the higher order address byte of the external ram segment
21028 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21033 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21037 ), therefore when using the External Stack option, this port
21041 be used by the application program.
21044 \begin_layout Subsection
21046 \begin_inset LatexCommand \index{Memory model}
21051 \begin_inset LatexCommand \index{DS390 memory model}
21058 \begin_layout Standard
21059 The only model supported is Flat 24
21060 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21065 This generates code for the 24 bit contiguous addressing mode of the Dallas
21067 In this mode, up to four meg of external RAM or code space can be directly
21069 See the data sheets at www.dalsemi.com for further information on this part.
21074 that the compiler does not generate any code to place the processor into
21075 24 bitmode (although
21079 in the ds390 libraries will do that for you).
21085 \begin_inset LatexCommand \index{Tinibios (DS390)}
21089 , the boot loader or similar code must ensure that the processor is in 24
21090 bit contiguous addressing mode before calling the SDCC startup code.
21101 \begin_layout Standard
21112 option, variables will by default be placed into the XDATA segment.
21117 Segments may be placed anywhere in the 4 meg address space using the usual
21122 \begin_layout Standard
21132 Note that if any segments are located above 64K, the -r flag must be passed
21133 to the linker to generate the proper segment relocations, and the Intel
21134 HEX output format must be used.
21135 The -r flag can be passed to the linker by using the option
21139 on the SDCC command line.
21140 However, currently the linker can not handle code segments > 64k.
21143 \begin_layout Section
21145 \begin_inset LatexCommand \label{sec:Pragmas}
21150 \begin_inset LatexCommand \index{Pragmas}
21157 \begin_layout Standard
21158 Pragmas are used to turn on and/or off certain compiler options.
21159 Some of them are closely related to corresponding command-line options
21161 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21167 Pragmas should be placed before and/or after a function, placing pragmas
21168 inside a function body could have unpredictable results.
21173 following #pragma directives:
21176 \begin_layout Itemize
21182 \begin_inset LatexCommand \index{\#pragma save}
21186 - this will save most current options to the save/restore stack.
21187 See #pragma\InsetSpace ~
21191 \begin_layout Itemize
21197 \begin_inset LatexCommand \index{\#pragma restore}
21201 - will restore saved options from the last save.
21202 saves & restores can be nested.
21203 SDCC uses a save/restore stack: save pushes current options to the stack,
21204 restore pulls current options from the stack.
21205 See #pragma\InsetSpace ~
21211 \begin_layout Itemize
21217 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21222 \begin_inset LatexCommand \index{function prologue}
21226 function1[,function2[,function3...]]
21227 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21231 - The compiler by default uses a caller saves convention for register saving
21232 across function calls, however this can cause unnecessary register pushing
21234 \begin_inset LatexCommand \index{push/pop}
21238 when calling small functions from larger functions.
21239 This option can be used to switch off the register saving convention for
21240 the function names specified.
21241 The compiler will not save registers when calling these functions, extra
21242 code need to be manually inserted at the entry and exit for these functions
21243 to save and restore the registers used by these functions, this can SUBSTANTIAL
21244 LY reduce code and improve run time performance of the generated code.
21245 In the future the compiler (with inter procedural analysis) may be able
21246 to determine the appropriate scheme to use for each function call.
21251 \begin_layout Standard
21260 -callee-saves command line option is used (see page
21261 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21265 ), the function names specified in #pragma\InsetSpace ~
21267 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21271 is appended to the list of functions specified in the command line.
21274 \begin_layout Itemize
21280 \begin_inset LatexCommand \index{\#pragma exclude}
21284 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21285 of pairs of push/pop
21286 \begin_inset LatexCommand \index{push/pop}
21295 \begin_inset LatexCommand \index{interrupt}
21308 The directive should be placed immediately before the ISR function definition
21309 and it affects ALL ISR functions following it.
21310 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21311 exclude\InsetSpace ~
21313 \begin_inset LatexCommand \index{\#pragma exclude}
21318 See also the related keyword _naked
21319 \begin_inset LatexCommand \index{\_naked}
21324 \begin_inset LatexCommand \index{\_\_naked}
21331 \begin_layout Itemize
21337 \begin_inset LatexCommand \index{pedantic}
21342 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21347 \begin_inset LatexCommand \label{ite:less_pedantic}
21351 - the compiler will not warn you anymore for obvious mistakes, you'r on
21353 See also the command line option -
21357 \begin_layout Standard
21367 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21374 More specifically, the following warnings will be disabled:
21376 comparison is always [true/false] due to limited range of data type
21380 overflow in implicit constant conversion
21382 (158); [the (in)famous]
21384 conditional flow changed by optimizer: so said EVELYN the modified DOG
21388 function '[function name]' must return value
21393 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21394 level) are disabled, too, namely:
21397 \begin_inset Note Note
21400 \begin_layout Standard
21401 dunno what comes here - this warning appears to be unused altogether
21410 [left/right] shifting more than size of object changed to zero
21418 integer overflow in expression
21422 unmatched #pragma save and #pragma restore
21426 comparison of 'signed char' with 'unsigned char' requires promotion to int
21430 ISO C90 does not support flexible array members
21434 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21438 \begin_inset Note Note
21441 \begin_layout Standard
21442 appears to be always blank - what was supposed to be here?
21451 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21452 complexity [number]
21457 \begin_layout Itemize
21463 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21467 - the compiler will not warn you anymore about warning number <nnnn>.
21470 \begin_layout Itemize
21476 \begin_inset LatexCommand \index{\#pragma nogcse}
21480 - will stop global common subexpression elimination.
21483 \begin_layout Itemize
21489 \begin_inset LatexCommand \index{\#pragma noinduction}
21493 - will stop loop induction optimizations.
21496 \begin_layout Itemize
21502 \begin_inset LatexCommand \index{\#pragma noinvariant}
21506 - will not do loop invariant optimizations.
21507 For more details see Loop Invariants in section
21508 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21515 \begin_layout Itemize
21521 \begin_inset LatexCommand \index{\#pragma noiv}
21525 - Do not generate interrupt
21526 \begin_inset LatexCommand \index{interrupt}
21531 \begin_inset LatexCommand \index{interrupt vector table}
21535 entries for all ISR functions defined after the pragma.
21536 This is useful in cases where the interrupt vector table must be defined
21537 manually, or when there is a secondary, manually defined interrupt vector
21539 for the autovector feature of the Cypress EZ-USB FX2).
21540 More elegantly this can be achieved by obmitting the optional interrupt
21541 number after the interrupt keyword, see section
21542 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21550 \begin_layout Itemize
21556 \begin_inset LatexCommand \index{\#pragma nojtbound}
21560 - will not generate code for boundary value checking, when switch statements
21561 are turned into jump-tables (dangerous).
21562 For more details see section
21563 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21570 \begin_layout Itemize
21576 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21580 - Will not do loop reversal optimization
21583 \begin_layout Itemize
21589 \begin_inset LatexCommand \index{\#pragma nooverlay}
21593 - the compiler will not overlay the parameters and local variables of a
21597 \begin_layout Itemize
21603 \begin_inset LatexCommand \index{\#pragma stackauto}
21611 \begin_layout Standard
21621 \begin_inset LatexCommand \index{-\/-stack-auto}
21626 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21630 Parameters and Local Variables.
21633 \begin_layout Itemize
21639 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21643 - The compiler will optimize code generation towards fast code, possibly
21644 at the expense of code size.
21645 Currently this has little effect.
21648 \begin_layout Itemize
21654 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21658 - The compiler will optimize code generation towards compact code, possibly
21659 at the expense of code speed.
21660 Currently this has little effect.
21663 \begin_layout Itemize
21669 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21673 - The compiler will attempt to generate code that is both compact and fast,
21674 as long as meeting one goal is not a detriment to the other (this is the
21679 \begin_layout Itemize
21685 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21689 - Generally follow the C89 standard, but allow SDCC features that conflict
21690 with the standard (default).
21693 \begin_layout Itemize
21699 \begin_inset LatexCommand \index{\#pragma std\_c89}
21703 - Follow the C89 standard and disable SDCC features that conflict with the
21707 \begin_layout Itemize
21713 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21717 - Generally follow the C99 standard, but allow SDCC features that conflict
21718 with the standard (incomplete support).
21721 \begin_layout Itemize
21727 \begin_inset LatexCommand \index{\#pragma std\_c99}
21731 - Follow the C99 standard and disable SDCC features that conflict with the
21732 standard (incomplete support).
21735 \begin_layout Itemize
21741 \begin_inset LatexCommand \index{\#pragma codeseg}
21745 - Use this name (max.
21746 8 characters) for the code segment.
21751 \begin_layout Standard
21763 \begin_layout Itemize
21769 \begin_inset LatexCommand \index{\#pragma constseg}
21773 - Use this name (max.
21774 8 characters) for the const segment.
21779 \begin_layout Standard
21791 \begin_layout Standard
21792 The preprocessor SDCPP
21793 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21797 supports the following #pragma directives:
21800 \begin_layout Itemize
21803 pedantic_parse_number
21806 \begin_inset LatexCommand \index{pedantic}
21811 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21816 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21820 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21821 properly and the macro LO_B(3) gets expanded.
21827 \begin_layout Standard
21836 -pedantic-parse-number command line option
21837 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21844 Below is an example on how to use this pragma.
21847 Note: this functionality is not in conformance with standard!
21850 \begin_layout Verse
21853 #pragma pedantic_parse_number +
21854 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21862 #define LO_B(x) ((x) & 0xff)
21866 unsigned char foo(void)
21873 unsigned char c=0xfe-LO_B(3)
21888 \begin_layout Itemize
21894 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21898 (+ | -) - switch _asm _endasm block preprocessing on / off.
21900 You use this prama to define multilines of assembly code.
21901 This will prevent the preprocessor from changing the formating required
21903 Below is an example on how to use this pragma.
21906 \begin_layout Verse
21909 #pragma preproc_asm -
21910 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21916 #define MYDELAY _asm
21921 nop ;my assembly comment...
21935 #pragma preproc_asm
21966 \begin_layout Itemize
21972 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21976 (+ | -) - Allow "naked" hash in macro definition, for example:
21980 #define DIR_LO(x) #(x & 0xff)
21985 Below is an example on how to use this pragma.
21988 \begin_layout Verse
21991 #pragma preproc_asm +
21993 #pragma sdcc_hash +
21994 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22009 mov R6_B3, #(x & 0xff)
22016 mov R7_B3, #((x >> 8) & 0xff)
22040 \begin_layout Standard
22041 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22042 ons which might cause the compiler to generate extra stack and/or data space
22043 to store compiler generated temporary variables.
22044 This usually happens in large functions.
22045 Pragma directives should be used as shown in the following example, they
22046 are used to control options and optimizations for a given function.
22050 \begin_layout Verse
22054 \begin_inset LatexCommand \index{\#pragma save}
22065 /* save the current settings */
22068 \begin_inset LatexCommand \index{\#pragma nogcse}
22077 /* turnoff global subexpression elimination */
22079 #pragma noinduction
22080 \begin_inset LatexCommand \index{\#pragma noinduction}
22084 /* turn off induction optimizations */
22107 \begin_inset LatexCommand \index{\#pragma restore}
22111 /* turn the optimizations back on */
22114 \begin_layout Standard
22115 The compiler will generate a warning message when extra space is allocated.
22116 It is strongly recommended that the save and restore pragma's be used when
22117 changing options for a function.
22126 \begin_layout Section
22127 Defines Created by the Compiler
22130 \begin_layout Standard
22131 The compiler creates the following #defines
22132 \begin_inset LatexCommand \index{\#defines}
22137 \begin_inset LatexCommand \index{Defines created by the compiler}
22146 \begin_layout Standard
22147 \begin_inset Tabular
22148 <lyxtabular version="3" rows="11" columns="2">
22150 <column alignment="left" valignment="top" leftline="true" width="3in">
22151 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22152 <row topline="true" bottomline="true">
22153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22156 \begin_layout Standard
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22167 \begin_layout Standard
22176 <row topline="true">
22177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22180 \begin_layout Standard
22182 \begin_inset LatexCommand \index{SDCC}
22191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22194 \begin_layout Standard
22196 Since version 2.5.6 the version number as an int (ex.
22203 <row topline="true">
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22207 \begin_layout Standard
22209 \begin_inset LatexCommand \index{SDCC\_mcs51}
22214 \begin_inset LatexCommand \index{SDCC\_ds390}
22219 \begin_inset LatexCommand \index{SDCC\_z80}
22228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22231 \begin_layout Standard
22232 depending on the model used (e.g.: -mds390)
22238 <row topline="true">
22239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22242 \begin_layout Standard
22244 \begin_inset LatexCommand \index{\_\_mcs51}
22249 \begin_inset LatexCommand \index{\_\_ds390}
22254 \begin_inset LatexCommand \index{\_\_hc08}
22259 \begin_inset LatexCommand \index{\_\_z80}
22268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22271 \begin_layout Standard
22272 depending on the model used (e.g.
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\_STACK\_AUTO}
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\_SMALL}
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\_MEDIUM}
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\_MODEL\_LARGE}
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\_USE\_XSTACK}
22462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22465 \begin_layout Standard
22472 \begin_layout Standard
22489 <row topline="true">
22490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22493 \begin_layout Standard
22495 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22507 \begin_layout Standard
22518 <row topline="true" bottomline="true">
22519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22522 \begin_layout Standard
22524 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22536 \begin_layout Standard
22554 \begin_layout Chapter
22555 Notes on supported Processors
22558 \begin_layout Section
22560 \begin_inset LatexCommand \label{sub:MCS51-variants}
22565 \begin_inset LatexCommand \index{MCS51 variants}
22572 \begin_layout Standard
22573 MCS51 processors are available from many vendors and come in many different
22575 While they might differ considerably in respect to Special Function Registers
22576 the core MCS51 is usually not modified or is kept compatible.
22580 \begin_layout Subsection
22581 pdata access by SFR
22584 \begin_layout Standard
22585 With the upcome of devices with internal xdata and flash memory devices
22587 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22591 as dedicated I/O port is becoming more popular.
22592 Switching the high byte for pdata
22593 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22597 access which was formerly done by port P2 is then achieved by a Special
22599 \begin_inset LatexCommand \index{sfr}
22604 In well-established MCS51 tradition the address of this
22608 is where the chip designers decided to put it.
22609 Needless to say that they didn't agree on a common name either.
22610 So that the startup code can correctly initialize xdata variables, you
22611 should define an sfr with the name _XPAGE
22614 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22620 at the appropriate location if the default, port P2, is not used for this.
22624 \begin_layout Verse
22627 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22631 \begin_layout Verse
22634 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22639 \begin_layout Verse
22642 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22646 \begin_layout Verse
22649 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22653 \begin_layout Verse
22656 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22660 \begin_layout Standard
22661 For more exotic implementations further customizations may be needed.
22663 \begin_inset LatexCommand \ref{sub:Startup-Code}
22667 for other possibilities.
22670 \begin_layout Subsection
22671 Other Features available by SFR
22674 \begin_layout Standard
22675 Some MCS51 variants offer features like Double DPTR
22676 \begin_inset LatexCommand \index{DPTR}
22680 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22681 These are currently not used for the MCS51 port.
22682 If you absolutely need them you can fall back to inline assembly or submit
22684 \begin_inset VSpace bigskip
22690 \begin_layout Section
22694 \begin_layout Standard
22696 \begin_inset LatexCommand \index{DS80C400}
22701 \begin_inset LatexCommand \index{DS400}
22705 microcontroller has a rich set of peripherals.
22706 In its built-in ROM library it includes functions to access some of the
22707 features, among them is a TCP stack with IP4 and IP6 support.
22708 Library headers (currently in beta status) and other files are provided
22712 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22718 \begin_inset VSpace bigskip
22724 \begin_layout Section
22725 The Z80 and gbz80 port
22728 \begin_layout Standard
22729 SDCC can target both the Zilog Z80
22730 \begin_inset LatexCommand \index{Z80}
22734 and the Nintendo Gameboy's Z80-like gbz80
22735 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22740 The Z80 port is passed through the same
22743 \begin_inset LatexCommand \index{Regression test}
22750 \begin_inset LatexCommand \ref{sec:Quality-control}
22754 ) as the MCS51 and DS390 ports, so floating point support, support for long
22755 variables and bitfield support is fine.
22756 See mailing lists and forums about interrupt routines.
22759 \begin_layout Standard
22760 As always, the code is the authoritative reference - see z80/ralloc.c and
22763 \begin_inset LatexCommand \index{Z80!stack}
22767 frame is similar to that generated by the IAR Z80 compiler.
22768 IX is used as the base pointer, HL and IY are used as a temporary registers,
22769 and BC and DE are available for holding variables.
22771 \begin_inset LatexCommand \index{Z80!return value}
22775 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22777 The gbz80 port use the same set of registers for the return values, but
22778 in a different order of significance: E (one byte), DE (two bytes), or
22780 \begin_inset VSpace bigskip
22786 \begin_layout Section
22790 \begin_layout Standard
22791 The port to the Freescale/Motorola HC08
22792 \begin_inset LatexCommand \index{HC08}
22796 family has been added in October 2003, and is still undergoing some basic
22798 The code generator is complete, but the register allocation is still quite
22800 Some of the SDCC's standard C library functions have embedded non-HC08
22801 inline assembly and so are not yet usable.
22804 \begin_layout Standard
22805 The HC08 port passes the regression test suite (see section
22806 \begin_inset LatexCommand \ref{sec:Quality-control}
22811 \begin_inset VSpace bigskip
22819 \begin_layout Section
22823 \begin_layout Standard
22824 The PIC14 port adds support for Microchip(TM)'s 14
22828 \begin_layout Standard
22838 \begin_inset LatexCommand \index{PIC14}
22843 This port is not yet mature and still lacks many features.
22844 However, it can work for simple code.
22847 \begin_layout Standard
22848 Currently supported devices include:
22851 \begin_layout Standard
22852 12F: 629, 635, 675, 683
22855 \begin_layout Standard
22859 \begin_layout Standard
22863 \begin_layout Standard
22864 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22867 \begin_layout Standard
22868 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22872 \begin_layout Standard
22876 \begin_layout Standard
22877 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22881 \begin_layout Standard
22882 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22885 \begin_layout Standard
22886 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22890 \begin_layout Standard
22891 16F: 913, 914, 916, 917
22894 \begin_layout Standard
22895 An up-to-date list of currently supported devices can be obtained via
22897 sdcc -mpic14 -phelp foo.c
22899 (foo.c must exist...).
22902 \begin_layout Subsection
22904 \begin_inset LatexCommand \index{code page (pic14)}
22909 \begin_inset LatexCommand \index{Memory bank (pic14)}
22916 \begin_layout Standard
22917 The linker organizes allocation for the code page and RAM banks.
22918 It does not have intimate knowledge of the code flow.
22919 It will put all the code section of a single .asm file into a single code
22921 In order to make use of multiple code pages, separate asm files must be
22923 The compiler assigns all
22927 functions of a single .c file into the same code page.
22931 To get the best results,
22932 follow these guidelines:
22935 \begin_layout Enumerate
22936 Make local functions static, as non static functions require code page selection
22939 Due to the way sdcc handles functions, place called functions prior
22940 to calling functions in the file wherever possible: Otherwise sdcc will
22941 insert unneccessary pagesel directives around the call, believing that
22942 the called function is externally defined.
22945 \begin_layout Enumerate
22946 For devices that have multiple code pages it is more efficient to use the
22947 same number of files as pages: Use up to 4 separate .c files for the 16F877,
22948 but only 2 files for the 16F874.
22949 This way the linker can put the code for each file into different code
22950 pages and there will be less page selection overhead.
22953 \begin_layout Enumerate
22954 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22955 instruction set), use 'unsigned char' wherever possible instead of 'int'.
22958 \begin_layout Subsection
22959 Adding New Devices to the Port
22962 \begin_layout Standard
22963 Adding support for a new 14
22967 \begin_layout Standard
22976 bit PIC MCU requires the following steps:
22979 \begin_layout Enumerate
22980 Create a new device description.
22982 Each device is described in two files: pic16f*.h
22984 These files primarily define SFRs, structs to access their bits, and symbolic
22985 configuration options.
22986 Both files can be generated from gputils' .inc files using the perl script
22989 support/scripts/inc2h.pl
22992 This file also contains further instructions on how to proceed.
22995 \begin_layout Enumerate
22996 Copy the .h file into SDCC's include path and either add the .c file to your
22997 project or copy it to
22999 device/lib/pic/libdev
23002 Afterwards, rebuild and install the libraries.
23005 \begin_layout Enumerate
23006 Edit pic14devices.txt in SDCC's include path (
23008 device/include/pic/
23010 in the source tree or
23012 /usr/local/share/sdcc/include/pic
23014 after installation).
23016 You need to add a device specification here to make
23017 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23019 Probably you can copy and modify an existing entry.
23020 The file format is documented at the top of the file.
23023 \begin_layout Subsection
23027 \begin_layout Standard
23028 For the interrupt function, use the keyword '__interrupt'
23029 \begin_inset LatexCommand \index{PIC14!interrupt}
23033 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23034 there to avoid a syntax error - it ought to be fixed).
23038 \begin_layout Verse
23041 void Intr(void) __interrupt 0
23047 T0IF = 0; /* Clear timer interrupt */
23052 \begin_layout Subsection
23053 Linking and Assembling
23056 \begin_layout Standard
23057 For assembling you can use either GPUTILS'
23058 \begin_inset LatexCommand \index{gputils (pic tools)}
23062 gpasm.exe or MPLAB's mpasmwin.exe.
23063 GPUTILS are available from
23064 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23069 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23070 If you use MPLAB and an interrupt function then the linker script file
23071 vectors section will need to be enlarged to link with mplink.
23082 \begin_layout Verse
23095 sdcc -V -mpic14 -p16f877 -c $<
23099 $(PRJ).hex: $(OBJS)
23109 gplink -m -s $(PRJ).lkr
23110 -o $(PRJ).hex $(OBJS) libsdcc.lib
23113 \begin_layout Standard
23121 \begin_layout Verse
23134 sdcc -S -V -mpic14 -p16f877 $<
23144 mpasmwin /q /o $*.asm
23148 $(PRJ).hex: $(OBJS)
23159 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23162 \begin_layout Standard
23163 Please note that indentations within a
23167 have to be done with a tabulator character.
23170 \begin_layout Subsection
23171 Command-Line Options
23174 \begin_layout Standard
23175 Besides the switches common to all SDCC backends, the PIC14 port accepts
23176 the following options (for an updated list see sdcc -
23180 \begin_layout Standard
23192 \begin_layout Description
23197 \begin_layout Standard
23207 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23211 emit debug info in assembly output
23214 \begin_layout Description
23219 \begin_layout Standard
23229 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23233 disable (slightly faulty) optimization on pCode
23236 \begin_layout Description
23241 \begin_layout Standard
23251 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23255 sets the lowest address of the argument passing stack (defaults to a suitably
23256 large shared databank to reduce BANKSEL overhead)
23259 \begin_layout Description
23264 \begin_layout Standard
23274 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23278 sets the size if the argument passing stack (default: 16, minimum: 4)
23281 \begin_layout Subsection
23282 Environment Variables
23285 \begin_layout Standard
23286 The PIC14 port recognizes the following environment variables:
23289 \begin_layout Description
23290 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23291 register (the ones called r0xNNNN) in a section of its own.
23292 By default (if this variable is unset), sdcc tries to cluster registers
23293 in sections in order to reduce the BANKSEL overhead when accessing them.
23296 \begin_layout Subsection
23300 \begin_layout Standard
23301 The PIC14 library currently only contains support routines required by the
23302 compiler to implement multiplication, division, and floating point support.
23303 No libc-like replacement is available at the moment, though many of the
23304 common sdcc library sources (in
23308 ) should also compile with the PIC14 port.
23311 \begin_layout Subsubsection
23312 error: missing definition for symbol
23313 \begin_inset Quotes sld
23317 \begin_inset Quotes srd
23323 \begin_layout Standard
23324 The PIC14 port uses library routines to provide more complex operations
23325 like multiplication, division/modulus and (generic) pointer dereferencing.
23326 In order to add these routines to your project, you must link with PIC14's
23332 For single source file projects this is done automatically, more complex
23337 to the linker's arguments.
23338 Make sure you also add an include path for the library (using the -I switch
23342 \begin_layout Subsubsection
23343 Processor mismatch in file
23344 \begin_inset Quotes sld
23348 \begin_inset Quotes srd
23354 \begin_layout Standard
23355 This warning can usually be ignored due to the very good compatibility amongst
23360 \begin_layout Standard
23370 \begin_inset LatexCommand \index{PIC14}
23377 \begin_layout Standard
23378 You might also consider recompiling the library for your specific device
23379 by changing the ARCH=p16f877 (default target) entry in
23381 device/lib/pic/Makefile.in
23385 device/lib/pic/Makefile
23387 to reflect your device.
23388 This might even improve performance for smaller devices as unneccesary
23389 BANKSELs might be removed.
23392 \begin_layout Subsection
23396 \begin_layout Subsubsection
23400 \begin_layout Standard
23401 Functions with variable argument lists (like printf) are not yet supported.
23402 Similarly, taking the argument of the first argument passed into a function
23403 does not work: It is currently passed in WREG and has no address...
23406 \begin_layout Subsubsection
23407 Regression tests fail
23410 \begin_layout Standard
23411 Though the small subset of regression tests in src/regression passes, SDCC
23412 regression test suite does not, indicating that there are still major bugs
23414 However, many smaller projects have successfully used SDCC in the past...
23417 \begin_layout Standard
23425 \begin_layout Section
23427 \begin_inset LatexCommand \index{PIC16}
23434 \begin_layout Standard
23436 \begin_inset LatexCommand \index{PIC16}
23440 port is the portion of SDCC that is responsible to produce code for the
23442 \begin_inset LatexCommand \index{Microchip}
23446 (TM) microcontrollers with 16 bit core.
23447 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23448 Currently supported devices are:
23451 \begin_layout Standard
23452 18F: 242, 248, 252, 258, 442, 448, 452, 458
23455 \begin_layout Standard
23459 \begin_layout Standard
23460 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23463 \begin_layout Standard
23464 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23467 \begin_layout Standard
23468 18F: 6520, 6620, 6680, 6720
23471 \begin_layout Standard
23472 18F: 8520, 8620, 8680, 8720
23475 \begin_layout Subsection
23479 \begin_layout Standard
23480 PIC16 port supports the standard command line arguments as supposed, with
23481 the exception of certain cases that will be mentioned in the following
23485 \begin_layout Description
23490 \begin_layout Standard
23500 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23508 \begin_layout Standard
23520 \begin_layout Description
23525 \begin_layout Standard
23534 -fommit-frame-pointer
23535 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23539 Frame pointer will be omitted when the function uses no local variables.
23542 \begin_layout Subsection
23543 Port Specific Options
23544 \begin_inset LatexCommand \index{Options PIC16}
23551 \begin_layout Standard
23552 The port specific options appear after the global options in the sdcc -
23556 \begin_layout Standard
23568 \begin_layout Subsubsection
23569 Code Generation Options
23572 \begin_layout Standard
23573 These options influence the generated assembler code.
23576 \begin_layout Description
23581 \begin_layout Standard
23590 -pstack-model=[model] Used in conjuction with the command above.
23591 Defines the stack model to be used, valid stack models are:
23596 \labelwidthstring 00.00.0000
23601 Selects small stack model.
23602 8 bit stack and frame pointers.
23603 Supports 256 bytes stack size.
23607 \labelwidthstring 00.00.0000
23612 Selects large stack model.
23613 16 bit stack and frame pointers.
23614 Supports 65536 bytes stack size.
23618 \begin_layout Description
23623 \begin_layout Standard
23632 -pno-banksel Do not generate BANKSEL assembler directives.
23635 \begin_layout Description
23640 \begin_layout Standard
23649 -extended Enable extended instruction set/literal offset addressing mode.
23653 \begin_layout Subsubsection
23654 Optimization Options
23657 \begin_layout Description
23662 \begin_layout Standard
23671 -obanksel=n Set optimization level for inserting BANKSELs.
23678 \labelwidthstring 00.00.0000
23683 \labelwidthstring 00.00.0000
23684 1 checks previous used register and if it is the same then does not emit
23685 BANKSEL, accounts only for labels.
23689 \labelwidthstring 00.00.0000
23690 2 tries to check the location of (even different) symbols and removes BANKSELs
23691 if they are in the same bank.
23696 Important: There might be problems if the linker script has data sections
23697 across bank borders!
23701 \begin_layout Description
23706 \begin_layout Standard
23715 -denable-peeps Force the usage of peepholes.
23719 \begin_layout Description
23724 \begin_layout Standard
23733 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23736 \begin_layout Description
23741 \begin_layout Standard
23750 -optimize-cmp Try to optimize some compares.
23753 \begin_layout Description
23758 \begin_layout Standard
23767 -optimize-df Analyze the dataflow of the generated code and improve it.
23770 \begin_layout Subsubsection
23774 \begin_layout Description
23779 \begin_layout Standard
23788 -asm= Sets the full path and name of an external assembler to call.
23791 \begin_layout Description
23796 \begin_layout Standard
23806 \begin_inset LatexCommand \index{PIC16!MPLAB}
23810 compatibility option.
23811 Currently only suppresses special gpasm directives.
23814 \begin_layout Subsubsection
23818 \begin_layout Description
23823 \begin_layout Standard
23832 -link= Sets the full path and name of an external linker to call.
23835 \begin_layout Description
23840 \begin_layout Standard
23849 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23850 unitialized data variables with [kword].
23851 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23854 \begin_layout Description
23859 \begin_layout Standard
23868 -ivt-loc=n Place the interrupt vector table at address
23873 Useful for bootloaders.
23876 \begin_layout Description
23881 \begin_layout Standard
23890 -nodefaultlibs Do not link default libraries when linking.
23893 \begin_layout Description
23898 \begin_layout Standard
23907 -use-crt= Use a custom run-time module instead of the defaults.
23910 \begin_layout Description
23915 \begin_layout Standard
23924 -no-crt Don't link the default run-time modules
23927 \begin_layout Subsubsection
23931 \begin_layout Standard
23932 Debugging options enable extra debugging information in the output files.
23935 \begin_layout Description
23940 \begin_layout Standard
23949 -debug-xtra Similar to -
23953 \begin_layout Standard
23963 \begin_inset LatexCommand \index{-\/-debug}
23967 , but dumps more information.
23970 \begin_layout Description
23975 \begin_layout Standard
23984 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23986 <source> is the name of the file being compiled.
23989 \begin_layout Description
23994 \begin_layout Standard
24003 -pcode-verbose Enable pcode debugging information in translation.
24006 \begin_layout Description
24011 \begin_layout Standard
24020 -calltree Dump call tree in .calltree file.
24023 \begin_layout Description
24028 \begin_layout Standard
24037 -gstack Trace push/pops for stack pointer overflow.
24040 \begin_layout Subsection
24041 Enviroment Variables
24044 \begin_layout Standard
24045 There is a number of enviromental variables that can be used when running
24046 SDCC to enable certain optimizations or force a specific program behaviour.
24047 these variables are primarily for debugging purposes so they can be enabled/dis
24051 \begin_layout Standard
24052 Currently there is only two such variables available:
24055 \begin_layout Description
24056 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24057 bitfields is optimized by directly loading FSR0 with the address of the
24058 bitfield structure.
24059 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24061 This step saves data ram and code space for functions that make heavy use
24063 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24068 \begin_layout Description
24069 NO_REG_OPT Do not perform pCode registers optimization.
24070 This should be used for debugging purposes.
24071 If bugs in the pcode optimizer are found, users can benefit from temporarily
24072 disabling the optimizer until the bug is fixed.
24075 \begin_layout Subsection
24076 Preprocessor Macros
24079 \begin_layout Standard
24081 \begin_inset LatexCommand \index{PIC16}
24085 port defines the following preprocessor macros while translating a source.
24088 \begin_layout Standard
24090 \begin_inset Tabular
24091 <lyxtabular version="3" rows="6" columns="2">
24093 <column alignment="center" valignment="top" leftline="true" width="0">
24094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24095 <row topline="true" bottomline="true">
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24099 \begin_layout Standard
24105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24108 \begin_layout Standard
24115 <row topline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24119 \begin_layout Standard
24125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24128 \begin_layout Standard
24129 Port identification
24135 <row topline="true">
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24139 \begin_layout Standard
24144 \begin_layout Standard
24158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24161 \begin_layout Standard
24162 Port identification (same as above)
24168 <row topline="true">
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24172 \begin_layout Standard
24178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24181 \begin_layout Standard
24182 MCU Identification.
24187 is the microcontrol identification number, i.e.
24194 <row topline="true">
24195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24198 \begin_layout Standard
24203 \begin_layout Standard
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24220 \begin_layout Standard
24221 MCU Identification (same as above)
24227 <row topline="true" bottomline="true">
24228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24231 \begin_layout Standard
24237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24240 \begin_layout Standard
24241 nnn = SMALL or LARGE respectively according to the stack model used
24254 \begin_layout Standard
24255 In addition the following macros are defined when calling assembler:
24258 \begin_layout Standard
24260 \begin_inset Tabular
24261 <lyxtabular version="3" rows="4" columns="2">
24263 <column alignment="center" valignment="top" leftline="true" width="0">
24264 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24265 <row topline="true" bottomline="true">
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24269 \begin_layout Standard
24275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24278 \begin_layout Standard
24285 <row topline="true">
24286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24289 \begin_layout Standard
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24298 \begin_layout Standard
24299 MCU Identification.
24304 is the microcontrol identification number, i.e.
24311 <row topline="true">
24312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24315 \begin_layout Standard
24321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24324 \begin_layout Standard
24325 nnn = SMALL or LARGE respectively according to the memory model used for
24332 <row topline="true" bottomline="true">
24333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24336 \begin_layout Standard
24342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24345 \begin_layout Standard
24346 nnn = SMALL or LARGE respectively according to the stack model used
24359 \begin_layout Subsection
24363 \begin_layout Standard
24365 \begin_inset LatexCommand \index{PIC16}
24369 port uses the following directories for searching header files and libraries.
24372 \begin_layout Standard
24374 \begin_inset Tabular
24375 <lyxtabular version="3" rows="3" columns="4">
24377 <column alignment="center" valignment="top" leftline="true" width="0">
24378 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24379 <column alignment="center" valignment="top" width="0">
24380 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24381 <row topline="true" bottomline="true">
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24385 \begin_layout Standard
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24394 \begin_layout Standard
24400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24403 \begin_layout Standard
24409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24412 \begin_layout Standard
24419 <row topline="true">
24420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24423 \begin_layout Standard
24424 PREFIX/sdcc/include/pic16
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24432 \begin_layout Standard
24433 PIC16 specific headers
24438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24441 \begin_layout Standard
24447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24450 \begin_layout Standard
24457 <row topline="true" bottomline="true">
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24461 \begin_layout Standard
24462 PREFIX/sdcc/lib/pic16
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24470 \begin_layout Standard
24471 PIC16 specific libraries
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24479 \begin_layout Standard
24485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24488 \begin_layout Standard
24502 \begin_layout Subsection
24504 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24511 \begin_layout Standard
24513 \begin_inset LatexCommand \index{PIC16}
24517 port currently supports the following pragmas:
24520 \begin_layout Description
24522 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24526 This forces the code generator to initialize the stack & frame pointers
24527 at a specific address.
24528 This is an ad hoc solution for cases where no STACK directive is available
24529 in the linker script or gplink is not instructed to create a stack section.
24532 stack pragma should be used only once in a project.
24533 Multiple pragmas may result in indeterminate behaviour of the program.
24537 \begin_layout Standard
24538 The old format (ie.
24539 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24540 cross page boundaries (or even exceed the available data RAM) and crash
24542 Make sure that stack does not cross page boundaries when using the SMALL
24550 The format is as follows:
24555 \begin_layout LyX-Code
24556 #pragma stack bottom_address [stack_size]
24561 \begin_layout Standard
24566 is the lower bound of the stack section.
24567 The stack pointer initially will point at address (bottom_address+stack_size-1).
24570 \begin_layout LyX-Code
24574 \begin_layout LyX-Code
24578 \begin_layout LyX-Code
24579 /* initializes stack of 100 bytes at RAM address 0x200 */
24582 \begin_layout LyX-Code
24583 #pragma stack 0x200 100
24586 \begin_layout Standard
24587 If the stack_size field is omitted then a stack is created with the default
24589 This size might be enough for most programs, but its not enough for operations
24590 with deep function nesting or excessive stack usage.
24593 \begin_layout Description
24595 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24599 Force a function to a static FLASH address.
24602 \begin_layout LyX-Code
24606 \begin_layout LyX-Code
24610 \begin_layout LyX-Code
24611 /* place function test_func at 0x4000 */
24614 \begin_layout LyX-Code
24615 #pragma code test_func 0x4000
24618 \begin_layout LyX-Code
24622 \begin_layout Description
24623 library instructs the linker to use a library module.
24628 \begin_layout LyX-Code
24629 #pragma library module_name
24632 \begin_layout Standard
24637 can be any library or object file (including its path).
24638 Note that there are four reserved keywords which have special meaning.
24642 \begin_layout Standard
24644 \begin_inset Tabular
24645 <lyxtabular version="3" rows="6" columns="3">
24647 <column alignment="center" valignment="top" leftline="true" width="0">
24648 <column alignment="block" valignment="top" leftline="true" width="20page%">
24649 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24650 <row topline="true" bottomline="true">
24651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24654 \begin_layout Standard
24660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24663 \begin_layout Standard
24669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24672 \begin_layout Standard
24679 <row topline="true">
24680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24683 \begin_layout Standard
24691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24694 \begin_layout Standard
24695 ignore all library pragmas
24700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24703 \begin_layout Standard
24712 <row topline="true">
24713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24716 \begin_layout Standard
24724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24727 \begin_layout Standard
24733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24736 \begin_layout Standard
24747 <row topline="true">
24748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24751 \begin_layout Standard
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24762 \begin_layout Standard
24763 link the Math libarary
24768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24771 \begin_layout Standard
24782 <row topline="true">
24783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24786 \begin_layout Standard
24794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24797 \begin_layout Standard
24798 link the I/O library
24803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24806 \begin_layout Standard
24817 <row topline="true" bottomline="true">
24818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24821 \begin_layout Standard
24829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24832 \begin_layout Standard
24833 link the debug library
24838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24841 \begin_layout Standard
24858 * is the device number, i.e.
24859 452 for PIC18F452 MCU.
24862 \begin_layout Standard
24863 This feature allows for linking with specific libraries withoug having to
24864 explicit name them in the command line.
24869 keyword will reject all modules specified by the library pragma.
24872 \begin_layout Description
24873 udata The pragma udata instructs the compiler to emit code so that linker
24874 will place a variable at a specific memory bank.
24877 \begin_layout LyX-Code
24881 \begin_layout LyX-Code
24885 \begin_layout LyX-Code
24886 /* places variable foo at bank2 */
24889 \begin_layout LyX-Code
24890 #pragma udata bank2 foo
24893 \begin_layout LyX-Code
24897 \begin_layout Standard
24898 In order for this pragma to work extra SECTION directives should be added
24899 in the .lkr script.
24900 In the following example a sample .lkr file is shown:
24903 \begin_layout LyX-Code
24907 \begin_layout LyX-Code
24908 // Sample linker script for the PIC18F452 processor
24911 \begin_layout LyX-Code
24915 \begin_layout LyX-Code
24916 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24919 \begin_layout LyX-Code
24920 CODEPAGE NAME=page START=0x2A END=0x7FFF
24923 \begin_layout LyX-Code
24924 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24927 \begin_layout LyX-Code
24928 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24931 \begin_layout LyX-Code
24932 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24935 \begin_layout LyX-Code
24936 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24939 \begin_layout LyX-Code
24940 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24943 \begin_layout LyX-Code
24947 \begin_layout LyX-Code
24948 DATABANK NAME=gpr0 START=0x80 END=0xFF
24951 \begin_layout LyX-Code
24952 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24955 \begin_layout LyX-Code
24956 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24959 \begin_layout LyX-Code
24960 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24963 \begin_layout LyX-Code
24964 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24967 \begin_layout LyX-Code
24968 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24971 \begin_layout LyX-Code
24972 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24975 \begin_layout LyX-Code
24979 \begin_layout LyX-Code
24980 SECTION NAME=CONFIG ROM=config
24983 \begin_layout LyX-Code
24987 \begin_layout LyX-Code
24988 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24991 \begin_layout LyX-Code
24992 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24995 \begin_layout LyX-Code
24996 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24999 \begin_layout LyX-Code
25000 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25003 \begin_layout LyX-Code
25004 SECTION NAME=bank4 RAM=gpr4
25007 \begin_layout LyX-Code
25008 SECTION NAME=bank5 RAM=gpr5
25011 \begin_layout Standard
25012 The linker will recognise the section name set in the pragma statement and
25013 will position the variable at the memory bank set with the RAM field at
25014 the SECTION line in the linker script file.
25017 \begin_layout Subsection
25019 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25026 \begin_layout Standard
25027 There is one main header file
25028 \begin_inset LatexCommand \index{PIC16!Header files}
25032 that can be included to the source files using the pic16
25033 \begin_inset LatexCommand \index{PIC16}
25043 This header file contains the definitions for the processor special registers,
25044 so it is necessary if the source accesses them.
25045 It can be included by adding the following line in the beginning of the
25049 \begin_layout LyX-Code
25050 #include <pic18fregs.h>
25053 \begin_layout Standard
25054 The specific microcontroller is selected within the pic18fregs.h automatically,
25055 so the same source can be used with a variety of devices.
25058 \begin_layout Subsection
25062 \begin_layout Standard
25064 \begin_inset LatexCommand \index{PIC16!Libraries}
25069 \begin_inset LatexCommand \index{PIC16}
25073 port depends on are the microcontroller device libraries which contain
25074 the symbol definitions for the microcontroller special function registers.
25075 These libraries have the format pic18fxxxx.lib, where
25079 is the microcontroller identification number.
25080 The specific library is selected automatically by the compiler at link
25081 stage according to the selected device.
25084 \begin_layout Standard
25085 Libraries are created with gplib which is part of the gputils package
25086 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25093 \begin_layout Subsubsection*
25094 Building the libraries
25097 \begin_layout Standard
25098 Before using SDCC/pic16 there are some libraries that need to be compiled.
25099 This process is not done automatically by SDCC since not all users use
25100 SDCC for pic16 projects.
25101 So each user should compile the libraries separately.
25104 \begin_layout Standard
25105 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25108 \begin_layout LyX-Code
25109 cd device/lib/pic16
25112 \begin_layout LyX-Code
25116 \begin_layout LyX-Code
25120 \begin_layout LyX-Code
25124 \begin_layout LyX-Code
25128 \begin_layout LyX-Code
25129 su -c 'make install' # install the libraries, you need the root password
25132 \begin_layout Standard
25133 If you need to install the headers too, do:
25136 \begin_layout LyX-Code
25140 \begin_layout LyX-Code
25141 su -c 'make install' # install the headers, you need the root password
25144 \begin_layout Standard
25145 There exist a special target to build the I/O libraries.
25146 This target is not automatically build because it will build the I/O library
25152 This way building will take quite a lot of time.
25153 Users are advised to edit the
25155 device/lib/pic16/pics.build
25157 file and then execute:
25160 \begin_layout LyX-Code
25164 \begin_layout Subsection
25165 Adding New Devices to the Port
25168 \begin_layout Standard
25169 Adding support for a new 16
25173 \begin_layout Standard
25182 bit PIC MCU requires the following steps:
25185 \begin_layout Enumerate
25186 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25190 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25194 \begin_layout Enumerate
25197 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25200 \begin_layout Enumerate
25203 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25206 \begin_layout Enumerate
25209 /path/to/sdcc/device/lib/pics.all
25217 Note: No 18f prefix here!
25220 \begin_layout Enumerate
25223 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25227 Add your DEVICE if it does not compile in
25242 \begin_layout Enumerate
25245 /path/to/sdcc/device/include/pic16/pic18fregs.h
25248 The file format is self-explanatory, just add
25252 #elif defined(picDEVICE)
25254 # include <picDEVICE.h>
25258 at the right place (keep it sorted).
25261 \begin_layout Enumerate
25264 /path/to/sdcc/src/pic16/devices.inc
25267 Copy and modify an existing entry and insert it at the correct place (keep
25269 The file is hardly documented, look at the entries for the 18f2221...
25272 \begin_layout Enumerate
25273 Recompile SDCC, including the pic16 libraries.
25276 \begin_layout Subsection
25280 \begin_layout Standard
25281 The following memory models are supported by the PIC16 port:
25284 \begin_layout Itemize
25288 \begin_layout Itemize
25292 \begin_layout Standard
25293 Memory model affects the default size of pointers within the source.
25294 The sizes are shown in the next table:
25297 \begin_layout Standard
25299 \begin_inset Tabular
25300 <lyxtabular version="3" rows="3" columns="3">
25302 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25303 <column alignment="center" valignment="top" leftline="true" width="0">
25304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25305 <row topline="true" bottomline="true">
25306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25309 \begin_layout Standard
25310 Pointer sizes according to memory model
25315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25318 \begin_layout Standard
25324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25327 \begin_layout Standard
25334 <row topline="true" bottomline="true">
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25338 \begin_layout Standard
25344 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25347 \begin_layout Standard
25353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25356 \begin_layout Standard
25363 <row topline="true" bottomline="true">
25364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25367 \begin_layout Standard
25373 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25376 \begin_layout Standard
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25385 \begin_layout Standard
25399 \begin_layout Standard
25400 It is advisable that all sources within a project are compiled with the
25402 If one wants to override the default memory model, this can be done by
25403 declaring a pointer as
25412 Far selects large memory model's pointers, while near selects small memory
25416 \begin_layout Standard
25417 The standard device libraries (see
25418 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25422 ) contain no reference to pointers, so they can be used with both memory
25426 \begin_layout Subsection
25430 \begin_layout Standard
25432 \begin_inset LatexCommand \index{PIC16!stack}
25436 implementation for the PIC16 port uses two indirect registers, FSR1 and
25440 \begin_layout Description
25441 FSR1 is assigned as stack pointer
25444 \begin_layout Description
25445 FSR2 is assigned as frame pointer
25448 \begin_layout Standard
25449 The following stack models are supported by the PIC16 port
25452 \begin_layout Itemize
25460 \begin_layout Itemize
25468 \begin_layout Standard
25473 model means that only the FSRxL byte is used to access stack and frame,
25480 uses both FSRxL and FSRxH registers.
25481 The following table shows the stack/frame pointers sizes according to stack
25482 model and the maximum space they can address:
25485 \begin_layout Standard
25487 \begin_inset Tabular
25488 <lyxtabular version="3" rows="3" columns="3">
25490 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25491 <column alignment="center" valignment="top" leftline="true" width="0">
25492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25493 <row topline="true" bottomline="true">
25494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25497 \begin_layout Standard
25498 Stack & Frame pointer sizes according to stack model
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25506 \begin_layout Standard
25512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25515 \begin_layout Standard
25522 <row topline="true">
25523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25526 \begin_layout Standard
25532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25535 \begin_layout Standard
25541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25544 \begin_layout Standard
25551 <row topline="true" bottomline="true">
25552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25555 \begin_layout Standard
25561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25564 \begin_layout Standard
25570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25573 \begin_layout Standard
25587 \begin_layout Standard
25592 stack model is currently not working properly throughout the code generator.
25593 So its use is not advised.
25594 Also there are some other points that need special care:
25599 \begin_layout Enumerate
25600 Do not create stack sections with size more than one physical bank (that
25604 \begin_layout Enumerate
25605 Stack sections should no cross physical bank limits (i.e.
25606 #pragma stack 0x50 0x100)
25609 \begin_layout Standard
25610 These limitations are caused by the fact that only FSRxL is modified when
25611 using SMALL stack model, so no more than 256 bytes of stack can be used.
25612 This problem will disappear after LARGE model is fully implemented.
25615 \begin_layout Subsection
25619 \begin_layout Standard
25620 In addition to the standard SDCC function keywords, PIC16
25621 \begin_inset LatexCommand \index{PIC16}
25625 port makes available two more:
25628 \begin_layout Description
25630 \begin_inset LatexCommand \index{PIC16!wparam}
25634 Use the WREG to pass one byte of the first function argument.
25635 This improves speed but you may not use this for functions with arguments
25636 that are called via function pointers, otherwise the first byte of the
25637 first parameter will get lost.
25641 \begin_layout LyX-Code
25642 void func_wparam(int a) wparam
25645 \begin_layout LyX-Code
25649 \begin_layout LyX-Code
25650 /* WREG hold the lower part of a */
25653 \begin_layout LyX-Code
25654 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25658 \begin_layout LyX-Code
25662 \begin_layout LyX-Code
25666 \begin_layout Description
25668 \begin_inset LatexCommand \index{PIC16!shadowregs}
25672 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25673 hardware shadow registers which hold the values of WREG, STATUS and BSR
25675 This can be done by adding the keyword
25683 keyword in the function's header.
25686 \begin_layout LyX-Code
25687 void isr_shadow(void) shadowregs interrupt 1
25690 \begin_layout LyX-Code
25694 \begin_layout LyX-Code
25698 \begin_layout LyX-Code
25702 \begin_layout Standard
25707 instructs the code generator not to store/restore WREG, STATUS, BSR when
25708 entering/exiting the ISR.
25711 \begin_layout Subsection
25712 Function return values
25715 \begin_layout Standard
25716 Return values from functions are placed to the appropriate registers following
25717 a modified Microchip policy optimized for SDCC.
25718 The following table shows these registers:
25721 \begin_layout Standard
25723 \begin_inset Tabular
25724 <lyxtabular version="3" rows="6" columns="2">
25726 <column alignment="center" valignment="top" leftline="true" width="0">
25727 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25728 <row topline="true" bottomline="true">
25729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25732 \begin_layout Standard
25738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25741 \begin_layout Standard
25742 destination register
25748 <row topline="true">
25749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25752 \begin_layout Standard
25758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25761 \begin_layout Standard
25768 <row topline="true">
25769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25772 \begin_layout Standard
25778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25781 \begin_layout Standard
25788 <row topline="true">
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25792 \begin_layout Standard
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25801 \begin_layout Standard
25808 <row topline="true">
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25812 \begin_layout Standard
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25821 \begin_layout Standard
25822 FSR0L:PRODH:PRODL:WREG
25828 <row topline="true" bottomline="true">
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25832 \begin_layout Standard
25838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25841 \begin_layout Standard
25842 on stack, FSR0 points to the beginning
25855 \begin_layout Subsection
25859 \begin_layout Standard
25861 \begin_inset LatexCommand \index{PIC16!interrupt}
25865 service routine (ISR) is declared using the
25872 \begin_layout LyX-Code
25873 void isr(void) interrupt
25878 \begin_layout LyX-Code
25882 \begin_layout LyX-Code
25886 \begin_layout LyX-Code
25890 \begin_layout Standard
25895 is the interrupt number, which for PIC18F devices can be:
25898 \begin_layout Standard
25900 \begin_inset Tabular
25901 <lyxtabular version="3" rows="4" columns="3">
25903 <column alignment="center" valignment="top" leftline="true" width="0">
25904 <column alignment="center" valignment="top" leftline="true" width="0">
25905 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25906 <row topline="true" bottomline="true">
25907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25910 \begin_layout Standard
25918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25921 \begin_layout Standard
25927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25930 \begin_layout Standard
25931 Interrupt Vector Address
25937 <row topline="true">
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25941 \begin_layout Standard
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25950 \begin_layout Standard
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25959 \begin_layout Standard
25966 <row topline="true">
25967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25970 \begin_layout Standard
25985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25988 \begin_layout Standard
25998 HIGH priority interrupts
26003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26006 \begin_layout Standard
26013 <row topline="true" bottomline="true">
26014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26017 \begin_layout Standard
26023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26026 \begin_layout Standard
26027 LOW priority interrupts
26032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26035 \begin_layout Standard
26049 \begin_layout Standard
26050 When generating assembly code for ISR the code generator places a
26056 Interrupt Vector Address
26058 which points at the genetated ISR.
26059 This single GOTO instruction is part of an automatically generated
26061 interrupt entry point
26064 The actuall ISR code is placed as normally would in the code space.
26065 Upon interrupt request, the GOTO instruction is executed which jumps to
26067 When declaring interrupt functions as _naked this GOTO instruction is
26072 The whole interrupt functions is therefore placed at the Interrupt Vector
26073 Address of the specific interrupt.
26074 This is not a problem for the LOW priority interrupts, but it is a problem
26075 for the RESET and the HIGH priority interrupts because code may be written
26076 at the next interrupt´s vector address and cause undeterminate program
26077 behaviour if that interrupt is raised.
26081 \begin_layout Standard
26082 This is not a problem when
26085 \begin_layout Enumerate
26086 this is a HIGH interrupt ISR and LOW interrupts are
26093 \begin_layout Enumerate
26094 when the ISR is small enough not to reach the next interrupt´s vector address.
26102 \begin_layout Standard
26107 is possible to be omitted.
26108 This way a function is generated similar to an ISR, but it is not assigned
26112 \begin_layout Standard
26113 When entering an interrupt, currently the PIC16
26114 \begin_inset LatexCommand \index{PIC16}
26118 port automatically saves the following registers:
26121 \begin_layout Itemize
26125 \begin_layout Itemize
26129 \begin_layout Itemize
26133 \begin_layout Itemize
26134 PROD (PRODL and PRODH)
26137 \begin_layout Itemize
26138 FSR0 (FSR0L and FSR0H)
26141 \begin_layout Standard
26142 These registers are restored upon return from the interrupt routine.
26146 \begin_layout Standard
26147 NOTE that when the _naked attribute is specified for an interrupt routine,
26148 then NO registers are stored or restored.
26156 \begin_layout Subsection
26160 \begin_layout Standard
26161 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26162 There are 3 types of generic pointers currently implemented data, code
26163 and eeprom pointers.
26164 They are differentiated by the value of the 7th and 6th bits of the upper
26168 \begin_layout Standard
26170 \begin_inset Tabular
26171 <lyxtabular version="3" rows="5" columns="5">
26173 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26174 <column alignment="center" valignment="top" width="0">
26175 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26176 <column alignment="center" valignment="top" width="0">
26177 <column alignment="left" valignment="top" rightline="true" width="0">
26178 <row topline="true" bottomline="true">
26179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26182 \begin_layout Standard
26188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26191 \begin_layout Standard
26197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26200 \begin_layout Standard
26206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26209 \begin_layout Standard
26210 rest of the pointer
26215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26218 \begin_layout Standard
26225 <row topline="true" bottomline="true">
26226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26229 \begin_layout Standard
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" rightline="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
26261 uuuuuu uuuuxxxx xxxxxxxx
26266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26269 \begin_layout Standard
26270 a 12-bit data pointer in data RAM memory
26276 <row bottomline="true">
26277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_layout Standard
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" rightline="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
26312 uxxxxx xxxxxxxx xxxxxxxx
26317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26320 \begin_layout Standard
26321 a 21-bit code pointer in FLASH memory
26327 <row bottomline="true">
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26331 \begin_layout Standard
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" rightline="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
26363 uuuuuu uuuuuuxx xxxxxxxx
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26371 \begin_layout Standard
26372 a 10-bit eeprom pointer in EEPROM memory
26378 <row bottomline="true">
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26382 \begin_layout Standard
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26391 \begin_layout Standard
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26400 \begin_layout Standard
26406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26409 \begin_layout Standard
26414 xxxxxx xxxxxxxx xxxxxxxx
26419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26422 \begin_layout Standard
26423 unimplemented pointer type
26436 \begin_layout Standard
26437 Generic pointer are read and written with a set of library functions which
26438 read/write 1, 2, 3, 4 bytes.
26441 \begin_layout Subsection
26445 \begin_layout Subsubsection
26446 Standard I/O Streams
26449 \begin_layout Standard
26454 the type FILE is defined as:
26457 \begin_layout LyX-Code
26458 typedef char * FILE;
26461 \begin_layout Standard
26462 This type is the stream type implemented I/O in the PIC18F devices.
26463 Also the standard input and output streams are declared in stdio.h:
26466 \begin_layout LyX-Code
26467 extern FILE * stdin;
26470 \begin_layout LyX-Code
26471 extern FILE * stdout;
26474 \begin_layout Standard
26475 The FILE type is actually a generic pointer which defines one more type
26476 of generic pointers, the
26481 This new type has the format:
26484 \begin_layout Standard
26486 \begin_inset Tabular
26487 <lyxtabular version="3" rows="2" columns="7">
26489 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26490 <column alignment="center" valignment="top" width="0">
26491 <column alignment="center" valignment="top" leftline="true" width="0">
26492 <column alignment="center" valignment="top" leftline="true" width="0">
26493 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26494 <column alignment="center" valignment="top" width="0">
26495 <column alignment="left" valignment="top" rightline="true" width="0">
26496 <row topline="true" bottomline="true">
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26500 \begin_layout Standard
26506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26509 \begin_layout Standard
26515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26518 \begin_layout Standard
26524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26527 \begin_layout Standard
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26536 \begin_layout Standard
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26545 \begin_layout Standard
26546 rest of the pointer
26551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26554 \begin_layout Standard
26561 <row topline="true" bottomline="true">
26562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26565 \begin_layout Standard
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26574 \begin_layout Standard
26580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26583 \begin_layout Standard
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26592 \begin_layout Standard
26598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26601 \begin_layout Standard
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26610 \begin_layout Standard
26620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26623 \begin_layout Standard
26624 upper byte high nubble is 0x2n, the rest are zeroes
26637 \begin_layout Standard
26638 Currently implemented there are 3 types of streams defined:
26641 \begin_layout Standard
26643 \begin_inset Tabular
26644 <lyxtabular version="3" rows="4" columns="4">
26646 <column alignment="center" valignment="top" leftline="true" width="0">
26647 <column alignment="center" valignment="top" leftline="true" width="0">
26648 <column alignment="center" valignment="top" leftline="true" width="0">
26649 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26650 <row topline="true" bottomline="true">
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26654 \begin_layout Standard
26660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26663 \begin_layout Standard
26669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26672 \begin_layout Standard
26678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26681 \begin_layout Standard
26688 <row topline="true">
26689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26692 \begin_layout Standard
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26701 \begin_layout Standard
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_layout Standard
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26721 \begin_layout Standard
26722 Writes/Reads characters via the USART peripheral
26728 <row topline="true">
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26732 \begin_layout Standard
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26741 \begin_layout Standard
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26752 \begin_layout Standard
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26761 \begin_layout Standard
26762 Writes/Reads characters via the MSSP peripheral
26768 <row topline="true" bottomline="true">
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26772 \begin_layout Standard
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26781 \begin_layout Standard
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26792 \begin_layout Standard
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26801 \begin_layout Standard
26802 Writes/Reads characters via used defined functions
26815 \begin_layout Standard
26816 The stream identifiers are declared as macros in the stdio.h header.
26819 \begin_layout Standard
26820 In the libc library there exist the functions that are used to write to
26821 each of the above streams.
26825 \begin_layout Description
26830 \begin_layout Standard
26839 _stream_usart_putchar writes a character at the USART stream
26842 \begin_layout Description
26847 \begin_layout Standard
26856 _stream_mssp_putchar writes a character at the MSSP stream
26859 \begin_layout Description
26860 putchar dummy function.
26861 This writes a character to a user specified manner.
26864 \begin_layout Standard
26865 In order to increase performance
26869 is declared in stdio.h as having its parameter in WREG (it has the wparam
26871 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26872 in a user-friendly way.
26877 is the name of the variable that holds the character to print.
26878 An example follows:
26881 \begin_layout LyX-Code
26882 #include <pic18fregs.h>
26891 \begin_layout LyX-Code
26895 \begin_layout LyX-Code
26896 PORTA = c; /* dump character c to PORTA */
26899 \begin_layout LyX-Code
26907 \begin_layout LyX-Code
26911 \begin_layout LyX-Code
26912 stdout = STREAM_USER; /* this is not necessary, since stdout points
26915 \begin_layout LyX-Code
26916 * by default to STREAM_USER */
26919 \begin_layout LyX-Code
26921 \begin_inset Quotes sld
26924 This is a printf test
26927 \begin_inset Quotes srd
26933 \begin_layout LyX-Code
26937 \begin_layout LyX-Code
26941 \begin_layout Subsubsection
26945 \begin_layout Standard
26946 PIC16 contains an implementation of the printf-family of functions.
26947 There exist the following functions:
26950 \begin_layout LyX-Code
26951 extern unsigned int sprintf(char *buf, char *fmt, ...);
26954 \begin_layout LyX-Code
26955 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26958 \begin_layout LyX-Code
26962 \begin_layout LyX-Code
26963 extern unsigned int printf(char *fmt, ...);
26966 \begin_layout LyX-Code
26967 extern unsigned int vprintf(char *fmt, va_lista ap);
26970 \begin_layout LyX-Code
26974 \begin_layout LyX-Code
26975 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26978 \begin_layout LyX-Code
26979 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26982 \begin_layout Standard
26983 For sprintf and vsprintf
26987 should normally be a data pointer where the resulting string will be placed.
26988 No range checking is done so the user should allocate the necessery buffer.
26989 For fprintf and vfprintf
26993 should be a stream pointer (i.e.
26994 stdout, STREAM_MSSP, etc...).
26997 \begin_layout Subsubsection
27001 \begin_layout Standard
27002 The PIC18F family of microcontrollers supports a number of interrupt sources.
27003 A list of these interrupts is shown in the following table:
27006 \begin_layout Standard
27008 \begin_inset Tabular
27009 <lyxtabular version="3" rows="11" columns="4">
27011 <column alignment="left" valignment="top" leftline="true" width="0">
27012 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27013 <column alignment="left" valignment="top" leftline="true" width="0">
27014 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27015 <row topline="true" bottomline="true">
27016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27019 \begin_layout Standard
27025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27028 \begin_layout Standard
27034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27037 \begin_layout Standard
27043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27046 \begin_layout Standard
27053 <row topline="true">
27054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27057 \begin_layout Standard
27063 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27066 \begin_layout Standard
27067 PORTB change interrupt
27072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27075 \begin_layout Standard
27081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27084 \begin_layout Standard
27085 EEPROM/FLASH write complete interrupt
27091 <row topline="true">
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27095 \begin_layout Standard
27101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27104 \begin_layout Standard
27105 INT0 external interrupt
27110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27113 \begin_layout Standard
27119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27122 \begin_layout Standard
27123 Bus collision interrupt
27129 <row topline="true">
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27133 \begin_layout Standard
27139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27142 \begin_layout Standard
27143 INT1 external interrupt
27148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27151 \begin_layout Standard
27157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27160 \begin_layout Standard
27161 Low voltage detect interrupt
27167 <row topline="true">
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27171 \begin_layout Standard
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27180 \begin_layout Standard
27181 INT2 external interrupt
27186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27189 \begin_layout Standard
27195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27198 \begin_layout Standard
27199 Parallel slave port interrupt
27205 <row topline="true">
27206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27209 \begin_layout Standard
27215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27218 \begin_layout Standard
27219 CCP1 module interrupt
27224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27227 \begin_layout Standard
27233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27236 \begin_layout Standard
27237 AD convertion complete interrupt
27243 <row topline="true">
27244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27247 \begin_layout Standard
27253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27256 \begin_layout Standard
27257 CCP2 module interrupt
27262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27265 \begin_layout Standard
27271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27274 \begin_layout Standard
27275 USART receive interrupt
27281 <row topline="true">
27282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27285 \begin_layout Standard
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27294 \begin_layout Standard
27295 TMR0 overflow interrupt
27300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27303 \begin_layout Standard
27309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27312 \begin_layout Standard
27313 USART transmit interrupt
27319 <row topline="true">
27320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27323 \begin_layout Standard
27329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27332 \begin_layout Standard
27333 TMR1 overflow interrupt
27338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27341 \begin_layout Standard
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27350 \begin_layout Standard
27351 SSP receive/transmit interrupt
27357 <row topline="true">
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27361 \begin_layout Standard
27367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27370 \begin_layout Standard
27371 TMR2 matches PR2 interrupt
27376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27379 \begin_layout Standard
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27388 \begin_layout Standard
27395 <row topline="true" bottomline="true">
27396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27399 \begin_layout Standard
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27408 \begin_layout Standard
27409 TMR3 overflow interrupt
27414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27417 \begin_layout Standard
27423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27426 \begin_layout Standard
27440 \begin_layout Standard
27441 The prototypes for these names are defined in the header file
27448 \begin_layout Standard
27449 In order to simplify signal handling, a number of macros is provided:
27453 \labelwidthstring 00.00.0000
27454 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27455 high priority interrupts.
27460 is the function name to use.
27464 \labelwidthstring 00.00.0000
27465 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27466 low priority interrupt.
27471 is the function name to use.
27475 \labelwidthstring 00.00.0000
27476 DEF_HANDLER(sig,handler) define a handler for signal
27482 \labelwidthstring 00.00.0000
27483 END_DEF end the declaration of the dispatch table.
27486 \begin_layout Standard
27487 Additionally there are two more macros to simplify the declaration of the
27492 \labelwidthstring 00.00.0000
27495 SIGHANDLER(handler)
27497 this declares the function prototype for the
27505 \labelwidthstring 00.00.0000
27506 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27509 \begin_layout Standard
27510 An example of using the macros above is shown below:
27513 \begin_layout LyX-Code
27514 #include <pic18fregs.h>
27517 \begin_layout LyX-Code
27518 #include <signal.h>
27522 DEF_INTHIGH(high_int)
27525 \begin_layout LyX-Code
27526 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27529 \begin_layout LyX-Code
27530 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27533 \begin_layout LyX-Code
27538 SIGHANDLER(_tmr0_handler)
27541 \begin_layout LyX-Code
27545 \begin_layout LyX-Code
27546 /* action to be taken when timer 0 overflows */
27549 \begin_layout LyX-Code
27554 SIGHANDLERNAKED(_bcol_handler)
27557 \begin_layout LyX-Code
27561 \begin_layout LyX-Code
27565 \begin_layout LyX-Code
27566 /* action to be taken when bus collision occurs */
27569 \begin_layout LyX-Code
27573 \begin_layout LyX-Code
27577 \begin_layout LyX-Code
27581 \begin_layout Standard
27586 Special care should be taken when using the above scheme:
27589 \begin_layout Itemize
27590 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27593 \begin_layout Itemize
27594 when declaring SIGHANDLERNAKED handler never forget to use
27598 for proper returning.
27601 \begin_layout Subsection
27605 \begin_layout Standard
27606 Here you can find some general tips for compiling programs with SDCC/pic16.
27609 \begin_layout Subsubsection
27613 \begin_layout Standard
27615 \begin_inset LatexCommand \index{PIC16!stack}
27619 size (that is 64 bytes) probably is enough for many programs.
27620 One must take care that when there are many levels of function nesting,
27621 or there is excessive usage of stack, its size should be extended.
27622 An example of such a case is the printf/sprintf family of functions.
27623 If you encounter problems like not being able to print integers, then you
27624 need to set the stack size around the maximum (256 for small stack model).
27625 The following diagram shows what happens when calling printf to print an
27629 \begin_layout LyX-Code
27630 printf () --> ltoa () --> ultoa () --> divschar ()
27633 \begin_layout Standard
27634 It is should be understood that stack is easily consumed when calling complicate
27636 Using command line arguments like -
27640 \begin_layout Standard
27649 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27651 Other ways to reduce stack usage may exist.
27654 \begin_layout Subsection
27658 \begin_layout Standard
27659 The PIC16 Port currently does not pass SDCC's regression test
27660 \begin_inset LatexCommand \index{Regression test (PIC16)}
27665 \begin_inset LatexCommand \ref{sec:Quality-control}
27669 ) and thus the snapshot build regression tests for the PIC16 target are
27670 currently disabled for all hosts
27675 \begin_layout Chapter
27679 \begin_layout Standard
27680 There are several approaches to debugging your code.
27681 This chapter is meant to show your options and to give detail on some of
27686 When writing your code:
27689 \begin_layout Itemize
27690 write your code with debugging in mind (avoid duplicating code, put conceptually
27691 similar variables into structs, use structured code, have strategic points
27692 within your code where all variables are consistent, ...)
27695 \begin_layout Itemize
27696 run a syntax-checking tool like splint
27697 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27702 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27710 \begin_layout Standard
27720 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27727 \begin_layout Itemize
27728 for the high level code use a C-compiler (like f.e.
27729 GCC) to compile run and debug the code on your host.
27734 \begin_layout Standard
27744 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27748 ) on how to handle syntax extensions like __xdata, __at(), ...
27752 \begin_layout Itemize
27753 use another C-compiler to compile code for your target.
27754 Always an option but not recommended:) And not very likely to help you.
27755 If you seriously consider walking this path you should at least occasionally
27756 check portability of your code.
27757 Most commercial compiler vendors will offer an evaluation version so you
27758 can test compile your code or snippets of your code.
27761 \begin_layout Standard
27762 Debugging on a simulator:
27765 \begin_layout Itemize
27766 there is a separate section about SDCDB (section
27767 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27774 \begin_layout Itemize
27775 or (8051 specific) use a freeware/commercial simulator which interfaces
27777 \begin_inset LatexCommand \index{AOMF, AOMF51}
27782 \begin_inset LatexCommand \ref{OMF file}
27786 ) optionally generated by SDCC.
27789 \begin_layout Standard
27790 Debugging On-target:
27793 \begin_layout Itemize
27794 use a MCU port pin to serially output debug data to the RS232 port of your
27796 You'll probably want some level shifting device typically involving a MAX232
27798 If the hardware serial port of the MCU is not available search for 'Software
27799 UART' in your favourite search machine.
27802 \begin_layout Itemize
27803 use an on-target monitor.
27804 In this context a monitor is a small program which usually accepts commands
27805 via a serial line and allows to set program counter, to single step through
27806 a program and read/write memory locations.
27807 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27809 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27816 \begin_layout Itemize
27817 toggle MCU port pins at strategic points within your code and use an oscilloscop
27821 digital oscilloscope
27824 \begin_inset LatexCommand \index{Oscilloscope}
27828 with deep trace memory is really helpful especially if you have to debug
27829 a realtime application.
27830 If you need to monitor more pins than your oscilloscope provides you can
27831 sometimes get away with a small R-2R network.
27832 On a single channel oscilloscope you could f.e.
27833 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27835 \begin_inset Formula $\Omega$
27838 resistor and the other one by a 5\InsetSpace ~
27840 \begin_inset Formula $\Omega$
27843 resistor to the oscilloscope probe (check output drive capability of the
27844 pins you want to monitor).
27845 If you need to monitor many more pins a
27852 \begin_layout Itemize
27866 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27871 Usually very expensive.
27872 And very nice to have too.
27873 And usually locks you (for years...) to the devices the ICE can emulate.
27877 \begin_layout Itemize
27878 use a remote debugger.
27879 In most 8-bit systems the symbol information is not available on the target,
27880 and a complete debugger is too bulky for the target system.
27881 Therefore usually a debugger on the host system connects to an on-target
27882 debugging stub which accepts only primitive commands.
27885 Terms to enter into your favourite search engine could be 'remote debugging',
27886 'gdb stub' or 'inferior debugger'.
27890 \begin_layout Itemize
27891 use an on target hardware debugger.
27892 Some of the more modern MCUs include hardware support for setting break
27893 points and monitoring/changing variables by using dedicated hardware pins.
27894 This facility doesn't require additional code to run on the target and
27899 doesn't affect runtime behaviour until a breakpoint is hit.
27900 For the mcs51 most hardware debuggers use the AOMF
27901 \begin_inset LatexCommand \index{AOMF, AOMF51}
27906 \begin_inset LatexCommand \ref{OMF file}
27914 \begin_layout Standard
27918 \begin_layout Itemize
27919 if you are not familiar with any of the following terms you're likely to
27920 run into problems rather sooner than later:
27937 As an embedded programmer you
27941 to know them so why not look them up
27945 you have problems?)
27948 \begin_layout Itemize
27949 tell someone else about your problem (actually this is a surprisingly effective
27950 means to hunt down the bug even if the listener is not familiar with your
27952 As 'failure to communicate' is probably one of the job-induced deformations
27953 of an embedded programmer this is highly encouraged.
27956 \begin_layout Section
27957 Debugging with SDCDB
27958 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27963 \begin_inset LatexCommand \index{SDCDB (debugger)}
27970 \begin_layout Standard
27971 SDCC is distributed with a source level debugger
27972 \begin_inset LatexCommand \index{Debugger}
27977 The debugger uses a command line interface, the command repertoire of the
27978 debugger has been kept as close to gdb
27979 \begin_inset LatexCommand \index{gdb}
27983 (the GNU debugger) as possible.
27984 The configuration and build process is part of the standard compiler installati
27985 on, which also builds and installs the debugger in the target directory
27986 specified during configuration.
27987 The debugger allows you debug BOTH at the C source and at the ASM source
27991 \begin_layout Subsection
27992 Compiling for Debugging
27995 \begin_layout Standard
28000 \begin_layout Standard
28010 \begin_inset LatexCommand \index{-\/-debug}
28014 option must be specified for all files for which debug information is to
28016 The compiler generates a .adb file for each of these files.
28017 The linker creates the .cdb
28018 \begin_inset LatexCommand \index{<file>.cdb}
28023 \begin_inset LatexCommand \index{<file>.adb}
28027 files and the address information.
28028 This .cdb is used by the debugger.
28031 \begin_layout Subsection
28032 How the Debugger Works
28035 \begin_layout Standard
28040 \begin_layout Standard
28049 -debug option is specified the compiler generates extra symbol information
28050 some of which are put into the assembler source and some are put into the
28052 Then the linker creates the .cdb file from the individual .adb files with
28053 the address information for the symbols.
28054 The debugger reads the symbolic information generated by the compiler &
28055 the address information generated by the linker.
28056 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28057 execution is controlled by the debugger.
28058 When a command is issued for the debugger, it translates it into appropriate
28059 commands for the simulator.
28060 (Currently SDCDM only connects to the simulator but
28065 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28069 is an effort to connect directly to the hardware.)
28072 \begin_layout Subsection
28073 Starting the Debugger SDCDB
28076 \begin_layout Standard
28077 The debugger can be started using the following command line.
28078 (Assume the file you are debugging has the file name foo).
28092 The debugger will look for the following files.
28095 \begin_layout Itemize
28096 foo.c - the source file.
28099 \begin_layout Itemize
28100 foo.cdb - the debugger symbol information file.
28103 \begin_layout Itemize
28104 foo.ihx - the Intel hex format
28105 \begin_inset LatexCommand \index{Intel hex format}
28112 \begin_layout Subsection
28113 SDCDB Command Line Options
28116 \begin_layout Itemize
28121 \begin_layout Standard
28130 -directory=<source file directory> this option can used to specify the directory
28132 The debugger will look into the directory list specified for source, cdb
28134 The items in the directory list must be separated by ':', e.g.
28135 if the source files can be in the directories /home/src1 and /home/src2,
28140 \begin_layout Standard
28149 -directory option should be -
28153 \begin_layout Standard
28162 -directory=/home/src1:/home/src2.
28163 Note there can be no spaces in the option.
28167 \begin_layout Itemize
28168 -cd <directory> - change to the <directory>.
28171 \begin_layout Itemize
28172 -fullname - used by GUI front ends.
28175 \begin_layout Itemize
28176 -cpu <cpu-type> - this argument is passed to the simulator please see the
28177 simulator docs for details.
28180 \begin_layout Itemize
28181 -X <Clock frequency > this options is passed to the simulator please see
28182 the simulator docs for details.
28185 \begin_layout Itemize
28186 -s <serial port file> passed to simulator see the simulator docs for details.
28189 \begin_layout Itemize
28190 -S <serial in,out> passed to simulator see the simulator docs for details.
28193 \begin_layout Itemize
28194 -k <port number> passed to simulator see the simulator docs for details.
28197 \begin_layout Subsection
28198 SDCDB Debugger Commands
28201 \begin_layout Standard
28202 As mentioned earlier the command interface for the debugger has been deliberatel
28203 y kept as close the GNU debugger gdb, as possible.
28204 This will help the integration with existing graphical user interfaces
28205 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28206 If you use a graphical user interface for the debugger you can skip this
28210 \begin_layout Subsubsection*
28211 break [line | file:line | function | file:function]
28214 \begin_layout Standard
28215 Set breakpoint at specified line or function:
28224 sdcdb>break foo.c:100
28226 sdcdb>break funcfoo
28228 sdcdb>break foo.c:funcfoo
28231 \begin_layout Subsubsection*
28232 clear [line | file:line | function | file:function ]
28235 \begin_layout Standard
28236 Clear breakpoint at specified line or function:
28245 sdcdb>clear foo.c:100
28247 sdcdb>clear funcfoo
28249 sdcdb>clear foo.c:funcfoo
28252 \begin_layout Subsubsection*
28256 \begin_layout Standard
28257 Continue program being debugged, after breakpoint.
28260 \begin_layout Subsubsection*
28264 \begin_layout Standard
28265 Execute till the end of the current function.
28268 \begin_layout Subsubsection*
28272 \begin_layout Standard
28273 Delete breakpoint number 'n'.
28274 If used without any option clear ALL user defined break points.
28277 \begin_layout Subsubsection*
28278 info [break | stack | frame | registers ]
28281 \begin_layout Itemize
28282 info break - list all breakpoints
28285 \begin_layout Itemize
28286 info stack - show the function call stack.
28289 \begin_layout Itemize
28290 info frame - show information about the current execution frame.
28293 \begin_layout Itemize
28294 info registers - show content of all registers.
28297 \begin_layout Subsubsection*
28301 \begin_layout Standard
28302 Step program until it reaches a different source line.
28303 Note: pressing <return> repeats the last command.
28306 \begin_layout Subsubsection*
28310 \begin_layout Standard
28311 Step program, proceeding through subroutine calls.
28314 \begin_layout Subsubsection*
28318 \begin_layout Standard
28319 Start debugged program.
28322 \begin_layout Subsubsection*
28326 \begin_layout Standard
28327 Print type information of the variable.
28330 \begin_layout Subsubsection*
28334 \begin_layout Standard
28335 print value of variable.
28338 \begin_layout Subsubsection*
28342 \begin_layout Standard
28343 load the given file name.
28344 Note this is an alternate method of loading file for debugging.
28347 \begin_layout Subsubsection*
28351 \begin_layout Standard
28352 print information about current frame.
28355 \begin_layout Subsubsection*
28359 \begin_layout Standard
28360 Toggle between C source & assembly source.
28363 \begin_layout Subsubsection*
28364 ! simulator command
28367 \begin_layout Standard
28368 Send the string following '!' to the simulator, the simulator response is
28370 Note the debugger does not interpret the command being sent to the simulator,
28371 so if a command like 'go' is sent the debugger can loose its execution
28372 context and may display incorrect values.
28375 \begin_layout Subsubsection*
28379 \begin_layout Standard
28382 My name is Bobby Brown"
28385 \begin_layout Subsection
28386 Interfacing SDCDB with DDD
28389 \begin_layout Standard
28390 \begin_inset Note Note
28393 \begin_layout Standard
28394 The screenshot was converted from png to eps with:
28395 \begin_inset Quotes sld
28398 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28399 \begin_inset Quotes srd
28402 which produces a pretty compact eps file which is free from compression
28406 \begin_layout Standard
28407 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28408 as this broke the build system on Sourceforge (pdf-file was broken.
28409 pdflatex does not accept eps files).
28417 \begin_layout Standard
28433 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28439 shows a screenshot of a debugging session with DDD
28440 \begin_inset LatexCommand \index{DDD (debugger)}
28444 (Unix only) on a simulated 8032.
28445 The debugging session might not run as smoothly as the screenshot suggests.
28446 The debugger allows setting of breakpoints, displaying and changing variables,
28447 single stepping through C and assembler code.
28450 The source was compiled with
28464 \begin_layout Standard
28476 -debug ddd_example.c
28489 and DDD was invoked with
28496 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28499 \begin_layout Standard
28500 \begin_inset Note Note
28503 \begin_layout Standard
28504 Check that the double quotes or an apostroph within the command line survive
28505 the LyX tool chain.
28506 Previously the apostrophs got slanted in the PDF output so a cut and paste
28515 \begin_layout Subsection
28516 Interfacing SDCDB with XEmacs
28517 \begin_inset LatexCommand \index{XEmacs}
28522 \begin_inset LatexCommand \index{Emacs}
28529 \begin_layout Standard
28530 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28531 sdcdb.el and sdcdbsrc.el.
28532 These two files can be found in the $(prefix)/bin directory after the installat
28534 These files need to be loaded into XEmacs for the interface to work.
28535 This can be done at XEmacs startup time by inserting the following into
28536 your '.xemacs' file (which can be found in your HOME directory):
28542 (load-file sdcdbsrc.el)
28548 .xemacs is a lisp file so the () around the command is REQUIRED.
28549 The files can also be loaded dynamically while XEmacs is running, set the
28550 environment variable 'EMACSLOADPATH' to the installation bin directory
28551 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28552 To start the interface enter the following command:
28566 You will prompted to enter the file name to be debugged.
28571 The command line options that are passed to the simulator directly are
28572 bound to default values in the file sdcdbsrc.el.
28573 The variables are listed below, these values maybe changed as required.
28576 \begin_layout Itemize
28577 sdcdbsrc-cpu-type '51
28580 \begin_layout Itemize
28581 sdcdbsrc-frequency '11059200
28584 \begin_layout Itemize
28585 sdcdbsrc-serial nil
28588 \begin_layout Standard
28589 The following is a list of key mapping for the debugger interface.
28592 \begin_layout Standard
28615 binding\InsetSpace ~
28653 -------\InsetSpace ~
28724 sdcdb-back-from-src\InsetSpace ~
28753 rom-src\InsetSpace ~
28763 SDCDB continue command
28781 sdcdb-step-from-src\InsetSpace ~
28810 hatis-c-sexp\InsetSpace ~
28820 SDCDB ptypecommand for data at
28887 sdcdbsrc-delete\InsetSpace ~
28902 B Delete all breakpoints if no arg
28951 given or delete arg (C-u arg x)
28970 -frame\InsetSpace ~
28985 SDCDB Display current frame if no arg,
29034 given or display frame arg
29102 sdcdbsrc-goto-sdcdb\InsetSpace ~
29112 Goto the SDCDB output buffer
29131 t-c-sexp\InsetSpace ~
29142 SDCDB print command for data at
29209 sdcdbsrc-goto-sdcdb\InsetSpace ~
29220 o the SDCDB output buffer
29238 sdcdbsrc-mode\InsetSpace ~
29254 Toggles Sdcdbsrc mode (turns it
29270 sdcdb-finish-from-src\InsetSpace ~
29278 SDCDB finish command
29312 Set break for line with point
29327 sdcdbsrc-mode\InsetSpace ~
29343 Toggle Sdcdbsrc mode
29359 dbsrc-srcmode\InsetSpace ~
29383 \begin_layout Chapter
29387 \begin_layout Standard
29388 Here are a few guidelines that will help the compiler generate more efficient
29389 code, some of the tips are specific to this compiler others are generally
29390 good programming practice.
29393 \begin_layout Itemize
29394 Use the smallest data type to represent your data-value.
29395 If it is known in advance that the value is going to be less than 256 then
29396 use an 'unsigned char' instead of a 'short' or 'int'.
29397 Please note, that ANSI C requires both signed and unsigned chars to be
29398 promoted to 'signed int'
29399 \begin_inset LatexCommand \index{promotion to signed int}
29404 \begin_inset Marginal
29407 \begin_layout Standard
29416 before doing any operation.
29418 \begin_inset LatexCommand \index{type promotion}
29423 \begin_inset LatexCommand \label{type promotion}
29427 can be omitted, if the result is the same.
29428 The effect of the promotion rules together with the sign-extension is often
29433 \begin_layout Verse
29436 unsigned char uc = 0xfe;
29438 if (uc * uc < 0) /* this is true! */
29451 \begin_layout Standard
29458 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29466 \begin_layout Verse
29469 (unsigned char) -12 / (signed char) -3 = ...
29472 \begin_layout Standard
29473 No, the result is not 4:
29476 \begin_layout Verse
29479 (int) (unsigned char) -12 / (int) (signed char) -3 =
29481 (int) (unsigned char)
29482 0xf4 / (int) (signed char) 0xfd =
29484 (int) 0x00f4 / (int) 0xfffd =
29489 (int) 244 / (int) -3 =
29491 (int) -81 = (int) 0xffaf;
29494 \begin_layout Standard
29495 Don't complain, that gcc gives you a different result.
29496 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29497 Therefore the results are different.
29500 \begin_inset Quotes sld
29504 \begin_inset Quotes srd
29510 \begin_layout Quote
29513 If well-defined overflow characteristics are important and negative values
29514 are not, or if you want to steer clear of sign-extension problems when
29515 manipulating bits or bytes, use one of the corresponding unsigned types.
29516 (Beware when mixing signed and unsigned values in expressions, though.)
29519 character types (especially unsigned char) can be used as "tiny" integers,
29520 doing so is sometimes more trouble than it's worth, due to unpredictable
29521 sign extension and increased code size.
29525 \begin_layout Itemize
29526 Use unsigned when it is known in advance that the value is not going to
29528 This helps especially if you are doing division or multiplication, bit-shifting
29529 or are using an array index.
29532 \begin_layout Itemize
29533 NEVER jump into a LOOP.
29536 \begin_layout Itemize
29537 Declare the variables to be local
29538 \begin_inset LatexCommand \index{local variables}
29542 whenever possible, especially loop control variables (induction).
29545 \begin_layout Itemize
29546 Have a look at the assembly listing to get a
29547 \begin_inset Quotes sld
29551 \begin_inset Quotes srd
29554 for the code generation.
29557 \begin_layout Section
29558 Porting code from or to other compilers
29559 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29566 \begin_layout Itemize
29567 check whether endianness of the compilers differs and adapt where needed.
29570 \begin_layout Itemize
29571 check the device specific header files
29572 \begin_inset LatexCommand \index{Header files}
29577 \begin_inset LatexCommand \index{Include files}
29581 for compiler specific syntax.
29582 Eventually include the file <compiler.h
29583 \begin_inset LatexCommand \index{compiler.h (include file)}
29588 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29592 to allow using common header files.
29595 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29602 \begin_layout Itemize
29603 check whether the startup code contains the correct initialization (watchdog,
29607 \begin_layout Itemize
29608 check whether the sizes of short, int, long match.
29611 \begin_layout Itemize
29612 check if some 16 or 32 bit hardware registers require a specific addressing
29613 order (least significant or most significant byte first) and adapt if needed
29622 relate to time and not to lower/upper memory location here, so this is
29627 the same as endianness).
29630 \begin_layout Itemize
29631 check whether the keyword
29635 is used where needed.
29636 The compilers might differ in their optimization characteristics (as different
29637 versions of the same compiler might also use more clever optimizations
29638 this is good idea anyway).
29640 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29647 \begin_layout Itemize
29648 check that the compilers are not told to supress warnings.
29651 \begin_layout Itemize
29652 check and convert compiler specific extensions (interrupts, memory areas,
29656 \begin_layout Itemize
29657 check for differences in type promotion.
29658 Especially check for math operations on
29667 For the sake of C99 compatibility SDCC will probably promote these to
29671 more often than other compilers.
29672 Eventually insert explicit casts to
29681 Also check that the ~\InsetSpace ~
29683 \begin_inset LatexCommand \index{\~\/ Operator}
29690 \begin_inset LatexCommand \index{bit}
29696 variables, use the !\InsetSpace ~
29699 \begin_inset LatexCommand \ref{type promotion}
29704 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29711 \begin_layout Itemize
29712 check the assembly code generated for interrupt routines (f.e.
29713 for calls to possibly non-reentrant library functions).
29716 \begin_layout Itemize
29717 check whether timing loops result in proper timing (or preferably consider
29718 a rewrite of the code with timer based delays instead).
29721 \begin_layout Itemize
29722 check for differences in printf parameters (some compilers push (va_arg
29723 \begin_inset LatexCommand \index{vararg, va\_arg}
29727 ) char variables as
29731 others push them as
29737 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29744 \begin_layout Itemize
29745 check the resulting memory map
29746 \begin_inset LatexCommand \index{Memory map}
29751 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29752 ly idata, pdata, xdata).
29753 Eventually check if unexpected library functions are included.
29756 \begin_layout Section
29758 \begin_inset LatexCommand \index{Tools}
29762 included in the distribution
29765 \begin_layout Standard
29767 \begin_inset Tabular
29768 <lyxtabular version="3" rows="12" columns="3">
29770 <column alignment="left" valignment="top" leftline="true" width="0pt">
29771 <column alignment="left" valignment="top" leftline="true" width="0pt">
29772 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29773 <row topline="true" bottomline="true">
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29777 \begin_layout Standard
29785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29788 \begin_layout Standard
29796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29799 \begin_layout Standard
29808 <row topline="true">
29809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29812 \begin_layout Standard
29814 \begin_inset LatexCommand \index{uCsim}
29823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29826 \begin_layout Standard
29827 Simulator for various architectures
29832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29835 \begin_layout Standard
29842 <row topline="true">
29843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29846 \begin_layout Standard
29852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29855 \begin_layout Standard
29857 \begin_inset LatexCommand \index{Header files}
29862 \begin_inset LatexCommand \index{Include files}
29871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29874 \begin_layout Standard
29875 sdcc/support/scripts
29881 <row topline="true">
29882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29885 \begin_layout Standard
29891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29894 \begin_layout Standard
29895 header file conversion
29900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29903 \begin_layout Standard
29904 sdcc/support/scripts
29910 <row topline="true">
29911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29914 \begin_layout Standard
29920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29923 \begin_layout Standard
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29932 \begin_layout Standard
29948 <row topline="true">
29949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29952 \begin_layout Standard
29958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29961 \begin_layout Standard
29967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29970 \begin_layout Standard
29986 <row topline="true">
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29990 \begin_layout Standard
29996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29999 \begin_layout Standard
30005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30008 \begin_layout Standard
30024 <row topline="true">
30025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30028 \begin_layout Standard
30034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30037 \begin_layout Standard
30043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30046 \begin_layout Standard
30062 <row topline="true">
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30066 \begin_layout Standard
30072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30075 \begin_layout Standard
30081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30084 \begin_layout Standard
30100 <row topline="true">
30101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30104 \begin_layout Standard
30110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30113 \begin_layout Standard
30119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30122 \begin_layout Standard
30138 <row topline="true">
30139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30142 \begin_layout Standard
30148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30151 \begin_layout Standard
30157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30160 \begin_layout Standard
30176 <row topline="true" bottomline="true">
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30180 \begin_layout Standard
30186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30189 \begin_layout Standard
30191 \begin_inset LatexCommand \index{packihx (tool)}
30200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30203 \begin_layout Standard
30228 \begin_layout Section
30230 \begin_inset LatexCommand \index{Documentation}
30234 included in the distribution
30237 \begin_layout Standard
30239 \begin_inset Tabular
30240 <lyxtabular version="3" rows="10" columns="2">
30242 <column alignment="block" valignment="top" leftline="true" width="40col%">
30243 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30244 <row topline="true" bottomline="true" endhead="true">
30245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30248 \begin_layout Standard
30256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30259 \begin_layout Standard
30262 Filename / Where to get
30268 <row topline="true">
30269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30272 \begin_layout Standard
30273 SDCC Compiler User Guide
30278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30281 \begin_layout Standard
30282 You're reading it right now
30294 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30304 <row topline="true">
30305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30308 \begin_layout Standard
30314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30317 \begin_layout Standard
30330 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30340 <row topline="true">
30341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30344 \begin_layout Standard
30346 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30351 \begin_inset LatexCommand \index{Assembler documentation}
30358 \begin_inset LatexCommand \index{aslink}
30363 \begin_inset LatexCommand \index{Linker documentation}
30372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30375 \begin_layout Standard
30376 sdcc/as/doc/asxhtm.html
30388 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30398 <row topline="true">
30399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30402 \begin_layout Standard
30403 SDCC regression test
30404 \begin_inset LatexCommand \index{Regression test}
30413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30416 \begin_layout Standard
30417 sdcc/doc/test_suite_spec.pdf
30429 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30439 <row topline="true">
30440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30443 \begin_layout Standard
30449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30452 \begin_layout Standard
30465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30475 <row topline="true">
30476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30479 \begin_layout Standard
30480 Notes on debugging with SDCDB
30481 \begin_inset LatexCommand \index{SDCDB (debugger)}
30490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30493 \begin_layout Standard
30494 sdcc/debugger/README
30506 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30516 <row topline="true">
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30520 \begin_layout Standard
30522 \begin_inset LatexCommand \index{uCsim}
30526 Software simulator for microcontrollers
30531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30534 \begin_layout Standard
30564 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30574 <row topline="true">
30575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30578 \begin_layout Standard
30579 Temporary notes on the pic16
30580 \begin_inset LatexCommand \index{PIC16}
30589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30592 \begin_layout Standard
30593 sdcc/src/pic16/NOTES
30605 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30615 <row topline="true" bottomline="true">
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30619 \begin_layout Standard
30620 SDCC internal documentation (debugging file format)
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30628 \begin_layout Standard
30658 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30677 \begin_layout Section
30678 Related open source tools
30679 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30684 \begin_inset LatexCommand \index{Related tools}
30691 \begin_layout Standard
30693 \begin_inset Tabular
30694 <lyxtabular version="3" rows="14" columns="3">
30696 <column alignment="left" valignment="top" leftline="true" width="0pt">
30697 <column alignment="block" valignment="top" leftline="true" width="30line%">
30698 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30699 <row topline="true" bottomline="true">
30700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30703 \begin_layout Standard
30711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30714 \begin_layout Standard
30722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30725 \begin_layout Standard
30734 <row topline="true">
30735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30738 \begin_layout Standard
30740 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30752 \begin_layout Standard
30758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30761 \begin_layout Standard
30762 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30772 <row topline="true">
30773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30776 \begin_layout Standard
30778 \begin_inset LatexCommand \index{gputils (pic tools)}
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30790 \begin_layout Standard
30796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30799 \begin_layout Standard
30800 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30810 <row topline="true">
30811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30814 \begin_layout Standard
30820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30823 \begin_layout Standard
30829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30832 \begin_layout Standard
30833 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30843 <row topline="true">
30844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30847 \begin_layout Standard
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30856 \begin_layout Standard
30857 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30866 \begin_layout Standard
30867 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30877 <row topline="true">
30878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30881 \begin_layout Standard
30883 \begin_inset LatexCommand \index{indent (source formatting tool)}
30892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30895 \begin_layout Standard
30896 Formats C source - Master of the white spaces
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30904 \begin_layout Standard
30905 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30915 <row topline="true">
30916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30919 \begin_layout Standard
30921 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30933 \begin_layout Standard
30934 Object file conversion, checksumming, ...
30939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30942 \begin_layout Standard
30943 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30953 <row topline="true">
30954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30957 \begin_layout Standard
30959 \begin_inset LatexCommand \index{objdump (tool)}
30968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30971 \begin_layout Standard
30972 Object file conversion, ...
30977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30980 \begin_layout Standard
30981 Part of binutils (should be there anyway)
30987 <row topline="true">
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30991 \begin_layout Standard
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31000 \begin_layout Standard
31001 8051 monitor (hex up-/download, single step, disassemble)
31006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31009 \begin_layout Standard
31010 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31020 <row topline="true">
31021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_layout Standard
31026 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31038 \begin_layout Standard
31039 Source code documentation system
31044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31047 \begin_layout Standard
31048 \begin_inset LatexCommand \url{http://www.doxygen.org}
31058 <row topline="true">
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_layout Standard
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31071 \begin_layout Standard
31072 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31080 \begin_layout Standard
31081 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31091 <row topline="true">
31092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31095 \begin_layout Standard
31101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31104 \begin_layout Standard
31105 8051 monitor (hex up-/download, single step, disassemble)
31110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31113 \begin_layout Standard
31114 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31124 <row topline="true">
31125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31128 \begin_layout Standard
31130 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31142 \begin_layout Standard
31143 Statically checks c sources (see
31144 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31156 \begin_layout Standard
31157 \begin_inset LatexCommand \url{http://www.splint.org}
31167 <row topline="true" bottomline="true">
31168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31171 \begin_layout Standard
31173 \begin_inset LatexCommand \index{DDD (debugger)}
31182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31185 \begin_layout Standard
31186 Debugger, serves nicely as GUI to SDCDB
31187 \begin_inset LatexCommand \index{SDCDB (debugger)}
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31199 \begin_layout Standard
31200 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31219 \begin_layout Section
31220 Related documentation / recommended reading
31223 \begin_layout Standard
31225 \begin_inset Tabular
31226 <lyxtabular version="3" rows="7" columns="3">
31228 <column alignment="left" valignment="top" leftline="true" width="0pt">
31229 <column alignment="left" valignment="top" leftline="true" width="0">
31230 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31231 <row topline="true" bottomline="true">
31232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31235 \begin_layout Standard
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31246 \begin_layout Standard
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31257 \begin_layout Standard
31266 <row topline="true">
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31270 \begin_layout Standard
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31288 \begin_layout Standard
31290 \begin_inset LatexCommand \index{C Reference card}
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31302 \begin_layout Standard
31303 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31313 <row topline="true">
31314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31317 \begin_layout Standard
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31326 \begin_layout Standard
31328 \begin_inset LatexCommand \index{C FAQ}
31337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31340 \begin_layout Standard
31341 \begin_inset LatexCommand \url{http://www.c-faq.com}
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
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/standards.html#9899}
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 \begin_inset Quotes sld
31410 Extensions for Embedded C
31411 \begin_inset Quotes srd
31419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31422 \begin_layout Standard
31425 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31435 <row topline="true">
31436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31439 \begin_layout Standard
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31448 \begin_layout Standard
31449 Latest datasheet of target CPU
31454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31457 \begin_layout Standard
31464 <row topline="true" bottomline="true">
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31468 \begin_layout Standard
31474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31477 \begin_layout Standard
31478 Revision history of datasheet
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31486 \begin_layout Standard
31502 \begin_layout Section
31503 Application notes specifically for SDCC
31506 \begin_layout Standard
31507 SDCC makes no claims about the completeness of this list and about up-to-datenes
31508 s or correctness of the application notes
31509 \begin_inset LatexCommand \index{Application notes}
31516 \begin_layout Standard
31520 \begin_inset Tabular
31521 <lyxtabular version="3" rows="7" columns="3">
31523 <column alignment="block" valignment="top" leftline="true" width="17col%">
31524 <column alignment="block" valignment="top" leftline="true" width="27col%">
31525 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31526 <row topline="true" bottomline="true">
31527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31530 \begin_layout Standard
31539 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31542 \begin_layout Standard
31551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31554 \begin_layout Standard
31564 <row topline="true">
31565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31568 \begin_layout Standard
31576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31579 \begin_layout Standard
31582 Using the SDCC Compiler for the DS80C400
31583 \begin_inset LatexCommand \index{DS80C400}
31592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31595 \begin_layout Standard
31598 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31608 <row topline="true">
31609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31612 \begin_layout Standard
31620 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31623 \begin_layout Standard
31626 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31627 \begin_inset LatexCommand \index{DS89C4x0}
31631 Family of Microcontrollers
31636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31639 \begin_layout Standard
31642 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31652 <row topline="true">
31653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31656 \begin_layout Standard
31659 Silicon Laboratories / Cygnal
31664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31667 \begin_layout Standard
31670 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31671 \begin_inset LatexCommand \index{IDE}
31680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31683 \begin_layout Standard
31686 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31696 <row topline="true">
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31700 \begin_layout Standard
31703 Ramtron / Goal Semiconductor
31708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31711 \begin_layout Standard
31714 Interfacing SDCC to Syn and Textpad
31719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31722 \begin_layout Standard
31725 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31735 <row topline="true">
31736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31739 \begin_layout Standard
31742 Ramtron / Goal Semiconductor
31747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31750 \begin_layout Standard
31753 Installing and Configuring SDCC and Crimson Editor
31758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31761 \begin_layout Standard
31764 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31774 <row topline="true" bottomline="true">
31775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31778 \begin_layout Standard
31786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31789 \begin_layout Standard
31792 MSC12xx Programming with SDCC
31797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31800 \begin_layout Standard
31803 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31820 \begin_layout Section
31824 \begin_layout Standard
31825 Some questions answered, some pointers given - it might be time to in turn
31833 \begin_layout Itemize
31834 can you solve your project with the selected microcontroller? Would you
31835 find out early or rather late that your target is too small/slow/whatever?
31836 Can you switch to a slightly better device if it doesn't fit?
31839 \begin_layout Itemize
31840 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31841 and/or another programming language be more adequate? Would an operating
31842 system on the target device help?
31845 \begin_layout Itemize
31846 if you solved the problem, will the marketing department be happy?
31849 \begin_layout Itemize
31850 if the marketing department is happy, will customers be happy?
31853 \begin_layout Itemize
31854 if you're the project manager, marketing department and maybe even the customer
31855 in one person, have you tried to see the project from the outside?
31858 \begin_layout Itemize
31859 is the project done if you think it is done? Or is just that other interface/pro
31860 tocol/feature/configuration/option missing? How about website, manual(s),
31861 internationali(z|s)ation, packaging, labels, 2nd source for components,
31862 electromagnetic compatability/interference, documentation for production,
31863 production test software, update mechanism, patent issues?
31866 \begin_layout Itemize
31867 is your project adequately positioned in that magic triangle: fame, fortune,
31871 \begin_layout Standard
31872 Maybe not all answers to these questions are known and some answers may
31877 , nevertheless knowing these questions may help you to avoid burnout
31881 \begin_layout Standard
31882 burnout is bad for electronic devices, programmers and motorcycle tyres
31888 Chances are you didn't want to hear some of them...
31891 \begin_layout Chapter
31893 \begin_inset LatexCommand \index{Support}
31900 \begin_layout Standard
31901 SDCC has grown to be a large project.
31902 The compiler alone (without the preprocessor, assembler and linker) is
31903 well over 150,000 lines of code (blank stripped).
31904 The open source nature of this project is a key to its continued growth
31906 You gain the benefit and support of many active software developers and
31908 Is SDCC perfect? No, that's why we need your help.
31909 The developers take pride in fixing reported bugs.
31910 You can help by reporting the bugs and helping other SDCC users.
31911 There are lots of ways to contribute, and we encourage you to take part
31912 in making SDCC a great software package.
31916 \begin_layout Standard
31917 The SDCC project is hosted on the SDCC sourceforge site at
31918 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31923 You'll find the complete set of mailing lists
31924 \begin_inset LatexCommand \index{Mailing list(s)}
31928 , forums, bug reporting system, patch submission
31929 \begin_inset LatexCommand \index{Patch submission}
31934 \begin_inset LatexCommand \index{download}
31938 area and Subversion code repository
31939 \begin_inset LatexCommand \index{Subversion code repository}
31946 \begin_layout Section
31948 \begin_inset LatexCommand \index{Bug reporting}
31953 \begin_inset LatexCommand \index{Reporting bugs}
31960 \begin_layout Standard
31961 The recommended way of reporting bugs is using the infrastructure of the
31963 You can follow the status of bug reports there and have an overview about
31967 \begin_layout Standard
31968 Bug reports are automatically forwarded to the developer mailing list and
31969 will be fixed ASAP.
31970 When reporting a bug, it is very useful to include a small test program
31971 (the smaller the better) which reproduces the problem.
31972 If you can isolate the problem by looking at the generated assembly code,
31973 this can be very helpful.
31974 Compiling your program with the -
31978 \begin_layout Standard
31988 \begin_inset LatexCommand \index{-\/-dumpall}
31992 option can sometimes be useful in locating optimization problems.
31993 When reporting a bug please make sure you:
31996 \begin_layout Enumerate
31997 Attach the code you are compiling with SDCC.
32001 \begin_layout Enumerate
32002 Specify the exact command you use to run SDCC, or attach your Makefile.
32006 \begin_layout Enumerate
32007 Specify the SDCC version (type "
32013 "), your platform, and operating system.
32017 \begin_layout Enumerate
32018 Provide an exact copy of any error message or incorrect output.
32022 \begin_layout Enumerate
32023 Put something meaningful in the subject of your message.
32026 \begin_layout Standard
32027 Please attempt to include these 5 important parts, as applicable, in all
32028 requests for support or when reporting any problems or bugs with SDCC.
32029 Though this will make your message lengthy, it will greatly improve your
32030 chance that SDCC users and developers will be able to help you.
32031 Some SDCC developers are frustrated by bug reports without code provided
32032 that they can use to reproduce and ultimately fix the problem, so please
32033 be sure to provide sample code if you are reporting a bug!
32036 \begin_layout Standard
32037 Please have a short check that you are using a recent version of SDCC and
32038 the bug is not yet known.
32039 This is the link for reporting bugs:
32040 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32045 With SDCC on average having more than 200 downloads
32046 \begin_inset LatexCommand \index{download}
32050 on sourceforge per day
32054 \begin_layout Standard
32055 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32056 between 2002 and 2005.
32057 This does not include other methods of distribution.
32062 there must be some users.
32063 So it's not exactly easy to find a new bug.
32064 If you find one we need it:
32066 reporting bugs is good
32071 \begin_layout Section
32072 Requesting Features
32073 \begin_inset LatexCommand \label{sub:Requesting-Features}
32078 \begin_inset LatexCommand \index{Feature request}
32083 \begin_inset LatexCommand \index{Requesting features}
32090 \begin_layout Standard
32091 Like bug reports feature requests are forwarded to the developer mailing
32093 This is the link for requesting features:
32094 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32101 \begin_layout Section
32105 \begin_layout Standard
32106 Like bug reports contributed patches are forwarded to the developer mailing
32108 This is the link for submitting patches
32109 \begin_inset LatexCommand \index{Patch submission}
32114 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32121 \begin_layout Standard
32122 You need to specify some parameters to the
32126 command for the patches to be useful.
32127 If you modified more than one file a patch created f.e.
32132 \begin_inset Quotes sld
32135 diff -Naur unmodified_directory modified_directory >my_changes.patch
32136 \begin_inset Quotes srd
32142 will be fine, otherwise
32146 \begin_inset Quotes sld
32149 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32150 \begin_inset Quotes srd
32160 \begin_layout Section
32164 \begin_layout Standard
32165 These links should take you directly to the
32166 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32174 \begin_layout Standard
32175 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32176 automated messages (mid 2003)
32182 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32187 \begin_inset LatexCommand \index{Mailing list(s)}
32191 and forums are archived and searchable so if you are lucky someone already
32192 had a similar problem.
32193 While mails to the lists themselves are delivered promptly their web front
32194 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32195 if you're seriously using SDCC please consider subscribing to the lists.
32198 \begin_layout Section
32202 \begin_layout Standard
32203 You can follow the status of the Subversion version
32204 \begin_inset LatexCommand \index{version}
32208 of SDCC by watching the Changelog
32209 \begin_inset LatexCommand \index{Changelog}
32213 in the Subversion repository
32216 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32223 \begin_layout Section
32224 Subversion Source Code Repository
32227 \begin_layout Standard
32234 or the filenames of the snapshot versions of SDCC include date and its
32236 \begin_inset LatexCommand \index{Subversion code repository}
32241 Subversion allows to download the source of recent or previous versions
32243 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32247 (by number or by date).
32248 An on-line source code browser and detailled instructions are also available
32250 SDCC versions starting from 1999 up to now are available (currently the
32251 versions prior to the conversion from cvs
32252 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32256 to Subversion (April 2006) are either by accessible by Subversion or by
32260 \begin_layout Section
32262 \begin_inset LatexCommand \index{Release policy}
32269 \begin_layout Standard
32270 Historically there often were long delays between official releases and
32271 the sourceforge download area tends to get not updated at all.
32272 Excuses in the past might have referred to problems with live range analysis,
32273 but as this was fixed a while ago, the current problem is that another
32274 excuse has to be found.
32275 Kidding aside, we have to get better there! On the other hand there are
32276 daily snapshots available at
32277 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32281 , and you can always build the very last version (hopefully with many bugs
32282 fixed, and features added) from the source code available at
32283 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32289 \begin_inset LatexCommand \index{wiki}
32294 \begin_inset LatexCommand \index{Release wiki}
32299 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32303 also holds some information about past and future releases.
32306 \begin_layout Section
32308 \begin_inset LatexCommand \index{Examples}
32315 \begin_layout Standard
32316 You'll find some small examples in the directory
32318 sdcc/device/examples/.
32321 More examples and libraries are available at
32323 The SDCC Open Knowledge Resource
32324 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32331 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32338 \begin_layout Standard
32339 \begin_inset Note Note
32342 \begin_layout Standard
32343 I did insert a reference to Paul's web site here although it seems rather
32344 dedicated to a specific 8032 board (I think it's okay because it f.e.
32345 shows LCD/Harddisc interface and has a free 8051 monitor.
32346 Independent 8032 board vendors face hard competition of heavily subsidized
32347 development boards anyway).
32350 \begin_layout Standard
32351 Maybe we should include some links to real world applications.
32352 Preferably pointer to pointers (one for each architecture) so this stays
32361 \begin_layout Section
32363 \begin_inset LatexCommand \label{sec:Quality-control}
32368 \begin_inset LatexCommand \index{Quality control}
32375 \begin_layout Standard
32376 The compiler is passed through snaphot build compile and build checks.
32382 \begin_inset LatexCommand \index{Regression test}
32386 check that SDCC itself compiles flawlessly on several host platforms (i386,
32387 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32388 the quality of the code generated by SDCC by running the code for several
32389 target platforms through simulators.
32390 The regression test suite comprises more than 100 files which expand to
32391 more than 500 test cases which include more than 4500 tests.
32392 The results of these tests are published daily on SDCC's snapshot page
32393 (click on the red or green symbols on the right side of
32394 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32401 \begin_layout Standard
32402 There is a separate document
32405 \begin_inset LatexCommand \index{Test suite}
32412 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32416 about the regression test suite.
32419 \begin_layout Standard
32420 You'll find the test code in the directory
32422 sdcc/support/regression
32425 You can run these tests manually by running
32429 in this directory (or f.e.
32434 \begin_inset Quotes sld
32438 \begin_inset Quotes srd
32444 if you don't want to run the complete tests).
32445 The test code might also be interesting if you want to look for examples
32446 \begin_inset LatexCommand \index{Examples}
32450 checking corner cases of SDCC or if you plan to submit patches
32451 \begin_inset LatexCommand \index{Patch submission}
32458 \begin_layout Standard
32459 The PIC14 port uses a different set of regression tests
32460 \begin_inset LatexCommand \index{Regression test (PIC14)}
32464 , you'll find them in the directory
32466 sdcc/src/regression
32471 \begin_layout Section
32472 Use of SDCC in Education
32475 \begin_layout Standard
32484 \begin_layout Standard
32485 the phrase "use in education" might evoke the association "
32489 fit for use in education".
32490 This connotation is not intended but nevertheless risked as the licensing
32491 of SDCC makes it difficult to offer educational discounts
32497 If your rationales are to:
32500 \begin_layout Enumerate
32501 give students a chance to understand the
32505 steps of code generation
32508 \begin_layout Enumerate
32509 have a curriculum that can be extended for years.
32510 Then you could use an fpga board as target and your curriculum will seamlessly
32511 extend from logic synthesis (
32512 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32517 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32521 ), over assembly programming, to C to FPGA compilers (
32522 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32529 \begin_layout Enumerate
32530 be able to insert excursions about skills like using a revision control
32531 system, submitting/applying patches, using a type-setting (as opposed to
32532 word-processing) engine LyX/LaTeX, using
32533 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32538 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32542 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32543 Source Software, CPU simulation, compiler regression tests
32544 \begin_inset LatexCommand \index{Regression test}
32551 And if there should be a shortage of ideas then you can always point students
32552 to the ever-growing feature request list
32553 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32560 \begin_layout Enumerate
32561 not tie students to a specific host platform and instead allow them to use
32566 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32568 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32575 \begin_layout Enumerate
32576 not encourage students to use illegal copies of educational software
32579 \begin_layout Enumerate
32580 be immune to licensing/availability/price changes of the chosen tool chain
32583 \begin_layout Enumerate
32584 be able to change to a new target platform without having to adopt a new
32588 \begin_layout Enumerate
32589 have complete control over and insight into the tool chain
32592 \begin_layout Enumerate
32593 make your students aware about the pros and cons of open source software
32597 \begin_layout Enumerate
32598 give back to the public as you are probably at least partially publically
32602 \begin_layout Enumerate
32603 give students a chance to publically prove their skills and to possibly
32604 see a world wide impact
32607 \begin_layout Standard
32608 then SDCC is probably among the first choices.
32609 Well, probably SDCC might be the only choice.
32614 \begin_layout Chapter
32615 SDCC Technical Data
32618 \begin_layout Section
32620 \begin_inset LatexCommand \index{Optimizations}
32627 \begin_layout Standard
32628 SDCC performs a host of standard optimizations in addition to some MCU specific
32633 \begin_layout Subsection
32634 Sub-expression Elimination
32635 \begin_inset LatexCommand \index{Subexpression elimination}
32642 \begin_layout Standard
32643 The compiler does local and
32662 \begin_layout Verse
32670 \begin_layout Standard
32671 will be translated to
32674 \begin_layout Verse
32684 \begin_layout Standard
32685 Some subexpressions are not as obvious as the above example, e.g.:
32688 \begin_layout Verse
32696 \begin_layout Standard
32697 In this case the address arithmetic a->b[i] will be computed only once;
32698 the equivalent code in C would be.
32701 \begin_layout Verse
32711 \begin_layout Standard
32712 The compiler will try to keep these temporary variables in registers.
32715 \begin_layout Subsection
32716 Dead-Code Elimination
32717 \begin_inset LatexCommand \index{Dead-code elimination}
32724 \begin_layout Verse
32739 i = 1; \InsetSpace ~
32748 global = 1;\InsetSpace ~
32762 global = 3;\InsetSpace ~
32768 \begin_layout Standard
32772 \begin_layout Verse
32788 \begin_layout Subsection
32790 \begin_inset LatexCommand \index{Copy propagation}
32797 \begin_layout Verse
32821 \begin_layout Standard
32825 \begin_layout Verse
32849 \begin_layout Standard
32850 Note: the dead stores created by this copy propagation will be eliminated
32851 by dead-code elimination.
32854 \begin_layout Subsection
32856 \begin_inset LatexCommand \index{Loop optimization}
32861 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32868 \begin_layout Standard
32869 Two types of loop optimizations are done by SDCC
32877 of loop induction variables.
32878 In addition to the strength reduction the optimizer marks the induction
32879 variables and the register allocator tries to keep the induction variables
32880 in registers for the duration of the loop.
32881 Because of this preference of the register allocator
32882 \begin_inset LatexCommand \index{Register allocation}
32886 , loop induction optimization causes an increase in register pressure, which
32887 may cause unwanted spilling of other temporary variables into the stack
32888 \begin_inset LatexCommand \index{stack}
32893 The compiler will generate a warning message when it is forced to allocate
32894 extra space either on the stack or data space.
32895 If this extra space allocation is undesirable then induction optimization
32896 can be eliminated either for the entire source file (with -
32900 \begin_layout Standard
32909 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32911 \begin_inset LatexCommand \index{\#pragma noinduction}
32922 \begin_layout Verse
32925 for (i = 0 ; i < 100 ; i ++)
32934 \begin_layout Standard
32938 \begin_layout Verse
32943 for (i = 0; i < 100; i++)
32952 \begin_layout Standard
32953 As mentioned previously some loop invariants are not as apparent, all static
32954 address computations are also moved out of the loop.
32959 \begin_inset LatexCommand \index{Strength reduction}
32963 , this optimization substitutes an expression by a cheaper expression:
32966 \begin_layout Verse
32969 for (i=0;i < 100; i++)
32978 \begin_layout Standard
32982 \begin_layout Verse
32989 for (i=0;i< 100;i++) {
32995 ar[itemp1] = itemp2;
33013 \begin_layout Standard
33014 The more expensive multiplication
33015 \begin_inset LatexCommand \index{Multiplication}
33019 is changed to a less expensive addition.
33022 \begin_layout Subsection
33024 \begin_inset LatexCommand \index{Loop reversing}
33031 \begin_layout Standard
33032 This optimization is done to reduce the overhead of checking loop boundaries
33033 for every iteration.
33034 Some simple loops can be reversed and implemented using a
33035 \begin_inset Quotes eld
33038 decrement and jump if not zero
33039 \begin_inset Quotes erd
33043 SDCC checks for the following criterion to determine if a loop is reversible
33044 (note: more sophisticated compilers use data-dependency analysis to make
33045 this determination, SDCC uses a more simple minded analysis).
33048 \begin_layout Itemize
33049 The 'for' loop is of the form
33055 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33065 \begin_layout Itemize
33066 The <for body> does not contain
33067 \begin_inset Quotes eld
33071 \begin_inset Quotes erd
33075 \begin_inset Quotes erd
33081 \begin_layout Itemize
33082 All goto's are contained within the loop.
33085 \begin_layout Itemize
33086 No function calls within the loop.
33089 \begin_layout Itemize
33090 The loop control variable <sym> is not assigned any value within the loop
33093 \begin_layout Itemize
33094 The loop control variable does NOT participate in any arithmetic operation
33098 \begin_layout Itemize
33099 There are NO switch statements in the loop.
33102 \begin_layout Subsection
33103 Algebraic Simplifications
33106 \begin_layout Standard
33107 SDCC does numerous algebraic simplifications, the following is a small sub-set
33108 of these optimizations.
33111 \begin_layout Verse
33114 i = j + 0;\InsetSpace ~
33118 /* changed to: */\InsetSpace ~
33124 i /= 2;\InsetSpace ~
33131 /* changed to: */\InsetSpace ~
33138 = j - j;\InsetSpace ~
33142 /* changed to: */\InsetSpace ~
33148 i = j / 1;\InsetSpace ~
33152 /* changed to: */\InsetSpace ~
33159 \begin_layout Standard
33160 Note the subexpressions
33161 \begin_inset LatexCommand \index{Subexpression}
33165 given above are generally introduced by macro expansions or as a result
33166 of copy/constant propagation.
33169 \begin_layout Subsection
33170 'switch' Statements
33171 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33176 \begin_inset LatexCommand \index{switch statement}
33183 \begin_layout Standard
33184 SDCC can optimize switch statements to jump tables
33185 \begin_inset LatexCommand \index{jump tables}
33190 It makes the decision based on an estimate of the generated code size.
33191 SDCC is quite liberal in the requirements for jump table generation:
33194 \begin_layout Itemize
33195 The labels need not be in order, and the starting number need not be one
33196 or zero, the case labels are in numerical sequence or not too many case
33197 labels are missing.
33201 \begin_layout Verse
33204 switch(i) {\InsetSpace ~
33235 case 4: ...\InsetSpace ~
33267 case 5: ...\InsetSpace ~
33299 case 3: ...\InsetSpace ~
33330 case 6: ...\InsetSpace ~
33362 case 7: ...\InsetSpace ~
33394 case 8: ...\InsetSpace ~
33426 case 9: ...\InsetSpace ~
33458 case 10: ...\InsetSpace ~
33489 case 11: ...\InsetSpace ~
33556 \begin_layout Standard
33557 Both the above switch statements will be implemented using a jump-table.
33558 The example to the right side is slightly more efficient as the check for
33559 the lower boundary of the jump-table is not needed.
33563 \begin_layout Itemize
33564 The number of case labels is not larger than supported by the target architectur
33568 \begin_layout Itemize
33569 If the case labels are not in numerical sequence ('gaps' between cases)
33570 SDCC checks whether a jump table with additionally inserted dummy cases
33571 is still attractive.
33575 \begin_layout Itemize
33576 If the starting number is not zero and a check for the lower boundary of
33577 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33582 \begin_layout Standard
33583 Switch statements which have large gaps in the numeric sequence or those
33584 that have too many case labels can be split into more than one switch statement
33585 for efficient code generation, e.g.:
33588 \begin_layout Verse
33666 \begin_layout Standard
33667 If the above switch statement is broken down into two switch statements
33670 \begin_layout Verse
33713 \begin_layout Standard
33717 \begin_layout Verse
33760 \begin_layout Standard
33761 then both the switch statements will be implemented using jump-tables whereas
33762 the unmodified switch statement will not be.
33765 \begin_layout Standard
33766 \begin_inset Note Note
33769 \begin_layout Standard
33770 There might be reasons which SDCC cannot know about to either favour or
33771 not favour jump tables.
33772 If the target system has to be as quick for the last switch case as for
33773 the first (pro jump table), or if the switch argument is known to be zero
33774 in the majority of the cases (contra jump table).
33782 \begin_layout Standard
33783 The pragma nojtbound
33784 \begin_inset LatexCommand \index{\#pragma nojtbound}
33788 can be used to turn off checking the
33801 It has no effect if a default label is supplied.
33802 Use of this pragma is dangerous: if the switch
33803 \begin_inset LatexCommand \index{switch statement}
33807 argument is not matched by a case statement the processor will happily
33811 \begin_layout Subsection
33812 Bit-shifting Operations
33813 \begin_inset LatexCommand \index{Bit shifting}
33820 \begin_layout Standard
33821 Bit shifting is one of the most frequently used operation in embedded programmin
33823 SDCC tries to implement bit-shift operations in the most efficient way
33827 \begin_layout Verse
33840 \begin_layout Standard
33841 generates the following code:
33844 \begin_layout Verse
33859 \begin_layout Standard
33860 In general SDCC will never setup a loop if the shift count is known.
33864 \begin_layout Verse
33877 \begin_layout Standard
33881 \begin_layout Verse
33905 \begin_layout Subsection
33907 \begin_inset LatexCommand \index{Bit rotation}
33914 \begin_layout Standard
33915 A special case of the bit-shift operation is bit rotation
33916 \begin_inset LatexCommand \index{rotating bits}
33920 , SDCC recognizes the following expression to be a left bit-rotation:
33923 \begin_layout Verse
33931 char i;\InsetSpace ~
33942 /* unsigned is needed for rotation */
33947 i = ((i << 1) | (i >> 7));
33956 \begin_layout Standard
33957 will generate the following code:
33960 \begin_layout Verse
33977 \begin_layout Standard
33978 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33979 ns of this case will also be recognized as bit-rotation, i.e.:
33982 \begin_layout Verse
33985 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33988 \begin_layout Subsection
33989 Nibble and Byte Swapping
33992 \begin_layout Standard
33993 Other special cases of the bit-shift operations are nibble or byte swapping
33994 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33998 , SDCC recognizes the following expressions:
34001 \begin_layout Verse
34022 i = ((i << 4) | (i >> 4));
34028 j = ((j << 8) | (j >> 8));
34031 \begin_layout Standard
34032 and generates a swap instruction for the nibble swapping
34033 \begin_inset LatexCommand \index{Nibble swapping}
34037 or move instructions for the byte swapping
34038 \begin_inset LatexCommand \index{Byte swapping}
34044 \begin_inset Quotes sld
34048 \begin_inset Quotes srd
34051 example can be used to convert from little to big-endian or vice versa.
34052 If you want to change the endianness of a
34056 integer you have to cast to
34063 \begin_layout Standard
34064 Note that SDCC stores numbers in little-endian
34068 \begin_layout Standard
34069 Usually 8-bit processors don't care much about endianness.
34070 This is not the case for the standard 8051 which only has an instruction
34076 \begin_inset LatexCommand \index{DPTR}
34084 so little-endian is the more efficient byte order.
34090 \begin_inset LatexCommand \index{little-endian}
34095 \begin_inset LatexCommand \index{Endianness}
34100 lowest order first).
34103 \begin_layout Subsection
34105 \begin_inset LatexCommand \index{Highest Order Bit}
34110 \begin_inset LatexCommand \index{Any Order Bit}
34117 \begin_layout Standard
34118 It is frequently required to obtain the highest order bit of an integral
34119 type (long, int, short or char types).
34120 Also obtaining any other order bit is not uncommon.
34121 SDCC recognizes the following expressions to yield the highest order bit
34122 and generates optimized code for it, e.g.:
34125 \begin_layout Verse
34136 unsigned char hob1, aob1;
34140 bit hob2, hob3, aob2,
34150 hob1 = (gint >> 15) & 1;
34154 hob2 = (gint >> 15) & 1;
34158 hob3 = gint & 0x8000;
34163 aob1 = (gint >> 9) & 1;
34167 aob2 = (gint >> 8) & 1;
34171 aob3 = gint & 0x0800;
34181 \begin_layout Standard
34182 will generate the following code:
34185 \begin_layout Verse
34216 000A E5*01\InsetSpace ~
34243 000C 23\InsetSpace ~
34274 000D 54 01\InsetSpace ~
34302 000F F5*02\InsetSpace ~
34357 0011 E5*01\InsetSpace ~
34385 0013 33\InsetSpace ~
34415 0014 92*00\InsetSpace ~
34471 0016 E5*01\InsetSpace ~
34498 0018 33\InsetSpace ~
34528 0019 92*01\InsetSpace ~
34584 001B E5*01\InsetSpace ~
34643 001E 54 01\InsetSpace ~
34670 0020 F5*03\InsetSpace ~
34726 0022 E5*01\InsetSpace ~
34753 0024 13\InsetSpace ~
34783 0025 92*02\InsetSpace ~
34839 0027 E5*01\InsetSpace ~
34894 002B 92*03\InsetSpace ~
34922 \begin_layout Standard
34923 Other variations of these cases however will
34928 They are standard C expressions, so I heartily recommend these be the only
34929 way to get the highest order bit, (it is portable).
34930 Of course it will be recognized even if it is embedded in other expressions,
34934 \begin_layout Verse
34937 xyz = gint + ((gint >> 15) & 1);
34940 \begin_layout Standard
34941 will still be recognized.
34944 \begin_layout Subsection
34946 \begin_inset LatexCommand \index{Higher Order Byte}
34950 / Higher Order Word
34951 \begin_inset LatexCommand \index{Higher Order Word}
34958 \begin_layout Standard
34959 It is also frequently required to obtain a higher order byte or word of
34960 a larger integral type (long, int or short types).
34961 SDCC recognizes the following expressions to yield the higher order byte
34962 or word and generates optimized code for it, e.g.:
34965 \begin_layout Verse
34970 unsigned long int glong;
34978 unsigned char hob1,
34983 unsigned int how1, how2;
34992 hob1 = (gint >> 8) & 0xFF;
34996 hob2 = glong >> 24;
35000 how1 = (glong >> 16) & 0xFFFF;
35015 \begin_layout Standard
35016 will generate the following code:
35019 \begin_layout Verse
35050 0037 85*01*06\InsetSpace ~
35072 _foo_hob1_1_1,(_gint + 1)
35103 003A 85*05*07\InsetSpace ~
35125 _foo_hob2_1_1,(_glong + 3)
35155 003D 85*04*08\InsetSpace ~
35178 _foo_how1_1_1,(_glong + 2)
35180 0040 85*05*09\InsetSpace ~
35205 0043 85*03*0A\InsetSpace ~
35227 _foo_how2_1_1,(_glong + 1)
35229 0046 85*04*0B\InsetSpace ~
35252 (_foo_how2_1_1 + 1),(_glong + 2)
35255 \begin_layout Standard
35256 Again, variations of these cases may
35261 They are standard C expressions, so I heartily recommend these be the only
35262 way to get the higher order byte/word, (it is portable).
35263 Of course it will be recognized even if it is embedded in other expressions,
35267 \begin_layout Verse
35270 xyz = gint + ((gint >> 8) & 0xFF);
35273 \begin_layout Standard
35274 will still be recognized.
35277 \begin_layout Subsection
35279 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35284 \begin_inset LatexCommand \index{Peephole optimizer}
35291 \begin_layout Standard
35292 The compiler uses a rule based, pattern matching and re-writing mechanism
35293 for peep-hole optimization.
35298 a peep-hole optimizer by Christopher W.
35299 Fraser (cwfraser\InsetSpace ~
35302 A default set of rules are compiled into the compiler, additional rules
35303 may be added with the
35309 \begin_layout Standard
35319 \begin_inset LatexCommand \index{-\/-peep-file}
35326 The rule language is best illustrated with examples.
35329 \begin_layout Verse
35351 \begin_layout Standard
35352 The above rule will change the following assembly
35353 \begin_inset LatexCommand \index{Assembler routines}
35360 \begin_layout Verse
35368 \begin_layout Standard
35372 \begin_layout Verse
35378 \begin_layout Standard
35379 Note: All occurrences of a
35383 (pattern variable) must denote the same string.
35384 With the above rule, the assembly sequence:
35387 \begin_layout Verse
35395 \begin_layout Standard
35396 will remain unmodified.
35400 Other special case optimizations may be added by the
35407 \begin_layout Standard
35420 some variants of the 8051 MCU
35421 \begin_inset LatexCommand \index{MCS51 variants}
35434 The following two rules will change all
35451 \begin_layout Verse
35454 replace { lcall %1 } by { acall %1 }
35456 replace { ljmp %1 } by { ajmp %1 }
35459 \begin_layout Standard
35462 inline-assembler code
35464 is also passed through the peep hole optimizer, thus the peephole optimizer
35465 can also be used as an assembly level macro expander.
35466 The rules themselves are MCU dependent whereas the rule language infra-structur
35467 e is MCU independent.
35468 Peephole optimization rules for other MCU can be easily programmed using
35473 The syntax for a rule is as follows:
35476 \begin_layout Verse
35479 rule := replace [ restart ] '{' <assembly sequence> '
35517 <assembly sequence> '
35535 '}' [if <functionName> ] '
35540 \begin_layout Standard
35541 <assembly sequence> := assembly instruction (each instruction including
35542 labels must be on a separate line).
35546 The optimizer will apply to the rules
35547 one by one from the top in the sequence of their appearance, it will terminate
35548 when all rules are exhausted.
35549 If the 'restart' option is specified, then the optimizer will start matching
35550 the rules again from the top, this option for a rule is expensive (performance)
35551 , it is intended to be used in situations where a transformation will trigger
35552 the same rule again.
35553 An example of this (not a good one, it has side effects) is the following
35557 \begin_layout Verse
35577 \begin_layout Standard
35578 Note that the replace pattern cannot be a blank, but can be a comment line.
35579 Without the 'restart' option only the innermost 'pop' 'push' pair would
35580 be eliminated, i.e.:
35583 \begin_layout Verse
35595 \begin_layout Standard
35599 \begin_layout Verse
35609 \begin_layout Standard
35614 the restart option the rule will be applied again to the resulting code
35615 and then all the pop-push pairs will be eliminated to yield:
35618 \begin_layout Verse
35626 \begin_layout Standard
35627 A conditional function can be attached to a rule.
35628 Attaching rules are somewhat more involved, let me illustrate this with
35632 \begin_layout Verse
35656 \begin_layout Standard
35657 The optimizer does a look-up of a function name table defined in function
35662 in the source file SDCCpeeph.c, with the name
35667 If it finds a corresponding entry the function is called.
35668 Note there can be no parameters specified for these functions, in this
35673 is crucial, since the function
35677 expects to find the label in that particular variable (the hash table containin
35678 g the variable bindings is passed as a parameter).
35679 If you want to code more such functions, take a close look at the function
35680 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35681 Currently implemented are
35683 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35684 24bitMode, portIsDS390, 24bitModeAndPortDS390
35693 \begin_layout Standard
35694 I know this whole thing is a little kludgey, but maybe some day we will
35695 have some better means.
35696 If you are looking at this file, you will see the default rules that are
35697 compiled into the compiler, you can add your own rules in the default set
35698 there if you get tired of specifying the -
35702 \begin_layout Standard
35714 \begin_layout Section
35716 \begin_inset LatexCommand \index{ANSI-compliance}
35721 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35728 \begin_layout Standard
35729 The latest publically available version of the standard
35731 ISO/IEC 9899 - Programming languages - C
35733 should be available at:
35734 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35743 \begin_layout Standard
35744 Deviations from the compliance:
35747 \begin_layout Itemize
35748 functions are not reentrant
35749 \begin_inset LatexCommand \index{reentrant}
35753 unless explicitly declared as such or the
35759 \begin_layout Standard
35769 \begin_inset LatexCommand \index{-\/-stack-auto}
35775 command line option is specified.
35778 \begin_layout Itemize
35780 \begin_inset LatexCommand \index{struct}
35785 \begin_inset LatexCommand \index{union}
35789 cannot be assigned values directly, cannot be passed as function parameters
35790 or assigned to each other and cannot be a return value
35791 \begin_inset LatexCommand \index{return value}
35795 from a function, e.g.:
35799 \begin_layout Verse
35822 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35841 s parms) /* invalid in SDCC although allowed in ANSI */
35863 return rets; /* is invalid in SDCC although allowed in ANSI */
35869 \begin_layout Itemize
35870 initialization of structure arrays must be fully braced.
35874 \begin_layout Verse
35877 struct s { char x } a[] = {1, 2};\InsetSpace ~
35882 /* invalid in SDCC */
35885 } a[] = {{1}, {2}}; /* OK */
35889 \begin_layout Itemize
35891 \begin_inset LatexCommand \index{long long (not supported)}
35896 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35903 \begin_layout Itemize
35905 \begin_inset LatexCommand \index{double (not supported)}
35909 ' precision floating point
35910 \begin_inset LatexCommand \index{Floating point support}
35917 \begin_layout Itemize
35919 \begin_inset LatexCommand \index{K\&R style}
35923 function declarations are NOT allowed.
35927 \begin_layout Verse
35930 foo(i,j) /* this old style of function declarations */
35932 int i,j; /* are valid
35933 in ANSI but not valid in SDCC */
35948 \begin_layout Itemize
35949 Most enhancements in C99 are not supported, f.e.:
35953 \begin_layout Verse
35958 \begin_inset LatexCommand \index{inline (not supported)}
35964 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35970 can be used as a work around */
35978 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35982 \begin_layout Itemize
35983 Certain words that are valid identifiers in the standard may be reserved
35984 words in SDCC unless the
35990 \begin_layout Standard
36000 \begin_inset LatexCommand \index{-\/-std-c89}
36008 \begin_layout Standard
36018 \begin_inset LatexCommand \index{-\/-std-c99}
36024 command line options are used.
36025 These may include (depending on the selected processor): 'at', 'banked',
36026 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36027 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36028 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36030 Compliant equivalents of these keywords are always available in a form
36031 that begin with two underscores
36032 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36037 '__data' instead of 'data'.
36040 \begin_layout Section
36041 Cyclomatic Complexity
36042 \begin_inset LatexCommand \index{Cyclomatic complexity}
36049 \begin_layout Standard
36050 Cyclomatic complexity of a function is defined as the number of independent
36051 paths the program can take during execution of the function.
36052 This is an important number since it defines the number test cases you
36053 have to generate to validate the function.
36054 The accepted industry standard for complexity number is 10, if the cyclomatic
36055 complexity reported by SDCC exceeds 10 you should think about simplification
36056 of the function logic.
36057 Note that the complexity level is not related to the number of lines of
36058 code in a function.
36059 Large functions can have low complexity, and small functions can have large
36065 SDCC uses the following formula to compute the complexity:
36070 \begin_layout Standard
36071 complexity = (number of edges in control flow graph) - (number of nodes
36072 in control flow graph) + 2;
36076 Having said that the industry standard is 10,
36077 you should be aware that in some cases it be may unavoidable to have a
36078 complexity level of less than 10.
36079 For example if you have switch statement with more than 10 case labels,
36080 each case label adds one to the complexity level.
36081 The complexity level is by no means an absolute measure of the algorithmic
36082 complexity of the function, it does however provide a good starting point
36083 for which functions you might look at for further optimization.
36086 \begin_layout Section
36087 Retargetting for other Processors
36090 \begin_layout Standard
36091 The issues for retargetting the compiler are far too numerous to be covered
36093 What follows is a brief description of each of the seven phases of the
36094 compiler and its MCU dependency.
36097 \begin_layout Itemize
36098 Parsing the source and building the annotated parse tree.
36099 This phase is largely MCU independent (except for the language extensions).
36100 Syntax & semantic checks are also done in this phase, along with some initial
36101 optimizations like back patching labels and the pattern matching optimizations
36102 like bit-rotation etc.
36105 \begin_layout Itemize
36106 The second phase involves generating an intermediate code which can be easy
36107 manipulated during the later phases.
36108 This phase is entirely MCU independent.
36109 The intermediate code generation assumes the target machine has unlimited
36110 number of registers, and designates them with the name iTemp.
36111 The compiler can be made to dump a human readable form of the code generated
36116 \begin_layout Standard
36128 \begin_layout Itemize
36129 This phase does the bulk of the standard optimizations and is also MCU independe
36131 This phase can be broken down into several sub-phases:
36135 Break down intermediate
36136 code (iCode) into basic blocks.
36138 Do control flow & data flow analysis on the
36141 Do local common subexpression elimination, then global subexpressio
36144 Dead code elimination
36148 If loop optimizations
36149 caused any changes then do 'global subexpression elimination' and 'dead
36150 code elimination' again.
36153 \begin_layout Itemize
36154 This phase determines the live-ranges; by live range I mean those iTemp
36155 variables defined by the compiler that still survive after all the optimization
36157 Live range analysis
36158 \begin_inset LatexCommand \index{Live range analysis}
36162 is essential for register allocation, since these computation determines
36163 which of these iTemps will be assigned to registers, and for how long.
36166 \begin_layout Itemize
36167 Phase five is register allocation.
36168 There are two parts to this process.
36172 The first part I call 'register packing'
36173 (for lack of a better term).
36174 In this case several MCU specific expression folding is done to reduce
36179 The second part is more MCU independent and deals with
36180 allocating registers to the remaining live ranges.
36181 A lot of MCU specific code does creep into this phase because of the limited
36182 number of index registers available in the 8051.
36185 \begin_layout Itemize
36186 The Code generation phase is (unhappily), entirely MCU dependent and very
36187 little (if any at all) of this code can be reused for other MCU.
36188 However the scheme for allocating a homogenized assembler operand for each
36189 iCode operand may be reused.
36192 \begin_layout Itemize
36193 As mentioned in the optimization section the peep-hole optimizer is rule
36194 based system, which can reprogrammed for other MCUs.
36197 \begin_layout Standard
36198 More information is available in a wiki
36199 \begin_inset LatexCommand \index{wiki}
36204 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36208 ) and in the thread
36209 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36216 \begin_layout Chapter
36218 \begin_inset LatexCommand \index{Compiler internals}
36225 \begin_layout Section
36226 The anatomy of the compiler
36227 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36234 \begin_layout Standard
36237 This is an excerpt from an article published in Circuit Cellar Magazine
36243 It's a little outdated (the compiler is much more efficient now and user/develo
36244 per friendly), but pretty well exposes the guts of it all.
36250 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36251 It is fairly easy to retarget for other 8-bit MCU.
36252 Here we take a look at some of the internals of the compiler.
36256 \begin_layout Paragraph*
36258 \begin_inset LatexCommand \index{Parsing}
36265 \begin_layout Standard
36266 Parsing the input source file and creating an AST (Annotated Syntax Tree
36267 \begin_inset LatexCommand \index{Annotated syntax tree}
36272 This phase also involves propagating types (annotating each node of the
36273 parse tree with type information) and semantic analysis.
36274 There are some MCU specific parsing rules.
36275 For example the storage classes, the extended storage classes are MCU specific
36276 while there may be a xdata storage class for 8051 there is no such storage
36277 class for z80 or Atmel AVR.
36278 SDCC allows MCU specific storage class extensions, i.e.
36279 xdata will be treated as a storage class specifier when parsing 8051 C
36280 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36284 \begin_layout Paragraph*
36286 \begin_inset LatexCommand \index{iCode}
36293 \begin_layout Standard
36294 Intermediate code generation.
36295 In this phase the AST is broken down into three-operand form (iCode).
36296 These three operand forms are represented as doubly linked lists.
36297 ICode is the term given to the intermediate form generated by the compiler.
36298 ICode example section shows some examples of iCode generated for some simple
36299 C source functions.
36302 \begin_layout Paragraph*
36304 \begin_inset LatexCommand \index{Optimizations}
36311 \begin_layout Standard
36312 Bulk of the target independent optimizations is performed in this phase.
36313 The optimizations include constant propagation, common sub-expression eliminati
36314 on, loop invariant code movement, strength reduction of loop induction variables
36315 and dead-code elimination.
36318 \begin_layout Paragraph*
36319 Live range analysis
36320 \begin_inset LatexCommand \index{Live range analysis}
36327 \begin_layout Standard
36328 During intermediate code generation phase, the compiler assumes the target
36329 machine has infinite number of registers and generates a lot of temporary
36331 The live range computation determines the lifetime of each of these compiler-ge
36332 nerated temporaries.
36333 A picture speaks a thousand words.
36334 ICode example sections show the live range annotations for each of the
36336 It is important to note here, each iCode is assigned a number in the order
36337 of its execution in the function.
36338 The live ranges are computed in terms of these numbers.
36339 The from number is the number of the iCode which first defines the operand
36340 and the to number signifies the iCode which uses this operand last.
36343 \begin_layout Paragraph*
36344 Register Allocation
36345 \begin_inset LatexCommand \index{Register allocation}
36352 \begin_layout Standard
36353 The register allocation determines the type and number of registers needed
36355 In most MCUs only a few registers can be used for indirect addressing.
36356 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36357 address the internal ram and DPTR to indirectly address the external ram.
36358 The compiler will try to allocate the appropriate register to pointer variables
36360 ICode example section shows the operands annotated with the registers assigned
36362 The compiler will try to keep operands in registers as much as possible;
36363 there are several schemes the compiler uses to do achieve this.
36364 When the compiler runs out of registers the compiler will check to see
36365 if there are any live operands which is not used or defined in the current
36366 basic block being processed, if there are any found then it will push that
36367 operand and use the registers in this block, the operand will then be popped
36368 at the end of the basic block.
36372 \begin_layout Standard
36373 There are other MCU specific considerations in this phase.
36374 Some MCUs have an accumulator; very short-lived operands could be assigned
36375 to the accumulator instead of a general-purpose register.
36378 \begin_layout Paragraph*
36382 \begin_layout Standard
36383 Figure II gives a table of iCode
36384 \begin_inset LatexCommand \index{iCode}
36388 operations supported by the compiler.
36389 The code generation involves translating these operations into corresponding
36390 assembly code for the processor.
36391 This sounds overly simple but that is the essence of code generation.
36392 Some of the iCode operations are generated on a MCU specific manner for
36393 example, the z80 port does not use registers to pass parameters so the
36394 SEND and RECV iCode operations will not be generated, and it also does
36395 not support JUMPTABLES.
36401 \begin_layout Standard
36405 \begin_inset Tabular
36406 <lyxtabular version="3" rows="39" columns="4">
36407 <features islongtable="true" headBottomDL="true">
36408 <column alignment="block" valignment="top" leftline="true" width="13col%">
36409 <column alignment="left" valignment="top" leftline="true" width="13col%">
36410 <column alignment="block" valignment="top" leftline="true" width="22col%">
36411 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36412 <row topline="true" bottomline="true" endhead="true">
36413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36416 \begin_layout Standard
36422 \begin_inset LatexCommand \index{iCode}
36431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36434 \begin_layout Standard
36442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36445 \begin_layout Standard
36453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36456 \begin_layout Standard
36465 <row topline="true">
36466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36469 \begin_layout Standard
36477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36480 \begin_layout Standard
36483 IC_LEFT() IC_RESULT()
36488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36491 \begin_layout Standard
36499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36502 \begin_layout Standard
36505 IC_RESULT = ! IC_LEFT;
36511 <row topline="true">
36512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36515 \begin_layout Standard
36523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36526 \begin_layout Standard
36529 IC_LEFT() IC_RESULT()
36534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36537 \begin_layout Standard
36540 Bitwise complement of
36545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36548 \begin_layout Standard
36551 IC_RESULT = ~IC_LEFT;
36557 <row topline="true">
36558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36561 \begin_layout Standard
36569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36572 \begin_layout Standard
36575 IC_LEFT() IC_RESULT()
36580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36583 \begin_layout Standard
36586 Rotate right with carry
36591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36594 \begin_layout Standard
36597 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36603 <row topline="true">
36604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36607 \begin_layout Standard
36615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36618 \begin_layout Standard
36621 IC_LEFT() IC_RESULT()
36626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36629 \begin_layout Standard
36632 Rotate left with carry
36637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36640 \begin_layout Standard
36643 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36649 <row topline="true">
36650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36653 \begin_layout Standard
36661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36664 \begin_layout Standard
36667 IC_LEFT() IC_RESULT()
36672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36675 \begin_layout Standard
36678 Get the highest order bit of IC_LEFT
36683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36686 \begin_layout Standard
36689 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36695 <row topline="true">
36696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36699 \begin_layout Standard
36707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36710 \begin_layout Standard
36713 IC_LEFT() IC_RESULT()
36718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36721 \begin_layout Standard
36729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36732 \begin_layout Standard
36735 IC_RESULT = - IC_LEFT;
36741 <row topline="true">
36742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36745 \begin_layout Standard
36753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36756 \begin_layout Standard
36764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36767 \begin_layout Standard
36770 Push the operand into stack
36775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36778 \begin_layout Standard
36787 <row topline="true">
36788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36791 \begin_layout Standard
36799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36802 \begin_layout Standard
36810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36813 \begin_layout Standard
36816 Pop the operand from the stack
36821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36824 \begin_layout Standard
36833 <row topline="true">
36834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36837 \begin_layout Standard
36845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36848 \begin_layout Standard
36851 IC_LEFT() IC_RESULT()
36856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36859 \begin_layout Standard
36862 Call the function represented by IC_LEFT
36867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36870 \begin_layout Standard
36873 IC_RESULT = IC_LEFT();
36879 <row topline="true">
36880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36883 \begin_layout Standard
36891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36894 \begin_layout Standard
36897 IC_LEFT() IC_RESULT()
36902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36905 \begin_layout Standard
36908 Call via function pointer
36913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36916 \begin_layout Standard
36919 IC_RESULT = (*IC_LEFT)();
36925 <row topline="true">
36926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36929 \begin_layout Standard
36937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36940 \begin_layout Standard
36948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36951 \begin_layout Standard
36954 Return the value in operand IC_LEFT
36959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36962 \begin_layout Standard
36971 <row topline="true">
36972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36975 \begin_layout Standard
36983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36986 \begin_layout Standard
36994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36997 \begin_layout Standard
37005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37008 \begin_layout Standard
37017 <row topline="true">
37018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37021 \begin_layout Standard
37029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37032 \begin_layout Standard
37040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37043 \begin_layout Standard
37051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37054 \begin_layout Standard
37063 <row topline="true">
37064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37067 \begin_layout Standard
37075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37078 \begin_layout Standard
37081 IC_LEFT() IC_RIGHT() IC_RESULT()
37086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37089 \begin_layout Standard
37097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37100 \begin_layout Standard
37103 IC_RESULT = IC_LEFT + IC_RIGHT
37109 <row topline="true">
37110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37113 \begin_layout Standard
37121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37124 \begin_layout Standard
37127 IC_LEFT() IC_RIGHT() IC_RESULT()
37132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37135 \begin_layout Standard
37143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37146 \begin_layout Standard
37149 IC_RESULT = IC_LEFT - IC_RIGHT
37155 <row topline="true">
37156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37159 \begin_layout Standard
37167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37170 \begin_layout Standard
37173 IC_LEFT() IC_RIGHT() IC_RESULT()
37178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37181 \begin_layout Standard
37189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37192 \begin_layout Standard
37195 IC_RESULT = IC_LEFT * IC_RIGHT;
37201 <row topline="true">
37202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37205 \begin_layout Standard
37213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37216 \begin_layout Standard
37219 IC_LEFT() IC_RIGHT() IC_RESULT()
37224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37227 \begin_layout Standard
37235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37238 \begin_layout Standard
37241 IC_RESULT = IC_LEFT / IC_RIGHT;
37247 <row topline="true">
37248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37251 \begin_layout Standard
37259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37262 \begin_layout Standard
37265 IC_LEFT() IC_RIGHT() IC_RESULT()
37270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37273 \begin_layout Standard
37281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37284 \begin_layout Standard
37287 IC_RESULT = IC_LEFT % IC_RIGHT;
37293 <row topline="true">
37294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37297 \begin_layout Standard
37305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37308 \begin_layout Standard
37311 IC_LEFT() IC_RIGHT() IC_RESULT()
37316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37319 \begin_layout Standard
37327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37330 \begin_layout Standard
37333 IC_RESULT = IC_LEFT < IC_RIGHT;
37339 <row topline="true">
37340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37343 \begin_layout Standard
37351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37354 \begin_layout Standard
37357 IC_LEFT() IC_RIGHT() IC_RESULT()
37362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37365 \begin_layout Standard
37373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37376 \begin_layout Standard
37379 IC_RESULT = IC_LEFT > IC_RIGHT;
37385 <row topline="true">
37386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37389 \begin_layout Standard
37397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37400 \begin_layout Standard
37403 IC_LEFT() IC_RIGHT() IC_RESULT()
37408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37411 \begin_layout Standard
37419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37422 \begin_layout Standard
37425 IC_RESULT = IC_LEFT == IC_RIGHT;
37431 <row topline="true">
37432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37435 \begin_layout Standard
37443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37446 \begin_layout Standard
37449 IC_LEFT() IC_RIGHT() IC_RESULT()
37454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37457 \begin_layout Standard
37460 Logical and operation
37465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37468 \begin_layout Standard
37471 IC_RESULT = IC_LEFT && IC_RIGHT;
37477 <row topline="true">
37478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37481 \begin_layout Standard
37489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37492 \begin_layout Standard
37495 IC_LEFT() IC_RIGHT() IC_RESULT()
37500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37503 \begin_layout Standard
37506 Logical or operation
37511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37514 \begin_layout Standard
37517 IC_RESULT = IC_LEFT || IC_RIGHT;
37523 <row topline="true">
37524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37527 \begin_layout Standard
37535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37538 \begin_layout Standard
37541 IC_LEFT() IC_RIGHT() IC_RESULT()
37546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37549 \begin_layout Standard
37557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37560 \begin_layout Standard
37563 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37569 <row topline="true">
37570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37573 \begin_layout Standard
37581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37584 \begin_layout Standard
37587 IC_LEFT() IC_RIGHT() IC_RESULT()
37592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37595 \begin_layout Standard
37603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37606 \begin_layout Standard
37609 IC_RESULT = IC_LEFT | IC_RIGHT;
37615 <row topline="true">
37616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37619 \begin_layout Standard
37627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37630 \begin_layout Standard
37633 IC_LEFT() IC_RIGHT() IC_RESULT()
37638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37641 \begin_layout Standard
37649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37652 \begin_layout Standard
37655 IC_RESULT = IC_LEFT & IC_RIGHT;
37661 <row topline="true">
37662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37665 \begin_layout Standard
37673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37676 \begin_layout Standard
37679 IC_LEFT() IC_RIGHT() IC_RESULT()
37684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37687 \begin_layout Standard
37695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37698 \begin_layout Standard
37701 IC_RESULT = IC_LEFT << IC_RIGHT
37707 <row topline="true">
37708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37711 \begin_layout Standard
37719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37722 \begin_layout Standard
37725 IC_LEFT() IC_RIGHT() IC_RESULT()
37730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37733 \begin_layout Standard
37741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37744 \begin_layout Standard
37747 IC_RESULT = IC_LEFT >> IC_RIGHT
37753 <row topline="true">
37754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37757 \begin_layout Standard
37767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37770 \begin_layout Standard
37773 IC_LEFT() IC_RESULT()
37778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37781 \begin_layout Standard
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37792 \begin_layout Standard
37795 IC_RESULT = (*IC_LEFT);
37801 <row topline="true">
37802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37805 \begin_layout Standard
37813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37816 \begin_layout Standard
37819 IC_RIGHT() IC_RESULT()
37824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37827 \begin_layout Standard
37835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37838 \begin_layout Standard
37841 (*IC_RESULT) = IC_RIGHT;
37847 <row topline="true">
37848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37851 \begin_layout Standard
37859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37862 \begin_layout Standard
37865 IC_RIGHT() IC_RESULT()
37870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37873 \begin_layout Standard
37881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37884 \begin_layout Standard
37887 IC_RESULT = IC_RIGHT;
37893 <row topline="true">
37894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37897 \begin_layout Standard
37905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37908 \begin_layout Standard
37911 IC_COND IC_TRUE IC_LABEL
37916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37919 \begin_layout Standard
37923 If true label is present then jump to true label if condition is true else
37924 jump to false label if condition is false
37929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37932 \begin_layout Standard
37935 if (IC_COND) goto IC_TRUE;
37941 If (!IC_COND) goto IC_FALSE;
37947 <row topline="true">
37948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37951 \begin_layout Standard
37959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37962 \begin_layout Standard
37965 IC_LEFT() IC_RESULT()
37970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37973 \begin_layout Standard
37981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37984 \begin_layout Standard
37987 IC_RESULT = &IC_LEFT();
37993 <row topline="true">
37994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37997 \begin_layout Standard
38005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38008 \begin_layout Standard
38011 IC_JTCOND IC_JTLABELS
38016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38019 \begin_layout Standard
38022 Jump to list of labels depending on the value of JTCOND
38027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38030 \begin_layout Standard
38039 <row topline="true">
38040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38043 \begin_layout Standard
38051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38054 \begin_layout Standard
38057 IC_RIGHT() IC_LEFT() IC_RESULT()
38062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38065 \begin_layout Standard
38073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38076 \begin_layout Standard
38079 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38085 <row topline="true">
38086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38089 \begin_layout Standard
38097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38100 \begin_layout Standard
38108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38111 \begin_layout Standard
38114 This is used for passing parameters in registers;
38116 move IC_LEFT to the next
38117 available parameter register.
38122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38125 \begin_layout Standard
38134 <row topline="true">
38135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38138 \begin_layout Standard
38146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38149 \begin_layout Standard
38157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38160 \begin_layout Standard
38163 This is used for receiving parameters passed in registers;
38166 in the next parameter register to IC_RESULT
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38174 \begin_layout Standard
38183 <row topline="true" bottomline="true">
38184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38187 \begin_layout Standard
38191 (some more have been added)
38196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38199 \begin_layout Standard
38205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38208 \begin_layout Standard
38214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38217 \begin_layout Standard
38241 \begin_layout Standard
38242 \begin_inset Note Note
38245 \begin_layout Standard
38246 In the original article Figure II was announced to be downloadable on
38251 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38259 \begin_layout Paragraph*
38261 \begin_inset LatexCommand \index{iCode}
38268 \begin_layout Standard
38269 This section shows some details of iCode.
38270 The example C code does not do anything useful; it is used as an example
38271 to illustrate the intermediate code generated by the compiler.
38274 \begin_layout Verse
38284 /* This function does nothing useful.
38291 for the purpose of explaining iCode */
38294 short function (data
38303 short i=10; \InsetSpace ~
38305 /* dead initialization eliminated */
38311 /* dead initialization eliminated */
38339 /* compiler detects i,j to be induction
38344 for (i = 0, j = 10 ; i < 10 ; i++, j
38350 \begin_layout Standard
38373 mul += i * 3; \InsetSpace ~
38375 /* this multiplication remains */
38382 j * 3;\InsetSpace ~
38384 /* this multiplication changed to addition */
38398 \begin_layout Standard
38399 In addition to the operands each iCode contains information about the filename
38400 and line it corresponds to in the source file.
38401 The first field in the listing should be interpreted as follows:
38406 Filename(linenumber: iCode Execution sequence number : ICode hash table
38407 key : loop depth of the iCode).
38412 Then follows the human readable form of the ICode operation.
38413 Each operand of this triplet form can be of three basic types a) compiler
38414 generated temporary b) user defined variable c) a constant value.
38415 Note that local variables and parameters are replaced by compiler generated
38418 \begin_inset LatexCommand \index{Live range analysis}
38422 are computed only for temporaries (i.e.
38423 live ranges are not computed for global variables).
38425 \begin_inset LatexCommand \index{Register allocation}
38429 are allocated for temporaries only.
38430 Operands are formatted in the following manner:
38435 Operand Name [lr live-from : live-to ] { type information } [ registers
38441 As mentioned earlier the live ranges are computed in terms of the execution
38442 sequence number of the iCodes, for example
38444 the iTemp0 is live from (i.e.
38445 first defined in iCode with execution sequence number 3, and is last used
38446 in the iCode with sequence number 5).
38447 For induction variables such as iTemp21 the live range computation extends
38448 the lifetime from the start to the end of the loop.
38450 The register allocator
38451 used the live range information to allocate registers, the same registers
38452 may be used for different temporaries if their live ranges do not overlap,
38453 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38454 ranges do not overlap.
38455 In addition the allocator also takes into consideration the type and usage
38456 of a temporary, for example itemp6 is a pointer to near space and is used
38457 as to fetch data from (i.e.
38458 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38459 Some short lived temporaries are allocated to special registers which have
38460 meaning to the code generator e.g.
38461 iTemp13 is allocated to a pseudo register CC which tells the back end that
38462 the temporary is used only for a conditional jump the code generation makes
38463 use of this information to optimize a compare and jump ICode.
38467 \begin_inset LatexCommand \index{Loop optimization}
38471 performed by the compiler.
38472 It can detect induction variables iTemp21(i) and iTemp23(j).
38473 Also note the compiler does selective strength reduction
38474 \begin_inset LatexCommand \index{Strength reduction}
38479 the multiplication of an induction variable in line 18 (gint = j * 3) is
38480 changed to addition, a new temporary iTemp17 is allocated and assigned
38481 a initial value, a constant 3 is then added for each iteration of the loop.
38482 The compiler does not change the multiplication
38483 \begin_inset LatexCommand \index{Multiplication}
38487 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38490 Note the dead code elimination
38491 \begin_inset LatexCommand \index{Dead-code elimination}
38495 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38501 \begin_layout Standard
38504 Sample.c (5:1:0:0) _entry($9) :
38507 \begin_layout Standard
38510 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38513 \begin_layout Standard
38516 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38519 \begin_layout Standard
38522 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38525 \begin_layout Standard
38528 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38532 \begin_layout Standard
38535 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38538 \begin_layout Standard
38541 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38545 \begin_layout Standard
38548 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38551 \begin_layout Standard
38554 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38558 \begin_layout Standard
38561 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38565 \begin_layout Standard
38568 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38572 \begin_layout Standard
38575 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38579 \begin_layout Standard
38582 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38583 * int}[r0] + 0x2 {short}
38586 \begin_layout Standard
38589 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38592 \begin_layout Standard
38595 Sample.c(11:17:21:0)_whilebreak_0($3) :
38598 \begin_layout Standard
38601 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38604 \begin_layout Standard
38607 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38610 \begin_layout Standard
38613 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38616 \begin_layout Standard
38619 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38622 \begin_layout Standard
38625 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38628 \begin_layout Standard
38631 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38634 \begin_layout Standard
38637 Sample.c(15:24:26:1)_forcond_0($4) :
38640 \begin_layout Standard
38643 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38647 \begin_layout Standard
38650 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38653 \begin_layout Standard
38656 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38657 + ITemp21 [lr21:38]{short}[r4]
38660 \begin_layout Standard
38663 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38667 \begin_layout Standard
38670 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38671 + iTemp15 [lr29:30]{short}[r1]
38674 \begin_layout Standard
38677 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38681 \begin_layout Standard
38684 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38688 \begin_layout Standard
38691 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38695 \begin_layout Standard
38698 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38702 \begin_layout Standard
38705 Sample.c(19:38:47:1) goto _forcond_0($4)
38708 \begin_layout Standard
38711 Sample.c(19:39:48:0)_forbreak_0($7) :
38714 \begin_layout Standard
38717 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38718 + ITemp11 [lr19:40]{short}[r3]
38721 \begin_layout Standard
38724 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38727 \begin_layout Standard
38730 Sample.c(20:42:51:0)_return($8) :
38733 \begin_layout Standard
38736 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38742 Finally the code generated for this function:
38747 \begin_layout Standard
38753 \begin_layout Standard
38759 \begin_layout Standard
38767 \begin_layout Standard
38773 \begin_layout Standard
38781 \begin_layout Standard
38787 \begin_layout Standard
38790 ; ----------------------------------------------
38793 \begin_layout Standard
38796 ; function function
38799 \begin_layout Standard
38802 ; ----------------------------------------------
38805 \begin_layout Standard
38811 \begin_layout Standard
38814 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38817 \begin_layout Standard
38825 \begin_layout Standard
38828 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38831 \begin_layout Standard
38839 \begin_layout Standard
38842 ;_whilecontinue_0($1) :
38845 \begin_layout Standard
38851 \begin_layout Standard
38854 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38857 \begin_layout Standard
38860 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38863 \begin_layout Standard
38871 \begin_layout Standard
38879 \begin_layout Standard
38887 \begin_layout Standard
38895 \begin_layout Standard
38903 \begin_layout Standard
38911 \begin_layout Standard
38919 \begin_layout Standard
38925 \begin_layout Standard
38928 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38931 \begin_layout Standard
38939 \begin_layout Standard
38947 \begin_layout Standard
38950 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38953 \begin_layout Standard
38961 \begin_layout Standard
38969 \begin_layout Standard
38977 \begin_layout Standard
38985 \begin_layout Standard
38993 \begin_layout Standard
39001 \begin_layout Standard
39004 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39007 \begin_layout Standard
39015 \begin_layout Standard
39023 \begin_layout Standard
39031 \begin_layout Standard
39039 \begin_layout Standard
39047 \begin_layout Standard
39050 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39053 \begin_layout Standard
39061 \begin_layout Standard
39069 \begin_layout Standard
39077 \begin_layout Standard
39080 ; iTemp6 [lr5:16]{_near * int}[r0] =
39083 \begin_layout Standard
39086 ; iTemp6 [lr5:16]{_near * int}[r0] +
39089 \begin_layout Standard
39095 \begin_layout Standard
39103 \begin_layout Standard
39106 ; goto _whilecontinue_0($1)
39109 \begin_layout Standard
39117 \begin_layout Standard
39120 ; _whilebreak_0($3) :
39123 \begin_layout Standard
39129 \begin_layout Standard
39132 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39135 \begin_layout Standard
39143 \begin_layout Standard
39146 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39149 \begin_layout Standard
39157 \begin_layout Standard
39160 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39163 \begin_layout Standard
39171 \begin_layout Standard
39174 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39177 \begin_layout Standard
39185 \begin_layout Standard
39193 \begin_layout Standard
39196 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39199 \begin_layout Standard
39207 \begin_layout Standard
39215 \begin_layout Standard
39221 \begin_layout Standard
39227 \begin_layout Standard
39230 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39233 \begin_layout Standard
39236 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39239 \begin_layout Standard
39247 \begin_layout Standard
39255 \begin_layout Standard
39263 \begin_layout Standard
39271 \begin_layout Standard
39279 \begin_layout Standard
39285 \begin_layout Standard
39288 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39291 \begin_layout Standard
39294 ; iTemp21 [lr21:38]{short}[r4]
39297 \begin_layout Standard
39305 \begin_layout Standard
39313 \begin_layout Standard
39321 \begin_layout Standard
39324 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39327 \begin_layout Standard
39335 \begin_layout Standard
39343 \begin_layout Standard
39351 \begin_layout Standard
39359 \begin_layout Standard
39362 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39365 \begin_layout Standard
39368 ; iTemp15 [lr29:30]{short}[r1]
39371 \begin_layout Standard
39379 \begin_layout Standard
39387 \begin_layout Standard
39390 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39393 \begin_layout Standard
39401 \begin_layout Standard
39409 \begin_layout Standard
39417 \begin_layout Standard
39425 \begin_layout Standard
39433 \begin_layout Standard
39441 \begin_layout Standard
39444 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39447 \begin_layout Standard
39455 \begin_layout Standard
39463 \begin_layout Standard
39471 \begin_layout Standard
39479 \begin_layout Standard
39487 \begin_layout Standard
39495 \begin_layout Standard
39498 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39501 \begin_layout Standard
39509 \begin_layout Standard
39512 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39515 \begin_layout Standard
39523 \begin_layout Standard
39528 cjne r5,#0xff,00104$
39531 \begin_layout Standard
39539 \begin_layout Standard
39542 ; goto _forcond_0($4)
39545 \begin_layout Standard
39553 \begin_layout Standard
39556 ; _forbreak_0($7) :
39559 \begin_layout Standard
39565 \begin_layout Standard
39568 ; ret iTemp24 [lr40:41]{short}
39571 \begin_layout Standard
39579 \begin_layout Standard
39587 \begin_layout Standard
39595 \begin_layout Standard
39601 \begin_layout Standard
39607 \begin_layout Standard
39617 \begin_layout Section
39618 A few words about basic block successors, predecessors and dominators
39621 \begin_layout Standard
39622 Successors are basic blocks
39623 \begin_inset LatexCommand \index{Basic blocks}
39627 that might execute after this basic block.
39629 Predecessors are basic blocks
39630 that might execute before reaching this basic block.
39632 Dominators are basic
39633 blocks that WILL execute before reaching this basic block.
39638 \begin_layout Standard
39642 \begin_layout Standard
39646 \begin_layout Standard
39654 \begin_layout Standard
39658 \begin_layout Standard
39666 \begin_layout Standard
39672 \begin_layout Standard
39673 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39676 \begin_layout Standard
39677 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39680 \begin_layout Standard
39681 c) domVect of [BB4] = BB1 ...
39682 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39686 \begin_layout Chapter
39690 \begin_layout Standard
39691 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39701 Thanks to all the other volunteer developers who have helped with coding,
39702 testing, web-page creation, distribution sets, etc.
39703 You know who you are :-)
39711 Thanks to Sourceforge
39712 \begin_inset LatexCommand \url{http://www.sf.net}
39716 which has hosted the project since 1999 and donates significant download
39725 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39726 cycles and bandwidth for snapshot builds.
39731 \begin_layout Standard
39732 This document was initially written by Sandeep Dutta
39735 \begin_layout Standard
39736 All product names mentioned herein may be trademarks
39737 \begin_inset LatexCommand \index{Trademarks}
39741 of their respective companies.
39745 \begin_layout Section*
39749 \begin_layout Standard
39750 To avoid confusion, the installation and building options for SDCC itself
39751 (chapter 2) are not part of the index.
39754 \begin_layout Standard
39755 \begin_inset LatexCommand \printindex{}