1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is 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 C99 standard!
6969 \labelwidthstring 00.00.0000
6973 preprocessorOption[,preprocessorOption]
6976 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6981 Pass the preprocessorOption to the preprocessor
6986 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6991 SDCC uses an adapted version of the preprocessor
6995 of the GNU Compiler Collection
6996 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7005 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7009 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7014 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7021 \begin_layout Standard
7022 \begin_inset VSpace bigskip
7028 \begin_layout Subsection
7030 \begin_inset LatexCommand \index{Options linker}
7035 \begin_inset LatexCommand \index{Linker options}
7043 \labelwidthstring 00.00.0000
7053 \begin_layout Standard
7065 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7070 \begin_inset LatexCommand \index{-L -\/-lib-path}
7077 <absolute path to additional libraries> This option is passed to the linkage
7078 editor's additional libraries
7079 \begin_inset LatexCommand \index{Libraries}
7084 The path name must be absolute.
7085 Additional library files may be specified in the command line.
7086 See section Compiling programs for more details.
7090 \labelwidthstring 00.00.0000
7097 \begin_layout Standard
7109 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7114 <Value> The start location of the external ram
7115 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7119 , default value is 0.
7120 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7124 \begin_layout Standard
7133 -xram-loc 0x8000 or -
7137 \begin_layout Standard
7150 \labelwidthstring 00.00.0000
7157 \begin_layout Standard
7169 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7174 <Value> The start location of the code
7175 \begin_inset LatexCommand \index{code}
7179 segment, default value 0.
7180 Note when this option is used the interrupt vector table
7181 \begin_inset LatexCommand \index{interrupt vector table}
7185 is also relocated to the given address.
7186 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7190 \begin_layout Standard
7199 -code-loc 0x8000 or -
7203 \begin_layout Standard
7216 \labelwidthstring 00.00.0000
7223 \begin_layout Standard
7235 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7240 <Value> By default the stack
7241 \begin_inset LatexCommand \index{stack}
7245 is placed after the data segment.
7246 Using this option the stack can be placed anywhere in the internal memory
7248 The value entered can be in Hexadecimal or Decimal format, e.g.
7253 \begin_layout Standard
7262 -stack-loc 0x20 or -
7266 \begin_layout Standard
7276 Since the sp register is incremented before a push or call, the initial
7277 sp will be set to one byte prior the provided value.
7278 The provided value should not overlap any other memory areas such as used
7279 register banks or the data segment and with enough space for the current
7287 \begin_layout Standard
7300 \begin_inset LatexCommand \index{-\/-pack-iram}
7304 option (which is now a default setting) will override this setting, so
7305 you should also specify the
7311 \begin_layout Standard
7324 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7328 option if you need to manually place the stack.
7332 \labelwidthstring 00.00.0000
7339 \begin_layout Standard
7351 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7356 <Value> By default the external stack
7357 \begin_inset LatexCommand \index{xstack}
7361 is placed after the pdata
7362 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7367 Using this option the xstack can be placed anywhere in the external memory
7369 The value entered can be in Hexadecimal or Decimal format, e.g.
7374 \begin_layout Standard
7383 -xstack-loc 0x8000 or -
7387 \begin_layout Standard
7397 The provided value should not overlap any other memory areas such as the
7398 pdata or xdata segment and with enough space for the current application.
7402 \labelwidthstring 00.00.0000
7409 \begin_layout Standard
7421 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7426 <Value> The start location of the internal ram data
7427 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7432 The value entered can be in Hexadecimal or Decimal format, eg.
7437 \begin_layout Standard
7450 \begin_layout Standard
7460 (By default, the start location of the internal ram data segment is set
7461 as low as possible in memory, taking into account the used register banks
7462 and the bit segment at address 0x20.
7463 For example if register banks 0 and 1 are used without bit variables, the
7464 data segment will be set, if -
7468 \begin_layout Standard
7477 -data-loc is not used, to location 0x10.)
7481 \labelwidthstring 00.00.0000
7488 \begin_layout Standard
7500 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7505 <Value> The start location of the indirectly addressable internal ram
7506 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7510 of the 8051, default value is 0x80.
7511 The value entered can be in Hexadecimal or Decimal format, eg.
7516 \begin_layout Standard
7525 -idata-loc 0x88 or -
7529 \begin_layout Standard
7542 \labelwidthstring 00.00.0000
7549 \begin_layout Standard
7561 <Value> The start location of the bit
7562 \begin_inset LatexCommand \index{bit}
7566 addressable internal ram of the 8051.
7572 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7577 \labelwidthstring 00.00.0000
7584 \begin_layout Standard
7594 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7603 The linker output (final object code) is in Intel Hex format.
7604 \begin_inset LatexCommand \index{Intel hex format}
7608 This is the default option.
7609 The format itself is documented in the documentation of srecord
7610 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7618 \labelwidthstring 00.00.0000
7625 \begin_layout Standard
7635 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7644 The linker output (final object code) is in Motorola S19 format
7645 \begin_inset LatexCommand \index{Motorola S19 format}
7650 The format itself is documented in the documentation of srecord.
7654 \labelwidthstring 00.00.0000
7661 \begin_layout Standard
7671 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7676 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7685 The linker output (final object code) is in ELF format
7686 \begin_inset LatexCommand \index{ELF format}
7691 (Currently only supported for the HC08
7692 \begin_inset LatexCommand \index{HC08}
7700 \labelwidthstring 00.00.0000
7704 linkOption[,linkOption]
7707 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7712 Pass the linkOption to the linker.
7713 If a bootloader is used an option like
7714 \begin_inset Quotes sld
7719 \begin_inset Quotes srd
7722 would be typical to set the start of the code segment.
7723 See also #pragma constseg and #pragma codeseg in section
7724 \begin_inset LatexCommand \ref{sec:Pragmas}
7729 File sdcc/as/doc/asxhtm.html has more on linker options.
7732 \begin_layout Standard
7733 \begin_inset VSpace bigskip
7739 \begin_layout Subsection
7741 \begin_inset LatexCommand \index{Options MCS51}
7746 \begin_inset LatexCommand \index{MCS51 options}
7754 \labelwidthstring 00.00.0000
7761 \begin_layout Standard
7771 \begin_inset LatexCommand \index{-\/-model-small}
7782 Generate code for Small Model programs, see section Memory Models for more
7784 This is the default model.
7788 \labelwidthstring 00.00.0000
7795 \begin_layout Standard
7805 \begin_inset LatexCommand \index{-\/-model-medium}
7811 Generate code for Medium model programs, see section Memory Models for
7813 If this option is used all source files in the project have to be compiled
7815 It must also be used when invoking the linker.
7819 \labelwidthstring 00.00.0000
7826 \begin_layout Standard
7836 \begin_inset LatexCommand \index{-\/-model-large}
7842 Generate code for Large model programs, see section Memory Models for more
7844 If this option is used all source files in the project have to be compiled
7846 It must also be used when invoking the linker.
7850 \labelwidthstring 00.00.0000
7857 \begin_layout Standard
7867 \begin_inset LatexCommand \index{-\/-xstack}
7873 Uses a pseudo stack in the pdata
7874 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7878 area (usually the first 256 bytes in the external ram) for allocating variables
7879 and passing parameters.
7881 \begin_inset LatexCommand \ref{sub:External-Stack}
7886 External Stack for more details.
7890 \labelwidthstring 00.00.0000
7897 \begin_layout Standard
7910 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7914 Causes the linker to check if the internal ram usage is within limits of
7919 \labelwidthstring 00.00.0000
7926 \begin_layout Standard
7939 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7943 Causes the linker to check if the external ram usage is within limits of
7948 \labelwidthstring 00.00.0000
7955 \begin_layout Standard
7968 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7972 Causes the linker to check if the code memory usage is within limits of
7977 \labelwidthstring 00.00.0000
7984 \begin_layout Standard
7997 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8001 Causes the linker to check if there is at minimum <Value> bytes for stack.
8005 \labelwidthstring 00.00.0000
8012 \begin_layout Standard
8025 \begin_inset LatexCommand \index{-\/-pack-iram}
8029 Causes the linker to use unused register banks for data variables and pack
8030 data, idata and stack together.
8031 This is the default now.
8035 \labelwidthstring 00.00.0000
8042 \begin_layout Standard
8055 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8059 Causes the linker to use old style for allocating memory areas.
8062 \begin_layout Standard
8063 \begin_inset VSpace bigskip
8069 \begin_layout Subsection
8070 DS390 / DS400 Options
8071 \begin_inset LatexCommand \index{Options DS390}
8076 \begin_inset LatexCommand \index{DS390}
8084 \labelwidthstring 00.00.0000
8091 \begin_layout Standard
8103 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8113 Generate 24-bit flat mode code.
8114 This is the one and only that the ds390 code generator supports right now
8115 and is default when using
8120 See section Memory Models for more details.
8124 \labelwidthstring 00.00.0000
8131 \begin_layout Standard
8141 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8147 disable interrupts during ESP:SP updates.
8151 \labelwidthstring 00.00.0000
8158 \begin_layout Standard
8170 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8174 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8175 This is the one and only that the ds390 code generator supports right now
8176 and is default when using
8181 In this mode, the stack is located in the lower 1K of the internal RAM,
8182 which is mapped to 0x400000.
8183 Note that the support is incomplete, since it still uses a single byte
8184 as the stack pointer.
8185 This means that only the lower 256 bytes of the potential 1K stack space
8186 will actually be used.
8187 However, this does allow you to reclaim the precious 256 bytes of low RAM
8188 for use for the DATA and IDATA segments.
8189 The compiler will not generate any code to put the processor into 10 bit
8191 It is important to ensure that the processor is in this mode before calling
8192 any re-entrant functions compiled with this option.
8193 In principle, this should work with the
8199 \begin_layout Standard
8209 \begin_inset LatexCommand \index{-\/-stack-auto}
8215 option, but that has not been tested.
8216 It is incompatible with the
8222 \begin_layout Standard
8232 \begin_inset LatexCommand \index{-\/-xstack}
8239 It also only makes sense if the processor is in 24 bit contiguous addressing
8246 \begin_layout Standard
8255 -model-flat24 option
8260 \begin_inset Note Note
8264 \labelwidthstring 00.00.0000
8267 --stack-8-bit - switches off the 10-bit mode
8276 \labelwidthstring 00.00.0000
8283 \begin_layout Standard
8293 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8299 insert call to function __stack_probe at each function prologue.
8303 \labelwidthstring 00.00.0000
8310 \begin_layout Standard
8320 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8326 <nnnn> LibraryID used in -mTININative.
8331 \labelwidthstring 00.00.0000
8338 \begin_layout Standard
8348 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8354 generate code for DS390 Arithmetic Accelerator.
8358 \begin_layout Standard
8359 \begin_inset VSpace bigskip
8365 \begin_layout Subsection
8367 \begin_inset LatexCommand \index{Options Z80}
8372 \begin_inset LatexCommand \index{Z80}
8380 \labelwidthstring 00.00.0000
8387 \begin_layout Standard
8399 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8409 Force a called function to always save BC.
8413 \labelwidthstring 00.00.0000
8420 \begin_layout Standard
8432 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8436 When linking, skip the standard crt0.o object file.
8437 You must provide your own crt0.o for your system when linking.
8441 \begin_layout Standard
8442 \begin_inset VSpace bigskip
8448 \begin_layout Subsection
8449 Optimization Options
8450 \begin_inset LatexCommand \index{Options optimization}
8455 \begin_inset LatexCommand \index{Optimization options}
8463 \labelwidthstring 00.00.0000
8470 \begin_layout Standard
8480 \begin_inset LatexCommand \index{-\/-nogcse}
8486 Will not do global subexpression elimination, this option may be used when
8487 the compiler creates undesirably large stack/data spaces to store compiler
8497 \begin_inset LatexCommand \index{sloc (spill location)}
8502 A warning message will be generated when this happens and the compiler
8503 will indicate the number of extra bytes it allocated.
8504 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8506 \begin_inset LatexCommand \index{\#pragma nogcse}
8510 can be used to turn off global subexpression elimination
8511 \begin_inset LatexCommand \index{Subexpression elimination}
8515 for a given function only.
8519 \labelwidthstring 00.00.0000
8526 \begin_layout Standard
8536 \begin_inset LatexCommand \index{-\/-noinvariant}
8542 Will not do loop invariant optimizations, this may be turned off for reasons
8543 explained for the previous option.
8544 For more details of loop optimizations performed see Loop Invariants in
8546 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8551 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8553 \begin_inset LatexCommand \index{\#pragma noinvariant}
8557 can be used to turn off invariant optimizations for a given function only.
8561 \labelwidthstring 00.00.0000
8568 \begin_layout Standard
8578 \begin_inset LatexCommand \index{-\/-noinduction}
8584 Will not do loop induction optimizations, see section strength reduction
8586 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8588 \begin_inset LatexCommand \index{\#pragma noinduction}
8592 can be used to turn off induction optimizations for a given function only.
8596 \labelwidthstring 00.00.0000
8603 \begin_layout Standard
8613 \begin_inset LatexCommand \index{-\/-nojtbound}
8624 Will not generate boundary condition check when switch statements
8625 \begin_inset LatexCommand \index{switch statement}
8629 are implemented using jump-tables.
8631 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8636 Switch Statements for more details.
8637 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8639 \begin_inset LatexCommand \index{\#pragma nojtbound}
8643 can be used to turn off boundary checking for jump tables for a given function
8648 \labelwidthstring 00.00.0000
8655 \begin_layout Standard
8665 \begin_inset LatexCommand \index{-\/-noloopreverse}
8674 Will not do loop reversal
8675 \begin_inset LatexCommand \index{Loop reversing}
8683 \labelwidthstring 00.00.0000
8688 \begin_layout Standard
8702 \begin_inset LatexCommand \index{-\/-nolabelopt }
8706 Will not optimize labels (makes the dumpfiles more readable).
8710 \labelwidthstring 00.00.0000
8717 \begin_layout Standard
8727 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8733 Will not memcpy initialized data from code space into xdata space.
8734 This saves a few bytes in code space if you don't have initialized data
8735 \begin_inset LatexCommand \index{Variable initialization}
8743 \labelwidthstring 00.00.0000
8750 \begin_layout Standard
8760 \begin_inset LatexCommand \index{-\/-nooverlay}
8766 The compiler will not overlay parameters and local variables of any function,
8767 see section Parameters and local variables for more details.
8771 \labelwidthstring 00.00.0000
8778 \begin_layout Standard
8788 \begin_inset LatexCommand \index{-\/-no-peep}
8794 Disable peep-hole optimization with built-in rules.
8798 \labelwidthstring 00.00.0000
8805 \begin_layout Standard
8817 \begin_inset LatexCommand \index{-\/-peep-file}
8822 <filename> This option can be used to use additional rules to be used by
8823 the peep hole optimizer.
8825 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8830 Peep Hole optimizations for details on how to write these rules.
8834 \labelwidthstring 00.00.0000
8841 \begin_layout Standard
8851 \begin_inset LatexCommand \index{-\/-peep-asm}
8857 Pass the inline assembler code through the peep hole optimizer.
8858 This can cause unexpected changes to inline assembler code, please go through
8859 the peephole optimizer
8860 \begin_inset LatexCommand \index{Peephole optimizer}
8864 rules defined in the source file tree '<target>/peeph.def' before using
8869 \labelwidthstring 00.00.0000
8876 \begin_layout Standard
8886 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8892 The compiler will optimize code generation towards fast code, possibly
8893 at the expense of code size.
8897 \labelwidthstring 00.00.0000
8904 \begin_layout Standard
8914 \begin_inset LatexCommand \index{-\/-opt-code-size}
8920 The compiler will optimize code generation towards compact code, possibly
8921 at the expense of code speed.
8924 \begin_layout Standard
8925 \begin_inset VSpace bigskip
8931 \begin_layout Subsection
8933 \begin_inset LatexCommand \index{Options other}
8941 \labelwidthstring 00.00.0000
8949 \begin_layout Standard
8959 \begin_inset LatexCommand \index{-\/-compile-only}
8964 \begin_inset LatexCommand \index{-c -\/-compile-only}
8970 will compile and assemble the source, but will not call the linkage editor.
8974 \labelwidthstring 00.00.0000
8983 \begin_layout Standard
8995 \begin_inset LatexCommand \index{-\/-c1mode}
9001 reads the preprocessed source from standard input and compiles it.
9002 The file name for the assembler output must be specified using the -o option.
9006 \labelwidthstring 00.00.0000
9010 \begin_inset LatexCommand \index{-E}
9016 Run only the C preprocessor.
9017 Preprocess all the C source files specified and output the results to standard
9022 \labelwidthstring 00.00.0000
9027 \begin_inset LatexCommand \index{-o <path/file>}
9033 The output path resp.
9034 file where everything will be placed.
9035 If the parameter is a path, it must have a trailing slash (or backslash
9036 for the Windows binaries) to be recognized as a path.
9041 \labelwidthstring 00.00.0000
9048 \begin_layout Standard
9058 \begin_inset LatexCommand \index{-\/-stack-auto}
9069 All functions in the source file will be compiled as
9074 \begin_inset LatexCommand \index{reentrant}
9079 the parameters and local variables will be allocated on the stack
9080 \begin_inset LatexCommand \index{stack}
9086 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9090 Parameters and Local Variables for more details.
9091 If this option is used all source files in the project should be compiled
9093 It automatically implies --int-long-reent and --float-reent.
9098 \labelwidthstring 00.00.0000
9105 \begin_layout Standard
9115 \begin_inset LatexCommand \index{-\/-callee-saves}
9120 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9124 function1[,function2][,function3]....
9127 The compiler by default uses a caller saves convention for register saving
9128 across function calls, however this can cause unnecessary register pushing
9129 and popping when calling small functions from larger functions.
9130 This option can be used to switch the register saving convention for the
9131 function names specified.
9132 The compiler will not save registers when calling these functions, no extra
9133 code will be generated at the entry and exit (function prologue
9136 \begin_inset LatexCommand \index{function prologue}
9145 \begin_inset LatexCommand \index{function epilogue}
9151 ) for these functions to save and restore the registers used by these functions,
9152 this can SUBSTANTIALLY reduce code and improve run time performance of
9154 In the future the compiler (with inter procedural analysis) will be able
9155 to determine the appropriate scheme to use for each function call.
9156 DO NOT use this option for built-in functions such as _mulint..., if this
9157 option is used for a library function the appropriate library function
9158 needs to be recompiled with the same option.
9159 If the project consists of multiple source files then all the source file
9160 should be compiled with the same -
9164 \begin_layout Standard
9173 -callee-saves option string.
9174 Also see #pragma\InsetSpace ~
9176 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9181 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9189 \labelwidthstring 00.00.0000
9196 \begin_layout Standard
9206 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9220 \begin_layout Standard
9229 -callee-saves will be applied to all functions by default.
9233 \labelwidthstring 00.00.0000
9240 \begin_layout Standard
9250 \begin_inset LatexCommand \index{-\/-debug}
9259 When this option is used the compiler will generate debug information.
9260 The debug information collected in a file with .cdb extension can be used
9262 For more information see documentation for SDCDB.
9263 Another file with no extension contains debug information in AOMF or AOMF51
9264 \begin_inset LatexCommand \index{AOMF, AOMF51}
9268 format which is commonly used by third party tools.
9272 \labelwidthstring 00.00.0000
9276 \begin_inset LatexCommand \index{-S}
9287 Stop after the stage of compilation proper; do not assemble.
9288 The output is an assembler code file for the input file specified.
9292 \labelwidthstring 00.00.0000
9299 \begin_layout Standard
9309 \begin_inset LatexCommand \index{-\/-int-long-reent}
9315 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9316 Note by default these libraries are compiled as non-reentrant.
9317 See section Installation for more details.
9321 \labelwidthstring 00.00.0000
9328 \begin_layout Standard
9338 \begin_inset LatexCommand \index{-\/-cyclomatic}
9347 This option will cause the compiler to generate an information message for
9348 each function in the source file.
9349 The message contains some
9353 information about the function.
9354 The number of edges and nodes the compiler detected in the control flow
9355 graph of the function, and most importantly the
9357 cyclomatic complexity
9358 \begin_inset LatexCommand \index{Cyclomatic complexity}
9364 see section on Cyclomatic Complexity for more details.
9368 \labelwidthstring 00.00.0000
9375 \begin_layout Standard
9385 \begin_inset LatexCommand \index{-\/-float-reent}
9391 Floating point library is compiled as reentrant
9392 \begin_inset LatexCommand \index{reentrant}
9397 See section Installation for more details.
9401 \labelwidthstring 00.00.0000
9408 \begin_layout Standard
9418 \begin_inset LatexCommand \index{-\/-funsigned-char}
9424 The default signedness for every type is
9429 In some embedded environments the default signedness of
9438 To set the signess for characters to unsigned, use the option --funsigned-char.
9439 If this option is set and no signedness keyword (unsigned/signed) is given,
9440 a char will be signed.
9441 All other types are unaffected.
9445 \labelwidthstring 00.00.0000
9452 \begin_layout Standard
9462 \begin_inset LatexCommand \index{-\/-main-return}
9468 This option can be used if the code generated is called by a monitor program
9469 or if the main routine includes an endless loop.
9470 This option results in slightly smaller code and saves two bytes of stack
9472 The return from the 'main'
9473 \begin_inset LatexCommand \index{main return}
9477 function will return to the function calling main.
9478 The default setting is to lock up i.e.
9487 \labelwidthstring 00.00.0000
9494 \begin_layout Standard
9504 \begin_inset LatexCommand \index{-\/-nostdinc}
9510 This will prevent the compiler from passing on the default include path
9511 to the preprocessor.
9515 \labelwidthstring 00.00.0000
9522 \begin_layout Standard
9532 \begin_inset LatexCommand \index{-\/-nostdlib}
9538 This will prevent the compiler from passing on the default library
9539 \begin_inset LatexCommand \index{Libraries}
9547 \labelwidthstring 00.00.0000
9554 \begin_layout Standard
9564 \begin_inset LatexCommand \index{-\/-verbose}
9570 Shows the various actions the compiler is performing.
9574 \labelwidthstring 00.00.0000
9578 \begin_inset LatexCommand \index{-V}
9584 Shows the actual commands the compiler is executing.
9588 \labelwidthstring 00.00.0000
9595 \begin_layout Standard
9605 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9611 Hides your ugly and inefficient c-code from the asm file, so you can always
9612 blame the compiler :)
9616 \labelwidthstring 00.00.0000
9623 \begin_layout Standard
9633 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9639 Will not include peep-hole comments in the generated files.
9643 \labelwidthstring 00.00.0000
9650 \begin_layout Standard
9660 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9666 Will not include code generator comments in the generated files.
9670 \labelwidthstring 00.00.0000
9677 \begin_layout Standard
9687 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9693 Include i-codes in the asm file.
9694 Sounds like noise but is most helpful for debugging the compiler itself.
9698 \labelwidthstring 00.00.0000
9705 \begin_layout Standard
9715 \begin_inset LatexCommand \index{pedantic}
9720 \begin_inset LatexCommand \index{-\/-less-pedantic}
9727 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9731 Disable some of the more pedantic warnings
9732 \begin_inset LatexCommand \index{Warnings}
9737 For more details, see the less_pedantic pragma
9738 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9746 \labelwidthstring 00.00.0000
9753 \begin_layout Standard
9762 -disable-warning\InsetSpace ~
9764 \begin_inset LatexCommand \index{-\/-disable-warning}
9770 Disable specific warning with number <nnnn>.
9774 \labelwidthstring 00.00.0000
9781 \begin_layout Standard
9791 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9797 Display the directories in the compiler's search path
9801 \labelwidthstring 00.00.0000
9808 \begin_layout Standard
9818 \begin_inset LatexCommand \index{-\/-vc}
9824 Display errors and warnings using MSVC style, so you can use SDCC with
9825 the visual studio IDE
9826 \begin_inset LatexCommand \index{IDE}
9831 With SDCC both offering a GCC-like (the default) and a MSVC-like
9832 \begin_inset LatexCommand \index{MSVC output style}
9836 output style, integration into most programming editors should be straightforwa
9841 \labelwidthstring 00.00.0000
9848 \begin_layout Standard
9858 \begin_inset LatexCommand \index{-\/-use-stdout}
9864 Send errors and warnings to stdout instead of stderr.
9868 \labelwidthstring 00.00.0000
9872 asmOption[,asmOption]
9875 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9880 Pass the asmOption to the assembler
9881 \begin_inset LatexCommand \index{Options assembler}
9886 \begin_inset LatexCommand \index{Assembler options}
9891 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9895 \labelwidthstring 00.00.0000
9902 \begin_layout Standard
9912 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9918 Generally follow the C89 standard, but allow SDCC features that conflict
9919 with the standard (default).
9923 \labelwidthstring 00.00.0000
9930 \begin_layout Standard
9940 \begin_inset LatexCommand \index{-\/-std-c89}
9946 Follow the C89 standard and disable SDCC features that conflict with the
9951 \labelwidthstring 00.00.0000
9958 \begin_layout Standard
9968 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9974 Generally follow the C99 standard, but allow SDCC features that conflict
9975 with the standard (incomplete support).
9979 \labelwidthstring 00.00.0000
9986 \begin_layout Standard
9996 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10002 Follow the C99 standard and disable SDCC features that conflict with the
10003 standard (incomplete support).
10007 \labelwidthstring 00.00.0000
10014 \begin_layout Standard
10026 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10031 <Name> The name to be used for the code
10032 \begin_inset LatexCommand \index{code}
10036 segment, default CSEG.
10037 This is useful if you need to tell the compiler to put the code in a special
10038 segment so you can later on tell the linker to put this segment in a special
10040 Can be used for instance when using bank switching to put the code in a
10045 \labelwidthstring 00.00.0000
10052 \begin_layout Standard
10064 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10069 <Name> The name to be used for the const
10070 \begin_inset LatexCommand \index{code}
10074 segment, default CONST.
10075 This is useful if you need to tell the compiler to put the const data in
10076 a special segment so you can later on tell the linker to put this segment
10077 in a special place in memory.
10078 Can be used for instance when using bank switching to put the const data
10083 \labelwidthstring 00.00.0000
10090 \begin_layout Standard
10099 -fdollars-in-identifiers
10100 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10106 Permit '$' as an identifier character.
10110 \labelwidthstring 00.00.0000
10117 \begin_layout Standard
10129 \begin_inset LatexCommand \index{-\/-more-pedantic}
10134 \begin_inset LatexCommand \index{pedantic}
10144 a SDCC compiler option but if you want
10148 warnings you can use a separate tool dedicated to syntax checking like
10150 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10155 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10160 \begin_inset LatexCommand \url{http://www.splint.org}
10165 To make your source files parseable by splint you will have to include
10171 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10175 in your source file and add brackets around extended keywords (like
10178 \begin_inset Quotes sld
10191 \begin_inset Quotes srd
10199 \begin_inset Quotes sld
10202 __interrupt\InsetSpace ~
10204 \begin_inset Quotes srd
10212 Splint has an excellent on line manual at
10213 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10217 and it's capabilities go beyond pure syntax checking.
10218 You'll need to tell splint the location of SDCC's include files so a typical
10219 command line could look like this:
10223 splint\InsetSpace ~
10225 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10231 \labelwidthstring 00.00.0000
10238 \begin_layout Standard
10250 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10255 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10259 Treat short as 8-bit (for backward compatibility with older versions of
10260 compiler - see section
10261 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10268 \begin_layout Standard
10269 \begin_inset VSpace bigskip
10275 \begin_layout Subsection
10276 Intermediate Dump Options
10277 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10282 \begin_inset LatexCommand \index{Options intermediate dump}
10287 \begin_inset LatexCommand \index{Intermediate dump options}
10294 \begin_layout Standard
10295 The following options are provided for the purpose of retargetting and debugging
10297 They provide a means to dump the intermediate code (iCode
10298 \begin_inset LatexCommand \index{iCode}
10302 ) generated by the compiler in human readable form at various stages of
10303 the compilation process.
10304 More on iCodes see chapter
10305 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10310 \begin_inset Quotes srd
10313 The anatomy of the compiler
10314 \begin_inset Quotes srd
10321 \labelwidthstring 00.00.0000
10328 \begin_layout Standard
10338 \begin_inset LatexCommand \index{-\/-dumpraw}
10344 This option will cause the compiler to dump the intermediate code into
10347 <source filename>.dumpraw
10349 just after the intermediate code has been generated for a function, i.e.
10350 before any optimizations are done.
10352 \begin_inset LatexCommand \index{Basic blocks}
10356 at this stage ordered in the depth first number, so they may not be in
10357 sequence of execution.
10361 \labelwidthstring 00.00.0000
10368 \begin_layout Standard
10378 \begin_inset LatexCommand \index{-\/-dumpgcse}
10384 Will create a dump of iCode's, after global subexpression elimination
10385 \begin_inset LatexCommand \index{Global subexpression elimination}
10389 , into a file named
10391 <source filename>.dumpgcse.
10395 \labelwidthstring 00.00.0000
10402 \begin_layout Standard
10412 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10418 Will create a dump of iCode's, after deadcode elimination
10419 \begin_inset LatexCommand \index{Dead-code elimination}
10423 , into a file named
10425 <source filename>.dumpdeadcode.
10429 \labelwidthstring 00.00.0000
10436 \begin_layout Standard
10446 \begin_inset LatexCommand \index{-\/-dumploop}
10455 Will create a dump of iCode's, after loop optimizations
10456 \begin_inset LatexCommand \index{Loop optimization}
10460 , into a file named
10462 <source filename>.dumploop.
10466 \labelwidthstring 00.00.0000
10473 \begin_layout Standard
10483 \begin_inset LatexCommand \index{-\/-dumprange}
10492 Will create a dump of iCode's, after live range analysis
10493 \begin_inset LatexCommand \index{Live range analysis}
10497 , into a file named
10499 <source filename>.dumprange.
10503 \labelwidthstring 00.00.0000
10510 \begin_layout Standard
10520 \begin_inset LatexCommand \index{-\/-dumlrange}
10526 Will dump the life ranges
10527 \begin_inset LatexCommand \index{Live range analysis}
10535 \labelwidthstring 00.00.0000
10542 \begin_layout Standard
10552 \begin_inset LatexCommand \index{-\/-dumpregassign}
10561 Will create a dump of iCode's, after register assignment
10562 \begin_inset LatexCommand \index{Register assignment}
10566 , into a file named
10568 <source filename>.dumprassgn.
10572 \labelwidthstring 00.00.0000
10579 \begin_layout Standard
10589 \begin_inset LatexCommand \index{-\/-dumplrange}
10595 Will create a dump of the live ranges of iTemp's
10599 \labelwidthstring 00.00.0000
10606 \begin_layout Standard
10616 \begin_inset LatexCommand \index{-\/-dumpall}
10627 Will cause all the above mentioned dumps to be created.
10630 \begin_layout Standard
10631 \begin_inset VSpace bigskip
10637 \begin_layout Subsection
10638 Redirecting output on Windows Shells
10641 \begin_layout Standard
10642 By default SDCC writes it's error messages to
10643 \begin_inset Quotes sld
10647 \begin_inset Quotes srd
10651 To force all messages to
10652 \begin_inset Quotes sld
10656 \begin_inset Quotes srd
10668 \begin_layout Standard
10683 \begin_inset LatexCommand \index{-\/-use-stdout}
10688 Additionally, if you happen to have visual studio installed in your windows
10689 machine, you can use it to compile your sources using a custom build and
10696 \begin_layout Standard
10708 \begin_inset LatexCommand \index{-\/-vc}
10713 Something like this should work:
10732 \begin_layout Standard
10751 \begin_layout Standard
10763 -model-large -c $(InputPath)
10766 \begin_inset VSpace bigskip
10772 \begin_layout Section
10773 Environment variables
10774 \begin_inset LatexCommand \index{Environment variables}
10781 \begin_layout Standard
10782 SDCC recognizes the following environment variables:
10786 \labelwidthstring 00.00.0000
10790 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10796 SDCC installs a signal handler
10797 \begin_inset LatexCommand \index{signal handler}
10801 to be able to delete temporary files after an user break (^C) or an exception.
10802 If this environment variable is set, SDCC won't install the signal handler
10803 in order to be able to debug SDCC.
10807 \labelwidthstring 00.00.0000
10813 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10819 Path, where temporary files will be created.
10820 The order of the variables is the search order.
10821 In a standard *nix environment these variables are not set, and there's
10822 no need to set them.
10823 On Windows it's recommended to set one of them.
10827 \labelwidthstring 00.00.0000
10831 \begin_inset LatexCommand \index{SDCC\_HOME}
10838 \begin_inset LatexCommand \ref{sub:Install-paths}
10844 \begin_inset Quotes sld
10848 \begin_inset Quotes srd
10855 \labelwidthstring 00.00.0000
10859 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10866 \begin_inset LatexCommand \ref{sub:Search-Paths}
10872 \begin_inset Quotes sld
10876 \begin_inset Quotes srd
10883 \labelwidthstring 00.00.0000
10887 \begin_inset LatexCommand \index{SDCC\_LIB}
10894 \begin_inset LatexCommand \ref{sub:Search-Paths}
10900 \begin_inset Quotes sld
10904 \begin_inset Quotes srd
10910 \begin_layout Standard
10911 There are some more environment variables recognized by SDCC, but these
10912 are solely used for debugging purposes.
10913 They can change or disappear very quickly, and will never be documented.
10914 \begin_inset VSpace bigskip
10920 \begin_layout Section
10921 Storage Class Language Extensions
10924 \begin_layout Subsection
10925 MCS51/DS390 Storage Class
10926 \begin_inset LatexCommand \index{Storage class}
10930 Language Extensions
10933 \begin_layout Standard
10934 In addition to the ANSI storage classes SDCC allows the following MCS51
10935 specific storage classes:
10938 \begin_layout Subsubsection
10940 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10945 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10950 \begin_inset LatexCommand \index{near (storage class)}
10955 \begin_inset LatexCommand \index{\_\_near (storage class)}
10962 \begin_layout Standard
10967 storage class for the Small Memory model (
10975 or the more ANSI-C compliant forms
10983 can be used synonymously).
10984 Variables declared with this storage class will be allocated in the directly
10985 addressable portion of the internal RAM of a 8051, e.g.:
10988 \begin_layout Verse
10991 __data unsigned char test_data;
10994 \begin_layout Standard
10995 Writing 0x01 to this variable generates the assembly code:
10998 \begin_layout Verse
11001 75*00 01\InsetSpace ~
11009 \begin_layout Subsubsection
11011 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11016 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11021 \begin_inset LatexCommand \index{far (storage class)}
11026 \begin_inset LatexCommand \index{\_\_far (storage class)}
11033 \begin_layout Standard
11034 Variables declared with this storage class will be placed in the external
11040 storage class for the Large Memory model, e.g.:
11043 \begin_layout Verse
11046 __xdata unsigned char test_xdata;
11049 \begin_layout Standard
11050 Writing 0x01 to this variable generates the assembly code:
11053 \begin_layout Verse
11056 90s00r00\InsetSpace ~
11087 \begin_layout Subsubsection
11089 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11094 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11101 \begin_layout Standard
11102 Variables declared with this storage class will be allocated into the indirectly
11103 addressable portion of the internal ram of a 8051, e.g.:
11106 \begin_layout Verse
11109 __idata unsigned char test_idata;
11112 \begin_layout Standard
11113 Writing 0x01 to this variable generates the assembly code:
11116 \begin_layout Verse
11143 \begin_layout Standard
11144 Please note, the first 128 byte of idata physically access the same RAM
11145 as the data memory.
11146 The original 8051 had 128 byte idata memory, nowadays most devices have
11147 256 byte idata memory.
11149 \begin_inset LatexCommand \index{stack}
11153 is located in idata memory.
11156 \begin_layout Subsubsection
11158 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11163 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11170 \begin_layout Standard
11171 Paged xdata access is just as straightforward as using the other addressing
11173 It is typically located at the start of xdata and has a maximum size of
11175 The following example writes 0x01 to the pdata variable.
11176 Please note, pdata access physically accesses xdata memory.
11177 The high byte of the address is determined by port P2
11178 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11182 (or in case of some 8051 variants by a separate Special Function Register,
11184 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11193 storage class for the Medium Memory model, e.g.:
11196 \begin_layout Verse
11199 __pdata unsigned char test_pdata;
11202 \begin_layout Standard
11203 Writing 0x01 to this variable generates the assembly code:
11206 \begin_layout Verse
11215 mov r0,#_test_pdata
11237 \begin_layout Standard
11242 \begin_layout Standard
11252 \begin_inset LatexCommand \index{-\/-xstack}
11256 option is used the pdata memory area is followed by the xstack memory area
11257 and the sum of their sizes is limited to 256 bytes.
11260 \begin_layout Subsubsection
11262 \begin_inset LatexCommand \index{code}
11267 \begin_inset LatexCommand \index{\_\_code}
11274 \begin_layout Standard
11275 'Variables' declared with this storage class will be placed in the code
11279 \begin_layout Verse
11282 __code unsigned char test_code;
11285 \begin_layout Standard
11286 Read access to this variable generates the assembly code:
11289 \begin_layout Verse
11292 90s00r6F\InsetSpace ~
11295 mov dptr,#_test_code
11320 \begin_layout Standard
11325 indexed arrays of characters in code memory can be accessed efficiently:
11328 \begin_layout Verse
11331 __code char test_array[] = {'c','h','e','a','p'};
11334 \begin_layout Standard
11335 Read access to this array using an 8-bit unsigned index generates the assembly
11339 \begin_layout Verse
11351 \begin_layout Verse
11354 90s00r41\InsetSpace ~
11357 mov dptr,#_test_array
11360 \begin_layout Verse
11375 \begin_layout Subsubsection
11377 \begin_inset LatexCommand \index{bit}
11382 \begin_inset LatexCommand \index{\_\_bit}
11389 \begin_layout Standard
11390 This is a data-type and a storage class specifier.
11391 When a variable is declared as a bit, it is allocated into the bit addressable
11392 memory of 8051, e.g.:
11395 \begin_layout Verse
11401 \begin_layout Standard
11402 Writing 1 to this variable generates the assembly code:
11405 \begin_layout Verse
11419 \begin_layout Standard
11420 The bit addressable memory consists of 128 bits which are located from 0x20
11421 to 0x2f in data memory.
11424 Apart from this 8051 specific storage class most architectures support
11426 \begin_inset LatexCommand \index{bitfields}
11434 \begin_layout Standard
11435 Not really meant as examples, but nevertheless showing what bitfields are
11436 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11442 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11443 signed modifier are implemented as unsigned.
11446 \begin_layout Subsubsection
11448 \begin_inset LatexCommand \index{sfr}
11453 \begin_inset LatexCommand \index{\_\_sfr}
11458 \begin_inset LatexCommand \index{sfr16}
11463 \begin_inset LatexCommand \index{\_\_sfr16}
11468 \begin_inset LatexCommand \index{sfr32}
11473 \begin_inset LatexCommand \index{\_\_sfr32}
11478 \begin_inset LatexCommand \index{\_\_sbit}
11483 \begin_inset LatexCommand \index{sbit}
11490 \begin_layout Standard
11491 Like the bit keyword,
11493 sfr / sfr16 / sfr32 / sbit
11495 signify both a data-type and storage class, they are used to describe the
11516 variables of a 8051, eg:
11519 \begin_layout Verse
11523 \begin_inset LatexCommand \index{at}
11528 \begin_inset LatexCommand \index{\_\_at}
11532 (0x80) P0;\InsetSpace ~
11533 /* special function register P0 at location 0x80 */
11538 special function register combination for timer 0
11542 with the high byte at
11543 location 0x8C and the low byte at location 0x8A */
11545 __sfr16 __at (0x8C8A)
11551 \begin_inset LatexCommand \index{at}
11556 \begin_inset LatexCommand \index{\_\_at}
11560 (0xd7) CY;\InsetSpace ~
11562 \begin_inset LatexCommand \index{Flags}
11567 \begin_inset LatexCommand \index{Carry flag}
11574 \begin_layout Standard
11575 Special function registers which are located on an address dividable by
11576 8 are bit-addressable, an
11580 addresses a specific bit within these sfr.
11582 16 Bit and 32 bit special function
11583 register combinations which require a certain access order are better not
11593 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11594 this is not guaranteed.
11599 \begin_layout Standard
11600 Please note, if you use a header file which was written for another compiler
11601 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11607 Specifically the syntax
11610 sfr P0 = 0x80;\InsetSpace ~
11617 by SDCC to an assignment of 0x80 to a variable called P0
11620 \begin_inset Marginal
11623 \begin_layout Standard
11635 Nevertheless it is possible to write header files
11636 \begin_inset LatexCommand \index{Header files}
11641 \begin_inset LatexCommand \index{Include files}
11645 which can be shared among different compilers (see section
11646 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11654 \begin_layout Subsubsection
11656 \begin_inset LatexCommand \index{Pointer}
11660 to MCS51/DS390 specific memory spaces
11663 \begin_layout Standard
11664 SDCC allows (via language extensions) pointers to explicitly point to any
11665 of the memory spaces
11666 \begin_inset LatexCommand \index{Memory model}
11671 In addition to the explicit pointers, the compiler uses (by default) generic
11672 pointers which can be used to point to any of the memory spaces.
11677 declaration examples:
11680 \begin_layout Verse
11683 /* pointer physically in internal ram pointing to object in external ram
11686 __xdata unsigned char * __data p;
11690 /* pointer physically in external ram
11691 pointing to object in internal ram */
11693 __data unsigned char * __xdata p;
11698 pointer physically in code rom pointing to data in xdata space */
11701 unsigned char * __code p;
11705 /* pointer physically in code space pointing to
11706 data in code space */
11708 __code unsigned char * __code p;
11713 physically located in xdata space */
11715 unsigned char * __xdata p;
11720 pointer physically located in default memory space */
11727 the following is a function pointer
11728 \begin_inset LatexCommand \index{function pointer}
11732 physically located in data space */
11734 char (* __data fp)(void);
11737 \begin_layout Standard
11738 Well you get the idea.
11743 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11756 The highest order byte of the
11760 pointers contains the data space information.
11761 Assembler support routines are called whenever data is stored or retrieved
11767 These are useful for developing reusable library
11768 \begin_inset LatexCommand \index{Libraries}
11773 Explicitly specifying the pointer
11774 \begin_inset LatexCommand \index{pointer}
11778 type will generate the most efficient code.
11781 \begin_layout Subsubsection
11782 Notes on MCS51 memory
11783 \begin_inset LatexCommand \index{MCS51 memory}
11790 \begin_layout Standard
11791 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11792 RAM memory which is structured as follows:
11796 - Bytes 00-1F - 32 bytes to hold
11797 up to 4 banks of the registers R0 to R7,
11799 - Bytes 20-2F - 16 bytes to hold
11801 \begin_inset LatexCommand \index{bit}
11807 - Bytes 30-7F - 80 bytes for general purpose use.
11812 \begin_layout Standard
11813 Additionally some members of the MCS51 family may have up to 128 bytes of
11814 additional, indirectly addressable, internal RAM memory (
11819 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11824 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11829 Furthermore, some chips may have some built in external memory (
11834 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11839 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11843 ) which should not be confused with the internal, directly addressable RAM
11849 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11854 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11859 Sometimes this built in
11863 memory has to be activated before using it (you can probably find this
11864 information on the datasheet of the microcontroller your are using, see
11866 \begin_inset LatexCommand \ref{sub:Startup-Code}
11874 \begin_layout Standard
11875 Normally SDCC will only use the first bank
11876 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11880 of registers (register bank 0), but it is possible to specify that other
11881 banks of registers (keyword
11888 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11893 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11899 ) should be used for example in interrupt
11900 \begin_inset LatexCommand \index{interrupt}
11905 \begin_inset LatexCommand \index{\_\_interrupt}
11910 By default, the compiler will place the stack after the last byte of allocated
11911 memory for variables.
11912 For example, if the first 2 banks of registers are used, and only four
11917 variables, it will position the base of the internal stack at address 20
11919 This implies that as the stack
11920 \begin_inset LatexCommand \index{stack}
11924 grows, it will use up the remaining register banks, and the 16 bytes used
11925 by the 128 bit variables, and 80 bytes for general purpose use.
11926 If any bit variables are used, the data variables will be placed in unused
11927 register banks and after the byte holding the last bit variable.
11928 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11933 variables will be placed starting from address 0x10 to 0x20 and continue
11939 \begin_layout Standard
11949 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11953 to specify the start address of the
11961 \begin_layout Standard
11971 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11975 to specify the size of the total internal RAM (
11989 \begin_layout Standard
11990 By default the 8051 linker will place the stack after the last byte of (i)data
11996 \begin_layout Standard
12006 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12010 allows you to specify the start of the stack, i.e.
12011 you could start it after any data in the general purpose area.
12012 If your microcontroller has additional indirectly addressable internal
12017 ) you can place the stack on it.
12018 You may also need to use -
12022 \begin_layout Standard
12032 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12036 to set the start address of the external RAM (
12044 \begin_layout Standard
12054 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12058 to specify its size.
12059 Same goes for the code memory, using -
12063 \begin_layout Standard
12073 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12081 \begin_layout Standard
12091 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12096 If in doubt, don't specify any options and see if the resulting memory
12097 layout is appropriate, then you can adjust it.
12100 \begin_layout Standard
12101 The linker generates two files with memory allocation information.
12102 The first, with extension .map
12103 \begin_inset LatexCommand \index{<file>.map}
12107 shows all the variables and segments.
12108 The second with extension .mem
12109 \begin_inset LatexCommand \index{<file>.mem}
12113 shows the final memory layout.
12114 The linker will complain either if memory segments overlap, there is not
12115 enough memory, or there is not enough space for stack.
12116 If you get any linking warnings and/or errors related to stack or segments
12117 allocation, take a look at either the .map or .mem files to find out what
12119 The .mem file may even suggest a solution to the problem.
12120 \begin_inset VSpace bigskip
12126 \begin_layout Subsection
12127 Z80/Z180 Storage Class
12128 \begin_inset LatexCommand \index{Z80!Storage class}
12132 Language Extensions
12135 \begin_layout Subsubsection
12137 \begin_inset LatexCommand \index{sfr}
12142 \begin_inset LatexCommand \index{\_\_sfr}
12146 (in/out to 8-bit addresses)
12149 \begin_layout Standard
12151 \begin_inset LatexCommand \index{Z80}
12155 family has separate address spaces for memory and
12165 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12170 \begin_inset LatexCommand \index{Z80!I/O memory}
12175 \begin_inset LatexCommand \index{Z180!I/O memory}
12179 is accessed with special instructions, e.g.:
12182 \begin_layout Verse
12185 sfr at 0x78 IoPort;\InsetSpace ~
12187 /* define a var in I/O space at 78h called IoPort */
12191 \begin_layout Standard
12192 Writing 0x01 to this variable generates the assembly code:
12195 \begin_layout Verse
12215 \begin_layout Subsubsection
12217 \begin_inset LatexCommand \index{sfr}
12222 \begin_inset LatexCommand \index{\_\_sfr}
12226 (in/out to 16-bit addresses)
12229 \begin_layout Standard
12234 is used to support 16 bit addresses in I/O memory e.g.:
12237 \begin_layout Verse
12241 \begin_inset LatexCommand \index{at}
12246 \begin_inset LatexCommand \index{\_\_at}
12253 \begin_layout Standard
12254 Writing 0x01 to this variable generates the assembly code:
12257 \begin_layout Verse
12260 01 23 01\InsetSpace ~
12282 \begin_layout Subsubsection
12284 \begin_inset LatexCommand \index{sfr}
12289 \begin_inset LatexCommand \index{\_\_sfr}
12293 (in0/out0 to 8 bit addresses on Z180
12294 \begin_inset LatexCommand \index{Z180}
12299 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12306 \begin_layout Standard
12307 The compiler option -
12311 \begin_layout Standard
12321 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12325 =180 (80) and a compiler #pragma\InsetSpace ~
12327 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12331 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12341 If you include the file z180.h this will be set automatically.
12342 \begin_inset VSpace bigskip
12348 \begin_layout Subsection
12350 \begin_inset LatexCommand \index{HC08!Storage class}
12354 Language Extensions
12357 \begin_layout Subsubsection
12359 \begin_inset LatexCommand \index{data (hc08 storage class)}
12364 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12371 \begin_layout Standard
12372 The data storage class declares a variable that resides in the first 256
12373 bytes of memory (the direct page).
12375 \begin_inset LatexCommand \index{HC08}
12379 is most efficient at accessing variables (especially pointers) stored here.
12382 \begin_layout Subsubsection
12384 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12389 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12396 \begin_layout Standard
12397 The xdata storage class declares a variable that can reside anywhere in
12399 This is the default if no storage class is specified.
12401 \begin_inset VSpace bigskip
12407 \begin_layout Section
12408 Absolute Addressing
12409 \begin_inset LatexCommand \index{Absolute addressing}
12416 \begin_layout Standard
12417 Data items can be assigned an absolute address with the
12420 \begin_inset LatexCommand \index{at}
12425 \begin_inset LatexCommand \index{\_\_at}
12431 keyword, in addition to a storage class, e.g.:
12434 \begin_layout Verse
12438 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12443 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12448 \begin_inset LatexCommand \index{at}
12453 \begin_inset LatexCommand \index{\_\_at}
12457 0x7ffe unsigned int chksum;
12460 \begin_layout Standard
12461 or, better conforming to ISO/IEC 9899 C:
12464 \begin_layout Verse
12467 __xdata __at (0x7ffe) unsigned int chksum;
12470 \begin_layout Standard
12471 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12472 of the external ram.
12477 reserve any space for variables declared in this way
12478 \begin_inset Marginal
12481 \begin_layout Standard
12490 (they are implemented with an equate in the assembler).
12491 Thus it is left to the programmer to make sure there are no overlaps with
12492 other variables that are declared without the absolute address.
12493 The assembler listing file (.lst
12494 \begin_inset LatexCommand \index{<file>.lst}
12498 ) and the linker output files (.rst
12499 \begin_inset LatexCommand \index{<file>.rst}
12504 \begin_inset LatexCommand \index{<file>.map}
12508 ) are good places to look for such overlaps.
12509 Variables with an absolute address are
12512 \begin_inset Marginal
12515 \begin_layout Standard
12527 \begin_inset LatexCommand \index{Variable initialization}
12534 \begin_layout Standard
12535 In case of memory mapped I/O devices the keyword
12539 has to be used to tell the compiler that accesses might not be removed:
12542 \begin_layout Verse
12546 \begin_inset LatexCommand \index{volatile}
12551 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12556 \begin_inset LatexCommand \index{at}
12560 (0x8000) unsigned char PORTA_8255;
12563 \begin_layout Standard
12564 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12569 \begin_inset LatexCommand \index{Aligned array}
12576 starts at a block (256 byte) boundary
12577 \begin_inset LatexCommand \index{block boundary}
12582 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12588 Absolute addresses can be specified for variables in all
12589 storage classes, e.g.:
12592 \begin_layout Verse
12596 \begin_inset LatexCommand \index{bit}
12601 \begin_inset LatexCommand \index{at}
12608 \begin_layout Standard
12609 The above example will allocate the variable at offset 0x02 in the bit-addressab
12611 There is no real advantage to assigning absolute addresses to variables
12612 in this manner, unless you want strict control over all the variables allocated.
12613 One possible use would be to write hardware portable code.
12614 For example, if you have a routine that uses one or more of the microcontroller
12615 I/O pins, and such pins are different for two different hardwares, you
12616 can declare the I/O pins in your routine using:
12619 \begin_layout Verse
12623 \begin_inset LatexCommand \index{volatile}
12627 __bit MOSI;\InsetSpace ~
12631 /* master out, slave in */
12633 extern volatile __bit MISO;\InsetSpace ~
12640 extern volatile __bit MCLK;\InsetSpace ~
12649 Output of a byte on a 3-wire serial bus.
12654 If needed adapt polarity of clock,
12655 polarity of data and bit order
12660 unsigned char spi_io(unsigned char out_byte)
12685 MOSI = out_byte & 0x80;
12716 /* _asm nop _endasm; */\InsetSpace ~
12724 /* for slow peripherals */
12776 \begin_layout Standard
12777 Then, someplace in the code for the first hardware you would use
12780 \begin_layout Verse
12784 \begin_inset LatexCommand \index{at}
12789 \begin_inset LatexCommand \index{\_\_at}
12793 (0x80) MOSI;\InsetSpace ~
12797 /* I/O port 0, bit 0 */
12799 __bit __at (0x81) MISO;\InsetSpace ~
12806 __bit __at (0x82) MCLK;\InsetSpace ~
12810 /* I/O port 0, bit 2 */
12813 \begin_layout Standard
12814 Similarly, for the second hardware you would use
12817 \begin_layout Verse
12820 __bit __at (0x83) MOSI;\InsetSpace ~
12824 /* I/O port 0, bit 3 */
12826 __bit __at (0x91) MISO;\InsetSpace ~
12831 I/O port 1, bit 1 */
12834 \begin_inset LatexCommand \index{bit}
12838 __at (0x92) MCLK;\InsetSpace ~
12842 /* I/O port 1, bit 2 */
12845 \begin_layout Standard
12846 and you can use the same hardware dependent routine without changes, as
12847 for example in a library.
12848 This is somehow similar to sbit, but only one absolute address has to be
12849 specified in the whole project.
12850 \begin_inset VSpace bigskip
12856 \begin_layout Section
12858 \begin_inset LatexCommand \index{Parameters}
12863 \begin_inset LatexCommand \index{function parameter}
12868 \begin_inset LatexCommand \index{local variables}
12873 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12880 \begin_layout Standard
12881 Automatic (local) variables and parameters to functions can either be placed
12882 on the stack or in data-space.
12883 The default action of the compiler is to place these variables in the internal
12884 RAM (for small model) or external RAM (for large model).
12885 This in fact makes them similar to
12888 \begin_inset LatexCommand \index{static}
12894 so by default functions are non-reentrant
12895 \begin_inset LatexCommand \index{reentrant}
12904 They can be placed on the stack
12905 \begin_inset LatexCommand \index{stack}
12915 \begin_layout Standard
12925 \begin_inset LatexCommand \index{-\/-stack-auto}
12933 #pragma\InsetSpace ~
12937 \begin_inset LatexCommand \index{\#pragma stackauto}
12944 \begin_inset LatexCommand \index{reentrant}
12950 keyword in the function declaration, e.g.:
12953 \begin_layout Verse
12956 unsigned char foo(char i) __reentrant
12970 \begin_layout Standard
12971 Since stack space on 8051 is limited, the
12981 \begin_layout Standard
12992 option should be used sparingly.
12993 Note that the reentrant keyword just means that the parameters & local
12994 variables will be allocated to the stack, it
12998 mean that the function is register bank
12999 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13008 \begin_inset LatexCommand \index{local variables}
13012 can be assigned storage classes and absolute
13013 \begin_inset LatexCommand \index{Absolute addressing}
13020 \begin_layout Verse
13023 unsigned char foo()
13031 __xdata unsigned char i;
13044 \begin_inset LatexCommand \index{at}
13048 (0x31) unsigned char j;
13060 \begin_layout Standard
13061 In the above example the variable
13065 will be allocated in the external ram,
13069 in bit addressable space and
13080 \begin_layout Standard
13091 or when a function is declared as
13095 this should only be done for static variables.
13098 \begin_layout Standard
13100 \begin_inset LatexCommand \index{function parameter}
13104 however are not allowed any storage class
13105 \begin_inset LatexCommand \index{Storage class}
13109 , (storage classes for parameters will be ignored), their allocation is
13110 governed by the memory model in use, and the reentrancy options.
13113 \begin_layout Standard
13114 It is however allowed to use bit parameters in reentrant functions and also
13115 non-static local bit variables are supported.
13116 Efficient use is limited to 8 semi-bitregisters in bit space.
13117 They are pushed and popped to stack
13118 \begin_inset LatexCommand \index{stack}
13122 as a single byte just like the normal registers.
13125 \begin_layout Section
13127 \begin_inset LatexCommand \label{sub:Overlaying}
13132 \begin_inset LatexCommand \index{Overlaying}
13139 \begin_layout Standard
13141 \begin_inset LatexCommand \index{reentrant}
13145 functions SDCC will try to reduce internal ram space usage by overlaying
13146 parameters and local variables of a function (if possible).
13147 Parameters and local variables
13148 \begin_inset LatexCommand \index{local variables}
13152 of a function will be allocated to an overlayable segment if the function
13155 no other function calls and the function is non-reentrant and the memory
13157 \begin_inset LatexCommand \index{Memory model}
13164 If an explicit storage class
13165 \begin_inset LatexCommand \index{Storage class}
13169 is specified for a local variable, it will NOT be overlayed.
13172 \begin_layout Standard
13173 Note that the compiler (not the linkage editor) makes the decision for overlayin
13175 Functions that are called from an interrupt service routine
13176 \begin_inset Marginal
13179 \begin_layout Standard
13187 should be preceded by a #pragma\InsetSpace ~
13189 \begin_inset LatexCommand \index{\#pragma nooverlay}
13193 if they are not reentrant.
13196 \begin_layout Standard
13197 Also note that the compiler does not do any processing of inline assembler
13198 code, so the compiler might incorrectly assign local variables and parameters
13199 of a function into the overlay segment if the inline assembler code calls
13200 other c-functions that might use the overlay.
13201 In that case the #pragma\InsetSpace ~
13202 nooverlay should be used.
13205 \begin_layout Standard
13206 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13208 \begin_inset LatexCommand \index{Multiplication}
13213 \begin_inset LatexCommand \index{Division}
13217 will NOT be overlayed since these are implemented using external functions,
13221 \begin_layout Verse
13227 \begin_inset LatexCommand \index{\#pragma nooverlay}
13233 void set_error(unsigned char errcd)
13250 some_isr () __interrupt
13251 \begin_inset LatexCommand \index{interrupt}
13281 \begin_layout Standard
13282 In the above example the parameter
13290 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13292 not present, this could cause unpredictable runtime behavior when called
13293 from an interrupt service routine.
13294 The #pragma\InsetSpace ~
13295 nooverlay ensures that the parameters and local variables for
13296 the function are NOT overlayed.
13297 \begin_inset VSpace bigskip
13303 \begin_layout Section
13304 Interrupt Service Routines
13305 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13312 \begin_layout Subsection
13313 General Information
13316 \begin_layout Standard
13329 outines to be coded in C, with some extended keywords.
13332 \begin_layout Verse
13335 void timer_isr (void) __interrupt (1) __using (1)
13349 \begin_layout Standard
13350 The optional number following the
13353 \begin_inset LatexCommand \index{interrupt}
13358 \begin_inset LatexCommand \index{\_\_interrupt}
13364 keyword is the interrupt number this routine will service.
13365 When present, the compiler will insert a call to this routine in the interrupt
13367 \begin_inset LatexCommand \index{interrupt vector table}
13371 for the interrupt number specified.
13372 If you have multiple source files in your project, interrupt service routines
13373 can be present in any of them, but a prototype of the isr MUST be present
13374 or included in the file that contains the function
13379 The optional (8051 specific) keyword
13382 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13387 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13393 can be used to tell the compiler to use the specified register bank when
13394 generating code for this function.
13397 Interrupt service routines open the door for some very interesting bugs:
13400 \begin_layout Subsubsection
13401 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13405 Common interrupt pitfall: variable not declared
13410 \begin_layout Standard
13411 If an interrupt service routine changes variables which are accessed by
13412 other functions these variables have to be declared
13417 \begin_inset LatexCommand \index{volatile}
13423 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13430 \begin_layout Subsubsection
13431 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13435 Common interrupt pitfall:
13440 \begin_layout Standard
13441 If the access to these variables is not
13444 \begin_inset LatexCommand \index{atomic}
13451 the processor needs more than one instruction for the access and could
13452 be interrupted while accessing the variable) the interrupt must be disabled
13453 during the access to avoid inconsistent data.
13456 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13457 and should be protected by disabling interrupts.
13458 You're not automatically on the safe side if you use 8 bit variables though.
13459 We need an example here: f.e.
13460 on the 8051 the harmless looking
13461 \begin_inset Quotes srd
13471 \begin_inset Quotes sld
13480 \begin_inset Quotes srd
13490 \begin_inset Quotes sld
13493 from within an interrupt routine might get lost if the interrupt occurs
13496 \begin_inset Quotes sld
13501 counter\InsetSpace ~
13506 \begin_inset Quotes srd
13509 is not atomic on the 8051 even if
13513 is located in data memory.
13515 Bugs like these are hard to reproduce and can
13516 cause a lot of trouble.
13520 \begin_layout Subsubsection
13521 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13525 Common interrupt pitfall:
13530 \begin_layout Standard
13531 The return address and the registers used in the interrupt service routine
13532 are saved on the stack
13533 \begin_inset LatexCommand \index{stack}
13537 so there must be sufficient stack space.
13538 If there isn't variables or registers (or even the return address itself)
13545 \begin_inset LatexCommand \index{stack overflow}
13549 is most likely to happen if the interrupt occurs during the
13550 \begin_inset Quotes sld
13554 \begin_inset Quotes srd
13557 subroutine when the stack is already in use for f.e.
13558 many return addresses.
13561 \begin_layout Subsubsection
13562 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13566 Common interrupt pitfall:
13568 use of non-reentrant functions
13571 \begin_layout Standard
13572 A special note here, int (16 bit) and long (32 bit) integer division
13573 \begin_inset LatexCommand \index{Division}
13578 \begin_inset LatexCommand \index{Multiplication}
13583 \begin_inset LatexCommand \index{Modulus}
13588 \begin_inset LatexCommand \index{Floating point support}
13592 operations are implemented using external support routines.
13593 If an interrupt service routine needs to do any of these operations then
13594 the support routines (as mentioned in a following section) will have to
13595 be recompiled using the
13601 \begin_layout Standard
13611 \begin_inset LatexCommand \index{-\/-stack-auto}
13617 option and the source file will need to be compiled using the
13623 \begin_layout Standard
13635 \begin_inset LatexCommand \index{-\/-int-long-reent}
13642 Note, the type promotion
13643 \begin_inset LatexCommand \index{type promotion}
13647 required by ANSI C can cause 16 bit routines to be used
13648 \begin_inset Marginal
13651 \begin_layout Standard
13660 without the programmer being aware of it.
13664 (unsigned char)(tail-1)
13666 within the if clause in section
13667 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13674 \begin_layout Standard
13675 Calling other functions from an interrupt service routine is not recommended,
13676 avoid it if possible.
13677 Note that when some function is called from an interrupt service routine
13678 it should be preceded by a #pragma\InsetSpace ~
13680 \begin_inset LatexCommand \index{\#pragma nooverlay}
13684 if it is not reentrant.
13685 Furthermore nonreentrant functions should not be called from the main program
13686 while the interrupt service routine might be active.
13687 They also must not be called from low priority interrupt service routines
13688 while a high priority interrupt service routine might be active.
13689 You could use semaphores or make the function
13693 if all parameters are passed in registers.
13696 \begin_inset LatexCommand \ref{sub:Overlaying}
13701 about Overlaying and section
13702 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13707 about Functions using private register banks.
13708 \begin_inset VSpace bigskip
13714 \begin_layout Subsection
13715 MCS51/DS390 Interrupt Service Routines
13718 \begin_layout Standard
13720 \begin_inset LatexCommand \index{interrupt}
13724 numbers and the corresponding address & descriptions for the Standard 8051/8052
13726 SDCC will automatically adjust the
13727 \begin_inset LatexCommand \index{interrupt vector table}
13731 to the maximum interrupt number specified.
13736 \begin_layout Standard
13738 \begin_inset Tabular
13739 <lyxtabular version="3" rows="9" columns="3">
13741 <column alignment="center" valignment="top" leftline="true" width="0in">
13742 <column alignment="left" valignment="top" leftline="true" width="0in">
13743 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13744 <row topline="true" bottomline="true">
13745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13748 \begin_layout Standard
13754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13757 \begin_layout Standard
13763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13766 \begin_layout Standard
13773 <row topline="true">
13774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13777 \begin_layout Standard
13783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13786 \begin_layout Standard
13792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13795 \begin_layout Standard
13802 <row topline="true">
13803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13806 \begin_layout Standard
13812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13815 \begin_layout Standard
13821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13824 \begin_layout Standard
13831 <row topline="true">
13832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13835 \begin_layout Standard
13841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13844 \begin_layout Standard
13850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13853 \begin_layout Standard
13860 <row topline="true">
13861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13864 \begin_layout Standard
13870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13873 \begin_layout Standard
13879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13882 \begin_layout Standard
13889 <row topline="true">
13890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13893 \begin_layout Standard
13899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13902 \begin_layout Standard
13908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13911 \begin_layout Standard
13918 <row topline="true">
13919 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13922 \begin_layout Standard
13928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13931 \begin_layout Standard
13937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13940 \begin_layout Standard
13947 <row topline="true">
13948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13951 \begin_layout Standard
13957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13960 \begin_layout Standard
13966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13969 \begin_layout Standard
13976 <row topline="true" bottomline="true">
13977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13980 \begin_layout Standard
13986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13989 \begin_layout Standard
13995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13998 \begin_layout Standard
14014 \begin_layout Standard
14015 If the interrupt service routine is defined without
14018 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14023 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14029 a register bank or with register bank 0 (
14033 0), the compiler will save the registers used by itself on the stack upon
14034 entry and restore them at exit, however if such an interrupt service routine
14035 calls another function then the entire register bank will be saved on the
14037 This scheme may be advantageous for small interrupt service routines which
14038 have low register usage.
14041 \begin_layout Standard
14042 If the interrupt service routine is defined to be using a specific register
14047 & psw are saved and restored, if such an interrupt service routine calls
14048 another function (using another register bank) then the entire register
14049 bank of the called function will be saved on the stack
14050 \begin_inset LatexCommand \index{stack}
14055 This scheme is recommended for larger interrupt service routines.
14056 \begin_inset VSpace bigskip
14062 \begin_layout Subsection
14064 \begin_inset LatexCommand \index{HC08}
14068 Interrupt Service Routines
14071 \begin_layout Standard
14072 Since the number of interrupts
14073 \begin_inset LatexCommand \index{HC08!interrupt}
14077 available is chip specific and the interrupt vector table always ends at
14078 the last byte of memory, the interrupt numbers corresponds to the interrupt
14079 vectors in reverse order of address.
14080 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14081 2 will use the interrupt vector at 0xfffa, and so on.
14082 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14083 this way; instead see section
14084 \begin_inset LatexCommand \ref{sub:Startup-Code}
14088 for details on customizing startup.
14089 \begin_inset VSpace bigskip
14095 \begin_layout Subsection
14096 Z80 Interrupt Service Routines
14099 \begin_layout Standard
14101 \begin_inset LatexCommand \index{Z80}
14105 uses several different methods for determining the correct interrupt
14106 \begin_inset LatexCommand \index{Z80!interrupt}
14110 vector depending on the hardware implementation.
14111 Therefore, SDCC ignores the optional interrupt number and does not attempt
14112 to generate an interrupt vector table.
14115 \begin_layout Standard
14116 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14117 instruction to return from the interrupt.
14118 To write an interrupt handler for the non-maskable interrupt, which needs
14119 a RETN instruction instead, add the
14126 \begin_layout Verse
14129 void nmi_isr (void) critical interrupt
14143 \begin_layout Standard
14144 However if you need to create a non-interruptable interrupt service routine
14145 you would also require the
14150 To distinguish between this and an nmi_isr you must provide an interrupt
14152 \begin_inset VSpace bigskip
14158 \begin_layout Section
14159 Enabling and Disabling Interrupts
14162 \begin_layout Subsection
14163 Critical Functions and Critical Statements
14166 \begin_layout Standard
14167 A special keyword may be associated with a block or a function declaring
14173 SDCC will generate code to disable all interrupts
14174 \begin_inset LatexCommand \index{interrupt}
14178 upon entry to a critical function and restore the interrupt enable to the
14179 previous state before returning.
14180 Nesting critical functions will need one additional byte on the stack
14181 \begin_inset LatexCommand \index{stack}
14188 \begin_layout Verse
14191 int foo () __critical
14192 \begin_inset LatexCommand \index{critical}
14197 \begin_inset LatexCommand \index{\_\_critical}
14222 \begin_layout Standard
14223 The critical attribute maybe used with other attributes like
14233 may also be used to disable interrupts more locally:
14236 \begin_layout Verse
14242 \begin_layout Standard
14243 More than one statement could have been included in the block.
14246 \begin_layout Subsection
14247 Enabling and Disabling Interrupts directly
14250 \begin_layout Standard
14252 \begin_inset LatexCommand \index{interrupt}
14256 can also be disabled and enabled directly (8051):
14259 \begin_layout Verse
14262 EA = 0;\InsetSpace ~
14288 \begin_layout Verse
14324 \begin_layout Verse
14327 EA = 1;\InsetSpace ~
14356 \begin_layout Verse
14395 \begin_layout Standard
14396 On other architectures which have seperate opcodes for enabling and disabling
14397 interrupts you might want to make use of defines with inline assembly
14398 \begin_inset LatexCommand \index{Assembler routines}
14403 \begin_inset LatexCommand \index{HC08!interrupt}
14410 \begin_layout Verse
14414 \begin_inset LatexCommand \index{\_asm}
14423 \begin_inset LatexCommand \index{\_endasm}
14430 \begin_layout Verse
14433 #define SEI _asm\InsetSpace ~
14440 \begin_layout Verse
14446 \begin_layout Standard
14447 Note: it is sometimes sufficient to disable only a specific interrupt source
14449 a timer or serial interrupt by manipulating an
14452 \begin_inset LatexCommand \index{interrupt mask}
14462 \begin_layout Standard
14463 Usually the time during which interrupts are disabled should be kept as
14465 This minimizes both
14470 \begin_inset LatexCommand \index{interrupt latency}
14474 (the time between the occurrence of the interrupt and the execution of
14475 the first code in the interrupt routine) and
14480 \begin_inset LatexCommand \index{interrupt jitter}
14484 (the difference between the shortest and the longest interrupt latency).
14485 These really are something different, f.e.
14486 a serial interrupt has to be served before its buffer overruns so it cares
14487 for the maximum interrupt latency, whereas it does not care about jitter.
14488 On a loudspeaker driven via a digital to analog converter which is fed
14489 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14490 a much smaller jitter will be very audible.
14493 \begin_layout Standard
14494 You can reenable interrupts within an interrupt routine and on some architecture
14495 s you can make use of two (or more) levels of
14497 interrupt priorities
14500 \begin_inset LatexCommand \index{interrupt priority}
14505 On some architectures which don't support interrupt priorities these can
14506 be implemented by manipulating the interrupt mask and reenabling interrupts
14507 within the interrupt routine.
14508 Check there is sufficient space on the stack
14509 \begin_inset LatexCommand \index{stack}
14513 and don't add complexity unless you have to.
14517 \begin_layout Subsection
14519 \begin_inset LatexCommand \index{semaphore}
14523 locking (mcs51/ds390)
14526 \begin_layout Standard
14527 Some architectures (mcs51/ds390) have an atomic
14528 \begin_inset LatexCommand \index{atomic}
14541 These type of instructions are typically used in preemptive multitasking
14542 systems, where a routine f.e.
14543 claims the use of a data structure ('acquires a lock
14544 \begin_inset LatexCommand \index{lock}
14548 on it'), makes some modifications and then releases the lock when the data
14549 structure is consistent again.
14550 The instruction may also be used if interrupt and non-interrupt code have
14551 to compete for a resource.
14552 With the atomic bit test and clear instruction interrupts
14553 \begin_inset LatexCommand \index{interrupt}
14557 don't have to be disabled for the locking operation.
14561 \begin_layout Standard
14562 SDCC generates this instruction if the source follows this pattern:
14565 \begin_layout Verse
14569 \begin_inset LatexCommand \index{volatile}
14573 bit resource_is_free;
14577 if (resource_is_free)
14587 resource_is_free=0;
14600 resource_is_free=1;
14607 \begin_layout Standard
14608 Note, mcs51 and ds390 support only an atomic
14609 \begin_inset LatexCommand \index{atomic}
14617 instruction (as opposed to atomic bit test and
14622 \begin_layout Section
14623 Functions using private register banks
14624 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14631 \begin_layout Standard
14632 Some architectures have support for quickly changing register sets.
14633 SDCC supports this feature with the
14636 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14641 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14647 attribute (which tells the compiler to use a register bank
14648 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14652 other than the default bank zero).
14653 It should only be applied to
14656 \begin_inset LatexCommand \index{interrupt}
14662 functions (see footnote below).
14663 This will in most circumstances make the generated ISR code more efficient
14664 since it will not have to save registers on the stack.
14667 \begin_layout Standard
14672 attribute will have no effect on the generated code for a
14676 function (but may occasionally be useful anyway
14680 \begin_layout Standard
14681 possible exception: if a function is called ONLY from 'interrupt' functions
14682 using a particular bank, it can be declared with the same 'using' attribute
14683 as the calling 'interrupt' functions.
14684 For instance, if you have several ISRs using bank one, and all of them
14685 call memcpy(), it might make sense to create a specialized version of memcpy()
14686 'using 1', since this would prevent the ISR from having to save bank zero
14687 to the stack on entry and switch to bank zero before calling the function
14696 (pending: Note, nowadays the
14700 attribute has an effect on
14704 the generated code for a
14715 \begin_layout Standard
14720 function using a non-zero bank will assume that it can trash that register
14721 bank, and will not save it.
14722 Since high-priority interrupts
14723 \begin_inset LatexCommand \index{interrupts}
14728 \begin_inset LatexCommand \index{interrupt priority}
14732 can interrupt low-priority ones on the 8051 and friends, this means that
14733 if a high-priority ISR
14737 a particular bank occurs while processing a low-priority ISR
14741 the same bank, terrible and bad things can happen.
14742 To prevent this, no single register bank should be
14746 by both a high priority and a low priority ISR.
14747 This is probably most easily done by having all high priority ISRs use
14748 one bank and all low priority ISRs use another.
14749 If you have an ISR which can change priority at runtime, you're on your
14750 own: I suggest using the default bank zero and taking the small performance
14754 \begin_layout Standard
14755 It is most efficient if your ISR calls no other functions.
14756 If your ISR must call other functions, it is most efficient if those functions
14757 use the same bank as the ISR (see note 1 below); the next best is if the
14758 called functions use bank zero.
14759 It is very inefficient to call a function using a different, non-zero bank
14762 \begin_inset VSpace bigskip
14768 \begin_layout Section
14770 \begin_inset LatexCommand \label{sub:Startup-Code}
14775 \begin_inset LatexCommand \index{Startup code}
14782 \begin_layout Subsection
14783 MCS51/DS390 Startup Code
14786 \begin_layout Standard
14787 The compiler triggers the linker to link certain initialization modules
14788 from the runtime library
14789 \begin_inset LatexCommand \index{Runtime library}
14793 called crt<something>.
14794 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14795 GSINIT5) is not linked unless the --xstack option is used.
14796 These modules are highly entangled by the use of special segments/areas,
14797 but a common layout is shown below:
14800 \begin_layout Verse
14808 \begin_layout Verse
14832 ljmp __sdcc_gsinit_startup
14835 \begin_layout Verse
14843 \begin_layout Verse
14855 .area GSINIT0 (CODE)
14857 __sdcc_gsinit_startup::
14867 mov sp,#__start__stack - 1
14870 \begin_layout Verse
14878 \begin_layout Verse
14890 .area GSINIT1 (CODE)
14892 __sdcc_init_xstack::
14894 ; Need to initialize in GSINIT1 in
14895 case the user's __sdcc_external_startup uses the xstack.
14905 mov __XPAGE,#(__start__x
14916 mov _spx,#__start__xstack
14919 \begin_layout Verse
14927 \begin_layout Verse
14939 .area GSINIT2 (CODE)
14949 lcall __sdcc_external_startup
14969 jz __sdcc_init_data
14980 __sdcc_program_startup
14985 \begin_layout Verse
14993 \begin_layout Verse
15005 .area GSINIT3 (CODE)
15058 mov r2,#((l_XINIT+255) >> 8)
15089 __XPAGE,#(s_XISEG >> 8)
15091 00001$:\InsetSpace ~
15155 00002$:\InsetSpace ~
15182 \begin_layout Verse
15190 \begin_layout Verse
15202 .area GSINIT4 (CODE)
15204 __mcs51_genRAMCLEAR::
15226 00004$:\InsetSpace ~
15240 ; _mcs51_genRAMCLEAR() end
15243 \begin_layout Verse
15251 \begin_layout Verse
15263 .area GSINIT4 (CODE)
15265 __mcs51_genXRAMCLEAR::
15316 mov __XPAGE,#(s_PSEG >> 8)
15328 00005$:\InsetSpace ~
15382 orl a,#(l_XSEG >> 8)
15425 00007$:\InsetSpace ~
15462 \begin_layout Verse
15470 \begin_layout Verse
15482 .area GSINIT5 (CODE)
15484 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15487 ; and __mcs51_genRAMCLEAR modifies _spx.
15497 mov __XPAGE,#(__start__x
15508 mov _spx,#__start__xstack
15511 \begin_layout Verse
15516 (application modules)
15519 \begin_layout Verse
15531 .area GSINIT (CODE)
15534 \begin_layout Verse
15542 \begin_layout Verse
15554 .area GSFINAL (CODE)
15564 ljmp __sdcc_program_startup
15566 ;---------------------------------
15567 -----------------------
15571 ;--------------------------------------------------
15594 __sdcc_program_startup:
15607 return from main will lock up
15620 \begin_layout Standard
15621 One of these modules (crtstart.asm) contains a call to the C routine
15623 _sdcc_external_startup()
15624 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15633 at the start of the CODE area.
15634 This routine is also in the runtime library
15635 \begin_inset LatexCommand \index{Runtime library}
15639 and returns 0 by default.
15640 If this routine returns a non-zero value, the static & global variable
15641 initialization will be skipped and the function main will be invoked.
15642 Otherwise static & global variables will be initialized before the function
15646 _sdcc_external_startup()
15648 routine to your program to override the default if you need to setup hardware
15649 or perform some other critical operation prior to static & global variable
15651 \begin_inset LatexCommand \index{Variable initialization}
15656 On some mcs51 variants xdata
15657 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15661 memory has to be explicitly enabled before it can be accessed or if the
15663 \begin_inset LatexCommand \index{watchdog}
15667 needs to be disabled, this is the place to do it.
15668 The startup code clears all internal data memory, 256 bytes by default,
15669 but from 0 to n-1 if
15675 \begin_layout Standard
15685 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15692 (recommended for Chipcon CC1010).
15695 \begin_layout Standard
15696 See also the compiler options
15702 \begin_layout Standard
15718 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15728 \begin_layout Standard
15740 \begin_inset LatexCommand \index{-\/-main-return}
15745 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15749 about MCS51-variants.
15750 \begin_inset VSpace bigskip
15756 \begin_layout Subsection
15760 \begin_layout Standard
15762 \begin_inset LatexCommand \index{HC08}
15766 startup code follows the same scheme as the MCS51 startup code.
15767 \begin_inset VSpace bigskip
15773 \begin_layout Subsection
15777 \begin_layout Standard
15779 \begin_inset LatexCommand \index{Z80}
15783 the startup code is inserted by linking with crt0.o which is generated from
15784 sdcc/device/lib/z80/crt0.s.
15785 If you need a different startup code you can use the compiler option
15794 \begin_layout Standard
15809 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15813 and provide your own crt0.o.
15815 \begin_inset VSpace bigskip
15821 \begin_layout Section
15822 Inline Assembler Code
15823 \begin_inset LatexCommand \index{Assembler routines}
15830 \begin_layout Subsection
15831 A Step by Step Introduction
15832 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15839 \begin_layout Standard
15840 Starting from a small snippet of c-code this example shows for the MCS51
15841 how to use inline assembly, access variables, a function parameter and
15842 an array in xdata memory.
15843 The example uses an MCS51 here but is easily adapted for other architectures.
15844 This is a buffer routine which should be optimized:
15847 \begin_layout Verse
15851 unsigned char __far
15852 \begin_inset LatexCommand \index{far (storage class)}
15857 \begin_inset LatexCommand \index{\_\_far (storage class)}
15862 \begin_inset LatexCommand \index{at}
15867 \begin_inset LatexCommand \index{\_\_at}
15871 (0x7f00) buf[0x100];
15872 \begin_inset LatexCommand \index{Aligned array}
15878 unsigned char head, tail;\InsetSpace ~
15896 \begin_inset LatexCommand \index{interrupt}
15948 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15960 void to_buffer( unsigned char c )
15968 if( head != (unsigned char)(tail-1)
15975 \begin_inset LatexCommand \index{promotion to signed int}
15980 \begin_inset LatexCommand \index{type promotion}
15985 \begin_inset Marginal
15988 \begin_layout Standard
16007 buf[ head++ ] = c;\InsetSpace ~
16023 /* access to a 256 byte aligned array */
16028 \begin_layout Standard
16029 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16030 then a corresponding buffer.asm file is generated.
16031 We define a new function
16035 in file buffer.c in which we cut and paste the generated code, removing
16036 unwanted comments and some ':'.
16038 \begin_inset Quotes sld
16046 \begin_inset Quotes srd
16050 \begin_inset Quotes sld
16058 \begin_inset Quotes srd
16065 \begin_layout Standard
16066 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16067 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16069 The latter is also used in the library functions.
16074 to the beginning and the end of the function body:
16077 \begin_layout Verse
16081 /* With a cut and paste from the .asm file, we have something to start with.
16087 function is not yet OK! (registers aren't saved) */
16089 void to_buffer_asm(
16099 \begin_inset LatexCommand \index{\_asm}
16104 \begin_inset LatexCommand \index{\_\_asm}
16118 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16124 \begin_inset LatexCommand \index{promotion to signed int}
16129 \begin_inset LatexCommand \index{type promotion}
16182 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16183 \begin_inset LatexCommand \index{Aligned array}
16249 \begin_inset LatexCommand \index{\_endasm}
16254 \begin_inset LatexCommand \index{\_\_endasm}
16263 \begin_layout Standard
16264 The new file buffer.c should compile with only one warning about the unreferenced
16265 function argument 'c'.
16266 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16267 (1) and finally have:
16270 \begin_layout Verse
16274 unsigned char __far __at(0x7f00) buf[0x100];
16276 unsigned char head, tail;
16287 void to_buffer( unsigned char c )
16296 head != (unsigned char)(tail-1) )
16325 c; // to avoid warning: unreferenced function argument
16332 \begin_inset LatexCommand \index{\_asm}
16337 \begin_inset LatexCommand \index{\_\_asm}
16351 ; save used registers here.
16362 ; If we were still using r2,r3 we would have to push them here.
16365 ; if( head != (unsigned char)(tail-1) )
16409 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16445 a,dpl \InsetSpace ~
16452 ; dpl holds lower byte of function argument
16464 dpl,_head \InsetSpace ~
16467 ; buf is 0x100 byte aligned so head can be used directly
16510 ; we could do an ANL _head,#0x0f here to use a
16511 smaller buffer (see above)
16523 ; restore used registers here
16530 \begin_inset LatexCommand \index{\_endasm}
16535 \begin_inset LatexCommand \index{\_\_endasm}
16546 \begin_layout Standard
16547 The inline assembler code can contain any valid code understood by the assembler
16548 , this includes any assembler directives and comment lines.
16549 The assembler does not like some characters like ':' or ''' in comments.
16550 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16551 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16556 \begin_inset LatexCommand \index{Assembler documentation}
16561 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16569 \begin_layout Standard
16570 The compiler does not do any validation of the code within the
16573 \begin_inset LatexCommand \index{\_asm}
16578 \begin_inset LatexCommand \index{\_\_asm}
16586 \begin_inset LatexCommand \index{\_endasm}
16591 \begin_inset LatexCommand \index{\_\_endasm}
16600 Specifically it will not know which registers are used and thus register
16602 \begin_inset LatexCommand \index{push/pop}
16606 has to be done manually.
16610 \begin_layout Standard
16611 It is recommended that each assembly instruction (including labels) be placed
16612 in a separate line (as the example shows).
16617 \begin_layout Standard
16629 \begin_inset LatexCommand \index{-\/-peep-asm}
16635 command line option is used, the inline assembler code will be passed through
16636 the peephole optimizer
16637 \begin_inset LatexCommand \index{Peephole optimizer}
16642 There are only a few (if any) cases where this option makes sense, it might
16643 cause some unexpected changes in the inline assembler code.
16644 Please go through the peephole optimizer rules defined in file
16648 before using this option.
16651 \begin_layout Subsection
16653 \begin_inset LatexCommand \label{sub:Naked-Functions}
16658 \begin_inset LatexCommand \index{Naked functions}
16665 \begin_layout Standard
16666 A special keyword may be associated with a function declaring it as
16669 \begin_inset LatexCommand \index{\_naked}
16674 \begin_inset LatexCommand \index{\_\_naked}
16685 function modifier attribute prevents the compiler from generating prologue
16686 \begin_inset LatexCommand \index{function prologue}
16691 \begin_inset LatexCommand \index{function epilogue}
16695 code for that function.
16696 This means that the user is entirely responsible for such things as saving
16697 any registers that may need to be preserved, selecting the proper register
16698 bank, generating the
16702 instruction at the end, etc.
16703 Practically, this means that the contents of the function must be written
16704 in inline assembler.
16705 This is particularly useful for interrupt functions, which can have a large
16706 (and often unnecessary) prologue/epilogue.
16707 For example, compare the code generated by these two functions:
16710 \begin_layout Verse
16714 \begin_inset LatexCommand \index{volatile}
16718 data unsigned char counter;
16722 void simpleInterrupt(void) __interrupt
16723 \begin_inset LatexCommand \index{interrupt}
16728 \begin_inset LatexCommand \index{\_\_interrupt}
16746 void nakedInterrupt(void) __interrupt (2) __naked
16755 \begin_inset LatexCommand \index{\_asm}
16760 \begin_inset LatexCommand \index{\_\_asm}
16777 _counter ; does not change flags, no need to save psw
16790 include ret or reti in _naked function.
16797 \begin_inset LatexCommand \index{\_endasm}
16802 \begin_inset LatexCommand \index{\_\_endasm}
16811 \begin_layout Standard
16812 For an 8051 target, the generated simpleInterrupt looks like:
16815 \begin_layout Verse
16822 example, recent versions of SDCC generate
16828 code for simpleInterrupt() and nakedInterrupt()!
16969 \begin_layout Standard
16970 whereas nakedInterrupt looks like:
16973 \begin_layout Verse
16986 _counter ; does not change flags, no need to save psw
17005 MUST explicitly include ret or reti in _naked function
17008 \begin_layout Standard
17009 The related directive #pragma exclude
17010 \begin_inset LatexCommand \index{\#pragma exclude}
17014 allows a more fine grained control over pushing & popping
17015 \begin_inset LatexCommand \index{push/pop}
17022 \begin_layout Standard
17023 While there is nothing preventing you from writing C code inside a
17027 function, there are many ways to shoot yourself in the foot doing this,
17028 and it is recommended that you stick to inline assembler.
17031 \begin_layout Subsection
17032 Use of Labels within Inline Assembler
17035 \begin_layout Standard
17036 SDCC allows the use of in-line assembler with a few restrictions regarding
17038 In older versions of the compiler all labels defined within inline assembler
17039 code had to be of the form
17043 where nnnnn is a number less than 100 (which implies a limit of utmost
17044 100 inline assembler labels
17055 \begin_layout Verse
17059 \begin_inset LatexCommand \index{\_asm}
17064 \begin_inset LatexCommand \index{\_\_asm}
17094 \begin_inset LatexCommand \index{\_endasm}
17099 \begin_inset LatexCommand \index{\_\_endasm}
17106 \begin_layout Standard
17107 Inline assembler code cannot reference any C-labels, however it can reference
17109 \begin_inset LatexCommand \index{Labels}
17113 defined by the inline assembler, e.g.:
17116 \begin_layout Verse
17139 ; some assembler code
17160 /* some more c code */
17162 clabel:\InsetSpace ~
17164 /* inline assembler cannot reference this
17177 $0003: ;label (can be referenced by inline assembler only)
17185 \begin_inset LatexCommand \index{\_endasm}
17190 \begin_inset LatexCommand \index{\_\_endasm}
17200 /* some more c code */
17205 \begin_layout Standard
17206 In other words inline assembly code can access labels defined in inline
17207 assembly within the scope of the function.
17208 The same goes the other way, i.e.
17209 labels defines in inline assembly can not be accessed by C statements.
17212 \begin_layout Section
17213 Interfacing with Assembler Code
17214 \begin_inset LatexCommand \index{Assembler routines}
17221 \begin_layout Subsection
17222 Global Registers used for Parameter Passing
17223 \begin_inset LatexCommand \index{Parameter passing}
17230 \begin_layout Standard
17231 The compiler always uses the global registers
17234 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17239 \begin_inset LatexCommand \index{DPTR}
17244 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17253 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17259 to pass the first parameter to a function, and also to pass the return
17261 \begin_inset LatexCommand \index{return value}
17265 of function; according to the following scheme: one byte return value in
17270 , two byte value in
17279 three byte values (generic pointers) in
17291 , and four byte values in
17309 \begin_inset LatexCommand \index{generic pointer}
17313 contain type of accessed memory in
17334 \begin_inset Note Note
17337 \begin_layout Standard
17338 This might not be the case of certain memory models (medium???)
17346 \begin_layout Standard
17347 The second parameter onwards is either allocated on the stack (for reentrant
17352 \begin_layout Standard
17361 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17365 \begin_layout Subsection
17369 \begin_layout Standard
17370 Unless the called function is declared as
17375 \begin_inset LatexCommand \index{naked}
17383 \begin_layout Standard
17393 \begin_inset LatexCommand \index{-\/-callee-saves}
17401 \begin_layout Standard
17410 -all-callee-saves command line option or the corresponding callee_saves
17411 pragma are used, the caller will save the registers (
17415 ) around the call, so the called function can destroy they content freely.
17418 \begin_layout Standard
17419 If the called function is not declared as
17423 , the caller will swap register banks around the call, if caller and callee
17424 use different register banks (having them defined by the
17432 \begin_layout Standard
17433 The called function can also use
17449 observing that they are used for parameter/return value passing.
17452 \begin_layout Subsection
17453 Assembler Routine (non-reentrant)
17456 \begin_layout Standard
17457 In the following example
17458 \begin_inset LatexCommand \index{reentrant}
17463 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17467 the function c_func calls an assembler routine asm_func, which takes two
17469 \begin_inset LatexCommand \index{function parameter}
17476 \begin_layout Verse
17479 extern int asm_func(unsigned char, unsigned char);
17483 int c_func (unsigned char
17484 i, unsigned char j)
17492 return asm_func(i,j);
17506 return c_func(10,9);
17511 \begin_layout Standard
17512 The corresponding assembler function is:
17515 \begin_layout Verse
17518 .globl _asm_func_PARM_2
17620 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17637 \begin_layout Standard
17638 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17639 the parameter number starting from 1, and counting from the left.
17640 The first parameter is passed in
17656 according to the description above.
17657 The variable name for the second parameter will be _<function_name>_PARM_2.
17662 ble the assembler routine with the following command:
17669 asx8051 -losg asmfunc.asm
17676 Then compile and link the assembler routine to the C source file with the
17684 sdcc cfunc.c asmfunc.rel
17687 \begin_layout Subsection
17688 Assembler Routine (reentrant)
17691 \begin_layout Standard
17693 \begin_inset LatexCommand \index{reentrant}
17698 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17702 the second parameter
17703 \begin_inset LatexCommand \index{function parameter}
17707 onwards will be passed on the stack, the parameters are pushed from right
17709 before the call the second leftmost parameter will be on the top of the
17710 stack (the leftmost parameter is passed in registers).
17711 Here is an example:
17714 \begin_layout Verse
17717 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17722 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
17731 return asm_func(i,j,k);
17745 return c_func(10,9,8);
17750 \begin_layout Standard
17751 The corresponding (unoptimized) assembler routine is:
17754 \begin_layout Verse
17774 _bp,sp\InsetSpace ~
17780 ;stack contains: _bp, return
17781 address, second parameter, third parameter
17805 a,#0xfd\InsetSpace ~
17811 pointer to the second parameter
17835 a,#0xfc\InsetSpace ~
17841 to the rightmost parameter
17882 result (= sum of all three parameters)
17897 ;return value goes into dptr
17931 \begin_layout Standard
17932 The compiling and linking procedure remains the same, however note the extra
17933 entry & exit linkage required for the assembler code, _bp is the stack
17934 frame pointer and is used to compute the offset into the stack for parameters
17935 and local variables.
17936 \begin_inset VSpace bigskip
17942 \begin_layout Section
17944 \begin_inset LatexCommand \index{int (16 bit)}
17949 \begin_inset LatexCommand \index{long (32 bit)}
17956 \begin_layout Standard
17957 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17958 multiplication and modulus operations are implemented by support routines.
17959 These support routines are all developed in ANSI-C to facilitate porting
17960 to other MCUs, although some model specific assembler optimizations are
17962 The following files contain the described routines, all of them can be
17963 found in <installdir>/share/sdcc/lib.
17968 \begin_layout Standard
17970 \begin_inset Tabular
17971 <lyxtabular version="3" rows="11" columns="2">
17973 <column alignment="left" valignment="top" leftline="true" width="0">
17974 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17975 <row topline="true" bottomline="true">
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17979 \begin_layout Standard
17987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17990 \begin_layout Standard
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_layout Standard
18009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18012 \begin_layout Standard
18013 16 bit multiplication
18019 <row topline="true">
18020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18023 \begin_layout Standard
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18032 \begin_layout Standard
18033 signed 16 bit division (calls _divuint)
18039 <row topline="true">
18040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18043 \begin_layout Standard
18049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18052 \begin_layout Standard
18053 unsigned 16 bit division
18059 <row topline="true">
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18063 \begin_layout Standard
18069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18072 \begin_layout Standard
18073 signed 16 bit modulus (calls _moduint)
18079 <row topline="true">
18080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18083 \begin_layout Standard
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18092 \begin_layout Standard
18093 unsigned 16 bit modulus
18099 <row topline="true">
18100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18103 \begin_layout Standard
18109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18112 \begin_layout Standard
18113 32 bit multiplication
18119 <row topline="true">
18120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18123 \begin_layout Standard
18129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18132 \begin_layout Standard
18133 signed 32 division (calls _divulong)
18139 <row topline="true">
18140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18143 \begin_layout Standard
18149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18152 \begin_layout Standard
18153 unsigned 32 division
18159 <row topline="true">
18160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18163 \begin_layout Standard
18169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18172 \begin_layout Standard
18173 signed 32 bit modulus (calls _modulong)
18179 <row topline="true" bottomline="true">
18180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18183 \begin_layout Standard
18189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18192 \begin_layout Standard
18193 unsigned 32 bit modulus
18208 \begin_layout Standard
18209 Since they are compiled as
18214 \begin_inset LatexCommand \index{reentrant}
18219 \begin_inset LatexCommand \index{interrupt}
18223 service routines should not do any of the above operations.
18224 If this is unavoidable then the above routines will need to be compiled
18231 \begin_layout Standard
18241 \begin_inset LatexCommand \index{-\/-stack-auto}
18247 option, after which the source program will have to be compiled with
18253 \begin_layout Standard
18263 \begin_inset LatexCommand \index{-\/-int-long-reent}
18270 Notice that you don't have to call these routines directly.
18271 The compiler will use them automatically every time an integer operation
18275 \begin_layout Section
18276 Floating Point Support
18277 \begin_inset LatexCommand \index{Floating point support}
18284 \begin_layout Standard
18285 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18286 The floating point support routines are derived from gcc's floatlib.c and
18287 consist of the following routines:
18292 \begin_layout Standard
18296 \begin_inset Tabular
18297 <lyxtabular version="3" rows="17" columns="2">
18299 <column alignment="left" valignment="top" leftline="true" width="0">
18300 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18301 <row topline="true" bottomline="true">
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18305 \begin_layout Standard
18320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18323 \begin_layout Standard
18330 <row topline="true">
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18334 \begin_layout Standard
18349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18352 \begin_layout Standard
18362 add floating point numbers
18368 <row topline="true">
18369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18372 \begin_layout Standard
18387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18390 \begin_layout Standard
18400 subtract floating point numbers
18406 <row topline="true">
18407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18410 \begin_layout Standard
18425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18428 \begin_layout Standard
18438 divide floating point numbers
18444 <row topline="true">
18445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18448 \begin_layout Standard
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18466 \begin_layout Standard
18476 multiply floating point numbers
18482 <row topline="true">
18483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18486 \begin_layout Standard
18501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18504 \begin_layout Standard
18514 convert floating point to unsigned char
18520 <row topline="true">
18521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18524 \begin_layout Standard
18539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18542 \begin_layout Standard
18552 convert floating point to signed char
18558 <row topline="true">
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18562 \begin_layout Standard
18577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18580 \begin_layout Standard
18590 convert floating point to unsigned int
18596 <row topline="true">
18597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18600 \begin_layout Standard
18615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18618 \begin_layout Standard
18628 convert floating point to signed int
18634 <row topline="true">
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18638 \begin_layout Standard
18661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18664 \begin_layout Standard
18674 convert floating point to unsigned long
18680 <row topline="true">
18681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18684 \begin_layout Standard
18699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18702 \begin_layout Standard
18712 convert floating point to signed long
18718 <row topline="true">
18719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18722 \begin_layout Standard
18737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18740 \begin_layout Standard
18750 convert unsigned char to floating point
18756 <row topline="true">
18757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18760 \begin_layout Standard
18775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18778 \begin_layout Standard
18788 convert char to floating point number
18794 <row topline="true">
18795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18798 \begin_layout Standard
18813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18816 \begin_layout Standard
18826 convert unsigned int to floating point
18832 <row topline="true">
18833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18836 \begin_layout Standard
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18854 \begin_layout Standard
18864 convert int to floating point numbers
18870 <row topline="true">
18871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18874 \begin_layout Standard
18889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18892 \begin_layout Standard
18902 convert unsigned long to floating point number
18908 <row topline="true" bottomline="true">
18909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18912 \begin_layout Standard
18927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18930 \begin_layout Standard
18940 convert long to floating point number
18955 \begin_layout Standard
18956 These support routines are developed in ANSI-C so there is room for space
18957 and speed improvement
18961 \begin_layout Standard
18962 These floating point routines (
18966 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18973 Note if all these routines are used simultaneously the data space might
18975 For serious floating point usage the large model might be needed.
18976 Also notice that you don't have to call this routines directly.
18977 The compiler will use them automatically every time a floating point operation
18979 \begin_inset VSpace bigskip
18985 \begin_layout Section
18987 \begin_inset LatexCommand \index{Libraries}
18994 \begin_layout Standard
18997 <pending: this is messy and incomplete - a little more information is in
18998 sdcc/doc/libdoc.txt
19003 \begin_layout Subsection
19004 Compiler support routines (_gptrget, _mulint etc.)
19007 \begin_layout Subsection
19008 Stdclib functions (puts, printf, strcat etc.)
19011 \begin_layout Subsubsection
19015 \begin_layout Paragraph
19016 getchar(), putchar()
19019 \begin_layout Standard
19020 \begin_inset LatexCommand \index{<stdio.h>}
19024 As usual on embedded systems you have to provide your own
19027 \begin_inset LatexCommand \index{getchar()}
19036 \begin_inset LatexCommand \index{putchar()}
19043 SDCC does not know whether the system connects to a serial line with or
19044 without handshake, LCD, keyboard or other device.
19058 You'll find examples for serial routines f.e.
19059 in sdcc/device/lib.
19060 For the mcs51 this minimalistic polling
19064 routine might be a start:
19067 \begin_layout Verse
19070 void putchar (char c) {
19076 while (!TI)\InsetSpace ~
19079 /* assumes UART is initialized */
19107 \begin_layout Paragraph
19111 \begin_layout Standard
19115 \begin_inset LatexCommand \index{printf()}
19125 does not support float (except on ds390).
19126 To enable this recompile it with the option
19132 \begin_layout Standard
19142 \begin_inset LatexCommand \index{USE\_FLOATS}
19148 on the command line.
19155 \begin_layout Standard
19165 \begin_inset LatexCommand \index{-\/-model-large}
19171 for the mcs51 port, since this uses a lot of memory.
19174 \begin_layout Standard
19175 If you're short on code memory you might want to use
19178 \begin_inset LatexCommand \index{printf\_small()}
19193 For the mcs51 there additionally are assembly versions
19196 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19202 (subset of printf using less than 270 bytes) and
19205 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19214 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19220 (floating-point aware version of printf_fast) which should fit the requirements
19221 of many embedded systems (printf_fast() can be customized by unsetting
19226 support long variables and field widths).
19227 Be sure to use only one of these printf options within a project.
19232 \begin_layout Standard
19233 Feature matrix of different
19240 \begin_layout Standard
19241 \begin_inset Tabular
19242 <lyxtabular version="3" rows="14" columns="7">
19243 <features islongtable="true">
19244 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19245 <column alignment="center" valignment="top" leftline="true" width="0">
19246 <column alignment="center" valignment="top" leftline="true" width="12col%">
19247 <column alignment="center" valignment="top" leftline="true" width="10col%">
19248 <column alignment="center" valignment="top" leftline="true" width="0">
19249 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19250 <column alignment="center" valignment="top" rightline="true" width="0">
19251 <row topline="true" bottomline="true" endhead="true">
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19255 \begin_layout Standard
19264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19267 \begin_layout Standard
19269 \begin_inset LatexCommand \index{printf}
19278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19281 \begin_layout Standard
19289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19292 \begin_layout Standard
19298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19301 \begin_layout Standard
19307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19310 \begin_layout Standard
19316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19319 \begin_layout Standard
19326 <row topline="true" endhead="true">
19327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19330 \begin_layout Standard
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19339 \begin_layout Standard
19347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19350 \begin_layout Standard
19358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19361 \begin_layout Standard
19369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19372 \begin_layout Standard
19380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19383 \begin_layout Standard
19391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19394 \begin_layout Standard
19403 <row topline="true" endhead="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_layout Standard
19408 \begin_inset Quotes sld
19412 \begin_inset Quotes srd
19418 \begin_layout Standard
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19427 \begin_layout Standard
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19436 \begin_layout Standard
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19445 \begin_layout Standard
19451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19454 \begin_layout Standard
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19463 \begin_layout Standard
19469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19472 \begin_layout Standard
19479 <row topline="true" endhead="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19483 \begin_layout Standard
19487 \begin_layout Standard
19493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19496 \begin_layout Standard
19502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19505 \begin_layout Standard
19511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19514 \begin_layout Standard
19515 0.45k / 0.47k (+ _ltoa)
19520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19523 \begin_layout Standard
19529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19532 \begin_layout Standard
19538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19541 \begin_layout Standard
19548 <row topline="true">
19549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19552 \begin_layout Standard
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19561 \begin_layout Standard
19571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19574 \begin_layout Standard
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_layout Standard
19663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19666 \begin_layout Standard
19672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19675 \begin_layout Standard
19681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19684 \begin_layout Standard
19691 <row topline="true">
19692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19695 \begin_layout Standard
19696 long (32 bit) support
19701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19704 \begin_layout Standard
19710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19713 \begin_layout Standard
19719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19722 \begin_layout Standard
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19731 \begin_layout Standard
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19740 \begin_layout Standard
19755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19758 \begin_layout Standard
19765 <row topline="true">
19766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19769 \begin_layout Standard
19770 byte arguments on stack
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19778 \begin_layout Standard
19784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19787 \begin_layout Standard
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19796 \begin_layout Standard
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19805 \begin_layout Standard
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19814 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_layout Standard
19830 <row topline="true">
19831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 \begin_layout Standard
19836 \begin_inset LatexCommand \index{Floating point support}
19845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19848 \begin_layout Standard
19854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19857 \begin_layout Standard
19863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19866 \begin_layout Standard
19872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19875 \begin_layout Standard
19881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19884 \begin_layout Standard
19889 \begin_layout Standard
19890 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19903 \begin_layout Standard
19910 <row topline="true">
19911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19914 \begin_layout Standard
19915 float formats %e %g
19920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19923 \begin_layout Standard
19929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19932 \begin_layout Standard
19938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19941 \begin_layout Standard
19947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19950 \begin_layout Standard
19956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19959 \begin_layout Standard
19965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19968 \begin_layout Standard
19975 <row topline="true" bottomline="true">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_layout Standard
19985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19988 \begin_layout Standard
19994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19997 \begin_layout Standard
20003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20006 \begin_layout Standard
20012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_layout Standard
20021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20024 \begin_layout Standard
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20033 \begin_layout Standard
20040 <row bottomline="true">
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20044 \begin_layout Standard
20049 \begin_layout Standard
20050 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20054 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20062 \begin_layout Standard
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20071 \begin_layout Standard
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20080 \begin_layout Standard
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20098 \begin_layout Standard
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20107 \begin_layout Standard
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20116 \begin_layout Standard
20123 <row bottomline="true">
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20127 \begin_layout Standard
20132 \begin_layout Standard
20133 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20142 \begin_layout Standard
20148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20151 \begin_layout Standard
20157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20160 \begin_layout Standard
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20169 \begin_layout Standard
20175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20178 \begin_layout Standard
20184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20187 \begin_layout Standard
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20196 \begin_layout Standard
20201 \begin_layout Standard
20202 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20213 <row bottomline="true">
20214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20217 \begin_layout Standard
20222 \begin_layout Standard
20223 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20232 \begin_layout Standard
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20241 \begin_layout Standard
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20250 \begin_layout Standard
20256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20259 \begin_layout Standard
20265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20268 \begin_layout Standard
20274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20277 \begin_layout Standard
20283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20286 \begin_layout Standard
20293 <row bottomline="true">
20294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20297 \begin_layout Standard
20302 \begin_layout Standard
20303 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20312 \begin_layout Standard
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20321 \begin_layout Standard
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_layout Standard
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 \begin_layout Standard
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20348 \begin_layout Standard
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_layout Standard
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20366 \begin_layout Standard
20380 \begin_layout Subsubsection
20382 \begin_inset LatexCommand \index{malloc.h}
20389 \begin_layout Standard
20390 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20391 using dynamic memory allocation
20392 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20397 \begin_inset LatexCommand \index{heap (malloc)}
20401 space of 1024 bytes is provided for malloc to allocate memory from.
20402 If you need a different heap size you need to recompile _heap.c with the
20403 required size defined in HEAP_SIZE.
20404 It is recommended to make a copy of this file into your project directory
20405 and compile it there with:
20408 \begin_layout Verse
20411 sdcc -c _heap.c -D HEAD_SIZE=2048
20414 \begin_layout Standard
20415 And then link it with:
20418 \begin_layout Verse
20421 sdcc main.rel _heap.rel
20424 \begin_layout Subsection
20425 Math functions (sinf, powf, sqrtf etc.)
20428 \begin_layout Subsubsection
20432 \begin_layout Standard
20433 See definitions in file <math.h>.
20436 \begin_layout Subsection
20440 \begin_layout Standard
20442 \begin_inset LatexCommand \index{Libraries}
20446 included in SDCC should have a license at least as liberal as the GNU Lesser
20447 General Public License
20448 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20459 \begin_layout Standard
20460 \begin_inset Note Note
20463 \begin_layout Standard
20464 license statements for the libraries are missing.
20465 sdcc/device/lib/ser_ir.c
20468 \begin_layout Standard
20470 come with a GPL (as opposed to LGPL) License - this will not be liberal
20471 enough for many embedded programmers.
20479 \begin_layout Standard
20480 If you have ported some library or want to share experience about some code
20482 falls into any of these categories Busses (I
20483 \begin_inset Formula $^{\textrm{2}}$
20486 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20487 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20488 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20489 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20494 would certainly like to hear about it.
20497 \begin_layout Standard
20498 Programmers coding for embedded systems are not especially famous for being
20499 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20500 e these references are very valuable.
20501 Let's help to create a climate where information is shared.
20502 \begin_inset VSpace bigskip
20508 \begin_layout Section
20512 \begin_layout Subsection
20513 MCS51 Memory Models
20514 \begin_inset LatexCommand \index{Memory model}
20519 \begin_inset LatexCommand \index{MCS51 memory model}
20526 \begin_layout Subsubsection
20527 Small, Medium and Large
20530 \begin_layout Standard
20531 SDCC allows three memory models for MCS51 code,
20540 Modules compiled with different memory models should
20544 be combined together or the results would be unpredictable.
20545 The library routines supplied with the compiler are compiled as small,
20547 The compiled library modules are contained in separate directories as small,
20548 medium and large so that you can link to the appropriate set.
20551 \begin_layout Standard
20552 When the medium or large model is used all variables declared without a
20553 storage class will be allocated into the external ram, this includes all
20554 parameters and local variables (for non-reentrant
20555 \begin_inset LatexCommand \index{reentrant}
20560 When the small model is used variables without storage class are allocated
20561 in the internal ram.
20564 \begin_layout Standard
20565 Judicious usage of the processor specific storage classes
20566 \begin_inset LatexCommand \index{Storage class}
20570 and the 'reentrant' function type will yield much more efficient code,
20571 than using the large model.
20572 Several optimizations are disabled when the program is compiled using the
20573 large model, it is therefore recommended that the small model be used unless
20574 absolutely required.
20577 \begin_layout Subsubsection
20579 \begin_inset LatexCommand \label{sub:External-Stack}
20584 \begin_inset LatexCommand \index{stack}
20589 \begin_inset LatexCommand \index{External stack (mcs51)}
20596 \begin_layout Standard
20597 The external stack (-
20601 \begin_layout Standard
20611 \begin_inset LatexCommand \index{-\/-xstack}
20615 ) is located in pdata
20616 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20620 memory (usually at the start of the external ram segment) and uses all
20621 unused space in pdata (max.
20627 \begin_layout Standard
20636 -xstack option is used to compile the program, the parameters and local
20638 \begin_inset LatexCommand \index{local variables}
20642 of all reentrant functions are allocated in this area.
20643 This option is provided for programs with large stack space requirements.
20644 When used with the -
20648 \begin_layout Standard
20658 \begin_inset LatexCommand \index{-\/-stack-auto}
20662 option, all parameters and local variables are allocated on the external
20663 stack (note: support libraries will need to be recompiled with the same
20665 There is a predefined target in the library makefile).
20668 \begin_layout Standard
20669 The compiler outputs the higher order address byte of the external ram segment
20671 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20676 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20680 ), therefore when using the External Stack option, this port
20684 be used by the application program.
20687 \begin_layout Subsection
20689 \begin_inset LatexCommand \index{Memory model}
20694 \begin_inset LatexCommand \index{DS390 memory model}
20701 \begin_layout Standard
20702 The only model supported is Flat 24
20703 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20708 This generates code for the 24 bit contiguous addressing mode of the Dallas
20710 In this mode, up to four meg of external RAM or code space can be directly
20712 See the data sheets at www.dalsemi.com for further information on this part.
20717 that the compiler does not generate any code to place the processor into
20718 24 bitmode (although
20722 in the ds390 libraries will do that for you).
20728 \begin_inset LatexCommand \index{Tinibios (DS390)}
20732 , the boot loader or similar code must ensure that the processor is in 24
20733 bit contiguous addressing mode before calling the SDCC startup code.
20744 \begin_layout Standard
20755 option, variables will by default be placed into the XDATA segment.
20760 Segments may be placed anywhere in the 4 meg address space using the usual
20765 \begin_layout Standard
20775 Note that if any segments are located above 64K, the -r flag must be passed
20776 to the linker to generate the proper segment relocations, and the Intel
20777 HEX output format must be used.
20778 The -r flag can be passed to the linker by using the option
20782 on the SDCC command line.
20783 However, currently the linker can not handle code segments > 64k.
20786 \begin_layout Section
20788 \begin_inset LatexCommand \label{sec:Pragmas}
20793 \begin_inset LatexCommand \index{Pragmas}
20800 \begin_layout Standard
20801 Pragmas are used to turn on and/or off certain compiler options.
20802 Some of them are closely related to corresponding command-line options
20804 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20810 Pragmas should be placed before and/or after a function, placing pragmas
20811 inside a function body could have unpredictable results.
20816 following #pragma directives:
20819 \begin_layout Itemize
20825 \begin_inset LatexCommand \index{\#pragma save}
20829 - this will save most current options to the save/restore stack.
20830 See #pragma\InsetSpace ~
20834 \begin_layout Itemize
20840 \begin_inset LatexCommand \index{\#pragma restore}
20844 - will restore saved options from the last save.
20845 saves & restores can be nested.
20846 SDCC uses a save/restore stack: save pushes current options to the stack,
20847 restore pulls current options from the stack.
20848 See #pragma\InsetSpace ~
20854 \begin_layout Itemize
20860 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20865 \begin_inset LatexCommand \index{function prologue}
20869 function1[,function2[,function3...]]
20870 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20874 - The compiler by default uses a caller saves convention for register saving
20875 across function calls, however this can cause unnecessary register pushing
20877 \begin_inset LatexCommand \index{push/pop}
20881 when calling small functions from larger functions.
20882 This option can be used to switch off the register saving convention for
20883 the function names specified.
20884 The compiler will not save registers when calling these functions, extra
20885 code need to be manually inserted at the entry and exit for these functions
20886 to save and restore the registers used by these functions, this can SUBSTANTIAL
20887 LY reduce code and improve run time performance of the generated code.
20888 In the future the compiler (with inter procedural analysis) may be able
20889 to determine the appropriate scheme to use for each function call.
20894 \begin_layout Standard
20903 -callee-saves command line option is used (see page
20904 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20908 ), the function names specified in #pragma\InsetSpace ~
20910 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20914 is appended to the list of functions specified in the command line.
20917 \begin_layout Itemize
20923 \begin_inset LatexCommand \index{\#pragma exclude}
20927 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20928 of pairs of push/pop
20929 \begin_inset LatexCommand \index{push/pop}
20938 \begin_inset LatexCommand \index{interrupt}
20951 The directive should be placed immediately before the ISR function definition
20952 and it affects ALL ISR functions following it.
20953 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20954 exclude\InsetSpace ~
20956 \begin_inset LatexCommand \index{\#pragma exclude}
20961 See also the related keyword _naked
20962 \begin_inset LatexCommand \index{\_naked}
20967 \begin_inset LatexCommand \index{\_\_naked}
20974 \begin_layout Itemize
20980 \begin_inset LatexCommand \index{pedantic}
20985 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20990 \begin_inset LatexCommand \label{ite:less_pedantic}
20994 - the compiler will not warn you anymore for obvious mistakes, you'r on
20996 See also the command line option -
21000 \begin_layout Standard
21010 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21017 More specifically, the following warnings will be disabled:
21019 comparison is always [true/false] due to limited range of data type
21023 overflow in implicit constant conversion
21025 (158); [the (in)famous]
21027 conditional flow changed by optimizer: so said EVELYN the modified DOG
21031 function '[function name]' must return value
21036 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21037 level) are disabled, too, namely:
21040 \begin_inset Note Note
21043 \begin_layout Standard
21044 dunno what comes here - this warning appears to be unused altogether
21053 [left/right] shifting more than size of object changed to zero
21061 integer overflow in expression
21065 unmatched #pragma save and #pragma restore
21069 comparison of 'signed char' with 'unsigned char' requires promotion to int
21073 ISO C90 does not support flexible array members
21077 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21081 \begin_inset Note Note
21084 \begin_layout Standard
21085 appears to be always blank - what was supposed to be here?
21094 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21095 complexity [number]
21100 \begin_layout Itemize
21106 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21110 - the compiler will not warn you anymore about warning number <nnnn>.
21112 \begin_inset Note Note
21115 \begin_layout Itemize
21116 \begin_inset Quotes sld
21119 For list of warnings and corresponding codes, see err_warn.txt
21120 \begin_inset Quotes srd
21123 This list should probably be part of the manual? See Patch #1697136
21131 \begin_layout Itemize
21137 \begin_inset LatexCommand \index{\#pragma nogcse}
21141 - will stop global common subexpression elimination.
21144 \begin_layout Itemize
21150 \begin_inset LatexCommand \index{\#pragma noinduction}
21154 - will stop loop induction optimizations.
21157 \begin_layout Itemize
21163 \begin_inset LatexCommand \index{\#pragma noinvariant}
21167 - will not do loop invariant optimizations.
21168 For more details see Loop Invariants in section
21169 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21176 \begin_layout Itemize
21182 \begin_inset LatexCommand \index{\#pragma noiv}
21186 - Do not generate interrupt
21187 \begin_inset LatexCommand \index{interrupt}
21192 \begin_inset LatexCommand \index{interrupt vector table}
21196 entries for all ISR functions defined after the pragma.
21197 This is useful in cases where the interrupt vector table must be defined
21198 manually, or when there is a secondary, manually defined interrupt vector
21200 for the autovector feature of the Cypress EZ-USB FX2).
21201 More elegantly this can be achieved by obmitting the optional interrupt
21202 number after the interrupt keyword, see section
21203 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21211 \begin_layout Itemize
21217 \begin_inset LatexCommand \index{\#pragma nojtbound}
21221 - will not generate code for boundary value checking, when switch statements
21222 are turned into jump-tables (dangerous).
21223 For more details see section
21224 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21231 \begin_layout Itemize
21237 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21241 - Will not do loop reversal optimization
21244 \begin_layout Itemize
21250 \begin_inset LatexCommand \index{\#pragma nooverlay}
21254 - the compiler will not overlay the parameters and local variables of a
21258 \begin_layout Itemize
21264 \begin_inset LatexCommand \index{\#pragma stackauto}
21272 \begin_layout Standard
21282 \begin_inset LatexCommand \index{-\/-stack-auto}
21287 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21291 Parameters and Local Variables.
21294 \begin_layout Itemize
21300 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21304 - The compiler will optimize code generation towards fast code, possibly
21305 at the expense of code size.
21306 Currently this has little effect.
21309 \begin_layout Itemize
21315 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21319 - The compiler will optimize code generation towards compact code, possibly
21320 at the expense of code speed.
21321 Currently this has little effect.
21324 \begin_layout Itemize
21330 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21334 - The compiler will attempt to generate code that is both compact and fast,
21335 as long as meeting one goal is not a detriment to the other (this is the
21340 \begin_layout Itemize
21346 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21350 - Generally follow the C89 standard, but allow SDCC features that conflict
21351 with the standard (default).
21354 \begin_layout Itemize
21360 \begin_inset LatexCommand \index{\#pragma std\_c89}
21364 - Follow the C89 standard and disable SDCC features that conflict with the
21368 \begin_layout Itemize
21374 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21378 - Generally follow the C99 standard, but allow SDCC features that conflict
21379 with the standard (incomplete support).
21382 \begin_layout Itemize
21388 \begin_inset LatexCommand \index{\#pragma std\_c99}
21392 - Follow the C99 standard and disable SDCC features that conflict with the
21393 standard (incomplete support).
21396 \begin_layout Itemize
21402 \begin_inset LatexCommand \index{\#pragma codeseg}
21406 - Use this name (max.
21407 8 characters) for the code segment.
21412 \begin_layout Standard
21424 \begin_layout Itemize
21430 \begin_inset LatexCommand \index{\#pragma constseg}
21434 - Use this name (max.
21435 8 characters) for the const segment.
21440 \begin_layout Standard
21452 \begin_layout Standard
21453 The preprocessor SDCPP
21454 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21458 supports the following #pragma directives:
21461 \begin_layout Itemize
21464 pedantic_parse_number
21467 \begin_inset LatexCommand \index{pedantic}
21472 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21477 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21481 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21482 properly and the macro LO_B(3) gets expanded.
21488 \begin_layout Standard
21497 -pedantic-parse-number command line option
21498 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21505 Below is an example on how to use this pragma.
21508 Note: this functionality is not in conformance with standard!
21511 \begin_layout Verse
21514 #pragma pedantic_parse_number +
21515 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21523 #define LO_B(x) ((x) & 0xff)
21527 unsigned char foo(void)
21534 unsigned char c=0xfe-LO_B(3)
21549 \begin_layout Itemize
21555 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21559 (+ | -) - switch _asm _endasm block preprocessing on / off.
21561 You use this prama to define multilines of assembly code.
21562 This will prevent the preprocessor from changing the formating required
21564 Below is an example on how to use this pragma.
21567 \begin_layout Verse
21570 #pragma preproc_asm -
21571 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21577 #define MYDELAY _asm
21582 nop ;my assembly comment...
21596 #pragma preproc_asm
21627 \begin_layout Itemize
21633 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21637 (+ | -) - Allow "naked" hash in macro definition, for example:
21641 #define DIR_LO(x) #(x & 0xff)
21646 Below is an example on how to use this pragma.
21649 \begin_layout Verse
21652 #pragma preproc_asm +
21654 #pragma sdcc_hash +
21655 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21670 mov R6_B3, #(x & 0xff)
21677 mov R7_B3, #((x >> 8) & 0xff)
21701 \begin_layout Standard
21702 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21703 ons which might cause the compiler to generate extra stack and/or data space
21704 to store compiler generated temporary variables.
21705 This usually happens in large functions.
21706 Pragma directives should be used as shown in the following example, they
21707 are used to control options and optimizations for a given function.
21711 \begin_layout Verse
21715 \begin_inset LatexCommand \index{\#pragma save}
21726 /* save the current settings */
21729 \begin_inset LatexCommand \index{\#pragma nogcse}
21738 /* turnoff global subexpression elimination */
21740 #pragma noinduction
21741 \begin_inset LatexCommand \index{\#pragma noinduction}
21745 /* turn off induction optimizations */
21768 \begin_inset LatexCommand \index{\#pragma restore}
21772 /* turn the optimizations back on */
21775 \begin_layout Standard
21776 The compiler will generate a warning message when extra space is allocated.
21777 It is strongly recommended that the save and restore pragma's be used when
21778 changing options for a function.
21787 \begin_layout Section
21788 Defines Created by the Compiler
21791 \begin_layout Standard
21792 The compiler creates the following #defines
21793 \begin_inset LatexCommand \index{\#defines}
21798 \begin_inset LatexCommand \index{Defines created by the compiler}
21807 \begin_layout Standard
21808 \begin_inset Tabular
21809 <lyxtabular version="3" rows="11" columns="2">
21811 <column alignment="left" valignment="top" leftline="true" width="3in">
21812 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21813 <row topline="true" bottomline="true">
21814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21817 \begin_layout Standard
21825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21828 \begin_layout Standard
21837 <row topline="true">
21838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21841 \begin_layout Standard
21843 \begin_inset LatexCommand \index{SDCC}
21852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21855 \begin_layout Standard
21857 Since version 2.5.6 the version number as an int (ex.
21864 <row topline="true">
21865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21868 \begin_layout Standard
21870 \begin_inset LatexCommand \index{SDCC\_mcs51}
21875 \begin_inset LatexCommand \index{SDCC\_ds390}
21880 \begin_inset LatexCommand \index{SDCC\_z80}
21889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21892 \begin_layout Standard
21893 depending on the model used (e.g.: -mds390)
21899 <row topline="true">
21900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21903 \begin_layout Standard
21905 \begin_inset LatexCommand \index{\_\_mcs51}
21910 \begin_inset LatexCommand \index{\_\_ds390}
21915 \begin_inset LatexCommand \index{\_\_hc08}
21920 \begin_inset LatexCommand \index{\_\_z80}
21929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21932 \begin_layout Standard
21933 depending on the model used (e.g.
21940 <row topline="true">
21941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21944 \begin_layout Standard
21946 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21958 \begin_layout Standard
21965 \begin_layout Standard
21982 <row topline="true">
21983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21986 \begin_layout Standard
21988 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22000 \begin_layout Standard
22007 \begin_layout Standard
22024 <row topline="true">
22025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22028 \begin_layout Standard
22030 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22042 \begin_layout Standard
22049 \begin_layout Standard
22066 <row topline="true">
22067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22070 \begin_layout Standard
22072 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22084 \begin_layout Standard
22091 \begin_layout Standard
22108 <row topline="true">
22109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22112 \begin_layout Standard
22114 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22126 \begin_layout Standard
22133 \begin_layout Standard
22150 <row topline="true">
22151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22154 \begin_layout Standard
22156 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22168 \begin_layout Standard
22179 <row topline="true" bottomline="true">
22180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22183 \begin_layout Standard
22185 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22197 \begin_layout Standard
22215 \begin_layout Chapter
22216 Notes on supported Processors
22219 \begin_layout Section
22221 \begin_inset LatexCommand \label{sub:MCS51-variants}
22226 \begin_inset LatexCommand \index{MCS51 variants}
22233 \begin_layout Standard
22234 MCS51 processors are available from many vendors and come in many different
22236 While they might differ considerably in respect to Special Function Registers
22237 the core MCS51 is usually not modified or is kept compatible.
22241 \begin_layout Subsection
22242 pdata access by SFR
22245 \begin_layout Standard
22246 With the upcome of devices with internal xdata and flash memory devices
22248 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22252 as dedicated I/O port is becoming more popular.
22253 Switching the high byte for pdata
22254 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22258 access which was formerly done by port P2 is then achieved by a Special
22260 \begin_inset LatexCommand \index{sfr}
22265 In well-established MCS51 tradition the address of this
22269 is where the chip designers decided to put it.
22270 Needless to say that they didn't agree on a common name either.
22271 So that the startup code can correctly initialize xdata variables, you
22272 should define an sfr with the name _XPAGE
22275 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22281 at the appropriate location if the default, port P2, is not used for this.
22285 \begin_layout Verse
22288 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22292 \begin_layout Verse
22295 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22300 \begin_layout Verse
22303 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22307 \begin_layout Verse
22310 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22314 \begin_layout Verse
22317 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22321 \begin_layout Standard
22322 For more exotic implementations further customizations may be needed.
22324 \begin_inset LatexCommand \ref{sub:Startup-Code}
22328 for other possibilities.
22331 \begin_layout Subsection
22332 Other Features available by SFR
22335 \begin_layout Standard
22336 Some MCS51 variants offer features like Double DPTR
22337 \begin_inset LatexCommand \index{DPTR}
22341 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22342 These are currently not used for the MCS51 port.
22343 If you absolutely need them you can fall back to inline assembly or submit
22345 \begin_inset VSpace bigskip
22351 \begin_layout Section
22355 \begin_layout Standard
22357 \begin_inset LatexCommand \index{DS80C400}
22362 \begin_inset LatexCommand \index{DS400}
22366 microcontroller has a rich set of peripherals.
22367 In its built-in ROM library it includes functions to access some of the
22368 features, among them is a TCP stack with IP4 and IP6 support.
22369 Library headers (currently in beta status) and other files are provided
22373 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22379 \begin_inset VSpace bigskip
22385 \begin_layout Section
22386 The Z80 and gbz80 port
22389 \begin_layout Standard
22390 SDCC can target both the Zilog Z80
22391 \begin_inset LatexCommand \index{Z80}
22395 and the Nintendo Gameboy's Z80-like gbz80
22396 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22401 The Z80 port is passed through the same
22404 \begin_inset LatexCommand \index{Regression test}
22411 \begin_inset LatexCommand \ref{sec:Quality-control}
22415 ) as the MCS51 and DS390 ports, so floating point support, support for long
22416 variables and bitfield support is fine.
22417 See mailing lists and forums about interrupt routines.
22420 \begin_layout Standard
22421 As always, the code is the authoritative reference - see z80/ralloc.c and
22424 \begin_inset LatexCommand \index{Z80!stack}
22428 frame is similar to that generated by the IAR Z80 compiler.
22429 IX is used as the base pointer, HL and IY are used as a temporary registers,
22430 and BC and DE are available for holding variables.
22432 \begin_inset LatexCommand \index{Z80!return value}
22436 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22438 The gbz80 port use the same set of registers for the return values, but
22439 in a different order of significance: E (one byte), DE (two bytes), or
22441 \begin_inset VSpace bigskip
22447 \begin_layout Section
22451 \begin_layout Standard
22452 The port to the Freescale/Motorola HC08
22453 \begin_inset LatexCommand \index{HC08}
22457 family has been added in October 2003, and is still undergoing some basic
22459 The code generator is complete, but the register allocation is still quite
22461 Some of the SDCC's standard C library functions have embedded non-HC08
22462 inline assembly and so are not yet usable.
22465 \begin_layout Standard
22466 The HC08 port passes the regression test suite (see section
22467 \begin_inset LatexCommand \ref{sec:Quality-control}
22472 \begin_inset VSpace bigskip
22480 \begin_layout Section
22484 \begin_layout Standard
22486 \begin_inset LatexCommand \index{PIC14}
22490 port still requires a major effort from the development community.
22491 However it can work for simple code.
22492 It passes its (smaller set of) regression tests
22493 \begin_inset LatexCommand \index{Regression test (PIC14)}
22499 sdcc/src/regression
22504 \begin_layout Subsection
22505 C code and 14bit PIC code page
22506 \begin_inset LatexCommand \index{code page (pic14)}
22511 \begin_inset LatexCommand \index{RAM bank (pic14)}
22518 \begin_layout Standard
22519 The linker organizes allocation for the code page and RAM banks.
22520 It does not have intimate knowledge of the code flow.
22521 It will put all the code section of a single asm file into a single code
22523 In order to make use of multiple code pages, separate asm files must be
22525 The compiler treats all functions of a single C file as being in the same
22526 code page unless it is non static.
22530 To get the best follow these guide lines:
22533 \begin_layout Enumerate
22534 Make local functions static, as non static functions require code page selection
22538 \begin_layout Enumerate
22539 For devices that have multiple code pages it is more efficient to use the
22540 same number of files as pages, i.e.
22541 for the 16F877 use 4 separate files and i.e.
22542 for the 16F874 use 2 separate files.
22543 This way the linker can put the code for each file into different code
22544 pages and there's less page selection overhead.
22547 \begin_layout Enumerate
22548 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22549 instruction set), use 'unsigned char' whereever possible instead of 'int'.
22552 \begin_layout Subsection
22553 Creating a device include file
22556 \begin_layout Standard
22557 For generating a device include file
22558 \begin_inset LatexCommand \index{PIC14!Header files}
22562 use the support perl script inc2h.pl kept in directory support/script.
22565 \begin_layout Subsection
22569 \begin_layout Standard
22570 For the interrupt function, use the keyword '__interrupt'
22571 \begin_inset LatexCommand \index{PIC14!interrupt}
22575 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22576 there to avoid a syntax error - it ought to be fixed).
22580 \begin_layout Verse
22583 void Intr(void) __interrupt 0
22589 T0IF = 0; /* Clear timer interrupt */
22594 \begin_layout Subsection
22595 Linking and assembling
22598 \begin_layout Standard
22599 For assembling you can use either GPUTILS'
22600 \begin_inset LatexCommand \index{gputils (pic tools)}
22604 gpasm.exe or MPLAB's mpasmwin.exe.
22605 GPUTILS is available from
22606 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22611 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22612 If you use MPLAB and an interrupt function then the linker script file
22613 vectors section will need to be enlarged to link with mplink.
22624 \begin_layout Verse
22637 sdcc -S -V -mpic14 -p16F877 $<
22651 $(PRJ).hex: $(OBJS)
22662 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22665 \begin_layout Standard
22673 \begin_layout Verse
22686 sdcc -S -V -mpic14 -p16F877 $<
22696 mpasmwin /q /o $*.asm
22700 $(PRJ).hex: $(OBJS)
22711 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22714 \begin_layout Standard
22715 Please note that indentations within a
22719 have to be done with a tabulator character.
22722 \begin_layout Subsection
22723 Command-line options
22726 \begin_layout Standard
22727 Besides the switches common to all SDCC backends, the PIC14 port accepts
22728 the following options (for an updated list see sdcc -
22732 \begin_layout Standard
22745 \labelwidthstring 00.00.0000
22750 \begin_layout Standard
22760 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22764 emit debug info in assembly output
22768 \labelwidthstring 00.00.0000
22773 \begin_layout Standard
22783 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22787 disable (slightly faulty) optimization on pCode
22791 \labelwidthstring 00.00.0000
22796 \begin_layout Standard
22806 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22810 sets the lowest address of the argument passing stack (defaults to a suitably
22811 large shared databank to reduce BANKSEL overhead)
22815 \labelwidthstring 00.00.0000
22820 \begin_layout Standard
22830 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22834 sets the size if the argument passing stack (default: 16, minimum: 4)
22837 \begin_layout Subsection
22841 \begin_layout Subsubsection
22842 error: missing definition for symbol
22843 \begin_inset Quotes sld
22847 \begin_inset Quotes srd
22853 \begin_layout Standard
22854 The PIC14 port uses library routines to provide more complex operations
22855 like multiplication, division/modulus and (generic) pointer dereferencing.
22856 In order to add these routines to your project, you must link with PIC14's
22862 For single source file projects this is done automatically, more complex
22867 to the linker's arguments.
22868 Make sure you also add an include path for the library (using the -I switch
22872 \begin_layout Subsubsection
22873 Processor mismatch in file
22874 \begin_inset Quotes sld
22878 \begin_inset Quotes srd
22884 \begin_layout Standard
22885 This warning can usually be ignored due to the very good compatibility amongst
22887 \begin_inset LatexCommand \index{PIC14}
22894 \begin_layout Standard
22895 You might also consider recompiling the library for your specific device
22896 by changing the ARCH=p16f877 (default target) entry in
22898 device/lib/pic/Makefile.in
22902 device/lib/pic/Makefile
22904 to reflect your device.
22905 This might even improve performance for smaller devices as unneccesary
22906 BANKSELs migth be removed.
22909 \begin_layout Subsection
22913 \begin_layout Subsubsection
22917 \begin_layout Standard
22918 Currently, data can only be initialized if it resides in the source file
22924 Data in other source files will silently
22932 \begin_inset Marginal
22935 \begin_layout Standard
22951 \begin_layout Section
22953 \begin_inset LatexCommand \index{PIC16}
22960 \begin_layout Standard
22962 \begin_inset LatexCommand \index{PIC16}
22966 port is the portion of SDCC that is responsible to produce code for the
22968 \begin_inset LatexCommand \index{Microchip}
22972 (TM) microcontrollers with 16 bit core.
22973 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22974 Currently supported devices are:
22977 \begin_layout Standard
22979 \begin_inset Tabular
22980 <lyxtabular version="3" rows="4" columns="6">
22982 <column alignment="center" valignment="top" leftline="true" width="0">
22983 <column alignment="center" valignment="top" leftline="true" width="0">
22984 <column alignment="center" valignment="top" leftline="true" width="0">
22985 <column alignment="center" valignment="top" leftline="true" width="0">
22986 <column alignment="center" valignment="top" leftline="true" width="0">
22987 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22988 <row topline="true">
22989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22992 \begin_layout Standard
22998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23001 \begin_layout Standard
23007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23010 \begin_layout Standard
23016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23019 \begin_layout Standard
23025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23028 \begin_layout Standard
23034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23037 \begin_layout Standard
23044 <row topline="true">
23045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23048 \begin_layout Standard
23054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23057 \begin_layout Standard
23063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23066 \begin_layout Standard
23072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23075 \begin_layout Standard
23081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23084 \begin_layout Standard
23090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23093 \begin_layout Standard
23100 <row topline="true">
23101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23104 \begin_layout Standard
23110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23113 \begin_layout Standard
23119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23122 \begin_layout Standard
23128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23131 \begin_layout Standard
23137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23140 \begin_layout Standard
23146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23149 \begin_layout Standard
23156 <row topline="true" bottomline="true">
23157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23160 \begin_layout Standard
23166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23169 \begin_layout Standard
23175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23178 \begin_layout Standard
23184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23187 \begin_layout Standard
23193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23196 \begin_layout Standard
23202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23205 \begin_layout Standard
23219 \begin_layout Subsection
23223 \begin_layout Standard
23224 PIC16 port supports the standard command line arguments as supposed, with
23225 the exception of certain cases that will be mentioned in the following
23230 \labelwidthstring 00.00.0000
23235 \begin_layout Standard
23245 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23253 \begin_layout Standard
23266 \labelwidthstring 00.00.0000
23271 \begin_layout Standard
23280 -fommit-frame-pointer
23281 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23285 Frame pointer will be omitted when the function uses no local variables.
23288 \begin_layout Subsection
23289 Port Specific Options
23290 \begin_inset LatexCommand \index{Options PIC16}
23297 \begin_layout Standard
23298 The port specific options appear after the global options in the sdcc --help
23302 \begin_layout Subsubsection
23306 \begin_layout Standard
23307 General options enable certain port features and optimizations.
23311 \labelwidthstring 00.00.0000
23316 \begin_layout Standard
23325 -pstack-model=[model] Used in conjuction with the command above.
23326 Defines the stack model to be used, valid stack models are :
23331 \labelwidthstring 00.00.0000
23336 Selects small stack model.
23337 8 bit stack and frame pointers.
23338 Supports 256 bytes stack size.
23342 \labelwidthstring 00.00.0000
23347 Selects large stack model.
23348 16 bit stack and frame pointers.
23349 Supports 65536 bytes stack size.
23354 \labelwidthstring 00.00.0000
23359 \begin_layout Standard
23368 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23369 unitialized data variables with [kword].
23370 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23374 \labelwidthstring 00.00.0000
23379 \begin_layout Standard
23388 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23389 Useful for bootloaders.
23393 \labelwidthstring 00.00.0000
23398 \begin_layout Standard
23407 -asm= sets the full path and name of an external assembler to call.
23411 \labelwidthstring 00.00.0000
23416 \begin_layout Standard
23425 -link= sets the full path and name of an external linker to call.
23429 \labelwidthstring 00.00.0000
23434 \begin_layout Standard
23444 \begin_inset LatexCommand \index{PIC16!MPLAB}
23448 compatibility option.
23449 Currently only suppresses special gpasm directives.
23452 \begin_layout Subsubsection
23453 Optimization Options
23457 \labelwidthstring 00.00.0000
23462 \begin_layout Standard
23471 -optimize-goto Try to use (conditional) BRA instead of GOTO
23475 \labelwidthstring 00.00.0000
23480 \begin_layout Standard
23489 -optimize-cmp Try to optimize some compares.
23493 \labelwidthstring 00.00.0000
23498 \begin_layout Standard
23507 -optimize-df Analyze the dataflow of the generated code and improve it.
23511 \labelwidthstring 00.00.0000
23516 \begin_layout Standard
23525 -obanksel=nn Set optimization level for inserting BANKSELs.
23532 \labelwidthstring 00.00.0000
23537 \labelwidthstring 00.00.0000
23538 1 checks previous used register and if it is the same then does not emit
23539 BANKSEL, accounts only for labels.
23543 \labelwidthstring 00.00.0000
23544 2 tries to check the location of (even different) symbols and removes BANKSELs
23545 if they are in the same bank.
23550 Important: There might be problems if the linker script has data sections
23551 across bank borders!
23555 \begin_layout Subsubsection
23560 \labelwidthstring 00.00.0000
23565 \begin_layout Standard
23574 -nodefaultlibs do not link default libraries when linking
23578 \labelwidthstring 00.00.0000
23583 \begin_layout Standard
23592 -no-crt Don't link the default run-time modules
23596 \labelwidthstring 00.00.0000
23601 \begin_layout Standard
23610 -use-crt= Use a custom run-time module instead of the defaults.
23613 \begin_layout Subsubsection
23617 \begin_layout Standard
23618 Debugging options enable extra debugging information in the output files.
23622 \labelwidthstring 00.00.0000
23627 \begin_layout Standard
23636 -debug-xtra Similar to -
23640 \begin_layout Standard
23650 \begin_inset LatexCommand \index{-\/-debug}
23654 , but dumps more information.
23658 \labelwidthstring 00.00.0000
23663 \begin_layout Standard
23672 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23674 <source> is the name of the file compiled.
23678 \labelwidthstring 00.00.0000
23683 \begin_layout Standard
23692 -pcode-verbose Enable pcode debugging information in translation.
23696 \labelwidthstring 00.00.0000
23701 \begin_layout Standard
23710 -denable-peeps Force the usage of peepholes.
23715 \labelwidthstring 00.00.0000
23720 \begin_layout Standard
23729 -gstack Trace push/pops for stack pointer overflow
23733 \labelwidthstring 00.00.0000
23738 \begin_layout Standard
23747 -call-tree dump call tree in .calltree file
23750 \begin_layout Subsection
23751 Enviromental Variables
23754 \begin_layout Standard
23755 There is a number of enviromental variables that can be used when running
23756 SDCC to enable certain optimizations or force a specific program behaviour.
23757 these variables are primarily for debugging purposes so they can be enabled/dis
23761 \begin_layout Standard
23762 Currently there is only two such variables available:
23766 \labelwidthstring 00.00.0000
23767 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23768 bitfields is optimized by directly loading FSR0 with the address of the
23769 bitfield structure.
23770 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23772 This step saves data ram and code space for functions that perform heavy
23775 80 bytes of code space are saved when compiling malloc.c with this option).
23780 \labelwidthstring 00.00.0000
23781 NO_REG_OPT do not perform pCode registers optimization.
23782 This should be used for debugging purposes.
23783 In some where bugs in the pcode optimizer are found, users can benefit
23784 from temporarily disabling the optimizer until the bug is fixed.
23787 \begin_layout Subsection
23788 Preprocessor Macros
23791 \begin_layout Standard
23793 \begin_inset LatexCommand \index{PIC16}
23797 port defines the following preprocessor macros while translating a source.
23800 \begin_layout Standard
23802 \begin_inset Tabular
23803 <lyxtabular version="3" rows="6" columns="2">
23805 <column alignment="center" valignment="top" leftline="true" width="0">
23806 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23807 <row topline="true" bottomline="true">
23808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23811 \begin_layout Standard
23817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23820 \begin_layout Standard
23827 <row topline="true">
23828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23831 \begin_layout Standard
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23840 \begin_layout Standard
23841 Port identification
23847 <row topline="true">
23848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23851 \begin_layout Standard
23856 \begin_layout Standard
23870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23873 \begin_layout Standard
23874 Port identification (same as above)
23880 <row topline="true">
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23884 \begin_layout Standard
23890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23893 \begin_layout Standard
23894 MCU Identification.
23899 is the microcontrol identification number, i.e.
23906 <row topline="true">
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 \begin_layout Standard
23915 \begin_layout Standard
23929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23932 \begin_layout Standard
23933 MCU Identification (same as above)
23939 <row topline="true" bottomline="true">
23940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23943 \begin_layout Standard
23949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23952 \begin_layout Standard
23953 nnn = SMALL or LARGE respectively according to the stack model used
23966 \begin_layout Standard
23967 In addition the following macros are defined when calling assembler:
23970 \begin_layout Standard
23972 \begin_inset Tabular
23973 <lyxtabular version="3" rows="4" columns="2">
23975 <column alignment="center" valignment="top" leftline="true" width="0">
23976 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23977 <row topline="true" bottomline="true">
23978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23981 \begin_layout Standard
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23990 \begin_layout Standard
23997 <row topline="true">
23998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24001 \begin_layout Standard
24007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24010 \begin_layout Standard
24011 MCU Identification.
24016 is the microcontrol identification number, i.e.
24023 <row topline="true">
24024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24027 \begin_layout Standard
24033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24036 \begin_layout Standard
24037 nnn = SMALL or LARGE respectively according to the memory model used for
24044 <row topline="true" bottomline="true">
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24048 \begin_layout Standard
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24057 \begin_layout Standard
24058 nnn = SMALL or LARGE respectively according to the stack model used
24071 \begin_layout Subsection
24075 \begin_layout Standard
24077 \begin_inset LatexCommand \index{PIC16}
24081 port uses the following directories for searching header files and libraries.
24084 \begin_layout Standard
24086 \begin_inset Tabular
24087 <lyxtabular version="3" rows="3" columns="4">
24089 <column alignment="center" valignment="top" leftline="true" width="0">
24090 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24091 <column alignment="center" valignment="top" width="0">
24092 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24093 <row topline="true" bottomline="true">
24094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24097 \begin_layout Standard
24103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24106 \begin_layout Standard
24112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24115 \begin_layout Standard
24121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24124 \begin_layout Standard
24131 <row topline="true">
24132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24135 \begin_layout Standard
24136 PREFIX/sdcc/include/pic16
24141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24144 \begin_layout Standard
24145 PIC16 specific headers
24150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24153 \begin_layout Standard
24159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24162 \begin_layout Standard
24169 <row topline="true" bottomline="true">
24170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24173 \begin_layout Standard
24174 PREFIX/sdcc/lib/pic16
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24182 \begin_layout Standard
24183 PIC16 specific libraries
24188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24191 \begin_layout Standard
24197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24200 \begin_layout Standard
24214 \begin_layout Subsection
24216 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24223 \begin_layout Standard
24225 \begin_inset LatexCommand \index{PIC16}
24229 port currently supports the following pragmas:
24233 \labelwidthstring 00.00.0000
24235 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24240 \begin_inset LatexCommand \index{PIC16!stack}
24244 forces the code generator to initialize the stack & frame pointers at a
24246 This is an adhoc solution for cases where no STACK directive is available
24247 in the linker script or gplink is not instructed to create a stack section.
24250 stack pragma should be used only once in a project.
24251 Multiple pragmas may result in indeterminate behaviour of the program.
24255 \begin_layout Standard
24256 The old format (ie.
24257 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24258 cross page boundaries (or even exceed the available data RAM) and crash
24260 Make sure that stack does not cross page boundaries when using the SMALL
24268 The format is as follows:
24271 \begin_layout LyX-Code
24272 #pragma stack bottom_address [stack_size]
24275 \begin_layout Standard
24280 is the lower bound of the stack section.
24281 The stack pointer initially will point at address (bottom_address+stack_size-1).
24284 \begin_layout LyX-Code
24288 \begin_layout LyX-Code
24292 \begin_layout LyX-Code
24293 /* initializes stack of 100 bytes at RAM address 0x200 */
24296 \begin_layout LyX-Code
24297 #pragma stack 0x200 100
24300 \begin_layout Standard
24301 If the stack_size field is omitted then a stack is created with the default
24303 This size might be enough for most programs, but its not enough for operations
24304 with deep function nesting or excessive stack usage.
24308 \labelwidthstring 00.00.0000
24310 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24314 place a function symbol at static FLASH address
24317 \begin_layout LyX-Code
24321 \begin_layout LyX-Code
24325 \begin_layout LyX-Code
24326 /* place function test_func at 0x4000 */
24329 \begin_layout LyX-Code
24330 #pragma code test_func 0x4000
24333 \begin_layout LyX-Code
24338 \labelwidthstring 00.00.0000
24339 library instructs the linker to use a library module.
24344 \begin_layout LyX-Code
24345 #pragma library module_name
24348 \begin_layout Standard
24353 can be any library or object file (including its path).
24354 Note that there are four reserved keywords which have special meaning.
24358 \begin_layout Standard
24360 \begin_inset Tabular
24361 <lyxtabular version="3" rows="6" columns="3">
24363 <column alignment="center" valignment="top" leftline="true" width="0">
24364 <column alignment="block" valignment="top" leftline="true" width="20page%">
24365 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24366 <row topline="true" bottomline="true">
24367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24370 \begin_layout Standard
24376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24379 \begin_layout Standard
24385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24388 \begin_layout Standard
24395 <row topline="true">
24396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24399 \begin_layout Standard
24407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24410 \begin_layout Standard
24411 ignore all library pragmas
24416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24419 \begin_layout Standard
24428 <row topline="true">
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24432 \begin_layout Standard
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24443 \begin_layout Standard
24449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24452 \begin_layout Standard
24463 <row topline="true">
24464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24467 \begin_layout Standard
24475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24478 \begin_layout Standard
24479 link the Math libarary
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24487 \begin_layout Standard
24498 <row topline="true">
24499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24502 \begin_layout Standard
24510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24513 \begin_layout Standard
24514 link the I/O library
24519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24522 \begin_layout Standard
24533 <row topline="true" bottomline="true">
24534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24537 \begin_layout Standard
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24548 \begin_layout Standard
24549 link the debug library
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24557 \begin_layout Standard
24574 * is the device number, i.e.
24575 452 for PIC18F452 MCU.
24578 \begin_layout Standard
24579 This feature allows for linking with specific libraries withoug having to
24580 explicit name them in the command line.
24585 keyword will reject all modules specified by the library pragma.
24589 \labelwidthstring 00.00.0000
24590 udata pragma udata instructs the compiler to emit code so that linker will
24591 place a variable at a specific memory bank
24594 \begin_layout LyX-Code
24598 \begin_layout LyX-Code
24602 \begin_layout LyX-Code
24603 /* places variable foo at bank2 */
24606 \begin_layout LyX-Code
24607 #pragma udata bank2 foo
24610 \begin_layout LyX-Code
24614 \begin_layout Standard
24615 In order for this pragma to work extra SECTION directives should be added
24616 in the .lkr script.
24617 In the following example a sample .lkr file is shown:
24620 \begin_layout LyX-Code
24624 \begin_layout LyX-Code
24625 // Sample linker script for the PIC18F452 processor
24628 \begin_layout LyX-Code
24632 \begin_layout LyX-Code
24633 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24636 \begin_layout LyX-Code
24637 CODEPAGE NAME=page START=0x2A END=0x7FFF
24640 \begin_layout LyX-Code
24641 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24644 \begin_layout LyX-Code
24645 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24648 \begin_layout LyX-Code
24649 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24652 \begin_layout LyX-Code
24653 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24656 \begin_layout LyX-Code
24657 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24660 \begin_layout LyX-Code
24664 \begin_layout LyX-Code
24665 DATABANK NAME=gpr0 START=0x80 END=0xFF
24668 \begin_layout LyX-Code
24669 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24672 \begin_layout LyX-Code
24673 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24676 \begin_layout LyX-Code
24677 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24680 \begin_layout LyX-Code
24681 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24684 \begin_layout LyX-Code
24685 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24688 \begin_layout LyX-Code
24689 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24692 \begin_layout LyX-Code
24696 \begin_layout LyX-Code
24697 SECTION NAME=CONFIG ROM=config
24700 \begin_layout LyX-Code
24704 \begin_layout LyX-Code
24705 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24708 \begin_layout LyX-Code
24709 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24712 \begin_layout LyX-Code
24713 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24716 \begin_layout LyX-Code
24717 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24720 \begin_layout LyX-Code
24721 SECTION NAME=bank4 RAM=gpr4
24724 \begin_layout LyX-Code
24725 SECTION NAME=bank5 RAM=gpr5
24728 \begin_layout Standard
24729 The linker will recognise the section name set in the pragma statement and
24730 will position the variable at the memory bank set with the RAM field at
24731 the SECTION line in the linker script file.
24734 \begin_layout Subsection
24736 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24743 \begin_layout Standard
24744 There is one main header file
24745 \begin_inset LatexCommand \index{PIC16!Header files}
24749 that can be included to the source files using the pic16
24750 \begin_inset LatexCommand \index{PIC16}
24760 This header file contains the definitions for the processor special registers,
24761 so it is necessary if the source accesses them.
24762 It can be included by adding the following line in the beginning of the
24766 \begin_layout LyX-Code
24767 #include <pic18fregs.h>
24770 \begin_layout Standard
24771 The specific microcontroller is selected within the pic18fregs.h automatically,
24772 so the same source can be used with a variety of devices.
24775 \begin_layout Subsection
24779 \begin_layout Standard
24781 \begin_inset LatexCommand \index{PIC16!Libraries}
24786 \begin_inset LatexCommand \index{PIC16}
24790 port depends on are the microcontroller device libraries which contain
24791 the symbol definitions for the microcontroller special function registers.
24792 These libraries have the format pic18fxxxx.lib, where
24796 is the microcontroller identification number.
24797 The specific library is selected automatically by the compiler at link
24798 stage according to the selected device.
24801 \begin_layout Standard
24802 Libraries are created with gplib which is part of the gputils package
24803 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24810 \begin_layout Subsubsection*
24811 Building the libraries
24814 \begin_layout Standard
24815 Before using SDCC/pic16 there are some libraries that need to be compiled.
24816 This process is not done automatically by SDCC since not all users use
24817 SDCC for pic16 projects.
24818 So each user should compile the libraries separately.
24821 \begin_layout Standard
24822 The steps to compile the pic16 libraries under Linux are:
24825 \begin_layout LyX-Code
24826 cd device/lib/pic16
24829 \begin_layout LyX-Code
24833 \begin_layout LyX-Code
24837 \begin_layout LyX-Code
24841 \begin_layout LyX-Code
24845 \begin_layout LyX-Code
24846 su -c 'make install' # install the libraries, you need the root password
24849 \begin_layout Standard
24850 If you need to install the headers too, do:
24853 \begin_layout LyX-Code
24857 \begin_layout LyX-Code
24858 su -c 'make install' # install the headers, you need the root password
24861 \begin_layout Standard
24862 There exist a special target to build the I/O libraries.
24863 This target is not automatically build because it will build the I/O library
24869 This way building will take quite a lot of time.
24870 Users are advised to edit the
24872 device/lib/pic16/pics.build
24874 file and then execute:
24877 \begin_layout LyX-Code
24881 \begin_layout Subsection
24885 \begin_layout Standard
24886 The following memory models are supported by the PIC16 port:
24889 \begin_layout Itemize
24893 \begin_layout Itemize
24897 \begin_layout Standard
24898 Memory model affects the default size of pointers within the source.
24899 The sizes are shown in the next table:
24902 \begin_layout Standard
24904 \begin_inset Tabular
24905 <lyxtabular version="3" rows="3" columns="3">
24907 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24908 <column alignment="center" valignment="top" leftline="true" width="0">
24909 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24910 <row topline="true" bottomline="true">
24911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24914 \begin_layout Standard
24915 Pointer sizes according to memory model
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24923 \begin_layout Standard
24929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24932 \begin_layout Standard
24939 <row topline="true" bottomline="true">
24940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24943 \begin_layout Standard
24949 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24952 \begin_layout Standard
24958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24961 \begin_layout Standard
24968 <row topline="true" bottomline="true">
24969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24972 \begin_layout Standard
24978 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24981 \begin_layout Standard
24987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24990 \begin_layout Standard
25004 \begin_layout Standard
25005 It is advisable that all sources within a project are compiled with the
25007 If one wants to override the default memory model, this can be done by
25008 declaring a pointer as
25017 Far selects large memory model's pointers, while near selects small memory
25021 \begin_layout Standard
25022 The standard device libraries (see
25023 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25027 ) contain no reference to pointers, so they can be used with both memory
25031 \begin_layout Subsection
25035 \begin_layout Standard
25037 \begin_inset LatexCommand \index{PIC16!stack}
25041 implementation for the PIC16 port uses two indirect registers, FSR1 and
25046 \labelwidthstring 00.00.0000
25047 FSR1 is assigned as stack pointer
25051 \labelwidthstring 00.00.0000
25052 FSR2 is assigned as frame pointer
25055 \begin_layout Standard
25056 The following stack models are supported by the PIC16 port
25059 \begin_layout Itemize
25067 \begin_layout Itemize
25075 \begin_layout Standard
25080 model means that only the FSRxL byte is used to access stack and frame,
25087 uses both FSRxL and FSRxH registers.
25088 The following table shows the stack/frame pointers sizes according to stack
25089 model and the maximum space they can address:
25092 \begin_layout Standard
25094 \begin_inset Tabular
25095 <lyxtabular version="3" rows="3" columns="3">
25097 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25098 <column alignment="center" valignment="top" leftline="true" width="0">
25099 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25100 <row topline="true" bottomline="true">
25101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25104 \begin_layout Standard
25105 Stack & Frame pointer sizes according to stack model
25110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25113 \begin_layout Standard
25119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25122 \begin_layout Standard
25129 <row topline="true">
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25133 \begin_layout Standard
25139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25142 \begin_layout Standard
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25151 \begin_layout Standard
25158 <row topline="true" bottomline="true">
25159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25162 \begin_layout Standard
25168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25171 \begin_layout Standard
25177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25180 \begin_layout Standard
25194 \begin_layout Standard
25199 stack model is currently not working properly throughout the code generator.
25200 So its use is not advised.
25201 Also there are some other points that need special care:
25206 \begin_layout Enumerate
25207 Do not create stack sections with size more than one physical bank (that
25211 \begin_layout Enumerate
25212 Stack sections should no cross physical bank limits (i.e.
25213 #pragma stack 0x50 0x100)
25216 \begin_layout Standard
25217 These limitations are caused by the fact that only FSRxL is modified when
25218 using SMALL stack model, so no more than 256 bytes of stack can be used.
25219 This problem will disappear after LARGE model is fully implemented.
25222 \begin_layout Subsection
25226 \begin_layout Standard
25227 In addition to the standard SDCC function keywords, PIC16
25228 \begin_inset LatexCommand \index{PIC16}
25232 port makes available two more:
25236 \labelwidthstring 00.00.0000
25238 \begin_inset LatexCommand \index{PIC16!wparam}
25242 Use the WREG to pass one byte of the first function argument.
25243 This improves speed but you may not use this for functions with arguments
25244 that are called via function pointers, otherwise the first byte of the
25245 first parameter will get lost.
25249 \begin_layout LyX-Code
25250 void func_wparam(int a) wparam
25253 \begin_layout LyX-Code
25257 \begin_layout LyX-Code
25258 /* WREG hold the lower part of a */
25261 \begin_layout LyX-Code
25262 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25266 \begin_layout LyX-Code
25270 \begin_layout LyX-Code
25275 \labelwidthstring 00.00.0000
25277 \begin_inset LatexCommand \index{PIC16!shadowregs}
25281 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25282 hardware shadow registers which hold the values of WREG, STATUS and BSR
25284 This can be done by adding the keyword
25292 keyword in the function's header.
25295 \begin_layout LyX-Code
25296 void isr_shadow(void) shadowregs interrupt 1
25299 \begin_layout LyX-Code
25303 \begin_layout LyX-Code
25307 \begin_layout LyX-Code
25311 \begin_layout Standard
25316 instructs the code generator not to store/restore WREG, STATUS, BSR when
25317 entering/exiting the ISR.
25320 \begin_layout Subsection
25321 Function return values
25324 \begin_layout Standard
25325 Return values from functions are placed to the appropriate registers following
25326 a modified Microchip policy optimized for SDCC.
25327 The following table shows these registers:
25330 \begin_layout Standard
25332 \begin_inset Tabular
25333 <lyxtabular version="3" rows="6" columns="2">
25335 <column alignment="center" valignment="top" leftline="true" width="0">
25336 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25337 <row topline="true" bottomline="true">
25338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25341 \begin_layout Standard
25347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25350 \begin_layout Standard
25351 destination register
25357 <row topline="true">
25358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25361 \begin_layout Standard
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25370 \begin_layout Standard
25377 <row topline="true">
25378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25381 \begin_layout Standard
25387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25390 \begin_layout Standard
25397 <row topline="true">
25398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25401 \begin_layout Standard
25407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25410 \begin_layout Standard
25417 <row topline="true">
25418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25421 \begin_layout Standard
25427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25430 \begin_layout Standard
25431 FSR0L:PRODH:PRODL:WREG
25437 <row topline="true" bottomline="true">
25438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25441 \begin_layout Standard
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25450 \begin_layout Standard
25451 on stack, FSR0 points to the beginning
25464 \begin_layout Subsection
25468 \begin_layout Standard
25470 \begin_inset LatexCommand \index{PIC16!interrupt}
25474 service routine (ISR) is declared using the
25481 \begin_layout LyX-Code
25482 void isr(void) interrupt
25487 \begin_layout LyX-Code
25491 \begin_layout LyX-Code
25495 \begin_layout LyX-Code
25499 \begin_layout Standard
25504 is the interrupt number, which for PIC18F devices can be:
25507 \begin_layout Standard
25509 \begin_inset Tabular
25510 <lyxtabular version="3" rows="4" columns="3">
25512 <column alignment="center" valignment="top" leftline="true" width="0">
25513 <column alignment="center" valignment="top" leftline="true" width="0">
25514 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25515 <row topline="true" bottomline="true">
25516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25519 \begin_layout Standard
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25530 \begin_layout Standard
25536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25539 \begin_layout Standard
25540 Interrupt Vector Address
25546 <row topline="true">
25547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25550 \begin_layout Standard
25556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25559 \begin_layout Standard
25565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25568 \begin_layout Standard
25575 <row topline="true">
25576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25579 \begin_layout Standard
25594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25597 \begin_layout Standard
25607 HIGH priority interrupts
25612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25615 \begin_layout Standard
25622 <row topline="true" bottomline="true">
25623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25626 \begin_layout Standard
25632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25635 \begin_layout Standard
25636 LOW priority interrupts
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25644 \begin_layout Standard
25658 \begin_layout Standard
25659 When generating assembly code for ISR the code generator places a
25665 Interrupt Vector Address
25667 which points at the genetated ISR.
25668 This single GOTO instruction is part of an automatically generated
25670 interrupt entry point
25673 The actuall ISR code is placed as normally would in the code space.
25674 Upon interrupt request, the GOTO instruction is executed which jumps to
25676 When declaring interrupt functions as _naked this GOTO instruction is
25681 The whole interrupt functions is therefore placed at the Interrupt Vector
25682 Address of the specific interrupt.
25683 This is not a problem for the LOW priority interrupts, but it is a problem
25684 for the RESET and the HIGH priority interrupts because code may be written
25685 at the next interrupt´s vector address and cause undeterminate program
25686 behaviour if that interrupt is raised.
25690 \begin_layout Standard
25691 This is not a problem when
25694 \begin_layout Enumerate
25695 this is a HIGH interrupt ISR and LOW interrupts are
25702 \begin_layout Enumerate
25703 when the ISR is small enough not to reach the next interrupt´s vector address.
25711 \begin_layout Standard
25716 is possible to be omitted.
25717 This way a function is generated similar to an ISR, but it is not assigned
25721 \begin_layout Standard
25722 When entering an interrupt, currently the PIC16
25723 \begin_inset LatexCommand \index{PIC16}
25727 port automatically saves the following registers:
25730 \begin_layout Itemize
25734 \begin_layout Itemize
25738 \begin_layout Itemize
25742 \begin_layout Itemize
25743 PROD (PRODL and PRODH)
25746 \begin_layout Itemize
25747 FSR0 (FSR0L and FSR0H)
25750 \begin_layout Standard
25751 These registers are restored upon return from the interrupt routine.
25755 \begin_layout Standard
25756 NOTE that when the _naked attribute is specified for an interrupt routine,
25757 then NO registers are stored or restored.
25765 \begin_layout Subsection
25769 \begin_layout Standard
25770 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25771 There are 3 types of generic pointers currently implemented data, code
25772 and eeprom pointers.
25773 They are differentiated by the value of the 7th and 6th bits of the upper
25777 \begin_layout Standard
25779 \begin_inset Tabular
25780 <lyxtabular version="3" rows="5" columns="5">
25782 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25783 <column alignment="center" valignment="top" width="0">
25784 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25785 <column alignment="center" valignment="top" width="0">
25786 <column alignment="left" valignment="top" rightline="true" width="0">
25787 <row topline="true" bottomline="true">
25788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25791 \begin_layout Standard
25797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25800 \begin_layout Standard
25806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25809 \begin_layout Standard
25815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25818 \begin_layout Standard
25819 rest of the pointer
25824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25827 \begin_layout Standard
25834 <row topline="true" bottomline="true">
25835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25838 \begin_layout Standard
25844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25847 \begin_layout Standard
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25856 \begin_layout Standard
25862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25865 \begin_layout Standard
25870 uuuuuu uuuuxxxx xxxxxxxx
25875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25878 \begin_layout Standard
25879 a 12-bit data pointer in data RAM memory
25885 <row bottomline="true">
25886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25889 \begin_layout Standard
25895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25898 \begin_layout Standard
25904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25907 \begin_layout Standard
25913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25916 \begin_layout Standard
25921 uxxxxx xxxxxxxx xxxxxxxx
25926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25929 \begin_layout Standard
25930 a 21-bit code pointer in FLASH memory
25936 <row bottomline="true">
25937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25940 \begin_layout Standard
25946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25949 \begin_layout Standard
25955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25958 \begin_layout Standard
25964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25967 \begin_layout Standard
25972 uuuuuu uuuuuuxx xxxxxxxx
25977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25980 \begin_layout Standard
25981 a 10-bit eeprom pointer in EEPROM memory
25987 <row bottomline="true">
25988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25991 \begin_layout Standard
25997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26000 \begin_layout Standard
26006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26009 \begin_layout Standard
26015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26018 \begin_layout Standard
26023 xxxxxx xxxxxxxx xxxxxxxx
26028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26031 \begin_layout Standard
26032 unimplemented pointer type
26045 \begin_layout Standard
26046 Generic pointer are read and written with a set of library functions which
26047 read/write 1, 2, 3, 4 bytes.
26050 \begin_layout Subsection
26054 \begin_layout Subsubsection
26055 Standard I/O Streams
26058 \begin_layout Standard
26063 the type FILE is defined as:
26066 \begin_layout LyX-Code
26067 typedef char * FILE;
26070 \begin_layout Standard
26071 This type is the stream type implemented I/O in the PIC18F devices.
26072 Also the standard input and output streams are declared in stdio.h:
26075 \begin_layout LyX-Code
26076 extern FILE * stdin;
26079 \begin_layout LyX-Code
26080 extern FILE * stdout;
26083 \begin_layout Standard
26084 The FILE type is actually a generic pointer which defines one more type
26085 of generic pointers, the
26090 This new type has the format:
26093 \begin_layout Standard
26095 \begin_inset Tabular
26096 <lyxtabular version="3" rows="2" columns="7">
26098 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26099 <column alignment="center" valignment="top" width="0">
26100 <column alignment="center" valignment="top" leftline="true" width="0">
26101 <column alignment="center" valignment="top" leftline="true" width="0">
26102 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26103 <column alignment="center" valignment="top" width="0">
26104 <column alignment="left" valignment="top" rightline="true" width="0">
26105 <row topline="true" bottomline="true">
26106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26109 \begin_layout Standard
26115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26118 \begin_layout Standard
26124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26127 \begin_layout Standard
26133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26136 \begin_layout Standard
26142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26145 \begin_layout Standard
26151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26154 \begin_layout Standard
26155 rest of the pointer
26160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26163 \begin_layout Standard
26170 <row topline="true" bottomline="true">
26171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26174 \begin_layout Standard
26180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26183 \begin_layout Standard
26189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26192 \begin_layout Standard
26198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26201 \begin_layout Standard
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26210 \begin_layout Standard
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26219 \begin_layout Standard
26229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26232 \begin_layout Standard
26233 upper byte high nubble is 0x2n, the rest are zeroes
26246 \begin_layout Standard
26247 Currently implemented there are 3 types of streams defined:
26250 \begin_layout Standard
26252 \begin_inset Tabular
26253 <lyxtabular version="3" rows="4" columns="4">
26255 <column alignment="center" valignment="top" leftline="true" width="0">
26256 <column alignment="center" valignment="top" leftline="true" width="0">
26257 <column alignment="center" valignment="top" leftline="true" width="0">
26258 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26259 <row topline="true" bottomline="true">
26260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26263 \begin_layout Standard
26269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26272 \begin_layout Standard
26278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26281 \begin_layout Standard
26287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26290 \begin_layout Standard
26297 <row topline="true">
26298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26301 \begin_layout Standard
26307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26310 \begin_layout Standard
26318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26321 \begin_layout Standard
26327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26330 \begin_layout Standard
26331 Writes/Reads characters via the USART peripheral
26337 <row topline="true">
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26341 \begin_layout Standard
26347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26350 \begin_layout Standard
26358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26361 \begin_layout Standard
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26370 \begin_layout Standard
26371 Writes/Reads characters via the MSSP peripheral
26377 <row topline="true" bottomline="true">
26378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26381 \begin_layout Standard
26387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26390 \begin_layout Standard
26398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26401 \begin_layout Standard
26407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26410 \begin_layout Standard
26411 Writes/Reads characters via used defined functions
26424 \begin_layout Standard
26425 The stream identifiers are declared as macros in the stdio.h header.
26428 \begin_layout Standard
26429 In the libc library there exist the functions that are used to write to
26430 each of the above streams.
26435 \labelwidthstring 00.00.0000
26440 \begin_layout Standard
26449 _stream_usart_putchar writes a character at the USART stream
26453 \labelwidthstring 00.00.0000
26458 \begin_layout Standard
26467 _stream_mssp_putchar writes a character at the MSSP stream
26471 \labelwidthstring 00.00.0000
26472 putchar dummy function.
26473 This writes a character to a user specified manner.
26476 \begin_layout Standard
26477 In order to increase performance
26481 is declared in stdio.h as having its parameter in WREG (it has the wparam
26483 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26484 in a user-friendly way.
26489 is the name of the variable that holds the character to print.
26490 An example follows:
26493 \begin_layout LyX-Code
26494 #include <pic18fregs.h>
26503 \begin_layout LyX-Code
26507 \begin_layout LyX-Code
26508 PORTA = c; /* dump character c to PORTA */
26511 \begin_layout LyX-Code
26519 \begin_layout LyX-Code
26523 \begin_layout LyX-Code
26524 stdout = STREAM_USER; /* this is not necessary, since stdout points
26527 \begin_layout LyX-Code
26528 * by default to STREAM_USER */
26531 \begin_layout LyX-Code
26532 printf (¨This is a printf test
26537 \begin_layout LyX-Code
26541 \begin_layout LyX-Code
26545 \begin_layout Subsubsection
26549 \begin_layout Standard
26550 PIC16 contains an implementation of the printf-family of functions.
26551 There exist the following functions:
26554 \begin_layout LyX-Code
26555 extern unsigned int sprintf(char *buf, char *fmt, ...);
26558 \begin_layout LyX-Code
26559 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26562 \begin_layout LyX-Code
26566 \begin_layout LyX-Code
26567 extern unsigned int printf(char *fmt, ...);
26570 \begin_layout LyX-Code
26571 extern unsigned int vprintf(char *fmt, va_lista ap);
26574 \begin_layout LyX-Code
26578 \begin_layout LyX-Code
26579 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26582 \begin_layout LyX-Code
26583 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26586 \begin_layout Standard
26587 For sprintf and vsprintf
26591 should normally be a data pointer where the resulting string will be placed.
26592 No range checking is done so the user should allocate the necessery buffer.
26593 For fprintf and vfprintf
26597 should be a stream pointer (i.e.
26598 stdout, STREAM_MSSP, etc...).
26601 \begin_layout Subsubsection
26605 \begin_layout Standard
26606 The PIC18F family of microcontrollers supports a number of interrupt sources.
26607 A list of these interrupts is shown in the following table:
26610 \begin_layout Standard
26612 \begin_inset Tabular
26613 <lyxtabular version="3" rows="11" columns="4">
26615 <column alignment="left" valignment="top" leftline="true" width="0">
26616 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26617 <column alignment="left" valignment="top" leftline="true" width="0">
26618 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26619 <row topline="true" bottomline="true">
26620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26623 \begin_layout Standard
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26632 \begin_layout Standard
26638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26641 \begin_layout Standard
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26650 \begin_layout Standard
26657 <row topline="true">
26658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26661 \begin_layout Standard
26667 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26670 \begin_layout Standard
26671 PORTB change interrupt
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_layout Standard
26685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26688 \begin_layout Standard
26689 EEPROM/FLASH write complete interrupt
26695 <row topline="true">
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26699 \begin_layout Standard
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26708 \begin_layout Standard
26709 INT0 external interrupt
26714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26717 \begin_layout Standard
26723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26726 \begin_layout Standard
26727 Bus collision interrupt
26733 <row topline="true">
26734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26737 \begin_layout Standard
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26746 \begin_layout Standard
26747 INT1 external interrupt
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26755 \begin_layout Standard
26761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26764 \begin_layout Standard
26765 Low voltage detect interrupt
26771 <row topline="true">
26772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26775 \begin_layout Standard
26781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26784 \begin_layout Standard
26785 INT2 external interrupt
26790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26793 \begin_layout Standard
26799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26802 \begin_layout Standard
26803 Parallel slave port interrupt
26809 <row topline="true">
26810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26813 \begin_layout Standard
26819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26822 \begin_layout Standard
26823 CCP1 module interrupt
26828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26831 \begin_layout Standard
26837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26840 \begin_layout Standard
26841 AD convertion complete interrupt
26847 <row topline="true">
26848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26851 \begin_layout Standard
26857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26860 \begin_layout Standard
26861 CCP2 module interrupt
26866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26869 \begin_layout Standard
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26878 \begin_layout Standard
26879 USART receive interrupt
26885 <row topline="true">
26886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26889 \begin_layout Standard
26895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26898 \begin_layout Standard
26899 TMR0 overflow interrupt
26904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26907 \begin_layout Standard
26913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26916 \begin_layout Standard
26917 USART transmit interrupt
26923 <row topline="true">
26924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26927 \begin_layout Standard
26933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26936 \begin_layout Standard
26937 TMR1 overflow interrupt
26942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26945 \begin_layout Standard
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26954 \begin_layout Standard
26955 SSP receive/transmit interrupt
26961 <row topline="true">
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26965 \begin_layout Standard
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26974 \begin_layout Standard
26975 TMR2 matches PR2 interrupt
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26983 \begin_layout Standard
26989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26992 \begin_layout Standard
26999 <row topline="true" bottomline="true">
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27003 \begin_layout Standard
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27012 \begin_layout Standard
27013 TMR3 overflow interrupt
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_layout Standard
27027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27030 \begin_layout Standard
27044 \begin_layout Standard
27045 The prototypes for these names are defined in the header file
27052 \begin_layout Standard
27053 In order to simplify signal handling, a number of macros is provided:
27057 \labelwidthstring 00.00.0000
27058 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27059 high priority interrupts.
27064 is the function name to use.
27068 \labelwidthstring 00.00.0000
27069 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27070 low priority interrupt.
27075 is the function name to use.
27079 \labelwidthstring 00.00.0000
27080 DEF_HANDLER(sig,handler) define a handler for signal
27086 \labelwidthstring 00.00.0000
27087 END_DEF end the declaration of the dispatch table.
27090 \begin_layout Standard
27091 Additionally there are two more macros to simplify the declaration of the
27096 \labelwidthstring 00.00.0000
27099 SIGHANDLER(handler)
27101 this declares the function prototype for the
27109 \labelwidthstring 00.00.0000
27110 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27113 \begin_layout Standard
27114 An example of using the macros above is shown below:
27117 \begin_layout LyX-Code
27118 #include <pic18fregs.h>
27121 \begin_layout LyX-Code
27122 #include <signal.h>
27126 DEF_INTHIGH(high_int)
27129 \begin_layout LyX-Code
27130 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27133 \begin_layout LyX-Code
27134 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27137 \begin_layout LyX-Code
27142 SIGHANDLER(_tmr0_handler)
27145 \begin_layout LyX-Code
27149 \begin_layout LyX-Code
27150 /* action to be taken when timer 0 overflows */
27153 \begin_layout LyX-Code
27158 SIGHANDLERNAKED(_bcol_handler)
27161 \begin_layout LyX-Code
27165 \begin_layout LyX-Code
27169 \begin_layout LyX-Code
27170 /* action to be taken when bus collision occurs */
27173 \begin_layout LyX-Code
27177 \begin_layout LyX-Code
27181 \begin_layout LyX-Code
27185 \begin_layout Standard
27190 Special care should be taken when using the above scheme:
27193 \begin_layout Itemize
27194 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27197 \begin_layout Itemize
27198 when declaring SIGHANDLERNAKED handler never forget to use
27202 for proper returning.
27205 \begin_layout Subsection
27209 \begin_layout Standard
27210 Here you can find some general tips for compiling programs with SDCC/pic16.
27213 \begin_layout Subsubsection
27217 \begin_layout Standard
27219 \begin_inset LatexCommand \index{PIC16!stack}
27223 size (that is 64 bytes) probably is enough for many programs.
27224 One must take care that when there are many levels of function nesting,
27225 or there is excessive usage of stack, its size should be extended.
27226 An example of such a case is the printf/sprintf family of functions.
27227 If you encounter problems like not being able to print integers, then you
27228 need to set the stack size around the maximum (256 for small stack model).
27229 The following diagram shows what happens when calling printf to print an
27233 \begin_layout LyX-Code
27234 printf () --> ltoa () --> ultoa () --> divschar ()
27237 \begin_layout Standard
27238 It is should be understood that stack is easily consumed when calling complicate
27240 Using command line arguments like -
27244 \begin_layout Standard
27253 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27255 Other ways to reduce stack usage may exist.
27258 \begin_layout Subsection
27262 \begin_layout Standard
27263 The PIC16 Port currently does not pass SDCC's regression test
27264 \begin_inset LatexCommand \index{Regression test (PIC16)}
27269 \begin_inset LatexCommand \ref{sec:Quality-control}
27273 ) and thus the snapshot build regression tests for the PIC16 target are
27274 currently disabled for all hosts
27279 \begin_layout Chapter
27283 \begin_layout Standard
27284 There are several approaches to debugging your code.
27285 This chapter is meant to show your options and to give detail on some of
27290 When writing your code:
27293 \begin_layout Itemize
27294 write your code with debugging in mind (avoid duplicating code, put conceptually
27295 similar variables into structs, use structured code, have strategic points
27296 within your code where all variables are consistent, ...)
27299 \begin_layout Itemize
27300 run a syntax-checking tool like splint
27301 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27306 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27314 \begin_layout Standard
27324 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27331 \begin_layout Itemize
27332 for the high level code use a C-compiler (like f.e.
27333 GCC) to compile run and debug the code on your host.
27338 \begin_layout Standard
27348 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27352 ) on how to handle syntax extensions like __xdata, __at(), ...
27356 \begin_layout Itemize
27357 use another C-compiler to compile code for your target.
27358 Always an option but not recommended:) And not very likely to help you.
27359 If you seriously consider walking this path you should at least occasionally
27360 check portability of your code.
27361 Most commercial compiler vendors will offer an evaluation version so you
27362 can test compile your code or snippets of your code.
27365 \begin_layout Standard
27366 Debugging on a simulator:
27369 \begin_layout Itemize
27370 there is a separate section about SDCDB (section
27371 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27378 \begin_layout Itemize
27379 or (8051 specific) use a freeware/commercial simulator which interfaces
27381 \begin_inset LatexCommand \index{AOMF, AOMF51}
27386 \begin_inset LatexCommand \ref{OMF file}
27390 ) optionally generated by SDCC.
27393 \begin_layout Standard
27394 Debugging On-target:
27397 \begin_layout Itemize
27398 use a MCU port pin to serially output debug data to the RS232 port of your
27400 You'll probably want some level shifting device typically involving a MAX232
27402 If the hardware serial port of the MCU is not available search for 'Software
27403 UART' in your favourite search machine.
27406 \begin_layout Itemize
27407 use an on-target monitor.
27408 In this context a monitor is a small program which usually accepts commands
27409 via a serial line and allows to set program counter, to single step through
27410 a program and read/write memory locations.
27411 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27413 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27420 \begin_layout Itemize
27421 toggle MCU port pins at strategic points within your code and use an oscilloscop
27425 digital oscilloscope
27428 \begin_inset LatexCommand \index{Oscilloscope}
27432 with deep trace memory is really helpful especially if you have to debug
27433 a realtime application.
27434 If you need to monitor more pins than your oscilloscope provides you can
27435 sometimes get away with a small R-2R network.
27436 On a single channel oscilloscope you could f.e.
27437 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27439 \begin_inset Formula $\Omega$
27442 resistor and the other one by a 5\InsetSpace ~
27444 \begin_inset Formula $\Omega$
27447 resistor to the oscilloscope probe (check output drive capability of the
27448 pins you want to monitor).
27449 If you need to monitor many more pins a
27456 \begin_layout Itemize
27470 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27475 Usually very expensive.
27476 And very nice to have too.
27477 And usually locks you (for years...) to the devices the ICE can emulate.
27481 \begin_layout Itemize
27482 use a remote debugger.
27483 In most 8-bit systems the symbol information is not available on the target,
27484 and a complete debugger is too bulky for the target system.
27485 Therefore usually a debugger on the host system connects to an on-target
27486 debugging stub which accepts only primitive commands.
27489 Terms to enter into your favourite search engine could be 'remote debugging',
27490 'gdb stub' or 'inferior debugger'.
27494 \begin_layout Itemize
27495 use an on target hardware debugger.
27496 Some of the more modern MCUs include hardware support for setting break
27497 points and monitoring/changing variables by using dedicated hardware pins.
27498 This facility doesn't require additional code to run on the target and
27503 doesn't affect runtime behaviour until a breakpoint is hit.
27504 For the mcs51 most hardware debuggers use the AOMF
27505 \begin_inset LatexCommand \index{AOMF, AOMF51}
27510 \begin_inset LatexCommand \ref{OMF file}
27518 \begin_layout Standard
27522 \begin_layout Itemize
27523 if you are not familiar with any of the following terms you're likely to
27524 run into problems rather sooner than later:
27541 As an embedded programmer you
27545 to know them so why not look them up
27549 you have problems?)
27552 \begin_layout Itemize
27553 tell someone else about your problem (actually this is a surprisingly effective
27554 means to hunt down the bug even if the listener is not familiar with your
27556 As 'failure to communicate' is probably one of the job-induced deformations
27557 of an embedded programmer this is highly encouraged.
27560 \begin_layout Section
27561 Debugging with SDCDB
27562 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27567 \begin_inset LatexCommand \index{SDCDB (debugger)}
27574 \begin_layout Standard
27575 SDCC is distributed with a source level debugger
27576 \begin_inset LatexCommand \index{Debugger}
27581 The debugger uses a command line interface, the command repertoire of the
27582 debugger has been kept as close to gdb
27583 \begin_inset LatexCommand \index{gdb}
27587 (the GNU debugger) as possible.
27588 The configuration and build process is part of the standard compiler installati
27589 on, which also builds and installs the debugger in the target directory
27590 specified during configuration.
27591 The debugger allows you debug BOTH at the C source and at the ASM source
27595 \begin_layout Subsection
27596 Compiling for Debugging
27599 \begin_layout Standard
27604 \begin_layout Standard
27614 \begin_inset LatexCommand \index{-\/-debug}
27618 option must be specified for all files for which debug information is to
27620 The compiler generates a .adb file for each of these files.
27621 The linker creates the .cdb
27622 \begin_inset LatexCommand \index{<file>.cdb}
27627 \begin_inset LatexCommand \index{<file>.adb}
27631 files and the address information.
27632 This .cdb is used by the debugger.
27635 \begin_layout Subsection
27636 How the Debugger Works
27639 \begin_layout Standard
27644 \begin_layout Standard
27653 -debug option is specified the compiler generates extra symbol information
27654 some of which are put into the assembler source and some are put into the
27656 Then the linker creates the .cdb file from the individual .adb files with
27657 the address information for the symbols.
27658 The debugger reads the symbolic information generated by the compiler &
27659 the address information generated by the linker.
27660 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27661 execution is controlled by the debugger.
27662 When a command is issued for the debugger, it translates it into appropriate
27663 commands for the simulator.
27664 (Currently SDCDM only connects to the simulator but
27669 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27673 is an effort to connect directly to the hardware.)
27676 \begin_layout Subsection
27677 Starting the Debugger SDCDB
27680 \begin_layout Standard
27681 The debugger can be started using the following command line.
27682 (Assume the file you are debugging has the file name foo).
27696 The debugger will look for the following files.
27699 \begin_layout Itemize
27700 foo.c - the source file.
27703 \begin_layout Itemize
27704 foo.cdb - the debugger symbol information file.
27707 \begin_layout Itemize
27708 foo.ihx - the Intel hex format
27709 \begin_inset LatexCommand \index{Intel hex format}
27716 \begin_layout Subsection
27717 SDCDB Command Line Options
27720 \begin_layout Itemize
27725 \begin_layout Standard
27734 -directory=<source file directory> this option can used to specify the directory
27736 The debugger will look into the directory list specified for source, cdb
27738 The items in the directory list must be separated by ':', e.g.
27739 if the source files can be in the directories /home/src1 and /home/src2,
27744 \begin_layout Standard
27753 -directory option should be -
27757 \begin_layout Standard
27766 -directory=/home/src1:/home/src2.
27767 Note there can be no spaces in the option.
27771 \begin_layout Itemize
27772 -cd <directory> - change to the <directory>.
27775 \begin_layout Itemize
27776 -fullname - used by GUI front ends.
27779 \begin_layout Itemize
27780 -cpu <cpu-type> - this argument is passed to the simulator please see the
27781 simulator docs for details.
27784 \begin_layout Itemize
27785 -X <Clock frequency > this options is passed to the simulator please see
27786 the simulator docs for details.
27789 \begin_layout Itemize
27790 -s <serial port file> passed to simulator see the simulator docs for details.
27793 \begin_layout Itemize
27794 -S <serial in,out> passed to simulator see the simulator docs for details.
27797 \begin_layout Itemize
27798 -k <port number> passed to simulator see the simulator docs for details.
27801 \begin_layout Subsection
27802 SDCDB Debugger Commands
27805 \begin_layout Standard
27806 As mentioned earlier the command interface for the debugger has been deliberatel
27807 y kept as close the GNU debugger gdb, as possible.
27808 This will help the integration with existing graphical user interfaces
27809 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27810 If you use a graphical user interface for the debugger you can skip this
27814 \begin_layout Subsubsection*
27815 break [line | file:line | function | file:function]
27818 \begin_layout Standard
27819 Set breakpoint at specified line or function:
27828 sdcdb>break foo.c:100
27830 sdcdb>break funcfoo
27832 sdcdb>break foo.c:funcfoo
27835 \begin_layout Subsubsection*
27836 clear [line | file:line | function | file:function ]
27839 \begin_layout Standard
27840 Clear breakpoint at specified line or function:
27849 sdcdb>clear foo.c:100
27851 sdcdb>clear funcfoo
27853 sdcdb>clear foo.c:funcfoo
27856 \begin_layout Subsubsection*
27860 \begin_layout Standard
27861 Continue program being debugged, after breakpoint.
27864 \begin_layout Subsubsection*
27868 \begin_layout Standard
27869 Execute till the end of the current function.
27872 \begin_layout Subsubsection*
27876 \begin_layout Standard
27877 Delete breakpoint number 'n'.
27878 If used without any option clear ALL user defined break points.
27881 \begin_layout Subsubsection*
27882 info [break | stack | frame | registers ]
27885 \begin_layout Itemize
27886 info break - list all breakpoints
27889 \begin_layout Itemize
27890 info stack - show the function call stack.
27893 \begin_layout Itemize
27894 info frame - show information about the current execution frame.
27897 \begin_layout Itemize
27898 info registers - show content of all registers.
27901 \begin_layout Subsubsection*
27905 \begin_layout Standard
27906 Step program until it reaches a different source line.
27907 Note: pressing <return> repeats the last command.
27910 \begin_layout Subsubsection*
27914 \begin_layout Standard
27915 Step program, proceeding through subroutine calls.
27918 \begin_layout Subsubsection*
27922 \begin_layout Standard
27923 Start debugged program.
27926 \begin_layout Subsubsection*
27930 \begin_layout Standard
27931 Print type information of the variable.
27934 \begin_layout Subsubsection*
27938 \begin_layout Standard
27939 print value of variable.
27942 \begin_layout Subsubsection*
27946 \begin_layout Standard
27947 load the given file name.
27948 Note this is an alternate method of loading file for debugging.
27951 \begin_layout Subsubsection*
27955 \begin_layout Standard
27956 print information about current frame.
27959 \begin_layout Subsubsection*
27963 \begin_layout Standard
27964 Toggle between C source & assembly source.
27967 \begin_layout Subsubsection*
27968 ! simulator command
27971 \begin_layout Standard
27972 Send the string following '!' to the simulator, the simulator response is
27974 Note the debugger does not interpret the command being sent to the simulator,
27975 so if a command like 'go' is sent the debugger can loose its execution
27976 context and may display incorrect values.
27979 \begin_layout Subsubsection*
27983 \begin_layout Standard
27986 My name is Bobby Brown"
27989 \begin_layout Subsection
27990 Interfacing SDCDB with DDD
27993 \begin_layout Standard
27994 \begin_inset Note Note
27997 \begin_layout Standard
27998 The screenshot was converted from png to eps with:
27999 \begin_inset Quotes sld
28002 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28003 \begin_inset Quotes srd
28006 which produces a pretty compact eps file which is free from compression
28010 \begin_layout Standard
28011 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28012 as this broke the build system on Sourceforge (pdf-file was broken.
28013 pdflatex does not accept eps files).
28021 \begin_layout Standard
28037 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28043 shows a screenshot of a debugging session with DDD
28044 \begin_inset LatexCommand \index{DDD (debugger)}
28048 (Unix only) on a simulated 8032.
28049 The debugging session might not run as smoothly as the screenshot suggests.
28050 The debugger allows setting of breakpoints, displaying and changing variables,
28051 single stepping through C and assembler code.
28054 The source was compiled with
28068 \begin_layout Standard
28080 -debug ddd_example.c
28093 and DDD was invoked with
28100 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28103 \begin_layout Standard
28104 \begin_inset Note Note
28107 \begin_layout Standard
28108 Check that the double quotes or an apostroph within the command line survive
28109 the LyX tool chain.
28110 Previously the apostrophs got slanted in the PDF output so a cut and paste
28119 \begin_layout Subsection
28120 Interfacing SDCDB with XEmacs
28121 \begin_inset LatexCommand \index{XEmacs}
28126 \begin_inset LatexCommand \index{Emacs}
28133 \begin_layout Standard
28134 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28135 sdcdb.el and sdcdbsrc.el.
28136 These two files can be found in the $(prefix)/bin directory after the installat
28138 These files need to be loaded into XEmacs for the interface to work.
28139 This can be done at XEmacs startup time by inserting the following into
28140 your '.xemacs' file (which can be found in your HOME directory):
28146 (load-file sdcdbsrc.el)
28152 .xemacs is a lisp file so the () around the command is REQUIRED.
28153 The files can also be loaded dynamically while XEmacs is running, set the
28154 environment variable 'EMACSLOADPATH' to the installation bin directory
28155 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28156 To start the interface enter the following command:
28170 You will prompted to enter the file name to be debugged.
28175 The command line options that are passed to the simulator directly are
28176 bound to default values in the file sdcdbsrc.el.
28177 The variables are listed below, these values maybe changed as required.
28180 \begin_layout Itemize
28181 sdcdbsrc-cpu-type '51
28184 \begin_layout Itemize
28185 sdcdbsrc-frequency '11059200
28188 \begin_layout Itemize
28189 sdcdbsrc-serial nil
28192 \begin_layout Standard
28193 The following is a list of key mapping for the debugger interface.
28196 \begin_layout Standard
28219 binding\InsetSpace ~
28257 -------\InsetSpace ~
28328 sdcdb-back-from-src\InsetSpace ~
28357 rom-src\InsetSpace ~
28367 SDCDB continue command
28385 sdcdb-step-from-src\InsetSpace ~
28414 hatis-c-sexp\InsetSpace ~
28424 SDCDB ptypecommand for data at
28491 sdcdbsrc-delete\InsetSpace ~
28506 B Delete all breakpoints if no arg
28555 given or delete arg (C-u arg x)
28574 -frame\InsetSpace ~
28589 SDCDB Display current frame if no arg,
28638 given or display frame arg
28706 sdcdbsrc-goto-sdcdb\InsetSpace ~
28716 Goto the SDCDB output buffer
28735 t-c-sexp\InsetSpace ~
28746 SDCDB print command for data at
28813 sdcdbsrc-goto-sdcdb\InsetSpace ~
28824 o the SDCDB output buffer
28842 sdcdbsrc-mode\InsetSpace ~
28858 Toggles Sdcdbsrc mode (turns it
28874 sdcdb-finish-from-src\InsetSpace ~
28882 SDCDB finish command
28916 Set break for line with point
28931 sdcdbsrc-mode\InsetSpace ~
28947 Toggle Sdcdbsrc mode
28963 dbsrc-srcmode\InsetSpace ~
28987 \begin_layout Chapter
28991 \begin_layout Standard
28992 Here are a few guidelines that will help the compiler generate more efficient
28993 code, some of the tips are specific to this compiler others are generally
28994 good programming practice.
28997 \begin_layout Itemize
28998 Use the smallest data type to represent your data-value.
28999 If it is known in advance that the value is going to be less than 256 then
29000 use an 'unsigned char' instead of a 'short' or 'int'.
29001 Please note, that ANSI C requires both signed and unsigned chars to be
29002 promoted to 'signed int'
29003 \begin_inset LatexCommand \index{promotion to signed int}
29008 \begin_inset Marginal
29011 \begin_layout Standard
29020 before doing any operation.
29022 \begin_inset LatexCommand \index{type promotion}
29027 \begin_inset LatexCommand \label{type promotion}
29031 can be omitted, if the result is the same.
29032 The effect of the promotion rules together with the sign-extension is often
29037 \begin_layout Verse
29040 unsigned char uc = 0xfe;
29042 if (uc * uc < 0) /* this is true! */
29055 \begin_layout Standard
29062 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29070 \begin_layout Verse
29073 (unsigned char) -12 / (signed char) -3 = ...
29076 \begin_layout Standard
29077 No, the result is not 4:
29080 \begin_layout Verse
29083 (int) (unsigned char) -12 / (int) (signed char) -3 =
29085 (int) (unsigned char)
29086 0xf4 / (int) (signed char) 0xfd =
29088 (int) 0x00f4 / (int) 0xfffd =
29093 (int) 244 / (int) -3 =
29095 (int) -81 = (int) 0xffaf;
29098 \begin_layout Standard
29099 Don't complain, that gcc gives you a different result.
29100 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29101 Therefore the results are different.
29104 \begin_inset Quotes sld
29108 \begin_inset Quotes srd
29114 \begin_layout Quote
29117 If well-defined overflow characteristics are important and negative values
29118 are not, or if you want to steer clear of sign-extension problems when
29119 manipulating bits or bytes, use one of the corresponding unsigned types.
29120 (Beware when mixing signed and unsigned values in expressions, though.)
29123 character types (especially unsigned char) can be used as "tiny" integers,
29124 doing so is sometimes more trouble than it's worth, due to unpredictable
29125 sign extension and increased code size.
29129 \begin_layout Itemize
29130 Use unsigned when it is known in advance that the value is not going to
29132 This helps especially if you are doing division or multiplication, bit-shifting
29133 or are using an array index.
29136 \begin_layout Itemize
29137 NEVER jump into a LOOP.
29140 \begin_layout Itemize
29141 Declare the variables to be local
29142 \begin_inset LatexCommand \index{local variables}
29146 whenever possible, especially loop control variables (induction).
29149 \begin_layout Itemize
29150 Have a look at the assembly listing to get a
29151 \begin_inset Quotes sld
29155 \begin_inset Quotes srd
29158 for the code generation.
29161 \begin_layout Section
29162 Porting code from or to other compilers
29163 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29170 \begin_layout Itemize
29171 check whether endianness of the compilers differs and adapt where needed.
29174 \begin_layout Itemize
29175 check the device specific header files
29176 \begin_inset LatexCommand \index{Header files}
29181 \begin_inset LatexCommand \index{Include files}
29185 for compiler specific syntax.
29186 Eventually include the file <compiler.h
29187 \begin_inset LatexCommand \index{compiler.h (include file)}
29192 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29196 to allow using common header files.
29199 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29206 \begin_layout Itemize
29207 check whether the startup code contains the correct initialization (watchdog,
29211 \begin_layout Itemize
29212 check whether the sizes of short, int, long match.
29215 \begin_layout Itemize
29216 check if some 16 or 32 bit hardware registers require a specific addressing
29217 order (least significant or most significant byte first) and adapt if needed
29226 relate to time and not to lower/upper memory location here, so this is
29231 the same as endianness).
29234 \begin_layout Itemize
29235 check whether the keyword
29239 is used where needed.
29240 The compilers might differ in their optimization characteristics (as different
29241 versions of the same compiler might also use more clever optimizations
29242 this is good idea anyway).
29244 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29251 \begin_layout Itemize
29252 check that the compilers are not told to supress warnings.
29255 \begin_layout Itemize
29256 check and convert compiler specific extensions (interrupts, memory areas,
29260 \begin_layout Itemize
29261 check for differences in type promotion.
29262 Especially check for math operations on
29271 For the sake of C99 compatibility SDCC will probably promote these to
29275 more often than other compilers.
29276 Eventually insert explicit casts to
29285 Also check that the ~\InsetSpace ~
29287 \begin_inset LatexCommand \index{\~\/ Operator}
29294 \begin_inset LatexCommand \index{bit}
29300 variables, use the !\InsetSpace ~
29303 \begin_inset LatexCommand \ref{type promotion}
29308 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29315 \begin_layout Itemize
29316 check the assembly code generated for interrupt routines (f.e.
29317 for calls to possibly non-reentrant library functions).
29320 \begin_layout Itemize
29321 check whether timing loops result in proper timing (or preferably consider
29322 a rewrite of the code with timer based delays instead).
29325 \begin_layout Itemize
29326 check for differences in printf parameters (some compilers push (va_arg
29327 \begin_inset LatexCommand \index{vararg, va\_arg}
29331 ) char variables as
29335 others push them as
29341 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29348 \begin_layout Itemize
29349 check the resulting memory map
29350 \begin_inset LatexCommand \index{Memory map}
29355 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29356 ly idata, pdata, xdata).
29357 Eventually check if unexpected library functions are included.
29360 \begin_layout Section
29362 \begin_inset LatexCommand \index{Tools}
29366 included in the distribution
29369 \begin_layout Standard
29371 \begin_inset Tabular
29372 <lyxtabular version="3" rows="12" columns="3">
29374 <column alignment="left" valignment="top" leftline="true" width="0pt">
29375 <column alignment="left" valignment="top" leftline="true" width="0pt">
29376 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29377 <row topline="true" bottomline="true">
29378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29381 \begin_layout Standard
29389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29392 \begin_layout Standard
29400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29403 \begin_layout Standard
29412 <row topline="true">
29413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29416 \begin_layout Standard
29418 \begin_inset LatexCommand \index{uCsim}
29427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29430 \begin_layout Standard
29431 Simulator for various architectures
29436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29439 \begin_layout Standard
29446 <row topline="true">
29447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29450 \begin_layout Standard
29456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29459 \begin_layout Standard
29461 \begin_inset LatexCommand \index{Header files}
29466 \begin_inset LatexCommand \index{Include files}
29475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29478 \begin_layout Standard
29479 sdcc/support/scripts
29485 <row topline="true">
29486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29489 \begin_layout Standard
29495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29498 \begin_layout Standard
29499 header file conversion
29504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29507 \begin_layout Standard
29508 sdcc/support/scripts
29514 <row topline="true">
29515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29518 \begin_layout Standard
29524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29527 \begin_layout Standard
29533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29536 \begin_layout Standard
29552 <row topline="true">
29553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29556 \begin_layout Standard
29562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29565 \begin_layout Standard
29571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29574 \begin_layout Standard
29590 <row topline="true">
29591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29594 \begin_layout Standard
29600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29603 \begin_layout Standard
29609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29612 \begin_layout Standard
29628 <row topline="true">
29629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29632 \begin_layout Standard
29638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29641 \begin_layout Standard
29647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29650 \begin_layout Standard
29666 <row topline="true">
29667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29670 \begin_layout Standard
29676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29679 \begin_layout Standard
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29688 \begin_layout Standard
29704 <row topline="true">
29705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29708 \begin_layout Standard
29714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29717 \begin_layout Standard
29723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29726 \begin_layout Standard
29742 <row topline="true">
29743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29746 \begin_layout Standard
29752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29755 \begin_layout Standard
29761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29764 \begin_layout Standard
29780 <row topline="true" bottomline="true">
29781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29784 \begin_layout Standard
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29793 \begin_layout Standard
29795 \begin_inset LatexCommand \index{packihx (tool)}
29804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29807 \begin_layout Standard
29832 \begin_layout Section
29834 \begin_inset LatexCommand \index{Documentation}
29838 included in the distribution
29841 \begin_layout Standard
29843 \begin_inset Tabular
29844 <lyxtabular version="3" rows="10" columns="2">
29846 <column alignment="block" valignment="top" leftline="true" width="40col%">
29847 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29848 <row topline="true" bottomline="true" endhead="true">
29849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29852 \begin_layout Standard
29860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29863 \begin_layout Standard
29866 Filename / Where to get
29872 <row topline="true">
29873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29876 \begin_layout Standard
29877 SDCC Compiler User Guide
29882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29885 \begin_layout Standard
29886 You're reading it right now
29898 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29908 <row topline="true">
29909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29912 \begin_layout Standard
29918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29921 \begin_layout Standard
29934 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29944 <row topline="true">
29945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29948 \begin_layout Standard
29950 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29955 \begin_inset LatexCommand \index{Assembler documentation}
29962 \begin_inset LatexCommand \index{aslink}
29967 \begin_inset LatexCommand \index{Linker documentation}
29976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29979 \begin_layout Standard
29980 sdcc/as/doc/asxhtm.html
29992 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30002 <row topline="true">
30003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30006 \begin_layout Standard
30007 SDCC regression test
30008 \begin_inset LatexCommand \index{Regression test}
30017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30020 \begin_layout Standard
30021 sdcc/doc/test_suite_spec.pdf
30033 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30043 <row topline="true">
30044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30047 \begin_layout Standard
30053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30056 \begin_layout Standard
30069 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30079 <row topline="true">
30080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30083 \begin_layout Standard
30084 Notes on debugging with SDCDB
30085 \begin_inset LatexCommand \index{SDCDB (debugger)}
30094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30097 \begin_layout Standard
30098 sdcc/debugger/README
30110 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30120 <row topline="true">
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30124 \begin_layout Standard
30126 \begin_inset LatexCommand \index{uCsim}
30130 Software simulator for microcontrollers
30135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30138 \begin_layout Standard
30168 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30178 <row topline="true">
30179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30182 \begin_layout Standard
30183 Temporary notes on the pic16
30184 \begin_inset LatexCommand \index{PIC16}
30193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30196 \begin_layout Standard
30197 sdcc/src/pic16/NOTES
30209 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30219 <row topline="true" bottomline="true">
30220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30223 \begin_layout Standard
30224 SDCC internal documentation (debugging file format)
30229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30232 \begin_layout Standard
30262 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30281 \begin_layout Section
30282 Related open source tools
30283 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30288 \begin_inset LatexCommand \index{Related tools}
30295 \begin_layout Standard
30297 \begin_inset Tabular
30298 <lyxtabular version="3" rows="14" columns="3">
30300 <column alignment="left" valignment="top" leftline="true" width="0pt">
30301 <column alignment="block" valignment="top" leftline="true" width="30line%">
30302 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30303 <row topline="true" bottomline="true">
30304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30307 \begin_layout Standard
30315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30318 \begin_layout Standard
30326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30329 \begin_layout Standard
30338 <row topline="true">
30339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30342 \begin_layout Standard
30344 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30356 \begin_layout Standard
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30365 \begin_layout Standard
30366 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30376 <row topline="true">
30377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30380 \begin_layout Standard
30382 \begin_inset LatexCommand \index{gputils (pic tools)}
30391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30394 \begin_layout Standard
30400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30403 \begin_layout Standard
30404 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30414 <row topline="true">
30415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30418 \begin_layout Standard
30424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30427 \begin_layout Standard
30433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30436 \begin_layout Standard
30437 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30447 <row topline="true">
30448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30451 \begin_layout Standard
30457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30460 \begin_layout Standard
30461 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30470 \begin_layout Standard
30471 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30481 <row topline="true">
30482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30485 \begin_layout Standard
30487 \begin_inset LatexCommand \index{indent (source formatting tool)}
30496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30499 \begin_layout Standard
30500 Formats C source - Master of the white spaces
30505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30508 \begin_layout Standard
30509 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30519 <row topline="true">
30520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30523 \begin_layout Standard
30525 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30537 \begin_layout Standard
30538 Object file conversion, checksumming, ...
30543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30546 \begin_layout Standard
30547 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30557 <row topline="true">
30558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30561 \begin_layout Standard
30563 \begin_inset LatexCommand \index{objdump (tool)}
30572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30575 \begin_layout Standard
30576 Object file conversion, ...
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30584 \begin_layout Standard
30585 Part of binutils (should be there anyway)
30591 <row topline="true">
30592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30595 \begin_layout Standard
30601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30604 \begin_layout Standard
30605 8051 monitor (hex up-/download, single step, disassemble)
30610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30613 \begin_layout Standard
30614 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30624 <row topline="true">
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30628 \begin_layout Standard
30630 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30642 \begin_layout Standard
30643 Source code documentation system
30648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30651 \begin_layout Standard
30652 \begin_inset LatexCommand \url{http://www.doxygen.org}
30662 <row topline="true">
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30666 \begin_layout Standard
30672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30675 \begin_layout Standard
30676 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30684 \begin_layout Standard
30685 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30695 <row topline="true">
30696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30699 \begin_layout Standard
30705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30708 \begin_layout Standard
30709 8051 monitor (hex up-/download, single step, disassemble)
30714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30717 \begin_layout Standard
30718 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30728 <row topline="true">
30729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30732 \begin_layout Standard
30734 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30746 \begin_layout Standard
30747 Statically checks c sources (see
30748 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30760 \begin_layout Standard
30761 \begin_inset LatexCommand \url{http://www.splint.org}
30771 <row topline="true" bottomline="true">
30772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30775 \begin_layout Standard
30777 \begin_inset LatexCommand \index{DDD (debugger)}
30786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30789 \begin_layout Standard
30790 Debugger, serves nicely as GUI to SDCDB
30791 \begin_inset LatexCommand \index{SDCDB (debugger)}
30800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30803 \begin_layout Standard
30804 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30823 \begin_layout Section
30824 Related documentation / recommended reading
30827 \begin_layout Standard
30829 \begin_inset Tabular
30830 <lyxtabular version="3" rows="7" columns="3">
30832 <column alignment="left" valignment="top" leftline="true" width="0pt">
30833 <column alignment="left" valignment="top" leftline="true" width="0">
30834 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30835 <row topline="true" bottomline="true">
30836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30839 \begin_layout Standard
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30850 \begin_layout Standard
30858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30861 \begin_layout Standard
30870 <row topline="true">
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30874 \begin_layout Standard
30889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30892 \begin_layout Standard
30894 \begin_inset LatexCommand \index{C Reference card}
30903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30906 \begin_layout Standard
30907 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30917 <row topline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30921 \begin_layout Standard
30927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30930 \begin_layout Standard
30932 \begin_inset LatexCommand \index{C FAQ}
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30944 \begin_layout Standard
30945 \begin_inset LatexCommand \url{http://www.c-faq.com}
30955 <row topline="true">
30956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30959 \begin_layout Standard
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30968 \begin_layout Standard
30969 \begin_inset Quotes sld
30973 \begin_inset Quotes srd
30981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30984 \begin_layout Standard
30987 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30997 <row topline="true">
30998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31001 \begin_layout Standard
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31010 \begin_layout Standard
31011 \begin_inset Quotes sld
31014 Extensions for Embedded C
31015 \begin_inset Quotes srd
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31026 \begin_layout Standard
31029 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31039 <row topline="true">
31040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31043 \begin_layout Standard
31049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31052 \begin_layout Standard
31053 Latest datasheet of target CPU
31058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31061 \begin_layout Standard
31068 <row topline="true" bottomline="true">
31069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31072 \begin_layout Standard
31078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31081 \begin_layout Standard
31082 Revision history of datasheet
31087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31090 \begin_layout Standard
31106 \begin_layout Section
31107 Application notes specifically for SDCC
31110 \begin_layout Standard
31111 SDCC makes no claims about the completeness of this list and about up-to-datenes
31112 s or correctness of the application notes
31113 \begin_inset LatexCommand \index{Application notes}
31120 \begin_layout Standard
31124 \begin_inset Tabular
31125 <lyxtabular version="3" rows="7" columns="3">
31127 <column alignment="block" valignment="top" leftline="true" width="17col%">
31128 <column alignment="block" valignment="top" leftline="true" width="27col%">
31129 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31130 <row topline="true" bottomline="true">
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31134 \begin_layout Standard
31143 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31146 \begin_layout Standard
31155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31158 \begin_layout Standard
31168 <row topline="true">
31169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31172 \begin_layout Standard
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31183 \begin_layout Standard
31186 Using the SDCC Compiler for the DS80C400
31187 \begin_inset LatexCommand \index{DS80C400}
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31199 \begin_layout Standard
31202 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31212 <row topline="true">
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31216 \begin_layout Standard
31224 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31227 \begin_layout Standard
31230 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31231 \begin_inset LatexCommand \index{DS89C4x0}
31235 Family of Microcontrollers
31240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31243 \begin_layout Standard
31246 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31256 <row topline="true">
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31260 \begin_layout Standard
31263 Silicon Laboratories / Cygnal
31268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31271 \begin_layout Standard
31274 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31275 \begin_inset LatexCommand \index{IDE}
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31287 \begin_layout Standard
31290 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31300 <row topline="true">
31301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31304 \begin_layout Standard
31307 Ramtron / Goal Semiconductor
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31315 \begin_layout Standard
31318 Interfacing SDCC to Syn and Textpad
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31326 \begin_layout Standard
31329 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31339 <row topline="true">
31340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31343 \begin_layout Standard
31346 Ramtron / Goal Semiconductor
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31354 \begin_layout Standard
31357 Installing and Configuring SDCC and Crimson Editor
31362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31365 \begin_layout Standard
31368 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31378 <row topline="true" bottomline="true">
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31382 \begin_layout Standard
31390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31393 \begin_layout Standard
31396 MSC12xx Programming with SDCC
31401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31404 \begin_layout Standard
31407 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31424 \begin_layout Section
31428 \begin_layout Standard
31429 Some questions answered, some pointers given - it might be time to in turn
31437 \begin_layout Itemize
31438 can you solve your project with the selected microcontroller? Would you
31439 find out early or rather late that your target is too small/slow/whatever?
31440 Can you switch to a slightly better device if it doesn't fit?
31443 \begin_layout Itemize
31444 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31445 and/or another programming language be more adequate? Would an operating
31446 system on the target device help?
31449 \begin_layout Itemize
31450 if you solved the problem, will the marketing department be happy?
31453 \begin_layout Itemize
31454 if the marketing department is happy, will customers be happy?
31457 \begin_layout Itemize
31458 if you're the project manager, marketing department and maybe even the customer
31459 in one person, have you tried to see the project from the outside?
31462 \begin_layout Itemize
31463 is the project done if you think it is done? Or is just that other interface/pro
31464 tocol/feature/configuration/option missing? How about website, manual(s),
31465 internationali(z|s)ation, packaging, labels, 2nd source for components,
31466 electromagnetic compatability/interference, documentation for production,
31467 production test software, update mechanism, patent issues?
31470 \begin_layout Itemize
31471 is your project adequately positioned in that magic triangle: fame, fortune,
31475 \begin_layout Standard
31476 Maybe not all answers to these questions are known and some answers may
31481 , nevertheless knowing these questions may help you to avoid burnout
31485 \begin_layout Standard
31486 burnout is bad for electronic devices, programmers and motorcycle tyres
31492 Chances are you didn't want to hear some of them...
31495 \begin_layout Chapter
31497 \begin_inset LatexCommand \index{Support}
31504 \begin_layout Standard
31505 SDCC has grown to be a large project.
31506 The compiler alone (without the preprocessor, assembler and linker) is
31507 well over 150,000 lines of code (blank stripped).
31508 The open source nature of this project is a key to its continued growth
31510 You gain the benefit and support of many active software developers and
31512 Is SDCC perfect? No, that's why we need your help.
31513 The developers take pride in fixing reported bugs.
31514 You can help by reporting the bugs and helping other SDCC users.
31515 There are lots of ways to contribute, and we encourage you to take part
31516 in making SDCC a great software package.
31520 \begin_layout Standard
31521 The SDCC project is hosted on the SDCC sourceforge site at
31522 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31527 You'll find the complete set of mailing lists
31528 \begin_inset LatexCommand \index{Mailing list(s)}
31532 , forums, bug reporting system, patch submission
31533 \begin_inset LatexCommand \index{Patch submission}
31538 \begin_inset LatexCommand \index{download}
31542 area and Subversion code repository
31543 \begin_inset LatexCommand \index{Subversion code repository}
31550 \begin_layout Section
31552 \begin_inset LatexCommand \index{Bug reporting}
31557 \begin_inset LatexCommand \index{Reporting bugs}
31564 \begin_layout Standard
31565 The recommended way of reporting bugs is using the infrastructure of the
31567 You can follow the status of bug reports there and have an overview about
31571 \begin_layout Standard
31572 Bug reports are automatically forwarded to the developer mailing list and
31573 will be fixed ASAP.
31574 When reporting a bug, it is very useful to include a small test program
31575 (the smaller the better) which reproduces the problem.
31576 If you can isolate the problem by looking at the generated assembly code,
31577 this can be very helpful.
31578 Compiling your program with the -
31582 \begin_layout Standard
31592 \begin_inset LatexCommand \index{-\/-dumpall}
31596 option can sometimes be useful in locating optimization problems.
31597 When reporting a bug please make sure you:
31600 \begin_layout Enumerate
31601 Attach the code you are compiling with SDCC.
31605 \begin_layout Enumerate
31606 Specify the exact command you use to run SDCC, or attach your Makefile.
31610 \begin_layout Enumerate
31611 Specify the SDCC version (type "
31617 "), your platform, and operating system.
31621 \begin_layout Enumerate
31622 Provide an exact copy of any error message or incorrect output.
31626 \begin_layout Enumerate
31627 Put something meaningful in the subject of your message.
31630 \begin_layout Standard
31631 Please attempt to include these 5 important parts, as applicable, in all
31632 requests for support or when reporting any problems or bugs with SDCC.
31633 Though this will make your message lengthy, it will greatly improve your
31634 chance that SDCC users and developers will be able to help you.
31635 Some SDCC developers are frustrated by bug reports without code provided
31636 that they can use to reproduce and ultimately fix the problem, so please
31637 be sure to provide sample code if you are reporting a bug!
31640 \begin_layout Standard
31641 Please have a short check that you are using a recent version of SDCC and
31642 the bug is not yet known.
31643 This is the link for reporting bugs:
31644 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31649 With SDCC on average having more than 200 downloads
31650 \begin_inset LatexCommand \index{download}
31654 on sourceforge per day
31658 \begin_layout Standard
31659 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31660 between 2002 and 2005.
31661 This does not include other methods of distribution.
31666 there must be some users.
31667 So it's not exactly easy to find a new bug.
31668 If you find one we need it:
31670 reporting bugs is good
31675 \begin_layout Section
31676 Requesting Features
31677 \begin_inset LatexCommand \label{sub:Requesting-Features}
31682 \begin_inset LatexCommand \index{Feature request}
31687 \begin_inset LatexCommand \index{Requesting features}
31694 \begin_layout Standard
31695 Like bug reports feature requests are forwarded to the developer mailing
31697 This is the link for requesting features:
31698 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31705 \begin_layout Section
31709 \begin_layout Standard
31710 Like bug reports contributed patches are forwarded to the developer mailing
31712 This is the link for submitting patches
31713 \begin_inset LatexCommand \index{Patch submission}
31718 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31725 \begin_layout Standard
31726 You need to specify some parameters to the
31730 command for the patches to be useful.
31731 If you modified more than one file a patch created f.e.
31736 \begin_inset Quotes sld
31739 diff -Naur unmodified_directory modified_directory >my_changes.patch
31740 \begin_inset Quotes srd
31746 will be fine, otherwise
31750 \begin_inset Quotes sld
31753 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31754 \begin_inset Quotes srd
31764 \begin_layout Section
31768 \begin_layout Standard
31769 These links should take you directly to the
31770 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31778 \begin_layout Standard
31779 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31780 automated messages (mid 2003)
31786 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31791 \begin_inset LatexCommand \index{Mailing list(s)}
31795 and forums are archived and searchable so if you are lucky someone already
31796 had a similar problem.
31797 While mails to the lists themselves are delivered promptly their web front
31798 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31799 if you're seriously using SDCC please consider subscribing to the lists.
31802 \begin_layout Section
31806 \begin_layout Standard
31807 You can follow the status of the Subversion version
31808 \begin_inset LatexCommand \index{version}
31812 of SDCC by watching the Changelog
31813 \begin_inset LatexCommand \index{Changelog}
31817 in the Subversion repository
31820 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31827 \begin_layout Section
31828 Subversion Source Code Repository
31831 \begin_layout Standard
31838 or the filenames of the snapshot versions of SDCC include date and its
31840 \begin_inset LatexCommand \index{Subversion code repository}
31845 Subversion allows to download the source of recent or previous versions
31847 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31851 (by number or by date).
31852 An on-line source code browser and detailled instructions are also available
31854 SDCC versions starting from 1999 up to now are available (currently the
31855 versions prior to the conversion from cvs
31856 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31860 to Subversion (April 2006) are either by accessible by Subversion or by
31864 \begin_layout Section
31866 \begin_inset LatexCommand \index{Release policy}
31873 \begin_layout Standard
31874 Historically there often were long delays between official releases and
31875 the sourceforge download area tends to get not updated at all.
31876 Excuses in the past might have referred to problems with live range analysis,
31877 but as this was fixed a while ago, the current problem is that another
31878 excuse has to be found.
31879 Kidding aside, we have to get better there! On the other hand there are
31880 daily snapshots available at
31881 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31885 , and you can always build the very last version (hopefully with many bugs
31886 fixed, and features added) from the source code available at
31887 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31893 \begin_inset LatexCommand \index{wiki}
31898 \begin_inset LatexCommand \index{Release wiki}
31903 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31907 also holds some information about past and future releases.
31910 \begin_layout Section
31912 \begin_inset LatexCommand \index{Examples}
31919 \begin_layout Standard
31920 You'll find some small examples in the directory
31922 sdcc/device/examples/.
31925 More examples and libraries are available at
31927 The SDCC Open Knowledge Resource
31928 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31935 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31942 \begin_layout Standard
31943 \begin_inset Note Note
31946 \begin_layout Standard
31947 I did insert a reference to Paul's web site here although it seems rather
31948 dedicated to a specific 8032 board (I think it's okay because it f.e.
31949 shows LCD/Harddisc interface and has a free 8051 monitor.
31950 Independent 8032 board vendors face hard competition of heavily subsidized
31951 development boards anyway).
31954 \begin_layout Standard
31955 Maybe we should include some links to real world applications.
31956 Preferably pointer to pointers (one for each architecture) so this stays
31965 \begin_layout Section
31967 \begin_inset LatexCommand \label{sec:Quality-control}
31972 \begin_inset LatexCommand \index{Quality control}
31979 \begin_layout Standard
31980 The compiler is passed through snaphot build compile and build checks.
31986 \begin_inset LatexCommand \index{Regression test}
31990 check that SDCC itself compiles flawlessly on several host platforms (i386,
31991 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
31992 the quality of the code generated by SDCC by running the code for several
31993 target platforms through simulators.
31994 The regression test suite comprises more than 100 files which expand to
31995 more than 500 test cases which include more than 4500 tests.
31996 The results of these tests are published daily on SDCC's snapshot page
31997 (click on the red or green symbols on the right side of
31998 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32005 \begin_layout Standard
32006 There is a separate document
32009 \begin_inset LatexCommand \index{Test suite}
32016 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32020 about the regression test suite.
32023 \begin_layout Standard
32024 You'll find the test code in the directory
32026 sdcc/support/regression
32029 You can run these tests manually by running
32033 in this directory (or f.e.
32038 \begin_inset Quotes sld
32042 \begin_inset Quotes srd
32048 if you don't want to run the complete tests).
32049 The test code might also be interesting if you want to look for examples
32050 \begin_inset LatexCommand \index{Examples}
32054 checking corner cases of SDCC or if you plan to submit patches
32055 \begin_inset LatexCommand \index{Patch submission}
32062 \begin_layout Standard
32063 The 14bit pic port uses a different set of regression tests
32064 \begin_inset LatexCommand \index{Regression test (PIC14)}
32068 , you'll find them in the directory
32070 sdcc/src/regression
32075 \begin_layout Section
32076 Use of SDCC in Education
32079 \begin_layout Standard
32088 \begin_layout Standard
32089 the phrase "use in education" might evoke the association "
32093 fit for use in education".
32094 This connotation is not intended but nevertheless risked as the licensing
32095 of SDCC makes it difficult to offer educational discounts
32101 If your rationales are to:
32104 \begin_layout Enumerate
32105 give students a chance to understand the
32109 steps of code generation
32112 \begin_layout Enumerate
32113 have a curriculum that can be extended for years.
32114 Then you could use an fpga board as target and your curriculum will seamlessly
32115 extend from logic synthesis (
32116 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32121 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32125 ), over assembly programming, to C to FPGA compilers (
32126 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32133 \begin_layout Enumerate
32134 be able to insert excursions about skills like using a revision control
32135 system, submitting/applying patches, using a type-setting (as opposed to
32136 word-processing) engine LyX/LaTeX, using
32137 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32142 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32146 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32147 Source Software, CPU simulation, compiler regression tests
32148 \begin_inset LatexCommand \index{Regression test}
32155 And if there should be a shortage of ideas then you can always point students
32156 to the ever-growing feature request list
32157 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32164 \begin_layout Enumerate
32165 not tie students to a specific host platform and instead allow them to use
32170 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
32172 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32179 \begin_layout Enumerate
32180 not encourage students to use illegal copies of educational software
32183 \begin_layout Enumerate
32184 be immune to licensing/availability/price changes of the chosen tool chain
32187 \begin_layout Enumerate
32188 be able to change to a new target platform without having to adopt a new
32192 \begin_layout Enumerate
32193 have complete control over and insight into the tool chain
32196 \begin_layout Enumerate
32197 make your students aware about the pros and cons of open source software
32201 \begin_layout Enumerate
32202 give back to the public as you are probably at least partially publically
32206 \begin_layout Enumerate
32207 give students a chance to publically prove their skills and to possibly
32208 see a world wide impact
32211 \begin_layout Standard
32212 then SDCC is probably among the first choices.
32213 Well, probably SDCC might be the only choice.
32218 \begin_layout Chapter
32219 SDCC Technical Data
32222 \begin_layout Section
32224 \begin_inset LatexCommand \index{Optimizations}
32231 \begin_layout Standard
32232 SDCC performs a host of standard optimizations in addition to some MCU specific
32237 \begin_layout Subsection
32238 Sub-expression Elimination
32239 \begin_inset LatexCommand \index{Subexpression elimination}
32246 \begin_layout Standard
32247 The compiler does local and
32266 \begin_layout Verse
32274 \begin_layout Standard
32275 will be translated to
32278 \begin_layout Verse
32288 \begin_layout Standard
32289 Some subexpressions are not as obvious as the above example, e.g.:
32292 \begin_layout Verse
32300 \begin_layout Standard
32301 In this case the address arithmetic a->b[i] will be computed only once;
32302 the equivalent code in C would be.
32305 \begin_layout Verse
32315 \begin_layout Standard
32316 The compiler will try to keep these temporary variables in registers.
32319 \begin_layout Subsection
32320 Dead-Code Elimination
32321 \begin_inset LatexCommand \index{Dead-code elimination}
32328 \begin_layout Verse
32343 i = 1; \InsetSpace ~
32352 global = 1;\InsetSpace ~
32366 global = 3;\InsetSpace ~
32372 \begin_layout Standard
32376 \begin_layout Verse
32392 \begin_layout Subsection
32394 \begin_inset LatexCommand \index{Copy propagation}
32401 \begin_layout Verse
32425 \begin_layout Standard
32429 \begin_layout Verse
32453 \begin_layout Standard
32454 Note: the dead stores created by this copy propagation will be eliminated
32455 by dead-code elimination.
32458 \begin_layout Subsection
32460 \begin_inset LatexCommand \index{Loop optimization}
32465 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32472 \begin_layout Standard
32473 Two types of loop optimizations are done by SDCC
32481 of loop induction variables.
32482 In addition to the strength reduction the optimizer marks the induction
32483 variables and the register allocator tries to keep the induction variables
32484 in registers for the duration of the loop.
32485 Because of this preference of the register allocator
32486 \begin_inset LatexCommand \index{Register allocation}
32490 , loop induction optimization causes an increase in register pressure, which
32491 may cause unwanted spilling of other temporary variables into the stack
32492 \begin_inset LatexCommand \index{stack}
32497 The compiler will generate a warning message when it is forced to allocate
32498 extra space either on the stack or data space.
32499 If this extra space allocation is undesirable then induction optimization
32500 can be eliminated either for the entire source file (with -
32504 \begin_layout Standard
32513 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32515 \begin_inset LatexCommand \index{\#pragma noinduction}
32526 \begin_layout Verse
32529 for (i = 0 ; i < 100 ; i ++)
32538 \begin_layout Standard
32542 \begin_layout Verse
32547 for (i = 0; i < 100; i++)
32556 \begin_layout Standard
32557 As mentioned previously some loop invariants are not as apparent, all static
32558 address computations are also moved out of the loop.
32563 \begin_inset LatexCommand \index{Strength reduction}
32567 , this optimization substitutes an expression by a cheaper expression:
32570 \begin_layout Verse
32573 for (i=0;i < 100; i++)
32582 \begin_layout Standard
32586 \begin_layout Verse
32593 for (i=0;i< 100;i++) {
32599 ar[itemp1] = itemp2;
32617 \begin_layout Standard
32618 The more expensive multiplication
32619 \begin_inset LatexCommand \index{Multiplication}
32623 is changed to a less expensive addition.
32626 \begin_layout Subsection
32628 \begin_inset LatexCommand \index{Loop reversing}
32635 \begin_layout Standard
32636 This optimization is done to reduce the overhead of checking loop boundaries
32637 for every iteration.
32638 Some simple loops can be reversed and implemented using a
32639 \begin_inset Quotes eld
32642 decrement and jump if not zero
32643 \begin_inset Quotes erd
32647 SDCC checks for the following criterion to determine if a loop is reversible
32648 (note: more sophisticated compilers use data-dependency analysis to make
32649 this determination, SDCC uses a more simple minded analysis).
32652 \begin_layout Itemize
32653 The 'for' loop is of the form
32659 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32669 \begin_layout Itemize
32670 The <for body> does not contain
32671 \begin_inset Quotes eld
32675 \begin_inset Quotes erd
32679 \begin_inset Quotes erd
32685 \begin_layout Itemize
32686 All goto's are contained within the loop.
32689 \begin_layout Itemize
32690 No function calls within the loop.
32693 \begin_layout Itemize
32694 The loop control variable <sym> is not assigned any value within the loop
32697 \begin_layout Itemize
32698 The loop control variable does NOT participate in any arithmetic operation
32702 \begin_layout Itemize
32703 There are NO switch statements in the loop.
32706 \begin_layout Subsection
32707 Algebraic Simplifications
32710 \begin_layout Standard
32711 SDCC does numerous algebraic simplifications, the following is a small sub-set
32712 of these optimizations.
32715 \begin_layout Verse
32718 i = j + 0;\InsetSpace ~
32722 /* changed to: */\InsetSpace ~
32728 i /= 2;\InsetSpace ~
32735 /* changed to: */\InsetSpace ~
32742 = j - j;\InsetSpace ~
32746 /* changed to: */\InsetSpace ~
32752 i = j / 1;\InsetSpace ~
32756 /* changed to: */\InsetSpace ~
32763 \begin_layout Standard
32764 Note the subexpressions
32765 \begin_inset LatexCommand \index{Subexpression}
32769 given above are generally introduced by macro expansions or as a result
32770 of copy/constant propagation.
32773 \begin_layout Subsection
32774 'switch' Statements
32775 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32780 \begin_inset LatexCommand \index{switch statement}
32787 \begin_layout Standard
32788 SDCC can optimize switch statements to jump tables
32789 \begin_inset LatexCommand \index{jump tables}
32794 It makes the decision based on an estimate of the generated code size.
32795 SDCC is quite liberal in the requirements for jump table generation:
32798 \begin_layout Itemize
32799 The labels need not be in order, and the starting number need not be one
32800 or zero, the case labels are in numerical sequence or not too many case
32801 labels are missing.
32805 \begin_layout Verse
32808 switch(i) {\InsetSpace ~
32839 case 4: ...\InsetSpace ~
32871 case 5: ...\InsetSpace ~
32903 case 3: ...\InsetSpace ~
32934 case 6: ...\InsetSpace ~
32966 case 7: ...\InsetSpace ~
32998 case 8: ...\InsetSpace ~
33030 case 9: ...\InsetSpace ~
33062 case 10: ...\InsetSpace ~
33093 case 11: ...\InsetSpace ~
33160 \begin_layout Standard
33161 Both the above switch statements will be implemented using a jump-table.
33162 The example to the right side is slightly more efficient as the check for
33163 the lower boundary of the jump-table is not needed.
33167 \begin_layout Itemize
33168 The number of case labels is not larger than supported by the target architectur
33172 \begin_layout Itemize
33173 If the case labels are not in numerical sequence ('gaps' between cases)
33174 SDCC checks whether a jump table with additionally inserted dummy cases
33175 is still attractive.
33179 \begin_layout Itemize
33180 If the starting number is not zero and a check for the lower boundary of
33181 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33186 \begin_layout Standard
33187 Switch statements which have large gaps in the numeric sequence or those
33188 that have too many case labels can be split into more than one switch statement
33189 for efficient code generation, e.g.:
33192 \begin_layout Verse
33270 \begin_layout Standard
33271 If the above switch statement is broken down into two switch statements
33274 \begin_layout Verse
33317 \begin_layout Standard
33321 \begin_layout Verse
33364 \begin_layout Standard
33365 then both the switch statements will be implemented using jump-tables whereas
33366 the unmodified switch statement will not be.
33369 \begin_layout Standard
33370 \begin_inset Note Note
33373 \begin_layout Standard
33374 There might be reasons which SDCC cannot know about to either favour or
33375 not favour jump tables.
33376 If the target system has to be as quick for the last switch case as for
33377 the first (pro jump table), or if the switch argument is known to be zero
33378 in the majority of the cases (contra jump table).
33386 \begin_layout Standard
33387 The pragma nojtbound
33388 \begin_inset LatexCommand \index{\#pragma nojtbound}
33392 can be used to turn off checking the
33405 It has no effect if a default label is supplied.
33406 Use of this pragma is dangerous: if the switch
33407 \begin_inset LatexCommand \index{switch statement}
33411 argument is not matched by a case statement the processor will happily
33415 \begin_layout Subsection
33416 Bit-shifting Operations
33417 \begin_inset LatexCommand \index{Bit shifting}
33424 \begin_layout Standard
33425 Bit shifting is one of the most frequently used operation in embedded programmin
33427 SDCC tries to implement bit-shift operations in the most efficient way
33431 \begin_layout Verse
33444 \begin_layout Standard
33445 generates the following code:
33448 \begin_layout Verse
33463 \begin_layout Standard
33464 In general SDCC will never setup a loop if the shift count is known.
33468 \begin_layout Verse
33481 \begin_layout Standard
33485 \begin_layout Verse
33509 \begin_layout Subsection
33511 \begin_inset LatexCommand \index{Bit rotation}
33518 \begin_layout Standard
33519 A special case of the bit-shift operation is bit rotation
33520 \begin_inset LatexCommand \index{rotating bits}
33524 , SDCC recognizes the following expression to be a left bit-rotation:
33527 \begin_layout Verse
33535 char i;\InsetSpace ~
33546 /* unsigned is needed for rotation */
33551 i = ((i << 1) | (i >> 7));
33560 \begin_layout Standard
33561 will generate the following code:
33564 \begin_layout Verse
33581 \begin_layout Standard
33582 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33583 ns of this case will also be recognized as bit-rotation, i.e.:
33586 \begin_layout Verse
33589 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33592 \begin_layout Subsection
33593 Nibble and Byte Swapping
33596 \begin_layout Standard
33597 Other special cases of the bit-shift operations are nibble or byte swapping
33598 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33602 , SDCC recognizes the following expressions:
33605 \begin_layout Verse
33626 i = ((i << 4) | (i >> 4));
33632 j = ((j << 8) | (j >> 8));
33635 \begin_layout Standard
33636 and generates a swap instruction for the nibble swapping
33637 \begin_inset LatexCommand \index{Nibble swapping}
33641 or move instructions for the byte swapping
33642 \begin_inset LatexCommand \index{Byte swapping}
33648 \begin_inset Quotes sld
33652 \begin_inset Quotes srd
33655 example can be used to convert from little to big-endian or vice versa.
33656 If you want to change the endianness of a
33660 integer you have to cast to
33667 \begin_layout Standard
33668 Note that SDCC stores numbers in little-endian
33672 \begin_layout Standard
33673 Usually 8-bit processors don't care much about endianness.
33674 This is not the case for the standard 8051 which only has an instruction
33680 \begin_inset LatexCommand \index{DPTR}
33688 so little-endian is the more efficient byte order.
33694 \begin_inset LatexCommand \index{little-endian}
33699 \begin_inset LatexCommand \index{Endianness}
33704 lowest order first).
33707 \begin_layout Subsection
33709 \begin_inset LatexCommand \index{Highest Order Bit}
33714 \begin_inset LatexCommand \index{Any Order Bit}
33721 \begin_layout Standard
33722 It is frequently required to obtain the highest order bit of an integral
33723 type (long, int, short or char types).
33724 Also obtaining any other order bit is not uncommon.
33725 SDCC recognizes the following expressions to yield the highest order bit
33726 and generates optimized code for it, e.g.:
33729 \begin_layout Verse
33740 unsigned char hob1, aob1;
33744 bit hob2, hob3, aob2,
33754 hob1 = (gint >> 15) & 1;
33758 hob2 = (gint >> 15) & 1;
33762 hob3 = gint & 0x8000;
33767 aob1 = (gint >> 9) & 1;
33771 aob2 = (gint >> 8) & 1;
33775 aob3 = gint & 0x0800;
33785 \begin_layout Standard
33786 will generate the following code:
33789 \begin_layout Verse
33820 000A E5*01\InsetSpace ~
33847 000C 23\InsetSpace ~
33878 000D 54 01\InsetSpace ~
33906 000F F5*02\InsetSpace ~
33961 0011 E5*01\InsetSpace ~
33989 0013 33\InsetSpace ~
34019 0014 92*00\InsetSpace ~
34075 0016 E5*01\InsetSpace ~
34102 0018 33\InsetSpace ~
34132 0019 92*01\InsetSpace ~
34188 001B E5*01\InsetSpace ~
34247 001E 54 01\InsetSpace ~
34274 0020 F5*03\InsetSpace ~
34330 0022 E5*01\InsetSpace ~
34357 0024 13\InsetSpace ~
34387 0025 92*02\InsetSpace ~
34443 0027 E5*01\InsetSpace ~
34498 002B 92*03\InsetSpace ~
34526 \begin_layout Standard
34527 Other variations of these cases however will
34532 They are standard C expressions, so I heartily recommend these be the only
34533 way to get the highest order bit, (it is portable).
34534 Of course it will be recognized even if it is embedded in other expressions,
34538 \begin_layout Verse
34541 xyz = gint + ((gint >> 15) & 1);
34544 \begin_layout Standard
34545 will still be recognized.
34548 \begin_layout Subsection
34550 \begin_inset LatexCommand \index{Higher Order Byte}
34554 / Higher Order Word
34555 \begin_inset LatexCommand \index{Higher Order Word}
34562 \begin_layout Standard
34563 It is also frequently required to obtain a higher order byte or word of
34564 a larger integral type (long, int or short types).
34565 SDCC recognizes the following expressions to yield the higher order byte
34566 or word and generates optimized code for it, e.g.:
34569 \begin_layout Verse
34574 unsigned long int glong;
34582 unsigned char hob1,
34587 unsigned int how1, how2;
34596 hob1 = (gint >> 8) & 0xFF;
34600 hob2 = glong >> 24;
34604 how1 = (glong >> 16) & 0xFFFF;
34619 \begin_layout Standard
34620 will generate the following code:
34623 \begin_layout Verse
34654 0037 85*01*06\InsetSpace ~
34676 _foo_hob1_1_1,(_gint + 1)
34707 003A 85*05*07\InsetSpace ~
34729 _foo_hob2_1_1,(_glong + 3)
34759 003D 85*04*08\InsetSpace ~
34782 _foo_how1_1_1,(_glong + 2)
34784 0040 85*05*09\InsetSpace ~
34809 0043 85*03*0A\InsetSpace ~
34831 _foo_how2_1_1,(_glong + 1)
34833 0046 85*04*0B\InsetSpace ~
34856 (_foo_how2_1_1 + 1),(_glong + 2)
34859 \begin_layout Standard
34860 Again, variations of these cases may
34865 They are standard C expressions, so I heartily recommend these be the only
34866 way to get the higher order byte/word, (it is portable).
34867 Of course it will be recognized even if it is embedded in other expressions,
34871 \begin_layout Verse
34874 xyz = gint + ((gint >> 8) & 0xFF);
34877 \begin_layout Standard
34878 will still be recognized.
34881 \begin_layout Subsection
34883 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34888 \begin_inset LatexCommand \index{Peephole optimizer}
34895 \begin_layout Standard
34896 The compiler uses a rule based, pattern matching and re-writing mechanism
34897 for peep-hole optimization.
34902 a peep-hole optimizer by Christopher W.
34903 Fraser (cwfraser\InsetSpace ~
34906 A default set of rules are compiled into the compiler, additional rules
34907 may be added with the
34913 \begin_layout Standard
34923 \begin_inset LatexCommand \index{-\/-peep-file}
34930 The rule language is best illustrated with examples.
34933 \begin_layout Verse
34955 \begin_layout Standard
34956 The above rule will change the following assembly
34957 \begin_inset LatexCommand \index{Assembler routines}
34964 \begin_layout Verse
34972 \begin_layout Standard
34976 \begin_layout Verse
34982 \begin_layout Standard
34983 Note: All occurrences of a
34987 (pattern variable) must denote the same string.
34988 With the above rule, the assembly sequence:
34991 \begin_layout Verse
34999 \begin_layout Standard
35000 will remain unmodified.
35004 Other special case optimizations may be added by the
35011 \begin_layout Standard
35024 some variants of the 8051 MCU
35025 \begin_inset LatexCommand \index{MCS51 variants}
35038 The following two rules will change all
35055 \begin_layout Verse
35058 replace { lcall %1 } by { acall %1 }
35060 replace { ljmp %1 } by { ajmp %1 }
35063 \begin_layout Standard
35066 inline-assembler code
35068 is also passed through the peep hole optimizer, thus the peephole optimizer
35069 can also be used as an assembly level macro expander.
35070 The rules themselves are MCU dependent whereas the rule language infra-structur
35071 e is MCU independent.
35072 Peephole optimization rules for other MCU can be easily programmed using
35077 The syntax for a rule is as follows:
35080 \begin_layout Verse
35083 rule := replace [ restart ] '{' <assembly sequence> '
35121 <assembly sequence> '
35139 '}' [if <functionName> ] '
35144 \begin_layout Standard
35145 <assembly sequence> := assembly instruction (each instruction including
35146 labels must be on a separate line).
35150 The optimizer will apply to the rules
35151 one by one from the top in the sequence of their appearance, it will terminate
35152 when all rules are exhausted.
35153 If the 'restart' option is specified, then the optimizer will start matching
35154 the rules again from the top, this option for a rule is expensive (performance)
35155 , it is intended to be used in situations where a transformation will trigger
35156 the same rule again.
35157 An example of this (not a good one, it has side effects) is the following
35161 \begin_layout Verse
35181 \begin_layout Standard
35182 Note that the replace pattern cannot be a blank, but can be a comment line.
35183 Without the 'restart' option only the innermost 'pop' 'push' pair would
35184 be eliminated, i.e.:
35187 \begin_layout Verse
35199 \begin_layout Standard
35203 \begin_layout Verse
35213 \begin_layout Standard
35218 the restart option the rule will be applied again to the resulting code
35219 and then all the pop-push pairs will be eliminated to yield:
35222 \begin_layout Verse
35230 \begin_layout Standard
35231 A conditional function can be attached to a rule.
35232 Attaching rules are somewhat more involved, let me illustrate this with
35236 \begin_layout Verse
35260 \begin_layout Standard
35261 The optimizer does a look-up of a function name table defined in function
35266 in the source file SDCCpeeph.c, with the name
35271 If it finds a corresponding entry the function is called.
35272 Note there can be no parameters specified for these functions, in this
35277 is crucial, since the function
35281 expects to find the label in that particular variable (the hash table containin
35282 g the variable bindings is passed as a parameter).
35283 If you want to code more such functions, take a close look at the function
35284 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35285 Currently implemented are
35287 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35288 24bitMode, portIsDS390, 24bitModeAndPortDS390
35297 \begin_layout Standard
35298 I know this whole thing is a little kludgey, but maybe some day we will
35299 have some better means.
35300 If you are looking at this file, you will see the default rules that are
35301 compiled into the compiler, you can add your own rules in the default set
35302 there if you get tired of specifying the -
35306 \begin_layout Standard
35318 \begin_layout Section
35320 \begin_inset LatexCommand \index{ANSI-compliance}
35325 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35332 \begin_layout Standard
35333 The latest publically available version of the standard
35335 ISO/IEC 9899 - Programming languages - C
35337 should be available at:
35338 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35347 \begin_layout Standard
35348 Deviations from the compliance:
35351 \begin_layout Itemize
35352 functions are not reentrant
35353 \begin_inset LatexCommand \index{reentrant}
35357 unless explicitly declared as such or the
35363 \begin_layout Standard
35373 \begin_inset LatexCommand \index{-\/-stack-auto}
35379 command line option is specified.
35382 \begin_layout Itemize
35384 \begin_inset LatexCommand \index{struct}
35389 \begin_inset LatexCommand \index{union}
35393 cannot be assigned values directly, cannot be passed as function parameters
35394 or assigned to each other and cannot be a return value
35395 \begin_inset LatexCommand \index{return value}
35399 from a function, e.g.:
35403 \begin_layout Verse
35426 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35445 s parms) /* invalid in SDCC although allowed in ANSI */
35467 return rets; /* is invalid in SDCC although allowed in ANSI */
35473 \begin_layout Itemize
35474 initialization of structure arrays must be fully braced.
35478 \begin_layout Verse
35481 struct s { char x } a[] = {1, 2};\InsetSpace ~
35486 /* invalid in SDCC */
35489 } a[] = {{1}, {2}}; /* OK */
35493 \begin_layout Itemize
35495 \begin_inset LatexCommand \index{long long (not supported)}
35500 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35507 \begin_layout Itemize
35509 \begin_inset LatexCommand \index{double (not supported)}
35513 ' precision floating point
35514 \begin_inset LatexCommand \index{Floating point support}
35521 \begin_layout Itemize
35523 \begin_inset LatexCommand \index{K\&R style}
35527 function declarations are NOT allowed.
35531 \begin_layout Verse
35534 foo(i,j) /* this old style of function declarations */
35536 int i,j; /* are valid
35537 in ANSI but not valid in SDCC */
35552 \begin_layout Itemize
35553 Most enhancements in C99 are not supported, f.e.:
35557 \begin_layout Verse
35562 \begin_inset LatexCommand \index{inline (not supported)}
35568 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35574 can be used as a work around */
35582 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35586 \begin_layout Itemize
35587 Certain words that are valid identifiers in the standard may be reserved
35588 words in SDCC unless the
35594 \begin_layout Standard
35604 \begin_inset LatexCommand \index{-\/-std-c89}
35612 \begin_layout Standard
35622 \begin_inset LatexCommand \index{-\/-std-c99}
35628 command line options are used.
35629 These may include (depending on the selected processor): 'at', 'banked',
35630 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35631 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35632 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35634 Compliant equivalents of these keywords are always available in a form
35635 that begin with two underscores
35636 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35641 '__data' instead of 'data'.
35644 \begin_layout Section
35645 Cyclomatic Complexity
35646 \begin_inset LatexCommand \index{Cyclomatic complexity}
35653 \begin_layout Standard
35654 Cyclomatic complexity of a function is defined as the number of independent
35655 paths the program can take during execution of the function.
35656 This is an important number since it defines the number test cases you
35657 have to generate to validate the function.
35658 The accepted industry standard for complexity number is 10, if the cyclomatic
35659 complexity reported by SDCC exceeds 10 you should think about simplification
35660 of the function logic.
35661 Note that the complexity level is not related to the number of lines of
35662 code in a function.
35663 Large functions can have low complexity, and small functions can have large
35669 SDCC uses the following formula to compute the complexity:
35674 \begin_layout Standard
35675 complexity = (number of edges in control flow graph) - (number of nodes
35676 in control flow graph) + 2;
35680 Having said that the industry standard is 10,
35681 you should be aware that in some cases it be may unavoidable to have a
35682 complexity level of less than 10.
35683 For example if you have switch statement with more than 10 case labels,
35684 each case label adds one to the complexity level.
35685 The complexity level is by no means an absolute measure of the algorithmic
35686 complexity of the function, it does however provide a good starting point
35687 for which functions you might look at for further optimization.
35690 \begin_layout Section
35691 Retargetting for other Processors
35694 \begin_layout Standard
35695 The issues for retargetting the compiler are far too numerous to be covered
35697 What follows is a brief description of each of the seven phases of the
35698 compiler and its MCU dependency.
35701 \begin_layout Itemize
35702 Parsing the source and building the annotated parse tree.
35703 This phase is largely MCU independent (except for the language extensions).
35704 Syntax & semantic checks are also done in this phase, along with some initial
35705 optimizations like back patching labels and the pattern matching optimizations
35706 like bit-rotation etc.
35709 \begin_layout Itemize
35710 The second phase involves generating an intermediate code which can be easy
35711 manipulated during the later phases.
35712 This phase is entirely MCU independent.
35713 The intermediate code generation assumes the target machine has unlimited
35714 number of registers, and designates them with the name iTemp.
35715 The compiler can be made to dump a human readable form of the code generated
35720 \begin_layout Standard
35732 \begin_layout Itemize
35733 This phase does the bulk of the standard optimizations and is also MCU independe
35735 This phase can be broken down into several sub-phases:
35739 Break down intermediate
35740 code (iCode) into basic blocks.
35742 Do control flow & data flow analysis on the
35745 Do local common subexpression elimination, then global subexpressio
35748 Dead code elimination
35752 If loop optimizations
35753 caused any changes then do 'global subexpression elimination' and 'dead
35754 code elimination' again.
35757 \begin_layout Itemize
35758 This phase determines the live-ranges; by live range I mean those iTemp
35759 variables defined by the compiler that still survive after all the optimization
35761 Live range analysis
35762 \begin_inset LatexCommand \index{Live range analysis}
35766 is essential for register allocation, since these computation determines
35767 which of these iTemps will be assigned to registers, and for how long.
35770 \begin_layout Itemize
35771 Phase five is register allocation.
35772 There are two parts to this process.
35776 The first part I call 'register packing'
35777 (for lack of a better term).
35778 In this case several MCU specific expression folding is done to reduce
35783 The second part is more MCU independent and deals with
35784 allocating registers to the remaining live ranges.
35785 A lot of MCU specific code does creep into this phase because of the limited
35786 number of index registers available in the 8051.
35789 \begin_layout Itemize
35790 The Code generation phase is (unhappily), entirely MCU dependent and very
35791 little (if any at all) of this code can be reused for other MCU.
35792 However the scheme for allocating a homogenized assembler operand for each
35793 iCode operand may be reused.
35796 \begin_layout Itemize
35797 As mentioned in the optimization section the peep-hole optimizer is rule
35798 based system, which can reprogrammed for other MCUs.
35801 \begin_layout Standard
35802 More information is available in a wiki
35803 \begin_inset LatexCommand \index{wiki}
35808 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35812 ) and in the thread
35813 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35820 \begin_layout Chapter
35822 \begin_inset LatexCommand \index{Compiler internals}
35829 \begin_layout Section
35830 The anatomy of the compiler
35831 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35838 \begin_layout Standard
35841 This is an excerpt from an article published in Circuit Cellar Magazine
35847 It's a little outdated (the compiler is much more efficient now and user/develo
35848 per friendly), but pretty well exposes the guts of it all.
35854 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35855 It is fairly easy to retarget for other 8-bit MCU.
35856 Here we take a look at some of the internals of the compiler.
35860 \begin_layout Paragraph*
35862 \begin_inset LatexCommand \index{Parsing}
35869 \begin_layout Standard
35870 Parsing the input source file and creating an AST (Annotated Syntax Tree
35871 \begin_inset LatexCommand \index{Annotated syntax tree}
35876 This phase also involves propagating types (annotating each node of the
35877 parse tree with type information) and semantic analysis.
35878 There are some MCU specific parsing rules.
35879 For example the storage classes, the extended storage classes are MCU specific
35880 while there may be a xdata storage class for 8051 there is no such storage
35881 class for z80 or Atmel AVR.
35882 SDCC allows MCU specific storage class extensions, i.e.
35883 xdata will be treated as a storage class specifier when parsing 8051 C
35884 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35888 \begin_layout Paragraph*
35890 \begin_inset LatexCommand \index{iCode}
35897 \begin_layout Standard
35898 Intermediate code generation.
35899 In this phase the AST is broken down into three-operand form (iCode).
35900 These three operand forms are represented as doubly linked lists.
35901 ICode is the term given to the intermediate form generated by the compiler.
35902 ICode example section shows some examples of iCode generated for some simple
35903 C source functions.
35906 \begin_layout Paragraph*
35908 \begin_inset LatexCommand \index{Optimizations}
35915 \begin_layout Standard
35916 Bulk of the target independent optimizations is performed in this phase.
35917 The optimizations include constant propagation, common sub-expression eliminati
35918 on, loop invariant code movement, strength reduction of loop induction variables
35919 and dead-code elimination.
35922 \begin_layout Paragraph*
35923 Live range analysis
35924 \begin_inset LatexCommand \index{Live range analysis}
35931 \begin_layout Standard
35932 During intermediate code generation phase, the compiler assumes the target
35933 machine has infinite number of registers and generates a lot of temporary
35935 The live range computation determines the lifetime of each of these compiler-ge
35936 nerated temporaries.
35937 A picture speaks a thousand words.
35938 ICode example sections show the live range annotations for each of the
35940 It is important to note here, each iCode is assigned a number in the order
35941 of its execution in the function.
35942 The live ranges are computed in terms of these numbers.
35943 The from number is the number of the iCode which first defines the operand
35944 and the to number signifies the iCode which uses this operand last.
35947 \begin_layout Paragraph*
35948 Register Allocation
35949 \begin_inset LatexCommand \index{Register allocation}
35956 \begin_layout Standard
35957 The register allocation determines the type and number of registers needed
35959 In most MCUs only a few registers can be used for indirect addressing.
35960 In case of 8051 for example the registers R0 & R1 can be used to indirectly
35961 address the internal ram and DPTR to indirectly address the external ram.
35962 The compiler will try to allocate the appropriate register to pointer variables
35964 ICode example section shows the operands annotated with the registers assigned
35966 The compiler will try to keep operands in registers as much as possible;
35967 there are several schemes the compiler uses to do achieve this.
35968 When the compiler runs out of registers the compiler will check to see
35969 if there are any live operands which is not used or defined in the current
35970 basic block being processed, if there are any found then it will push that
35971 operand and use the registers in this block, the operand will then be popped
35972 at the end of the basic block.
35976 \begin_layout Standard
35977 There are other MCU specific considerations in this phase.
35978 Some MCUs have an accumulator; very short-lived operands could be assigned
35979 to the accumulator instead of a general-purpose register.
35982 \begin_layout Paragraph*
35986 \begin_layout Standard
35987 Figure II gives a table of iCode
35988 \begin_inset LatexCommand \index{iCode}
35992 operations supported by the compiler.
35993 The code generation involves translating these operations into corresponding
35994 assembly code for the processor.
35995 This sounds overly simple but that is the essence of code generation.
35996 Some of the iCode operations are generated on a MCU specific manner for
35997 example, the z80 port does not use registers to pass parameters so the
35998 SEND and RECV iCode operations will not be generated, and it also does
35999 not support JUMPTABLES.
36005 \begin_layout Standard
36009 \begin_inset Tabular
36010 <lyxtabular version="3" rows="39" columns="4">
36011 <features islongtable="true" headBottomDL="true">
36012 <column alignment="block" valignment="top" leftline="true" width="13col%">
36013 <column alignment="left" valignment="top" leftline="true" width="13col%">
36014 <column alignment="block" valignment="top" leftline="true" width="22col%">
36015 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36016 <row topline="true" bottomline="true" endhead="true">
36017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36020 \begin_layout Standard
36026 \begin_inset LatexCommand \index{iCode}
36035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36038 \begin_layout Standard
36046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36049 \begin_layout Standard
36057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36060 \begin_layout Standard
36069 <row topline="true">
36070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36073 \begin_layout Standard
36081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36084 \begin_layout Standard
36087 IC_LEFT() IC_RESULT()
36092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36095 \begin_layout Standard
36103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36106 \begin_layout Standard
36109 IC_RESULT = ! IC_LEFT;
36115 <row topline="true">
36116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36119 \begin_layout Standard
36127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36130 \begin_layout Standard
36133 IC_LEFT() IC_RESULT()
36138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36141 \begin_layout Standard
36144 Bitwise complement of
36149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36152 \begin_layout Standard
36155 IC_RESULT = ~IC_LEFT;
36161 <row topline="true">
36162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36165 \begin_layout Standard
36173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36176 \begin_layout Standard
36179 IC_LEFT() IC_RESULT()
36184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36187 \begin_layout Standard
36190 Rotate right with carry
36195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36198 \begin_layout Standard
36201 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36207 <row topline="true">
36208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36211 \begin_layout Standard
36219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36222 \begin_layout Standard
36225 IC_LEFT() IC_RESULT()
36230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36233 \begin_layout Standard
36236 Rotate left with carry
36241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36244 \begin_layout Standard
36247 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36253 <row topline="true">
36254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36257 \begin_layout Standard
36265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36268 \begin_layout Standard
36271 IC_LEFT() IC_RESULT()
36276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36279 \begin_layout Standard
36282 Get the highest order bit of IC_LEFT
36287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36290 \begin_layout Standard
36293 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36299 <row topline="true">
36300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36303 \begin_layout Standard
36311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36314 \begin_layout Standard
36317 IC_LEFT() IC_RESULT()
36322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36325 \begin_layout Standard
36333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36336 \begin_layout Standard
36339 IC_RESULT = - IC_LEFT;
36345 <row topline="true">
36346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36349 \begin_layout Standard
36357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36360 \begin_layout Standard
36368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36371 \begin_layout Standard
36374 Push the operand into stack
36379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36382 \begin_layout Standard
36391 <row topline="true">
36392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36395 \begin_layout Standard
36403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36406 \begin_layout Standard
36414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36417 \begin_layout Standard
36420 Pop the operand from the stack
36425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36428 \begin_layout Standard
36437 <row topline="true">
36438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36441 \begin_layout Standard
36449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36452 \begin_layout Standard
36455 IC_LEFT() IC_RESULT()
36460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36463 \begin_layout Standard
36466 Call the function represented by IC_LEFT
36471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36474 \begin_layout Standard
36477 IC_RESULT = IC_LEFT();
36483 <row topline="true">
36484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36487 \begin_layout Standard
36495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36498 \begin_layout Standard
36501 IC_LEFT() IC_RESULT()
36506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36509 \begin_layout Standard
36512 Call via function pointer
36517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36520 \begin_layout Standard
36523 IC_RESULT = (*IC_LEFT)();
36529 <row topline="true">
36530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36533 \begin_layout Standard
36541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36544 \begin_layout Standard
36552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36555 \begin_layout Standard
36558 Return the value in operand IC_LEFT
36563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36566 \begin_layout Standard
36575 <row topline="true">
36576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36579 \begin_layout Standard
36587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36590 \begin_layout Standard
36598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36601 \begin_layout Standard
36609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36612 \begin_layout Standard
36621 <row topline="true">
36622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36625 \begin_layout Standard
36633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36636 \begin_layout Standard
36644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36647 \begin_layout Standard
36655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36658 \begin_layout Standard
36667 <row topline="true">
36668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36671 \begin_layout Standard
36679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36682 \begin_layout Standard
36685 IC_LEFT() IC_RIGHT() IC_RESULT()
36690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36693 \begin_layout Standard
36701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36704 \begin_layout Standard
36707 IC_RESULT = IC_LEFT + IC_RIGHT
36713 <row topline="true">
36714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36717 \begin_layout Standard
36725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36728 \begin_layout Standard
36731 IC_LEFT() IC_RIGHT() IC_RESULT()
36736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36739 \begin_layout Standard
36747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36750 \begin_layout Standard
36753 IC_RESULT = IC_LEFT - IC_RIGHT
36759 <row topline="true">
36760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36763 \begin_layout Standard
36771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36774 \begin_layout Standard
36777 IC_LEFT() IC_RIGHT() IC_RESULT()
36782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36785 \begin_layout Standard
36793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36796 \begin_layout Standard
36799 IC_RESULT = IC_LEFT * IC_RIGHT;
36805 <row topline="true">
36806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36809 \begin_layout Standard
36817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36820 \begin_layout Standard
36823 IC_LEFT() IC_RIGHT() IC_RESULT()
36828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36831 \begin_layout Standard
36839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36842 \begin_layout Standard
36845 IC_RESULT = IC_LEFT / IC_RIGHT;
36851 <row topline="true">
36852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36855 \begin_layout Standard
36863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36866 \begin_layout Standard
36869 IC_LEFT() IC_RIGHT() IC_RESULT()
36874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36877 \begin_layout Standard
36885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36888 \begin_layout Standard
36891 IC_RESULT = IC_LEFT % IC_RIGHT;
36897 <row topline="true">
36898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36901 \begin_layout Standard
36909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36912 \begin_layout Standard
36915 IC_LEFT() IC_RIGHT() IC_RESULT()
36920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36923 \begin_layout Standard
36931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36934 \begin_layout Standard
36937 IC_RESULT = IC_LEFT < IC_RIGHT;
36943 <row topline="true">
36944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36947 \begin_layout Standard
36955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36958 \begin_layout Standard
36961 IC_LEFT() IC_RIGHT() IC_RESULT()
36966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36969 \begin_layout Standard
36977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36980 \begin_layout Standard
36983 IC_RESULT = IC_LEFT > IC_RIGHT;
36989 <row topline="true">
36990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36993 \begin_layout Standard
37001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37004 \begin_layout Standard
37007 IC_LEFT() IC_RIGHT() IC_RESULT()
37012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37015 \begin_layout Standard
37023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37026 \begin_layout Standard
37029 IC_RESULT = IC_LEFT == IC_RIGHT;
37035 <row topline="true">
37036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37039 \begin_layout Standard
37047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37050 \begin_layout Standard
37053 IC_LEFT() IC_RIGHT() IC_RESULT()
37058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37061 \begin_layout Standard
37064 Logical and operation
37069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37072 \begin_layout Standard
37075 IC_RESULT = IC_LEFT && IC_RIGHT;
37081 <row topline="true">
37082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37085 \begin_layout Standard
37093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37096 \begin_layout Standard
37099 IC_LEFT() IC_RIGHT() IC_RESULT()
37104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37107 \begin_layout Standard
37110 Logical or operation
37115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37118 \begin_layout Standard
37121 IC_RESULT = IC_LEFT || IC_RIGHT;
37127 <row topline="true">
37128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37131 \begin_layout Standard
37139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37142 \begin_layout Standard
37145 IC_LEFT() IC_RIGHT() IC_RESULT()
37150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37153 \begin_layout Standard
37161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37164 \begin_layout Standard
37167 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37173 <row topline="true">
37174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37177 \begin_layout Standard
37185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37188 \begin_layout Standard
37191 IC_LEFT() IC_RIGHT() IC_RESULT()
37196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37199 \begin_layout Standard
37207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37210 \begin_layout Standard
37213 IC_RESULT = IC_LEFT | IC_RIGHT;
37219 <row topline="true">
37220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37223 \begin_layout Standard
37231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37234 \begin_layout Standard
37237 IC_LEFT() IC_RIGHT() IC_RESULT()
37242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37245 \begin_layout Standard
37253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37256 \begin_layout Standard
37259 IC_RESULT = IC_LEFT & IC_RIGHT;
37265 <row topline="true">
37266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37269 \begin_layout Standard
37277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37280 \begin_layout Standard
37283 IC_LEFT() IC_RIGHT() IC_RESULT()
37288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37291 \begin_layout Standard
37299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37302 \begin_layout Standard
37305 IC_RESULT = IC_LEFT << IC_RIGHT
37311 <row topline="true">
37312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37315 \begin_layout Standard
37323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37326 \begin_layout Standard
37329 IC_LEFT() IC_RIGHT() IC_RESULT()
37334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37337 \begin_layout Standard
37345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37348 \begin_layout Standard
37351 IC_RESULT = IC_LEFT >> IC_RIGHT
37357 <row topline="true">
37358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37361 \begin_layout Standard
37371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37374 \begin_layout Standard
37377 IC_LEFT() IC_RESULT()
37382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37385 \begin_layout Standard
37393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37396 \begin_layout Standard
37399 IC_RESULT = (*IC_LEFT);
37405 <row topline="true">
37406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37409 \begin_layout Standard
37417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37420 \begin_layout Standard
37423 IC_RIGHT() IC_RESULT()
37428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37431 \begin_layout Standard
37439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37442 \begin_layout Standard
37445 (*IC_RESULT) = IC_RIGHT;
37451 <row topline="true">
37452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37455 \begin_layout Standard
37463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37466 \begin_layout Standard
37469 IC_RIGHT() IC_RESULT()
37474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37477 \begin_layout Standard
37485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37488 \begin_layout Standard
37491 IC_RESULT = IC_RIGHT;
37497 <row topline="true">
37498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37501 \begin_layout Standard
37509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37512 \begin_layout Standard
37515 IC_COND IC_TRUE IC_LABEL
37520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37523 \begin_layout Standard
37527 If true label is present then jump to true label if condition is true else
37528 jump to false label if condition is false
37533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37536 \begin_layout Standard
37539 if (IC_COND) goto IC_TRUE;
37545 If (!IC_COND) goto IC_FALSE;
37551 <row topline="true">
37552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37555 \begin_layout Standard
37563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37566 \begin_layout Standard
37569 IC_LEFT() IC_RESULT()
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37577 \begin_layout Standard
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37588 \begin_layout Standard
37591 IC_RESULT = &IC_LEFT();
37597 <row topline="true">
37598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37601 \begin_layout Standard
37609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37612 \begin_layout Standard
37615 IC_JTCOND IC_JTLABELS
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37623 \begin_layout Standard
37626 Jump to list of labels depending on the value of JTCOND
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37634 \begin_layout Standard
37643 <row topline="true">
37644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37647 \begin_layout Standard
37655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37658 \begin_layout Standard
37661 IC_RIGHT() IC_LEFT() IC_RESULT()
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37669 \begin_layout Standard
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37680 \begin_layout Standard
37683 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37689 <row topline="true">
37690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37693 \begin_layout Standard
37701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37704 \begin_layout Standard
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37715 \begin_layout Standard
37718 This is used for passing parameters in registers;
37720 move IC_LEFT to the next
37721 available parameter register.
37726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37729 \begin_layout Standard
37738 <row topline="true">
37739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37742 \begin_layout Standard
37750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37753 \begin_layout Standard
37761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37764 \begin_layout Standard
37767 This is used for receiving parameters passed in registers;
37770 in the next parameter register to IC_RESULT
37775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37778 \begin_layout Standard
37787 <row topline="true" bottomline="true">
37788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37791 \begin_layout Standard
37795 (some more have been added)
37800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37803 \begin_layout Standard
37809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37812 \begin_layout Standard
37818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37821 \begin_layout Standard
37845 \begin_layout Standard
37846 \begin_inset Note Note
37849 \begin_layout Standard
37850 In the original article Figure II was announced to be downloadable on
37855 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37863 \begin_layout Paragraph*
37865 \begin_inset LatexCommand \index{iCode}
37872 \begin_layout Standard
37873 This section shows some details of iCode.
37874 The example C code does not do anything useful; it is used as an example
37875 to illustrate the intermediate code generated by the compiler.
37878 \begin_layout Verse
37888 /* This function does nothing useful.
37895 for the purpose of explaining iCode */
37898 short function (data
37907 short i=10; \InsetSpace ~
37909 /* dead initialization eliminated */
37915 /* dead initialization eliminated */
37943 /* compiler detects i,j to be induction
37948 for (i = 0, j = 10 ; i < 10 ; i++, j
37954 \begin_layout Standard
37977 mul += i * 3; \InsetSpace ~
37979 /* this multiplication remains */
37986 j * 3;\InsetSpace ~
37988 /* this multiplication changed to addition */
38002 \begin_layout Standard
38003 In addition to the operands each iCode contains information about the filename
38004 and line it corresponds to in the source file.
38005 The first field in the listing should be interpreted as follows:
38010 Filename(linenumber: iCode Execution sequence number : ICode hash table
38011 key : loop depth of the iCode).
38016 Then follows the human readable form of the ICode operation.
38017 Each operand of this triplet form can be of three basic types a) compiler
38018 generated temporary b) user defined variable c) a constant value.
38019 Note that local variables and parameters are replaced by compiler generated
38022 \begin_inset LatexCommand \index{Live range analysis}
38026 are computed only for temporaries (i.e.
38027 live ranges are not computed for global variables).
38029 \begin_inset LatexCommand \index{Register allocation}
38033 are allocated for temporaries only.
38034 Operands are formatted in the following manner:
38039 Operand Name [lr live-from : live-to ] { type information } [ registers
38045 As mentioned earlier the live ranges are computed in terms of the execution
38046 sequence number of the iCodes, for example
38048 the iTemp0 is live from (i.e.
38049 first defined in iCode with execution sequence number 3, and is last used
38050 in the iCode with sequence number 5).
38051 For induction variables such as iTemp21 the live range computation extends
38052 the lifetime from the start to the end of the loop.
38054 The register allocator
38055 used the live range information to allocate registers, the same registers
38056 may be used for different temporaries if their live ranges do not overlap,
38057 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38058 ranges do not overlap.
38059 In addition the allocator also takes into consideration the type and usage
38060 of a temporary, for example itemp6 is a pointer to near space and is used
38061 as to fetch data from (i.e.
38062 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38063 Some short lived temporaries are allocated to special registers which have
38064 meaning to the code generator e.g.
38065 iTemp13 is allocated to a pseudo register CC which tells the back end that
38066 the temporary is used only for a conditional jump the code generation makes
38067 use of this information to optimize a compare and jump ICode.
38071 \begin_inset LatexCommand \index{Loop optimization}
38075 performed by the compiler.
38076 It can detect induction variables iTemp21(i) and iTemp23(j).
38077 Also note the compiler does selective strength reduction
38078 \begin_inset LatexCommand \index{Strength reduction}
38083 the multiplication of an induction variable in line 18 (gint = j * 3) is
38084 changed to addition, a new temporary iTemp17 is allocated and assigned
38085 a initial value, a constant 3 is then added for each iteration of the loop.
38086 The compiler does not change the multiplication
38087 \begin_inset LatexCommand \index{Multiplication}
38091 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38094 Note the dead code elimination
38095 \begin_inset LatexCommand \index{Dead-code elimination}
38099 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38105 \begin_layout Standard
38108 Sample.c (5:1:0:0) _entry($9) :
38111 \begin_layout Standard
38114 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38117 \begin_layout Standard
38120 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38123 \begin_layout Standard
38126 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38129 \begin_layout Standard
38132 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38136 \begin_layout Standard
38139 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38142 \begin_layout Standard
38145 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38149 \begin_layout Standard
38152 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38155 \begin_layout Standard
38158 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38162 \begin_layout Standard
38165 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38169 \begin_layout Standard
38172 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38176 \begin_layout Standard
38179 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38183 \begin_layout Standard
38186 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38187 * int}[r0] + 0x2 {short}
38190 \begin_layout Standard
38193 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38196 \begin_layout Standard
38199 Sample.c(11:17:21:0)_whilebreak_0($3) :
38202 \begin_layout Standard
38205 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38208 \begin_layout Standard
38211 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38214 \begin_layout Standard
38217 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38220 \begin_layout Standard
38223 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38226 \begin_layout Standard
38229 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38232 \begin_layout Standard
38235 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38238 \begin_layout Standard
38241 Sample.c(15:24:26:1)_forcond_0($4) :
38244 \begin_layout Standard
38247 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38251 \begin_layout Standard
38254 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38257 \begin_layout Standard
38260 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38261 + ITemp21 [lr21:38]{short}[r4]
38264 \begin_layout Standard
38267 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38271 \begin_layout Standard
38274 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38275 + iTemp15 [lr29:30]{short}[r1]
38278 \begin_layout Standard
38281 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38285 \begin_layout Standard
38288 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38292 \begin_layout Standard
38295 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38299 \begin_layout Standard
38302 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38306 \begin_layout Standard
38309 Sample.c(19:38:47:1) goto _forcond_0($4)
38312 \begin_layout Standard
38315 Sample.c(19:39:48:0)_forbreak_0($7) :
38318 \begin_layout Standard
38321 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38322 + ITemp11 [lr19:40]{short}[r3]
38325 \begin_layout Standard
38328 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38331 \begin_layout Standard
38334 Sample.c(20:42:51:0)_return($8) :
38337 \begin_layout Standard
38340 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38346 Finally the code generated for this function:
38351 \begin_layout Standard
38357 \begin_layout Standard
38363 \begin_layout Standard
38371 \begin_layout Standard
38377 \begin_layout Standard
38385 \begin_layout Standard
38391 \begin_layout Standard
38394 ; ----------------------------------------------
38397 \begin_layout Standard
38400 ; function function
38403 \begin_layout Standard
38406 ; ----------------------------------------------
38409 \begin_layout Standard
38415 \begin_layout Standard
38418 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38421 \begin_layout Standard
38429 \begin_layout Standard
38432 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38435 \begin_layout Standard
38443 \begin_layout Standard
38446 ;_whilecontinue_0($1) :
38449 \begin_layout Standard
38455 \begin_layout Standard
38458 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38461 \begin_layout Standard
38464 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38467 \begin_layout Standard
38475 \begin_layout Standard
38483 \begin_layout Standard
38491 \begin_layout Standard
38499 \begin_layout Standard
38507 \begin_layout Standard
38515 \begin_layout Standard
38523 \begin_layout Standard
38529 \begin_layout Standard
38532 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38535 \begin_layout Standard
38543 \begin_layout Standard
38551 \begin_layout Standard
38554 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38557 \begin_layout Standard
38565 \begin_layout Standard
38573 \begin_layout Standard
38581 \begin_layout Standard
38589 \begin_layout Standard
38597 \begin_layout Standard
38605 \begin_layout Standard
38608 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38611 \begin_layout Standard
38619 \begin_layout Standard
38627 \begin_layout Standard
38635 \begin_layout Standard
38643 \begin_layout Standard
38651 \begin_layout Standard
38654 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38657 \begin_layout Standard
38665 \begin_layout Standard
38673 \begin_layout Standard
38681 \begin_layout Standard
38684 ; iTemp6 [lr5:16]{_near * int}[r0] =
38687 \begin_layout Standard
38690 ; iTemp6 [lr5:16]{_near * int}[r0] +
38693 \begin_layout Standard
38699 \begin_layout Standard
38707 \begin_layout Standard
38710 ; goto _whilecontinue_0($1)
38713 \begin_layout Standard
38721 \begin_layout Standard
38724 ; _whilebreak_0($3) :
38727 \begin_layout Standard
38733 \begin_layout Standard
38736 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38739 \begin_layout Standard
38747 \begin_layout Standard
38750 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38753 \begin_layout Standard
38761 \begin_layout Standard
38764 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38767 \begin_layout Standard
38775 \begin_layout Standard
38778 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38781 \begin_layout Standard
38789 \begin_layout Standard
38797 \begin_layout Standard
38800 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38803 \begin_layout Standard
38811 \begin_layout Standard
38819 \begin_layout Standard
38825 \begin_layout Standard
38831 \begin_layout Standard
38834 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38837 \begin_layout Standard
38840 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38843 \begin_layout Standard
38851 \begin_layout Standard
38859 \begin_layout Standard
38867 \begin_layout Standard
38875 \begin_layout Standard
38883 \begin_layout Standard
38889 \begin_layout Standard
38892 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38895 \begin_layout Standard
38898 ; iTemp21 [lr21:38]{short}[r4]
38901 \begin_layout Standard
38909 \begin_layout Standard
38917 \begin_layout Standard
38925 \begin_layout Standard
38928 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38931 \begin_layout Standard
38939 \begin_layout Standard
38947 \begin_layout Standard
38955 \begin_layout Standard
38963 \begin_layout Standard
38966 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
38969 \begin_layout Standard
38972 ; iTemp15 [lr29:30]{short}[r1]
38975 \begin_layout Standard
38983 \begin_layout Standard
38991 \begin_layout Standard
38994 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38997 \begin_layout Standard
39005 \begin_layout Standard
39013 \begin_layout Standard
39021 \begin_layout Standard
39029 \begin_layout Standard
39037 \begin_layout Standard
39045 \begin_layout Standard
39048 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39051 \begin_layout Standard
39059 \begin_layout Standard
39067 \begin_layout Standard
39075 \begin_layout Standard
39083 \begin_layout Standard
39091 \begin_layout Standard
39099 \begin_layout Standard
39102 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39105 \begin_layout Standard
39113 \begin_layout Standard
39116 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39119 \begin_layout Standard
39127 \begin_layout Standard
39132 cjne r5,#0xff,00104$
39135 \begin_layout Standard
39143 \begin_layout Standard
39146 ; goto _forcond_0($4)
39149 \begin_layout Standard
39157 \begin_layout Standard
39160 ; _forbreak_0($7) :
39163 \begin_layout Standard
39169 \begin_layout Standard
39172 ; ret iTemp24 [lr40:41]{short}
39175 \begin_layout Standard
39183 \begin_layout Standard
39191 \begin_layout Standard
39199 \begin_layout Standard
39205 \begin_layout Standard
39211 \begin_layout Standard
39221 \begin_layout Section
39222 A few words about basic block successors, predecessors and dominators
39225 \begin_layout Standard
39226 Successors are basic blocks
39227 \begin_inset LatexCommand \index{Basic blocks}
39231 that might execute after this basic block.
39233 Predecessors are basic blocks
39234 that might execute before reaching this basic block.
39236 Dominators are basic
39237 blocks that WILL execute before reaching this basic block.
39242 \begin_layout Standard
39246 \begin_layout Standard
39250 \begin_layout Standard
39258 \begin_layout Standard
39262 \begin_layout Standard
39270 \begin_layout Standard
39276 \begin_layout Standard
39277 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39280 \begin_layout Standard
39281 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39284 \begin_layout Standard
39285 c) domVect of [BB4] = BB1 ...
39286 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39290 \begin_layout Chapter
39294 \begin_layout Standard
39295 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39305 Thanks to all the other volunteer developers who have helped with coding,
39306 testing, web-page creation, distribution sets, etc.
39307 You know who you are :-)
39315 Also thanks to Sourceforge
39316 \begin_inset LatexCommand \url{http://www.sf.net}
39320 which has hosted the project since 1999 and donates significant download
39321 bandwidth and probably more than
39325 \begin_layout Standard
39332 CPU cycles per day.
39335 \begin_inset Note Note
39338 \begin_layout Standard
39339 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39340 minutes for (configure+make+regression test), and there is (i386, amd64,
39341 alpha, ppc64, (mingw32), sparc, macosx).
39350 \begin_layout Standard
39351 This document was initially written by Sandeep Dutta
39354 \begin_layout Standard
39355 All product names mentioned herein may be trademarks
39356 \begin_inset LatexCommand \index{Trademarks}
39360 of their respective companies.
39364 \begin_layout Section*
39368 \begin_layout Standard
39369 To avoid confusion, the installation and building options for SDCC itself
39370 (chapter 2) are not part of the index.
39373 \begin_layout Standard
39374 \begin_inset LatexCommand \printindex{}