1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \paperfontsize default
29 \papersize letterpaper
34 \paperorientation portrait
41 \paragraph_separation indent
43 \quotes_language swedish
47 \tracking_changes false
53 \begin_layout Standard
54 \begin_inset Note Note
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59 --version) are written this way: -
63 \begin_layout Standard
75 \begin_layout Standard
77 three consecutive dashes would otherwise result in a long resp.
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
101 SDCC Compiler User Guide
116 \begin_layout Standard
117 \begin_inset Note Note
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
137 \begin_layout Chapter
141 \begin_layout Section
145 \begin_layout Standard
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
171 designed for 8 bit Microprocessors.
172 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179 Zilog Z80 based MCUs.
180 It can be retargeted for other microprocessors, support for Microchip PIC,
181 Atmel AVR is under development.
182 The entire source code for the compiler is distributed under GPL.
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
189 \begin_inset LatexCommand \index{aslink}
193 , an open source retargetable assembler & linker.
194 SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
200 In addition to the MCU specific optimizations SDCC also does a host of
201 standard optimizations like:
204 \begin_layout Itemize
205 global sub expression elimination,
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
213 \begin_layout Itemize
214 constant folding & propagation,
217 \begin_layout Itemize
221 \begin_layout Itemize
222 dead code elimination
225 \begin_layout Itemize
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235 be well suited for other 8 bit MCUs.
240 The peep hole optimizer uses a rule based substitution mechanism which
246 Supported data-types are:
249 \begin_layout Standard
251 <lyxtabular version="3" rows="8" columns="5">
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 \begin_layout Standard
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
271 \begin_layout Standard
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 \begin_layout Standard
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_layout Standard
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
298 \begin_layout Standard
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 \begin_layout Standard
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_layout Standard
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 \begin_layout Standard
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_layout Standard
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
345 \begin_layout Standard
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
356 \begin_layout Standard
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_layout Standard
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
374 \begin_layout Standard
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
383 \begin_layout Standard
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
392 \begin_layout Standard
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
403 \begin_layout Standard
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_layout Standard
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
421 \begin_layout Standard
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 \begin_layout Standard
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 \begin_layout Standard
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
450 \begin_layout Standard
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
459 \begin_layout Standard
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 \begin_layout Standard
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 \begin_layout Standard
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 \begin_layout Standard
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_layout Standard
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_layout Standard
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
515 \begin_layout Standard
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
533 \begin_layout Standard
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_layout Standard
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 \begin_layout Standard
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_layout Standard
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
571 \begin_layout Standard
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 \begin_layout Standard
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
600 \begin_layout Standard
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
609 \begin_layout Standard
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
618 \begin_layout Standard
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
627 \begin_layout Standard
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
636 \begin_layout Standard
649 The compiler also allows
651 inline assembler code
653 to be embedded anywhere in a function.
654 In addition, routines developed in assembly can also be called.
659 provides an option (-
663 \begin_layout Standard
672 -cyclomatic) to report the relative complexity of a function.
673 These functions can then be further optimized, or hand coded in assembly
679 SDCC also comes with a companion source level debugger SDCDB.
680 The debugger currently uses ucSim, a free open source simulator for 8051
681 and other micro-controllers.
685 The latest SDCC version can be downloaded from
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
697 Please note: the compiler will probably always be some steps ahead of this
702 \begin_inset LatexCommand \index{Status of documentation}
710 \begin_layout Standard
711 Obviously this has pros and cons
719 \begin_layout Section
723 \begin_layout Standard
724 All packages used in this compiler system are
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733 etc) is distributed with the package.
734 This documentation is maintained using a free open source word processor
737 This program is free software; you can redistribute it and/or modify
738 it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
743 as published by the Free Software Foundation; either version 2, or (at
744 your option) any later version.
745 This program is distributed in the hope that it will be useful, but WITHOUT
746 ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
751 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752 See the GNU General Public License for more details.
753 You should have received a copy of the GNU General Public License along
754 with this program; if not, write to the Free Software Foundation, 59 Temple
755 Place - Suite 330, Boston, MA 02111-1307, USA.
756 In other words, you are welcome to use, share and improve this program.
757 You are forbidden to forbid anyone else to use, share and improve what
759 Help stamp out software-hoarding!
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773 Commands you have to type in are printed in
781 Code samples are printed in
786 Interesting items and new terms are printed in
791 \begin_layout Section
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
797 with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
808 But we also sometimes introduce some incompatibilities with older versions.
809 Not just for the fun of it, but to make the compiler more stable, efficient
811 \begin_inset LatexCommand \index{ANSI-compliance}
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
820 for ANSI-Compliance).
822 \begin_inset Note Note
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838 (8 bits) which is not ANSI compliant.
839 To maintain compatibility, old programs may be compiled using the --short-is-8b
840 its commandline option (see
841 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
848 \begin_layout Itemize
849 the default directory for gcc-builds where include, library and documentation
850 files are stored is now in /usr/local/share.
853 \begin_layout Itemize
854 char type parameters to vararg
855 \begin_inset LatexCommand \index{vararg, va\_arg}
859 functions are casted to int unless explicitly casted
860 \begin_inset Marginal
863 \begin_layout Standard
888 will push a as an int and as a char resp.
891 \begin_layout Itemize
896 \begin_layout Standard
905 -regextend has been removed.
908 \begin_layout Itemize
913 \begin_layout Standard
922 -noregparms has been removed.
925 \begin_layout Itemize
930 \begin_layout Standard
939 -stack-after-data has been removed.
942 \begin_layout Itemize
944 \begin_inset LatexCommand \index{bit}
949 \begin_inset LatexCommand \index{sbit}
954 \begin_inset LatexCommand \index{\_\_sbit}
958 types now consistently behave like the C99 _Bool type with respect to type
960 \begin_inset LatexCommand \index{type conversion}
965 \begin_inset LatexCommand \index{type promotion}
970 The most common incompatibility resulting from this change is related to
972 \begin_inset LatexCommand \index{Bit toggling}
987 \begin_inset LatexCommand \index{\~\/ Operator}
991 b; /* equivalent to b=1 instead of toggling b */
992 \begin_inset Marginal
995 \begin_layout Standard
1008 b = !b; /* toggles b */
1012 In previous versions, both forms would have toggled the bit.
1015 \begin_layout Standard
1018 <pending: more incompatibilities?>
1021 \begin_layout Section
1025 \begin_layout Standard
1026 What do you need before you start installation of SDCC? A computer, and
1027 a desire to compute.
1028 The preferred method of installation is to compile SDCC from source using
1030 For Windows some pre-compiled binary distributions are available for your
1032 You should have some experience with command line tools and compiler use.
1035 \begin_layout Section
1039 \begin_layout Standard
1040 The SDCC home page at
1041 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1045 is a great place to find distribution sets.
1046 You can also find links to the user mailing lists that offer help or discuss
1047 SDCC with other SDCC users.
1048 Web links to other SDCC related sites can also be found here.
1049 This document can be found in the DOC directory of the source package as
1050 a text or HTML file.
1051 A pdf version of this document is available at
1052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1057 Some of the other tools (simulator and assembler) included with SDCC contain
1058 their own documentation and can be found in the source distribution.
1059 If you want the latest unreleased software, the complete source package
1060 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1064 \begin_layout Section
1065 Wishes for the future
1068 \begin_layout Standard
1069 There are (and always will be) some things that could be done.
1070 Here are some I can think of:
1075 \begin_layout Standard
1078 char KernelFunction3(char p) at 0x340;
1083 \begin_layout Standard
1087 \begin_inset LatexCommand \index{code banking (limited support)}
1097 If you can think of some more, please see the section
1098 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1102 about filing feature requests
1103 \begin_inset LatexCommand \index{Requesting features}
1108 \begin_inset LatexCommand \index{Feature request}
1117 \begin_layout Chapter
1119 \begin_inset LatexCommand \index{Installation}
1126 \begin_layout Standard
1127 For most users it is sufficient to skip to either section
1128 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1133 \begin_inset LatexCommand \ref{sub:Windows-Install}
1138 More detailed instructions follow below.
1141 \begin_layout Section
1143 \begin_inset LatexCommand \index{Options SDCC configuration}
1150 \begin_layout Standard
1151 The install paths, search paths and other options are defined when running
1153 The defaults can be overridden by:
1157 \labelwidthstring 00.00.0000
1162 \begin_layout Standard
1171 -prefix see table below
1175 \labelwidthstring 00.00.0000
1180 \begin_layout Standard
1189 -exec_prefix see table below
1193 \labelwidthstring 00.00.0000
1198 \begin_layout Standard
1207 -bindir see table below
1211 \labelwidthstring 00.00.0000
1216 \begin_layout Standard
1225 -datadir see table below
1229 \labelwidthstring 00.00.0000
1234 \begin_layout Standard
1243 -datarootdir see table below
1249 \labelwidthstring 00.00.0000
1252 docdir environment variable, see table below
1256 \labelwidthstring 00.00.0000
1259 include_dir_suffix environment variable, see table below
1263 \labelwidthstring 00.00.0000
1266 lib_dir_suffix environment variable, see table below
1270 \labelwidthstring 00.00.0000
1273 sdccconf_h_dir_separator environment variable, either / or
1278 This character will only be used in sdccconf.h; don't forget it's a C-header,
1279 therefore a double-backslash is needed there.
1285 \labelwidthstring 00.00.0000
1290 \begin_layout Standard
1299 -disable-mcs51-port Excludes the Intel mcs51 port
1303 \labelwidthstring 00.00.0000
1308 \begin_layout Standard
1317 -disable-gbz80-port Excludes the Gameboy gbz80 port
1321 \labelwidthstring 00.00.0000
1326 \begin_layout Standard
1335 -disable-z80-port Excludes the z80 port
1339 \labelwidthstring 00.00.0000
1344 \begin_layout Standard
1353 -disable-avr-port Excludes the AVR port
1357 \labelwidthstring 00.00.0000
1362 \begin_layout Standard
1371 -disable-ds390-port Excludes the DS390 port
1375 \labelwidthstring 00.00.0000
1380 \begin_layout Standard
1389 -disable-hc08-port Excludes the HC08 port
1393 \labelwidthstring 00.00.0000
1398 \begin_layout Standard
1407 -disable-pic-port Excludes the PIC port
1411 \labelwidthstring 00.00.0000
1416 \begin_layout Standard
1425 -disable-xa51-port Excludes the XA51 port
1429 \labelwidthstring 00.00.0000
1434 \begin_layout Standard
1443 -disable-ucsim Disables configuring and building of ucsim
1447 \labelwidthstring 00.00.0000
1452 \begin_layout Standard
1461 -disable-device-lib Disables automatically building device libraries
1465 \labelwidthstring 00.00.0000
1470 \begin_layout Standard
1479 -disable-packihx Disables building packihx
1485 \labelwidthstring 00.00.0000
1490 \begin_layout Standard
1499 -enable-doc Build pdf, html and txt files from the lyx sources
1503 \labelwidthstring 00.00.0000
1508 \begin_layout Standard
1517 -enable-libgc Use the Bohem memory allocator.
1518 Lower runtime footprint.
1521 \begin_layout Standard
1522 Furthermore the environment variables CC, CFLAGS, ...
1523 the tools and their arguments can be influenced.
1524 Please see `configure -
1528 \begin_layout Standard
1537 -help` and the man/info pages of `configure` for details.
1542 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1543 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1544 SDCC_LIB_NAME are defined by `configure` too.
1545 At the moment it's not possible to change the default settings (it was
1546 simply never required).
1550 These configure options are compiled into the binaries,
1551 and can only be changed by rerunning 'configure' and recompiling SDCC.
1552 The configure options are written in
1556 to distinguish them from run time environment variables (see section search
1562 \begin_inset Quotes sld
1566 \begin_inset Quotes srd
1569 are used by the SDCC team to build the official Win32 binaries.
1570 The SDCC team uses Mingw32 to build the official Windows binaries, because
1574 \begin_layout Enumerate
1578 \begin_layout Enumerate
1579 a gcc compiler and last but not least
1582 \begin_layout Enumerate
1583 the binaries can be built by cross compiling on SDCC Distributed Compile
1587 \begin_layout Standard
1588 See the examples, how to pass the Win32 settings to 'configure'.
1589 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1590 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1600 \begin_layout Standard
1602 \begin_inset Tabular
1603 <lyxtabular version="3" rows="9" columns="3">
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" width="0in">
1607 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1608 <row topline="true" bottomline="true">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1612 \begin_layout Standard
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1621 \begin_layout Standard
1627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1630 \begin_layout Standard
1637 <row topline="true">
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1641 \begin_layout Standard
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1652 \begin_layout Standard
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1661 \begin_layout Standard
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1674 \begin_layout Standard
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1685 \begin_layout Standard
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1696 \begin_layout Standard
1705 <row topline="true">
1706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 \begin_layout Standard
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_layout Standard
1730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1733 \begin_layout Standard
1746 <row topline="true">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 \begin_layout Standard
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1761 \begin_layout Standard
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1772 \begin_layout Standard
1781 <row topline="true">
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1785 \begin_layout Standard
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1796 \begin_layout Standard
1806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1809 \begin_layout Standard
1818 <row topline="true">
1819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1822 \begin_layout Standard
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 \begin_layout Standard
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1846 \begin_layout Standard
1859 <row topline="true">
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_layout Standard
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1874 \begin_layout Standard
1880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1883 \begin_layout Standard
1890 <row topline="true" bottomline="true">
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1894 \begin_layout Standard
1902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1905 \begin_layout Standard
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1914 \begin_layout Standard
1930 \begin_layout Standard
1932 'configure' also computes relative paths.
1933 This is needed for full relocatability of a binary package and to complete
1934 search paths (see section search paths below):
1939 \begin_layout Standard
1941 \begin_inset Tabular
1942 <lyxtabular version="3" rows="4" columns="3">
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" width="0in">
1946 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1947 <row topline="true" bottomline="true">
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1951 \begin_layout Standard
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1960 \begin_layout Standard
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1969 \begin_layout Standard
1976 <row topline="true" bottomline="true">
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1980 \begin_layout Standard
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1991 \begin_layout Standard
1997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2000 \begin_layout Standard
2007 <row bottomline="true">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2011 \begin_layout Standard
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2022 \begin_layout Standard
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2031 \begin_layout Standard
2038 <row bottomline="true">
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2042 \begin_layout Standard
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2053 \begin_layout Standard
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2062 \begin_layout Standard
2078 \begin_layout Standard
2083 \begin_layout LyX-Code
2090 \begin_layout Standard
2100 \begin_inset Quotes srd
2104 \begin_inset Quotes srd
2111 \begin_layout Standard
2121 \begin_inset Quotes srd
2125 \begin_inset Quotes srd
2134 \begin_layout Standard
2147 \begin_layout Standard
2159 \begin_layout Standard
2160 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2164 \begin_layout LyX-Code
2170 \begin_inset Quotes srd
2173 i586-mingw32msvc-gcc
2174 \begin_inset Quotes srd
2178 \begin_inset Quotes srd
2181 i586-mingw32msvc-g++
2182 \begin_inset Quotes srd
2190 \begin_inset Quotes srd
2193 i586-mingw32msvc-ranlib
2194 \begin_inset Quotes srd
2202 \begin_inset Quotes srd
2205 i586-mingw32msvc-strip
2206 \begin_inset Quotes srd
2217 \begin_layout Standard
2227 \begin_inset Quotes srd
2231 \begin_inset Quotes srd
2242 \begin_layout Standard
2252 \begin_inset Quotes srd
2256 \begin_inset Quotes srd
2264 \begin_inset Quotes srd
2270 \begin_inset Quotes srd
2278 \begin_inset Quotes srd
2282 \begin_inset Quotes srd
2290 \begin_inset Quotes srd
2294 \begin_inset Quotes srd
2301 sdccconf_h_dir_separator=
2302 \begin_inset Quotes srd
2314 \begin_inset Quotes srd
2325 \begin_layout Standard
2342 \begin_layout Standard
2351 -host=i586-mingw32msvc
2359 \begin_layout Standard
2368 -build=unknown-unknown-linux-gnu
2371 \begin_layout Standard
2373 \begin_inset Quotes sld
2377 \begin_inset Quotes srd
2380 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2384 \begin_layout LyX-Code
2393 \begin_layout Standard
2403 \begin_inset Quotes srd
2407 \begin_inset Quotes srd
2418 \begin_layout Standard
2428 \begin_inset Quotes srd
2432 \begin_inset Quotes srd
2440 \begin_inset Quotes srd
2446 \begin_inset Quotes srd
2454 \begin_inset Quotes srd
2458 \begin_inset Quotes srd
2466 \begin_inset Quotes srd
2470 \begin_inset Quotes srd
2477 sdccconf_h_dir_separator=
2478 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2498 \begin_inset Quotes srd
2502 \begin_inset Quotes srd
2510 \begin_inset Quotes srd
2514 \begin_inset Quotes srd
2520 \begin_layout Standard
2521 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2526 \begin_layout Standard
2535 -C' turns on caching, which gives a little bit extra speed.
2536 However if options are changed, it can be necessary to delete the config.cache
2540 \begin_layout Section
2542 \begin_inset LatexCommand \label{sub:Install-paths}
2547 \begin_inset LatexCommand \index{Install paths}
2554 \begin_layout Standard
2555 \begin_inset VSpace medskip
2561 \begin_layout Standard
2563 \begin_inset Tabular
2564 <lyxtabular version="3" rows="5" columns="4">
2566 <column alignment="left" valignment="top" leftline="true" width="0">
2567 <column alignment="left" valignment="top" leftline="true" width="0">
2568 <column alignment="left" valignment="top" leftline="true" width="0">
2569 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2570 <row topline="true" bottomline="true">
2571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2574 \begin_layout Standard
2582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2585 \begin_layout Standard
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2596 \begin_layout Standard
2604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2607 \begin_layout Standard
2616 <row topline="true">
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2620 \begin_layout Standard
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2629 \begin_layout Standard
2637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2640 \begin_layout Standard
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2649 \begin_layout Standard
2660 <row topline="true">
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_layout Standard
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2673 \begin_layout Standard
2676 $DATADIR/ $INCLUDE_DIR_SUFFIX
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2684 \begin_layout Standard
2685 /usr/local/share/sdcc/include
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2693 \begin_layout Standard
2704 <row topline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2708 \begin_layout Standard
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2717 \begin_layout Standard
2720 $DATADIR/$LIB_DIR_SUFFIX
2725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2728 \begin_layout Standard
2729 /usr/local/share/sdcc/lib
2734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2737 \begin_layout Standard
2748 <row topline="true" bottomline="true">
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_layout Standard
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2761 \begin_layout Standard
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2772 \begin_layout Standard
2773 /usr/local/share/sdcc/doc
2778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2781 \begin_layout Standard
2802 *compiler, preprocessor, assembler, and linker
2808 is auto-appended by the compiler, e.g.
2809 small, large, z80, ds390 etc
2812 \begin_layout Standard
2814 The install paths can still be changed during `make install` with e.g.:
2817 \begin_layout LyX-Code
2818 make install prefix=$(HOME)/local/sdcc
2821 \begin_layout Standard
2822 Of course this doesn't change the search paths compiled into the binaries.
2827 r the install path can be changed by defining DESTDIR
2828 \begin_inset LatexCommand \index{DESTDIR}
2835 \begin_layout LyX-Code
2836 make install DESTDIR=$(HOME)/sdcc.rpm/
2839 \begin_layout Standard
2840 Please note that DESTDIR must have a trailing slash!
2843 \begin_layout Section
2845 \begin_inset LatexCommand \label{sub:Search-Paths}
2850 \begin_inset LatexCommand \index{Search path}
2857 \begin_layout Standard
2858 Some search paths or parts of them are determined by configure variables
2863 , see section above).
2864 Further search paths are determined by environment variables during runtime.
2867 The paths searched when running the compiler are as follows (the first
2873 Binary files (preprocessor, assembler and linker)
2878 \begin_layout Standard
2880 \begin_inset Tabular
2881 <lyxtabular version="3" rows="4" columns="3">
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" width="0in">
2885 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2886 <row topline="true" bottomline="true">
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_layout Standard
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2899 \begin_layout Standard
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2908 \begin_layout Standard
2915 <row topline="true">
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2919 \begin_layout Standard
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2930 \begin_layout Standard
2936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2939 \begin_layout Standard
2948 <row topline="true">
2949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2952 \begin_layout Standard
2953 Path of argv[0] (if available)
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_layout Standard
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2970 \begin_layout Standard
2977 <row topline="true" bottomline="true">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2981 \begin_layout Standard
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2990 \begin_layout Standard
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2999 \begin_layout Standard
3015 \begin_layout Standard
3023 \begin_layout Standard
3025 \begin_inset Tabular
3026 <lyxtabular version="3" rows="6" columns="3">
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3030 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3031 <row topline="true" bottomline="true">
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3035 \begin_layout Standard
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3044 \begin_layout Standard
3050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3053 \begin_layout Standard
3060 <row topline="true">
3061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3064 \begin_layout Standard
3069 \begin_layout Standard
3083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3086 \begin_layout Standard
3091 \begin_layout Standard
3105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3108 \begin_layout Standard
3113 \begin_layout Standard
3128 <row topline="true">
3129 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3132 \begin_layout Standard
3138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3141 \begin_layout Standard
3147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3150 \begin_layout Standard
3157 <row topline="true">
3158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3161 \begin_layout Standard
3173 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3176 \begin_layout Standard
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3189 \begin_layout Standard
3198 <row topline="true">
3199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3202 \begin_layout Standard
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3221 \begin_layout Standard
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3272 \begin_layout Standard
3283 <row topline="true" bottomline="true">
3284 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3287 \begin_layout Standard
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3304 \begin_layout Standard
3305 /usr/local/share/sdcc/
3312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3315 \begin_layout Standard
3331 \begin_layout Standard
3337 \begin_layout Standard
3346 -nostdinc disables the last two search paths.
3356 \begin_layout Standard
3357 With the exception of
3358 \begin_inset Quotes sld
3365 \begin_layout Standard
3375 \begin_inset Quotes srd
3382 is auto-appended by the compiler (e.g.
3383 small, large, z80, ds390 etc.).
3389 \begin_layout Standard
3391 \begin_inset Tabular
3392 <lyxtabular version="3" rows="6" columns="3">
3394 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3395 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3396 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3397 <row topline="true" bottomline="true">
3398 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3401 \begin_layout Standard
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3410 \begin_layout Standard
3416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3419 \begin_layout Standard
3426 <row topline="true">
3427 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3430 \begin_layout Standard
3435 \begin_layout Standard
3449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3452 \begin_layout Standard
3457 \begin_layout Standard
3471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3474 \begin_layout Standard
3479 \begin_layout Standard
3494 <row topline="true">
3495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3498 \begin_layout Standard
3508 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3511 \begin_layout Standard
3521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3524 \begin_layout Standard
3537 <row topline="true">
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3541 \begin_layout Standard
3548 $LIB_DIR_SUFFIX/<model>
3553 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3556 \begin_layout Standard
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3571 \begin_layout Standard
3586 <row topline="true">
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3590 \begin_layout Standard
3601 $LIB_DIR_SUFFIX/<model>
3606 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3609 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3717 <row topline="true" bottomline="true">
3718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3721 \begin_layout Standard
3726 $LIB_DIR_SUFFIX/<model>
3731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3734 \begin_layout Standard
3735 /usr/local/share/sdcc/
3744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3747 \begin_layout Standard
3763 \begin_layout Standard
3764 \begin_inset Note Note
3767 \begin_layout Standard
3768 Don't delete any of the stray spaces in the table above without checking
3769 the HTML output (last line)!
3777 \begin_layout Standard
3785 \begin_layout Standard
3794 -nostdlib disables the last two search paths.
3797 \begin_layout Section
3799 \begin_inset LatexCommand \index{Building SDCC}
3806 \begin_layout Subsection
3807 Building SDCC on Linux
3808 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3815 \begin_layout Enumerate
3818 Download the source package
3820 either from the SDCC Subversion repository or from snapshot builds
3822 , it will be named something like sdcc
3833 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3840 \begin_layout Enumerate
3843 Bring up a command line terminal, such as xterm.
3846 \begin_layout Enumerate
3849 Unpack the file using a command like:
3852 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3853 \begin_inset Quotes srd
3859 , this will create a sub-directory called sdcc with all of the sources.
3862 \begin_layout Enumerate
3863 Change directory into the main SDCC directory, for example type:
3871 \begin_layout Enumerate
3881 This configures the package for compilation on your system.
3884 \begin_layout Enumerate
3898 All of the source packages will compile, this can take a while.
3901 \begin_layout Enumerate
3915 This copies the binary executables, the include files, the libraries and
3916 the documentation to the install directories.
3917 Proceed with section
3918 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3925 \begin_layout Subsection
3926 Building SDCC on Mac OS X
3929 \begin_layout Standard
3930 Follow the instruction for Linux.
3934 On Mac OS X 10.2.x it was reported, that the
3935 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3936 Fortunately there's also gcc 2.9.x installed, which works fine.
3937 This compiler can be selected by running 'configure' with:
3940 \begin_layout LyX-Code
3941 ./configure CC=gcc2 CXX=g++2
3944 \begin_layout Subsection
3945 Cross compiling SDCC on Linux for Windows
3948 \begin_layout Standard
3949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3950 See section 'Configure Options'.
3953 \begin_layout Subsection
3954 Building SDCC using Cygwin and Mingw32
3957 \begin_layout Standard
3958 For building and installing a Cygwin executable follow the instructions
3964 \begin_inset Quotes sld
3968 \begin_inset Quotes srd
3971 Win32-binary can be built, which will not need the Cygwin-DLL.
3972 For the necessary 'configure' options see section 'configure options' or
3973 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3978 Cygwin on Windows download setup.exe from
3979 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3985 \begin_inset Quotes sld
3988 default text file type
3989 \begin_inset Quotes srd
3993 \begin_inset Quotes sld
3997 \begin_inset Quotes srd
4000 and download/install at least the following packages.
4001 Some packages are selected by default, others will be automatically selected
4002 because of dependencies with the manually selected packages.
4003 Never deselect these packages!
4006 \begin_layout Itemize
4010 \begin_layout Itemize
4014 \begin_layout Itemize
4015 gcc ; version 3.x is fine, no need to use the old 2.9x
4018 \begin_layout Itemize
4019 binutils ; selected with gcc
4022 \begin_layout Itemize
4026 \begin_layout Itemize
4027 rxvt ; a nice console, which makes life much easier under windoze (see below)
4030 \begin_layout Itemize
4031 man ; not really needed for building SDCC, but you'll miss it sooner or
4035 \begin_layout Itemize
4036 less ; not really needed for building SDCC, but you'll miss it sooner or
4040 \begin_layout Itemize
4041 svn ; only if you use Subversion access
4044 \begin_layout Standard
4045 If you want to develop something you'll need:
4048 \begin_layout Itemize
4049 python ; for the regression tests
4052 \begin_layout Itemize
4053 gdb ; the gnu debugger, together with the nice GUI
4054 \begin_inset Quotes sld
4058 \begin_inset Quotes srd
4064 \begin_layout Itemize
4065 openssh ; to access the CF or commit changes
4068 \begin_layout Itemize
4069 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4070 use autoconf-stable!
4073 \begin_layout Standard
4074 rxvt is a nice console with history.
4075 Replace in your cygwin.bat the line
4078 \begin_layout LyX-Code
4083 \begin_layout Standard
4095 \begin_layout Standard
4099 \begin_layout LyX-Code
4100 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4103 \begin_layout LyX-Code
4104 -bg black -fg white -geometry 100x65 -e bash -
4108 \begin_layout Standard
4120 \begin_layout Standard
4121 Text selected with the mouse is automatically copied to the clipboard, pasting
4122 works with shift-insert.
4126 The other good tip is to make sure you have no //c/-styl
4127 e paths anywhere, use /cygdrive/c/ instead.
4128 Using // invokes a network lookup which is very slow.
4130 \begin_inset Quotes sld
4134 \begin_inset Quotes srd
4137 is too long, you can change it with e.g.
4140 \begin_layout LyX-Code
4144 \begin_layout Standard
4145 SDCC sources use the unix line ending LF.
4146 Life is much easier, if you store the source tree on a drive which is mounted
4148 And use an editor which can handle LF-only line endings.
4149 Make sure not to commit files with windows line endings.
4150 The tabulator spacing
4151 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4155 used in the project is 8.
4156 Although a tabulator spacing of 8 is a sensible choice for programmers
4157 (it's a power of 2 and allows to display 8/16 bit signed variables without
4158 loosing columns) the plan is to move towards using only spaces in the source.
4161 \begin_layout Subsection
4162 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4165 \begin_layout Standard
4168 Download the source package
4170 either from the SDCC Subversion repository or from the
4171 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4177 , it will be named something like sdcc
4181 -yyyymmdd-rrrr.tar.bz2.
4184 SDCC is distributed with all the projects, workspaces, and files you need
4185 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4186 The workspace name is 'sdcc.dsw'.
4187 Please note that as it is now, all the executables are created in a folder
4191 Once built you need to copy the executables from sdcc
4195 bin before running SDCC.
4200 WARNING: Visual studio is very picky with line terminations; it expects
4201 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4202 When using the Subversion repository it's easiest to configure the svn
4203 client to convert automatically for you.
4204 If however you are getting a message such as "This makefile was not generated
4205 by Developer Studio etc.
4207 \begin_inset Quotes srd
4210 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4211 need to convert the Unix style line endings to DOS style line endings.
4212 To do so you can use the
4213 \begin_inset Quotes sld
4217 \begin_inset Quotes srd
4220 utility freely available on the internet.
4221 Doug Hawkins reported in the sdcc-user list that this works:
4229 SDCC> unix2dos sdcc.dsw
4235 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4239 In order to build SDCC with MSVC
4240 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4241 One good place to get them is
4242 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4250 Download the file UnxUtils
4251 \begin_inset LatexCommand \index{UnxUtils}
4256 Now you have to install the utilities and setup MSVC so it can locate the
4258 Here there are two alternatives (choose one!):
4261 \begin_layout Enumerate
4266 a) Extract UnxUtils.zip to your C:
4268 hard disk PRESERVING the original paths, otherwise bison won't work.
4269 (If you are using WinZip make certain that 'Use folder names' is selected)
4274 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4275 'Show directories for:' select 'Executable files', and in the directories
4276 window add a new path: 'C:
4286 (As a side effect, you get a bunch of Unix utilities that
4287 could be useful, such as diff and patch.)
4290 \begin_layout Enumerate
4295 This one avoids extracting a bunch of files you may not
4296 use, but requires some extra work:
4300 a) Create a directory were to put the
4301 tools needed, or use a directory already present.
4308 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4309 gawk.exe to such directory WITHOUT preserving the original paths.
4310 (If you are using WinZip make certain that 'Use folder names' is not selected)
4315 ) Rename bison.exe to '_bison.exe'.
4319 d) Create a batch file 'bison.bat' in 'C:
4323 ' and add these lines:
4343 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4347 Steps 'c' and 'd' are needed
4348 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4349 reside in some weird Unix directory, '/usr/local/share/' I think.
4350 So it is necessary to tell bison where those files are located if they
4351 are not in such directory.
4352 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4357 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4358 in 'Show directories for:' select 'Executable files', and in the directories
4359 window add a new path: 'c:
4362 Note that you can use any other path instead of 'c:
4364 util', even the path where the Visual C++ tools are, probably: 'C:
4368 Microsoft Visual Studio
4373 So you don't have to execute step 'e' :)
4376 \begin_layout Standard
4378 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4379 the executables from sdcc
4383 bin, and you can compile using SDCC.
4386 \begin_layout Subsection
4387 Building SDCC Using Borland
4390 \begin_layout Enumerate
4391 From the sdcc directory, run the command "make -f Makefile.bcc".
4392 This should regenerate all the .exe files in the bin directory except for
4396 \begin_layout Enumerate
4397 If you modify any source files and need to rebuild, be aware that the dependenci
4398 es may not be correctly calculated.
4399 The safest option is to delete all .obj files and run the build again.
4400 From a Cygwin BASH prompt, this can easily be done with the command (be
4401 sure you are in the sdcc directory):
4411 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4413 ) -print -exec rm {}
4422 or on Windows NT/2000/XP from the command prompt with the command:
4429 del /s *.obj *.lib *.rul
4432 from the sdcc directory.
4435 \begin_layout Subsection
4436 Windows Install Using a ZIP Package
4439 \begin_layout Enumerate
4440 Download the binary zip package from
4441 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4445 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4446 This should unpack to a group of sub-directories.
4447 An example directory structure after unpacking the mingw32 package is:
4452 bin for the executables, c:
4460 lib for the include and libraries.
4463 \begin_layout Enumerate
4464 Adjust your environment variable PATH to include the location of the bin
4465 directory or start sdcc using the full path.
4468 \begin_layout Subsection
4469 Windows Install Using the Setup Program
4470 \begin_inset LatexCommand \label{sub:Windows-Install}
4477 \begin_layout Standard
4478 Download the setup program
4480 sdcc-x.y.z-setup.exe
4482 for an official release from
4485 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4489 or a setup program for one of the snapshots
4491 sdcc-yyyymmdd-xxxx-setup.exe
4494 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4499 A windows typical installer will guide you through the installation process.
4502 \begin_layout Subsection
4504 \begin_inset LatexCommand \index{VPATH}
4511 \begin_layout Standard
4512 SDCC supports the VPATH feature provided by configure and make.
4513 It allows to separate the source and build trees.
4517 \begin_layout Standard
4544 \begin_layout Standard
4547 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4548 # extract source to directory sdcc
4551 \begin_layout Standard
4554 mkdir sdcc.build\InsetSpace ~
4563 # put output in sdcc.build
4566 \begin_layout Standard
4572 \begin_layout Standard
4575 ../sdcc/configure\InsetSpace ~
4583 # configure is doing all the magic!
4586 \begin_layout Standard
4592 \begin_layout Standard
4598 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4599 It automagically computes the variables srcdir, top_srcdir and top_buildir
4605 the generated files will be in ~/sdcc.build, while the source files stay
4608 This is not only usefull for building different binaries, e.g.
4609 when cross compiling.
4610 It also gives you a much better overview in the source tree when all the
4611 generated files are not scattered between the source files.
4612 And the best thing is: if you want to change a file you can leave the original
4613 file untouched in the source directory.
4614 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4615 Makefile.dep` and `make`.
4620 will do the rest for you!
4623 \begin_layout Section
4624 Building the Documentation
4627 \begin_layout Standard
4632 \begin_layout Standard
4641 -enable-doc to the configure arguments to build the documentation together
4642 with all the other stuff.
4643 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4644 dvips and makeindex) to get the job done.
4645 Another possibility is to change to the doc directory and to type
4649 \begin_inset Quotes srd
4653 \begin_inset Quotes srd
4660 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4663 \begin_inset LatexCommand \url{http://www.lyx.org}
4667 as editor is straightforward.
4668 Prebuilt documentation in html and pdf format is available from
4669 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4676 \begin_layout Section
4677 Reading the Documentation
4678 \begin_inset LatexCommand \index{Documentation}
4685 \begin_layout Standard
4686 Currently reading the document in pdf format is recommended, as for unknown
4687 reason the hyperlinks are working there whereas in the html version they
4692 \begin_layout Standard
4693 If you should know why please drop us a note
4701 You'll find the pdf version
4702 \begin_inset LatexCommand \index{PDF version of this document}
4707 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4715 \begin_inset LatexCommand \index{HTML version of this document}
4720 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4726 This documentation is in some aspects different from a commercial documentation:
4730 \begin_layout Itemize
4731 It tries to document SDCC for several processor architectures in one document
4732 (commercially these probably would be separate documents/products).
4734 \begin_inset LatexCommand \index{Status of documentation}
4738 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4740 Z80, PIC14, PIC16 and HC08.
4743 \begin_layout Itemize
4744 There are many references pointing away from this documentation.
4745 Don't let this distract you.
4747 was a reference like
4748 \begin_inset LatexCommand \url{http://www.opencores.org}
4752 together with a statement
4753 \begin_inset Quotes sld
4756 some processors which are targetted by SDCC can be implemented in a
4773 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4778 \begin_inset Quotes srd
4782 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4787 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4792 \begin_inset Quotes sld
4795 have you ever heard of an open source compiler that compiles a subset of
4797 \begin_inset Quotes srd
4800 we expect you to have a quick look there and come back.
4801 If you read this you are on the right track.
4804 \begin_layout Itemize
4805 Some sections attribute more space to problems, restrictions and warnings
4806 than to the solution.
4809 \begin_layout Itemize
4810 The installation section and the section about the debugger is intimidating.
4813 \begin_layout Itemize
4814 There are still lots of typos and there are more different writing styles
4818 \begin_layout Section
4819 Testing the SDCC Compiler
4820 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4827 \begin_layout Standard
4828 The first thing you should do after installing your SDCC compiler is to
4837 \begin_layout Standard
4847 \begin_inset LatexCommand \index{version}
4854 at the prompt, and the program should run and output its version like:
4859 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4863 \begin_layout Standard
4864 If it doesn't run, or gives a message about not finding sdcc program, then
4865 you need to check over your installation.
4866 Make sure that the sdcc bin directory is in your executable search path
4867 defined by the PATH environment setting (
4872 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4879 Install trouble-shooting for suggestions
4882 Make sure that the sdcc program is in the bin folder, if not perhaps something
4883 did not install correctly.
4891 is commonly installed as described in section
4892 \begin_inset Quotes sld
4895 Install and search paths
4896 \begin_inset Quotes srd
4905 Make sure the compiler works on a very simple example.
4906 Type in the following test.c program using your favorite
4931 \begin_layout Standard
4934 Compile this using the following command:
4943 If all goes well, the compiler will generate a test.asm and test.rel file.
4944 Congratulations, you've just compiled your first program with SDCC.
4945 We used the -c option to tell SDCC not to link the generated code, just
4946 to keep things simple for this step.
4954 The next step is to try it with the linker.
4964 If all goes well the compiler will link with the libraries and produce
4965 a test.ihx output file.
4970 (no test.ihx, and the linker generates warnings), then the problem is most
4979 usr/local/share/sdcc/lib directory
4986 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4993 Install trouble-shooting for suggestions).
5001 The final test is to ensure
5009 header files and libraries.
5010 Edit test.c and change it to the following:
5028 strcpy(str1, "testing");
5033 \begin_layout Standard
5036 Compile this by typing
5043 This should generate a test.ihx output file, and it should give no warnings
5044 such as not finding the string.h file.
5045 If it cannot find the string.h file, then the problem is that
5049 cannot find the /usr/local/share/sdcc/include directory
5056 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5063 Install trouble-shooting section for suggestions).
5072 \begin_layout Standard
5084 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5088 to find exactly where SDCC is looking for the include and lib files.
5091 \begin_layout Section
5092 Install Trouble-shooting
5093 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5098 \begin_inset LatexCommand \index{Install trouble-shooting}
5105 \begin_layout Subsection
5106 If SDCC does not build correctly
5109 \begin_layout Standard
5110 A thing to try is starting from scratch by unpacking the .tgz source package
5111 again in an empty directory.
5119 ./configure 2>&1 | tee configure.log
5133 make 2>&1 | tee make.log
5140 If anything goes wrong, you can review the log files to locate the problem.
5141 Or a relevant part of this can be attached to an email that could be helpful
5142 when requesting help from the mailing list.
5145 \begin_layout Subsection
5147 \begin_inset Quotes sld
5151 \begin_inset Quotes srd
5157 \begin_layout Standard
5159 \begin_inset Quotes sld
5163 \begin_inset Quotes srd
5166 command is a script that analyzes your system and performs some configuration
5167 to ensure the source package compiles on your system.
5168 It will take a few minutes to run, and will compile a few tests to determine
5169 what compiler features are installed.
5172 \begin_layout Subsection
5174 \begin_inset Quotes sld
5178 \begin_inset Quotes srd
5184 \begin_layout Standard
5185 This runs the GNU make tool, which automatically compiles all the source
5186 packages into the final installed binary executables.
5189 \begin_layout Subsection
5191 \begin_inset Quotes sld
5195 \begin_inset Quotes erd
5201 \begin_layout Standard
5202 This will install the compiler, other executables libraries and include
5203 files into the appropriate directories.
5205 \begin_inset LatexCommand \ref{sub:Install-paths}
5211 \begin_inset LatexCommand \ref{sub:Search-Paths}
5216 about install and search paths.
5218 On most systems you will need super-user privilege
5222 \begin_layout Section
5226 \begin_layout Standard
5227 SDCC is not just a compiler, but a collection of tools by various developers.
5228 These include linkers, assemblers, simulators and other components.
5229 Here is a summary of some of the components.
5230 Note that the included simulator and assembler have separate documentation
5231 which you can find in the source package in their respective directories.
5232 As SDCC grows to include support for other processors, other packages from
5233 various developers are included and may have their own sets of documentation.
5238 might want to look at the files which are installed in <installdir>.
5239 At the time of this writing, we find the following programs for gcc-builds:
5244 In <installdir>/bin:
5247 \begin_layout Itemize
5248 sdcc - The compiler.
5251 \begin_layout Itemize
5252 sdcpp - The C preprocessor.
5255 \begin_layout Itemize
5256 asx8051 - The assembler for 8051 type processors.
5259 \begin_layout Itemize
5264 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5267 \begin_layout Itemize
5268 aslink -The linker for 8051 type processors.
5271 \begin_layout Itemize
5276 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5279 \begin_layout Itemize
5280 s51 - The ucSim 8051 simulator.
5283 \begin_layout Itemize
5284 sdcdb - The source debugger.
5287 \begin_layout Itemize
5288 packihx - A tool to pack (compress) Intel hex files.
5291 \begin_layout Standard
5292 In <installdir>/share/sdcc/include
5295 \begin_layout Itemize
5299 \begin_layout Standard
5300 In <installdir>/share/sdcc/lib
5303 \begin_layout Itemize
5304 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5308 \begin_layout Standard
5309 In <installdir>/share/sdcc/doc
5312 \begin_layout Itemize
5316 \begin_layout Standard
5317 As development for other processors proceeds, this list will expand to include
5318 executables to support processors like AVR, PIC, etc.
5321 \begin_layout Subsection
5325 \begin_layout Standard
5326 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5327 the assembler and linkage editor.
5330 \begin_layout Subsection
5331 sdcpp - The C-Preprocessor
5334 \begin_layout Standard
5336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5340 is a modified version of the GNU cpp
5341 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5346 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5351 The C preprocessor is used to pull in #include sources, process #ifdef
5352 statements, #defines and so on.
5355 \begin_layout Subsection
5364 - The Assemblers and Linkage Editors
5367 \begin_layout Standard
5368 This is retargettable assembler & linkage editor, it was developed by Alan
5370 John Hartman created the version for 8051, and I (Sandeep) have made some
5371 enhancements and bug fixes for it to work properly with SDCC.
5374 \begin_layout Subsection
5378 \begin_layout Standard
5380 \begin_inset LatexCommand \index{s51}
5384 is a free open source simulator developed by Daniel Drotos.
5385 The simulator is built as part of the build process.
5386 For more information visit Daniel's web site at:
5387 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5392 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5396 \begin_layout Subsection
5397 sdcdb - Source Level Debugger
5400 \begin_layout Standard
5402 \begin_inset LatexCommand \index{SDCDB (debugger)}
5406 is the companion source level debugger.
5407 More about SDCDB in section
5408 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5413 The current version of the debugger uses Daniel's Simulator S51
5414 \begin_inset LatexCommand \index{s51}
5418 , but can be easily changed to use other simulators.
5421 \begin_layout Chapter
5425 \begin_layout Section
5429 \begin_layout Subsection
5430 Single Source File Projects
5433 \begin_layout Standard
5434 For single source file 8051 projects the process is very simple.
5435 Compile your programs with the following command
5438 "sdcc sourcefile.c".
5442 This will compile, assemble and link your source file.
5443 Output files are as follows:
5446 \begin_layout Itemize
5448 \begin_inset LatexCommand \index{<file>.asm}
5453 \begin_inset LatexCommand \index{Assembler source}
5457 file created by the compiler
5460 \begin_layout Itemize
5462 \begin_inset LatexCommand \index{<file>.lst}
5467 \begin_inset LatexCommand \index{Assembler listing}
5471 file created by the Assembler
5474 \begin_layout Itemize
5476 \begin_inset LatexCommand \index{<file>.rst}
5481 \begin_inset LatexCommand \index{Assembler listing}
5485 file updated with linkedit information, created by linkage editor
5488 \begin_layout Itemize
5490 \begin_inset LatexCommand \index{<file>.sym}
5495 \begin_inset LatexCommand \index{Symbol listing}
5499 for the sourcefile, created by the assembler
5502 \begin_layout Itemize
5504 \begin_inset LatexCommand \index{<file>.rel}
5509 \begin_inset LatexCommand \index{<file>.o}
5514 \begin_inset LatexCommand \index{Object file}
5518 created by the assembler, input to Linkage editor
5521 \begin_layout Itemize
5523 \begin_inset LatexCommand \index{<file>.map}
5528 \begin_inset LatexCommand \index{Memory map}
5532 for the load module, created by the Linker
5535 \begin_layout Itemize
5537 \begin_inset LatexCommand \index{<file>.mem}
5541 - A file with a summary of the memory usage
5544 \begin_layout Itemize
5546 \begin_inset LatexCommand \index{<file>.ihx}
5550 - The load module in Intel hex format
5551 \begin_inset LatexCommand \index{Intel hex format}
5555 (you can select the Motorola S19 format
5556 \begin_inset LatexCommand \index{Motorola S19 format}
5564 \begin_layout Standard
5574 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5579 If you need another format you might want to use
5586 \begin_inset LatexCommand \index{objdump (tool)}
5597 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5602 \begin_inset Note Note
5605 \begin_layout Standard
5612 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5617 Both formats are documented in the documentation of srecord
5618 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5625 \begin_layout Itemize
5627 \begin_inset LatexCommand \index{<file>.adb}
5631 - An intermediate file containing debug information needed to create the
5636 \begin_layout Standard
5646 \begin_inset LatexCommand \index{-\/-debug}
5653 \begin_layout Itemize
5655 \begin_inset LatexCommand \index{<file>.cdb}
5659 - An optional file (with -
5663 \begin_layout Standard
5672 -debug) containing debug information.
5673 The format is documented in cdbfileformat.pdf
5676 \begin_layout Itemize
5679 \begin_inset LatexCommand \index{<file> (no extension)}
5683 An optional AOMF or AOMF51
5684 \begin_inset LatexCommand \index{AOMF, AOMF51}
5689 \begin_inset LatexCommand \label{OMF file}
5693 file containing debug information (generated with option -
5697 \begin_layout Standard
5723 ormat is a subformat of the OMF51 format and is commonly used by third party
5725 \begin_inset LatexCommand \index{Debugger}
5729 , simulators, emulators).
5732 \begin_layout Itemize
5734 \begin_inset LatexCommand \index{<file>.dump*}
5738 - Dump file to debug the compiler it self (generated with option -
5742 \begin_layout Standard
5751 -dumpall) (see section
5752 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5758 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5764 \begin_inset Quotes sld
5767 Anatomy of the compiler
5768 \begin_inset Quotes srd
5774 \begin_layout Subsection
5775 Postprocessing the Intel Hex
5776 \begin_inset LatexCommand \index{Intel hex format}
5781 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5788 \begin_layout Standard
5789 In most cases this won't be needed but the Intel Hex file
5790 \begin_inset LatexCommand \index{<file>.ihx}
5794 which is generated by SDCC might include lines of varying length and the
5795 addresses within the file are not guaranteed to be strictly ascending.
5796 If your toolchain or a bootloader does not like this you can use the tool
5802 \begin_inset LatexCommand \index{packihx (tool)}
5806 which is part of the SDCC distribution:
5813 packihx sourcefile.ihx >sourcefile.hex
5820 The separately available
5825 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5829 package additionally allows to set undefined locations to a predefined
5830 value, to insert checksums
5831 \begin_inset LatexCommand \index{checksum}
5835 of various flavours (crc, add, xor) and to perform other manipulations
5836 (convert, split, crop, offset, ...).
5844 srec_cat\InsetSpace ~
5846 sourcefile.ihx -intel\InsetSpace ~
5848 -o sourcefile.hex -intel
5855 An example for a more complex command line
5859 \begin_layout Standard
5860 the command backfills
5861 \begin_inset LatexCommand \index{backfill unused memory}
5865 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5867 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5868 will be interpreted as an
5876 (where an emergency routine could sit).
5889 srec_cat\InsetSpace ~
5890 sourcefile.ihx -intel\InsetSpace ~
5892 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5893 -little-endian-checksum-nega
5894 tive 0xfffe 0x02 0x02\InsetSpace ~
5896 -o sourcefile.hex -intel
5905 The srecord package is available at
5906 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5913 \begin_layout Subsection
5914 Projects with Multiple Source Files
5917 \begin_layout Standard
5918 SDCC can compile only ONE file at a time.
5919 Let us for example assume that you have a project containing the following
5924 foo1.c (contains some functions)
5926 foo2.c (contains some more functions)
5929 n.c (contains more functions and the function main)
5937 The first two files will need to be compiled separately with the commands:
5969 Then compile the source file containing the
5974 \begin_inset LatexCommand \index{Linker}
5978 the files together with the following command:
5986 foomain.c\InsetSpace ~
5987 foo1.rel\InsetSpace ~
5992 \begin_inset LatexCommand \index{<file>.rel}
6004 can be separately compiled as well:
6015 sdcc foomain.rel foo1.rel foo2.rel
6022 The file containing the
6037 file specified in the command line, since the linkage editor processes
6038 file in the order they are presented to it.
6039 The linker is invoked from SDCC using a script file with extension .lnk
6040 \begin_inset LatexCommand \index{<file>.lnk}
6045 You can view this file to troubleshoot linking problems such as those arising
6046 from missing libraries.
6049 \begin_layout Subsection
6050 Projects with Additional Libraries
6051 \begin_inset LatexCommand \index{Libraries}
6058 \begin_layout Standard
6059 Some reusable routines may be compiled into a library, see the documentation
6060 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6064 \begin_inset LatexCommand \index{<file>.lib}
6071 Libraries created in this manner can be included in the command line.
6072 Make sure you include the -L <library-path> option to tell the linker where
6073 to look for these files if they are not in the current directory.
6074 Here is an example, assuming you have the source file
6086 (if that is not the same as your current project):
6093 sdcc foomain.c foolib.lib -L mylib
6104 must be an absolute path name.
6108 The most efficient way to use libraries is
6109 to keep separate modules in separate source files.
6110 The lib file now should name all the modules.rel
6111 \begin_inset LatexCommand \index{<file>.rel}
6116 For an example see the standard library file
6120 in the directory <installdir>/share/lib/small.
6123 \begin_layout Subsection
6124 Using sdcclib to Create and Manage Libraries
6125 \begin_inset LatexCommand \index{sdcclib}
6132 \begin_layout Standard
6133 Alternatively, instead of having a .rel file for each entry on the library
6134 file as described in the preceding section, sdcclib can be used to embed
6135 all the modules belonging to such library in the library file itself.
6136 This results in a larger library file, but it greatly reduces the number
6137 of disk files accessed by the linker.
6138 Additionally, the packed library file contains an index of all include
6139 modules and symbols that significantly speeds up the linking process.
6140 To display a list of options supported by sdcclib type:
6145 \begin_layout Standard
6150 \begin_inset LatexCommand \index{sdcclib}
6161 To create a new library file, start by compiling all the required modules.
6167 \begin_layout Standard
6174 \begin_layout Standard
6181 \begin_layout Standard
6188 \begin_layout Standard
6195 \begin_layout Standard
6204 \begin_layout Standard
6205 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6207 The next step is to add the .rel files to the library file:
6212 \begin_layout Standard
6216 sdcclib libint.lib _divsint.rel
6219 \begin_inset LatexCommand \index{sdcclib}
6226 \begin_layout Standard
6230 sdcclib libint.lib _divuint.rel
6233 \begin_layout Standard
6237 sdcclib libint.lib _modsint.rel
6240 \begin_layout Standard
6244 sdcclib libint.lib _moduint.rel
6247 \begin_layout Standard
6251 sdcclib libint.lib _mulint.rel
6258 \begin_layout Standard
6259 If the file already exists in the library, it will be replaced.
6260 To see what modules and symbols are included in the library, options -s
6261 and -m are available.
6269 sdcclib -s libint.lib
6272 \begin_inset LatexCommand \index{sdcclib}
6284 \begin_layout Standard
6290 \begin_layout Standard
6296 \begin_layout Standard
6304 \begin_layout Standard
6310 \begin_layout Standard
6316 \begin_layout Standard
6322 \begin_layout Standard
6328 \begin_layout Standard
6336 \begin_layout Standard
6342 \begin_layout Standard
6348 \begin_layout Standard
6356 \begin_layout Standard
6362 \begin_layout Standard
6368 \begin_layout Standard
6374 \begin_layout Standard
6382 \begin_layout Standard
6388 \begin_layout Standard
6399 \begin_layout Standard
6400 If the source files are compiled using -
6404 \begin_layout Standard
6414 \begin_inset LatexCommand \index{-\/-debug}
6418 , the corresponding debug information file .adb will be include in the library
6420 The library files created with sdcclib are plain text files, so they can
6421 be viewed with a text editor.
6422 It is not recomended to modify a library file created with sdcclib using
6423 a text editor, as there are file indexes numbers located accross the file
6424 used by the linker to quickly locate the required module to link.
6425 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6426 it can be safely deleted, since all the information required for linking
6427 is embedded in the library file itself.
6428 Library files created using sdcclib are used as described in the preceding
6430 \begin_inset VSpace bigskip
6436 \begin_layout Section
6437 Command Line Options
6438 \begin_inset LatexCommand \index{Command Line Options}
6443 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6450 \begin_layout Subsection
6451 Processor Selection Options
6452 \begin_inset LatexCommand \index{Options processor selection}
6457 \begin_inset LatexCommand \index{Processor selection options}
6465 \labelwidthstring 00.00.0000
6469 \begin_inset LatexCommand \index{-mmcs51}
6475 Generate code for the Intel MCS51
6476 \begin_inset LatexCommand \index{MCS51}
6480 family of processors.
6481 This is the default processor target.
6485 \labelwidthstring 00.00.0000
6489 \begin_inset LatexCommand \index{-mds390}
6495 Generate code for the Dallas DS80C390
6496 \begin_inset LatexCommand \index{DS80C390}
6504 \labelwidthstring 00.00.0000
6508 \begin_inset LatexCommand \index{-mds400}
6514 Generate code for the Dallas DS80C400
6515 \begin_inset LatexCommand \index{DS80C400}
6523 \labelwidthstring 00.00.0000
6527 \begin_inset LatexCommand \index{-mhc08}
6533 Generate code for the Freescale/Motorola HC08
6534 \begin_inset LatexCommand \index{HC08}
6538 family of processors.
6542 \labelwidthstring 00.00.0000
6546 \begin_inset LatexCommand \index{-mz80}
6552 Generate code for the Zilog Z80
6553 \begin_inset LatexCommand \index{Z80}
6557 family of processors.
6561 \labelwidthstring 00.00.0000
6565 \begin_inset LatexCommand \index{-mgbz80}
6571 Generate code for the GameBoy Z80
6572 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6576 processor (Not actively maintained).
6580 \labelwidthstring 00.00.0000
6584 \begin_inset LatexCommand \index{-mavr}
6590 Generate code for the Atmel AVR
6591 \begin_inset LatexCommand \index{AVR}
6595 processor (Not maintained, not complete).
6596 AVR users should probably have a look at winavr
6597 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6602 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6606 , which is based on AVR-port of the gcc compiler.
6609 \begin_layout Standard
6610 \begin_inset Note Note
6613 \begin_layout Standard
6614 I think it is fair to direct users there for now.
6615 Open source is also about avoiding unnecessary work .
6616 But I didn't find the 'official' link.
6625 \labelwidthstring 00.00.0000
6629 \begin_inset LatexCommand \index{-mpic14}
6635 Generate code for the Microchip PIC 14
6636 \begin_inset LatexCommand \index{PIC14}
6640 -bit processors (p16f84 and variants.
6641 In development, not complete).
6644 \begin_layout Standard
6645 \begin_inset Note Note
6648 \begin_layout Standard
6649 p16f627 p16f628 p16f84 p16f873 p16f877?
6658 \labelwidthstring 00.00.0000
6662 \begin_inset LatexCommand \index{-mpic16}
6668 Generate code for the Microchip PIC 16
6669 \begin_inset LatexCommand \index{PIC16}
6673 -bit processors (p18f452 and variants.
6674 In development, not complete).
6678 \labelwidthstring 00.00.0000
6683 Generate code for the Toshiba TLCS-900H
6684 \begin_inset LatexCommand \index{TLCS-900H}
6688 processor (Not maintained, not complete).
6692 \labelwidthstring 00.00.0000
6696 \begin_inset LatexCommand \index{-mxa51}
6702 Generate code for the Phillips XA51
6703 \begin_inset LatexCommand \index{XA51}
6707 processor (Not maintained, not complete).
6710 \begin_layout Standard
6711 \begin_inset VSpace bigskip
6717 \begin_layout Subsection
6718 Preprocessor Options
6719 \begin_inset LatexCommand \index{Options preprocessor}
6724 \begin_inset LatexCommand \index{Preprocessor options}
6729 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6737 \labelwidthstring 00.00.0000
6741 \begin_inset LatexCommand \index{-I<path>}
6747 The additional location where the preprocessor will look for <..h> or
6748 \begin_inset Quotes eld
6752 \begin_inset Quotes erd
6759 \labelwidthstring 00.00.0000
6763 \begin_inset LatexCommand \index{-D<macro[=value]>}
6769 Command line definition of macros.
6770 Passed to the preprocessor.
6774 \labelwidthstring 00.00.0000
6778 \begin_inset LatexCommand \index{-M}
6784 Tell the preprocessor to output a rule suitable for make describing the
6785 dependencies of each object file.
6786 For each source file, the preprocessor outputs one make-rule whose target
6787 is the object file name for that source file and whose dependencies are
6788 all the files `#include'd in it.
6789 This rule may be a single line or may be continued with `
6791 '-newline if it is long.
6792 The list of rules is printed on standard output instead of the preprocessed
6795 \begin_inset LatexCommand \index{-E}
6803 \labelwidthstring 00.00.0000
6807 \begin_inset LatexCommand \index{-C}
6813 Tell the preprocessor not to discard comments.
6814 Used with the `-E' option.
6818 \labelwidthstring 00.00.0000
6822 \begin_inset LatexCommand \index{-MM}
6833 Like `-M' but the output mentions only the user header files included with
6835 \begin_inset Quotes eld
6839 System header files included with `#include <file>' are omitted.
6843 \labelwidthstring 00.00.0000
6847 \begin_inset LatexCommand \index{-Aquestion(answer)}
6853 Assert the answer answer for question, in case it is tested with a preprocessor
6854 conditional such as `#if #question(answer)'.
6855 `-A-' disables the standard assertions that normally describe the target
6860 \labelwidthstring 00.00.0000
6864 \begin_inset LatexCommand \index{-Umacro}
6870 Undefine macro macro.
6871 `-U' options are evaluated after all `-D' options, but before any `-include'
6872 and `-imacros' options.
6876 \labelwidthstring 00.00.0000
6880 \begin_inset LatexCommand \index{-dM}
6886 Tell the preprocessor to output only a list of the macro definitions that
6887 are in effect at the end of preprocessing.
6888 Used with the `-E' option.
6892 \labelwidthstring 00.00.0000
6896 \begin_inset LatexCommand \index{-dD}
6902 Tell the preprocessor to pass all macro definitions into the output, in
6903 their proper sequence in the rest of the output.
6907 \labelwidthstring 00.00.0000
6911 \begin_inset LatexCommand \index{-dN}
6922 Like `-dD' except that the macro arguments and contents are omitted.
6923 Only `#define name' is included in the output.
6927 \labelwidthstring 00.00.0000
6930 -pedantic-parse-number
6931 \begin_inset LatexCommand \index{pedantic}
6936 \begin_inset LatexCommand \index{-pedantic-parse-number}
6944 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6952 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6953 and the macro LO_B(3) gets expanded.
6954 See also #pragma pedantic_parse_number
6955 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6960 \begin_inset LatexCommand \ref{sec:Pragmas}
6966 Note: this functionality is not in conformance with C99 standard!
6970 \labelwidthstring 00.00.0000
6974 preprocessorOption[,preprocessorOption]
6977 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6982 Pass the preprocessorOption to the preprocessor
6987 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6992 SDCC uses an adapted version of the preprocessor
6996 of the GNU Compiler Collection
6997 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7006 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7010 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7015 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7022 \begin_layout Standard
7023 \begin_inset VSpace bigskip
7029 \begin_layout Subsection
7031 \begin_inset LatexCommand \index{Options linker}
7036 \begin_inset LatexCommand \index{Linker options}
7044 \labelwidthstring 00.00.0000
7054 \begin_layout Standard
7066 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7071 \begin_inset LatexCommand \index{-L -\/-lib-path}
7078 <absolute path to additional libraries> This option is passed to the linkage
7079 editor's additional libraries
7080 \begin_inset LatexCommand \index{Libraries}
7085 The path name must be absolute.
7086 Additional library files may be specified in the command line.
7087 See section Compiling programs for more details.
7091 \labelwidthstring 00.00.0000
7098 \begin_layout Standard
7110 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7115 <Value> The start location of the external ram
7116 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7120 , default value is 0.
7121 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7125 \begin_layout Standard
7134 -xram-loc 0x8000 or -
7138 \begin_layout Standard
7151 \labelwidthstring 00.00.0000
7158 \begin_layout Standard
7170 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7175 <Value> The start location of the code
7176 \begin_inset LatexCommand \index{code}
7180 segment, default value 0.
7181 Note when this option is used the interrupt vector table
7182 \begin_inset LatexCommand \index{interrupt vector table}
7186 is also relocated to the given address.
7187 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7191 \begin_layout Standard
7200 -code-loc 0x8000 or -
7204 \begin_layout Standard
7217 \labelwidthstring 00.00.0000
7224 \begin_layout Standard
7236 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7241 <Value> By default the stack
7242 \begin_inset LatexCommand \index{stack}
7246 is placed after the data segment.
7247 Using this option the stack can be placed anywhere in the internal memory
7249 The value entered can be in Hexadecimal or Decimal format, e.g.
7254 \begin_layout Standard
7263 -stack-loc 0x20 or -
7267 \begin_layout Standard
7277 Since the sp register is incremented before a push or call, the initial
7278 sp will be set to one byte prior the provided value.
7279 The provided value should not overlap any other memory areas such as used
7280 register banks or the data segment and with enough space for the current
7288 \begin_layout Standard
7301 \begin_inset LatexCommand \index{-\/-pack-iram}
7305 option (which is now a default setting) will override this setting, so
7306 you should also specify the
7312 \begin_layout Standard
7325 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7329 option if you need to manually place the stack.
7333 \labelwidthstring 00.00.0000
7340 \begin_layout Standard
7352 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7357 <Value> By default the external stack
7358 \begin_inset LatexCommand \index{xstack}
7362 is placed after the pdata
7363 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7368 Using this option the xstack can be placed anywhere in the external memory
7370 The value entered can be in Hexadecimal or Decimal format, e.g.
7375 \begin_layout Standard
7384 -xstack-loc 0x8000 or -
7388 \begin_layout Standard
7398 The provided value should not overlap any other memory areas such as the
7399 pdata or xdata segment and with enough space for the current application.
7403 \labelwidthstring 00.00.0000
7410 \begin_layout Standard
7422 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7427 <Value> The start location of the internal ram data
7428 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7433 The value entered can be in Hexadecimal or Decimal format, eg.
7438 \begin_layout Standard
7451 \begin_layout Standard
7461 (By default, the start location of the internal ram data segment is set
7462 as low as possible in memory, taking into account the used register banks
7463 and the bit segment at address 0x20.
7464 For example if register banks 0 and 1 are used without bit variables, the
7465 data segment will be set, if -
7469 \begin_layout Standard
7478 -data-loc is not used, to location 0x10.)
7482 \labelwidthstring 00.00.0000
7489 \begin_layout Standard
7501 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7506 <Value> The start location of the indirectly addressable internal ram
7507 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7511 of the 8051, default value is 0x80.
7512 The value entered can be in Hexadecimal or Decimal format, eg.
7517 \begin_layout Standard
7526 -idata-loc 0x88 or -
7530 \begin_layout Standard
7543 \labelwidthstring 00.00.0000
7550 \begin_layout Standard
7562 <Value> The start location of the bit
7563 \begin_inset LatexCommand \index{bit}
7567 addressable internal ram of the 8051.
7573 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7578 \labelwidthstring 00.00.0000
7585 \begin_layout Standard
7595 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7604 The linker output (final object code) is in Intel Hex format.
7605 \begin_inset LatexCommand \index{Intel hex format}
7609 This is the default option.
7610 The format itself is documented in the documentation of srecord
7611 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7619 \labelwidthstring 00.00.0000
7626 \begin_layout Standard
7636 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7645 The linker output (final object code) is in Motorola S19 format
7646 \begin_inset LatexCommand \index{Motorola S19 format}
7651 The format itself is documented in the documentation of srecord.
7655 \labelwidthstring 00.00.0000
7662 \begin_layout Standard
7672 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7677 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7686 The linker output (final object code) is in ELF format
7687 \begin_inset LatexCommand \index{ELF format}
7692 (Currently only supported for the HC08
7693 \begin_inset LatexCommand \index{HC08}
7701 \labelwidthstring 00.00.0000
7705 linkOption[,linkOption]
7708 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7713 Pass the linkOption to the linker.
7714 If a bootloader is used an option like
7715 \begin_inset Quotes sld
7720 \begin_inset Quotes srd
7723 would be typical to set the start of the code segment.
7724 See also #pragma constseg and #pragma codeseg in section
7725 \begin_inset LatexCommand \ref{sec:Pragmas}
7730 File sdcc/as/doc/asxhtm.html has more on linker options.
7733 \begin_layout Standard
7734 \begin_inset VSpace bigskip
7740 \begin_layout Subsection
7742 \begin_inset LatexCommand \index{Options MCS51}
7747 \begin_inset LatexCommand \index{MCS51 options}
7755 \labelwidthstring 00.00.0000
7762 \begin_layout Standard
7772 \begin_inset LatexCommand \index{-\/-model-small}
7783 Generate code for Small Model programs, see section Memory Models for more
7785 This is the default model.
7789 \labelwidthstring 00.00.0000
7796 \begin_layout Standard
7806 \begin_inset LatexCommand \index{-\/-model-medium}
7812 Generate code for Medium model programs, see section Memory Models for
7814 If this option is used all source files in the project have to be compiled
7816 It must also be used when invoking the linker.
7820 \labelwidthstring 00.00.0000
7827 \begin_layout Standard
7837 \begin_inset LatexCommand \index{-\/-model-large}
7843 Generate code for Large model programs, see section Memory Models for more
7845 If this option is used all source files in the project have to be compiled
7847 It must also be used when invoking the linker.
7851 \labelwidthstring 00.00.0000
7858 \begin_layout Standard
7868 \begin_inset LatexCommand \index{-\/-xstack}
7874 Uses a pseudo stack in the pdata
7875 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7879 area (usually the first 256 bytes in the external ram) for allocating variables
7880 and passing parameters.
7882 \begin_inset LatexCommand \ref{sub:External-Stack}
7887 External Stack for more details.
7891 \labelwidthstring 00.00.0000
7898 \begin_layout Standard
7911 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7915 Causes the linker to check if the internal ram usage is within limits of
7920 \labelwidthstring 00.00.0000
7927 \begin_layout Standard
7940 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7944 Causes the linker to check if the external ram usage is within limits of
7949 \labelwidthstring 00.00.0000
7956 \begin_layout Standard
7969 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7973 Causes the linker to check if the code memory usage is within limits of
7978 \labelwidthstring 00.00.0000
7985 \begin_layout Standard
7998 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8002 Causes the linker to check if there is at minimum <Value> bytes for stack.
8006 \labelwidthstring 00.00.0000
8013 \begin_layout Standard
8026 \begin_inset LatexCommand \index{-\/-pack-iram}
8030 Causes the linker to use unused register banks for data variables and pack
8031 data, idata and stack together.
8032 This is the default now.
8036 \labelwidthstring 00.00.0000
8043 \begin_layout Standard
8056 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8060 Causes the linker to use old style for allocating memory areas.
8063 \begin_layout Standard
8064 \begin_inset VSpace bigskip
8070 \begin_layout Subsection
8071 DS390 / DS400 Options
8072 \begin_inset LatexCommand \index{Options DS390}
8077 \begin_inset LatexCommand \index{DS390}
8085 \labelwidthstring 00.00.0000
8092 \begin_layout Standard
8104 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8114 Generate 24-bit flat mode code.
8115 This is the one and only that the ds390 code generator supports right now
8116 and is default when using
8121 See section Memory Models for more details.
8125 \labelwidthstring 00.00.0000
8132 \begin_layout Standard
8142 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8148 disable interrupts during ESP:SP updates.
8152 \labelwidthstring 00.00.0000
8159 \begin_layout Standard
8171 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8175 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8176 This is the one and only that the ds390 code generator supports right now
8177 and is default when using
8182 In this mode, the stack is located in the lower 1K of the internal RAM,
8183 which is mapped to 0x400000.
8184 Note that the support is incomplete, since it still uses a single byte
8185 as the stack pointer.
8186 This means that only the lower 256 bytes of the potential 1K stack space
8187 will actually be used.
8188 However, this does allow you to reclaim the precious 256 bytes of low RAM
8189 for use for the DATA and IDATA segments.
8190 The compiler will not generate any code to put the processor into 10 bit
8192 It is important to ensure that the processor is in this mode before calling
8193 any re-entrant functions compiled with this option.
8194 In principle, this should work with the
8200 \begin_layout Standard
8210 \begin_inset LatexCommand \index{-\/-stack-auto}
8216 option, but that has not been tested.
8217 It is incompatible with the
8223 \begin_layout Standard
8233 \begin_inset LatexCommand \index{-\/-xstack}
8240 It also only makes sense if the processor is in 24 bit contiguous addressing
8247 \begin_layout Standard
8256 -model-flat24 option
8261 \begin_inset Note Note
8265 \labelwidthstring 00.00.0000
8268 --stack-8-bit - switches off the 10-bit mode
8277 \labelwidthstring 00.00.0000
8284 \begin_layout Standard
8294 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8300 insert call to function __stack_probe at each function prologue.
8304 \labelwidthstring 00.00.0000
8311 \begin_layout Standard
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8327 <nnnn> LibraryID used in -mTININative.
8332 \labelwidthstring 00.00.0000
8339 \begin_layout Standard
8349 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8355 generate code for DS390 Arithmetic Accelerator.
8359 \begin_layout Standard
8360 \begin_inset VSpace bigskip
8366 \begin_layout Subsection
8368 \begin_inset LatexCommand \index{Options Z80}
8373 \begin_inset LatexCommand \index{Z80}
8381 \labelwidthstring 00.00.0000
8388 \begin_layout Standard
8400 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8410 Force a called function to always save BC.
8414 \labelwidthstring 00.00.0000
8421 \begin_layout Standard
8433 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8437 When linking, skip the standard crt0.o object file.
8438 You must provide your own crt0.o for your system when linking.
8442 \begin_layout Standard
8443 \begin_inset VSpace bigskip
8449 \begin_layout Subsection
8450 Optimization Options
8451 \begin_inset LatexCommand \index{Options optimization}
8456 \begin_inset LatexCommand \index{Optimization options}
8464 \labelwidthstring 00.00.0000
8471 \begin_layout Standard
8481 \begin_inset LatexCommand \index{-\/-nogcse}
8487 Will not do global subexpression elimination, this option may be used when
8488 the compiler creates undesirably large stack/data spaces to store compiler
8498 \begin_inset LatexCommand \index{sloc (spill location)}
8503 A warning message will be generated when this happens and the compiler
8504 will indicate the number of extra bytes it allocated.
8505 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8507 \begin_inset LatexCommand \index{\#pragma nogcse}
8511 can be used to turn off global subexpression elimination
8512 \begin_inset LatexCommand \index{Subexpression elimination}
8516 for a given function only.
8520 \labelwidthstring 00.00.0000
8527 \begin_layout Standard
8537 \begin_inset LatexCommand \index{-\/-noinvariant}
8543 Will not do loop invariant optimizations, this may be turned off for reasons
8544 explained for the previous option.
8545 For more details of loop optimizations performed see Loop Invariants in
8547 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8552 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8554 \begin_inset LatexCommand \index{\#pragma noinvariant}
8558 can be used to turn off invariant optimizations for a given function only.
8562 \labelwidthstring 00.00.0000
8569 \begin_layout Standard
8579 \begin_inset LatexCommand \index{-\/-noinduction}
8585 Will not do loop induction optimizations, see section strength reduction
8587 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8589 \begin_inset LatexCommand \index{\#pragma noinduction}
8593 can be used to turn off induction optimizations for a given function only.
8597 \labelwidthstring 00.00.0000
8604 \begin_layout Standard
8614 \begin_inset LatexCommand \index{-\/-nojtbound}
8625 Will not generate boundary condition check when switch statements
8626 \begin_inset LatexCommand \index{switch statement}
8630 are implemented using jump-tables.
8632 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8637 Switch Statements for more details.
8638 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8640 \begin_inset LatexCommand \index{\#pragma nojtbound}
8644 can be used to turn off boundary checking for jump tables for a given function
8649 \labelwidthstring 00.00.0000
8656 \begin_layout Standard
8666 \begin_inset LatexCommand \index{-\/-noloopreverse}
8675 Will not do loop reversal
8676 \begin_inset LatexCommand \index{Loop reversing}
8684 \labelwidthstring 00.00.0000
8689 \begin_layout Standard
8703 \begin_inset LatexCommand \index{-\/-nolabelopt }
8707 Will not optimize labels (makes the dumpfiles more readable).
8711 \labelwidthstring 00.00.0000
8718 \begin_layout Standard
8728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8734 Will not memcpy initialized data from code space into xdata space.
8735 This saves a few bytes in code space if you don't have initialized data
8736 \begin_inset LatexCommand \index{Variable initialization}
8744 \labelwidthstring 00.00.0000
8751 \begin_layout Standard
8761 \begin_inset LatexCommand \index{-\/-nooverlay}
8767 The compiler will not overlay parameters and local variables of any function,
8768 see section Parameters and local variables for more details.
8772 \labelwidthstring 00.00.0000
8779 \begin_layout Standard
8789 \begin_inset LatexCommand \index{-\/-no-peep}
8795 Disable peep-hole optimization with built-in rules.
8799 \labelwidthstring 00.00.0000
8806 \begin_layout Standard
8818 \begin_inset LatexCommand \index{-\/-peep-file}
8823 <filename> This option can be used to use additional rules to be used by
8824 the peep hole optimizer.
8826 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8831 Peep Hole optimizations for details on how to write these rules.
8835 \labelwidthstring 00.00.0000
8842 \begin_layout Standard
8852 \begin_inset LatexCommand \index{-\/-peep-asm}
8858 Pass the inline assembler code through the peep hole optimizer.
8859 This can cause unexpected changes to inline assembler code, please go through
8860 the peephole optimizer
8861 \begin_inset LatexCommand \index{Peephole optimizer}
8865 rules defined in the source file tree '<target>/peeph.def' before using
8870 \labelwidthstring 00.00.0000
8877 \begin_layout Standard
8887 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8893 The compiler will optimize code generation towards fast code, possibly
8894 at the expense of code size.
8898 \labelwidthstring 00.00.0000
8905 \begin_layout Standard
8915 \begin_inset LatexCommand \index{-\/-opt-code-size}
8921 The compiler will optimize code generation towards compact code, possibly
8922 at the expense of code speed.
8925 \begin_layout Standard
8926 \begin_inset VSpace bigskip
8932 \begin_layout Subsection
8934 \begin_inset LatexCommand \index{Options other}
8942 \labelwidthstring 00.00.0000
8950 \begin_layout Standard
8960 \begin_inset LatexCommand \index{-\/-compile-only}
8965 \begin_inset LatexCommand \index{-c -\/-compile-only}
8971 will compile and assemble the source, but will not call the linkage editor.
8975 \labelwidthstring 00.00.0000
8984 \begin_layout Standard
8996 \begin_inset LatexCommand \index{-\/-c1mode}
9002 reads the preprocessed source from standard input and compiles it.
9003 The file name for the assembler output must be specified using the -o option.
9007 \labelwidthstring 00.00.0000
9011 \begin_inset LatexCommand \index{-E}
9017 Run only the C preprocessor.
9018 Preprocess all the C source files specified and output the results to standard
9023 \labelwidthstring 00.00.0000
9028 \begin_inset LatexCommand \index{-o <path/file>}
9034 The output path resp.
9035 file where everything will be placed.
9036 If the parameter is a path, it must have a trailing slash (or backslash
9037 for the Windows binaries) to be recognized as a path.
9042 \labelwidthstring 00.00.0000
9049 \begin_layout Standard
9059 \begin_inset LatexCommand \index{-\/-stack-auto}
9070 All functions in the source file will be compiled as
9075 \begin_inset LatexCommand \index{reentrant}
9080 the parameters and local variables will be allocated on the stack
9081 \begin_inset LatexCommand \index{stack}
9087 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9091 Parameters and Local Variables for more details.
9092 If this option is used all source files in the project should be compiled
9094 It automatically implies --int-long-reent and --float-reent.
9099 \labelwidthstring 00.00.0000
9106 \begin_layout Standard
9116 \begin_inset LatexCommand \index{-\/-callee-saves}
9121 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9125 function1[,function2][,function3]....
9128 The compiler by default uses a caller saves convention for register saving
9129 across function calls, however this can cause unnecessary register pushing
9130 and popping when calling small functions from larger functions.
9131 This option can be used to switch the register saving convention for the
9132 function names specified.
9133 The compiler will not save registers when calling these functions, no extra
9134 code will be generated at the entry and exit (function prologue
9137 \begin_inset LatexCommand \index{function prologue}
9146 \begin_inset LatexCommand \index{function epilogue}
9152 ) for these functions to save and restore the registers used by these functions,
9153 this can SUBSTANTIALLY reduce code and improve run time performance of
9155 In the future the compiler (with inter procedural analysis) will be able
9156 to determine the appropriate scheme to use for each function call.
9157 DO NOT use this option for built-in functions such as _mulint..., if this
9158 option is used for a library function the appropriate library function
9159 needs to be recompiled with the same option.
9160 If the project consists of multiple source files then all the source file
9161 should be compiled with the same -
9165 \begin_layout Standard
9174 -callee-saves option string.
9175 Also see #pragma\InsetSpace ~
9177 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9182 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9190 \labelwidthstring 00.00.0000
9197 \begin_layout Standard
9207 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9221 \begin_layout Standard
9230 -callee-saves will be applied to all functions by default.
9234 \labelwidthstring 00.00.0000
9241 \begin_layout Standard
9251 \begin_inset LatexCommand \index{-\/-debug}
9260 When this option is used the compiler will generate debug information.
9261 The debug information collected in a file with .cdb extension can be used
9263 For more information see documentation for SDCDB.
9264 Another file with no extension contains debug information in AOMF or AOMF51
9265 \begin_inset LatexCommand \index{AOMF, AOMF51}
9269 format which is commonly used by third party tools.
9273 \labelwidthstring 00.00.0000
9277 \begin_inset LatexCommand \index{-S}
9288 Stop after the stage of compilation proper; do not assemble.
9289 The output is an assembler code file for the input file specified.
9293 \labelwidthstring 00.00.0000
9300 \begin_layout Standard
9310 \begin_inset LatexCommand \index{-\/-int-long-reent}
9316 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9317 Note by default these libraries are compiled as non-reentrant.
9318 See section Installation for more details.
9322 \labelwidthstring 00.00.0000
9329 \begin_layout Standard
9339 \begin_inset LatexCommand \index{-\/-cyclomatic}
9348 This option will cause the compiler to generate an information message for
9349 each function in the source file.
9350 The message contains some
9354 information about the function.
9355 The number of edges and nodes the compiler detected in the control flow
9356 graph of the function, and most importantly the
9358 cyclomatic complexity
9359 \begin_inset LatexCommand \index{Cyclomatic complexity}
9365 see section on Cyclomatic Complexity for more details.
9369 \labelwidthstring 00.00.0000
9376 \begin_layout Standard
9386 \begin_inset LatexCommand \index{-\/-float-reent}
9392 Floating point library is compiled as reentrant
9393 \begin_inset LatexCommand \index{reentrant}
9398 See section Installation for more details.
9402 \labelwidthstring 00.00.0000
9409 \begin_layout Standard
9419 \begin_inset LatexCommand \index{-\/-funsigned-char}
9425 The default signedness for every type is
9430 In some embedded environments the default signedness of
9439 To set the signess for characters to unsigned, use the option --funsigned-char.
9440 If this option is set and no signedness keyword (unsigned/signed) is given,
9441 a char will be signed.
9442 All other types are unaffected.
9446 \labelwidthstring 00.00.0000
9453 \begin_layout Standard
9463 \begin_inset LatexCommand \index{-\/-main-return}
9469 This option can be used if the code generated is called by a monitor program
9470 or if the main routine includes an endless loop.
9471 This option results in slightly smaller code and saves two bytes of stack
9473 The return from the 'main'
9474 \begin_inset LatexCommand \index{main return}
9478 function will return to the function calling main.
9479 The default setting is to lock up i.e.
9488 \labelwidthstring 00.00.0000
9495 \begin_layout Standard
9505 \begin_inset LatexCommand \index{-\/-nostdinc}
9511 This will prevent the compiler from passing on the default include path
9512 to the preprocessor.
9516 \labelwidthstring 00.00.0000
9523 \begin_layout Standard
9533 \begin_inset LatexCommand \index{-\/-nostdlib}
9539 This will prevent the compiler from passing on the default library
9540 \begin_inset LatexCommand \index{Libraries}
9548 \labelwidthstring 00.00.0000
9555 \begin_layout Standard
9565 \begin_inset LatexCommand \index{-\/-verbose}
9571 Shows the various actions the compiler is performing.
9575 \labelwidthstring 00.00.0000
9579 \begin_inset LatexCommand \index{-V}
9585 Shows the actual commands the compiler is executing.
9589 \labelwidthstring 00.00.0000
9596 \begin_layout Standard
9606 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9612 Hides your ugly and inefficient c-code from the asm file, so you can always
9613 blame the compiler :)
9617 \labelwidthstring 00.00.0000
9624 \begin_layout Standard
9634 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9640 Will not include peep-hole comments in the generated files.
9644 \labelwidthstring 00.00.0000
9651 \begin_layout Standard
9661 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9667 Include code generator comments in the generated asm files.
9671 \labelwidthstring 00.00.0000
9678 \begin_layout Standard
9688 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9694 Include i-codes in the asm file.
9695 Sounds like noise but is most helpful for debugging the compiler itself.
9699 \labelwidthstring 00.00.0000
9706 \begin_layout Standard
9716 \begin_inset LatexCommand \index{pedantic}
9721 \begin_inset LatexCommand \index{-\/-less-pedantic}
9728 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9732 Disable some of the more pedantic warnings
9733 \begin_inset LatexCommand \index{Warnings}
9738 For more details, see the less_pedantic pragma
9739 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9747 \labelwidthstring 00.00.0000
9754 \begin_layout Standard
9763 -disable-warning\InsetSpace ~
9765 \begin_inset LatexCommand \index{-\/-disable-warning}
9771 Disable specific warning with number <nnnn>.
9775 \labelwidthstring 00.00.0000
9782 \begin_layout Standard
9792 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9798 Display the directories in the compiler's search path
9802 \labelwidthstring 00.00.0000
9809 \begin_layout Standard
9819 \begin_inset LatexCommand \index{-\/-vc}
9825 Display errors and warnings using MSVC style, so you can use SDCC with
9826 the visual studio IDE
9827 \begin_inset LatexCommand \index{IDE}
9832 With SDCC both offering a GCC-like (the default) and a MSVC-like
9833 \begin_inset LatexCommand \index{MSVC output style}
9837 output style, integration into most programming editors should be straightforwa
9842 \labelwidthstring 00.00.0000
9849 \begin_layout Standard
9859 \begin_inset LatexCommand \index{-\/-use-stdout}
9865 Send errors and warnings to stdout instead of stderr.
9869 \labelwidthstring 00.00.0000
9873 asmOption[,asmOption]
9876 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9881 Pass the asmOption to the assembler
9882 \begin_inset LatexCommand \index{Options assembler}
9887 \begin_inset LatexCommand \index{Assembler options}
9892 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9896 \labelwidthstring 00.00.0000
9903 \begin_layout Standard
9913 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9919 Generally follow the C89 standard, but allow SDCC features that conflict
9920 with the standard (default).
9924 \labelwidthstring 00.00.0000
9931 \begin_layout Standard
9941 \begin_inset LatexCommand \index{-\/-std-c89}
9947 Follow the C89 standard and disable SDCC features that conflict with the
9952 \labelwidthstring 00.00.0000
9959 \begin_layout Standard
9969 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9975 Generally follow the C99 standard, but allow SDCC features that conflict
9976 with the standard (incomplete support).
9980 \labelwidthstring 00.00.0000
9987 \begin_layout Standard
9997 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10003 Follow the C99 standard and disable SDCC features that conflict with the
10004 standard (incomplete support).
10008 \labelwidthstring 00.00.0000
10015 \begin_layout Standard
10027 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10032 <Name> The name to be used for the code
10033 \begin_inset LatexCommand \index{code}
10037 segment, default CSEG.
10038 This is useful if you need to tell the compiler to put the code in a special
10039 segment so you can later on tell the linker to put this segment in a special
10041 Can be used for instance when using bank switching to put the code in a
10046 \labelwidthstring 00.00.0000
10053 \begin_layout Standard
10065 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10070 <Name> The name to be used for the const
10071 \begin_inset LatexCommand \index{code}
10075 segment, default CONST.
10076 This is useful if you need to tell the compiler to put the const data in
10077 a special segment so you can later on tell the linker to put this segment
10078 in a special place in memory.
10079 Can be used for instance when using bank switching to put the const data
10084 \labelwidthstring 00.00.0000
10091 \begin_layout Standard
10100 -fdollars-in-identifiers
10101 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10107 Permit '$' as an identifier character.
10111 \labelwidthstring 00.00.0000
10118 \begin_layout Standard
10130 \begin_inset LatexCommand \index{-\/-more-pedantic}
10135 \begin_inset LatexCommand \index{pedantic}
10145 a SDCC compiler option but if you want
10149 warnings you can use a separate tool dedicated to syntax checking like
10151 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10156 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10161 \begin_inset LatexCommand \url{http://www.splint.org}
10166 To make your source files parseable by splint you will have to include
10172 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10176 in your source file and add brackets around extended keywords (like
10179 \begin_inset Quotes sld
10192 \begin_inset Quotes srd
10200 \begin_inset Quotes sld
10203 __interrupt\InsetSpace ~
10205 \begin_inset Quotes srd
10213 Splint has an excellent on line manual at
10214 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10218 and it's capabilities go beyond pure syntax checking.
10219 You'll need to tell splint the location of SDCC's include files so a typical
10220 command line could look like this:
10224 splint\InsetSpace ~
10226 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10232 \labelwidthstring 00.00.0000
10239 \begin_layout Standard
10251 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10256 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10260 Treat short as 8-bit (for backward compatibility with older versions of
10261 compiler - see section
10262 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10269 \begin_layout Standard
10270 \begin_inset VSpace bigskip
10276 \begin_layout Subsection
10277 Intermediate Dump Options
10278 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10283 \begin_inset LatexCommand \index{Options intermediate dump}
10288 \begin_inset LatexCommand \index{Intermediate dump options}
10295 \begin_layout Standard
10296 The following options are provided for the purpose of retargetting and debugging
10298 They provide a means to dump the intermediate code (iCode
10299 \begin_inset LatexCommand \index{iCode}
10303 ) generated by the compiler in human readable form at various stages of
10304 the compilation process.
10305 More on iCodes see chapter
10306 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10311 \begin_inset Quotes srd
10314 The anatomy of the compiler
10315 \begin_inset Quotes srd
10322 \labelwidthstring 00.00.0000
10329 \begin_layout Standard
10339 \begin_inset LatexCommand \index{-\/-dumpraw}
10345 This option will cause the compiler to dump the intermediate code into
10348 <source filename>.dumpraw
10350 just after the intermediate code has been generated for a function, i.e.
10351 before any optimizations are done.
10353 \begin_inset LatexCommand \index{Basic blocks}
10357 at this stage ordered in the depth first number, so they may not be in
10358 sequence of execution.
10362 \labelwidthstring 00.00.0000
10369 \begin_layout Standard
10379 \begin_inset LatexCommand \index{-\/-dumpgcse}
10385 Will create a dump of iCode's, after global subexpression elimination
10386 \begin_inset LatexCommand \index{Global subexpression elimination}
10390 , into a file named
10392 <source filename>.dumpgcse.
10396 \labelwidthstring 00.00.0000
10403 \begin_layout Standard
10413 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10419 Will create a dump of iCode's, after deadcode elimination
10420 \begin_inset LatexCommand \index{Dead-code elimination}
10424 , into a file named
10426 <source filename>.dumpdeadcode.
10430 \labelwidthstring 00.00.0000
10437 \begin_layout Standard
10447 \begin_inset LatexCommand \index{-\/-dumploop}
10456 Will create a dump of iCode's, after loop optimizations
10457 \begin_inset LatexCommand \index{Loop optimization}
10461 , into a file named
10463 <source filename>.dumploop.
10467 \labelwidthstring 00.00.0000
10474 \begin_layout Standard
10484 \begin_inset LatexCommand \index{-\/-dumprange}
10493 Will create a dump of iCode's, after live range analysis
10494 \begin_inset LatexCommand \index{Live range analysis}
10498 , into a file named
10500 <source filename>.dumprange.
10504 \labelwidthstring 00.00.0000
10511 \begin_layout Standard
10521 \begin_inset LatexCommand \index{-\/-dumlrange}
10527 Will dump the life ranges
10528 \begin_inset LatexCommand \index{Live range analysis}
10536 \labelwidthstring 00.00.0000
10543 \begin_layout Standard
10553 \begin_inset LatexCommand \index{-\/-dumpregassign}
10562 Will create a dump of iCode's, after register assignment
10563 \begin_inset LatexCommand \index{Register assignment}
10567 , into a file named
10569 <source filename>.dumprassgn.
10573 \labelwidthstring 00.00.0000
10580 \begin_layout Standard
10590 \begin_inset LatexCommand \index{-\/-dumplrange}
10596 Will create a dump of the live ranges of iTemp's
10600 \labelwidthstring 00.00.0000
10607 \begin_layout Standard
10617 \begin_inset LatexCommand \index{-\/-dumpall}
10628 Will cause all the above mentioned dumps to be created.
10631 \begin_layout Standard
10632 \begin_inset VSpace bigskip
10638 \begin_layout Subsection
10639 Redirecting output on Windows Shells
10642 \begin_layout Standard
10643 By default SDCC writes it's error messages to
10644 \begin_inset Quotes sld
10648 \begin_inset Quotes srd
10652 To force all messages to
10653 \begin_inset Quotes sld
10657 \begin_inset Quotes srd
10669 \begin_layout Standard
10684 \begin_inset LatexCommand \index{-\/-use-stdout}
10689 Additionally, if you happen to have visual studio installed in your windows
10690 machine, you can use it to compile your sources using a custom build and
10697 \begin_layout Standard
10709 \begin_inset LatexCommand \index{-\/-vc}
10714 Something like this should work:
10733 \begin_layout Standard
10752 \begin_layout Standard
10764 -model-large -c $(InputPath)
10767 \begin_inset VSpace bigskip
10773 \begin_layout Section
10774 Environment variables
10775 \begin_inset LatexCommand \index{Environment variables}
10782 \begin_layout Standard
10783 SDCC recognizes the following environment variables:
10787 \labelwidthstring 00.00.0000
10791 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10797 SDCC installs a signal handler
10798 \begin_inset LatexCommand \index{signal handler}
10802 to be able to delete temporary files after an user break (^C) or an exception.
10803 If this environment variable is set, SDCC won't install the signal handler
10804 in order to be able to debug SDCC.
10808 \labelwidthstring 00.00.0000
10814 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10820 Path, where temporary files will be created.
10821 The order of the variables is the search order.
10822 In a standard *nix environment these variables are not set, and there's
10823 no need to set them.
10824 On Windows it's recommended to set one of them.
10828 \labelwidthstring 00.00.0000
10832 \begin_inset LatexCommand \index{SDCC\_HOME}
10839 \begin_inset LatexCommand \ref{sub:Install-paths}
10845 \begin_inset Quotes sld
10849 \begin_inset Quotes srd
10856 \labelwidthstring 00.00.0000
10860 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10867 \begin_inset LatexCommand \ref{sub:Search-Paths}
10873 \begin_inset Quotes sld
10877 \begin_inset Quotes srd
10884 \labelwidthstring 00.00.0000
10888 \begin_inset LatexCommand \index{SDCC\_LIB}
10895 \begin_inset LatexCommand \ref{sub:Search-Paths}
10901 \begin_inset Quotes sld
10905 \begin_inset Quotes srd
10911 \begin_layout Standard
10912 There are some more environment variables recognized by SDCC, but these
10913 are solely used for debugging purposes.
10914 They can change or disappear very quickly, and will never be documented.
10915 \begin_inset VSpace bigskip
10921 \begin_layout Section
10922 Storage Class Language Extensions
10925 \begin_layout Subsection
10926 MCS51/DS390 Storage Class
10927 \begin_inset LatexCommand \index{Storage class}
10931 Language Extensions
10934 \begin_layout Standard
10935 In addition to the ANSI storage classes SDCC allows the following MCS51
10936 specific storage classes:
10939 \begin_layout Subsubsection
10941 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10946 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10951 \begin_inset LatexCommand \index{near (storage class)}
10956 \begin_inset LatexCommand \index{\_\_near (storage class)}
10963 \begin_layout Standard
10968 storage class for the Small Memory model (
10976 or the more ANSI-C compliant forms
10984 can be used synonymously).
10985 Variables declared with this storage class will be allocated in the directly
10986 addressable portion of the internal RAM of a 8051, e.g.:
10989 \begin_layout Verse
10992 __data unsigned char test_data;
10995 \begin_layout Standard
10996 Writing 0x01 to this variable generates the assembly code:
10999 \begin_layout Verse
11002 75*00 01\InsetSpace ~
11010 \begin_layout Subsubsection
11012 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11017 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11022 \begin_inset LatexCommand \index{far (storage class)}
11027 \begin_inset LatexCommand \index{\_\_far (storage class)}
11034 \begin_layout Standard
11035 Variables declared with this storage class will be placed in the external
11041 storage class for the Large Memory model, e.g.:
11044 \begin_layout Verse
11047 __xdata unsigned char test_xdata;
11050 \begin_layout Standard
11051 Writing 0x01 to this variable generates the assembly code:
11054 \begin_layout Verse
11057 90s00r00\InsetSpace ~
11088 \begin_layout Subsubsection
11090 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11095 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11102 \begin_layout Standard
11103 Variables declared with this storage class will be allocated into the indirectly
11104 addressable portion of the internal ram of a 8051, e.g.:
11107 \begin_layout Verse
11110 __idata unsigned char test_idata;
11113 \begin_layout Standard
11114 Writing 0x01 to this variable generates the assembly code:
11117 \begin_layout Verse
11144 \begin_layout Standard
11145 Please note, the first 128 byte of idata physically access the same RAM
11146 as the data memory.
11147 The original 8051 had 128 byte idata memory, nowadays most devices have
11148 256 byte idata memory.
11150 \begin_inset LatexCommand \index{stack}
11154 is located in idata memory.
11157 \begin_layout Subsubsection
11159 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11164 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11171 \begin_layout Standard
11172 Paged xdata access is just as straightforward as using the other addressing
11174 It is typically located at the start of xdata and has a maximum size of
11176 The following example writes 0x01 to the pdata variable.
11177 Please note, pdata access physically accesses xdata memory.
11178 The high byte of the address is determined by port P2
11179 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11183 (or in case of some 8051 variants by a separate Special Function Register,
11185 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11194 storage class for the Medium Memory model, e.g.:
11197 \begin_layout Verse
11200 __pdata unsigned char test_pdata;
11203 \begin_layout Standard
11204 Writing 0x01 to this variable generates the assembly code:
11207 \begin_layout Verse
11216 mov r0,#_test_pdata
11238 \begin_layout Standard
11243 \begin_layout Standard
11253 \begin_inset LatexCommand \index{-\/-xstack}
11257 option is used the pdata memory area is followed by the xstack memory area
11258 and the sum of their sizes is limited to 256 bytes.
11261 \begin_layout Subsubsection
11263 \begin_inset LatexCommand \index{code}
11268 \begin_inset LatexCommand \index{\_\_code}
11275 \begin_layout Standard
11276 'Variables' declared with this storage class will be placed in the code
11280 \begin_layout Verse
11283 __code unsigned char test_code;
11286 \begin_layout Standard
11287 Read access to this variable generates the assembly code:
11290 \begin_layout Verse
11293 90s00r6F\InsetSpace ~
11296 mov dptr,#_test_code
11321 \begin_layout Standard
11326 indexed arrays of characters in code memory can be accessed efficiently:
11329 \begin_layout Verse
11332 __code char test_array[] = {'c','h','e','a','p'};
11335 \begin_layout Standard
11336 Read access to this array using an 8-bit unsigned index generates the assembly
11340 \begin_layout Verse
11352 \begin_layout Verse
11355 90s00r41\InsetSpace ~
11358 mov dptr,#_test_array
11361 \begin_layout Verse
11376 \begin_layout Subsubsection
11378 \begin_inset LatexCommand \index{bit}
11383 \begin_inset LatexCommand \index{\_\_bit}
11390 \begin_layout Standard
11391 This is a data-type and a storage class specifier.
11392 When a variable is declared as a bit, it is allocated into the bit addressable
11393 memory of 8051, e.g.:
11396 \begin_layout Verse
11402 \begin_layout Standard
11403 Writing 1 to this variable generates the assembly code:
11406 \begin_layout Verse
11420 \begin_layout Standard
11421 The bit addressable memory consists of 128 bits which are located from 0x20
11422 to 0x2f in data memory.
11425 Apart from this 8051 specific storage class most architectures support
11427 \begin_inset LatexCommand \index{bitfields}
11435 \begin_layout Standard
11436 Not really meant as examples, but nevertheless showing what bitfields are
11437 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11443 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11444 signed modifier are implemented as unsigned.
11447 \begin_layout Subsubsection
11449 \begin_inset LatexCommand \index{sfr}
11454 \begin_inset LatexCommand \index{\_\_sfr}
11459 \begin_inset LatexCommand \index{sfr16}
11464 \begin_inset LatexCommand \index{\_\_sfr16}
11469 \begin_inset LatexCommand \index{sfr32}
11474 \begin_inset LatexCommand \index{\_\_sfr32}
11479 \begin_inset LatexCommand \index{\_\_sbit}
11484 \begin_inset LatexCommand \index{sbit}
11491 \begin_layout Standard
11492 Like the bit keyword,
11494 sfr / sfr16 / sfr32 / sbit
11496 signify both a data-type and storage class, they are used to describe the
11517 variables of a 8051, eg:
11520 \begin_layout Verse
11524 \begin_inset LatexCommand \index{at}
11529 \begin_inset LatexCommand \index{\_\_at}
11533 (0x80) P0;\InsetSpace ~
11534 /* special function register P0 at location 0x80 */
11539 special function register combination for timer 0
11543 with the high byte at
11544 location 0x8C and the low byte at location 0x8A */
11546 __sfr16 __at (0x8C8A)
11552 \begin_inset LatexCommand \index{at}
11557 \begin_inset LatexCommand \index{\_\_at}
11561 (0xd7) CY;\InsetSpace ~
11563 \begin_inset LatexCommand \index{Flags}
11568 \begin_inset LatexCommand \index{Carry flag}
11575 \begin_layout Standard
11576 Special function registers which are located on an address dividable by
11577 8 are bit-addressable, an
11581 addresses a specific bit within these sfr.
11583 16 Bit and 32 bit special function
11584 register combinations which require a certain access order are better not
11594 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11595 this is not guaranteed.
11600 \begin_layout Standard
11601 Please note, if you use a header file which was written for another compiler
11602 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11608 Specifically the syntax
11611 sfr P0 = 0x80;\InsetSpace ~
11618 by SDCC to an assignment of 0x80 to a variable called P0
11621 \begin_inset Marginal
11624 \begin_layout Standard
11636 Nevertheless it is possible to write header files
11637 \begin_inset LatexCommand \index{Header files}
11642 \begin_inset LatexCommand \index{Include files}
11646 which can be shared among different compilers (see section
11647 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11655 \begin_layout Subsubsection
11657 \begin_inset LatexCommand \index{Pointer}
11661 to MCS51/DS390 specific memory spaces
11664 \begin_layout Standard
11665 SDCC allows (via language extensions) pointers to explicitly point to any
11666 of the memory spaces
11667 \begin_inset LatexCommand \index{Memory model}
11672 In addition to the explicit pointers, the compiler uses (by default) generic
11673 pointers which can be used to point to any of the memory spaces.
11678 declaration examples:
11681 \begin_layout Verse
11684 /* pointer physically in internal ram pointing to object in external ram
11687 __xdata unsigned char * __data p;
11691 /* pointer physically in external ram
11692 pointing to object in internal ram */
11694 __data unsigned char * __xdata p;
11699 pointer physically in code rom pointing to data in xdata space */
11702 unsigned char * __code p;
11706 /* pointer physically in code space pointing to
11707 data in code space */
11709 __code unsigned char * __code p;
11714 physically located in xdata space */
11716 unsigned char * __xdata p;
11721 pointer physically located in default memory space */
11728 the following is a function pointer
11729 \begin_inset LatexCommand \index{function pointer}
11733 physically located in data space */
11735 char (* __data fp)(void);
11738 \begin_layout Standard
11739 Well you get the idea.
11744 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11757 The highest order byte of the
11761 pointers contains the data space information.
11762 Assembler support routines are called whenever data is stored or retrieved
11768 These are useful for developing reusable library
11769 \begin_inset LatexCommand \index{Libraries}
11774 Explicitly specifying the pointer
11775 \begin_inset LatexCommand \index{pointer}
11779 type will generate the most efficient code.
11782 \begin_layout Subsubsection
11783 Notes on MCS51 memory
11784 \begin_inset LatexCommand \index{MCS51 memory}
11791 \begin_layout Standard
11792 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11793 RAM memory which is structured as follows:
11797 - Bytes 00-1F - 32 bytes to hold
11798 up to 4 banks of the registers R0 to R7,
11800 - Bytes 20-2F - 16 bytes to hold
11802 \begin_inset LatexCommand \index{bit}
11808 - Bytes 30-7F - 80 bytes for general purpose use.
11813 \begin_layout Standard
11814 Additionally some members of the MCS51 family may have up to 128 bytes of
11815 additional, indirectly addressable, internal RAM memory (
11820 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11825 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11830 Furthermore, some chips may have some built in external memory (
11835 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11840 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11844 ) which should not be confused with the internal, directly addressable RAM
11850 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11855 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11860 Sometimes this built in
11864 memory has to be activated before using it (you can probably find this
11865 information on the datasheet of the microcontroller your are using, see
11867 \begin_inset LatexCommand \ref{sub:Startup-Code}
11875 \begin_layout Standard
11876 Normally SDCC will only use the first bank
11877 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11881 of registers (register bank 0), but it is possible to specify that other
11882 banks of registers (keyword
11889 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11894 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11900 ) should be used for example in interrupt
11901 \begin_inset LatexCommand \index{interrupt}
11906 \begin_inset LatexCommand \index{\_\_interrupt}
11911 By default, the compiler will place the stack after the last byte of allocated
11912 memory for variables.
11913 For example, if the first 2 banks of registers are used, and only four
11918 variables, it will position the base of the internal stack at address 20
11920 This implies that as the stack
11921 \begin_inset LatexCommand \index{stack}
11925 grows, it will use up the remaining register banks, and the 16 bytes used
11926 by the 128 bit variables, and 80 bytes for general purpose use.
11927 If any bit variables are used, the data variables will be placed in unused
11928 register banks and after the byte holding the last bit variable.
11929 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11934 variables will be placed starting from address 0x10 to 0x20 and continue
11940 \begin_layout Standard
11950 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11954 to specify the start address of the
11962 \begin_layout Standard
11972 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11976 to specify the size of the total internal RAM (
11990 \begin_layout Standard
11991 By default the 8051 linker will place the stack after the last byte of (i)data
11997 \begin_layout Standard
12007 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12011 allows you to specify the start of the stack, i.e.
12012 you could start it after any data in the general purpose area.
12013 If your microcontroller has additional indirectly addressable internal
12018 ) you can place the stack on it.
12019 You may also need to use -
12023 \begin_layout Standard
12033 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12037 to set the start address of the external RAM (
12045 \begin_layout Standard
12055 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12059 to specify its size.
12060 Same goes for the code memory, using -
12064 \begin_layout Standard
12074 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12082 \begin_layout Standard
12092 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12097 If in doubt, don't specify any options and see if the resulting memory
12098 layout is appropriate, then you can adjust it.
12101 \begin_layout Standard
12102 The linker generates two files with memory allocation information.
12103 The first, with extension .map
12104 \begin_inset LatexCommand \index{<file>.map}
12108 shows all the variables and segments.
12109 The second with extension .mem
12110 \begin_inset LatexCommand \index{<file>.mem}
12114 shows the final memory layout.
12115 The linker will complain either if memory segments overlap, there is not
12116 enough memory, or there is not enough space for stack.
12117 If you get any linking warnings and/or errors related to stack or segments
12118 allocation, take a look at either the .map or .mem files to find out what
12120 The .mem file may even suggest a solution to the problem.
12121 \begin_inset VSpace bigskip
12127 \begin_layout Subsection
12128 Z80/Z180 Storage Class
12129 \begin_inset LatexCommand \index{Z80!Storage class}
12133 Language Extensions
12136 \begin_layout Subsubsection
12138 \begin_inset LatexCommand \index{sfr}
12143 \begin_inset LatexCommand \index{\_\_sfr}
12147 (in/out to 8-bit addresses)
12150 \begin_layout Standard
12152 \begin_inset LatexCommand \index{Z80}
12156 family has separate address spaces for memory and
12166 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12171 \begin_inset LatexCommand \index{Z80!I/O memory}
12176 \begin_inset LatexCommand \index{Z180!I/O memory}
12180 is accessed with special instructions, e.g.:
12183 \begin_layout Verse
12186 sfr at 0x78 IoPort;\InsetSpace ~
12188 /* define a var in I/O space at 78h called IoPort */
12192 \begin_layout Standard
12193 Writing 0x01 to this variable generates the assembly code:
12196 \begin_layout Verse
12216 \begin_layout Subsubsection
12218 \begin_inset LatexCommand \index{sfr}
12223 \begin_inset LatexCommand \index{\_\_sfr}
12227 (in/out to 16-bit addresses)
12230 \begin_layout Standard
12235 is used to support 16 bit addresses in I/O memory e.g.:
12238 \begin_layout Verse
12242 \begin_inset LatexCommand \index{at}
12247 \begin_inset LatexCommand \index{\_\_at}
12254 \begin_layout Standard
12255 Writing 0x01 to this variable generates the assembly code:
12258 \begin_layout Verse
12261 01 23 01\InsetSpace ~
12283 \begin_layout Subsubsection
12285 \begin_inset LatexCommand \index{sfr}
12290 \begin_inset LatexCommand \index{\_\_sfr}
12294 (in0/out0 to 8 bit addresses on Z180
12295 \begin_inset LatexCommand \index{Z180}
12300 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12307 \begin_layout Standard
12308 The compiler option -
12312 \begin_layout Standard
12322 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12326 =180 (80) and a compiler #pragma\InsetSpace ~
12328 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12332 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12342 If you include the file z180.h this will be set automatically.
12343 \begin_inset VSpace bigskip
12349 \begin_layout Subsection
12351 \begin_inset LatexCommand \index{HC08!Storage class}
12355 Language Extensions
12358 \begin_layout Subsubsection
12360 \begin_inset LatexCommand \index{data (hc08 storage class)}
12365 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12372 \begin_layout Standard
12373 The data storage class declares a variable that resides in the first 256
12374 bytes of memory (the direct page).
12376 \begin_inset LatexCommand \index{HC08}
12380 is most efficient at accessing variables (especially pointers) stored here.
12383 \begin_layout Subsubsection
12385 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12390 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12397 \begin_layout Standard
12398 The xdata storage class declares a variable that can reside anywhere in
12400 This is the default if no storage class is specified.
12402 \begin_inset VSpace bigskip
12408 \begin_layout Section
12409 Absolute Addressing
12410 \begin_inset LatexCommand \index{Absolute addressing}
12417 \begin_layout Standard
12418 Data items can be assigned an absolute address with the
12421 \begin_inset LatexCommand \index{at}
12426 \begin_inset LatexCommand \index{\_\_at}
12432 keyword, in addition to a storage class, e.g.:
12435 \begin_layout Verse
12439 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12444 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12449 \begin_inset LatexCommand \index{at}
12454 \begin_inset LatexCommand \index{\_\_at}
12458 0x7ffe unsigned int chksum;
12461 \begin_layout Standard
12462 or, better conforming to ISO/IEC 9899 C:
12465 \begin_layout Verse
12468 __xdata __at (0x7ffe) unsigned int chksum;
12471 \begin_layout Standard
12472 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12473 of the external ram.
12478 reserve any space for variables declared in this way
12479 \begin_inset Marginal
12482 \begin_layout Standard
12491 (they are implemented with an equate in the assembler).
12492 Thus it is left to the programmer to make sure there are no overlaps with
12493 other variables that are declared without the absolute address.
12494 The assembler listing file (.lst
12495 \begin_inset LatexCommand \index{<file>.lst}
12499 ) and the linker output files (.rst
12500 \begin_inset LatexCommand \index{<file>.rst}
12505 \begin_inset LatexCommand \index{<file>.map}
12509 ) are good places to look for such overlaps.
12510 Variables with an absolute address are
12513 \begin_inset Marginal
12516 \begin_layout Standard
12528 \begin_inset LatexCommand \index{Variable initialization}
12535 \begin_layout Standard
12536 In case of memory mapped I/O devices the keyword
12540 has to be used to tell the compiler that accesses might not be removed:
12543 \begin_layout Verse
12547 \begin_inset LatexCommand \index{volatile}
12552 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12557 \begin_inset LatexCommand \index{at}
12561 (0x8000) unsigned char PORTA_8255;
12564 \begin_layout Standard
12565 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12570 \begin_inset LatexCommand \index{Aligned array}
12577 starts at a block (256 byte) boundary
12578 \begin_inset LatexCommand \index{block boundary}
12583 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12589 Absolute addresses can be specified for variables in all
12590 storage classes, e.g.:
12593 \begin_layout Verse
12597 \begin_inset LatexCommand \index{bit}
12602 \begin_inset LatexCommand \index{at}
12609 \begin_layout Standard
12610 The above example will allocate the variable at offset 0x02 in the bit-addressab
12612 There is no real advantage to assigning absolute addresses to variables
12613 in this manner, unless you want strict control over all the variables allocated.
12614 One possible use would be to write hardware portable code.
12615 For example, if you have a routine that uses one or more of the microcontroller
12616 I/O pins, and such pins are different for two different hardwares, you
12617 can declare the I/O pins in your routine using:
12620 \begin_layout Verse
12624 \begin_inset LatexCommand \index{volatile}
12628 __bit MOSI;\InsetSpace ~
12632 /* master out, slave in */
12634 extern volatile __bit MISO;\InsetSpace ~
12641 extern volatile __bit MCLK;\InsetSpace ~
12650 Output of a byte on a 3-wire serial bus.
12655 If needed adapt polarity of clock,
12656 polarity of data and bit order
12661 unsigned char spi_io(unsigned char out_byte)
12686 MOSI = out_byte & 0x80;
12717 /* _asm nop _endasm; */\InsetSpace ~
12725 /* for slow peripherals */
12777 \begin_layout Standard
12778 Then, someplace in the code for the first hardware you would use
12781 \begin_layout Verse
12785 \begin_inset LatexCommand \index{at}
12790 \begin_inset LatexCommand \index{\_\_at}
12794 (0x80) MOSI;\InsetSpace ~
12798 /* I/O port 0, bit 0 */
12800 __bit __at (0x81) MISO;\InsetSpace ~
12807 __bit __at (0x82) MCLK;\InsetSpace ~
12811 /* I/O port 0, bit 2 */
12814 \begin_layout Standard
12815 Similarly, for the second hardware you would use
12818 \begin_layout Verse
12821 __bit __at (0x83) MOSI;\InsetSpace ~
12825 /* I/O port 0, bit 3 */
12827 __bit __at (0x91) MISO;\InsetSpace ~
12832 I/O port 1, bit 1 */
12835 \begin_inset LatexCommand \index{bit}
12839 __at (0x92) MCLK;\InsetSpace ~
12843 /* I/O port 1, bit 2 */
12846 \begin_layout Standard
12847 and you can use the same hardware dependent routine without changes, as
12848 for example in a library.
12849 This is somehow similar to sbit, but only one absolute address has to be
12850 specified in the whole project.
12851 \begin_inset VSpace bigskip
12857 \begin_layout Section
12859 \begin_inset LatexCommand \index{Parameters}
12864 \begin_inset LatexCommand \index{function parameter}
12869 \begin_inset LatexCommand \index{local variables}
12874 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12881 \begin_layout Standard
12882 Automatic (local) variables and parameters to functions can either be placed
12883 on the stack or in data-space.
12884 The default action of the compiler is to place these variables in the internal
12885 RAM (for small model) or external RAM (for large model).
12886 This in fact makes them similar to
12889 \begin_inset LatexCommand \index{static}
12895 so by default functions are non-reentrant
12896 \begin_inset LatexCommand \index{reentrant}
12905 They can be placed on the stack
12906 \begin_inset LatexCommand \index{stack}
12916 \begin_layout Standard
12926 \begin_inset LatexCommand \index{-\/-stack-auto}
12934 #pragma\InsetSpace ~
12938 \begin_inset LatexCommand \index{\#pragma stackauto}
12945 \begin_inset LatexCommand \index{reentrant}
12951 keyword in the function declaration, e.g.:
12954 \begin_layout Verse
12957 unsigned char foo(char i) __reentrant
12971 \begin_layout Standard
12972 Since stack space on 8051 is limited, the
12982 \begin_layout Standard
12993 option should be used sparingly.
12994 Note that the reentrant keyword just means that the parameters & local
12995 variables will be allocated to the stack, it
12999 mean that the function is register bank
13000 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13009 \begin_inset LatexCommand \index{local variables}
13013 can be assigned storage classes and absolute
13014 \begin_inset LatexCommand \index{Absolute addressing}
13021 \begin_layout Verse
13024 unsigned char foo()
13032 __xdata unsigned char i;
13045 \begin_inset LatexCommand \index{at}
13049 (0x31) unsigned char j;
13061 \begin_layout Standard
13062 In the above example the variable
13066 will be allocated in the external ram,
13070 in bit addressable space and
13081 \begin_layout Standard
13092 or when a function is declared as
13096 this should only be done for static variables.
13099 \begin_layout Standard
13101 \begin_inset LatexCommand \index{function parameter}
13105 however are not allowed any storage class
13106 \begin_inset LatexCommand \index{Storage class}
13110 , (storage classes for parameters will be ignored), their allocation is
13111 governed by the memory model in use, and the reentrancy options.
13114 \begin_layout Standard
13115 It is however allowed to use bit parameters in reentrant functions and also
13116 non-static local bit variables are supported.
13117 Efficient use is limited to 8 semi-bitregisters in bit space.
13118 They are pushed and popped to stack
13119 \begin_inset LatexCommand \index{stack}
13123 as a single byte just like the normal registers.
13126 \begin_layout Section
13128 \begin_inset LatexCommand \label{sub:Overlaying}
13133 \begin_inset LatexCommand \index{Overlaying}
13140 \begin_layout Standard
13142 \begin_inset LatexCommand \index{reentrant}
13146 functions SDCC will try to reduce internal ram space usage by overlaying
13147 parameters and local variables of a function (if possible).
13148 Parameters and local variables
13149 \begin_inset LatexCommand \index{local variables}
13153 of a function will be allocated to an overlayable segment if the function
13156 no other function calls and the function is non-reentrant and the memory
13158 \begin_inset LatexCommand \index{Memory model}
13165 If an explicit storage class
13166 \begin_inset LatexCommand \index{Storage class}
13170 is specified for a local variable, it will NOT be overlayed.
13173 \begin_layout Standard
13174 Note that the compiler (not the linkage editor) makes the decision for overlayin
13176 Functions that are called from an interrupt service routine
13177 \begin_inset Marginal
13180 \begin_layout Standard
13188 should be preceded by a #pragma\InsetSpace ~
13190 \begin_inset LatexCommand \index{\#pragma nooverlay}
13194 if they are not reentrant.
13197 \begin_layout Standard
13198 Also note that the compiler does not do any processing of inline assembler
13199 code, so the compiler might incorrectly assign local variables and parameters
13200 of a function into the overlay segment if the inline assembler code calls
13201 other c-functions that might use the overlay.
13202 In that case the #pragma\InsetSpace ~
13203 nooverlay should be used.
13206 \begin_layout Standard
13207 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13209 \begin_inset LatexCommand \index{Multiplication}
13214 \begin_inset LatexCommand \index{Division}
13218 will NOT be overlayed since these are implemented using external functions,
13222 \begin_layout Verse
13228 \begin_inset LatexCommand \index{\#pragma nooverlay}
13234 void set_error(unsigned char errcd)
13251 some_isr () __interrupt
13252 \begin_inset LatexCommand \index{interrupt}
13282 \begin_layout Standard
13283 In the above example the parameter
13291 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13293 not present, this could cause unpredictable runtime behavior when called
13294 from an interrupt service routine.
13295 The #pragma\InsetSpace ~
13296 nooverlay ensures that the parameters and local variables for
13297 the function are NOT overlayed.
13298 \begin_inset VSpace bigskip
13304 \begin_layout Section
13305 Interrupt Service Routines
13306 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13313 \begin_layout Subsection
13314 General Information
13317 \begin_layout Standard
13330 outines to be coded in C, with some extended keywords.
13333 \begin_layout Verse
13336 void timer_isr (void) __interrupt (1) __using (1)
13350 \begin_layout Standard
13351 The optional number following the
13354 \begin_inset LatexCommand \index{interrupt}
13359 \begin_inset LatexCommand \index{\_\_interrupt}
13365 keyword is the interrupt number this routine will service.
13366 When present, the compiler will insert a call to this routine in the interrupt
13368 \begin_inset LatexCommand \index{interrupt vector table}
13372 for the interrupt number specified.
13373 If you have multiple source files in your project, interrupt service routines
13374 can be present in any of them, but a prototype of the isr MUST be present
13375 or included in the file that contains the function
13380 The optional (8051 specific) keyword
13383 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13388 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13394 can be used to tell the compiler to use the specified register bank when
13395 generating code for this function.
13398 Interrupt service routines open the door for some very interesting bugs:
13401 \begin_layout Subsubsection
13402 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13406 Common interrupt pitfall: variable not declared
13411 \begin_layout Standard
13412 If an interrupt service routine changes variables which are accessed by
13413 other functions these variables have to be declared
13418 \begin_inset LatexCommand \index{volatile}
13424 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13431 \begin_layout Subsubsection
13432 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13436 Common interrupt pitfall:
13441 \begin_layout Standard
13442 If the access to these variables is not
13445 \begin_inset LatexCommand \index{atomic}
13452 the processor needs more than one instruction for the access and could
13453 be interrupted while accessing the variable) the interrupt must be disabled
13454 during the access to avoid inconsistent data.
13457 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13458 and should be protected by disabling interrupts.
13459 You're not automatically on the safe side if you use 8 bit variables though.
13460 We need an example here: f.e.
13461 on the 8051 the harmless looking
13462 \begin_inset Quotes srd
13472 \begin_inset Quotes sld
13481 \begin_inset Quotes srd
13491 \begin_inset Quotes sld
13494 from within an interrupt routine might get lost if the interrupt occurs
13497 \begin_inset Quotes sld
13502 counter\InsetSpace ~
13507 \begin_inset Quotes srd
13510 is not atomic on the 8051 even if
13514 is located in data memory.
13516 Bugs like these are hard to reproduce and can
13517 cause a lot of trouble.
13521 \begin_layout Subsubsection
13522 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13526 Common interrupt pitfall:
13531 \begin_layout Standard
13532 The return address and the registers used in the interrupt service routine
13533 are saved on the stack
13534 \begin_inset LatexCommand \index{stack}
13538 so there must be sufficient stack space.
13539 If there isn't variables or registers (or even the return address itself)
13546 \begin_inset LatexCommand \index{stack overflow}
13550 is most likely to happen if the interrupt occurs during the
13551 \begin_inset Quotes sld
13555 \begin_inset Quotes srd
13558 subroutine when the stack is already in use for f.e.
13559 many return addresses.
13562 \begin_layout Subsubsection
13563 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13567 Common interrupt pitfall:
13569 use of non-reentrant functions
13572 \begin_layout Standard
13573 A special note here, int (16 bit) and long (32 bit) integer division
13574 \begin_inset LatexCommand \index{Division}
13579 \begin_inset LatexCommand \index{Multiplication}
13584 \begin_inset LatexCommand \index{Modulus}
13589 \begin_inset LatexCommand \index{Floating point support}
13593 operations are implemented using external support routines.
13594 If an interrupt service routine needs to do any of these operations then
13595 the support routines (as mentioned in a following section) will have to
13596 be recompiled using the
13602 \begin_layout Standard
13612 \begin_inset LatexCommand \index{-\/-stack-auto}
13618 option and the source file will need to be compiled using the
13624 \begin_layout Standard
13636 \begin_inset LatexCommand \index{-\/-int-long-reent}
13643 Note, the type promotion
13644 \begin_inset LatexCommand \index{type promotion}
13648 required by ANSI C can cause 16 bit routines to be used
13649 \begin_inset Marginal
13652 \begin_layout Standard
13661 without the programmer being aware of it.
13665 (unsigned char)(tail-1)
13667 within the if clause in section
13668 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13675 \begin_layout Standard
13676 Calling other functions from an interrupt service routine is not recommended,
13677 avoid it if possible.
13678 Note that when some function is called from an interrupt service routine
13679 it should be preceded by a #pragma\InsetSpace ~
13681 \begin_inset LatexCommand \index{\#pragma nooverlay}
13685 if it is not reentrant.
13686 Furthermore nonreentrant functions should not be called from the main program
13687 while the interrupt service routine might be active.
13688 They also must not be called from low priority interrupt service routines
13689 while a high priority interrupt service routine might be active.
13690 You could use semaphores or make the function
13694 if all parameters are passed in registers.
13697 \begin_inset LatexCommand \ref{sub:Overlaying}
13702 about Overlaying and section
13703 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13708 about Functions using private register banks.
13709 \begin_inset VSpace bigskip
13715 \begin_layout Subsection
13716 MCS51/DS390 Interrupt Service Routines
13719 \begin_layout Standard
13721 \begin_inset LatexCommand \index{interrupt}
13725 numbers and the corresponding address & descriptions for the Standard 8051/8052
13727 SDCC will automatically adjust the
13728 \begin_inset LatexCommand \index{interrupt vector table}
13732 to the maximum interrupt number specified.
13737 \begin_layout Standard
13739 \begin_inset Tabular
13740 <lyxtabular version="3" rows="9" columns="3">
13742 <column alignment="center" valignment="top" leftline="true" width="0in">
13743 <column alignment="left" valignment="top" leftline="true" width="0in">
13744 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13745 <row topline="true" bottomline="true">
13746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13749 \begin_layout Standard
13755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13758 \begin_layout Standard
13764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13767 \begin_layout Standard
13774 <row topline="true">
13775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13778 \begin_layout Standard
13784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13787 \begin_layout Standard
13793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13796 \begin_layout Standard
13803 <row topline="true">
13804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13807 \begin_layout Standard
13813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13816 \begin_layout Standard
13822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13825 \begin_layout Standard
13832 <row topline="true">
13833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13836 \begin_layout Standard
13842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13845 \begin_layout Standard
13851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13854 \begin_layout Standard
13861 <row topline="true">
13862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13865 \begin_layout Standard
13871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13874 \begin_layout Standard
13880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13883 \begin_layout Standard
13890 <row topline="true">
13891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13894 \begin_layout Standard
13900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13903 \begin_layout Standard
13909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13912 \begin_layout Standard
13919 <row topline="true">
13920 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13923 \begin_layout Standard
13929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13932 \begin_layout Standard
13938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13941 \begin_layout Standard
13948 <row topline="true">
13949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13952 \begin_layout Standard
13958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13961 \begin_layout Standard
13967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13970 \begin_layout Standard
13977 <row topline="true" bottomline="true">
13978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13981 \begin_layout Standard
13987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13990 \begin_layout Standard
13996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13999 \begin_layout Standard
14015 \begin_layout Standard
14016 If the interrupt service routine is defined without
14019 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14024 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14030 a register bank or with register bank 0 (
14034 0), the compiler will save the registers used by itself on the stack upon
14035 entry and restore them at exit, however if such an interrupt service routine
14036 calls another function then the entire register bank will be saved on the
14038 This scheme may be advantageous for small interrupt service routines which
14039 have low register usage.
14042 \begin_layout Standard
14043 If the interrupt service routine is defined to be using a specific register
14048 & psw are saved and restored, if such an interrupt service routine calls
14049 another function (using another register bank) then the entire register
14050 bank of the called function will be saved on the stack
14051 \begin_inset LatexCommand \index{stack}
14056 This scheme is recommended for larger interrupt service routines.
14057 \begin_inset VSpace bigskip
14063 \begin_layout Subsection
14065 \begin_inset LatexCommand \index{HC08}
14069 Interrupt Service Routines
14072 \begin_layout Standard
14073 Since the number of interrupts
14074 \begin_inset LatexCommand \index{HC08!interrupt}
14078 available is chip specific and the interrupt vector table always ends at
14079 the last byte of memory, the interrupt numbers corresponds to the interrupt
14080 vectors in reverse order of address.
14081 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14082 2 will use the interrupt vector at 0xfffa, and so on.
14083 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14084 this way; instead see section
14085 \begin_inset LatexCommand \ref{sub:Startup-Code}
14089 for details on customizing startup.
14090 \begin_inset VSpace bigskip
14096 \begin_layout Subsection
14097 Z80 Interrupt Service Routines
14100 \begin_layout Standard
14102 \begin_inset LatexCommand \index{Z80}
14106 uses several different methods for determining the correct interrupt
14107 \begin_inset LatexCommand \index{Z80!interrupt}
14111 vector depending on the hardware implementation.
14112 Therefore, SDCC ignores the optional interrupt number and does not attempt
14113 to generate an interrupt vector table.
14116 \begin_layout Standard
14117 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14118 instruction to return from the interrupt.
14119 To write an interrupt handler for the non-maskable interrupt, which needs
14120 a RETN instruction instead, add the
14127 \begin_layout Verse
14130 void nmi_isr (void) critical interrupt
14144 \begin_layout Standard
14145 However if you need to create a non-interruptable interrupt service routine
14146 you would also require the
14151 To distinguish between this and an nmi_isr you must provide an interrupt
14153 \begin_inset VSpace bigskip
14159 \begin_layout Section
14160 Enabling and Disabling Interrupts
14163 \begin_layout Subsection
14164 Critical Functions and Critical Statements
14167 \begin_layout Standard
14168 A special keyword may be associated with a block or a function declaring
14174 SDCC will generate code to disable all interrupts
14175 \begin_inset LatexCommand \index{interrupt}
14179 upon entry to a critical function and restore the interrupt enable to the
14180 previous state before returning.
14181 Nesting critical functions will need one additional byte on the stack
14182 \begin_inset LatexCommand \index{stack}
14189 \begin_layout Verse
14192 int foo () __critical
14193 \begin_inset LatexCommand \index{critical}
14198 \begin_inset LatexCommand \index{\_\_critical}
14223 \begin_layout Standard
14224 The critical attribute maybe used with other attributes like
14234 may also be used to disable interrupts more locally:
14237 \begin_layout Verse
14243 \begin_layout Standard
14244 More than one statement could have been included in the block.
14247 \begin_layout Subsection
14248 Enabling and Disabling Interrupts directly
14251 \begin_layout Standard
14253 \begin_inset LatexCommand \index{interrupt}
14257 can also be disabled and enabled directly (8051):
14260 \begin_layout Verse
14263 EA = 0;\InsetSpace ~
14289 \begin_layout Verse
14325 \begin_layout Verse
14328 EA = 1;\InsetSpace ~
14357 \begin_layout Verse
14396 \begin_layout Standard
14397 On other architectures which have seperate opcodes for enabling and disabling
14398 interrupts you might want to make use of defines with inline assembly
14399 \begin_inset LatexCommand \index{Assembler routines}
14404 \begin_inset LatexCommand \index{HC08!interrupt}
14411 \begin_layout Verse
14415 \begin_inset LatexCommand \index{\_asm}
14424 \begin_inset LatexCommand \index{\_endasm}
14431 \begin_layout Verse
14434 #define SEI _asm\InsetSpace ~
14441 \begin_layout Verse
14447 \begin_layout Standard
14448 Note: it is sometimes sufficient to disable only a specific interrupt source
14450 a timer or serial interrupt by manipulating an
14453 \begin_inset LatexCommand \index{interrupt mask}
14463 \begin_layout Standard
14464 Usually the time during which interrupts are disabled should be kept as
14466 This minimizes both
14471 \begin_inset LatexCommand \index{interrupt latency}
14475 (the time between the occurrence of the interrupt and the execution of
14476 the first code in the interrupt routine) and
14481 \begin_inset LatexCommand \index{interrupt jitter}
14485 (the difference between the shortest and the longest interrupt latency).
14486 These really are something different, f.e.
14487 a serial interrupt has to be served before its buffer overruns so it cares
14488 for the maximum interrupt latency, whereas it does not care about jitter.
14489 On a loudspeaker driven via a digital to analog converter which is fed
14490 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14491 a much smaller jitter will be very audible.
14494 \begin_layout Standard
14495 You can reenable interrupts within an interrupt routine and on some architecture
14496 s you can make use of two (or more) levels of
14498 interrupt priorities
14501 \begin_inset LatexCommand \index{interrupt priority}
14506 On some architectures which don't support interrupt priorities these can
14507 be implemented by manipulating the interrupt mask and reenabling interrupts
14508 within the interrupt routine.
14509 Check there is sufficient space on the stack
14510 \begin_inset LatexCommand \index{stack}
14514 and don't add complexity unless you have to.
14518 \begin_layout Subsection
14520 \begin_inset LatexCommand \index{semaphore}
14524 locking (mcs51/ds390)
14527 \begin_layout Standard
14528 Some architectures (mcs51/ds390) have an atomic
14529 \begin_inset LatexCommand \index{atomic}
14542 These type of instructions are typically used in preemptive multitasking
14543 systems, where a routine f.e.
14544 claims the use of a data structure ('acquires a lock
14545 \begin_inset LatexCommand \index{lock}
14549 on it'), makes some modifications and then releases the lock when the data
14550 structure is consistent again.
14551 The instruction may also be used if interrupt and non-interrupt code have
14552 to compete for a resource.
14553 With the atomic bit test and clear instruction interrupts
14554 \begin_inset LatexCommand \index{interrupt}
14558 don't have to be disabled for the locking operation.
14562 \begin_layout Standard
14563 SDCC generates this instruction if the source follows this pattern:
14566 \begin_layout Verse
14570 \begin_inset LatexCommand \index{volatile}
14574 bit resource_is_free;
14578 if (resource_is_free)
14588 resource_is_free=0;
14601 resource_is_free=1;
14608 \begin_layout Standard
14609 Note, mcs51 and ds390 support only an atomic
14610 \begin_inset LatexCommand \index{atomic}
14618 instruction (as opposed to atomic bit test and
14623 \begin_layout Section
14624 Functions using private register banks
14625 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14632 \begin_layout Standard
14633 Some architectures have support for quickly changing register sets.
14634 SDCC supports this feature with the
14637 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14642 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14648 attribute (which tells the compiler to use a register bank
14649 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14653 other than the default bank zero).
14654 It should only be applied to
14657 \begin_inset LatexCommand \index{interrupt}
14663 functions (see footnote below).
14664 This will in most circumstances make the generated ISR code more efficient
14665 since it will not have to save registers on the stack.
14668 \begin_layout Standard
14673 attribute will have no effect on the generated code for a
14677 function (but may occasionally be useful anyway
14681 \begin_layout Standard
14682 possible exception: if a function is called ONLY from 'interrupt' functions
14683 using a particular bank, it can be declared with the same 'using' attribute
14684 as the calling 'interrupt' functions.
14685 For instance, if you have several ISRs using bank one, and all of them
14686 call memcpy(), it might make sense to create a specialized version of memcpy()
14687 'using 1', since this would prevent the ISR from having to save bank zero
14688 to the stack on entry and switch to bank zero before calling the function
14697 (pending: Note, nowadays the
14701 attribute has an effect on
14705 the generated code for a
14716 \begin_layout Standard
14721 function using a non-zero bank will assume that it can trash that register
14722 bank, and will not save it.
14723 Since high-priority interrupts
14724 \begin_inset LatexCommand \index{interrupts}
14729 \begin_inset LatexCommand \index{interrupt priority}
14733 can interrupt low-priority ones on the 8051 and friends, this means that
14734 if a high-priority ISR
14738 a particular bank occurs while processing a low-priority ISR
14742 the same bank, terrible and bad things can happen.
14743 To prevent this, no single register bank should be
14747 by both a high priority and a low priority ISR.
14748 This is probably most easily done by having all high priority ISRs use
14749 one bank and all low priority ISRs use another.
14750 If you have an ISR which can change priority at runtime, you're on your
14751 own: I suggest using the default bank zero and taking the small performance
14755 \begin_layout Standard
14756 It is most efficient if your ISR calls no other functions.
14757 If your ISR must call other functions, it is most efficient if those functions
14758 use the same bank as the ISR (see note 1 below); the next best is if the
14759 called functions use bank zero.
14760 It is very inefficient to call a function using a different, non-zero bank
14763 \begin_inset VSpace bigskip
14769 \begin_layout Section
14771 \begin_inset LatexCommand \label{sub:Startup-Code}
14776 \begin_inset LatexCommand \index{Startup code}
14783 \begin_layout Subsection
14784 MCS51/DS390 Startup Code
14787 \begin_layout Standard
14788 The compiler triggers the linker to link certain initialization modules
14789 from the runtime library
14790 \begin_inset LatexCommand \index{Runtime library}
14794 called crt<something>.
14795 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14796 GSINIT5) is not linked unless the --xstack option is used.
14797 These modules are highly entangled by the use of special segments/areas,
14798 but a common layout is shown below:
14801 \begin_layout Verse
14809 \begin_layout Verse
14833 ljmp __sdcc_gsinit_startup
14836 \begin_layout Verse
14844 \begin_layout Verse
14856 .area GSINIT0 (CODE)
14858 __sdcc_gsinit_startup::
14868 mov sp,#__start__stack - 1
14871 \begin_layout Verse
14879 \begin_layout Verse
14891 .area GSINIT1 (CODE)
14893 __sdcc_init_xstack::
14895 ; Need to initialize in GSINIT1 in
14896 case the user's __sdcc_external_startup uses the xstack.
14906 mov __XPAGE,#(__start__x
14917 mov _spx,#__start__xstack
14920 \begin_layout Verse
14928 \begin_layout Verse
14940 .area GSINIT2 (CODE)
14950 lcall __sdcc_external_startup
14970 jz __sdcc_init_data
14981 __sdcc_program_startup
14986 \begin_layout Verse
14994 \begin_layout Verse
15006 .area GSINIT3 (CODE)
15059 mov r2,#((l_XINIT+255) >> 8)
15090 __XPAGE,#(s_XISEG >> 8)
15092 00001$:\InsetSpace ~
15156 00002$:\InsetSpace ~
15183 \begin_layout Verse
15191 \begin_layout Verse
15203 .area GSINIT4 (CODE)
15205 __mcs51_genRAMCLEAR::
15227 00004$:\InsetSpace ~
15241 ; _mcs51_genRAMCLEAR() end
15244 \begin_layout Verse
15252 \begin_layout Verse
15264 .area GSINIT4 (CODE)
15266 __mcs51_genXRAMCLEAR::
15317 mov __XPAGE,#(s_PSEG >> 8)
15329 00005$:\InsetSpace ~
15383 orl a,#(l_XSEG >> 8)
15426 00007$:\InsetSpace ~
15463 \begin_layout Verse
15471 \begin_layout Verse
15483 .area GSINIT5 (CODE)
15485 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15488 ; and __mcs51_genRAMCLEAR modifies _spx.
15498 mov __XPAGE,#(__start__x
15509 mov _spx,#__start__xstack
15512 \begin_layout Verse
15517 (application modules)
15520 \begin_layout Verse
15532 .area GSINIT (CODE)
15535 \begin_layout Verse
15543 \begin_layout Verse
15555 .area GSFINAL (CODE)
15565 ljmp __sdcc_program_startup
15567 ;---------------------------------
15568 -----------------------
15572 ;--------------------------------------------------
15595 __sdcc_program_startup:
15608 return from main will lock up
15621 \begin_layout Standard
15622 One of these modules (crtstart.asm) contains a call to the C routine
15624 _sdcc_external_startup()
15625 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15634 at the start of the CODE area.
15635 This routine is also in the runtime library
15636 \begin_inset LatexCommand \index{Runtime library}
15640 and returns 0 by default.
15641 If this routine returns a non-zero value, the static & global variable
15642 initialization will be skipped and the function main will be invoked.
15643 Otherwise static & global variables will be initialized before the function
15647 _sdcc_external_startup()
15649 routine to your program to override the default if you need to setup hardware
15650 or perform some other critical operation prior to static & global variable
15652 \begin_inset LatexCommand \index{Variable initialization}
15657 On some mcs51 variants xdata
15658 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15662 memory has to be explicitly enabled before it can be accessed or if the
15664 \begin_inset LatexCommand \index{watchdog}
15668 needs to be disabled, this is the place to do it.
15669 The startup code clears all internal data memory, 256 bytes by default,
15670 but from 0 to n-1 if
15676 \begin_layout Standard
15686 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15693 (recommended for Chipcon CC1010).
15696 \begin_layout Standard
15697 See also the compiler options
15703 \begin_layout Standard
15719 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15729 \begin_layout Standard
15741 \begin_inset LatexCommand \index{-\/-main-return}
15746 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15750 about MCS51-variants.
15751 \begin_inset VSpace bigskip
15757 \begin_layout Subsection
15761 \begin_layout Standard
15763 \begin_inset LatexCommand \index{HC08}
15767 startup code follows the same scheme as the MCS51 startup code.
15768 \begin_inset VSpace bigskip
15774 \begin_layout Subsection
15778 \begin_layout Standard
15780 \begin_inset LatexCommand \index{Z80}
15784 the startup code is inserted by linking with crt0.o which is generated from
15785 sdcc/device/lib/z80/crt0.s.
15786 If you need a different startup code you can use the compiler option
15795 \begin_layout Standard
15810 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15814 and provide your own crt0.o.
15816 \begin_inset VSpace bigskip
15822 \begin_layout Section
15823 Inline Assembler Code
15824 \begin_inset LatexCommand \index{Assembler routines}
15831 \begin_layout Subsection
15832 A Step by Step Introduction
15833 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15840 \begin_layout Standard
15841 Starting from a small snippet of c-code this example shows for the MCS51
15842 how to use inline assembly, access variables, a function parameter and
15843 an array in xdata memory.
15844 The example uses an MCS51 here but is easily adapted for other architectures.
15845 This is a buffer routine which should be optimized:
15848 \begin_layout Verse
15852 unsigned char __far
15853 \begin_inset LatexCommand \index{far (storage class)}
15858 \begin_inset LatexCommand \index{\_\_far (storage class)}
15863 \begin_inset LatexCommand \index{at}
15868 \begin_inset LatexCommand \index{\_\_at}
15872 (0x7f00) buf[0x100];
15873 \begin_inset LatexCommand \index{Aligned array}
15879 unsigned char head, tail;\InsetSpace ~
15897 \begin_inset LatexCommand \index{interrupt}
15949 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15961 void to_buffer( unsigned char c )
15969 if( head != (unsigned char)(tail-1)
15976 \begin_inset LatexCommand \index{promotion to signed int}
15981 \begin_inset LatexCommand \index{type promotion}
15986 \begin_inset Marginal
15989 \begin_layout Standard
16008 buf[ head++ ] = c;\InsetSpace ~
16024 /* access to a 256 byte aligned array */
16029 \begin_layout Standard
16030 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16031 then a corresponding buffer.asm file is generated.
16032 We define a new function
16036 in file buffer.c in which we cut and paste the generated code, removing
16037 unwanted comments and some ':'.
16039 \begin_inset Quotes sld
16047 \begin_inset Quotes srd
16051 \begin_inset Quotes sld
16059 \begin_inset Quotes srd
16066 \begin_layout Standard
16067 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16068 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16070 The latter is also used in the library functions.
16075 to the beginning and the end of the function body:
16078 \begin_layout Verse
16082 /* With a cut and paste from the .asm file, we have something to start with.
16088 function is not yet OK! (registers aren't saved) */
16090 void to_buffer_asm(
16100 \begin_inset LatexCommand \index{\_asm}
16105 \begin_inset LatexCommand \index{\_\_asm}
16119 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16125 \begin_inset LatexCommand \index{promotion to signed int}
16130 \begin_inset LatexCommand \index{type promotion}
16183 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16184 \begin_inset LatexCommand \index{Aligned array}
16250 \begin_inset LatexCommand \index{\_endasm}
16255 \begin_inset LatexCommand \index{\_\_endasm}
16264 \begin_layout Standard
16265 The new file buffer.c should compile with only one warning about the unreferenced
16266 function argument 'c'.
16267 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16268 (1) and finally have:
16271 \begin_layout Verse
16275 unsigned char __far __at(0x7f00) buf[0x100];
16277 unsigned char head, tail;
16288 void to_buffer( unsigned char c )
16297 head != (unsigned char)(tail-1) )
16326 c; // to avoid warning: unreferenced function argument
16333 \begin_inset LatexCommand \index{\_asm}
16338 \begin_inset LatexCommand \index{\_\_asm}
16352 ; save used registers here.
16363 ; If we were still using r2,r3 we would have to push them here.
16366 ; if( head != (unsigned char)(tail-1) )
16410 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16446 a,dpl \InsetSpace ~
16453 ; dpl holds lower byte of function argument
16465 dpl,_head \InsetSpace ~
16468 ; buf is 0x100 byte aligned so head can be used directly
16511 ; we could do an ANL _head,#0x0f here to use a
16512 smaller buffer (see above)
16524 ; restore used registers here
16531 \begin_inset LatexCommand \index{\_endasm}
16536 \begin_inset LatexCommand \index{\_\_endasm}
16547 \begin_layout Standard
16548 The inline assembler code can contain any valid code understood by the assembler
16549 , this includes any assembler directives and comment lines.
16550 The assembler does not like some characters like ':' or ''' in comments.
16551 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16552 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16557 \begin_inset LatexCommand \index{Assembler documentation}
16562 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16570 \begin_layout Standard
16571 The compiler does not do any validation of the code within the
16574 \begin_inset LatexCommand \index{\_asm}
16579 \begin_inset LatexCommand \index{\_\_asm}
16587 \begin_inset LatexCommand \index{\_endasm}
16592 \begin_inset LatexCommand \index{\_\_endasm}
16601 Specifically it will not know which registers are used and thus register
16603 \begin_inset LatexCommand \index{push/pop}
16607 has to be done manually.
16611 \begin_layout Standard
16612 It is recommended that each assembly instruction (including labels) be placed
16613 in a separate line (as the example shows).
16618 \begin_layout Standard
16630 \begin_inset LatexCommand \index{-\/-peep-asm}
16636 command line option is used, the inline assembler code will be passed through
16637 the peephole optimizer
16638 \begin_inset LatexCommand \index{Peephole optimizer}
16643 There are only a few (if any) cases where this option makes sense, it might
16644 cause some unexpected changes in the inline assembler code.
16645 Please go through the peephole optimizer rules defined in file
16649 before using this option.
16652 \begin_layout Subsection
16654 \begin_inset LatexCommand \label{sub:Naked-Functions}
16659 \begin_inset LatexCommand \index{Naked functions}
16666 \begin_layout Standard
16667 A special keyword may be associated with a function declaring it as
16670 \begin_inset LatexCommand \index{\_naked}
16675 \begin_inset LatexCommand \index{\_\_naked}
16686 function modifier attribute prevents the compiler from generating prologue
16687 \begin_inset LatexCommand \index{function prologue}
16692 \begin_inset LatexCommand \index{function epilogue}
16696 code for that function.
16697 This means that the user is entirely responsible for such things as saving
16698 any registers that may need to be preserved, selecting the proper register
16699 bank, generating the
16703 instruction at the end, etc.
16704 Practically, this means that the contents of the function must be written
16705 in inline assembler.
16706 This is particularly useful for interrupt functions, which can have a large
16707 (and often unnecessary) prologue/epilogue.
16708 For example, compare the code generated by these two functions:
16711 \begin_layout Verse
16715 \begin_inset LatexCommand \index{volatile}
16719 data unsigned char counter;
16723 void simpleInterrupt(void) __interrupt
16724 \begin_inset LatexCommand \index{interrupt}
16729 \begin_inset LatexCommand \index{\_\_interrupt}
16747 void nakedInterrupt(void) __interrupt (2) __naked
16756 \begin_inset LatexCommand \index{\_asm}
16761 \begin_inset LatexCommand \index{\_\_asm}
16778 _counter ; does not change flags, no need to save psw
16791 include ret or reti in _naked function.
16798 \begin_inset LatexCommand \index{\_endasm}
16803 \begin_inset LatexCommand \index{\_\_endasm}
16812 \begin_layout Standard
16813 For an 8051 target, the generated simpleInterrupt looks like:
16816 \begin_layout Verse
16823 example, recent versions of SDCC generate
16829 code for simpleInterrupt() and nakedInterrupt()!
16970 \begin_layout Standard
16971 whereas nakedInterrupt looks like:
16974 \begin_layout Verse
16987 _counter ; does not change flags, no need to save psw
17006 MUST explicitly include ret or reti in _naked function
17009 \begin_layout Standard
17010 The related directive #pragma exclude
17011 \begin_inset LatexCommand \index{\#pragma exclude}
17015 allows a more fine grained control over pushing & popping
17016 \begin_inset LatexCommand \index{push/pop}
17023 \begin_layout Standard
17024 While there is nothing preventing you from writing C code inside a
17028 function, there are many ways to shoot yourself in the foot doing this,
17029 and it is recommended that you stick to inline assembler.
17032 \begin_layout Subsection
17033 Use of Labels within Inline Assembler
17036 \begin_layout Standard
17037 SDCC allows the use of in-line assembler with a few restrictions regarding
17039 In older versions of the compiler all labels defined within inline assembler
17040 code had to be of the form
17044 where nnnnn is a number less than 100 (which implies a limit of utmost
17045 100 inline assembler labels
17056 \begin_layout Verse
17060 \begin_inset LatexCommand \index{\_asm}
17065 \begin_inset LatexCommand \index{\_\_asm}
17095 \begin_inset LatexCommand \index{\_endasm}
17100 \begin_inset LatexCommand \index{\_\_endasm}
17107 \begin_layout Standard
17108 Inline assembler code cannot reference any C-labels, however it can reference
17110 \begin_inset LatexCommand \index{Labels}
17114 defined by the inline assembler, e.g.:
17117 \begin_layout Verse
17140 ; some assembler code
17161 /* some more c code */
17163 clabel:\InsetSpace ~
17165 /* inline assembler cannot reference this
17178 $0003: ;label (can be referenced by inline assembler only)
17186 \begin_inset LatexCommand \index{\_endasm}
17191 \begin_inset LatexCommand \index{\_\_endasm}
17201 /* some more c code */
17206 \begin_layout Standard
17207 In other words inline assembly code can access labels defined in inline
17208 assembly within the scope of the function.
17209 The same goes the other way, i.e.
17210 labels defines in inline assembly can not be accessed by C statements.
17213 \begin_layout Section
17214 Interfacing with Assembler Code
17215 \begin_inset LatexCommand \index{Assembler routines}
17222 \begin_layout Subsection
17223 Global Registers used for Parameter Passing
17224 \begin_inset LatexCommand \index{Parameter passing}
17231 \begin_layout Standard
17232 The compiler always uses the global registers
17235 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17240 \begin_inset LatexCommand \index{DPTR}
17245 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17254 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17260 to pass the first parameter to a function, and also to pass the return
17262 \begin_inset LatexCommand \index{return value}
17266 of function; according to the following scheme: one byte return value in
17271 , two byte value in
17280 three byte values (generic pointers) in
17292 , and four byte values in
17310 \begin_inset LatexCommand \index{generic pointer}
17314 contain type of accessed memory in
17335 \begin_inset Note Note
17338 \begin_layout Standard
17339 This might not be the case of certain memory models (medium???)
17347 \begin_layout Standard
17348 The second parameter onwards is either allocated on the stack (for reentrant
17353 \begin_layout Standard
17362 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17366 \begin_layout Subsection
17370 \begin_layout Standard
17371 Unless the called function is declared as
17376 \begin_inset LatexCommand \index{naked}
17384 \begin_layout Standard
17394 \begin_inset LatexCommand \index{-\/-callee-saves}
17402 \begin_layout Standard
17411 -all-callee-saves command line option or the corresponding callee_saves
17412 pragma are used, the caller will save the registers (
17416 ) around the call, so the called function can destroy they content freely.
17419 \begin_layout Standard
17420 If the called function is not declared as
17424 , the caller will swap register banks around the call, if caller and callee
17425 use different register banks (having them defined by the
17433 \begin_layout Standard
17434 The called function can also use
17450 observing that they are used for parameter/return value passing.
17453 \begin_layout Subsection
17454 Assembler Routine (non-reentrant)
17457 \begin_layout Standard
17458 In the following example
17459 \begin_inset LatexCommand \index{reentrant}
17464 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17468 the function c_func calls an assembler routine asm_func, which takes two
17470 \begin_inset LatexCommand \index{function parameter}
17477 \begin_layout Verse
17480 extern int asm_func(unsigned char, unsigned char);
17484 int c_func (unsigned char
17485 i, unsigned char j)
17493 return asm_func(i,j);
17507 return c_func(10,9);
17512 \begin_layout Standard
17513 The corresponding assembler function is:
17516 \begin_layout Verse
17519 .globl _asm_func_PARM_2
17621 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17638 \begin_layout Standard
17639 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17640 the parameter number starting from 1, and counting from the left.
17641 The first parameter is passed in
17657 according to the description above.
17658 The variable name for the second parameter will be _<function_name>_PARM_2.
17663 ble the assembler routine with the following command:
17670 asx8051 -losg asmfunc.asm
17677 Then compile and link the assembler routine to the C source file with the
17685 sdcc cfunc.c asmfunc.rel
17688 \begin_layout Subsection
17689 Assembler Routine (reentrant)
17692 \begin_layout Standard
17694 \begin_inset LatexCommand \index{reentrant}
17699 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17703 the second parameter
17704 \begin_inset LatexCommand \index{function parameter}
17708 onwards will be passed on the stack, the parameters are pushed from right
17710 before the call the second leftmost parameter will be on the top of the
17711 stack (the leftmost parameter is passed in registers).
17712 Here is an example:
17715 \begin_layout Verse
17718 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17723 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
17732 return asm_func(i,j,k);
17746 return c_func(10,9,8);
17751 \begin_layout Standard
17752 The corresponding (unoptimized) assembler routine is:
17755 \begin_layout Verse
17775 _bp,sp\InsetSpace ~
17781 ;stack contains: _bp, return
17782 address, second parameter, third parameter
17806 a,#0xfd\InsetSpace ~
17812 pointer to the second parameter
17836 a,#0xfc\InsetSpace ~
17842 to the rightmost parameter
17883 result (= sum of all three parameters)
17898 ;return value goes into dptr
17932 \begin_layout Standard
17933 The compiling and linking procedure remains the same, however note the extra
17934 entry & exit linkage required for the assembler code, _bp is the stack
17935 frame pointer and is used to compute the offset into the stack for parameters
17936 and local variables.
17937 \begin_inset VSpace bigskip
17943 \begin_layout Section
17945 \begin_inset LatexCommand \index{int (16 bit)}
17950 \begin_inset LatexCommand \index{long (32 bit)}
17957 \begin_layout Standard
17958 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17959 multiplication and modulus operations are implemented by support routines.
17960 These support routines are all developed in ANSI-C to facilitate porting
17961 to other MCUs, although some model specific assembler optimizations are
17963 The following files contain the described routines, all of them can be
17964 found in <installdir>/share/sdcc/lib.
17969 \begin_layout Standard
17971 \begin_inset Tabular
17972 <lyxtabular version="3" rows="11" columns="2">
17974 <column alignment="left" valignment="top" leftline="true" width="0">
17975 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17976 <row topline="true" bottomline="true">
17977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17980 \begin_layout Standard
17988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17991 \begin_layout Standard
18000 <row topline="true">
18001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18004 \begin_layout Standard
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18013 \begin_layout Standard
18014 16 bit multiplication
18020 <row topline="true">
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18024 \begin_layout Standard
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18033 \begin_layout Standard
18034 signed 16 bit division (calls _divuint)
18040 <row topline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18044 \begin_layout Standard
18050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18053 \begin_layout Standard
18054 unsigned 16 bit division
18060 <row topline="true">
18061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18064 \begin_layout Standard
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 \begin_layout Standard
18074 signed 16 bit modulus (calls _moduint)
18080 <row topline="true">
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18084 \begin_layout Standard
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18093 \begin_layout Standard
18094 unsigned 16 bit modulus
18100 <row topline="true">
18101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18104 \begin_layout Standard
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18113 \begin_layout Standard
18114 32 bit multiplication
18120 <row topline="true">
18121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18124 \begin_layout Standard
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18133 \begin_layout Standard
18134 signed 32 division (calls _divulong)
18140 <row topline="true">
18141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18144 \begin_layout Standard
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18153 \begin_layout Standard
18154 unsigned 32 division
18160 <row topline="true">
18161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18164 \begin_layout Standard
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18173 \begin_layout Standard
18174 signed 32 bit modulus (calls _modulong)
18180 <row topline="true" bottomline="true">
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18184 \begin_layout Standard
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18193 \begin_layout Standard
18194 unsigned 32 bit modulus
18209 \begin_layout Standard
18210 Since they are compiled as
18215 \begin_inset LatexCommand \index{reentrant}
18220 \begin_inset LatexCommand \index{interrupt}
18224 service routines should not do any of the above operations.
18225 If this is unavoidable then the above routines will need to be compiled
18232 \begin_layout Standard
18242 \begin_inset LatexCommand \index{-\/-stack-auto}
18248 option, after which the source program will have to be compiled with
18254 \begin_layout Standard
18264 \begin_inset LatexCommand \index{-\/-int-long-reent}
18271 Notice that you don't have to call these routines directly.
18272 The compiler will use them automatically every time an integer operation
18276 \begin_layout Section
18277 Floating Point Support
18278 \begin_inset LatexCommand \index{Floating point support}
18285 \begin_layout Standard
18286 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18287 The floating point support routines are derived from gcc's floatlib.c and
18288 consist of the following routines:
18293 \begin_layout Standard
18297 \begin_inset Tabular
18298 <lyxtabular version="3" rows="17" columns="2">
18300 <column alignment="left" valignment="top" leftline="true" width="0">
18301 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18302 <row topline="true" bottomline="true">
18303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18306 \begin_layout Standard
18321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18324 \begin_layout Standard
18331 <row topline="true">
18332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18335 \begin_layout Standard
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18353 \begin_layout Standard
18363 add floating point numbers
18369 <row topline="true">
18370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18373 \begin_layout Standard
18388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18391 \begin_layout Standard
18401 subtract floating point numbers
18407 <row topline="true">
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18411 \begin_layout Standard
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18429 \begin_layout Standard
18439 divide floating point numbers
18445 <row topline="true">
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18449 \begin_layout Standard
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18467 \begin_layout Standard
18477 multiply floating point numbers
18483 <row topline="true">
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18487 \begin_layout Standard
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18505 \begin_layout Standard
18515 convert floating point to unsigned char
18521 <row topline="true">
18522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18525 \begin_layout Standard
18540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18543 \begin_layout Standard
18553 convert floating point to signed char
18559 <row topline="true">
18560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18563 \begin_layout Standard
18578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18581 \begin_layout Standard
18591 convert floating point to unsigned int
18597 <row topline="true">
18598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18601 \begin_layout Standard
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18619 \begin_layout Standard
18629 convert floating point to signed int
18635 <row topline="true">
18636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18639 \begin_layout Standard
18662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18665 \begin_layout Standard
18675 convert floating point to unsigned long
18681 <row topline="true">
18682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18685 \begin_layout Standard
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18703 \begin_layout Standard
18713 convert floating point to signed long
18719 <row topline="true">
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18723 \begin_layout Standard
18738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18741 \begin_layout Standard
18751 convert unsigned char to floating point
18757 <row topline="true">
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18761 \begin_layout Standard
18776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18779 \begin_layout Standard
18789 convert char to floating point number
18795 <row topline="true">
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18799 \begin_layout Standard
18814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18817 \begin_layout Standard
18827 convert unsigned int to floating point
18833 <row topline="true">
18834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18837 \begin_layout Standard
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18855 \begin_layout Standard
18865 convert int to floating point numbers
18871 <row topline="true">
18872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18875 \begin_layout Standard
18890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18893 \begin_layout Standard
18903 convert unsigned long to floating point number
18909 <row topline="true" bottomline="true">
18910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18913 \begin_layout Standard
18928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18931 \begin_layout Standard
18941 convert long to floating point number
18956 \begin_layout Standard
18957 These support routines are developed in ANSI-C so there is room for space
18958 and speed improvement
18962 \begin_layout Standard
18963 These floating point routines (
18967 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18974 Note if all these routines are used simultaneously the data space might
18976 For serious floating point usage the large model might be needed.
18977 Also notice that you don't have to call this routines directly.
18978 The compiler will use them automatically every time a floating point operation
18980 \begin_inset VSpace bigskip
18986 \begin_layout Section
18988 \begin_inset LatexCommand \index{Libraries}
18995 \begin_layout Standard
18998 <pending: this is messy and incomplete - a little more information is in
18999 sdcc/doc/libdoc.txt
19004 \begin_layout Subsection
19005 Compiler support routines (_gptrget, _mulint etc.)
19008 \begin_layout Subsection
19009 Stdclib functions (puts, printf, strcat etc.)
19012 \begin_layout Subsubsection
19016 \begin_layout Paragraph
19017 getchar(), putchar()
19020 \begin_layout Standard
19021 \begin_inset LatexCommand \index{<stdio.h>}
19025 As usual on embedded systems you have to provide your own
19028 \begin_inset LatexCommand \index{getchar()}
19037 \begin_inset LatexCommand \index{putchar()}
19044 SDCC does not know whether the system connects to a serial line with or
19045 without handshake, LCD, keyboard or other device.
19059 You'll find examples for serial routines f.e.
19060 in sdcc/device/lib.
19061 For the mcs51 this minimalistic polling
19065 routine might be a start:
19068 \begin_layout Verse
19071 void putchar (char c) {
19077 while (!TI)\InsetSpace ~
19080 /* assumes UART is initialized */
19108 \begin_layout Paragraph
19112 \begin_layout Standard
19116 \begin_inset LatexCommand \index{printf()}
19126 does not support float (except on ds390).
19127 To enable this recompile it with the option
19133 \begin_layout Standard
19143 \begin_inset LatexCommand \index{USE\_FLOATS}
19149 on the command line.
19156 \begin_layout Standard
19166 \begin_inset LatexCommand \index{-\/-model-large}
19172 for the mcs51 port, since this uses a lot of memory.
19175 \begin_layout Standard
19176 If you're short on code memory you might want to use
19179 \begin_inset LatexCommand \index{printf\_small()}
19194 For the mcs51 there additionally are assembly versions
19197 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19203 (subset of printf using less than 270 bytes) and
19206 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19215 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19221 (floating-point aware version of printf_fast) which should fit the requirements
19222 of many embedded systems (printf_fast() can be customized by unsetting
19227 support long variables and field widths).
19228 Be sure to use only one of these printf options within a project.
19233 \begin_layout Standard
19234 Feature matrix of different
19241 \begin_layout Standard
19242 \begin_inset Tabular
19243 <lyxtabular version="3" rows="14" columns="7">
19244 <features islongtable="true">
19245 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19246 <column alignment="center" valignment="top" leftline="true" width="0">
19247 <column alignment="center" valignment="top" leftline="true" width="12col%">
19248 <column alignment="center" valignment="top" leftline="true" width="10col%">
19249 <column alignment="center" valignment="top" leftline="true" width="0">
19250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19251 <column alignment="center" valignment="top" rightline="true" width="0">
19252 <row topline="true" bottomline="true" endhead="true">
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19256 \begin_layout Standard
19265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19268 \begin_layout Standard
19270 \begin_inset LatexCommand \index{printf}
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19282 \begin_layout Standard
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19293 \begin_layout Standard
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19302 \begin_layout Standard
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19311 \begin_layout Standard
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19320 \begin_layout Standard
19327 <row topline="true" endhead="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19331 \begin_layout Standard
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19340 \begin_layout Standard
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19351 \begin_layout Standard
19359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19362 \begin_layout Standard
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19373 \begin_layout Standard
19381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19384 \begin_layout Standard
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19395 \begin_layout Standard
19404 <row topline="true" endhead="true">
19405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19408 \begin_layout Standard
19409 \begin_inset Quotes sld
19413 \begin_inset Quotes srd
19419 \begin_layout Standard
19425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19428 \begin_layout Standard
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19437 \begin_layout Standard
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19446 \begin_layout Standard
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19455 \begin_layout Standard
19461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19464 \begin_layout Standard
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19473 \begin_layout Standard
19480 <row topline="true" endhead="true">
19481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19484 \begin_layout Standard
19488 \begin_layout Standard
19494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19497 \begin_layout Standard
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19506 \begin_layout Standard
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19515 \begin_layout Standard
19516 0.45k / 0.47k (+ _ltoa)
19521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19524 \begin_layout Standard
19530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19533 \begin_layout Standard
19539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19542 \begin_layout Standard
19549 <row topline="true">
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19553 \begin_layout Standard
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19562 \begin_layout Standard
19572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19575 \begin_layout Standard
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19625 \begin_layout Standard
19664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19667 \begin_layout Standard
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19676 \begin_layout Standard
19682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19685 \begin_layout Standard
19692 <row topline="true">
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19696 \begin_layout Standard
19697 long (32 bit) support
19702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19705 \begin_layout Standard
19711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19714 \begin_layout Standard
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19723 \begin_layout Standard
19729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19732 \begin_layout Standard
19738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19741 \begin_layout Standard
19756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19759 \begin_layout Standard
19766 <row topline="true">
19767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19770 \begin_layout Standard
19771 byte arguments on stack
19776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19779 \begin_layout Standard
19785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19788 \begin_layout Standard
19794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19797 \begin_layout Standard
19803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19806 \begin_layout Standard
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19815 \begin_layout Standard
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19824 \begin_layout Standard
19831 <row topline="true">
19832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19835 \begin_layout Standard
19837 \begin_inset LatexCommand \index{Floating point support}
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19849 \begin_layout Standard
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19858 \begin_layout Standard
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19867 \begin_layout Standard
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19876 \begin_layout Standard
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19885 \begin_layout Standard
19890 \begin_layout Standard
19891 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19904 \begin_layout Standard
19911 <row topline="true">
19912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19915 \begin_layout Standard
19916 float formats %e %g
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19924 \begin_layout Standard
19930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19933 \begin_layout Standard
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19942 \begin_layout Standard
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_layout Standard
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19960 \begin_layout Standard
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19969 \begin_layout Standard
19976 <row topline="true" bottomline="true">
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19980 \begin_layout Standard
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_layout Standard
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19998 \begin_layout Standard
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_layout Standard
20013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20016 \begin_layout Standard
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20025 \begin_layout Standard
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20034 \begin_layout Standard
20041 <row bottomline="true">
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20045 \begin_layout Standard
20050 \begin_layout Standard
20051 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20055 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20063 \begin_layout Standard
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20072 \begin_layout Standard
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20081 \begin_layout Standard
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20090 \begin_layout Standard
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20099 \begin_layout Standard
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20108 \begin_layout Standard
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20117 \begin_layout Standard
20124 <row bottomline="true">
20125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20128 \begin_layout Standard
20133 \begin_layout Standard
20134 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20143 \begin_layout Standard
20149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20152 \begin_layout Standard
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20161 \begin_layout Standard
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_layout Standard
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20179 \begin_layout Standard
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20188 \begin_layout Standard
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20197 \begin_layout Standard
20202 \begin_layout Standard
20203 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20214 <row bottomline="true">
20215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20218 \begin_layout Standard
20223 \begin_layout Standard
20224 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20233 \begin_layout Standard
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20242 \begin_layout Standard
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_layout Standard
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20260 \begin_layout Standard
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20269 \begin_layout Standard
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20278 \begin_layout Standard
20284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20287 \begin_layout Standard
20294 <row bottomline="true">
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20298 \begin_layout Standard
20303 \begin_layout Standard
20304 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20313 \begin_layout Standard
20319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20322 \begin_layout Standard
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 \begin_layout Standard
20337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20340 \begin_layout Standard
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20349 \begin_layout Standard
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20358 \begin_layout Standard
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20367 \begin_layout Standard
20381 \begin_layout Subsubsection
20383 \begin_inset LatexCommand \index{malloc.h}
20390 \begin_layout Standard
20391 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20392 using dynamic memory allocation
20393 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20398 \begin_inset LatexCommand \index{heap (malloc)}
20402 space of 1024 bytes is provided for malloc to allocate memory from.
20403 If you need a different heap size you need to recompile _heap.c with the
20404 required size defined in HEAP_SIZE.
20405 It is recommended to make a copy of this file into your project directory
20406 and compile it there with:
20409 \begin_layout Verse
20412 sdcc -c _heap.c -D HEAD_SIZE=2048
20415 \begin_layout Standard
20416 And then link it with:
20419 \begin_layout Verse
20422 sdcc main.rel _heap.rel
20425 \begin_layout Subsection
20426 Math functions (sinf, powf, sqrtf etc.)
20429 \begin_layout Subsubsection
20433 \begin_layout Standard
20434 See definitions in file <math.h>.
20437 \begin_layout Subsection
20441 \begin_layout Standard
20443 \begin_inset LatexCommand \index{Libraries}
20447 included in SDCC should have a license at least as liberal as the GNU Lesser
20448 General Public License
20449 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20460 \begin_layout Standard
20461 \begin_inset Note Note
20464 \begin_layout Standard
20465 license statements for the libraries are missing.
20466 sdcc/device/lib/ser_ir.c
20469 \begin_layout Standard
20471 come with a GPL (as opposed to LGPL) License - this will not be liberal
20472 enough for many embedded programmers.
20480 \begin_layout Standard
20481 If you have ported some library or want to share experience about some code
20483 falls into any of these categories Busses (I
20484 \begin_inset Formula $^{\textrm{2}}$
20487 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20488 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20489 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20490 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20495 would certainly like to hear about it.
20498 \begin_layout Standard
20499 Programmers coding for embedded systems are not especially famous for being
20500 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20501 e these references are very valuable.
20502 Let's help to create a climate where information is shared.
20503 \begin_inset VSpace bigskip
20509 \begin_layout Section
20513 \begin_layout Subsection
20514 MCS51 Memory Models
20515 \begin_inset LatexCommand \index{Memory model}
20520 \begin_inset LatexCommand \index{MCS51 memory model}
20527 \begin_layout Subsubsection
20528 Small, Medium and Large
20531 \begin_layout Standard
20532 SDCC allows three memory models for MCS51 code,
20541 Modules compiled with different memory models should
20545 be combined together or the results would be unpredictable.
20546 The library routines supplied with the compiler are compiled as small,
20548 The compiled library modules are contained in separate directories as small,
20549 medium and large so that you can link to the appropriate set.
20552 \begin_layout Standard
20553 When the medium or large model is used all variables declared without a
20554 storage class will be allocated into the external ram, this includes all
20555 parameters and local variables (for non-reentrant
20556 \begin_inset LatexCommand \index{reentrant}
20561 When the small model is used variables without storage class are allocated
20562 in the internal ram.
20565 \begin_layout Standard
20566 Judicious usage of the processor specific storage classes
20567 \begin_inset LatexCommand \index{Storage class}
20571 and the 'reentrant' function type will yield much more efficient code,
20572 than using the large model.
20573 Several optimizations are disabled when the program is compiled using the
20574 large model, it is therefore recommended that the small model be used unless
20575 absolutely required.
20578 \begin_layout Subsubsection
20580 \begin_inset LatexCommand \label{sub:External-Stack}
20585 \begin_inset LatexCommand \index{stack}
20590 \begin_inset LatexCommand \index{External stack (mcs51)}
20597 \begin_layout Standard
20598 The external stack (-
20602 \begin_layout Standard
20612 \begin_inset LatexCommand \index{-\/-xstack}
20616 ) is located in pdata
20617 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20621 memory (usually at the start of the external ram segment) and uses all
20622 unused space in pdata (max.
20628 \begin_layout Standard
20637 -xstack option is used to compile the program, the parameters and local
20639 \begin_inset LatexCommand \index{local variables}
20643 of all reentrant functions are allocated in this area.
20644 This option is provided for programs with large stack space requirements.
20645 When used with the -
20649 \begin_layout Standard
20659 \begin_inset LatexCommand \index{-\/-stack-auto}
20663 option, all parameters and local variables are allocated on the external
20664 stack (note: support libraries will need to be recompiled with the same
20666 There is a predefined target in the library makefile).
20669 \begin_layout Standard
20670 The compiler outputs the higher order address byte of the external ram segment
20672 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20677 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20681 ), therefore when using the External Stack option, this port
20685 be used by the application program.
20688 \begin_layout Subsection
20690 \begin_inset LatexCommand \index{Memory model}
20695 \begin_inset LatexCommand \index{DS390 memory model}
20702 \begin_layout Standard
20703 The only model supported is Flat 24
20704 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20709 This generates code for the 24 bit contiguous addressing mode of the Dallas
20711 In this mode, up to four meg of external RAM or code space can be directly
20713 See the data sheets at www.dalsemi.com for further information on this part.
20718 that the compiler does not generate any code to place the processor into
20719 24 bitmode (although
20723 in the ds390 libraries will do that for you).
20729 \begin_inset LatexCommand \index{Tinibios (DS390)}
20733 , the boot loader or similar code must ensure that the processor is in 24
20734 bit contiguous addressing mode before calling the SDCC startup code.
20745 \begin_layout Standard
20756 option, variables will by default be placed into the XDATA segment.
20761 Segments may be placed anywhere in the 4 meg address space using the usual
20766 \begin_layout Standard
20776 Note that if any segments are located above 64K, the -r flag must be passed
20777 to the linker to generate the proper segment relocations, and the Intel
20778 HEX output format must be used.
20779 The -r flag can be passed to the linker by using the option
20783 on the SDCC command line.
20784 However, currently the linker can not handle code segments > 64k.
20787 \begin_layout Section
20789 \begin_inset LatexCommand \label{sec:Pragmas}
20794 \begin_inset LatexCommand \index{Pragmas}
20801 \begin_layout Standard
20802 Pragmas are used to turn on and/or off certain compiler options.
20803 Some of them are closely related to corresponding command-line options
20805 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20811 Pragmas should be placed before and/or after a function, placing pragmas
20812 inside a function body could have unpredictable results.
20817 following #pragma directives:
20820 \begin_layout Itemize
20826 \begin_inset LatexCommand \index{\#pragma save}
20830 - this will save most current options to the save/restore stack.
20831 See #pragma\InsetSpace ~
20835 \begin_layout Itemize
20841 \begin_inset LatexCommand \index{\#pragma restore}
20845 - will restore saved options from the last save.
20846 saves & restores can be nested.
20847 SDCC uses a save/restore stack: save pushes current options to the stack,
20848 restore pulls current options from the stack.
20849 See #pragma\InsetSpace ~
20855 \begin_layout Itemize
20861 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20866 \begin_inset LatexCommand \index{function prologue}
20870 function1[,function2[,function3...]]
20871 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20875 - The compiler by default uses a caller saves convention for register saving
20876 across function calls, however this can cause unnecessary register pushing
20878 \begin_inset LatexCommand \index{push/pop}
20882 when calling small functions from larger functions.
20883 This option can be used to switch off the register saving convention for
20884 the function names specified.
20885 The compiler will not save registers when calling these functions, extra
20886 code need to be manually inserted at the entry and exit for these functions
20887 to save and restore the registers used by these functions, this can SUBSTANTIAL
20888 LY reduce code and improve run time performance of the generated code.
20889 In the future the compiler (with inter procedural analysis) may be able
20890 to determine the appropriate scheme to use for each function call.
20895 \begin_layout Standard
20904 -callee-saves command line option is used (see page
20905 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20909 ), the function names specified in #pragma\InsetSpace ~
20911 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20915 is appended to the list of functions specified in the command line.
20918 \begin_layout Itemize
20924 \begin_inset LatexCommand \index{\#pragma exclude}
20928 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20929 of pairs of push/pop
20930 \begin_inset LatexCommand \index{push/pop}
20939 \begin_inset LatexCommand \index{interrupt}
20952 The directive should be placed immediately before the ISR function definition
20953 and it affects ALL ISR functions following it.
20954 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20955 exclude\InsetSpace ~
20957 \begin_inset LatexCommand \index{\#pragma exclude}
20962 See also the related keyword _naked
20963 \begin_inset LatexCommand \index{\_naked}
20968 \begin_inset LatexCommand \index{\_\_naked}
20975 \begin_layout Itemize
20981 \begin_inset LatexCommand \index{pedantic}
20986 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20991 \begin_inset LatexCommand \label{ite:less_pedantic}
20995 - the compiler will not warn you anymore for obvious mistakes, you'r on
20997 See also the command line option -
21001 \begin_layout Standard
21011 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21018 More specifically, the following warnings will be disabled:
21020 comparison is always [true/false] due to limited range of data type
21024 overflow in implicit constant conversion
21026 (158); [the (in)famous]
21028 conditional flow changed by optimizer: so said EVELYN the modified DOG
21032 function '[function name]' must return value
21037 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21038 level) are disabled, too, namely:
21041 \begin_inset Note Note
21044 \begin_layout Standard
21045 dunno what comes here - this warning appears to be unused altogether
21054 [left/right] shifting more than size of object changed to zero
21062 integer overflow in expression
21066 unmatched #pragma save and #pragma restore
21070 comparison of 'signed char' with 'unsigned char' requires promotion to int
21074 ISO C90 does not support flexible array members
21078 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21082 \begin_inset Note Note
21085 \begin_layout Standard
21086 appears to be always blank - what was supposed to be here?
21095 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21096 complexity [number]
21101 \begin_layout Itemize
21107 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21111 - the compiler will not warn you anymore about warning number <nnnn>.
21113 \begin_inset Note Note
21116 \begin_layout Itemize
21117 \begin_inset Quotes sld
21120 For list of warnings and corresponding codes, see err_warn.txt
21121 \begin_inset Quotes srd
21124 This list should probably be part of the manual? See Patch #1697136
21132 \begin_layout Itemize
21138 \begin_inset LatexCommand \index{\#pragma nogcse}
21142 - will stop global common subexpression elimination.
21145 \begin_layout Itemize
21151 \begin_inset LatexCommand \index{\#pragma noinduction}
21155 - will stop loop induction optimizations.
21158 \begin_layout Itemize
21164 \begin_inset LatexCommand \index{\#pragma noinvariant}
21168 - will not do loop invariant optimizations.
21169 For more details see Loop Invariants in section
21170 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21177 \begin_layout Itemize
21183 \begin_inset LatexCommand \index{\#pragma noiv}
21187 - Do not generate interrupt
21188 \begin_inset LatexCommand \index{interrupt}
21193 \begin_inset LatexCommand \index{interrupt vector table}
21197 entries for all ISR functions defined after the pragma.
21198 This is useful in cases where the interrupt vector table must be defined
21199 manually, or when there is a secondary, manually defined interrupt vector
21201 for the autovector feature of the Cypress EZ-USB FX2).
21202 More elegantly this can be achieved by obmitting the optional interrupt
21203 number after the interrupt keyword, see section
21204 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21212 \begin_layout Itemize
21218 \begin_inset LatexCommand \index{\#pragma nojtbound}
21222 - will not generate code for boundary value checking, when switch statements
21223 are turned into jump-tables (dangerous).
21224 For more details see section
21225 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21232 \begin_layout Itemize
21238 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21242 - Will not do loop reversal optimization
21245 \begin_layout Itemize
21251 \begin_inset LatexCommand \index{\#pragma nooverlay}
21255 - the compiler will not overlay the parameters and local variables of a
21259 \begin_layout Itemize
21265 \begin_inset LatexCommand \index{\#pragma stackauto}
21273 \begin_layout Standard
21283 \begin_inset LatexCommand \index{-\/-stack-auto}
21288 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21292 Parameters and Local Variables.
21295 \begin_layout Itemize
21301 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21305 - The compiler will optimize code generation towards fast code, possibly
21306 at the expense of code size.
21307 Currently this has little effect.
21310 \begin_layout Itemize
21316 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21320 - The compiler will optimize code generation towards compact code, possibly
21321 at the expense of code speed.
21322 Currently this has little effect.
21325 \begin_layout Itemize
21331 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21335 - The compiler will attempt to generate code that is both compact and fast,
21336 as long as meeting one goal is not a detriment to the other (this is the
21341 \begin_layout Itemize
21347 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21351 - Generally follow the C89 standard, but allow SDCC features that conflict
21352 with the standard (default).
21355 \begin_layout Itemize
21361 \begin_inset LatexCommand \index{\#pragma std\_c89}
21365 - Follow the C89 standard and disable SDCC features that conflict with the
21369 \begin_layout Itemize
21375 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21379 - Generally follow the C99 standard, but allow SDCC features that conflict
21380 with the standard (incomplete support).
21383 \begin_layout Itemize
21389 \begin_inset LatexCommand \index{\#pragma std\_c99}
21393 - Follow the C99 standard and disable SDCC features that conflict with the
21394 standard (incomplete support).
21397 \begin_layout Itemize
21403 \begin_inset LatexCommand \index{\#pragma codeseg}
21407 - Use this name (max.
21408 8 characters) for the code segment.
21413 \begin_layout Standard
21425 \begin_layout Itemize
21431 \begin_inset LatexCommand \index{\#pragma constseg}
21435 - Use this name (max.
21436 8 characters) for the const segment.
21441 \begin_layout Standard
21453 \begin_layout Standard
21454 The preprocessor SDCPP
21455 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21459 supports the following #pragma directives:
21462 \begin_layout Itemize
21465 pedantic_parse_number
21468 \begin_inset LatexCommand \index{pedantic}
21473 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21478 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21482 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21483 properly and the macro LO_B(3) gets expanded.
21489 \begin_layout Standard
21498 -pedantic-parse-number command line option
21499 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21506 Below is an example on how to use this pragma.
21509 Note: this functionality is not in conformance with standard!
21512 \begin_layout Verse
21515 #pragma pedantic_parse_number +
21516 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21524 #define LO_B(x) ((x) & 0xff)
21528 unsigned char foo(void)
21535 unsigned char c=0xfe-LO_B(3)
21550 \begin_layout Itemize
21556 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21560 (+ | -) - switch _asm _endasm block preprocessing on / off.
21562 You use this prama to define multilines of assembly code.
21563 This will prevent the preprocessor from changing the formating required
21565 Below is an example on how to use this pragma.
21568 \begin_layout Verse
21571 #pragma preproc_asm -
21572 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21578 #define MYDELAY _asm
21583 nop ;my assembly comment...
21597 #pragma preproc_asm
21628 \begin_layout Itemize
21634 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21638 (+ | -) - Allow "naked" hash in macro definition, for example:
21642 #define DIR_LO(x) #(x & 0xff)
21647 Below is an example on how to use this pragma.
21650 \begin_layout Verse
21653 #pragma preproc_asm +
21655 #pragma sdcc_hash +
21656 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21671 mov R6_B3, #(x & 0xff)
21678 mov R7_B3, #((x >> 8) & 0xff)
21702 \begin_layout Standard
21703 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21704 ons which might cause the compiler to generate extra stack and/or data space
21705 to store compiler generated temporary variables.
21706 This usually happens in large functions.
21707 Pragma directives should be used as shown in the following example, they
21708 are used to control options and optimizations for a given function.
21712 \begin_layout Verse
21716 \begin_inset LatexCommand \index{\#pragma save}
21727 /* save the current settings */
21730 \begin_inset LatexCommand \index{\#pragma nogcse}
21739 /* turnoff global subexpression elimination */
21741 #pragma noinduction
21742 \begin_inset LatexCommand \index{\#pragma noinduction}
21746 /* turn off induction optimizations */
21769 \begin_inset LatexCommand \index{\#pragma restore}
21773 /* turn the optimizations back on */
21776 \begin_layout Standard
21777 The compiler will generate a warning message when extra space is allocated.
21778 It is strongly recommended that the save and restore pragma's be used when
21779 changing options for a function.
21788 \begin_layout Section
21789 Defines Created by the Compiler
21792 \begin_layout Standard
21793 The compiler creates the following #defines
21794 \begin_inset LatexCommand \index{\#defines}
21799 \begin_inset LatexCommand \index{Defines created by the compiler}
21808 \begin_layout Standard
21809 \begin_inset Tabular
21810 <lyxtabular version="3" rows="11" columns="2">
21812 <column alignment="left" valignment="top" leftline="true" width="3in">
21813 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21814 <row topline="true" bottomline="true">
21815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21818 \begin_layout Standard
21826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21829 \begin_layout Standard
21838 <row topline="true">
21839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21842 \begin_layout Standard
21844 \begin_inset LatexCommand \index{SDCC}
21853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21856 \begin_layout Standard
21858 Since version 2.5.6 the version number as an int (ex.
21865 <row topline="true">
21866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21869 \begin_layout Standard
21871 \begin_inset LatexCommand \index{SDCC\_mcs51}
21876 \begin_inset LatexCommand \index{SDCC\_ds390}
21881 \begin_inset LatexCommand \index{SDCC\_z80}
21890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21893 \begin_layout Standard
21894 depending on the model used (e.g.: -mds390)
21900 <row topline="true">
21901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21904 \begin_layout Standard
21906 \begin_inset LatexCommand \index{\_\_mcs51}
21911 \begin_inset LatexCommand \index{\_\_ds390}
21916 \begin_inset LatexCommand \index{\_\_hc08}
21921 \begin_inset LatexCommand \index{\_\_z80}
21930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21933 \begin_layout Standard
21934 depending on the model used (e.g.
21941 <row topline="true">
21942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21945 \begin_layout Standard
21947 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21959 \begin_layout Standard
21966 \begin_layout Standard
21983 <row topline="true">
21984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21987 \begin_layout Standard
21989 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22001 \begin_layout Standard
22008 \begin_layout Standard
22025 <row topline="true">
22026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22029 \begin_layout Standard
22031 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22043 \begin_layout Standard
22050 \begin_layout Standard
22067 <row topline="true">
22068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22071 \begin_layout Standard
22073 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22085 \begin_layout Standard
22092 \begin_layout Standard
22109 <row topline="true">
22110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22113 \begin_layout Standard
22115 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22127 \begin_layout Standard
22134 \begin_layout Standard
22151 <row topline="true">
22152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22155 \begin_layout Standard
22157 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22169 \begin_layout Standard
22180 <row topline="true" bottomline="true">
22181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22184 \begin_layout Standard
22186 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22198 \begin_layout Standard
22216 \begin_layout Chapter
22217 Notes on supported Processors
22220 \begin_layout Section
22222 \begin_inset LatexCommand \label{sub:MCS51-variants}
22227 \begin_inset LatexCommand \index{MCS51 variants}
22234 \begin_layout Standard
22235 MCS51 processors are available from many vendors and come in many different
22237 While they might differ considerably in respect to Special Function Registers
22238 the core MCS51 is usually not modified or is kept compatible.
22242 \begin_layout Subsection
22243 pdata access by SFR
22246 \begin_layout Standard
22247 With the upcome of devices with internal xdata and flash memory devices
22249 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22253 as dedicated I/O port is becoming more popular.
22254 Switching the high byte for pdata
22255 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22259 access which was formerly done by port P2 is then achieved by a Special
22261 \begin_inset LatexCommand \index{sfr}
22266 In well-established MCS51 tradition the address of this
22270 is where the chip designers decided to put it.
22271 Needless to say that they didn't agree on a common name either.
22272 So that the startup code can correctly initialize xdata variables, you
22273 should define an sfr with the name _XPAGE
22276 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22282 at the appropriate location if the default, port P2, is not used for this.
22286 \begin_layout Verse
22289 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22293 \begin_layout Verse
22296 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22301 \begin_layout Verse
22304 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22308 \begin_layout Verse
22311 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22315 \begin_layout Verse
22318 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22322 \begin_layout Standard
22323 For more exotic implementations further customizations may be needed.
22325 \begin_inset LatexCommand \ref{sub:Startup-Code}
22329 for other possibilities.
22332 \begin_layout Subsection
22333 Other Features available by SFR
22336 \begin_layout Standard
22337 Some MCS51 variants offer features like Double DPTR
22338 \begin_inset LatexCommand \index{DPTR}
22342 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22343 These are currently not used for the MCS51 port.
22344 If you absolutely need them you can fall back to inline assembly or submit
22346 \begin_inset VSpace bigskip
22352 \begin_layout Section
22356 \begin_layout Standard
22358 \begin_inset LatexCommand \index{DS80C400}
22363 \begin_inset LatexCommand \index{DS400}
22367 microcontroller has a rich set of peripherals.
22368 In its built-in ROM library it includes functions to access some of the
22369 features, among them is a TCP stack with IP4 and IP6 support.
22370 Library headers (currently in beta status) and other files are provided
22374 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22380 \begin_inset VSpace bigskip
22386 \begin_layout Section
22387 The Z80 and gbz80 port
22390 \begin_layout Standard
22391 SDCC can target both the Zilog Z80
22392 \begin_inset LatexCommand \index{Z80}
22396 and the Nintendo Gameboy's Z80-like gbz80
22397 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22402 The Z80 port is passed through the same
22405 \begin_inset LatexCommand \index{Regression test}
22412 \begin_inset LatexCommand \ref{sec:Quality-control}
22416 ) as the MCS51 and DS390 ports, so floating point support, support for long
22417 variables and bitfield support is fine.
22418 See mailing lists and forums about interrupt routines.
22421 \begin_layout Standard
22422 As always, the code is the authoritative reference - see z80/ralloc.c and
22425 \begin_inset LatexCommand \index{Z80!stack}
22429 frame is similar to that generated by the IAR Z80 compiler.
22430 IX is used as the base pointer, HL and IY are used as a temporary registers,
22431 and BC and DE are available for holding variables.
22433 \begin_inset LatexCommand \index{Z80!return value}
22437 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22439 The gbz80 port use the same set of registers for the return values, but
22440 in a different order of significance: E (one byte), DE (two bytes), or
22442 \begin_inset VSpace bigskip
22448 \begin_layout Section
22452 \begin_layout Standard
22453 The port to the Freescale/Motorola HC08
22454 \begin_inset LatexCommand \index{HC08}
22458 family has been added in October 2003, and is still undergoing some basic
22460 The code generator is complete, but the register allocation is still quite
22462 Some of the SDCC's standard C library functions have embedded non-HC08
22463 inline assembly and so are not yet usable.
22466 \begin_layout Standard
22467 The HC08 port passes the regression test suite (see section
22468 \begin_inset LatexCommand \ref{sec:Quality-control}
22473 \begin_inset VSpace bigskip
22481 \begin_layout Section
22485 \begin_layout Standard
22487 \begin_inset LatexCommand \index{PIC14}
22491 port still requires a major effort from the development community.
22492 However it can work for simple code.
22493 It passes its (smaller set of) regression tests
22494 \begin_inset LatexCommand \index{Regression test (PIC14)}
22500 sdcc/src/regression
22505 \begin_layout Subsection
22506 C code and 14bit PIC code page
22507 \begin_inset LatexCommand \index{code page (pic14)}
22512 \begin_inset LatexCommand \index{RAM bank (pic14)}
22519 \begin_layout Standard
22520 The linker organizes allocation for the code page and RAM banks.
22521 It does not have intimate knowledge of the code flow.
22522 It will put all the code section of a single asm file into a single code
22524 In order to make use of multiple code pages, separate asm files must be
22526 The compiler treats all functions of a single C file as being in the same
22527 code page unless it is non static.
22531 To get the best follow these guide lines:
22534 \begin_layout Enumerate
22535 Make local functions static, as non static functions require code page selection
22539 \begin_layout Enumerate
22540 For devices that have multiple code pages it is more efficient to use the
22541 same number of files as pages, i.e.
22542 for the 16F877 use 4 separate files and i.e.
22543 for the 16F874 use 2 separate files.
22544 This way the linker can put the code for each file into different code
22545 pages and there's less page selection overhead.
22548 \begin_layout Enumerate
22549 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22550 instruction set), use 'unsigned char' whereever possible instead of 'int'.
22553 \begin_layout Subsection
22554 Creating a device include file
22557 \begin_layout Standard
22558 For generating a device include file
22559 \begin_inset LatexCommand \index{PIC14!Header files}
22563 use the support perl script inc2h.pl kept in directory support/script.
22566 \begin_layout Subsection
22570 \begin_layout Standard
22571 For the interrupt function, use the keyword '__interrupt'
22572 \begin_inset LatexCommand \index{PIC14!interrupt}
22576 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22577 there to avoid a syntax error - it ought to be fixed).
22581 \begin_layout Verse
22584 void Intr(void) __interrupt 0
22590 T0IF = 0; /* Clear timer interrupt */
22595 \begin_layout Subsection
22596 Linking and assembling
22599 \begin_layout Standard
22600 For assembling you can use either GPUTILS'
22601 \begin_inset LatexCommand \index{gputils (pic tools)}
22605 gpasm.exe or MPLAB's mpasmwin.exe.
22606 GPUTILS is available from
22607 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22612 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22613 If you use MPLAB and an interrupt function then the linker script file
22614 vectors section will need to be enlarged to link with mplink.
22625 \begin_layout Verse
22638 sdcc -S -V -mpic14 -p16F877 $<
22652 $(PRJ).hex: $(OBJS)
22663 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22666 \begin_layout Standard
22674 \begin_layout Verse
22687 sdcc -S -V -mpic14 -p16F877 $<
22697 mpasmwin /q /o $*.asm
22701 $(PRJ).hex: $(OBJS)
22712 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22715 \begin_layout Standard
22716 Please note that indentations within a
22720 have to be done with a tabulator character.
22723 \begin_layout Subsection
22724 Command-line options
22727 \begin_layout Standard
22728 Besides the switches common to all SDCC backends, the PIC14 port accepts
22729 the following options (for an updated list see sdcc -
22733 \begin_layout Standard
22746 \labelwidthstring 00.00.0000
22751 \begin_layout Standard
22761 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22765 emit debug info in assembly output
22769 \labelwidthstring 00.00.0000
22774 \begin_layout Standard
22784 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22788 disable (slightly faulty) optimization on pCode
22792 \labelwidthstring 00.00.0000
22797 \begin_layout Standard
22807 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22811 sets the lowest address of the argument passing stack (defaults to a suitably
22812 large shared databank to reduce BANKSEL overhead)
22816 \labelwidthstring 00.00.0000
22821 \begin_layout Standard
22831 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22835 sets the size if the argument passing stack (default: 16, minimum: 4)
22838 \begin_layout Subsection
22842 \begin_layout Subsubsection
22843 error: missing definition for symbol
22844 \begin_inset Quotes sld
22848 \begin_inset Quotes srd
22854 \begin_layout Standard
22855 The PIC14 port uses library routines to provide more complex operations
22856 like multiplication, division/modulus and (generic) pointer dereferencing.
22857 In order to add these routines to your project, you must link with PIC14's
22863 For single source file projects this is done automatically, more complex
22868 to the linker's arguments.
22869 Make sure you also add an include path for the library (using the -I switch
22873 \begin_layout Subsubsection
22874 Processor mismatch in file
22875 \begin_inset Quotes sld
22879 \begin_inset Quotes srd
22885 \begin_layout Standard
22886 This warning can usually be ignored due to the very good compatibility amongst
22888 \begin_inset LatexCommand \index{PIC14}
22895 \begin_layout Standard
22896 You might also consider recompiling the library for your specific device
22897 by changing the ARCH=p16f877 (default target) entry in
22899 device/lib/pic/Makefile.in
22903 device/lib/pic/Makefile
22905 to reflect your device.
22906 This might even improve performance for smaller devices as unneccesary
22907 BANKSELs migth be removed.
22910 \begin_layout Subsection
22914 \begin_layout Subsubsection
22918 \begin_layout Standard
22919 Currently, data can only be initialized if it resides in the source file
22925 Data in other source files will silently
22933 \begin_inset Marginal
22936 \begin_layout Standard
22952 \begin_layout Section
22954 \begin_inset LatexCommand \index{PIC16}
22961 \begin_layout Standard
22963 \begin_inset LatexCommand \index{PIC16}
22967 port is the portion of SDCC that is responsible to produce code for the
22969 \begin_inset LatexCommand \index{Microchip}
22973 (TM) microcontrollers with 16 bit core.
22974 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22975 Currently supported devices are:
22978 \begin_layout Standard
22980 \begin_inset Tabular
22981 <lyxtabular version="3" rows="4" columns="6">
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" width="0">
22988 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22989 <row topline="true">
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22993 \begin_layout Standard
22999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23002 \begin_layout Standard
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23011 \begin_layout Standard
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23020 \begin_layout Standard
23026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23029 \begin_layout Standard
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23038 \begin_layout Standard
23045 <row topline="true">
23046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23049 \begin_layout Standard
23055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23058 \begin_layout Standard
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23067 \begin_layout Standard
23073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23076 \begin_layout Standard
23082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23085 \begin_layout Standard
23091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23094 \begin_layout Standard
23101 <row topline="true">
23102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23105 \begin_layout Standard
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23114 \begin_layout Standard
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23123 \begin_layout Standard
23129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23132 \begin_layout Standard
23138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23141 \begin_layout Standard
23147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23150 \begin_layout Standard
23157 <row topline="true" bottomline="true">
23158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23161 \begin_layout Standard
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23170 \begin_layout Standard
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23179 \begin_layout Standard
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23188 \begin_layout Standard
23194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23197 \begin_layout Standard
23203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23206 \begin_layout Standard
23220 \begin_layout Subsection
23224 \begin_layout Standard
23225 PIC16 port supports the standard command line arguments as supposed, with
23226 the exception of certain cases that will be mentioned in the following
23231 \labelwidthstring 00.00.0000
23236 \begin_layout Standard
23246 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23254 \begin_layout Standard
23267 \labelwidthstring 00.00.0000
23272 \begin_layout Standard
23281 -fommit-frame-pointer
23282 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23286 Frame pointer will be omitted when the function uses no local variables.
23289 \begin_layout Subsection
23290 Port Specific Options
23291 \begin_inset LatexCommand \index{Options PIC16}
23298 \begin_layout Standard
23299 The port specific options appear after the global options in the sdcc --help
23303 \begin_layout Subsubsection
23307 \begin_layout Standard
23308 General options enable certain port features and optimizations.
23312 \labelwidthstring 00.00.0000
23317 \begin_layout Standard
23326 -pstack-model=[model] Used in conjuction with the command above.
23327 Defines the stack model to be used, valid stack models are :
23332 \labelwidthstring 00.00.0000
23337 Selects small stack model.
23338 8 bit stack and frame pointers.
23339 Supports 256 bytes stack size.
23343 \labelwidthstring 00.00.0000
23348 Selects large stack model.
23349 16 bit stack and frame pointers.
23350 Supports 65536 bytes stack size.
23355 \labelwidthstring 00.00.0000
23360 \begin_layout Standard
23369 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23370 unitialized data variables with [kword].
23371 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23375 \labelwidthstring 00.00.0000
23380 \begin_layout Standard
23389 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23390 Useful for bootloaders.
23394 \labelwidthstring 00.00.0000
23399 \begin_layout Standard
23408 -asm= sets the full path and name of an external assembler to call.
23412 \labelwidthstring 00.00.0000
23417 \begin_layout Standard
23426 -link= sets the full path and name of an external linker to call.
23430 \labelwidthstring 00.00.0000
23435 \begin_layout Standard
23445 \begin_inset LatexCommand \index{PIC16!MPLAB}
23449 compatibility option.
23450 Currently only suppresses special gpasm directives.
23453 \begin_layout Subsubsection
23454 Optimization Options
23458 \labelwidthstring 00.00.0000
23463 \begin_layout Standard
23472 -optimize-goto Try to use (conditional) BRA instead of GOTO
23476 \labelwidthstring 00.00.0000
23481 \begin_layout Standard
23490 -optimize-cmp Try to optimize some compares.
23494 \labelwidthstring 00.00.0000
23499 \begin_layout Standard
23508 -optimize-df Analyze the dataflow of the generated code and improve it.
23512 \labelwidthstring 00.00.0000
23517 \begin_layout Standard
23526 -obanksel=nn Set optimization level for inserting BANKSELs.
23533 \labelwidthstring 00.00.0000
23538 \labelwidthstring 00.00.0000
23539 1 checks previous used register and if it is the same then does not emit
23540 BANKSEL, accounts only for labels.
23544 \labelwidthstring 00.00.0000
23545 2 tries to check the location of (even different) symbols and removes BANKSELs
23546 if they are in the same bank.
23551 Important: There might be problems if the linker script has data sections
23552 across bank borders!
23556 \begin_layout Subsubsection
23561 \labelwidthstring 00.00.0000
23566 \begin_layout Standard
23575 -nodefaultlibs do not link default libraries when linking
23579 \labelwidthstring 00.00.0000
23584 \begin_layout Standard
23593 -no-crt Don't link the default run-time modules
23597 \labelwidthstring 00.00.0000
23602 \begin_layout Standard
23611 -use-crt= Use a custom run-time module instead of the defaults.
23614 \begin_layout Subsubsection
23618 \begin_layout Standard
23619 Debugging options enable extra debugging information in the output files.
23623 \labelwidthstring 00.00.0000
23628 \begin_layout Standard
23637 -debug-xtra Similar to -
23641 \begin_layout Standard
23651 \begin_inset LatexCommand \index{-\/-debug}
23655 , but dumps more information.
23659 \labelwidthstring 00.00.0000
23664 \begin_layout Standard
23673 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23675 <source> is the name of the file compiled.
23679 \labelwidthstring 00.00.0000
23684 \begin_layout Standard
23693 -pcode-verbose Enable pcode debugging information in translation.
23697 \labelwidthstring 00.00.0000
23702 \begin_layout Standard
23711 -denable-peeps Force the usage of peepholes.
23716 \labelwidthstring 00.00.0000
23721 \begin_layout Standard
23730 -gstack Trace push/pops for stack pointer overflow
23734 \labelwidthstring 00.00.0000
23739 \begin_layout Standard
23748 -call-tree dump call tree in .calltree file
23751 \begin_layout Subsection
23752 Enviromental Variables
23755 \begin_layout Standard
23756 There is a number of enviromental variables that can be used when running
23757 SDCC to enable certain optimizations or force a specific program behaviour.
23758 these variables are primarily for debugging purposes so they can be enabled/dis
23762 \begin_layout Standard
23763 Currently there is only two such variables available:
23767 \labelwidthstring 00.00.0000
23768 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23769 bitfields is optimized by directly loading FSR0 with the address of the
23770 bitfield structure.
23771 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23773 This step saves data ram and code space for functions that perform heavy
23776 80 bytes of code space are saved when compiling malloc.c with this option).
23781 \labelwidthstring 00.00.0000
23782 NO_REG_OPT do not perform pCode registers optimization.
23783 This should be used for debugging purposes.
23784 In some where bugs in the pcode optimizer are found, users can benefit
23785 from temporarily disabling the optimizer until the bug is fixed.
23788 \begin_layout Subsection
23789 Preprocessor Macros
23792 \begin_layout Standard
23794 \begin_inset LatexCommand \index{PIC16}
23798 port defines the following preprocessor macros while translating a source.
23801 \begin_layout Standard
23803 \begin_inset Tabular
23804 <lyxtabular version="3" rows="6" columns="2">
23806 <column alignment="center" valignment="top" leftline="true" width="0">
23807 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23808 <row topline="true" bottomline="true">
23809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23812 \begin_layout Standard
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23821 \begin_layout Standard
23828 <row topline="true">
23829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23832 \begin_layout Standard
23838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23841 \begin_layout Standard
23842 Port identification
23848 <row topline="true">
23849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23852 \begin_layout Standard
23857 \begin_layout Standard
23871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23874 \begin_layout Standard
23875 Port identification (same as above)
23881 <row topline="true">
23882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23885 \begin_layout Standard
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23894 \begin_layout Standard
23895 MCU Identification.
23900 is the microcontrol identification number, i.e.
23907 <row topline="true">
23908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23911 \begin_layout Standard
23916 \begin_layout Standard
23930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23933 \begin_layout Standard
23934 MCU Identification (same as above)
23940 <row topline="true" bottomline="true">
23941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23944 \begin_layout Standard
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23953 \begin_layout Standard
23954 nnn = SMALL or LARGE respectively according to the stack model used
23967 \begin_layout Standard
23968 In addition the following macros are defined when calling assembler:
23971 \begin_layout Standard
23973 \begin_inset Tabular
23974 <lyxtabular version="3" rows="4" columns="2">
23976 <column alignment="center" valignment="top" leftline="true" width="0">
23977 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23978 <row topline="true" bottomline="true">
23979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23982 \begin_layout Standard
23988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23991 \begin_layout Standard
23998 <row topline="true">
23999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24002 \begin_layout Standard
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24011 \begin_layout Standard
24012 MCU Identification.
24017 is the microcontrol identification number, i.e.
24024 <row topline="true">
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24028 \begin_layout Standard
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24037 \begin_layout Standard
24038 nnn = SMALL or LARGE respectively according to the memory model used for
24045 <row topline="true" bottomline="true">
24046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24049 \begin_layout Standard
24055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24058 \begin_layout Standard
24059 nnn = SMALL or LARGE respectively according to the stack model used
24072 \begin_layout Subsection
24076 \begin_layout Standard
24078 \begin_inset LatexCommand \index{PIC16}
24082 port uses the following directories for searching header files and libraries.
24085 \begin_layout Standard
24087 \begin_inset Tabular
24088 <lyxtabular version="3" rows="3" columns="4">
24090 <column alignment="center" valignment="top" leftline="true" width="0">
24091 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24092 <column alignment="center" valignment="top" width="0">
24093 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24094 <row topline="true" bottomline="true">
24095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24098 \begin_layout Standard
24104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24107 \begin_layout Standard
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24116 \begin_layout Standard
24122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24125 \begin_layout Standard
24132 <row topline="true">
24133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24136 \begin_layout Standard
24137 PREFIX/sdcc/include/pic16
24142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24145 \begin_layout Standard
24146 PIC16 specific headers
24151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24154 \begin_layout Standard
24160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24163 \begin_layout Standard
24170 <row topline="true" bottomline="true">
24171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24174 \begin_layout Standard
24175 PREFIX/sdcc/lib/pic16
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24183 \begin_layout Standard
24184 PIC16 specific libraries
24189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24192 \begin_layout Standard
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24201 \begin_layout Standard
24215 \begin_layout Subsection
24217 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24224 \begin_layout Standard
24226 \begin_inset LatexCommand \index{PIC16}
24230 port currently supports the following pragmas:
24234 \labelwidthstring 00.00.0000
24236 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24241 \begin_inset LatexCommand \index{PIC16!stack}
24245 forces the code generator to initialize the stack & frame pointers at a
24247 This is an adhoc solution for cases where no STACK directive is available
24248 in the linker script or gplink is not instructed to create a stack section.
24251 stack pragma should be used only once in a project.
24252 Multiple pragmas may result in indeterminate behaviour of the program.
24256 \begin_layout Standard
24257 The old format (ie.
24258 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24259 cross page boundaries (or even exceed the available data RAM) and crash
24261 Make sure that stack does not cross page boundaries when using the SMALL
24269 The format is as follows:
24272 \begin_layout LyX-Code
24273 #pragma stack bottom_address [stack_size]
24276 \begin_layout Standard
24281 is the lower bound of the stack section.
24282 The stack pointer initially will point at address (bottom_address+stack_size-1).
24285 \begin_layout LyX-Code
24289 \begin_layout LyX-Code
24293 \begin_layout LyX-Code
24294 /* initializes stack of 100 bytes at RAM address 0x200 */
24297 \begin_layout LyX-Code
24298 #pragma stack 0x200 100
24301 \begin_layout Standard
24302 If the stack_size field is omitted then a stack is created with the default
24304 This size might be enough for most programs, but its not enough for operations
24305 with deep function nesting or excessive stack usage.
24309 \labelwidthstring 00.00.0000
24311 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24315 place a function symbol at static FLASH address
24318 \begin_layout LyX-Code
24322 \begin_layout LyX-Code
24326 \begin_layout LyX-Code
24327 /* place function test_func at 0x4000 */
24330 \begin_layout LyX-Code
24331 #pragma code test_func 0x4000
24334 \begin_layout LyX-Code
24339 \labelwidthstring 00.00.0000
24340 library instructs the linker to use a library module.
24345 \begin_layout LyX-Code
24346 #pragma library module_name
24349 \begin_layout Standard
24354 can be any library or object file (including its path).
24355 Note that there are four reserved keywords which have special meaning.
24359 \begin_layout Standard
24361 \begin_inset Tabular
24362 <lyxtabular version="3" rows="6" columns="3">
24364 <column alignment="center" valignment="top" leftline="true" width="0">
24365 <column alignment="block" valignment="top" leftline="true" width="20page%">
24366 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24367 <row topline="true" bottomline="true">
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24371 \begin_layout Standard
24377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24380 \begin_layout Standard
24386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24389 \begin_layout Standard
24396 <row topline="true">
24397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24400 \begin_layout Standard
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24411 \begin_layout Standard
24412 ignore all library pragmas
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24420 \begin_layout Standard
24429 <row topline="true">
24430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24433 \begin_layout Standard
24441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24444 \begin_layout Standard
24450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24453 \begin_layout Standard
24464 <row topline="true">
24465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24468 \begin_layout Standard
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24479 \begin_layout Standard
24480 link the Math libarary
24485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24488 \begin_layout Standard
24499 <row topline="true">
24500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24503 \begin_layout Standard
24511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24514 \begin_layout Standard
24515 link the I/O library
24520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24523 \begin_layout Standard
24534 <row topline="true" bottomline="true">
24535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24538 \begin_layout Standard
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24549 \begin_layout Standard
24550 link the debug library
24555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24558 \begin_layout Standard
24575 * is the device number, i.e.
24576 452 for PIC18F452 MCU.
24579 \begin_layout Standard
24580 This feature allows for linking with specific libraries withoug having to
24581 explicit name them in the command line.
24586 keyword will reject all modules specified by the library pragma.
24590 \labelwidthstring 00.00.0000
24591 udata pragma udata instructs the compiler to emit code so that linker will
24592 place a variable at a specific memory bank
24595 \begin_layout LyX-Code
24599 \begin_layout LyX-Code
24603 \begin_layout LyX-Code
24604 /* places variable foo at bank2 */
24607 \begin_layout LyX-Code
24608 #pragma udata bank2 foo
24611 \begin_layout LyX-Code
24615 \begin_layout Standard
24616 In order for this pragma to work extra SECTION directives should be added
24617 in the .lkr script.
24618 In the following example a sample .lkr file is shown:
24621 \begin_layout LyX-Code
24625 \begin_layout LyX-Code
24626 // Sample linker script for the PIC18F452 processor
24629 \begin_layout LyX-Code
24633 \begin_layout LyX-Code
24634 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24637 \begin_layout LyX-Code
24638 CODEPAGE NAME=page START=0x2A END=0x7FFF
24641 \begin_layout LyX-Code
24642 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24645 \begin_layout LyX-Code
24646 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24649 \begin_layout LyX-Code
24650 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24653 \begin_layout LyX-Code
24654 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24657 \begin_layout LyX-Code
24658 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24661 \begin_layout LyX-Code
24665 \begin_layout LyX-Code
24666 DATABANK NAME=gpr0 START=0x80 END=0xFF
24669 \begin_layout LyX-Code
24670 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24673 \begin_layout LyX-Code
24674 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24677 \begin_layout LyX-Code
24678 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24681 \begin_layout LyX-Code
24682 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24685 \begin_layout LyX-Code
24686 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24689 \begin_layout LyX-Code
24690 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24693 \begin_layout LyX-Code
24697 \begin_layout LyX-Code
24698 SECTION NAME=CONFIG ROM=config
24701 \begin_layout LyX-Code
24705 \begin_layout LyX-Code
24706 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24709 \begin_layout LyX-Code
24710 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24713 \begin_layout LyX-Code
24714 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24717 \begin_layout LyX-Code
24718 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24721 \begin_layout LyX-Code
24722 SECTION NAME=bank4 RAM=gpr4
24725 \begin_layout LyX-Code
24726 SECTION NAME=bank5 RAM=gpr5
24729 \begin_layout Standard
24730 The linker will recognise the section name set in the pragma statement and
24731 will position the variable at the memory bank set with the RAM field at
24732 the SECTION line in the linker script file.
24735 \begin_layout Subsection
24737 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24744 \begin_layout Standard
24745 There is one main header file
24746 \begin_inset LatexCommand \index{PIC16!Header files}
24750 that can be included to the source files using the pic16
24751 \begin_inset LatexCommand \index{PIC16}
24761 This header file contains the definitions for the processor special registers,
24762 so it is necessary if the source accesses them.
24763 It can be included by adding the following line in the beginning of the
24767 \begin_layout LyX-Code
24768 #include <pic18fregs.h>
24771 \begin_layout Standard
24772 The specific microcontroller is selected within the pic18fregs.h automatically,
24773 so the same source can be used with a variety of devices.
24776 \begin_layout Subsection
24780 \begin_layout Standard
24782 \begin_inset LatexCommand \index{PIC16!Libraries}
24787 \begin_inset LatexCommand \index{PIC16}
24791 port depends on are the microcontroller device libraries which contain
24792 the symbol definitions for the microcontroller special function registers.
24793 These libraries have the format pic18fxxxx.lib, where
24797 is the microcontroller identification number.
24798 The specific library is selected automatically by the compiler at link
24799 stage according to the selected device.
24802 \begin_layout Standard
24803 Libraries are created with gplib which is part of the gputils package
24804 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24811 \begin_layout Subsubsection*
24812 Building the libraries
24815 \begin_layout Standard
24816 Before using SDCC/pic16 there are some libraries that need to be compiled.
24817 This process is not done automatically by SDCC since not all users use
24818 SDCC for pic16 projects.
24819 So each user should compile the libraries separately.
24822 \begin_layout Standard
24823 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24826 \begin_layout LyX-Code
24827 cd device/lib/pic16
24830 \begin_layout LyX-Code
24834 \begin_layout LyX-Code
24838 \begin_layout LyX-Code
24842 \begin_layout LyX-Code
24846 \begin_layout LyX-Code
24847 su -c 'make install' # install the libraries, you need the root password
24850 \begin_layout Standard
24851 If you need to install the headers too, do:
24854 \begin_layout LyX-Code
24858 \begin_layout LyX-Code
24859 su -c 'make install' # install the headers, you need the root password
24862 \begin_layout Standard
24863 There exist a special target to build the I/O libraries.
24864 This target is not automatically build because it will build the I/O library
24870 This way building will take quite a lot of time.
24871 Users are advised to edit the
24873 device/lib/pic16/pics.build
24875 file and then execute:
24878 \begin_layout LyX-Code
24882 \begin_layout Subsection
24886 \begin_layout Standard
24887 The following memory models are supported by the PIC16 port:
24890 \begin_layout Itemize
24894 \begin_layout Itemize
24898 \begin_layout Standard
24899 Memory model affects the default size of pointers within the source.
24900 The sizes are shown in the next table:
24903 \begin_layout Standard
24905 \begin_inset Tabular
24906 <lyxtabular version="3" rows="3" columns="3">
24908 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24909 <column alignment="center" valignment="top" leftline="true" width="0">
24910 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24911 <row topline="true" bottomline="true">
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24915 \begin_layout Standard
24916 Pointer sizes according to memory model
24921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24924 \begin_layout Standard
24930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24933 \begin_layout Standard
24940 <row topline="true" bottomline="true">
24941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24944 \begin_layout Standard
24950 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24953 \begin_layout Standard
24959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24962 \begin_layout Standard
24969 <row topline="true" bottomline="true">
24970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24973 \begin_layout Standard
24979 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24982 \begin_layout Standard
24988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24991 \begin_layout Standard
25005 \begin_layout Standard
25006 It is advisable that all sources within a project are compiled with the
25008 If one wants to override the default memory model, this can be done by
25009 declaring a pointer as
25018 Far selects large memory model's pointers, while near selects small memory
25022 \begin_layout Standard
25023 The standard device libraries (see
25024 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25028 ) contain no reference to pointers, so they can be used with both memory
25032 \begin_layout Subsection
25036 \begin_layout Standard
25038 \begin_inset LatexCommand \index{PIC16!stack}
25042 implementation for the PIC16 port uses two indirect registers, FSR1 and
25047 \labelwidthstring 00.00.0000
25048 FSR1 is assigned as stack pointer
25052 \labelwidthstring 00.00.0000
25053 FSR2 is assigned as frame pointer
25056 \begin_layout Standard
25057 The following stack models are supported by the PIC16 port
25060 \begin_layout Itemize
25068 \begin_layout Itemize
25076 \begin_layout Standard
25081 model means that only the FSRxL byte is used to access stack and frame,
25088 uses both FSRxL and FSRxH registers.
25089 The following table shows the stack/frame pointers sizes according to stack
25090 model and the maximum space they can address:
25093 \begin_layout Standard
25095 \begin_inset Tabular
25096 <lyxtabular version="3" rows="3" columns="3">
25098 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25099 <column alignment="center" valignment="top" leftline="true" width="0">
25100 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25101 <row topline="true" bottomline="true">
25102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25105 \begin_layout Standard
25106 Stack & Frame pointer sizes according to stack model
25111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25114 \begin_layout Standard
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25123 \begin_layout Standard
25130 <row topline="true">
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25134 \begin_layout Standard
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25143 \begin_layout Standard
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25152 \begin_layout Standard
25159 <row topline="true" bottomline="true">
25160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25163 \begin_layout Standard
25169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25172 \begin_layout Standard
25178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25181 \begin_layout Standard
25195 \begin_layout Standard
25200 stack model is currently not working properly throughout the code generator.
25201 So its use is not advised.
25202 Also there are some other points that need special care:
25207 \begin_layout Enumerate
25208 Do not create stack sections with size more than one physical bank (that
25212 \begin_layout Enumerate
25213 Stack sections should no cross physical bank limits (i.e.
25214 #pragma stack 0x50 0x100)
25217 \begin_layout Standard
25218 These limitations are caused by the fact that only FSRxL is modified when
25219 using SMALL stack model, so no more than 256 bytes of stack can be used.
25220 This problem will disappear after LARGE model is fully implemented.
25223 \begin_layout Subsection
25227 \begin_layout Standard
25228 In addition to the standard SDCC function keywords, PIC16
25229 \begin_inset LatexCommand \index{PIC16}
25233 port makes available two more:
25237 \labelwidthstring 00.00.0000
25239 \begin_inset LatexCommand \index{PIC16!wparam}
25243 Use the WREG to pass one byte of the first function argument.
25244 This improves speed but you may not use this for functions with arguments
25245 that are called via function pointers, otherwise the first byte of the
25246 first parameter will get lost.
25250 \begin_layout LyX-Code
25251 void func_wparam(int a) wparam
25254 \begin_layout LyX-Code
25258 \begin_layout LyX-Code
25259 /* WREG hold the lower part of a */
25262 \begin_layout LyX-Code
25263 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25267 \begin_layout LyX-Code
25271 \begin_layout LyX-Code
25276 \labelwidthstring 00.00.0000
25278 \begin_inset LatexCommand \index{PIC16!shadowregs}
25282 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25283 hardware shadow registers which hold the values of WREG, STATUS and BSR
25285 This can be done by adding the keyword
25293 keyword in the function's header.
25296 \begin_layout LyX-Code
25297 void isr_shadow(void) shadowregs interrupt 1
25300 \begin_layout LyX-Code
25304 \begin_layout LyX-Code
25308 \begin_layout LyX-Code
25312 \begin_layout Standard
25317 instructs the code generator not to store/restore WREG, STATUS, BSR when
25318 entering/exiting the ISR.
25321 \begin_layout Subsection
25322 Function return values
25325 \begin_layout Standard
25326 Return values from functions are placed to the appropriate registers following
25327 a modified Microchip policy optimized for SDCC.
25328 The following table shows these registers:
25331 \begin_layout Standard
25333 \begin_inset Tabular
25334 <lyxtabular version="3" rows="6" columns="2">
25336 <column alignment="center" valignment="top" leftline="true" width="0">
25337 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25338 <row topline="true" bottomline="true">
25339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25342 \begin_layout Standard
25348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25351 \begin_layout Standard
25352 destination register
25358 <row topline="true">
25359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25362 \begin_layout Standard
25368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25371 \begin_layout Standard
25378 <row topline="true">
25379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25382 \begin_layout Standard
25388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25391 \begin_layout Standard
25398 <row topline="true">
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25402 \begin_layout Standard
25408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25411 \begin_layout Standard
25418 <row topline="true">
25419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25422 \begin_layout Standard
25428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25431 \begin_layout Standard
25432 FSR0L:PRODH:PRODL:WREG
25438 <row topline="true" bottomline="true">
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25442 \begin_layout Standard
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25451 \begin_layout Standard
25452 on stack, FSR0 points to the beginning
25465 \begin_layout Subsection
25469 \begin_layout Standard
25471 \begin_inset LatexCommand \index{PIC16!interrupt}
25475 service routine (ISR) is declared using the
25482 \begin_layout LyX-Code
25483 void isr(void) interrupt
25488 \begin_layout LyX-Code
25492 \begin_layout LyX-Code
25496 \begin_layout LyX-Code
25500 \begin_layout Standard
25505 is the interrupt number, which for PIC18F devices can be:
25508 \begin_layout Standard
25510 \begin_inset Tabular
25511 <lyxtabular version="3" rows="4" columns="3">
25513 <column alignment="center" valignment="top" leftline="true" width="0">
25514 <column alignment="center" valignment="top" leftline="true" width="0">
25515 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25516 <row topline="true" bottomline="true">
25517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25520 \begin_layout Standard
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25531 \begin_layout Standard
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25540 \begin_layout Standard
25541 Interrupt Vector Address
25547 <row topline="true">
25548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25551 \begin_layout Standard
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25560 \begin_layout Standard
25566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25569 \begin_layout Standard
25576 <row topline="true">
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25580 \begin_layout Standard
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25598 \begin_layout Standard
25608 HIGH priority interrupts
25613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25616 \begin_layout Standard
25623 <row topline="true" bottomline="true">
25624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25627 \begin_layout Standard
25633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25636 \begin_layout Standard
25637 LOW priority interrupts
25642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25645 \begin_layout Standard
25659 \begin_layout Standard
25660 When generating assembly code for ISR the code generator places a
25666 Interrupt Vector Address
25668 which points at the genetated ISR.
25669 This single GOTO instruction is part of an automatically generated
25671 interrupt entry point
25674 The actuall ISR code is placed as normally would in the code space.
25675 Upon interrupt request, the GOTO instruction is executed which jumps to
25677 When declaring interrupt functions as _naked this GOTO instruction is
25682 The whole interrupt functions is therefore placed at the Interrupt Vector
25683 Address of the specific interrupt.
25684 This is not a problem for the LOW priority interrupts, but it is a problem
25685 for the RESET and the HIGH priority interrupts because code may be written
25686 at the next interrupt´s vector address and cause undeterminate program
25687 behaviour if that interrupt is raised.
25691 \begin_layout Standard
25692 This is not a problem when
25695 \begin_layout Enumerate
25696 this is a HIGH interrupt ISR and LOW interrupts are
25703 \begin_layout Enumerate
25704 when the ISR is small enough not to reach the next interrupt´s vector address.
25712 \begin_layout Standard
25717 is possible to be omitted.
25718 This way a function is generated similar to an ISR, but it is not assigned
25722 \begin_layout Standard
25723 When entering an interrupt, currently the PIC16
25724 \begin_inset LatexCommand \index{PIC16}
25728 port automatically saves the following registers:
25731 \begin_layout Itemize
25735 \begin_layout Itemize
25739 \begin_layout Itemize
25743 \begin_layout Itemize
25744 PROD (PRODL and PRODH)
25747 \begin_layout Itemize
25748 FSR0 (FSR0L and FSR0H)
25751 \begin_layout Standard
25752 These registers are restored upon return from the interrupt routine.
25756 \begin_layout Standard
25757 NOTE that when the _naked attribute is specified for an interrupt routine,
25758 then NO registers are stored or restored.
25766 \begin_layout Subsection
25770 \begin_layout Standard
25771 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25772 There are 3 types of generic pointers currently implemented data, code
25773 and eeprom pointers.
25774 They are differentiated by the value of the 7th and 6th bits of the upper
25778 \begin_layout Standard
25780 \begin_inset Tabular
25781 <lyxtabular version="3" rows="5" columns="5">
25783 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25784 <column alignment="center" valignment="top" width="0">
25785 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25786 <column alignment="center" valignment="top" width="0">
25787 <column alignment="left" valignment="top" rightline="true" width="0">
25788 <row topline="true" bottomline="true">
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25792 \begin_layout Standard
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25801 \begin_layout Standard
25807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25810 \begin_layout Standard
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25819 \begin_layout Standard
25820 rest of the pointer
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25828 \begin_layout Standard
25835 <row topline="true" bottomline="true">
25836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25839 \begin_layout Standard
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25848 \begin_layout Standard
25854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25857 \begin_layout Standard
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25866 \begin_layout Standard
25871 uuuuuu uuuuxxxx xxxxxxxx
25876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25879 \begin_layout Standard
25880 a 12-bit data pointer in data RAM memory
25886 <row bottomline="true">
25887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25890 \begin_layout Standard
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25899 \begin_layout Standard
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25908 \begin_layout Standard
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25917 \begin_layout Standard
25922 uxxxxx xxxxxxxx xxxxxxxx
25927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25930 \begin_layout Standard
25931 a 21-bit code pointer in FLASH memory
25937 <row bottomline="true">
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25941 \begin_layout Standard
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25950 \begin_layout Standard
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25959 \begin_layout Standard
25965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25968 \begin_layout Standard
25973 uuuuuu uuuuuuxx xxxxxxxx
25978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25981 \begin_layout Standard
25982 a 10-bit eeprom pointer in EEPROM memory
25988 <row bottomline="true">
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25992 \begin_layout Standard
25998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26001 \begin_layout Standard
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26010 \begin_layout Standard
26016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26019 \begin_layout Standard
26024 xxxxxx xxxxxxxx xxxxxxxx
26029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26032 \begin_layout Standard
26033 unimplemented pointer type
26046 \begin_layout Standard
26047 Generic pointer are read and written with a set of library functions which
26048 read/write 1, 2, 3, 4 bytes.
26051 \begin_layout Subsection
26055 \begin_layout Subsubsection
26056 Standard I/O Streams
26059 \begin_layout Standard
26064 the type FILE is defined as:
26067 \begin_layout LyX-Code
26068 typedef char * FILE;
26071 \begin_layout Standard
26072 This type is the stream type implemented I/O in the PIC18F devices.
26073 Also the standard input and output streams are declared in stdio.h:
26076 \begin_layout LyX-Code
26077 extern FILE * stdin;
26080 \begin_layout LyX-Code
26081 extern FILE * stdout;
26084 \begin_layout Standard
26085 The FILE type is actually a generic pointer which defines one more type
26086 of generic pointers, the
26091 This new type has the format:
26094 \begin_layout Standard
26096 \begin_inset Tabular
26097 <lyxtabular version="3" rows="2" columns="7">
26099 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26100 <column alignment="center" valignment="top" width="0">
26101 <column alignment="center" valignment="top" leftline="true" width="0">
26102 <column alignment="center" valignment="top" leftline="true" width="0">
26103 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26104 <column alignment="center" valignment="top" width="0">
26105 <column alignment="left" valignment="top" rightline="true" width="0">
26106 <row topline="true" bottomline="true">
26107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26110 \begin_layout Standard
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26119 \begin_layout Standard
26125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26128 \begin_layout Standard
26134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26137 \begin_layout Standard
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26146 \begin_layout Standard
26152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26155 \begin_layout Standard
26156 rest of the pointer
26161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26164 \begin_layout Standard
26171 <row topline="true" bottomline="true">
26172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26175 \begin_layout Standard
26181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26184 \begin_layout Standard
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26193 \begin_layout Standard
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26202 \begin_layout Standard
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26211 \begin_layout Standard
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26220 \begin_layout Standard
26230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26233 \begin_layout Standard
26234 upper byte high nubble is 0x2n, the rest are zeroes
26247 \begin_layout Standard
26248 Currently implemented there are 3 types of streams defined:
26251 \begin_layout Standard
26253 \begin_inset Tabular
26254 <lyxtabular version="3" rows="4" columns="4">
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" width="0">
26259 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26260 <row topline="true" bottomline="true">
26261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26264 \begin_layout Standard
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26273 \begin_layout Standard
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 \begin_layout Standard
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26291 \begin_layout Standard
26298 <row topline="true">
26299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26302 \begin_layout Standard
26308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26311 \begin_layout Standard
26319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26322 \begin_layout Standard
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26331 \begin_layout Standard
26332 Writes/Reads characters via the USART peripheral
26338 <row topline="true">
26339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26342 \begin_layout Standard
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26351 \begin_layout Standard
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26362 \begin_layout Standard
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26371 \begin_layout Standard
26372 Writes/Reads characters via the MSSP peripheral
26378 <row topline="true" bottomline="true">
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26382 \begin_layout Standard
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26391 \begin_layout Standard
26399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26402 \begin_layout Standard
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26411 \begin_layout Standard
26412 Writes/Reads characters via used defined functions
26425 \begin_layout Standard
26426 The stream identifiers are declared as macros in the stdio.h header.
26429 \begin_layout Standard
26430 In the libc library there exist the functions that are used to write to
26431 each of the above streams.
26436 \labelwidthstring 00.00.0000
26441 \begin_layout Standard
26450 _stream_usart_putchar writes a character at the USART stream
26454 \labelwidthstring 00.00.0000
26459 \begin_layout Standard
26468 _stream_mssp_putchar writes a character at the MSSP stream
26472 \labelwidthstring 00.00.0000
26473 putchar dummy function.
26474 This writes a character to a user specified manner.
26477 \begin_layout Standard
26478 In order to increase performance
26482 is declared in stdio.h as having its parameter in WREG (it has the wparam
26484 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26485 in a user-friendly way.
26490 is the name of the variable that holds the character to print.
26491 An example follows:
26494 \begin_layout LyX-Code
26495 #include <pic18fregs.h>
26504 \begin_layout LyX-Code
26508 \begin_layout LyX-Code
26509 PORTA = c; /* dump character c to PORTA */
26512 \begin_layout LyX-Code
26520 \begin_layout LyX-Code
26524 \begin_layout LyX-Code
26525 stdout = STREAM_USER; /* this is not necessary, since stdout points
26528 \begin_layout LyX-Code
26529 * by default to STREAM_USER */
26532 \begin_layout LyX-Code
26533 printf (¨This is a printf test
26538 \begin_layout LyX-Code
26542 \begin_layout LyX-Code
26546 \begin_layout Subsubsection
26550 \begin_layout Standard
26551 PIC16 contains an implementation of the printf-family of functions.
26552 There exist the following functions:
26555 \begin_layout LyX-Code
26556 extern unsigned int sprintf(char *buf, char *fmt, ...);
26559 \begin_layout LyX-Code
26560 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26563 \begin_layout LyX-Code
26567 \begin_layout LyX-Code
26568 extern unsigned int printf(char *fmt, ...);
26571 \begin_layout LyX-Code
26572 extern unsigned int vprintf(char *fmt, va_lista ap);
26575 \begin_layout LyX-Code
26579 \begin_layout LyX-Code
26580 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26583 \begin_layout LyX-Code
26584 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26587 \begin_layout Standard
26588 For sprintf and vsprintf
26592 should normally be a data pointer where the resulting string will be placed.
26593 No range checking is done so the user should allocate the necessery buffer.
26594 For fprintf and vfprintf
26598 should be a stream pointer (i.e.
26599 stdout, STREAM_MSSP, etc...).
26602 \begin_layout Subsubsection
26606 \begin_layout Standard
26607 The PIC18F family of microcontrollers supports a number of interrupt sources.
26608 A list of these interrupts is shown in the following table:
26611 \begin_layout Standard
26613 \begin_inset Tabular
26614 <lyxtabular version="3" rows="11" columns="4">
26616 <column alignment="left" valignment="top" leftline="true" width="0">
26617 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26618 <column alignment="left" valignment="top" leftline="true" width="0">
26619 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26620 <row topline="true" bottomline="true">
26621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26624 \begin_layout Standard
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26633 \begin_layout Standard
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26642 \begin_layout Standard
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26651 \begin_layout Standard
26658 <row topline="true">
26659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26662 \begin_layout Standard
26668 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26671 \begin_layout Standard
26672 PORTB change interrupt
26677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26680 \begin_layout Standard
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26689 \begin_layout Standard
26690 EEPROM/FLASH write complete interrupt
26696 <row topline="true">
26697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26700 \begin_layout Standard
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26709 \begin_layout Standard
26710 INT0 external interrupt
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_layout Standard
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26727 \begin_layout Standard
26728 Bus collision interrupt
26734 <row topline="true">
26735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26738 \begin_layout Standard
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26747 \begin_layout Standard
26748 INT1 external interrupt
26753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26756 \begin_layout Standard
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26765 \begin_layout Standard
26766 Low voltage detect interrupt
26772 <row topline="true">
26773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26776 \begin_layout Standard
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26785 \begin_layout Standard
26786 INT2 external interrupt
26791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26794 \begin_layout Standard
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26803 \begin_layout Standard
26804 Parallel slave port interrupt
26810 <row topline="true">
26811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26814 \begin_layout Standard
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26823 \begin_layout Standard
26824 CCP1 module interrupt
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26832 \begin_layout Standard
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26841 \begin_layout Standard
26842 AD convertion complete interrupt
26848 <row topline="true">
26849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26852 \begin_layout Standard
26858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26861 \begin_layout Standard
26862 CCP2 module interrupt
26867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26870 \begin_layout Standard
26876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26879 \begin_layout Standard
26880 USART receive interrupt
26886 <row topline="true">
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26890 \begin_layout Standard
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26899 \begin_layout Standard
26900 TMR0 overflow interrupt
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26908 \begin_layout Standard
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26917 \begin_layout Standard
26918 USART transmit interrupt
26924 <row topline="true">
26925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26928 \begin_layout Standard
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26937 \begin_layout Standard
26938 TMR1 overflow interrupt
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26946 \begin_layout Standard
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26955 \begin_layout Standard
26956 SSP receive/transmit interrupt
26962 <row topline="true">
26963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26966 \begin_layout Standard
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26975 \begin_layout Standard
26976 TMR2 matches PR2 interrupt
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26984 \begin_layout Standard
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_layout Standard
27000 <row topline="true" bottomline="true">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27004 \begin_layout Standard
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27013 \begin_layout Standard
27014 TMR3 overflow interrupt
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27022 \begin_layout Standard
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27031 \begin_layout Standard
27045 \begin_layout Standard
27046 The prototypes for these names are defined in the header file
27053 \begin_layout Standard
27054 In order to simplify signal handling, a number of macros is provided:
27058 \labelwidthstring 00.00.0000
27059 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27060 high priority interrupts.
27065 is the function name to use.
27069 \labelwidthstring 00.00.0000
27070 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27071 low priority interrupt.
27076 is the function name to use.
27080 \labelwidthstring 00.00.0000
27081 DEF_HANDLER(sig,handler) define a handler for signal
27087 \labelwidthstring 00.00.0000
27088 END_DEF end the declaration of the dispatch table.
27091 \begin_layout Standard
27092 Additionally there are two more macros to simplify the declaration of the
27097 \labelwidthstring 00.00.0000
27100 SIGHANDLER(handler)
27102 this declares the function prototype for the
27110 \labelwidthstring 00.00.0000
27111 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27114 \begin_layout Standard
27115 An example of using the macros above is shown below:
27118 \begin_layout LyX-Code
27119 #include <pic18fregs.h>
27122 \begin_layout LyX-Code
27123 #include <signal.h>
27127 DEF_INTHIGH(high_int)
27130 \begin_layout LyX-Code
27131 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27134 \begin_layout LyX-Code
27135 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27138 \begin_layout LyX-Code
27143 SIGHANDLER(_tmr0_handler)
27146 \begin_layout LyX-Code
27150 \begin_layout LyX-Code
27151 /* action to be taken when timer 0 overflows */
27154 \begin_layout LyX-Code
27159 SIGHANDLERNAKED(_bcol_handler)
27162 \begin_layout LyX-Code
27166 \begin_layout LyX-Code
27170 \begin_layout LyX-Code
27171 /* action to be taken when bus collision occurs */
27174 \begin_layout LyX-Code
27178 \begin_layout LyX-Code
27182 \begin_layout LyX-Code
27186 \begin_layout Standard
27191 Special care should be taken when using the above scheme:
27194 \begin_layout Itemize
27195 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27198 \begin_layout Itemize
27199 when declaring SIGHANDLERNAKED handler never forget to use
27203 for proper returning.
27206 \begin_layout Subsection
27210 \begin_layout Standard
27211 Here you can find some general tips for compiling programs with SDCC/pic16.
27214 \begin_layout Subsubsection
27218 \begin_layout Standard
27220 \begin_inset LatexCommand \index{PIC16!stack}
27224 size (that is 64 bytes) probably is enough for many programs.
27225 One must take care that when there are many levels of function nesting,
27226 or there is excessive usage of stack, its size should be extended.
27227 An example of such a case is the printf/sprintf family of functions.
27228 If you encounter problems like not being able to print integers, then you
27229 need to set the stack size around the maximum (256 for small stack model).
27230 The following diagram shows what happens when calling printf to print an
27234 \begin_layout LyX-Code
27235 printf () --> ltoa () --> ultoa () --> divschar ()
27238 \begin_layout Standard
27239 It is should be understood that stack is easily consumed when calling complicate
27241 Using command line arguments like -
27245 \begin_layout Standard
27254 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27256 Other ways to reduce stack usage may exist.
27259 \begin_layout Subsection
27263 \begin_layout Standard
27264 The PIC16 Port currently does not pass SDCC's regression test
27265 \begin_inset LatexCommand \index{Regression test (PIC16)}
27270 \begin_inset LatexCommand \ref{sec:Quality-control}
27274 ) and thus the snapshot build regression tests for the PIC16 target are
27275 currently disabled for all hosts
27280 \begin_layout Chapter
27284 \begin_layout Standard
27285 There are several approaches to debugging your code.
27286 This chapter is meant to show your options and to give detail on some of
27291 When writing your code:
27294 \begin_layout Itemize
27295 write your code with debugging in mind (avoid duplicating code, put conceptually
27296 similar variables into structs, use structured code, have strategic points
27297 within your code where all variables are consistent, ...)
27300 \begin_layout Itemize
27301 run a syntax-checking tool like splint
27302 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27307 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27315 \begin_layout Standard
27325 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27332 \begin_layout Itemize
27333 for the high level code use a C-compiler (like f.e.
27334 GCC) to compile run and debug the code on your host.
27339 \begin_layout Standard
27349 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27353 ) on how to handle syntax extensions like __xdata, __at(), ...
27357 \begin_layout Itemize
27358 use another C-compiler to compile code for your target.
27359 Always an option but not recommended:) And not very likely to help you.
27360 If you seriously consider walking this path you should at least occasionally
27361 check portability of your code.
27362 Most commercial compiler vendors will offer an evaluation version so you
27363 can test compile your code or snippets of your code.
27366 \begin_layout Standard
27367 Debugging on a simulator:
27370 \begin_layout Itemize
27371 there is a separate section about SDCDB (section
27372 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27379 \begin_layout Itemize
27380 or (8051 specific) use a freeware/commercial simulator which interfaces
27382 \begin_inset LatexCommand \index{AOMF, AOMF51}
27387 \begin_inset LatexCommand \ref{OMF file}
27391 ) optionally generated by SDCC.
27394 \begin_layout Standard
27395 Debugging On-target:
27398 \begin_layout Itemize
27399 use a MCU port pin to serially output debug data to the RS232 port of your
27401 You'll probably want some level shifting device typically involving a MAX232
27403 If the hardware serial port of the MCU is not available search for 'Software
27404 UART' in your favourite search machine.
27407 \begin_layout Itemize
27408 use an on-target monitor.
27409 In this context a monitor is a small program which usually accepts commands
27410 via a serial line and allows to set program counter, to single step through
27411 a program and read/write memory locations.
27412 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27414 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27421 \begin_layout Itemize
27422 toggle MCU port pins at strategic points within your code and use an oscilloscop
27426 digital oscilloscope
27429 \begin_inset LatexCommand \index{Oscilloscope}
27433 with deep trace memory is really helpful especially if you have to debug
27434 a realtime application.
27435 If you need to monitor more pins than your oscilloscope provides you can
27436 sometimes get away with a small R-2R network.
27437 On a single channel oscilloscope you could f.e.
27438 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27440 \begin_inset Formula $\Omega$
27443 resistor and the other one by a 5\InsetSpace ~
27445 \begin_inset Formula $\Omega$
27448 resistor to the oscilloscope probe (check output drive capability of the
27449 pins you want to monitor).
27450 If you need to monitor many more pins a
27457 \begin_layout Itemize
27471 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27476 Usually very expensive.
27477 And very nice to have too.
27478 And usually locks you (for years...) to the devices the ICE can emulate.
27482 \begin_layout Itemize
27483 use a remote debugger.
27484 In most 8-bit systems the symbol information is not available on the target,
27485 and a complete debugger is too bulky for the target system.
27486 Therefore usually a debugger on the host system connects to an on-target
27487 debugging stub which accepts only primitive commands.
27490 Terms to enter into your favourite search engine could be 'remote debugging',
27491 'gdb stub' or 'inferior debugger'.
27495 \begin_layout Itemize
27496 use an on target hardware debugger.
27497 Some of the more modern MCUs include hardware support for setting break
27498 points and monitoring/changing variables by using dedicated hardware pins.
27499 This facility doesn't require additional code to run on the target and
27504 doesn't affect runtime behaviour until a breakpoint is hit.
27505 For the mcs51 most hardware debuggers use the AOMF
27506 \begin_inset LatexCommand \index{AOMF, AOMF51}
27511 \begin_inset LatexCommand \ref{OMF file}
27519 \begin_layout Standard
27523 \begin_layout Itemize
27524 if you are not familiar with any of the following terms you're likely to
27525 run into problems rather sooner than later:
27542 As an embedded programmer you
27546 to know them so why not look them up
27550 you have problems?)
27553 \begin_layout Itemize
27554 tell someone else about your problem (actually this is a surprisingly effective
27555 means to hunt down the bug even if the listener is not familiar with your
27557 As 'failure to communicate' is probably one of the job-induced deformations
27558 of an embedded programmer this is highly encouraged.
27561 \begin_layout Section
27562 Debugging with SDCDB
27563 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27568 \begin_inset LatexCommand \index{SDCDB (debugger)}
27575 \begin_layout Standard
27576 SDCC is distributed with a source level debugger
27577 \begin_inset LatexCommand \index{Debugger}
27582 The debugger uses a command line interface, the command repertoire of the
27583 debugger has been kept as close to gdb
27584 \begin_inset LatexCommand \index{gdb}
27588 (the GNU debugger) as possible.
27589 The configuration and build process is part of the standard compiler installati
27590 on, which also builds and installs the debugger in the target directory
27591 specified during configuration.
27592 The debugger allows you debug BOTH at the C source and at the ASM source
27596 \begin_layout Subsection
27597 Compiling for Debugging
27600 \begin_layout Standard
27605 \begin_layout Standard
27615 \begin_inset LatexCommand \index{-\/-debug}
27619 option must be specified for all files for which debug information is to
27621 The compiler generates a .adb file for each of these files.
27622 The linker creates the .cdb
27623 \begin_inset LatexCommand \index{<file>.cdb}
27628 \begin_inset LatexCommand \index{<file>.adb}
27632 files and the address information.
27633 This .cdb is used by the debugger.
27636 \begin_layout Subsection
27637 How the Debugger Works
27640 \begin_layout Standard
27645 \begin_layout Standard
27654 -debug option is specified the compiler generates extra symbol information
27655 some of which are put into the assembler source and some are put into the
27657 Then the linker creates the .cdb file from the individual .adb files with
27658 the address information for the symbols.
27659 The debugger reads the symbolic information generated by the compiler &
27660 the address information generated by the linker.
27661 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27662 execution is controlled by the debugger.
27663 When a command is issued for the debugger, it translates it into appropriate
27664 commands for the simulator.
27665 (Currently SDCDM only connects to the simulator but
27670 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27674 is an effort to connect directly to the hardware.)
27677 \begin_layout Subsection
27678 Starting the Debugger SDCDB
27681 \begin_layout Standard
27682 The debugger can be started using the following command line.
27683 (Assume the file you are debugging has the file name foo).
27697 The debugger will look for the following files.
27700 \begin_layout Itemize
27701 foo.c - the source file.
27704 \begin_layout Itemize
27705 foo.cdb - the debugger symbol information file.
27708 \begin_layout Itemize
27709 foo.ihx - the Intel hex format
27710 \begin_inset LatexCommand \index{Intel hex format}
27717 \begin_layout Subsection
27718 SDCDB Command Line Options
27721 \begin_layout Itemize
27726 \begin_layout Standard
27735 -directory=<source file directory> this option can used to specify the directory
27737 The debugger will look into the directory list specified for source, cdb
27739 The items in the directory list must be separated by ':', e.g.
27740 if the source files can be in the directories /home/src1 and /home/src2,
27745 \begin_layout Standard
27754 -directory option should be -
27758 \begin_layout Standard
27767 -directory=/home/src1:/home/src2.
27768 Note there can be no spaces in the option.
27772 \begin_layout Itemize
27773 -cd <directory> - change to the <directory>.
27776 \begin_layout Itemize
27777 -fullname - used by GUI front ends.
27780 \begin_layout Itemize
27781 -cpu <cpu-type> - this argument is passed to the simulator please see the
27782 simulator docs for details.
27785 \begin_layout Itemize
27786 -X <Clock frequency > this options is passed to the simulator please see
27787 the simulator docs for details.
27790 \begin_layout Itemize
27791 -s <serial port file> passed to simulator see the simulator docs for details.
27794 \begin_layout Itemize
27795 -S <serial in,out> passed to simulator see the simulator docs for details.
27798 \begin_layout Itemize
27799 -k <port number> passed to simulator see the simulator docs for details.
27802 \begin_layout Subsection
27803 SDCDB Debugger Commands
27806 \begin_layout Standard
27807 As mentioned earlier the command interface for the debugger has been deliberatel
27808 y kept as close the GNU debugger gdb, as possible.
27809 This will help the integration with existing graphical user interfaces
27810 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27811 If you use a graphical user interface for the debugger you can skip this
27815 \begin_layout Subsubsection*
27816 break [line | file:line | function | file:function]
27819 \begin_layout Standard
27820 Set breakpoint at specified line or function:
27829 sdcdb>break foo.c:100
27831 sdcdb>break funcfoo
27833 sdcdb>break foo.c:funcfoo
27836 \begin_layout Subsubsection*
27837 clear [line | file:line | function | file:function ]
27840 \begin_layout Standard
27841 Clear breakpoint at specified line or function:
27850 sdcdb>clear foo.c:100
27852 sdcdb>clear funcfoo
27854 sdcdb>clear foo.c:funcfoo
27857 \begin_layout Subsubsection*
27861 \begin_layout Standard
27862 Continue program being debugged, after breakpoint.
27865 \begin_layout Subsubsection*
27869 \begin_layout Standard
27870 Execute till the end of the current function.
27873 \begin_layout Subsubsection*
27877 \begin_layout Standard
27878 Delete breakpoint number 'n'.
27879 If used without any option clear ALL user defined break points.
27882 \begin_layout Subsubsection*
27883 info [break | stack | frame | registers ]
27886 \begin_layout Itemize
27887 info break - list all breakpoints
27890 \begin_layout Itemize
27891 info stack - show the function call stack.
27894 \begin_layout Itemize
27895 info frame - show information about the current execution frame.
27898 \begin_layout Itemize
27899 info registers - show content of all registers.
27902 \begin_layout Subsubsection*
27906 \begin_layout Standard
27907 Step program until it reaches a different source line.
27908 Note: pressing <return> repeats the last command.
27911 \begin_layout Subsubsection*
27915 \begin_layout Standard
27916 Step program, proceeding through subroutine calls.
27919 \begin_layout Subsubsection*
27923 \begin_layout Standard
27924 Start debugged program.
27927 \begin_layout Subsubsection*
27931 \begin_layout Standard
27932 Print type information of the variable.
27935 \begin_layout Subsubsection*
27939 \begin_layout Standard
27940 print value of variable.
27943 \begin_layout Subsubsection*
27947 \begin_layout Standard
27948 load the given file name.
27949 Note this is an alternate method of loading file for debugging.
27952 \begin_layout Subsubsection*
27956 \begin_layout Standard
27957 print information about current frame.
27960 \begin_layout Subsubsection*
27964 \begin_layout Standard
27965 Toggle between C source & assembly source.
27968 \begin_layout Subsubsection*
27969 ! simulator command
27972 \begin_layout Standard
27973 Send the string following '!' to the simulator, the simulator response is
27975 Note the debugger does not interpret the command being sent to the simulator,
27976 so if a command like 'go' is sent the debugger can loose its execution
27977 context and may display incorrect values.
27980 \begin_layout Subsubsection*
27984 \begin_layout Standard
27987 My name is Bobby Brown"
27990 \begin_layout Subsection
27991 Interfacing SDCDB with DDD
27994 \begin_layout Standard
27995 \begin_inset Note Note
27998 \begin_layout Standard
27999 The screenshot was converted from png to eps with:
28000 \begin_inset Quotes sld
28003 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28004 \begin_inset Quotes srd
28007 which produces a pretty compact eps file which is free from compression
28011 \begin_layout Standard
28012 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28013 as this broke the build system on Sourceforge (pdf-file was broken.
28014 pdflatex does not accept eps files).
28022 \begin_layout Standard
28038 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28044 shows a screenshot of a debugging session with DDD
28045 \begin_inset LatexCommand \index{DDD (debugger)}
28049 (Unix only) on a simulated 8032.
28050 The debugging session might not run as smoothly as the screenshot suggests.
28051 The debugger allows setting of breakpoints, displaying and changing variables,
28052 single stepping through C and assembler code.
28055 The source was compiled with
28069 \begin_layout Standard
28081 -debug ddd_example.c
28094 and DDD was invoked with
28101 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28104 \begin_layout Standard
28105 \begin_inset Note Note
28108 \begin_layout Standard
28109 Check that the double quotes or an apostroph within the command line survive
28110 the LyX tool chain.
28111 Previously the apostrophs got slanted in the PDF output so a cut and paste
28120 \begin_layout Subsection
28121 Interfacing SDCDB with XEmacs
28122 \begin_inset LatexCommand \index{XEmacs}
28127 \begin_inset LatexCommand \index{Emacs}
28134 \begin_layout Standard
28135 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28136 sdcdb.el and sdcdbsrc.el.
28137 These two files can be found in the $(prefix)/bin directory after the installat
28139 These files need to be loaded into XEmacs for the interface to work.
28140 This can be done at XEmacs startup time by inserting the following into
28141 your '.xemacs' file (which can be found in your HOME directory):
28147 (load-file sdcdbsrc.el)
28153 .xemacs is a lisp file so the () around the command is REQUIRED.
28154 The files can also be loaded dynamically while XEmacs is running, set the
28155 environment variable 'EMACSLOADPATH' to the installation bin directory
28156 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28157 To start the interface enter the following command:
28171 You will prompted to enter the file name to be debugged.
28176 The command line options that are passed to the simulator directly are
28177 bound to default values in the file sdcdbsrc.el.
28178 The variables are listed below, these values maybe changed as required.
28181 \begin_layout Itemize
28182 sdcdbsrc-cpu-type '51
28185 \begin_layout Itemize
28186 sdcdbsrc-frequency '11059200
28189 \begin_layout Itemize
28190 sdcdbsrc-serial nil
28193 \begin_layout Standard
28194 The following is a list of key mapping for the debugger interface.
28197 \begin_layout Standard
28220 binding\InsetSpace ~
28258 -------\InsetSpace ~
28329 sdcdb-back-from-src\InsetSpace ~
28358 rom-src\InsetSpace ~
28368 SDCDB continue command
28386 sdcdb-step-from-src\InsetSpace ~
28415 hatis-c-sexp\InsetSpace ~
28425 SDCDB ptypecommand for data at
28492 sdcdbsrc-delete\InsetSpace ~
28507 B Delete all breakpoints if no arg
28556 given or delete arg (C-u arg x)
28575 -frame\InsetSpace ~
28590 SDCDB Display current frame if no arg,
28639 given or display frame arg
28707 sdcdbsrc-goto-sdcdb\InsetSpace ~
28717 Goto the SDCDB output buffer
28736 t-c-sexp\InsetSpace ~
28747 SDCDB print command for data at
28814 sdcdbsrc-goto-sdcdb\InsetSpace ~
28825 o the SDCDB output buffer
28843 sdcdbsrc-mode\InsetSpace ~
28859 Toggles Sdcdbsrc mode (turns it
28875 sdcdb-finish-from-src\InsetSpace ~
28883 SDCDB finish command
28917 Set break for line with point
28932 sdcdbsrc-mode\InsetSpace ~
28948 Toggle Sdcdbsrc mode
28964 dbsrc-srcmode\InsetSpace ~
28988 \begin_layout Chapter
28992 \begin_layout Standard
28993 Here are a few guidelines that will help the compiler generate more efficient
28994 code, some of the tips are specific to this compiler others are generally
28995 good programming practice.
28998 \begin_layout Itemize
28999 Use the smallest data type to represent your data-value.
29000 If it is known in advance that the value is going to be less than 256 then
29001 use an 'unsigned char' instead of a 'short' or 'int'.
29002 Please note, that ANSI C requires both signed and unsigned chars to be
29003 promoted to 'signed int'
29004 \begin_inset LatexCommand \index{promotion to signed int}
29009 \begin_inset Marginal
29012 \begin_layout Standard
29021 before doing any operation.
29023 \begin_inset LatexCommand \index{type promotion}
29028 \begin_inset LatexCommand \label{type promotion}
29032 can be omitted, if the result is the same.
29033 The effect of the promotion rules together with the sign-extension is often
29038 \begin_layout Verse
29041 unsigned char uc = 0xfe;
29043 if (uc * uc < 0) /* this is true! */
29056 \begin_layout Standard
29063 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29071 \begin_layout Verse
29074 (unsigned char) -12 / (signed char) -3 = ...
29077 \begin_layout Standard
29078 No, the result is not 4:
29081 \begin_layout Verse
29084 (int) (unsigned char) -12 / (int) (signed char) -3 =
29086 (int) (unsigned char)
29087 0xf4 / (int) (signed char) 0xfd =
29089 (int) 0x00f4 / (int) 0xfffd =
29094 (int) 244 / (int) -3 =
29096 (int) -81 = (int) 0xffaf;
29099 \begin_layout Standard
29100 Don't complain, that gcc gives you a different result.
29101 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29102 Therefore the results are different.
29105 \begin_inset Quotes sld
29109 \begin_inset Quotes srd
29115 \begin_layout Quote
29118 If well-defined overflow characteristics are important and negative values
29119 are not, or if you want to steer clear of sign-extension problems when
29120 manipulating bits or bytes, use one of the corresponding unsigned types.
29121 (Beware when mixing signed and unsigned values in expressions, though.)
29124 character types (especially unsigned char) can be used as "tiny" integers,
29125 doing so is sometimes more trouble than it's worth, due to unpredictable
29126 sign extension and increased code size.
29130 \begin_layout Itemize
29131 Use unsigned when it is known in advance that the value is not going to
29133 This helps especially if you are doing division or multiplication, bit-shifting
29134 or are using an array index.
29137 \begin_layout Itemize
29138 NEVER jump into a LOOP.
29141 \begin_layout Itemize
29142 Declare the variables to be local
29143 \begin_inset LatexCommand \index{local variables}
29147 whenever possible, especially loop control variables (induction).
29150 \begin_layout Itemize
29151 Have a look at the assembly listing to get a
29152 \begin_inset Quotes sld
29156 \begin_inset Quotes srd
29159 for the code generation.
29162 \begin_layout Section
29163 Porting code from or to other compilers
29164 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29171 \begin_layout Itemize
29172 check whether endianness of the compilers differs and adapt where needed.
29175 \begin_layout Itemize
29176 check the device specific header files
29177 \begin_inset LatexCommand \index{Header files}
29182 \begin_inset LatexCommand \index{Include files}
29186 for compiler specific syntax.
29187 Eventually include the file <compiler.h
29188 \begin_inset LatexCommand \index{compiler.h (include file)}
29193 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29197 to allow using common header files.
29200 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29207 \begin_layout Itemize
29208 check whether the startup code contains the correct initialization (watchdog,
29212 \begin_layout Itemize
29213 check whether the sizes of short, int, long match.
29216 \begin_layout Itemize
29217 check if some 16 or 32 bit hardware registers require a specific addressing
29218 order (least significant or most significant byte first) and adapt if needed
29227 relate to time and not to lower/upper memory location here, so this is
29232 the same as endianness).
29235 \begin_layout Itemize
29236 check whether the keyword
29240 is used where needed.
29241 The compilers might differ in their optimization characteristics (as different
29242 versions of the same compiler might also use more clever optimizations
29243 this is good idea anyway).
29245 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29252 \begin_layout Itemize
29253 check that the compilers are not told to supress warnings.
29256 \begin_layout Itemize
29257 check and convert compiler specific extensions (interrupts, memory areas,
29261 \begin_layout Itemize
29262 check for differences in type promotion.
29263 Especially check for math operations on
29272 For the sake of C99 compatibility SDCC will probably promote these to
29276 more often than other compilers.
29277 Eventually insert explicit casts to
29286 Also check that the ~\InsetSpace ~
29288 \begin_inset LatexCommand \index{\~\/ Operator}
29295 \begin_inset LatexCommand \index{bit}
29301 variables, use the !\InsetSpace ~
29304 \begin_inset LatexCommand \ref{type promotion}
29309 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29316 \begin_layout Itemize
29317 check the assembly code generated for interrupt routines (f.e.
29318 for calls to possibly non-reentrant library functions).
29321 \begin_layout Itemize
29322 check whether timing loops result in proper timing (or preferably consider
29323 a rewrite of the code with timer based delays instead).
29326 \begin_layout Itemize
29327 check for differences in printf parameters (some compilers push (va_arg
29328 \begin_inset LatexCommand \index{vararg, va\_arg}
29332 ) char variables as
29336 others push them as
29342 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29349 \begin_layout Itemize
29350 check the resulting memory map
29351 \begin_inset LatexCommand \index{Memory map}
29356 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29357 ly idata, pdata, xdata).
29358 Eventually check if unexpected library functions are included.
29361 \begin_layout Section
29363 \begin_inset LatexCommand \index{Tools}
29367 included in the distribution
29370 \begin_layout Standard
29372 \begin_inset Tabular
29373 <lyxtabular version="3" rows="12" columns="3">
29375 <column alignment="left" valignment="top" leftline="true" width="0pt">
29376 <column alignment="left" valignment="top" leftline="true" width="0pt">
29377 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29378 <row topline="true" bottomline="true">
29379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29382 \begin_layout Standard
29390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29393 \begin_layout Standard
29401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29404 \begin_layout Standard
29413 <row topline="true">
29414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29417 \begin_layout Standard
29419 \begin_inset LatexCommand \index{uCsim}
29428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29431 \begin_layout Standard
29432 Simulator for various architectures
29437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29440 \begin_layout Standard
29447 <row topline="true">
29448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29451 \begin_layout Standard
29457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29460 \begin_layout Standard
29462 \begin_inset LatexCommand \index{Header files}
29467 \begin_inset LatexCommand \index{Include files}
29476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29479 \begin_layout Standard
29480 sdcc/support/scripts
29486 <row topline="true">
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29490 \begin_layout Standard
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29499 \begin_layout Standard
29500 header file conversion
29505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29508 \begin_layout Standard
29509 sdcc/support/scripts
29515 <row topline="true">
29516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29519 \begin_layout Standard
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29528 \begin_layout Standard
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29537 \begin_layout Standard
29553 <row topline="true">
29554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29557 \begin_layout Standard
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29566 \begin_layout Standard
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29575 \begin_layout Standard
29591 <row topline="true">
29592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29595 \begin_layout Standard
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29604 \begin_layout Standard
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29613 \begin_layout Standard
29629 <row topline="true">
29630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29633 \begin_layout Standard
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29642 \begin_layout Standard
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29651 \begin_layout Standard
29667 <row topline="true">
29668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29671 \begin_layout Standard
29677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29680 \begin_layout Standard
29686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29689 \begin_layout Standard
29705 <row topline="true">
29706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29709 \begin_layout Standard
29715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29718 \begin_layout Standard
29724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29727 \begin_layout Standard
29743 <row topline="true">
29744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29747 \begin_layout Standard
29753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29756 \begin_layout Standard
29762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29765 \begin_layout Standard
29781 <row topline="true" bottomline="true">
29782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29785 \begin_layout Standard
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29794 \begin_layout Standard
29796 \begin_inset LatexCommand \index{packihx (tool)}
29805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29808 \begin_layout Standard
29833 \begin_layout Section
29835 \begin_inset LatexCommand \index{Documentation}
29839 included in the distribution
29842 \begin_layout Standard
29844 \begin_inset Tabular
29845 <lyxtabular version="3" rows="10" columns="2">
29847 <column alignment="block" valignment="top" leftline="true" width="40col%">
29848 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29849 <row topline="true" bottomline="true" endhead="true">
29850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29853 \begin_layout Standard
29861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29864 \begin_layout Standard
29867 Filename / Where to get
29873 <row topline="true">
29874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29877 \begin_layout Standard
29878 SDCC Compiler User Guide
29883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29886 \begin_layout Standard
29887 You're reading it right now
29899 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29909 <row topline="true">
29910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29913 \begin_layout Standard
29919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29922 \begin_layout Standard
29935 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29945 <row topline="true">
29946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29949 \begin_layout Standard
29951 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29956 \begin_inset LatexCommand \index{Assembler documentation}
29963 \begin_inset LatexCommand \index{aslink}
29968 \begin_inset LatexCommand \index{Linker documentation}
29977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29980 \begin_layout Standard
29981 sdcc/as/doc/asxhtm.html
29993 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30003 <row topline="true">
30004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30007 \begin_layout Standard
30008 SDCC regression test
30009 \begin_inset LatexCommand \index{Regression test}
30018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30021 \begin_layout Standard
30022 sdcc/doc/test_suite_spec.pdf
30034 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30044 <row topline="true">
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30048 \begin_layout Standard
30054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30057 \begin_layout Standard
30070 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30080 <row topline="true">
30081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30084 \begin_layout Standard
30085 Notes on debugging with SDCDB
30086 \begin_inset LatexCommand \index{SDCDB (debugger)}
30095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30098 \begin_layout Standard
30099 sdcc/debugger/README
30111 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30121 <row topline="true">
30122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30125 \begin_layout Standard
30127 \begin_inset LatexCommand \index{uCsim}
30131 Software simulator for microcontrollers
30136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30139 \begin_layout Standard
30169 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30179 <row topline="true">
30180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30183 \begin_layout Standard
30184 Temporary notes on the pic16
30185 \begin_inset LatexCommand \index{PIC16}
30194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30197 \begin_layout Standard
30198 sdcc/src/pic16/NOTES
30210 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30220 <row topline="true" bottomline="true">
30221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30224 \begin_layout Standard
30225 SDCC internal documentation (debugging file format)
30230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30233 \begin_layout Standard
30263 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30282 \begin_layout Section
30283 Related open source tools
30284 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30289 \begin_inset LatexCommand \index{Related tools}
30296 \begin_layout Standard
30298 \begin_inset Tabular
30299 <lyxtabular version="3" rows="14" columns="3">
30301 <column alignment="left" valignment="top" leftline="true" width="0pt">
30302 <column alignment="block" valignment="top" leftline="true" width="30line%">
30303 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30304 <row topline="true" bottomline="true">
30305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30308 \begin_layout Standard
30316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30319 \begin_layout Standard
30327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30330 \begin_layout Standard
30339 <row topline="true">
30340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30343 \begin_layout Standard
30345 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30357 \begin_layout Standard
30363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30366 \begin_layout Standard
30367 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30377 <row topline="true">
30378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30381 \begin_layout Standard
30383 \begin_inset LatexCommand \index{gputils (pic tools)}
30392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30395 \begin_layout Standard
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30404 \begin_layout Standard
30405 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30415 <row topline="true">
30416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30419 \begin_layout Standard
30425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30428 \begin_layout Standard
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30437 \begin_layout Standard
30438 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30448 <row topline="true">
30449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30452 \begin_layout Standard
30458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30461 \begin_layout Standard
30462 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30471 \begin_layout Standard
30472 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30482 <row topline="true">
30483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30486 \begin_layout Standard
30488 \begin_inset LatexCommand \index{indent (source formatting tool)}
30497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30500 \begin_layout Standard
30501 Formats C source - Master of the white spaces
30506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30509 \begin_layout Standard
30510 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30520 <row topline="true">
30521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30524 \begin_layout Standard
30526 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30538 \begin_layout Standard
30539 Object file conversion, checksumming, ...
30544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30547 \begin_layout Standard
30548 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30558 <row topline="true">
30559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30562 \begin_layout Standard
30564 \begin_inset LatexCommand \index{objdump (tool)}
30573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30576 \begin_layout Standard
30577 Object file conversion, ...
30582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30585 \begin_layout Standard
30586 Part of binutils (should be there anyway)
30592 <row topline="true">
30593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30596 \begin_layout Standard
30602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30605 \begin_layout Standard
30606 8051 monitor (hex up-/download, single step, disassemble)
30611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30614 \begin_layout Standard
30615 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30625 <row topline="true">
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30629 \begin_layout Standard
30631 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30643 \begin_layout Standard
30644 Source code documentation system
30649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30652 \begin_layout Standard
30653 \begin_inset LatexCommand \url{http://www.doxygen.org}
30663 <row topline="true">
30664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30667 \begin_layout Standard
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30676 \begin_layout Standard
30677 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30685 \begin_layout Standard
30686 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30696 <row topline="true">
30697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30700 \begin_layout Standard
30706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30709 \begin_layout Standard
30710 8051 monitor (hex up-/download, single step, disassemble)
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30718 \begin_layout Standard
30719 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30729 <row topline="true">
30730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30733 \begin_layout Standard
30735 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30747 \begin_layout Standard
30748 Statically checks c sources (see
30749 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30761 \begin_layout Standard
30762 \begin_inset LatexCommand \url{http://www.splint.org}
30772 <row topline="true" bottomline="true">
30773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30776 \begin_layout Standard
30778 \begin_inset LatexCommand \index{DDD (debugger)}
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30790 \begin_layout Standard
30791 Debugger, serves nicely as GUI to SDCDB
30792 \begin_inset LatexCommand \index{SDCDB (debugger)}
30801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30804 \begin_layout Standard
30805 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30824 \begin_layout Section
30825 Related documentation / recommended reading
30828 \begin_layout Standard
30830 \begin_inset Tabular
30831 <lyxtabular version="3" rows="7" columns="3">
30833 <column alignment="left" valignment="top" leftline="true" width="0pt">
30834 <column alignment="left" valignment="top" leftline="true" width="0">
30835 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30836 <row topline="true" bottomline="true">
30837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30840 \begin_layout Standard
30848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30851 \begin_layout Standard
30859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30862 \begin_layout Standard
30871 <row topline="true">
30872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30875 \begin_layout Standard
30890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30893 \begin_layout Standard
30895 \begin_inset LatexCommand \index{C Reference card}
30904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30907 \begin_layout Standard
30908 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30918 <row topline="true">
30919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30922 \begin_layout Standard
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30931 \begin_layout Standard
30933 \begin_inset LatexCommand \index{C FAQ}
30942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30945 \begin_layout Standard
30946 \begin_inset LatexCommand \url{http://www.c-faq.com}
30956 <row topline="true">
30957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30960 \begin_layout Standard
30966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30969 \begin_layout Standard
30970 \begin_inset Quotes sld
30974 \begin_inset Quotes srd
30982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30985 \begin_layout Standard
30988 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30998 <row topline="true">
30999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31002 \begin_layout Standard
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31011 \begin_layout Standard
31012 \begin_inset Quotes sld
31015 Extensions for Embedded C
31016 \begin_inset Quotes srd
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31027 \begin_layout Standard
31030 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31040 <row topline="true">
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31044 \begin_layout Standard
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31053 \begin_layout Standard
31054 Latest datasheet of target CPU
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31062 \begin_layout Standard
31069 <row topline="true" bottomline="true">
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31073 \begin_layout Standard
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31082 \begin_layout Standard
31083 Revision history of datasheet
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31091 \begin_layout Standard
31107 \begin_layout Section
31108 Application notes specifically for SDCC
31111 \begin_layout Standard
31112 SDCC makes no claims about the completeness of this list and about up-to-datenes
31113 s or correctness of the application notes
31114 \begin_inset LatexCommand \index{Application notes}
31121 \begin_layout Standard
31125 \begin_inset Tabular
31126 <lyxtabular version="3" rows="7" columns="3">
31128 <column alignment="block" valignment="top" leftline="true" width="17col%">
31129 <column alignment="block" valignment="top" leftline="true" width="27col%">
31130 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31131 <row topline="true" bottomline="true">
31132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31135 \begin_layout Standard
31144 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31147 \begin_layout Standard
31156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31159 \begin_layout Standard
31169 <row topline="true">
31170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31173 \begin_layout Standard
31181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31184 \begin_layout Standard
31187 Using the SDCC Compiler for the DS80C400
31188 \begin_inset LatexCommand \index{DS80C400}
31197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31200 \begin_layout Standard
31203 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31213 <row topline="true">
31214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31217 \begin_layout Standard
31225 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31228 \begin_layout Standard
31231 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31232 \begin_inset LatexCommand \index{DS89C4x0}
31236 Family of Microcontrollers
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31244 \begin_layout Standard
31247 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31257 <row topline="true">
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31261 \begin_layout Standard
31264 Silicon Laboratories / Cygnal
31269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31272 \begin_layout Standard
31275 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31276 \begin_inset LatexCommand \index{IDE}
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31288 \begin_layout Standard
31291 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31301 <row topline="true">
31302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31305 \begin_layout Standard
31308 Ramtron / Goal Semiconductor
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31316 \begin_layout Standard
31319 Interfacing SDCC to Syn and Textpad
31324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31327 \begin_layout Standard
31330 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31340 <row topline="true">
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31344 \begin_layout Standard
31347 Ramtron / Goal Semiconductor
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31355 \begin_layout Standard
31358 Installing and Configuring SDCC and Crimson Editor
31363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31366 \begin_layout Standard
31369 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31379 <row topline="true" bottomline="true">
31380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31383 \begin_layout Standard
31391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31394 \begin_layout Standard
31397 MSC12xx Programming with SDCC
31402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31405 \begin_layout Standard
31408 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31425 \begin_layout Section
31429 \begin_layout Standard
31430 Some questions answered, some pointers given - it might be time to in turn
31438 \begin_layout Itemize
31439 can you solve your project with the selected microcontroller? Would you
31440 find out early or rather late that your target is too small/slow/whatever?
31441 Can you switch to a slightly better device if it doesn't fit?
31444 \begin_layout Itemize
31445 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31446 and/or another programming language be more adequate? Would an operating
31447 system on the target device help?
31450 \begin_layout Itemize
31451 if you solved the problem, will the marketing department be happy?
31454 \begin_layout Itemize
31455 if the marketing department is happy, will customers be happy?
31458 \begin_layout Itemize
31459 if you're the project manager, marketing department and maybe even the customer
31460 in one person, have you tried to see the project from the outside?
31463 \begin_layout Itemize
31464 is the project done if you think it is done? Or is just that other interface/pro
31465 tocol/feature/configuration/option missing? How about website, manual(s),
31466 internationali(z|s)ation, packaging, labels, 2nd source for components,
31467 electromagnetic compatability/interference, documentation for production,
31468 production test software, update mechanism, patent issues?
31471 \begin_layout Itemize
31472 is your project adequately positioned in that magic triangle: fame, fortune,
31476 \begin_layout Standard
31477 Maybe not all answers to these questions are known and some answers may
31482 , nevertheless knowing these questions may help you to avoid burnout
31486 \begin_layout Standard
31487 burnout is bad for electronic devices, programmers and motorcycle tyres
31493 Chances are you didn't want to hear some of them...
31496 \begin_layout Chapter
31498 \begin_inset LatexCommand \index{Support}
31505 \begin_layout Standard
31506 SDCC has grown to be a large project.
31507 The compiler alone (without the preprocessor, assembler and linker) is
31508 well over 150,000 lines of code (blank stripped).
31509 The open source nature of this project is a key to its continued growth
31511 You gain the benefit and support of many active software developers and
31513 Is SDCC perfect? No, that's why we need your help.
31514 The developers take pride in fixing reported bugs.
31515 You can help by reporting the bugs and helping other SDCC users.
31516 There are lots of ways to contribute, and we encourage you to take part
31517 in making SDCC a great software package.
31521 \begin_layout Standard
31522 The SDCC project is hosted on the SDCC sourceforge site at
31523 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31528 You'll find the complete set of mailing lists
31529 \begin_inset LatexCommand \index{Mailing list(s)}
31533 , forums, bug reporting system, patch submission
31534 \begin_inset LatexCommand \index{Patch submission}
31539 \begin_inset LatexCommand \index{download}
31543 area and Subversion code repository
31544 \begin_inset LatexCommand \index{Subversion code repository}
31551 \begin_layout Section
31553 \begin_inset LatexCommand \index{Bug reporting}
31558 \begin_inset LatexCommand \index{Reporting bugs}
31565 \begin_layout Standard
31566 The recommended way of reporting bugs is using the infrastructure of the
31568 You can follow the status of bug reports there and have an overview about
31572 \begin_layout Standard
31573 Bug reports are automatically forwarded to the developer mailing list and
31574 will be fixed ASAP.
31575 When reporting a bug, it is very useful to include a small test program
31576 (the smaller the better) which reproduces the problem.
31577 If you can isolate the problem by looking at the generated assembly code,
31578 this can be very helpful.
31579 Compiling your program with the -
31583 \begin_layout Standard
31593 \begin_inset LatexCommand \index{-\/-dumpall}
31597 option can sometimes be useful in locating optimization problems.
31598 When reporting a bug please make sure you:
31601 \begin_layout Enumerate
31602 Attach the code you are compiling with SDCC.
31606 \begin_layout Enumerate
31607 Specify the exact command you use to run SDCC, or attach your Makefile.
31611 \begin_layout Enumerate
31612 Specify the SDCC version (type "
31618 "), your platform, and operating system.
31622 \begin_layout Enumerate
31623 Provide an exact copy of any error message or incorrect output.
31627 \begin_layout Enumerate
31628 Put something meaningful in the subject of your message.
31631 \begin_layout Standard
31632 Please attempt to include these 5 important parts, as applicable, in all
31633 requests for support or when reporting any problems or bugs with SDCC.
31634 Though this will make your message lengthy, it will greatly improve your
31635 chance that SDCC users and developers will be able to help you.
31636 Some SDCC developers are frustrated by bug reports without code provided
31637 that they can use to reproduce and ultimately fix the problem, so please
31638 be sure to provide sample code if you are reporting a bug!
31641 \begin_layout Standard
31642 Please have a short check that you are using a recent version of SDCC and
31643 the bug is not yet known.
31644 This is the link for reporting bugs:
31645 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31650 With SDCC on average having more than 200 downloads
31651 \begin_inset LatexCommand \index{download}
31655 on sourceforge per day
31659 \begin_layout Standard
31660 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31661 between 2002 and 2005.
31662 This does not include other methods of distribution.
31667 there must be some users.
31668 So it's not exactly easy to find a new bug.
31669 If you find one we need it:
31671 reporting bugs is good
31676 \begin_layout Section
31677 Requesting Features
31678 \begin_inset LatexCommand \label{sub:Requesting-Features}
31683 \begin_inset LatexCommand \index{Feature request}
31688 \begin_inset LatexCommand \index{Requesting features}
31695 \begin_layout Standard
31696 Like bug reports feature requests are forwarded to the developer mailing
31698 This is the link for requesting features:
31699 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31706 \begin_layout Section
31710 \begin_layout Standard
31711 Like bug reports contributed patches are forwarded to the developer mailing
31713 This is the link for submitting patches
31714 \begin_inset LatexCommand \index{Patch submission}
31719 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31726 \begin_layout Standard
31727 You need to specify some parameters to the
31731 command for the patches to be useful.
31732 If you modified more than one file a patch created f.e.
31737 \begin_inset Quotes sld
31740 diff -Naur unmodified_directory modified_directory >my_changes.patch
31741 \begin_inset Quotes srd
31747 will be fine, otherwise
31751 \begin_inset Quotes sld
31754 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31755 \begin_inset Quotes srd
31765 \begin_layout Section
31769 \begin_layout Standard
31770 These links should take you directly to the
31771 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31779 \begin_layout Standard
31780 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31781 automated messages (mid 2003)
31787 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31792 \begin_inset LatexCommand \index{Mailing list(s)}
31796 and forums are archived and searchable so if you are lucky someone already
31797 had a similar problem.
31798 While mails to the lists themselves are delivered promptly their web front
31799 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31800 if you're seriously using SDCC please consider subscribing to the lists.
31803 \begin_layout Section
31807 \begin_layout Standard
31808 You can follow the status of the Subversion version
31809 \begin_inset LatexCommand \index{version}
31813 of SDCC by watching the Changelog
31814 \begin_inset LatexCommand \index{Changelog}
31818 in the Subversion repository
31821 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31828 \begin_layout Section
31829 Subversion Source Code Repository
31832 \begin_layout Standard
31839 or the filenames of the snapshot versions of SDCC include date and its
31841 \begin_inset LatexCommand \index{Subversion code repository}
31846 Subversion allows to download the source of recent or previous versions
31848 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31852 (by number or by date).
31853 An on-line source code browser and detailled instructions are also available
31855 SDCC versions starting from 1999 up to now are available (currently the
31856 versions prior to the conversion from cvs
31857 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31861 to Subversion (April 2006) are either by accessible by Subversion or by
31865 \begin_layout Section
31867 \begin_inset LatexCommand \index{Release policy}
31874 \begin_layout Standard
31875 Historically there often were long delays between official releases and
31876 the sourceforge download area tends to get not updated at all.
31877 Excuses in the past might have referred to problems with live range analysis,
31878 but as this was fixed a while ago, the current problem is that another
31879 excuse has to be found.
31880 Kidding aside, we have to get better there! On the other hand there are
31881 daily snapshots available at
31882 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31886 , and you can always build the very last version (hopefully with many bugs
31887 fixed, and features added) from the source code available at
31888 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31894 \begin_inset LatexCommand \index{wiki}
31899 \begin_inset LatexCommand \index{Release wiki}
31904 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31908 also holds some information about past and future releases.
31911 \begin_layout Section
31913 \begin_inset LatexCommand \index{Examples}
31920 \begin_layout Standard
31921 You'll find some small examples in the directory
31923 sdcc/device/examples/.
31926 More examples and libraries are available at
31928 The SDCC Open Knowledge Resource
31929 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31936 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31943 \begin_layout Standard
31944 \begin_inset Note Note
31947 \begin_layout Standard
31948 I did insert a reference to Paul's web site here although it seems rather
31949 dedicated to a specific 8032 board (I think it's okay because it f.e.
31950 shows LCD/Harddisc interface and has a free 8051 monitor.
31951 Independent 8032 board vendors face hard competition of heavily subsidized
31952 development boards anyway).
31955 \begin_layout Standard
31956 Maybe we should include some links to real world applications.
31957 Preferably pointer to pointers (one for each architecture) so this stays
31966 \begin_layout Section
31968 \begin_inset LatexCommand \label{sec:Quality-control}
31973 \begin_inset LatexCommand \index{Quality control}
31980 \begin_layout Standard
31981 The compiler is passed through snaphot build compile and build checks.
31987 \begin_inset LatexCommand \index{Regression test}
31991 check that SDCC itself compiles flawlessly on several host platforms (i386,
31992 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
31993 the quality of the code generated by SDCC by running the code for several
31994 target platforms through simulators.
31995 The regression test suite comprises more than 100 files which expand to
31996 more than 500 test cases which include more than 4500 tests.
31997 The results of these tests are published daily on SDCC's snapshot page
31998 (click on the red or green symbols on the right side of
31999 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32006 \begin_layout Standard
32007 There is a separate document
32010 \begin_inset LatexCommand \index{Test suite}
32017 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32021 about the regression test suite.
32024 \begin_layout Standard
32025 You'll find the test code in the directory
32027 sdcc/support/regression
32030 You can run these tests manually by running
32034 in this directory (or f.e.
32039 \begin_inset Quotes sld
32043 \begin_inset Quotes srd
32049 if you don't want to run the complete tests).
32050 The test code might also be interesting if you want to look for examples
32051 \begin_inset LatexCommand \index{Examples}
32055 checking corner cases of SDCC or if you plan to submit patches
32056 \begin_inset LatexCommand \index{Patch submission}
32063 \begin_layout Standard
32064 The 14bit pic port uses a different set of regression tests
32065 \begin_inset LatexCommand \index{Regression test (PIC14)}
32069 , you'll find them in the directory
32071 sdcc/src/regression
32076 \begin_layout Section
32077 Use of SDCC in Education
32080 \begin_layout Standard
32089 \begin_layout Standard
32090 the phrase "use in education" might evoke the association "
32094 fit for use in education".
32095 This connotation is not intended but nevertheless risked as the licensing
32096 of SDCC makes it difficult to offer educational discounts
32102 If your rationales are to:
32105 \begin_layout Enumerate
32106 give students a chance to understand the
32110 steps of code generation
32113 \begin_layout Enumerate
32114 have a curriculum that can be extended for years.
32115 Then you could use an fpga board as target and your curriculum will seamlessly
32116 extend from logic synthesis (
32117 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32122 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32126 ), over assembly programming, to C to FPGA compilers (
32127 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32134 \begin_layout Enumerate
32135 be able to insert excursions about skills like using a revision control
32136 system, submitting/applying patches, using a type-setting (as opposed to
32137 word-processing) engine LyX/LaTeX, using
32138 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32143 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32147 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32148 Source Software, CPU simulation, compiler regression tests
32149 \begin_inset LatexCommand \index{Regression test}
32156 And if there should be a shortage of ideas then you can always point students
32157 to the ever-growing feature request list
32158 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32165 \begin_layout Enumerate
32166 not tie students to a specific host platform and instead allow them to use
32171 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32173 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32180 \begin_layout Enumerate
32181 not encourage students to use illegal copies of educational software
32184 \begin_layout Enumerate
32185 be immune to licensing/availability/price changes of the chosen tool chain
32188 \begin_layout Enumerate
32189 be able to change to a new target platform without having to adopt a new
32193 \begin_layout Enumerate
32194 have complete control over and insight into the tool chain
32197 \begin_layout Enumerate
32198 make your students aware about the pros and cons of open source software
32202 \begin_layout Enumerate
32203 give back to the public as you are probably at least partially publically
32207 \begin_layout Enumerate
32208 give students a chance to publically prove their skills and to possibly
32209 see a world wide impact
32212 \begin_layout Standard
32213 then SDCC is probably among the first choices.
32214 Well, probably SDCC might be the only choice.
32219 \begin_layout Chapter
32220 SDCC Technical Data
32223 \begin_layout Section
32225 \begin_inset LatexCommand \index{Optimizations}
32232 \begin_layout Standard
32233 SDCC performs a host of standard optimizations in addition to some MCU specific
32238 \begin_layout Subsection
32239 Sub-expression Elimination
32240 \begin_inset LatexCommand \index{Subexpression elimination}
32247 \begin_layout Standard
32248 The compiler does local and
32267 \begin_layout Verse
32275 \begin_layout Standard
32276 will be translated to
32279 \begin_layout Verse
32289 \begin_layout Standard
32290 Some subexpressions are not as obvious as the above example, e.g.:
32293 \begin_layout Verse
32301 \begin_layout Standard
32302 In this case the address arithmetic a->b[i] will be computed only once;
32303 the equivalent code in C would be.
32306 \begin_layout Verse
32316 \begin_layout Standard
32317 The compiler will try to keep these temporary variables in registers.
32320 \begin_layout Subsection
32321 Dead-Code Elimination
32322 \begin_inset LatexCommand \index{Dead-code elimination}
32329 \begin_layout Verse
32344 i = 1; \InsetSpace ~
32353 global = 1;\InsetSpace ~
32367 global = 3;\InsetSpace ~
32373 \begin_layout Standard
32377 \begin_layout Verse
32393 \begin_layout Subsection
32395 \begin_inset LatexCommand \index{Copy propagation}
32402 \begin_layout Verse
32426 \begin_layout Standard
32430 \begin_layout Verse
32454 \begin_layout Standard
32455 Note: the dead stores created by this copy propagation will be eliminated
32456 by dead-code elimination.
32459 \begin_layout Subsection
32461 \begin_inset LatexCommand \index{Loop optimization}
32466 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32473 \begin_layout Standard
32474 Two types of loop optimizations are done by SDCC
32482 of loop induction variables.
32483 In addition to the strength reduction the optimizer marks the induction
32484 variables and the register allocator tries to keep the induction variables
32485 in registers for the duration of the loop.
32486 Because of this preference of the register allocator
32487 \begin_inset LatexCommand \index{Register allocation}
32491 , loop induction optimization causes an increase in register pressure, which
32492 may cause unwanted spilling of other temporary variables into the stack
32493 \begin_inset LatexCommand \index{stack}
32498 The compiler will generate a warning message when it is forced to allocate
32499 extra space either on the stack or data space.
32500 If this extra space allocation is undesirable then induction optimization
32501 can be eliminated either for the entire source file (with -
32505 \begin_layout Standard
32514 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32516 \begin_inset LatexCommand \index{\#pragma noinduction}
32527 \begin_layout Verse
32530 for (i = 0 ; i < 100 ; i ++)
32539 \begin_layout Standard
32543 \begin_layout Verse
32548 for (i = 0; i < 100; i++)
32557 \begin_layout Standard
32558 As mentioned previously some loop invariants are not as apparent, all static
32559 address computations are also moved out of the loop.
32564 \begin_inset LatexCommand \index{Strength reduction}
32568 , this optimization substitutes an expression by a cheaper expression:
32571 \begin_layout Verse
32574 for (i=0;i < 100; i++)
32583 \begin_layout Standard
32587 \begin_layout Verse
32594 for (i=0;i< 100;i++) {
32600 ar[itemp1] = itemp2;
32618 \begin_layout Standard
32619 The more expensive multiplication
32620 \begin_inset LatexCommand \index{Multiplication}
32624 is changed to a less expensive addition.
32627 \begin_layout Subsection
32629 \begin_inset LatexCommand \index{Loop reversing}
32636 \begin_layout Standard
32637 This optimization is done to reduce the overhead of checking loop boundaries
32638 for every iteration.
32639 Some simple loops can be reversed and implemented using a
32640 \begin_inset Quotes eld
32643 decrement and jump if not zero
32644 \begin_inset Quotes erd
32648 SDCC checks for the following criterion to determine if a loop is reversible
32649 (note: more sophisticated compilers use data-dependency analysis to make
32650 this determination, SDCC uses a more simple minded analysis).
32653 \begin_layout Itemize
32654 The 'for' loop is of the form
32660 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32670 \begin_layout Itemize
32671 The <for body> does not contain
32672 \begin_inset Quotes eld
32676 \begin_inset Quotes erd
32680 \begin_inset Quotes erd
32686 \begin_layout Itemize
32687 All goto's are contained within the loop.
32690 \begin_layout Itemize
32691 No function calls within the loop.
32694 \begin_layout Itemize
32695 The loop control variable <sym> is not assigned any value within the loop
32698 \begin_layout Itemize
32699 The loop control variable does NOT participate in any arithmetic operation
32703 \begin_layout Itemize
32704 There are NO switch statements in the loop.
32707 \begin_layout Subsection
32708 Algebraic Simplifications
32711 \begin_layout Standard
32712 SDCC does numerous algebraic simplifications, the following is a small sub-set
32713 of these optimizations.
32716 \begin_layout Verse
32719 i = j + 0;\InsetSpace ~
32723 /* changed to: */\InsetSpace ~
32729 i /= 2;\InsetSpace ~
32736 /* changed to: */\InsetSpace ~
32743 = j - j;\InsetSpace ~
32747 /* changed to: */\InsetSpace ~
32753 i = j / 1;\InsetSpace ~
32757 /* changed to: */\InsetSpace ~
32764 \begin_layout Standard
32765 Note the subexpressions
32766 \begin_inset LatexCommand \index{Subexpression}
32770 given above are generally introduced by macro expansions or as a result
32771 of copy/constant propagation.
32774 \begin_layout Subsection
32775 'switch' Statements
32776 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32781 \begin_inset LatexCommand \index{switch statement}
32788 \begin_layout Standard
32789 SDCC can optimize switch statements to jump tables
32790 \begin_inset LatexCommand \index{jump tables}
32795 It makes the decision based on an estimate of the generated code size.
32796 SDCC is quite liberal in the requirements for jump table generation:
32799 \begin_layout Itemize
32800 The labels need not be in order, and the starting number need not be one
32801 or zero, the case labels are in numerical sequence or not too many case
32802 labels are missing.
32806 \begin_layout Verse
32809 switch(i) {\InsetSpace ~
32840 case 4: ...\InsetSpace ~
32872 case 5: ...\InsetSpace ~
32904 case 3: ...\InsetSpace ~
32935 case 6: ...\InsetSpace ~
32967 case 7: ...\InsetSpace ~
32999 case 8: ...\InsetSpace ~
33031 case 9: ...\InsetSpace ~
33063 case 10: ...\InsetSpace ~
33094 case 11: ...\InsetSpace ~
33161 \begin_layout Standard
33162 Both the above switch statements will be implemented using a jump-table.
33163 The example to the right side is slightly more efficient as the check for
33164 the lower boundary of the jump-table is not needed.
33168 \begin_layout Itemize
33169 The number of case labels is not larger than supported by the target architectur
33173 \begin_layout Itemize
33174 If the case labels are not in numerical sequence ('gaps' between cases)
33175 SDCC checks whether a jump table with additionally inserted dummy cases
33176 is still attractive.
33180 \begin_layout Itemize
33181 If the starting number is not zero and a check for the lower boundary of
33182 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33187 \begin_layout Standard
33188 Switch statements which have large gaps in the numeric sequence or those
33189 that have too many case labels can be split into more than one switch statement
33190 for efficient code generation, e.g.:
33193 \begin_layout Verse
33271 \begin_layout Standard
33272 If the above switch statement is broken down into two switch statements
33275 \begin_layout Verse
33318 \begin_layout Standard
33322 \begin_layout Verse
33365 \begin_layout Standard
33366 then both the switch statements will be implemented using jump-tables whereas
33367 the unmodified switch statement will not be.
33370 \begin_layout Standard
33371 \begin_inset Note Note
33374 \begin_layout Standard
33375 There might be reasons which SDCC cannot know about to either favour or
33376 not favour jump tables.
33377 If the target system has to be as quick for the last switch case as for
33378 the first (pro jump table), or if the switch argument is known to be zero
33379 in the majority of the cases (contra jump table).
33387 \begin_layout Standard
33388 The pragma nojtbound
33389 \begin_inset LatexCommand \index{\#pragma nojtbound}
33393 can be used to turn off checking the
33406 It has no effect if a default label is supplied.
33407 Use of this pragma is dangerous: if the switch
33408 \begin_inset LatexCommand \index{switch statement}
33412 argument is not matched by a case statement the processor will happily
33416 \begin_layout Subsection
33417 Bit-shifting Operations
33418 \begin_inset LatexCommand \index{Bit shifting}
33425 \begin_layout Standard
33426 Bit shifting is one of the most frequently used operation in embedded programmin
33428 SDCC tries to implement bit-shift operations in the most efficient way
33432 \begin_layout Verse
33445 \begin_layout Standard
33446 generates the following code:
33449 \begin_layout Verse
33464 \begin_layout Standard
33465 In general SDCC will never setup a loop if the shift count is known.
33469 \begin_layout Verse
33482 \begin_layout Standard
33486 \begin_layout Verse
33510 \begin_layout Subsection
33512 \begin_inset LatexCommand \index{Bit rotation}
33519 \begin_layout Standard
33520 A special case of the bit-shift operation is bit rotation
33521 \begin_inset LatexCommand \index{rotating bits}
33525 , SDCC recognizes the following expression to be a left bit-rotation:
33528 \begin_layout Verse
33536 char i;\InsetSpace ~
33547 /* unsigned is needed for rotation */
33552 i = ((i << 1) | (i >> 7));
33561 \begin_layout Standard
33562 will generate the following code:
33565 \begin_layout Verse
33582 \begin_layout Standard
33583 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33584 ns of this case will also be recognized as bit-rotation, i.e.:
33587 \begin_layout Verse
33590 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33593 \begin_layout Subsection
33594 Nibble and Byte Swapping
33597 \begin_layout Standard
33598 Other special cases of the bit-shift operations are nibble or byte swapping
33599 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33603 , SDCC recognizes the following expressions:
33606 \begin_layout Verse
33627 i = ((i << 4) | (i >> 4));
33633 j = ((j << 8) | (j >> 8));
33636 \begin_layout Standard
33637 and generates a swap instruction for the nibble swapping
33638 \begin_inset LatexCommand \index{Nibble swapping}
33642 or move instructions for the byte swapping
33643 \begin_inset LatexCommand \index{Byte swapping}
33649 \begin_inset Quotes sld
33653 \begin_inset Quotes srd
33656 example can be used to convert from little to big-endian or vice versa.
33657 If you want to change the endianness of a
33661 integer you have to cast to
33668 \begin_layout Standard
33669 Note that SDCC stores numbers in little-endian
33673 \begin_layout Standard
33674 Usually 8-bit processors don't care much about endianness.
33675 This is not the case for the standard 8051 which only has an instruction
33681 \begin_inset LatexCommand \index{DPTR}
33689 so little-endian is the more efficient byte order.
33695 \begin_inset LatexCommand \index{little-endian}
33700 \begin_inset LatexCommand \index{Endianness}
33705 lowest order first).
33708 \begin_layout Subsection
33710 \begin_inset LatexCommand \index{Highest Order Bit}
33715 \begin_inset LatexCommand \index{Any Order Bit}
33722 \begin_layout Standard
33723 It is frequently required to obtain the highest order bit of an integral
33724 type (long, int, short or char types).
33725 Also obtaining any other order bit is not uncommon.
33726 SDCC recognizes the following expressions to yield the highest order bit
33727 and generates optimized code for it, e.g.:
33730 \begin_layout Verse
33741 unsigned char hob1, aob1;
33745 bit hob2, hob3, aob2,
33755 hob1 = (gint >> 15) & 1;
33759 hob2 = (gint >> 15) & 1;
33763 hob3 = gint & 0x8000;
33768 aob1 = (gint >> 9) & 1;
33772 aob2 = (gint >> 8) & 1;
33776 aob3 = gint & 0x0800;
33786 \begin_layout Standard
33787 will generate the following code:
33790 \begin_layout Verse
33821 000A E5*01\InsetSpace ~
33848 000C 23\InsetSpace ~
33879 000D 54 01\InsetSpace ~
33907 000F F5*02\InsetSpace ~
33962 0011 E5*01\InsetSpace ~
33990 0013 33\InsetSpace ~
34020 0014 92*00\InsetSpace ~
34076 0016 E5*01\InsetSpace ~
34103 0018 33\InsetSpace ~
34133 0019 92*01\InsetSpace ~
34189 001B E5*01\InsetSpace ~
34248 001E 54 01\InsetSpace ~
34275 0020 F5*03\InsetSpace ~
34331 0022 E5*01\InsetSpace ~
34358 0024 13\InsetSpace ~
34388 0025 92*02\InsetSpace ~
34444 0027 E5*01\InsetSpace ~
34499 002B 92*03\InsetSpace ~
34527 \begin_layout Standard
34528 Other variations of these cases however will
34533 They are standard C expressions, so I heartily recommend these be the only
34534 way to get the highest order bit, (it is portable).
34535 Of course it will be recognized even if it is embedded in other expressions,
34539 \begin_layout Verse
34542 xyz = gint + ((gint >> 15) & 1);
34545 \begin_layout Standard
34546 will still be recognized.
34549 \begin_layout Subsection
34551 \begin_inset LatexCommand \index{Higher Order Byte}
34555 / Higher Order Word
34556 \begin_inset LatexCommand \index{Higher Order Word}
34563 \begin_layout Standard
34564 It is also frequently required to obtain a higher order byte or word of
34565 a larger integral type (long, int or short types).
34566 SDCC recognizes the following expressions to yield the higher order byte
34567 or word and generates optimized code for it, e.g.:
34570 \begin_layout Verse
34575 unsigned long int glong;
34583 unsigned char hob1,
34588 unsigned int how1, how2;
34597 hob1 = (gint >> 8) & 0xFF;
34601 hob2 = glong >> 24;
34605 how1 = (glong >> 16) & 0xFFFF;
34620 \begin_layout Standard
34621 will generate the following code:
34624 \begin_layout Verse
34655 0037 85*01*06\InsetSpace ~
34677 _foo_hob1_1_1,(_gint + 1)
34708 003A 85*05*07\InsetSpace ~
34730 _foo_hob2_1_1,(_glong + 3)
34760 003D 85*04*08\InsetSpace ~
34783 _foo_how1_1_1,(_glong + 2)
34785 0040 85*05*09\InsetSpace ~
34810 0043 85*03*0A\InsetSpace ~
34832 _foo_how2_1_1,(_glong + 1)
34834 0046 85*04*0B\InsetSpace ~
34857 (_foo_how2_1_1 + 1),(_glong + 2)
34860 \begin_layout Standard
34861 Again, variations of these cases may
34866 They are standard C expressions, so I heartily recommend these be the only
34867 way to get the higher order byte/word, (it is portable).
34868 Of course it will be recognized even if it is embedded in other expressions,
34872 \begin_layout Verse
34875 xyz = gint + ((gint >> 8) & 0xFF);
34878 \begin_layout Standard
34879 will still be recognized.
34882 \begin_layout Subsection
34884 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34889 \begin_inset LatexCommand \index{Peephole optimizer}
34896 \begin_layout Standard
34897 The compiler uses a rule based, pattern matching and re-writing mechanism
34898 for peep-hole optimization.
34903 a peep-hole optimizer by Christopher W.
34904 Fraser (cwfraser\InsetSpace ~
34907 A default set of rules are compiled into the compiler, additional rules
34908 may be added with the
34914 \begin_layout Standard
34924 \begin_inset LatexCommand \index{-\/-peep-file}
34931 The rule language is best illustrated with examples.
34934 \begin_layout Verse
34956 \begin_layout Standard
34957 The above rule will change the following assembly
34958 \begin_inset LatexCommand \index{Assembler routines}
34965 \begin_layout Verse
34973 \begin_layout Standard
34977 \begin_layout Verse
34983 \begin_layout Standard
34984 Note: All occurrences of a
34988 (pattern variable) must denote the same string.
34989 With the above rule, the assembly sequence:
34992 \begin_layout Verse
35000 \begin_layout Standard
35001 will remain unmodified.
35005 Other special case optimizations may be added by the
35012 \begin_layout Standard
35025 some variants of the 8051 MCU
35026 \begin_inset LatexCommand \index{MCS51 variants}
35039 The following two rules will change all
35056 \begin_layout Verse
35059 replace { lcall %1 } by { acall %1 }
35061 replace { ljmp %1 } by { ajmp %1 }
35064 \begin_layout Standard
35067 inline-assembler code
35069 is also passed through the peep hole optimizer, thus the peephole optimizer
35070 can also be used as an assembly level macro expander.
35071 The rules themselves are MCU dependent whereas the rule language infra-structur
35072 e is MCU independent.
35073 Peephole optimization rules for other MCU can be easily programmed using
35078 The syntax for a rule is as follows:
35081 \begin_layout Verse
35084 rule := replace [ restart ] '{' <assembly sequence> '
35122 <assembly sequence> '
35140 '}' [if <functionName> ] '
35145 \begin_layout Standard
35146 <assembly sequence> := assembly instruction (each instruction including
35147 labels must be on a separate line).
35151 The optimizer will apply to the rules
35152 one by one from the top in the sequence of their appearance, it will terminate
35153 when all rules are exhausted.
35154 If the 'restart' option is specified, then the optimizer will start matching
35155 the rules again from the top, this option for a rule is expensive (performance)
35156 , it is intended to be used in situations where a transformation will trigger
35157 the same rule again.
35158 An example of this (not a good one, it has side effects) is the following
35162 \begin_layout Verse
35182 \begin_layout Standard
35183 Note that the replace pattern cannot be a blank, but can be a comment line.
35184 Without the 'restart' option only the innermost 'pop' 'push' pair would
35185 be eliminated, i.e.:
35188 \begin_layout Verse
35200 \begin_layout Standard
35204 \begin_layout Verse
35214 \begin_layout Standard
35219 the restart option the rule will be applied again to the resulting code
35220 and then all the pop-push pairs will be eliminated to yield:
35223 \begin_layout Verse
35231 \begin_layout Standard
35232 A conditional function can be attached to a rule.
35233 Attaching rules are somewhat more involved, let me illustrate this with
35237 \begin_layout Verse
35261 \begin_layout Standard
35262 The optimizer does a look-up of a function name table defined in function
35267 in the source file SDCCpeeph.c, with the name
35272 If it finds a corresponding entry the function is called.
35273 Note there can be no parameters specified for these functions, in this
35278 is crucial, since the function
35282 expects to find the label in that particular variable (the hash table containin
35283 g the variable bindings is passed as a parameter).
35284 If you want to code more such functions, take a close look at the function
35285 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35286 Currently implemented are
35288 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35289 24bitMode, portIsDS390, 24bitModeAndPortDS390
35298 \begin_layout Standard
35299 I know this whole thing is a little kludgey, but maybe some day we will
35300 have some better means.
35301 If you are looking at this file, you will see the default rules that are
35302 compiled into the compiler, you can add your own rules in the default set
35303 there if you get tired of specifying the -
35307 \begin_layout Standard
35319 \begin_layout Section
35321 \begin_inset LatexCommand \index{ANSI-compliance}
35326 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35333 \begin_layout Standard
35334 The latest publically available version of the standard
35336 ISO/IEC 9899 - Programming languages - C
35338 should be available at:
35339 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35348 \begin_layout Standard
35349 Deviations from the compliance:
35352 \begin_layout Itemize
35353 functions are not reentrant
35354 \begin_inset LatexCommand \index{reentrant}
35358 unless explicitly declared as such or the
35364 \begin_layout Standard
35374 \begin_inset LatexCommand \index{-\/-stack-auto}
35380 command line option is specified.
35383 \begin_layout Itemize
35385 \begin_inset LatexCommand \index{struct}
35390 \begin_inset LatexCommand \index{union}
35394 cannot be assigned values directly, cannot be passed as function parameters
35395 or assigned to each other and cannot be a return value
35396 \begin_inset LatexCommand \index{return value}
35400 from a function, e.g.:
35404 \begin_layout Verse
35427 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35446 s parms) /* invalid in SDCC although allowed in ANSI */
35468 return rets; /* is invalid in SDCC although allowed in ANSI */
35474 \begin_layout Itemize
35475 initialization of structure arrays must be fully braced.
35479 \begin_layout Verse
35482 struct s { char x } a[] = {1, 2};\InsetSpace ~
35487 /* invalid in SDCC */
35490 } a[] = {{1}, {2}}; /* OK */
35494 \begin_layout Itemize
35496 \begin_inset LatexCommand \index{long long (not supported)}
35501 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35508 \begin_layout Itemize
35510 \begin_inset LatexCommand \index{double (not supported)}
35514 ' precision floating point
35515 \begin_inset LatexCommand \index{Floating point support}
35522 \begin_layout Itemize
35524 \begin_inset LatexCommand \index{K\&R style}
35528 function declarations are NOT allowed.
35532 \begin_layout Verse
35535 foo(i,j) /* this old style of function declarations */
35537 int i,j; /* are valid
35538 in ANSI but not valid in SDCC */
35553 \begin_layout Itemize
35554 Most enhancements in C99 are not supported, f.e.:
35558 \begin_layout Verse
35563 \begin_inset LatexCommand \index{inline (not supported)}
35569 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35575 can be used as a work around */
35583 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35587 \begin_layout Itemize
35588 Certain words that are valid identifiers in the standard may be reserved
35589 words in SDCC unless the
35595 \begin_layout Standard
35605 \begin_inset LatexCommand \index{-\/-std-c89}
35613 \begin_layout Standard
35623 \begin_inset LatexCommand \index{-\/-std-c99}
35629 command line options are used.
35630 These may include (depending on the selected processor): 'at', 'banked',
35631 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35632 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35633 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35635 Compliant equivalents of these keywords are always available in a form
35636 that begin with two underscores
35637 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35642 '__data' instead of 'data'.
35645 \begin_layout Section
35646 Cyclomatic Complexity
35647 \begin_inset LatexCommand \index{Cyclomatic complexity}
35654 \begin_layout Standard
35655 Cyclomatic complexity of a function is defined as the number of independent
35656 paths the program can take during execution of the function.
35657 This is an important number since it defines the number test cases you
35658 have to generate to validate the function.
35659 The accepted industry standard for complexity number is 10, if the cyclomatic
35660 complexity reported by SDCC exceeds 10 you should think about simplification
35661 of the function logic.
35662 Note that the complexity level is not related to the number of lines of
35663 code in a function.
35664 Large functions can have low complexity, and small functions can have large
35670 SDCC uses the following formula to compute the complexity:
35675 \begin_layout Standard
35676 complexity = (number of edges in control flow graph) - (number of nodes
35677 in control flow graph) + 2;
35681 Having said that the industry standard is 10,
35682 you should be aware that in some cases it be may unavoidable to have a
35683 complexity level of less than 10.
35684 For example if you have switch statement with more than 10 case labels,
35685 each case label adds one to the complexity level.
35686 The complexity level is by no means an absolute measure of the algorithmic
35687 complexity of the function, it does however provide a good starting point
35688 for which functions you might look at for further optimization.
35691 \begin_layout Section
35692 Retargetting for other Processors
35695 \begin_layout Standard
35696 The issues for retargetting the compiler are far too numerous to be covered
35698 What follows is a brief description of each of the seven phases of the
35699 compiler and its MCU dependency.
35702 \begin_layout Itemize
35703 Parsing the source and building the annotated parse tree.
35704 This phase is largely MCU independent (except for the language extensions).
35705 Syntax & semantic checks are also done in this phase, along with some initial
35706 optimizations like back patching labels and the pattern matching optimizations
35707 like bit-rotation etc.
35710 \begin_layout Itemize
35711 The second phase involves generating an intermediate code which can be easy
35712 manipulated during the later phases.
35713 This phase is entirely MCU independent.
35714 The intermediate code generation assumes the target machine has unlimited
35715 number of registers, and designates them with the name iTemp.
35716 The compiler can be made to dump a human readable form of the code generated
35721 \begin_layout Standard
35733 \begin_layout Itemize
35734 This phase does the bulk of the standard optimizations and is also MCU independe
35736 This phase can be broken down into several sub-phases:
35740 Break down intermediate
35741 code (iCode) into basic blocks.
35743 Do control flow & data flow analysis on the
35746 Do local common subexpression elimination, then global subexpressio
35749 Dead code elimination
35753 If loop optimizations
35754 caused any changes then do 'global subexpression elimination' and 'dead
35755 code elimination' again.
35758 \begin_layout Itemize
35759 This phase determines the live-ranges; by live range I mean those iTemp
35760 variables defined by the compiler that still survive after all the optimization
35762 Live range analysis
35763 \begin_inset LatexCommand \index{Live range analysis}
35767 is essential for register allocation, since these computation determines
35768 which of these iTemps will be assigned to registers, and for how long.
35771 \begin_layout Itemize
35772 Phase five is register allocation.
35773 There are two parts to this process.
35777 The first part I call 'register packing'
35778 (for lack of a better term).
35779 In this case several MCU specific expression folding is done to reduce
35784 The second part is more MCU independent and deals with
35785 allocating registers to the remaining live ranges.
35786 A lot of MCU specific code does creep into this phase because of the limited
35787 number of index registers available in the 8051.
35790 \begin_layout Itemize
35791 The Code generation phase is (unhappily), entirely MCU dependent and very
35792 little (if any at all) of this code can be reused for other MCU.
35793 However the scheme for allocating a homogenized assembler operand for each
35794 iCode operand may be reused.
35797 \begin_layout Itemize
35798 As mentioned in the optimization section the peep-hole optimizer is rule
35799 based system, which can reprogrammed for other MCUs.
35802 \begin_layout Standard
35803 More information is available in a wiki
35804 \begin_inset LatexCommand \index{wiki}
35809 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35813 ) and in the thread
35814 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35821 \begin_layout Chapter
35823 \begin_inset LatexCommand \index{Compiler internals}
35830 \begin_layout Section
35831 The anatomy of the compiler
35832 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35839 \begin_layout Standard
35842 This is an excerpt from an article published in Circuit Cellar Magazine
35848 It's a little outdated (the compiler is much more efficient now and user/develo
35849 per friendly), but pretty well exposes the guts of it all.
35855 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35856 It is fairly easy to retarget for other 8-bit MCU.
35857 Here we take a look at some of the internals of the compiler.
35861 \begin_layout Paragraph*
35863 \begin_inset LatexCommand \index{Parsing}
35870 \begin_layout Standard
35871 Parsing the input source file and creating an AST (Annotated Syntax Tree
35872 \begin_inset LatexCommand \index{Annotated syntax tree}
35877 This phase also involves propagating types (annotating each node of the
35878 parse tree with type information) and semantic analysis.
35879 There are some MCU specific parsing rules.
35880 For example the storage classes, the extended storage classes are MCU specific
35881 while there may be a xdata storage class for 8051 there is no such storage
35882 class for z80 or Atmel AVR.
35883 SDCC allows MCU specific storage class extensions, i.e.
35884 xdata will be treated as a storage class specifier when parsing 8051 C
35885 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35889 \begin_layout Paragraph*
35891 \begin_inset LatexCommand \index{iCode}
35898 \begin_layout Standard
35899 Intermediate code generation.
35900 In this phase the AST is broken down into three-operand form (iCode).
35901 These three operand forms are represented as doubly linked lists.
35902 ICode is the term given to the intermediate form generated by the compiler.
35903 ICode example section shows some examples of iCode generated for some simple
35904 C source functions.
35907 \begin_layout Paragraph*
35909 \begin_inset LatexCommand \index{Optimizations}
35916 \begin_layout Standard
35917 Bulk of the target independent optimizations is performed in this phase.
35918 The optimizations include constant propagation, common sub-expression eliminati
35919 on, loop invariant code movement, strength reduction of loop induction variables
35920 and dead-code elimination.
35923 \begin_layout Paragraph*
35924 Live range analysis
35925 \begin_inset LatexCommand \index{Live range analysis}
35932 \begin_layout Standard
35933 During intermediate code generation phase, the compiler assumes the target
35934 machine has infinite number of registers and generates a lot of temporary
35936 The live range computation determines the lifetime of each of these compiler-ge
35937 nerated temporaries.
35938 A picture speaks a thousand words.
35939 ICode example sections show the live range annotations for each of the
35941 It is important to note here, each iCode is assigned a number in the order
35942 of its execution in the function.
35943 The live ranges are computed in terms of these numbers.
35944 The from number is the number of the iCode which first defines the operand
35945 and the to number signifies the iCode which uses this operand last.
35948 \begin_layout Paragraph*
35949 Register Allocation
35950 \begin_inset LatexCommand \index{Register allocation}
35957 \begin_layout Standard
35958 The register allocation determines the type and number of registers needed
35960 In most MCUs only a few registers can be used for indirect addressing.
35961 In case of 8051 for example the registers R0 & R1 can be used to indirectly
35962 address the internal ram and DPTR to indirectly address the external ram.
35963 The compiler will try to allocate the appropriate register to pointer variables
35965 ICode example section shows the operands annotated with the registers assigned
35967 The compiler will try to keep operands in registers as much as possible;
35968 there are several schemes the compiler uses to do achieve this.
35969 When the compiler runs out of registers the compiler will check to see
35970 if there are any live operands which is not used or defined in the current
35971 basic block being processed, if there are any found then it will push that
35972 operand and use the registers in this block, the operand will then be popped
35973 at the end of the basic block.
35977 \begin_layout Standard
35978 There are other MCU specific considerations in this phase.
35979 Some MCUs have an accumulator; very short-lived operands could be assigned
35980 to the accumulator instead of a general-purpose register.
35983 \begin_layout Paragraph*
35987 \begin_layout Standard
35988 Figure II gives a table of iCode
35989 \begin_inset LatexCommand \index{iCode}
35993 operations supported by the compiler.
35994 The code generation involves translating these operations into corresponding
35995 assembly code for the processor.
35996 This sounds overly simple but that is the essence of code generation.
35997 Some of the iCode operations are generated on a MCU specific manner for
35998 example, the z80 port does not use registers to pass parameters so the
35999 SEND and RECV iCode operations will not be generated, and it also does
36000 not support JUMPTABLES.
36006 \begin_layout Standard
36010 \begin_inset Tabular
36011 <lyxtabular version="3" rows="39" columns="4">
36012 <features islongtable="true" headBottomDL="true">
36013 <column alignment="block" valignment="top" leftline="true" width="13col%">
36014 <column alignment="left" valignment="top" leftline="true" width="13col%">
36015 <column alignment="block" valignment="top" leftline="true" width="22col%">
36016 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36017 <row topline="true" bottomline="true" endhead="true">
36018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36021 \begin_layout Standard
36027 \begin_inset LatexCommand \index{iCode}
36036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36039 \begin_layout Standard
36047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36050 \begin_layout Standard
36058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36061 \begin_layout Standard
36070 <row topline="true">
36071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36074 \begin_layout Standard
36082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36085 \begin_layout Standard
36088 IC_LEFT() IC_RESULT()
36093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36096 \begin_layout Standard
36104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36107 \begin_layout Standard
36110 IC_RESULT = ! IC_LEFT;
36116 <row topline="true">
36117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36120 \begin_layout Standard
36128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36131 \begin_layout Standard
36134 IC_LEFT() IC_RESULT()
36139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36142 \begin_layout Standard
36145 Bitwise complement of
36150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36153 \begin_layout Standard
36156 IC_RESULT = ~IC_LEFT;
36162 <row topline="true">
36163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36166 \begin_layout Standard
36174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36177 \begin_layout Standard
36180 IC_LEFT() IC_RESULT()
36185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36188 \begin_layout Standard
36191 Rotate right with carry
36196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36199 \begin_layout Standard
36202 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36208 <row topline="true">
36209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36212 \begin_layout Standard
36220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36223 \begin_layout Standard
36226 IC_LEFT() IC_RESULT()
36231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36234 \begin_layout Standard
36237 Rotate left with carry
36242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36245 \begin_layout Standard
36248 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36254 <row topline="true">
36255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36258 \begin_layout Standard
36266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36269 \begin_layout Standard
36272 IC_LEFT() IC_RESULT()
36277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36280 \begin_layout Standard
36283 Get the highest order bit of IC_LEFT
36288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36291 \begin_layout Standard
36294 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36300 <row topline="true">
36301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36304 \begin_layout Standard
36312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36315 \begin_layout Standard
36318 IC_LEFT() IC_RESULT()
36323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36326 \begin_layout Standard
36334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36337 \begin_layout Standard
36340 IC_RESULT = - IC_LEFT;
36346 <row topline="true">
36347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36350 \begin_layout Standard
36358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36361 \begin_layout Standard
36369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36372 \begin_layout Standard
36375 Push the operand into stack
36380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36383 \begin_layout Standard
36392 <row topline="true">
36393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36396 \begin_layout Standard
36404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36407 \begin_layout Standard
36415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36418 \begin_layout Standard
36421 Pop the operand from the stack
36426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36429 \begin_layout Standard
36438 <row topline="true">
36439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36442 \begin_layout Standard
36450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36453 \begin_layout Standard
36456 IC_LEFT() IC_RESULT()
36461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36464 \begin_layout Standard
36467 Call the function represented by IC_LEFT
36472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36475 \begin_layout Standard
36478 IC_RESULT = IC_LEFT();
36484 <row topline="true">
36485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36488 \begin_layout Standard
36496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36499 \begin_layout Standard
36502 IC_LEFT() IC_RESULT()
36507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36510 \begin_layout Standard
36513 Call via function pointer
36518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36521 \begin_layout Standard
36524 IC_RESULT = (*IC_LEFT)();
36530 <row topline="true">
36531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36534 \begin_layout Standard
36542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36545 \begin_layout Standard
36553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36556 \begin_layout Standard
36559 Return the value in operand IC_LEFT
36564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36567 \begin_layout Standard
36576 <row topline="true">
36577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36580 \begin_layout Standard
36588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36591 \begin_layout Standard
36599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36602 \begin_layout Standard
36610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36613 \begin_layout Standard
36622 <row topline="true">
36623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36626 \begin_layout Standard
36634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36637 \begin_layout Standard
36645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36648 \begin_layout Standard
36656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36659 \begin_layout Standard
36668 <row topline="true">
36669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36672 \begin_layout Standard
36680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36683 \begin_layout Standard
36686 IC_LEFT() IC_RIGHT() IC_RESULT()
36691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36694 \begin_layout Standard
36702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36705 \begin_layout Standard
36708 IC_RESULT = IC_LEFT + IC_RIGHT
36714 <row topline="true">
36715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36718 \begin_layout Standard
36726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36729 \begin_layout Standard
36732 IC_LEFT() IC_RIGHT() IC_RESULT()
36737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36740 \begin_layout Standard
36748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36751 \begin_layout Standard
36754 IC_RESULT = IC_LEFT - IC_RIGHT
36760 <row topline="true">
36761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36764 \begin_layout Standard
36772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36775 \begin_layout Standard
36778 IC_LEFT() IC_RIGHT() IC_RESULT()
36783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36786 \begin_layout Standard
36794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36797 \begin_layout Standard
36800 IC_RESULT = IC_LEFT * IC_RIGHT;
36806 <row topline="true">
36807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36810 \begin_layout Standard
36818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36821 \begin_layout Standard
36824 IC_LEFT() IC_RIGHT() IC_RESULT()
36829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36832 \begin_layout Standard
36840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36843 \begin_layout Standard
36846 IC_RESULT = IC_LEFT / IC_RIGHT;
36852 <row topline="true">
36853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36856 \begin_layout Standard
36864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36867 \begin_layout Standard
36870 IC_LEFT() IC_RIGHT() IC_RESULT()
36875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36878 \begin_layout Standard
36886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36889 \begin_layout Standard
36892 IC_RESULT = IC_LEFT % IC_RIGHT;
36898 <row topline="true">
36899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36902 \begin_layout Standard
36910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36913 \begin_layout Standard
36916 IC_LEFT() IC_RIGHT() IC_RESULT()
36921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36924 \begin_layout Standard
36932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36935 \begin_layout Standard
36938 IC_RESULT = IC_LEFT < IC_RIGHT;
36944 <row topline="true">
36945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36948 \begin_layout Standard
36956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36959 \begin_layout Standard
36962 IC_LEFT() IC_RIGHT() IC_RESULT()
36967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36970 \begin_layout Standard
36978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36981 \begin_layout Standard
36984 IC_RESULT = IC_LEFT > IC_RIGHT;
36990 <row topline="true">
36991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36994 \begin_layout Standard
37002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37005 \begin_layout Standard
37008 IC_LEFT() IC_RIGHT() IC_RESULT()
37013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37016 \begin_layout Standard
37024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37027 \begin_layout Standard
37030 IC_RESULT = IC_LEFT == IC_RIGHT;
37036 <row topline="true">
37037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37040 \begin_layout Standard
37048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37051 \begin_layout Standard
37054 IC_LEFT() IC_RIGHT() IC_RESULT()
37059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37062 \begin_layout Standard
37065 Logical and operation
37070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37073 \begin_layout Standard
37076 IC_RESULT = IC_LEFT && IC_RIGHT;
37082 <row topline="true">
37083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37086 \begin_layout Standard
37094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37097 \begin_layout Standard
37100 IC_LEFT() IC_RIGHT() IC_RESULT()
37105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37108 \begin_layout Standard
37111 Logical or operation
37116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37119 \begin_layout Standard
37122 IC_RESULT = IC_LEFT || IC_RIGHT;
37128 <row topline="true">
37129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37132 \begin_layout Standard
37140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37143 \begin_layout Standard
37146 IC_LEFT() IC_RIGHT() IC_RESULT()
37151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37154 \begin_layout Standard
37162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37165 \begin_layout Standard
37168 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37174 <row topline="true">
37175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37178 \begin_layout Standard
37186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37189 \begin_layout Standard
37192 IC_LEFT() IC_RIGHT() IC_RESULT()
37197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37200 \begin_layout Standard
37208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37211 \begin_layout Standard
37214 IC_RESULT = IC_LEFT | IC_RIGHT;
37220 <row topline="true">
37221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37224 \begin_layout Standard
37232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37235 \begin_layout Standard
37238 IC_LEFT() IC_RIGHT() IC_RESULT()
37243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37246 \begin_layout Standard
37254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37257 \begin_layout Standard
37260 IC_RESULT = IC_LEFT & IC_RIGHT;
37266 <row topline="true">
37267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37270 \begin_layout Standard
37278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37281 \begin_layout Standard
37284 IC_LEFT() IC_RIGHT() IC_RESULT()
37289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37292 \begin_layout Standard
37300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37303 \begin_layout Standard
37306 IC_RESULT = IC_LEFT << IC_RIGHT
37312 <row topline="true">
37313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37316 \begin_layout Standard
37324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37327 \begin_layout Standard
37330 IC_LEFT() IC_RIGHT() IC_RESULT()
37335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37338 \begin_layout Standard
37346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37349 \begin_layout Standard
37352 IC_RESULT = IC_LEFT >> IC_RIGHT
37358 <row topline="true">
37359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37362 \begin_layout Standard
37372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37375 \begin_layout Standard
37378 IC_LEFT() IC_RESULT()
37383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37386 \begin_layout Standard
37394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37397 \begin_layout Standard
37400 IC_RESULT = (*IC_LEFT);
37406 <row topline="true">
37407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37410 \begin_layout Standard
37418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37421 \begin_layout Standard
37424 IC_RIGHT() IC_RESULT()
37429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37432 \begin_layout Standard
37440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37443 \begin_layout Standard
37446 (*IC_RESULT) = IC_RIGHT;
37452 <row topline="true">
37453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37456 \begin_layout Standard
37464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37467 \begin_layout Standard
37470 IC_RIGHT() IC_RESULT()
37475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37478 \begin_layout Standard
37486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37489 \begin_layout Standard
37492 IC_RESULT = IC_RIGHT;
37498 <row topline="true">
37499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37502 \begin_layout Standard
37510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37513 \begin_layout Standard
37516 IC_COND IC_TRUE IC_LABEL
37521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37524 \begin_layout Standard
37528 If true label is present then jump to true label if condition is true else
37529 jump to false label if condition is false
37534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37537 \begin_layout Standard
37540 if (IC_COND) goto IC_TRUE;
37546 If (!IC_COND) goto IC_FALSE;
37552 <row topline="true">
37553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37556 \begin_layout Standard
37564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37567 \begin_layout Standard
37570 IC_LEFT() IC_RESULT()
37575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37578 \begin_layout Standard
37586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37589 \begin_layout Standard
37592 IC_RESULT = &IC_LEFT();
37598 <row topline="true">
37599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37602 \begin_layout Standard
37610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37613 \begin_layout Standard
37616 IC_JTCOND IC_JTLABELS
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37624 \begin_layout Standard
37627 Jump to list of labels depending on the value of JTCOND
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37635 \begin_layout Standard
37644 <row topline="true">
37645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37648 \begin_layout Standard
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37659 \begin_layout Standard
37662 IC_RIGHT() IC_LEFT() IC_RESULT()
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37670 \begin_layout Standard
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37681 \begin_layout Standard
37684 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37690 <row topline="true">
37691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37694 \begin_layout Standard
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37705 \begin_layout Standard
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37716 \begin_layout Standard
37719 This is used for passing parameters in registers;
37721 move IC_LEFT to the next
37722 available parameter register.
37727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37730 \begin_layout Standard
37739 <row topline="true">
37740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37743 \begin_layout Standard
37751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37754 \begin_layout Standard
37762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37765 \begin_layout Standard
37768 This is used for receiving parameters passed in registers;
37771 in the next parameter register to IC_RESULT
37776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37779 \begin_layout Standard
37788 <row topline="true" bottomline="true">
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37792 \begin_layout Standard
37796 (some more have been added)
37801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37804 \begin_layout Standard
37810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37813 \begin_layout Standard
37819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37822 \begin_layout Standard
37846 \begin_layout Standard
37847 \begin_inset Note Note
37850 \begin_layout Standard
37851 In the original article Figure II was announced to be downloadable on
37856 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37864 \begin_layout Paragraph*
37866 \begin_inset LatexCommand \index{iCode}
37873 \begin_layout Standard
37874 This section shows some details of iCode.
37875 The example C code does not do anything useful; it is used as an example
37876 to illustrate the intermediate code generated by the compiler.
37879 \begin_layout Verse
37889 /* This function does nothing useful.
37896 for the purpose of explaining iCode */
37899 short function (data
37908 short i=10; \InsetSpace ~
37910 /* dead initialization eliminated */
37916 /* dead initialization eliminated */
37944 /* compiler detects i,j to be induction
37949 for (i = 0, j = 10 ; i < 10 ; i++, j
37955 \begin_layout Standard
37978 mul += i * 3; \InsetSpace ~
37980 /* this multiplication remains */
37987 j * 3;\InsetSpace ~
37989 /* this multiplication changed to addition */
38003 \begin_layout Standard
38004 In addition to the operands each iCode contains information about the filename
38005 and line it corresponds to in the source file.
38006 The first field in the listing should be interpreted as follows:
38011 Filename(linenumber: iCode Execution sequence number : ICode hash table
38012 key : loop depth of the iCode).
38017 Then follows the human readable form of the ICode operation.
38018 Each operand of this triplet form can be of three basic types a) compiler
38019 generated temporary b) user defined variable c) a constant value.
38020 Note that local variables and parameters are replaced by compiler generated
38023 \begin_inset LatexCommand \index{Live range analysis}
38027 are computed only for temporaries (i.e.
38028 live ranges are not computed for global variables).
38030 \begin_inset LatexCommand \index{Register allocation}
38034 are allocated for temporaries only.
38035 Operands are formatted in the following manner:
38040 Operand Name [lr live-from : live-to ] { type information } [ registers
38046 As mentioned earlier the live ranges are computed in terms of the execution
38047 sequence number of the iCodes, for example
38049 the iTemp0 is live from (i.e.
38050 first defined in iCode with execution sequence number 3, and is last used
38051 in the iCode with sequence number 5).
38052 For induction variables such as iTemp21 the live range computation extends
38053 the lifetime from the start to the end of the loop.
38055 The register allocator
38056 used the live range information to allocate registers, the same registers
38057 may be used for different temporaries if their live ranges do not overlap,
38058 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38059 ranges do not overlap.
38060 In addition the allocator also takes into consideration the type and usage
38061 of a temporary, for example itemp6 is a pointer to near space and is used
38062 as to fetch data from (i.e.
38063 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38064 Some short lived temporaries are allocated to special registers which have
38065 meaning to the code generator e.g.
38066 iTemp13 is allocated to a pseudo register CC which tells the back end that
38067 the temporary is used only for a conditional jump the code generation makes
38068 use of this information to optimize a compare and jump ICode.
38072 \begin_inset LatexCommand \index{Loop optimization}
38076 performed by the compiler.
38077 It can detect induction variables iTemp21(i) and iTemp23(j).
38078 Also note the compiler does selective strength reduction
38079 \begin_inset LatexCommand \index{Strength reduction}
38084 the multiplication of an induction variable in line 18 (gint = j * 3) is
38085 changed to addition, a new temporary iTemp17 is allocated and assigned
38086 a initial value, a constant 3 is then added for each iteration of the loop.
38087 The compiler does not change the multiplication
38088 \begin_inset LatexCommand \index{Multiplication}
38092 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38095 Note the dead code elimination
38096 \begin_inset LatexCommand \index{Dead-code elimination}
38100 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38106 \begin_layout Standard
38109 Sample.c (5:1:0:0) _entry($9) :
38112 \begin_layout Standard
38115 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38118 \begin_layout Standard
38121 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38124 \begin_layout Standard
38127 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38130 \begin_layout Standard
38133 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38137 \begin_layout Standard
38140 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38143 \begin_layout Standard
38146 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38150 \begin_layout Standard
38153 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38156 \begin_layout Standard
38159 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38163 \begin_layout Standard
38166 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38170 \begin_layout Standard
38173 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38177 \begin_layout Standard
38180 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38184 \begin_layout Standard
38187 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38188 * int}[r0] + 0x2 {short}
38191 \begin_layout Standard
38194 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38197 \begin_layout Standard
38200 Sample.c(11:17:21:0)_whilebreak_0($3) :
38203 \begin_layout Standard
38206 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38209 \begin_layout Standard
38212 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38215 \begin_layout Standard
38218 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38221 \begin_layout Standard
38224 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38227 \begin_layout Standard
38230 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38233 \begin_layout Standard
38236 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38239 \begin_layout Standard
38242 Sample.c(15:24:26:1)_forcond_0($4) :
38245 \begin_layout Standard
38248 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38252 \begin_layout Standard
38255 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38258 \begin_layout Standard
38261 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38262 + ITemp21 [lr21:38]{short}[r4]
38265 \begin_layout Standard
38268 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38272 \begin_layout Standard
38275 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38276 + iTemp15 [lr29:30]{short}[r1]
38279 \begin_layout Standard
38282 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38286 \begin_layout Standard
38289 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38293 \begin_layout Standard
38296 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38300 \begin_layout Standard
38303 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38307 \begin_layout Standard
38310 Sample.c(19:38:47:1) goto _forcond_0($4)
38313 \begin_layout Standard
38316 Sample.c(19:39:48:0)_forbreak_0($7) :
38319 \begin_layout Standard
38322 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38323 + ITemp11 [lr19:40]{short}[r3]
38326 \begin_layout Standard
38329 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38332 \begin_layout Standard
38335 Sample.c(20:42:51:0)_return($8) :
38338 \begin_layout Standard
38341 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38347 Finally the code generated for this function:
38352 \begin_layout Standard
38358 \begin_layout Standard
38364 \begin_layout Standard
38372 \begin_layout Standard
38378 \begin_layout Standard
38386 \begin_layout Standard
38392 \begin_layout Standard
38395 ; ----------------------------------------------
38398 \begin_layout Standard
38401 ; function function
38404 \begin_layout Standard
38407 ; ----------------------------------------------
38410 \begin_layout Standard
38416 \begin_layout Standard
38419 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38422 \begin_layout Standard
38430 \begin_layout Standard
38433 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38436 \begin_layout Standard
38444 \begin_layout Standard
38447 ;_whilecontinue_0($1) :
38450 \begin_layout Standard
38456 \begin_layout Standard
38459 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38462 \begin_layout Standard
38465 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38468 \begin_layout Standard
38476 \begin_layout Standard
38484 \begin_layout Standard
38492 \begin_layout Standard
38500 \begin_layout Standard
38508 \begin_layout Standard
38516 \begin_layout Standard
38524 \begin_layout Standard
38530 \begin_layout Standard
38533 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38536 \begin_layout Standard
38544 \begin_layout Standard
38552 \begin_layout Standard
38555 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38558 \begin_layout Standard
38566 \begin_layout Standard
38574 \begin_layout Standard
38582 \begin_layout Standard
38590 \begin_layout Standard
38598 \begin_layout Standard
38606 \begin_layout Standard
38609 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38612 \begin_layout Standard
38620 \begin_layout Standard
38628 \begin_layout Standard
38636 \begin_layout Standard
38644 \begin_layout Standard
38652 \begin_layout Standard
38655 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38658 \begin_layout Standard
38666 \begin_layout Standard
38674 \begin_layout Standard
38682 \begin_layout Standard
38685 ; iTemp6 [lr5:16]{_near * int}[r0] =
38688 \begin_layout Standard
38691 ; iTemp6 [lr5:16]{_near * int}[r0] +
38694 \begin_layout Standard
38700 \begin_layout Standard
38708 \begin_layout Standard
38711 ; goto _whilecontinue_0($1)
38714 \begin_layout Standard
38722 \begin_layout Standard
38725 ; _whilebreak_0($3) :
38728 \begin_layout Standard
38734 \begin_layout Standard
38737 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38740 \begin_layout Standard
38748 \begin_layout Standard
38751 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38754 \begin_layout Standard
38762 \begin_layout Standard
38765 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38768 \begin_layout Standard
38776 \begin_layout Standard
38779 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38782 \begin_layout Standard
38790 \begin_layout Standard
38798 \begin_layout Standard
38801 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38804 \begin_layout Standard
38812 \begin_layout Standard
38820 \begin_layout Standard
38826 \begin_layout Standard
38832 \begin_layout Standard
38835 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38838 \begin_layout Standard
38841 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38844 \begin_layout Standard
38852 \begin_layout Standard
38860 \begin_layout Standard
38868 \begin_layout Standard
38876 \begin_layout Standard
38884 \begin_layout Standard
38890 \begin_layout Standard
38893 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38896 \begin_layout Standard
38899 ; iTemp21 [lr21:38]{short}[r4]
38902 \begin_layout Standard
38910 \begin_layout Standard
38918 \begin_layout Standard
38926 \begin_layout Standard
38929 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38932 \begin_layout Standard
38940 \begin_layout Standard
38948 \begin_layout Standard
38956 \begin_layout Standard
38964 \begin_layout Standard
38967 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
38970 \begin_layout Standard
38973 ; iTemp15 [lr29:30]{short}[r1]
38976 \begin_layout Standard
38984 \begin_layout Standard
38992 \begin_layout Standard
38995 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38998 \begin_layout Standard
39006 \begin_layout Standard
39014 \begin_layout Standard
39022 \begin_layout Standard
39030 \begin_layout Standard
39038 \begin_layout Standard
39046 \begin_layout Standard
39049 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39052 \begin_layout Standard
39060 \begin_layout Standard
39068 \begin_layout Standard
39076 \begin_layout Standard
39084 \begin_layout Standard
39092 \begin_layout Standard
39100 \begin_layout Standard
39103 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39106 \begin_layout Standard
39114 \begin_layout Standard
39117 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39120 \begin_layout Standard
39128 \begin_layout Standard
39133 cjne r5,#0xff,00104$
39136 \begin_layout Standard
39144 \begin_layout Standard
39147 ; goto _forcond_0($4)
39150 \begin_layout Standard
39158 \begin_layout Standard
39161 ; _forbreak_0($7) :
39164 \begin_layout Standard
39170 \begin_layout Standard
39173 ; ret iTemp24 [lr40:41]{short}
39176 \begin_layout Standard
39184 \begin_layout Standard
39192 \begin_layout Standard
39200 \begin_layout Standard
39206 \begin_layout Standard
39212 \begin_layout Standard
39222 \begin_layout Section
39223 A few words about basic block successors, predecessors and dominators
39226 \begin_layout Standard
39227 Successors are basic blocks
39228 \begin_inset LatexCommand \index{Basic blocks}
39232 that might execute after this basic block.
39234 Predecessors are basic blocks
39235 that might execute before reaching this basic block.
39237 Dominators are basic
39238 blocks that WILL execute before reaching this basic block.
39243 \begin_layout Standard
39247 \begin_layout Standard
39251 \begin_layout Standard
39259 \begin_layout Standard
39263 \begin_layout Standard
39271 \begin_layout Standard
39277 \begin_layout Standard
39278 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39281 \begin_layout Standard
39282 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39285 \begin_layout Standard
39286 c) domVect of [BB4] = BB1 ...
39287 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39291 \begin_layout Chapter
39295 \begin_layout Standard
39296 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39306 Thanks to all the other volunteer developers who have helped with coding,
39307 testing, web-page creation, distribution sets, etc.
39308 You know who you are :-)
39316 Also thanks to Sourceforge
39317 \begin_inset LatexCommand \url{http://www.sf.net}
39321 which has hosted the project since 1999 and donates significant download
39322 bandwidth and probably more than
39326 \begin_layout Standard
39333 CPU cycles per day.
39336 \begin_inset Note Note
39339 \begin_layout Standard
39340 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39341 minutes for (configure+make+regression test), and there is (i386, amd64,
39342 alpha, ppc64, (mingw32), sparc, Mac OS X).
39351 \begin_layout Standard
39352 This document was initially written by Sandeep Dutta
39355 \begin_layout Standard
39356 All product names mentioned herein may be trademarks
39357 \begin_inset LatexCommand \index{Trademarks}
39361 of their respective companies.
39365 \begin_layout Section*
39369 \begin_layout Standard
39370 To avoid confusion, the installation and building options for SDCC itself
39371 (chapter 2) are not part of the index.
39374 \begin_layout Standard
39375 \begin_inset LatexCommand \printindex{}