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 \begin_layout Standard
8443 \begin_inset VSpace bigskip
8449 \begin_layout Subsection
8450 Optimization Options
8451 \begin_inset LatexCommand \index{Options optimization}
8456 \begin_inset LatexCommand \index{Optimization options}
8464 \labelwidthstring 00.00.0000
8471 \begin_layout Standard
8481 \begin_inset LatexCommand \index{-\/-nogcse}
8487 Will not do global subexpression elimination, this option may be used when
8488 the compiler creates undesirably large stack/data spaces to store compiler
8498 \begin_inset LatexCommand \index{sloc (spill location)}
8503 A warning message will be generated when this happens and the compiler
8504 will indicate the number of extra bytes it allocated.
8505 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8507 \begin_inset LatexCommand \index{\#pragma nogcse}
8511 can be used to turn off global subexpression elimination
8512 \begin_inset LatexCommand \index{Subexpression elimination}
8516 for a given function only.
8520 \labelwidthstring 00.00.0000
8527 \begin_layout Standard
8537 \begin_inset LatexCommand \index{-\/-noinvariant}
8543 Will not do loop invariant optimizations, this may be turned off for reasons
8544 explained for the previous option.
8545 For more details of loop optimizations performed see Loop Invariants in
8547 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8552 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8554 \begin_inset LatexCommand \index{\#pragma noinvariant}
8558 can be used to turn off invariant optimizations for a given function only.
8562 \labelwidthstring 00.00.0000
8569 \begin_layout Standard
8579 \begin_inset LatexCommand \index{-\/-noinduction}
8585 Will not do loop induction optimizations, see section strength reduction
8587 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8589 \begin_inset LatexCommand \index{\#pragma noinduction}
8593 can be used to turn off induction optimizations for a given function only.
8597 \labelwidthstring 00.00.0000
8604 \begin_layout Standard
8614 \begin_inset LatexCommand \index{-\/-nojtbound}
8625 Will not generate boundary condition check when switch statements
8626 \begin_inset LatexCommand \index{switch statement}
8630 are implemented using jump-tables.
8632 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8637 Switch Statements for more details.
8638 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8640 \begin_inset LatexCommand \index{\#pragma nojtbound}
8644 can be used to turn off boundary checking for jump tables for a given function
8649 \labelwidthstring 00.00.0000
8656 \begin_layout Standard
8666 \begin_inset LatexCommand \index{-\/-noloopreverse}
8675 Will not do loop reversal
8676 \begin_inset LatexCommand \index{Loop reversing}
8684 \labelwidthstring 00.00.0000
8689 \begin_layout Standard
8703 \begin_inset LatexCommand \index{-\/-nolabelopt }
8707 Will not optimize labels (makes the dumpfiles more readable).
8711 \labelwidthstring 00.00.0000
8718 \begin_layout Standard
8728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8734 Will not memcpy initialized data from code space into xdata space.
8735 This saves a few bytes in code space if you don't have initialized data
8736 \begin_inset LatexCommand \index{Variable initialization}
8744 \labelwidthstring 00.00.0000
8751 \begin_layout Standard
8761 \begin_inset LatexCommand \index{-\/-nooverlay}
8767 The compiler will not overlay parameters and local variables of any function,
8768 see section Parameters and local variables for more details.
8772 \labelwidthstring 00.00.0000
8779 \begin_layout Standard
8789 \begin_inset LatexCommand \index{-\/-no-peep}
8795 Disable peep-hole optimization with built-in rules.
8799 \labelwidthstring 00.00.0000
8806 \begin_layout Standard
8818 \begin_inset LatexCommand \index{-\/-peep-file}
8823 <filename> This option can be used to use additional rules to be used by
8824 the peep hole optimizer.
8826 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8831 Peep Hole optimizations for details on how to write these rules.
8835 \labelwidthstring 00.00.0000
8842 \begin_layout Standard
8852 \begin_inset LatexCommand \index{-\/-peep-asm}
8858 Pass the inline assembler code through the peep hole optimizer.
8859 This can cause unexpected changes to inline assembler code, please go through
8860 the peephole optimizer
8861 \begin_inset LatexCommand \index{Peephole optimizer}
8865 rules defined in the source file tree '<target>/peeph.def' before using
8870 \labelwidthstring 00.00.0000
8877 \begin_layout Standard
8887 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8893 The compiler will optimize code generation towards fast code, possibly
8894 at the expense of code size.
8898 \labelwidthstring 00.00.0000
8905 \begin_layout Standard
8915 \begin_inset LatexCommand \index{-\/-opt-code-size}
8921 The compiler will optimize code generation towards compact code, possibly
8922 at the expense of code speed.
8925 \begin_layout Standard
8926 \begin_inset VSpace bigskip
8932 \begin_layout Subsection
8934 \begin_inset LatexCommand \index{Options other}
8942 \labelwidthstring 00.00.0000
8950 \begin_layout Standard
8960 \begin_inset LatexCommand \index{-\/-compile-only}
8965 \begin_inset LatexCommand \index{-c -\/-compile-only}
8971 will compile and assemble the source, but will not call the linkage editor.
8975 \labelwidthstring 00.00.0000
8984 \begin_layout Standard
8996 \begin_inset LatexCommand \index{-\/-c1mode}
9002 reads the preprocessed source from standard input and compiles it.
9003 The file name for the assembler output must be specified using the -o option.
9007 \labelwidthstring 00.00.0000
9011 \begin_inset LatexCommand \index{-E}
9017 Run only the C preprocessor.
9018 Preprocess all the C source files specified and output the results to standard
9023 \labelwidthstring 00.00.0000
9028 \begin_inset LatexCommand \index{-o <path/file>}
9034 The output path resp.
9035 file where everything will be placed.
9036 If the parameter is a path, it must have a trailing slash (or backslash
9037 for the Windows binaries) to be recognized as a path.
9042 \labelwidthstring 00.00.0000
9049 \begin_layout Standard
9059 \begin_inset LatexCommand \index{-\/-stack-auto}
9070 All functions in the source file will be compiled as
9075 \begin_inset LatexCommand \index{reentrant}
9080 the parameters and local variables will be allocated on the stack
9081 \begin_inset LatexCommand \index{stack}
9087 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9091 Parameters and Local Variables for more details.
9092 If this option is used all source files in the project should be compiled
9094 It automatically implies --int-long-reent and --float-reent.
9099 \labelwidthstring 00.00.0000
9106 \begin_layout Standard
9116 \begin_inset LatexCommand \index{-\/-callee-saves}
9121 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9125 function1[,function2][,function3]....
9128 The compiler by default uses a caller saves convention for register saving
9129 across function calls, however this can cause unnecessary register pushing
9130 and popping when calling small functions from larger functions.
9131 This option can be used to switch the register saving convention for the
9132 function names specified.
9133 The compiler will not save registers when calling these functions, no extra
9134 code will be generated at the entry and exit (function prologue
9137 \begin_inset LatexCommand \index{function prologue}
9146 \begin_inset LatexCommand \index{function epilogue}
9152 ) for these functions to save and restore the registers used by these functions,
9153 this can SUBSTANTIALLY reduce code and improve run time performance of
9155 In the future the compiler (with inter procedural analysis) will be able
9156 to determine the appropriate scheme to use for each function call.
9157 DO NOT use this option for built-in functions such as _mulint..., if this
9158 option is used for a library function the appropriate library function
9159 needs to be recompiled with the same option.
9160 If the project consists of multiple source files then all the source file
9161 should be compiled with the same -
9165 \begin_layout Standard
9174 -callee-saves option string.
9175 Also see #pragma\InsetSpace ~
9177 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9182 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9190 \labelwidthstring 00.00.0000
9197 \begin_layout Standard
9207 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9221 \begin_layout Standard
9230 -callee-saves will be applied to all functions by default.
9234 \labelwidthstring 00.00.0000
9241 \begin_layout Standard
9251 \begin_inset LatexCommand \index{-\/-debug}
9260 When this option is used the compiler will generate debug information.
9261 The debug information collected in a file with .cdb extension can be used
9263 For more information see documentation for SDCDB.
9264 Another file with no extension contains debug information in AOMF or AOMF51
9265 \begin_inset LatexCommand \index{AOMF, AOMF51}
9269 format which is commonly used by third party tools.
9273 \labelwidthstring 00.00.0000
9277 \begin_inset LatexCommand \index{-S}
9288 Stop after the stage of compilation proper; do not assemble.
9289 The output is an assembler code file for the input file specified.
9293 \labelwidthstring 00.00.0000
9300 \begin_layout Standard
9310 \begin_inset LatexCommand \index{-\/-int-long-reent}
9316 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9317 Note by default these libraries are compiled as non-reentrant.
9318 See section Installation for more details.
9322 \labelwidthstring 00.00.0000
9329 \begin_layout Standard
9339 \begin_inset LatexCommand \index{-\/-cyclomatic}
9348 This option will cause the compiler to generate an information message for
9349 each function in the source file.
9350 The message contains some
9354 information about the function.
9355 The number of edges and nodes the compiler detected in the control flow
9356 graph of the function, and most importantly the
9358 cyclomatic complexity
9359 \begin_inset LatexCommand \index{Cyclomatic complexity}
9365 see section on Cyclomatic Complexity for more details.
9369 \labelwidthstring 00.00.0000
9376 \begin_layout Standard
9386 \begin_inset LatexCommand \index{-\/-float-reent}
9392 Floating point library is compiled as reentrant
9393 \begin_inset LatexCommand \index{reentrant}
9398 See section Installation for more details.
9402 \labelwidthstring 00.00.0000
9409 \begin_layout Standard
9419 \begin_inset LatexCommand \index{-\/-funsigned-char}
9425 The default signedness for every type is
9430 In some embedded environments the default signedness of
9439 To set the signess for characters to unsigned, use the option --funsigned-char.
9440 If this option is set and no signedness keyword (unsigned/signed) is given,
9441 a char will be signed.
9442 All other types are unaffected.
9446 \labelwidthstring 00.00.0000
9453 \begin_layout Standard
9463 \begin_inset LatexCommand \index{-\/-main-return}
9469 This option can be used if the code generated is called by a monitor program
9470 or if the main routine includes an endless loop.
9471 This option results in slightly smaller code and saves two bytes of stack
9473 The return from the 'main'
9474 \begin_inset LatexCommand \index{main return}
9478 function will return to the function calling main.
9479 The default setting is to lock up i.e.
9488 \labelwidthstring 00.00.0000
9495 \begin_layout Standard
9505 \begin_inset LatexCommand \index{-\/-nostdinc}
9511 This will prevent the compiler from passing on the default include path
9512 to the preprocessor.
9516 \labelwidthstring 00.00.0000
9523 \begin_layout Standard
9533 \begin_inset LatexCommand \index{-\/-nostdlib}
9539 This will prevent the compiler from passing on the default library
9540 \begin_inset LatexCommand \index{Libraries}
9548 \labelwidthstring 00.00.0000
9555 \begin_layout Standard
9565 \begin_inset LatexCommand \index{-\/-verbose}
9571 Shows the various actions the compiler is performing.
9575 \labelwidthstring 00.00.0000
9579 \begin_inset LatexCommand \index{-V}
9585 Shows the actual commands the compiler is executing.
9589 \labelwidthstring 00.00.0000
9596 \begin_layout Standard
9606 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9612 Hides your ugly and inefficient c-code from the asm file, so you can always
9613 blame the compiler :)
9617 \labelwidthstring 00.00.0000
9624 \begin_layout Standard
9634 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9640 Include code generator and peep-hole comments in the generated asm files.
9644 \labelwidthstring 00.00.0000
9651 \begin_layout Standard
9661 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9667 Don't include peep-hole comments in the generated asm files even if --fverbose-
9668 asm option is specified.
9672 \labelwidthstring 00.00.0000
9679 \begin_layout Standard
9689 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9695 Include i-codes in the asm file.
9696 Sounds like noise but is most helpful for debugging the compiler itself.
9700 \labelwidthstring 00.00.0000
9707 \begin_layout Standard
9717 \begin_inset LatexCommand \index{pedantic}
9722 \begin_inset LatexCommand \index{-\/-less-pedantic}
9729 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9733 Disable some of the more pedantic warnings
9734 \begin_inset LatexCommand \index{Warnings}
9739 For more details, see the less_pedantic pragma
9740 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9748 \labelwidthstring 00.00.0000
9755 \begin_layout Standard
9764 -disable-warning\InsetSpace ~
9766 \begin_inset LatexCommand \index{-\/-disable-warning}
9772 Disable specific warning with number <nnnn>.
9776 \labelwidthstring 00.00.0000
9783 \begin_layout Standard
9793 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9799 Display the directories in the compiler's search path
9803 \labelwidthstring 00.00.0000
9810 \begin_layout Standard
9820 \begin_inset LatexCommand \index{-\/-vc}
9826 Display errors and warnings using MSVC style, so you can use SDCC with
9827 the visual studio IDE
9828 \begin_inset LatexCommand \index{IDE}
9833 With SDCC both offering a GCC-like (the default) and a MSVC-like
9834 \begin_inset LatexCommand \index{MSVC output style}
9838 output style, integration into most programming editors should be straightforwa
9843 \labelwidthstring 00.00.0000
9850 \begin_layout Standard
9860 \begin_inset LatexCommand \index{-\/-use-stdout}
9866 Send errors and warnings to stdout instead of stderr.
9870 \labelwidthstring 00.00.0000
9874 asmOption[,asmOption]
9877 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9882 Pass the asmOption to the assembler
9883 \begin_inset LatexCommand \index{Options assembler}
9888 \begin_inset LatexCommand \index{Assembler options}
9893 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9897 \labelwidthstring 00.00.0000
9904 \begin_layout Standard
9914 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9920 Generally follow the C89 standard, but allow SDCC features that conflict
9921 with the standard (default).
9925 \labelwidthstring 00.00.0000
9932 \begin_layout Standard
9942 \begin_inset LatexCommand \index{-\/-std-c89}
9948 Follow the C89 standard and disable SDCC features that conflict with the
9953 \labelwidthstring 00.00.0000
9960 \begin_layout Standard
9970 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9976 Generally follow the C99 standard, but allow SDCC features that conflict
9977 with the standard (incomplete support).
9981 \labelwidthstring 00.00.0000
9988 \begin_layout Standard
9998 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10004 Follow the C99 standard and disable SDCC features that conflict with the
10005 standard (incomplete support).
10009 \labelwidthstring 00.00.0000
10016 \begin_layout Standard
10028 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10033 <Name> The name to be used for the code
10034 \begin_inset LatexCommand \index{code}
10038 segment, default CSEG.
10039 This is useful if you need to tell the compiler to put the code in a special
10040 segment so you can later on tell the linker to put this segment in a special
10042 Can be used for instance when using bank switching to put the code in a
10047 \labelwidthstring 00.00.0000
10054 \begin_layout Standard
10066 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10071 <Name> The name to be used for the const
10072 \begin_inset LatexCommand \index{const}
10076 segment, default CONST.
10077 This is useful if you need to tell the compiler to put the const data in
10078 a special segment so you can later on tell the linker to put this segment
10079 in a special place in memory.
10080 Can be used for instance when using bank switching to put the const data
10085 \labelwidthstring 00.00.0000
10092 \begin_layout Standard
10101 -fdollars-in-identifiers
10102 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10108 Permit '$' as an identifier character.
10112 \labelwidthstring 00.00.0000
10119 \begin_layout Standard
10131 \begin_inset LatexCommand \index{-\/-more-pedantic}
10136 \begin_inset LatexCommand \index{pedantic}
10146 a SDCC compiler option but if you want
10150 warnings you can use a separate tool dedicated to syntax checking like
10152 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10157 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10162 \begin_inset LatexCommand \url{http://www.splint.org}
10167 To make your source files parseable by splint you will have to include
10173 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10177 in your source file and add brackets around extended keywords (like
10180 \begin_inset Quotes sld
10193 \begin_inset Quotes srd
10201 \begin_inset Quotes sld
10204 __interrupt\InsetSpace ~
10206 \begin_inset Quotes srd
10214 Splint has an excellent on line manual at
10215 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10219 and it's capabilities go beyond pure syntax checking.
10220 You'll need to tell splint the location of SDCC's include files so a typical
10221 command line could look like this:
10225 splint\InsetSpace ~
10227 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10233 \labelwidthstring 00.00.0000
10240 \begin_layout Standard
10252 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10257 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10261 Treat short as 8-bit (for backward compatibility with older versions of
10262 compiler - see section
10263 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10270 \begin_layout Standard
10271 \begin_inset VSpace bigskip
10277 \begin_layout Subsection
10278 Intermediate Dump Options
10279 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10284 \begin_inset LatexCommand \index{Options intermediate dump}
10289 \begin_inset LatexCommand \index{Intermediate dump options}
10296 \begin_layout Standard
10297 The following options are provided for the purpose of retargetting and debugging
10299 They provide a means to dump the intermediate code (iCode
10300 \begin_inset LatexCommand \index{iCode}
10304 ) generated by the compiler in human readable form at various stages of
10305 the compilation process.
10306 More on iCodes see chapter
10307 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10312 \begin_inset Quotes srd
10315 The anatomy of the compiler
10316 \begin_inset Quotes srd
10323 \labelwidthstring 00.00.0000
10330 \begin_layout Standard
10340 \begin_inset LatexCommand \index{-\/-dumpraw}
10346 This option will cause the compiler to dump the intermediate code into
10349 <source filename>.dumpraw
10351 just after the intermediate code has been generated for a function, i.e.
10352 before any optimizations are done.
10354 \begin_inset LatexCommand \index{Basic blocks}
10358 at this stage ordered in the depth first number, so they may not be in
10359 sequence of execution.
10363 \labelwidthstring 00.00.0000
10370 \begin_layout Standard
10380 \begin_inset LatexCommand \index{-\/-dumpgcse}
10386 Will create a dump of iCode's, after global subexpression elimination
10387 \begin_inset LatexCommand \index{Global subexpression elimination}
10391 , into a file named
10393 <source filename>.dumpgcse.
10397 \labelwidthstring 00.00.0000
10404 \begin_layout Standard
10414 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10420 Will create a dump of iCode's, after deadcode elimination
10421 \begin_inset LatexCommand \index{Dead-code elimination}
10425 , into a file named
10427 <source filename>.dumpdeadcode.
10431 \labelwidthstring 00.00.0000
10438 \begin_layout Standard
10448 \begin_inset LatexCommand \index{-\/-dumploop}
10457 Will create a dump of iCode's, after loop optimizations
10458 \begin_inset LatexCommand \index{Loop optimization}
10462 , into a file named
10464 <source filename>.dumploop.
10468 \labelwidthstring 00.00.0000
10475 \begin_layout Standard
10485 \begin_inset LatexCommand \index{-\/-dumprange}
10494 Will create a dump of iCode's, after live range analysis
10495 \begin_inset LatexCommand \index{Live range analysis}
10499 , into a file named
10501 <source filename>.dumprange.
10505 \labelwidthstring 00.00.0000
10512 \begin_layout Standard
10522 \begin_inset LatexCommand \index{-\/-dumlrange}
10528 Will dump the life ranges
10529 \begin_inset LatexCommand \index{Live range analysis}
10537 \labelwidthstring 00.00.0000
10544 \begin_layout Standard
10554 \begin_inset LatexCommand \index{-\/-dumpregassign}
10563 Will create a dump of iCode's, after register assignment
10564 \begin_inset LatexCommand \index{Register assignment}
10568 , into a file named
10570 <source filename>.dumprassgn.
10574 \labelwidthstring 00.00.0000
10581 \begin_layout Standard
10591 \begin_inset LatexCommand \index{-\/-dumplrange}
10597 Will create a dump of the live ranges of iTemp's
10601 \labelwidthstring 00.00.0000
10608 \begin_layout Standard
10618 \begin_inset LatexCommand \index{-\/-dumpall}
10629 Will cause all the above mentioned dumps to be created.
10632 \begin_layout Standard
10633 \begin_inset VSpace bigskip
10639 \begin_layout Subsection
10640 Redirecting output on Windows Shells
10643 \begin_layout Standard
10644 By default SDCC writes it's error messages to
10645 \begin_inset Quotes sld
10649 \begin_inset Quotes srd
10653 To force all messages to
10654 \begin_inset Quotes sld
10658 \begin_inset Quotes srd
10670 \begin_layout Standard
10685 \begin_inset LatexCommand \index{-\/-use-stdout}
10690 Additionally, if you happen to have visual studio installed in your windows
10691 machine, you can use it to compile your sources using a custom build and
10698 \begin_layout Standard
10710 \begin_inset LatexCommand \index{-\/-vc}
10715 Something like this should work:
10734 \begin_layout Standard
10753 \begin_layout Standard
10765 -model-large -c $(InputPath)
10768 \begin_inset VSpace bigskip
10774 \begin_layout Section
10775 Environment variables
10776 \begin_inset LatexCommand \index{Environment variables}
10783 \begin_layout Standard
10784 SDCC recognizes the following environment variables:
10788 \labelwidthstring 00.00.0000
10792 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10798 SDCC installs a signal handler
10799 \begin_inset LatexCommand \index{signal handler}
10803 to be able to delete temporary files after an user break (^C) or an exception.
10804 If this environment variable is set, SDCC won't install the signal handler
10805 in order to be able to debug SDCC.
10809 \labelwidthstring 00.00.0000
10815 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10821 Path, where temporary files will be created.
10822 The order of the variables is the search order.
10823 In a standard *nix environment these variables are not set, and there's
10824 no need to set them.
10825 On Windows it's recommended to set one of them.
10829 \labelwidthstring 00.00.0000
10833 \begin_inset LatexCommand \index{SDCC\_HOME}
10840 \begin_inset LatexCommand \ref{sub:Install-paths}
10846 \begin_inset Quotes sld
10850 \begin_inset Quotes srd
10857 \labelwidthstring 00.00.0000
10861 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10868 \begin_inset LatexCommand \ref{sub:Search-Paths}
10874 \begin_inset Quotes sld
10878 \begin_inset Quotes srd
10885 \labelwidthstring 00.00.0000
10889 \begin_inset LatexCommand \index{SDCC\_LIB}
10896 \begin_inset LatexCommand \ref{sub:Search-Paths}
10902 \begin_inset Quotes sld
10906 \begin_inset Quotes srd
10912 \begin_layout Standard
10913 There are some more environment variables recognized by SDCC, but these
10914 are solely used for debugging purposes.
10915 They can change or disappear very quickly, and will never be documented.
10916 \begin_inset VSpace bigskip
10922 \begin_layout Section
10923 Storage Class Language Extensions
10926 \begin_layout Subsection
10927 MCS51/DS390 Storage Class
10928 \begin_inset LatexCommand \index{Storage class}
10932 Language Extensions
10935 \begin_layout Standard
10936 In addition to the ANSI storage classes SDCC allows the following MCS51
10937 specific storage classes:
10940 \begin_layout Subsubsection
10942 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10947 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10952 \begin_inset LatexCommand \index{near (storage class)}
10957 \begin_inset LatexCommand \index{\_\_near (storage class)}
10964 \begin_layout Standard
10969 storage class for the Small Memory model (
10977 or the more ANSI-C compliant forms
10985 can be used synonymously).
10986 Variables declared with this storage class will be allocated in the directly
10987 addressable portion of the internal RAM of a 8051, e.g.:
10990 \begin_layout Verse
10993 __data unsigned char test_data;
10996 \begin_layout Standard
10997 Writing 0x01 to this variable generates the assembly code:
11000 \begin_layout Verse
11003 75*00 01\InsetSpace ~
11011 \begin_layout Subsubsection
11013 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11018 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11023 \begin_inset LatexCommand \index{far (storage class)}
11028 \begin_inset LatexCommand \index{\_\_far (storage class)}
11035 \begin_layout Standard
11036 Variables declared with this storage class will be placed in the external
11042 storage class for the Large Memory model, e.g.:
11045 \begin_layout Verse
11048 __xdata unsigned char test_xdata;
11051 \begin_layout Standard
11052 Writing 0x01 to this variable generates the assembly code:
11055 \begin_layout Verse
11058 90s00r00\InsetSpace ~
11089 \begin_layout Subsubsection
11091 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11096 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11103 \begin_layout Standard
11104 Variables declared with this storage class will be allocated into the indirectly
11105 addressable portion of the internal ram of a 8051, e.g.:
11108 \begin_layout Verse
11111 __idata unsigned char test_idata;
11114 \begin_layout Standard
11115 Writing 0x01 to this variable generates the assembly code:
11118 \begin_layout Verse
11145 \begin_layout Standard
11146 Please note, the first 128 byte of idata physically access the same RAM
11147 as the data memory.
11148 The original 8051 had 128 byte idata memory, nowadays most devices have
11149 256 byte idata memory.
11151 \begin_inset LatexCommand \index{stack}
11155 is located in idata memory.
11158 \begin_layout Subsubsection
11160 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11165 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11172 \begin_layout Standard
11173 Paged xdata access is just as straightforward as using the other addressing
11175 It is typically located at the start of xdata and has a maximum size of
11177 The following example writes 0x01 to the pdata variable.
11178 Please note, pdata access physically accesses xdata memory.
11179 The high byte of the address is determined by port P2
11180 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11184 (or in case of some 8051 variants by a separate Special Function Register,
11186 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11195 storage class for the Medium Memory model, e.g.:
11198 \begin_layout Verse
11201 __pdata unsigned char test_pdata;
11204 \begin_layout Standard
11205 Writing 0x01 to this variable generates the assembly code:
11208 \begin_layout Verse
11217 mov r0,#_test_pdata
11239 \begin_layout Standard
11244 \begin_layout Standard
11254 \begin_inset LatexCommand \index{-\/-xstack}
11258 option is used the pdata memory area is followed by the xstack memory area
11259 and the sum of their sizes is limited to 256 bytes.
11262 \begin_layout Subsubsection
11264 \begin_inset LatexCommand \index{code}
11269 \begin_inset LatexCommand \index{\_\_code}
11276 \begin_layout Standard
11277 'Variables' declared with this storage class will be placed in the code
11281 \begin_layout Verse
11284 __code unsigned char test_code;
11287 \begin_layout Standard
11288 Read access to this variable generates the assembly code:
11291 \begin_layout Verse
11294 90s00r6F\InsetSpace ~
11297 mov dptr,#_test_code
11322 \begin_layout Standard
11327 indexed arrays of characters in code memory can be accessed efficiently:
11330 \begin_layout Verse
11333 __code char test_array[] = {'c','h','e','a','p'};
11336 \begin_layout Standard
11337 Read access to this array using an 8-bit unsigned index generates the assembly
11341 \begin_layout Verse
11353 \begin_layout Verse
11356 90s00r41\InsetSpace ~
11359 mov dptr,#_test_array
11362 \begin_layout Verse
11377 \begin_layout Subsubsection
11379 \begin_inset LatexCommand \index{bit}
11384 \begin_inset LatexCommand \index{\_\_bit}
11391 \begin_layout Standard
11392 This is a data-type and a storage class specifier.
11393 When a variable is declared as a bit, it is allocated into the bit addressable
11394 memory of 8051, e.g.:
11397 \begin_layout Verse
11403 \begin_layout Standard
11404 Writing 1 to this variable generates the assembly code:
11407 \begin_layout Verse
11421 \begin_layout Standard
11422 The bit addressable memory consists of 128 bits which are located from 0x20
11423 to 0x2f in data memory.
11426 Apart from this 8051 specific storage class most architectures support
11428 \begin_inset LatexCommand \index{bitfields}
11436 \begin_layout Standard
11437 Not really meant as examples, but nevertheless showing what bitfields are
11438 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11444 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11445 signed modifier are implemented as unsigned.
11448 \begin_layout Subsubsection
11450 \begin_inset LatexCommand \index{sfr}
11455 \begin_inset LatexCommand \index{\_\_sfr}
11460 \begin_inset LatexCommand \index{sfr16}
11465 \begin_inset LatexCommand \index{\_\_sfr16}
11470 \begin_inset LatexCommand \index{sfr32}
11475 \begin_inset LatexCommand \index{\_\_sfr32}
11480 \begin_inset LatexCommand \index{\_\_sbit}
11485 \begin_inset LatexCommand \index{sbit}
11492 \begin_layout Standard
11493 Like the bit keyword,
11495 sfr / sfr16 / sfr32 / sbit
11497 signify both a data-type and storage class, they are used to describe the
11518 variables of a 8051, eg:
11521 \begin_layout Verse
11525 \begin_inset LatexCommand \index{at}
11530 \begin_inset LatexCommand \index{\_\_at}
11534 (0x80) P0;\InsetSpace ~
11535 /* special function register P0 at location 0x80 */
11540 special function register combination for timer 0
11544 with the high byte at
11545 location 0x8C and the low byte at location 0x8A */
11547 __sfr16 __at (0x8C8A)
11553 \begin_inset LatexCommand \index{at}
11558 \begin_inset LatexCommand \index{\_\_at}
11562 (0xd7) CY;\InsetSpace ~
11564 \begin_inset LatexCommand \index{Flags}
11569 \begin_inset LatexCommand \index{Carry flag}
11576 \begin_layout Standard
11577 Special function registers which are located on an address dividable by
11578 8 are bit-addressable, an
11582 addresses a specific bit within these sfr.
11584 16 Bit and 32 bit special function
11585 register combinations which require a certain access order are better not
11595 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11596 this is not guaranteed.
11601 \begin_layout Standard
11602 Please note, if you use a header file which was written for another compiler
11603 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11609 Specifically the syntax
11612 sfr P0 = 0x80;\InsetSpace ~
11619 by SDCC to an assignment of 0x80 to a variable called P0
11622 \begin_inset Marginal
11625 \begin_layout Standard
11637 Nevertheless it is possible to write header files
11638 \begin_inset LatexCommand \index{Header files}
11643 \begin_inset LatexCommand \index{Include files}
11647 which can be shared among different compilers (see section
11648 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11656 \begin_layout Subsubsection
11658 \begin_inset LatexCommand \index{Pointer}
11662 to MCS51/DS390 specific memory spaces
11665 \begin_layout Standard
11666 SDCC allows (via language extensions) pointers to explicitly point to any
11667 of the memory spaces
11668 \begin_inset LatexCommand \index{Memory model}
11673 In addition to the explicit pointers, the compiler uses (by default) generic
11674 pointers which can be used to point to any of the memory spaces.
11679 declaration examples:
11682 \begin_layout Verse
11685 /* pointer physically in internal ram pointing to object in external ram
11688 __xdata unsigned char * __data p;
11692 /* pointer physically in external ram
11693 pointing to object in internal ram */
11695 __data unsigned char * __xdata p;
11700 pointer physically in code rom pointing to data in xdata space */
11703 unsigned char * __code p;
11707 /* pointer physically in code space pointing to
11708 data in code space */
11710 __code unsigned char * __code p;
11715 physically located in xdata space */
11717 unsigned char * __xdata p;
11722 pointer physically located in default memory space */
11729 the following is a function pointer
11730 \begin_inset LatexCommand \index{function pointer}
11734 physically located in data space */
11736 char (* __data fp)(void);
11739 \begin_layout Standard
11740 Well you get the idea.
11745 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11758 The highest order byte of the
11762 pointers contains the data space information.
11763 Assembler support routines are called whenever data is stored or retrieved
11769 These are useful for developing reusable library
11770 \begin_inset LatexCommand \index{Libraries}
11775 Explicitly specifying the pointer
11776 \begin_inset LatexCommand \index{pointer}
11780 type will generate the most efficient code.
11783 \begin_layout Subsubsection
11784 Notes on MCS51 memory
11785 \begin_inset LatexCommand \index{MCS51 memory}
11792 \begin_layout Standard
11793 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11794 RAM memory which is structured as follows:
11798 - Bytes 00-1F - 32 bytes to hold
11799 up to 4 banks of the registers R0 to R7,
11801 - Bytes 20-2F - 16 bytes to hold
11803 \begin_inset LatexCommand \index{bit}
11809 - Bytes 30-7F - 80 bytes for general purpose use.
11814 \begin_layout Standard
11815 Additionally some members of the MCS51 family may have up to 128 bytes of
11816 additional, indirectly addressable, internal RAM memory (
11821 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11826 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11831 Furthermore, some chips may have some built in external memory (
11836 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11841 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11845 ) which should not be confused with the internal, directly addressable RAM
11851 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11856 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11861 Sometimes this built in
11865 memory has to be activated before using it (you can probably find this
11866 information on the datasheet of the microcontroller your are using, see
11868 \begin_inset LatexCommand \ref{sub:Startup-Code}
11876 \begin_layout Standard
11877 Normally SDCC will only use the first bank
11878 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11882 of registers (register bank 0), but it is possible to specify that other
11883 banks of registers (keyword
11890 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11895 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11901 ) should be used for example in interrupt
11902 \begin_inset LatexCommand \index{interrupt}
11907 \begin_inset LatexCommand \index{\_\_interrupt}
11912 By default, the compiler will place the stack after the last byte of allocated
11913 memory for variables.
11914 For example, if the first 2 banks of registers are used, and only four
11919 variables, it will position the base of the internal stack at address 20
11921 This implies that as the stack
11922 \begin_inset LatexCommand \index{stack}
11926 grows, it will use up the remaining register banks, and the 16 bytes used
11927 by the 128 bit variables, and 80 bytes for general purpose use.
11928 If any bit variables are used, the data variables will be placed in unused
11929 register banks and after the byte holding the last bit variable.
11930 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11935 variables will be placed starting from address 0x10 to 0x20 and continue
11941 \begin_layout Standard
11951 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11955 to specify the start address of the
11963 \begin_layout Standard
11973 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11977 to specify the size of the total internal RAM (
11991 \begin_layout Standard
11992 By default the 8051 linker will place the stack after the last byte of (i)data
11998 \begin_layout Standard
12008 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12012 allows you to specify the start of the stack, i.e.
12013 you could start it after any data in the general purpose area.
12014 If your microcontroller has additional indirectly addressable internal
12019 ) you can place the stack on it.
12020 You may also need to use -
12024 \begin_layout Standard
12034 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12038 to set the start address of the external RAM (
12046 \begin_layout Standard
12056 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12060 to specify its size.
12061 Same goes for the code memory, using -
12065 \begin_layout Standard
12075 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12083 \begin_layout Standard
12093 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12098 If in doubt, don't specify any options and see if the resulting memory
12099 layout is appropriate, then you can adjust it.
12102 \begin_layout Standard
12103 The linker generates two files with memory allocation information.
12104 The first, with extension .map
12105 \begin_inset LatexCommand \index{<file>.map}
12109 shows all the variables and segments.
12110 The second with extension .mem
12111 \begin_inset LatexCommand \index{<file>.mem}
12115 shows the final memory layout.
12116 The linker will complain either if memory segments overlap, there is not
12117 enough memory, or there is not enough space for stack.
12118 If you get any linking warnings and/or errors related to stack or segments
12119 allocation, take a look at either the .map or .mem files to find out what
12121 The .mem file may even suggest a solution to the problem.
12122 \begin_inset VSpace bigskip
12128 \begin_layout Subsection
12129 Z80/Z180 Storage Class
12130 \begin_inset LatexCommand \index{Z80!Storage class}
12134 Language Extensions
12137 \begin_layout Subsubsection
12139 \begin_inset LatexCommand \index{sfr}
12144 \begin_inset LatexCommand \index{\_\_sfr}
12148 (in/out to 8-bit addresses)
12151 \begin_layout Standard
12153 \begin_inset LatexCommand \index{Z80}
12157 family has separate address spaces for memory and
12167 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12172 \begin_inset LatexCommand \index{Z80!I/O memory}
12177 \begin_inset LatexCommand \index{Z180!I/O memory}
12181 is accessed with special instructions, e.g.:
12184 \begin_layout Verse
12187 sfr at 0x78 IoPort;\InsetSpace ~
12189 /* define a var in I/O space at 78h called IoPort */
12193 \begin_layout Standard
12194 Writing 0x01 to this variable generates the assembly code:
12197 \begin_layout Verse
12217 \begin_layout Subsubsection
12219 \begin_inset LatexCommand \index{sfr}
12224 \begin_inset LatexCommand \index{\_\_sfr}
12228 (in/out to 16-bit addresses)
12231 \begin_layout Standard
12236 is used to support 16 bit addresses in I/O memory e.g.:
12239 \begin_layout Verse
12243 \begin_inset LatexCommand \index{at}
12248 \begin_inset LatexCommand \index{\_\_at}
12255 \begin_layout Standard
12256 Writing 0x01 to this variable generates the assembly code:
12259 \begin_layout Verse
12262 01 23 01\InsetSpace ~
12284 \begin_layout Subsubsection
12286 \begin_inset LatexCommand \index{sfr}
12291 \begin_inset LatexCommand \index{\_\_sfr}
12295 (in0/out0 to 8 bit addresses on Z180
12296 \begin_inset LatexCommand \index{Z180}
12301 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12308 \begin_layout Standard
12309 The compiler option -
12313 \begin_layout Standard
12323 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12327 =180 (80) and a compiler #pragma\InsetSpace ~
12329 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12333 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12343 If you include the file z180.h this will be set automatically.
12344 \begin_inset VSpace bigskip
12350 \begin_layout Subsection
12352 \begin_inset LatexCommand \index{HC08!Storage class}
12356 Language Extensions
12359 \begin_layout Subsubsection
12361 \begin_inset LatexCommand \index{data (hc08 storage class)}
12366 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12373 \begin_layout Standard
12374 The data storage class declares a variable that resides in the first 256
12375 bytes of memory (the direct page).
12377 \begin_inset LatexCommand \index{HC08}
12381 is most efficient at accessing variables (especially pointers) stored here.
12384 \begin_layout Subsubsection
12386 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12391 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12398 \begin_layout Standard
12399 The xdata storage class declares a variable that can reside anywhere in
12401 This is the default if no storage class is specified.
12403 \begin_inset VSpace bigskip
12409 \begin_layout Section
12410 Absolute Addressing
12411 \begin_inset LatexCommand \index{Absolute addressing}
12418 \begin_layout Standard
12419 Data items can be assigned an absolute address with the
12422 \begin_inset LatexCommand \index{at}
12427 \begin_inset LatexCommand \index{\_\_at}
12433 keyword, in addition to a storage class, e.g.:
12436 \begin_layout Verse
12440 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12445 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12450 \begin_inset LatexCommand \index{at}
12455 \begin_inset LatexCommand \index{\_\_at}
12459 0x7ffe unsigned int chksum;
12462 \begin_layout Standard
12463 or, better conforming to ISO/IEC 9899 C:
12466 \begin_layout Verse
12469 __xdata __at (0x7ffe) unsigned int chksum;
12472 \begin_layout Standard
12473 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12474 of the external ram.
12479 reserve any space for variables declared in this way
12480 \begin_inset Marginal
12483 \begin_layout Standard
12492 (they are implemented with an equate in the assembler).
12493 Thus it is left to the programmer to make sure there are no overlaps with
12494 other variables that are declared without the absolute address.
12495 The assembler listing file (.lst
12496 \begin_inset LatexCommand \index{<file>.lst}
12500 ) and the linker output files (.rst
12501 \begin_inset LatexCommand \index{<file>.rst}
12506 \begin_inset LatexCommand \index{<file>.map}
12510 ) are good places to look for such overlaps.
12511 Variables with an absolute address are
12514 \begin_inset Marginal
12517 \begin_layout Standard
12529 \begin_inset LatexCommand \index{Variable initialization}
12536 \begin_layout Standard
12537 In case of memory mapped I/O devices the keyword
12541 has to be used to tell the compiler that accesses might not be removed:
12544 \begin_layout Verse
12548 \begin_inset LatexCommand \index{volatile}
12553 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12558 \begin_inset LatexCommand \index{at}
12562 (0x8000) unsigned char PORTA_8255;
12565 \begin_layout Standard
12566 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12571 \begin_inset LatexCommand \index{Aligned array}
12578 starts at a block (256 byte) boundary
12579 \begin_inset LatexCommand \index{block boundary}
12584 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12590 Absolute addresses can be specified for variables in all
12591 storage classes, e.g.:
12594 \begin_layout Verse
12598 \begin_inset LatexCommand \index{bit}
12603 \begin_inset LatexCommand \index{at}
12610 \begin_layout Standard
12611 The above example will allocate the variable at offset 0x02 in the bit-addressab
12613 There is no real advantage to assigning absolute addresses to variables
12614 in this manner, unless you want strict control over all the variables allocated.
12615 One possible use would be to write hardware portable code.
12616 For example, if you have a routine that uses one or more of the microcontroller
12617 I/O pins, and such pins are different for two different hardwares, you
12618 can declare the I/O pins in your routine using:
12621 \begin_layout Verse
12625 \begin_inset LatexCommand \index{volatile}
12629 __bit MOSI;\InsetSpace ~
12633 /* master out, slave in */
12635 extern volatile __bit MISO;\InsetSpace ~
12642 extern volatile __bit MCLK;\InsetSpace ~
12651 Output of a byte on a 3-wire serial bus.
12656 If needed adapt polarity of clock,
12657 polarity of data and bit order
12662 unsigned char spi_io(unsigned char out_byte)
12687 MOSI = out_byte & 0x80;
12718 /* _asm nop _endasm; */\InsetSpace ~
12726 /* for slow peripherals */
12778 \begin_layout Standard
12779 Then, someplace in the code for the first hardware you would use
12782 \begin_layout Verse
12786 \begin_inset LatexCommand \index{at}
12791 \begin_inset LatexCommand \index{\_\_at}
12795 (0x80) MOSI;\InsetSpace ~
12799 /* I/O port 0, bit 0 */
12801 __bit __at (0x81) MISO;\InsetSpace ~
12808 __bit __at (0x82) MCLK;\InsetSpace ~
12812 /* I/O port 0, bit 2 */
12815 \begin_layout Standard
12816 Similarly, for the second hardware you would use
12819 \begin_layout Verse
12822 __bit __at (0x83) MOSI;\InsetSpace ~
12826 /* I/O port 0, bit 3 */
12828 __bit __at (0x91) MISO;\InsetSpace ~
12833 I/O port 1, bit 1 */
12836 \begin_inset LatexCommand \index{bit}
12840 __at (0x92) MCLK;\InsetSpace ~
12844 /* I/O port 1, bit 2 */
12847 \begin_layout Standard
12848 and you can use the same hardware dependent routine without changes, as
12849 for example in a library.
12850 This is somehow similar to sbit, but only one absolute address has to be
12851 specified in the whole project.
12852 \begin_inset VSpace bigskip
12858 \begin_layout Section
12860 \begin_inset LatexCommand \index{Parameters}
12865 \begin_inset LatexCommand \index{function parameter}
12870 \begin_inset LatexCommand \index{local variables}
12875 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12882 \begin_layout Standard
12883 Automatic (local) variables and parameters to functions can either be placed
12884 on the stack or in data-space.
12885 The default action of the compiler is to place these variables in the internal
12886 RAM (for small model) or external RAM (for large model).
12887 This in fact makes them similar to
12890 \begin_inset LatexCommand \index{static}
12896 so by default functions are non-reentrant
12897 \begin_inset LatexCommand \index{reentrant}
12906 They can be placed on the stack
12907 \begin_inset LatexCommand \index{stack}
12917 \begin_layout Standard
12927 \begin_inset LatexCommand \index{-\/-stack-auto}
12935 #pragma\InsetSpace ~
12939 \begin_inset LatexCommand \index{\#pragma stackauto}
12946 \begin_inset LatexCommand \index{reentrant}
12952 keyword in the function declaration, e.g.:
12955 \begin_layout Verse
12958 unsigned char foo(char i) __reentrant
12972 \begin_layout Standard
12973 Since stack space on 8051 is limited, the
12983 \begin_layout Standard
12994 option should be used sparingly.
12995 Note that the reentrant keyword just means that the parameters & local
12996 variables will be allocated to the stack, it
13000 mean that the function is register bank
13001 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13010 \begin_inset LatexCommand \index{local variables}
13014 can be assigned storage classes and absolute
13015 \begin_inset LatexCommand \index{Absolute addressing}
13022 \begin_layout Verse
13025 unsigned char foo()
13033 __xdata unsigned char i;
13046 \begin_inset LatexCommand \index{at}
13050 (0x31) unsigned char j;
13062 \begin_layout Standard
13063 In the above example the variable
13067 will be allocated in the external ram,
13071 in bit addressable space and
13082 \begin_layout Standard
13093 or when a function is declared as
13097 this should only be done for static variables.
13100 \begin_layout Standard
13102 \begin_inset LatexCommand \index{function parameter}
13106 however are not allowed any storage class
13107 \begin_inset LatexCommand \index{Storage class}
13111 , (storage classes for parameters will be ignored), their allocation is
13112 governed by the memory model in use, and the reentrancy options.
13115 \begin_layout Standard
13116 It is however allowed to use bit parameters in reentrant functions and also
13117 non-static local bit variables are supported.
13118 Efficient use is limited to 8 semi-bitregisters in bit space.
13119 They are pushed and popped to stack
13120 \begin_inset LatexCommand \index{stack}
13124 as a single byte just like the normal registers.
13127 \begin_layout Section
13129 \begin_inset LatexCommand \label{sub:Overlaying}
13134 \begin_inset LatexCommand \index{Overlaying}
13141 \begin_layout Standard
13143 \begin_inset LatexCommand \index{reentrant}
13147 functions SDCC will try to reduce internal ram space usage by overlaying
13148 parameters and local variables of a function (if possible).
13149 Parameters and local variables
13150 \begin_inset LatexCommand \index{local variables}
13154 of a function will be allocated to an overlayable segment if the function
13157 no other function calls and the function is non-reentrant and the memory
13159 \begin_inset LatexCommand \index{Memory model}
13166 If an explicit storage class
13167 \begin_inset LatexCommand \index{Storage class}
13171 is specified for a local variable, it will NOT be overlayed.
13174 \begin_layout Standard
13175 Note that the compiler (not the linkage editor) makes the decision for overlayin
13177 Functions that are called from an interrupt service routine
13178 \begin_inset Marginal
13181 \begin_layout Standard
13189 should be preceded by a #pragma\InsetSpace ~
13191 \begin_inset LatexCommand \index{\#pragma nooverlay}
13195 if they are not reentrant.
13198 \begin_layout Standard
13199 Also note that the compiler does not do any processing of inline assembler
13200 code, so the compiler might incorrectly assign local variables and parameters
13201 of a function into the overlay segment if the inline assembler code calls
13202 other c-functions that might use the overlay.
13203 In that case the #pragma\InsetSpace ~
13204 nooverlay should be used.
13207 \begin_layout Standard
13208 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13210 \begin_inset LatexCommand \index{Multiplication}
13215 \begin_inset LatexCommand \index{Division}
13219 will NOT be overlayed since these are implemented using external functions,
13223 \begin_layout Verse
13229 \begin_inset LatexCommand \index{\#pragma nooverlay}
13235 void set_error(unsigned char errcd)
13252 some_isr () __interrupt
13253 \begin_inset LatexCommand \index{interrupt}
13283 \begin_layout Standard
13284 In the above example the parameter
13292 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13294 not present, this could cause unpredictable runtime behavior when called
13295 from an interrupt service routine.
13296 The #pragma\InsetSpace ~
13297 nooverlay ensures that the parameters and local variables for
13298 the function are NOT overlayed.
13299 \begin_inset VSpace bigskip
13305 \begin_layout Section
13306 Interrupt Service Routines
13307 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13314 \begin_layout Subsection
13315 General Information
13318 \begin_layout Standard
13331 outines to be coded in C, with some extended keywords.
13334 \begin_layout Verse
13337 void timer_isr (void) __interrupt (1) __using (1)
13351 \begin_layout Standard
13352 The optional number following the
13355 \begin_inset LatexCommand \index{interrupt}
13360 \begin_inset LatexCommand \index{\_\_interrupt}
13366 keyword is the interrupt number this routine will service.
13367 When present, the compiler will insert a call to this routine in the interrupt
13369 \begin_inset LatexCommand \index{interrupt vector table}
13373 for the interrupt number specified.
13374 If you have multiple source files in your project, interrupt service routines
13375 can be present in any of them, but a prototype of the isr MUST be present
13376 or included in the file that contains the function
13381 The optional (8051 specific) keyword
13384 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13389 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13395 can be used to tell the compiler to use the specified register bank when
13396 generating code for this function.
13399 Interrupt service routines open the door for some very interesting bugs:
13402 \begin_layout Subsubsection
13403 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13407 Common interrupt pitfall: variable not declared
13412 \begin_layout Standard
13413 If an interrupt service routine changes variables which are accessed by
13414 other functions these variables have to be declared
13419 \begin_inset LatexCommand \index{volatile}
13425 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13432 \begin_layout Subsubsection
13433 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13437 Common interrupt pitfall:
13442 \begin_layout Standard
13443 If the access to these variables is not
13446 \begin_inset LatexCommand \index{atomic}
13453 the processor needs more than one instruction for the access and could
13454 be interrupted while accessing the variable) the interrupt must be disabled
13455 during the access to avoid inconsistent data.
13458 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13459 and should be protected by disabling interrupts.
13460 You're not automatically on the safe side if you use 8 bit variables though.
13461 We need an example here: f.e.
13462 on the 8051 the harmless looking
13463 \begin_inset Quotes srd
13473 \begin_inset Quotes sld
13482 \begin_inset Quotes srd
13492 \begin_inset Quotes sld
13495 from within an interrupt routine might get lost if the interrupt occurs
13498 \begin_inset Quotes sld
13503 counter\InsetSpace ~
13508 \begin_inset Quotes srd
13511 is not atomic on the 8051 even if
13515 is located in data memory.
13517 Bugs like these are hard to reproduce and can
13518 cause a lot of trouble.
13522 \begin_layout Subsubsection
13523 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13527 Common interrupt pitfall:
13532 \begin_layout Standard
13533 The return address and the registers used in the interrupt service routine
13534 are saved on the stack
13535 \begin_inset LatexCommand \index{stack}
13539 so there must be sufficient stack space.
13540 If there isn't variables or registers (or even the return address itself)
13547 \begin_inset LatexCommand \index{stack overflow}
13551 is most likely to happen if the interrupt occurs during the
13552 \begin_inset Quotes sld
13556 \begin_inset Quotes srd
13559 subroutine when the stack is already in use for f.e.
13560 many return addresses.
13563 \begin_layout Subsubsection
13564 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13568 Common interrupt pitfall:
13570 use of non-reentrant functions
13573 \begin_layout Standard
13574 A special note here, int (16 bit) and long (32 bit) integer division
13575 \begin_inset LatexCommand \index{Division}
13580 \begin_inset LatexCommand \index{Multiplication}
13585 \begin_inset LatexCommand \index{Modulus}
13590 \begin_inset LatexCommand \index{Floating point support}
13594 operations are implemented using external support routines.
13595 If an interrupt service routine needs to do any of these operations then
13596 the support routines (as mentioned in a following section) will have to
13597 be recompiled using the
13603 \begin_layout Standard
13613 \begin_inset LatexCommand \index{-\/-stack-auto}
13619 option and the source file will need to be compiled using the
13625 \begin_layout Standard
13637 \begin_inset LatexCommand \index{-\/-int-long-reent}
13644 Note, the type promotion
13645 \begin_inset LatexCommand \index{type promotion}
13649 required by ANSI C can cause 16 bit routines to be used
13650 \begin_inset Marginal
13653 \begin_layout Standard
13662 without the programmer being aware of it.
13666 (unsigned char)(tail-1)
13668 within the if clause in section
13669 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13676 \begin_layout Standard
13677 Calling other functions from an interrupt service routine is not recommended,
13678 avoid it if possible.
13679 Note that when some function is called from an interrupt service routine
13680 it should be preceded by a #pragma\InsetSpace ~
13682 \begin_inset LatexCommand \index{\#pragma nooverlay}
13686 if it is not reentrant.
13687 Furthermore nonreentrant functions should not be called from the main program
13688 while the interrupt service routine might be active.
13689 They also must not be called from low priority interrupt service routines
13690 while a high priority interrupt service routine might be active.
13691 You could use semaphores or make the function
13695 if all parameters are passed in registers.
13698 \begin_inset LatexCommand \ref{sub:Overlaying}
13703 about Overlaying and section
13704 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13709 about Functions using private register banks.
13710 \begin_inset VSpace bigskip
13716 \begin_layout Subsection
13717 MCS51/DS390 Interrupt Service Routines
13720 \begin_layout Standard
13722 \begin_inset LatexCommand \index{interrupt}
13726 numbers and the corresponding address & descriptions for the Standard 8051/8052
13728 SDCC will automatically adjust the
13729 \begin_inset LatexCommand \index{interrupt vector table}
13733 to the maximum interrupt number specified.
13738 \begin_layout Standard
13740 \begin_inset Tabular
13741 <lyxtabular version="3" rows="9" columns="3">
13743 <column alignment="center" valignment="top" leftline="true" width="0in">
13744 <column alignment="left" valignment="top" leftline="true" width="0in">
13745 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13746 <row topline="true" bottomline="true">
13747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13750 \begin_layout Standard
13756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13759 \begin_layout Standard
13765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13768 \begin_layout Standard
13775 <row topline="true">
13776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13779 \begin_layout Standard
13785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13788 \begin_layout Standard
13794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13797 \begin_layout Standard
13804 <row topline="true">
13805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13808 \begin_layout Standard
13814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13817 \begin_layout Standard
13823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13826 \begin_layout Standard
13833 <row topline="true">
13834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13837 \begin_layout Standard
13843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13846 \begin_layout Standard
13852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13855 \begin_layout Standard
13862 <row topline="true">
13863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13866 \begin_layout Standard
13872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13875 \begin_layout Standard
13881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13884 \begin_layout Standard
13891 <row topline="true">
13892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13895 \begin_layout Standard
13901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13904 \begin_layout Standard
13910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13913 \begin_layout Standard
13920 <row topline="true">
13921 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13924 \begin_layout Standard
13930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13933 \begin_layout Standard
13939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13942 \begin_layout Standard
13949 <row topline="true">
13950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13953 \begin_layout Standard
13959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13962 \begin_layout Standard
13968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13971 \begin_layout Standard
13978 <row topline="true" bottomline="true">
13979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13982 \begin_layout Standard
13988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13991 \begin_layout Standard
13997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14000 \begin_layout Standard
14016 \begin_layout Standard
14017 If the interrupt service routine is defined without
14020 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14025 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14031 a register bank or with register bank 0 (
14035 0), the compiler will save the registers used by itself on the stack upon
14036 entry and restore them at exit, however if such an interrupt service routine
14037 calls another function then the entire register bank will be saved on the
14039 This scheme may be advantageous for small interrupt service routines which
14040 have low register usage.
14043 \begin_layout Standard
14044 If the interrupt service routine is defined to be using a specific register
14049 & psw are saved and restored, if such an interrupt service routine calls
14050 another function (using another register bank) then the entire register
14051 bank of the called function will be saved on the stack
14052 \begin_inset LatexCommand \index{stack}
14057 This scheme is recommended for larger interrupt service routines.
14058 \begin_inset VSpace bigskip
14064 \begin_layout Subsection
14066 \begin_inset LatexCommand \index{HC08}
14070 Interrupt Service Routines
14073 \begin_layout Standard
14074 Since the number of interrupts
14075 \begin_inset LatexCommand \index{HC08!interrupt}
14079 available is chip specific and the interrupt vector table always ends at
14080 the last byte of memory, the interrupt numbers corresponds to the interrupt
14081 vectors in reverse order of address.
14082 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14083 2 will use the interrupt vector at 0xfffa, and so on.
14084 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14085 this way; instead see section
14086 \begin_inset LatexCommand \ref{sub:Startup-Code}
14090 for details on customizing startup.
14091 \begin_inset VSpace bigskip
14097 \begin_layout Subsection
14098 Z80 Interrupt Service Routines
14101 \begin_layout Standard
14103 \begin_inset LatexCommand \index{Z80}
14107 uses several different methods for determining the correct interrupt
14108 \begin_inset LatexCommand \index{Z80!interrupt}
14112 vector depending on the hardware implementation.
14113 Therefore, SDCC ignores the optional interrupt number and does not attempt
14114 to generate an interrupt vector table.
14117 \begin_layout Standard
14118 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14119 instruction to return from the interrupt.
14120 To write an interrupt handler for the non-maskable interrupt, which needs
14121 a RETN instruction instead, add the
14128 \begin_layout Verse
14131 void nmi_isr (void) critical interrupt
14145 \begin_layout Standard
14146 However if you need to create a non-interruptable interrupt service routine
14147 you would also require the
14152 To distinguish between this and an nmi_isr you must provide an interrupt
14154 \begin_inset VSpace bigskip
14160 \begin_layout Section
14161 Enabling and Disabling Interrupts
14164 \begin_layout Subsection
14165 Critical Functions and Critical Statements
14168 \begin_layout Standard
14169 A special keyword may be associated with a block or a function declaring
14175 SDCC will generate code to disable all interrupts
14176 \begin_inset LatexCommand \index{interrupt}
14180 upon entry to a critical function and restore the interrupt enable to the
14181 previous state before returning.
14182 Nesting critical functions will need one additional byte on the stack
14183 \begin_inset LatexCommand \index{stack}
14190 \begin_layout Verse
14193 int foo () __critical
14194 \begin_inset LatexCommand \index{critical}
14199 \begin_inset LatexCommand \index{\_\_critical}
14224 \begin_layout Standard
14225 The critical attribute maybe used with other attributes like
14235 may also be used to disable interrupts more locally:
14238 \begin_layout Verse
14244 \begin_layout Standard
14245 More than one statement could have been included in the block.
14248 \begin_layout Subsection
14249 Enabling and Disabling Interrupts directly
14252 \begin_layout Standard
14254 \begin_inset LatexCommand \index{interrupt}
14258 can also be disabled and enabled directly (8051):
14261 \begin_layout Verse
14264 EA = 0;\InsetSpace ~
14290 \begin_layout Verse
14326 \begin_layout Verse
14329 EA = 1;\InsetSpace ~
14358 \begin_layout Verse
14397 \begin_layout Standard
14398 On other architectures which have seperate opcodes for enabling and disabling
14399 interrupts you might want to make use of defines with inline assembly
14400 \begin_inset LatexCommand \index{Assembler routines}
14405 \begin_inset LatexCommand \index{HC08!interrupt}
14412 \begin_layout Verse
14416 \begin_inset LatexCommand \index{\_asm}
14425 \begin_inset LatexCommand \index{\_endasm}
14432 \begin_layout Verse
14435 #define SEI _asm\InsetSpace ~
14442 \begin_layout Verse
14448 \begin_layout Standard
14449 Note: it is sometimes sufficient to disable only a specific interrupt source
14451 a timer or serial interrupt by manipulating an
14454 \begin_inset LatexCommand \index{interrupt mask}
14464 \begin_layout Standard
14465 Usually the time during which interrupts are disabled should be kept as
14467 This minimizes both
14472 \begin_inset LatexCommand \index{interrupt latency}
14476 (the time between the occurrence of the interrupt and the execution of
14477 the first code in the interrupt routine) and
14482 \begin_inset LatexCommand \index{interrupt jitter}
14486 (the difference between the shortest and the longest interrupt latency).
14487 These really are something different, f.e.
14488 a serial interrupt has to be served before its buffer overruns so it cares
14489 for the maximum interrupt latency, whereas it does not care about jitter.
14490 On a loudspeaker driven via a digital to analog converter which is fed
14491 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14492 a much smaller jitter will be very audible.
14495 \begin_layout Standard
14496 You can reenable interrupts within an interrupt routine and on some architecture
14497 s you can make use of two (or more) levels of
14499 interrupt priorities
14502 \begin_inset LatexCommand \index{interrupt priority}
14507 On some architectures which don't support interrupt priorities these can
14508 be implemented by manipulating the interrupt mask and reenabling interrupts
14509 within the interrupt routine.
14510 Check there is sufficient space on the stack
14511 \begin_inset LatexCommand \index{stack}
14515 and don't add complexity unless you have to.
14519 \begin_layout Subsection
14521 \begin_inset LatexCommand \index{semaphore}
14525 locking (mcs51/ds390)
14528 \begin_layout Standard
14529 Some architectures (mcs51/ds390) have an atomic
14530 \begin_inset LatexCommand \index{atomic}
14543 These type of instructions are typically used in preemptive multitasking
14544 systems, where a routine f.e.
14545 claims the use of a data structure ('acquires a lock
14546 \begin_inset LatexCommand \index{lock}
14550 on it'), makes some modifications and then releases the lock when the data
14551 structure is consistent again.
14552 The instruction may also be used if interrupt and non-interrupt code have
14553 to compete for a resource.
14554 With the atomic bit test and clear instruction interrupts
14555 \begin_inset LatexCommand \index{interrupt}
14559 don't have to be disabled for the locking operation.
14563 \begin_layout Standard
14564 SDCC generates this instruction if the source follows this pattern:
14567 \begin_layout Verse
14571 \begin_inset LatexCommand \index{volatile}
14575 bit resource_is_free;
14579 if (resource_is_free)
14589 resource_is_free=0;
14602 resource_is_free=1;
14609 \begin_layout Standard
14610 Note, mcs51 and ds390 support only an atomic
14611 \begin_inset LatexCommand \index{atomic}
14619 instruction (as opposed to atomic bit test and
14624 \begin_layout Section
14625 Functions using private register banks
14626 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14633 \begin_layout Standard
14634 Some architectures have support for quickly changing register sets.
14635 SDCC supports this feature with the
14638 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14643 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14649 attribute (which tells the compiler to use a register bank
14650 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14654 other than the default bank zero).
14655 It should only be applied to
14658 \begin_inset LatexCommand \index{interrupt}
14664 functions (see footnote below).
14665 This will in most circumstances make the generated ISR code more efficient
14666 since it will not have to save registers on the stack.
14669 \begin_layout Standard
14674 attribute will have no effect on the generated code for a
14678 function (but may occasionally be useful anyway
14682 \begin_layout Standard
14683 possible exception: if a function is called ONLY from 'interrupt' functions
14684 using a particular bank, it can be declared with the same 'using' attribute
14685 as the calling 'interrupt' functions.
14686 For instance, if you have several ISRs using bank one, and all of them
14687 call memcpy(), it might make sense to create a specialized version of memcpy()
14688 'using 1', since this would prevent the ISR from having to save bank zero
14689 to the stack on entry and switch to bank zero before calling the function
14698 (pending: Note, nowadays the
14702 attribute has an effect on
14706 the generated code for a
14717 \begin_layout Standard
14722 function using a non-zero bank will assume that it can trash that register
14723 bank, and will not save it.
14724 Since high-priority interrupts
14725 \begin_inset LatexCommand \index{interrupts}
14730 \begin_inset LatexCommand \index{interrupt priority}
14734 can interrupt low-priority ones on the 8051 and friends, this means that
14735 if a high-priority ISR
14739 a particular bank occurs while processing a low-priority ISR
14743 the same bank, terrible and bad things can happen.
14744 To prevent this, no single register bank should be
14748 by both a high priority and a low priority ISR.
14749 This is probably most easily done by having all high priority ISRs use
14750 one bank and all low priority ISRs use another.
14751 If you have an ISR which can change priority at runtime, you're on your
14752 own: I suggest using the default bank zero and taking the small performance
14756 \begin_layout Standard
14757 It is most efficient if your ISR calls no other functions.
14758 If your ISR must call other functions, it is most efficient if those functions
14759 use the same bank as the ISR (see note 1 below); the next best is if the
14760 called functions use bank zero.
14761 It is very inefficient to call a function using a different, non-zero bank
14764 \begin_inset VSpace bigskip
14770 \begin_layout Section
14772 \begin_inset LatexCommand \label{sub:Startup-Code}
14777 \begin_inset LatexCommand \index{Startup code}
14784 \begin_layout Subsection
14785 MCS51/DS390 Startup Code
14788 \begin_layout Standard
14789 The compiler triggers the linker to link certain initialization modules
14790 from the runtime library
14791 \begin_inset LatexCommand \index{Runtime library}
14795 called crt<something>.
14796 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14797 GSINIT5) is not linked unless the --xstack option is used.
14798 These modules are highly entangled by the use of special segments/areas,
14799 but a common layout is shown below:
14802 \begin_layout Verse
14810 \begin_layout Verse
14834 ljmp __sdcc_gsinit_startup
14837 \begin_layout Verse
14845 \begin_layout Verse
14857 .area GSINIT0 (CODE)
14859 __sdcc_gsinit_startup::
14869 mov sp,#__start__stack - 1
14872 \begin_layout Verse
14880 \begin_layout Verse
14892 .area GSINIT1 (CODE)
14894 __sdcc_init_xstack::
14896 ; Need to initialize in GSINIT1 in
14897 case the user's __sdcc_external_startup uses the xstack.
14907 mov __XPAGE,#(__start__x
14918 mov _spx,#__start__xstack
14921 \begin_layout Verse
14929 \begin_layout Verse
14941 .area GSINIT2 (CODE)
14951 lcall __sdcc_external_startup
14971 jz __sdcc_init_data
14982 __sdcc_program_startup
14987 \begin_layout Verse
14995 \begin_layout Verse
15007 .area GSINIT3 (CODE)
15060 mov r2,#((l_XINIT+255) >> 8)
15091 __XPAGE,#(s_XISEG >> 8)
15093 00001$:\InsetSpace ~
15157 00002$:\InsetSpace ~
15184 \begin_layout Verse
15192 \begin_layout Verse
15204 .area GSINIT4 (CODE)
15206 __mcs51_genRAMCLEAR::
15228 00004$:\InsetSpace ~
15242 ; _mcs51_genRAMCLEAR() end
15245 \begin_layout Verse
15253 \begin_layout Verse
15265 .area GSINIT4 (CODE)
15267 __mcs51_genXRAMCLEAR::
15318 mov __XPAGE,#(s_PSEG >> 8)
15330 00005$:\InsetSpace ~
15384 orl a,#(l_XSEG >> 8)
15427 00007$:\InsetSpace ~
15464 \begin_layout Verse
15472 \begin_layout Verse
15484 .area GSINIT5 (CODE)
15486 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15489 ; and __mcs51_genRAMCLEAR modifies _spx.
15499 mov __XPAGE,#(__start__x
15510 mov _spx,#__start__xstack
15513 \begin_layout Verse
15518 (application modules)
15521 \begin_layout Verse
15533 .area GSINIT (CODE)
15536 \begin_layout Verse
15544 \begin_layout Verse
15556 .area GSFINAL (CODE)
15566 ljmp __sdcc_program_startup
15568 ;---------------------------------
15569 -----------------------
15573 ;--------------------------------------------------
15596 __sdcc_program_startup:
15609 return from main will lock up
15622 \begin_layout Standard
15623 One of these modules (crtstart.asm) contains a call to the C routine
15625 _sdcc_external_startup()
15626 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15635 at the start of the CODE area.
15636 This routine is also in the runtime library
15637 \begin_inset LatexCommand \index{Runtime library}
15641 and returns 0 by default.
15642 If this routine returns a non-zero value, the static & global variable
15643 initialization will be skipped and the function main will be invoked.
15644 Otherwise static & global variables will be initialized before the function
15648 _sdcc_external_startup()
15650 routine to your program to override the default if you need to setup hardware
15651 or perform some other critical operation prior to static & global variable
15653 \begin_inset LatexCommand \index{Variable initialization}
15658 On some mcs51 variants xdata
15659 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15663 memory has to be explicitly enabled before it can be accessed or if the
15665 \begin_inset LatexCommand \index{watchdog}
15669 needs to be disabled, this is the place to do it.
15670 The startup code clears all internal data memory, 256 bytes by default,
15671 but from 0 to n-1 if
15677 \begin_layout Standard
15687 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15694 (recommended for Chipcon CC1010).
15697 \begin_layout Standard
15698 See also the compiler options
15704 \begin_layout Standard
15720 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15730 \begin_layout Standard
15742 \begin_inset LatexCommand \index{-\/-main-return}
15747 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15751 about MCS51-variants.
15752 \begin_inset VSpace bigskip
15758 \begin_layout Subsection
15762 \begin_layout Standard
15764 \begin_inset LatexCommand \index{HC08}
15768 startup code follows the same scheme as the MCS51 startup code.
15769 \begin_inset VSpace bigskip
15775 \begin_layout Subsection
15779 \begin_layout Standard
15781 \begin_inset LatexCommand \index{Z80}
15785 the startup code is inserted by linking with crt0.o which is generated from
15786 sdcc/device/lib/z80/crt0.s.
15787 If you need a different startup code you can use the compiler option
15796 \begin_layout Standard
15811 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15815 and provide your own crt0.o.
15817 \begin_inset VSpace bigskip
15823 \begin_layout Section
15824 Inline Assembler Code
15825 \begin_inset LatexCommand \index{Assembler routines}
15832 \begin_layout Subsection
15833 A Step by Step Introduction
15834 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15841 \begin_layout Standard
15842 Starting from a small snippet of c-code this example shows for the MCS51
15843 how to use inline assembly, access variables, a function parameter and
15844 an array in xdata memory.
15845 The example uses an MCS51 here but is easily adapted for other architectures.
15846 This is a buffer routine which should be optimized:
15849 \begin_layout Verse
15853 unsigned char __far
15854 \begin_inset LatexCommand \index{far (storage class)}
15859 \begin_inset LatexCommand \index{\_\_far (storage class)}
15864 \begin_inset LatexCommand \index{at}
15869 \begin_inset LatexCommand \index{\_\_at}
15873 (0x7f00) buf[0x100];
15874 \begin_inset LatexCommand \index{Aligned array}
15880 unsigned char head, tail;\InsetSpace ~
15898 \begin_inset LatexCommand \index{interrupt}
15950 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15962 void to_buffer( unsigned char c )
15970 if( head != (unsigned char)(tail-1)
15977 \begin_inset LatexCommand \index{promotion to signed int}
15982 \begin_inset LatexCommand \index{type promotion}
15987 \begin_inset Marginal
15990 \begin_layout Standard
16009 buf[ head++ ] = c;\InsetSpace ~
16025 /* access to a 256 byte aligned array */
16030 \begin_layout Standard
16031 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16032 then a corresponding buffer.asm file is generated.
16033 We define a new function
16037 in file buffer.c in which we cut and paste the generated code, removing
16038 unwanted comments and some ':'.
16040 \begin_inset Quotes sld
16048 \begin_inset Quotes srd
16052 \begin_inset Quotes sld
16060 \begin_inset Quotes srd
16067 \begin_layout Standard
16068 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16069 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16071 The latter is also used in the library functions.
16076 to the beginning and the end of the function body:
16079 \begin_layout Verse
16083 /* With a cut and paste from the .asm file, we have something to start with.
16089 function is not yet OK! (registers aren't saved) */
16091 void to_buffer_asm(
16101 \begin_inset LatexCommand \index{\_asm}
16106 \begin_inset LatexCommand \index{\_\_asm}
16120 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16126 \begin_inset LatexCommand \index{promotion to signed int}
16131 \begin_inset LatexCommand \index{type promotion}
16184 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16185 \begin_inset LatexCommand \index{Aligned array}
16251 \begin_inset LatexCommand \index{\_endasm}
16256 \begin_inset LatexCommand \index{\_\_endasm}
16265 \begin_layout Standard
16266 The new file buffer.c should compile with only one warning about the unreferenced
16267 function argument 'c'.
16268 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16269 (1) and finally have:
16272 \begin_layout Verse
16276 unsigned char __far __at(0x7f00) buf[0x100];
16278 unsigned char head, tail;
16289 void to_buffer( unsigned char c )
16298 head != (unsigned char)(tail-1) )
16327 c; // to avoid warning: unreferenced function argument
16334 \begin_inset LatexCommand \index{\_asm}
16339 \begin_inset LatexCommand \index{\_\_asm}
16353 ; save used registers here.
16364 ; If we were still using r2,r3 we would have to push them here.
16367 ; if( head != (unsigned char)(tail-1) )
16411 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16447 a,dpl \InsetSpace ~
16454 ; dpl holds lower byte of function argument
16466 dpl,_head \InsetSpace ~
16469 ; buf is 0x100 byte aligned so head can be used directly
16512 ; we could do an ANL _head,#0x0f here to use a
16513 smaller buffer (see above)
16525 ; restore used registers here
16532 \begin_inset LatexCommand \index{\_endasm}
16537 \begin_inset LatexCommand \index{\_\_endasm}
16548 \begin_layout Standard
16549 The inline assembler code can contain any valid code understood by the assembler
16550 , this includes any assembler directives and comment lines.
16551 The assembler does not like some characters like ':' or ''' in comments.
16552 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16553 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16558 \begin_inset LatexCommand \index{Assembler documentation}
16563 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16571 \begin_layout Standard
16572 The compiler does not do any validation of the code within the
16575 \begin_inset LatexCommand \index{\_asm}
16580 \begin_inset LatexCommand \index{\_\_asm}
16588 \begin_inset LatexCommand \index{\_endasm}
16593 \begin_inset LatexCommand \index{\_\_endasm}
16602 Specifically it will not know which registers are used and thus register
16604 \begin_inset LatexCommand \index{push/pop}
16608 has to be done manually.
16612 \begin_layout Standard
16613 It is recommended that each assembly instruction (including labels) be placed
16614 in a separate line (as the example shows).
16619 \begin_layout Standard
16631 \begin_inset LatexCommand \index{-\/-peep-asm}
16637 command line option is used, the inline assembler code will be passed through
16638 the peephole optimizer
16639 \begin_inset LatexCommand \index{Peephole optimizer}
16644 There are only a few (if any) cases where this option makes sense, it might
16645 cause some unexpected changes in the inline assembler code.
16646 Please go through the peephole optimizer rules defined in file
16650 before using this option.
16653 \begin_layout Subsection
16655 \begin_inset LatexCommand \label{sub:Naked-Functions}
16660 \begin_inset LatexCommand \index{Naked functions}
16667 \begin_layout Standard
16668 A special keyword may be associated with a function declaring it as
16671 \begin_inset LatexCommand \index{\_naked}
16676 \begin_inset LatexCommand \index{\_\_naked}
16687 function modifier attribute prevents the compiler from generating prologue
16688 \begin_inset LatexCommand \index{function prologue}
16693 \begin_inset LatexCommand \index{function epilogue}
16697 code for that function.
16698 This means that the user is entirely responsible for such things as saving
16699 any registers that may need to be preserved, selecting the proper register
16700 bank, generating the
16704 instruction at the end, etc.
16705 Practically, this means that the contents of the function must be written
16706 in inline assembler.
16707 This is particularly useful for interrupt functions, which can have a large
16708 (and often unnecessary) prologue/epilogue.
16709 For example, compare the code generated by these two functions:
16712 \begin_layout Verse
16716 \begin_inset LatexCommand \index{volatile}
16720 data unsigned char counter;
16724 void simpleInterrupt(void) __interrupt
16725 \begin_inset LatexCommand \index{interrupt}
16730 \begin_inset LatexCommand \index{\_\_interrupt}
16748 void nakedInterrupt(void) __interrupt (2) __naked
16757 \begin_inset LatexCommand \index{\_asm}
16762 \begin_inset LatexCommand \index{\_\_asm}
16779 _counter ; does not change flags, no need to save psw
16792 include ret or reti in _naked function.
16799 \begin_inset LatexCommand \index{\_endasm}
16804 \begin_inset LatexCommand \index{\_\_endasm}
16813 \begin_layout Standard
16814 For an 8051 target, the generated simpleInterrupt looks like:
16817 \begin_layout Verse
16824 example, recent versions of SDCC generate
16830 code for simpleInterrupt() and nakedInterrupt()!
16971 \begin_layout Standard
16972 whereas nakedInterrupt looks like:
16975 \begin_layout Verse
16988 _counter ; does not change flags, no need to save psw
17007 MUST explicitly include ret or reti in _naked function
17010 \begin_layout Standard
17011 The related directive #pragma exclude
17012 \begin_inset LatexCommand \index{\#pragma exclude}
17016 allows a more fine grained control over pushing & popping
17017 \begin_inset LatexCommand \index{push/pop}
17024 \begin_layout Standard
17025 While there is nothing preventing you from writing C code inside a
17029 function, there are many ways to shoot yourself in the foot doing this,
17030 and it is recommended that you stick to inline assembler.
17033 \begin_layout Subsection
17034 Use of Labels within Inline Assembler
17037 \begin_layout Standard
17038 SDCC allows the use of in-line assembler with a few restrictions regarding
17040 In older versions of the compiler all labels defined within inline assembler
17041 code had to be of the form
17045 where nnnnn is a number less than 100 (which implies a limit of utmost
17046 100 inline assembler labels
17057 \begin_layout Verse
17061 \begin_inset LatexCommand \index{\_asm}
17066 \begin_inset LatexCommand \index{\_\_asm}
17096 \begin_inset LatexCommand \index{\_endasm}
17101 \begin_inset LatexCommand \index{\_\_endasm}
17108 \begin_layout Standard
17109 Inline assembler code cannot reference any C-labels, however it can reference
17111 \begin_inset LatexCommand \index{Labels}
17115 defined by the inline assembler, e.g.:
17118 \begin_layout Verse
17141 ; some assembler code
17162 /* some more c code */
17164 clabel:\InsetSpace ~
17166 /* inline assembler cannot reference this
17179 $0003: ;label (can be referenced by inline assembler only)
17187 \begin_inset LatexCommand \index{\_endasm}
17192 \begin_inset LatexCommand \index{\_\_endasm}
17202 /* some more c code */
17207 \begin_layout Standard
17208 In other words inline assembly code can access labels defined in inline
17209 assembly within the scope of the function.
17210 The same goes the other way, i.e.
17211 labels defines in inline assembly can not be accessed by C statements.
17214 \begin_layout Section
17215 Interfacing with Assembler Code
17216 \begin_inset LatexCommand \index{Assembler routines}
17223 \begin_layout Subsection
17224 Global Registers used for Parameter Passing
17225 \begin_inset LatexCommand \index{Parameter passing}
17232 \begin_layout Standard
17233 The compiler always uses the global registers
17236 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17241 \begin_inset LatexCommand \index{DPTR}
17246 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17255 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17261 to pass the first parameter to a function, and also to pass the return
17263 \begin_inset LatexCommand \index{return value}
17267 of function; according to the following scheme: one byte return value in
17272 , two byte value in
17281 three byte values (generic pointers) in
17293 , and four byte values in
17311 \begin_inset LatexCommand \index{generic pointer}
17315 contain type of accessed memory in
17336 \begin_inset Note Note
17339 \begin_layout Standard
17340 This might not be the case of certain memory models (medium???)
17348 \begin_layout Standard
17349 The second parameter onwards is either allocated on the stack (for reentrant
17354 \begin_layout Standard
17363 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17367 \begin_layout Subsection
17371 \begin_layout Standard
17372 Unless the called function is declared as
17377 \begin_inset LatexCommand \index{naked}
17385 \begin_layout Standard
17395 \begin_inset LatexCommand \index{-\/-callee-saves}
17403 \begin_layout Standard
17412 -all-callee-saves command line option or the corresponding callee_saves
17413 pragma are used, the caller will save the registers (
17417 ) around the call, so the called function can destroy they content freely.
17420 \begin_layout Standard
17421 If the called function is not declared as
17425 , the caller will swap register banks around the call, if caller and callee
17426 use different register banks (having them defined by the
17434 \begin_layout Standard
17435 The called function can also use
17451 observing that they are used for parameter/return value passing.
17454 \begin_layout Subsection
17455 Assembler Routine (non-reentrant)
17458 \begin_layout Standard
17459 In the following example
17460 \begin_inset LatexCommand \index{reentrant}
17465 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17469 the function c_func calls an assembler routine asm_func, which takes two
17471 \begin_inset LatexCommand \index{function parameter}
17478 \begin_layout Verse
17481 extern int asm_func(unsigned char, unsigned char);
17485 int c_func (unsigned char
17486 i, unsigned char j)
17494 return asm_func(i,j);
17508 return c_func(10,9);
17513 \begin_layout Standard
17514 The corresponding assembler function is:
17517 \begin_layout Verse
17520 .globl _asm_func_PARM_2
17622 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17639 \begin_layout Standard
17640 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17641 the parameter number starting from 1, and counting from the left.
17642 The first parameter is passed in
17658 according to the description above.
17659 The variable name for the second parameter will be _<function_name>_PARM_2.
17664 ble the assembler routine with the following command:
17671 asx8051 -losg asmfunc.asm
17678 Then compile and link the assembler routine to the C source file with the
17686 sdcc cfunc.c asmfunc.rel
17689 \begin_layout Subsection
17690 Assembler Routine (reentrant)
17693 \begin_layout Standard
17695 \begin_inset LatexCommand \index{reentrant}
17700 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17704 the second parameter
17705 \begin_inset LatexCommand \index{function parameter}
17709 onwards will be passed on the stack, the parameters are pushed from right
17711 before the call the second leftmost parameter will be on the top of the
17712 stack (the leftmost parameter is passed in registers).
17713 Here is an example:
17716 \begin_layout Verse
17719 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17724 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
17733 return asm_func(i,j,k);
17747 return c_func(10,9,8);
17752 \begin_layout Standard
17753 The corresponding (unoptimized) assembler routine is:
17756 \begin_layout Verse
17776 _bp,sp\InsetSpace ~
17782 ;stack contains: _bp, return
17783 address, second parameter, third parameter
17807 a,#0xfd\InsetSpace ~
17813 pointer to the second parameter
17837 a,#0xfc\InsetSpace ~
17843 to the rightmost parameter
17884 result (= sum of all three parameters)
17899 ;return value goes into dptr
17933 \begin_layout Standard
17934 The compiling and linking procedure remains the same, however note the extra
17935 entry & exit linkage required for the assembler code, _bp is the stack
17936 frame pointer and is used to compute the offset into the stack for parameters
17937 and local variables.
17938 \begin_inset VSpace bigskip
17944 \begin_layout Section
17946 \begin_inset LatexCommand \index{int (16 bit)}
17951 \begin_inset LatexCommand \index{long (32 bit)}
17958 \begin_layout Standard
17959 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17960 multiplication and modulus operations are implemented by support routines.
17961 These support routines are all developed in ANSI-C to facilitate porting
17962 to other MCUs, although some model specific assembler optimizations are
17964 The following files contain the described routines, all of them can be
17965 found in <installdir>/share/sdcc/lib.
17970 \begin_layout Standard
17972 \begin_inset Tabular
17973 <lyxtabular version="3" rows="11" columns="2">
17975 <column alignment="left" valignment="top" leftline="true" width="0">
17976 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17977 <row topline="true" bottomline="true">
17978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17981 \begin_layout Standard
17989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17992 \begin_layout Standard
18001 <row topline="true">
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18005 \begin_layout Standard
18011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18014 \begin_layout Standard
18015 16 bit multiplication
18021 <row topline="true">
18022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18025 \begin_layout Standard
18031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18034 \begin_layout Standard
18035 signed 16 bit division (calls _divuint)
18041 <row topline="true">
18042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18045 \begin_layout Standard
18051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18054 \begin_layout Standard
18055 unsigned 16 bit division
18061 <row topline="true">
18062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18065 \begin_layout Standard
18071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18074 \begin_layout Standard
18075 signed 16 bit modulus (calls _moduint)
18081 <row topline="true">
18082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18085 \begin_layout Standard
18091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18094 \begin_layout Standard
18095 unsigned 16 bit modulus
18101 <row topline="true">
18102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18105 \begin_layout Standard
18111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18114 \begin_layout Standard
18115 32 bit multiplication
18121 <row topline="true">
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18125 \begin_layout Standard
18131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18134 \begin_layout Standard
18135 signed 32 division (calls _divulong)
18141 <row topline="true">
18142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18145 \begin_layout Standard
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18154 \begin_layout Standard
18155 unsigned 32 division
18161 <row topline="true">
18162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18165 \begin_layout Standard
18171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18174 \begin_layout Standard
18175 signed 32 bit modulus (calls _modulong)
18181 <row topline="true" bottomline="true">
18182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18185 \begin_layout Standard
18191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18194 \begin_layout Standard
18195 unsigned 32 bit modulus
18210 \begin_layout Standard
18211 Since they are compiled as
18216 \begin_inset LatexCommand \index{reentrant}
18221 \begin_inset LatexCommand \index{interrupt}
18225 service routines should not do any of the above operations.
18226 If this is unavoidable then the above routines will need to be compiled
18233 \begin_layout Standard
18243 \begin_inset LatexCommand \index{-\/-stack-auto}
18249 option, after which the source program will have to be compiled with
18255 \begin_layout Standard
18265 \begin_inset LatexCommand \index{-\/-int-long-reent}
18272 Notice that you don't have to call these routines directly.
18273 The compiler will use them automatically every time an integer operation
18277 \begin_layout Section
18278 Floating Point Support
18279 \begin_inset LatexCommand \index{Floating point support}
18286 \begin_layout Standard
18287 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18288 The floating point support routines are derived from gcc's floatlib.c and
18289 consist of the following routines:
18294 \begin_layout Standard
18298 \begin_inset Tabular
18299 <lyxtabular version="3" rows="17" columns="2">
18301 <column alignment="left" valignment="top" leftline="true" width="0">
18302 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18303 <row topline="true" bottomline="true">
18304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18307 \begin_layout Standard
18322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18325 \begin_layout Standard
18332 <row topline="true">
18333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18336 \begin_layout Standard
18351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18354 \begin_layout Standard
18364 add floating point numbers
18370 <row topline="true">
18371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18374 \begin_layout Standard
18389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18392 \begin_layout Standard
18402 subtract floating point numbers
18408 <row topline="true">
18409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18412 \begin_layout Standard
18427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18430 \begin_layout Standard
18440 divide floating point numbers
18446 <row topline="true">
18447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18450 \begin_layout Standard
18465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18468 \begin_layout Standard
18478 multiply floating point numbers
18484 <row topline="true">
18485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18488 \begin_layout Standard
18503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18506 \begin_layout Standard
18516 convert floating point to unsigned char
18522 <row topline="true">
18523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18526 \begin_layout Standard
18541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18544 \begin_layout Standard
18554 convert floating point to signed char
18560 <row topline="true">
18561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18564 \begin_layout Standard
18579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18582 \begin_layout Standard
18592 convert floating point to unsigned int
18598 <row topline="true">
18599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18602 \begin_layout Standard
18617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18620 \begin_layout Standard
18630 convert floating point to signed int
18636 <row topline="true">
18637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18640 \begin_layout Standard
18663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18666 \begin_layout Standard
18676 convert floating point to unsigned long
18682 <row topline="true">
18683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18686 \begin_layout Standard
18701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18704 \begin_layout Standard
18714 convert floating point to signed long
18720 <row topline="true">
18721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18724 \begin_layout Standard
18739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18742 \begin_layout Standard
18752 convert unsigned char to floating point
18758 <row topline="true">
18759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18762 \begin_layout Standard
18777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18780 \begin_layout Standard
18790 convert char to floating point number
18796 <row topline="true">
18797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18800 \begin_layout Standard
18815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18818 \begin_layout Standard
18828 convert unsigned int to floating point
18834 <row topline="true">
18835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18838 \begin_layout Standard
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18856 \begin_layout Standard
18866 convert int to floating point numbers
18872 <row topline="true">
18873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18876 \begin_layout Standard
18891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18894 \begin_layout Standard
18904 convert unsigned long to floating point number
18910 <row topline="true" bottomline="true">
18911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18914 \begin_layout Standard
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18932 \begin_layout Standard
18942 convert long to floating point number
18957 \begin_layout Standard
18958 These support routines are developed in ANSI-C so there is room for space
18959 and speed improvement
18963 \begin_layout Standard
18964 These floating point routines (
18968 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18975 Note if all these routines are used simultaneously the data space might
18977 For serious floating point usage the large model might be needed.
18978 Also notice that you don't have to call this routines directly.
18979 The compiler will use them automatically every time a floating point operation
18981 \begin_inset VSpace bigskip
18987 \begin_layout Section
18989 \begin_inset LatexCommand \index{Libraries}
18996 \begin_layout Standard
18999 <pending: this is messy and incomplete - a little more information is in
19000 sdcc/doc/libdoc.txt
19005 \begin_layout Subsection
19006 Compiler support routines (_gptrget, _mulint etc.)
19009 \begin_layout Subsection
19010 Stdclib functions (puts, printf, strcat etc.)
19013 \begin_layout Subsubsection
19017 \begin_layout Paragraph
19018 getchar(), putchar()
19021 \begin_layout Standard
19022 \begin_inset LatexCommand \index{<stdio.h>}
19026 As usual on embedded systems you have to provide your own
19029 \begin_inset LatexCommand \index{getchar()}
19038 \begin_inset LatexCommand \index{putchar()}
19045 SDCC does not know whether the system connects to a serial line with or
19046 without handshake, LCD, keyboard or other device.
19060 You'll find examples for serial routines f.e.
19061 in sdcc/device/lib.
19062 For the mcs51 this minimalistic polling
19066 routine might be a start:
19069 \begin_layout Verse
19072 void putchar (char c) {
19078 while (!TI)\InsetSpace ~
19081 /* assumes UART is initialized */
19109 \begin_layout Paragraph
19113 \begin_layout Standard
19117 \begin_inset LatexCommand \index{printf()}
19127 does not support float (except on ds390).
19128 To enable this recompile it with the option
19134 \begin_layout Standard
19144 \begin_inset LatexCommand \index{USE\_FLOATS}
19150 on the command line.
19157 \begin_layout Standard
19167 \begin_inset LatexCommand \index{-\/-model-large}
19173 for the mcs51 port, since this uses a lot of memory.
19176 \begin_layout Standard
19177 If you're short on code memory you might want to use
19180 \begin_inset LatexCommand \index{printf\_small()}
19195 For the mcs51 there additionally are assembly versions
19198 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19204 (subset of printf using less than 270 bytes) and
19207 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19216 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19222 (floating-point aware version of printf_fast) which should fit the requirements
19223 of many embedded systems (printf_fast() can be customized by unsetting
19228 support long variables and field widths).
19229 Be sure to use only one of these printf options within a project.
19234 \begin_layout Standard
19235 Feature matrix of different
19242 \begin_layout Standard
19243 \begin_inset Tabular
19244 <lyxtabular version="3" rows="14" columns="7">
19245 <features islongtable="true">
19246 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19247 <column alignment="center" valignment="top" leftline="true" width="0">
19248 <column alignment="center" valignment="top" leftline="true" width="12col%">
19249 <column alignment="center" valignment="top" leftline="true" width="10col%">
19250 <column alignment="center" valignment="top" leftline="true" width="0">
19251 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19252 <column alignment="center" valignment="top" rightline="true" width="0">
19253 <row topline="true" bottomline="true" endhead="true">
19254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19257 \begin_layout Standard
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19269 \begin_layout Standard
19271 \begin_inset LatexCommand \index{printf}
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19283 \begin_layout Standard
19291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19294 \begin_layout Standard
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19303 \begin_layout Standard
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19312 \begin_layout Standard
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19321 \begin_layout Standard
19328 <row topline="true" endhead="true">
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19332 \begin_layout Standard
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19341 \begin_layout Standard
19349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19352 \begin_layout Standard
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19363 \begin_layout Standard
19371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19374 \begin_layout Standard
19382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19385 \begin_layout Standard
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19396 \begin_layout Standard
19405 <row topline="true" endhead="true">
19406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19409 \begin_layout Standard
19410 \begin_inset Quotes sld
19414 \begin_inset Quotes srd
19420 \begin_layout Standard
19426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19429 \begin_layout Standard
19435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19438 \begin_layout Standard
19444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19447 \begin_layout Standard
19453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19456 \begin_layout Standard
19462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19465 \begin_layout Standard
19471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19474 \begin_layout Standard
19481 <row topline="true" endhead="true">
19482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19485 \begin_layout Standard
19489 \begin_layout Standard
19495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19498 \begin_layout Standard
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19507 \begin_layout Standard
19513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19516 \begin_layout Standard
19517 0.45k / 0.47k (+ _ltoa)
19522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19525 \begin_layout Standard
19531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19534 \begin_layout Standard
19540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19543 \begin_layout Standard
19550 <row topline="true">
19551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19554 \begin_layout Standard
19560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19563 \begin_layout Standard
19573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19576 \begin_layout Standard
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19626 \begin_layout Standard
19665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19668 \begin_layout Standard
19674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19677 \begin_layout Standard
19683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19686 \begin_layout Standard
19693 <row topline="true">
19694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19697 \begin_layout Standard
19698 long (32 bit) support
19703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19706 \begin_layout Standard
19712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19715 \begin_layout Standard
19721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19724 \begin_layout Standard
19730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19733 \begin_layout Standard
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19742 \begin_layout Standard
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19760 \begin_layout Standard
19767 <row topline="true">
19768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19771 \begin_layout Standard
19772 byte arguments on stack
19777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19780 \begin_layout Standard
19786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19789 \begin_layout Standard
19795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19798 \begin_layout Standard
19804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19807 \begin_layout Standard
19813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19816 \begin_layout Standard
19822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19825 \begin_layout Standard
19832 <row topline="true">
19833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19836 \begin_layout Standard
19838 \begin_inset LatexCommand \index{Floating point support}
19847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19850 \begin_layout Standard
19856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19859 \begin_layout Standard
19865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19868 \begin_layout Standard
19874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19877 \begin_layout Standard
19883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19886 \begin_layout Standard
19891 \begin_layout Standard
19892 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19905 \begin_layout Standard
19912 <row topline="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19916 \begin_layout Standard
19917 float formats %e %g
19922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19925 \begin_layout Standard
19931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19934 \begin_layout Standard
19940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19943 \begin_layout Standard
19949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19952 \begin_layout Standard
19958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19961 \begin_layout Standard
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19970 \begin_layout Standard
19977 <row topline="true" bottomline="true">
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19981 \begin_layout Standard
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19990 \begin_layout Standard
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19999 \begin_layout Standard
20005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 \begin_layout Standard
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20017 \begin_layout Standard
20023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20026 \begin_layout Standard
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20035 \begin_layout Standard
20042 <row bottomline="true">
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20046 \begin_layout Standard
20051 \begin_layout Standard
20052 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20056 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20064 \begin_layout Standard
20070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20073 \begin_layout Standard
20079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20082 \begin_layout Standard
20088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20091 \begin_layout Standard
20097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20100 \begin_layout Standard
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_layout Standard
20115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20118 \begin_layout Standard
20125 <row bottomline="true">
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20129 \begin_layout Standard
20134 \begin_layout Standard
20135 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
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" usebox="none">
20171 \begin_layout Standard
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20180 \begin_layout Standard
20186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20189 \begin_layout Standard
20195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20198 \begin_layout Standard
20203 \begin_layout Standard
20204 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20215 <row bottomline="true">
20216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20219 \begin_layout Standard
20224 \begin_layout Standard
20225 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20234 \begin_layout Standard
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20243 \begin_layout Standard
20249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20252 \begin_layout Standard
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20261 \begin_layout Standard
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20270 \begin_layout Standard
20276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20279 \begin_layout Standard
20285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20288 \begin_layout Standard
20295 <row bottomline="true">
20296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20299 \begin_layout Standard
20304 \begin_layout Standard
20305 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20314 \begin_layout Standard
20320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20323 \begin_layout Standard
20329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20332 \begin_layout Standard
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20341 \begin_layout Standard
20347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20350 \begin_layout Standard
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20359 \begin_layout Standard
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20368 \begin_layout Standard
20382 \begin_layout Subsubsection
20384 \begin_inset LatexCommand \index{malloc.h}
20391 \begin_layout Standard
20392 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20393 using dynamic memory allocation
20394 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20399 \begin_inset LatexCommand \index{heap (malloc)}
20403 space of 1024 bytes is provided for malloc to allocate memory from.
20404 If you need a different heap size you need to recompile _heap.c with the
20405 required size defined in HEAP_SIZE.
20406 It is recommended to make a copy of this file into your project directory
20407 and compile it there with:
20410 \begin_layout Verse
20413 sdcc -c _heap.c -D HEAD_SIZE=2048
20416 \begin_layout Standard
20417 And then link it with:
20420 \begin_layout Verse
20423 sdcc main.rel _heap.rel
20426 \begin_layout Subsection
20427 Math functions (sinf, powf, sqrtf etc.)
20430 \begin_layout Subsubsection
20434 \begin_layout Standard
20435 See definitions in file <math.h>.
20438 \begin_layout Subsection
20442 \begin_layout Standard
20444 \begin_inset LatexCommand \index{Libraries}
20448 included in SDCC should have a license at least as liberal as the GNU Lesser
20449 General Public License
20450 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20461 \begin_layout Standard
20462 \begin_inset Note Note
20465 \begin_layout Standard
20466 license statements for the libraries are missing.
20467 sdcc/device/lib/ser_ir.c
20470 \begin_layout Standard
20472 come with a GPL (as opposed to LGPL) License - this will not be liberal
20473 enough for many embedded programmers.
20481 \begin_layout Standard
20482 If you have ported some library or want to share experience about some code
20484 falls into any of these categories Busses (I
20485 \begin_inset Formula $^{\textrm{2}}$
20488 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20489 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20490 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20491 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20496 would certainly like to hear about it.
20499 \begin_layout Standard
20500 Programmers coding for embedded systems are not especially famous for being
20501 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20502 e these references are very valuable.
20503 Let's help to create a climate where information is shared.
20504 \begin_inset VSpace bigskip
20510 \begin_layout Section
20514 \begin_layout Subsection
20515 MCS51 Memory Models
20516 \begin_inset LatexCommand \index{Memory model}
20521 \begin_inset LatexCommand \index{MCS51 memory model}
20528 \begin_layout Subsubsection
20529 Small, Medium and Large
20532 \begin_layout Standard
20533 SDCC allows three memory models for MCS51 code,
20542 Modules compiled with different memory models should
20546 be combined together or the results would be unpredictable.
20547 The library routines supplied with the compiler are compiled as small,
20549 The compiled library modules are contained in separate directories as small,
20550 medium and large so that you can link to the appropriate set.
20553 \begin_layout Standard
20554 When the medium or large model is used all variables declared without a
20555 storage class will be allocated into the external ram, this includes all
20556 parameters and local variables (for non-reentrant
20557 \begin_inset LatexCommand \index{reentrant}
20562 When the small model is used variables without storage class are allocated
20563 in the internal ram.
20566 \begin_layout Standard
20567 Judicious usage of the processor specific storage classes
20568 \begin_inset LatexCommand \index{Storage class}
20572 and the 'reentrant' function type will yield much more efficient code,
20573 than using the large model.
20574 Several optimizations are disabled when the program is compiled using the
20575 large model, it is therefore recommended that the small model be used unless
20576 absolutely required.
20579 \begin_layout Subsubsection
20581 \begin_inset LatexCommand \label{sub:External-Stack}
20586 \begin_inset LatexCommand \index{stack}
20591 \begin_inset LatexCommand \index{External stack (mcs51)}
20598 \begin_layout Standard
20599 The external stack (-
20603 \begin_layout Standard
20613 \begin_inset LatexCommand \index{-\/-xstack}
20617 ) is located in pdata
20618 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20622 memory (usually at the start of the external ram segment) and uses all
20623 unused space in pdata (max.
20629 \begin_layout Standard
20638 -xstack option is used to compile the program, the parameters and local
20640 \begin_inset LatexCommand \index{local variables}
20644 of all reentrant functions are allocated in this area.
20645 This option is provided for programs with large stack space requirements.
20646 When used with the -
20650 \begin_layout Standard
20660 \begin_inset LatexCommand \index{-\/-stack-auto}
20664 option, all parameters and local variables are allocated on the external
20665 stack (note: support libraries will need to be recompiled with the same
20667 There is a predefined target in the library makefile).
20670 \begin_layout Standard
20671 The compiler outputs the higher order address byte of the external ram segment
20673 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20678 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20682 ), therefore when using the External Stack option, this port
20686 be used by the application program.
20689 \begin_layout Subsection
20691 \begin_inset LatexCommand \index{Memory model}
20696 \begin_inset LatexCommand \index{DS390 memory model}
20703 \begin_layout Standard
20704 The only model supported is Flat 24
20705 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20710 This generates code for the 24 bit contiguous addressing mode of the Dallas
20712 In this mode, up to four meg of external RAM or code space can be directly
20714 See the data sheets at www.dalsemi.com for further information on this part.
20719 that the compiler does not generate any code to place the processor into
20720 24 bitmode (although
20724 in the ds390 libraries will do that for you).
20730 \begin_inset LatexCommand \index{Tinibios (DS390)}
20734 , the boot loader or similar code must ensure that the processor is in 24
20735 bit contiguous addressing mode before calling the SDCC startup code.
20746 \begin_layout Standard
20757 option, variables will by default be placed into the XDATA segment.
20762 Segments may be placed anywhere in the 4 meg address space using the usual
20767 \begin_layout Standard
20777 Note that if any segments are located above 64K, the -r flag must be passed
20778 to the linker to generate the proper segment relocations, and the Intel
20779 HEX output format must be used.
20780 The -r flag can be passed to the linker by using the option
20784 on the SDCC command line.
20785 However, currently the linker can not handle code segments > 64k.
20788 \begin_layout Section
20790 \begin_inset LatexCommand \label{sec:Pragmas}
20795 \begin_inset LatexCommand \index{Pragmas}
20802 \begin_layout Standard
20803 Pragmas are used to turn on and/or off certain compiler options.
20804 Some of them are closely related to corresponding command-line options
20806 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20812 Pragmas should be placed before and/or after a function, placing pragmas
20813 inside a function body could have unpredictable results.
20818 following #pragma directives:
20821 \begin_layout Itemize
20827 \begin_inset LatexCommand \index{\#pragma save}
20831 - this will save most current options to the save/restore stack.
20832 See #pragma\InsetSpace ~
20836 \begin_layout Itemize
20842 \begin_inset LatexCommand \index{\#pragma restore}
20846 - will restore saved options from the last save.
20847 saves & restores can be nested.
20848 SDCC uses a save/restore stack: save pushes current options to the stack,
20849 restore pulls current options from the stack.
20850 See #pragma\InsetSpace ~
20856 \begin_layout Itemize
20862 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20867 \begin_inset LatexCommand \index{function prologue}
20871 function1[,function2[,function3...]]
20872 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20876 - The compiler by default uses a caller saves convention for register saving
20877 across function calls, however this can cause unnecessary register pushing
20879 \begin_inset LatexCommand \index{push/pop}
20883 when calling small functions from larger functions.
20884 This option can be used to switch off the register saving convention for
20885 the function names specified.
20886 The compiler will not save registers when calling these functions, extra
20887 code need to be manually inserted at the entry and exit for these functions
20888 to save and restore the registers used by these functions, this can SUBSTANTIAL
20889 LY reduce code and improve run time performance of the generated code.
20890 In the future the compiler (with inter procedural analysis) may be able
20891 to determine the appropriate scheme to use for each function call.
20896 \begin_layout Standard
20905 -callee-saves command line option is used (see page
20906 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20910 ), the function names specified in #pragma\InsetSpace ~
20912 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20916 is appended to the list of functions specified in the command line.
20919 \begin_layout Itemize
20925 \begin_inset LatexCommand \index{\#pragma exclude}
20929 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20930 of pairs of push/pop
20931 \begin_inset LatexCommand \index{push/pop}
20940 \begin_inset LatexCommand \index{interrupt}
20953 The directive should be placed immediately before the ISR function definition
20954 and it affects ALL ISR functions following it.
20955 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20956 exclude\InsetSpace ~
20958 \begin_inset LatexCommand \index{\#pragma exclude}
20963 See also the related keyword _naked
20964 \begin_inset LatexCommand \index{\_naked}
20969 \begin_inset LatexCommand \index{\_\_naked}
20976 \begin_layout Itemize
20982 \begin_inset LatexCommand \index{pedantic}
20987 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20992 \begin_inset LatexCommand \label{ite:less_pedantic}
20996 - the compiler will not warn you anymore for obvious mistakes, you'r on
20998 See also the command line option -
21002 \begin_layout Standard
21012 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21019 More specifically, the following warnings will be disabled:
21021 comparison is always [true/false] due to limited range of data type
21025 overflow in implicit constant conversion
21027 (158); [the (in)famous]
21029 conditional flow changed by optimizer: so said EVELYN the modified DOG
21033 function '[function name]' must return value
21038 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21039 level) are disabled, too, namely:
21042 \begin_inset Note Note
21045 \begin_layout Standard
21046 dunno what comes here - this warning appears to be unused altogether
21055 [left/right] shifting more than size of object changed to zero
21063 integer overflow in expression
21067 unmatched #pragma save and #pragma restore
21071 comparison of 'signed char' with 'unsigned char' requires promotion to int
21075 ISO C90 does not support flexible array members
21079 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21083 \begin_inset Note Note
21086 \begin_layout Standard
21087 appears to be always blank - what was supposed to be here?
21096 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21097 complexity [number]
21102 \begin_layout Itemize
21108 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21112 - the compiler will not warn you anymore about warning number <nnnn>.
21115 \begin_layout Itemize
21121 \begin_inset LatexCommand \index{\#pragma nogcse}
21125 - will stop global common subexpression elimination.
21128 \begin_layout Itemize
21134 \begin_inset LatexCommand \index{\#pragma noinduction}
21138 - will stop loop induction optimizations.
21141 \begin_layout Itemize
21147 \begin_inset LatexCommand \index{\#pragma noinvariant}
21151 - will not do loop invariant optimizations.
21152 For more details see Loop Invariants in section
21153 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21160 \begin_layout Itemize
21166 \begin_inset LatexCommand \index{\#pragma noiv}
21170 - Do not generate interrupt
21171 \begin_inset LatexCommand \index{interrupt}
21176 \begin_inset LatexCommand \index{interrupt vector table}
21180 entries for all ISR functions defined after the pragma.
21181 This is useful in cases where the interrupt vector table must be defined
21182 manually, or when there is a secondary, manually defined interrupt vector
21184 for the autovector feature of the Cypress EZ-USB FX2).
21185 More elegantly this can be achieved by obmitting the optional interrupt
21186 number after the interrupt keyword, see section
21187 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21195 \begin_layout Itemize
21201 \begin_inset LatexCommand \index{\#pragma nojtbound}
21205 - will not generate code for boundary value checking, when switch statements
21206 are turned into jump-tables (dangerous).
21207 For more details see section
21208 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21215 \begin_layout Itemize
21221 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21225 - Will not do loop reversal optimization
21228 \begin_layout Itemize
21234 \begin_inset LatexCommand \index{\#pragma nooverlay}
21238 - the compiler will not overlay the parameters and local variables of a
21242 \begin_layout Itemize
21248 \begin_inset LatexCommand \index{\#pragma stackauto}
21256 \begin_layout Standard
21266 \begin_inset LatexCommand \index{-\/-stack-auto}
21271 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21275 Parameters and Local Variables.
21278 \begin_layout Itemize
21284 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21288 - The compiler will optimize code generation towards fast code, possibly
21289 at the expense of code size.
21290 Currently this has little effect.
21293 \begin_layout Itemize
21299 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21303 - The compiler will optimize code generation towards compact code, possibly
21304 at the expense of code speed.
21305 Currently this has little effect.
21308 \begin_layout Itemize
21314 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21318 - The compiler will attempt to generate code that is both compact and fast,
21319 as long as meeting one goal is not a detriment to the other (this is the
21324 \begin_layout Itemize
21330 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21334 - Generally follow the C89 standard, but allow SDCC features that conflict
21335 with the standard (default).
21338 \begin_layout Itemize
21344 \begin_inset LatexCommand \index{\#pragma std\_c89}
21348 - Follow the C89 standard and disable SDCC features that conflict with the
21352 \begin_layout Itemize
21358 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21362 - Generally follow the C99 standard, but allow SDCC features that conflict
21363 with the standard (incomplete support).
21366 \begin_layout Itemize
21372 \begin_inset LatexCommand \index{\#pragma std\_c99}
21376 - Follow the C99 standard and disable SDCC features that conflict with the
21377 standard (incomplete support).
21380 \begin_layout Itemize
21386 \begin_inset LatexCommand \index{\#pragma codeseg}
21390 - Use this name (max.
21391 8 characters) for the code segment.
21396 \begin_layout Standard
21408 \begin_layout Itemize
21414 \begin_inset LatexCommand \index{\#pragma constseg}
21418 - Use this name (max.
21419 8 characters) for the const segment.
21424 \begin_layout Standard
21436 \begin_layout Standard
21437 The preprocessor SDCPP
21438 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21442 supports the following #pragma directives:
21445 \begin_layout Itemize
21448 pedantic_parse_number
21451 \begin_inset LatexCommand \index{pedantic}
21456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21461 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21465 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21466 properly and the macro LO_B(3) gets expanded.
21472 \begin_layout Standard
21481 -pedantic-parse-number command line option
21482 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21489 Below is an example on how to use this pragma.
21492 Note: this functionality is not in conformance with standard!
21495 \begin_layout Verse
21498 #pragma pedantic_parse_number +
21499 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21507 #define LO_B(x) ((x) & 0xff)
21511 unsigned char foo(void)
21518 unsigned char c=0xfe-LO_B(3)
21533 \begin_layout Itemize
21539 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21543 (+ | -) - switch _asm _endasm block preprocessing on / off.
21545 You use this prama to define multilines of assembly code.
21546 This will prevent the preprocessor from changing the formating required
21548 Below is an example on how to use this pragma.
21551 \begin_layout Verse
21554 #pragma preproc_asm -
21555 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21561 #define MYDELAY _asm
21566 nop ;my assembly comment...
21580 #pragma preproc_asm
21611 \begin_layout Itemize
21617 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21621 (+ | -) - Allow "naked" hash in macro definition, for example:
21625 #define DIR_LO(x) #(x & 0xff)
21630 Below is an example on how to use this pragma.
21633 \begin_layout Verse
21636 #pragma preproc_asm +
21638 #pragma sdcc_hash +
21639 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21654 mov R6_B3, #(x & 0xff)
21661 mov R7_B3, #((x >> 8) & 0xff)
21685 \begin_layout Standard
21686 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21687 ons which might cause the compiler to generate extra stack and/or data space
21688 to store compiler generated temporary variables.
21689 This usually happens in large functions.
21690 Pragma directives should be used as shown in the following example, they
21691 are used to control options and optimizations for a given function.
21695 \begin_layout Verse
21699 \begin_inset LatexCommand \index{\#pragma save}
21710 /* save the current settings */
21713 \begin_inset LatexCommand \index{\#pragma nogcse}
21722 /* turnoff global subexpression elimination */
21724 #pragma noinduction
21725 \begin_inset LatexCommand \index{\#pragma noinduction}
21729 /* turn off induction optimizations */
21752 \begin_inset LatexCommand \index{\#pragma restore}
21756 /* turn the optimizations back on */
21759 \begin_layout Standard
21760 The compiler will generate a warning message when extra space is allocated.
21761 It is strongly recommended that the save and restore pragma's be used when
21762 changing options for a function.
21771 \begin_layout Section
21772 Defines Created by the Compiler
21775 \begin_layout Standard
21776 The compiler creates the following #defines
21777 \begin_inset LatexCommand \index{\#defines}
21782 \begin_inset LatexCommand \index{Defines created by the compiler}
21791 \begin_layout Standard
21792 \begin_inset Tabular
21793 <lyxtabular version="3" rows="11" columns="2">
21795 <column alignment="left" valignment="top" leftline="true" width="3in">
21796 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21797 <row topline="true" bottomline="true">
21798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21801 \begin_layout Standard
21809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21812 \begin_layout Standard
21821 <row topline="true">
21822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21825 \begin_layout Standard
21827 \begin_inset LatexCommand \index{SDCC}
21836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21839 \begin_layout Standard
21841 Since version 2.5.6 the version number as an int (ex.
21848 <row topline="true">
21849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21852 \begin_layout Standard
21854 \begin_inset LatexCommand \index{SDCC\_mcs51}
21859 \begin_inset LatexCommand \index{SDCC\_ds390}
21864 \begin_inset LatexCommand \index{SDCC\_z80}
21873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21876 \begin_layout Standard
21877 depending on the model used (e.g.: -mds390)
21883 <row topline="true">
21884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21887 \begin_layout Standard
21889 \begin_inset LatexCommand \index{\_\_mcs51}
21894 \begin_inset LatexCommand \index{\_\_ds390}
21899 \begin_inset LatexCommand \index{\_\_hc08}
21904 \begin_inset LatexCommand \index{\_\_z80}
21913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21916 \begin_layout Standard
21917 depending on the model used (e.g.
21924 <row topline="true">
21925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21928 \begin_layout Standard
21930 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21942 \begin_layout Standard
21949 \begin_layout Standard
21966 <row topline="true">
21967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21970 \begin_layout Standard
21972 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21984 \begin_layout Standard
21991 \begin_layout Standard
22008 <row topline="true">
22009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22012 \begin_layout Standard
22014 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22026 \begin_layout Standard
22033 \begin_layout Standard
22050 <row topline="true">
22051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22054 \begin_layout Standard
22056 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22068 \begin_layout Standard
22075 \begin_layout Standard
22092 <row topline="true">
22093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22096 \begin_layout Standard
22098 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22110 \begin_layout Standard
22117 \begin_layout Standard
22134 <row topline="true">
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22138 \begin_layout Standard
22140 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22152 \begin_layout Standard
22163 <row topline="true" bottomline="true">
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22167 \begin_layout Standard
22169 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22181 \begin_layout Standard
22199 \begin_layout Chapter
22200 Notes on supported Processors
22203 \begin_layout Section
22205 \begin_inset LatexCommand \label{sub:MCS51-variants}
22210 \begin_inset LatexCommand \index{MCS51 variants}
22217 \begin_layout Standard
22218 MCS51 processors are available from many vendors and come in many different
22220 While they might differ considerably in respect to Special Function Registers
22221 the core MCS51 is usually not modified or is kept compatible.
22225 \begin_layout Subsection
22226 pdata access by SFR
22229 \begin_layout Standard
22230 With the upcome of devices with internal xdata and flash memory devices
22232 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22236 as dedicated I/O port is becoming more popular.
22237 Switching the high byte for pdata
22238 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22242 access which was formerly done by port P2 is then achieved by a Special
22244 \begin_inset LatexCommand \index{sfr}
22249 In well-established MCS51 tradition the address of this
22253 is where the chip designers decided to put it.
22254 Needless to say that they didn't agree on a common name either.
22255 So that the startup code can correctly initialize xdata variables, you
22256 should define an sfr with the name _XPAGE
22259 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22265 at the appropriate location if the default, port P2, is not used for this.
22269 \begin_layout Verse
22272 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22276 \begin_layout Verse
22279 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22284 \begin_layout Verse
22287 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22291 \begin_layout Verse
22294 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22298 \begin_layout Verse
22301 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22305 \begin_layout Standard
22306 For more exotic implementations further customizations may be needed.
22308 \begin_inset LatexCommand \ref{sub:Startup-Code}
22312 for other possibilities.
22315 \begin_layout Subsection
22316 Other Features available by SFR
22319 \begin_layout Standard
22320 Some MCS51 variants offer features like Double DPTR
22321 \begin_inset LatexCommand \index{DPTR}
22325 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22326 These are currently not used for the MCS51 port.
22327 If you absolutely need them you can fall back to inline assembly or submit
22329 \begin_inset VSpace bigskip
22335 \begin_layout Section
22339 \begin_layout Standard
22341 \begin_inset LatexCommand \index{DS80C400}
22346 \begin_inset LatexCommand \index{DS400}
22350 microcontroller has a rich set of peripherals.
22351 In its built-in ROM library it includes functions to access some of the
22352 features, among them is a TCP stack with IP4 and IP6 support.
22353 Library headers (currently in beta status) and other files are provided
22357 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22363 \begin_inset VSpace bigskip
22369 \begin_layout Section
22370 The Z80 and gbz80 port
22373 \begin_layout Standard
22374 SDCC can target both the Zilog Z80
22375 \begin_inset LatexCommand \index{Z80}
22379 and the Nintendo Gameboy's Z80-like gbz80
22380 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22385 The Z80 port is passed through the same
22388 \begin_inset LatexCommand \index{Regression test}
22395 \begin_inset LatexCommand \ref{sec:Quality-control}
22399 ) as the MCS51 and DS390 ports, so floating point support, support for long
22400 variables and bitfield support is fine.
22401 See mailing lists and forums about interrupt routines.
22404 \begin_layout Standard
22405 As always, the code is the authoritative reference - see z80/ralloc.c and
22408 \begin_inset LatexCommand \index{Z80!stack}
22412 frame is similar to that generated by the IAR Z80 compiler.
22413 IX is used as the base pointer, HL and IY are used as a temporary registers,
22414 and BC and DE are available for holding variables.
22416 \begin_inset LatexCommand \index{Z80!return value}
22420 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22422 The gbz80 port use the same set of registers for the return values, but
22423 in a different order of significance: E (one byte), DE (two bytes), or
22425 \begin_inset VSpace bigskip
22431 \begin_layout Section
22435 \begin_layout Standard
22436 The port to the Freescale/Motorola HC08
22437 \begin_inset LatexCommand \index{HC08}
22441 family has been added in October 2003, and is still undergoing some basic
22443 The code generator is complete, but the register allocation is still quite
22445 Some of the SDCC's standard C library functions have embedded non-HC08
22446 inline assembly and so are not yet usable.
22449 \begin_layout Standard
22450 The HC08 port passes the regression test suite (see section
22451 \begin_inset LatexCommand \ref{sec:Quality-control}
22456 \begin_inset VSpace bigskip
22464 \begin_layout Section
22468 \begin_layout Standard
22470 \begin_inset LatexCommand \index{PIC14}
22474 port still requires a major effort from the development community.
22475 However it can work for simple code.
22476 It passes its (smaller set of) regression tests
22477 \begin_inset LatexCommand \index{Regression test (PIC14)}
22483 sdcc/src/regression
22488 \begin_layout Subsection
22489 C code and 14bit PIC code page
22490 \begin_inset LatexCommand \index{code page (pic14)}
22495 \begin_inset LatexCommand \index{RAM bank (pic14)}
22502 \begin_layout Standard
22503 The linker organizes allocation for the code page and RAM banks.
22504 It does not have intimate knowledge of the code flow.
22505 It will put all the code section of a single asm file into a single code
22507 In order to make use of multiple code pages, separate asm files must be
22509 The compiler treats all functions of a single C file as being in the same
22510 code page unless it is non static.
22514 To get the best follow these guide lines:
22517 \begin_layout Enumerate
22518 Make local functions static, as non static functions require code page selection
22522 \begin_layout Enumerate
22523 For devices that have multiple code pages it is more efficient to use the
22524 same number of files as pages, i.e.
22525 for the 16F877 use 4 separate files and i.e.
22526 for the 16F874 use 2 separate files.
22527 This way the linker can put the code for each file into different code
22528 pages and there's less page selection overhead.
22531 \begin_layout Enumerate
22532 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22533 instruction set), use 'unsigned char' whereever possible instead of 'int'.
22536 \begin_layout Subsection
22537 Creating a device include file
22540 \begin_layout Standard
22541 For generating a device include file
22542 \begin_inset LatexCommand \index{PIC14!Header files}
22546 use the support perl script inc2h.pl kept in directory support/script.
22549 \begin_layout Subsection
22553 \begin_layout Standard
22554 For the interrupt function, use the keyword '__interrupt'
22555 \begin_inset LatexCommand \index{PIC14!interrupt}
22559 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22560 there to avoid a syntax error - it ought to be fixed).
22564 \begin_layout Verse
22567 void Intr(void) __interrupt 0
22573 T0IF = 0; /* Clear timer interrupt */
22578 \begin_layout Subsection
22579 Linking and assembling
22582 \begin_layout Standard
22583 For assembling you can use either GPUTILS'
22584 \begin_inset LatexCommand \index{gputils (pic tools)}
22588 gpasm.exe or MPLAB's mpasmwin.exe.
22589 GPUTILS is available from
22590 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22595 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22596 If you use MPLAB and an interrupt function then the linker script file
22597 vectors section will need to be enlarged to link with mplink.
22608 \begin_layout Verse
22621 sdcc -S -V -mpic14 -p16F877 $<
22635 $(PRJ).hex: $(OBJS)
22646 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22649 \begin_layout Standard
22657 \begin_layout Verse
22670 sdcc -S -V -mpic14 -p16F877 $<
22680 mpasmwin /q /o $*.asm
22684 $(PRJ).hex: $(OBJS)
22695 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22698 \begin_layout Standard
22699 Please note that indentations within a
22703 have to be done with a tabulator character.
22706 \begin_layout Subsection
22707 Command-line options
22710 \begin_layout Standard
22711 Besides the switches common to all SDCC backends, the PIC14 port accepts
22712 the following options (for an updated list see sdcc -
22716 \begin_layout Standard
22729 \labelwidthstring 00.00.0000
22734 \begin_layout Standard
22744 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22748 emit debug info in assembly output
22752 \labelwidthstring 00.00.0000
22757 \begin_layout Standard
22767 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22771 disable (slightly faulty) optimization on pCode
22775 \labelwidthstring 00.00.0000
22780 \begin_layout Standard
22790 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22794 sets the lowest address of the argument passing stack (defaults to a suitably
22795 large shared databank to reduce BANKSEL overhead)
22799 \labelwidthstring 00.00.0000
22804 \begin_layout Standard
22814 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22818 sets the size if the argument passing stack (default: 16, minimum: 4)
22821 \begin_layout Subsection
22825 \begin_layout Subsubsection
22826 error: missing definition for symbol
22827 \begin_inset Quotes sld
22831 \begin_inset Quotes srd
22837 \begin_layout Standard
22838 The PIC14 port uses library routines to provide more complex operations
22839 like multiplication, division/modulus and (generic) pointer dereferencing.
22840 In order to add these routines to your project, you must link with PIC14's
22846 For single source file projects this is done automatically, more complex
22851 to the linker's arguments.
22852 Make sure you also add an include path for the library (using the -I switch
22856 \begin_layout Subsubsection
22857 Processor mismatch in file
22858 \begin_inset Quotes sld
22862 \begin_inset Quotes srd
22868 \begin_layout Standard
22869 This warning can usually be ignored due to the very good compatibility amongst
22871 \begin_inset LatexCommand \index{PIC14}
22878 \begin_layout Standard
22879 You might also consider recompiling the library for your specific device
22880 by changing the ARCH=p16f877 (default target) entry in
22882 device/lib/pic/Makefile.in
22886 device/lib/pic/Makefile
22888 to reflect your device.
22889 This might even improve performance for smaller devices as unneccesary
22890 BANKSELs migth be removed.
22893 \begin_layout Subsection
22897 \begin_layout Subsubsection
22901 \begin_layout Standard
22902 Currently, data can only be initialized if it resides in the source file
22908 Data in other source files will silently
22916 \begin_inset Marginal
22919 \begin_layout Standard
22935 \begin_layout Section
22937 \begin_inset LatexCommand \index{PIC16}
22944 \begin_layout Standard
22946 \begin_inset LatexCommand \index{PIC16}
22950 port is the portion of SDCC that is responsible to produce code for the
22952 \begin_inset LatexCommand \index{Microchip}
22956 (TM) microcontrollers with 16 bit core.
22957 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22958 Currently supported devices are:
22961 \begin_layout Standard
22963 \begin_inset Tabular
22964 <lyxtabular version="3" rows="4" columns="6">
22966 <column alignment="center" valignment="top" leftline="true" width="0">
22967 <column alignment="center" valignment="top" leftline="true" width="0">
22968 <column alignment="center" valignment="top" leftline="true" width="0">
22969 <column alignment="center" valignment="top" leftline="true" width="0">
22970 <column alignment="center" valignment="top" leftline="true" width="0">
22971 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22972 <row topline="true">
22973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22976 \begin_layout Standard
22982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22985 \begin_layout Standard
22991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22994 \begin_layout Standard
23000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23003 \begin_layout Standard
23009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23012 \begin_layout Standard
23018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23021 \begin_layout Standard
23028 <row topline="true">
23029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23032 \begin_layout Standard
23038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23041 \begin_layout Standard
23047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23050 \begin_layout Standard
23056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23059 \begin_layout Standard
23065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23068 \begin_layout Standard
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23077 \begin_layout Standard
23084 <row topline="true">
23085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23088 \begin_layout Standard
23094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23097 \begin_layout Standard
23103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23106 \begin_layout Standard
23112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23115 \begin_layout Standard
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23124 \begin_layout Standard
23130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23133 \begin_layout Standard
23140 <row topline="true" bottomline="true">
23141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23144 \begin_layout Standard
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23153 \begin_layout Standard
23159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23162 \begin_layout Standard
23168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23171 \begin_layout Standard
23177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23180 \begin_layout Standard
23186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23189 \begin_layout Standard
23203 \begin_layout Subsection
23207 \begin_layout Standard
23208 PIC16 port supports the standard command line arguments as supposed, with
23209 the exception of certain cases that will be mentioned in the following
23214 \labelwidthstring 00.00.0000
23219 \begin_layout Standard
23229 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23237 \begin_layout Standard
23250 \labelwidthstring 00.00.0000
23255 \begin_layout Standard
23264 -fommit-frame-pointer
23265 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23269 Frame pointer will be omitted when the function uses no local variables.
23272 \begin_layout Subsection
23273 Port Specific Options
23274 \begin_inset LatexCommand \index{Options PIC16}
23281 \begin_layout Standard
23282 The port specific options appear after the global options in the sdcc --help
23286 \begin_layout Subsubsection
23290 \begin_layout Standard
23291 General options enable certain port features and optimizations.
23295 \labelwidthstring 00.00.0000
23300 \begin_layout Standard
23309 -pstack-model=[model] Used in conjuction with the command above.
23310 Defines the stack model to be used, valid stack models are :
23315 \labelwidthstring 00.00.0000
23320 Selects small stack model.
23321 8 bit stack and frame pointers.
23322 Supports 256 bytes stack size.
23326 \labelwidthstring 00.00.0000
23331 Selects large stack model.
23332 16 bit stack and frame pointers.
23333 Supports 65536 bytes stack size.
23338 \labelwidthstring 00.00.0000
23343 \begin_layout Standard
23352 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23353 unitialized data variables with [kword].
23354 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23358 \labelwidthstring 00.00.0000
23363 \begin_layout Standard
23372 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23373 Useful for bootloaders.
23377 \labelwidthstring 00.00.0000
23382 \begin_layout Standard
23391 -asm= sets the full path and name of an external assembler to call.
23395 \labelwidthstring 00.00.0000
23400 \begin_layout Standard
23409 -link= sets the full path and name of an external linker to call.
23413 \labelwidthstring 00.00.0000
23418 \begin_layout Standard
23428 \begin_inset LatexCommand \index{PIC16!MPLAB}
23432 compatibility option.
23433 Currently only suppresses special gpasm directives.
23436 \begin_layout Subsubsection
23437 Optimization Options
23441 \labelwidthstring 00.00.0000
23446 \begin_layout Standard
23455 -optimize-goto Try to use (conditional) BRA instead of GOTO
23459 \labelwidthstring 00.00.0000
23464 \begin_layout Standard
23473 -optimize-cmp Try to optimize some compares.
23477 \labelwidthstring 00.00.0000
23482 \begin_layout Standard
23491 -optimize-df Analyze the dataflow of the generated code and improve it.
23495 \labelwidthstring 00.00.0000
23500 \begin_layout Standard
23509 -obanksel=nn Set optimization level for inserting BANKSELs.
23516 \labelwidthstring 00.00.0000
23521 \labelwidthstring 00.00.0000
23522 1 checks previous used register and if it is the same then does not emit
23523 BANKSEL, accounts only for labels.
23527 \labelwidthstring 00.00.0000
23528 2 tries to check the location of (even different) symbols and removes BANKSELs
23529 if they are in the same bank.
23534 Important: There might be problems if the linker script has data sections
23535 across bank borders!
23539 \begin_layout Subsubsection
23544 \labelwidthstring 00.00.0000
23549 \begin_layout Standard
23558 -nodefaultlibs do not link default libraries when linking
23562 \labelwidthstring 00.00.0000
23567 \begin_layout Standard
23576 -no-crt Don't link the default run-time modules
23580 \labelwidthstring 00.00.0000
23585 \begin_layout Standard
23594 -use-crt= Use a custom run-time module instead of the defaults.
23597 \begin_layout Subsubsection
23601 \begin_layout Standard
23602 Debugging options enable extra debugging information in the output files.
23606 \labelwidthstring 00.00.0000
23611 \begin_layout Standard
23620 -debug-xtra Similar to -
23624 \begin_layout Standard
23634 \begin_inset LatexCommand \index{-\/-debug}
23638 , but dumps more information.
23642 \labelwidthstring 00.00.0000
23647 \begin_layout Standard
23656 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23658 <source> is the name of the file compiled.
23662 \labelwidthstring 00.00.0000
23667 \begin_layout Standard
23676 -pcode-verbose Enable pcode debugging information in translation.
23680 \labelwidthstring 00.00.0000
23685 \begin_layout Standard
23694 -denable-peeps Force the usage of peepholes.
23699 \labelwidthstring 00.00.0000
23704 \begin_layout Standard
23713 -gstack Trace push/pops for stack pointer overflow
23717 \labelwidthstring 00.00.0000
23722 \begin_layout Standard
23731 -call-tree dump call tree in .calltree file
23734 \begin_layout Subsection
23735 Enviromental Variables
23738 \begin_layout Standard
23739 There is a number of enviromental variables that can be used when running
23740 SDCC to enable certain optimizations or force a specific program behaviour.
23741 these variables are primarily for debugging purposes so they can be enabled/dis
23745 \begin_layout Standard
23746 Currently there is only two such variables available:
23750 \labelwidthstring 00.00.0000
23751 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23752 bitfields is optimized by directly loading FSR0 with the address of the
23753 bitfield structure.
23754 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23756 This step saves data ram and code space for functions that perform heavy
23759 80 bytes of code space are saved when compiling malloc.c with this option).
23764 \labelwidthstring 00.00.0000
23765 NO_REG_OPT do not perform pCode registers optimization.
23766 This should be used for debugging purposes.
23767 In some where bugs in the pcode optimizer are found, users can benefit
23768 from temporarily disabling the optimizer until the bug is fixed.
23771 \begin_layout Subsection
23772 Preprocessor Macros
23775 \begin_layout Standard
23777 \begin_inset LatexCommand \index{PIC16}
23781 port defines the following preprocessor macros while translating a source.
23784 \begin_layout Standard
23786 \begin_inset Tabular
23787 <lyxtabular version="3" rows="6" columns="2">
23789 <column alignment="center" valignment="top" leftline="true" width="0">
23790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23791 <row topline="true" bottomline="true">
23792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23795 \begin_layout Standard
23801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23804 \begin_layout Standard
23811 <row topline="true">
23812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23815 \begin_layout Standard
23821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23824 \begin_layout Standard
23825 Port identification
23831 <row topline="true">
23832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23835 \begin_layout Standard
23840 \begin_layout Standard
23854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23857 \begin_layout Standard
23858 Port identification (same as above)
23864 <row topline="true">
23865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23868 \begin_layout Standard
23874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23877 \begin_layout Standard
23878 MCU Identification.
23883 is the microcontrol identification number, i.e.
23890 <row topline="true">
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23894 \begin_layout Standard
23899 \begin_layout Standard
23913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23916 \begin_layout Standard
23917 MCU Identification (same as above)
23923 <row topline="true" bottomline="true">
23924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23927 \begin_layout Standard
23933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23936 \begin_layout Standard
23937 nnn = SMALL or LARGE respectively according to the stack model used
23950 \begin_layout Standard
23951 In addition the following macros are defined when calling assembler:
23954 \begin_layout Standard
23956 \begin_inset Tabular
23957 <lyxtabular version="3" rows="4" columns="2">
23959 <column alignment="center" valignment="top" leftline="true" width="0">
23960 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23961 <row topline="true" bottomline="true">
23962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23965 \begin_layout Standard
23971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23974 \begin_layout Standard
23981 <row topline="true">
23982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23985 \begin_layout Standard
23991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23994 \begin_layout Standard
23995 MCU Identification.
24000 is the microcontrol identification number, i.e.
24007 <row topline="true">
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24011 \begin_layout Standard
24017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24020 \begin_layout Standard
24021 nnn = SMALL or LARGE respectively according to the memory model used for
24028 <row topline="true" bottomline="true">
24029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24032 \begin_layout Standard
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24041 \begin_layout Standard
24042 nnn = SMALL or LARGE respectively according to the stack model used
24055 \begin_layout Subsection
24059 \begin_layout Standard
24061 \begin_inset LatexCommand \index{PIC16}
24065 port uses the following directories for searching header files and libraries.
24068 \begin_layout Standard
24070 \begin_inset Tabular
24071 <lyxtabular version="3" rows="3" columns="4">
24073 <column alignment="center" valignment="top" leftline="true" width="0">
24074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24075 <column alignment="center" valignment="top" width="0">
24076 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24077 <row topline="true" bottomline="true">
24078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24081 \begin_layout Standard
24087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24090 \begin_layout Standard
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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
24120 PREFIX/sdcc/include/pic16
24125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24128 \begin_layout Standard
24129 PIC16 specific headers
24134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24137 \begin_layout Standard
24143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24146 \begin_layout Standard
24153 <row topline="true" bottomline="true">
24154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24157 \begin_layout Standard
24158 PREFIX/sdcc/lib/pic16
24163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24166 \begin_layout Standard
24167 PIC16 specific libraries
24172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24175 \begin_layout Standard
24181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24184 \begin_layout Standard
24198 \begin_layout Subsection
24200 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24207 \begin_layout Standard
24209 \begin_inset LatexCommand \index{PIC16}
24213 port currently supports the following pragmas:
24217 \labelwidthstring 00.00.0000
24219 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24224 \begin_inset LatexCommand \index{PIC16!stack}
24228 forces the code generator to initialize the stack & frame pointers at a
24230 This is an adhoc solution for cases where no STACK directive is available
24231 in the linker script or gplink is not instructed to create a stack section.
24234 stack pragma should be used only once in a project.
24235 Multiple pragmas may result in indeterminate behaviour of the program.
24239 \begin_layout Standard
24240 The old format (ie.
24241 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24242 cross page boundaries (or even exceed the available data RAM) and crash
24244 Make sure that stack does not cross page boundaries when using the SMALL
24252 The format is as follows:
24255 \begin_layout LyX-Code
24256 #pragma stack bottom_address [stack_size]
24259 \begin_layout Standard
24264 is the lower bound of the stack section.
24265 The stack pointer initially will point at address (bottom_address+stack_size-1).
24268 \begin_layout LyX-Code
24272 \begin_layout LyX-Code
24276 \begin_layout LyX-Code
24277 /* initializes stack of 100 bytes at RAM address 0x200 */
24280 \begin_layout LyX-Code
24281 #pragma stack 0x200 100
24284 \begin_layout Standard
24285 If the stack_size field is omitted then a stack is created with the default
24287 This size might be enough for most programs, but its not enough for operations
24288 with deep function nesting or excessive stack usage.
24292 \labelwidthstring 00.00.0000
24294 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24298 place a function symbol at static FLASH address
24301 \begin_layout LyX-Code
24305 \begin_layout LyX-Code
24309 \begin_layout LyX-Code
24310 /* place function test_func at 0x4000 */
24313 \begin_layout LyX-Code
24314 #pragma code test_func 0x4000
24317 \begin_layout LyX-Code
24322 \labelwidthstring 00.00.0000
24323 library instructs the linker to use a library module.
24328 \begin_layout LyX-Code
24329 #pragma library module_name
24332 \begin_layout Standard
24337 can be any library or object file (including its path).
24338 Note that there are four reserved keywords which have special meaning.
24342 \begin_layout Standard
24344 \begin_inset Tabular
24345 <lyxtabular version="3" rows="6" columns="3">
24347 <column alignment="center" valignment="top" leftline="true" width="0">
24348 <column alignment="block" valignment="top" leftline="true" width="20page%">
24349 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24350 <row topline="true" bottomline="true">
24351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24354 \begin_layout Standard
24360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24363 \begin_layout Standard
24369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24372 \begin_layout Standard
24379 <row topline="true">
24380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24383 \begin_layout Standard
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24394 \begin_layout Standard
24395 ignore all library pragmas
24400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24403 \begin_layout Standard
24412 <row topline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24416 \begin_layout Standard
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24427 \begin_layout Standard
24433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24436 \begin_layout Standard
24447 <row topline="true">
24448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24451 \begin_layout Standard
24459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24462 \begin_layout Standard
24463 link the Math libarary
24468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24471 \begin_layout Standard
24482 <row topline="true">
24483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24486 \begin_layout Standard
24494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24497 \begin_layout Standard
24498 link the I/O library
24503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24506 \begin_layout Standard
24517 <row topline="true" bottomline="true">
24518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24521 \begin_layout Standard
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24532 \begin_layout Standard
24533 link the debug library
24538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24541 \begin_layout Standard
24558 * is the device number, i.e.
24559 452 for PIC18F452 MCU.
24562 \begin_layout Standard
24563 This feature allows for linking with specific libraries withoug having to
24564 explicit name them in the command line.
24569 keyword will reject all modules specified by the library pragma.
24573 \labelwidthstring 00.00.0000
24574 udata pragma udata instructs the compiler to emit code so that linker will
24575 place a variable at a specific memory bank
24578 \begin_layout LyX-Code
24582 \begin_layout LyX-Code
24586 \begin_layout LyX-Code
24587 /* places variable foo at bank2 */
24590 \begin_layout LyX-Code
24591 #pragma udata bank2 foo
24594 \begin_layout LyX-Code
24598 \begin_layout Standard
24599 In order for this pragma to work extra SECTION directives should be added
24600 in the .lkr script.
24601 In the following example a sample .lkr file is shown:
24604 \begin_layout LyX-Code
24608 \begin_layout LyX-Code
24609 // Sample linker script for the PIC18F452 processor
24612 \begin_layout LyX-Code
24616 \begin_layout LyX-Code
24617 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24620 \begin_layout LyX-Code
24621 CODEPAGE NAME=page START=0x2A END=0x7FFF
24624 \begin_layout LyX-Code
24625 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24628 \begin_layout LyX-Code
24629 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24632 \begin_layout LyX-Code
24633 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24636 \begin_layout LyX-Code
24637 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24640 \begin_layout LyX-Code
24641 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24644 \begin_layout LyX-Code
24648 \begin_layout LyX-Code
24649 DATABANK NAME=gpr0 START=0x80 END=0xFF
24652 \begin_layout LyX-Code
24653 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24656 \begin_layout LyX-Code
24657 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24660 \begin_layout LyX-Code
24661 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24664 \begin_layout LyX-Code
24665 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24668 \begin_layout LyX-Code
24669 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24672 \begin_layout LyX-Code
24673 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24676 \begin_layout LyX-Code
24680 \begin_layout LyX-Code
24681 SECTION NAME=CONFIG ROM=config
24684 \begin_layout LyX-Code
24688 \begin_layout LyX-Code
24689 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24692 \begin_layout LyX-Code
24693 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24696 \begin_layout LyX-Code
24697 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24700 \begin_layout LyX-Code
24701 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24704 \begin_layout LyX-Code
24705 SECTION NAME=bank4 RAM=gpr4
24708 \begin_layout LyX-Code
24709 SECTION NAME=bank5 RAM=gpr5
24712 \begin_layout Standard
24713 The linker will recognise the section name set in the pragma statement and
24714 will position the variable at the memory bank set with the RAM field at
24715 the SECTION line in the linker script file.
24718 \begin_layout Subsection
24720 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24727 \begin_layout Standard
24728 There is one main header file
24729 \begin_inset LatexCommand \index{PIC16!Header files}
24733 that can be included to the source files using the pic16
24734 \begin_inset LatexCommand \index{PIC16}
24744 This header file contains the definitions for the processor special registers,
24745 so it is necessary if the source accesses them.
24746 It can be included by adding the following line in the beginning of the
24750 \begin_layout LyX-Code
24751 #include <pic18fregs.h>
24754 \begin_layout Standard
24755 The specific microcontroller is selected within the pic18fregs.h automatically,
24756 so the same source can be used with a variety of devices.
24759 \begin_layout Subsection
24763 \begin_layout Standard
24765 \begin_inset LatexCommand \index{PIC16!Libraries}
24770 \begin_inset LatexCommand \index{PIC16}
24774 port depends on are the microcontroller device libraries which contain
24775 the symbol definitions for the microcontroller special function registers.
24776 These libraries have the format pic18fxxxx.lib, where
24780 is the microcontroller identification number.
24781 The specific library is selected automatically by the compiler at link
24782 stage according to the selected device.
24785 \begin_layout Standard
24786 Libraries are created with gplib which is part of the gputils package
24787 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24794 \begin_layout Subsubsection*
24795 Building the libraries
24798 \begin_layout Standard
24799 Before using SDCC/pic16 there are some libraries that need to be compiled.
24800 This process is not done automatically by SDCC since not all users use
24801 SDCC for pic16 projects.
24802 So each user should compile the libraries separately.
24805 \begin_layout Standard
24806 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24809 \begin_layout LyX-Code
24810 cd device/lib/pic16
24813 \begin_layout LyX-Code
24817 \begin_layout LyX-Code
24821 \begin_layout LyX-Code
24825 \begin_layout LyX-Code
24829 \begin_layout LyX-Code
24830 su -c 'make install' # install the libraries, you need the root password
24833 \begin_layout Standard
24834 If you need to install the headers too, do:
24837 \begin_layout LyX-Code
24841 \begin_layout LyX-Code
24842 su -c 'make install' # install the headers, you need the root password
24845 \begin_layout Standard
24846 There exist a special target to build the I/O libraries.
24847 This target is not automatically build because it will build the I/O library
24853 This way building will take quite a lot of time.
24854 Users are advised to edit the
24856 device/lib/pic16/pics.build
24858 file and then execute:
24861 \begin_layout LyX-Code
24865 \begin_layout Subsection
24869 \begin_layout Standard
24870 The following memory models are supported by the PIC16 port:
24873 \begin_layout Itemize
24877 \begin_layout Itemize
24881 \begin_layout Standard
24882 Memory model affects the default size of pointers within the source.
24883 The sizes are shown in the next table:
24886 \begin_layout Standard
24888 \begin_inset Tabular
24889 <lyxtabular version="3" rows="3" columns="3">
24891 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24892 <column alignment="center" valignment="top" leftline="true" width="0">
24893 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24894 <row topline="true" bottomline="true">
24895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24898 \begin_layout Standard
24899 Pointer sizes according to memory model
24904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24907 \begin_layout Standard
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24916 \begin_layout Standard
24923 <row topline="true" bottomline="true">
24924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24927 \begin_layout Standard
24933 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24936 \begin_layout Standard
24942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24945 \begin_layout Standard
24952 <row topline="true" bottomline="true">
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24956 \begin_layout Standard
24962 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24965 \begin_layout Standard
24971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24974 \begin_layout Standard
24988 \begin_layout Standard
24989 It is advisable that all sources within a project are compiled with the
24991 If one wants to override the default memory model, this can be done by
24992 declaring a pointer as
25001 Far selects large memory model's pointers, while near selects small memory
25005 \begin_layout Standard
25006 The standard device libraries (see
25007 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25011 ) contain no reference to pointers, so they can be used with both memory
25015 \begin_layout Subsection
25019 \begin_layout Standard
25021 \begin_inset LatexCommand \index{PIC16!stack}
25025 implementation for the PIC16 port uses two indirect registers, FSR1 and
25030 \labelwidthstring 00.00.0000
25031 FSR1 is assigned as stack pointer
25035 \labelwidthstring 00.00.0000
25036 FSR2 is assigned as frame pointer
25039 \begin_layout Standard
25040 The following stack models are supported by the PIC16 port
25043 \begin_layout Itemize
25051 \begin_layout Itemize
25059 \begin_layout Standard
25064 model means that only the FSRxL byte is used to access stack and frame,
25071 uses both FSRxL and FSRxH registers.
25072 The following table shows the stack/frame pointers sizes according to stack
25073 model and the maximum space they can address:
25076 \begin_layout Standard
25078 \begin_inset Tabular
25079 <lyxtabular version="3" rows="3" columns="3">
25081 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25082 <column alignment="center" valignment="top" leftline="true" width="0">
25083 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25084 <row topline="true" bottomline="true">
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25088 \begin_layout Standard
25089 Stack & Frame pointer sizes according to stack model
25094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25097 \begin_layout Standard
25103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25106 \begin_layout Standard
25113 <row topline="true">
25114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25117 \begin_layout Standard
25123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25126 \begin_layout Standard
25132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25135 \begin_layout Standard
25142 <row topline="true" bottomline="true">
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25146 \begin_layout Standard
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25155 \begin_layout Standard
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25164 \begin_layout Standard
25178 \begin_layout Standard
25183 stack model is currently not working properly throughout the code generator.
25184 So its use is not advised.
25185 Also there are some other points that need special care:
25190 \begin_layout Enumerate
25191 Do not create stack sections with size more than one physical bank (that
25195 \begin_layout Enumerate
25196 Stack sections should no cross physical bank limits (i.e.
25197 #pragma stack 0x50 0x100)
25200 \begin_layout Standard
25201 These limitations are caused by the fact that only FSRxL is modified when
25202 using SMALL stack model, so no more than 256 bytes of stack can be used.
25203 This problem will disappear after LARGE model is fully implemented.
25206 \begin_layout Subsection
25210 \begin_layout Standard
25211 In addition to the standard SDCC function keywords, PIC16
25212 \begin_inset LatexCommand \index{PIC16}
25216 port makes available two more:
25220 \labelwidthstring 00.00.0000
25222 \begin_inset LatexCommand \index{PIC16!wparam}
25226 Use the WREG to pass one byte of the first function argument.
25227 This improves speed but you may not use this for functions with arguments
25228 that are called via function pointers, otherwise the first byte of the
25229 first parameter will get lost.
25233 \begin_layout LyX-Code
25234 void func_wparam(int a) wparam
25237 \begin_layout LyX-Code
25241 \begin_layout LyX-Code
25242 /* WREG hold the lower part of a */
25245 \begin_layout LyX-Code
25246 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25250 \begin_layout LyX-Code
25254 \begin_layout LyX-Code
25259 \labelwidthstring 00.00.0000
25261 \begin_inset LatexCommand \index{PIC16!shadowregs}
25265 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25266 hardware shadow registers which hold the values of WREG, STATUS and BSR
25268 This can be done by adding the keyword
25276 keyword in the function's header.
25279 \begin_layout LyX-Code
25280 void isr_shadow(void) shadowregs interrupt 1
25283 \begin_layout LyX-Code
25287 \begin_layout LyX-Code
25291 \begin_layout LyX-Code
25295 \begin_layout Standard
25300 instructs the code generator not to store/restore WREG, STATUS, BSR when
25301 entering/exiting the ISR.
25304 \begin_layout Subsection
25305 Function return values
25308 \begin_layout Standard
25309 Return values from functions are placed to the appropriate registers following
25310 a modified Microchip policy optimized for SDCC.
25311 The following table shows these registers:
25314 \begin_layout Standard
25316 \begin_inset Tabular
25317 <lyxtabular version="3" rows="6" columns="2">
25319 <column alignment="center" valignment="top" leftline="true" width="0">
25320 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25321 <row topline="true" bottomline="true">
25322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25325 \begin_layout Standard
25331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25334 \begin_layout Standard
25335 destination register
25341 <row topline="true">
25342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25345 \begin_layout Standard
25351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25354 \begin_layout Standard
25361 <row topline="true">
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25365 \begin_layout Standard
25371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25374 \begin_layout Standard
25381 <row topline="true">
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25385 \begin_layout Standard
25391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25394 \begin_layout Standard
25401 <row topline="true">
25402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25405 \begin_layout Standard
25411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25414 \begin_layout Standard
25415 FSR0L:PRODH:PRODL:WREG
25421 <row topline="true" bottomline="true">
25422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25425 \begin_layout Standard
25431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25434 \begin_layout Standard
25435 on stack, FSR0 points to the beginning
25448 \begin_layout Subsection
25452 \begin_layout Standard
25454 \begin_inset LatexCommand \index{PIC16!interrupt}
25458 service routine (ISR) is declared using the
25465 \begin_layout LyX-Code
25466 void isr(void) interrupt
25471 \begin_layout LyX-Code
25475 \begin_layout LyX-Code
25479 \begin_layout LyX-Code
25483 \begin_layout Standard
25488 is the interrupt number, which for PIC18F devices can be:
25491 \begin_layout Standard
25493 \begin_inset Tabular
25494 <lyxtabular version="3" rows="4" columns="3">
25496 <column alignment="center" valignment="top" leftline="true" width="0">
25497 <column alignment="center" valignment="top" leftline="true" width="0">
25498 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25499 <row topline="true" bottomline="true">
25500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25503 \begin_layout Standard
25511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25514 \begin_layout Standard
25520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25523 \begin_layout Standard
25524 Interrupt Vector Address
25530 <row topline="true">
25531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25534 \begin_layout Standard
25540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25543 \begin_layout Standard
25549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25552 \begin_layout Standard
25559 <row topline="true">
25560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25563 \begin_layout Standard
25578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25581 \begin_layout Standard
25591 HIGH priority interrupts
25596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25599 \begin_layout Standard
25606 <row topline="true" bottomline="true">
25607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25610 \begin_layout Standard
25616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25619 \begin_layout Standard
25620 LOW priority interrupts
25625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25628 \begin_layout Standard
25642 \begin_layout Standard
25643 When generating assembly code for ISR the code generator places a
25649 Interrupt Vector Address
25651 which points at the genetated ISR.
25652 This single GOTO instruction is part of an automatically generated
25654 interrupt entry point
25657 The actuall ISR code is placed as normally would in the code space.
25658 Upon interrupt request, the GOTO instruction is executed which jumps to
25660 When declaring interrupt functions as _naked this GOTO instruction is
25665 The whole interrupt functions is therefore placed at the Interrupt Vector
25666 Address of the specific interrupt.
25667 This is not a problem for the LOW priority interrupts, but it is a problem
25668 for the RESET and the HIGH priority interrupts because code may be written
25669 at the next interrupt´s vector address and cause undeterminate program
25670 behaviour if that interrupt is raised.
25674 \begin_layout Standard
25675 This is not a problem when
25678 \begin_layout Enumerate
25679 this is a HIGH interrupt ISR and LOW interrupts are
25686 \begin_layout Enumerate
25687 when the ISR is small enough not to reach the next interrupt´s vector address.
25695 \begin_layout Standard
25700 is possible to be omitted.
25701 This way a function is generated similar to an ISR, but it is not assigned
25705 \begin_layout Standard
25706 When entering an interrupt, currently the PIC16
25707 \begin_inset LatexCommand \index{PIC16}
25711 port automatically saves the following registers:
25714 \begin_layout Itemize
25718 \begin_layout Itemize
25722 \begin_layout Itemize
25726 \begin_layout Itemize
25727 PROD (PRODL and PRODH)
25730 \begin_layout Itemize
25731 FSR0 (FSR0L and FSR0H)
25734 \begin_layout Standard
25735 These registers are restored upon return from the interrupt routine.
25739 \begin_layout Standard
25740 NOTE that when the _naked attribute is specified for an interrupt routine,
25741 then NO registers are stored or restored.
25749 \begin_layout Subsection
25753 \begin_layout Standard
25754 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25755 There are 3 types of generic pointers currently implemented data, code
25756 and eeprom pointers.
25757 They are differentiated by the value of the 7th and 6th bits of the upper
25761 \begin_layout Standard
25763 \begin_inset Tabular
25764 <lyxtabular version="3" rows="5" columns="5">
25766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25767 <column alignment="center" valignment="top" width="0">
25768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25769 <column alignment="center" valignment="top" width="0">
25770 <column alignment="left" valignment="top" rightline="true" width="0">
25771 <row topline="true" bottomline="true">
25772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25775 \begin_layout Standard
25781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25784 \begin_layout Standard
25790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25793 \begin_layout Standard
25799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25802 \begin_layout Standard
25803 rest of the pointer
25808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25811 \begin_layout Standard
25818 <row topline="true" bottomline="true">
25819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25822 \begin_layout Standard
25828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25831 \begin_layout Standard
25837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25840 \begin_layout Standard
25846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25849 \begin_layout Standard
25854 uuuuuu uuuuxxxx xxxxxxxx
25859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25862 \begin_layout Standard
25863 a 12-bit data pointer in data RAM memory
25869 <row bottomline="true">
25870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25873 \begin_layout Standard
25879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25882 \begin_layout Standard
25888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25891 \begin_layout Standard
25897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25900 \begin_layout Standard
25905 uxxxxx xxxxxxxx xxxxxxxx
25910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25913 \begin_layout Standard
25914 a 21-bit code pointer in FLASH memory
25920 <row bottomline="true">
25921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25924 \begin_layout Standard
25930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25933 \begin_layout Standard
25939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25942 \begin_layout Standard
25948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25951 \begin_layout Standard
25956 uuuuuu uuuuuuxx xxxxxxxx
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25964 \begin_layout Standard
25965 a 10-bit eeprom pointer in EEPROM memory
25971 <row bottomline="true">
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25975 \begin_layout Standard
25981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25984 \begin_layout Standard
25990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25993 \begin_layout Standard
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26002 \begin_layout Standard
26007 xxxxxx xxxxxxxx xxxxxxxx
26012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26015 \begin_layout Standard
26016 unimplemented pointer type
26029 \begin_layout Standard
26030 Generic pointer are read and written with a set of library functions which
26031 read/write 1, 2, 3, 4 bytes.
26034 \begin_layout Subsection
26038 \begin_layout Subsubsection
26039 Standard I/O Streams
26042 \begin_layout Standard
26047 the type FILE is defined as:
26050 \begin_layout LyX-Code
26051 typedef char * FILE;
26054 \begin_layout Standard
26055 This type is the stream type implemented I/O in the PIC18F devices.
26056 Also the standard input and output streams are declared in stdio.h:
26059 \begin_layout LyX-Code
26060 extern FILE * stdin;
26063 \begin_layout LyX-Code
26064 extern FILE * stdout;
26067 \begin_layout Standard
26068 The FILE type is actually a generic pointer which defines one more type
26069 of generic pointers, the
26074 This new type has the format:
26077 \begin_layout Standard
26079 \begin_inset Tabular
26080 <lyxtabular version="3" rows="2" columns="7">
26082 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26083 <column alignment="center" valignment="top" width="0">
26084 <column alignment="center" valignment="top" leftline="true" width="0">
26085 <column alignment="center" valignment="top" leftline="true" width="0">
26086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26087 <column alignment="center" valignment="top" width="0">
26088 <column alignment="left" valignment="top" rightline="true" width="0">
26089 <row topline="true" bottomline="true">
26090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26093 \begin_layout Standard
26099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26102 \begin_layout Standard
26108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26111 \begin_layout Standard
26117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26120 \begin_layout Standard
26126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26129 \begin_layout Standard
26135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26138 \begin_layout Standard
26139 rest of the pointer
26144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26147 \begin_layout Standard
26154 <row topline="true" bottomline="true">
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26158 \begin_layout Standard
26164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26167 \begin_layout Standard
26173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26176 \begin_layout Standard
26182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26185 \begin_layout Standard
26191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26194 \begin_layout Standard
26200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26203 \begin_layout Standard
26213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26216 \begin_layout Standard
26217 upper byte high nubble is 0x2n, the rest are zeroes
26230 \begin_layout Standard
26231 Currently implemented there are 3 types of streams defined:
26234 \begin_layout Standard
26236 \begin_inset Tabular
26237 <lyxtabular version="3" rows="4" columns="4">
26239 <column alignment="center" valignment="top" leftline="true" width="0">
26240 <column alignment="center" valignment="top" leftline="true" width="0">
26241 <column alignment="center" valignment="top" leftline="true" width="0">
26242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26243 <row topline="true" bottomline="true">
26244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26247 \begin_layout Standard
26253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26256 \begin_layout Standard
26262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26265 \begin_layout Standard
26271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26274 \begin_layout Standard
26281 <row topline="true">
26282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26285 \begin_layout Standard
26291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26294 \begin_layout Standard
26302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26305 \begin_layout Standard
26311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26314 \begin_layout Standard
26315 Writes/Reads characters via the USART peripheral
26321 <row topline="true">
26322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26325 \begin_layout Standard
26331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26334 \begin_layout Standard
26342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26345 \begin_layout Standard
26351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26354 \begin_layout Standard
26355 Writes/Reads characters via the MSSP peripheral
26361 <row topline="true" bottomline="true">
26362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26365 \begin_layout Standard
26371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26374 \begin_layout Standard
26382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26385 \begin_layout Standard
26391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26394 \begin_layout Standard
26395 Writes/Reads characters via used defined functions
26408 \begin_layout Standard
26409 The stream identifiers are declared as macros in the stdio.h header.
26412 \begin_layout Standard
26413 In the libc library there exist the functions that are used to write to
26414 each of the above streams.
26419 \labelwidthstring 00.00.0000
26424 \begin_layout Standard
26433 _stream_usart_putchar writes a character at the USART stream
26437 \labelwidthstring 00.00.0000
26442 \begin_layout Standard
26451 _stream_mssp_putchar writes a character at the MSSP stream
26455 \labelwidthstring 00.00.0000
26456 putchar dummy function.
26457 This writes a character to a user specified manner.
26460 \begin_layout Standard
26461 In order to increase performance
26465 is declared in stdio.h as having its parameter in WREG (it has the wparam
26467 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26468 in a user-friendly way.
26473 is the name of the variable that holds the character to print.
26474 An example follows:
26477 \begin_layout LyX-Code
26478 #include <pic18fregs.h>
26487 \begin_layout LyX-Code
26491 \begin_layout LyX-Code
26492 PORTA = c; /* dump character c to PORTA */
26495 \begin_layout LyX-Code
26503 \begin_layout LyX-Code
26507 \begin_layout LyX-Code
26508 stdout = STREAM_USER; /* this is not necessary, since stdout points
26511 \begin_layout LyX-Code
26512 * by default to STREAM_USER */
26515 \begin_layout LyX-Code
26516 printf (¨This is a printf test
26521 \begin_layout LyX-Code
26525 \begin_layout LyX-Code
26529 \begin_layout Subsubsection
26533 \begin_layout Standard
26534 PIC16 contains an implementation of the printf-family of functions.
26535 There exist the following functions:
26538 \begin_layout LyX-Code
26539 extern unsigned int sprintf(char *buf, char *fmt, ...);
26542 \begin_layout LyX-Code
26543 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26546 \begin_layout LyX-Code
26550 \begin_layout LyX-Code
26551 extern unsigned int printf(char *fmt, ...);
26554 \begin_layout LyX-Code
26555 extern unsigned int vprintf(char *fmt, va_lista ap);
26558 \begin_layout LyX-Code
26562 \begin_layout LyX-Code
26563 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26566 \begin_layout LyX-Code
26567 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26570 \begin_layout Standard
26571 For sprintf and vsprintf
26575 should normally be a data pointer where the resulting string will be placed.
26576 No range checking is done so the user should allocate the necessery buffer.
26577 For fprintf and vfprintf
26581 should be a stream pointer (i.e.
26582 stdout, STREAM_MSSP, etc...).
26585 \begin_layout Subsubsection
26589 \begin_layout Standard
26590 The PIC18F family of microcontrollers supports a number of interrupt sources.
26591 A list of these interrupts is shown in the following table:
26594 \begin_layout Standard
26596 \begin_inset Tabular
26597 <lyxtabular version="3" rows="11" columns="4">
26599 <column alignment="left" valignment="top" leftline="true" width="0">
26600 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26601 <column alignment="left" valignment="top" leftline="true" width="0">
26602 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26603 <row topline="true" bottomline="true">
26604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26607 \begin_layout Standard
26613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26616 \begin_layout Standard
26622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26625 \begin_layout Standard
26631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26634 \begin_layout Standard
26641 <row topline="true">
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26645 \begin_layout Standard
26651 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26654 \begin_layout Standard
26655 PORTB change interrupt
26660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26663 \begin_layout Standard
26669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26672 \begin_layout Standard
26673 EEPROM/FLASH write complete interrupt
26679 <row topline="true">
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26683 \begin_layout Standard
26689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26692 \begin_layout Standard
26693 INT0 external interrupt
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26701 \begin_layout Standard
26707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26710 \begin_layout Standard
26711 Bus collision interrupt
26717 <row topline="true">
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26721 \begin_layout Standard
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26730 \begin_layout Standard
26731 INT1 external interrupt
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26739 \begin_layout Standard
26745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26748 \begin_layout Standard
26749 Low voltage detect interrupt
26755 <row topline="true">
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26759 \begin_layout Standard
26765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26768 \begin_layout Standard
26769 INT2 external interrupt
26774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26777 \begin_layout Standard
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26786 \begin_layout Standard
26787 Parallel slave port interrupt
26793 <row topline="true">
26794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26797 \begin_layout Standard
26803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26806 \begin_layout Standard
26807 CCP1 module interrupt
26812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26815 \begin_layout Standard
26821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26824 \begin_layout Standard
26825 AD convertion complete interrupt
26831 <row topline="true">
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26835 \begin_layout Standard
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26844 \begin_layout Standard
26845 CCP2 module interrupt
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26853 \begin_layout Standard
26859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26862 \begin_layout Standard
26863 USART receive interrupt
26869 <row topline="true">
26870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26873 \begin_layout Standard
26879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26882 \begin_layout Standard
26883 TMR0 overflow interrupt
26888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26891 \begin_layout Standard
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26900 \begin_layout Standard
26901 USART transmit interrupt
26907 <row topline="true">
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26911 \begin_layout Standard
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26920 \begin_layout Standard
26921 TMR1 overflow interrupt
26926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26929 \begin_layout Standard
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26938 \begin_layout Standard
26939 SSP receive/transmit interrupt
26945 <row topline="true">
26946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26949 \begin_layout Standard
26955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26958 \begin_layout Standard
26959 TMR2 matches PR2 interrupt
26964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26967 \begin_layout Standard
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26976 \begin_layout Standard
26983 <row topline="true" bottomline="true">
26984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26987 \begin_layout Standard
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26996 \begin_layout Standard
26997 TMR3 overflow interrupt
27002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27005 \begin_layout Standard
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27014 \begin_layout Standard
27028 \begin_layout Standard
27029 The prototypes for these names are defined in the header file
27036 \begin_layout Standard
27037 In order to simplify signal handling, a number of macros is provided:
27041 \labelwidthstring 00.00.0000
27042 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27043 high priority interrupts.
27048 is the function name to use.
27052 \labelwidthstring 00.00.0000
27053 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27054 low priority interrupt.
27059 is the function name to use.
27063 \labelwidthstring 00.00.0000
27064 DEF_HANDLER(sig,handler) define a handler for signal
27070 \labelwidthstring 00.00.0000
27071 END_DEF end the declaration of the dispatch table.
27074 \begin_layout Standard
27075 Additionally there are two more macros to simplify the declaration of the
27080 \labelwidthstring 00.00.0000
27083 SIGHANDLER(handler)
27085 this declares the function prototype for the
27093 \labelwidthstring 00.00.0000
27094 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27097 \begin_layout Standard
27098 An example of using the macros above is shown below:
27101 \begin_layout LyX-Code
27102 #include <pic18fregs.h>
27105 \begin_layout LyX-Code
27106 #include <signal.h>
27110 DEF_INTHIGH(high_int)
27113 \begin_layout LyX-Code
27114 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27117 \begin_layout LyX-Code
27118 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27121 \begin_layout LyX-Code
27126 SIGHANDLER(_tmr0_handler)
27129 \begin_layout LyX-Code
27133 \begin_layout LyX-Code
27134 /* action to be taken when timer 0 overflows */
27137 \begin_layout LyX-Code
27142 SIGHANDLERNAKED(_bcol_handler)
27145 \begin_layout LyX-Code
27149 \begin_layout LyX-Code
27153 \begin_layout LyX-Code
27154 /* action to be taken when bus collision occurs */
27157 \begin_layout LyX-Code
27161 \begin_layout LyX-Code
27165 \begin_layout LyX-Code
27169 \begin_layout Standard
27174 Special care should be taken when using the above scheme:
27177 \begin_layout Itemize
27178 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27181 \begin_layout Itemize
27182 when declaring SIGHANDLERNAKED handler never forget to use
27186 for proper returning.
27189 \begin_layout Subsection
27193 \begin_layout Standard
27194 Here you can find some general tips for compiling programs with SDCC/pic16.
27197 \begin_layout Subsubsection
27201 \begin_layout Standard
27203 \begin_inset LatexCommand \index{PIC16!stack}
27207 size (that is 64 bytes) probably is enough for many programs.
27208 One must take care that when there are many levels of function nesting,
27209 or there is excessive usage of stack, its size should be extended.
27210 An example of such a case is the printf/sprintf family of functions.
27211 If you encounter problems like not being able to print integers, then you
27212 need to set the stack size around the maximum (256 for small stack model).
27213 The following diagram shows what happens when calling printf to print an
27217 \begin_layout LyX-Code
27218 printf () --> ltoa () --> ultoa () --> divschar ()
27221 \begin_layout Standard
27222 It is should be understood that stack is easily consumed when calling complicate
27224 Using command line arguments like -
27228 \begin_layout Standard
27237 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27239 Other ways to reduce stack usage may exist.
27242 \begin_layout Subsection
27246 \begin_layout Standard
27247 The PIC16 Port currently does not pass SDCC's regression test
27248 \begin_inset LatexCommand \index{Regression test (PIC16)}
27253 \begin_inset LatexCommand \ref{sec:Quality-control}
27257 ) and thus the snapshot build regression tests for the PIC16 target are
27258 currently disabled for all hosts
27263 \begin_layout Chapter
27267 \begin_layout Standard
27268 There are several approaches to debugging your code.
27269 This chapter is meant to show your options and to give detail on some of
27274 When writing your code:
27277 \begin_layout Itemize
27278 write your code with debugging in mind (avoid duplicating code, put conceptually
27279 similar variables into structs, use structured code, have strategic points
27280 within your code where all variables are consistent, ...)
27283 \begin_layout Itemize
27284 run a syntax-checking tool like splint
27285 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27290 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27298 \begin_layout Standard
27308 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27315 \begin_layout Itemize
27316 for the high level code use a C-compiler (like f.e.
27317 GCC) to compile run and debug the code on your host.
27322 \begin_layout Standard
27332 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27336 ) on how to handle syntax extensions like __xdata, __at(), ...
27340 \begin_layout Itemize
27341 use another C-compiler to compile code for your target.
27342 Always an option but not recommended:) And not very likely to help you.
27343 If you seriously consider walking this path you should at least occasionally
27344 check portability of your code.
27345 Most commercial compiler vendors will offer an evaluation version so you
27346 can test compile your code or snippets of your code.
27349 \begin_layout Standard
27350 Debugging on a simulator:
27353 \begin_layout Itemize
27354 there is a separate section about SDCDB (section
27355 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27362 \begin_layout Itemize
27363 or (8051 specific) use a freeware/commercial simulator which interfaces
27365 \begin_inset LatexCommand \index{AOMF, AOMF51}
27370 \begin_inset LatexCommand \ref{OMF file}
27374 ) optionally generated by SDCC.
27377 \begin_layout Standard
27378 Debugging On-target:
27381 \begin_layout Itemize
27382 use a MCU port pin to serially output debug data to the RS232 port of your
27384 You'll probably want some level shifting device typically involving a MAX232
27386 If the hardware serial port of the MCU is not available search for 'Software
27387 UART' in your favourite search machine.
27390 \begin_layout Itemize
27391 use an on-target monitor.
27392 In this context a monitor is a small program which usually accepts commands
27393 via a serial line and allows to set program counter, to single step through
27394 a program and read/write memory locations.
27395 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27397 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27404 \begin_layout Itemize
27405 toggle MCU port pins at strategic points within your code and use an oscilloscop
27409 digital oscilloscope
27412 \begin_inset LatexCommand \index{Oscilloscope}
27416 with deep trace memory is really helpful especially if you have to debug
27417 a realtime application.
27418 If you need to monitor more pins than your oscilloscope provides you can
27419 sometimes get away with a small R-2R network.
27420 On a single channel oscilloscope you could f.e.
27421 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27423 \begin_inset Formula $\Omega$
27426 resistor and the other one by a 5\InsetSpace ~
27428 \begin_inset Formula $\Omega$
27431 resistor to the oscilloscope probe (check output drive capability of the
27432 pins you want to monitor).
27433 If you need to monitor many more pins a
27440 \begin_layout Itemize
27454 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27459 Usually very expensive.
27460 And very nice to have too.
27461 And usually locks you (for years...) to the devices the ICE can emulate.
27465 \begin_layout Itemize
27466 use a remote debugger.
27467 In most 8-bit systems the symbol information is not available on the target,
27468 and a complete debugger is too bulky for the target system.
27469 Therefore usually a debugger on the host system connects to an on-target
27470 debugging stub which accepts only primitive commands.
27473 Terms to enter into your favourite search engine could be 'remote debugging',
27474 'gdb stub' or 'inferior debugger'.
27478 \begin_layout Itemize
27479 use an on target hardware debugger.
27480 Some of the more modern MCUs include hardware support for setting break
27481 points and monitoring/changing variables by using dedicated hardware pins.
27482 This facility doesn't require additional code to run on the target and
27487 doesn't affect runtime behaviour until a breakpoint is hit.
27488 For the mcs51 most hardware debuggers use the AOMF
27489 \begin_inset LatexCommand \index{AOMF, AOMF51}
27494 \begin_inset LatexCommand \ref{OMF file}
27502 \begin_layout Standard
27506 \begin_layout Itemize
27507 if you are not familiar with any of the following terms you're likely to
27508 run into problems rather sooner than later:
27525 As an embedded programmer you
27529 to know them so why not look them up
27533 you have problems?)
27536 \begin_layout Itemize
27537 tell someone else about your problem (actually this is a surprisingly effective
27538 means to hunt down the bug even if the listener is not familiar with your
27540 As 'failure to communicate' is probably one of the job-induced deformations
27541 of an embedded programmer this is highly encouraged.
27544 \begin_layout Section
27545 Debugging with SDCDB
27546 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27551 \begin_inset LatexCommand \index{SDCDB (debugger)}
27558 \begin_layout Standard
27559 SDCC is distributed with a source level debugger
27560 \begin_inset LatexCommand \index{Debugger}
27565 The debugger uses a command line interface, the command repertoire of the
27566 debugger has been kept as close to gdb
27567 \begin_inset LatexCommand \index{gdb}
27571 (the GNU debugger) as possible.
27572 The configuration and build process is part of the standard compiler installati
27573 on, which also builds and installs the debugger in the target directory
27574 specified during configuration.
27575 The debugger allows you debug BOTH at the C source and at the ASM source
27579 \begin_layout Subsection
27580 Compiling for Debugging
27583 \begin_layout Standard
27588 \begin_layout Standard
27598 \begin_inset LatexCommand \index{-\/-debug}
27602 option must be specified for all files for which debug information is to
27604 The compiler generates a .adb file for each of these files.
27605 The linker creates the .cdb
27606 \begin_inset LatexCommand \index{<file>.cdb}
27611 \begin_inset LatexCommand \index{<file>.adb}
27615 files and the address information.
27616 This .cdb is used by the debugger.
27619 \begin_layout Subsection
27620 How the Debugger Works
27623 \begin_layout Standard
27628 \begin_layout Standard
27637 -debug option is specified the compiler generates extra symbol information
27638 some of which are put into the assembler source and some are put into the
27640 Then the linker creates the .cdb file from the individual .adb files with
27641 the address information for the symbols.
27642 The debugger reads the symbolic information generated by the compiler &
27643 the address information generated by the linker.
27644 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27645 execution is controlled by the debugger.
27646 When a command is issued for the debugger, it translates it into appropriate
27647 commands for the simulator.
27648 (Currently SDCDM only connects to the simulator but
27653 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27657 is an effort to connect directly to the hardware.)
27660 \begin_layout Subsection
27661 Starting the Debugger SDCDB
27664 \begin_layout Standard
27665 The debugger can be started using the following command line.
27666 (Assume the file you are debugging has the file name foo).
27680 The debugger will look for the following files.
27683 \begin_layout Itemize
27684 foo.c - the source file.
27687 \begin_layout Itemize
27688 foo.cdb - the debugger symbol information file.
27691 \begin_layout Itemize
27692 foo.ihx - the Intel hex format
27693 \begin_inset LatexCommand \index{Intel hex format}
27700 \begin_layout Subsection
27701 SDCDB Command Line Options
27704 \begin_layout Itemize
27709 \begin_layout Standard
27718 -directory=<source file directory> this option can used to specify the directory
27720 The debugger will look into the directory list specified for source, cdb
27722 The items in the directory list must be separated by ':', e.g.
27723 if the source files can be in the directories /home/src1 and /home/src2,
27728 \begin_layout Standard
27737 -directory option should be -
27741 \begin_layout Standard
27750 -directory=/home/src1:/home/src2.
27751 Note there can be no spaces in the option.
27755 \begin_layout Itemize
27756 -cd <directory> - change to the <directory>.
27759 \begin_layout Itemize
27760 -fullname - used by GUI front ends.
27763 \begin_layout Itemize
27764 -cpu <cpu-type> - this argument is passed to the simulator please see the
27765 simulator docs for details.
27768 \begin_layout Itemize
27769 -X <Clock frequency > this options is passed to the simulator please see
27770 the simulator docs for details.
27773 \begin_layout Itemize
27774 -s <serial port file> passed to simulator see the simulator docs for details.
27777 \begin_layout Itemize
27778 -S <serial in,out> passed to simulator see the simulator docs for details.
27781 \begin_layout Itemize
27782 -k <port number> passed to simulator see the simulator docs for details.
27785 \begin_layout Subsection
27786 SDCDB Debugger Commands
27789 \begin_layout Standard
27790 As mentioned earlier the command interface for the debugger has been deliberatel
27791 y kept as close the GNU debugger gdb, as possible.
27792 This will help the integration with existing graphical user interfaces
27793 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27794 If you use a graphical user interface for the debugger you can skip this
27798 \begin_layout Subsubsection*
27799 break [line | file:line | function | file:function]
27802 \begin_layout Standard
27803 Set breakpoint at specified line or function:
27812 sdcdb>break foo.c:100
27814 sdcdb>break funcfoo
27816 sdcdb>break foo.c:funcfoo
27819 \begin_layout Subsubsection*
27820 clear [line | file:line | function | file:function ]
27823 \begin_layout Standard
27824 Clear breakpoint at specified line or function:
27833 sdcdb>clear foo.c:100
27835 sdcdb>clear funcfoo
27837 sdcdb>clear foo.c:funcfoo
27840 \begin_layout Subsubsection*
27844 \begin_layout Standard
27845 Continue program being debugged, after breakpoint.
27848 \begin_layout Subsubsection*
27852 \begin_layout Standard
27853 Execute till the end of the current function.
27856 \begin_layout Subsubsection*
27860 \begin_layout Standard
27861 Delete breakpoint number 'n'.
27862 If used without any option clear ALL user defined break points.
27865 \begin_layout Subsubsection*
27866 info [break | stack | frame | registers ]
27869 \begin_layout Itemize
27870 info break - list all breakpoints
27873 \begin_layout Itemize
27874 info stack - show the function call stack.
27877 \begin_layout Itemize
27878 info frame - show information about the current execution frame.
27881 \begin_layout Itemize
27882 info registers - show content of all registers.
27885 \begin_layout Subsubsection*
27889 \begin_layout Standard
27890 Step program until it reaches a different source line.
27891 Note: pressing <return> repeats the last command.
27894 \begin_layout Subsubsection*
27898 \begin_layout Standard
27899 Step program, proceeding through subroutine calls.
27902 \begin_layout Subsubsection*
27906 \begin_layout Standard
27907 Start debugged program.
27910 \begin_layout Subsubsection*
27914 \begin_layout Standard
27915 Print type information of the variable.
27918 \begin_layout Subsubsection*
27922 \begin_layout Standard
27923 print value of variable.
27926 \begin_layout Subsubsection*
27930 \begin_layout Standard
27931 load the given file name.
27932 Note this is an alternate method of loading file for debugging.
27935 \begin_layout Subsubsection*
27939 \begin_layout Standard
27940 print information about current frame.
27943 \begin_layout Subsubsection*
27947 \begin_layout Standard
27948 Toggle between C source & assembly source.
27951 \begin_layout Subsubsection*
27952 ! simulator command
27955 \begin_layout Standard
27956 Send the string following '!' to the simulator, the simulator response is
27958 Note the debugger does not interpret the command being sent to the simulator,
27959 so if a command like 'go' is sent the debugger can loose its execution
27960 context and may display incorrect values.
27963 \begin_layout Subsubsection*
27967 \begin_layout Standard
27970 My name is Bobby Brown"
27973 \begin_layout Subsection
27974 Interfacing SDCDB with DDD
27977 \begin_layout Standard
27978 \begin_inset Note Note
27981 \begin_layout Standard
27982 The screenshot was converted from png to eps with:
27983 \begin_inset Quotes sld
27986 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
27987 \begin_inset Quotes srd
27990 which produces a pretty compact eps file which is free from compression
27994 \begin_layout Standard
27995 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
27996 as this broke the build system on Sourceforge (pdf-file was broken.
27997 pdflatex does not accept eps files).
28005 \begin_layout Standard
28021 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28027 shows a screenshot of a debugging session with DDD
28028 \begin_inset LatexCommand \index{DDD (debugger)}
28032 (Unix only) on a simulated 8032.
28033 The debugging session might not run as smoothly as the screenshot suggests.
28034 The debugger allows setting of breakpoints, displaying and changing variables,
28035 single stepping through C and assembler code.
28038 The source was compiled with
28052 \begin_layout Standard
28064 -debug ddd_example.c
28077 and DDD was invoked with
28084 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28087 \begin_layout Standard
28088 \begin_inset Note Note
28091 \begin_layout Standard
28092 Check that the double quotes or an apostroph within the command line survive
28093 the LyX tool chain.
28094 Previously the apostrophs got slanted in the PDF output so a cut and paste
28103 \begin_layout Subsection
28104 Interfacing SDCDB with XEmacs
28105 \begin_inset LatexCommand \index{XEmacs}
28110 \begin_inset LatexCommand \index{Emacs}
28117 \begin_layout Standard
28118 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28119 sdcdb.el and sdcdbsrc.el.
28120 These two files can be found in the $(prefix)/bin directory after the installat
28122 These files need to be loaded into XEmacs for the interface to work.
28123 This can be done at XEmacs startup time by inserting the following into
28124 your '.xemacs' file (which can be found in your HOME directory):
28130 (load-file sdcdbsrc.el)
28136 .xemacs is a lisp file so the () around the command is REQUIRED.
28137 The files can also be loaded dynamically while XEmacs is running, set the
28138 environment variable 'EMACSLOADPATH' to the installation bin directory
28139 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28140 To start the interface enter the following command:
28154 You will prompted to enter the file name to be debugged.
28159 The command line options that are passed to the simulator directly are
28160 bound to default values in the file sdcdbsrc.el.
28161 The variables are listed below, these values maybe changed as required.
28164 \begin_layout Itemize
28165 sdcdbsrc-cpu-type '51
28168 \begin_layout Itemize
28169 sdcdbsrc-frequency '11059200
28172 \begin_layout Itemize
28173 sdcdbsrc-serial nil
28176 \begin_layout Standard
28177 The following is a list of key mapping for the debugger interface.
28180 \begin_layout Standard
28203 binding\InsetSpace ~
28241 -------\InsetSpace ~
28312 sdcdb-back-from-src\InsetSpace ~
28341 rom-src\InsetSpace ~
28351 SDCDB continue command
28369 sdcdb-step-from-src\InsetSpace ~
28398 hatis-c-sexp\InsetSpace ~
28408 SDCDB ptypecommand for data at
28475 sdcdbsrc-delete\InsetSpace ~
28490 B Delete all breakpoints if no arg
28539 given or delete arg (C-u arg x)
28558 -frame\InsetSpace ~
28573 SDCDB Display current frame if no arg,
28622 given or display frame arg
28690 sdcdbsrc-goto-sdcdb\InsetSpace ~
28700 Goto the SDCDB output buffer
28719 t-c-sexp\InsetSpace ~
28730 SDCDB print command for data at
28797 sdcdbsrc-goto-sdcdb\InsetSpace ~
28808 o the SDCDB output buffer
28826 sdcdbsrc-mode\InsetSpace ~
28842 Toggles Sdcdbsrc mode (turns it
28858 sdcdb-finish-from-src\InsetSpace ~
28866 SDCDB finish command
28900 Set break for line with point
28915 sdcdbsrc-mode\InsetSpace ~
28931 Toggle Sdcdbsrc mode
28947 dbsrc-srcmode\InsetSpace ~
28971 \begin_layout Chapter
28975 \begin_layout Standard
28976 Here are a few guidelines that will help the compiler generate more efficient
28977 code, some of the tips are specific to this compiler others are generally
28978 good programming practice.
28981 \begin_layout Itemize
28982 Use the smallest data type to represent your data-value.
28983 If it is known in advance that the value is going to be less than 256 then
28984 use an 'unsigned char' instead of a 'short' or 'int'.
28985 Please note, that ANSI C requires both signed and unsigned chars to be
28986 promoted to 'signed int'
28987 \begin_inset LatexCommand \index{promotion to signed int}
28992 \begin_inset Marginal
28995 \begin_layout Standard
29004 before doing any operation.
29006 \begin_inset LatexCommand \index{type promotion}
29011 \begin_inset LatexCommand \label{type promotion}
29015 can be omitted, if the result is the same.
29016 The effect of the promotion rules together with the sign-extension is often
29021 \begin_layout Verse
29024 unsigned char uc = 0xfe;
29026 if (uc * uc < 0) /* this is true! */
29039 \begin_layout Standard
29046 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29054 \begin_layout Verse
29057 (unsigned char) -12 / (signed char) -3 = ...
29060 \begin_layout Standard
29061 No, the result is not 4:
29064 \begin_layout Verse
29067 (int) (unsigned char) -12 / (int) (signed char) -3 =
29069 (int) (unsigned char)
29070 0xf4 / (int) (signed char) 0xfd =
29072 (int) 0x00f4 / (int) 0xfffd =
29077 (int) 244 / (int) -3 =
29079 (int) -81 = (int) 0xffaf;
29082 \begin_layout Standard
29083 Don't complain, that gcc gives you a different result.
29084 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29085 Therefore the results are different.
29088 \begin_inset Quotes sld
29092 \begin_inset Quotes srd
29098 \begin_layout Quote
29101 If well-defined overflow characteristics are important and negative values
29102 are not, or if you want to steer clear of sign-extension problems when
29103 manipulating bits or bytes, use one of the corresponding unsigned types.
29104 (Beware when mixing signed and unsigned values in expressions, though.)
29107 character types (especially unsigned char) can be used as "tiny" integers,
29108 doing so is sometimes more trouble than it's worth, due to unpredictable
29109 sign extension and increased code size.
29113 \begin_layout Itemize
29114 Use unsigned when it is known in advance that the value is not going to
29116 This helps especially if you are doing division or multiplication, bit-shifting
29117 or are using an array index.
29120 \begin_layout Itemize
29121 NEVER jump into a LOOP.
29124 \begin_layout Itemize
29125 Declare the variables to be local
29126 \begin_inset LatexCommand \index{local variables}
29130 whenever possible, especially loop control variables (induction).
29133 \begin_layout Itemize
29134 Have a look at the assembly listing to get a
29135 \begin_inset Quotes sld
29139 \begin_inset Quotes srd
29142 for the code generation.
29145 \begin_layout Section
29146 Porting code from or to other compilers
29147 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29154 \begin_layout Itemize
29155 check whether endianness of the compilers differs and adapt where needed.
29158 \begin_layout Itemize
29159 check the device specific header files
29160 \begin_inset LatexCommand \index{Header files}
29165 \begin_inset LatexCommand \index{Include files}
29169 for compiler specific syntax.
29170 Eventually include the file <compiler.h
29171 \begin_inset LatexCommand \index{compiler.h (include file)}
29176 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29180 to allow using common header files.
29183 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29190 \begin_layout Itemize
29191 check whether the startup code contains the correct initialization (watchdog,
29195 \begin_layout Itemize
29196 check whether the sizes of short, int, long match.
29199 \begin_layout Itemize
29200 check if some 16 or 32 bit hardware registers require a specific addressing
29201 order (least significant or most significant byte first) and adapt if needed
29210 relate to time and not to lower/upper memory location here, so this is
29215 the same as endianness).
29218 \begin_layout Itemize
29219 check whether the keyword
29223 is used where needed.
29224 The compilers might differ in their optimization characteristics (as different
29225 versions of the same compiler might also use more clever optimizations
29226 this is good idea anyway).
29228 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29235 \begin_layout Itemize
29236 check that the compilers are not told to supress warnings.
29239 \begin_layout Itemize
29240 check and convert compiler specific extensions (interrupts, memory areas,
29244 \begin_layout Itemize
29245 check for differences in type promotion.
29246 Especially check for math operations on
29255 For the sake of C99 compatibility SDCC will probably promote these to
29259 more often than other compilers.
29260 Eventually insert explicit casts to
29269 Also check that the ~\InsetSpace ~
29271 \begin_inset LatexCommand \index{\~\/ Operator}
29278 \begin_inset LatexCommand \index{bit}
29284 variables, use the !\InsetSpace ~
29287 \begin_inset LatexCommand \ref{type promotion}
29292 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29299 \begin_layout Itemize
29300 check the assembly code generated for interrupt routines (f.e.
29301 for calls to possibly non-reentrant library functions).
29304 \begin_layout Itemize
29305 check whether timing loops result in proper timing (or preferably consider
29306 a rewrite of the code with timer based delays instead).
29309 \begin_layout Itemize
29310 check for differences in printf parameters (some compilers push (va_arg
29311 \begin_inset LatexCommand \index{vararg, va\_arg}
29315 ) char variables as
29319 others push them as
29325 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29332 \begin_layout Itemize
29333 check the resulting memory map
29334 \begin_inset LatexCommand \index{Memory map}
29339 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29340 ly idata, pdata, xdata).
29341 Eventually check if unexpected library functions are included.
29344 \begin_layout Section
29346 \begin_inset LatexCommand \index{Tools}
29350 included in the distribution
29353 \begin_layout Standard
29355 \begin_inset Tabular
29356 <lyxtabular version="3" rows="12" columns="3">
29358 <column alignment="left" valignment="top" leftline="true" width="0pt">
29359 <column alignment="left" valignment="top" leftline="true" width="0pt">
29360 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29361 <row topline="true" bottomline="true">
29362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29365 \begin_layout Standard
29373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29376 \begin_layout Standard
29384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29387 \begin_layout Standard
29396 <row topline="true">
29397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29400 \begin_layout Standard
29402 \begin_inset LatexCommand \index{uCsim}
29411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29414 \begin_layout Standard
29415 Simulator for various architectures
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29423 \begin_layout Standard
29430 <row topline="true">
29431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29434 \begin_layout Standard
29440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29443 \begin_layout Standard
29445 \begin_inset LatexCommand \index{Header files}
29450 \begin_inset LatexCommand \index{Include files}
29459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29462 \begin_layout Standard
29463 sdcc/support/scripts
29469 <row topline="true">
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29473 \begin_layout Standard
29479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29482 \begin_layout Standard
29483 header file conversion
29488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29491 \begin_layout Standard
29492 sdcc/support/scripts
29498 <row topline="true">
29499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29502 \begin_layout Standard
29508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29511 \begin_layout Standard
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29520 \begin_layout Standard
29536 <row topline="true">
29537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29540 \begin_layout Standard
29546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29549 \begin_layout Standard
29555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29558 \begin_layout Standard
29574 <row topline="true">
29575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29578 \begin_layout Standard
29584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29587 \begin_layout Standard
29593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29596 \begin_layout Standard
29612 <row topline="true">
29613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29616 \begin_layout Standard
29622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29625 \begin_layout Standard
29631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29634 \begin_layout Standard
29650 <row topline="true">
29651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29654 \begin_layout Standard
29660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29663 \begin_layout Standard
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29672 \begin_layout Standard
29688 <row topline="true">
29689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29692 \begin_layout Standard
29698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29701 \begin_layout Standard
29707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29710 \begin_layout Standard
29726 <row topline="true">
29727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29730 \begin_layout Standard
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29739 \begin_layout Standard
29745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29748 \begin_layout Standard
29764 <row topline="true" bottomline="true">
29765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29768 \begin_layout Standard
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29777 \begin_layout Standard
29779 \begin_inset LatexCommand \index{packihx (tool)}
29788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29791 \begin_layout Standard
29816 \begin_layout Section
29818 \begin_inset LatexCommand \index{Documentation}
29822 included in the distribution
29825 \begin_layout Standard
29827 \begin_inset Tabular
29828 <lyxtabular version="3" rows="10" columns="2">
29830 <column alignment="block" valignment="top" leftline="true" width="40col%">
29831 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29832 <row topline="true" bottomline="true" endhead="true">
29833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29836 \begin_layout Standard
29844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29847 \begin_layout Standard
29850 Filename / Where to get
29856 <row topline="true">
29857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29860 \begin_layout Standard
29861 SDCC Compiler User Guide
29866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29869 \begin_layout Standard
29870 You're reading it right now
29882 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29892 <row topline="true">
29893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29896 \begin_layout Standard
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29905 \begin_layout Standard
29918 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29928 <row topline="true">
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29932 \begin_layout Standard
29934 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29939 \begin_inset LatexCommand \index{Assembler documentation}
29946 \begin_inset LatexCommand \index{aslink}
29951 \begin_inset LatexCommand \index{Linker documentation}
29960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29963 \begin_layout Standard
29964 sdcc/as/doc/asxhtm.html
29976 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29986 <row topline="true">
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29990 \begin_layout Standard
29991 SDCC regression test
29992 \begin_inset LatexCommand \index{Regression test}
30001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30004 \begin_layout Standard
30005 sdcc/doc/test_suite_spec.pdf
30017 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30027 <row topline="true">
30028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30031 \begin_layout Standard
30037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30040 \begin_layout Standard
30053 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30063 <row topline="true">
30064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30067 \begin_layout Standard
30068 Notes on debugging with SDCDB
30069 \begin_inset LatexCommand \index{SDCDB (debugger)}
30078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30081 \begin_layout Standard
30082 sdcc/debugger/README
30094 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30104 <row topline="true">
30105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30108 \begin_layout Standard
30110 \begin_inset LatexCommand \index{uCsim}
30114 Software simulator for microcontrollers
30119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30122 \begin_layout Standard
30152 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30162 <row topline="true">
30163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30166 \begin_layout Standard
30167 Temporary notes on the pic16
30168 \begin_inset LatexCommand \index{PIC16}
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30180 \begin_layout Standard
30181 sdcc/src/pic16/NOTES
30193 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30203 <row topline="true" bottomline="true">
30204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30207 \begin_layout Standard
30208 SDCC internal documentation (debugging file format)
30213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30216 \begin_layout Standard
30246 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30265 \begin_layout Section
30266 Related open source tools
30267 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30272 \begin_inset LatexCommand \index{Related tools}
30279 \begin_layout Standard
30281 \begin_inset Tabular
30282 <lyxtabular version="3" rows="14" columns="3">
30284 <column alignment="left" valignment="top" leftline="true" width="0pt">
30285 <column alignment="block" valignment="top" leftline="true" width="30line%">
30286 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30287 <row topline="true" bottomline="true">
30288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30291 \begin_layout Standard
30299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30302 \begin_layout Standard
30310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30313 \begin_layout Standard
30322 <row topline="true">
30323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30326 \begin_layout Standard
30328 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30340 \begin_layout Standard
30346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30349 \begin_layout Standard
30350 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30360 <row topline="true">
30361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30364 \begin_layout Standard
30366 \begin_inset LatexCommand \index{gputils (pic tools)}
30375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30378 \begin_layout Standard
30384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30387 \begin_layout Standard
30388 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30398 <row topline="true">
30399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30402 \begin_layout Standard
30408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30411 \begin_layout Standard
30417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30420 \begin_layout Standard
30421 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30431 <row topline="true">
30432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30435 \begin_layout Standard
30441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30444 \begin_layout Standard
30445 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30454 \begin_layout Standard
30455 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30465 <row topline="true">
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30469 \begin_layout Standard
30471 \begin_inset LatexCommand \index{indent (source formatting tool)}
30480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30483 \begin_layout Standard
30484 Formats C source - Master of the white spaces
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30492 \begin_layout Standard
30493 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30503 <row topline="true">
30504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30507 \begin_layout Standard
30509 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30521 \begin_layout Standard
30522 Object file conversion, checksumming, ...
30527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30530 \begin_layout Standard
30531 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30541 <row topline="true">
30542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30545 \begin_layout Standard
30547 \begin_inset LatexCommand \index{objdump (tool)}
30556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30559 \begin_layout Standard
30560 Object file conversion, ...
30565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30568 \begin_layout Standard
30569 Part of binutils (should be there anyway)
30575 <row topline="true">
30576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30579 \begin_layout Standard
30585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30588 \begin_layout Standard
30589 8051 monitor (hex up-/download, single step, disassemble)
30594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30597 \begin_layout Standard
30598 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30608 <row topline="true">
30609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30612 \begin_layout Standard
30614 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30626 \begin_layout Standard
30627 Source code documentation system
30632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30635 \begin_layout Standard
30636 \begin_inset LatexCommand \url{http://www.doxygen.org}
30646 <row topline="true">
30647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30650 \begin_layout Standard
30656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30659 \begin_layout Standard
30660 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30668 \begin_layout Standard
30669 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30679 <row topline="true">
30680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30683 \begin_layout Standard
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30692 \begin_layout Standard
30693 8051 monitor (hex up-/download, single step, disassemble)
30698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30701 \begin_layout Standard
30702 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30712 <row topline="true">
30713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30716 \begin_layout Standard
30718 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30730 \begin_layout Standard
30731 Statically checks c sources (see
30732 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30744 \begin_layout Standard
30745 \begin_inset LatexCommand \url{http://www.splint.org}
30755 <row topline="true" bottomline="true">
30756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30759 \begin_layout Standard
30761 \begin_inset LatexCommand \index{DDD (debugger)}
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30773 \begin_layout Standard
30774 Debugger, serves nicely as GUI to SDCDB
30775 \begin_inset LatexCommand \index{SDCDB (debugger)}
30784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30787 \begin_layout Standard
30788 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30807 \begin_layout Section
30808 Related documentation / recommended reading
30811 \begin_layout Standard
30813 \begin_inset Tabular
30814 <lyxtabular version="3" rows="7" columns="3">
30816 <column alignment="left" valignment="top" leftline="true" width="0pt">
30817 <column alignment="left" valignment="top" leftline="true" width="0">
30818 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30819 <row topline="true" bottomline="true">
30820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30823 \begin_layout Standard
30831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30834 \begin_layout Standard
30842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30845 \begin_layout Standard
30854 <row topline="true">
30855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30858 \begin_layout Standard
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30876 \begin_layout Standard
30878 \begin_inset LatexCommand \index{C Reference card}
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30890 \begin_layout Standard
30891 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30901 <row topline="true">
30902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30905 \begin_layout Standard
30911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30914 \begin_layout Standard
30916 \begin_inset LatexCommand \index{C FAQ}
30925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30928 \begin_layout Standard
30929 \begin_inset LatexCommand \url{http://www.c-faq.com}
30939 <row topline="true">
30940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30943 \begin_layout Standard
30949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30952 \begin_layout Standard
30953 \begin_inset Quotes sld
30957 \begin_inset Quotes srd
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30968 \begin_layout Standard
30971 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30981 <row topline="true">
30982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30985 \begin_layout Standard
30991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_layout Standard
30995 \begin_inset Quotes sld
30998 Extensions for Embedded C
30999 \begin_inset Quotes srd
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31010 \begin_layout Standard
31013 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31023 <row topline="true">
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31027 \begin_layout Standard
31033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31036 \begin_layout Standard
31037 Latest datasheet of target CPU
31042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31045 \begin_layout Standard
31052 <row topline="true" bottomline="true">
31053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31056 \begin_layout Standard
31062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31065 \begin_layout Standard
31066 Revision history of datasheet
31071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31074 \begin_layout Standard
31090 \begin_layout Section
31091 Application notes specifically for SDCC
31094 \begin_layout Standard
31095 SDCC makes no claims about the completeness of this list and about up-to-datenes
31096 s or correctness of the application notes
31097 \begin_inset LatexCommand \index{Application notes}
31104 \begin_layout Standard
31108 \begin_inset Tabular
31109 <lyxtabular version="3" rows="7" columns="3">
31111 <column alignment="block" valignment="top" leftline="true" width="17col%">
31112 <column alignment="block" valignment="top" leftline="true" width="27col%">
31113 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31114 <row topline="true" bottomline="true">
31115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31118 \begin_layout Standard
31127 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31130 \begin_layout Standard
31139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31142 \begin_layout Standard
31152 <row topline="true">
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31156 \begin_layout Standard
31164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31167 \begin_layout Standard
31170 Using the SDCC Compiler for the DS80C400
31171 \begin_inset LatexCommand \index{DS80C400}
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31183 \begin_layout Standard
31186 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31196 <row topline="true">
31197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31200 \begin_layout Standard
31208 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31211 \begin_layout Standard
31214 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31215 \begin_inset LatexCommand \index{DS89C4x0}
31219 Family of Microcontrollers
31224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31227 \begin_layout Standard
31230 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31240 <row topline="true">
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31244 \begin_layout Standard
31247 Silicon Laboratories / Cygnal
31252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31255 \begin_layout Standard
31258 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31259 \begin_inset LatexCommand \index{IDE}
31268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31271 \begin_layout Standard
31274 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31284 <row topline="true">
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31288 \begin_layout Standard
31291 Ramtron / Goal Semiconductor
31296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31299 \begin_layout Standard
31302 Interfacing SDCC to Syn and Textpad
31307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31310 \begin_layout Standard
31313 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31323 <row topline="true">
31324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31327 \begin_layout Standard
31330 Ramtron / Goal Semiconductor
31335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31338 \begin_layout Standard
31341 Installing and Configuring SDCC and Crimson Editor
31346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31349 \begin_layout Standard
31352 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31362 <row topline="true" bottomline="true">
31363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31366 \begin_layout Standard
31374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31377 \begin_layout Standard
31380 MSC12xx Programming with SDCC
31385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31388 \begin_layout Standard
31391 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31408 \begin_layout Section
31412 \begin_layout Standard
31413 Some questions answered, some pointers given - it might be time to in turn
31421 \begin_layout Itemize
31422 can you solve your project with the selected microcontroller? Would you
31423 find out early or rather late that your target is too small/slow/whatever?
31424 Can you switch to a slightly better device if it doesn't fit?
31427 \begin_layout Itemize
31428 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31429 and/or another programming language be more adequate? Would an operating
31430 system on the target device help?
31433 \begin_layout Itemize
31434 if you solved the problem, will the marketing department be happy?
31437 \begin_layout Itemize
31438 if the marketing department is happy, will customers be happy?
31441 \begin_layout Itemize
31442 if you're the project manager, marketing department and maybe even the customer
31443 in one person, have you tried to see the project from the outside?
31446 \begin_layout Itemize
31447 is the project done if you think it is done? Or is just that other interface/pro
31448 tocol/feature/configuration/option missing? How about website, manual(s),
31449 internationali(z|s)ation, packaging, labels, 2nd source for components,
31450 electromagnetic compatability/interference, documentation for production,
31451 production test software, update mechanism, patent issues?
31454 \begin_layout Itemize
31455 is your project adequately positioned in that magic triangle: fame, fortune,
31459 \begin_layout Standard
31460 Maybe not all answers to these questions are known and some answers may
31465 , nevertheless knowing these questions may help you to avoid burnout
31469 \begin_layout Standard
31470 burnout is bad for electronic devices, programmers and motorcycle tyres
31476 Chances are you didn't want to hear some of them...
31479 \begin_layout Chapter
31481 \begin_inset LatexCommand \index{Support}
31488 \begin_layout Standard
31489 SDCC has grown to be a large project.
31490 The compiler alone (without the preprocessor, assembler and linker) is
31491 well over 150,000 lines of code (blank stripped).
31492 The open source nature of this project is a key to its continued growth
31494 You gain the benefit and support of many active software developers and
31496 Is SDCC perfect? No, that's why we need your help.
31497 The developers take pride in fixing reported bugs.
31498 You can help by reporting the bugs and helping other SDCC users.
31499 There are lots of ways to contribute, and we encourage you to take part
31500 in making SDCC a great software package.
31504 \begin_layout Standard
31505 The SDCC project is hosted on the SDCC sourceforge site at
31506 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31511 You'll find the complete set of mailing lists
31512 \begin_inset LatexCommand \index{Mailing list(s)}
31516 , forums, bug reporting system, patch submission
31517 \begin_inset LatexCommand \index{Patch submission}
31522 \begin_inset LatexCommand \index{download}
31526 area and Subversion code repository
31527 \begin_inset LatexCommand \index{Subversion code repository}
31534 \begin_layout Section
31536 \begin_inset LatexCommand \index{Bug reporting}
31541 \begin_inset LatexCommand \index{Reporting bugs}
31548 \begin_layout Standard
31549 The recommended way of reporting bugs is using the infrastructure of the
31551 You can follow the status of bug reports there and have an overview about
31555 \begin_layout Standard
31556 Bug reports are automatically forwarded to the developer mailing list and
31557 will be fixed ASAP.
31558 When reporting a bug, it is very useful to include a small test program
31559 (the smaller the better) which reproduces the problem.
31560 If you can isolate the problem by looking at the generated assembly code,
31561 this can be very helpful.
31562 Compiling your program with the -
31566 \begin_layout Standard
31576 \begin_inset LatexCommand \index{-\/-dumpall}
31580 option can sometimes be useful in locating optimization problems.
31581 When reporting a bug please make sure you:
31584 \begin_layout Enumerate
31585 Attach the code you are compiling with SDCC.
31589 \begin_layout Enumerate
31590 Specify the exact command you use to run SDCC, or attach your Makefile.
31594 \begin_layout Enumerate
31595 Specify the SDCC version (type "
31601 "), your platform, and operating system.
31605 \begin_layout Enumerate
31606 Provide an exact copy of any error message or incorrect output.
31610 \begin_layout Enumerate
31611 Put something meaningful in the subject of your message.
31614 \begin_layout Standard
31615 Please attempt to include these 5 important parts, as applicable, in all
31616 requests for support or when reporting any problems or bugs with SDCC.
31617 Though this will make your message lengthy, it will greatly improve your
31618 chance that SDCC users and developers will be able to help you.
31619 Some SDCC developers are frustrated by bug reports without code provided
31620 that they can use to reproduce and ultimately fix the problem, so please
31621 be sure to provide sample code if you are reporting a bug!
31624 \begin_layout Standard
31625 Please have a short check that you are using a recent version of SDCC and
31626 the bug is not yet known.
31627 This is the link for reporting bugs:
31628 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31633 With SDCC on average having more than 200 downloads
31634 \begin_inset LatexCommand \index{download}
31638 on sourceforge per day
31642 \begin_layout Standard
31643 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31644 between 2002 and 2005.
31645 This does not include other methods of distribution.
31650 there must be some users.
31651 So it's not exactly easy to find a new bug.
31652 If you find one we need it:
31654 reporting bugs is good
31659 \begin_layout Section
31660 Requesting Features
31661 \begin_inset LatexCommand \label{sub:Requesting-Features}
31666 \begin_inset LatexCommand \index{Feature request}
31671 \begin_inset LatexCommand \index{Requesting features}
31678 \begin_layout Standard
31679 Like bug reports feature requests are forwarded to the developer mailing
31681 This is the link for requesting features:
31682 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31689 \begin_layout Section
31693 \begin_layout Standard
31694 Like bug reports contributed patches are forwarded to the developer mailing
31696 This is the link for submitting patches
31697 \begin_inset LatexCommand \index{Patch submission}
31702 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31709 \begin_layout Standard
31710 You need to specify some parameters to the
31714 command for the patches to be useful.
31715 If you modified more than one file a patch created f.e.
31720 \begin_inset Quotes sld
31723 diff -Naur unmodified_directory modified_directory >my_changes.patch
31724 \begin_inset Quotes srd
31730 will be fine, otherwise
31734 \begin_inset Quotes sld
31737 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31738 \begin_inset Quotes srd
31748 \begin_layout Section
31752 \begin_layout Standard
31753 These links should take you directly to the
31754 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31762 \begin_layout Standard
31763 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31764 automated messages (mid 2003)
31770 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31775 \begin_inset LatexCommand \index{Mailing list(s)}
31779 and forums are archived and searchable so if you are lucky someone already
31780 had a similar problem.
31781 While mails to the lists themselves are delivered promptly their web front
31782 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31783 if you're seriously using SDCC please consider subscribing to the lists.
31786 \begin_layout Section
31790 \begin_layout Standard
31791 You can follow the status of the Subversion version
31792 \begin_inset LatexCommand \index{version}
31796 of SDCC by watching the Changelog
31797 \begin_inset LatexCommand \index{Changelog}
31801 in the Subversion repository
31804 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31811 \begin_layout Section
31812 Subversion Source Code Repository
31815 \begin_layout Standard
31822 or the filenames of the snapshot versions of SDCC include date and its
31824 \begin_inset LatexCommand \index{Subversion code repository}
31829 Subversion allows to download the source of recent or previous versions
31831 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31835 (by number or by date).
31836 An on-line source code browser and detailled instructions are also available
31838 SDCC versions starting from 1999 up to now are available (currently the
31839 versions prior to the conversion from cvs
31840 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31844 to Subversion (April 2006) are either by accessible by Subversion or by
31848 \begin_layout Section
31850 \begin_inset LatexCommand \index{Release policy}
31857 \begin_layout Standard
31858 Historically there often were long delays between official releases and
31859 the sourceforge download area tends to get not updated at all.
31860 Excuses in the past might have referred to problems with live range analysis,
31861 but as this was fixed a while ago, the current problem is that another
31862 excuse has to be found.
31863 Kidding aside, we have to get better there! On the other hand there are
31864 daily snapshots available at
31865 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31869 , and you can always build the very last version (hopefully with many bugs
31870 fixed, and features added) from the source code available at
31871 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31877 \begin_inset LatexCommand \index{wiki}
31882 \begin_inset LatexCommand \index{Release wiki}
31887 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31891 also holds some information about past and future releases.
31894 \begin_layout Section
31896 \begin_inset LatexCommand \index{Examples}
31903 \begin_layout Standard
31904 You'll find some small examples in the directory
31906 sdcc/device/examples/.
31909 More examples and libraries are available at
31911 The SDCC Open Knowledge Resource
31912 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31919 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31926 \begin_layout Standard
31927 \begin_inset Note Note
31930 \begin_layout Standard
31931 I did insert a reference to Paul's web site here although it seems rather
31932 dedicated to a specific 8032 board (I think it's okay because it f.e.
31933 shows LCD/Harddisc interface and has a free 8051 monitor.
31934 Independent 8032 board vendors face hard competition of heavily subsidized
31935 development boards anyway).
31938 \begin_layout Standard
31939 Maybe we should include some links to real world applications.
31940 Preferably pointer to pointers (one for each architecture) so this stays
31949 \begin_layout Section
31951 \begin_inset LatexCommand \label{sec:Quality-control}
31956 \begin_inset LatexCommand \index{Quality control}
31963 \begin_layout Standard
31964 The compiler is passed through snaphot build compile and build checks.
31970 \begin_inset LatexCommand \index{Regression test}
31974 check that SDCC itself compiles flawlessly on several host platforms (i386,
31975 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
31976 the quality of the code generated by SDCC by running the code for several
31977 target platforms through simulators.
31978 The regression test suite comprises more than 100 files which expand to
31979 more than 500 test cases which include more than 4500 tests.
31980 The results of these tests are published daily on SDCC's snapshot page
31981 (click on the red or green symbols on the right side of
31982 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
31989 \begin_layout Standard
31990 There is a separate document
31993 \begin_inset LatexCommand \index{Test suite}
32000 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32004 about the regression test suite.
32007 \begin_layout Standard
32008 You'll find the test code in the directory
32010 sdcc/support/regression
32013 You can run these tests manually by running
32017 in this directory (or f.e.
32022 \begin_inset Quotes sld
32026 \begin_inset Quotes srd
32032 if you don't want to run the complete tests).
32033 The test code might also be interesting if you want to look for examples
32034 \begin_inset LatexCommand \index{Examples}
32038 checking corner cases of SDCC or if you plan to submit patches
32039 \begin_inset LatexCommand \index{Patch submission}
32046 \begin_layout Standard
32047 The 14bit pic port uses a different set of regression tests
32048 \begin_inset LatexCommand \index{Regression test (PIC14)}
32052 , you'll find them in the directory
32054 sdcc/src/regression
32059 \begin_layout Section
32060 Use of SDCC in Education
32063 \begin_layout Standard
32072 \begin_layout Standard
32073 the phrase "use in education" might evoke the association "
32077 fit for use in education".
32078 This connotation is not intended but nevertheless risked as the licensing
32079 of SDCC makes it difficult to offer educational discounts
32085 If your rationales are to:
32088 \begin_layout Enumerate
32089 give students a chance to understand the
32093 steps of code generation
32096 \begin_layout Enumerate
32097 have a curriculum that can be extended for years.
32098 Then you could use an fpga board as target and your curriculum will seamlessly
32099 extend from logic synthesis (
32100 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32105 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32109 ), over assembly programming, to C to FPGA compilers (
32110 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32117 \begin_layout Enumerate
32118 be able to insert excursions about skills like using a revision control
32119 system, submitting/applying patches, using a type-setting (as opposed to
32120 word-processing) engine LyX/LaTeX, using
32121 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32126 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32130 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32131 Source Software, CPU simulation, compiler regression tests
32132 \begin_inset LatexCommand \index{Regression test}
32139 And if there should be a shortage of ideas then you can always point students
32140 to the ever-growing feature request list
32141 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32148 \begin_layout Enumerate
32149 not tie students to a specific host platform and instead allow them to use
32154 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32156 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32163 \begin_layout Enumerate
32164 not encourage students to use illegal copies of educational software
32167 \begin_layout Enumerate
32168 be immune to licensing/availability/price changes of the chosen tool chain
32171 \begin_layout Enumerate
32172 be able to change to a new target platform without having to adopt a new
32176 \begin_layout Enumerate
32177 have complete control over and insight into the tool chain
32180 \begin_layout Enumerate
32181 make your students aware about the pros and cons of open source software
32185 \begin_layout Enumerate
32186 give back to the public as you are probably at least partially publically
32190 \begin_layout Enumerate
32191 give students a chance to publically prove their skills and to possibly
32192 see a world wide impact
32195 \begin_layout Standard
32196 then SDCC is probably among the first choices.
32197 Well, probably SDCC might be the only choice.
32202 \begin_layout Chapter
32203 SDCC Technical Data
32206 \begin_layout Section
32208 \begin_inset LatexCommand \index{Optimizations}
32215 \begin_layout Standard
32216 SDCC performs a host of standard optimizations in addition to some MCU specific
32221 \begin_layout Subsection
32222 Sub-expression Elimination
32223 \begin_inset LatexCommand \index{Subexpression elimination}
32230 \begin_layout Standard
32231 The compiler does local and
32250 \begin_layout Verse
32258 \begin_layout Standard
32259 will be translated to
32262 \begin_layout Verse
32272 \begin_layout Standard
32273 Some subexpressions are not as obvious as the above example, e.g.:
32276 \begin_layout Verse
32284 \begin_layout Standard
32285 In this case the address arithmetic a->b[i] will be computed only once;
32286 the equivalent code in C would be.
32289 \begin_layout Verse
32299 \begin_layout Standard
32300 The compiler will try to keep these temporary variables in registers.
32303 \begin_layout Subsection
32304 Dead-Code Elimination
32305 \begin_inset LatexCommand \index{Dead-code elimination}
32312 \begin_layout Verse
32327 i = 1; \InsetSpace ~
32336 global = 1;\InsetSpace ~
32350 global = 3;\InsetSpace ~
32356 \begin_layout Standard
32360 \begin_layout Verse
32376 \begin_layout Subsection
32378 \begin_inset LatexCommand \index{Copy propagation}
32385 \begin_layout Verse
32409 \begin_layout Standard
32413 \begin_layout Verse
32437 \begin_layout Standard
32438 Note: the dead stores created by this copy propagation will be eliminated
32439 by dead-code elimination.
32442 \begin_layout Subsection
32444 \begin_inset LatexCommand \index{Loop optimization}
32449 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32456 \begin_layout Standard
32457 Two types of loop optimizations are done by SDCC
32465 of loop induction variables.
32466 In addition to the strength reduction the optimizer marks the induction
32467 variables and the register allocator tries to keep the induction variables
32468 in registers for the duration of the loop.
32469 Because of this preference of the register allocator
32470 \begin_inset LatexCommand \index{Register allocation}
32474 , loop induction optimization causes an increase in register pressure, which
32475 may cause unwanted spilling of other temporary variables into the stack
32476 \begin_inset LatexCommand \index{stack}
32481 The compiler will generate a warning message when it is forced to allocate
32482 extra space either on the stack or data space.
32483 If this extra space allocation is undesirable then induction optimization
32484 can be eliminated either for the entire source file (with -
32488 \begin_layout Standard
32497 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32499 \begin_inset LatexCommand \index{\#pragma noinduction}
32510 \begin_layout Verse
32513 for (i = 0 ; i < 100 ; i ++)
32522 \begin_layout Standard
32526 \begin_layout Verse
32531 for (i = 0; i < 100; i++)
32540 \begin_layout Standard
32541 As mentioned previously some loop invariants are not as apparent, all static
32542 address computations are also moved out of the loop.
32547 \begin_inset LatexCommand \index{Strength reduction}
32551 , this optimization substitutes an expression by a cheaper expression:
32554 \begin_layout Verse
32557 for (i=0;i < 100; i++)
32566 \begin_layout Standard
32570 \begin_layout Verse
32577 for (i=0;i< 100;i++) {
32583 ar[itemp1] = itemp2;
32601 \begin_layout Standard
32602 The more expensive multiplication
32603 \begin_inset LatexCommand \index{Multiplication}
32607 is changed to a less expensive addition.
32610 \begin_layout Subsection
32612 \begin_inset LatexCommand \index{Loop reversing}
32619 \begin_layout Standard
32620 This optimization is done to reduce the overhead of checking loop boundaries
32621 for every iteration.
32622 Some simple loops can be reversed and implemented using a
32623 \begin_inset Quotes eld
32626 decrement and jump if not zero
32627 \begin_inset Quotes erd
32631 SDCC checks for the following criterion to determine if a loop is reversible
32632 (note: more sophisticated compilers use data-dependency analysis to make
32633 this determination, SDCC uses a more simple minded analysis).
32636 \begin_layout Itemize
32637 The 'for' loop is of the form
32643 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32653 \begin_layout Itemize
32654 The <for body> does not contain
32655 \begin_inset Quotes eld
32659 \begin_inset Quotes erd
32663 \begin_inset Quotes erd
32669 \begin_layout Itemize
32670 All goto's are contained within the loop.
32673 \begin_layout Itemize
32674 No function calls within the loop.
32677 \begin_layout Itemize
32678 The loop control variable <sym> is not assigned any value within the loop
32681 \begin_layout Itemize
32682 The loop control variable does NOT participate in any arithmetic operation
32686 \begin_layout Itemize
32687 There are NO switch statements in the loop.
32690 \begin_layout Subsection
32691 Algebraic Simplifications
32694 \begin_layout Standard
32695 SDCC does numerous algebraic simplifications, the following is a small sub-set
32696 of these optimizations.
32699 \begin_layout Verse
32702 i = j + 0;\InsetSpace ~
32706 /* changed to: */\InsetSpace ~
32712 i /= 2;\InsetSpace ~
32719 /* changed to: */\InsetSpace ~
32726 = j - j;\InsetSpace ~
32730 /* changed to: */\InsetSpace ~
32736 i = j / 1;\InsetSpace ~
32740 /* changed to: */\InsetSpace ~
32747 \begin_layout Standard
32748 Note the subexpressions
32749 \begin_inset LatexCommand \index{Subexpression}
32753 given above are generally introduced by macro expansions or as a result
32754 of copy/constant propagation.
32757 \begin_layout Subsection
32758 'switch' Statements
32759 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32764 \begin_inset LatexCommand \index{switch statement}
32771 \begin_layout Standard
32772 SDCC can optimize switch statements to jump tables
32773 \begin_inset LatexCommand \index{jump tables}
32778 It makes the decision based on an estimate of the generated code size.
32779 SDCC is quite liberal in the requirements for jump table generation:
32782 \begin_layout Itemize
32783 The labels need not be in order, and the starting number need not be one
32784 or zero, the case labels are in numerical sequence or not too many case
32785 labels are missing.
32789 \begin_layout Verse
32792 switch(i) {\InsetSpace ~
32823 case 4: ...\InsetSpace ~
32855 case 5: ...\InsetSpace ~
32887 case 3: ...\InsetSpace ~
32918 case 6: ...\InsetSpace ~
32950 case 7: ...\InsetSpace ~
32982 case 8: ...\InsetSpace ~
33014 case 9: ...\InsetSpace ~
33046 case 10: ...\InsetSpace ~
33077 case 11: ...\InsetSpace ~
33144 \begin_layout Standard
33145 Both the above switch statements will be implemented using a jump-table.
33146 The example to the right side is slightly more efficient as the check for
33147 the lower boundary of the jump-table is not needed.
33151 \begin_layout Itemize
33152 The number of case labels is not larger than supported by the target architectur
33156 \begin_layout Itemize
33157 If the case labels are not in numerical sequence ('gaps' between cases)
33158 SDCC checks whether a jump table with additionally inserted dummy cases
33159 is still attractive.
33163 \begin_layout Itemize
33164 If the starting number is not zero and a check for the lower boundary of
33165 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33170 \begin_layout Standard
33171 Switch statements which have large gaps in the numeric sequence or those
33172 that have too many case labels can be split into more than one switch statement
33173 for efficient code generation, e.g.:
33176 \begin_layout Verse
33254 \begin_layout Standard
33255 If the above switch statement is broken down into two switch statements
33258 \begin_layout Verse
33301 \begin_layout Standard
33305 \begin_layout Verse
33348 \begin_layout Standard
33349 then both the switch statements will be implemented using jump-tables whereas
33350 the unmodified switch statement will not be.
33353 \begin_layout Standard
33354 \begin_inset Note Note
33357 \begin_layout Standard
33358 There might be reasons which SDCC cannot know about to either favour or
33359 not favour jump tables.
33360 If the target system has to be as quick for the last switch case as for
33361 the first (pro jump table), or if the switch argument is known to be zero
33362 in the majority of the cases (contra jump table).
33370 \begin_layout Standard
33371 The pragma nojtbound
33372 \begin_inset LatexCommand \index{\#pragma nojtbound}
33376 can be used to turn off checking the
33389 It has no effect if a default label is supplied.
33390 Use of this pragma is dangerous: if the switch
33391 \begin_inset LatexCommand \index{switch statement}
33395 argument is not matched by a case statement the processor will happily
33399 \begin_layout Subsection
33400 Bit-shifting Operations
33401 \begin_inset LatexCommand \index{Bit shifting}
33408 \begin_layout Standard
33409 Bit shifting is one of the most frequently used operation in embedded programmin
33411 SDCC tries to implement bit-shift operations in the most efficient way
33415 \begin_layout Verse
33428 \begin_layout Standard
33429 generates the following code:
33432 \begin_layout Verse
33447 \begin_layout Standard
33448 In general SDCC will never setup a loop if the shift count is known.
33452 \begin_layout Verse
33465 \begin_layout Standard
33469 \begin_layout Verse
33493 \begin_layout Subsection
33495 \begin_inset LatexCommand \index{Bit rotation}
33502 \begin_layout Standard
33503 A special case of the bit-shift operation is bit rotation
33504 \begin_inset LatexCommand \index{rotating bits}
33508 , SDCC recognizes the following expression to be a left bit-rotation:
33511 \begin_layout Verse
33519 char i;\InsetSpace ~
33530 /* unsigned is needed for rotation */
33535 i = ((i << 1) | (i >> 7));
33544 \begin_layout Standard
33545 will generate the following code:
33548 \begin_layout Verse
33565 \begin_layout Standard
33566 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33567 ns of this case will also be recognized as bit-rotation, i.e.:
33570 \begin_layout Verse
33573 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33576 \begin_layout Subsection
33577 Nibble and Byte Swapping
33580 \begin_layout Standard
33581 Other special cases of the bit-shift operations are nibble or byte swapping
33582 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33586 , SDCC recognizes the following expressions:
33589 \begin_layout Verse
33610 i = ((i << 4) | (i >> 4));
33616 j = ((j << 8) | (j >> 8));
33619 \begin_layout Standard
33620 and generates a swap instruction for the nibble swapping
33621 \begin_inset LatexCommand \index{Nibble swapping}
33625 or move instructions for the byte swapping
33626 \begin_inset LatexCommand \index{Byte swapping}
33632 \begin_inset Quotes sld
33636 \begin_inset Quotes srd
33639 example can be used to convert from little to big-endian or vice versa.
33640 If you want to change the endianness of a
33644 integer you have to cast to
33651 \begin_layout Standard
33652 Note that SDCC stores numbers in little-endian
33656 \begin_layout Standard
33657 Usually 8-bit processors don't care much about endianness.
33658 This is not the case for the standard 8051 which only has an instruction
33664 \begin_inset LatexCommand \index{DPTR}
33672 so little-endian is the more efficient byte order.
33678 \begin_inset LatexCommand \index{little-endian}
33683 \begin_inset LatexCommand \index{Endianness}
33688 lowest order first).
33691 \begin_layout Subsection
33693 \begin_inset LatexCommand \index{Highest Order Bit}
33698 \begin_inset LatexCommand \index{Any Order Bit}
33705 \begin_layout Standard
33706 It is frequently required to obtain the highest order bit of an integral
33707 type (long, int, short or char types).
33708 Also obtaining any other order bit is not uncommon.
33709 SDCC recognizes the following expressions to yield the highest order bit
33710 and generates optimized code for it, e.g.:
33713 \begin_layout Verse
33724 unsigned char hob1, aob1;
33728 bit hob2, hob3, aob2,
33738 hob1 = (gint >> 15) & 1;
33742 hob2 = (gint >> 15) & 1;
33746 hob3 = gint & 0x8000;
33751 aob1 = (gint >> 9) & 1;
33755 aob2 = (gint >> 8) & 1;
33759 aob3 = gint & 0x0800;
33769 \begin_layout Standard
33770 will generate the following code:
33773 \begin_layout Verse
33804 000A E5*01\InsetSpace ~
33831 000C 23\InsetSpace ~
33862 000D 54 01\InsetSpace ~
33890 000F F5*02\InsetSpace ~
33945 0011 E5*01\InsetSpace ~
33973 0013 33\InsetSpace ~
34003 0014 92*00\InsetSpace ~
34059 0016 E5*01\InsetSpace ~
34086 0018 33\InsetSpace ~
34116 0019 92*01\InsetSpace ~
34172 001B E5*01\InsetSpace ~
34231 001E 54 01\InsetSpace ~
34258 0020 F5*03\InsetSpace ~
34314 0022 E5*01\InsetSpace ~
34341 0024 13\InsetSpace ~
34371 0025 92*02\InsetSpace ~
34427 0027 E5*01\InsetSpace ~
34482 002B 92*03\InsetSpace ~
34510 \begin_layout Standard
34511 Other variations of these cases however will
34516 They are standard C expressions, so I heartily recommend these be the only
34517 way to get the highest order bit, (it is portable).
34518 Of course it will be recognized even if it is embedded in other expressions,
34522 \begin_layout Verse
34525 xyz = gint + ((gint >> 15) & 1);
34528 \begin_layout Standard
34529 will still be recognized.
34532 \begin_layout Subsection
34534 \begin_inset LatexCommand \index{Higher Order Byte}
34538 / Higher Order Word
34539 \begin_inset LatexCommand \index{Higher Order Word}
34546 \begin_layout Standard
34547 It is also frequently required to obtain a higher order byte or word of
34548 a larger integral type (long, int or short types).
34549 SDCC recognizes the following expressions to yield the higher order byte
34550 or word and generates optimized code for it, e.g.:
34553 \begin_layout Verse
34558 unsigned long int glong;
34566 unsigned char hob1,
34571 unsigned int how1, how2;
34580 hob1 = (gint >> 8) & 0xFF;
34584 hob2 = glong >> 24;
34588 how1 = (glong >> 16) & 0xFFFF;
34603 \begin_layout Standard
34604 will generate the following code:
34607 \begin_layout Verse
34638 0037 85*01*06\InsetSpace ~
34660 _foo_hob1_1_1,(_gint + 1)
34691 003A 85*05*07\InsetSpace ~
34713 _foo_hob2_1_1,(_glong + 3)
34743 003D 85*04*08\InsetSpace ~
34766 _foo_how1_1_1,(_glong + 2)
34768 0040 85*05*09\InsetSpace ~
34793 0043 85*03*0A\InsetSpace ~
34815 _foo_how2_1_1,(_glong + 1)
34817 0046 85*04*0B\InsetSpace ~
34840 (_foo_how2_1_1 + 1),(_glong + 2)
34843 \begin_layout Standard
34844 Again, variations of these cases may
34849 They are standard C expressions, so I heartily recommend these be the only
34850 way to get the higher order byte/word, (it is portable).
34851 Of course it will be recognized even if it is embedded in other expressions,
34855 \begin_layout Verse
34858 xyz = gint + ((gint >> 8) & 0xFF);
34861 \begin_layout Standard
34862 will still be recognized.
34865 \begin_layout Subsection
34867 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34872 \begin_inset LatexCommand \index{Peephole optimizer}
34879 \begin_layout Standard
34880 The compiler uses a rule based, pattern matching and re-writing mechanism
34881 for peep-hole optimization.
34886 a peep-hole optimizer by Christopher W.
34887 Fraser (cwfraser\InsetSpace ~
34890 A default set of rules are compiled into the compiler, additional rules
34891 may be added with the
34897 \begin_layout Standard
34907 \begin_inset LatexCommand \index{-\/-peep-file}
34914 The rule language is best illustrated with examples.
34917 \begin_layout Verse
34939 \begin_layout Standard
34940 The above rule will change the following assembly
34941 \begin_inset LatexCommand \index{Assembler routines}
34948 \begin_layout Verse
34956 \begin_layout Standard
34960 \begin_layout Verse
34966 \begin_layout Standard
34967 Note: All occurrences of a
34971 (pattern variable) must denote the same string.
34972 With the above rule, the assembly sequence:
34975 \begin_layout Verse
34983 \begin_layout Standard
34984 will remain unmodified.
34988 Other special case optimizations may be added by the
34995 \begin_layout Standard
35008 some variants of the 8051 MCU
35009 \begin_inset LatexCommand \index{MCS51 variants}
35022 The following two rules will change all
35039 \begin_layout Verse
35042 replace { lcall %1 } by { acall %1 }
35044 replace { ljmp %1 } by { ajmp %1 }
35047 \begin_layout Standard
35050 inline-assembler code
35052 is also passed through the peep hole optimizer, thus the peephole optimizer
35053 can also be used as an assembly level macro expander.
35054 The rules themselves are MCU dependent whereas the rule language infra-structur
35055 e is MCU independent.
35056 Peephole optimization rules for other MCU can be easily programmed using
35061 The syntax for a rule is as follows:
35064 \begin_layout Verse
35067 rule := replace [ restart ] '{' <assembly sequence> '
35105 <assembly sequence> '
35123 '}' [if <functionName> ] '
35128 \begin_layout Standard
35129 <assembly sequence> := assembly instruction (each instruction including
35130 labels must be on a separate line).
35134 The optimizer will apply to the rules
35135 one by one from the top in the sequence of their appearance, it will terminate
35136 when all rules are exhausted.
35137 If the 'restart' option is specified, then the optimizer will start matching
35138 the rules again from the top, this option for a rule is expensive (performance)
35139 , it is intended to be used in situations where a transformation will trigger
35140 the same rule again.
35141 An example of this (not a good one, it has side effects) is the following
35145 \begin_layout Verse
35165 \begin_layout Standard
35166 Note that the replace pattern cannot be a blank, but can be a comment line.
35167 Without the 'restart' option only the innermost 'pop' 'push' pair would
35168 be eliminated, i.e.:
35171 \begin_layout Verse
35183 \begin_layout Standard
35187 \begin_layout Verse
35197 \begin_layout Standard
35202 the restart option the rule will be applied again to the resulting code
35203 and then all the pop-push pairs will be eliminated to yield:
35206 \begin_layout Verse
35214 \begin_layout Standard
35215 A conditional function can be attached to a rule.
35216 Attaching rules are somewhat more involved, let me illustrate this with
35220 \begin_layout Verse
35244 \begin_layout Standard
35245 The optimizer does a look-up of a function name table defined in function
35250 in the source file SDCCpeeph.c, with the name
35255 If it finds a corresponding entry the function is called.
35256 Note there can be no parameters specified for these functions, in this
35261 is crucial, since the function
35265 expects to find the label in that particular variable (the hash table containin
35266 g the variable bindings is passed as a parameter).
35267 If you want to code more such functions, take a close look at the function
35268 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35269 Currently implemented are
35271 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35272 24bitMode, portIsDS390, 24bitModeAndPortDS390
35281 \begin_layout Standard
35282 I know this whole thing is a little kludgey, but maybe some day we will
35283 have some better means.
35284 If you are looking at this file, you will see the default rules that are
35285 compiled into the compiler, you can add your own rules in the default set
35286 there if you get tired of specifying the -
35290 \begin_layout Standard
35302 \begin_layout Section
35304 \begin_inset LatexCommand \index{ANSI-compliance}
35309 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35316 \begin_layout Standard
35317 The latest publically available version of the standard
35319 ISO/IEC 9899 - Programming languages - C
35321 should be available at:
35322 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35331 \begin_layout Standard
35332 Deviations from the compliance:
35335 \begin_layout Itemize
35336 functions are not reentrant
35337 \begin_inset LatexCommand \index{reentrant}
35341 unless explicitly declared as such or the
35347 \begin_layout Standard
35357 \begin_inset LatexCommand \index{-\/-stack-auto}
35363 command line option is specified.
35366 \begin_layout Itemize
35368 \begin_inset LatexCommand \index{struct}
35373 \begin_inset LatexCommand \index{union}
35377 cannot be assigned values directly, cannot be passed as function parameters
35378 or assigned to each other and cannot be a return value
35379 \begin_inset LatexCommand \index{return value}
35383 from a function, e.g.:
35387 \begin_layout Verse
35410 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35429 s parms) /* invalid in SDCC although allowed in ANSI */
35451 return rets; /* is invalid in SDCC although allowed in ANSI */
35457 \begin_layout Itemize
35458 initialization of structure arrays must be fully braced.
35462 \begin_layout Verse
35465 struct s { char x } a[] = {1, 2};\InsetSpace ~
35470 /* invalid in SDCC */
35473 } a[] = {{1}, {2}}; /* OK */
35477 \begin_layout Itemize
35479 \begin_inset LatexCommand \index{long long (not supported)}
35484 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35491 \begin_layout Itemize
35493 \begin_inset LatexCommand \index{double (not supported)}
35497 ' precision floating point
35498 \begin_inset LatexCommand \index{Floating point support}
35505 \begin_layout Itemize
35507 \begin_inset LatexCommand \index{K\&R style}
35511 function declarations are NOT allowed.
35515 \begin_layout Verse
35518 foo(i,j) /* this old style of function declarations */
35520 int i,j; /* are valid
35521 in ANSI but not valid in SDCC */
35536 \begin_layout Itemize
35537 Most enhancements in C99 are not supported, f.e.:
35541 \begin_layout Verse
35546 \begin_inset LatexCommand \index{inline (not supported)}
35552 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35558 can be used as a work around */
35566 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35570 \begin_layout Itemize
35571 Certain words that are valid identifiers in the standard may be reserved
35572 words in SDCC unless the
35578 \begin_layout Standard
35588 \begin_inset LatexCommand \index{-\/-std-c89}
35596 \begin_layout Standard
35606 \begin_inset LatexCommand \index{-\/-std-c99}
35612 command line options are used.
35613 These may include (depending on the selected processor): 'at', 'banked',
35614 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35615 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35616 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35618 Compliant equivalents of these keywords are always available in a form
35619 that begin with two underscores
35620 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35625 '__data' instead of 'data'.
35628 \begin_layout Section
35629 Cyclomatic Complexity
35630 \begin_inset LatexCommand \index{Cyclomatic complexity}
35637 \begin_layout Standard
35638 Cyclomatic complexity of a function is defined as the number of independent
35639 paths the program can take during execution of the function.
35640 This is an important number since it defines the number test cases you
35641 have to generate to validate the function.
35642 The accepted industry standard for complexity number is 10, if the cyclomatic
35643 complexity reported by SDCC exceeds 10 you should think about simplification
35644 of the function logic.
35645 Note that the complexity level is not related to the number of lines of
35646 code in a function.
35647 Large functions can have low complexity, and small functions can have large
35653 SDCC uses the following formula to compute the complexity:
35658 \begin_layout Standard
35659 complexity = (number of edges in control flow graph) - (number of nodes
35660 in control flow graph) + 2;
35664 Having said that the industry standard is 10,
35665 you should be aware that in some cases it be may unavoidable to have a
35666 complexity level of less than 10.
35667 For example if you have switch statement with more than 10 case labels,
35668 each case label adds one to the complexity level.
35669 The complexity level is by no means an absolute measure of the algorithmic
35670 complexity of the function, it does however provide a good starting point
35671 for which functions you might look at for further optimization.
35674 \begin_layout Section
35675 Retargetting for other Processors
35678 \begin_layout Standard
35679 The issues for retargetting the compiler are far too numerous to be covered
35681 What follows is a brief description of each of the seven phases of the
35682 compiler and its MCU dependency.
35685 \begin_layout Itemize
35686 Parsing the source and building the annotated parse tree.
35687 This phase is largely MCU independent (except for the language extensions).
35688 Syntax & semantic checks are also done in this phase, along with some initial
35689 optimizations like back patching labels and the pattern matching optimizations
35690 like bit-rotation etc.
35693 \begin_layout Itemize
35694 The second phase involves generating an intermediate code which can be easy
35695 manipulated during the later phases.
35696 This phase is entirely MCU independent.
35697 The intermediate code generation assumes the target machine has unlimited
35698 number of registers, and designates them with the name iTemp.
35699 The compiler can be made to dump a human readable form of the code generated
35704 \begin_layout Standard
35716 \begin_layout Itemize
35717 This phase does the bulk of the standard optimizations and is also MCU independe
35719 This phase can be broken down into several sub-phases:
35723 Break down intermediate
35724 code (iCode) into basic blocks.
35726 Do control flow & data flow analysis on the
35729 Do local common subexpression elimination, then global subexpressio
35732 Dead code elimination
35736 If loop optimizations
35737 caused any changes then do 'global subexpression elimination' and 'dead
35738 code elimination' again.
35741 \begin_layout Itemize
35742 This phase determines the live-ranges; by live range I mean those iTemp
35743 variables defined by the compiler that still survive after all the optimization
35745 Live range analysis
35746 \begin_inset LatexCommand \index{Live range analysis}
35750 is essential for register allocation, since these computation determines
35751 which of these iTemps will be assigned to registers, and for how long.
35754 \begin_layout Itemize
35755 Phase five is register allocation.
35756 There are two parts to this process.
35760 The first part I call 'register packing'
35761 (for lack of a better term).
35762 In this case several MCU specific expression folding is done to reduce
35767 The second part is more MCU independent and deals with
35768 allocating registers to the remaining live ranges.
35769 A lot of MCU specific code does creep into this phase because of the limited
35770 number of index registers available in the 8051.
35773 \begin_layout Itemize
35774 The Code generation phase is (unhappily), entirely MCU dependent and very
35775 little (if any at all) of this code can be reused for other MCU.
35776 However the scheme for allocating a homogenized assembler operand for each
35777 iCode operand may be reused.
35780 \begin_layout Itemize
35781 As mentioned in the optimization section the peep-hole optimizer is rule
35782 based system, which can reprogrammed for other MCUs.
35785 \begin_layout Standard
35786 More information is available in a wiki
35787 \begin_inset LatexCommand \index{wiki}
35792 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35796 ) and in the thread
35797 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35804 \begin_layout Chapter
35806 \begin_inset LatexCommand \index{Compiler internals}
35813 \begin_layout Section
35814 The anatomy of the compiler
35815 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35822 \begin_layout Standard
35825 This is an excerpt from an article published in Circuit Cellar Magazine
35831 It's a little outdated (the compiler is much more efficient now and user/develo
35832 per friendly), but pretty well exposes the guts of it all.
35838 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35839 It is fairly easy to retarget for other 8-bit MCU.
35840 Here we take a look at some of the internals of the compiler.
35844 \begin_layout Paragraph*
35846 \begin_inset LatexCommand \index{Parsing}
35853 \begin_layout Standard
35854 Parsing the input source file and creating an AST (Annotated Syntax Tree
35855 \begin_inset LatexCommand \index{Annotated syntax tree}
35860 This phase also involves propagating types (annotating each node of the
35861 parse tree with type information) and semantic analysis.
35862 There are some MCU specific parsing rules.
35863 For example the storage classes, the extended storage classes are MCU specific
35864 while there may be a xdata storage class for 8051 there is no such storage
35865 class for z80 or Atmel AVR.
35866 SDCC allows MCU specific storage class extensions, i.e.
35867 xdata will be treated as a storage class specifier when parsing 8051 C
35868 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35872 \begin_layout Paragraph*
35874 \begin_inset LatexCommand \index{iCode}
35881 \begin_layout Standard
35882 Intermediate code generation.
35883 In this phase the AST is broken down into three-operand form (iCode).
35884 These three operand forms are represented as doubly linked lists.
35885 ICode is the term given to the intermediate form generated by the compiler.
35886 ICode example section shows some examples of iCode generated for some simple
35887 C source functions.
35890 \begin_layout Paragraph*
35892 \begin_inset LatexCommand \index{Optimizations}
35899 \begin_layout Standard
35900 Bulk of the target independent optimizations is performed in this phase.
35901 The optimizations include constant propagation, common sub-expression eliminati
35902 on, loop invariant code movement, strength reduction of loop induction variables
35903 and dead-code elimination.
35906 \begin_layout Paragraph*
35907 Live range analysis
35908 \begin_inset LatexCommand \index{Live range analysis}
35915 \begin_layout Standard
35916 During intermediate code generation phase, the compiler assumes the target
35917 machine has infinite number of registers and generates a lot of temporary
35919 The live range computation determines the lifetime of each of these compiler-ge
35920 nerated temporaries.
35921 A picture speaks a thousand words.
35922 ICode example sections show the live range annotations for each of the
35924 It is important to note here, each iCode is assigned a number in the order
35925 of its execution in the function.
35926 The live ranges are computed in terms of these numbers.
35927 The from number is the number of the iCode which first defines the operand
35928 and the to number signifies the iCode which uses this operand last.
35931 \begin_layout Paragraph*
35932 Register Allocation
35933 \begin_inset LatexCommand \index{Register allocation}
35940 \begin_layout Standard
35941 The register allocation determines the type and number of registers needed
35943 In most MCUs only a few registers can be used for indirect addressing.
35944 In case of 8051 for example the registers R0 & R1 can be used to indirectly
35945 address the internal ram and DPTR to indirectly address the external ram.
35946 The compiler will try to allocate the appropriate register to pointer variables
35948 ICode example section shows the operands annotated with the registers assigned
35950 The compiler will try to keep operands in registers as much as possible;
35951 there are several schemes the compiler uses to do achieve this.
35952 When the compiler runs out of registers the compiler will check to see
35953 if there are any live operands which is not used or defined in the current
35954 basic block being processed, if there are any found then it will push that
35955 operand and use the registers in this block, the operand will then be popped
35956 at the end of the basic block.
35960 \begin_layout Standard
35961 There are other MCU specific considerations in this phase.
35962 Some MCUs have an accumulator; very short-lived operands could be assigned
35963 to the accumulator instead of a general-purpose register.
35966 \begin_layout Paragraph*
35970 \begin_layout Standard
35971 Figure II gives a table of iCode
35972 \begin_inset LatexCommand \index{iCode}
35976 operations supported by the compiler.
35977 The code generation involves translating these operations into corresponding
35978 assembly code for the processor.
35979 This sounds overly simple but that is the essence of code generation.
35980 Some of the iCode operations are generated on a MCU specific manner for
35981 example, the z80 port does not use registers to pass parameters so the
35982 SEND and RECV iCode operations will not be generated, and it also does
35983 not support JUMPTABLES.
35989 \begin_layout Standard
35993 \begin_inset Tabular
35994 <lyxtabular version="3" rows="39" columns="4">
35995 <features islongtable="true" headBottomDL="true">
35996 <column alignment="block" valignment="top" leftline="true" width="13col%">
35997 <column alignment="left" valignment="top" leftline="true" width="13col%">
35998 <column alignment="block" valignment="top" leftline="true" width="22col%">
35999 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36000 <row topline="true" bottomline="true" endhead="true">
36001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36004 \begin_layout Standard
36010 \begin_inset LatexCommand \index{iCode}
36019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36022 \begin_layout Standard
36030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36033 \begin_layout Standard
36041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36044 \begin_layout Standard
36053 <row topline="true">
36054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36057 \begin_layout Standard
36065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36068 \begin_layout Standard
36071 IC_LEFT() IC_RESULT()
36076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36079 \begin_layout Standard
36087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36090 \begin_layout Standard
36093 IC_RESULT = ! IC_LEFT;
36099 <row topline="true">
36100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36103 \begin_layout Standard
36111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36114 \begin_layout Standard
36117 IC_LEFT() IC_RESULT()
36122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36125 \begin_layout Standard
36128 Bitwise complement of
36133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36136 \begin_layout Standard
36139 IC_RESULT = ~IC_LEFT;
36145 <row topline="true">
36146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36149 \begin_layout Standard
36157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36160 \begin_layout Standard
36163 IC_LEFT() IC_RESULT()
36168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36171 \begin_layout Standard
36174 Rotate right with carry
36179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36182 \begin_layout Standard
36185 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36191 <row topline="true">
36192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36195 \begin_layout Standard
36203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36206 \begin_layout Standard
36209 IC_LEFT() IC_RESULT()
36214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36217 \begin_layout Standard
36220 Rotate left with carry
36225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36228 \begin_layout Standard
36231 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36237 <row topline="true">
36238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36241 \begin_layout Standard
36249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36252 \begin_layout Standard
36255 IC_LEFT() IC_RESULT()
36260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36263 \begin_layout Standard
36266 Get the highest order bit of IC_LEFT
36271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36274 \begin_layout Standard
36277 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36283 <row topline="true">
36284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36287 \begin_layout Standard
36295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36298 \begin_layout Standard
36301 IC_LEFT() IC_RESULT()
36306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36309 \begin_layout Standard
36317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36320 \begin_layout Standard
36323 IC_RESULT = - IC_LEFT;
36329 <row topline="true">
36330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36333 \begin_layout Standard
36341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36344 \begin_layout Standard
36352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36355 \begin_layout Standard
36358 Push the operand into stack
36363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36366 \begin_layout Standard
36375 <row topline="true">
36376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36379 \begin_layout Standard
36387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36390 \begin_layout Standard
36398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36401 \begin_layout Standard
36404 Pop the operand from the stack
36409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36412 \begin_layout Standard
36421 <row topline="true">
36422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36425 \begin_layout Standard
36433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36436 \begin_layout Standard
36439 IC_LEFT() IC_RESULT()
36444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36447 \begin_layout Standard
36450 Call the function represented by IC_LEFT
36455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36458 \begin_layout Standard
36461 IC_RESULT = IC_LEFT();
36467 <row topline="true">
36468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36471 \begin_layout Standard
36479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36482 \begin_layout Standard
36485 IC_LEFT() IC_RESULT()
36490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36493 \begin_layout Standard
36496 Call via function pointer
36501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36504 \begin_layout Standard
36507 IC_RESULT = (*IC_LEFT)();
36513 <row topline="true">
36514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36517 \begin_layout Standard
36525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36528 \begin_layout Standard
36536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36539 \begin_layout Standard
36542 Return the value in operand IC_LEFT
36547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36550 \begin_layout Standard
36559 <row topline="true">
36560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36563 \begin_layout Standard
36571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36574 \begin_layout Standard
36582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36585 \begin_layout Standard
36593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36596 \begin_layout Standard
36605 <row topline="true">
36606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36609 \begin_layout Standard
36617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36620 \begin_layout Standard
36628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36631 \begin_layout Standard
36639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36642 \begin_layout Standard
36651 <row topline="true">
36652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36655 \begin_layout Standard
36663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36666 \begin_layout Standard
36669 IC_LEFT() IC_RIGHT() IC_RESULT()
36674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36677 \begin_layout Standard
36685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36688 \begin_layout Standard
36691 IC_RESULT = IC_LEFT + IC_RIGHT
36697 <row topline="true">
36698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36701 \begin_layout Standard
36709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36712 \begin_layout Standard
36715 IC_LEFT() IC_RIGHT() IC_RESULT()
36720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36723 \begin_layout Standard
36731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36734 \begin_layout Standard
36737 IC_RESULT = IC_LEFT - IC_RIGHT
36743 <row topline="true">
36744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36747 \begin_layout Standard
36755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36758 \begin_layout Standard
36761 IC_LEFT() IC_RIGHT() IC_RESULT()
36766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36769 \begin_layout Standard
36777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36780 \begin_layout Standard
36783 IC_RESULT = IC_LEFT * IC_RIGHT;
36789 <row topline="true">
36790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36793 \begin_layout Standard
36801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36804 \begin_layout Standard
36807 IC_LEFT() IC_RIGHT() IC_RESULT()
36812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36815 \begin_layout Standard
36823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36826 \begin_layout Standard
36829 IC_RESULT = IC_LEFT / IC_RIGHT;
36835 <row topline="true">
36836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36839 \begin_layout Standard
36847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36850 \begin_layout Standard
36853 IC_LEFT() IC_RIGHT() IC_RESULT()
36858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36861 \begin_layout Standard
36869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36872 \begin_layout Standard
36875 IC_RESULT = IC_LEFT % IC_RIGHT;
36881 <row topline="true">
36882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36885 \begin_layout Standard
36893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36896 \begin_layout Standard
36899 IC_LEFT() IC_RIGHT() IC_RESULT()
36904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36907 \begin_layout Standard
36915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36918 \begin_layout Standard
36921 IC_RESULT = IC_LEFT < IC_RIGHT;
36927 <row topline="true">
36928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36931 \begin_layout Standard
36939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36942 \begin_layout Standard
36945 IC_LEFT() IC_RIGHT() IC_RESULT()
36950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36953 \begin_layout Standard
36961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36964 \begin_layout Standard
36967 IC_RESULT = IC_LEFT > IC_RIGHT;
36973 <row topline="true">
36974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36977 \begin_layout Standard
36985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36988 \begin_layout Standard
36991 IC_LEFT() IC_RIGHT() IC_RESULT()
36996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36999 \begin_layout Standard
37007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37010 \begin_layout Standard
37013 IC_RESULT = IC_LEFT == IC_RIGHT;
37019 <row topline="true">
37020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37023 \begin_layout Standard
37031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37034 \begin_layout Standard
37037 IC_LEFT() IC_RIGHT() IC_RESULT()
37042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37045 \begin_layout Standard
37048 Logical and operation
37053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37056 \begin_layout Standard
37059 IC_RESULT = IC_LEFT && IC_RIGHT;
37065 <row topline="true">
37066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37069 \begin_layout Standard
37077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37080 \begin_layout Standard
37083 IC_LEFT() IC_RIGHT() IC_RESULT()
37088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37091 \begin_layout Standard
37094 Logical or operation
37099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37102 \begin_layout Standard
37105 IC_RESULT = IC_LEFT || IC_RIGHT;
37111 <row topline="true">
37112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37115 \begin_layout Standard
37123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37126 \begin_layout Standard
37129 IC_LEFT() IC_RIGHT() IC_RESULT()
37134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37137 \begin_layout Standard
37145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37148 \begin_layout Standard
37151 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37157 <row topline="true">
37158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37161 \begin_layout Standard
37169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37172 \begin_layout Standard
37175 IC_LEFT() IC_RIGHT() IC_RESULT()
37180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37183 \begin_layout Standard
37191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37194 \begin_layout Standard
37197 IC_RESULT = IC_LEFT | IC_RIGHT;
37203 <row topline="true">
37204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37207 \begin_layout Standard
37215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37218 \begin_layout Standard
37221 IC_LEFT() IC_RIGHT() IC_RESULT()
37226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37229 \begin_layout Standard
37237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37240 \begin_layout Standard
37243 IC_RESULT = IC_LEFT & IC_RIGHT;
37249 <row topline="true">
37250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37253 \begin_layout Standard
37261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37264 \begin_layout Standard
37267 IC_LEFT() IC_RIGHT() IC_RESULT()
37272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37275 \begin_layout Standard
37283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37286 \begin_layout Standard
37289 IC_RESULT = IC_LEFT << IC_RIGHT
37295 <row topline="true">
37296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37299 \begin_layout Standard
37307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37310 \begin_layout Standard
37313 IC_LEFT() IC_RIGHT() IC_RESULT()
37318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37321 \begin_layout Standard
37329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37332 \begin_layout Standard
37335 IC_RESULT = IC_LEFT >> IC_RIGHT
37341 <row topline="true">
37342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37345 \begin_layout Standard
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37358 \begin_layout Standard
37361 IC_LEFT() IC_RESULT()
37366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37369 \begin_layout Standard
37377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37380 \begin_layout Standard
37383 IC_RESULT = (*IC_LEFT);
37389 <row topline="true">
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37393 \begin_layout Standard
37401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37404 \begin_layout Standard
37407 IC_RIGHT() IC_RESULT()
37412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37415 \begin_layout Standard
37423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37426 \begin_layout Standard
37429 (*IC_RESULT) = IC_RIGHT;
37435 <row topline="true">
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37439 \begin_layout Standard
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37450 \begin_layout Standard
37453 IC_RIGHT() IC_RESULT()
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37461 \begin_layout Standard
37469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37472 \begin_layout Standard
37475 IC_RESULT = IC_RIGHT;
37481 <row topline="true">
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37485 \begin_layout Standard
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37496 \begin_layout Standard
37499 IC_COND IC_TRUE IC_LABEL
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37507 \begin_layout Standard
37511 If true label is present then jump to true label if condition is true else
37512 jump to false label if condition is false
37517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37520 \begin_layout Standard
37523 if (IC_COND) goto IC_TRUE;
37529 If (!IC_COND) goto IC_FALSE;
37535 <row topline="true">
37536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37539 \begin_layout Standard
37547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37550 \begin_layout Standard
37553 IC_LEFT() IC_RESULT()
37558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37561 \begin_layout Standard
37569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37572 \begin_layout Standard
37575 IC_RESULT = &IC_LEFT();
37581 <row topline="true">
37582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37585 \begin_layout Standard
37593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37596 \begin_layout Standard
37599 IC_JTCOND IC_JTLABELS
37604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37607 \begin_layout Standard
37610 Jump to list of labels depending on the value of JTCOND
37615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37618 \begin_layout Standard
37627 <row topline="true">
37628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37631 \begin_layout Standard
37639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37642 \begin_layout Standard
37645 IC_RIGHT() IC_LEFT() IC_RESULT()
37650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37653 \begin_layout Standard
37661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37664 \begin_layout Standard
37667 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37673 <row topline="true">
37674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37677 \begin_layout Standard
37685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37688 \begin_layout Standard
37696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37699 \begin_layout Standard
37702 This is used for passing parameters in registers;
37704 move IC_LEFT to the next
37705 available parameter register.
37710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37713 \begin_layout Standard
37722 <row topline="true">
37723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37726 \begin_layout Standard
37734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37737 \begin_layout Standard
37745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37748 \begin_layout Standard
37751 This is used for receiving parameters passed in registers;
37754 in the next parameter register to IC_RESULT
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37762 \begin_layout Standard
37771 <row topline="true" bottomline="true">
37772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37775 \begin_layout Standard
37779 (some more have been added)
37784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37787 \begin_layout Standard
37793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37796 \begin_layout Standard
37802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37805 \begin_layout Standard
37829 \begin_layout Standard
37830 \begin_inset Note Note
37833 \begin_layout Standard
37834 In the original article Figure II was announced to be downloadable on
37839 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37847 \begin_layout Paragraph*
37849 \begin_inset LatexCommand \index{iCode}
37856 \begin_layout Standard
37857 This section shows some details of iCode.
37858 The example C code does not do anything useful; it is used as an example
37859 to illustrate the intermediate code generated by the compiler.
37862 \begin_layout Verse
37872 /* This function does nothing useful.
37879 for the purpose of explaining iCode */
37882 short function (data
37891 short i=10; \InsetSpace ~
37893 /* dead initialization eliminated */
37899 /* dead initialization eliminated */
37927 /* compiler detects i,j to be induction
37932 for (i = 0, j = 10 ; i < 10 ; i++, j
37938 \begin_layout Standard
37961 mul += i * 3; \InsetSpace ~
37963 /* this multiplication remains */
37970 j * 3;\InsetSpace ~
37972 /* this multiplication changed to addition */
37986 \begin_layout Standard
37987 In addition to the operands each iCode contains information about the filename
37988 and line it corresponds to in the source file.
37989 The first field in the listing should be interpreted as follows:
37994 Filename(linenumber: iCode Execution sequence number : ICode hash table
37995 key : loop depth of the iCode).
38000 Then follows the human readable form of the ICode operation.
38001 Each operand of this triplet form can be of three basic types a) compiler
38002 generated temporary b) user defined variable c) a constant value.
38003 Note that local variables and parameters are replaced by compiler generated
38006 \begin_inset LatexCommand \index{Live range analysis}
38010 are computed only for temporaries (i.e.
38011 live ranges are not computed for global variables).
38013 \begin_inset LatexCommand \index{Register allocation}
38017 are allocated for temporaries only.
38018 Operands are formatted in the following manner:
38023 Operand Name [lr live-from : live-to ] { type information } [ registers
38029 As mentioned earlier the live ranges are computed in terms of the execution
38030 sequence number of the iCodes, for example
38032 the iTemp0 is live from (i.e.
38033 first defined in iCode with execution sequence number 3, and is last used
38034 in the iCode with sequence number 5).
38035 For induction variables such as iTemp21 the live range computation extends
38036 the lifetime from the start to the end of the loop.
38038 The register allocator
38039 used the live range information to allocate registers, the same registers
38040 may be used for different temporaries if their live ranges do not overlap,
38041 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38042 ranges do not overlap.
38043 In addition the allocator also takes into consideration the type and usage
38044 of a temporary, for example itemp6 is a pointer to near space and is used
38045 as to fetch data from (i.e.
38046 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38047 Some short lived temporaries are allocated to special registers which have
38048 meaning to the code generator e.g.
38049 iTemp13 is allocated to a pseudo register CC which tells the back end that
38050 the temporary is used only for a conditional jump the code generation makes
38051 use of this information to optimize a compare and jump ICode.
38055 \begin_inset LatexCommand \index{Loop optimization}
38059 performed by the compiler.
38060 It can detect induction variables iTemp21(i) and iTemp23(j).
38061 Also note the compiler does selective strength reduction
38062 \begin_inset LatexCommand \index{Strength reduction}
38067 the multiplication of an induction variable in line 18 (gint = j * 3) is
38068 changed to addition, a new temporary iTemp17 is allocated and assigned
38069 a initial value, a constant 3 is then added for each iteration of the loop.
38070 The compiler does not change the multiplication
38071 \begin_inset LatexCommand \index{Multiplication}
38075 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38078 Note the dead code elimination
38079 \begin_inset LatexCommand \index{Dead-code elimination}
38083 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38089 \begin_layout Standard
38092 Sample.c (5:1:0:0) _entry($9) :
38095 \begin_layout Standard
38098 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38101 \begin_layout Standard
38104 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38107 \begin_layout Standard
38110 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38113 \begin_layout Standard
38116 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38120 \begin_layout Standard
38123 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38126 \begin_layout Standard
38129 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38133 \begin_layout Standard
38136 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38139 \begin_layout Standard
38142 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38146 \begin_layout Standard
38149 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38153 \begin_layout Standard
38156 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38160 \begin_layout Standard
38163 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38167 \begin_layout Standard
38170 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38171 * int}[r0] + 0x2 {short}
38174 \begin_layout Standard
38177 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38180 \begin_layout Standard
38183 Sample.c(11:17:21:0)_whilebreak_0($3) :
38186 \begin_layout Standard
38189 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38192 \begin_layout Standard
38195 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38198 \begin_layout Standard
38201 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38204 \begin_layout Standard
38207 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38210 \begin_layout Standard
38213 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38216 \begin_layout Standard
38219 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38222 \begin_layout Standard
38225 Sample.c(15:24:26:1)_forcond_0($4) :
38228 \begin_layout Standard
38231 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38235 \begin_layout Standard
38238 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38241 \begin_layout Standard
38244 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38245 + ITemp21 [lr21:38]{short}[r4]
38248 \begin_layout Standard
38251 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38255 \begin_layout Standard
38258 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38259 + iTemp15 [lr29:30]{short}[r1]
38262 \begin_layout Standard
38265 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38269 \begin_layout Standard
38272 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38276 \begin_layout Standard
38279 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38283 \begin_layout Standard
38286 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38290 \begin_layout Standard
38293 Sample.c(19:38:47:1) goto _forcond_0($4)
38296 \begin_layout Standard
38299 Sample.c(19:39:48:0)_forbreak_0($7) :
38302 \begin_layout Standard
38305 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38306 + ITemp11 [lr19:40]{short}[r3]
38309 \begin_layout Standard
38312 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38315 \begin_layout Standard
38318 Sample.c(20:42:51:0)_return($8) :
38321 \begin_layout Standard
38324 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38330 Finally the code generated for this function:
38335 \begin_layout Standard
38341 \begin_layout Standard
38347 \begin_layout Standard
38355 \begin_layout Standard
38361 \begin_layout Standard
38369 \begin_layout Standard
38375 \begin_layout Standard
38378 ; ----------------------------------------------
38381 \begin_layout Standard
38384 ; function function
38387 \begin_layout Standard
38390 ; ----------------------------------------------
38393 \begin_layout Standard
38399 \begin_layout Standard
38402 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38405 \begin_layout Standard
38413 \begin_layout Standard
38416 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38419 \begin_layout Standard
38427 \begin_layout Standard
38430 ;_whilecontinue_0($1) :
38433 \begin_layout Standard
38439 \begin_layout Standard
38442 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38445 \begin_layout Standard
38448 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38451 \begin_layout Standard
38459 \begin_layout Standard
38467 \begin_layout Standard
38475 \begin_layout Standard
38483 \begin_layout Standard
38491 \begin_layout Standard
38499 \begin_layout Standard
38507 \begin_layout Standard
38513 \begin_layout Standard
38516 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38519 \begin_layout Standard
38527 \begin_layout Standard
38535 \begin_layout Standard
38538 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38541 \begin_layout Standard
38549 \begin_layout Standard
38557 \begin_layout Standard
38565 \begin_layout Standard
38573 \begin_layout Standard
38581 \begin_layout Standard
38589 \begin_layout Standard
38592 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38595 \begin_layout Standard
38603 \begin_layout Standard
38611 \begin_layout Standard
38619 \begin_layout Standard
38627 \begin_layout Standard
38635 \begin_layout Standard
38638 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38641 \begin_layout Standard
38649 \begin_layout Standard
38657 \begin_layout Standard
38665 \begin_layout Standard
38668 ; iTemp6 [lr5:16]{_near * int}[r0] =
38671 \begin_layout Standard
38674 ; iTemp6 [lr5:16]{_near * int}[r0] +
38677 \begin_layout Standard
38683 \begin_layout Standard
38691 \begin_layout Standard
38694 ; goto _whilecontinue_0($1)
38697 \begin_layout Standard
38705 \begin_layout Standard
38708 ; _whilebreak_0($3) :
38711 \begin_layout Standard
38717 \begin_layout Standard
38720 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38723 \begin_layout Standard
38731 \begin_layout Standard
38734 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38737 \begin_layout Standard
38745 \begin_layout Standard
38748 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38751 \begin_layout Standard
38759 \begin_layout Standard
38762 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38765 \begin_layout Standard
38773 \begin_layout Standard
38781 \begin_layout Standard
38784 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38787 \begin_layout Standard
38795 \begin_layout Standard
38803 \begin_layout Standard
38809 \begin_layout Standard
38815 \begin_layout Standard
38818 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38821 \begin_layout Standard
38824 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38827 \begin_layout Standard
38835 \begin_layout Standard
38843 \begin_layout Standard
38851 \begin_layout Standard
38859 \begin_layout Standard
38867 \begin_layout Standard
38873 \begin_layout Standard
38876 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38879 \begin_layout Standard
38882 ; iTemp21 [lr21:38]{short}[r4]
38885 \begin_layout Standard
38893 \begin_layout Standard
38901 \begin_layout Standard
38909 \begin_layout Standard
38912 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38915 \begin_layout Standard
38923 \begin_layout Standard
38931 \begin_layout Standard
38939 \begin_layout Standard
38947 \begin_layout Standard
38950 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
38953 \begin_layout Standard
38956 ; iTemp15 [lr29:30]{short}[r1]
38959 \begin_layout Standard
38967 \begin_layout Standard
38975 \begin_layout Standard
38978 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38981 \begin_layout Standard
38989 \begin_layout Standard
38997 \begin_layout Standard
39005 \begin_layout Standard
39013 \begin_layout Standard
39021 \begin_layout Standard
39029 \begin_layout Standard
39032 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39035 \begin_layout Standard
39043 \begin_layout Standard
39051 \begin_layout Standard
39059 \begin_layout Standard
39067 \begin_layout Standard
39075 \begin_layout Standard
39083 \begin_layout Standard
39086 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39089 \begin_layout Standard
39097 \begin_layout Standard
39100 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39103 \begin_layout Standard
39111 \begin_layout Standard
39116 cjne r5,#0xff,00104$
39119 \begin_layout Standard
39127 \begin_layout Standard
39130 ; goto _forcond_0($4)
39133 \begin_layout Standard
39141 \begin_layout Standard
39144 ; _forbreak_0($7) :
39147 \begin_layout Standard
39153 \begin_layout Standard
39156 ; ret iTemp24 [lr40:41]{short}
39159 \begin_layout Standard
39167 \begin_layout Standard
39175 \begin_layout Standard
39183 \begin_layout Standard
39189 \begin_layout Standard
39195 \begin_layout Standard
39205 \begin_layout Section
39206 A few words about basic block successors, predecessors and dominators
39209 \begin_layout Standard
39210 Successors are basic blocks
39211 \begin_inset LatexCommand \index{Basic blocks}
39215 that might execute after this basic block.
39217 Predecessors are basic blocks
39218 that might execute before reaching this basic block.
39220 Dominators are basic
39221 blocks that WILL execute before reaching this basic block.
39226 \begin_layout Standard
39230 \begin_layout Standard
39234 \begin_layout Standard
39242 \begin_layout Standard
39246 \begin_layout Standard
39254 \begin_layout Standard
39260 \begin_layout Standard
39261 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39264 \begin_layout Standard
39265 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39268 \begin_layout Standard
39269 c) domVect of [BB4] = BB1 ...
39270 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39274 \begin_layout Chapter
39278 \begin_layout Standard
39279 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39289 Thanks to all the other volunteer developers who have helped with coding,
39290 testing, web-page creation, distribution sets, etc.
39291 You know who you are :-)
39299 Also thanks to Sourceforge
39300 \begin_inset LatexCommand \url{http://www.sf.net}
39304 which has hosted the project since 1999 and donates significant download
39305 bandwidth and probably more than
39309 \begin_layout Standard
39316 CPU cycles per day.
39319 \begin_inset Note Note
39322 \begin_layout Standard
39323 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39324 minutes for (configure+make+regression test), and there is (i386, amd64,
39325 alpha, ppc64, (mingw32), sparc, Mac OS X).
39334 \begin_layout Standard
39335 This document was initially written by Sandeep Dutta
39338 \begin_layout Standard
39339 All product names mentioned herein may be trademarks
39340 \begin_inset LatexCommand \index{Trademarks}
39344 of their respective companies.
39348 \begin_layout Section*
39352 \begin_layout Standard
39353 To avoid confusion, the installation and building options for SDCC itself
39354 (chapter 2) are not part of the index.
39357 \begin_layout Standard
39358 \begin_inset LatexCommand \printindex{}