1 #LyX 1.4.2 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is a 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, the debugger
680 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
685 The latest version can be downloaded from
686 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
696 Please note: the compiler will probably always be some steps ahead of this
701 \begin_inset LatexCommand \index{Status of documentation}
709 \begin_layout Standard
710 Obviously this has pros and cons
718 \begin_layout Section
722 \begin_layout Standard
723 All packages used in this compiler system are
731 ; source code for all the sub-packages (pre-processor, assemblers, linkers
732 etc) is distributed with the package.
733 This documentation is maintained using a freeware word processor (LyX).
736 program is free software; you can redistribute it and/or modify it under
737 the terms of the GNU General Public License
738 \begin_inset LatexCommand \index{GNU General Public License, GPL}
742 as published by the Free Software Foundation; either version 2, or (at
743 your option) any later version.
744 This program is distributed in the hope that it will be useful, but WITHOUT
745 ANY WARRANTY; without even the implied warranty
746 \begin_inset LatexCommand \index{warranty}
750 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
751 See the GNU General Public License for more details.
752 You should have received a copy of the GNU General Public License along
753 with this program; if not, write to the Free Software Foundation, 59 Temple
754 Place - Suite 330, Boston, MA 02111-1307, USA.
755 In other words, you are welcome to use, share and improve this program.
756 You are forbidden to forbid anyone else to use, share and improve what
758 Help stamp out software-hoarding!
761 \begin_layout Section
762 Typographic conventions
763 \begin_inset LatexCommand \index{Typographic conventions}
770 \begin_layout Standard
771 Throughout this manual, we will use the following convention.
772 Commands you have to type in are printed in
780 Code samples are printed in
785 Interesting items and new terms are printed in
790 \begin_layout Section
792 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
796 with previous versions
797 \begin_inset LatexCommand \index{Compatibility with previous versions}
804 \begin_layout Standard
805 Newer versions have usually numerous bug fixes compared with the previous
807 But we also sometimes introduce some incompatibilities with older versions.
808 Not just for the fun of it, but to make the compiler more stable, efficient
810 \begin_inset LatexCommand \index{ANSI-compliance}
815 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
819 for ANSI-Compliance).
821 \begin_inset Note Note
824 \begin_layout Standard
825 It would be fine to add to each item, in which version was it changed.
835 \begin_layout Itemize
836 short is now equivalent to int (16 bits), it used to be equivalent to char
837 (8 bits) which is not ANSI compliant.
838 To maintain compatibility, old programs may be compiled using the --short-is-8b
839 its commandline option (see
840 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
847 \begin_layout Itemize
848 the default directory for gcc-builds where include, library and documentation
849 files are stored is now in /usr/local/share.
852 \begin_layout Itemize
853 char type parameters to vararg
854 \begin_inset LatexCommand \index{vararg, va\_arg}
858 functions are casted to int unless explicitly casted
859 \begin_inset Marginal
862 \begin_layout Standard
887 will push a as an int and as a char resp.
890 \begin_layout Itemize
895 \begin_layout Standard
904 -regextend has been removed.
907 \begin_layout Itemize
912 \begin_layout Standard
921 -noregparms has been removed.
924 \begin_layout Itemize
929 \begin_layout Standard
938 -stack-after-data has been removed.
941 \begin_layout Itemize
943 \begin_inset LatexCommand \index{bit}
948 \begin_inset LatexCommand \index{sbit}
953 \begin_inset LatexCommand \index{\_\_sbit}
957 types now consistently behave like the C99 _Bool type with respect to type
959 \begin_inset LatexCommand \index{type conversion}
964 \begin_inset LatexCommand \index{type promotion}
969 The most common incompatibility resulting from this change is related to
971 \begin_inset LatexCommand \index{Bit toggling}
986 \begin_inset LatexCommand \index{\~\/ Operator}
990 b; /* equivalent to b=1 instead of toggling b */
991 \begin_inset Marginal
994 \begin_layout Standard
1007 b = !b; /* toggles b */
1011 In previous versions, both forms would have toggled the bit.
1014 \begin_layout Standard
1017 <pending: more incompatibilities?>
1020 \begin_layout Section
1024 \begin_layout Standard
1025 What do you need before you start installation of SDCC? A computer, and
1026 a desire to compute.
1027 The preferred method of installation is to compile SDCC from source using
1029 For Windows some pre-compiled binary distributions are available for your
1031 You should have some experience with command line tools and compiler use.
1034 \begin_layout Section
1038 \begin_layout Standard
1039 The SDCC home page at
1040 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1044 is a great place to find distribution sets.
1045 You can also find links to the user mailing lists that offer help or discuss
1046 SDCC with other SDCC users.
1047 Web links to other SDCC related sites can also be found here.
1048 This document can be found in the DOC directory of the source package as
1049 a text or HTML file.
1050 A pdf version of this document is available at
1051 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1056 Some of the other tools (simulator and assembler) included with SDCC contain
1057 their own documentation and can be found in the source distribution.
1058 If you want the latest unreleased software, the complete source package
1059 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1063 \begin_layout Section
1064 Wishes for the future
1067 \begin_layout Standard
1068 There are (and always will be) some things that could be done.
1069 Here are some I can think of:
1074 \begin_layout Standard
1077 char KernelFunction3(char p) at 0x340;
1082 \begin_layout Standard
1086 \begin_inset LatexCommand \index{code banking (limited support)}
1096 If you can think of some more, please see the section
1097 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1101 about filing feature requests
1102 \begin_inset LatexCommand \index{Requesting features}
1107 \begin_inset LatexCommand \index{Feature request}
1116 \begin_layout Chapter
1118 \begin_inset LatexCommand \index{Installation}
1125 \begin_layout Standard
1126 For most users it is sufficient to skip to either section
1127 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1132 \begin_inset LatexCommand \ref{sub:Windows-Install}
1137 More detailed instructions follow below.
1140 \begin_layout Section
1142 \begin_inset LatexCommand \index{Options SDCC configuration}
1149 \begin_layout Standard
1150 The install paths, search paths and other options are defined when running
1152 The defaults can be overridden by:
1156 \labelwidthstring 00.00.0000
1161 \begin_layout Standard
1170 -prefix see table below
1174 \labelwidthstring 00.00.0000
1179 \begin_layout Standard
1188 -exec_prefix see table below
1192 \labelwidthstring 00.00.0000
1197 \begin_layout Standard
1206 -bindir see table below
1210 \labelwidthstring 00.00.0000
1215 \begin_layout Standard
1224 -datadir see table below
1228 \labelwidthstring 00.00.0000
1233 \begin_layout Standard
1242 -datarootdir see table below
1248 \labelwidthstring 00.00.0000
1251 docdir environment variable, see table below
1255 \labelwidthstring 00.00.0000
1258 include_dir_suffix environment variable, see table below
1262 \labelwidthstring 00.00.0000
1265 lib_dir_suffix environment variable, see table below
1269 \labelwidthstring 00.00.0000
1272 sdccconf_h_dir_separator environment variable, either / or
1277 This character will only be used in sdccconf.h; don't forget it's a C-header,
1278 therefore a double-backslash is needed there.
1284 \labelwidthstring 00.00.0000
1289 \begin_layout Standard
1298 -disable-mcs51-port Excludes the Intel mcs51 port
1302 \labelwidthstring 00.00.0000
1307 \begin_layout Standard
1316 -disable-gbz80-port Excludes the Gameboy gbz80 port
1320 \labelwidthstring 00.00.0000
1325 \begin_layout Standard
1334 -disable-z80-port Excludes the z80 port
1338 \labelwidthstring 00.00.0000
1343 \begin_layout Standard
1352 -disable-avr-port Excludes the AVR port
1356 \labelwidthstring 00.00.0000
1361 \begin_layout Standard
1370 -disable-ds390-port Excludes the DS390 port
1374 \labelwidthstring 00.00.0000
1379 \begin_layout Standard
1388 -disable-hc08-port Excludes the HC08 port
1392 \labelwidthstring 00.00.0000
1397 \begin_layout Standard
1406 -disable-pic-port Excludes the PIC port
1410 \labelwidthstring 00.00.0000
1415 \begin_layout Standard
1424 -disable-xa51-port Excludes the XA51 port
1428 \labelwidthstring 00.00.0000
1433 \begin_layout Standard
1442 -disable-ucsim Disables configuring and building of ucsim
1446 \labelwidthstring 00.00.0000
1451 \begin_layout Standard
1460 -disable-device-lib Disables automatically building device libraries
1464 \labelwidthstring 00.00.0000
1469 \begin_layout Standard
1478 -disable-packihx Disables building packihx
1484 \labelwidthstring 00.00.0000
1489 \begin_layout Standard
1498 -enable-doc Build pdf, html and txt files from the lyx sources
1502 \labelwidthstring 00.00.0000
1507 \begin_layout Standard
1516 -enable-libgc Use the Bohem memory allocator.
1517 Lower runtime footprint.
1520 \begin_layout Standard
1521 Furthermore the environment variables CC, CFLAGS, ...
1522 the tools and their arguments can be influenced.
1523 Please see `configure -
1527 \begin_layout Standard
1536 -help` and the man/info pages of `configure` for details.
1541 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1542 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1543 SDCC_LIB_NAME are defined by `configure` too.
1544 At the moment it's not possible to change the default settings (it was
1545 simply never required).
1549 These configure options are compiled into the binaries,
1550 and can only be changed by rerunning 'configure' and recompiling SDCC.
1551 The configure options are written in
1555 to distinguish them from run time environment variables (see section search
1561 \begin_inset Quotes sld
1565 \begin_inset Quotes srd
1568 are used by the SDCC team to build the official Win32 binaries.
1569 The SDCC team uses Mingw32 to build the official Windows binaries, because
1573 \begin_layout Enumerate
1577 \begin_layout Enumerate
1578 a gcc compiler and last but not least
1581 \begin_layout Enumerate
1582 the binaries can be built by cross compiling on SDCC Distributed Compile
1586 \begin_layout Standard
1587 See the examples, how to pass the Win32 settings to 'configure'.
1588 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1589 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1599 \begin_layout Standard
1601 \begin_inset Tabular
1602 <lyxtabular version="3" rows="9" columns="3">
1604 <column alignment="block" valignment="top" leftline="true" width="0in">
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1607 <row topline="true" bottomline="true">
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1611 \begin_layout Standard
1617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1620 \begin_layout Standard
1626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1629 \begin_layout Standard
1636 <row topline="true">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1640 \begin_layout Standard
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_layout Standard
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1660 \begin_layout Standard
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1673 \begin_layout Standard
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1684 \begin_layout Standard
1692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1695 \begin_layout Standard
1704 <row topline="true">
1705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1708 \begin_layout Standard
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1719 \begin_layout Standard
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1732 \begin_layout Standard
1745 <row topline="true">
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1749 \begin_layout Standard
1757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1760 \begin_layout Standard
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1771 \begin_layout Standard
1780 <row topline="true">
1781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1784 \begin_layout Standard
1792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1795 \begin_layout Standard
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1808 \begin_layout Standard
1817 <row topline="true">
1818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1821 \begin_layout Standard
1829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1832 \begin_layout Standard
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1845 \begin_layout Standard
1858 <row topline="true">
1859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1862 \begin_layout Standard
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1873 \begin_layout Standard
1879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1882 \begin_layout Standard
1889 <row topline="true" bottomline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1893 \begin_layout Standard
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_layout Standard
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_layout Standard
1929 \begin_layout Standard
1931 'configure' also computes relative paths.
1932 This is needed for full relocatability of a binary package and to complete
1933 search paths (see section search paths below):
1938 \begin_layout Standard
1940 \begin_inset Tabular
1941 <lyxtabular version="3" rows="4" columns="3">
1943 <column alignment="block" valignment="top" leftline="true" width="0in">
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1946 <row topline="true" bottomline="true">
1947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1950 \begin_layout Standard
1956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1959 \begin_layout Standard
1965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1968 \begin_layout Standard
1975 <row topline="true" bottomline="true">
1976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 \begin_layout Standard
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_layout Standard
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 \begin_layout Standard
2006 <row bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2010 \begin_layout Standard
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_layout Standard
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 \begin_layout Standard
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2041 \begin_layout Standard
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2052 \begin_layout Standard
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2061 \begin_layout Standard
2077 \begin_layout Standard
2082 \begin_layout LyX-Code
2089 \begin_layout Standard
2099 \begin_inset Quotes srd
2103 \begin_inset Quotes srd
2110 \begin_layout Standard
2120 \begin_inset Quotes srd
2124 \begin_inset Quotes srd
2133 \begin_layout Standard
2146 \begin_layout Standard
2158 \begin_layout Standard
2159 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2163 \begin_layout LyX-Code
2169 \begin_inset Quotes srd
2172 i586-mingw32msvc-gcc
2173 \begin_inset Quotes srd
2177 \begin_inset Quotes srd
2180 i586-mingw32msvc-g++
2181 \begin_inset Quotes srd
2189 \begin_inset Quotes srd
2192 i586-mingw32msvc-ranlib
2193 \begin_inset Quotes srd
2201 \begin_inset Quotes srd
2204 i586-mingw32msvc-strip
2205 \begin_inset Quotes srd
2216 \begin_layout Standard
2226 \begin_inset Quotes srd
2230 \begin_inset Quotes srd
2241 \begin_layout Standard
2251 \begin_inset Quotes srd
2255 \begin_inset Quotes srd
2263 \begin_inset Quotes srd
2269 \begin_inset Quotes srd
2277 \begin_inset Quotes srd
2281 \begin_inset Quotes srd
2289 \begin_inset Quotes srd
2293 \begin_inset Quotes srd
2300 sdccconf_h_dir_separator=
2301 \begin_inset Quotes srd
2313 \begin_inset Quotes srd
2324 \begin_layout Standard
2341 \begin_layout Standard
2350 -host=i586-mingw32msvc
2358 \begin_layout Standard
2367 -build=unknown-unknown-linux-gnu
2370 \begin_layout Standard
2372 \begin_inset Quotes sld
2376 \begin_inset Quotes srd
2379 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2383 \begin_layout LyX-Code
2392 \begin_layout Standard
2402 \begin_inset Quotes srd
2406 \begin_inset Quotes srd
2417 \begin_layout Standard
2427 \begin_inset Quotes srd
2431 \begin_inset Quotes srd
2439 \begin_inset Quotes srd
2445 \begin_inset Quotes srd
2453 \begin_inset Quotes srd
2457 \begin_inset Quotes srd
2465 \begin_inset Quotes srd
2469 \begin_inset Quotes srd
2476 sdccconf_h_dir_separator=
2477 \begin_inset Quotes srd
2489 \begin_inset Quotes srd
2497 \begin_inset Quotes srd
2501 \begin_inset Quotes srd
2509 \begin_inset Quotes srd
2513 \begin_inset Quotes srd
2519 \begin_layout Standard
2520 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2525 \begin_layout Standard
2534 -C' turns on caching, which gives a little bit extra speed.
2535 However if options are changed, it can be necessary to delete the config.cache
2539 \begin_layout Section
2541 \begin_inset LatexCommand \label{sub:Install-paths}
2546 \begin_inset LatexCommand \index{Install paths}
2553 \begin_layout Standard
2554 \begin_inset VSpace medskip
2560 \begin_layout Standard
2562 \begin_inset Tabular
2563 <lyxtabular version="3" rows="5" columns="4">
2565 <column alignment="left" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
2569 <row topline="true" bottomline="true">
2570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2573 \begin_layout Standard
2581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2584 \begin_layout Standard
2592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2595 \begin_layout Standard
2603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2606 \begin_layout Standard
2615 <row topline="true">
2616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2619 \begin_layout Standard
2625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2628 \begin_layout Standard
2636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2639 \begin_layout Standard
2645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2648 \begin_layout Standard
2659 <row topline="true">
2660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2663 \begin_layout Standard
2669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2672 \begin_layout Standard
2675 $DATADIR/ $INCLUDE_DIR_SUFFIX
2680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2683 \begin_layout Standard
2684 /usr/local/share/sdcc/include
2689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2692 \begin_layout Standard
2703 <row topline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2707 \begin_layout Standard
2713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2716 \begin_layout Standard
2719 $DATADIR/$LIB_DIR_SUFFIX
2724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2727 \begin_layout Standard
2728 /usr/local/share/sdcc/lib
2733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2736 \begin_layout Standard
2747 <row topline="true" bottomline="true">
2748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2751 \begin_layout Standard
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2760 \begin_layout Standard
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2771 \begin_layout Standard
2772 /usr/local/share/sdcc/doc
2777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2780 \begin_layout Standard
2801 *compiler, preprocessor, assembler, and linker
2807 is auto-appended by the compiler, e.g.
2808 small, large, z80, ds390 etc
2811 \begin_layout Standard
2813 The install paths can still be changed during `make install` with e.g.:
2816 \begin_layout LyX-Code
2817 make install prefix=$(HOME)/local/sdcc
2820 \begin_layout Standard
2821 Of course this doesn't change the search paths compiled into the binaries.
2826 r the install path can be changed by defining DESTDIR
2827 \begin_inset LatexCommand \index{DESTDIR}
2834 \begin_layout LyX-Code
2835 make install DESTDIR=$(HOME)/sdcc.rpm/
2838 \begin_layout Standard
2839 Please note that DESTDIR must have a trailing slash!
2842 \begin_layout Section
2844 \begin_inset LatexCommand \label{sub:Search-Paths}
2849 \begin_inset LatexCommand \index{Search path}
2856 \begin_layout Standard
2857 Some search paths or parts of them are determined by configure variables
2862 , see section above).
2863 Further search paths are determined by environment variables during runtime.
2866 The paths searched when running the compiler are as follows (the first
2872 Binary files (preprocessor, assembler and linker)
2877 \begin_layout Standard
2879 \begin_inset Tabular
2880 <lyxtabular version="3" rows="4" columns="3">
2882 <column alignment="block" valignment="top" leftline="true" width="0in">
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2885 <row topline="true" bottomline="true">
2886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2889 \begin_layout Standard
2895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2898 \begin_layout Standard
2904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2907 \begin_layout Standard
2914 <row topline="true">
2915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2918 \begin_layout Standard
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_layout Standard
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2938 \begin_layout Standard
2947 <row topline="true">
2948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2951 \begin_layout Standard
2952 Path of argv[0] (if available)
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_layout Standard
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2969 \begin_layout Standard
2976 <row topline="true" bottomline="true">
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2980 \begin_layout Standard
2986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_layout Standard
2995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2998 \begin_layout Standard
3014 \begin_layout Standard
3022 \begin_layout Standard
3024 \begin_inset Tabular
3025 <lyxtabular version="3" rows="6" columns="3">
3027 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3030 <row topline="true" bottomline="true">
3031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3034 \begin_layout Standard
3040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3043 \begin_layout Standard
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3052 \begin_layout Standard
3059 <row topline="true">
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3063 \begin_layout Standard
3068 \begin_layout Standard
3082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3085 \begin_layout Standard
3090 \begin_layout Standard
3104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3107 \begin_layout Standard
3112 \begin_layout Standard
3127 <row topline="true">
3128 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3131 \begin_layout Standard
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_layout Standard
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3149 \begin_layout Standard
3156 <row topline="true">
3157 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_layout Standard
3172 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3175 \begin_layout Standard
3185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3188 \begin_layout Standard
3197 <row topline="true">
3198 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3201 \begin_layout Standard
3217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3220 \begin_layout Standard
3268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3271 \begin_layout Standard
3282 <row topline="true" bottomline="true">
3283 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3286 \begin_layout Standard
3300 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3303 \begin_layout Standard
3304 /usr/local/share/sdcc/
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3314 \begin_layout Standard
3330 \begin_layout Standard
3336 \begin_layout Standard
3345 -nostdinc disables the last two search paths.
3355 \begin_layout Standard
3356 With the exception of
3357 \begin_inset Quotes sld
3364 \begin_layout Standard
3374 \begin_inset Quotes srd
3381 is auto-appended by the compiler (e.g.
3382 small, large, z80, ds390 etc.).
3388 \begin_layout Standard
3390 \begin_inset Tabular
3391 <lyxtabular version="3" rows="6" columns="3">
3393 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3394 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3395 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3396 <row topline="true" bottomline="true">
3397 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3400 \begin_layout Standard
3406 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3409 \begin_layout Standard
3415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3418 \begin_layout Standard
3425 <row topline="true">
3426 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3429 \begin_layout Standard
3434 \begin_layout Standard
3448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3451 \begin_layout Standard
3456 \begin_layout Standard
3470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3473 \begin_layout Standard
3478 \begin_layout Standard
3493 <row topline="true">
3494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3497 \begin_layout Standard
3507 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3510 \begin_layout Standard
3520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3523 \begin_layout Standard
3536 <row topline="true">
3537 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3540 \begin_layout Standard
3547 $LIB_DIR_SUFFIX/<model>
3552 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3555 \begin_layout Standard
3567 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3570 \begin_layout Standard
3585 <row topline="true">
3586 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3589 \begin_layout Standard
3600 $LIB_DIR_SUFFIX/<model>
3605 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3608 \begin_layout Standard
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3662 \begin_layout Standard
3716 <row topline="true" bottomline="true">
3717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3720 \begin_layout Standard
3725 $LIB_DIR_SUFFIX/<model>
3730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3733 \begin_layout Standard
3734 /usr/local/share/sdcc/
3743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3746 \begin_layout Standard
3762 \begin_layout Standard
3763 \begin_inset Note Note
3766 \begin_layout Standard
3767 Don't delete any of the stray spaces in the table above without checking
3768 the HTML output (last line)!
3776 \begin_layout Standard
3784 \begin_layout Standard
3793 -nostdlib disables the last two search paths.
3796 \begin_layout Section
3798 \begin_inset LatexCommand \index{Building SDCC}
3805 \begin_layout Subsection
3806 Building SDCC on Linux
3807 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3814 \begin_layout Enumerate
3817 Download the source package
3819 either from the SDCC Subversion repository or from snapshot builds
3821 , it will be named something like sdcc
3832 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3839 \begin_layout Enumerate
3842 Bring up a command line terminal, such as xterm.
3845 \begin_layout Enumerate
3848 Unpack the file using a command like:
3851 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3852 \begin_inset Quotes srd
3858 , this will create a sub-directory called sdcc with all of the sources.
3861 \begin_layout Enumerate
3862 Change directory into the main SDCC directory, for example type:
3870 \begin_layout Enumerate
3880 This configures the package for compilation on your system.
3883 \begin_layout Enumerate
3897 All of the source packages will compile, this can take a while.
3900 \begin_layout Enumerate
3914 This copies the binary executables, the include files, the libraries and
3915 the documentation to the install directories.
3916 Proceed with section
3917 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3924 \begin_layout Subsection
3925 Building SDCC on OSX 2.x
3928 \begin_layout Standard
3929 Follow the instruction for Linux.
3933 On OSX 2.x it was reported, that the default
3934 gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3935 Fortunately there's also gcc 2.9.x installed, which works fine.
3936 This compiler can be selected by running 'configure' with:
3939 \begin_layout LyX-Code
3940 ./configure CC=gcc2 CXX=g++2
3943 \begin_layout Subsection
3944 Cross compiling SDCC on Linux for Windows
3947 \begin_layout Standard
3948 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3949 See section 'Configure Options'.
3952 \begin_layout Subsection
3953 Building SDCC using Cygwin and Mingw32
3956 \begin_layout Standard
3957 For building and installing a Cygwin executable follow the instructions
3963 \begin_inset Quotes sld
3967 \begin_inset Quotes srd
3970 Win32-binary can be built, which will not need the Cygwin-DLL.
3971 For the necessary 'configure' options see section 'configure options' or
3972 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3977 Cygwin on Windows download setup.exe from
3978 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3984 \begin_inset Quotes sld
3987 default text file type
3988 \begin_inset Quotes srd
3992 \begin_inset Quotes sld
3996 \begin_inset Quotes srd
3999 and download/install at least the following packages.
4000 Some packages are selected by default, others will be automatically selected
4001 because of dependencies with the manually selected packages.
4002 Never deselect these packages!
4005 \begin_layout Itemize
4009 \begin_layout Itemize
4013 \begin_layout Itemize
4014 gcc ; version 3.x is fine, no need to use the old 2.9x
4017 \begin_layout Itemize
4018 binutils ; selected with gcc
4021 \begin_layout Itemize
4025 \begin_layout Itemize
4026 rxvt ; a nice console, which makes life much easier under windoze (see below)
4029 \begin_layout Itemize
4030 man ; not really needed for building SDCC, but you'll miss it sooner or
4034 \begin_layout Itemize
4035 less ; not really needed for building SDCC, but you'll miss it sooner or
4039 \begin_layout Itemize
4040 svn ; only if you use Subversion access
4043 \begin_layout Standard
4044 If you want to develop something you'll need:
4047 \begin_layout Itemize
4048 python ; for the regression tests
4051 \begin_layout Itemize
4052 gdb ; the gnu debugger, together with the nice GUI
4053 \begin_inset Quotes sld
4057 \begin_inset Quotes srd
4063 \begin_layout Itemize
4064 openssh ; to access the CF or commit changes
4067 \begin_layout Itemize
4068 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4069 use autoconf-stable!
4072 \begin_layout Standard
4073 rxvt is a nice console with history.
4074 Replace in your cygwin.bat the line
4077 \begin_layout LyX-Code
4082 \begin_layout Standard
4094 \begin_layout Standard
4098 \begin_layout LyX-Code
4099 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4102 \begin_layout LyX-Code
4103 -bg black -fg white -geometry 100x65 -e bash -
4107 \begin_layout Standard
4119 \begin_layout Standard
4120 Text selected with the mouse is automatically copied to the clipboard, pasting
4121 works with shift-insert.
4125 The other good tip is to make sure you have no //c/-styl
4126 e paths anywhere, use /cygdrive/c/ instead.
4127 Using // invokes a network lookup which is very slow.
4129 \begin_inset Quotes sld
4133 \begin_inset Quotes srd
4136 is too long, you can change it with e.g.
4139 \begin_layout LyX-Code
4143 \begin_layout Standard
4144 SDCC sources use the unix line ending LF.
4145 Life is much easier, if you store the source tree on a drive which is mounted
4147 And use an editor which can handle LF-only line endings.
4148 Make sure not to commit files with windows line endings.
4149 The tabulator spacing
4150 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4154 used in the project is 8.
4155 Although a tabulator spacing of 8 is a sensible choice for programmers
4156 (it's a power of 2 and allows to display 8/16 bit signed variables without
4157 loosing columns) the plan is to move towards using only spaces in the source.
4160 \begin_layout Subsection
4161 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4164 \begin_layout Standard
4167 Download the source package
4169 either from the SDCC Subversion repository or from the
4170 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4176 , it will be named something like sdcc
4180 -yyyymmdd-rrrr.tar.bz2.
4183 SDCC is distributed with all the projects, workspaces, and files you need
4184 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4185 The workspace name is 'sdcc.dsw'.
4186 Please note that as it is now, all the executables are created in a folder
4190 Once built you need to copy the executables from sdcc
4194 bin before running SDCC.
4199 WARNING: Visual studio is very picky with line terminations; it expects
4200 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4201 When using the Subversion repository it's easiest to configure the svn
4202 client to convert automatically for you.
4203 If however you are getting a message such as "This makefile was not generated
4204 by Developer Studio etc.
4206 \begin_inset Quotes srd
4209 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4210 need to convert the Unix style line endings to DOS style line endings.
4211 To do so you can use the
4212 \begin_inset Quotes sld
4216 \begin_inset Quotes srd
4219 utility freely available on the internet.
4220 Doug Hawkins reported in the sdcc-user list that this works:
4228 SDCC> unix2dos sdcc.dsw
4234 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4238 In order to build SDCC with MSVC
4239 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4240 One good place to get them is
4241 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4249 Download the file UnxUtils
4250 \begin_inset LatexCommand \index{UnxUtils}
4255 Now you have to install the utilities and setup MSVC so it can locate the
4257 Here there are two alternatives (choose one!):
4260 \begin_layout Enumerate
4265 a) Extract UnxUtils.zip to your C:
4267 hard disk PRESERVING the original paths, otherwise bison won't work.
4268 (If you are using WinZip make certain that 'Use folder names' is selected)
4273 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4274 'Show directories for:' select 'Executable files', and in the directories
4275 window add a new path: 'C:
4285 (As a side effect, you get a bunch of Unix utilities that
4286 could be useful, such as diff and patch.)
4289 \begin_layout Enumerate
4294 This one avoids extracting a bunch of files you may not
4295 use, but requires some extra work:
4299 a) Create a directory were to put the
4300 tools needed, or use a directory already present.
4307 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4308 gawk.exe to such directory WITHOUT preserving the original paths.
4309 (If you are using WinZip make certain that 'Use folder names' is not selected)
4314 ) Rename bison.exe to '_bison.exe'.
4318 d) Create a batch file 'bison.bat' in 'C:
4322 ' and add these lines:
4342 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4346 Steps 'c' and 'd' are needed
4347 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4348 reside in some weird Unix directory, '/usr/local/share/' I think.
4349 So it is necessary to tell bison where those files are located if they
4350 are not in such directory.
4351 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4356 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4357 in 'Show directories for:' select 'Executable files', and in the directories
4358 window add a new path: 'c:
4361 Note that you can use any other path instead of 'c:
4363 util', even the path where the Visual C++ tools are, probably: 'C:
4367 Microsoft Visual Studio
4372 So you don't have to execute step 'e' :)
4375 \begin_layout Standard
4377 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4378 the executables from sdcc
4382 bin, and you can compile using SDCC.
4385 \begin_layout Subsection
4386 Building SDCC Using Borland
4389 \begin_layout Enumerate
4390 From the sdcc directory, run the command "make -f Makefile.bcc".
4391 This should regenerate all the .exe files in the bin directory except for
4395 \begin_layout Enumerate
4396 If you modify any source files and need to rebuild, be aware that the dependenci
4397 es may not be correctly calculated.
4398 The safest option is to delete all .obj files and run the build again.
4399 From a Cygwin BASH prompt, this can easily be done with the command (be
4400 sure you are in the sdcc directory):
4410 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4412 ) -print -exec rm {}
4421 or on Windows NT/2000/XP from the command prompt with the command:
4428 del /s *.obj *.lib *.rul
4431 from the sdcc directory.
4434 \begin_layout Subsection
4435 Windows Install Using a ZIP Package
4438 \begin_layout Enumerate
4439 Download the binary zip package from
4440 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4444 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4445 This should unpack to a group of sub-directories.
4446 An example directory structure after unpacking the mingw32 package is:
4451 bin for the executables, c:
4459 lib for the include and libraries.
4462 \begin_layout Enumerate
4463 Adjust your environment variable PATH to include the location of the bin
4464 directory or start sdcc using the full path.
4467 \begin_layout Subsection
4468 Windows Install Using the Setup Program
4469 \begin_inset LatexCommand \label{sub:Windows-Install}
4476 \begin_layout Standard
4477 Download the setup program
4479 sdcc-x.y.z-setup.exe
4481 for an official release from
4484 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4488 or a setup program for one of the snapshots
4490 sdcc-yyyymmdd-xxxx-setup.exe
4493 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4498 A windows typical installer will guide you through the installation process.
4501 \begin_layout Subsection
4503 \begin_inset LatexCommand \index{VPATH}
4510 \begin_layout Standard
4511 SDCC supports the VPATH feature provided by configure and make.
4512 It allows to separate the source and build trees.
4516 \begin_layout Standard
4543 \begin_layout Standard
4546 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4547 # extract source to directory sdcc
4550 \begin_layout Standard
4553 mkdir sdcc.build\InsetSpace ~
4562 # put output in sdcc.build
4565 \begin_layout Standard
4571 \begin_layout Standard
4574 ../sdcc/configure\InsetSpace ~
4582 # configure is doing all the magic!
4585 \begin_layout Standard
4591 \begin_layout Standard
4597 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4598 It automagically computes the variables srcdir, top_srcdir and top_buildir
4604 the generated files will be in ~/sdcc.build, while the source files stay
4607 This is not only usefull for building different binaries, e.g.
4608 when cross compiling.
4609 It also gives you a much better overview in the source tree when all the
4610 generated files are not scattered between the source files.
4611 And the best thing is: if you want to change a file you can leave the original
4612 file untouched in the source directory.
4613 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4614 Makefile.dep` and `make`.
4619 will do the rest for you!
4622 \begin_layout Section
4623 Building the Documentation
4626 \begin_layout Standard
4631 \begin_layout Standard
4640 -enable-doc to the configure arguments to build the documentation together
4641 with all the other stuff.
4642 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4643 dvips and makeindex) to get the job done.
4644 Another possibility is to change to the doc directory and to type
4648 \begin_inset Quotes srd
4652 \begin_inset Quotes srd
4659 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4662 \begin_inset LatexCommand \url{http://www.lyx.org}
4666 as editor is straightforward.
4667 Prebuilt documentation in html and pdf format is available from
4668 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4675 \begin_layout Section
4676 Reading the Documentation
4677 \begin_inset LatexCommand \index{Documentation}
4684 \begin_layout Standard
4685 Currently reading the document in pdf format is recommended, as for unknown
4686 reason the hyperlinks are working there whereas in the html version they
4691 \begin_layout Standard
4692 If you should know why please drop us a note
4700 You'll find the pdf version
4701 \begin_inset LatexCommand \index{PDF version of this document}
4706 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4714 \begin_inset LatexCommand \index{HTML version of this document}
4719 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4725 This documentation is in some aspects different from a commercial documentation:
4729 \begin_layout Itemize
4730 It tries to document SDCC for several processor architectures in one document
4731 (commercially these probably would be separate documents/products).
4733 \begin_inset LatexCommand \index{Status of documentation}
4737 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4739 Z80, PIC14, PIC16 and HC08.
4742 \begin_layout Itemize
4743 There are many references pointing away from this documentation.
4744 Don't let this distract you.
4746 was a reference like
4747 \begin_inset LatexCommand \url{http://www.opencores.org}
4751 together with a statement
4752 \begin_inset Quotes sld
4755 some processors which are targetted by SDCC can be implemented in a
4772 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4777 \begin_inset Quotes srd
4781 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4786 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4791 \begin_inset Quotes sld
4794 have you ever heard of an open source compiler that compiles a subset of
4796 \begin_inset Quotes srd
4799 we expect you to have a quick look there and come back.
4800 If you read this you are on the right track.
4803 \begin_layout Itemize
4804 Some sections attribute more space to problems, restrictions and warnings
4805 than to the solution.
4808 \begin_layout Itemize
4809 The installation section and the section about the debugger is intimidating.
4812 \begin_layout Itemize
4813 There are still lots of typos and there are more different writing styles
4817 \begin_layout Section
4818 Testing the SDCC Compiler
4819 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4826 \begin_layout Standard
4827 The first thing you should do after installing your SDCC compiler is to
4836 \begin_layout Standard
4846 \begin_inset LatexCommand \index{version}
4853 at the prompt, and the program should run and output its version like:
4858 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4862 \begin_layout Standard
4863 If it doesn't run, or gives a message about not finding sdcc program, then
4864 you need to check over your installation.
4865 Make sure that the sdcc bin directory is in your executable search path
4866 defined by the PATH environment setting (
4871 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4878 Install trouble-shooting for suggestions
4881 Make sure that the sdcc program is in the bin folder, if not perhaps something
4882 did not install correctly.
4890 is commonly installed as described in section
4891 \begin_inset Quotes sld
4894 Install and search paths
4895 \begin_inset Quotes srd
4904 Make sure the compiler works on a very simple example.
4905 Type in the following test.c program using your favorite
4930 \begin_layout Standard
4933 Compile this using the following command:
4942 If all goes well, the compiler will generate a test.asm and test.rel file.
4943 Congratulations, you've just compiled your first program with SDCC.
4944 We used the -c option to tell SDCC not to link the generated code, just
4945 to keep things simple for this step.
4953 The next step is to try it with the linker.
4963 If all goes well the compiler will link with the libraries and produce
4964 a test.ihx output file.
4969 (no test.ihx, and the linker generates warnings), then the problem is most
4978 usr/local/share/sdcc/lib directory
4985 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4992 Install trouble-shooting for suggestions).
5000 The final test is to ensure
5008 header files and libraries.
5009 Edit test.c and change it to the following:
5027 strcpy(str1, "testing");
5032 \begin_layout Standard
5035 Compile this by typing
5042 This should generate a test.ihx output file, and it should give no warnings
5043 such as not finding the string.h file.
5044 If it cannot find the string.h file, then the problem is that
5048 cannot find the /usr/local/share/sdcc/include directory
5055 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5062 Install trouble-shooting section for suggestions).
5071 \begin_layout Standard
5083 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5087 to find exactly where SDCC is looking for the include and lib files.
5090 \begin_layout Section
5091 Install Trouble-shooting
5092 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5097 \begin_inset LatexCommand \index{Install trouble-shooting}
5104 \begin_layout Subsection
5105 If SDCC does not build correctly
5108 \begin_layout Standard
5109 A thing to try is starting from scratch by unpacking the .tgz source package
5110 again in an empty directory.
5118 ./configure 2>&1 | tee configure.log
5132 make 2>&1 | tee make.log
5139 If anything goes wrong, you can review the log files to locate the problem.
5140 Or a relevant part of this can be attached to an email that could be helpful
5141 when requesting help from the mailing list.
5144 \begin_layout Subsection
5146 \begin_inset Quotes sld
5150 \begin_inset Quotes srd
5156 \begin_layout Standard
5158 \begin_inset Quotes sld
5162 \begin_inset Quotes srd
5165 command is a script that analyzes your system and performs some configuration
5166 to ensure the source package compiles on your system.
5167 It will take a few minutes to run, and will compile a few tests to determine
5168 what compiler features are installed.
5171 \begin_layout Subsection
5173 \begin_inset Quotes sld
5177 \begin_inset Quotes srd
5183 \begin_layout Standard
5184 This runs the GNU make tool, which automatically compiles all the source
5185 packages into the final installed binary executables.
5188 \begin_layout Subsection
5190 \begin_inset Quotes sld
5194 \begin_inset Quotes erd
5200 \begin_layout Standard
5201 This will install the compiler, other executables libraries and include
5202 files into the appropriate directories.
5204 \begin_inset LatexCommand \ref{sub:Install-paths}
5210 \begin_inset LatexCommand \ref{sub:Search-Paths}
5215 about install and search paths.
5217 On most systems you will need super-user privilege
5221 \begin_layout Section
5225 \begin_layout Standard
5226 SDCC is not just a compiler, but a collection of tools by various developers.
5227 These include linkers, assemblers, simulators and other components.
5228 Here is a summary of some of the components.
5229 Note that the included simulator and assembler have separate documentation
5230 which you can find in the source package in their respective directories.
5231 As SDCC grows to include support for other processors, other packages from
5232 various developers are included and may have their own sets of documentation.
5237 might want to look at the files which are installed in <installdir>.
5238 At the time of this writing, we find the following programs for gcc-builds:
5243 In <installdir>/bin:
5246 \begin_layout Itemize
5247 sdcc - The compiler.
5250 \begin_layout Itemize
5251 sdcpp - The C preprocessor.
5254 \begin_layout Itemize
5255 asx8051 - The assembler for 8051 type processors.
5258 \begin_layout Itemize
5263 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5266 \begin_layout Itemize
5267 aslink -The linker for 8051 type processors.
5270 \begin_layout Itemize
5275 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5278 \begin_layout Itemize
5279 s51 - The ucSim 8051 simulator.
5282 \begin_layout Itemize
5283 sdcdb - The source debugger.
5286 \begin_layout Itemize
5287 packihx - A tool to pack (compress) Intel hex files.
5290 \begin_layout Standard
5291 In <installdir>/share/sdcc/include
5294 \begin_layout Itemize
5298 \begin_layout Standard
5299 In <installdir>/share/sdcc/lib
5302 \begin_layout Itemize
5303 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5307 \begin_layout Standard
5308 In <installdir>/share/sdcc/doc
5311 \begin_layout Itemize
5315 \begin_layout Standard
5316 As development for other processors proceeds, this list will expand to include
5317 executables to support processors like AVR, PIC, etc.
5320 \begin_layout Subsection
5324 \begin_layout Standard
5325 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5326 the assembler and linkage editor.
5329 \begin_layout Subsection
5330 sdcpp - The C-Preprocessor
5333 \begin_layout Standard
5335 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5339 is a modified version of the GNU cpp
5340 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5345 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5350 The C preprocessor is used to pull in #include sources, process #ifdef
5351 statements, #defines and so on.
5354 \begin_layout Subsection
5363 - The Assemblers and Linkage Editors
5366 \begin_layout Standard
5367 This is retargettable assembler & linkage editor, it was developed by Alan
5369 John Hartman created the version for 8051, and I (Sandeep) have made some
5370 enhancements and bug fixes for it to work properly with SDCC.
5373 \begin_layout Subsection
5377 \begin_layout Standard
5379 \begin_inset LatexCommand \index{s51}
5383 is a freeware, opensource simulator developed by Daniel Drotos.
5384 The simulator is built as part of the build process.
5385 For more information visit Daniel's web site at:
5386 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5391 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5395 \begin_layout Subsection
5396 sdcdb - Source Level Debugger
5399 \begin_layout Standard
5401 \begin_inset LatexCommand \index{SDCDB (debugger)}
5405 is the companion source level debugger.
5406 More about SDCDB in section
5407 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5412 The current version of the debugger uses Daniel's Simulator S51
5413 \begin_inset LatexCommand \index{s51}
5417 , but can be easily changed to use other simulators.
5420 \begin_layout Chapter
5424 \begin_layout Section
5428 \begin_layout Subsection
5429 Single Source File Projects
5432 \begin_layout Standard
5433 For single source file 8051 projects the process is very simple.
5434 Compile your programs with the following command
5437 "sdcc sourcefile.c".
5441 This will compile, assemble and link your source file.
5442 Output files are as follows:
5445 \begin_layout Itemize
5447 \begin_inset LatexCommand \index{<file>.asm}
5452 \begin_inset LatexCommand \index{Assembler source}
5456 file created by the compiler
5459 \begin_layout Itemize
5461 \begin_inset LatexCommand \index{<file>.lst}
5466 \begin_inset LatexCommand \index{Assembler listing}
5470 file created by the Assembler
5473 \begin_layout Itemize
5475 \begin_inset LatexCommand \index{<file>.rst}
5480 \begin_inset LatexCommand \index{Assembler listing}
5484 file updated with linkedit information, created by linkage editor
5487 \begin_layout Itemize
5489 \begin_inset LatexCommand \index{<file>.sym}
5494 \begin_inset LatexCommand \index{Symbol listing}
5498 for the sourcefile, created by the assembler
5501 \begin_layout Itemize
5503 \begin_inset LatexCommand \index{<file>.rel}
5508 \begin_inset LatexCommand \index{<file>.o}
5513 \begin_inset LatexCommand \index{Object file}
5517 created by the assembler, input to Linkage editor
5520 \begin_layout Itemize
5522 \begin_inset LatexCommand \index{<file>.map}
5527 \begin_inset LatexCommand \index{Memory map}
5531 for the load module, created by the Linker
5534 \begin_layout Itemize
5536 \begin_inset LatexCommand \index{<file>.mem}
5540 - A file with a summary of the memory usage
5543 \begin_layout Itemize
5545 \begin_inset LatexCommand \index{<file>.ihx}
5549 - The load module in Intel hex format
5550 \begin_inset LatexCommand \index{Intel hex format}
5554 (you can select the Motorola S19 format
5555 \begin_inset LatexCommand \index{Motorola S19 format}
5563 \begin_layout Standard
5573 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5578 If you need another format you might want to use
5585 \begin_inset LatexCommand \index{objdump (tool)}
5596 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5601 \begin_inset Note Note
5604 \begin_layout Standard
5611 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5616 Both formats are documented in the documentation of srecord
5617 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5624 \begin_layout Itemize
5626 \begin_inset LatexCommand \index{<file>.adb}
5630 - An intermediate file containing debug information needed to create the
5635 \begin_layout Standard
5645 \begin_inset LatexCommand \index{-\/-debug}
5652 \begin_layout Itemize
5654 \begin_inset LatexCommand \index{<file>.cdb}
5658 - An optional file (with -
5662 \begin_layout Standard
5671 -debug) containing debug information.
5672 The format is documented in cdbfileformat.pdf
5675 \begin_layout Itemize
5678 \begin_inset LatexCommand \index{<file> (no extension)}
5682 An optional AOMF or AOMF51
5683 \begin_inset LatexCommand \index{AOMF, AOMF51}
5688 \begin_inset LatexCommand \label{OMF file}
5692 file containing debug information (generated with option -
5696 \begin_layout Standard
5722 ormat is a subformat of the OMF51 format and is commonly used by third party
5724 \begin_inset LatexCommand \index{Debugger}
5728 , simulators, emulators).
5731 \begin_layout Itemize
5733 \begin_inset LatexCommand \index{<file>.dump*}
5737 - Dump file to debug the compiler it self (generated with option -
5741 \begin_layout Standard
5750 -dumpall) (see section
5751 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5757 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5763 \begin_inset Quotes sld
5766 Anatomy of the compiler
5767 \begin_inset Quotes srd
5773 \begin_layout Subsection
5774 Postprocessing the Intel Hex
5775 \begin_inset LatexCommand \index{Intel hex format}
5780 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5787 \begin_layout Standard
5788 In most cases this won't be needed but the Intel Hex file
5789 \begin_inset LatexCommand \index{<file>.ihx}
5793 which is generated by SDCC might include lines of varying length and the
5794 addresses within the file are not guaranteed to be strictly ascending.
5795 If your toolchain or a bootloader does not like this you can use the tool
5801 \begin_inset LatexCommand \index{packihx (tool)}
5805 which is part of the SDCC distribution:
5812 packihx sourcefile.ihx >sourcefile.hex
5819 The separately available
5824 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5828 package additionally allows to set undefined locations to a predefined
5829 value, to insert checksums
5830 \begin_inset LatexCommand \index{checksum}
5834 of various flavours (crc, add, xor) and to perform other manipulations
5835 (convert, split, crop, offset, ...).
5843 srec_cat\InsetSpace ~
5845 sourcefile.ihx -intel\InsetSpace ~
5847 -o sourcefile.hex -intel
5854 An example for a more complex command line
5858 \begin_layout Standard
5859 the command backfills
5860 \begin_inset LatexCommand \index{backfill unused memory}
5864 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5866 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5867 will be interpreted as an
5875 (where an emergency routine could sit).
5888 srec_cat\InsetSpace ~
5889 sourcefile.ihx -intel\InsetSpace ~
5891 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5892 -little-endian-checksum-nega
5893 tive 0xfffe 0x02 0x02\InsetSpace ~
5895 -o sourcefile.hex -intel
5904 The srecord package is available at
5905 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5912 \begin_layout Subsection
5913 Projects with Multiple Source Files
5916 \begin_layout Standard
5917 SDCC can compile only ONE file at a time.
5918 Let us for example assume that you have a project containing the following
5923 foo1.c (contains some functions)
5925 foo2.c (contains some more functions)
5928 n.c (contains more functions and the function main)
5936 The first two files will need to be compiled separately with the commands:
5968 Then compile the source file containing the
5973 \begin_inset LatexCommand \index{Linker}
5977 the files together with the following command:
5985 foomain.c\InsetSpace ~
5986 foo1.rel\InsetSpace ~
5991 \begin_inset LatexCommand \index{<file>.rel}
6003 can be separately compiled as well:
6014 sdcc foomain.rel foo1.rel foo2.rel
6021 The file containing the
6036 file specified in the command line, since the linkage editor processes
6037 file in the order they are presented to it.
6038 The linker is invoked from SDCC using a script file with extension .lnk
6039 \begin_inset LatexCommand \index{<file>.lnk}
6044 You can view this file to troubleshoot linking problems such as those arising
6045 from missing libraries.
6048 \begin_layout Subsection
6049 Projects with Additional Libraries
6050 \begin_inset LatexCommand \index{Libraries}
6057 \begin_layout Standard
6058 Some reusable routines may be compiled into a library, see the documentation
6059 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6063 \begin_inset LatexCommand \index{<file>.lib}
6070 Libraries created in this manner can be included in the command line.
6071 Make sure you include the -L <library-path> option to tell the linker where
6072 to look for these files if they are not in the current directory.
6073 Here is an example, assuming you have the source file
6085 (if that is not the same as your current project):
6092 sdcc foomain.c foolib.lib -L mylib
6103 must be an absolute path name.
6107 The most efficient way to use libraries is
6108 to keep separate modules in separate source files.
6109 The lib file now should name all the modules.rel
6110 \begin_inset LatexCommand \index{<file>.rel}
6115 For an example see the standard library file
6119 in the directory <installdir>/share/lib/small.
6122 \begin_layout Subsection
6123 Using sdcclib to Create and Manage Libraries
6124 \begin_inset LatexCommand \index{sdcclib}
6131 \begin_layout Standard
6132 Alternatively, instead of having a .rel file for each entry on the library
6133 file as described in the preceding section, sdcclib can be used to embed
6134 all the modules belonging to such library in the library file itself.
6135 This results in a larger library file, but it greatly reduces the number
6136 of disk files accessed by the linker.
6137 Additionally, the packed library file contains an index of all include
6138 modules and symbols that significantly speeds up the linking process.
6139 To display a list of options supported by sdcclib type:
6144 \begin_layout Standard
6149 \begin_inset LatexCommand \index{sdcclib}
6160 To create a new library file, start by compiling all the required modules.
6166 \begin_layout Standard
6173 \begin_layout Standard
6180 \begin_layout Standard
6187 \begin_layout Standard
6194 \begin_layout Standard
6203 \begin_layout Standard
6204 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6206 The next step is to add the .rel files to the library file:
6211 \begin_layout Standard
6215 sdcclib libint.lib _divsint.rel
6218 \begin_inset LatexCommand \index{sdcclib}
6225 \begin_layout Standard
6229 sdcclib libint.lib _divuint.rel
6232 \begin_layout Standard
6236 sdcclib libint.lib _modsint.rel
6239 \begin_layout Standard
6243 sdcclib libint.lib _moduint.rel
6246 \begin_layout Standard
6250 sdcclib libint.lib _mulint.rel
6257 \begin_layout Standard
6258 If the file already exists in the library, it will be replaced.
6259 To see what modules and symbols are included in the library, options -s
6260 and -m are available.
6268 sdcclib -s libint.lib
6271 \begin_inset LatexCommand \index{sdcclib}
6283 \begin_layout Standard
6289 \begin_layout Standard
6295 \begin_layout Standard
6303 \begin_layout Standard
6309 \begin_layout Standard
6315 \begin_layout Standard
6321 \begin_layout Standard
6327 \begin_layout Standard
6335 \begin_layout Standard
6341 \begin_layout Standard
6347 \begin_layout Standard
6355 \begin_layout Standard
6361 \begin_layout Standard
6367 \begin_layout Standard
6373 \begin_layout Standard
6381 \begin_layout Standard
6387 \begin_layout Standard
6398 \begin_layout Standard
6399 If the source files are compiled using -
6403 \begin_layout Standard
6413 \begin_inset LatexCommand \index{-\/-debug}
6417 , the corresponding debug information file .adb will be include in the library
6419 The library files created with sdcclib are plain text files, so they can
6420 be viewed with a text editor.
6421 It is not recomended to modify a library file created with sdcclib using
6422 a text editor, as there are file indexes numbers located accross the file
6423 used by the linker to quickly locate the required module to link.
6424 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6425 it can be safely deleted, since all the information required for linking
6426 is embedded in the library file itself.
6427 Library files created using sdcclib are used as described in the preceding
6429 \begin_inset VSpace bigskip
6435 \begin_layout Section
6436 Command Line Options
6437 \begin_inset LatexCommand \index{Command Line Options}
6442 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6449 \begin_layout Subsection
6450 Processor Selection Options
6451 \begin_inset LatexCommand \index{Options processor selection}
6456 \begin_inset LatexCommand \index{Processor selection options}
6464 \labelwidthstring 00.00.0000
6468 \begin_inset LatexCommand \index{-mmcs51}
6474 Generate code for the Intel MCS51
6475 \begin_inset LatexCommand \index{MCS51}
6479 family of processors.
6480 This is the default processor target.
6484 \labelwidthstring 00.00.0000
6488 \begin_inset LatexCommand \index{-mds390}
6494 Generate code for the Dallas DS80C390
6495 \begin_inset LatexCommand \index{DS80C390}
6503 \labelwidthstring 00.00.0000
6507 \begin_inset LatexCommand \index{-mds400}
6513 Generate code for the Dallas DS80C400
6514 \begin_inset LatexCommand \index{DS80C400}
6522 \labelwidthstring 00.00.0000
6526 \begin_inset LatexCommand \index{-mhc08}
6532 Generate code for the Freescale/Motorola HC08
6533 \begin_inset LatexCommand \index{HC08}
6537 family of processors.
6541 \labelwidthstring 00.00.0000
6545 \begin_inset LatexCommand \index{-mz80}
6551 Generate code for the Zilog Z80
6552 \begin_inset LatexCommand \index{Z80}
6556 family of processors.
6560 \labelwidthstring 00.00.0000
6564 \begin_inset LatexCommand \index{-mgbz80}
6570 Generate code for the GameBoy Z80
6571 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6575 processor (Not actively maintained).
6579 \labelwidthstring 00.00.0000
6583 \begin_inset LatexCommand \index{-mavr}
6589 Generate code for the Atmel AVR
6590 \begin_inset LatexCommand \index{AVR}
6594 processor (Not maintained, not complete).
6595 AVR users should probably have a look at winavr
6596 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6601 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6605 , which is based on AVR-port of the gcc compiler.
6608 \begin_layout Standard
6609 \begin_inset Note Note
6612 \begin_layout Standard
6613 I think it is fair to direct users there for now.
6614 Open source is also about avoiding unnecessary work .
6615 But I didn't find the 'official' link.
6624 \labelwidthstring 00.00.0000
6628 \begin_inset LatexCommand \index{-mpic14}
6634 Generate code for the Microchip PIC 14
6635 \begin_inset LatexCommand \index{PIC14}
6639 -bit processors (p16f84 and variants.
6640 In development, not complete).
6643 \begin_layout Standard
6644 \begin_inset Note Note
6647 \begin_layout Standard
6648 p16f627 p16f628 p16f84 p16f873 p16f877?
6657 \labelwidthstring 00.00.0000
6661 \begin_inset LatexCommand \index{-mpic16}
6667 Generate code for the Microchip PIC 16
6668 \begin_inset LatexCommand \index{PIC16}
6672 -bit processors (p18f452 and variants.
6673 In development, not complete).
6677 \labelwidthstring 00.00.0000
6682 Generate code for the Toshiba TLCS-900H
6683 \begin_inset LatexCommand \index{TLCS-900H}
6687 processor (Not maintained, not complete).
6691 \labelwidthstring 00.00.0000
6695 \begin_inset LatexCommand \index{-mxa51}
6701 Generate code for the Phillips XA51
6702 \begin_inset LatexCommand \index{XA51}
6706 processor (Not maintained, not complete).
6709 \begin_layout Standard
6710 \begin_inset VSpace bigskip
6716 \begin_layout Subsection
6717 Preprocessor Options
6718 \begin_inset LatexCommand \index{Options preprocessor}
6723 \begin_inset LatexCommand \index{Preprocessor options}
6728 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6736 \labelwidthstring 00.00.0000
6740 \begin_inset LatexCommand \index{-I<path>}
6746 The additional location where the preprocessor will look for <..h> or
6747 \begin_inset Quotes eld
6751 \begin_inset Quotes erd
6758 \labelwidthstring 00.00.0000
6762 \begin_inset LatexCommand \index{-D<macro[=value]>}
6768 Command line definition of macros.
6769 Passed to the preprocessor.
6773 \labelwidthstring 00.00.0000
6777 \begin_inset LatexCommand \index{-M}
6783 Tell the preprocessor to output a rule suitable for make describing the
6784 dependencies of each object file.
6785 For each source file, the preprocessor outputs one make-rule whose target
6786 is the object file name for that source file and whose dependencies are
6787 all the files `#include'd in it.
6788 This rule may be a single line or may be continued with `
6790 '-newline if it is long.
6791 The list of rules is printed on standard output instead of the preprocessed
6794 \begin_inset LatexCommand \index{-E}
6802 \labelwidthstring 00.00.0000
6806 \begin_inset LatexCommand \index{-C}
6812 Tell the preprocessor not to discard comments.
6813 Used with the `-E' option.
6817 \labelwidthstring 00.00.0000
6821 \begin_inset LatexCommand \index{-MM}
6832 Like `-M' but the output mentions only the user header files included with
6834 \begin_inset Quotes eld
6838 System header files included with `#include <file>' are omitted.
6842 \labelwidthstring 00.00.0000
6846 \begin_inset LatexCommand \index{-Aquestion(answer)}
6852 Assert the answer answer for question, in case it is tested with a preprocessor
6853 conditional such as `#if #question(answer)'.
6854 `-A-' disables the standard assertions that normally describe the target
6859 \labelwidthstring 00.00.0000
6863 \begin_inset LatexCommand \index{-Umacro}
6869 Undefine macro macro.
6870 `-U' options are evaluated after all `-D' options, but before any `-include'
6871 and `-imacros' options.
6875 \labelwidthstring 00.00.0000
6879 \begin_inset LatexCommand \index{-dM}
6885 Tell the preprocessor to output only a list of the macro definitions that
6886 are in effect at the end of preprocessing.
6887 Used with the `-E' option.
6891 \labelwidthstring 00.00.0000
6895 \begin_inset LatexCommand \index{-dD}
6901 Tell the preprocessor to pass all macro definitions into the output, in
6902 their proper sequence in the rest of the output.
6906 \labelwidthstring 00.00.0000
6910 \begin_inset LatexCommand \index{-dN}
6921 Like `-dD' except that the macro arguments and contents are omitted.
6922 Only `#define name' is included in the output.
6926 \labelwidthstring 00.00.0000
6929 -pedantic-parse-number
6930 \begin_inset LatexCommand \index{pedantic}
6935 \begin_inset LatexCommand \index{-pedantic-parse-number}
6943 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6951 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6952 and the macro LO_B(3) gets expanded.
6953 See also #pragma pedantic_parse_number
6954 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6959 \begin_inset LatexCommand \ref{sec:Pragmas}
6965 Note: this functionality is not in conformance with
6966 \begin_inset Note Note
6969 \begin_layout Standard
6970 which standard? C99?
6979 \labelwidthstring 00.00.0000
6983 preprocessorOption[,preprocessorOption]
6986 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6991 Pass the preprocessorOption to the preprocessor
6996 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7001 SDCC uses an adapted version of the preprocessor
7005 of the GNU Compiler Collection
7006 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7015 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7019 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7024 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7031 \begin_layout Standard
7032 \begin_inset VSpace bigskip
7038 \begin_layout Subsection
7040 \begin_inset LatexCommand \index{Options linker}
7045 \begin_inset LatexCommand \index{Linker options}
7053 \labelwidthstring 00.00.0000
7063 \begin_layout Standard
7075 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7080 \begin_inset LatexCommand \index{-L -\/-lib-path}
7087 <absolute path to additional libraries> This option is passed to the linkage
7088 editor's additional libraries
7089 \begin_inset LatexCommand \index{Libraries}
7094 The path name must be absolute.
7095 Additional library files may be specified in the command line.
7096 See section Compiling programs for more details.
7100 \labelwidthstring 00.00.0000
7107 \begin_layout Standard
7119 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7124 <Value> The start location of the external ram
7125 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7129 , default value is 0.
7130 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7134 \begin_layout Standard
7143 -xram-loc 0x8000 or -
7147 \begin_layout Standard
7160 \labelwidthstring 00.00.0000
7167 \begin_layout Standard
7179 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7184 <Value> The start location of the code
7185 \begin_inset LatexCommand \index{code}
7189 segment, default value 0.
7190 Note when this option is used the interrupt vector table
7191 \begin_inset LatexCommand \index{interrupt vector table}
7195 is also relocated to the given address.
7196 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7200 \begin_layout Standard
7209 -code-loc 0x8000 or -
7213 \begin_layout Standard
7226 \labelwidthstring 00.00.0000
7233 \begin_layout Standard
7245 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7250 <Value> By default the stack
7251 \begin_inset LatexCommand \index{stack}
7255 is placed after the data segment.
7256 Using this option the stack can be placed anywhere in the internal memory
7258 The value entered can be in Hexadecimal or Decimal format, e.g.
7263 \begin_layout Standard
7272 -stack-loc 0x20 or -
7276 \begin_layout Standard
7286 Since the sp register is incremented before a push or call, the initial
7287 sp will be set to one byte prior the provided value.
7288 The provided value should not overlap any other memory areas such as used
7289 register banks or the data segment and with enough space for the current
7297 \begin_layout Standard
7310 \begin_inset LatexCommand \index{-\/-pack-iram}
7314 option (which is now a default setting) will override this setting, so
7315 you should also specify the
7321 \begin_layout Standard
7334 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7338 option if you need to manually place the stack.
7342 \labelwidthstring 00.00.0000
7349 \begin_layout Standard
7361 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7366 <Value> By default the external stack
7367 \begin_inset LatexCommand \index{xstack}
7371 is placed after the pdata
7372 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7377 Using this option the xstack can be placed anywhere in the external memory
7379 The value entered can be in Hexadecimal or Decimal format, e.g.
7384 \begin_layout Standard
7393 -xstack-loc 0x8000 or -
7397 \begin_layout Standard
7407 The provided value should not overlap any other memory areas such as the
7408 pdata or xdata segment and with enough space for the current application.
7412 \labelwidthstring 00.00.0000
7419 \begin_layout Standard
7431 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7436 <Value> The start location of the internal ram data
7437 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7442 The value entered can be in Hexadecimal or Decimal format, eg.
7447 \begin_layout Standard
7460 \begin_layout Standard
7470 (By default, the start location of the internal ram data segment is set
7471 as low as possible in memory, taking into account the used register banks
7472 and the bit segment at address 0x20.
7473 For example if register banks 0 and 1 are used without bit variables, the
7474 data segment will be set, if -
7478 \begin_layout Standard
7487 -data-loc is not used, to location 0x10.)
7491 \labelwidthstring 00.00.0000
7498 \begin_layout Standard
7510 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7515 <Value> The start location of the indirectly addressable internal ram
7516 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7520 of the 8051, default value is 0x80.
7521 The value entered can be in Hexadecimal or Decimal format, eg.
7526 \begin_layout Standard
7535 -idata-loc 0x88 or -
7539 \begin_layout Standard
7552 \labelwidthstring 00.00.0000
7559 \begin_layout Standard
7571 <Value> The start location of the bit
7572 \begin_inset LatexCommand \index{bit}
7576 addressable internal ram of the 8051.
7582 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7587 \labelwidthstring 00.00.0000
7594 \begin_layout Standard
7604 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7613 The linker output (final object code) is in Intel Hex format.
7614 \begin_inset LatexCommand \index{Intel hex format}
7618 This is the default option.
7619 The format itself is documented in the documentation of srecord
7620 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7628 \labelwidthstring 00.00.0000
7635 \begin_layout Standard
7645 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7654 The linker output (final object code) is in Motorola S19 format
7655 \begin_inset LatexCommand \index{Motorola S19 format}
7660 The format itself is documented in the documentation of srecord.
7664 \labelwidthstring 00.00.0000
7671 \begin_layout Standard
7681 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7686 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7695 The linker output (final object code) is in ELF format
7696 \begin_inset LatexCommand \index{ELF format}
7701 (Currently only supported for the HC08
7702 \begin_inset LatexCommand \index{HC08}
7710 \labelwidthstring 00.00.0000
7714 linkOption[,linkOption]
7717 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7722 Pass the linkOption to the linker.
7723 If a bootloader is used an option like
7724 \begin_inset Quotes sld
7729 \begin_inset Quotes srd
7732 would be typical to set the start of the code segment.
7733 See also #pragma constseg and #pragma codeseg in section
7734 \begin_inset LatexCommand \ref{sec:Pragmas}
7739 File sdcc/as/doc/asxhtm.html has more on linker options.
7742 \begin_layout Standard
7743 \begin_inset VSpace bigskip
7749 \begin_layout Subsection
7751 \begin_inset LatexCommand \index{Options MCS51}
7756 \begin_inset LatexCommand \index{MCS51 options}
7764 \labelwidthstring 00.00.0000
7771 \begin_layout Standard
7781 \begin_inset LatexCommand \index{-\/-model-small}
7792 Generate code for Small Model programs, see section Memory Models for more
7794 This is the default model.
7798 \labelwidthstring 00.00.0000
7805 \begin_layout Standard
7815 \begin_inset LatexCommand \index{-\/-model-medium}
7821 Generate code for Medium model programs, see section Memory Models for
7823 If this option is used all source files in the project have to be compiled
7825 It must also be used when invoking the linker.
7829 \labelwidthstring 00.00.0000
7836 \begin_layout Standard
7846 \begin_inset LatexCommand \index{-\/-model-large}
7852 Generate code for Large model programs, see section Memory Models for more
7854 If this option is used all source files in the project have to be compiled
7856 It must also be used when invoking the linker.
7860 \labelwidthstring 00.00.0000
7867 \begin_layout Standard
7877 \begin_inset LatexCommand \index{-\/-xstack}
7883 Uses a pseudo stack in the pdata
7884 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7888 area (usually the first 256 bytes in the external ram) for allocating variables
7889 and passing parameters.
7891 \begin_inset LatexCommand \ref{sub:External-Stack}
7896 External Stack for more details.
7900 \labelwidthstring 00.00.0000
7907 \begin_layout Standard
7920 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7924 Causes the linker to check if the internal ram usage is within limits of
7929 \labelwidthstring 00.00.0000
7936 \begin_layout Standard
7949 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7953 Causes the linker to check if the external ram usage is within limits of
7958 \labelwidthstring 00.00.0000
7965 \begin_layout Standard
7978 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7982 Causes the linker to check if the code memory usage is within limits of
7987 \labelwidthstring 00.00.0000
7994 \begin_layout Standard
8007 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8011 Causes the linker to check if there is at minimum <Value> bytes for stack.
8015 \labelwidthstring 00.00.0000
8022 \begin_layout Standard
8035 \begin_inset LatexCommand \index{-\/-pack-iram}
8039 Causes the linker to use unused register banks for data variables and pack
8040 data, idata and stack together.
8041 This is the default now.
8045 \labelwidthstring 00.00.0000
8052 \begin_layout Standard
8065 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8069 Causes the linker to use old style for allocating memory areas.
8072 \begin_layout Standard
8073 \begin_inset VSpace bigskip
8079 \begin_layout Subsection
8080 DS390 / DS400 Options
8081 \begin_inset LatexCommand \index{Options DS390}
8086 \begin_inset LatexCommand \index{DS390}
8094 \labelwidthstring 00.00.0000
8101 \begin_layout Standard
8113 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8123 Generate 24-bit flat mode code.
8124 This is the one and only that the ds390 code generator supports right now
8125 and is default when using
8130 See section Memory Models for more details.
8134 \labelwidthstring 00.00.0000
8141 \begin_layout Standard
8151 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8157 disable interrupts during ESP:SP updates.
8161 \labelwidthstring 00.00.0000
8168 \begin_layout Standard
8180 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8184 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8185 This is the one and only that the ds390 code generator supports right now
8186 and is default when using
8191 In this mode, the stack is located in the lower 1K of the internal RAM,
8192 which is mapped to 0x400000.
8193 Note that the support is incomplete, since it still uses a single byte
8194 as the stack pointer.
8195 This means that only the lower 256 bytes of the potential 1K stack space
8196 will actually be used.
8197 However, this does allow you to reclaim the precious 256 bytes of low RAM
8198 for use for the DATA and IDATA segments.
8199 The compiler will not generate any code to put the processor into 10 bit
8201 It is important to ensure that the processor is in this mode before calling
8202 any re-entrant functions compiled with this option.
8203 In principle, this should work with the
8209 \begin_layout Standard
8219 \begin_inset LatexCommand \index{-\/-stack-auto}
8225 option, but that has not been tested.
8226 It is incompatible with the
8232 \begin_layout Standard
8242 \begin_inset LatexCommand \index{-\/-xstack}
8249 It also only makes sense if the processor is in 24 bit contiguous addressing
8256 \begin_layout Standard
8265 -model-flat24 option
8270 \begin_inset Note Note
8274 \labelwidthstring 00.00.0000
8277 --stack-8-bit - switches off the 10-bit mode
8286 \labelwidthstring 00.00.0000
8293 \begin_layout Standard
8303 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8309 insert call to function __stack_probe at each function prologue.
8313 \labelwidthstring 00.00.0000
8320 \begin_layout Standard
8330 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8336 <nnnn> LibraryID used in -mTININative.
8341 \labelwidthstring 00.00.0000
8348 \begin_layout Standard
8358 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8364 generate code for DS390 Arithmetic Accelerator.
8368 \begin_layout Standard
8369 \begin_inset VSpace bigskip
8375 \begin_layout Subsection
8377 \begin_inset LatexCommand \index{Options Z80}
8382 \begin_inset LatexCommand \index{Z80}
8390 \labelwidthstring 00.00.0000
8397 \begin_layout Standard
8409 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8419 Force a called function to always save BC.
8423 \labelwidthstring 00.00.0000
8430 \begin_layout Standard
8442 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8446 When linking, skip the standard crt0.o object file.
8447 You must provide your own crt0.o for your system when linking.
8451 \begin_layout Standard
8452 \begin_inset VSpace bigskip
8458 \begin_layout Subsection
8459 Optimization Options
8460 \begin_inset LatexCommand \index{Options optimization}
8465 \begin_inset LatexCommand \index{Optimization options}
8473 \labelwidthstring 00.00.0000
8480 \begin_layout Standard
8490 \begin_inset LatexCommand \index{-\/-nogcse}
8496 Will not do global subexpression elimination, this option may be used when
8497 the compiler creates undesirably large stack/data spaces to store compiler
8507 \begin_inset LatexCommand \index{sloc (spill location)}
8512 A warning message will be generated when this happens and the compiler
8513 will indicate the number of extra bytes it allocated.
8514 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8516 \begin_inset LatexCommand \index{\#pragma nogcse}
8520 can be used to turn off global subexpression elimination
8521 \begin_inset LatexCommand \index{Subexpression elimination}
8525 for a given function only.
8529 \labelwidthstring 00.00.0000
8536 \begin_layout Standard
8546 \begin_inset LatexCommand \index{-\/-noinvariant}
8552 Will not do loop invariant optimizations, this may be turned off for reasons
8553 explained for the previous option.
8554 For more details of loop optimizations performed see Loop Invariants in
8556 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8561 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8563 \begin_inset LatexCommand \index{\#pragma noinvariant}
8567 can be used to turn off invariant optimizations for a given function only.
8571 \labelwidthstring 00.00.0000
8578 \begin_layout Standard
8588 \begin_inset LatexCommand \index{-\/-noinduction}
8594 Will not do loop induction optimizations, see section strength reduction
8596 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8598 \begin_inset LatexCommand \index{\#pragma noinduction}
8602 can be used to turn off induction optimizations for a given function only.
8606 \labelwidthstring 00.00.0000
8613 \begin_layout Standard
8623 \begin_inset LatexCommand \index{-\/-nojtbound}
8634 Will not generate boundary condition check when switch statements
8635 \begin_inset LatexCommand \index{switch statement}
8639 are implemented using jump-tables.
8641 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8646 Switch Statements for more details.
8647 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8649 \begin_inset LatexCommand \index{\#pragma nojtbound}
8653 can be used to turn off boundary checking for jump tables for a given function
8658 \labelwidthstring 00.00.0000
8665 \begin_layout Standard
8675 \begin_inset LatexCommand \index{-\/-noloopreverse}
8684 Will not do loop reversal
8685 \begin_inset LatexCommand \index{Loop reversing}
8693 \labelwidthstring 00.00.0000
8698 \begin_layout Standard
8712 \begin_inset LatexCommand \index{-\/-nolabelopt }
8716 Will not optimize labels (makes the dumpfiles more readable).
8720 \labelwidthstring 00.00.0000
8727 \begin_layout Standard
8737 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8743 Will not memcpy initialized data from code space into xdata space.
8744 This saves a few bytes in code space if you don't have initialized data
8745 \begin_inset LatexCommand \index{Variable initialization}
8753 \labelwidthstring 00.00.0000
8760 \begin_layout Standard
8770 \begin_inset LatexCommand \index{-\/-nooverlay}
8776 The compiler will not overlay parameters and local variables of any function,
8777 see section Parameters and local variables for more details.
8781 \labelwidthstring 00.00.0000
8788 \begin_layout Standard
8798 \begin_inset LatexCommand \index{-\/-no-peep}
8804 Disable peep-hole optimization with built-in rules.
8808 \labelwidthstring 00.00.0000
8815 \begin_layout Standard
8827 \begin_inset LatexCommand \index{-\/-peep-file}
8832 <filename> This option can be used to use additional rules to be used by
8833 the peep hole optimizer.
8835 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8840 Peep Hole optimizations for details on how to write these rules.
8844 \labelwidthstring 00.00.0000
8851 \begin_layout Standard
8861 \begin_inset LatexCommand \index{-\/-peep-asm}
8867 Pass the inline assembler code through the peep hole optimizer.
8868 This can cause unexpected changes to inline assembler code, please go through
8869 the peephole optimizer
8870 \begin_inset LatexCommand \index{Peephole optimizer}
8874 rules defined in the source file tree '<target>/peeph.def' before using
8879 \labelwidthstring 00.00.0000
8886 \begin_layout Standard
8896 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8902 The compiler will optimize code generation towards fast code, possibly
8903 at the expense of code size.
8907 \labelwidthstring 00.00.0000
8914 \begin_layout Standard
8924 \begin_inset LatexCommand \index{-\/-opt-code-size}
8930 The compiler will optimize code generation towards compact code, possibly
8931 at the expense of code speed.
8934 \begin_layout Standard
8935 \begin_inset VSpace bigskip
8941 \begin_layout Subsection
8943 \begin_inset LatexCommand \index{Options other}
8951 \labelwidthstring 00.00.0000
8959 \begin_layout Standard
8969 \begin_inset LatexCommand \index{-\/-compile-only}
8974 \begin_inset LatexCommand \index{-c -\/-compile-only}
8980 will compile and assemble the source, but will not call the linkage editor.
8984 \labelwidthstring 00.00.0000
8993 \begin_layout Standard
9005 \begin_inset LatexCommand \index{-\/-c1mode}
9011 reads the preprocessed source from standard input and compiles it.
9012 The file name for the assembler output must be specified using the -o option.
9016 \labelwidthstring 00.00.0000
9020 \begin_inset LatexCommand \index{-E}
9026 Run only the C preprocessor.
9027 Preprocess all the C source files specified and output the results to standard
9032 \labelwidthstring 00.00.0000
9037 \begin_inset LatexCommand \index{-o <path/file>}
9043 The output path resp.
9044 file where everything will be placed.
9045 If the parameter is a path, it must have a trailing slash (or backslash
9046 for the Windows binaries) to be recognized as a path.
9051 \labelwidthstring 00.00.0000
9058 \begin_layout Standard
9068 \begin_inset LatexCommand \index{-\/-stack-auto}
9079 All functions in the source file will be compiled as
9084 \begin_inset LatexCommand \index{reentrant}
9089 the parameters and local variables will be allocated on the stack
9090 \begin_inset LatexCommand \index{stack}
9096 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9100 Parameters and Local Variables for more details.
9101 If this option is used all source files in the project should be compiled
9103 It automatically implies --int-long-reent and --float-reent.
9108 \labelwidthstring 00.00.0000
9115 \begin_layout Standard
9125 \begin_inset LatexCommand \index{-\/-callee-saves}
9130 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9134 function1[,function2][,function3]....
9137 The compiler by default uses a caller saves convention for register saving
9138 across function calls, however this can cause unnecessary register pushing
9139 and popping when calling small functions from larger functions.
9140 This option can be used to switch the register saving convention for the
9141 function names specified.
9142 The compiler will not save registers when calling these functions, no extra
9143 code will be generated at the entry and exit (function prologue
9146 \begin_inset LatexCommand \index{function prologue}
9155 \begin_inset LatexCommand \index{function epilogue}
9161 ) for these functions to save and restore the registers used by these functions,
9162 this can SUBSTANTIALLY reduce code and improve run time performance of
9164 In the future the compiler (with inter procedural analysis) will be able
9165 to determine the appropriate scheme to use for each function call.
9166 DO NOT use this option for built-in functions such as _mulint..., if this
9167 option is used for a library function the appropriate library function
9168 needs to be recompiled with the same option.
9169 If the project consists of multiple source files then all the source file
9170 should be compiled with the same -
9174 \begin_layout Standard
9183 -callee-saves option string.
9184 Also see #pragma\InsetSpace ~
9186 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9191 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9199 \labelwidthstring 00.00.0000
9206 \begin_layout Standard
9216 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9230 \begin_layout Standard
9239 -callee-saves will be applied to all functions by default.
9243 \labelwidthstring 00.00.0000
9250 \begin_layout Standard
9260 \begin_inset LatexCommand \index{-\/-debug}
9269 When this option is used the compiler will generate debug information.
9270 The debug information collected in a file with .cdb extension can be used
9272 For more information see documentation for SDCDB.
9273 Another file with no extension contains debug information in AOMF or AOMF51
9274 \begin_inset LatexCommand \index{AOMF, AOMF51}
9278 format which is commonly used by third party tools.
9282 \labelwidthstring 00.00.0000
9286 \begin_inset LatexCommand \index{-S}
9297 Stop after the stage of compilation proper; do not assemble.
9298 The output is an assembler code file for the input file specified.
9302 \labelwidthstring 00.00.0000
9309 \begin_layout Standard
9319 \begin_inset LatexCommand \index{-\/-int-long-reent}
9325 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9326 Note by default these libraries are compiled as non-reentrant.
9327 See section Installation for more details.
9331 \labelwidthstring 00.00.0000
9338 \begin_layout Standard
9348 \begin_inset LatexCommand \index{-\/-cyclomatic}
9357 This option will cause the compiler to generate an information message for
9358 each function in the source file.
9359 The message contains some
9363 information about the function.
9364 The number of edges and nodes the compiler detected in the control flow
9365 graph of the function, and most importantly the
9367 cyclomatic complexity
9368 \begin_inset LatexCommand \index{Cyclomatic complexity}
9374 see section on Cyclomatic Complexity for more details.
9378 \labelwidthstring 00.00.0000
9385 \begin_layout Standard
9395 \begin_inset LatexCommand \index{-\/-float-reent}
9401 Floating point library is compiled as reentrant
9402 \begin_inset LatexCommand \index{reentrant}
9407 See section Installation for more details.
9411 \labelwidthstring 00.00.0000
9418 \begin_layout Standard
9428 \begin_inset LatexCommand \index{-\/-funsigned-char}
9434 The default signedness for every type is
9439 In some embedded environments the default signedness of
9448 To set the signess for characters to unsigned, use the option --funsigned-char.
9449 If this option is set and no signedness keyword (unsigned/signed) is given,
9450 a char will be signed.
9451 All other types are unaffected.
9455 \labelwidthstring 00.00.0000
9462 \begin_layout Standard
9472 \begin_inset LatexCommand \index{-\/-main-return}
9478 This option can be used if the code generated is called by a monitor program
9479 or if the main routine includes an endless loop.
9480 This option results in slightly smaller code and saves two bytes of stack
9482 The return from the 'main'
9483 \begin_inset LatexCommand \index{main return}
9487 function will return to the function calling main.
9488 The default setting is to lock up i.e.
9497 \labelwidthstring 00.00.0000
9504 \begin_layout Standard
9514 \begin_inset LatexCommand \index{-\/-nostdinc}
9520 This will prevent the compiler from passing on the default include path
9521 to the preprocessor.
9525 \labelwidthstring 00.00.0000
9532 \begin_layout Standard
9542 \begin_inset LatexCommand \index{-\/-nostdlib}
9548 This will prevent the compiler from passing on the default library
9549 \begin_inset LatexCommand \index{Libraries}
9557 \labelwidthstring 00.00.0000
9564 \begin_layout Standard
9574 \begin_inset LatexCommand \index{-\/-verbose}
9580 Shows the various actions the compiler is performing.
9584 \labelwidthstring 00.00.0000
9588 \begin_inset LatexCommand \index{-V}
9594 Shows the actual commands the compiler is executing.
9598 \labelwidthstring 00.00.0000
9605 \begin_layout Standard
9615 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9621 Hides your ugly and inefficient c-code from the asm file, so you can always
9622 blame the compiler :)
9626 \labelwidthstring 00.00.0000
9633 \begin_layout Standard
9643 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9649 Will not include peep-hole comments in the generated files.
9653 \labelwidthstring 00.00.0000
9660 \begin_layout Standard
9670 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9676 Will not include code generator comments in the generated files.
9680 \labelwidthstring 00.00.0000
9687 \begin_layout Standard
9697 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9703 Include i-codes in the asm file.
9704 Sounds like noise but is most helpful for debugging the compiler itself.
9708 \labelwidthstring 00.00.0000
9715 \begin_layout Standard
9725 \begin_inset LatexCommand \index{pedantic}
9730 \begin_inset LatexCommand \index{-\/-less-pedantic}
9737 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9741 Disable some of the more pedantic warnings
9742 \begin_inset LatexCommand \index{Warnings}
9747 For more details, see the less_pedantic pragma
9748 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9756 \labelwidthstring 00.00.0000
9763 \begin_layout Standard
9772 -disable-warning\InsetSpace ~
9774 \begin_inset LatexCommand \index{-\/-disable-warning}
9780 Disable specific warning with number <nnnn>.
9784 \labelwidthstring 00.00.0000
9791 \begin_layout Standard
9801 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9807 Display the directories in the compiler's search path
9811 \labelwidthstring 00.00.0000
9818 \begin_layout Standard
9828 \begin_inset LatexCommand \index{-\/-vc}
9834 Display errors and warnings using MSVC style, so you can use SDCC with
9835 the visual studio IDE
9836 \begin_inset LatexCommand \index{IDE}
9841 With SDCC both offering a GCC-like (the default) and a MSVC-like
9842 \begin_inset LatexCommand \index{MSVC output style}
9846 output style, integration into most programming editors should be straightforwa
9851 \labelwidthstring 00.00.0000
9858 \begin_layout Standard
9868 \begin_inset LatexCommand \index{-\/-use-stdout}
9874 Send errors and warnings to stdout instead of stderr.
9878 \labelwidthstring 00.00.0000
9882 asmOption[,asmOption]
9885 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9890 Pass the asmOption to the assembler
9891 \begin_inset LatexCommand \index{Options assembler}
9896 \begin_inset LatexCommand \index{Assembler options}
9901 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9905 \labelwidthstring 00.00.0000
9912 \begin_layout Standard
9922 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9928 Generally follow the C89 standard, but allow SDCC features that conflict
9929 with the standard (default).
9933 \labelwidthstring 00.00.0000
9940 \begin_layout Standard
9950 \begin_inset LatexCommand \index{-\/-std-c89}
9956 Follow the C89 standard and disable SDCC features that conflict with the
9961 \labelwidthstring 00.00.0000
9968 \begin_layout Standard
9978 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9984 Generally follow the C99 standard, but allow SDCC features that conflict
9985 with the standard (incomplete support).
9989 \labelwidthstring 00.00.0000
9996 \begin_layout Standard
10006 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10012 Follow the C99 standard and disable SDCC features that conflict with the
10013 standard (incomplete support).
10017 \labelwidthstring 00.00.0000
10024 \begin_layout Standard
10036 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10041 <Name> The name to be used for the code
10042 \begin_inset LatexCommand \index{code}
10046 segment, default CSEG.
10047 This is useful if you need to tell the compiler to put the code in a special
10048 segment so you can later on tell the linker to put this segment in a special
10050 Can be used for instance when using bank switching to put the code in a
10055 \labelwidthstring 00.00.0000
10062 \begin_layout Standard
10074 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10079 <Name> The name to be used for the const
10080 \begin_inset LatexCommand \index{code}
10084 segment, default CONST.
10085 This is useful if you need to tell the compiler to put the const data in
10086 a special segment so you can later on tell the linker to put this segment
10087 in a special place in memory.
10088 Can be used for instance when using bank switching to put the const data
10093 \labelwidthstring 00.00.0000
10100 \begin_layout Standard
10109 -fdollars-in-identifiers
10110 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10116 Permit '$' as an identifier character-
10120 \labelwidthstring 00.00.0000
10127 \begin_layout Standard
10139 \begin_inset LatexCommand \index{-\/-more-pedantic}
10144 \begin_inset LatexCommand \index{pedantic}
10154 a SDCC compiler option but if you want
10158 warnings you can use a separate tool dedicated to syntax checking like
10160 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10165 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10170 \begin_inset LatexCommand \url{http://www.splint.org}
10175 To make your source files parseable by splint you will have to include
10181 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10185 in your source file and add brackets around extended keywords (like
10188 \begin_inset Quotes sld
10201 \begin_inset Quotes srd
10209 \begin_inset Quotes sld
10212 __interrupt\InsetSpace ~
10214 \begin_inset Quotes srd
10222 Splint has an excellent on line manual at
10223 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10227 and it's capabilities go beyond pure syntax checking.
10228 You'll need to tell splint the location of SDCC's include files so a typical
10229 command line could look like this:
10233 splint\InsetSpace ~
10235 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10241 \labelwidthstring 00.00.0000
10248 \begin_layout Standard
10260 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10265 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10269 Treat short as 8-bit (for backward compatibility with older versions of
10270 compiler - see section
10271 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10278 \begin_layout Standard
10279 \begin_inset VSpace bigskip
10285 \begin_layout Subsection
10286 Intermediate Dump Options
10287 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10292 \begin_inset LatexCommand \index{Options intermediate dump}
10297 \begin_inset LatexCommand \index{Intermediate dump options}
10304 \begin_layout Standard
10305 The following options are provided for the purpose of retargetting and debugging
10307 They provide a means to dump the intermediate code (iCode
10308 \begin_inset LatexCommand \index{iCode}
10312 ) generated by the compiler in human readable form at various stages of
10313 the compilation process.
10314 More on iCodes see chapter
10315 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10320 \begin_inset Quotes srd
10323 The anatomy of the compiler
10324 \begin_inset Quotes srd
10331 \labelwidthstring 00.00.0000
10338 \begin_layout Standard
10348 \begin_inset LatexCommand \index{-\/-dumpraw}
10354 This option will cause the compiler to dump the intermediate code into
10357 <source filename>.dumpraw
10359 just after the intermediate code has been generated for a function, i.e.
10360 before any optimizations are done.
10362 \begin_inset LatexCommand \index{Basic blocks}
10366 at this stage ordered in the depth first number, so they may not be in
10367 sequence of execution.
10371 \labelwidthstring 00.00.0000
10378 \begin_layout Standard
10388 \begin_inset LatexCommand \index{-\/-dumpgcse}
10394 Will create a dump of iCode's, after global subexpression elimination
10395 \begin_inset LatexCommand \index{Global subexpression elimination}
10399 , into a file named
10401 <source filename>.dumpgcse.
10405 \labelwidthstring 00.00.0000
10412 \begin_layout Standard
10422 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10428 Will create a dump of iCode's, after deadcode elimination
10429 \begin_inset LatexCommand \index{Dead-code elimination}
10433 , into a file named
10435 <source filename>.dumpdeadcode.
10439 \labelwidthstring 00.00.0000
10446 \begin_layout Standard
10456 \begin_inset LatexCommand \index{-\/-dumploop}
10465 Will create a dump of iCode's, after loop optimizations
10466 \begin_inset LatexCommand \index{Loop optimization}
10470 , into a file named
10472 <source filename>.dumploop.
10476 \labelwidthstring 00.00.0000
10483 \begin_layout Standard
10493 \begin_inset LatexCommand \index{-\/-dumprange}
10502 Will create a dump of iCode's, after live range analysis
10503 \begin_inset LatexCommand \index{Live range analysis}
10507 , into a file named
10509 <source filename>.dumprange.
10513 \labelwidthstring 00.00.0000
10520 \begin_layout Standard
10530 \begin_inset LatexCommand \index{-\/-dumlrange}
10536 Will dump the life ranges
10537 \begin_inset LatexCommand \index{Live range analysis}
10545 \labelwidthstring 00.00.0000
10552 \begin_layout Standard
10562 \begin_inset LatexCommand \index{-\/-dumpregassign}
10571 Will create a dump of iCode's, after register assignment
10572 \begin_inset LatexCommand \index{Register assignment}
10576 , into a file named
10578 <source filename>.dumprassgn.
10582 \labelwidthstring 00.00.0000
10589 \begin_layout Standard
10599 \begin_inset LatexCommand \index{-\/-dumplrange}
10605 Will create a dump of the live ranges of iTemp's
10609 \labelwidthstring 00.00.0000
10616 \begin_layout Standard
10626 \begin_inset LatexCommand \index{-\/-dumpall}
10637 Will cause all the above mentioned dumps to be created.
10640 \begin_layout Standard
10641 \begin_inset VSpace bigskip
10647 \begin_layout Subsection
10648 Redirecting output on Windows Shells
10651 \begin_layout Standard
10652 By default SDCC writes it's error messages to
10653 \begin_inset Quotes sld
10657 \begin_inset Quotes srd
10661 To force all messages to
10662 \begin_inset Quotes sld
10666 \begin_inset Quotes srd
10678 \begin_layout Standard
10693 \begin_inset LatexCommand \index{-\/-use-stdout}
10698 Additionally, if you happen to have visual studio installed in your windows
10699 machine, you can use it to compile your sources using a custom build and
10706 \begin_layout Standard
10718 \begin_inset LatexCommand \index{-\/-vc}
10723 Something like this should work:
10742 \begin_layout Standard
10761 \begin_layout Standard
10773 -model-large -c $(InputPath)
10776 \begin_inset VSpace bigskip
10782 \begin_layout Section
10783 Environment variables
10784 \begin_inset LatexCommand \index{Environment variables}
10791 \begin_layout Standard
10792 SDCC recognizes the following environment variables:
10796 \labelwidthstring 00.00.0000
10800 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10806 SDCC installs a signal handler
10807 \begin_inset LatexCommand \index{signal handler}
10811 to be able to delete temporary files after an user break (^C) or an exception.
10812 If this environment variable is set, SDCC won't install the signal handler
10813 in order to be able to debug SDCC.
10817 \labelwidthstring 00.00.0000
10823 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10829 Path, where temporary files will be created.
10830 The order of the variables is the search order.
10831 In a standard *nix environment these variables are not set, and there's
10832 no need to set them.
10833 On Windows it's recommended to set one of them.
10837 \labelwidthstring 00.00.0000
10841 \begin_inset LatexCommand \index{SDCC\_HOME}
10848 \begin_inset LatexCommand \ref{sub:Install-paths}
10854 \begin_inset Quotes sld
10858 \begin_inset Quotes srd
10865 \labelwidthstring 00.00.0000
10869 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10876 \begin_inset LatexCommand \ref{sub:Search-Paths}
10882 \begin_inset Quotes sld
10886 \begin_inset Quotes srd
10893 \labelwidthstring 00.00.0000
10897 \begin_inset LatexCommand \index{SDCC\_LIB}
10904 \begin_inset LatexCommand \ref{sub:Search-Paths}
10910 \begin_inset Quotes sld
10914 \begin_inset Quotes srd
10920 \begin_layout Standard
10921 There are some more environment variables recognized by SDCC, but these
10922 are solely used for debugging purposes.
10923 They can change or disappear very quickly, and will never be documented.
10924 \begin_inset VSpace bigskip
10930 \begin_layout Section
10931 Storage Class Language Extensions
10934 \begin_layout Subsection
10935 MCS51/DS390 Storage Class
10936 \begin_inset LatexCommand \index{Storage class}
10940 Language Extensions
10943 \begin_layout Standard
10944 In addition to the ANSI storage classes SDCC allows the following MCS51
10945 specific storage classes:
10948 \begin_layout Subsubsection
10950 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10955 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10960 \begin_inset LatexCommand \index{near (storage class)}
10965 \begin_inset LatexCommand \index{\_\_near (storage class)}
10972 \begin_layout Standard
10977 storage class for the Small Memory model (
10985 or the more ANSI-C compliant forms
10993 can be used synonymously).
10994 Variables declared with this storage class will be allocated in the directly
10995 addressable portion of the internal RAM of a 8051, e.g.:
10998 \begin_layout Verse
11001 __data unsigned char test_data;
11004 \begin_layout Standard
11005 Writing 0x01 to this variable generates the assembly code:
11008 \begin_layout Verse
11011 75*00 01\InsetSpace ~
11019 \begin_layout Subsubsection
11021 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11026 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11031 \begin_inset LatexCommand \index{far (storage class)}
11036 \begin_inset LatexCommand \index{\_\_far (storage class)}
11043 \begin_layout Standard
11044 Variables declared with this storage class will be placed in the external
11050 storage class for the Large Memory model, e.g.:
11053 \begin_layout Verse
11056 __xdata unsigned char test_xdata;
11059 \begin_layout Standard
11060 Writing 0x01 to this variable generates the assembly code:
11063 \begin_layout Verse
11066 90s00r00\InsetSpace ~
11097 \begin_layout Subsubsection
11099 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11104 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11111 \begin_layout Standard
11112 Variables declared with this storage class will be allocated into the indirectly
11113 addressable portion of the internal ram of a 8051, e.g.:
11116 \begin_layout Verse
11119 __idata unsigned char test_idata;
11122 \begin_layout Standard
11123 Writing 0x01 to this variable generates the assembly code:
11126 \begin_layout Verse
11153 \begin_layout Standard
11154 Please note, the first 128 byte of idata physically access the same RAM
11155 as the data memory.
11156 The original 8051 had 128 byte idata memory, nowadays most devices have
11157 256 byte idata memory.
11159 \begin_inset LatexCommand \index{stack}
11163 is located in idata memory.
11166 \begin_layout Subsubsection
11168 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11173 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11180 \begin_layout Standard
11181 Paged xdata access is just as straightforward as using the other addressing
11183 It is typically located at the start of xdata and has a maximum size of
11185 The following example writes 0x01 to the pdata variable.
11186 Please note, pdata access physically accesses xdata memory.
11187 The high byte of the address is determined by port P2
11188 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11192 (or in case of some 8051 variants by a separate Special Function Register,
11194 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11203 storage class for the Medium Memory model, e.g.:
11206 \begin_layout Verse
11209 __pdata unsigned char test_pdata;
11212 \begin_layout Standard
11213 Writing 0x01 to this variable generates the assembly code:
11216 \begin_layout Verse
11225 mov r0,#_test_pdata
11247 \begin_layout Standard
11252 \begin_layout Standard
11262 \begin_inset LatexCommand \index{-\/-xstack}
11266 option is used the pdata memory area is followed by the xstack memory area
11267 and the sum of their sizes is limited to 256 bytes.
11270 \begin_layout Subsubsection
11272 \begin_inset LatexCommand \index{code}
11277 \begin_inset LatexCommand \index{\_\_code}
11284 \begin_layout Standard
11285 'Variables' declared with this storage class will be placed in the code
11289 \begin_layout Verse
11292 __code unsigned char test_code;
11295 \begin_layout Standard
11296 Read access to this variable generates the assembly code:
11299 \begin_layout Verse
11302 90s00r6F\InsetSpace ~
11305 mov dptr,#_test_code
11330 \begin_layout Standard
11335 indexed arrays of characters in code memory can be accessed efficiently:
11338 \begin_layout Verse
11341 __code char test_array[] = {'c','h','e','a','p'};
11344 \begin_layout Standard
11345 Read access to this array using an 8-bit unsigned index generates the assembly
11349 \begin_layout Verse
11361 \begin_layout Verse
11364 90s00r41\InsetSpace ~
11367 mov dptr,#_test_array
11370 \begin_layout Verse
11385 \begin_layout Subsubsection
11387 \begin_inset LatexCommand \index{bit}
11392 \begin_inset LatexCommand \index{\_\_bit}
11399 \begin_layout Standard
11400 This is a data-type and a storage class specifier.
11401 When a variable is declared as a bit, it is allocated into the bit addressable
11402 memory of 8051, e.g.:
11405 \begin_layout Verse
11411 \begin_layout Standard
11412 Writing 1 to this variable generates the assembly code:
11415 \begin_layout Verse
11429 \begin_layout Standard
11430 The bit addressable memory consists of 128 bits which are located from 0x20
11431 to 0x2f in data memory.
11434 Apart from this 8051 specific storage class most architectures support
11436 \begin_inset LatexCommand \index{bitfields}
11444 \begin_layout Standard
11445 Not really meant as examples, but nevertheless showing what bitfields are
11446 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11452 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11453 signed modifier are implemented as unsigned.
11456 \begin_layout Subsubsection
11458 \begin_inset LatexCommand \index{sfr}
11463 \begin_inset LatexCommand \index{\_\_sfr}
11468 \begin_inset LatexCommand \index{sfr16}
11473 \begin_inset LatexCommand \index{\_\_sfr16}
11478 \begin_inset LatexCommand \index{sfr32}
11483 \begin_inset LatexCommand \index{\_\_sfr32}
11488 \begin_inset LatexCommand \index{\_\_sbit}
11493 \begin_inset LatexCommand \index{sbit}
11500 \begin_layout Standard
11501 Like the bit keyword,
11503 sfr / sfr16 / sfr32 / sbit
11505 signify both a data-type and storage class, they are used to describe the
11526 variables of a 8051, eg:
11529 \begin_layout Verse
11533 \begin_inset LatexCommand \index{at}
11538 \begin_inset LatexCommand \index{\_\_at}
11542 (0x80) P0;\InsetSpace ~
11543 /* special function register P0 at location 0x80 */
11548 special function register combination for timer 0
11552 with the high byte at
11553 location 0x8C and the low byte at location 0x8A */
11555 __sfr16 __at (0x8C8A)
11561 \begin_inset LatexCommand \index{at}
11566 \begin_inset LatexCommand \index{\_\_at}
11570 (0xd7) CY;\InsetSpace ~
11572 \begin_inset LatexCommand \index{Flags}
11577 \begin_inset LatexCommand \index{Carry flag}
11584 \begin_layout Standard
11585 Special function registers which are located on an address dividable by
11586 8 are bit-addressable, an
11590 addresses a specific bit within these sfr.
11592 16 Bit and 32 bit special function
11593 register combinations which require a certain access order are better not
11603 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11604 this is not guaranteed.
11609 \begin_layout Standard
11610 Please note, if you use a header file which was written for another compiler
11611 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11617 Specifically the syntax
11620 sfr P0 = 0x80;\InsetSpace ~
11627 by SDCC to an assignment of 0x80 to a variable called P0
11630 \begin_inset Marginal
11633 \begin_layout Standard
11645 Nevertheless it is possible to write header files
11646 \begin_inset LatexCommand \index{Header files}
11651 \begin_inset LatexCommand \index{Include files}
11655 which can be shared among different compilers (see section
11656 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11664 \begin_layout Subsubsection
11666 \begin_inset LatexCommand \index{Pointer}
11670 to MCS51/DS390 specific memory spaces
11673 \begin_layout Standard
11674 SDCC allows (via language extensions) pointers to explicitly point to any
11675 of the memory spaces
11676 \begin_inset LatexCommand \index{Memory model}
11681 In addition to the explicit pointers, the compiler uses (by default) generic
11682 pointers which can be used to point to any of the memory spaces.
11687 declaration examples:
11690 \begin_layout Verse
11693 /* pointer physically in internal ram pointing to object in external ram
11696 __xdata unsigned char * __data p;
11700 /* pointer physically in external ram
11701 pointing to object in internal ram */
11703 __data unsigned char * __xdata p;
11708 pointer physically in code rom pointing to data in xdata space */
11711 unsigned char * __code p;
11715 /* pointer physically in code space pointing to
11716 data in code space */
11718 __code unsigned char * __code p;
11723 physically located in xdata space */
11725 unsigned char * __xdata p;
11730 pointer physically located in default memory space */
11737 the following is a function pointer
11738 \begin_inset LatexCommand \index{function pointer}
11742 physically located in data space */
11744 char (* __data fp)(void);
11747 \begin_layout Standard
11748 Well you get the idea.
11753 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11766 The highest order byte of the
11770 pointers contains the data space information.
11771 Assembler support routines are called whenever data is stored or retrieved
11777 These are useful for developing reusable library
11778 \begin_inset LatexCommand \index{Libraries}
11783 Explicitly specifying the pointer
11784 \begin_inset LatexCommand \index{pointer}
11788 type will generate the most efficient code.
11791 \begin_layout Subsubsection
11792 Notes on MCS51 memory
11793 \begin_inset LatexCommand \index{MCS51 memory}
11800 \begin_layout Standard
11801 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11802 RAM memory which is structured as follows:
11806 - Bytes 00-1F - 32 bytes to hold
11807 up to 4 banks of the registers R0 to R7,
11809 - Bytes 20-2F - 16 bytes to hold
11811 \begin_inset LatexCommand \index{bit}
11817 - Bytes 30-7F - 80 bytes for general purpose use.
11822 \begin_layout Standard
11823 Additionally some members of the MCS51 family may have up to 128 bytes of
11824 additional, indirectly addressable, internal RAM memory (
11829 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11834 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11839 Furthermore, some chips may have some built in external memory (
11844 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11849 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11853 ) which should not be confused with the internal, directly addressable RAM
11859 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11864 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11869 Sometimes this built in
11873 memory has to be activated before using it (you can probably find this
11874 information on the datasheet of the microcontroller your are using, see
11876 \begin_inset LatexCommand \ref{sub:Startup-Code}
11884 \begin_layout Standard
11885 Normally SDCC will only use the first bank
11886 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11890 of registers (register bank 0), but it is possible to specify that other
11891 banks of registers (keyword
11898 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11903 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11909 ) should be used for example in interrupt
11910 \begin_inset LatexCommand \index{interrupt}
11915 \begin_inset LatexCommand \index{\_\_interrupt}
11920 By default, the compiler will place the stack after the last byte of allocated
11921 memory for variables.
11922 For example, if the first 2 banks of registers are used, and only four
11927 variables, it will position the base of the internal stack at address 20
11929 This implies that as the stack
11930 \begin_inset LatexCommand \index{stack}
11934 grows, it will use up the remaining register banks, and the 16 bytes used
11935 by the 128 bit variables, and 80 bytes for general purpose use.
11936 If any bit variables are used, the data variables will be placed in unused
11937 register banks and after the byte holding the last bit variable.
11938 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11943 variables will be placed starting from address 0x10 to 0x20 and continue
11949 \begin_layout Standard
11959 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11963 to specify the start address of the
11971 \begin_layout Standard
11981 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11985 to specify the size of the total internal RAM (
11999 \begin_layout Standard
12000 By default the 8051 linker will place the stack after the last byte of (i)data
12006 \begin_layout Standard
12016 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12020 allows you to specify the start of the stack, i.e.
12021 you could start it after any data in the general purpose area.
12022 If your microcontroller has additional indirectly addressable internal
12027 ) you can place the stack on it.
12028 You may also need to use -
12032 \begin_layout Standard
12042 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12046 to set the start address of the external RAM (
12054 \begin_layout Standard
12064 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12068 to specify its size.
12069 Same goes for the code memory, using -
12073 \begin_layout Standard
12083 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12091 \begin_layout Standard
12101 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12106 If in doubt, don't specify any options and see if the resulting memory
12107 layout is appropriate, then you can adjust it.
12110 \begin_layout Standard
12111 The linker generates two files with memory allocation information.
12112 The first, with extension .map
12113 \begin_inset LatexCommand \index{<file>.map}
12117 shows all the variables and segments.
12118 The second with extension .mem
12119 \begin_inset LatexCommand \index{<file>.mem}
12123 shows the final memory layout.
12124 The linker will complain either if memory segments overlap, there is not
12125 enough memory, or there is not enough space for stack.
12126 If you get any linking warnings and/or errors related to stack or segments
12127 allocation, take a look at either the .map or .mem files to find out what
12129 The .mem file may even suggest a solution to the problem.
12130 \begin_inset VSpace bigskip
12136 \begin_layout Subsection
12137 Z80/Z180 Storage Class
12138 \begin_inset LatexCommand \index{Z80!Storage class}
12142 Language Extensions
12145 \begin_layout Subsubsection
12147 \begin_inset LatexCommand \index{sfr}
12152 \begin_inset LatexCommand \index{\_\_sfr}
12156 (in/out to 8-bit addresses)
12159 \begin_layout Standard
12161 \begin_inset LatexCommand \index{Z80}
12165 family has separate address spaces for memory and
12175 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12180 \begin_inset LatexCommand \index{Z80!I/O memory}
12185 \begin_inset LatexCommand \index{Z180!I/O memory}
12189 is accessed with special instructions, e.g.:
12192 \begin_layout Verse
12195 sfr at 0x78 IoPort;\InsetSpace ~
12197 /* define a var in I/O space at 78h called IoPort */
12201 \begin_layout Standard
12202 Writing 0x01 to this variable generates the assembly code:
12205 \begin_layout Verse
12225 \begin_layout Subsubsection
12227 \begin_inset LatexCommand \index{sfr}
12232 \begin_inset LatexCommand \index{\_\_sfr}
12236 (in/out to 16-bit addresses)
12239 \begin_layout Standard
12244 is used to support 16 bit addresses in I/O memory e.g.:
12247 \begin_layout Verse
12251 \begin_inset LatexCommand \index{at}
12256 \begin_inset LatexCommand \index{\_\_at}
12263 \begin_layout Standard
12264 Writing 0x01 to this variable generates the assembly code:
12267 \begin_layout Verse
12270 01 23 01\InsetSpace ~
12292 \begin_layout Subsubsection
12294 \begin_inset LatexCommand \index{sfr}
12299 \begin_inset LatexCommand \index{\_\_sfr}
12303 (in0/out0 to 8 bit addresses on Z180
12304 \begin_inset LatexCommand \index{Z180}
12309 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12316 \begin_layout Standard
12317 The compiler option -
12321 \begin_layout Standard
12331 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12335 =180 (80) and a compiler #pragma\InsetSpace ~
12337 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12341 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12351 If you include the file z180.h this will be set automatically.
12352 \begin_inset VSpace bigskip
12358 \begin_layout Subsection
12360 \begin_inset LatexCommand \index{HC08!Storage class}
12364 Language Extensions
12367 \begin_layout Subsubsection
12369 \begin_inset LatexCommand \index{data (hc08 storage class)}
12374 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12381 \begin_layout Standard
12382 The data storage class declares a variable that resides in the first 256
12383 bytes of memory (the direct page).
12385 \begin_inset LatexCommand \index{HC08}
12389 is most efficient at accessing variables (especially pointers) stored here.
12392 \begin_layout Subsubsection
12394 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12399 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12406 \begin_layout Standard
12407 The xdata storage class declares a variable that can reside anywhere in
12409 This is the default if no storage class is specified.
12411 \begin_inset VSpace bigskip
12417 \begin_layout Section
12418 Absolute Addressing
12419 \begin_inset LatexCommand \index{Absolute addressing}
12426 \begin_layout Standard
12427 Data items can be assigned an absolute address with the
12430 \begin_inset LatexCommand \index{at}
12435 \begin_inset LatexCommand \index{\_\_at}
12441 keyword, in addition to a storage class, e.g.:
12444 \begin_layout Verse
12448 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12453 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12458 \begin_inset LatexCommand \index{at}
12463 \begin_inset LatexCommand \index{\_\_at}
12467 0x7ffe unsigned int chksum;
12470 \begin_layout Standard
12471 or, better conforming to ISO/IEC 9899 C:
12474 \begin_layout Verse
12477 __xdata __at (0x7ffe) unsigned int chksum;
12480 \begin_layout Standard
12481 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12482 of the external ram.
12487 reserve any space for variables declared in this way
12488 \begin_inset Marginal
12491 \begin_layout Standard
12500 (they are implemented with an equate in the assembler).
12501 Thus it is left to the programmer to make sure there are no overlaps with
12502 other variables that are declared without the absolute address.
12503 The assembler listing file (.lst
12504 \begin_inset LatexCommand \index{<file>.lst}
12508 ) and the linker output files (.rst
12509 \begin_inset LatexCommand \index{<file>.rst}
12514 \begin_inset LatexCommand \index{<file>.map}
12518 ) are good places to look for such overlaps.
12519 Variables with an absolute address are
12522 \begin_inset Marginal
12525 \begin_layout Standard
12537 \begin_inset LatexCommand \index{Variable initialization}
12544 \begin_layout Standard
12545 In case of memory mapped I/O devices the keyword
12549 has to be used to tell the compiler that accesses might not be removed:
12552 \begin_layout Verse
12556 \begin_inset LatexCommand \index{volatile}
12561 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12566 \begin_inset LatexCommand \index{at}
12570 (0x8000) unsigned char PORTA_8255;
12573 \begin_layout Standard
12574 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12579 \begin_inset LatexCommand \index{Aligned array}
12586 starts at a block (256 byte) boundary
12587 \begin_inset LatexCommand \index{block boundary}
12592 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12598 Absolute addresses can be specified for variables in all
12599 storage classes, e.g.:
12602 \begin_layout Verse
12606 \begin_inset LatexCommand \index{bit}
12611 \begin_inset LatexCommand \index{at}
12618 \begin_layout Standard
12619 The above example will allocate the variable at offset 0x02 in the bit-addressab
12621 There is no real advantage to assigning absolute addresses to variables
12622 in this manner, unless you want strict control over all the variables allocated.
12623 One possible use would be to write hardware portable code.
12624 For example, if you have a routine that uses one or more of the microcontroller
12625 I/O pins, and such pins are different for two different hardwares, you
12626 can declare the I/O pins in your routine using:
12629 \begin_layout Verse
12633 \begin_inset LatexCommand \index{volatile}
12637 __bit MOSI;\InsetSpace ~
12641 /* master out, slave in */
12643 extern volatile __bit MISO;\InsetSpace ~
12650 extern volatile __bit MCLK;\InsetSpace ~
12659 Output of a byte on a 3-wire serial bus.
12664 If needed adapt polarity of clock,
12665 polarity of data and bit order
12670 unsigned char spi_io(unsigned char out_byte)
12695 MOSI = out_byte & 0x80;
12726 /* _asm nop _endasm; */\InsetSpace ~
12734 /* for slow peripherals */
12786 \begin_layout Standard
12787 Then, someplace in the code for the first hardware you would use
12790 \begin_layout Verse
12794 \begin_inset LatexCommand \index{at}
12799 \begin_inset LatexCommand \index{\_\_at}
12803 (0x80) MOSI;\InsetSpace ~
12807 /* I/O port 0, bit 0 */
12809 __bit __at (0x81) MISO;\InsetSpace ~
12816 __bit __at (0x82) MCLK;\InsetSpace ~
12820 /* I/O port 0, bit 2 */
12823 \begin_layout Standard
12824 Similarly, for the second hardware you would use
12827 \begin_layout Verse
12830 __bit __at (0x83) MOSI;\InsetSpace ~
12834 /* I/O port 0, bit 3 */
12836 __bit __at (0x91) MISO;\InsetSpace ~
12841 I/O port 1, bit 1 */
12844 \begin_inset LatexCommand \index{bit}
12848 __at (0x92) MCLK;\InsetSpace ~
12852 /* I/O port 1, bit 2 */
12855 \begin_layout Standard
12856 and you can use the same hardware dependent routine without changes, as
12857 for example in a library.
12858 This is somehow similar to sbit, but only one absolute address has to be
12859 specified in the whole project.
12860 \begin_inset VSpace bigskip
12866 \begin_layout Section
12868 \begin_inset LatexCommand \index{Parameters}
12873 \begin_inset LatexCommand \index{function parameter}
12878 \begin_inset LatexCommand \index{local variables}
12883 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12890 \begin_layout Standard
12891 Automatic (local) variables and parameters to functions can either be placed
12892 on the stack or in data-space.
12893 The default action of the compiler is to place these variables in the internal
12894 RAM (for small model) or external RAM (for large model).
12895 This in fact makes them similar to
12898 \begin_inset LatexCommand \index{static}
12904 so by default functions are non-reentrant
12905 \begin_inset LatexCommand \index{reentrant}
12914 They can be placed on the stack
12915 \begin_inset LatexCommand \index{stack}
12925 \begin_layout Standard
12935 \begin_inset LatexCommand \index{-\/-stack-auto}
12943 #pragma\InsetSpace ~
12947 \begin_inset LatexCommand \index{\#pragma stackauto}
12954 \begin_inset LatexCommand \index{reentrant}
12960 keyword in the function declaration, e.g.:
12963 \begin_layout Verse
12966 unsigned char foo(char i) __reentrant
12980 \begin_layout Standard
12981 Since stack space on 8051 is limited, the
12991 \begin_layout Standard
13002 option should be used sparingly.
13003 Note that the reentrant keyword just means that the parameters & local
13004 variables will be allocated to the stack, it
13008 mean that the function is register bank
13009 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13018 \begin_inset LatexCommand \index{local variables}
13022 can be assigned storage classes and absolute
13023 \begin_inset LatexCommand \index{Absolute addressing}
13030 \begin_layout Verse
13033 unsigned char foo()
13041 __xdata unsigned char i;
13054 \begin_inset LatexCommand \index{at}
13058 (0x31) unsigned char j;
13070 \begin_layout Standard
13071 In the above example the variable
13075 will be allocated in the external ram,
13079 in bit addressable space and
13090 \begin_layout Standard
13101 or when a function is declared as
13105 this should only be done for static variables.
13108 \begin_layout Standard
13110 \begin_inset LatexCommand \index{function parameter}
13114 however are not allowed any storage class
13115 \begin_inset LatexCommand \index{Storage class}
13119 , (storage classes for parameters will be ignored), their allocation is
13120 governed by the memory model in use, and the reentrancy options.
13123 \begin_layout Standard
13124 It is however allowed to use bit parameters in reentrant functions and also
13125 non-static local bit variables are supported.
13126 Efficient use is limited to 8 semi-bitregisters in bit space.
13127 They are pushed and popped to stack
13128 \begin_inset LatexCommand \index{stack}
13132 as a single byte just like the normal registers.
13135 \begin_layout Section
13137 \begin_inset LatexCommand \label{sub:Overlaying}
13142 \begin_inset LatexCommand \index{Overlaying}
13149 \begin_layout Standard
13151 \begin_inset LatexCommand \index{reentrant}
13155 functions SDCC will try to reduce internal ram space usage by overlaying
13156 parameters and local variables of a function (if possible).
13157 Parameters and local variables
13158 \begin_inset LatexCommand \index{local variables}
13162 of a function will be allocated to an overlayable segment if the function
13165 no other function calls and the function is non-reentrant and the memory
13167 \begin_inset LatexCommand \index{Memory model}
13174 If an explicit storage class
13175 \begin_inset LatexCommand \index{Storage class}
13179 is specified for a local variable, it will NOT be overlayed.
13182 \begin_layout Standard
13183 Note that the compiler (not the linkage editor) makes the decision for overlayin
13185 Functions that are called from an interrupt service routine
13186 \begin_inset Marginal
13189 \begin_layout Standard
13197 should be preceded by a #pragma\InsetSpace ~
13199 \begin_inset LatexCommand \index{\#pragma nooverlay}
13203 if they are not reentrant.
13206 \begin_layout Standard
13207 Also note that the compiler does not do any processing of inline assembler
13208 code, so the compiler might incorrectly assign local variables and parameters
13209 of a function into the overlay segment if the inline assembler code calls
13210 other c-functions that might use the overlay.
13211 In that case the #pragma\InsetSpace ~
13212 nooverlay should be used.
13215 \begin_layout Standard
13216 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13218 \begin_inset LatexCommand \index{Multiplication}
13223 \begin_inset LatexCommand \index{Division}
13227 will NOT be overlayed since these are implemented using external functions,
13231 \begin_layout Verse
13237 \begin_inset LatexCommand \index{\#pragma nooverlay}
13243 void set_error(unsigned char errcd)
13260 some_isr () __interrupt
13261 \begin_inset LatexCommand \index{interrupt}
13291 \begin_layout Standard
13292 In the above example the parameter
13300 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13302 not present, this could cause unpredictable runtime behavior when called
13303 from an interrupt service routine.
13304 The #pragma\InsetSpace ~
13305 nooverlay ensures that the parameters and local variables for
13306 the function are NOT overlayed.
13307 \begin_inset VSpace bigskip
13313 \begin_layout Section
13314 Interrupt Service Routines
13315 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13322 \begin_layout Subsection
13323 General Information
13326 \begin_layout Standard
13339 outines to be coded in C, with some extended keywords.
13342 \begin_layout Verse
13345 void timer_isr (void) __interrupt (1) __using (1)
13359 \begin_layout Standard
13360 The optional number following the
13363 \begin_inset LatexCommand \index{interrupt}
13368 \begin_inset LatexCommand \index{\_\_interrupt}
13374 keyword is the interrupt number this routine will service.
13375 When present, the compiler will insert a call to this routine in the interrupt
13377 \begin_inset LatexCommand \index{interrupt vector table}
13381 for the interrupt number specified.
13382 If you have multiple source files in your project, interrupt service routines
13383 can be present in any of them, but a prototype of the isr MUST be present
13384 or included in the file that contains the function
13389 The optional (8051 specific) keyword
13392 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13397 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13403 can be used to tell the compiler to use the specified register bank when
13404 generating code for this function.
13407 Interrupt service routines open the door for some very interesting bugs:
13410 \begin_layout Subsubsection
13411 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13415 Common interrupt pitfall: variable not declared
13420 \begin_layout Standard
13421 If an interrupt service routine changes variables which are accessed by
13422 other functions these variables have to be declared
13427 \begin_inset LatexCommand \index{volatile}
13433 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13440 \begin_layout Subsubsection
13441 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13445 Common interrupt pitfall:
13450 \begin_layout Standard
13451 If the access to these variables is not
13454 \begin_inset LatexCommand \index{atomic}
13461 the processor needs more than one instruction for the access and could
13462 be interrupted while accessing the variable) the interrupt must be disabled
13463 during the access to avoid inconsistent data.
13466 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13467 and should be protected by disabling interrupts.
13468 You're not automatically on the safe side if you use 8 bit variables though.
13469 We need an example here: f.e.
13470 on the 8051 the harmless looking
13471 \begin_inset Quotes srd
13481 \begin_inset Quotes sld
13490 \begin_inset Quotes srd
13500 \begin_inset Quotes sld
13503 from within an interrupt routine might get lost if the interrupt occurs
13506 \begin_inset Quotes sld
13511 counter\InsetSpace ~
13516 \begin_inset Quotes srd
13519 is not atomic on the 8051 even if
13523 is located in data memory.
13525 Bugs like these are hard to reproduce and can
13526 cause a lot of trouble.
13530 \begin_layout Subsubsection
13531 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13535 Common interrupt pitfall:
13540 \begin_layout Standard
13541 The return address and the registers used in the interrupt service routine
13542 are saved on the stack
13543 \begin_inset LatexCommand \index{stack}
13547 so there must be sufficient stack space.
13548 If there isn't variables or registers (or even the return address itself)
13555 \begin_inset LatexCommand \index{stack overflow}
13559 is most likely to happen if the interrupt occurs during the
13560 \begin_inset Quotes sld
13564 \begin_inset Quotes srd
13567 subroutine when the stack is already in use for f.e.
13568 many return addresses.
13571 \begin_layout Subsubsection
13572 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13576 Common interrupt pitfall:
13578 use of non-reentrant functions
13581 \begin_layout Standard
13582 A special note here, int (16 bit) and long (32 bit) integer division
13583 \begin_inset LatexCommand \index{Division}
13588 \begin_inset LatexCommand \index{Multiplication}
13593 \begin_inset LatexCommand \index{Modulus}
13598 \begin_inset LatexCommand \index{Floating point support}
13602 operations are implemented using external support routines.
13603 If an interrupt service routine needs to do any of these operations then
13604 the support routines (as mentioned in a following section) will have to
13605 be recompiled using the
13611 \begin_layout Standard
13621 \begin_inset LatexCommand \index{-\/-stack-auto}
13627 option and the source file will need to be compiled using the
13633 \begin_layout Standard
13645 \begin_inset LatexCommand \index{-\/-int-long-reent}
13652 Note, the type promotion
13653 \begin_inset LatexCommand \index{type promotion}
13657 required by ANSI C can cause 16 bit routines to be used
13658 \begin_inset Marginal
13661 \begin_layout Standard
13670 without the programmer being aware of it.
13674 (unsigned char)(tail-1)
13676 within the if clause in section
13677 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13684 \begin_layout Standard
13685 Calling other functions from an interrupt service routine is not recommended,
13686 avoid it if possible.
13687 Note that when some function is called from an interrupt service routine
13688 it should be preceded by a #pragma\InsetSpace ~
13690 \begin_inset LatexCommand \index{\#pragma nooverlay}
13694 if it is not reentrant.
13695 Furthermore nonreentrant functions should not be called from the main program
13696 while the interrupt service routine might be active.
13697 They also must not be called from low priority interrupt service routines
13698 while a high priority interrupt service routine might be active.
13699 You could use semaphores or make the function
13703 if all parameters are passed in registers.
13706 \begin_inset LatexCommand \ref{sub:Overlaying}
13711 about Overlaying and section
13712 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13717 about Functions using private register banks.
13718 \begin_inset VSpace bigskip
13724 \begin_layout Subsection
13725 MCS51/DS390 Interrupt Service Routines
13728 \begin_layout Standard
13730 \begin_inset LatexCommand \index{interrupt}
13734 numbers and the corresponding address & descriptions for the Standard 8051/8052
13736 SDCC will automatically adjust the
13737 \begin_inset LatexCommand \index{interrupt vector table}
13741 to the maximum interrupt number specified.
13746 \begin_layout Standard
13748 \begin_inset Tabular
13749 <lyxtabular version="3" rows="9" columns="3">
13751 <column alignment="center" valignment="top" leftline="true" width="0in">
13752 <column alignment="left" valignment="top" leftline="true" width="0in">
13753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13754 <row topline="true" bottomline="true">
13755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13758 \begin_layout Standard
13764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13767 \begin_layout Standard
13773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13776 \begin_layout Standard
13783 <row topline="true">
13784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13787 \begin_layout Standard
13793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13796 \begin_layout Standard
13802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13805 \begin_layout Standard
13812 <row topline="true">
13813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13816 \begin_layout Standard
13822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13825 \begin_layout Standard
13831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13834 \begin_layout Standard
13841 <row topline="true">
13842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13845 \begin_layout Standard
13851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13854 \begin_layout Standard
13860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13863 \begin_layout Standard
13870 <row topline="true">
13871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13874 \begin_layout Standard
13880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13883 \begin_layout Standard
13889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13892 \begin_layout Standard
13899 <row topline="true">
13900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13903 \begin_layout Standard
13909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13912 \begin_layout Standard
13918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13921 \begin_layout Standard
13928 <row topline="true">
13929 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13932 \begin_layout Standard
13938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13941 \begin_layout Standard
13947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13950 \begin_layout Standard
13957 <row topline="true">
13958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13961 \begin_layout Standard
13967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13970 \begin_layout Standard
13976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13979 \begin_layout Standard
13986 <row topline="true" bottomline="true">
13987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13990 \begin_layout Standard
13996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13999 \begin_layout Standard
14005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14008 \begin_layout Standard
14024 \begin_layout Standard
14025 If the interrupt service routine is defined without
14028 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14033 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14039 a register bank or with register bank 0 (
14043 0), the compiler will save the registers used by itself on the stack upon
14044 entry and restore them at exit, however if such an interrupt service routine
14045 calls another function then the entire register bank will be saved on the
14047 This scheme may be advantageous for small interrupt service routines which
14048 have low register usage.
14051 \begin_layout Standard
14052 If the interrupt service routine is defined to be using a specific register
14057 & psw are saved and restored, if such an interrupt service routine calls
14058 another function (using another register bank) then the entire register
14059 bank of the called function will be saved on the stack
14060 \begin_inset LatexCommand \index{stack}
14065 This scheme is recommended for larger interrupt service routines.
14066 \begin_inset VSpace bigskip
14072 \begin_layout Subsection
14074 \begin_inset LatexCommand \index{HC08}
14078 Interrupt Service Routines
14081 \begin_layout Standard
14082 Since the number of interrupts
14083 \begin_inset LatexCommand \index{HC08!interrupt}
14087 available is chip specific and the interrupt vector table always ends at
14088 the last byte of memory, the interrupt numbers corresponds to the interrupt
14089 vectors in reverse order of address.
14090 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14091 2 will use the interrupt vector at 0xfffa, and so on.
14092 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14093 this way; instead see section
14094 \begin_inset LatexCommand \ref{sub:Startup-Code}
14098 for details on customizing startup.
14099 \begin_inset VSpace bigskip
14105 \begin_layout Subsection
14106 Z80 Interrupt Service Routines
14109 \begin_layout Standard
14111 \begin_inset LatexCommand \index{Z80}
14115 uses several different methods for determining the correct interrupt
14116 \begin_inset LatexCommand \index{Z80!interrupt}
14120 vector depending on the hardware implementation.
14121 Therefore, SDCC ignores the optional interrupt number and does not attempt
14122 to generate an interrupt vector table.
14125 \begin_layout Standard
14126 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14127 instruction to return from the interrupt.
14128 To write an interrupt handler for the non-maskable interrupt, which needs
14129 a RETN instruction instead, add the
14136 \begin_layout Verse
14139 void nmi_isr (void) critical interrupt
14153 \begin_layout Standard
14154 However if you need to create a non-interruptable interrupt service routine
14155 you would also require the
14160 To distinguish between this and an nmi_isr you must provide an interrupt
14162 \begin_inset VSpace bigskip
14168 \begin_layout Section
14169 Enabling and Disabling Interrupts
14172 \begin_layout Subsection
14173 Critical Functions and Critical Statements
14176 \begin_layout Standard
14177 A special keyword may be associated with a block or a function declaring
14183 SDCC will generate code to disable all interrupts
14184 \begin_inset LatexCommand \index{interrupt}
14188 upon entry to a critical function and restore the interrupt enable to the
14189 previous state before returning.
14190 Nesting critical functions will need one additional byte on the stack
14191 \begin_inset LatexCommand \index{stack}
14198 \begin_layout Verse
14201 int foo () __critical
14202 \begin_inset LatexCommand \index{critical}
14207 \begin_inset LatexCommand \index{\_\_critical}
14232 \begin_layout Standard
14233 The critical attribute maybe used with other attributes like
14243 may also be used to disable interrupts more locally:
14246 \begin_layout Verse
14252 \begin_layout Standard
14253 More than one statement could have been included in the block.
14256 \begin_layout Subsection
14257 Enabling and Disabling Interrupts directly
14260 \begin_layout Standard
14262 \begin_inset LatexCommand \index{interrupt}
14266 can also be disabled and enabled directly (8051):
14269 \begin_layout Verse
14272 EA = 0;\InsetSpace ~
14298 \begin_layout Verse
14334 \begin_layout Verse
14337 EA = 1;\InsetSpace ~
14366 \begin_layout Verse
14405 \begin_layout Standard
14406 On other architectures which have seperate opcodes for enabling and disabling
14407 interrupts you might want to make use of defines with inline assembly
14408 \begin_inset LatexCommand \index{Assembler routines}
14413 \begin_inset LatexCommand \index{HC08!interrupt}
14420 \begin_layout Verse
14424 \begin_inset LatexCommand \index{\_asm}
14433 \begin_inset LatexCommand \index{\_endasm}
14440 \begin_layout Verse
14443 #define SEI _asm\InsetSpace ~
14450 \begin_layout Verse
14456 \begin_layout Standard
14457 Note: it is sometimes sufficient to disable only a specific interrupt source
14459 a timer or serial interrupt by manipulating an
14462 \begin_inset LatexCommand \index{interrupt mask}
14472 \begin_layout Standard
14473 Usually the time during which interrupts are disabled should be kept as
14475 This minimizes both
14480 \begin_inset LatexCommand \index{interrupt latency}
14484 (the time between the occurrence of the interrupt and the execution of
14485 the first code in the interrupt routine) and
14490 \begin_inset LatexCommand \index{interrupt jitter}
14494 (the difference between the shortest and the longest interrupt latency).
14495 These really are something different, f.e.
14496 a serial interrupt has to be served before its buffer overruns so it cares
14497 for the maximum interrupt latency, whereas it does not care about jitter.
14498 On a loudspeaker driven via a digital to analog converter which is fed
14499 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14500 a much smaller jitter will be very audible.
14503 \begin_layout Standard
14504 You can reenable interrupts within an interrupt routine and on some architecture
14505 s you can make use of two (or more) levels of
14507 interrupt priorities
14510 \begin_inset LatexCommand \index{interrupt priority}
14515 On some architectures which don't support interrupt priorities these can
14516 be implemented by manipulating the interrupt mask and reenabling interrupts
14517 within the interrupt routine.
14518 Check there is sufficient space on the stack
14519 \begin_inset LatexCommand \index{stack}
14523 and don't add complexity unless you have to.
14527 \begin_layout Subsection
14529 \begin_inset LatexCommand \index{semaphore}
14533 locking (mcs51/ds390)
14536 \begin_layout Standard
14537 Some architectures (mcs51/ds390) have an atomic
14538 \begin_inset LatexCommand \index{atomic}
14551 These type of instructions are typically used in preemptive multitasking
14552 systems, where a routine f.e.
14553 claims the use of a data structure ('acquires a lock
14554 \begin_inset LatexCommand \index{lock}
14558 on it'), makes some modifications and then releases the lock when the data
14559 structure is consistent again.
14560 The instruction may also be used if interrupt and non-interrupt code have
14561 to compete for a resource.
14562 With the atomic bit test and clear instruction interrupts
14563 \begin_inset LatexCommand \index{interrupt}
14567 don't have to be disabled for the locking operation.
14571 \begin_layout Standard
14572 SDCC generates this instruction if the source follows this pattern:
14575 \begin_layout Verse
14579 \begin_inset LatexCommand \index{volatile}
14583 bit resource_is_free;
14587 if (resource_is_free)
14597 resource_is_free=0;
14610 resource_is_free=1;
14617 \begin_layout Standard
14618 Note, mcs51 and ds390 support only an atomic
14619 \begin_inset LatexCommand \index{atomic}
14627 instruction (as opposed to atomic bit test and
14632 \begin_layout Section
14633 Functions using private register banks
14634 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14641 \begin_layout Standard
14642 Some architectures have support for quickly changing register sets.
14643 SDCC supports this feature with the
14646 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14651 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14657 attribute (which tells the compiler to use a register bank
14658 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14662 other than the default bank zero).
14663 It should only be applied to
14666 \begin_inset LatexCommand \index{interrupt}
14672 functions (see footnote below).
14673 This will in most circumstances make the generated ISR code more efficient
14674 since it will not have to save registers on the stack.
14677 \begin_layout Standard
14682 attribute will have no effect on the generated code for a
14686 function (but may occasionally be useful anyway
14690 \begin_layout Standard
14691 possible exception: if a function is called ONLY from 'interrupt' functions
14692 using a particular bank, it can be declared with the same 'using' attribute
14693 as the calling 'interrupt' functions.
14694 For instance, if you have several ISRs using bank one, and all of them
14695 call memcpy(), it might make sense to create a specialized version of memcpy()
14696 'using 1', since this would prevent the ISR from having to save bank zero
14697 to the stack on entry and switch to bank zero before calling the function
14706 (pending: Note, nowadays the
14710 attribute has an effect on
14714 the generated code for a
14725 \begin_layout Standard
14730 function using a non-zero bank will assume that it can trash that register
14731 bank, and will not save it.
14732 Since high-priority interrupts
14733 \begin_inset LatexCommand \index{interrupts}
14738 \begin_inset LatexCommand \index{interrupt priority}
14742 can interrupt low-priority ones on the 8051 and friends, this means that
14743 if a high-priority ISR
14747 a particular bank occurs while processing a low-priority ISR
14751 the same bank, terrible and bad things can happen.
14752 To prevent this, no single register bank should be
14756 by both a high priority and a low priority ISR.
14757 This is probably most easily done by having all high priority ISRs use
14758 one bank and all low priority ISRs use another.
14759 If you have an ISR which can change priority at runtime, you're on your
14760 own: I suggest using the default bank zero and taking the small performance
14764 \begin_layout Standard
14765 It is most efficient if your ISR calls no other functions.
14766 If your ISR must call other functions, it is most efficient if those functions
14767 use the same bank as the ISR (see note 1 below); the next best is if the
14768 called functions use bank zero.
14769 It is very inefficient to call a function using a different, non-zero bank
14772 \begin_inset VSpace bigskip
14778 \begin_layout Section
14780 \begin_inset LatexCommand \label{sub:Startup-Code}
14785 \begin_inset LatexCommand \index{Startup code}
14792 \begin_layout Subsection
14793 MCS51/DS390 Startup Code
14796 \begin_layout Standard
14797 The compiler triggers the linker to link certain initialization modules
14798 from the runtime library
14799 \begin_inset LatexCommand \index{Runtime library}
14803 called crt<something>.
14804 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14805 GSINIT5) is not linked unless the --xstack option is used.
14806 These modules are highly entangled by the use of special segments/areas,
14807 but a common layout is shown below:
14810 \begin_layout Verse
14818 \begin_layout Verse
14842 ljmp __sdcc_gsinit_startup
14845 \begin_layout Verse
14853 \begin_layout Verse
14865 .area GSINIT0 (CODE)
14867 __sdcc_gsinit_startup::
14877 mov sp,#__start__stack - 1
14880 \begin_layout Verse
14888 \begin_layout Verse
14900 .area GSINIT1 (CODE)
14902 __sdcc_init_xstack::
14904 ; Need to initialize in GSINIT1 in
14905 case the user's __sdcc_external_startup uses the xstack.
14915 mov __XPAGE,#(__start__x
14926 mov _spx,#__start__xstack
14929 \begin_layout Verse
14937 \begin_layout Verse
14949 .area GSINIT2 (CODE)
14959 lcall __sdcc_external_startup
14979 jz __sdcc_init_data
14990 __sdcc_program_startup
14995 \begin_layout Verse
15003 \begin_layout Verse
15015 .area GSINIT3 (CODE)
15068 mov r2,#((l_XINIT+255) >> 8)
15099 __XPAGE,#(s_XISEG >> 8)
15101 00001$:\InsetSpace ~
15165 00002$:\InsetSpace ~
15192 \begin_layout Verse
15200 \begin_layout Verse
15212 .area GSINIT4 (CODE)
15214 __mcs51_genRAMCLEAR::
15236 00004$:\InsetSpace ~
15250 ; _mcs51_genRAMCLEAR() end
15253 \begin_layout Verse
15261 \begin_layout Verse
15273 .area GSINIT4 (CODE)
15275 __mcs51_genXRAMCLEAR::
15326 mov __XPAGE,#(s_PSEG >> 8)
15338 00005$:\InsetSpace ~
15392 orl a,#(l_XSEG >> 8)
15435 00007$:\InsetSpace ~
15472 \begin_layout Verse
15480 \begin_layout Verse
15492 .area GSINIT5 (CODE)
15494 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15497 ; and __mcs51_genRAMCLEAR modifies _spx.
15507 mov __XPAGE,#(__start__x
15518 mov _spx,#__start__xstack
15521 \begin_layout Verse
15526 (application modules)
15529 \begin_layout Verse
15541 .area GSINIT (CODE)
15544 \begin_layout Verse
15552 \begin_layout Verse
15564 .area GSFINAL (CODE)
15574 ljmp __sdcc_program_startup
15576 ;---------------------------------
15577 -----------------------
15581 ;--------------------------------------------------
15604 __sdcc_program_startup:
15617 return from main will lock up
15630 \begin_layout Standard
15631 One of these modules (crtstart.asm) contains a call to the C routine
15633 _sdcc_external_startup()
15634 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15643 at the start of the CODE area.
15644 This routine is also in the runtime library
15645 \begin_inset LatexCommand \index{Runtime library}
15649 and returns 0 by default.
15650 If this routine returns a non-zero value, the static & global variable
15651 initialization will be skipped and the function main will be invoked.
15652 Otherwise static & global variables will be initialized before the function
15656 _sdcc_external_startup()
15658 routine to your program to override the default if you need to setup hardware
15659 or perform some other critical operation prior to static & global variable
15661 \begin_inset LatexCommand \index{Variable initialization}
15666 On some mcs51 variants xdata
15667 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15671 memory has to be explicitly enabled before it can be accessed or if the
15673 \begin_inset LatexCommand \index{watchdog}
15677 needs to be disabled, this is the place to do it.
15678 The startup code clears all internal data memory, 256 bytes by default,
15679 but from 0 to n-1 if
15685 \begin_layout Standard
15695 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15702 (recommended for Chipcon CC1010).
15705 \begin_layout Standard
15706 See also the compiler options
15712 \begin_layout Standard
15728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15738 \begin_layout Standard
15750 \begin_inset LatexCommand \index{-\/-main-return}
15755 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15759 about MCS51-variants.
15760 \begin_inset VSpace bigskip
15766 \begin_layout Subsection
15770 \begin_layout Standard
15772 \begin_inset LatexCommand \index{HC08}
15776 startup code follows the same scheme as the MCS51 startup code.
15777 \begin_inset VSpace bigskip
15783 \begin_layout Subsection
15787 \begin_layout Standard
15789 \begin_inset LatexCommand \index{Z80}
15793 the startup code is inserted by linking with crt0.o which is generated from
15794 sdcc/device/lib/z80/crt0.s.
15795 If you need a different startup code you can use the compiler option
15804 \begin_layout Standard
15819 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15823 and provide your own crt0.o.
15825 \begin_inset VSpace bigskip
15831 \begin_layout Section
15832 Inline Assembler Code
15833 \begin_inset LatexCommand \index{Assembler routines}
15840 \begin_layout Subsection
15841 A Step by Step Introduction
15842 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15849 \begin_layout Standard
15850 Starting from a small snippet of c-code this example shows for the MCS51
15851 how to use inline assembly, access variables, a function parameter and
15852 an array in xdata memory.
15853 The example uses an MCS51 here but is easily adapted for other architectures.
15854 This is a buffer routine which should be optimized:
15857 \begin_layout Verse
15861 unsigned char __far
15862 \begin_inset LatexCommand \index{far (storage class)}
15867 \begin_inset LatexCommand \index{\_\_far (storage class)}
15872 \begin_inset LatexCommand \index{at}
15877 \begin_inset LatexCommand \index{\_\_at}
15881 (0x7f00) buf[0x100];
15882 \begin_inset LatexCommand \index{Aligned array}
15888 unsigned char head, tail;\InsetSpace ~
15906 \begin_inset LatexCommand \index{interrupt}
15958 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15970 void to_buffer( unsigned char c )
15978 if( head != (unsigned char)(tail-1)
15985 \begin_inset LatexCommand \index{promotion to signed int}
15990 \begin_inset LatexCommand \index{type promotion}
15995 \begin_inset Marginal
15998 \begin_layout Standard
16017 buf[ head++ ] = c;\InsetSpace ~
16033 /* access to a 256 byte aligned array */
16038 \begin_layout Standard
16039 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16040 then a corresponding buffer.asm file is generated.
16041 We define a new function
16045 in file buffer.c in which we cut and paste the generated code, removing
16046 unwanted comments and some ':'.
16048 \begin_inset Quotes sld
16056 \begin_inset Quotes srd
16060 \begin_inset Quotes sld
16068 \begin_inset Quotes srd
16075 \begin_layout Standard
16076 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16077 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16079 The latter is also used in the library functions.
16084 to the beginning and the end of the function body:
16087 \begin_layout Verse
16091 /* With a cut and paste from the .asm file, we have something to start with.
16097 function is not yet OK! (registers aren't saved) */
16099 void to_buffer_asm(
16109 \begin_inset LatexCommand \index{\_asm}
16114 \begin_inset LatexCommand \index{\_\_asm}
16128 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16134 \begin_inset LatexCommand \index{promotion to signed int}
16139 \begin_inset LatexCommand \index{type promotion}
16192 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16193 \begin_inset LatexCommand \index{Aligned array}
16259 \begin_inset LatexCommand \index{\_endasm}
16264 \begin_inset LatexCommand \index{\_\_endasm}
16273 \begin_layout Standard
16274 The new file buffer.c should compile with only one warning about the unreferenced
16275 function argument 'c'.
16276 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16277 (1) and finally have:
16280 \begin_layout Verse
16284 unsigned char __far __at(0x7f00) buf[0x100];
16286 unsigned char head, tail;
16297 void to_buffer( unsigned char c )
16306 head != (unsigned char)(tail-1) )
16335 c; // to avoid warning: unreferenced function argument
16342 \begin_inset LatexCommand \index{\_asm}
16347 \begin_inset LatexCommand \index{\_\_asm}
16361 ; save used registers here.
16372 ; If we were still using r2,r3 we would have to push them here.
16375 ; if( head != (unsigned char)(tail-1) )
16419 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16455 a,dpl \InsetSpace ~
16462 ; dpl holds lower byte of function argument
16474 dpl,_head \InsetSpace ~
16477 ; buf is 0x100 byte aligned so head can be used directly
16520 ; we could do an ANL _head,#0x0f here to use a
16521 smaller buffer (see above)
16533 ; restore used registers here
16540 \begin_inset LatexCommand \index{\_endasm}
16545 \begin_inset LatexCommand \index{\_\_endasm}
16556 \begin_layout Standard
16557 The inline assembler code can contain any valid code understood by the assembler
16558 , this includes any assembler directives and comment lines.
16559 The assembler does not like some characters like ':' or ''' in comments.
16560 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16561 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16566 \begin_inset LatexCommand \index{Assembler documentation}
16571 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16579 \begin_layout Standard
16580 The compiler does not do any validation of the code within the
16583 \begin_inset LatexCommand \index{\_asm}
16588 \begin_inset LatexCommand \index{\_\_asm}
16596 \begin_inset LatexCommand \index{\_endasm}
16601 \begin_inset LatexCommand \index{\_\_endasm}
16610 Specifically it will not know which registers are used and thus register
16612 \begin_inset LatexCommand \index{push/pop}
16616 has to be done manually.
16620 \begin_layout Standard
16621 It is recommended that each assembly instruction (including labels) be placed
16622 in a separate line (as the example shows).
16627 \begin_layout Standard
16639 \begin_inset LatexCommand \index{-\/-peep-asm}
16645 command line option is used, the inline assembler code will be passed through
16646 the peephole optimizer
16647 \begin_inset LatexCommand \index{Peephole optimizer}
16652 There are only a few (if any) cases where this option makes sense, it might
16653 cause some unexpected changes in the inline assembler code.
16654 Please go through the peephole optimizer rules defined in file
16658 before using this option.
16661 \begin_layout Subsection
16663 \begin_inset LatexCommand \label{sub:Naked-Functions}
16668 \begin_inset LatexCommand \index{Naked functions}
16675 \begin_layout Standard
16676 A special keyword may be associated with a function declaring it as
16679 \begin_inset LatexCommand \index{\_naked}
16684 \begin_inset LatexCommand \index{\_\_naked}
16695 function modifier attribute prevents the compiler from generating prologue
16696 \begin_inset LatexCommand \index{function prologue}
16701 \begin_inset LatexCommand \index{function epilogue}
16705 code for that function.
16706 This means that the user is entirely responsible for such things as saving
16707 any registers that may need to be preserved, selecting the proper register
16708 bank, generating the
16712 instruction at the end, etc.
16713 Practically, this means that the contents of the function must be written
16714 in inline assembler.
16715 This is particularly useful for interrupt functions, which can have a large
16716 (and often unnecessary) prologue/epilogue.
16717 For example, compare the code generated by these two functions:
16720 \begin_layout Verse
16724 \begin_inset LatexCommand \index{volatile}
16728 data unsigned char counter;
16732 void simpleInterrupt(void) __interrupt
16733 \begin_inset LatexCommand \index{interrupt}
16738 \begin_inset LatexCommand \index{\_\_interrupt}
16756 void nakedInterrupt(void) __interrupt (2) __naked
16765 \begin_inset LatexCommand \index{\_asm}
16770 \begin_inset LatexCommand \index{\_\_asm}
16787 _counter ; does not change flags, no need to save psw
16800 include ret or reti in _naked function.
16807 \begin_inset LatexCommand \index{\_endasm}
16812 \begin_inset LatexCommand \index{\_\_endasm}
16821 \begin_layout Standard
16822 For an 8051 target, the generated simpleInterrupt looks like:
16825 \begin_layout Verse
16832 example, recent versions of SDCC generate
16838 code for simpleInterrupt() and nakedInterrupt()!
16979 \begin_layout Standard
16980 whereas nakedInterrupt looks like:
16983 \begin_layout Verse
16996 _counter ; does not change flags, no need to save psw
17015 MUST explicitly include ret or reti in _naked function
17018 \begin_layout Standard
17019 The related directive #pragma exclude
17020 \begin_inset LatexCommand \index{\#pragma exclude}
17024 allows a more fine grained control over pushing & popping
17025 \begin_inset LatexCommand \index{push/pop}
17032 \begin_layout Standard
17033 While there is nothing preventing you from writing C code inside a
17037 function, there are many ways to shoot yourself in the foot doing this,
17038 and it is recommended that you stick to inline assembler.
17041 \begin_layout Subsection
17042 Use of Labels within Inline Assembler
17045 \begin_layout Standard
17046 SDCC allows the use of in-line assembler with a few restrictions regarding
17048 In older versions of the compiler all labels defined within inline assembler
17049 code had to be of the form
17053 where nnnnn is a number less than 100 (which implies a limit of utmost
17054 100 inline assembler labels
17065 \begin_layout Verse
17069 \begin_inset LatexCommand \index{\_asm}
17074 \begin_inset LatexCommand \index{\_\_asm}
17104 \begin_inset LatexCommand \index{\_endasm}
17109 \begin_inset LatexCommand \index{\_\_endasm}
17116 \begin_layout Standard
17117 Inline assembler code cannot reference any C-labels, however it can reference
17119 \begin_inset LatexCommand \index{Labels}
17123 defined by the inline assembler, e.g.:
17126 \begin_layout Verse
17149 ; some assembler code
17170 /* some more c code */
17172 clabel:\InsetSpace ~
17174 /* inline assembler cannot reference this
17187 $0003: ;label (can be referenced by inline assembler only)
17195 \begin_inset LatexCommand \index{\_endasm}
17200 \begin_inset LatexCommand \index{\_\_endasm}
17210 /* some more c code */
17215 \begin_layout Standard
17216 In other words inline assembly code can access labels defined in inline
17217 assembly within the scope of the function.
17218 The same goes the other way, i.e.
17219 labels defines in inline assembly can not be accessed by C statements.
17222 \begin_layout Section
17223 Interfacing with Assembler Code
17224 \begin_inset LatexCommand \index{Assembler routines}
17231 \begin_layout Subsection
17232 Global Registers used for Parameter Passing
17233 \begin_inset LatexCommand \index{Parameter passing}
17240 \begin_layout Standard
17241 The compiler always uses the global registers
17244 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17249 \begin_inset LatexCommand \index{DPTR}
17254 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17263 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17269 to pass the first parameter to a function, and also to pass the return
17271 \begin_inset LatexCommand \index{return value}
17275 of function; according to the following scheme: one byte return value in
17280 , two byte value in
17289 three byte values (generic pointers) in
17301 , and four byte values in
17319 \begin_inset LatexCommand \index{generic pointer}
17323 contain type of accessed memory in
17344 \begin_inset Note Note
17347 \begin_layout Standard
17348 This might not be the case of certain memory models (medium???)
17356 \begin_layout Standard
17357 The second parameter onwards is either allocated on the stack (for reentrant
17362 \begin_layout Standard
17371 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17375 \begin_layout Subsection
17379 \begin_layout Standard
17380 Unless the called function is declared as
17385 \begin_inset LatexCommand \index{naked}
17393 \begin_layout Standard
17403 \begin_inset LatexCommand \index{-\/-callee-saves}
17411 \begin_layout Standard
17420 -all-callee-saves command line option or the corresponding callee_saves
17421 pragma are used, the caller will save the registers (
17425 ) around the call, so the called function can destroy they content freely.
17428 \begin_layout Standard
17429 If the called function is not declared as
17433 , the caller will swap register banks around the call, if caller and callee
17434 use different register banks (having them defined by the
17442 \begin_layout Standard
17443 The called function can also use
17459 observing that they are used for parameter/return value passing.
17462 \begin_layout Subsection
17463 Assembler Routine (non-reentrant)
17466 \begin_layout Standard
17467 In the following example
17468 \begin_inset LatexCommand \index{reentrant}
17473 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17477 the function c_func calls an assembler routine asm_func, which takes two
17479 \begin_inset LatexCommand \index{function parameter}
17486 \begin_layout Verse
17489 extern int asm_func(unsigned char, unsigned char);
17493 int c_func (unsigned char
17494 i, unsigned char j)
17502 return asm_func(i,j);
17516 return c_func(10,9);
17521 \begin_layout Standard
17522 The corresponding assembler function is:
17525 \begin_layout Verse
17528 .globl _asm_func_PARM_2
17630 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17647 \begin_layout Standard
17648 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17649 the parameter number starting from 1, and counting from the left.
17650 The first parameter is passed in
17666 according to the description above.
17667 The variable name for the second parameter will be _<function_name>_PARM_2.
17672 ble the assembler routine with the following command:
17679 asx8051 -losg asmfunc.asm
17686 Then compile and link the assembler routine to the C source file with the
17694 sdcc cfunc.c asmfunc.rel
17697 \begin_layout Subsection
17698 Assembler Routine (reentrant)
17701 \begin_layout Standard
17703 \begin_inset LatexCommand \index{reentrant}
17708 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17712 the second parameter
17713 \begin_inset LatexCommand \index{function parameter}
17717 onwards will be passed on the stack, the parameters are pushed from right
17719 before the call the second leftmost parameter will be on the top of the
17720 stack (the leftmost parameter is passed in registers).
17721 Here is an example:
17724 \begin_layout Verse
17727 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17732 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
17741 return asm_func(i,j,k);
17755 return c_func(10,9,8);
17760 \begin_layout Standard
17761 The corresponding (unoptimized) assembler routine is:
17764 \begin_layout Verse
17784 _bp,sp\InsetSpace ~
17790 ;stack contains: _bp, return
17791 address, second parameter, third parameter
17815 a,#0xfd\InsetSpace ~
17821 pointer to the second parameter
17845 a,#0xfc\InsetSpace ~
17851 to the rightmost parameter
17892 result (= sum of all three parameters)
17907 ;return value goes into dptr
17941 \begin_layout Standard
17942 The compiling and linking procedure remains the same, however note the extra
17943 entry & exit linkage required for the assembler code, _bp is the stack
17944 frame pointer and is used to compute the offset into the stack for parameters
17945 and local variables.
17946 \begin_inset VSpace bigskip
17952 \begin_layout Section
17954 \begin_inset LatexCommand \index{int (16 bit)}
17959 \begin_inset LatexCommand \index{long (32 bit)}
17966 \begin_layout Standard
17967 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17968 multiplication and modulus operations are implemented by support routines.
17969 These support routines are all developed in ANSI-C to facilitate porting
17970 to other MCUs, although some model specific assembler optimizations are
17972 The following files contain the described routines, all of them can be
17973 found in <installdir>/share/sdcc/lib.
17978 \begin_layout Standard
17980 \begin_inset Tabular
17981 <lyxtabular version="3" rows="11" columns="2">
17983 <column alignment="left" valignment="top" leftline="true" width="0">
17984 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17985 <row topline="true" bottomline="true">
17986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17989 \begin_layout Standard
17997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18000 \begin_layout Standard
18009 <row topline="true">
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18013 \begin_layout Standard
18019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18022 \begin_layout Standard
18023 16 bit multiplication
18029 <row topline="true">
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18033 \begin_layout Standard
18039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18042 \begin_layout Standard
18043 signed 16 bit division (calls _divuint)
18049 <row topline="true">
18050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18053 \begin_layout Standard
18059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18062 \begin_layout Standard
18063 unsigned 16 bit division
18069 <row topline="true">
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18073 \begin_layout Standard
18079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18082 \begin_layout Standard
18083 signed 16 bit modulus (calls _moduint)
18089 <row topline="true">
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18093 \begin_layout Standard
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18102 \begin_layout Standard
18103 unsigned 16 bit modulus
18109 <row topline="true">
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18113 \begin_layout Standard
18119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18122 \begin_layout Standard
18123 32 bit multiplication
18129 <row topline="true">
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18133 \begin_layout Standard
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18142 \begin_layout Standard
18143 signed 32 division (calls _divulong)
18149 <row topline="true">
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18153 \begin_layout Standard
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18162 \begin_layout Standard
18163 unsigned 32 division
18169 <row topline="true">
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18173 \begin_layout Standard
18179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18182 \begin_layout Standard
18183 signed 32 bit modulus (calls _modulong)
18189 <row topline="true" bottomline="true">
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18193 \begin_layout Standard
18199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18202 \begin_layout Standard
18203 unsigned 32 bit modulus
18218 \begin_layout Standard
18219 Since they are compiled as
18224 \begin_inset LatexCommand \index{reentrant}
18229 \begin_inset LatexCommand \index{interrupt}
18233 service routines should not do any of the above operations.
18234 If this is unavoidable then the above routines will need to be compiled
18241 \begin_layout Standard
18251 \begin_inset LatexCommand \index{-\/-stack-auto}
18257 option, after which the source program will have to be compiled with
18263 \begin_layout Standard
18273 \begin_inset LatexCommand \index{-\/-int-long-reent}
18280 Notice that you don't have to call these routines directly.
18281 The compiler will use them automatically every time an integer operation
18285 \begin_layout Section
18286 Floating Point Support
18287 \begin_inset LatexCommand \index{Floating point support}
18294 \begin_layout Standard
18295 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18296 The floating point support routines are derived from gcc's floatlib.c and
18297 consist of the following routines:
18302 \begin_layout Standard
18306 \begin_inset Tabular
18307 <lyxtabular version="3" rows="17" columns="2">
18309 <column alignment="left" valignment="top" leftline="true" width="0">
18310 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18311 <row topline="true" bottomline="true">
18312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18315 \begin_layout Standard
18330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18333 \begin_layout Standard
18340 <row topline="true">
18341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18344 \begin_layout Standard
18359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18362 \begin_layout Standard
18372 add floating point numbers
18378 <row topline="true">
18379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18382 \begin_layout Standard
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18400 \begin_layout Standard
18410 subtract floating point numbers
18416 <row topline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18420 \begin_layout Standard
18435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18438 \begin_layout Standard
18448 divide floating point numbers
18454 <row topline="true">
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18458 \begin_layout Standard
18473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18476 \begin_layout Standard
18486 multiply floating point numbers
18492 <row topline="true">
18493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18496 \begin_layout Standard
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18514 \begin_layout Standard
18524 convert floating point to unsigned char
18530 <row topline="true">
18531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18534 \begin_layout Standard
18549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18552 \begin_layout Standard
18562 convert floating point to signed char
18568 <row topline="true">
18569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18572 \begin_layout Standard
18587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18590 \begin_layout Standard
18600 convert floating point to unsigned int
18606 <row topline="true">
18607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18610 \begin_layout Standard
18625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18628 \begin_layout Standard
18638 convert floating point to signed int
18644 <row topline="true">
18645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18648 \begin_layout Standard
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18674 \begin_layout Standard
18684 convert floating point to unsigned long
18690 <row topline="true">
18691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18694 \begin_layout Standard
18709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18712 \begin_layout Standard
18722 convert floating point to signed long
18728 <row topline="true">
18729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18732 \begin_layout Standard
18747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18750 \begin_layout Standard
18760 convert unsigned char to floating point
18766 <row topline="true">
18767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18770 \begin_layout Standard
18785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18788 \begin_layout Standard
18798 convert char to floating point number
18804 <row topline="true">
18805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18808 \begin_layout Standard
18823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18826 \begin_layout Standard
18836 convert unsigned int to floating point
18842 <row topline="true">
18843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18846 \begin_layout Standard
18861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18864 \begin_layout Standard
18874 convert int to floating point numbers
18880 <row topline="true">
18881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18884 \begin_layout Standard
18899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18902 \begin_layout Standard
18912 convert unsigned long to floating point number
18918 <row topline="true" bottomline="true">
18919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18922 \begin_layout Standard
18937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18940 \begin_layout Standard
18950 convert long to floating point number
18965 \begin_layout Standard
18966 These support routines are developed in ANSI-C so there is room for space
18967 and speed improvement
18971 \begin_layout Standard
18972 These floating point routines (
18976 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18983 Note if all these routines are used simultaneously the data space might
18985 For serious floating point usage the large model might be needed.
18986 Also notice that you don't have to call this routines directly.
18987 The compiler will use them automatically every time a floating point operation
18989 \begin_inset VSpace bigskip
18995 \begin_layout Section
18997 \begin_inset LatexCommand \index{Libraries}
19004 \begin_layout Standard
19007 <pending: this is messy and incomplete - a little more information is in
19008 sdcc/doc/libdoc.txt
19013 \begin_layout Subsection
19014 Compiler support routines (_gptrget, _mulint etc.)
19017 \begin_layout Subsection
19018 Stdclib functions (puts, printf, strcat etc.)
19021 \begin_layout Subsubsection
19025 \begin_layout Paragraph
19026 getchar(), putchar()
19029 \begin_layout Standard
19030 \begin_inset LatexCommand \index{<stdio.h>}
19034 As usual on embedded systems you have to provide your own
19037 \begin_inset LatexCommand \index{getchar()}
19046 \begin_inset LatexCommand \index{putchar()}
19053 SDCC does not know whether the system connects to a serial line with or
19054 without handshake, LCD, keyboard or other device.
19068 You'll find examples for serial routines f.e.
19069 in sdcc/device/lib.
19070 For the mcs51 this minimalistic polling
19074 routine might be a start:
19077 \begin_layout Verse
19080 void putchar (char c) {
19086 while (!TI)\InsetSpace ~
19089 /* assumes UART is initialized */
19117 \begin_layout Paragraph
19121 \begin_layout Standard
19125 \begin_inset LatexCommand \index{printf()}
19135 does not support float (except on ds390).
19136 To enable this recompile it with the option
19142 \begin_layout Standard
19152 \begin_inset LatexCommand \index{USE\_FLOATS}
19158 on the command line.
19165 \begin_layout Standard
19175 \begin_inset LatexCommand \index{-\/-model-large}
19181 for the mcs51 port, since this uses a lot of memory.
19184 \begin_layout Standard
19185 If you're short on code memory you might want to use
19188 \begin_inset LatexCommand \index{printf\_small()}
19203 For the mcs51 there additionally are assembly versions
19206 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19212 (subset of printf using less than 270 bytes) and
19215 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19224 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19230 (floating-point aware version of printf_fast) which should fit the requirements
19231 of many embedded systems (printf_fast() can be customized by unsetting
19236 support long variables and field widths).
19237 Be sure to use only one of these printf options within a project.
19242 \begin_layout Standard
19243 Feature matrix of different
19250 \begin_layout Standard
19251 \begin_inset Tabular
19252 <lyxtabular version="3" rows="14" columns="7">
19253 <features islongtable="true">
19254 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19255 <column alignment="center" valignment="top" leftline="true" width="0">
19256 <column alignment="center" valignment="top" leftline="true" width="12col%">
19257 <column alignment="center" valignment="top" leftline="true" width="10col%">
19258 <column alignment="center" valignment="top" leftline="true" width="0">
19259 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19260 <column alignment="center" valignment="top" rightline="true" width="0">
19261 <row topline="true" bottomline="true" endhead="true">
19262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19265 \begin_layout Standard
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19277 \begin_layout Standard
19279 \begin_inset LatexCommand \index{printf}
19288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_layout Standard
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19302 \begin_layout Standard
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19311 \begin_layout Standard
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19320 \begin_layout Standard
19326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19329 \begin_layout Standard
19336 <row topline="true" endhead="true">
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19340 \begin_layout Standard
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19349 \begin_layout Standard
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_layout Standard
19368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19371 \begin_layout Standard
19379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19382 \begin_layout Standard
19390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19393 \begin_layout Standard
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19404 \begin_layout Standard
19413 <row topline="true" endhead="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19417 \begin_layout Standard
19418 \begin_inset Quotes sld
19422 \begin_inset Quotes srd
19428 \begin_layout Standard
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19437 \begin_layout Standard
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19446 \begin_layout Standard
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19455 \begin_layout Standard
19461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19464 \begin_layout Standard
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19473 \begin_layout Standard
19479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19482 \begin_layout Standard
19489 <row topline="true" endhead="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19493 \begin_layout Standard
19497 \begin_layout Standard
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19506 \begin_layout Standard
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19515 \begin_layout Standard
19521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19524 \begin_layout Standard
19525 0.45k / 0.47k (+ _ltoa)
19530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19533 \begin_layout Standard
19539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19542 \begin_layout Standard
19548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19551 \begin_layout Standard
19558 <row topline="true">
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19562 \begin_layout Standard
19568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19571 \begin_layout Standard
19581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19584 \begin_layout Standard
19631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19634 \begin_layout Standard
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19676 \begin_layout Standard
19682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19685 \begin_layout Standard
19691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19694 \begin_layout Standard
19701 <row topline="true">
19702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19705 \begin_layout Standard
19706 long (32 bit) support
19711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19714 \begin_layout Standard
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19723 \begin_layout Standard
19729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19732 \begin_layout Standard
19738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19741 \begin_layout Standard
19747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19750 \begin_layout Standard
19765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19768 \begin_layout Standard
19775 <row topline="true">
19776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19779 \begin_layout Standard
19780 byte arguments on stack
19785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19788 \begin_layout Standard
19794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19797 \begin_layout Standard
19803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19806 \begin_layout Standard
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19815 \begin_layout Standard
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19824 \begin_layout Standard
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19833 \begin_layout Standard
19840 <row topline="true">
19841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19844 \begin_layout Standard
19846 \begin_inset LatexCommand \index{Floating point support}
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19858 \begin_layout Standard
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19867 \begin_layout Standard
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19876 \begin_layout Standard
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19885 \begin_layout Standard
19891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19894 \begin_layout Standard
19899 \begin_layout Standard
19900 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19913 \begin_layout Standard
19920 <row topline="true">
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19924 \begin_layout Standard
19925 float formats %e %g
19930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19933 \begin_layout Standard
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19942 \begin_layout Standard
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_layout Standard
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19960 \begin_layout Standard
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19969 \begin_layout Standard
19975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19978 \begin_layout Standard
19985 <row topline="true" bottomline="true">
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_layout Standard
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19998 \begin_layout Standard
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_layout Standard
20013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20016 \begin_layout Standard
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20025 \begin_layout Standard
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20034 \begin_layout Standard
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20043 \begin_layout Standard
20050 <row bottomline="true">
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20054 \begin_layout Standard
20059 \begin_layout Standard
20060 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20064 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20072 \begin_layout Standard
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20081 \begin_layout Standard
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20090 \begin_layout Standard
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20099 \begin_layout Standard
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20108 \begin_layout Standard
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20117 \begin_layout Standard
20123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20126 \begin_layout Standard
20133 <row bottomline="true">
20134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20137 \begin_layout Standard
20142 \begin_layout Standard
20143 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20152 \begin_layout Standard
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20161 \begin_layout Standard
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_layout Standard
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20179 \begin_layout Standard
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20188 \begin_layout Standard
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20197 \begin_layout Standard
20203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20206 \begin_layout Standard
20211 \begin_layout Standard
20212 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20223 <row bottomline="true">
20224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20227 \begin_layout Standard
20232 \begin_layout Standard
20233 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20242 \begin_layout Standard
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_layout Standard
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20260 \begin_layout Standard
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20269 \begin_layout Standard
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20278 \begin_layout Standard
20284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20287 \begin_layout Standard
20293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20296 \begin_layout Standard
20303 <row bottomline="true">
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_layout Standard
20312 \begin_layout Standard
20313 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20322 \begin_layout Standard
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 \begin_layout Standard
20337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20340 \begin_layout Standard
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20349 \begin_layout Standard
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20358 \begin_layout Standard
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20367 \begin_layout Standard
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20376 \begin_layout Standard
20390 \begin_layout Subsubsection
20392 \begin_inset LatexCommand \index{malloc.h}
20399 \begin_layout Standard
20400 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20401 using dynamic memory allocation
20402 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20407 \begin_inset LatexCommand \index{heap (malloc)}
20411 space of 1024 bytes is provided for malloc to allocate memory from.
20412 If you need a different heap size you need to recompile _heap.c with the
20413 required size defined in HEAP_SIZE.
20414 It is recommended to make a copy of this file into your project directory
20415 and compile it there with:
20418 \begin_layout Verse
20421 sdcc -c _heap.c -D HEAD_SIZE=2048
20424 \begin_layout Standard
20425 And then link it with:
20428 \begin_layout Verse
20431 sdcc main.rel _heap.rel
20434 \begin_layout Subsection
20435 Math functions (sinf, powf, sqrtf etc.)
20438 \begin_layout Subsubsection
20442 \begin_layout Standard
20443 See definitions in file <math.h>.
20446 \begin_layout Subsection
20450 \begin_layout Standard
20452 \begin_inset LatexCommand \index{Libraries}
20456 included in SDCC should have a license at least as liberal as the GNU Lesser
20457 General Public License
20458 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20469 \begin_layout Standard
20470 \begin_inset Note Note
20473 \begin_layout Standard
20474 license statements for the libraries are missing.
20475 sdcc/device/lib/ser_ir.c
20478 \begin_layout Standard
20480 come with a GPL (as opposed to LGPL) License - this will not be liberal
20481 enough for many embedded programmers.
20489 \begin_layout Standard
20490 If you have ported some library or want to share experience about some code
20492 falls into any of these categories Busses (I
20493 \begin_inset Formula $^{\textrm{2}}$
20496 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20497 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20498 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20499 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20504 would certainly like to hear about it.
20507 \begin_layout Standard
20508 Programmers coding for embedded systems are not especially famous for being
20509 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20510 e these references are very valuable.
20511 Let's help to create a climate where information is shared.
20512 \begin_inset VSpace bigskip
20518 \begin_layout Section
20522 \begin_layout Subsection
20523 MCS51 Memory Models
20524 \begin_inset LatexCommand \index{Memory model}
20529 \begin_inset LatexCommand \index{MCS51 memory model}
20536 \begin_layout Subsubsection
20537 Small, Medium and Large
20540 \begin_layout Standard
20541 SDCC allows three memory models for MCS51 code,
20550 Modules compiled with different memory models should
20554 be combined together or the results would be unpredictable.
20555 The library routines supplied with the compiler are compiled as small,
20557 The compiled library modules are contained in separate directories as small,
20558 medium and large so that you can link to the appropriate set.
20561 \begin_layout Standard
20562 When the medium or large model is used all variables declared without a
20563 storage class will be allocated into the external ram, this includes all
20564 parameters and local variables (for non-reentrant
20565 \begin_inset LatexCommand \index{reentrant}
20570 When the small model is used variables without storage class are allocated
20571 in the internal ram.
20574 \begin_layout Standard
20575 Judicious usage of the processor specific storage classes
20576 \begin_inset LatexCommand \index{Storage class}
20580 and the 'reentrant' function type will yield much more efficient code,
20581 than using the large model.
20582 Several optimizations are disabled when the program is compiled using the
20583 large model, it is therefore recommended that the small model be used unless
20584 absolutely required.
20587 \begin_layout Subsubsection
20589 \begin_inset LatexCommand \label{sub:External-Stack}
20594 \begin_inset LatexCommand \index{stack}
20599 \begin_inset LatexCommand \index{External stack (mcs51)}
20606 \begin_layout Standard
20607 The external stack (-
20611 \begin_layout Standard
20621 \begin_inset LatexCommand \index{-\/-xstack}
20625 ) is located in pdata
20626 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20630 memory (usually at the start of the external ram segment) and uses all
20631 unused space in pdata (max.
20637 \begin_layout Standard
20646 -xstack option is used to compile the program, the parameters and local
20648 \begin_inset LatexCommand \index{local variables}
20652 of all reentrant functions are allocated in this area.
20653 This option is provided for programs with large stack space requirements.
20654 When used with the -
20658 \begin_layout Standard
20668 \begin_inset LatexCommand \index{-\/-stack-auto}
20672 option, all parameters and local variables are allocated on the external
20673 stack (note: support libraries will need to be recompiled with the same
20675 There is a predefined target in the library makefile).
20678 \begin_layout Standard
20679 The compiler outputs the higher order address byte of the external ram segment
20681 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20686 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20690 ), therefore when using the External Stack option, this port
20694 be used by the application program.
20697 \begin_layout Subsection
20699 \begin_inset LatexCommand \index{Memory model}
20704 \begin_inset LatexCommand \index{DS390 memory model}
20711 \begin_layout Standard
20712 The only model supported is Flat 24
20713 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20718 This generates code for the 24 bit contiguous addressing mode of the Dallas
20720 In this mode, up to four meg of external RAM or code space can be directly
20722 See the data sheets at www.dalsemi.com for further information on this part.
20727 that the compiler does not generate any code to place the processor into
20728 24 bitmode (although
20732 in the ds390 libraries will do that for you).
20738 \begin_inset LatexCommand \index{Tinibios (DS390)}
20742 , the boot loader or similar code must ensure that the processor is in 24
20743 bit contiguous addressing mode before calling the SDCC startup code.
20754 \begin_layout Standard
20765 option, variables will by default be placed into the XDATA segment.
20770 Segments may be placed anywhere in the 4 meg address space using the usual
20775 \begin_layout Standard
20785 Note that if any segments are located above 64K, the -r flag must be passed
20786 to the linker to generate the proper segment relocations, and the Intel
20787 HEX output format must be used.
20788 The -r flag can be passed to the linker by using the option
20792 on the SDCC command line.
20793 However, currently the linker can not handle code segments > 64k.
20796 \begin_layout Section
20798 \begin_inset LatexCommand \label{sec:Pragmas}
20803 \begin_inset LatexCommand \index{Pragmas}
20810 \begin_layout Standard
20811 Pragmas are used to turn on and/or off certain compiler options.
20812 Some of them are closely related to corresponding command-line options
20814 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20820 Pragmas should be placed before and/or after a function, placing pragmas
20821 inside a function body could have unpredictable results.
20826 following #pragma directives:
20829 \begin_layout Itemize
20835 \begin_inset LatexCommand \index{\#pragma save}
20839 - this will save most current options to the save/restore stack.
20840 See #pragma\InsetSpace ~
20844 \begin_layout Itemize
20850 \begin_inset LatexCommand \index{\#pragma restore}
20854 - will restore saved options from the last save.
20855 saves & restores can be nested.
20856 SDCC uses a save/restore stack: save pushes current options to the stack,
20857 restore pulls current options from the stack.
20858 See #pragma\InsetSpace ~
20864 \begin_layout Itemize
20870 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20875 \begin_inset LatexCommand \index{function prologue}
20879 function1[,function2[,function3...]]
20880 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20884 - The compiler by default uses a caller saves convention for register saving
20885 across function calls, however this can cause unnecessary register pushing
20887 \begin_inset LatexCommand \index{push/pop}
20891 when calling small functions from larger functions.
20892 This option can be used to switch off the register saving convention for
20893 the function names specified.
20894 The compiler will not save registers when calling these functions, extra
20895 code need to be manually inserted at the entry and exit for these functions
20896 to save and restore the registers used by these functions, this can SUBSTANTIAL
20897 LY reduce code and improve run time performance of the generated code.
20898 In the future the compiler (with inter procedural analysis) may be able
20899 to determine the appropriate scheme to use for each function call.
20904 \begin_layout Standard
20913 -callee-saves command line option is used (see page
20914 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20918 ), the function names specified in #pragma\InsetSpace ~
20920 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20924 is appended to the list of functions specified in the command line.
20927 \begin_layout Itemize
20933 \begin_inset LatexCommand \index{\#pragma exclude}
20937 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20938 of pairs of push/pop
20939 \begin_inset LatexCommand \index{push/pop}
20948 \begin_inset LatexCommand \index{interrupt}
20961 The directive should be placed immediately before the ISR function definition
20962 and it affects ALL ISR functions following it.
20963 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20964 exclude\InsetSpace ~
20966 \begin_inset LatexCommand \index{\#pragma exclude}
20971 See also the related keyword _naked
20972 \begin_inset LatexCommand \index{\_naked}
20977 \begin_inset LatexCommand \index{\_\_naked}
20984 \begin_layout Itemize
20990 \begin_inset LatexCommand \index{pedantic}
20995 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21000 \begin_inset LatexCommand \label{ite:less_pedantic}
21004 - the compiler will not warn you anymore for obvious mistakes, you'r on
21006 See also the command line option -
21010 \begin_layout Standard
21020 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21027 More specifically, the following warnings will be disabled:
21029 comparison is always [true/false] due to limited range of data type
21033 overflow in implicit constant conversion
21035 (158); [the (in)famous]
21037 conditional flow changed by optimizer: so said EVELYN the modified DOG
21041 function '[function name]' must return value
21046 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21047 level) are disabled, too, namely:
21050 \begin_inset Note Note
21053 \begin_layout Standard
21054 dunno what comes here - this warning appears to be unused altogether
21063 [left/right] shifting more than size of object changed to zero
21071 integer overflow in expression
21075 unmatched #pragma save and #pragma restore
21079 comparison of 'signed char' with 'unsigned char' requires promotion to int
21083 ISO C90 does not support flexible array members
21087 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21091 \begin_inset Note Note
21094 \begin_layout Standard
21095 appears to be always blank - what was supposed to be here?
21104 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21105 complexity [number]
21110 \begin_layout Itemize
21116 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21120 - the compiler will not warn you anymore about warning number <nnnn>.
21122 \begin_inset Note Note
21125 \begin_layout Itemize
21126 \begin_inset Quotes sld
21129 For list of warnings and corresponding codes, see err_warn.txt
21130 \begin_inset Quotes srd
21133 This list should probably be part of the manual? See Patch #1697136
21141 \begin_layout Itemize
21147 \begin_inset LatexCommand \index{\#pragma nogcse}
21151 - will stop global common subexpression elimination.
21154 \begin_layout Itemize
21160 \begin_inset LatexCommand \index{\#pragma noinduction}
21164 - will stop loop induction optimizations.
21167 \begin_layout Itemize
21173 \begin_inset LatexCommand \index{\#pragma noinvariant}
21177 - will not do loop invariant optimizations.
21178 For more details see Loop Invariants in section
21179 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21186 \begin_layout Itemize
21192 \begin_inset LatexCommand \index{\#pragma noiv}
21196 - Do not generate interrupt
21197 \begin_inset LatexCommand \index{interrupt}
21202 \begin_inset LatexCommand \index{interrupt vector table}
21206 entries for all ISR functions defined after the pragma.
21207 This is useful in cases where the interrupt vector table must be defined
21208 manually, or when there is a secondary, manually defined interrupt vector
21210 for the autovector feature of the Cypress EZ-USB FX2).
21211 More elegantly this can be achieved by obmitting the optional interrupt
21212 number after the interrupt keyword, see section
21213 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21221 \begin_layout Itemize
21227 \begin_inset LatexCommand \index{\#pragma nojtbound}
21231 - will not generate code for boundary value checking, when switch statements
21232 are turned into jump-tables (dangerous).
21233 For more details see section
21234 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21241 \begin_layout Itemize
21247 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21251 - Will not do loop reversal optimization
21254 \begin_layout Itemize
21260 \begin_inset LatexCommand \index{\#pragma nooverlay}
21264 - the compiler will not overlay the parameters and local variables of a
21268 \begin_layout Itemize
21274 \begin_inset LatexCommand \index{\#pragma stackauto}
21282 \begin_layout Standard
21292 \begin_inset LatexCommand \index{-\/-stack-auto}
21297 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21301 Parameters and Local Variables.
21304 \begin_layout Itemize
21310 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21314 - The compiler will optimize code generation towards fast code, possibly
21315 at the expense of code size.
21316 Currently this has little effect.
21319 \begin_layout Itemize
21325 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21329 - The compiler will optimize code generation towards compact code, possibly
21330 at the expense of code speed.
21331 Currently this has little effect.
21334 \begin_layout Itemize
21340 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21344 - The compiler will attempt to generate code that is both compact and fast,
21345 as long as meeting one goal is not a detriment to the other (this is the
21350 \begin_layout Itemize
21356 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21360 - Generally follow the C89 standard, but allow SDCC features that conflict
21361 with the standard (default).
21364 \begin_layout Itemize
21370 \begin_inset LatexCommand \index{\#pragma std\_c89}
21374 - Follow the C89 standard and disable SDCC features that conflict with the
21378 \begin_layout Itemize
21384 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21388 - Generally follow the C99 standard, but allow SDCC features that conflict
21389 with the standard (incomplete support).
21392 \begin_layout Itemize
21398 \begin_inset LatexCommand \index{\#pragma std\_c99}
21402 - Follow the C99 standard and disable SDCC features that conflict with the
21403 standard (incomplete support).
21406 \begin_layout Itemize
21412 \begin_inset LatexCommand \index{\#pragma codeseg}
21416 - Use this name (max.
21417 8 characters) for the code segment.
21422 \begin_layout Standard
21434 \begin_layout Itemize
21440 \begin_inset LatexCommand \index{\#pragma constseg}
21444 - Use this name (max.
21445 8 characters) for the const segment.
21450 \begin_layout Standard
21462 \begin_layout Standard
21463 The preprocessor SDCPP
21464 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21468 supports the following #pragma directives:
21471 \begin_layout Itemize
21474 pedantic_parse_number
21477 \begin_inset LatexCommand \index{pedantic}
21482 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21487 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21491 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21492 properly and the macro LO_B(3) gets expanded.
21498 \begin_layout Standard
21507 -pedantic-parse-number command line option
21508 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21515 Below is an example on how to use this pragma.
21518 Note: this functionality is not in conformance with standard!
21521 \begin_layout Verse
21524 #pragma pedantic_parse_number +
21525 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21533 #define LO_B(x) ((x) & 0xff)
21537 unsigned char foo(void)
21544 unsigned char c=0xfe-LO_B(3)
21559 \begin_layout Itemize
21565 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21569 (+ | -) - switch _asm _endasm block preprocessing on / off.
21571 You use this prama to define multilines of assembly code.
21572 This will prevent the preprocessor from changing the formating required
21574 Below is an example on how to use this pragma.
21577 \begin_layout Verse
21580 #pragma preproc_asm -
21581 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21587 #define MYDELAY _asm
21592 nop ;my assembly comment...
21606 #pragma preproc_asm
21637 \begin_layout Itemize
21643 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21647 (+ | -) - Allow "naked" hash in macro definition, for example:
21651 #define DIR_LO(x) #(x & 0xff)
21656 Below is an example on how to use this pragma.
21659 \begin_layout Verse
21662 #pragma preproc_asm +
21664 #pragma sdcc_hash +
21665 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21680 mov R6_B3, #(x & 0xff)
21687 mov R7_B3, #((x >> 8) & 0xff)
21711 \begin_layout Standard
21712 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21713 ons which might cause the compiler to generate extra stack and/or data space
21714 to store compiler generated temporary variables.
21715 This usually happens in large functions.
21716 Pragma directives should be used as shown in the following example, they
21717 are used to control options and optimizations for a given function.
21721 \begin_layout Verse
21725 \begin_inset LatexCommand \index{\#pragma save}
21736 /* save the current settings */
21739 \begin_inset LatexCommand \index{\#pragma nogcse}
21748 /* turnoff global subexpression elimination */
21750 #pragma noinduction
21751 \begin_inset LatexCommand \index{\#pragma noinduction}
21755 /* turn off induction optimizations */
21778 \begin_inset LatexCommand \index{\#pragma restore}
21782 /* turn the optimizations back on */
21785 \begin_layout Standard
21786 The compiler will generate a warning message when extra space is allocated.
21787 It is strongly recommended that the save and restore pragma's be used when
21788 changing options for a function.
21797 \begin_layout Section
21798 Defines Created by the Compiler
21801 \begin_layout Standard
21802 The compiler creates the following #defines
21803 \begin_inset LatexCommand \index{\#defines}
21808 \begin_inset LatexCommand \index{Defines created by the compiler}
21817 \begin_layout Standard
21818 \begin_inset Tabular
21819 <lyxtabular version="3" rows="11" columns="2">
21821 <column alignment="left" valignment="top" leftline="true" width="3in">
21822 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21823 <row topline="true" bottomline="true">
21824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21827 \begin_layout Standard
21835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21838 \begin_layout Standard
21847 <row topline="true">
21848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21851 \begin_layout Standard
21853 \begin_inset LatexCommand \index{SDCC}
21862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21865 \begin_layout Standard
21867 Since version 2.5.6 the version number as an int (ex.
21874 <row topline="true">
21875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21878 \begin_layout Standard
21880 \begin_inset LatexCommand \index{SDCC\_mcs51}
21885 \begin_inset LatexCommand \index{SDCC\_ds390}
21890 \begin_inset LatexCommand \index{SDCC\_z80}
21899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21902 \begin_layout Standard
21903 depending on the model used (e.g.: -mds390)
21909 <row topline="true">
21910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21913 \begin_layout Standard
21915 \begin_inset LatexCommand \index{\_\_mcs51}
21920 \begin_inset LatexCommand \index{\_\_ds390}
21925 \begin_inset LatexCommand \index{\_\_hc08}
21930 \begin_inset LatexCommand \index{\_\_z80}
21939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21942 \begin_layout Standard
21943 depending on the model used (e.g.
21950 <row topline="true">
21951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21954 \begin_layout Standard
21956 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21968 \begin_layout Standard
21975 \begin_layout Standard
21992 <row topline="true">
21993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21996 \begin_layout Standard
21998 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22010 \begin_layout Standard
22017 \begin_layout Standard
22034 <row topline="true">
22035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22038 \begin_layout Standard
22040 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22052 \begin_layout Standard
22059 \begin_layout Standard
22076 <row topline="true">
22077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22080 \begin_layout Standard
22082 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22094 \begin_layout Standard
22101 \begin_layout Standard
22118 <row topline="true">
22119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22122 \begin_layout Standard
22124 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22136 \begin_layout Standard
22143 \begin_layout Standard
22160 <row topline="true">
22161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22164 \begin_layout Standard
22166 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22178 \begin_layout Standard
22189 <row topline="true" bottomline="true">
22190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22193 \begin_layout Standard
22195 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22207 \begin_layout Standard
22225 \begin_layout Chapter
22226 Notes on supported Processors
22229 \begin_layout Section
22231 \begin_inset LatexCommand \label{sub:MCS51-variants}
22236 \begin_inset LatexCommand \index{MCS51 variants}
22243 \begin_layout Standard
22244 MCS51 processors are available from many vendors and come in many different
22246 While they might differ considerably in respect to Special Function Registers
22247 the core MCS51 is usually not modified or is kept compatible.
22251 \begin_layout Subsection
22252 pdata access by SFR
22255 \begin_layout Standard
22256 With the upcome of devices with internal xdata and flash memory devices
22258 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22262 as dedicated I/O port is becoming more popular.
22263 Switching the high byte for pdata
22264 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22268 access which was formerly done by port P2 is then achieved by a Special
22270 \begin_inset LatexCommand \index{sfr}
22275 In well-established MCS51 tradition the address of this
22279 is where the chip designers decided to put it.
22280 Needless to say that they didn't agree on a common name either.
22281 So that the startup code can correctly initialize xdata variables, you
22282 should define an sfr with the name _XPAGE
22285 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22291 at the appropriate location if the default, port P2, is not used for this.
22295 \begin_layout Verse
22298 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22302 \begin_layout Verse
22305 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22310 \begin_layout Verse
22313 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22317 \begin_layout Verse
22320 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22324 \begin_layout Verse
22327 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22331 \begin_layout Standard
22332 For more exotic implementations further customizations may be needed.
22334 \begin_inset LatexCommand \ref{sub:Startup-Code}
22338 for other possibilities.
22341 \begin_layout Subsection
22342 Other Features available by SFR
22345 \begin_layout Standard
22346 Some MCS51 variants offer features like Double DPTR
22347 \begin_inset LatexCommand \index{DPTR}
22351 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22352 These are currently not used for the MCS51 port.
22353 If you absolutely need them you can fall back to inline assembly or submit
22355 \begin_inset VSpace bigskip
22361 \begin_layout Section
22365 \begin_layout Standard
22367 \begin_inset LatexCommand \index{DS80C400}
22372 \begin_inset LatexCommand \index{DS400}
22376 microcontroller has a rich set of peripherals.
22377 In its built-in ROM library it includes functions to access some of the
22378 features, among them is a TCP stack with IP4 and IP6 support.
22379 Library headers (currently in beta status) and other files are provided
22383 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22389 \begin_inset VSpace bigskip
22395 \begin_layout Section
22396 The Z80 and gbz80 port
22399 \begin_layout Standard
22400 SDCC can target both the Zilog Z80
22401 \begin_inset LatexCommand \index{Z80}
22405 and the Nintendo Gameboy's Z80-like gbz80
22406 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22411 The Z80 port is passed through the same
22414 \begin_inset LatexCommand \index{Regression test}
22421 \begin_inset LatexCommand \ref{sec:Quality-control}
22425 ) as the MCS51 and DS390 ports, so floating point support, support for long
22426 variables and bitfield support is fine.
22427 See mailing lists and forums about interrupt routines.
22430 \begin_layout Standard
22431 As always, the code is the authoritative reference - see z80/ralloc.c and
22434 \begin_inset LatexCommand \index{Z80!stack}
22438 frame is similar to that generated by the IAR Z80 compiler.
22439 IX is used as the base pointer, HL and IY are used as a temporary registers,
22440 and BC and DE are available for holding variables.
22442 \begin_inset LatexCommand \index{Z80!return value}
22446 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22448 The gbz80 port use the same set of registers for the return values, but
22449 in a different order of significance: E (one byte), DE (two bytes), or
22451 \begin_inset VSpace bigskip
22457 \begin_layout Section
22461 \begin_layout Standard
22462 The port to the Freescale/Motorola HC08
22463 \begin_inset LatexCommand \index{HC08}
22467 family has been added in October 2003, and is still undergoing some basic
22469 The code generator is complete, but the register allocation is still quite
22471 Some of the SDCC's standard C library functions have embedded non-HC08
22472 inline assembly and so are not yet usable.
22475 \begin_layout Standard
22476 The HC08 port passes the regression test suite (see section
22477 \begin_inset LatexCommand \ref{sec:Quality-control}
22482 \begin_inset VSpace bigskip
22490 \begin_layout Section
22494 \begin_layout Standard
22496 \begin_inset LatexCommand \index{PIC14}
22500 port still requires a major effort from the development community.
22501 However it can work for simple code.
22502 It passes its (smaller set of) regression tests
22503 \begin_inset LatexCommand \index{Regression test (PIC14)}
22509 sdcc/src/regression
22514 \begin_layout Subsection
22515 C code and 14bit PIC code page
22516 \begin_inset LatexCommand \index{code page (pic14)}
22521 \begin_inset LatexCommand \index{RAM bank (pic14)}
22528 \begin_layout Standard
22529 The linker organizes allocation for the code page and RAM banks.
22530 It does not have intimate knowledge of the code flow.
22531 It will put all the code section of a single asm file into a single code
22533 In order to make use of multiple code pages, separate asm files must be
22535 The compiler treats all functions of a single C file as being in the same
22536 code page unless it is non static.
22540 To get the best follow these guide lines:
22543 \begin_layout Enumerate
22544 Make local functions static, as non static functions require code page selection
22548 \begin_layout Enumerate
22549 For devices that have multiple code pages it is more efficient to use the
22550 same number of files as pages, i.e.
22551 for the 16F877 use 4 separate files and i.e.
22552 for the 16F874 use 2 separate files.
22553 This way the linker can put the code for each file into different code
22554 pages and there's less page selection overhead.
22557 \begin_layout Enumerate
22558 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22559 instruction set), use 'unsigned char' whereever possible instead of 'int'.
22562 \begin_layout Subsection
22563 Creating a device include file
22566 \begin_layout Standard
22567 For generating a device include file
22568 \begin_inset LatexCommand \index{PIC14!Header files}
22572 use the support perl script inc2h.pl kept in directory support/script.
22575 \begin_layout Subsection
22579 \begin_layout Standard
22580 For the interrupt function, use the keyword '__interrupt'
22581 \begin_inset LatexCommand \index{PIC14!interrupt}
22585 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22586 there to avoid a syntax error - it ought to be fixed).
22590 \begin_layout Verse
22593 void Intr(void) __interrupt 0
22599 T0IF = 0; /* Clear timer interrupt */
22604 \begin_layout Subsection
22605 Linking and assembling
22608 \begin_layout Standard
22609 For assembling you can use either GPUTILS'
22610 \begin_inset LatexCommand \index{gputils (pic tools)}
22614 gpasm.exe or MPLAB's mpasmwin.exe.
22615 GPUTILS is available from
22616 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22621 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22622 If you use MPLAB and an interrupt function then the linker script file
22623 vectors section will need to be enlarged to link with mplink.
22634 \begin_layout Verse
22647 sdcc -S -V -mpic14 -p16F877 $<
22661 $(PRJ).hex: $(OBJS)
22672 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22675 \begin_layout Standard
22683 \begin_layout Verse
22696 sdcc -S -V -mpic14 -p16F877 $<
22706 mpasmwin /q /o $*.asm
22710 $(PRJ).hex: $(OBJS)
22721 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22724 \begin_layout Standard
22725 Please note that indentations within a
22729 have to be done with a tabulator character.
22732 \begin_layout Subsection
22733 Command-line options
22736 \begin_layout Standard
22737 Besides the switches common to all SDCC backends, the PIC14 port accepts
22738 the following options (for an updated list see sdcc -
22742 \begin_layout Standard
22755 \labelwidthstring 00.00.0000
22760 \begin_layout Standard
22770 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22774 emit debug info in assembly output
22778 \labelwidthstring 00.00.0000
22783 \begin_layout Standard
22793 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22797 disable (slightly faulty) optimization on pCode
22801 \labelwidthstring 00.00.0000
22806 \begin_layout Standard
22816 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22820 sets the lowest address of the argument passing stack (defaults to a suitably
22821 large shared databank to reduce BANKSEL overhead)
22825 \labelwidthstring 00.00.0000
22830 \begin_layout Standard
22840 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22844 sets the size if the argument passing stack (default: 16, minimum: 4)
22847 \begin_layout Subsection
22851 \begin_layout Subsubsection
22852 error: missing definition for symbol
22853 \begin_inset Quotes sld
22857 \begin_inset Quotes srd
22863 \begin_layout Standard
22864 The PIC14 port uses library routines to provide more complex operations
22865 like multiplication, division/modulus and (generic) pointer dereferencing.
22866 In order to add these routines to your project, you must link with PIC14's
22872 For single source file projects this is done automatically, more complex
22877 to the linker's arguments.
22878 Make sure you also add an include path for the library (using the -I switch
22882 \begin_layout Subsubsection
22883 Processor mismatch in file
22884 \begin_inset Quotes sld
22888 \begin_inset Quotes srd
22894 \begin_layout Standard
22895 This warning can usually be ignored due to the very good compatibility amongst
22897 \begin_inset LatexCommand \index{PIC14}
22904 \begin_layout Standard
22905 You might also consider recompiling the library for your specific device
22906 by changing the ARCH=p16f877 (default target) entry in
22908 device/lib/pic/Makefile.in
22912 device/lib/pic/Makefile
22914 to reflect your device.
22915 This might even improve performance for smaller devices as unneccesary
22916 BANKSELs migth be removed.
22919 \begin_layout Subsection
22923 \begin_layout Subsubsection
22927 \begin_layout Standard
22928 Currently, data can only be initialized if it resides in the source file
22934 Data in other source files will silently
22942 \begin_inset Marginal
22945 \begin_layout Standard
22961 \begin_layout Section
22963 \begin_inset LatexCommand \index{PIC16}
22970 \begin_layout Standard
22972 \begin_inset LatexCommand \index{PIC16}
22976 port is the portion of SDCC that is responsible to produce code for the
22978 \begin_inset LatexCommand \index{Microchip}
22982 (TM) microcontrollers with 16 bit core.
22983 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22984 Currently supported devices are:
22987 \begin_layout Standard
22989 \begin_inset Tabular
22990 <lyxtabular version="3" rows="4" columns="6">
22992 <column alignment="center" valignment="top" leftline="true" width="0">
22993 <column alignment="center" valignment="top" leftline="true" width="0">
22994 <column alignment="center" valignment="top" leftline="true" width="0">
22995 <column alignment="center" valignment="top" leftline="true" width="0">
22996 <column alignment="center" valignment="top" leftline="true" width="0">
22997 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22998 <row topline="true">
22999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23002 \begin_layout Standard
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23011 \begin_layout Standard
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23020 \begin_layout Standard
23026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23029 \begin_layout Standard
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23038 \begin_layout Standard
23044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23047 \begin_layout Standard
23054 <row topline="true">
23055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23058 \begin_layout Standard
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23067 \begin_layout Standard
23073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23076 \begin_layout Standard
23082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23085 \begin_layout Standard
23091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23094 \begin_layout Standard
23100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23103 \begin_layout Standard
23110 <row topline="true">
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23114 \begin_layout Standard
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23123 \begin_layout Standard
23129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23132 \begin_layout Standard
23138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23141 \begin_layout Standard
23147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23150 \begin_layout Standard
23156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23159 \begin_layout Standard
23166 <row topline="true" bottomline="true">
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23170 \begin_layout Standard
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23179 \begin_layout Standard
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23188 \begin_layout Standard
23194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23197 \begin_layout Standard
23203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23206 \begin_layout Standard
23212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23215 \begin_layout Standard
23229 \begin_layout Subsection
23233 \begin_layout Standard
23234 PIC16 port supports the standard command line arguments as supposed, with
23235 the exception of certain cases that will be mentioned in the following
23240 \labelwidthstring 00.00.0000
23245 \begin_layout Standard
23255 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23263 \begin_layout Standard
23276 \labelwidthstring 00.00.0000
23281 \begin_layout Standard
23290 -fommit-frame-pointer
23291 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23295 Frame pointer will be omitted when the function uses no local variables.
23298 \begin_layout Subsection
23299 Port Specific Options
23300 \begin_inset LatexCommand \index{Options PIC16}
23307 \begin_layout Standard
23308 The port specific options appear after the global options in the sdcc --help
23312 \begin_layout Subsubsection
23316 \begin_layout Standard
23317 General options enable certain port features and optimizations.
23321 \labelwidthstring 00.00.0000
23326 \begin_layout Standard
23335 -pstack-model=[model] Used in conjuction with the command above.
23336 Defines the stack model to be used, valid stack models are :
23341 \labelwidthstring 00.00.0000
23346 Selects small stack model.
23347 8 bit stack and frame pointers.
23348 Supports 256 bytes stack size.
23352 \labelwidthstring 00.00.0000
23357 Selects large stack model.
23358 16 bit stack and frame pointers.
23359 Supports 65536 bytes stack size.
23364 \labelwidthstring 00.00.0000
23369 \begin_layout Standard
23378 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23379 unitialized data variables with [kword].
23380 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23384 \labelwidthstring 00.00.0000
23389 \begin_layout Standard
23398 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23399 Useful for bootloaders.
23403 \labelwidthstring 00.00.0000
23408 \begin_layout Standard
23417 -asm= sets the full path and name of an external assembler to call.
23421 \labelwidthstring 00.00.0000
23426 \begin_layout Standard
23435 -link= sets the full path and name of an external linker to call.
23439 \labelwidthstring 00.00.0000
23444 \begin_layout Standard
23454 \begin_inset LatexCommand \index{PIC16!MPLAB}
23458 compatibility option.
23459 Currently only suppresses special gpasm directives.
23462 \begin_layout Subsubsection
23463 Optimization Options
23467 \labelwidthstring 00.00.0000
23472 \begin_layout Standard
23481 -optimize-goto Try to use (conditional) BRA instead of GOTO
23485 \labelwidthstring 00.00.0000
23490 \begin_layout Standard
23499 -optimize-cmp Try to optimize some compares.
23503 \labelwidthstring 00.00.0000
23508 \begin_layout Standard
23517 -optimize-df Analyze the dataflow of the generated code and improve it.
23521 \labelwidthstring 00.00.0000
23526 \begin_layout Standard
23535 -obanksel=nn Set optimization level for inserting BANKSELs.
23542 \labelwidthstring 00.00.0000
23547 \labelwidthstring 00.00.0000
23548 1 checks previous used register and if it is the same then does not emit
23549 BANKSEL, accounts only for labels.
23553 \labelwidthstring 00.00.0000
23554 2 tries to check the location of (even different) symbols and removes BANKSELs
23555 if they are in the same bank.
23560 Important: There might be problems if the linker script has data sections
23561 across bank borders!
23565 \begin_layout Subsubsection
23570 \labelwidthstring 00.00.0000
23575 \begin_layout Standard
23584 -nodefaultlibs do not link default libraries when linking
23588 \labelwidthstring 00.00.0000
23593 \begin_layout Standard
23602 -no-crt Don't link the default run-time modules
23606 \labelwidthstring 00.00.0000
23611 \begin_layout Standard
23620 -use-crt= Use a custom run-time module instead of the defaults.
23623 \begin_layout Subsubsection
23627 \begin_layout Standard
23628 Debugging options enable extra debugging information in the output files.
23632 \labelwidthstring 00.00.0000
23637 \begin_layout Standard
23646 -debug-xtra Similar to -
23650 \begin_layout Standard
23660 \begin_inset LatexCommand \index{-\/-debug}
23664 , but dumps more information.
23668 \labelwidthstring 00.00.0000
23673 \begin_layout Standard
23682 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23684 <source> is the name of the file compiled.
23688 \labelwidthstring 00.00.0000
23693 \begin_layout Standard
23702 -pcode-verbose Enable pcode debugging information in translation.
23706 \labelwidthstring 00.00.0000
23711 \begin_layout Standard
23720 -denable-peeps Force the usage of peepholes.
23725 \labelwidthstring 00.00.0000
23730 \begin_layout Standard
23739 -gstack Trace push/pops for stack pointer overflow
23743 \labelwidthstring 00.00.0000
23748 \begin_layout Standard
23757 -call-tree dump call tree in .calltree file
23760 \begin_layout Subsection
23761 Enviromental Variables
23764 \begin_layout Standard
23765 There is a number of enviromental variables that can be used when running
23766 SDCC to enable certain optimizations or force a specific program behaviour.
23767 these variables are primarily for debugging purposes so they can be enabled/dis
23771 \begin_layout Standard
23772 Currently there is only two such variables available:
23776 \labelwidthstring 00.00.0000
23777 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23778 bitfields is optimized by directly loading FSR0 with the address of the
23779 bitfield structure.
23780 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23782 This step saves data ram and code space for functions that perform heavy
23785 80 bytes of code space are saved when compiling malloc.c with this option).
23790 \labelwidthstring 00.00.0000
23791 NO_REG_OPT do not perform pCode registers optimization.
23792 This should be used for debugging purposes.
23793 In some where bugs in the pcode optimizer are found, users can benefit
23794 from temporarily disabling the optimizer until the bug is fixed.
23797 \begin_layout Subsection
23798 Preprocessor Macros
23801 \begin_layout Standard
23803 \begin_inset LatexCommand \index{PIC16}
23807 port defines the following preprocessor macros while translating a source.
23810 \begin_layout Standard
23812 \begin_inset Tabular
23813 <lyxtabular version="3" rows="6" columns="2">
23815 <column alignment="center" valignment="top" leftline="true" width="0">
23816 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23817 <row topline="true" bottomline="true">
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23821 \begin_layout Standard
23827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23830 \begin_layout Standard
23837 <row topline="true">
23838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23841 \begin_layout Standard
23847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23850 \begin_layout Standard
23851 Port identification
23857 <row topline="true">
23858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23861 \begin_layout Standard
23866 \begin_layout Standard
23880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23883 \begin_layout Standard
23884 Port identification (same as above)
23890 <row topline="true">
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23894 \begin_layout Standard
23900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23903 \begin_layout Standard
23904 MCU Identification.
23909 is the microcontrol identification number, i.e.
23916 <row topline="true">
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23920 \begin_layout Standard
23925 \begin_layout Standard
23939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23942 \begin_layout Standard
23943 MCU Identification (same as above)
23949 <row topline="true" bottomline="true">
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23953 \begin_layout Standard
23959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23962 \begin_layout Standard
23963 nnn = SMALL or LARGE respectively according to the stack model used
23976 \begin_layout Standard
23977 In addition the following macros are defined when calling assembler:
23980 \begin_layout Standard
23982 \begin_inset Tabular
23983 <lyxtabular version="3" rows="4" columns="2">
23985 <column alignment="center" valignment="top" leftline="true" width="0">
23986 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23987 <row topline="true" bottomline="true">
23988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23991 \begin_layout Standard
23997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24000 \begin_layout Standard
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 MCU Identification.
24026 is the microcontrol identification number, i.e.
24033 <row topline="true">
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24037 \begin_layout Standard
24043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24046 \begin_layout Standard
24047 nnn = SMALL or LARGE respectively according to the memory model used for
24054 <row topline="true" bottomline="true">
24055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24058 \begin_layout Standard
24064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24067 \begin_layout Standard
24068 nnn = SMALL or LARGE respectively according to the stack model used
24081 \begin_layout Subsection
24085 \begin_layout Standard
24087 \begin_inset LatexCommand \index{PIC16}
24091 port uses the following directories for searching header files and libraries.
24094 \begin_layout Standard
24096 \begin_inset Tabular
24097 <lyxtabular version="3" rows="3" columns="4">
24099 <column alignment="center" valignment="top" leftline="true" width="0">
24100 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24101 <column alignment="center" valignment="top" width="0">
24102 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24103 <row topline="true" bottomline="true">
24104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24107 \begin_layout Standard
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24116 \begin_layout Standard
24122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24125 \begin_layout Standard
24131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24134 \begin_layout Standard
24141 <row topline="true">
24142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24145 \begin_layout Standard
24146 PREFIX/sdcc/include/pic16
24151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24154 \begin_layout Standard
24155 PIC16 specific headers
24160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24163 \begin_layout Standard
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24172 \begin_layout Standard
24179 <row topline="true" bottomline="true">
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24183 \begin_layout Standard
24184 PREFIX/sdcc/lib/pic16
24189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24192 \begin_layout Standard
24193 PIC16 specific libraries
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24201 \begin_layout Standard
24207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24210 \begin_layout Standard
24224 \begin_layout Subsection
24226 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24233 \begin_layout Standard
24235 \begin_inset LatexCommand \index{PIC16}
24239 port currently supports the following pragmas:
24243 \labelwidthstring 00.00.0000
24245 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24250 \begin_inset LatexCommand \index{PIC16!stack}
24254 forces the code generator to initialize the stack & frame pointers at a
24256 This is an adhoc solution for cases where no STACK directive is available
24257 in the linker script or gplink is not instructed to create a stack section.
24260 stack pragma should be used only once in a project.
24261 Multiple pragmas may result in indeterminate behaviour of the program.
24265 \begin_layout Standard
24266 The old format (ie.
24267 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24268 cross page boundaries (or even exceed the available data RAM) and crash
24270 Make sure that stack does not cross page boundaries when using the SMALL
24278 The format is as follows:
24281 \begin_layout LyX-Code
24282 #pragma stack bottom_address [stack_size]
24285 \begin_layout Standard
24290 is the lower bound of the stack section.
24291 The stack pointer initially will point at address (bottom_address+stack_size-1).
24294 \begin_layout LyX-Code
24298 \begin_layout LyX-Code
24302 \begin_layout LyX-Code
24303 /* initializes stack of 100 bytes at RAM address 0x200 */
24306 \begin_layout LyX-Code
24307 #pragma stack 0x200 100
24310 \begin_layout Standard
24311 If the stack_size field is omitted then a stack is created with the default
24313 This size might be enough for most programs, but its not enough for operations
24314 with deep function nesting or excessive stack usage.
24318 \labelwidthstring 00.00.0000
24320 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24324 place a function symbol at static FLASH address
24327 \begin_layout LyX-Code
24331 \begin_layout LyX-Code
24335 \begin_layout LyX-Code
24336 /* place function test_func at 0x4000 */
24339 \begin_layout LyX-Code
24340 #pragma code test_func 0x4000
24343 \begin_layout LyX-Code
24348 \labelwidthstring 00.00.0000
24349 library instructs the linker to use a library module.
24354 \begin_layout LyX-Code
24355 #pragma library module_name
24358 \begin_layout Standard
24363 can be any library or object file (including its path).
24364 Note that there are four reserved keywords which have special meaning.
24368 \begin_layout Standard
24370 \begin_inset Tabular
24371 <lyxtabular version="3" rows="6" columns="3">
24373 <column alignment="center" valignment="top" leftline="true" width="0">
24374 <column alignment="block" valignment="top" leftline="true" width="20page%">
24375 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24376 <row topline="true" bottomline="true">
24377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24380 \begin_layout Standard
24386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24389 \begin_layout Standard
24395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24398 \begin_layout Standard
24405 <row topline="true">
24406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24409 \begin_layout Standard
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24420 \begin_layout Standard
24421 ignore all library pragmas
24426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24429 \begin_layout Standard
24438 <row topline="true">
24439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24442 \begin_layout Standard
24450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24453 \begin_layout Standard
24459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24462 \begin_layout Standard
24473 <row topline="true">
24474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24477 \begin_layout Standard
24485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24488 \begin_layout Standard
24489 link the Math libarary
24494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24497 \begin_layout Standard
24508 <row topline="true">
24509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24512 \begin_layout Standard
24520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24523 \begin_layout Standard
24524 link the I/O library
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24532 \begin_layout Standard
24543 <row topline="true" bottomline="true">
24544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24547 \begin_layout Standard
24555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24558 \begin_layout Standard
24559 link the debug library
24564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24567 \begin_layout Standard
24584 * is the device number, i.e.
24585 452 for PIC18F452 MCU.
24588 \begin_layout Standard
24589 This feature allows for linking with specific libraries withoug having to
24590 explicit name them in the command line.
24595 keyword will reject all modules specified by the library pragma.
24599 \labelwidthstring 00.00.0000
24600 udata pragma udata instructs the compiler to emit code so that linker will
24601 place a variable at a specific memory bank
24604 \begin_layout LyX-Code
24608 \begin_layout LyX-Code
24612 \begin_layout LyX-Code
24613 /* places variable foo at bank2 */
24616 \begin_layout LyX-Code
24617 #pragma udata bank2 foo
24620 \begin_layout LyX-Code
24624 \begin_layout Standard
24625 In order for this pragma to work extra SECTION directives should be added
24626 in the .lkr script.
24627 In the following example a sample .lkr file is shown:
24630 \begin_layout LyX-Code
24634 \begin_layout LyX-Code
24635 // Sample linker script for the PIC18F452 processor
24638 \begin_layout LyX-Code
24642 \begin_layout LyX-Code
24643 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24646 \begin_layout LyX-Code
24647 CODEPAGE NAME=page START=0x2A END=0x7FFF
24650 \begin_layout LyX-Code
24651 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24654 \begin_layout LyX-Code
24655 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24658 \begin_layout LyX-Code
24659 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24662 \begin_layout LyX-Code
24663 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24666 \begin_layout LyX-Code
24667 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24670 \begin_layout LyX-Code
24674 \begin_layout LyX-Code
24675 DATABANK NAME=gpr0 START=0x80 END=0xFF
24678 \begin_layout LyX-Code
24679 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24682 \begin_layout LyX-Code
24683 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24686 \begin_layout LyX-Code
24687 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24690 \begin_layout LyX-Code
24691 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24694 \begin_layout LyX-Code
24695 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24698 \begin_layout LyX-Code
24699 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24702 \begin_layout LyX-Code
24706 \begin_layout LyX-Code
24707 SECTION NAME=CONFIG ROM=config
24710 \begin_layout LyX-Code
24714 \begin_layout LyX-Code
24715 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24718 \begin_layout LyX-Code
24719 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24722 \begin_layout LyX-Code
24723 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24726 \begin_layout LyX-Code
24727 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24730 \begin_layout LyX-Code
24731 SECTION NAME=bank4 RAM=gpr4
24734 \begin_layout LyX-Code
24735 SECTION NAME=bank5 RAM=gpr5
24738 \begin_layout Standard
24739 The linker will recognise the section name set in the pragma statement and
24740 will position the variable at the memory bank set with the RAM field at
24741 the SECTION line in the linker script file.
24744 \begin_layout Subsection
24746 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24753 \begin_layout Standard
24754 There is one main header file
24755 \begin_inset LatexCommand \index{PIC16!Header files}
24759 that can be included to the source files using the pic16
24760 \begin_inset LatexCommand \index{PIC16}
24770 This header file contains the definitions for the processor special registers,
24771 so it is necessary if the source accesses them.
24772 It can be included by adding the following line in the beginning of the
24776 \begin_layout LyX-Code
24777 #include <pic18fregs.h>
24780 \begin_layout Standard
24781 The specific microcontroller is selected within the pic18fregs.h automatically,
24782 so the same source can be used with a variety of devices.
24785 \begin_layout Subsection
24789 \begin_layout Standard
24791 \begin_inset LatexCommand \index{PIC16!Libraries}
24796 \begin_inset LatexCommand \index{PIC16}
24800 port depends on are the microcontroller device libraries which contain
24801 the symbol definitions for the microcontroller special function registers.
24802 These libraries have the format pic18fxxxx.lib, where
24806 is the microcontroller identification number.
24807 The specific library is selected automatically by the compiler at link
24808 stage according to the selected device.
24811 \begin_layout Standard
24812 Libraries are created with gplib which is part of the gputils package
24813 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24820 \begin_layout Subsubsection*
24821 Building the libraries
24824 \begin_layout Standard
24825 Before using SDCC/pic16 there are some libraries that need to be compiled.
24826 This process is not done automatically by SDCC since not all users use
24827 SDCC for pic16 projects.
24828 So each user should compile the libraries separately.
24831 \begin_layout Standard
24832 The steps to compile the pic16 libraries under Linux are:
24835 \begin_layout LyX-Code
24836 cd device/lib/pic16
24839 \begin_layout LyX-Code
24843 \begin_layout LyX-Code
24847 \begin_layout LyX-Code
24851 \begin_layout LyX-Code
24855 \begin_layout LyX-Code
24856 su -c 'make install' # install the libraries, you need the root password
24859 \begin_layout Standard
24860 If you need to install the headers too, do:
24863 \begin_layout LyX-Code
24867 \begin_layout LyX-Code
24868 su -c 'make install' # install the headers, you need the root password
24871 \begin_layout Standard
24872 There exist a special target to build the I/O libraries.
24873 This target is not automatically build because it will build the I/O library
24879 This way building will take quite a lot of time.
24880 Users are advised to edit the
24882 device/lib/pic16/pics.build
24884 file and then execute:
24887 \begin_layout LyX-Code
24891 \begin_layout Subsection
24895 \begin_layout Standard
24896 The following memory models are supported by the PIC16 port:
24899 \begin_layout Itemize
24903 \begin_layout Itemize
24907 \begin_layout Standard
24908 Memory model affects the default size of pointers within the source.
24909 The sizes are shown in the next table:
24912 \begin_layout Standard
24914 \begin_inset Tabular
24915 <lyxtabular version="3" rows="3" columns="3">
24917 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24918 <column alignment="center" valignment="top" leftline="true" width="0">
24919 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24920 <row topline="true" bottomline="true">
24921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24924 \begin_layout Standard
24925 Pointer sizes according to memory model
24930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24933 \begin_layout Standard
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24942 \begin_layout Standard
24949 <row topline="true" bottomline="true">
24950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24953 \begin_layout Standard
24959 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24962 \begin_layout Standard
24968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24971 \begin_layout Standard
24978 <row topline="true" bottomline="true">
24979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24982 \begin_layout Standard
24988 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24991 \begin_layout Standard
24997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25000 \begin_layout Standard
25014 \begin_layout Standard
25015 It is advisable that all sources within a project are compiled with the
25017 If one wants to override the default memory model, this can be done by
25018 declaring a pointer as
25027 Far selects large memory model's pointers, while near selects small memory
25031 \begin_layout Standard
25032 The standard device libraries (see
25033 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25037 ) contain no reference to pointers, so they can be used with both memory
25041 \begin_layout Subsection
25045 \begin_layout Standard
25047 \begin_inset LatexCommand \index{PIC16!stack}
25051 implementation for the PIC16 port uses two indirect registers, FSR1 and
25056 \labelwidthstring 00.00.0000
25057 FSR1 is assigned as stack pointer
25061 \labelwidthstring 00.00.0000
25062 FSR2 is assigned as frame pointer
25065 \begin_layout Standard
25066 The following stack models are supported by the PIC16 port
25069 \begin_layout Itemize
25077 \begin_layout Itemize
25085 \begin_layout Standard
25090 model means that only the FSRxL byte is used to access stack and frame,
25097 uses both FSRxL and FSRxH registers.
25098 The following table shows the stack/frame pointers sizes according to stack
25099 model and the maximum space they can address:
25102 \begin_layout Standard
25104 \begin_inset Tabular
25105 <lyxtabular version="3" rows="3" columns="3">
25107 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25108 <column alignment="center" valignment="top" leftline="true" width="0">
25109 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25110 <row topline="true" bottomline="true">
25111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25114 \begin_layout Standard
25115 Stack & Frame pointer sizes according to stack model
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25123 \begin_layout Standard
25129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25132 \begin_layout Standard
25139 <row topline="true">
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25143 \begin_layout Standard
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25152 \begin_layout Standard
25158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25161 \begin_layout Standard
25168 <row topline="true" bottomline="true">
25169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25172 \begin_layout Standard
25178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25181 \begin_layout Standard
25187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25190 \begin_layout Standard
25204 \begin_layout Standard
25209 stack model is currently not working properly throughout the code generator.
25210 So its use is not advised.
25211 Also there are some other points that need special care:
25216 \begin_layout Enumerate
25217 Do not create stack sections with size more than one physical bank (that
25221 \begin_layout Enumerate
25222 Stack sections should no cross physical bank limits (i.e.
25223 #pragma stack 0x50 0x100)
25226 \begin_layout Standard
25227 These limitations are caused by the fact that only FSRxL is modified when
25228 using SMALL stack model, so no more than 256 bytes of stack can be used.
25229 This problem will disappear after LARGE model is fully implemented.
25232 \begin_layout Subsection
25236 \begin_layout Standard
25237 In addition to the standard SDCC function keywords, PIC16
25238 \begin_inset LatexCommand \index{PIC16}
25242 port makes available two more:
25246 \labelwidthstring 00.00.0000
25248 \begin_inset LatexCommand \index{PIC16!wparam}
25252 Use the WREG to pass one byte of the first function argument.
25253 This improves speed but you may not use this for functions with arguments
25254 that are called via function pointers, otherwise the first byte of the
25255 first parameter will get lost.
25259 \begin_layout LyX-Code
25260 void func_wparam(int a) wparam
25263 \begin_layout LyX-Code
25267 \begin_layout LyX-Code
25268 /* WREG hold the lower part of a */
25271 \begin_layout LyX-Code
25272 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25276 \begin_layout LyX-Code
25280 \begin_layout LyX-Code
25285 \labelwidthstring 00.00.0000
25287 \begin_inset LatexCommand \index{PIC16!shadowregs}
25291 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25292 hardware shadow registers which hold the values of WREG, STATUS and BSR
25294 This can be done by adding the keyword
25302 keyword in the function's header.
25305 \begin_layout LyX-Code
25306 void isr_shadow(void) shadowregs interrupt 1
25309 \begin_layout LyX-Code
25313 \begin_layout LyX-Code
25317 \begin_layout LyX-Code
25321 \begin_layout Standard
25326 instructs the code generator not to store/restore WREG, STATUS, BSR when
25327 entering/exiting the ISR.
25330 \begin_layout Subsection
25331 Function return values
25334 \begin_layout Standard
25335 Return values from functions are placed to the appropriate registers following
25336 a modified Microchip policy optimized for SDCC.
25337 The following table shows these registers:
25340 \begin_layout Standard
25342 \begin_inset Tabular
25343 <lyxtabular version="3" rows="6" columns="2">
25345 <column alignment="center" valignment="top" leftline="true" width="0">
25346 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25347 <row topline="true" bottomline="true">
25348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25351 \begin_layout Standard
25357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25360 \begin_layout Standard
25361 destination register
25367 <row topline="true">
25368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25371 \begin_layout Standard
25377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25380 \begin_layout Standard
25387 <row topline="true">
25388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25391 \begin_layout Standard
25397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25400 \begin_layout Standard
25407 <row topline="true">
25408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25411 \begin_layout Standard
25417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25420 \begin_layout Standard
25427 <row topline="true">
25428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25431 \begin_layout Standard
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25440 \begin_layout Standard
25441 FSR0L:PRODH:PRODL:WREG
25447 <row topline="true" bottomline="true">
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25451 \begin_layout Standard
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25460 \begin_layout Standard
25461 on stack, FSR0 points to the beginning
25474 \begin_layout Subsection
25478 \begin_layout Standard
25480 \begin_inset LatexCommand \index{PIC16!interrupt}
25484 service routine (ISR) is declared using the
25491 \begin_layout LyX-Code
25492 void isr(void) interrupt
25497 \begin_layout LyX-Code
25501 \begin_layout LyX-Code
25505 \begin_layout LyX-Code
25509 \begin_layout Standard
25514 is the interrupt number, which for PIC18F devices can be:
25517 \begin_layout Standard
25519 \begin_inset Tabular
25520 <lyxtabular version="3" rows="4" columns="3">
25522 <column alignment="center" valignment="top" leftline="true" width="0">
25523 <column alignment="center" valignment="top" leftline="true" width="0">
25524 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25525 <row topline="true" bottomline="true">
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25529 \begin_layout Standard
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25540 \begin_layout Standard
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25549 \begin_layout Standard
25550 Interrupt Vector Address
25556 <row topline="true">
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25560 \begin_layout Standard
25566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25569 \begin_layout Standard
25575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25578 \begin_layout Standard
25585 <row topline="true">
25586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25589 \begin_layout Standard
25604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25607 \begin_layout Standard
25617 HIGH priority interrupts
25622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25625 \begin_layout Standard
25632 <row topline="true" bottomline="true">
25633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25636 \begin_layout Standard
25642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25645 \begin_layout Standard
25646 LOW priority interrupts
25651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25654 \begin_layout Standard
25668 \begin_layout Standard
25669 When generating assembly code for ISR the code generator places a
25675 Interrupt Vector Address
25677 which points at the genetated ISR.
25678 This single GOTO instruction is part of an automatically generated
25680 interrupt entry point
25683 The actuall ISR code is placed as normally would in the code space.
25684 Upon interrupt request, the GOTO instruction is executed which jumps to
25686 When declaring interrupt functions as _naked this GOTO instruction is
25691 The whole interrupt functions is therefore placed at the Interrupt Vector
25692 Address of the specific interrupt.
25693 This is not a problem for the LOW priority interrupts, but it is a problem
25694 for the RESET and the HIGH priority interrupts because code may be written
25695 at the next interrupt´s vector address and cause undeterminate program
25696 behaviour if that interrupt is raised.
25700 \begin_layout Standard
25701 This is not a problem when
25704 \begin_layout Enumerate
25705 this is a HIGH interrupt ISR and LOW interrupts are
25712 \begin_layout Enumerate
25713 when the ISR is small enough not to reach the next interrupt´s vector address.
25721 \begin_layout Standard
25726 is possible to be omitted.
25727 This way a function is generated similar to an ISR, but it is not assigned
25731 \begin_layout Standard
25732 When entering an interrupt, currently the PIC16
25733 \begin_inset LatexCommand \index{PIC16}
25737 port automatically saves the following registers:
25740 \begin_layout Itemize
25744 \begin_layout Itemize
25748 \begin_layout Itemize
25752 \begin_layout Itemize
25753 PROD (PRODL and PRODH)
25756 \begin_layout Itemize
25757 FSR0 (FSR0L and FSR0H)
25760 \begin_layout Standard
25761 These registers are restored upon return from the interrupt routine.
25765 \begin_layout Standard
25766 NOTE that when the _naked attribute is specified for an interrupt routine,
25767 then NO registers are stored or restored.
25775 \begin_layout Subsection
25779 \begin_layout Standard
25780 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25781 There are 3 types of generic pointers currently implemented data, code
25782 and eeprom pointers.
25783 They are differentiated by the value of the 7th and 6th bits of the upper
25787 \begin_layout Standard
25789 \begin_inset Tabular
25790 <lyxtabular version="3" rows="5" columns="5">
25792 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25793 <column alignment="center" valignment="top" width="0">
25794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25795 <column alignment="center" valignment="top" width="0">
25796 <column alignment="left" valignment="top" rightline="true" width="0">
25797 <row topline="true" bottomline="true">
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25801 \begin_layout Standard
25807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25810 \begin_layout Standard
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25819 \begin_layout Standard
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25828 \begin_layout Standard
25829 rest of the pointer
25834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25837 \begin_layout Standard
25844 <row topline="true" bottomline="true">
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25848 \begin_layout Standard
25854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25857 \begin_layout Standard
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25866 \begin_layout Standard
25872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25875 \begin_layout Standard
25880 uuuuuu uuuuxxxx xxxxxxxx
25885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25888 \begin_layout Standard
25889 a 12-bit data pointer in data RAM memory
25895 <row bottomline="true">
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25899 \begin_layout Standard
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25908 \begin_layout Standard
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25917 \begin_layout Standard
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25926 \begin_layout Standard
25931 uxxxxx xxxxxxxx xxxxxxxx
25936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25939 \begin_layout Standard
25940 a 21-bit code pointer in FLASH memory
25946 <row bottomline="true">
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25950 \begin_layout Standard
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25959 \begin_layout Standard
25965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25968 \begin_layout Standard
25974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25977 \begin_layout Standard
25982 uuuuuu uuuuuuxx xxxxxxxx
25987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25990 \begin_layout Standard
25991 a 10-bit eeprom pointer in EEPROM memory
25997 <row bottomline="true">
25998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26001 \begin_layout Standard
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26010 \begin_layout Standard
26016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26019 \begin_layout Standard
26025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26028 \begin_layout Standard
26033 xxxxxx xxxxxxxx xxxxxxxx
26038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26041 \begin_layout Standard
26042 unimplemented pointer type
26055 \begin_layout Standard
26056 Generic pointer are read and written with a set of library functions which
26057 read/write 1, 2, 3, 4 bytes.
26060 \begin_layout Subsection
26064 \begin_layout Subsubsection
26065 Standard I/O Streams
26068 \begin_layout Standard
26073 the type FILE is defined as:
26076 \begin_layout LyX-Code
26077 typedef char * FILE;
26080 \begin_layout Standard
26081 This type is the stream type implemented I/O in the PIC18F devices.
26082 Also the standard input and output streams are declared in stdio.h:
26085 \begin_layout LyX-Code
26086 extern FILE * stdin;
26089 \begin_layout LyX-Code
26090 extern FILE * stdout;
26093 \begin_layout Standard
26094 The FILE type is actually a generic pointer which defines one more type
26095 of generic pointers, the
26100 This new type has the format:
26103 \begin_layout Standard
26105 \begin_inset Tabular
26106 <lyxtabular version="3" rows="2" columns="7">
26108 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26109 <column alignment="center" valignment="top" width="0">
26110 <column alignment="center" valignment="top" leftline="true" width="0">
26111 <column alignment="center" valignment="top" leftline="true" width="0">
26112 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26113 <column alignment="center" valignment="top" width="0">
26114 <column alignment="left" valignment="top" rightline="true" width="0">
26115 <row topline="true" bottomline="true">
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26119 \begin_layout Standard
26125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26128 \begin_layout Standard
26134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26137 \begin_layout Standard
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26146 \begin_layout Standard
26152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26155 \begin_layout Standard
26161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26164 \begin_layout Standard
26165 rest of the pointer
26170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26173 \begin_layout Standard
26180 <row topline="true" bottomline="true">
26181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26184 \begin_layout Standard
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26193 \begin_layout Standard
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26202 \begin_layout Standard
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26211 \begin_layout Standard
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26220 \begin_layout Standard
26226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26229 \begin_layout Standard
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26242 \begin_layout Standard
26243 upper byte high nubble is 0x2n, the rest are zeroes
26256 \begin_layout Standard
26257 Currently implemented there are 3 types of streams defined:
26260 \begin_layout Standard
26262 \begin_inset Tabular
26263 <lyxtabular version="3" rows="4" columns="4">
26265 <column alignment="center" valignment="top" leftline="true" width="0">
26266 <column alignment="center" valignment="top" leftline="true" width="0">
26267 <column alignment="center" valignment="top" leftline="true" width="0">
26268 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26269 <row topline="true" bottomline="true">
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26273 \begin_layout Standard
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 \begin_layout Standard
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26291 \begin_layout Standard
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26300 \begin_layout Standard
26307 <row topline="true">
26308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26311 \begin_layout Standard
26317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26320 \begin_layout Standard
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26331 \begin_layout Standard
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26340 \begin_layout Standard
26341 Writes/Reads characters via the USART peripheral
26347 <row topline="true">
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26351 \begin_layout Standard
26357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_layout Standard
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26371 \begin_layout Standard
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26380 \begin_layout Standard
26381 Writes/Reads characters via the MSSP peripheral
26387 <row topline="true" bottomline="true">
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26391 \begin_layout Standard
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26400 \begin_layout Standard
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26411 \begin_layout Standard
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26420 \begin_layout Standard
26421 Writes/Reads characters via used defined functions
26434 \begin_layout Standard
26435 The stream identifiers are declared as macros in the stdio.h header.
26438 \begin_layout Standard
26439 In the libc library there exist the functions that are used to write to
26440 each of the above streams.
26445 \labelwidthstring 00.00.0000
26450 \begin_layout Standard
26459 _stream_usart_putchar writes a character at the USART stream
26463 \labelwidthstring 00.00.0000
26468 \begin_layout Standard
26477 _stream_mssp_putchar writes a character at the MSSP stream
26481 \labelwidthstring 00.00.0000
26482 putchar dummy function.
26483 This writes a character to a user specified manner.
26486 \begin_layout Standard
26487 In order to increase performance
26491 is declared in stdio.h as having its parameter in WREG (it has the wparam
26493 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26494 in a user-friendly way.
26499 is the name of the variable that holds the character to print.
26500 An example follows:
26503 \begin_layout LyX-Code
26504 #include <pic18fregs.h>
26513 \begin_layout LyX-Code
26517 \begin_layout LyX-Code
26518 PORTA = c; /* dump character c to PORTA */
26521 \begin_layout LyX-Code
26529 \begin_layout LyX-Code
26533 \begin_layout LyX-Code
26534 stdout = STREAM_USER; /* this is not necessary, since stdout points
26537 \begin_layout LyX-Code
26538 * by default to STREAM_USER */
26541 \begin_layout LyX-Code
26542 printf (¨This is a printf test
26547 \begin_layout LyX-Code
26551 \begin_layout LyX-Code
26555 \begin_layout Subsubsection
26559 \begin_layout Standard
26560 PIC16 contains an implementation of the printf-family of functions.
26561 There exist the following functions:
26564 \begin_layout LyX-Code
26565 extern unsigned int sprintf(char *buf, char *fmt, ...);
26568 \begin_layout LyX-Code
26569 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26572 \begin_layout LyX-Code
26576 \begin_layout LyX-Code
26577 extern unsigned int printf(char *fmt, ...);
26580 \begin_layout LyX-Code
26581 extern unsigned int vprintf(char *fmt, va_lista ap);
26584 \begin_layout LyX-Code
26588 \begin_layout LyX-Code
26589 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26592 \begin_layout LyX-Code
26593 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26596 \begin_layout Standard
26597 For sprintf and vsprintf
26601 should normally be a data pointer where the resulting string will be placed.
26602 No range checking is done so the user should allocate the necessery buffer.
26603 For fprintf and vfprintf
26607 should be a stream pointer (i.e.
26608 stdout, STREAM_MSSP, etc...).
26611 \begin_layout Subsubsection
26615 \begin_layout Standard
26616 The PIC18F family of microcontrollers supports a number of interrupt sources.
26617 A list of these interrupts is shown in the following table:
26620 \begin_layout Standard
26622 \begin_inset Tabular
26623 <lyxtabular version="3" rows="11" columns="4">
26625 <column alignment="left" valignment="top" leftline="true" width="0">
26626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26627 <column alignment="left" valignment="top" leftline="true" width="0">
26628 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26629 <row topline="true" bottomline="true">
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26633 \begin_layout Standard
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26642 \begin_layout Standard
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26651 \begin_layout Standard
26657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26660 \begin_layout Standard
26667 <row topline="true">
26668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26671 \begin_layout Standard
26677 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26680 \begin_layout Standard
26681 PORTB change interrupt
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26689 \begin_layout Standard
26695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26698 \begin_layout Standard
26699 EEPROM/FLASH write complete interrupt
26705 <row topline="true">
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26709 \begin_layout Standard
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_layout Standard
26719 INT0 external interrupt
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26727 \begin_layout Standard
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26736 \begin_layout Standard
26737 Bus collision interrupt
26743 <row topline="true">
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26747 \begin_layout Standard
26753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26756 \begin_layout Standard
26757 INT1 external interrupt
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26765 \begin_layout Standard
26771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26774 \begin_layout Standard
26775 Low voltage detect interrupt
26781 <row topline="true">
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26785 \begin_layout Standard
26791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26794 \begin_layout Standard
26795 INT2 external interrupt
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26803 \begin_layout Standard
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26812 \begin_layout Standard
26813 Parallel slave port interrupt
26819 <row topline="true">
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26823 \begin_layout Standard
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26832 \begin_layout Standard
26833 CCP1 module interrupt
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26841 \begin_layout Standard
26847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26850 \begin_layout Standard
26851 AD convertion complete interrupt
26857 <row topline="true">
26858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26861 \begin_layout Standard
26867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26870 \begin_layout Standard
26871 CCP2 module interrupt
26876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26879 \begin_layout Standard
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26888 \begin_layout Standard
26889 USART receive interrupt
26895 <row topline="true">
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26899 \begin_layout Standard
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26908 \begin_layout Standard
26909 TMR0 overflow interrupt
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26917 \begin_layout Standard
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26926 \begin_layout Standard
26927 USART transmit interrupt
26933 <row topline="true">
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26937 \begin_layout Standard
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26946 \begin_layout Standard
26947 TMR1 overflow interrupt
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26955 \begin_layout Standard
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26964 \begin_layout Standard
26965 SSP receive/transmit interrupt
26971 <row topline="true">
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26975 \begin_layout Standard
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26984 \begin_layout Standard
26985 TMR2 matches PR2 interrupt
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_layout Standard
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27002 \begin_layout Standard
27009 <row topline="true" bottomline="true">
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_layout Standard
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27022 \begin_layout Standard
27023 TMR3 overflow interrupt
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27031 \begin_layout Standard
27037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27040 \begin_layout Standard
27054 \begin_layout Standard
27055 The prototypes for these names are defined in the header file
27062 \begin_layout Standard
27063 In order to simplify signal handling, a number of macros is provided:
27067 \labelwidthstring 00.00.0000
27068 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27069 high priority interrupts.
27074 is the function name to use.
27078 \labelwidthstring 00.00.0000
27079 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27080 low priority interrupt.
27085 is the function name to use.
27089 \labelwidthstring 00.00.0000
27090 DEF_HANDLER(sig,handler) define a handler for signal
27096 \labelwidthstring 00.00.0000
27097 END_DEF end the declaration of the dispatch table.
27100 \begin_layout Standard
27101 Additionally there are two more macros to simplify the declaration of the
27106 \labelwidthstring 00.00.0000
27109 SIGHANDLER(handler)
27111 this declares the function prototype for the
27119 \labelwidthstring 00.00.0000
27120 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27123 \begin_layout Standard
27124 An example of using the macros above is shown below:
27127 \begin_layout LyX-Code
27128 #include <pic18fregs.h>
27131 \begin_layout LyX-Code
27132 #include <signal.h>
27136 DEF_INTHIGH(high_int)
27139 \begin_layout LyX-Code
27140 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27143 \begin_layout LyX-Code
27144 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27147 \begin_layout LyX-Code
27152 SIGHANDLER(_tmr0_handler)
27155 \begin_layout LyX-Code
27159 \begin_layout LyX-Code
27160 /* action to be taken when timer 0 overflows */
27163 \begin_layout LyX-Code
27168 SIGHANDLERNAKED(_bcol_handler)
27171 \begin_layout LyX-Code
27175 \begin_layout LyX-Code
27179 \begin_layout LyX-Code
27180 /* action to be taken when bus collision occurs */
27183 \begin_layout LyX-Code
27187 \begin_layout LyX-Code
27191 \begin_layout LyX-Code
27195 \begin_layout Standard
27200 Special care should be taken when using the above scheme:
27203 \begin_layout Itemize
27204 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27207 \begin_layout Itemize
27208 when declaring SIGHANDLERNAKED handler never forget to use
27212 for proper returning.
27215 \begin_layout Subsection
27219 \begin_layout Standard
27220 Here you can find some general tips for compiling programs with SDCC/pic16.
27223 \begin_layout Subsubsection
27227 \begin_layout Standard
27229 \begin_inset LatexCommand \index{PIC16!stack}
27233 size (that is 64 bytes) probably is enough for many programs.
27234 One must take care that when there are many levels of function nesting,
27235 or there is excessive usage of stack, its size should be extended.
27236 An example of such a case is the printf/sprintf family of functions.
27237 If you encounter problems like not being able to print integers, then you
27238 need to set the stack size around the maximum (256 for small stack model).
27239 The following diagram shows what happens when calling printf to print an
27243 \begin_layout LyX-Code
27244 printf () --> ltoa () --> ultoa () --> divschar ()
27247 \begin_layout Standard
27248 It is should be understood that stack is easily consumed when calling complicate
27250 Using command line arguments like -
27254 \begin_layout Standard
27263 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27265 Other ways to reduce stack usage may exist.
27268 \begin_layout Subsection
27272 \begin_layout Standard
27273 The PIC16 Port currently does not pass SDCC's regression test
27274 \begin_inset LatexCommand \index{Regression test (PIC16)}
27279 \begin_inset LatexCommand \ref{sec:Quality-control}
27283 ) and thus the snapshot build regression tests for the PIC16 target are
27284 currently disabled for all hosts
27289 \begin_layout Chapter
27293 \begin_layout Standard
27294 There are several approaches to debugging your code.
27295 This chapter is meant to show your options and to give detail on some of
27300 When writing your code:
27303 \begin_layout Itemize
27304 write your code with debugging in mind (avoid duplicating code, put conceptually
27305 similar variables into structs, use structured code, have strategic points
27306 within your code where all variables are consistent, ...)
27309 \begin_layout Itemize
27310 run a syntax-checking tool like splint
27311 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27316 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27324 \begin_layout Standard
27334 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27341 \begin_layout Itemize
27342 for the high level code use a C-compiler (like f.e.
27343 GCC) to compile run and debug the code on your host.
27348 \begin_layout Standard
27358 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27362 ) on how to handle syntax extensions like __xdata, __at(), ...
27366 \begin_layout Itemize
27367 use another C-compiler to compile code for your target.
27368 Always an option but not recommended:) And not very likely to help you.
27369 If you seriously consider walking this path you should at least occasionally
27370 check portability of your code.
27371 Most commercial compiler vendors will offer an evaluation version so you
27372 can test compile your code or snippets of your code.
27375 \begin_layout Standard
27376 Debugging on a simulator:
27379 \begin_layout Itemize
27380 there is a separate section about SDCDB (section
27381 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27388 \begin_layout Itemize
27389 or (8051 specific) use a freeware/commercial simulator which interfaces
27391 \begin_inset LatexCommand \index{AOMF, AOMF51}
27396 \begin_inset LatexCommand \ref{OMF file}
27400 ) optionally generated by SDCC.
27403 \begin_layout Standard
27404 Debugging On-target:
27407 \begin_layout Itemize
27408 use a MCU port pin to serially output debug data to the RS232 port of your
27410 You'll probably want some level shifting device typically involving a MAX232
27412 If the hardware serial port of the MCU is not available search for 'Software
27413 UART' in your favourite search machine.
27416 \begin_layout Itemize
27417 use an on-target monitor.
27418 In this context a monitor is a small program which usually accepts commands
27419 via a serial line and allows to set program counter, to single step through
27420 a program and read/write memory locations.
27421 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27423 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27430 \begin_layout Itemize
27431 toggle MCU port pins at strategic points within your code and use an oscilloscop
27435 digital oscilloscope
27438 \begin_inset LatexCommand \index{Oscilloscope}
27442 with deep trace memory is really helpful especially if you have to debug
27443 a realtime application.
27444 If you need to monitor more pins than your oscilloscope provides you can
27445 sometimes get away with a small R-2R network.
27446 On a single channel oscilloscope you could f.e.
27447 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27449 \begin_inset Formula $\Omega$
27452 resistor and the other one by a 5\InsetSpace ~
27454 \begin_inset Formula $\Omega$
27457 resistor to the oscilloscope probe (check output drive capability of the
27458 pins you want to monitor).
27459 If you need to monitor many more pins a
27466 \begin_layout Itemize
27480 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27485 Usually very expensive.
27486 And very nice to have too.
27487 And usually locks you (for years...) to the devices the ICE can emulate.
27491 \begin_layout Itemize
27492 use a remote debugger.
27493 In most 8-bit systems the symbol information is not available on the target,
27494 and a complete debugger is too bulky for the target system.
27495 Therefore usually a debugger on the host system connects to an on-target
27496 debugging stub which accepts only primitive commands.
27499 Terms to enter into your favourite search engine could be 'remote debugging',
27500 'gdb stub' or 'inferior debugger'.
27504 \begin_layout Itemize
27505 use an on target hardware debugger.
27506 Some of the more modern MCUs include hardware support for setting break
27507 points and monitoring/changing variables by using dedicated hardware pins.
27508 This facility doesn't require additional code to run on the target and
27513 doesn't affect runtime behaviour until a breakpoint is hit.
27514 For the mcs51 most hardware debuggers use the AOMF
27515 \begin_inset LatexCommand \index{AOMF, AOMF51}
27520 \begin_inset LatexCommand \ref{OMF file}
27528 \begin_layout Standard
27532 \begin_layout Itemize
27533 if you are not familiar with any of the following terms you're likely to
27534 run into problems rather sooner than later:
27551 As an embedded programmer you
27555 to know them so why not look them up
27559 you have problems?)
27562 \begin_layout Itemize
27563 tell someone else about your problem (actually this is a surprisingly effective
27564 means to hunt down the bug even if the listener is not familiar with your
27566 As 'failure to communicate' is probably one of the job-induced deformations
27567 of an embedded programmer this is highly encouraged.
27570 \begin_layout Section
27571 Debugging with SDCDB
27572 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27577 \begin_inset LatexCommand \index{SDCDB (debugger)}
27584 \begin_layout Standard
27585 SDCC is distributed with a source level debugger
27586 \begin_inset LatexCommand \index{Debugger}
27591 The debugger uses a command line interface, the command repertoire of the
27592 debugger has been kept as close to gdb
27593 \begin_inset LatexCommand \index{gdb}
27597 (the GNU debugger) as possible.
27598 The configuration and build process is part of the standard compiler installati
27599 on, which also builds and installs the debugger in the target directory
27600 specified during configuration.
27601 The debugger allows you debug BOTH at the C source and at the ASM source
27605 \begin_layout Subsection
27606 Compiling for Debugging
27609 \begin_layout Standard
27614 \begin_layout Standard
27624 \begin_inset LatexCommand \index{-\/-debug}
27628 option must be specified for all files for which debug information is to
27630 The compiler generates a .adb file for each of these files.
27631 The linker creates the .cdb
27632 \begin_inset LatexCommand \index{<file>.cdb}
27637 \begin_inset LatexCommand \index{<file>.adb}
27641 files and the address information.
27642 This .cdb is used by the debugger.
27645 \begin_layout Subsection
27646 How the Debugger Works
27649 \begin_layout Standard
27654 \begin_layout Standard
27663 -debug option is specified the compiler generates extra symbol information
27664 some of which are put into the assembler source and some are put into the
27666 Then the linker creates the .cdb file from the individual .adb files with
27667 the address information for the symbols.
27668 The debugger reads the symbolic information generated by the compiler &
27669 the address information generated by the linker.
27670 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27671 execution is controlled by the debugger.
27672 When a command is issued for the debugger, it translates it into appropriate
27673 commands for the simulator.
27674 (Currently SDCDM only connects to the simulator but
27679 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27683 is an effort to connect directly to the hardware.)
27686 \begin_layout Subsection
27687 Starting the Debugger SDCDB
27690 \begin_layout Standard
27691 The debugger can be started using the following command line.
27692 (Assume the file you are debugging has the file name foo).
27706 The debugger will look for the following files.
27709 \begin_layout Itemize
27710 foo.c - the source file.
27713 \begin_layout Itemize
27714 foo.cdb - the debugger symbol information file.
27717 \begin_layout Itemize
27718 foo.ihx - the Intel hex format
27719 \begin_inset LatexCommand \index{Intel hex format}
27726 \begin_layout Subsection
27727 SDCDB Command Line Options
27730 \begin_layout Itemize
27735 \begin_layout Standard
27744 -directory=<source file directory> this option can used to specify the directory
27746 The debugger will look into the directory list specified for source, cdb
27748 The items in the directory list must be separated by ':', e.g.
27749 if the source files can be in the directories /home/src1 and /home/src2,
27754 \begin_layout Standard
27763 -directory option should be -
27767 \begin_layout Standard
27776 -directory=/home/src1:/home/src2.
27777 Note there can be no spaces in the option.
27781 \begin_layout Itemize
27782 -cd <directory> - change to the <directory>.
27785 \begin_layout Itemize
27786 -fullname - used by GUI front ends.
27789 \begin_layout Itemize
27790 -cpu <cpu-type> - this argument is passed to the simulator please see the
27791 simulator docs for details.
27794 \begin_layout Itemize
27795 -X <Clock frequency > this options is passed to the simulator please see
27796 the simulator docs for details.
27799 \begin_layout Itemize
27800 -s <serial port file> passed to simulator see the simulator docs for details.
27803 \begin_layout Itemize
27804 -S <serial in,out> passed to simulator see the simulator docs for details.
27807 \begin_layout Itemize
27808 -k <port number> passed to simulator see the simulator docs for details.
27811 \begin_layout Subsection
27812 SDCDB Debugger Commands
27815 \begin_layout Standard
27816 As mentioned earlier the command interface for the debugger has been deliberatel
27817 y kept as close the GNU debugger gdb, as possible.
27818 This will help the integration with existing graphical user interfaces
27819 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27820 If you use a graphical user interface for the debugger you can skip this
27824 \begin_layout Subsubsection*
27825 break [line | file:line | function | file:function]
27828 \begin_layout Standard
27829 Set breakpoint at specified line or function:
27838 sdcdb>break foo.c:100
27840 sdcdb>break funcfoo
27842 sdcdb>break foo.c:funcfoo
27845 \begin_layout Subsubsection*
27846 clear [line | file:line | function | file:function ]
27849 \begin_layout Standard
27850 Clear breakpoint at specified line or function:
27859 sdcdb>clear foo.c:100
27861 sdcdb>clear funcfoo
27863 sdcdb>clear foo.c:funcfoo
27866 \begin_layout Subsubsection*
27870 \begin_layout Standard
27871 Continue program being debugged, after breakpoint.
27874 \begin_layout Subsubsection*
27878 \begin_layout Standard
27879 Execute till the end of the current function.
27882 \begin_layout Subsubsection*
27886 \begin_layout Standard
27887 Delete breakpoint number 'n'.
27888 If used without any option clear ALL user defined break points.
27891 \begin_layout Subsubsection*
27892 info [break | stack | frame | registers ]
27895 \begin_layout Itemize
27896 info break - list all breakpoints
27899 \begin_layout Itemize
27900 info stack - show the function call stack.
27903 \begin_layout Itemize
27904 info frame - show information about the current execution frame.
27907 \begin_layout Itemize
27908 info registers - show content of all registers.
27911 \begin_layout Subsubsection*
27915 \begin_layout Standard
27916 Step program until it reaches a different source line.
27917 Note: pressing <return> repeats the last command.
27920 \begin_layout Subsubsection*
27924 \begin_layout Standard
27925 Step program, proceeding through subroutine calls.
27928 \begin_layout Subsubsection*
27932 \begin_layout Standard
27933 Start debugged program.
27936 \begin_layout Subsubsection*
27940 \begin_layout Standard
27941 Print type information of the variable.
27944 \begin_layout Subsubsection*
27948 \begin_layout Standard
27949 print value of variable.
27952 \begin_layout Subsubsection*
27956 \begin_layout Standard
27957 load the given file name.
27958 Note this is an alternate method of loading file for debugging.
27961 \begin_layout Subsubsection*
27965 \begin_layout Standard
27966 print information about current frame.
27969 \begin_layout Subsubsection*
27973 \begin_layout Standard
27974 Toggle between C source & assembly source.
27977 \begin_layout Subsubsection*
27978 ! simulator command
27981 \begin_layout Standard
27982 Send the string following '!' to the simulator, the simulator response is
27984 Note the debugger does not interpret the command being sent to the simulator,
27985 so if a command like 'go' is sent the debugger can loose its execution
27986 context and may display incorrect values.
27989 \begin_layout Subsubsection*
27993 \begin_layout Standard
27996 My name is Bobby Brown"
27999 \begin_layout Subsection
28000 Interfacing SDCDB with DDD
28003 \begin_layout Standard
28004 \begin_inset Note Note
28007 \begin_layout Standard
28008 The screenshot was converted from png to eps with:
28009 \begin_inset Quotes sld
28012 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28013 \begin_inset Quotes srd
28016 which produces a pretty compact eps file which is free from compression
28020 \begin_layout Standard
28021 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28022 as this broke the build system on Sourceforge (pdf-file was broken.
28023 pdflatex does not accept eps files).
28031 \begin_layout Standard
28047 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28053 shows a screenshot of a debugging session with DDD
28054 \begin_inset LatexCommand \index{DDD (debugger)}
28058 (Unix only) on a simulated 8032.
28059 The debugging session might not run as smoothly as the screenshot suggests.
28060 The debugger allows setting of breakpoints, displaying and changing variables,
28061 single stepping through C and assembler code.
28064 The source was compiled with
28078 \begin_layout Standard
28090 -debug ddd_example.c
28103 and DDD was invoked with
28110 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28113 \begin_layout Standard
28114 \begin_inset Note Note
28117 \begin_layout Standard
28118 Check that the double quotes or an apostroph within the command line survive
28119 the LyX tool chain.
28120 Previously the apostrophs got slanted in the PDF output so a cut and paste
28129 \begin_layout Subsection
28130 Interfacing SDCDB with XEmacs
28131 \begin_inset LatexCommand \index{XEmacs}
28136 \begin_inset LatexCommand \index{Emacs}
28143 \begin_layout Standard
28144 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28145 sdcdb.el and sdcdbsrc.el.
28146 These two files can be found in the $(prefix)/bin directory after the installat
28148 These files need to be loaded into XEmacs for the interface to work.
28149 This can be done at XEmacs startup time by inserting the following into
28150 your '.xemacs' file (which can be found in your HOME directory):
28156 (load-file sdcdbsrc.el)
28162 .xemacs is a lisp file so the () around the command is REQUIRED.
28163 The files can also be loaded dynamically while XEmacs is running, set the
28164 environment variable 'EMACSLOADPATH' to the installation bin directory
28165 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28166 To start the interface enter the following command:
28180 You will prompted to enter the file name to be debugged.
28185 The command line options that are passed to the simulator directly are
28186 bound to default values in the file sdcdbsrc.el.
28187 The variables are listed below, these values maybe changed as required.
28190 \begin_layout Itemize
28191 sdcdbsrc-cpu-type '51
28194 \begin_layout Itemize
28195 sdcdbsrc-frequency '11059200
28198 \begin_layout Itemize
28199 sdcdbsrc-serial nil
28202 \begin_layout Standard
28203 The following is a list of key mapping for the debugger interface.
28206 \begin_layout Standard
28229 binding\InsetSpace ~
28267 -------\InsetSpace ~
28338 sdcdb-back-from-src\InsetSpace ~
28367 rom-src\InsetSpace ~
28377 SDCDB continue command
28395 sdcdb-step-from-src\InsetSpace ~
28424 hatis-c-sexp\InsetSpace ~
28434 SDCDB ptypecommand for data at
28501 sdcdbsrc-delete\InsetSpace ~
28516 B Delete all breakpoints if no arg
28565 given or delete arg (C-u arg x)
28584 -frame\InsetSpace ~
28599 SDCDB Display current frame if no arg,
28648 given or display frame arg
28716 sdcdbsrc-goto-sdcdb\InsetSpace ~
28726 Goto the SDCDB output buffer
28745 t-c-sexp\InsetSpace ~
28756 SDCDB print command for data at
28823 sdcdbsrc-goto-sdcdb\InsetSpace ~
28834 o the SDCDB output buffer
28852 sdcdbsrc-mode\InsetSpace ~
28868 Toggles Sdcdbsrc mode (turns it
28884 sdcdb-finish-from-src\InsetSpace ~
28892 SDCDB finish command
28926 Set break for line with point
28941 sdcdbsrc-mode\InsetSpace ~
28957 Toggle Sdcdbsrc mode
28973 dbsrc-srcmode\InsetSpace ~
28997 \begin_layout Chapter
29001 \begin_layout Standard
29002 Here are a few guidelines that will help the compiler generate more efficient
29003 code, some of the tips are specific to this compiler others are generally
29004 good programming practice.
29007 \begin_layout Itemize
29008 Use the smallest data type to represent your data-value.
29009 If it is known in advance that the value is going to be less than 256 then
29010 use an 'unsigned char' instead of a 'short' or 'int'.
29011 Please note, that ANSI C requires both signed and unsigned chars to be
29012 promoted to 'signed int'
29013 \begin_inset LatexCommand \index{promotion to signed int}
29018 \begin_inset Marginal
29021 \begin_layout Standard
29030 before doing any operation.
29032 \begin_inset LatexCommand \index{type promotion}
29037 \begin_inset LatexCommand \label{type promotion}
29041 can be omitted, if the result is the same.
29042 The effect of the promotion rules together with the sign-extension is often
29047 \begin_layout Verse
29050 unsigned char uc = 0xfe;
29052 if (uc * uc < 0) /* this is true! */
29065 \begin_layout Standard
29072 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29080 \begin_layout Verse
29083 (unsigned char) -12 / (signed char) -3 = ...
29086 \begin_layout Standard
29087 No, the result is not 4:
29090 \begin_layout Verse
29093 (int) (unsigned char) -12 / (int) (signed char) -3 =
29095 (int) (unsigned char)
29096 0xf4 / (int) (signed char) 0xfd =
29098 (int) 0x00f4 / (int) 0xfffd =
29103 (int) 244 / (int) -3 =
29105 (int) -81 = (int) 0xffaf;
29108 \begin_layout Standard
29109 Don't complain, that gcc gives you a different result.
29110 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29111 Therefore the results are different.
29114 \begin_inset Quotes sld
29118 \begin_inset Quotes srd
29124 \begin_layout Quote
29127 If well-defined overflow characteristics are important and negative values
29128 are not, or if you want to steer clear of sign-extension problems when
29129 manipulating bits or bytes, use one of the corresponding unsigned types.
29130 (Beware when mixing signed and unsigned values in expressions, though.)
29133 character types (especially unsigned char) can be used as "tiny" integers,
29134 doing so is sometimes more trouble than it's worth, due to unpredictable
29135 sign extension and increased code size.
29139 \begin_layout Itemize
29140 Use unsigned when it is known in advance that the value is not going to
29142 This helps especially if you are doing division or multiplication, bit-shifting
29143 or are using an array index.
29146 \begin_layout Itemize
29147 NEVER jump into a LOOP.
29150 \begin_layout Itemize
29151 Declare the variables to be local
29152 \begin_inset LatexCommand \index{local variables}
29156 whenever possible, especially loop control variables (induction).
29159 \begin_layout Itemize
29160 Have a look at the assembly listing to get a
29161 \begin_inset Quotes sld
29165 \begin_inset Quotes srd
29168 for the code generation.
29171 \begin_layout Section
29172 Porting code from or to other compilers
29173 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29180 \begin_layout Itemize
29181 check whether endianness of the compilers differs and adapt where needed.
29184 \begin_layout Itemize
29185 check the device specific header files
29186 \begin_inset LatexCommand \index{Header files}
29191 \begin_inset LatexCommand \index{Include files}
29195 for compiler specific syntax.
29196 Eventually include the file <compiler.h
29197 \begin_inset LatexCommand \index{compiler.h (include file)}
29202 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29206 to allow using common header files.
29209 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29216 \begin_layout Itemize
29217 check whether the startup code contains the correct initialization (watchdog,
29221 \begin_layout Itemize
29222 check whether the sizes of short, int, long match.
29225 \begin_layout Itemize
29226 check if some 16 or 32 bit hardware registers require a specific addressing
29227 order (least significant or most significant byte first) and adapt if needed
29236 relate to time and not to lower/upper memory location here, so this is
29241 the same as endianness).
29244 \begin_layout Itemize
29245 check whether the keyword
29249 is used where needed.
29250 The compilers might differ in their optimization characteristics (as different
29251 versions of the same compiler might also use more clever optimizations
29252 this is good idea anyway).
29254 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29261 \begin_layout Itemize
29262 check that the compilers are not told to supress warnings.
29265 \begin_layout Itemize
29266 check and convert compiler specific extensions (interrupts, memory areas,
29270 \begin_layout Itemize
29271 check for differences in type promotion.
29272 Especially check for math operations on
29281 For the sake of C99 compatibility SDCC will probably promote these to
29285 more often than other compilers.
29286 Eventually insert explicit casts to
29295 Also check that the ~\InsetSpace ~
29297 \begin_inset LatexCommand \index{\~\/ Operator}
29304 \begin_inset LatexCommand \index{bit}
29310 variables, use the !\InsetSpace ~
29313 \begin_inset LatexCommand \ref{type promotion}
29318 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29325 \begin_layout Itemize
29326 check the assembly code generated for interrupt routines (f.e.
29327 for calls to possibly non-reentrant library functions).
29330 \begin_layout Itemize
29331 check whether timing loops result in proper timing (or preferably consider
29332 a rewrite of the code with timer based delays instead).
29335 \begin_layout Itemize
29336 check for differences in printf parameters (some compilers push (va_arg
29337 \begin_inset LatexCommand \index{vararg, va\_arg}
29341 ) char variables as
29345 others push them as
29351 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29358 \begin_layout Itemize
29359 check the resulting memory map
29360 \begin_inset LatexCommand \index{Memory map}
29365 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29366 ly idata, pdata, xdata).
29367 Eventually check if unexpected library functions are included.
29370 \begin_layout Section
29372 \begin_inset LatexCommand \index{Tools}
29376 included in the distribution
29379 \begin_layout Standard
29381 \begin_inset Tabular
29382 <lyxtabular version="3" rows="12" columns="3">
29384 <column alignment="left" valignment="top" leftline="true" width="0pt">
29385 <column alignment="left" valignment="top" leftline="true" width="0pt">
29386 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29387 <row topline="true" bottomline="true">
29388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29391 \begin_layout Standard
29399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29402 \begin_layout Standard
29410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29413 \begin_layout Standard
29422 <row topline="true">
29423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29426 \begin_layout Standard
29428 \begin_inset LatexCommand \index{uCsim}
29437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29440 \begin_layout Standard
29441 Simulator for various architectures
29446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29449 \begin_layout Standard
29456 <row topline="true">
29457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29460 \begin_layout Standard
29466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29469 \begin_layout Standard
29471 \begin_inset LatexCommand \index{Header files}
29476 \begin_inset LatexCommand \index{Include files}
29485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29488 \begin_layout Standard
29489 sdcc/support/scripts
29495 <row topline="true">
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29499 \begin_layout Standard
29505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29508 \begin_layout Standard
29509 header file conversion
29514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29517 \begin_layout Standard
29518 sdcc/support/scripts
29524 <row topline="true">
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29528 \begin_layout Standard
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29537 \begin_layout Standard
29543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29546 \begin_layout Standard
29562 <row topline="true">
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29566 \begin_layout Standard
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29575 \begin_layout Standard
29581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29584 \begin_layout Standard
29600 <row topline="true">
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29604 \begin_layout Standard
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29613 \begin_layout Standard
29619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29622 \begin_layout Standard
29638 <row topline="true">
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29642 \begin_layout Standard
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29651 \begin_layout Standard
29657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29660 \begin_layout Standard
29676 <row topline="true">
29677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29680 \begin_layout Standard
29686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29689 \begin_layout Standard
29695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29698 \begin_layout Standard
29714 <row topline="true">
29715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29718 \begin_layout Standard
29724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29727 \begin_layout Standard
29733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29736 \begin_layout Standard
29752 <row topline="true">
29753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29756 \begin_layout Standard
29762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29765 \begin_layout Standard
29771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29774 \begin_layout Standard
29790 <row topline="true" bottomline="true">
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29794 \begin_layout Standard
29800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29803 \begin_layout Standard
29805 \begin_inset LatexCommand \index{packihx (tool)}
29814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29817 \begin_layout Standard
29842 \begin_layout Section
29844 \begin_inset LatexCommand \index{Documentation}
29848 included in the distribution
29851 \begin_layout Standard
29853 \begin_inset Tabular
29854 <lyxtabular version="3" rows="10" columns="2">
29856 <column alignment="block" valignment="top" leftline="true" width="40col%">
29857 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29858 <row topline="true" bottomline="true" endhead="true">
29859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29862 \begin_layout Standard
29870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29873 \begin_layout Standard
29876 Filename / Where to get
29882 <row topline="true">
29883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29886 \begin_layout Standard
29887 SDCC Compiler User Guide
29892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29895 \begin_layout Standard
29896 You're reading it right now
29908 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29918 <row topline="true">
29919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29922 \begin_layout Standard
29928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29931 \begin_layout Standard
29944 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29954 <row topline="true">
29955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29958 \begin_layout Standard
29960 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29965 \begin_inset LatexCommand \index{Assembler documentation}
29972 \begin_inset LatexCommand \index{aslink}
29977 \begin_inset LatexCommand \index{Linker documentation}
29986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29989 \begin_layout Standard
29990 sdcc/as/doc/asxhtm.html
30002 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30012 <row topline="true">
30013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30016 \begin_layout Standard
30017 SDCC regression test
30018 \begin_inset LatexCommand \index{Regression test}
30027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30030 \begin_layout Standard
30031 sdcc/doc/test_suite_spec.pdf
30043 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30053 <row topline="true">
30054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30057 \begin_layout Standard
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30066 \begin_layout Standard
30079 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30089 <row topline="true">
30090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30093 \begin_layout Standard
30094 Notes on debugging with SDCDB
30095 \begin_inset LatexCommand \index{SDCDB (debugger)}
30104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30107 \begin_layout Standard
30108 sdcc/debugger/README
30120 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30130 <row topline="true">
30131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30134 \begin_layout Standard
30136 \begin_inset LatexCommand \index{uCsim}
30140 Software simulator for microcontrollers
30145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30148 \begin_layout Standard
30178 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30188 <row topline="true">
30189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30192 \begin_layout Standard
30193 Temporary notes on the pic16
30194 \begin_inset LatexCommand \index{PIC16}
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30206 \begin_layout Standard
30207 sdcc/src/pic16/NOTES
30219 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30229 <row topline="true" bottomline="true">
30230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30233 \begin_layout Standard
30234 SDCC internal documentation (debugging file format)
30239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30242 \begin_layout Standard
30272 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30291 \begin_layout Section
30292 Related open source tools
30293 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30298 \begin_inset LatexCommand \index{Related tools}
30305 \begin_layout Standard
30307 \begin_inset Tabular
30308 <lyxtabular version="3" rows="14" columns="3">
30310 <column alignment="left" valignment="top" leftline="true" width="0pt">
30311 <column alignment="block" valignment="top" leftline="true" width="30line%">
30312 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30313 <row topline="true" bottomline="true">
30314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30317 \begin_layout Standard
30325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30328 \begin_layout Standard
30336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30339 \begin_layout Standard
30348 <row topline="true">
30349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30352 \begin_layout Standard
30354 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30366 \begin_layout Standard
30372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30375 \begin_layout Standard
30376 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30386 <row topline="true">
30387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30390 \begin_layout Standard
30392 \begin_inset LatexCommand \index{gputils (pic tools)}
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30404 \begin_layout Standard
30410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30413 \begin_layout Standard
30414 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30424 <row topline="true">
30425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30428 \begin_layout Standard
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30437 \begin_layout Standard
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30446 \begin_layout Standard
30447 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30457 <row topline="true">
30458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30461 \begin_layout Standard
30467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30470 \begin_layout Standard
30471 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30480 \begin_layout Standard
30481 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30491 <row topline="true">
30492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30495 \begin_layout Standard
30497 \begin_inset LatexCommand \index{indent (source formatting tool)}
30506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30509 \begin_layout Standard
30510 Formats C source - Master of the white spaces
30515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30518 \begin_layout Standard
30519 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30529 <row topline="true">
30530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30533 \begin_layout Standard
30535 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30547 \begin_layout Standard
30548 Object file conversion, checksumming, ...
30553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30556 \begin_layout Standard
30557 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30567 <row topline="true">
30568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30571 \begin_layout Standard
30573 \begin_inset LatexCommand \index{objdump (tool)}
30582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30585 \begin_layout Standard
30586 Object file conversion, ...
30591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30594 \begin_layout Standard
30595 Part of binutils (should be there anyway)
30601 <row topline="true">
30602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30605 \begin_layout Standard
30611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30614 \begin_layout Standard
30615 8051 monitor (hex up-/download, single step, disassemble)
30620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30623 \begin_layout Standard
30624 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30634 <row topline="true">
30635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30638 \begin_layout Standard
30640 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30652 \begin_layout Standard
30653 Source code documentation system
30658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30661 \begin_layout Standard
30662 \begin_inset LatexCommand \url{http://www.doxygen.org}
30672 <row topline="true">
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30676 \begin_layout Standard
30682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30685 \begin_layout Standard
30686 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30694 \begin_layout Standard
30695 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30705 <row topline="true">
30706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30709 \begin_layout Standard
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30718 \begin_layout Standard
30719 8051 monitor (hex up-/download, single step, disassemble)
30724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30727 \begin_layout Standard
30728 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30738 <row topline="true">
30739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30742 \begin_layout Standard
30744 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30756 \begin_layout Standard
30757 Statically checks c sources (see
30758 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30770 \begin_layout Standard
30771 \begin_inset LatexCommand \url{http://www.splint.org}
30781 <row topline="true" bottomline="true">
30782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30785 \begin_layout Standard
30787 \begin_inset LatexCommand \index{DDD (debugger)}
30796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30799 \begin_layout Standard
30800 Debugger, serves nicely as GUI to SDCDB
30801 \begin_inset LatexCommand \index{SDCDB (debugger)}
30810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30813 \begin_layout Standard
30814 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30833 \begin_layout Section
30834 Related documentation / recommended reading
30837 \begin_layout Standard
30839 \begin_inset Tabular
30840 <lyxtabular version="3" rows="7" columns="3">
30842 <column alignment="left" valignment="top" leftline="true" width="0pt">
30843 <column alignment="left" valignment="top" leftline="true" width="0">
30844 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30845 <row topline="true" bottomline="true">
30846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30849 \begin_layout Standard
30857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30860 \begin_layout Standard
30868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30871 \begin_layout Standard
30880 <row topline="true">
30881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30884 \begin_layout Standard
30899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30902 \begin_layout Standard
30904 \begin_inset LatexCommand \index{C Reference card}
30913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30916 \begin_layout Standard
30917 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30927 <row topline="true">
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30931 \begin_layout Standard
30937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30940 \begin_layout Standard
30942 \begin_inset LatexCommand \index{C FAQ}
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30954 \begin_layout Standard
30955 \begin_inset LatexCommand \url{http://www.c-faq.com}
30965 <row topline="true">
30966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30969 \begin_layout Standard
30975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30978 \begin_layout Standard
30979 \begin_inset Quotes sld
30983 \begin_inset Quotes srd
30991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30994 \begin_layout Standard
30997 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31007 <row topline="true">
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31011 \begin_layout Standard
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31020 \begin_layout Standard
31021 \begin_inset Quotes sld
31024 Extensions for Embedded C
31025 \begin_inset Quotes srd
31033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31036 \begin_layout Standard
31039 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31049 <row topline="true">
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31053 \begin_layout Standard
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_layout Standard
31063 Latest datasheet of target CPU
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_layout Standard
31078 <row topline="true" bottomline="true">
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31082 \begin_layout Standard
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31091 \begin_layout Standard
31092 Revision history of datasheet
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31100 \begin_layout Standard
31116 \begin_layout Section
31117 Application notes specifically for SDCC
31120 \begin_layout Standard
31121 SDCC makes no claims about the completeness of this list and about up-to-datenes
31122 s or correctness of the application notes
31123 \begin_inset LatexCommand \index{Application notes}
31130 \begin_layout Standard
31134 \begin_inset Tabular
31135 <lyxtabular version="3" rows="7" columns="3">
31137 <column alignment="block" valignment="top" leftline="true" width="17col%">
31138 <column alignment="block" valignment="top" leftline="true" width="27col%">
31139 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31140 <row topline="true" bottomline="true">
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31144 \begin_layout Standard
31153 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31156 \begin_layout Standard
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31168 \begin_layout Standard
31178 <row topline="true">
31179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31182 \begin_layout Standard
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31193 \begin_layout Standard
31196 Using the SDCC Compiler for the DS80C400
31197 \begin_inset LatexCommand \index{DS80C400}
31206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31209 \begin_layout Standard
31212 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31222 <row topline="true">
31223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_layout Standard
31234 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31237 \begin_layout Standard
31240 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31241 \begin_inset LatexCommand \index{DS89C4x0}
31245 Family of Microcontrollers
31250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31253 \begin_layout Standard
31256 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31266 <row topline="true">
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31270 \begin_layout Standard
31273 Silicon Laboratories / Cygnal
31278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31281 \begin_layout Standard
31284 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31285 \begin_inset LatexCommand \index{IDE}
31294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31297 \begin_layout Standard
31300 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31310 <row topline="true">
31311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31314 \begin_layout Standard
31317 Ramtron / Goal Semiconductor
31322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31325 \begin_layout Standard
31328 Interfacing SDCC to Syn and Textpad
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31336 \begin_layout Standard
31339 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31349 <row topline="true">
31350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31353 \begin_layout Standard
31356 Ramtron / Goal Semiconductor
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31364 \begin_layout Standard
31367 Installing and Configuring SDCC and Crimson Editor
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31375 \begin_layout Standard
31378 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31388 <row topline="true" bottomline="true">
31389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31392 \begin_layout Standard
31400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31403 \begin_layout Standard
31406 MSC12xx Programming with SDCC
31411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31414 \begin_layout Standard
31417 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31434 \begin_layout Section
31438 \begin_layout Standard
31439 Some questions answered, some pointers given - it might be time to in turn
31447 \begin_layout Itemize
31448 can you solve your project with the selected microcontroller? Would you
31449 find out early or rather late that your target is too small/slow/whatever?
31450 Can you switch to a slightly better device if it doesn't fit?
31453 \begin_layout Itemize
31454 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31455 and/or another programming language be more adequate? Would an operating
31456 system on the target device help?
31459 \begin_layout Itemize
31460 if you solved the problem, will the marketing department be happy?
31463 \begin_layout Itemize
31464 if the marketing department is happy, will customers be happy?
31467 \begin_layout Itemize
31468 if you're the project manager, marketing department and maybe even the customer
31469 in one person, have you tried to see the project from the outside?
31472 \begin_layout Itemize
31473 is the project done if you think it is done? Or is just that other interface/pro
31474 tocol/feature/configuration/option missing? How about website, manual(s),
31475 internationali(z|s)ation, packaging, labels, 2nd source for components,
31476 electromagnetic compatability/interference, documentation for production,
31477 production test software, update mechanism, patent issues?
31480 \begin_layout Itemize
31481 is your project adequately positioned in that magic triangle: fame, fortune,
31485 \begin_layout Standard
31486 Maybe not all answers to these questions are known and some answers may
31491 , nevertheless knowing these questions may help you to avoid burnout
31495 \begin_layout Standard
31496 burnout is bad for electronic devices, programmers and motorcycle tyres
31502 Chances are you didn't want to hear some of them...
31505 \begin_layout Chapter
31507 \begin_inset LatexCommand \index{Support}
31514 \begin_layout Standard
31515 SDCC has grown to be a large project.
31516 The compiler alone (without the preprocessor, assembler and linker) is
31517 well over 150,000 lines of code (blank stripped).
31518 The open source nature of this project is a key to its continued growth
31520 You gain the benefit and support of many active software developers and
31522 Is SDCC perfect? No, that's why we need your help.
31523 The developers take pride in fixing reported bugs.
31524 You can help by reporting the bugs and helping other SDCC users.
31525 There are lots of ways to contribute, and we encourage you to take part
31526 in making SDCC a great software package.
31530 \begin_layout Standard
31531 The SDCC project is hosted on the SDCC sourceforge site at
31532 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31537 You'll find the complete set of mailing lists
31538 \begin_inset LatexCommand \index{Mailing list(s)}
31542 , forums, bug reporting system, patch submission
31543 \begin_inset LatexCommand \index{Patch submission}
31548 \begin_inset LatexCommand \index{download}
31552 area and Subversion code repository
31553 \begin_inset LatexCommand \index{Subversion code repository}
31560 \begin_layout Section
31562 \begin_inset LatexCommand \index{Bug reporting}
31567 \begin_inset LatexCommand \index{Reporting bugs}
31574 \begin_layout Standard
31575 The recommended way of reporting bugs is using the infrastructure of the
31577 You can follow the status of bug reports there and have an overview about
31581 \begin_layout Standard
31582 Bug reports are automatically forwarded to the developer mailing list and
31583 will be fixed ASAP.
31584 When reporting a bug, it is very useful to include a small test program
31585 (the smaller the better) which reproduces the problem.
31586 If you can isolate the problem by looking at the generated assembly code,
31587 this can be very helpful.
31588 Compiling your program with the -
31592 \begin_layout Standard
31602 \begin_inset LatexCommand \index{-\/-dumpall}
31606 option can sometimes be useful in locating optimization problems.
31607 When reporting a bug please make sure you:
31610 \begin_layout Enumerate
31611 Attach the code you are compiling with SDCC.
31615 \begin_layout Enumerate
31616 Specify the exact command you use to run SDCC, or attach your Makefile.
31620 \begin_layout Enumerate
31621 Specify the SDCC version (type "
31627 "), your platform, and operating system.
31631 \begin_layout Enumerate
31632 Provide an exact copy of any error message or incorrect output.
31636 \begin_layout Enumerate
31637 Put something meaningful in the subject of your message.
31640 \begin_layout Standard
31641 Please attempt to include these 5 important parts, as applicable, in all
31642 requests for support or when reporting any problems or bugs with SDCC.
31643 Though this will make your message lengthy, it will greatly improve your
31644 chance that SDCC users and developers will be able to help you.
31645 Some SDCC developers are frustrated by bug reports without code provided
31646 that they can use to reproduce and ultimately fix the problem, so please
31647 be sure to provide sample code if you are reporting a bug!
31650 \begin_layout Standard
31651 Please have a short check that you are using a recent version of SDCC and
31652 the bug is not yet known.
31653 This is the link for reporting bugs:
31654 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31659 With SDCC on average having more than 200 downloads
31660 \begin_inset LatexCommand \index{download}
31664 on sourceforge per day
31668 \begin_layout Standard
31669 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31670 between 2002 and 2005.
31671 This does not include other methods of distribution.
31676 there must be some users.
31677 So it's not exactly easy to find a new bug.
31678 If you find one we need it:
31680 reporting bugs is good
31685 \begin_layout Section
31686 Requesting Features
31687 \begin_inset LatexCommand \label{sub:Requesting-Features}
31692 \begin_inset LatexCommand \index{Feature request}
31697 \begin_inset LatexCommand \index{Requesting features}
31704 \begin_layout Standard
31705 Like bug reports feature requests are forwarded to the developer mailing
31707 This is the link for requesting features:
31708 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31715 \begin_layout Section
31719 \begin_layout Standard
31720 Like bug reports contributed patches are forwarded to the developer mailing
31722 This is the link for submitting patches
31723 \begin_inset LatexCommand \index{Patch submission}
31728 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31735 \begin_layout Standard
31736 You need to specify some parameters to the
31740 command for the patches to be useful.
31741 If you modified more than one file a patch created f.e.
31746 \begin_inset Quotes sld
31749 diff -Naur unmodified_directory modified_directory >my_changes.patch
31750 \begin_inset Quotes srd
31756 will be fine, otherwise
31760 \begin_inset Quotes sld
31763 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31764 \begin_inset Quotes srd
31774 \begin_layout Section
31778 \begin_layout Standard
31779 These links should take you directly to the
31780 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31788 \begin_layout Standard
31789 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31790 automated messages (mid 2003)
31796 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31801 \begin_inset LatexCommand \index{Mailing list(s)}
31805 and forums are archived and searchable so if you are lucky someone already
31806 had a similar problem.
31807 While mails to the lists themselves are delivered promptly their web front
31808 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31809 if you're seriously using SDCC please consider subscribing to the lists.
31812 \begin_layout Section
31816 \begin_layout Standard
31817 You can follow the status of the Subversion version
31818 \begin_inset LatexCommand \index{version}
31822 of SDCC by watching the Changelog
31823 \begin_inset LatexCommand \index{Changelog}
31827 in the Subversion repository
31830 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31837 \begin_layout Section
31838 Subversion Source Code Repository
31841 \begin_layout Standard
31848 or the filenames of the snapshot versions of SDCC include date and its
31850 \begin_inset LatexCommand \index{Subversion code repository}
31855 Subversion allows to download the source of recent or previous versions
31857 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31861 (by number or by date).
31862 An on-line source code browser and detailled instructions are also available
31864 SDCC versions starting from 1999 up to now are available (currently the
31865 versions prior to the conversion from cvs
31866 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31870 to Subversion (April 2006) are either by accessible by Subversion or by
31874 \begin_layout Section
31876 \begin_inset LatexCommand \index{Release policy}
31883 \begin_layout Standard
31884 Historically there often were long delays between official releases and
31885 the sourceforge download area tends to get not updated at all.
31886 Excuses in the past might have referred to problems with live range analysis,
31887 but as this was fixed a while ago, the current problem is that another
31888 excuse has to be found.
31889 Kidding aside, we have to get better there! On the other hand there are
31890 daily snapshots available at
31891 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31895 , and you can always build the very last version (hopefully with many bugs
31896 fixed, and features added) from the source code available at
31897 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31903 \begin_inset LatexCommand \index{wiki}
31908 \begin_inset LatexCommand \index{Release wiki}
31913 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31917 also holds some information about past and future releases.
31920 \begin_layout Section
31922 \begin_inset LatexCommand \index{Examples}
31929 \begin_layout Standard
31930 You'll find some small examples in the directory
31932 sdcc/device/examples/.
31935 More examples and libraries are available at
31937 The SDCC Open Knowledge Resource
31938 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31945 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31952 \begin_layout Standard
31953 \begin_inset Note Note
31956 \begin_layout Standard
31957 I did insert a reference to Paul's web site here although it seems rather
31958 dedicated to a specific 8032 board (I think it's okay because it f.e.
31959 shows LCD/Harddisc interface and has a free 8051 monitor.
31960 Independent 8032 board vendors face hard competition of heavily subsidized
31961 development boards anyway).
31964 \begin_layout Standard
31965 Maybe we should include some links to real world applications.
31966 Preferably pointer to pointers (one for each architecture) so this stays
31975 \begin_layout Section
31977 \begin_inset LatexCommand \label{sec:Quality-control}
31982 \begin_inset LatexCommand \index{Quality control}
31989 \begin_layout Standard
31990 The compiler is passed through snaphot build compile and build checks.
31996 \begin_inset LatexCommand \index{Regression test}
32000 check that SDCC itself compiles flawlessly on several host platforms (i386,
32001 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
32002 the quality of the code generated by SDCC by running the code for several
32003 target platforms through simulators.
32004 The regression test suite comprises more than 100 files which expand to
32005 more than 500 test cases which include more than 4500 tests.
32006 The results of these tests are published daily on SDCC's snapshot page
32007 (click on the red or green symbols on the right side of
32008 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32015 \begin_layout Standard
32016 There is a separate document
32019 \begin_inset LatexCommand \index{Test suite}
32026 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32030 about the regression test suite.
32033 \begin_layout Standard
32034 You'll find the test code in the directory
32036 sdcc/support/regression
32039 You can run these tests manually by running
32043 in this directory (or f.e.
32048 \begin_inset Quotes sld
32052 \begin_inset Quotes srd
32058 if you don't want to run the complete tests).
32059 The test code might also be interesting if you want to look for examples
32060 \begin_inset LatexCommand \index{Examples}
32064 checking corner cases of SDCC or if you plan to submit patches
32065 \begin_inset LatexCommand \index{Patch submission}
32072 \begin_layout Standard
32073 The 14bit pic port uses a different set of regression tests
32074 \begin_inset LatexCommand \index{Regression test (PIC14)}
32078 , you'll find them in the directory
32080 sdcc/src/regression
32085 \begin_layout Section
32086 Use of SDCC in Education
32089 \begin_layout Standard
32098 \begin_layout Standard
32099 the phrase "use in education" might evoke the association "
32103 fit for use in education".
32104 This connotation is not intended but nevertheless risked as the licensing
32105 of SDCC makes it difficult to offer educational discounts
32111 If your rationales are to:
32114 \begin_layout Enumerate
32115 give students a chance to understand the
32119 steps of code generation
32122 \begin_layout Enumerate
32123 have a curriculum that can be extended for years.
32124 Then you could use an fpga board as target and your curriculum will seamlessly
32125 extend from logic synthesis (
32126 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32131 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32135 ), over assembly programming, to C to FPGA compilers (
32136 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32143 \begin_layout Enumerate
32144 be able to insert excursions about skills like using a revision control
32145 system, submitting/applying patches, using a type-setting (as opposed to
32146 word-processing) engine LyX/LaTeX, using
32147 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32152 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32156 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32157 Source Software, CPU simulation, compiler regression tests
32158 \begin_inset LatexCommand \index{Regression test}
32165 And if there should be a shortage of ideas then you can always point students
32166 to the ever-growing feature request list
32167 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32174 \begin_layout Enumerate
32175 not tie students to a specific host platform and instead allow them to use
32180 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
32182 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32189 \begin_layout Enumerate
32190 not encourage students to use illegal copies of educational software
32193 \begin_layout Enumerate
32194 be immune to licensing/availability/price changes of the chosen tool chain
32197 \begin_layout Enumerate
32198 be able to change to a new target platform without having to adopt a new
32202 \begin_layout Enumerate
32203 have complete control over and insight into the tool chain
32206 \begin_layout Enumerate
32207 make your students aware about the pros and cons of open source software
32211 \begin_layout Enumerate
32212 give back to the public as you are probably at least partially publically
32216 \begin_layout Enumerate
32217 give students a chance to publically prove their skills and to possibly
32218 see a world wide impact
32221 \begin_layout Standard
32222 then SDCC is probably among the first choices.
32223 Well, probably SDCC might be the only choice.
32228 \begin_layout Chapter
32229 SDCC Technical Data
32232 \begin_layout Section
32234 \begin_inset LatexCommand \index{Optimizations}
32241 \begin_layout Standard
32242 SDCC performs a host of standard optimizations in addition to some MCU specific
32247 \begin_layout Subsection
32248 Sub-expression Elimination
32249 \begin_inset LatexCommand \index{Subexpression elimination}
32256 \begin_layout Standard
32257 The compiler does local and
32276 \begin_layout Verse
32284 \begin_layout Standard
32285 will be translated to
32288 \begin_layout Verse
32298 \begin_layout Standard
32299 Some subexpressions are not as obvious as the above example, e.g.:
32302 \begin_layout Verse
32310 \begin_layout Standard
32311 In this case the address arithmetic a->b[i] will be computed only once;
32312 the equivalent code in C would be.
32315 \begin_layout Verse
32325 \begin_layout Standard
32326 The compiler will try to keep these temporary variables in registers.
32329 \begin_layout Subsection
32330 Dead-Code Elimination
32331 \begin_inset LatexCommand \index{Dead-code elimination}
32338 \begin_layout Verse
32353 i = 1; \InsetSpace ~
32362 global = 1;\InsetSpace ~
32376 global = 3;\InsetSpace ~
32382 \begin_layout Standard
32386 \begin_layout Verse
32402 \begin_layout Subsection
32404 \begin_inset LatexCommand \index{Copy propagation}
32411 \begin_layout Verse
32435 \begin_layout Standard
32439 \begin_layout Verse
32463 \begin_layout Standard
32464 Note: the dead stores created by this copy propagation will be eliminated
32465 by dead-code elimination.
32468 \begin_layout Subsection
32470 \begin_inset LatexCommand \index{Loop optimization}
32475 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32482 \begin_layout Standard
32483 Two types of loop optimizations are done by SDCC
32491 of loop induction variables.
32492 In addition to the strength reduction the optimizer marks the induction
32493 variables and the register allocator tries to keep the induction variables
32494 in registers for the duration of the loop.
32495 Because of this preference of the register allocator
32496 \begin_inset LatexCommand \index{Register allocation}
32500 , loop induction optimization causes an increase in register pressure, which
32501 may cause unwanted spilling of other temporary variables into the stack
32502 \begin_inset LatexCommand \index{stack}
32507 The compiler will generate a warning message when it is forced to allocate
32508 extra space either on the stack or data space.
32509 If this extra space allocation is undesirable then induction optimization
32510 can be eliminated either for the entire source file (with -
32514 \begin_layout Standard
32523 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32525 \begin_inset LatexCommand \index{\#pragma noinduction}
32536 \begin_layout Verse
32539 for (i = 0 ; i < 100 ; i ++)
32548 \begin_layout Standard
32552 \begin_layout Verse
32557 for (i = 0; i < 100; i++)
32566 \begin_layout Standard
32567 As mentioned previously some loop invariants are not as apparent, all static
32568 address computations are also moved out of the loop.
32573 \begin_inset LatexCommand \index{Strength reduction}
32577 , this optimization substitutes an expression by a cheaper expression:
32580 \begin_layout Verse
32583 for (i=0;i < 100; i++)
32592 \begin_layout Standard
32596 \begin_layout Verse
32603 for (i=0;i< 100;i++) {
32609 ar[itemp1] = itemp2;
32627 \begin_layout Standard
32628 The more expensive multiplication
32629 \begin_inset LatexCommand \index{Multiplication}
32633 is changed to a less expensive addition.
32636 \begin_layout Subsection
32638 \begin_inset LatexCommand \index{Loop reversing}
32645 \begin_layout Standard
32646 This optimization is done to reduce the overhead of checking loop boundaries
32647 for every iteration.
32648 Some simple loops can be reversed and implemented using a
32649 \begin_inset Quotes eld
32652 decrement and jump if not zero
32653 \begin_inset Quotes erd
32657 SDCC checks for the following criterion to determine if a loop is reversible
32658 (note: more sophisticated compilers use data-dependency analysis to make
32659 this determination, SDCC uses a more simple minded analysis).
32662 \begin_layout Itemize
32663 The 'for' loop is of the form
32669 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32679 \begin_layout Itemize
32680 The <for body> does not contain
32681 \begin_inset Quotes eld
32685 \begin_inset Quotes erd
32689 \begin_inset Quotes erd
32695 \begin_layout Itemize
32696 All goto's are contained within the loop.
32699 \begin_layout Itemize
32700 No function calls within the loop.
32703 \begin_layout Itemize
32704 The loop control variable <sym> is not assigned any value within the loop
32707 \begin_layout Itemize
32708 The loop control variable does NOT participate in any arithmetic operation
32712 \begin_layout Itemize
32713 There are NO switch statements in the loop.
32716 \begin_layout Subsection
32717 Algebraic Simplifications
32720 \begin_layout Standard
32721 SDCC does numerous algebraic simplifications, the following is a small sub-set
32722 of these optimizations.
32725 \begin_layout Verse
32728 i = j + 0;\InsetSpace ~
32732 /* changed to: */\InsetSpace ~
32738 i /= 2;\InsetSpace ~
32745 /* changed to: */\InsetSpace ~
32752 = j - j;\InsetSpace ~
32756 /* changed to: */\InsetSpace ~
32762 i = j / 1;\InsetSpace ~
32766 /* changed to: */\InsetSpace ~
32773 \begin_layout Standard
32774 Note the subexpressions
32775 \begin_inset LatexCommand \index{Subexpression}
32779 given above are generally introduced by macro expansions or as a result
32780 of copy/constant propagation.
32783 \begin_layout Subsection
32784 'switch' Statements
32785 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32790 \begin_inset LatexCommand \index{switch statement}
32797 \begin_layout Standard
32798 SDCC can optimize switch statements to jump tables
32799 \begin_inset LatexCommand \index{jump tables}
32804 It makes the decision based on an estimate of the generated code size.
32805 SDCC is quite liberal in the requirements for jump table generation:
32808 \begin_layout Itemize
32809 The labels need not be in order, and the starting number need not be one
32810 or zero, the case labels are in numerical sequence or not too many case
32811 labels are missing.
32815 \begin_layout Verse
32818 switch(i) {\InsetSpace ~
32849 case 4: ...\InsetSpace ~
32881 case 5: ...\InsetSpace ~
32913 case 3: ...\InsetSpace ~
32944 case 6: ...\InsetSpace ~
32976 case 7: ...\InsetSpace ~
33008 case 8: ...\InsetSpace ~
33040 case 9: ...\InsetSpace ~
33072 case 10: ...\InsetSpace ~
33103 case 11: ...\InsetSpace ~
33170 \begin_layout Standard
33171 Both the above switch statements will be implemented using a jump-table.
33172 The example to the right side is slightly more efficient as the check for
33173 the lower boundary of the jump-table is not needed.
33177 \begin_layout Itemize
33178 The number of case labels is not larger than supported by the target architectur
33182 \begin_layout Itemize
33183 If the case labels are not in numerical sequence ('gaps' between cases)
33184 SDCC checks whether a jump table with additionally inserted dummy cases
33185 is still attractive.
33189 \begin_layout Itemize
33190 If the starting number is not zero and a check for the lower boundary of
33191 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33196 \begin_layout Standard
33197 Switch statements which have large gaps in the numeric sequence or those
33198 that have too many case labels can be split into more than one switch statement
33199 for efficient code generation, e.g.:
33202 \begin_layout Verse
33280 \begin_layout Standard
33281 If the above switch statement is broken down into two switch statements
33284 \begin_layout Verse
33327 \begin_layout Standard
33331 \begin_layout Verse
33374 \begin_layout Standard
33375 then both the switch statements will be implemented using jump-tables whereas
33376 the unmodified switch statement will not be.
33379 \begin_layout Standard
33380 \begin_inset Note Note
33383 \begin_layout Standard
33384 There might be reasons which SDCC cannot know about to either favour or
33385 not favour jump tables.
33386 If the target system has to be as quick for the last switch case as for
33387 the first (pro jump table), or if the switch argument is known to be zero
33388 in the majority of the cases (contra jump table).
33396 \begin_layout Standard
33397 The pragma nojtbound
33398 \begin_inset LatexCommand \index{\#pragma nojtbound}
33402 can be used to turn off checking the
33415 It has no effect if a default label is supplied.
33416 Use of this pragma is dangerous: if the switch
33417 \begin_inset LatexCommand \index{switch statement}
33421 argument is not matched by a case statement the processor will happily
33425 \begin_layout Subsection
33426 Bit-shifting Operations
33427 \begin_inset LatexCommand \index{Bit shifting}
33434 \begin_layout Standard
33435 Bit shifting is one of the most frequently used operation in embedded programmin
33437 SDCC tries to implement bit-shift operations in the most efficient way
33441 \begin_layout Verse
33454 \begin_layout Standard
33455 generates the following code:
33458 \begin_layout Verse
33473 \begin_layout Standard
33474 In general SDCC will never setup a loop if the shift count is known.
33478 \begin_layout Verse
33491 \begin_layout Standard
33495 \begin_layout Verse
33519 \begin_layout Subsection
33521 \begin_inset LatexCommand \index{Bit rotation}
33528 \begin_layout Standard
33529 A special case of the bit-shift operation is bit rotation
33530 \begin_inset LatexCommand \index{rotating bits}
33534 , SDCC recognizes the following expression to be a left bit-rotation:
33537 \begin_layout Verse
33545 char i;\InsetSpace ~
33556 /* unsigned is needed for rotation */
33561 i = ((i << 1) | (i >> 7));
33570 \begin_layout Standard
33571 will generate the following code:
33574 \begin_layout Verse
33591 \begin_layout Standard
33592 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33593 ns of this case will also be recognized as bit-rotation, i.e.:
33596 \begin_layout Verse
33599 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33602 \begin_layout Subsection
33603 Nibble and Byte Swapping
33606 \begin_layout Standard
33607 Other special cases of the bit-shift operations are nibble or byte swapping
33608 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33612 , SDCC recognizes the following expressions:
33615 \begin_layout Verse
33636 i = ((i << 4) | (i >> 4));
33642 j = ((j << 8) | (j >> 8));
33645 \begin_layout Standard
33646 and generates a swap instruction for the nibble swapping
33647 \begin_inset LatexCommand \index{Nibble swapping}
33651 or move instructions for the byte swapping
33652 \begin_inset LatexCommand \index{Byte swapping}
33658 \begin_inset Quotes sld
33662 \begin_inset Quotes srd
33665 example can be used to convert from little to big-endian or vice versa.
33666 If you want to change the endianness of a
33670 integer you have to cast to
33677 \begin_layout Standard
33678 Note that SDCC stores numbers in little-endian
33682 \begin_layout Standard
33683 Usually 8-bit processors don't care much about endianness.
33684 This is not the case for the standard 8051 which only has an instruction
33690 \begin_inset LatexCommand \index{DPTR}
33698 so little-endian is the more efficient byte order.
33704 \begin_inset LatexCommand \index{little-endian}
33709 \begin_inset LatexCommand \index{Endianness}
33714 lowest order first).
33717 \begin_layout Subsection
33719 \begin_inset LatexCommand \index{Highest Order Bit}
33724 \begin_inset LatexCommand \index{Any Order Bit}
33731 \begin_layout Standard
33732 It is frequently required to obtain the highest order bit of an integral
33733 type (long, int, short or char types).
33734 Also obtaining any other order bit is not uncommon.
33735 SDCC recognizes the following expressions to yield the highest order bit
33736 and generates optimized code for it, e.g.:
33739 \begin_layout Verse
33750 unsigned char hob1, aob1;
33754 bit hob2, hob3, aob2,
33764 hob1 = (gint >> 15) & 1;
33768 hob2 = (gint >> 15) & 1;
33772 hob3 = gint & 0x8000;
33777 aob1 = (gint >> 9) & 1;
33781 aob2 = (gint >> 8) & 1;
33785 aob3 = gint & 0x0800;
33795 \begin_layout Standard
33796 will generate the following code:
33799 \begin_layout Verse
33830 000A E5*01\InsetSpace ~
33857 000C 23\InsetSpace ~
33888 000D 54 01\InsetSpace ~
33916 000F F5*02\InsetSpace ~
33971 0011 E5*01\InsetSpace ~
33999 0013 33\InsetSpace ~
34029 0014 92*00\InsetSpace ~
34085 0016 E5*01\InsetSpace ~
34112 0018 33\InsetSpace ~
34142 0019 92*01\InsetSpace ~
34198 001B E5*01\InsetSpace ~
34257 001E 54 01\InsetSpace ~
34284 0020 F5*03\InsetSpace ~
34340 0022 E5*01\InsetSpace ~
34367 0024 13\InsetSpace ~
34397 0025 92*02\InsetSpace ~
34453 0027 E5*01\InsetSpace ~
34508 002B 92*03\InsetSpace ~
34536 \begin_layout Standard
34537 Other variations of these cases however will
34542 They are standard C expressions, so I heartily recommend these be the only
34543 way to get the highest order bit, (it is portable).
34544 Of course it will be recognized even if it is embedded in other expressions,
34548 \begin_layout Verse
34551 xyz = gint + ((gint >> 15) & 1);
34554 \begin_layout Standard
34555 will still be recognized.
34558 \begin_layout Subsection
34560 \begin_inset LatexCommand \index{Higher Order Byte}
34564 / Higher Order Word
34565 \begin_inset LatexCommand \index{Higher Order Word}
34572 \begin_layout Standard
34573 It is also frequently required to obtain a higher order byte or word of
34574 a larger integral type (long, int or short types).
34575 SDCC recognizes the following expressions to yield the higher order byte
34576 or word and generates optimized code for it, e.g.:
34579 \begin_layout Verse
34584 unsigned long int glong;
34592 unsigned char hob1,
34597 unsigned int how1, how2;
34606 hob1 = (gint >> 8) & 0xFF;
34610 hob2 = glong >> 24;
34614 how1 = (glong >> 16) & 0xFFFF;
34629 \begin_layout Standard
34630 will generate the following code:
34633 \begin_layout Verse
34664 0037 85*01*06\InsetSpace ~
34686 _foo_hob1_1_1,(_gint + 1)
34717 003A 85*05*07\InsetSpace ~
34739 _foo_hob2_1_1,(_glong + 3)
34769 003D 85*04*08\InsetSpace ~
34792 _foo_how1_1_1,(_glong + 2)
34794 0040 85*05*09\InsetSpace ~
34819 0043 85*03*0A\InsetSpace ~
34841 _foo_how2_1_1,(_glong + 1)
34843 0046 85*04*0B\InsetSpace ~
34866 (_foo_how2_1_1 + 1),(_glong + 2)
34869 \begin_layout Standard
34870 Again, variations of these cases may
34875 They are standard C expressions, so I heartily recommend these be the only
34876 way to get the higher order byte/word, (it is portable).
34877 Of course it will be recognized even if it is embedded in other expressions,
34881 \begin_layout Verse
34884 xyz = gint + ((gint >> 8) & 0xFF);
34887 \begin_layout Standard
34888 will still be recognized.
34891 \begin_layout Subsection
34893 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34898 \begin_inset LatexCommand \index{Peephole optimizer}
34905 \begin_layout Standard
34906 The compiler uses a rule based, pattern matching and re-writing mechanism
34907 for peep-hole optimization.
34912 a peep-hole optimizer by Christopher W.
34913 Fraser (cwfraser\InsetSpace ~
34916 A default set of rules are compiled into the compiler, additional rules
34917 may be added with the
34923 \begin_layout Standard
34933 \begin_inset LatexCommand \index{-\/-peep-file}
34940 The rule language is best illustrated with examples.
34943 \begin_layout Verse
34965 \begin_layout Standard
34966 The above rule will change the following assembly
34967 \begin_inset LatexCommand \index{Assembler routines}
34974 \begin_layout Verse
34982 \begin_layout Standard
34986 \begin_layout Verse
34992 \begin_layout Standard
34993 Note: All occurrences of a
34997 (pattern variable) must denote the same string.
34998 With the above rule, the assembly sequence:
35001 \begin_layout Verse
35009 \begin_layout Standard
35010 will remain unmodified.
35014 Other special case optimizations may be added by the
35021 \begin_layout Standard
35034 some variants of the 8051 MCU
35035 \begin_inset LatexCommand \index{MCS51 variants}
35048 The following two rules will change all
35065 \begin_layout Verse
35068 replace { lcall %1 } by { acall %1 }
35070 replace { ljmp %1 } by { ajmp %1 }
35073 \begin_layout Standard
35076 inline-assembler code
35078 is also passed through the peep hole optimizer, thus the peephole optimizer
35079 can also be used as an assembly level macro expander.
35080 The rules themselves are MCU dependent whereas the rule language infra-structur
35081 e is MCU independent.
35082 Peephole optimization rules for other MCU can be easily programmed using
35087 The syntax for a rule is as follows:
35090 \begin_layout Verse
35093 rule := replace [ restart ] '{' <assembly sequence> '
35131 <assembly sequence> '
35149 '}' [if <functionName> ] '
35154 \begin_layout Standard
35155 <assembly sequence> := assembly instruction (each instruction including
35156 labels must be on a separate line).
35160 The optimizer will apply to the rules
35161 one by one from the top in the sequence of their appearance, it will terminate
35162 when all rules are exhausted.
35163 If the 'restart' option is specified, then the optimizer will start matching
35164 the rules again from the top, this option for a rule is expensive (performance)
35165 , it is intended to be used in situations where a transformation will trigger
35166 the same rule again.
35167 An example of this (not a good one, it has side effects) is the following
35171 \begin_layout Verse
35191 \begin_layout Standard
35192 Note that the replace pattern cannot be a blank, but can be a comment line.
35193 Without the 'restart' option only the innermost 'pop' 'push' pair would
35194 be eliminated, i.e.:
35197 \begin_layout Verse
35209 \begin_layout Standard
35213 \begin_layout Verse
35223 \begin_layout Standard
35228 the restart option the rule will be applied again to the resulting code
35229 and then all the pop-push pairs will be eliminated to yield:
35232 \begin_layout Verse
35240 \begin_layout Standard
35241 A conditional function can be attached to a rule.
35242 Attaching rules are somewhat more involved, let me illustrate this with
35246 \begin_layout Verse
35270 \begin_layout Standard
35271 The optimizer does a look-up of a function name table defined in function
35276 in the source file SDCCpeeph.c, with the name
35281 If it finds a corresponding entry the function is called.
35282 Note there can be no parameters specified for these functions, in this
35287 is crucial, since the function
35291 expects to find the label in that particular variable (the hash table containin
35292 g the variable bindings is passed as a parameter).
35293 If you want to code more such functions, take a close look at the function
35294 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35295 Currently implemented are
35297 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35298 24bitMode, portIsDS390, 24bitModeAndPortDS390
35307 \begin_layout Standard
35308 I know this whole thing is a little kludgey, but maybe some day we will
35309 have some better means.
35310 If you are looking at this file, you will see the default rules that are
35311 compiled into the compiler, you can add your own rules in the default set
35312 there if you get tired of specifying the -
35316 \begin_layout Standard
35328 \begin_layout Section
35330 \begin_inset LatexCommand \index{ANSI-compliance}
35335 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35342 \begin_layout Standard
35343 The latest publically available version of the standard
35345 ISO/IEC 9899 - Programming languages - C
35347 should be available at:
35348 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35357 \begin_layout Standard
35358 Deviations from the compliance:
35361 \begin_layout Itemize
35362 functions are not reentrant
35363 \begin_inset LatexCommand \index{reentrant}
35367 unless explicitly declared as such or the
35373 \begin_layout Standard
35383 \begin_inset LatexCommand \index{-\/-stack-auto}
35389 command line option is specified.
35392 \begin_layout Itemize
35394 \begin_inset LatexCommand \index{struct}
35399 \begin_inset LatexCommand \index{union}
35403 cannot be assigned values directly, cannot be passed as function parameters
35404 or assigned to each other and cannot be a return value
35405 \begin_inset LatexCommand \index{return value}
35409 from a function, e.g.:
35413 \begin_layout Verse
35436 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35455 s parms) /* invalid in SDCC although allowed in ANSI */
35477 return rets; /* is invalid in SDCC although allowed in ANSI */
35483 \begin_layout Itemize
35484 initialization of structure arrays must be fully braced.
35488 \begin_layout Verse
35491 struct s { char x } a[] = {1, 2};\InsetSpace ~
35496 /* invalid in SDCC */
35499 } a[] = {{1}, {2}}; /* OK */
35503 \begin_layout Itemize
35505 \begin_inset LatexCommand \index{long long (not supported)}
35510 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35517 \begin_layout Itemize
35519 \begin_inset LatexCommand \index{double (not supported)}
35523 ' precision floating point
35524 \begin_inset LatexCommand \index{Floating point support}
35531 \begin_layout Itemize
35533 \begin_inset LatexCommand \index{K\&R style}
35537 function declarations are NOT allowed.
35541 \begin_layout Verse
35544 foo(i,j) /* this old style of function declarations */
35546 int i,j; /* are valid
35547 in ANSI but not valid in SDCC */
35562 \begin_layout Itemize
35563 Most enhancements in C99 are not supported, f.e.:
35567 \begin_layout Verse
35572 \begin_inset LatexCommand \index{inline (not supported)}
35578 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35584 can be used as a work around */
35592 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35596 \begin_layout Itemize
35597 Certain words that are valid identifiers in the standard may be reserved
35598 words in SDCC unless the
35604 \begin_layout Standard
35614 \begin_inset LatexCommand \index{-\/-std-c89}
35622 \begin_layout Standard
35632 \begin_inset LatexCommand \index{-\/-std-c99}
35638 command line options are used.
35639 These may include (depending on the selected processor): 'at', 'banked',
35640 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35641 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35642 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35644 Compliant equivalents of these keywords are always available in a form
35645 that begin with two underscores
35646 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35651 '__data' instead of 'data'.
35654 \begin_layout Section
35655 Cyclomatic Complexity
35656 \begin_inset LatexCommand \index{Cyclomatic complexity}
35663 \begin_layout Standard
35664 Cyclomatic complexity of a function is defined as the number of independent
35665 paths the program can take during execution of the function.
35666 This is an important number since it defines the number test cases you
35667 have to generate to validate the function.
35668 The accepted industry standard for complexity number is 10, if the cyclomatic
35669 complexity reported by SDCC exceeds 10 you should think about simplification
35670 of the function logic.
35671 Note that the complexity level is not related to the number of lines of
35672 code in a function.
35673 Large functions can have low complexity, and small functions can have large
35679 SDCC uses the following formula to compute the complexity:
35684 \begin_layout Standard
35685 complexity = (number of edges in control flow graph) - (number of nodes
35686 in control flow graph) + 2;
35690 Having said that the industry standard is 10,
35691 you should be aware that in some cases it be may unavoidable to have a
35692 complexity level of less than 10.
35693 For example if you have switch statement with more than 10 case labels,
35694 each case label adds one to the complexity level.
35695 The complexity level is by no means an absolute measure of the algorithmic
35696 complexity of the function, it does however provide a good starting point
35697 for which functions you might look at for further optimization.
35700 \begin_layout Section
35701 Retargetting for other Processors
35704 \begin_layout Standard
35705 The issues for retargetting the compiler are far too numerous to be covered
35707 What follows is a brief description of each of the seven phases of the
35708 compiler and its MCU dependency.
35711 \begin_layout Itemize
35712 Parsing the source and building the annotated parse tree.
35713 This phase is largely MCU independent (except for the language extensions).
35714 Syntax & semantic checks are also done in this phase, along with some initial
35715 optimizations like back patching labels and the pattern matching optimizations
35716 like bit-rotation etc.
35719 \begin_layout Itemize
35720 The second phase involves generating an intermediate code which can be easy
35721 manipulated during the later phases.
35722 This phase is entirely MCU independent.
35723 The intermediate code generation assumes the target machine has unlimited
35724 number of registers, and designates them with the name iTemp.
35725 The compiler can be made to dump a human readable form of the code generated
35730 \begin_layout Standard
35742 \begin_layout Itemize
35743 This phase does the bulk of the standard optimizations and is also MCU independe
35745 This phase can be broken down into several sub-phases:
35749 Break down intermediate
35750 code (iCode) into basic blocks.
35752 Do control flow & data flow analysis on the
35755 Do local common subexpression elimination, then global subexpressio
35758 Dead code elimination
35762 If loop optimizations
35763 caused any changes then do 'global subexpression elimination' and 'dead
35764 code elimination' again.
35767 \begin_layout Itemize
35768 This phase determines the live-ranges; by live range I mean those iTemp
35769 variables defined by the compiler that still survive after all the optimization
35771 Live range analysis
35772 \begin_inset LatexCommand \index{Live range analysis}
35776 is essential for register allocation, since these computation determines
35777 which of these iTemps will be assigned to registers, and for how long.
35780 \begin_layout Itemize
35781 Phase five is register allocation.
35782 There are two parts to this process.
35786 The first part I call 'register packing'
35787 (for lack of a better term).
35788 In this case several MCU specific expression folding is done to reduce
35793 The second part is more MCU independent and deals with
35794 allocating registers to the remaining live ranges.
35795 A lot of MCU specific code does creep into this phase because of the limited
35796 number of index registers available in the 8051.
35799 \begin_layout Itemize
35800 The Code generation phase is (unhappily), entirely MCU dependent and very
35801 little (if any at all) of this code can be reused for other MCU.
35802 However the scheme for allocating a homogenized assembler operand for each
35803 iCode operand may be reused.
35806 \begin_layout Itemize
35807 As mentioned in the optimization section the peep-hole optimizer is rule
35808 based system, which can reprogrammed for other MCUs.
35811 \begin_layout Standard
35812 More information is available in a wiki
35813 \begin_inset LatexCommand \index{wiki}
35818 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35822 ) and in the thread
35823 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35830 \begin_layout Chapter
35832 \begin_inset LatexCommand \index{Compiler internals}
35839 \begin_layout Section
35840 The anatomy of the compiler
35841 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35848 \begin_layout Standard
35851 This is an excerpt from an article published in Circuit Cellar Magazine
35857 It's a little outdated (the compiler is much more efficient now and user/develo
35858 per friendly), but pretty well exposes the guts of it all.
35864 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35865 It is fairly easy to retarget for other 8-bit MCU.
35866 Here we take a look at some of the internals of the compiler.
35870 \begin_layout Paragraph*
35872 \begin_inset LatexCommand \index{Parsing}
35879 \begin_layout Standard
35880 Parsing the input source file and creating an AST (Annotated Syntax Tree
35881 \begin_inset LatexCommand \index{Annotated syntax tree}
35886 This phase also involves propagating types (annotating each node of the
35887 parse tree with type information) and semantic analysis.
35888 There are some MCU specific parsing rules.
35889 For example the storage classes, the extended storage classes are MCU specific
35890 while there may be a xdata storage class for 8051 there is no such storage
35891 class for z80 or Atmel AVR.
35892 SDCC allows MCU specific storage class extensions, i.e.
35893 xdata will be treated as a storage class specifier when parsing 8051 C
35894 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35898 \begin_layout Paragraph*
35900 \begin_inset LatexCommand \index{iCode}
35907 \begin_layout Standard
35908 Intermediate code generation.
35909 In this phase the AST is broken down into three-operand form (iCode).
35910 These three operand forms are represented as doubly linked lists.
35911 ICode is the term given to the intermediate form generated by the compiler.
35912 ICode example section shows some examples of iCode generated for some simple
35913 C source functions.
35916 \begin_layout Paragraph*
35918 \begin_inset LatexCommand \index{Optimizations}
35925 \begin_layout Standard
35926 Bulk of the target independent optimizations is performed in this phase.
35927 The optimizations include constant propagation, common sub-expression eliminati
35928 on, loop invariant code movement, strength reduction of loop induction variables
35929 and dead-code elimination.
35932 \begin_layout Paragraph*
35933 Live range analysis
35934 \begin_inset LatexCommand \index{Live range analysis}
35941 \begin_layout Standard
35942 During intermediate code generation phase, the compiler assumes the target
35943 machine has infinite number of registers and generates a lot of temporary
35945 The live range computation determines the lifetime of each of these compiler-ge
35946 nerated temporaries.
35947 A picture speaks a thousand words.
35948 ICode example sections show the live range annotations for each of the
35950 It is important to note here, each iCode is assigned a number in the order
35951 of its execution in the function.
35952 The live ranges are computed in terms of these numbers.
35953 The from number is the number of the iCode which first defines the operand
35954 and the to number signifies the iCode which uses this operand last.
35957 \begin_layout Paragraph*
35958 Register Allocation
35959 \begin_inset LatexCommand \index{Register allocation}
35966 \begin_layout Standard
35967 The register allocation determines the type and number of registers needed
35969 In most MCUs only a few registers can be used for indirect addressing.
35970 In case of 8051 for example the registers R0 & R1 can be used to indirectly
35971 address the internal ram and DPTR to indirectly address the external ram.
35972 The compiler will try to allocate the appropriate register to pointer variables
35974 ICode example section shows the operands annotated with the registers assigned
35976 The compiler will try to keep operands in registers as much as possible;
35977 there are several schemes the compiler uses to do achieve this.
35978 When the compiler runs out of registers the compiler will check to see
35979 if there are any live operands which is not used or defined in the current
35980 basic block being processed, if there are any found then it will push that
35981 operand and use the registers in this block, the operand will then be popped
35982 at the end of the basic block.
35986 \begin_layout Standard
35987 There are other MCU specific considerations in this phase.
35988 Some MCUs have an accumulator; very short-lived operands could be assigned
35989 to the accumulator instead of a general-purpose register.
35992 \begin_layout Paragraph*
35996 \begin_layout Standard
35997 Figure II gives a table of iCode
35998 \begin_inset LatexCommand \index{iCode}
36002 operations supported by the compiler.
36003 The code generation involves translating these operations into corresponding
36004 assembly code for the processor.
36005 This sounds overly simple but that is the essence of code generation.
36006 Some of the iCode operations are generated on a MCU specific manner for
36007 example, the z80 port does not use registers to pass parameters so the
36008 SEND and RECV iCode operations will not be generated, and it also does
36009 not support JUMPTABLES.
36015 \begin_layout Standard
36019 \begin_inset Tabular
36020 <lyxtabular version="3" rows="39" columns="4">
36021 <features islongtable="true" headBottomDL="true">
36022 <column alignment="block" valignment="top" leftline="true" width="13col%">
36023 <column alignment="left" valignment="top" leftline="true" width="13col%">
36024 <column alignment="block" valignment="top" leftline="true" width="22col%">
36025 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36026 <row topline="true" bottomline="true" endhead="true">
36027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36030 \begin_layout Standard
36036 \begin_inset LatexCommand \index{iCode}
36045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36048 \begin_layout Standard
36056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36059 \begin_layout Standard
36067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36070 \begin_layout Standard
36079 <row topline="true">
36080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36083 \begin_layout Standard
36091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36094 \begin_layout Standard
36097 IC_LEFT() IC_RESULT()
36102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36105 \begin_layout Standard
36113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36116 \begin_layout Standard
36119 IC_RESULT = ! IC_LEFT;
36125 <row topline="true">
36126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36129 \begin_layout Standard
36137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36140 \begin_layout Standard
36143 IC_LEFT() IC_RESULT()
36148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36151 \begin_layout Standard
36154 Bitwise complement of
36159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36162 \begin_layout Standard
36165 IC_RESULT = ~IC_LEFT;
36171 <row topline="true">
36172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36175 \begin_layout Standard
36183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36186 \begin_layout Standard
36189 IC_LEFT() IC_RESULT()
36194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36197 \begin_layout Standard
36200 Rotate right with carry
36205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36208 \begin_layout Standard
36211 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36217 <row topline="true">
36218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36221 \begin_layout Standard
36229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36232 \begin_layout Standard
36235 IC_LEFT() IC_RESULT()
36240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36243 \begin_layout Standard
36246 Rotate left with carry
36251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36254 \begin_layout Standard
36257 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36263 <row topline="true">
36264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36267 \begin_layout Standard
36275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36278 \begin_layout Standard
36281 IC_LEFT() IC_RESULT()
36286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36289 \begin_layout Standard
36292 Get the highest order bit of IC_LEFT
36297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36300 \begin_layout Standard
36303 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36309 <row topline="true">
36310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36313 \begin_layout Standard
36321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36324 \begin_layout Standard
36327 IC_LEFT() IC_RESULT()
36332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36335 \begin_layout Standard
36343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36346 \begin_layout Standard
36349 IC_RESULT = - IC_LEFT;
36355 <row topline="true">
36356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36359 \begin_layout Standard
36367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36370 \begin_layout Standard
36378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36381 \begin_layout Standard
36384 Push the operand into stack
36389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36392 \begin_layout Standard
36401 <row topline="true">
36402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36405 \begin_layout Standard
36413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36416 \begin_layout Standard
36424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36427 \begin_layout Standard
36430 Pop the operand from the stack
36435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36438 \begin_layout Standard
36447 <row topline="true">
36448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36451 \begin_layout Standard
36459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36462 \begin_layout Standard
36465 IC_LEFT() IC_RESULT()
36470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36473 \begin_layout Standard
36476 Call the function represented by IC_LEFT
36481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36484 \begin_layout Standard
36487 IC_RESULT = IC_LEFT();
36493 <row topline="true">
36494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36497 \begin_layout Standard
36505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36508 \begin_layout Standard
36511 IC_LEFT() IC_RESULT()
36516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36519 \begin_layout Standard
36522 Call via function pointer
36527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36530 \begin_layout Standard
36533 IC_RESULT = (*IC_LEFT)();
36539 <row topline="true">
36540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36543 \begin_layout Standard
36551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36554 \begin_layout Standard
36562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36565 \begin_layout Standard
36568 Return the value in operand IC_LEFT
36573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36576 \begin_layout Standard
36585 <row topline="true">
36586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36589 \begin_layout Standard
36597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36600 \begin_layout Standard
36608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36611 \begin_layout Standard
36619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36622 \begin_layout Standard
36631 <row topline="true">
36632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36635 \begin_layout Standard
36643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36646 \begin_layout Standard
36654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36657 \begin_layout Standard
36665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36668 \begin_layout Standard
36677 <row topline="true">
36678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36681 \begin_layout Standard
36689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36692 \begin_layout Standard
36695 IC_LEFT() IC_RIGHT() IC_RESULT()
36700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36703 \begin_layout Standard
36711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36714 \begin_layout Standard
36717 IC_RESULT = IC_LEFT + IC_RIGHT
36723 <row topline="true">
36724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36727 \begin_layout Standard
36735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36738 \begin_layout Standard
36741 IC_LEFT() IC_RIGHT() IC_RESULT()
36746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36749 \begin_layout Standard
36757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36760 \begin_layout Standard
36763 IC_RESULT = IC_LEFT - IC_RIGHT
36769 <row topline="true">
36770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36773 \begin_layout Standard
36781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36784 \begin_layout Standard
36787 IC_LEFT() IC_RIGHT() IC_RESULT()
36792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36795 \begin_layout Standard
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36806 \begin_layout Standard
36809 IC_RESULT = IC_LEFT * IC_RIGHT;
36815 <row topline="true">
36816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36819 \begin_layout Standard
36827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36830 \begin_layout Standard
36833 IC_LEFT() IC_RIGHT() IC_RESULT()
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36841 \begin_layout Standard
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36852 \begin_layout Standard
36855 IC_RESULT = IC_LEFT / IC_RIGHT;
36861 <row topline="true">
36862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36865 \begin_layout Standard
36873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36876 \begin_layout Standard
36879 IC_LEFT() IC_RIGHT() IC_RESULT()
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36887 \begin_layout Standard
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36898 \begin_layout Standard
36901 IC_RESULT = IC_LEFT % IC_RIGHT;
36907 <row topline="true">
36908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36911 \begin_layout Standard
36919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36922 \begin_layout Standard
36925 IC_LEFT() IC_RIGHT() IC_RESULT()
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36933 \begin_layout Standard
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36944 \begin_layout Standard
36947 IC_RESULT = IC_LEFT < IC_RIGHT;
36953 <row topline="true">
36954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36957 \begin_layout Standard
36965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36968 \begin_layout Standard
36971 IC_LEFT() IC_RIGHT() IC_RESULT()
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36979 \begin_layout Standard
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36990 \begin_layout Standard
36993 IC_RESULT = IC_LEFT > IC_RIGHT;
36999 <row topline="true">
37000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37003 \begin_layout Standard
37011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37014 \begin_layout Standard
37017 IC_LEFT() IC_RIGHT() IC_RESULT()
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37025 \begin_layout Standard
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37036 \begin_layout Standard
37039 IC_RESULT = IC_LEFT == IC_RIGHT;
37045 <row topline="true">
37046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37049 \begin_layout Standard
37057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37060 \begin_layout Standard
37063 IC_LEFT() IC_RIGHT() IC_RESULT()
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37071 \begin_layout Standard
37074 Logical and operation
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37082 \begin_layout Standard
37085 IC_RESULT = IC_LEFT && IC_RIGHT;
37091 <row topline="true">
37092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37095 \begin_layout Standard
37103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37106 \begin_layout Standard
37109 IC_LEFT() IC_RIGHT() IC_RESULT()
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37117 \begin_layout Standard
37120 Logical or operation
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37128 \begin_layout Standard
37131 IC_RESULT = IC_LEFT || IC_RIGHT;
37137 <row topline="true">
37138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37141 \begin_layout Standard
37149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37152 \begin_layout Standard
37155 IC_LEFT() IC_RIGHT() IC_RESULT()
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37163 \begin_layout Standard
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37174 \begin_layout Standard
37177 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37183 <row topline="true">
37184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37187 \begin_layout Standard
37195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37198 \begin_layout Standard
37201 IC_LEFT() IC_RIGHT() IC_RESULT()
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37209 \begin_layout Standard
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37220 \begin_layout Standard
37223 IC_RESULT = IC_LEFT | IC_RIGHT;
37229 <row topline="true">
37230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37233 \begin_layout Standard
37241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37244 \begin_layout Standard
37247 IC_LEFT() IC_RIGHT() IC_RESULT()
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37255 \begin_layout Standard
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37266 \begin_layout Standard
37269 IC_RESULT = IC_LEFT & IC_RIGHT;
37275 <row topline="true">
37276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37279 \begin_layout Standard
37287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37290 \begin_layout Standard
37293 IC_LEFT() IC_RIGHT() IC_RESULT()
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37301 \begin_layout Standard
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37312 \begin_layout Standard
37315 IC_RESULT = IC_LEFT << IC_RIGHT
37321 <row topline="true">
37322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37325 \begin_layout Standard
37333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37336 \begin_layout Standard
37339 IC_LEFT() IC_RIGHT() IC_RESULT()
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37347 \begin_layout Standard
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37358 \begin_layout Standard
37361 IC_RESULT = IC_LEFT >> IC_RIGHT
37367 <row topline="true">
37368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37371 \begin_layout Standard
37381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37384 \begin_layout Standard
37387 IC_LEFT() IC_RESULT()
37392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37395 \begin_layout Standard
37403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37406 \begin_layout Standard
37409 IC_RESULT = (*IC_LEFT);
37415 <row topline="true">
37416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37419 \begin_layout Standard
37427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37430 \begin_layout Standard
37433 IC_RIGHT() IC_RESULT()
37438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37441 \begin_layout Standard
37449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37452 \begin_layout Standard
37455 (*IC_RESULT) = IC_RIGHT;
37461 <row topline="true">
37462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37465 \begin_layout Standard
37473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37476 \begin_layout Standard
37479 IC_RIGHT() IC_RESULT()
37484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37487 \begin_layout Standard
37495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37498 \begin_layout Standard
37501 IC_RESULT = IC_RIGHT;
37507 <row topline="true">
37508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37511 \begin_layout Standard
37519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37522 \begin_layout Standard
37525 IC_COND IC_TRUE IC_LABEL
37530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37533 \begin_layout Standard
37537 If true label is present then jump to true label if condition is true else
37538 jump to false label if condition is false
37543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37546 \begin_layout Standard
37549 if (IC_COND) goto IC_TRUE;
37555 If (!IC_COND) goto IC_FALSE;
37561 <row topline="true">
37562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37565 \begin_layout Standard
37573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37576 \begin_layout Standard
37579 IC_LEFT() IC_RESULT()
37584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37587 \begin_layout Standard
37595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37598 \begin_layout Standard
37601 IC_RESULT = &IC_LEFT();
37607 <row topline="true">
37608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37611 \begin_layout Standard
37619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37622 \begin_layout Standard
37625 IC_JTCOND IC_JTLABELS
37630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37633 \begin_layout Standard
37636 Jump to list of labels depending on the value of JTCOND
37641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37644 \begin_layout Standard
37653 <row topline="true">
37654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37657 \begin_layout Standard
37665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37668 \begin_layout Standard
37671 IC_RIGHT() IC_LEFT() IC_RESULT()
37676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37679 \begin_layout Standard
37687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37690 \begin_layout Standard
37693 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37699 <row topline="true">
37700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37703 \begin_layout Standard
37711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37714 \begin_layout Standard
37722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37725 \begin_layout Standard
37728 This is used for passing parameters in registers;
37730 move IC_LEFT to the next
37731 available parameter register.
37736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37739 \begin_layout Standard
37748 <row topline="true">
37749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37752 \begin_layout Standard
37760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37763 \begin_layout Standard
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37774 \begin_layout Standard
37777 This is used for receiving parameters passed in registers;
37780 in the next parameter register to IC_RESULT
37785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37788 \begin_layout Standard
37797 <row topline="true" bottomline="true">
37798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37801 \begin_layout Standard
37805 (some more have been added)
37810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37813 \begin_layout Standard
37819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37822 \begin_layout Standard
37828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37831 \begin_layout Standard
37855 \begin_layout Standard
37856 \begin_inset Note Note
37859 \begin_layout Standard
37860 In the original article Figure II was announced to be downloadable on
37865 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37873 \begin_layout Paragraph*
37875 \begin_inset LatexCommand \index{iCode}
37882 \begin_layout Standard
37883 This section shows some details of iCode.
37884 The example C code does not do anything useful; it is used as an example
37885 to illustrate the intermediate code generated by the compiler.
37888 \begin_layout Verse
37898 /* This function does nothing useful.
37905 for the purpose of explaining iCode */
37908 short function (data
37917 short i=10; \InsetSpace ~
37919 /* dead initialization eliminated */
37925 /* dead initialization eliminated */
37953 /* compiler detects i,j to be induction
37958 for (i = 0, j = 10 ; i < 10 ; i++, j
37964 \begin_layout Standard
37987 mul += i * 3; \InsetSpace ~
37989 /* this multiplication remains */
37996 j * 3;\InsetSpace ~
37998 /* this multiplication changed to addition */
38012 \begin_layout Standard
38013 In addition to the operands each iCode contains information about the filename
38014 and line it corresponds to in the source file.
38015 The first field in the listing should be interpreted as follows:
38020 Filename(linenumber: iCode Execution sequence number : ICode hash table
38021 key : loop depth of the iCode).
38026 Then follows the human readable form of the ICode operation.
38027 Each operand of this triplet form can be of three basic types a) compiler
38028 generated temporary b) user defined variable c) a constant value.
38029 Note that local variables and parameters are replaced by compiler generated
38032 \begin_inset LatexCommand \index{Live range analysis}
38036 are computed only for temporaries (i.e.
38037 live ranges are not computed for global variables).
38039 \begin_inset LatexCommand \index{Register allocation}
38043 are allocated for temporaries only.
38044 Operands are formatted in the following manner:
38049 Operand Name [lr live-from : live-to ] { type information } [ registers
38055 As mentioned earlier the live ranges are computed in terms of the execution
38056 sequence number of the iCodes, for example
38058 the iTemp0 is live from (i.e.
38059 first defined in iCode with execution sequence number 3, and is last used
38060 in the iCode with sequence number 5).
38061 For induction variables such as iTemp21 the live range computation extends
38062 the lifetime from the start to the end of the loop.
38064 The register allocator
38065 used the live range information to allocate registers, the same registers
38066 may be used for different temporaries if their live ranges do not overlap,
38067 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38068 ranges do not overlap.
38069 In addition the allocator also takes into consideration the type and usage
38070 of a temporary, for example itemp6 is a pointer to near space and is used
38071 as to fetch data from (i.e.
38072 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38073 Some short lived temporaries are allocated to special registers which have
38074 meaning to the code generator e.g.
38075 iTemp13 is allocated to a pseudo register CC which tells the back end that
38076 the temporary is used only for a conditional jump the code generation makes
38077 use of this information to optimize a compare and jump ICode.
38081 \begin_inset LatexCommand \index{Loop optimization}
38085 performed by the compiler.
38086 It can detect induction variables iTemp21(i) and iTemp23(j).
38087 Also note the compiler does selective strength reduction
38088 \begin_inset LatexCommand \index{Strength reduction}
38093 the multiplication of an induction variable in line 18 (gint = j * 3) is
38094 changed to addition, a new temporary iTemp17 is allocated and assigned
38095 a initial value, a constant 3 is then added for each iteration of the loop.
38096 The compiler does not change the multiplication
38097 \begin_inset LatexCommand \index{Multiplication}
38101 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38104 Note the dead code elimination
38105 \begin_inset LatexCommand \index{Dead-code elimination}
38109 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38115 \begin_layout Standard
38118 Sample.c (5:1:0:0) _entry($9) :
38121 \begin_layout Standard
38124 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38127 \begin_layout Standard
38130 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38133 \begin_layout Standard
38136 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38139 \begin_layout Standard
38142 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38146 \begin_layout Standard
38149 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38152 \begin_layout Standard
38155 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38159 \begin_layout Standard
38162 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38165 \begin_layout Standard
38168 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38172 \begin_layout Standard
38175 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38179 \begin_layout Standard
38182 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38186 \begin_layout Standard
38189 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38193 \begin_layout Standard
38196 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38197 * int}[r0] + 0x2 {short}
38200 \begin_layout Standard
38203 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38206 \begin_layout Standard
38209 Sample.c(11:17:21:0)_whilebreak_0($3) :
38212 \begin_layout Standard
38215 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38218 \begin_layout Standard
38221 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38224 \begin_layout Standard
38227 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38230 \begin_layout Standard
38233 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38236 \begin_layout Standard
38239 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38242 \begin_layout Standard
38245 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38248 \begin_layout Standard
38251 Sample.c(15:24:26:1)_forcond_0($4) :
38254 \begin_layout Standard
38257 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38261 \begin_layout Standard
38264 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38267 \begin_layout Standard
38270 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38271 + ITemp21 [lr21:38]{short}[r4]
38274 \begin_layout Standard
38277 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38281 \begin_layout Standard
38284 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38285 + iTemp15 [lr29:30]{short}[r1]
38288 \begin_layout Standard
38291 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38295 \begin_layout Standard
38298 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38302 \begin_layout Standard
38305 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38309 \begin_layout Standard
38312 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38316 \begin_layout Standard
38319 Sample.c(19:38:47:1) goto _forcond_0($4)
38322 \begin_layout Standard
38325 Sample.c(19:39:48:0)_forbreak_0($7) :
38328 \begin_layout Standard
38331 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38332 + ITemp11 [lr19:40]{short}[r3]
38335 \begin_layout Standard
38338 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38341 \begin_layout Standard
38344 Sample.c(20:42:51:0)_return($8) :
38347 \begin_layout Standard
38350 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38356 Finally the code generated for this function:
38361 \begin_layout Standard
38367 \begin_layout Standard
38373 \begin_layout Standard
38381 \begin_layout Standard
38387 \begin_layout Standard
38395 \begin_layout Standard
38401 \begin_layout Standard
38404 ; ----------------------------------------------
38407 \begin_layout Standard
38410 ; function function
38413 \begin_layout Standard
38416 ; ----------------------------------------------
38419 \begin_layout Standard
38425 \begin_layout Standard
38428 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38431 \begin_layout Standard
38439 \begin_layout Standard
38442 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38445 \begin_layout Standard
38453 \begin_layout Standard
38456 ;_whilecontinue_0($1) :
38459 \begin_layout Standard
38465 \begin_layout Standard
38468 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38471 \begin_layout Standard
38474 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38477 \begin_layout Standard
38485 \begin_layout Standard
38493 \begin_layout Standard
38501 \begin_layout Standard
38509 \begin_layout Standard
38517 \begin_layout Standard
38525 \begin_layout Standard
38533 \begin_layout Standard
38539 \begin_layout Standard
38542 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38545 \begin_layout Standard
38553 \begin_layout Standard
38561 \begin_layout Standard
38564 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38567 \begin_layout Standard
38575 \begin_layout Standard
38583 \begin_layout Standard
38591 \begin_layout Standard
38599 \begin_layout Standard
38607 \begin_layout Standard
38615 \begin_layout Standard
38618 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38621 \begin_layout Standard
38629 \begin_layout Standard
38637 \begin_layout Standard
38645 \begin_layout Standard
38653 \begin_layout Standard
38661 \begin_layout Standard
38664 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38667 \begin_layout Standard
38675 \begin_layout Standard
38683 \begin_layout Standard
38691 \begin_layout Standard
38694 ; iTemp6 [lr5:16]{_near * int}[r0] =
38697 \begin_layout Standard
38700 ; iTemp6 [lr5:16]{_near * int}[r0] +
38703 \begin_layout Standard
38709 \begin_layout Standard
38717 \begin_layout Standard
38720 ; goto _whilecontinue_0($1)
38723 \begin_layout Standard
38731 \begin_layout Standard
38734 ; _whilebreak_0($3) :
38737 \begin_layout Standard
38743 \begin_layout Standard
38746 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38749 \begin_layout Standard
38757 \begin_layout Standard
38760 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38763 \begin_layout Standard
38771 \begin_layout Standard
38774 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38777 \begin_layout Standard
38785 \begin_layout Standard
38788 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38791 \begin_layout Standard
38799 \begin_layout Standard
38807 \begin_layout Standard
38810 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38813 \begin_layout Standard
38821 \begin_layout Standard
38829 \begin_layout Standard
38835 \begin_layout Standard
38841 \begin_layout Standard
38844 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38847 \begin_layout Standard
38850 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38853 \begin_layout Standard
38861 \begin_layout Standard
38869 \begin_layout Standard
38877 \begin_layout Standard
38885 \begin_layout Standard
38893 \begin_layout Standard
38899 \begin_layout Standard
38902 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38905 \begin_layout Standard
38908 ; iTemp21 [lr21:38]{short}[r4]
38911 \begin_layout Standard
38919 \begin_layout Standard
38927 \begin_layout Standard
38935 \begin_layout Standard
38938 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38941 \begin_layout Standard
38949 \begin_layout Standard
38957 \begin_layout Standard
38965 \begin_layout Standard
38973 \begin_layout Standard
38976 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
38979 \begin_layout Standard
38982 ; iTemp15 [lr29:30]{short}[r1]
38985 \begin_layout Standard
38993 \begin_layout Standard
39001 \begin_layout Standard
39004 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39007 \begin_layout Standard
39015 \begin_layout Standard
39023 \begin_layout Standard
39031 \begin_layout Standard
39039 \begin_layout Standard
39047 \begin_layout Standard
39055 \begin_layout Standard
39058 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39061 \begin_layout Standard
39069 \begin_layout Standard
39077 \begin_layout Standard
39085 \begin_layout Standard
39093 \begin_layout Standard
39101 \begin_layout Standard
39109 \begin_layout Standard
39112 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39115 \begin_layout Standard
39123 \begin_layout Standard
39126 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39129 \begin_layout Standard
39137 \begin_layout Standard
39142 cjne r5,#0xff,00104$
39145 \begin_layout Standard
39153 \begin_layout Standard
39156 ; goto _forcond_0($4)
39159 \begin_layout Standard
39167 \begin_layout Standard
39170 ; _forbreak_0($7) :
39173 \begin_layout Standard
39179 \begin_layout Standard
39182 ; ret iTemp24 [lr40:41]{short}
39185 \begin_layout Standard
39193 \begin_layout Standard
39201 \begin_layout Standard
39209 \begin_layout Standard
39215 \begin_layout Standard
39221 \begin_layout Standard
39231 \begin_layout Section
39232 A few words about basic block successors, predecessors and dominators
39235 \begin_layout Standard
39236 Successors are basic blocks
39237 \begin_inset LatexCommand \index{Basic blocks}
39241 that might execute after this basic block.
39243 Predecessors are basic blocks
39244 that might execute before reaching this basic block.
39246 Dominators are basic
39247 blocks that WILL execute before reaching this basic block.
39252 \begin_layout Standard
39256 \begin_layout Standard
39260 \begin_layout Standard
39268 \begin_layout Standard
39272 \begin_layout Standard
39280 \begin_layout Standard
39286 \begin_layout Standard
39287 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39290 \begin_layout Standard
39291 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39294 \begin_layout Standard
39295 c) domVect of [BB4] = BB1 ...
39296 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39300 \begin_layout Chapter
39304 \begin_layout Standard
39305 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39315 Thanks to all the other volunteer developers who have helped with coding,
39316 testing, web-page creation, distribution sets, etc.
39317 You know who you are :-)
39325 Also thanks to Sourceforge
39326 \begin_inset LatexCommand \url{http://www.sf.net}
39330 which has hosted the project since 1999 and donates significant download
39331 bandwidth and probably more than
39335 \begin_layout Standard
39342 CPU cycles per day.
39345 \begin_inset Note Note
39348 \begin_layout Standard
39349 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39350 minutes for (configure+make+regression test), and there is (i386, amd64,
39351 alpha, ppc64, (mingw32), sparc, macosx).
39360 \begin_layout Standard
39361 This document was initially written by Sandeep Dutta
39364 \begin_layout Standard
39365 All product names mentioned herein may be trademarks
39366 \begin_inset LatexCommand \index{Trademarks}
39370 of their respective companies.
39374 \begin_layout Section*
39378 \begin_layout Standard
39379 To avoid confusion, the installation and building options for SDCC itself
39380 (chapter 2) are not part of the index.
39383 \begin_layout Standard
39384 \begin_inset LatexCommand \printindex{}