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 where everything will be placed or the file name used for
9035 all generated output files.
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 Note for Windows users: if the path contains spaces, it should be surrounded
9044 The trailing backslash should be doubled in order to prevent escaping the
9045 final quote, for example:
9048 \begin_inset Quotes sld
9062 \begin_inset Quotes srd
9067 or put after the final quote, for example:
9070 \begin_inset Quotes sld
9080 \begin_inset Quotes srd
9088 The path using slashes for directory delimiters can be used too, for example:
9092 \begin_inset Quotes sld
9095 F:/Projects/test3/output 1/
9096 \begin_inset Quotes srd
9105 \labelwidthstring 00.00.0000
9112 \begin_layout Standard
9122 \begin_inset LatexCommand \index{-\/-stack-auto}
9133 All functions in the source file will be compiled as
9138 \begin_inset LatexCommand \index{reentrant}
9143 the parameters and local variables will be allocated on the stack
9144 \begin_inset LatexCommand \index{stack}
9150 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9154 Parameters and Local Variables for more details.
9155 If this option is used all source files in the project should be compiled
9157 It automatically implies --int-long-reent and --float-reent.
9162 \labelwidthstring 00.00.0000
9169 \begin_layout Standard
9179 \begin_inset LatexCommand \index{-\/-callee-saves}
9184 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9188 function1[,function2][,function3]....
9191 The compiler by default uses a caller saves convention for register saving
9192 across function calls, however this can cause unnecessary register pushing
9193 and popping when calling small functions from larger functions.
9194 This option can be used to switch the register saving convention for the
9195 function names specified.
9196 The compiler will not save registers when calling these functions, no extra
9197 code will be generated at the entry and exit (function prologue
9200 \begin_inset LatexCommand \index{function prologue}
9209 \begin_inset LatexCommand \index{function epilogue}
9215 ) for these functions to save and restore the registers used by these functions,
9216 this can SUBSTANTIALLY reduce code and improve run time performance of
9218 In the future the compiler (with inter procedural analysis) will be able
9219 to determine the appropriate scheme to use for each function call.
9220 DO NOT use this option for built-in functions such as _mulint..., if this
9221 option is used for a library function the appropriate library function
9222 needs to be recompiled with the same option.
9223 If the project consists of multiple source files then all the source file
9224 should be compiled with the same -
9228 \begin_layout Standard
9237 -callee-saves option string.
9238 Also see #pragma\InsetSpace ~
9240 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9245 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9253 \labelwidthstring 00.00.0000
9260 \begin_layout Standard
9270 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9284 \begin_layout Standard
9293 -callee-saves will be applied to all functions by default.
9297 \labelwidthstring 00.00.0000
9304 \begin_layout Standard
9314 \begin_inset LatexCommand \index{-\/-debug}
9323 When this option is used the compiler will generate debug information.
9324 The debug information collected in a file with .cdb extension can be used
9326 For more information see documentation for SDCDB.
9327 Another file with no extension contains debug information in AOMF or AOMF51
9328 \begin_inset LatexCommand \index{AOMF, AOMF51}
9332 format which is commonly used by third party tools.
9336 \labelwidthstring 00.00.0000
9340 \begin_inset LatexCommand \index{-S}
9351 Stop after the stage of compilation proper; do not assemble.
9352 The output is an assembler code file for the input file specified.
9356 \labelwidthstring 00.00.0000
9363 \begin_layout Standard
9373 \begin_inset LatexCommand \index{-\/-int-long-reent}
9379 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9380 Note by default these libraries are compiled as non-reentrant.
9381 See section Installation for more details.
9385 \labelwidthstring 00.00.0000
9392 \begin_layout Standard
9402 \begin_inset LatexCommand \index{-\/-cyclomatic}
9411 This option will cause the compiler to generate an information message for
9412 each function in the source file.
9413 The message contains some
9417 information about the function.
9418 The number of edges and nodes the compiler detected in the control flow
9419 graph of the function, and most importantly the
9421 cyclomatic complexity
9422 \begin_inset LatexCommand \index{Cyclomatic complexity}
9428 see section on Cyclomatic Complexity for more details.
9432 \labelwidthstring 00.00.0000
9439 \begin_layout Standard
9449 \begin_inset LatexCommand \index{-\/-float-reent}
9455 Floating point library is compiled as reentrant
9456 \begin_inset LatexCommand \index{reentrant}
9461 See section Installation for more details.
9465 \labelwidthstring 00.00.0000
9472 \begin_layout Standard
9482 \begin_inset LatexCommand \index{-\/-funsigned-char}
9488 The default signedness for every type is
9493 In some embedded environments the default signedness of
9502 To set the signess for characters to unsigned, use the option --funsigned-char.
9503 If this option is set and no signedness keyword (unsigned/signed) is given,
9504 a char will be signed.
9505 All other types are unaffected.
9509 \labelwidthstring 00.00.0000
9516 \begin_layout Standard
9526 \begin_inset LatexCommand \index{-\/-main-return}
9532 This option can be used if the code generated is called by a monitor program
9533 or if the main routine includes an endless loop.
9534 This option results in slightly smaller code and saves two bytes of stack
9536 The return from the 'main'
9537 \begin_inset LatexCommand \index{main return}
9541 function will return to the function calling main.
9542 The default setting is to lock up i.e.
9551 \labelwidthstring 00.00.0000
9558 \begin_layout Standard
9568 \begin_inset LatexCommand \index{-\/-nostdinc}
9574 This will prevent the compiler from passing on the default include path
9575 to the preprocessor.
9579 \labelwidthstring 00.00.0000
9586 \begin_layout Standard
9596 \begin_inset LatexCommand \index{-\/-nostdlib}
9602 This will prevent the compiler from passing on the default library
9603 \begin_inset LatexCommand \index{Libraries}
9611 \labelwidthstring 00.00.0000
9618 \begin_layout Standard
9628 \begin_inset LatexCommand \index{-\/-verbose}
9634 Shows the various actions the compiler is performing.
9638 \labelwidthstring 00.00.0000
9642 \begin_inset LatexCommand \index{-V}
9648 Shows the actual commands the compiler is executing.
9652 \labelwidthstring 00.00.0000
9659 \begin_layout Standard
9669 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9675 Hides your ugly and inefficient c-code from the asm file, so you can always
9676 blame the compiler :)
9680 \labelwidthstring 00.00.0000
9687 \begin_layout Standard
9697 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9703 Include code generator and peep-hole comments in the generated asm files.
9707 \labelwidthstring 00.00.0000
9714 \begin_layout Standard
9724 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9730 Don't include peep-hole comments in the generated asm files even if --fverbose-
9731 asm option is specified.
9735 \labelwidthstring 00.00.0000
9742 \begin_layout Standard
9752 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9758 Include i-codes in the asm file.
9759 Sounds like noise but is most helpful for debugging the compiler itself.
9763 \labelwidthstring 00.00.0000
9770 \begin_layout Standard
9780 \begin_inset LatexCommand \index{pedantic}
9785 \begin_inset LatexCommand \index{-\/-less-pedantic}
9792 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9796 Disable some of the more pedantic warnings
9797 \begin_inset LatexCommand \index{Warnings}
9802 For more details, see the less_pedantic pragma
9803 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9811 \labelwidthstring 00.00.0000
9818 \begin_layout Standard
9827 -disable-warning\InsetSpace ~
9829 \begin_inset LatexCommand \index{-\/-disable-warning}
9835 Disable specific warning with number <nnnn>.
9839 \labelwidthstring 00.00.0000
9846 \begin_layout Standard
9856 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9862 Display the directories in the compiler's search path
9866 \labelwidthstring 00.00.0000
9873 \begin_layout Standard
9883 \begin_inset LatexCommand \index{-\/-vc}
9889 Display errors and warnings using MSVC style, so you can use SDCC with
9890 the visual studio IDE
9891 \begin_inset LatexCommand \index{IDE}
9896 With SDCC both offering a GCC-like (the default) and a MSVC-like
9897 \begin_inset LatexCommand \index{MSVC output style}
9901 output style, integration into most programming editors should be straightforwa
9906 \labelwidthstring 00.00.0000
9913 \begin_layout Standard
9923 \begin_inset LatexCommand \index{-\/-use-stdout}
9929 Send errors and warnings to stdout instead of stderr.
9933 \labelwidthstring 00.00.0000
9937 asmOption[,asmOption]
9940 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9945 Pass the asmOption to the assembler
9946 \begin_inset LatexCommand \index{Options assembler}
9951 \begin_inset LatexCommand \index{Assembler options}
9956 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9960 \labelwidthstring 00.00.0000
9967 \begin_layout Standard
9977 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9983 Generally follow the C89 standard, but allow SDCC features that conflict
9984 with the standard (default).
9988 \labelwidthstring 00.00.0000
9995 \begin_layout Standard
10005 \begin_inset LatexCommand \index{-\/-std-c89}
10011 Follow the C89 standard and disable SDCC features that conflict with the
10016 \labelwidthstring 00.00.0000
10023 \begin_layout Standard
10033 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10039 Generally follow the C99 standard, but allow SDCC features that conflict
10040 with the standard (incomplete support).
10044 \labelwidthstring 00.00.0000
10051 \begin_layout Standard
10061 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10067 Follow the C99 standard and disable SDCC features that conflict with the
10068 standard (incomplete support).
10072 \labelwidthstring 00.00.0000
10079 \begin_layout Standard
10091 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10096 <Name> The name to be used for the code
10097 \begin_inset LatexCommand \index{code}
10101 segment, default CSEG.
10102 This is useful if you need to tell the compiler to put the code in a special
10103 segment so you can later on tell the linker to put this segment in a special
10105 Can be used for instance when using bank switching to put the code in a
10110 \labelwidthstring 00.00.0000
10117 \begin_layout Standard
10129 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10134 <Name> The name to be used for the const
10135 \begin_inset LatexCommand \index{const}
10139 segment, default CONST.
10140 This is useful if you need to tell the compiler to put the const data in
10141 a special segment so you can later on tell the linker to put this segment
10142 in a special place in memory.
10143 Can be used for instance when using bank switching to put the const data
10148 \labelwidthstring 00.00.0000
10155 \begin_layout Standard
10164 -fdollars-in-identifiers
10165 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10171 Permit '$' as an identifier character.
10175 \labelwidthstring 00.00.0000
10182 \begin_layout Standard
10194 \begin_inset LatexCommand \index{-\/-more-pedantic}
10199 \begin_inset LatexCommand \index{pedantic}
10209 a SDCC compiler option but if you want
10213 warnings you can use a separate tool dedicated to syntax checking like
10215 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10220 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10225 \begin_inset LatexCommand \url{http://www.splint.org}
10230 To make your source files parseable by splint you will have to include
10236 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10240 in your source file and add brackets around extended keywords (like
10243 \begin_inset Quotes sld
10256 \begin_inset Quotes srd
10264 \begin_inset Quotes sld
10267 __interrupt\InsetSpace ~
10269 \begin_inset Quotes srd
10277 Splint has an excellent on line manual at
10278 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10282 and it's capabilities go beyond pure syntax checking.
10283 You'll need to tell splint the location of SDCC's include files so a typical
10284 command line could look like this:
10288 splint\InsetSpace ~
10290 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10296 \labelwidthstring 00.00.0000
10303 \begin_layout Standard
10315 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10320 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10324 Treat short as 8-bit (for backward compatibility with older versions of
10325 compiler - see section
10326 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10333 \begin_layout Standard
10334 \begin_inset VSpace bigskip
10340 \begin_layout Subsection
10341 Intermediate Dump Options
10342 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10347 \begin_inset LatexCommand \index{Options intermediate dump}
10352 \begin_inset LatexCommand \index{Intermediate dump options}
10359 \begin_layout Standard
10360 The following options are provided for the purpose of retargetting and debugging
10362 They provide a means to dump the intermediate code (iCode
10363 \begin_inset LatexCommand \index{iCode}
10367 ) generated by the compiler in human readable form at various stages of
10368 the compilation process.
10369 More on iCodes see chapter
10370 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10375 \begin_inset Quotes srd
10378 The anatomy of the compiler
10379 \begin_inset Quotes srd
10386 \labelwidthstring 00.00.0000
10393 \begin_layout Standard
10403 \begin_inset LatexCommand \index{-\/-dumpraw}
10409 This option will cause the compiler to dump the intermediate code into
10412 <source filename>.dumpraw
10414 just after the intermediate code has been generated for a function, i.e.
10415 before any optimizations are done.
10417 \begin_inset LatexCommand \index{Basic blocks}
10421 at this stage ordered in the depth first number, so they may not be in
10422 sequence of execution.
10426 \labelwidthstring 00.00.0000
10433 \begin_layout Standard
10443 \begin_inset LatexCommand \index{-\/-dumpgcse}
10449 Will create a dump of iCode's, after global subexpression elimination
10450 \begin_inset LatexCommand \index{Global subexpression elimination}
10454 , into a file named
10456 <source filename>.dumpgcse.
10460 \labelwidthstring 00.00.0000
10467 \begin_layout Standard
10477 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10483 Will create a dump of iCode's, after deadcode elimination
10484 \begin_inset LatexCommand \index{Dead-code elimination}
10488 , into a file named
10490 <source filename>.dumpdeadcode.
10494 \labelwidthstring 00.00.0000
10501 \begin_layout Standard
10511 \begin_inset LatexCommand \index{-\/-dumploop}
10520 Will create a dump of iCode's, after loop optimizations
10521 \begin_inset LatexCommand \index{Loop optimization}
10525 , into a file named
10527 <source filename>.dumploop.
10531 \labelwidthstring 00.00.0000
10538 \begin_layout Standard
10548 \begin_inset LatexCommand \index{-\/-dumprange}
10557 Will create a dump of iCode's, after live range analysis
10558 \begin_inset LatexCommand \index{Live range analysis}
10562 , into a file named
10564 <source filename>.dumprange.
10568 \labelwidthstring 00.00.0000
10575 \begin_layout Standard
10585 \begin_inset LatexCommand \index{-\/-dumlrange}
10591 Will dump the life ranges
10592 \begin_inset LatexCommand \index{Live range analysis}
10600 \labelwidthstring 00.00.0000
10607 \begin_layout Standard
10617 \begin_inset LatexCommand \index{-\/-dumpregassign}
10626 Will create a dump of iCode's, after register assignment
10627 \begin_inset LatexCommand \index{Register assignment}
10631 , into a file named
10633 <source filename>.dumprassgn.
10637 \labelwidthstring 00.00.0000
10644 \begin_layout Standard
10654 \begin_inset LatexCommand \index{-\/-dumplrange}
10660 Will create a dump of the live ranges of iTemp's
10664 \labelwidthstring 00.00.0000
10671 \begin_layout Standard
10681 \begin_inset LatexCommand \index{-\/-dumpall}
10692 Will cause all the above mentioned dumps to be created.
10695 \begin_layout Standard
10696 \begin_inset VSpace bigskip
10702 \begin_layout Subsection
10703 Redirecting output on Windows Shells
10706 \begin_layout Standard
10707 By default SDCC writes it's error messages to
10708 \begin_inset Quotes sld
10712 \begin_inset Quotes srd
10716 To force all messages to
10717 \begin_inset Quotes sld
10721 \begin_inset Quotes srd
10733 \begin_layout Standard
10748 \begin_inset LatexCommand \index{-\/-use-stdout}
10753 Additionally, if you happen to have visual studio installed in your windows
10754 machine, you can use it to compile your sources using a custom build and
10761 \begin_layout Standard
10773 \begin_inset LatexCommand \index{-\/-vc}
10778 Something like this should work:
10797 \begin_layout Standard
10816 \begin_layout Standard
10828 -model-large -c $(InputPath)
10831 \begin_inset VSpace bigskip
10837 \begin_layout Section
10838 Environment variables
10839 \begin_inset LatexCommand \index{Environment variables}
10846 \begin_layout Standard
10847 SDCC recognizes the following environment variables:
10851 \labelwidthstring 00.00.0000
10855 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10861 SDCC installs a signal handler
10862 \begin_inset LatexCommand \index{signal handler}
10866 to be able to delete temporary files after an user break (^C) or an exception.
10867 If this environment variable is set, SDCC won't install the signal handler
10868 in order to be able to debug SDCC.
10872 \labelwidthstring 00.00.0000
10878 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10884 Path, where temporary files will be created.
10885 The order of the variables is the search order.
10886 In a standard *nix environment these variables are not set, and there's
10887 no need to set them.
10888 On Windows it's recommended to set one of them.
10892 \labelwidthstring 00.00.0000
10896 \begin_inset LatexCommand \index{SDCC\_HOME}
10903 \begin_inset LatexCommand \ref{sub:Install-paths}
10909 \begin_inset Quotes sld
10913 \begin_inset Quotes srd
10920 \labelwidthstring 00.00.0000
10924 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10931 \begin_inset LatexCommand \ref{sub:Search-Paths}
10937 \begin_inset Quotes sld
10941 \begin_inset Quotes srd
10948 \labelwidthstring 00.00.0000
10952 \begin_inset LatexCommand \index{SDCC\_LIB}
10959 \begin_inset LatexCommand \ref{sub:Search-Paths}
10965 \begin_inset Quotes sld
10969 \begin_inset Quotes srd
10975 \begin_layout Standard
10976 There are some more environment variables recognized by SDCC, but these
10977 are solely used for debugging purposes.
10978 They can change or disappear very quickly, and will never be documented.
10979 \begin_inset VSpace bigskip
10985 \begin_layout Section
10986 Storage Class Language Extensions
10989 \begin_layout Subsection
10990 MCS51/DS390 Storage Class
10991 \begin_inset LatexCommand \index{Storage class}
10995 Language Extensions
10998 \begin_layout Standard
10999 In addition to the ANSI storage classes SDCC allows the following MCS51
11000 specific storage classes:
11003 \begin_layout Subsubsection
11005 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11010 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11015 \begin_inset LatexCommand \index{near (storage class)}
11020 \begin_inset LatexCommand \index{\_\_near (storage class)}
11027 \begin_layout Standard
11032 storage class for the Small Memory model (
11040 or the more ANSI-C compliant forms
11048 can be used synonymously).
11049 Variables declared with this storage class will be allocated in the directly
11050 addressable portion of the internal RAM of a 8051, e.g.:
11053 \begin_layout Verse
11056 __data unsigned char test_data;
11059 \begin_layout Standard
11060 Writing 0x01 to this variable generates the assembly code:
11063 \begin_layout Verse
11066 75*00 01\InsetSpace ~
11074 \begin_layout Subsubsection
11076 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11081 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11086 \begin_inset LatexCommand \index{far (storage class)}
11091 \begin_inset LatexCommand \index{\_\_far (storage class)}
11098 \begin_layout Standard
11099 Variables declared with this storage class will be placed in the external
11105 storage class for the Large Memory model, e.g.:
11108 \begin_layout Verse
11111 __xdata unsigned char test_xdata;
11114 \begin_layout Standard
11115 Writing 0x01 to this variable generates the assembly code:
11118 \begin_layout Verse
11121 90s00r00\InsetSpace ~
11152 \begin_layout Subsubsection
11154 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11159 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11166 \begin_layout Standard
11167 Variables declared with this storage class will be allocated into the indirectly
11168 addressable portion of the internal ram of a 8051, e.g.:
11171 \begin_layout Verse
11174 __idata unsigned char test_idata;
11177 \begin_layout Standard
11178 Writing 0x01 to this variable generates the assembly code:
11181 \begin_layout Verse
11208 \begin_layout Standard
11209 Please note, the first 128 byte of idata physically access the same RAM
11210 as the data memory.
11211 The original 8051 had 128 byte idata memory, nowadays most devices have
11212 256 byte idata memory.
11214 \begin_inset LatexCommand \index{stack}
11218 is located in idata memory.
11221 \begin_layout Subsubsection
11223 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11228 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11235 \begin_layout Standard
11236 Paged xdata access is just as straightforward as using the other addressing
11238 It is typically located at the start of xdata and has a maximum size of
11240 The following example writes 0x01 to the pdata variable.
11241 Please note, pdata access physically accesses xdata memory.
11242 The high byte of the address is determined by port P2
11243 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11247 (or in case of some 8051 variants by a separate Special Function Register,
11249 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11258 storage class for the Medium Memory model, e.g.:
11261 \begin_layout Verse
11264 __pdata unsigned char test_pdata;
11267 \begin_layout Standard
11268 Writing 0x01 to this variable generates the assembly code:
11271 \begin_layout Verse
11280 mov r0,#_test_pdata
11302 \begin_layout Standard
11307 \begin_layout Standard
11317 \begin_inset LatexCommand \index{-\/-xstack}
11321 option is used the pdata memory area is followed by the xstack memory area
11322 and the sum of their sizes is limited to 256 bytes.
11325 \begin_layout Subsubsection
11327 \begin_inset LatexCommand \index{code}
11332 \begin_inset LatexCommand \index{\_\_code}
11339 \begin_layout Standard
11340 'Variables' declared with this storage class will be placed in the code
11344 \begin_layout Verse
11347 __code unsigned char test_code;
11350 \begin_layout Standard
11351 Read access to this variable generates the assembly code:
11354 \begin_layout Verse
11357 90s00r6F\InsetSpace ~
11360 mov dptr,#_test_code
11385 \begin_layout Standard
11390 indexed arrays of characters in code memory can be accessed efficiently:
11393 \begin_layout Verse
11396 __code char test_array[] = {'c','h','e','a','p'};
11399 \begin_layout Standard
11400 Read access to this array using an 8-bit unsigned index generates the assembly
11404 \begin_layout Verse
11416 \begin_layout Verse
11419 90s00r41\InsetSpace ~
11422 mov dptr,#_test_array
11425 \begin_layout Verse
11440 \begin_layout Subsubsection
11442 \begin_inset LatexCommand \index{bit}
11447 \begin_inset LatexCommand \index{\_\_bit}
11454 \begin_layout Standard
11455 This is a data-type and a storage class specifier.
11456 When a variable is declared as a bit, it is allocated into the bit addressable
11457 memory of 8051, e.g.:
11460 \begin_layout Verse
11466 \begin_layout Standard
11467 Writing 1 to this variable generates the assembly code:
11470 \begin_layout Verse
11484 \begin_layout Standard
11485 The bit addressable memory consists of 128 bits which are located from 0x20
11486 to 0x2f in data memory.
11489 Apart from this 8051 specific storage class most architectures support
11491 \begin_inset LatexCommand \index{bitfields}
11499 \begin_layout Standard
11500 Not really meant as examples, but nevertheless showing what bitfields are
11501 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11507 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11508 signed modifier are implemented as unsigned.
11511 \begin_layout Subsubsection
11513 \begin_inset LatexCommand \index{sfr}
11518 \begin_inset LatexCommand \index{\_\_sfr}
11523 \begin_inset LatexCommand \index{sfr16}
11528 \begin_inset LatexCommand \index{\_\_sfr16}
11533 \begin_inset LatexCommand \index{sfr32}
11538 \begin_inset LatexCommand \index{\_\_sfr32}
11543 \begin_inset LatexCommand \index{\_\_sbit}
11548 \begin_inset LatexCommand \index{sbit}
11555 \begin_layout Standard
11556 Like the bit keyword,
11558 sfr / sfr16 / sfr32 / sbit
11560 signify both a data-type and storage class, they are used to describe the
11581 variables of a 8051, eg:
11584 \begin_layout Verse
11588 \begin_inset LatexCommand \index{at}
11593 \begin_inset LatexCommand \index{\_\_at}
11597 (0x80) P0;\InsetSpace ~
11598 /* special function register P0 at location 0x80 */
11603 special function register combination for timer 0
11607 with the high byte at
11608 location 0x8C and the low byte at location 0x8A */
11610 __sfr16 __at (0x8C8A)
11616 \begin_inset LatexCommand \index{at}
11621 \begin_inset LatexCommand \index{\_\_at}
11625 (0xd7) CY;\InsetSpace ~
11627 \begin_inset LatexCommand \index{Flags}
11632 \begin_inset LatexCommand \index{Carry flag}
11639 \begin_layout Standard
11640 Special function registers which are located on an address dividable by
11641 8 are bit-addressable, an
11645 addresses a specific bit within these sfr.
11647 16 Bit and 32 bit special function
11648 register combinations which require a certain access order are better not
11658 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11659 this is not guaranteed.
11664 \begin_layout Standard
11665 Please note, if you use a header file which was written for another compiler
11666 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11672 Specifically the syntax
11675 sfr P0 = 0x80;\InsetSpace ~
11682 by SDCC to an assignment of 0x80 to a variable called P0
11685 \begin_inset Marginal
11688 \begin_layout Standard
11700 Nevertheless it is possible to write header files
11701 \begin_inset LatexCommand \index{Header files}
11706 \begin_inset LatexCommand \index{Include files}
11710 which can be shared among different compilers (see section
11711 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11719 \begin_layout Subsubsection
11721 \begin_inset LatexCommand \index{Pointer}
11725 to MCS51/DS390 specific memory spaces
11728 \begin_layout Standard
11729 SDCC allows (via language extensions) pointers to explicitly point to any
11730 of the memory spaces
11731 \begin_inset LatexCommand \index{Memory model}
11736 In addition to the explicit pointers, the compiler uses (by default) generic
11737 pointers which can be used to point to any of the memory spaces.
11742 declaration examples:
11745 \begin_layout Verse
11748 /* pointer physically in internal ram pointing to object in external ram
11751 __xdata unsigned char * __data p;
11755 /* pointer physically in external ram
11756 pointing to object in internal ram */
11758 __data unsigned char * __xdata p;
11763 pointer physically in code rom pointing to data in xdata space */
11766 unsigned char * __code p;
11770 /* pointer physically in code space pointing to
11771 data in code space */
11773 __code unsigned char * __code p;
11778 physically located in xdata space */
11780 unsigned char * __xdata p;
11785 pointer physically located in default memory space */
11792 the following is a function pointer
11793 \begin_inset LatexCommand \index{function pointer}
11797 physically located in data space */
11799 char (* __data fp)(void);
11802 \begin_layout Standard
11803 Well you get the idea.
11808 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
11821 The highest order byte of the
11825 pointers contains the data space information.
11826 Assembler support routines are called whenever data is stored or retrieved
11832 These are useful for developing reusable library
11833 \begin_inset LatexCommand \index{Libraries}
11838 Explicitly specifying the pointer
11839 \begin_inset LatexCommand \index{pointer}
11843 type will generate the most efficient code.
11846 \begin_layout Subsubsection
11847 Notes on MCS51 memory
11848 \begin_inset LatexCommand \index{MCS51 memory}
11855 \begin_layout Standard
11856 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11857 RAM memory which is structured as follows:
11861 - Bytes 00-1F - 32 bytes to hold
11862 up to 4 banks of the registers R0 to R7,
11864 - Bytes 20-2F - 16 bytes to hold
11866 \begin_inset LatexCommand \index{bit}
11872 - Bytes 30-7F - 80 bytes for general purpose use.
11877 \begin_layout Standard
11878 Additionally some members of the MCS51 family may have up to 128 bytes of
11879 additional, indirectly addressable, internal RAM memory (
11884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11889 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11894 Furthermore, some chips may have some built in external memory (
11899 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11904 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11908 ) which should not be confused with the internal, directly addressable RAM
11914 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11919 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11924 Sometimes this built in
11928 memory has to be activated before using it (you can probably find this
11929 information on the datasheet of the microcontroller your are using, see
11931 \begin_inset LatexCommand \ref{sub:Startup-Code}
11939 \begin_layout Standard
11940 Normally SDCC will only use the first bank
11941 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11945 of registers (register bank 0), but it is possible to specify that other
11946 banks of registers (keyword
11953 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11958 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11964 ) should be used for example in interrupt
11965 \begin_inset LatexCommand \index{interrupt}
11970 \begin_inset LatexCommand \index{\_\_interrupt}
11975 By default, the compiler will place the stack after the last byte of allocated
11976 memory for variables.
11977 For example, if the first 2 banks of registers are used, and only four
11982 variables, it will position the base of the internal stack at address 20
11984 This implies that as the stack
11985 \begin_inset LatexCommand \index{stack}
11989 grows, it will use up the remaining register banks, and the 16 bytes used
11990 by the 128 bit variables, and 80 bytes for general purpose use.
11991 If any bit variables are used, the data variables will be placed in unused
11992 register banks and after the byte holding the last bit variable.
11993 For example, if register banks 0 and 1 are used, and there are 9 bit variables
11998 variables will be placed starting from address 0x10 to 0x20 and continue
12004 \begin_layout Standard
12014 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12018 to specify the start address of the
12026 \begin_layout Standard
12036 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12040 to specify the size of the total internal RAM (
12054 \begin_layout Standard
12055 By default the 8051 linker will place the stack after the last byte of (i)data
12061 \begin_layout Standard
12071 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12075 allows you to specify the start of the stack, i.e.
12076 you could start it after any data in the general purpose area.
12077 If your microcontroller has additional indirectly addressable internal
12082 ) you can place the stack on it.
12083 You may also need to use -
12087 \begin_layout Standard
12097 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12101 to set the start address of the external RAM (
12109 \begin_layout Standard
12119 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12123 to specify its size.
12124 Same goes for the code memory, using -
12128 \begin_layout Standard
12138 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12146 \begin_layout Standard
12156 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12161 If in doubt, don't specify any options and see if the resulting memory
12162 layout is appropriate, then you can adjust it.
12165 \begin_layout Standard
12166 The linker generates two files with memory allocation information.
12167 The first, with extension .map
12168 \begin_inset LatexCommand \index{<file>.map}
12172 shows all the variables and segments.
12173 The second with extension .mem
12174 \begin_inset LatexCommand \index{<file>.mem}
12178 shows the final memory layout.
12179 The linker will complain either if memory segments overlap, there is not
12180 enough memory, or there is not enough space for stack.
12181 If you get any linking warnings and/or errors related to stack or segments
12182 allocation, take a look at either the .map or .mem files to find out what
12184 The .mem file may even suggest a solution to the problem.
12185 \begin_inset VSpace bigskip
12191 \begin_layout Subsection
12192 Z80/Z180 Storage Class
12193 \begin_inset LatexCommand \index{Z80!Storage class}
12197 Language Extensions
12200 \begin_layout Subsubsection
12202 \begin_inset LatexCommand \index{sfr}
12207 \begin_inset LatexCommand \index{\_\_sfr}
12211 (in/out to 8-bit addresses)
12214 \begin_layout Standard
12216 \begin_inset LatexCommand \index{Z80}
12220 family has separate address spaces for memory and
12230 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12235 \begin_inset LatexCommand \index{Z80!I/O memory}
12240 \begin_inset LatexCommand \index{Z180!I/O memory}
12244 is accessed with special instructions, e.g.:
12247 \begin_layout Verse
12250 sfr at 0x78 IoPort;\InsetSpace ~
12252 /* define a var in I/O space at 78h called IoPort */
12256 \begin_layout Standard
12257 Writing 0x01 to this variable generates the assembly code:
12260 \begin_layout Verse
12280 \begin_layout Subsubsection
12282 \begin_inset LatexCommand \index{sfr}
12287 \begin_inset LatexCommand \index{\_\_sfr}
12291 (in/out to 16-bit addresses)
12294 \begin_layout Standard
12299 is used to support 16 bit addresses in I/O memory e.g.:
12302 \begin_layout Verse
12306 \begin_inset LatexCommand \index{at}
12311 \begin_inset LatexCommand \index{\_\_at}
12318 \begin_layout Standard
12319 Writing 0x01 to this variable generates the assembly code:
12322 \begin_layout Verse
12325 01 23 01\InsetSpace ~
12347 \begin_layout Subsubsection
12349 \begin_inset LatexCommand \index{sfr}
12354 \begin_inset LatexCommand \index{\_\_sfr}
12358 (in0/out0 to 8 bit addresses on Z180
12359 \begin_inset LatexCommand \index{Z180}
12364 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12371 \begin_layout Standard
12372 The compiler option -
12376 \begin_layout Standard
12386 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12390 =180 (80) and a compiler #pragma\InsetSpace ~
12392 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12396 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12406 If you include the file z180.h this will be set automatically.
12407 \begin_inset VSpace bigskip
12413 \begin_layout Subsection
12415 \begin_inset LatexCommand \index{HC08!Storage class}
12419 Language Extensions
12422 \begin_layout Subsubsection
12424 \begin_inset LatexCommand \index{data (hc08 storage class)}
12429 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12436 \begin_layout Standard
12437 The data storage class declares a variable that resides in the first 256
12438 bytes of memory (the direct page).
12440 \begin_inset LatexCommand \index{HC08}
12444 is most efficient at accessing variables (especially pointers) stored here.
12447 \begin_layout Subsubsection
12449 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12454 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12461 \begin_layout Standard
12462 The xdata storage class declares a variable that can reside anywhere in
12464 This is the default if no storage class is specified.
12466 \begin_inset VSpace bigskip
12472 \begin_layout Section
12473 Absolute Addressing
12474 \begin_inset LatexCommand \index{Absolute addressing}
12481 \begin_layout Standard
12482 Data items can be assigned an absolute address with the
12485 \begin_inset LatexCommand \index{at}
12490 \begin_inset LatexCommand \index{\_\_at}
12496 keyword, in addition to a storage class, e.g.:
12499 \begin_layout Verse
12503 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12508 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12513 \begin_inset LatexCommand \index{at}
12518 \begin_inset LatexCommand \index{\_\_at}
12522 0x7ffe unsigned int chksum;
12525 \begin_layout Standard
12526 or, better conforming to ISO/IEC 9899 C:
12529 \begin_layout Verse
12532 __xdata __at (0x7ffe) unsigned int chksum;
12535 \begin_layout Standard
12536 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12537 of the external ram.
12542 reserve any space for variables declared in this way
12543 \begin_inset Marginal
12546 \begin_layout Standard
12555 (they are implemented with an equate in the assembler).
12556 Thus it is left to the programmer to make sure there are no overlaps with
12557 other variables that are declared without the absolute address.
12558 The assembler listing file (.lst
12559 \begin_inset LatexCommand \index{<file>.lst}
12563 ) and the linker output files (.rst
12564 \begin_inset LatexCommand \index{<file>.rst}
12569 \begin_inset LatexCommand \index{<file>.map}
12573 ) are good places to look for such overlaps.
12574 Variables with an absolute address are
12577 \begin_inset Marginal
12580 \begin_layout Standard
12592 \begin_inset LatexCommand \index{Variable initialization}
12599 \begin_layout Standard
12600 In case of memory mapped I/O devices the keyword
12604 has to be used to tell the compiler that accesses might not be removed:
12607 \begin_layout Verse
12611 \begin_inset LatexCommand \index{volatile}
12616 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12621 \begin_inset LatexCommand \index{at}
12625 (0x8000) unsigned char PORTA_8255;
12628 \begin_layout Standard
12629 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12634 \begin_inset LatexCommand \index{Aligned array}
12641 starts at a block (256 byte) boundary
12642 \begin_inset LatexCommand \index{block boundary}
12647 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12653 Absolute addresses can be specified for variables in all
12654 storage classes, e.g.:
12657 \begin_layout Verse
12661 \begin_inset LatexCommand \index{bit}
12666 \begin_inset LatexCommand \index{at}
12673 \begin_layout Standard
12674 The above example will allocate the variable at offset 0x02 in the bit-addressab
12676 There is no real advantage to assigning absolute addresses to variables
12677 in this manner, unless you want strict control over all the variables allocated.
12678 One possible use would be to write hardware portable code.
12679 For example, if you have a routine that uses one or more of the microcontroller
12680 I/O pins, and such pins are different for two different hardwares, you
12681 can declare the I/O pins in your routine using:
12684 \begin_layout Verse
12688 \begin_inset LatexCommand \index{volatile}
12692 __bit MOSI;\InsetSpace ~
12696 /* master out, slave in */
12698 extern volatile __bit MISO;\InsetSpace ~
12705 extern volatile __bit MCLK;\InsetSpace ~
12714 Output of a byte on a 3-wire serial bus.
12719 If needed adapt polarity of clock,
12720 polarity of data and bit order
12725 unsigned char spi_io(unsigned char out_byte)
12750 MOSI = out_byte & 0x80;
12781 /* _asm nop _endasm; */\InsetSpace ~
12789 /* for slow peripherals */
12841 \begin_layout Standard
12842 Then, someplace in the code for the first hardware you would use
12845 \begin_layout Verse
12849 \begin_inset LatexCommand \index{at}
12854 \begin_inset LatexCommand \index{\_\_at}
12858 (0x80) MOSI;\InsetSpace ~
12862 /* I/O port 0, bit 0 */
12864 __bit __at (0x81) MISO;\InsetSpace ~
12871 __bit __at (0x82) MCLK;\InsetSpace ~
12875 /* I/O port 0, bit 2 */
12878 \begin_layout Standard
12879 Similarly, for the second hardware you would use
12882 \begin_layout Verse
12885 __bit __at (0x83) MOSI;\InsetSpace ~
12889 /* I/O port 0, bit 3 */
12891 __bit __at (0x91) MISO;\InsetSpace ~
12896 I/O port 1, bit 1 */
12899 \begin_inset LatexCommand \index{bit}
12903 __at (0x92) MCLK;\InsetSpace ~
12907 /* I/O port 1, bit 2 */
12910 \begin_layout Standard
12911 and you can use the same hardware dependent routine without changes, as
12912 for example in a library.
12913 This is somehow similar to sbit, but only one absolute address has to be
12914 specified in the whole project.
12915 \begin_inset VSpace bigskip
12921 \begin_layout Section
12923 \begin_inset LatexCommand \index{Parameters}
12928 \begin_inset LatexCommand \index{function parameter}
12933 \begin_inset LatexCommand \index{local variables}
12938 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12945 \begin_layout Standard
12946 Automatic (local) variables and parameters to functions can either be placed
12947 on the stack or in data-space.
12948 The default action of the compiler is to place these variables in the internal
12949 RAM (for small model) or external RAM (for large model).
12950 This in fact makes them similar to
12953 \begin_inset LatexCommand \index{static}
12959 so by default functions are non-reentrant
12960 \begin_inset LatexCommand \index{reentrant}
12969 They can be placed on the stack
12970 \begin_inset LatexCommand \index{stack}
12980 \begin_layout Standard
12990 \begin_inset LatexCommand \index{-\/-stack-auto}
12998 #pragma\InsetSpace ~
13002 \begin_inset LatexCommand \index{\#pragma stackauto}
13009 \begin_inset LatexCommand \index{reentrant}
13015 keyword in the function declaration, e.g.:
13018 \begin_layout Verse
13021 unsigned char foo(char i) __reentrant
13035 \begin_layout Standard
13036 Since stack space on 8051 is limited, the
13046 \begin_layout Standard
13057 option should be used sparingly.
13058 Note that the reentrant keyword just means that the parameters & local
13059 variables will be allocated to the stack, it
13063 mean that the function is register bank
13064 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13073 \begin_inset LatexCommand \index{local variables}
13077 can be assigned storage classes and absolute
13078 \begin_inset LatexCommand \index{Absolute addressing}
13085 \begin_layout Verse
13088 unsigned char foo()
13096 __xdata unsigned char i;
13109 \begin_inset LatexCommand \index{at}
13113 (0x31) unsigned char j;
13125 \begin_layout Standard
13126 In the above example the variable
13130 will be allocated in the external ram,
13134 in bit addressable space and
13145 \begin_layout Standard
13156 or when a function is declared as
13160 this should only be done for static variables.
13163 \begin_layout Standard
13165 \begin_inset LatexCommand \index{function parameter}
13169 however are not allowed any storage class
13170 \begin_inset LatexCommand \index{Storage class}
13174 , (storage classes for parameters will be ignored), their allocation is
13175 governed by the memory model in use, and the reentrancy options.
13178 \begin_layout Standard
13179 It is however allowed to use bit parameters in reentrant functions and also
13180 non-static local bit variables are supported.
13181 Efficient use is limited to 8 semi-bitregisters in bit space.
13182 They are pushed and popped to stack
13183 \begin_inset LatexCommand \index{stack}
13187 as a single byte just like the normal registers.
13190 \begin_layout Section
13192 \begin_inset LatexCommand \label{sub:Overlaying}
13197 \begin_inset LatexCommand \index{Overlaying}
13204 \begin_layout Standard
13206 \begin_inset LatexCommand \index{reentrant}
13210 functions SDCC will try to reduce internal ram space usage by overlaying
13211 parameters and local variables of a function (if possible).
13212 Parameters and local variables
13213 \begin_inset LatexCommand \index{local variables}
13217 of a function will be allocated to an overlayable segment if the function
13220 no other function calls and the function is non-reentrant and the memory
13222 \begin_inset LatexCommand \index{Memory model}
13229 If an explicit storage class
13230 \begin_inset LatexCommand \index{Storage class}
13234 is specified for a local variable, it will NOT be overlayed.
13237 \begin_layout Standard
13238 Note that the compiler (not the linkage editor) makes the decision for overlayin
13240 Functions that are called from an interrupt service routine
13241 \begin_inset Marginal
13244 \begin_layout Standard
13252 should be preceded by a #pragma\InsetSpace ~
13254 \begin_inset LatexCommand \index{\#pragma nooverlay}
13258 if they are not reentrant.
13261 \begin_layout Standard
13262 Also note that the compiler does not do any processing of inline assembler
13263 code, so the compiler might incorrectly assign local variables and parameters
13264 of a function into the overlay segment if the inline assembler code calls
13265 other c-functions that might use the overlay.
13266 In that case the #pragma\InsetSpace ~
13267 nooverlay should be used.
13270 \begin_layout Standard
13271 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13273 \begin_inset LatexCommand \index{Multiplication}
13278 \begin_inset LatexCommand \index{Division}
13282 will NOT be overlayed since these are implemented using external functions,
13286 \begin_layout Verse
13292 \begin_inset LatexCommand \index{\#pragma nooverlay}
13298 void set_error(unsigned char errcd)
13315 some_isr () __interrupt
13316 \begin_inset LatexCommand \index{interrupt}
13346 \begin_layout Standard
13347 In the above example the parameter
13355 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13357 not present, this could cause unpredictable runtime behavior when called
13358 from an interrupt service routine.
13359 The #pragma\InsetSpace ~
13360 nooverlay ensures that the parameters and local variables for
13361 the function are NOT overlayed.
13362 \begin_inset VSpace bigskip
13368 \begin_layout Section
13369 Interrupt Service Routines
13370 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13377 \begin_layout Subsection
13378 General Information
13381 \begin_layout Standard
13394 outines to be coded in C, with some extended keywords.
13397 \begin_layout Verse
13400 void timer_isr (void) __interrupt (1) __using (1)
13414 \begin_layout Standard
13415 The optional number following the
13418 \begin_inset LatexCommand \index{interrupt}
13423 \begin_inset LatexCommand \index{\_\_interrupt}
13429 keyword is the interrupt number this routine will service.
13430 When present, the compiler will insert a call to this routine in the interrupt
13432 \begin_inset LatexCommand \index{interrupt vector table}
13436 for the interrupt number specified.
13437 If you have multiple source files in your project, interrupt service routines
13438 can be present in any of them, but a prototype of the isr MUST be present
13439 or included in the file that contains the function
13444 The optional (8051 specific) keyword
13447 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13452 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13458 can be used to tell the compiler to use the specified register bank when
13459 generating code for this function.
13462 Interrupt service routines open the door for some very interesting bugs:
13465 \begin_layout Subsubsection
13466 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13470 Common interrupt pitfall: variable not declared
13475 \begin_layout Standard
13476 If an interrupt service routine changes variables which are accessed by
13477 other functions these variables have to be declared
13482 \begin_inset LatexCommand \index{volatile}
13488 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13495 \begin_layout Subsubsection
13496 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13500 Common interrupt pitfall:
13505 \begin_layout Standard
13506 If the access to these variables is not
13509 \begin_inset LatexCommand \index{atomic}
13516 the processor needs more than one instruction for the access and could
13517 be interrupted while accessing the variable) the interrupt must be disabled
13518 during the access to avoid inconsistent data.
13521 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13522 and should be protected by disabling interrupts.
13523 You're not automatically on the safe side if you use 8 bit variables though.
13524 We need an example here: f.e.
13525 on the 8051 the harmless looking
13526 \begin_inset Quotes srd
13536 \begin_inset Quotes sld
13545 \begin_inset Quotes srd
13555 \begin_inset Quotes sld
13558 from within an interrupt routine might get lost if the interrupt occurs
13561 \begin_inset Quotes sld
13566 counter\InsetSpace ~
13571 \begin_inset Quotes srd
13574 is not atomic on the 8051 even if
13578 is located in data memory.
13580 Bugs like these are hard to reproduce and can
13581 cause a lot of trouble.
13585 \begin_layout Subsubsection
13586 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13590 Common interrupt pitfall:
13595 \begin_layout Standard
13596 The return address and the registers used in the interrupt service routine
13597 are saved on the stack
13598 \begin_inset LatexCommand \index{stack}
13602 so there must be sufficient stack space.
13603 If there isn't variables or registers (or even the return address itself)
13610 \begin_inset LatexCommand \index{stack overflow}
13614 is most likely to happen if the interrupt occurs during the
13615 \begin_inset Quotes sld
13619 \begin_inset Quotes srd
13622 subroutine when the stack is already in use for f.e.
13623 many return addresses.
13626 \begin_layout Subsubsection
13627 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13631 Common interrupt pitfall:
13633 use of non-reentrant functions
13636 \begin_layout Standard
13637 A special note here, int (16 bit) and long (32 bit) integer division
13638 \begin_inset LatexCommand \index{Division}
13643 \begin_inset LatexCommand \index{Multiplication}
13648 \begin_inset LatexCommand \index{Modulus}
13653 \begin_inset LatexCommand \index{Floating point support}
13657 operations are implemented using external support routines.
13658 If an interrupt service routine needs to do any of these operations then
13659 the support routines (as mentioned in a following section) will have to
13660 be recompiled using the
13666 \begin_layout Standard
13676 \begin_inset LatexCommand \index{-\/-stack-auto}
13682 option and the source file will need to be compiled using the
13688 \begin_layout Standard
13700 \begin_inset LatexCommand \index{-\/-int-long-reent}
13707 Note, the type promotion
13708 \begin_inset LatexCommand \index{type promotion}
13712 required by ANSI C can cause 16 bit routines to be used
13713 \begin_inset Marginal
13716 \begin_layout Standard
13725 without the programmer being aware of it.
13729 (unsigned char)(tail-1)
13731 within the if clause in section
13732 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13739 \begin_layout Standard
13740 Calling other functions from an interrupt service routine is not recommended,
13741 avoid it if possible.
13742 Note that when some function is called from an interrupt service routine
13743 it should be preceded by a #pragma\InsetSpace ~
13745 \begin_inset LatexCommand \index{\#pragma nooverlay}
13749 if it is not reentrant.
13750 Furthermore nonreentrant functions should not be called from the main program
13751 while the interrupt service routine might be active.
13752 They also must not be called from low priority interrupt service routines
13753 while a high priority interrupt service routine might be active.
13754 You could use semaphores or make the function
13758 if all parameters are passed in registers.
13761 \begin_inset LatexCommand \ref{sub:Overlaying}
13766 about Overlaying and section
13767 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13772 about Functions using private register banks.
13773 \begin_inset VSpace bigskip
13779 \begin_layout Subsection
13780 MCS51/DS390 Interrupt Service Routines
13783 \begin_layout Standard
13785 \begin_inset LatexCommand \index{interrupt}
13789 numbers and the corresponding address & descriptions for the Standard 8051/8052
13791 SDCC will automatically adjust the
13792 \begin_inset LatexCommand \index{interrupt vector table}
13796 to the maximum interrupt number specified.
13801 \begin_layout Standard
13803 \begin_inset Tabular
13804 <lyxtabular version="3" rows="9" columns="3">
13806 <column alignment="center" valignment="top" leftline="true" width="0in">
13807 <column alignment="left" valignment="top" leftline="true" width="0in">
13808 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13809 <row topline="true" bottomline="true">
13810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13813 \begin_layout Standard
13819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13822 \begin_layout Standard
13828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13831 \begin_layout Standard
13838 <row topline="true">
13839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13842 \begin_layout Standard
13848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13851 \begin_layout Standard
13857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13860 \begin_layout Standard
13867 <row topline="true">
13868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13871 \begin_layout Standard
13877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13880 \begin_layout Standard
13886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13889 \begin_layout Standard
13896 <row topline="true">
13897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13900 \begin_layout Standard
13906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13909 \begin_layout Standard
13915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13918 \begin_layout Standard
13925 <row topline="true">
13926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13929 \begin_layout Standard
13935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13938 \begin_layout Standard
13944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13947 \begin_layout Standard
13954 <row topline="true">
13955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13958 \begin_layout Standard
13964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13967 \begin_layout Standard
13973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13976 \begin_layout Standard
13983 <row topline="true">
13984 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13987 \begin_layout Standard
13993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13996 \begin_layout Standard
14002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14005 \begin_layout Standard
14012 <row topline="true">
14013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14016 \begin_layout Standard
14022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14025 \begin_layout Standard
14031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14034 \begin_layout Standard
14041 <row topline="true" bottomline="true">
14042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14045 \begin_layout Standard
14051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14054 \begin_layout Standard
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14063 \begin_layout Standard
14079 \begin_layout Standard
14080 If the interrupt service routine is defined without
14083 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14088 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14094 a register bank or with register bank 0 (
14098 0), the compiler will save the registers used by itself on the stack upon
14099 entry and restore them at exit, however if such an interrupt service routine
14100 calls another function then the entire register bank will be saved on the
14102 This scheme may be advantageous for small interrupt service routines which
14103 have low register usage.
14106 \begin_layout Standard
14107 If the interrupt service routine is defined to be using a specific register
14112 & psw are saved and restored, if such an interrupt service routine calls
14113 another function (using another register bank) then the entire register
14114 bank of the called function will be saved on the stack
14115 \begin_inset LatexCommand \index{stack}
14120 This scheme is recommended for larger interrupt service routines.
14121 \begin_inset VSpace bigskip
14127 \begin_layout Subsection
14129 \begin_inset LatexCommand \index{HC08}
14133 Interrupt Service Routines
14136 \begin_layout Standard
14137 Since the number of interrupts
14138 \begin_inset LatexCommand \index{HC08!interrupt}
14142 available is chip specific and the interrupt vector table always ends at
14143 the last byte of memory, the interrupt numbers corresponds to the interrupt
14144 vectors in reverse order of address.
14145 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14146 2 will use the interrupt vector at 0xfffa, and so on.
14147 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14148 this way; instead see section
14149 \begin_inset LatexCommand \ref{sub:Startup-Code}
14153 for details on customizing startup.
14154 \begin_inset VSpace bigskip
14160 \begin_layout Subsection
14161 Z80 Interrupt Service Routines
14164 \begin_layout Standard
14166 \begin_inset LatexCommand \index{Z80}
14170 uses several different methods for determining the correct interrupt
14171 \begin_inset LatexCommand \index{Z80!interrupt}
14175 vector depending on the hardware implementation.
14176 Therefore, SDCC ignores the optional interrupt number and does not attempt
14177 to generate an interrupt vector table.
14180 \begin_layout Standard
14181 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14182 instruction to return from the interrupt.
14183 To write an interrupt handler for the non-maskable interrupt, which needs
14184 a RETN instruction instead, add the
14191 \begin_layout Verse
14194 void nmi_isr (void) critical interrupt
14208 \begin_layout Standard
14209 However if you need to create a non-interruptable interrupt service routine
14210 you would also require the
14215 To distinguish between this and an nmi_isr you must provide an interrupt
14217 \begin_inset VSpace bigskip
14223 \begin_layout Section
14224 Enabling and Disabling Interrupts
14227 \begin_layout Subsection
14228 Critical Functions and Critical Statements
14231 \begin_layout Standard
14232 A special keyword may be associated with a block or a function declaring
14238 SDCC will generate code to disable all interrupts
14239 \begin_inset LatexCommand \index{interrupt}
14243 upon entry to a critical function and restore the interrupt enable to the
14244 previous state before returning.
14245 Nesting critical functions will need one additional byte on the stack
14246 \begin_inset LatexCommand \index{stack}
14253 \begin_layout Verse
14256 int foo () __critical
14257 \begin_inset LatexCommand \index{critical}
14262 \begin_inset LatexCommand \index{\_\_critical}
14287 \begin_layout Standard
14288 The critical attribute maybe used with other attributes like
14298 may also be used to disable interrupts more locally:
14301 \begin_layout Verse
14307 \begin_layout Standard
14308 More than one statement could have been included in the block.
14311 \begin_layout Subsection
14312 Enabling and Disabling Interrupts directly
14315 \begin_layout Standard
14317 \begin_inset LatexCommand \index{interrupt}
14321 can also be disabled and enabled directly (8051):
14324 \begin_layout Verse
14327 EA = 0;\InsetSpace ~
14353 \begin_layout Verse
14389 \begin_layout Verse
14392 EA = 1;\InsetSpace ~
14421 \begin_layout Verse
14460 \begin_layout Standard
14461 On other architectures which have seperate opcodes for enabling and disabling
14462 interrupts you might want to make use of defines with inline assembly
14463 \begin_inset LatexCommand \index{Assembler routines}
14468 \begin_inset LatexCommand \index{HC08!interrupt}
14475 \begin_layout Verse
14479 \begin_inset LatexCommand \index{\_asm}
14488 \begin_inset LatexCommand \index{\_endasm}
14495 \begin_layout Verse
14498 #define SEI _asm\InsetSpace ~
14505 \begin_layout Verse
14511 \begin_layout Standard
14512 Note: it is sometimes sufficient to disable only a specific interrupt source
14514 a timer or serial interrupt by manipulating an
14517 \begin_inset LatexCommand \index{interrupt mask}
14527 \begin_layout Standard
14528 Usually the time during which interrupts are disabled should be kept as
14530 This minimizes both
14535 \begin_inset LatexCommand \index{interrupt latency}
14539 (the time between the occurrence of the interrupt and the execution of
14540 the first code in the interrupt routine) and
14545 \begin_inset LatexCommand \index{interrupt jitter}
14549 (the difference between the shortest and the longest interrupt latency).
14550 These really are something different, f.e.
14551 a serial interrupt has to be served before its buffer overruns so it cares
14552 for the maximum interrupt latency, whereas it does not care about jitter.
14553 On a loudspeaker driven via a digital to analog converter which is fed
14554 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14555 a much smaller jitter will be very audible.
14558 \begin_layout Standard
14559 You can reenable interrupts within an interrupt routine and on some architecture
14560 s you can make use of two (or more) levels of
14562 interrupt priorities
14565 \begin_inset LatexCommand \index{interrupt priority}
14570 On some architectures which don't support interrupt priorities these can
14571 be implemented by manipulating the interrupt mask and reenabling interrupts
14572 within the interrupt routine.
14573 Check there is sufficient space on the stack
14574 \begin_inset LatexCommand \index{stack}
14578 and don't add complexity unless you have to.
14582 \begin_layout Subsection
14584 \begin_inset LatexCommand \index{semaphore}
14588 locking (mcs51/ds390)
14591 \begin_layout Standard
14592 Some architectures (mcs51/ds390) have an atomic
14593 \begin_inset LatexCommand \index{atomic}
14606 These type of instructions are typically used in preemptive multitasking
14607 systems, where a routine f.e.
14608 claims the use of a data structure ('acquires a lock
14609 \begin_inset LatexCommand \index{lock}
14613 on it'), makes some modifications and then releases the lock when the data
14614 structure is consistent again.
14615 The instruction may also be used if interrupt and non-interrupt code have
14616 to compete for a resource.
14617 With the atomic bit test and clear instruction interrupts
14618 \begin_inset LatexCommand \index{interrupt}
14622 don't have to be disabled for the locking operation.
14626 \begin_layout Standard
14627 SDCC generates this instruction if the source follows this pattern:
14630 \begin_layout Verse
14634 \begin_inset LatexCommand \index{volatile}
14638 bit resource_is_free;
14642 if (resource_is_free)
14652 resource_is_free=0;
14665 resource_is_free=1;
14672 \begin_layout Standard
14673 Note, mcs51 and ds390 support only an atomic
14674 \begin_inset LatexCommand \index{atomic}
14682 instruction (as opposed to atomic bit test and
14687 \begin_layout Section
14688 Functions using private register banks
14689 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14696 \begin_layout Standard
14697 Some architectures have support for quickly changing register sets.
14698 SDCC supports this feature with the
14701 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14706 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14712 attribute (which tells the compiler to use a register bank
14713 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14717 other than the default bank zero).
14718 It should only be applied to
14721 \begin_inset LatexCommand \index{interrupt}
14727 functions (see footnote below).
14728 This will in most circumstances make the generated ISR code more efficient
14729 since it will not have to save registers on the stack.
14732 \begin_layout Standard
14737 attribute will have no effect on the generated code for a
14741 function (but may occasionally be useful anyway
14745 \begin_layout Standard
14746 possible exception: if a function is called ONLY from 'interrupt' functions
14747 using a particular bank, it can be declared with the same 'using' attribute
14748 as the calling 'interrupt' functions.
14749 For instance, if you have several ISRs using bank one, and all of them
14750 call memcpy(), it might make sense to create a specialized version of memcpy()
14751 'using 1', since this would prevent the ISR from having to save bank zero
14752 to the stack on entry and switch to bank zero before calling the function
14761 (pending: Note, nowadays the
14765 attribute has an effect on
14769 the generated code for a
14780 \begin_layout Standard
14785 function using a non-zero bank will assume that it can trash that register
14786 bank, and will not save it.
14787 Since high-priority interrupts
14788 \begin_inset LatexCommand \index{interrupts}
14793 \begin_inset LatexCommand \index{interrupt priority}
14797 can interrupt low-priority ones on the 8051 and friends, this means that
14798 if a high-priority ISR
14802 a particular bank occurs while processing a low-priority ISR
14806 the same bank, terrible and bad things can happen.
14807 To prevent this, no single register bank should be
14811 by both a high priority and a low priority ISR.
14812 This is probably most easily done by having all high priority ISRs use
14813 one bank and all low priority ISRs use another.
14814 If you have an ISR which can change priority at runtime, you're on your
14815 own: I suggest using the default bank zero and taking the small performance
14819 \begin_layout Standard
14820 It is most efficient if your ISR calls no other functions.
14821 If your ISR must call other functions, it is most efficient if those functions
14822 use the same bank as the ISR (see note 1 below); the next best is if the
14823 called functions use bank zero.
14824 It is very inefficient to call a function using a different, non-zero bank
14827 \begin_inset VSpace bigskip
14833 \begin_layout Section
14835 \begin_inset LatexCommand \label{sub:Startup-Code}
14840 \begin_inset LatexCommand \index{Startup code}
14847 \begin_layout Subsection
14848 MCS51/DS390 Startup Code
14851 \begin_layout Standard
14852 The compiler triggers the linker to link certain initialization modules
14853 from the runtime library
14854 \begin_inset LatexCommand \index{Runtime library}
14858 called crt<something>.
14859 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14860 GSINIT5) is not linked unless the --xstack option is used.
14861 These modules are highly entangled by the use of special segments/areas,
14862 but a common layout is shown below:
14865 \begin_layout Verse
14873 \begin_layout Verse
14897 ljmp __sdcc_gsinit_startup
14900 \begin_layout Verse
14908 \begin_layout Verse
14920 .area GSINIT0 (CODE)
14922 __sdcc_gsinit_startup::
14932 mov sp,#__start__stack - 1
14935 \begin_layout Verse
14943 \begin_layout Verse
14955 .area GSINIT1 (CODE)
14957 __sdcc_init_xstack::
14959 ; Need to initialize in GSINIT1 in
14960 case the user's __sdcc_external_startup uses the xstack.
14970 mov __XPAGE,#(__start__x
14981 mov _spx,#__start__xstack
14984 \begin_layout Verse
14992 \begin_layout Verse
15004 .area GSINIT2 (CODE)
15014 lcall __sdcc_external_startup
15034 jz __sdcc_init_data
15045 __sdcc_program_startup
15050 \begin_layout Verse
15058 \begin_layout Verse
15070 .area GSINIT3 (CODE)
15123 mov r2,#((l_XINIT+255) >> 8)
15154 __XPAGE,#(s_XISEG >> 8)
15156 00001$:\InsetSpace ~
15220 00002$:\InsetSpace ~
15247 \begin_layout Verse
15255 \begin_layout Verse
15267 .area GSINIT4 (CODE)
15269 __mcs51_genRAMCLEAR::
15291 00004$:\InsetSpace ~
15305 ; _mcs51_genRAMCLEAR() end
15308 \begin_layout Verse
15316 \begin_layout Verse
15328 .area GSINIT4 (CODE)
15330 __mcs51_genXRAMCLEAR::
15381 mov __XPAGE,#(s_PSEG >> 8)
15393 00005$:\InsetSpace ~
15447 orl a,#(l_XSEG >> 8)
15490 00007$:\InsetSpace ~
15527 \begin_layout Verse
15535 \begin_layout Verse
15547 .area GSINIT5 (CODE)
15549 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15552 ; and __mcs51_genRAMCLEAR modifies _spx.
15562 mov __XPAGE,#(__start__x
15573 mov _spx,#__start__xstack
15576 \begin_layout Verse
15581 (application modules)
15584 \begin_layout Verse
15596 .area GSINIT (CODE)
15599 \begin_layout Verse
15607 \begin_layout Verse
15619 .area GSFINAL (CODE)
15629 ljmp __sdcc_program_startup
15631 ;---------------------------------
15632 -----------------------
15636 ;--------------------------------------------------
15659 __sdcc_program_startup:
15672 return from main will lock up
15685 \begin_layout Standard
15686 One of these modules (crtstart.asm) contains a call to the C routine
15688 _sdcc_external_startup()
15689 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15698 at the start of the CODE area.
15699 This routine is also in the runtime library
15700 \begin_inset LatexCommand \index{Runtime library}
15704 and returns 0 by default.
15705 If this routine returns a non-zero value, the static & global variable
15706 initialization will be skipped and the function main will be invoked.
15707 Otherwise static & global variables will be initialized before the function
15711 _sdcc_external_startup()
15713 routine to your program to override the default if you need to setup hardware
15714 or perform some other critical operation prior to static & global variable
15716 \begin_inset LatexCommand \index{Variable initialization}
15721 On some mcs51 variants xdata
15722 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15726 memory has to be explicitly enabled before it can be accessed or if the
15728 \begin_inset LatexCommand \index{watchdog}
15732 needs to be disabled, this is the place to do it.
15733 The startup code clears all internal data memory, 256 bytes by default,
15734 but from 0 to n-1 if
15740 \begin_layout Standard
15750 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15757 (recommended for Chipcon CC1010).
15760 \begin_layout Standard
15761 See also the compiler options
15767 \begin_layout Standard
15783 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15793 \begin_layout Standard
15805 \begin_inset LatexCommand \index{-\/-main-return}
15810 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15814 about MCS51-variants.
15815 \begin_inset VSpace bigskip
15821 \begin_layout Subsection
15825 \begin_layout Standard
15827 \begin_inset LatexCommand \index{HC08}
15831 startup code follows the same scheme as the MCS51 startup code.
15832 \begin_inset VSpace bigskip
15838 \begin_layout Subsection
15842 \begin_layout Standard
15844 \begin_inset LatexCommand \index{Z80}
15848 the startup code is inserted by linking with crt0.o which is generated from
15849 sdcc/device/lib/z80/crt0.s.
15850 If you need a different startup code you can use the compiler option
15859 \begin_layout Standard
15874 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15878 and provide your own crt0.o.
15880 \begin_inset VSpace bigskip
15886 \begin_layout Section
15887 Inline Assembler Code
15888 \begin_inset LatexCommand \index{Assembler routines}
15895 \begin_layout Subsection
15896 A Step by Step Introduction
15897 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15904 \begin_layout Standard
15905 Starting from a small snippet of c-code this example shows for the MCS51
15906 how to use inline assembly, access variables, a function parameter and
15907 an array in xdata memory.
15908 The example uses an MCS51 here but is easily adapted for other architectures.
15909 This is a buffer routine which should be optimized:
15912 \begin_layout Verse
15916 unsigned char __far
15917 \begin_inset LatexCommand \index{far (storage class)}
15922 \begin_inset LatexCommand \index{\_\_far (storage class)}
15927 \begin_inset LatexCommand \index{at}
15932 \begin_inset LatexCommand \index{\_\_at}
15936 (0x7f00) buf[0x100];
15937 \begin_inset LatexCommand \index{Aligned array}
15943 unsigned char head, tail;\InsetSpace ~
15961 \begin_inset LatexCommand \index{interrupt}
16013 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16025 void to_buffer( unsigned char c )
16033 if( head != (unsigned char)(tail-1)
16040 \begin_inset LatexCommand \index{promotion to signed int}
16045 \begin_inset LatexCommand \index{type promotion}
16050 \begin_inset Marginal
16053 \begin_layout Standard
16072 buf[ head++ ] = c;\InsetSpace ~
16088 /* access to a 256 byte aligned array */
16093 \begin_layout Standard
16094 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16095 then a corresponding buffer.asm file is generated.
16096 We define a new function
16100 in file buffer.c in which we cut and paste the generated code, removing
16101 unwanted comments and some ':'.
16103 \begin_inset Quotes sld
16111 \begin_inset Quotes srd
16115 \begin_inset Quotes sld
16123 \begin_inset Quotes srd
16130 \begin_layout Standard
16131 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16132 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16134 The latter is also used in the library functions.
16139 to the beginning and the end of the function body:
16142 \begin_layout Verse
16146 /* With a cut and paste from the .asm file, we have something to start with.
16152 function is not yet OK! (registers aren't saved) */
16154 void to_buffer_asm(
16164 \begin_inset LatexCommand \index{\_asm}
16169 \begin_inset LatexCommand \index{\_\_asm}
16183 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16189 \begin_inset LatexCommand \index{promotion to signed int}
16194 \begin_inset LatexCommand \index{type promotion}
16247 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16248 \begin_inset LatexCommand \index{Aligned array}
16314 \begin_inset LatexCommand \index{\_endasm}
16319 \begin_inset LatexCommand \index{\_\_endasm}
16328 \begin_layout Standard
16329 The new file buffer.c should compile with only one warning about the unreferenced
16330 function argument 'c'.
16331 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16332 (1) and finally have:
16335 \begin_layout Verse
16339 unsigned char __far __at(0x7f00) buf[0x100];
16341 unsigned char head, tail;
16352 void to_buffer( unsigned char c )
16361 head != (unsigned char)(tail-1) )
16390 c; // to avoid warning: unreferenced function argument
16397 \begin_inset LatexCommand \index{\_asm}
16402 \begin_inset LatexCommand \index{\_\_asm}
16416 ; save used registers here.
16427 ; If we were still using r2,r3 we would have to push them here.
16430 ; if( head != (unsigned char)(tail-1) )
16474 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16510 a,dpl \InsetSpace ~
16517 ; dpl holds lower byte of function argument
16529 dpl,_head \InsetSpace ~
16532 ; buf is 0x100 byte aligned so head can be used directly
16575 ; we could do an ANL _head,#0x0f here to use a
16576 smaller buffer (see above)
16588 ; restore used registers here
16595 \begin_inset LatexCommand \index{\_endasm}
16600 \begin_inset LatexCommand \index{\_\_endasm}
16611 \begin_layout Standard
16612 The inline assembler code can contain any valid code understood by the assembler
16613 , this includes any assembler directives and comment lines.
16614 The assembler does not like some characters like ':' or ''' in comments.
16615 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16616 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16621 \begin_inset LatexCommand \index{Assembler documentation}
16626 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16634 \begin_layout Standard
16635 The compiler does not do any validation of the code within the
16638 \begin_inset LatexCommand \index{\_asm}
16643 \begin_inset LatexCommand \index{\_\_asm}
16651 \begin_inset LatexCommand \index{\_endasm}
16656 \begin_inset LatexCommand \index{\_\_endasm}
16665 Specifically it will not know which registers are used and thus register
16667 \begin_inset LatexCommand \index{push/pop}
16671 has to be done manually.
16675 \begin_layout Standard
16676 It is recommended that each assembly instruction (including labels) be placed
16677 in a separate line (as the example shows).
16682 \begin_layout Standard
16694 \begin_inset LatexCommand \index{-\/-peep-asm}
16700 command line option is used, the inline assembler code will be passed through
16701 the peephole optimizer
16702 \begin_inset LatexCommand \index{Peephole optimizer}
16707 There are only a few (if any) cases where this option makes sense, it might
16708 cause some unexpected changes in the inline assembler code.
16709 Please go through the peephole optimizer rules defined in file
16713 before using this option.
16716 \begin_layout Subsection
16718 \begin_inset LatexCommand \label{sub:Naked-Functions}
16723 \begin_inset LatexCommand \index{Naked functions}
16730 \begin_layout Standard
16731 A special keyword may be associated with a function declaring it as
16734 \begin_inset LatexCommand \index{\_naked}
16739 \begin_inset LatexCommand \index{\_\_naked}
16750 function modifier attribute prevents the compiler from generating prologue
16751 \begin_inset LatexCommand \index{function prologue}
16756 \begin_inset LatexCommand \index{function epilogue}
16760 code for that function.
16761 This means that the user is entirely responsible for such things as saving
16762 any registers that may need to be preserved, selecting the proper register
16763 bank, generating the
16767 instruction at the end, etc.
16768 Practically, this means that the contents of the function must be written
16769 in inline assembler.
16770 This is particularly useful for interrupt functions, which can have a large
16771 (and often unnecessary) prologue/epilogue.
16772 For example, compare the code generated by these two functions:
16775 \begin_layout Verse
16779 \begin_inset LatexCommand \index{volatile}
16783 data unsigned char counter;
16787 void simpleInterrupt(void) __interrupt
16788 \begin_inset LatexCommand \index{interrupt}
16793 \begin_inset LatexCommand \index{\_\_interrupt}
16811 void nakedInterrupt(void) __interrupt (2) __naked
16820 \begin_inset LatexCommand \index{\_asm}
16825 \begin_inset LatexCommand \index{\_\_asm}
16842 _counter ; does not change flags, no need to save psw
16855 include ret or reti in _naked function.
16862 \begin_inset LatexCommand \index{\_endasm}
16867 \begin_inset LatexCommand \index{\_\_endasm}
16876 \begin_layout Standard
16877 For an 8051 target, the generated simpleInterrupt looks like:
16880 \begin_layout Verse
16887 example, recent versions of SDCC generate
16893 code for simpleInterrupt() and nakedInterrupt()!
17034 \begin_layout Standard
17035 whereas nakedInterrupt looks like:
17038 \begin_layout Verse
17051 _counter ; does not change flags, no need to save psw
17070 MUST explicitly include ret or reti in _naked function
17073 \begin_layout Standard
17074 The related directive #pragma exclude
17075 \begin_inset LatexCommand \index{\#pragma exclude}
17079 allows a more fine grained control over pushing & popping
17080 \begin_inset LatexCommand \index{push/pop}
17087 \begin_layout Standard
17088 While there is nothing preventing you from writing C code inside a
17092 function, there are many ways to shoot yourself in the foot doing this,
17093 and it is recommended that you stick to inline assembler.
17096 \begin_layout Subsection
17097 Use of Labels within Inline Assembler
17100 \begin_layout Standard
17101 SDCC allows the use of in-line assembler with a few restrictions regarding
17103 In older versions of the compiler all labels defined within inline assembler
17104 code had to be of the form
17108 where nnnnn is a number less than 100 (which implies a limit of utmost
17109 100 inline assembler labels
17120 \begin_layout Verse
17124 \begin_inset LatexCommand \index{\_asm}
17129 \begin_inset LatexCommand \index{\_\_asm}
17159 \begin_inset LatexCommand \index{\_endasm}
17164 \begin_inset LatexCommand \index{\_\_endasm}
17171 \begin_layout Standard
17172 Inline assembler code cannot reference any C-labels, however it can reference
17174 \begin_inset LatexCommand \index{Labels}
17178 defined by the inline assembler, e.g.:
17181 \begin_layout Verse
17204 ; some assembler code
17225 /* some more c code */
17227 clabel:\InsetSpace ~
17229 /* inline assembler cannot reference this
17242 $0003: ;label (can be referenced by inline assembler only)
17250 \begin_inset LatexCommand \index{\_endasm}
17255 \begin_inset LatexCommand \index{\_\_endasm}
17265 /* some more c code */
17270 \begin_layout Standard
17271 In other words inline assembly code can access labels defined in inline
17272 assembly within the scope of the function.
17273 The same goes the other way, i.e.
17274 labels defines in inline assembly can not be accessed by C statements.
17277 \begin_layout Section
17278 Interfacing with Assembler Code
17279 \begin_inset LatexCommand \index{Assembler routines}
17286 \begin_layout Subsection
17287 Global Registers used for Parameter Passing
17288 \begin_inset LatexCommand \index{Parameter passing}
17295 \begin_layout Standard
17296 The compiler always uses the global registers
17299 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17304 \begin_inset LatexCommand \index{DPTR}
17309 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17318 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17324 to pass the first parameter to a function, and also to pass the return
17326 \begin_inset LatexCommand \index{return value}
17330 of function; according to the following scheme: one byte return value in
17335 , two byte value in
17344 three byte values (generic pointers) in
17356 , and four byte values in
17374 \begin_inset LatexCommand \index{generic pointer}
17378 contain type of accessed memory in
17399 \begin_inset Note Note
17402 \begin_layout Standard
17403 This might not be the case of certain memory models (medium???)
17411 \begin_layout Standard
17412 The second parameter onwards is either allocated on the stack (for reentrant
17417 \begin_layout Standard
17426 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17430 \begin_layout Subsection
17434 \begin_layout Standard
17435 Unless the called function is declared as
17440 \begin_inset LatexCommand \index{naked}
17448 \begin_layout Standard
17458 \begin_inset LatexCommand \index{-\/-callee-saves}
17466 \begin_layout Standard
17475 -all-callee-saves command line option or the corresponding callee_saves
17476 pragma are used, the caller will save the registers (
17480 ) around the call, so the called function can destroy they content freely.
17483 \begin_layout Standard
17484 If the called function is not declared as
17488 , the caller will swap register banks around the call, if caller and callee
17489 use different register banks (having them defined by the
17497 \begin_layout Standard
17498 The called function can also use
17514 observing that they are used for parameter/return value passing.
17517 \begin_layout Subsection
17518 Assembler Routine (non-reentrant)
17521 \begin_layout Standard
17522 In the following example
17523 \begin_inset LatexCommand \index{reentrant}
17528 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17532 the function c_func calls an assembler routine asm_func, which takes two
17534 \begin_inset LatexCommand \index{function parameter}
17541 \begin_layout Verse
17544 extern int asm_func(unsigned char, unsigned char);
17548 int c_func (unsigned char
17549 i, unsigned char j)
17557 return asm_func(i,j);
17571 return c_func(10,9);
17576 \begin_layout Standard
17577 The corresponding assembler function is:
17580 \begin_layout Verse
17583 .globl _asm_func_PARM_2
17685 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17702 \begin_layout Standard
17703 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17704 the parameter number starting from 1, and counting from the left.
17705 The first parameter is passed in
17721 according to the description above.
17722 The variable name for the second parameter will be _<function_name>_PARM_2.
17727 ble the assembler routine with the following command:
17734 asx8051 -losg asmfunc.asm
17741 Then compile and link the assembler routine to the C source file with the
17749 sdcc cfunc.c asmfunc.rel
17752 \begin_layout Subsection
17753 Assembler Routine (reentrant)
17756 \begin_layout Standard
17758 \begin_inset LatexCommand \index{reentrant}
17763 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17767 the second parameter
17768 \begin_inset LatexCommand \index{function parameter}
17772 onwards will be passed on the stack, the parameters are pushed from right
17774 before the call the second leftmost parameter will be on the top of the
17775 stack (the leftmost parameter is passed in registers).
17776 Here is an example:
17779 \begin_layout Verse
17782 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17787 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
17796 return asm_func(i,j,k);
17810 return c_func(10,9,8);
17815 \begin_layout Standard
17816 The corresponding (unoptimized) assembler routine is:
17819 \begin_layout Verse
17839 _bp,sp\InsetSpace ~
17845 ;stack contains: _bp, return
17846 address, second parameter, third parameter
17870 a,#0xfd\InsetSpace ~
17876 pointer to the second parameter
17900 a,#0xfc\InsetSpace ~
17906 to the rightmost parameter
17947 result (= sum of all three parameters)
17962 ;return value goes into dptr
17996 \begin_layout Standard
17997 The compiling and linking procedure remains the same, however note the extra
17998 entry & exit linkage required for the assembler code, _bp is the stack
17999 frame pointer and is used to compute the offset into the stack for parameters
18000 and local variables.
18001 \begin_inset VSpace bigskip
18007 \begin_layout Section
18009 \begin_inset LatexCommand \index{int (16 bit)}
18014 \begin_inset LatexCommand \index{long (32 bit)}
18021 \begin_layout Standard
18022 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18023 multiplication and modulus operations are implemented by support routines.
18024 These support routines are all developed in ANSI-C to facilitate porting
18025 to other MCUs, although some model specific assembler optimizations are
18027 The following files contain the described routines, all of them can be
18028 found in <installdir>/share/sdcc/lib.
18033 \begin_layout Standard
18035 \begin_inset Tabular
18036 <lyxtabular version="3" rows="11" columns="2">
18038 <column alignment="left" valignment="top" leftline="true" width="0">
18039 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18040 <row topline="true" bottomline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18044 \begin_layout Standard
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18055 \begin_layout Standard
18064 <row topline="true">
18065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18068 \begin_layout Standard
18074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18077 \begin_layout Standard
18078 16 bit multiplication
18084 <row topline="true">
18085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18088 \begin_layout Standard
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18097 \begin_layout Standard
18098 signed 16 bit division (calls _divuint)
18104 <row topline="true">
18105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18108 \begin_layout Standard
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18117 \begin_layout Standard
18118 unsigned 16 bit division
18124 <row topline="true">
18125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18128 \begin_layout Standard
18134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18137 \begin_layout Standard
18138 signed 16 bit modulus (calls _moduint)
18144 <row topline="true">
18145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18148 \begin_layout Standard
18154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18157 \begin_layout Standard
18158 unsigned 16 bit modulus
18164 <row topline="true">
18165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18168 \begin_layout Standard
18174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18177 \begin_layout Standard
18178 32 bit multiplication
18184 <row topline="true">
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18188 \begin_layout Standard
18194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18197 \begin_layout Standard
18198 signed 32 division (calls _divulong)
18204 <row topline="true">
18205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18208 \begin_layout Standard
18214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18217 \begin_layout Standard
18218 unsigned 32 division
18224 <row topline="true">
18225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18228 \begin_layout Standard
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18237 \begin_layout Standard
18238 signed 32 bit modulus (calls _modulong)
18244 <row topline="true" bottomline="true">
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18248 \begin_layout Standard
18254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18257 \begin_layout Standard
18258 unsigned 32 bit modulus
18273 \begin_layout Standard
18274 Since they are compiled as
18279 \begin_inset LatexCommand \index{reentrant}
18284 \begin_inset LatexCommand \index{interrupt}
18288 service routines should not do any of the above operations.
18289 If this is unavoidable then the above routines will need to be compiled
18296 \begin_layout Standard
18306 \begin_inset LatexCommand \index{-\/-stack-auto}
18312 option, after which the source program will have to be compiled with
18318 \begin_layout Standard
18328 \begin_inset LatexCommand \index{-\/-int-long-reent}
18335 Notice that you don't have to call these routines directly.
18336 The compiler will use them automatically every time an integer operation
18340 \begin_layout Section
18341 Floating Point Support
18342 \begin_inset LatexCommand \index{Floating point support}
18349 \begin_layout Standard
18350 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18351 The floating point support routines are derived from gcc's floatlib.c and
18352 consist of the following routines:
18357 \begin_layout Standard
18361 \begin_inset Tabular
18362 <lyxtabular version="3" rows="17" columns="2">
18364 <column alignment="left" valignment="top" leftline="true" width="0">
18365 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18366 <row topline="true" bottomline="true">
18367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18370 \begin_layout Standard
18385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18388 \begin_layout Standard
18395 <row topline="true">
18396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18399 \begin_layout Standard
18414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18417 \begin_layout Standard
18427 add floating point numbers
18433 <row topline="true">
18434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18437 \begin_layout Standard
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18455 \begin_layout Standard
18465 subtract floating point numbers
18471 <row topline="true">
18472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18475 \begin_layout Standard
18490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18493 \begin_layout Standard
18503 divide floating point numbers
18509 <row topline="true">
18510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18513 \begin_layout Standard
18528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18531 \begin_layout Standard
18541 multiply floating point numbers
18547 <row topline="true">
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18551 \begin_layout Standard
18566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18569 \begin_layout Standard
18579 convert floating point to unsigned char
18585 <row topline="true">
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18589 \begin_layout Standard
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18607 \begin_layout Standard
18617 convert floating point to signed char
18623 <row topline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 \begin_layout Standard
18642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18645 \begin_layout Standard
18655 convert floating point to unsigned int
18661 <row topline="true">
18662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18665 \begin_layout Standard
18680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18683 \begin_layout Standard
18693 convert floating point to signed int
18699 <row topline="true">
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18703 \begin_layout Standard
18726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18729 \begin_layout Standard
18739 convert floating point to unsigned long
18745 <row topline="true">
18746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18749 \begin_layout Standard
18764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18767 \begin_layout Standard
18777 convert floating point to signed long
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18787 \begin_layout Standard
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18805 \begin_layout Standard
18815 convert unsigned char to floating point
18821 <row topline="true">
18822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18825 \begin_layout Standard
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18843 \begin_layout Standard
18853 convert char to floating point number
18859 <row topline="true">
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18863 \begin_layout Standard
18878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18881 \begin_layout Standard
18891 convert unsigned int to floating point
18897 <row topline="true">
18898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18901 \begin_layout Standard
18916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18919 \begin_layout Standard
18929 convert int to floating point numbers
18935 <row topline="true">
18936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18939 \begin_layout Standard
18954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18957 \begin_layout Standard
18967 convert unsigned long to floating point number
18973 <row topline="true" bottomline="true">
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18977 \begin_layout Standard
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18995 \begin_layout Standard
19005 convert long to floating point number
19020 \begin_layout Standard
19021 These support routines are developed in ANSI-C so there is room for space
19022 and speed improvement
19026 \begin_layout Standard
19027 These floating point routines (
19031 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19038 Note if all these routines are used simultaneously the data space might
19040 For serious floating point usage the large model might be needed.
19041 Also notice that you don't have to call this routines directly.
19042 The compiler will use them automatically every time a floating point operation
19044 \begin_inset VSpace bigskip
19050 \begin_layout Section
19052 \begin_inset LatexCommand \index{Libraries}
19059 \begin_layout Standard
19062 <pending: this is messy and incomplete - a little more information is in
19063 sdcc/doc/libdoc.txt
19068 \begin_layout Subsection
19069 Compiler support routines (_gptrget, _mulint etc.)
19072 \begin_layout Subsection
19073 Stdclib functions (puts, printf, strcat etc.)
19076 \begin_layout Subsubsection
19080 \begin_layout Paragraph
19081 getchar(), putchar()
19084 \begin_layout Standard
19085 \begin_inset LatexCommand \index{<stdio.h>}
19089 As usual on embedded systems you have to provide your own
19092 \begin_inset LatexCommand \index{getchar()}
19101 \begin_inset LatexCommand \index{putchar()}
19108 SDCC does not know whether the system connects to a serial line with or
19109 without handshake, LCD, keyboard or other device.
19123 You'll find examples for serial routines f.e.
19124 in sdcc/device/lib.
19125 For the mcs51 this minimalistic polling
19129 routine might be a start:
19132 \begin_layout Verse
19135 void putchar (char c) {
19141 while (!TI)\InsetSpace ~
19144 /* assumes UART is initialized */
19172 \begin_layout Paragraph
19176 \begin_layout Standard
19180 \begin_inset LatexCommand \index{printf()}
19190 does not support float (except on ds390).
19191 To enable this recompile it with the option
19197 \begin_layout Standard
19207 \begin_inset LatexCommand \index{USE\_FLOATS}
19213 on the command line.
19220 \begin_layout Standard
19230 \begin_inset LatexCommand \index{-\/-model-large}
19236 for the mcs51 port, since this uses a lot of memory.
19239 \begin_layout Standard
19240 If you're short on code memory you might want to use
19243 \begin_inset LatexCommand \index{printf\_small()}
19258 For the mcs51 there additionally are assembly versions
19261 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19267 (subset of printf using less than 270 bytes) and
19270 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19279 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19285 (floating-point aware version of printf_fast) which should fit the requirements
19286 of many embedded systems (printf_fast() can be customized by unsetting
19291 support long variables and field widths).
19292 Be sure to use only one of these printf options within a project.
19297 \begin_layout Standard
19298 Feature matrix of different
19305 \begin_layout Standard
19306 \begin_inset Tabular
19307 <lyxtabular version="3" rows="14" columns="7">
19308 <features islongtable="true">
19309 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19310 <column alignment="center" valignment="top" leftline="true" width="0">
19311 <column alignment="center" valignment="top" leftline="true" width="12col%">
19312 <column alignment="center" valignment="top" leftline="true" width="10col%">
19313 <column alignment="center" valignment="top" leftline="true" width="0">
19314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19315 <column alignment="center" valignment="top" rightline="true" width="0">
19316 <row topline="true" bottomline="true" endhead="true">
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19320 \begin_layout Standard
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19332 \begin_layout Standard
19334 \begin_inset LatexCommand \index{printf}
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19346 \begin_layout Standard
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19357 \begin_layout Standard
19363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19366 \begin_layout Standard
19372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19375 \begin_layout Standard
19381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19384 \begin_layout Standard
19391 <row topline="true" endhead="true">
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19395 \begin_layout Standard
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19404 \begin_layout Standard
19412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19415 \begin_layout Standard
19423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19426 \begin_layout Standard
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19437 \begin_layout Standard
19445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19448 \begin_layout Standard
19456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19459 \begin_layout Standard
19468 <row topline="true" endhead="true">
19469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19472 \begin_layout Standard
19473 \begin_inset Quotes sld
19477 \begin_inset Quotes srd
19483 \begin_layout Standard
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19492 \begin_layout Standard
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 \begin_layout Standard
19507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19510 \begin_layout Standard
19516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_layout Standard
19525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19528 \begin_layout Standard
19534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_layout Standard
19544 <row topline="true" endhead="true">
19545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19548 \begin_layout Standard
19552 \begin_layout Standard
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19561 \begin_layout Standard
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19570 \begin_layout Standard
19576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19579 \begin_layout Standard
19580 0.45k / 0.47k (+ _ltoa)
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19588 \begin_layout Standard
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19597 \begin_layout Standard
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19606 \begin_layout Standard
19613 <row topline="true">
19614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19617 \begin_layout Standard
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19626 \begin_layout Standard
19636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19639 \begin_layout Standard
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19689 \begin_layout Standard
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19731 \begin_layout Standard
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19740 \begin_layout Standard
19746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19749 \begin_layout Standard
19756 <row topline="true">
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19760 \begin_layout Standard
19761 long (32 bit) support
19766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19769 \begin_layout Standard
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19778 \begin_layout Standard
19784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19787 \begin_layout Standard
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19796 \begin_layout Standard
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19805 \begin_layout Standard
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_layout Standard
19830 <row topline="true">
19831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 \begin_layout Standard
19835 byte arguments on stack
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19843 \begin_layout Standard
19849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 \begin_layout Standard
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19861 \begin_layout Standard
19867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19870 \begin_layout Standard
19876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19879 \begin_layout Standard
19885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19888 \begin_layout Standard
19895 <row topline="true">
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19899 \begin_layout Standard
19901 \begin_inset LatexCommand \index{Floating point support}
19910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19913 \begin_layout Standard
19919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19922 \begin_layout Standard
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_layout Standard
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_layout Standard
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19949 \begin_layout Standard
19954 \begin_layout Standard
19955 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19968 \begin_layout Standard
19975 <row topline="true">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_layout Standard
19980 float formats %e %g
19985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19988 \begin_layout Standard
19994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19997 \begin_layout Standard
20003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20006 \begin_layout Standard
20012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_layout Standard
20021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20024 \begin_layout Standard
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20033 \begin_layout Standard
20040 <row topline="true" bottomline="true">
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20044 \begin_layout Standard
20050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20053 \begin_layout Standard
20059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20062 \begin_layout Standard
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20071 \begin_layout Standard
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20080 \begin_layout Standard
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20098 \begin_layout Standard
20105 <row bottomline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_layout Standard
20114 \begin_layout Standard
20115 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20119 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20127 \begin_layout Standard
20133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20136 \begin_layout Standard
20142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20145 \begin_layout Standard
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20154 \begin_layout Standard
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20163 \begin_layout Standard
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20172 \begin_layout Standard
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20181 \begin_layout Standard
20188 <row bottomline="true">
20189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20192 \begin_layout Standard
20197 \begin_layout Standard
20198 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20207 \begin_layout Standard
20213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20216 \begin_layout Standard
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20225 \begin_layout Standard
20231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20234 \begin_layout Standard
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20243 \begin_layout Standard
20249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20252 \begin_layout Standard
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20261 \begin_layout Standard
20266 \begin_layout Standard
20267 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20278 <row bottomline="true">
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20282 \begin_layout Standard
20287 \begin_layout Standard
20288 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20297 \begin_layout Standard
20303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20306 \begin_layout Standard
20312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20315 \begin_layout Standard
20321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20324 \begin_layout Standard
20330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20333 \begin_layout Standard
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20342 \begin_layout Standard
20348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20351 \begin_layout Standard
20358 <row bottomline="true">
20359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20362 \begin_layout Standard
20367 \begin_layout Standard
20368 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20377 \begin_layout Standard
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20386 \begin_layout Standard
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_layout Standard
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20404 \begin_layout Standard
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20413 \begin_layout Standard
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20422 \begin_layout Standard
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20431 \begin_layout Standard
20445 \begin_layout Subsubsection
20447 \begin_inset LatexCommand \index{malloc.h}
20454 \begin_layout Standard
20455 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20456 using dynamic memory allocation
20457 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20462 \begin_inset LatexCommand \index{heap (malloc)}
20466 space of 1024 bytes is provided for malloc to allocate memory from.
20467 If you need a different heap size you need to recompile _heap.c with the
20468 required size defined in HEAP_SIZE.
20469 It is recommended to make a copy of this file into your project directory
20470 and compile it there with:
20473 \begin_layout Verse
20476 sdcc -c _heap.c -D HEAD_SIZE=2048
20479 \begin_layout Standard
20480 And then link it with:
20483 \begin_layout Verse
20486 sdcc main.rel _heap.rel
20489 \begin_layout Subsection
20490 Math functions (sinf, powf, sqrtf etc.)
20493 \begin_layout Subsubsection
20497 \begin_layout Standard
20498 See definitions in file <math.h>.
20501 \begin_layout Subsection
20505 \begin_layout Standard
20507 \begin_inset LatexCommand \index{Libraries}
20511 included in SDCC should have a license at least as liberal as the GNU Lesser
20512 General Public License
20513 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20524 \begin_layout Standard
20525 \begin_inset Note Note
20528 \begin_layout Standard
20529 license statements for the libraries are missing.
20530 sdcc/device/lib/ser_ir.c
20533 \begin_layout Standard
20535 come with a GPL (as opposed to LGPL) License - this will not be liberal
20536 enough for many embedded programmers.
20544 \begin_layout Standard
20545 If you have ported some library or want to share experience about some code
20547 falls into any of these categories Busses (I
20548 \begin_inset Formula $^{\textrm{2}}$
20551 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20552 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20553 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20554 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20559 would certainly like to hear about it.
20562 \begin_layout Standard
20563 Programmers coding for embedded systems are not especially famous for being
20564 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20565 e these references are very valuable.
20566 Let's help to create a climate where information is shared.
20567 \begin_inset VSpace bigskip
20573 \begin_layout Section
20577 \begin_layout Subsection
20578 MCS51 Memory Models
20579 \begin_inset LatexCommand \index{Memory model}
20584 \begin_inset LatexCommand \index{MCS51 memory model}
20591 \begin_layout Subsubsection
20592 Small, Medium and Large
20595 \begin_layout Standard
20596 SDCC allows three memory models for MCS51 code,
20605 Modules compiled with different memory models should
20609 be combined together or the results would be unpredictable.
20610 The library routines supplied with the compiler are compiled as small,
20612 The compiled library modules are contained in separate directories as small,
20613 medium and large so that you can link to the appropriate set.
20616 \begin_layout Standard
20617 When the medium or large model is used all variables declared without a
20618 storage class will be allocated into the external ram, this includes all
20619 parameters and local variables (for non-reentrant
20620 \begin_inset LatexCommand \index{reentrant}
20625 When the small model is used variables without storage class are allocated
20626 in the internal ram.
20629 \begin_layout Standard
20630 Judicious usage of the processor specific storage classes
20631 \begin_inset LatexCommand \index{Storage class}
20635 and the 'reentrant' function type will yield much more efficient code,
20636 than using the large model.
20637 Several optimizations are disabled when the program is compiled using the
20638 large model, it is therefore recommended that the small model be used unless
20639 absolutely required.
20642 \begin_layout Subsubsection
20644 \begin_inset LatexCommand \label{sub:External-Stack}
20649 \begin_inset LatexCommand \index{stack}
20654 \begin_inset LatexCommand \index{External stack (mcs51)}
20661 \begin_layout Standard
20662 The external stack (-
20666 \begin_layout Standard
20676 \begin_inset LatexCommand \index{-\/-xstack}
20680 ) is located in pdata
20681 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20685 memory (usually at the start of the external ram segment) and uses all
20686 unused space in pdata (max.
20692 \begin_layout Standard
20701 -xstack option is used to compile the program, the parameters and local
20703 \begin_inset LatexCommand \index{local variables}
20707 of all reentrant functions are allocated in this area.
20708 This option is provided for programs with large stack space requirements.
20709 When used with the -
20713 \begin_layout Standard
20723 \begin_inset LatexCommand \index{-\/-stack-auto}
20727 option, all parameters and local variables are allocated on the external
20728 stack (note: support libraries will need to be recompiled with the same
20730 There is a predefined target in the library makefile).
20733 \begin_layout Standard
20734 The compiler outputs the higher order address byte of the external ram segment
20736 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20741 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20745 ), therefore when using the External Stack option, this port
20749 be used by the application program.
20752 \begin_layout Subsection
20754 \begin_inset LatexCommand \index{Memory model}
20759 \begin_inset LatexCommand \index{DS390 memory model}
20766 \begin_layout Standard
20767 The only model supported is Flat 24
20768 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20773 This generates code for the 24 bit contiguous addressing mode of the Dallas
20775 In this mode, up to four meg of external RAM or code space can be directly
20777 See the data sheets at www.dalsemi.com for further information on this part.
20782 that the compiler does not generate any code to place the processor into
20783 24 bitmode (although
20787 in the ds390 libraries will do that for you).
20793 \begin_inset LatexCommand \index{Tinibios (DS390)}
20797 , the boot loader or similar code must ensure that the processor is in 24
20798 bit contiguous addressing mode before calling the SDCC startup code.
20809 \begin_layout Standard
20820 option, variables will by default be placed into the XDATA segment.
20825 Segments may be placed anywhere in the 4 meg address space using the usual
20830 \begin_layout Standard
20840 Note that if any segments are located above 64K, the -r flag must be passed
20841 to the linker to generate the proper segment relocations, and the Intel
20842 HEX output format must be used.
20843 The -r flag can be passed to the linker by using the option
20847 on the SDCC command line.
20848 However, currently the linker can not handle code segments > 64k.
20851 \begin_layout Section
20853 \begin_inset LatexCommand \label{sec:Pragmas}
20858 \begin_inset LatexCommand \index{Pragmas}
20865 \begin_layout Standard
20866 Pragmas are used to turn on and/or off certain compiler options.
20867 Some of them are closely related to corresponding command-line options
20869 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20875 Pragmas should be placed before and/or after a function, placing pragmas
20876 inside a function body could have unpredictable results.
20881 following #pragma directives:
20884 \begin_layout Itemize
20890 \begin_inset LatexCommand \index{\#pragma save}
20894 - this will save most current options to the save/restore stack.
20895 See #pragma\InsetSpace ~
20899 \begin_layout Itemize
20905 \begin_inset LatexCommand \index{\#pragma restore}
20909 - will restore saved options from the last save.
20910 saves & restores can be nested.
20911 SDCC uses a save/restore stack: save pushes current options to the stack,
20912 restore pulls current options from the stack.
20913 See #pragma\InsetSpace ~
20919 \begin_layout Itemize
20925 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20930 \begin_inset LatexCommand \index{function prologue}
20934 function1[,function2[,function3...]]
20935 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20939 - The compiler by default uses a caller saves convention for register saving
20940 across function calls, however this can cause unnecessary register pushing
20942 \begin_inset LatexCommand \index{push/pop}
20946 when calling small functions from larger functions.
20947 This option can be used to switch off the register saving convention for
20948 the function names specified.
20949 The compiler will not save registers when calling these functions, extra
20950 code need to be manually inserted at the entry and exit for these functions
20951 to save and restore the registers used by these functions, this can SUBSTANTIAL
20952 LY reduce code and improve run time performance of the generated code.
20953 In the future the compiler (with inter procedural analysis) may be able
20954 to determine the appropriate scheme to use for each function call.
20959 \begin_layout Standard
20968 -callee-saves command line option is used (see page
20969 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20973 ), the function names specified in #pragma\InsetSpace ~
20975 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20979 is appended to the list of functions specified in the command line.
20982 \begin_layout Itemize
20988 \begin_inset LatexCommand \index{\#pragma exclude}
20992 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20993 of pairs of push/pop
20994 \begin_inset LatexCommand \index{push/pop}
21003 \begin_inset LatexCommand \index{interrupt}
21016 The directive should be placed immediately before the ISR function definition
21017 and it affects ALL ISR functions following it.
21018 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21019 exclude\InsetSpace ~
21021 \begin_inset LatexCommand \index{\#pragma exclude}
21026 See also the related keyword _naked
21027 \begin_inset LatexCommand \index{\_naked}
21032 \begin_inset LatexCommand \index{\_\_naked}
21039 \begin_layout Itemize
21045 \begin_inset LatexCommand \index{pedantic}
21050 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21055 \begin_inset LatexCommand \label{ite:less_pedantic}
21059 - the compiler will not warn you anymore for obvious mistakes, you'r on
21061 See also the command line option -
21065 \begin_layout Standard
21075 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21082 More specifically, the following warnings will be disabled:
21084 comparison is always [true/false] due to limited range of data type
21088 overflow in implicit constant conversion
21090 (158); [the (in)famous]
21092 conditional flow changed by optimizer: so said EVELYN the modified DOG
21096 function '[function name]' must return value
21101 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21102 level) are disabled, too, namely:
21105 \begin_inset Note Note
21108 \begin_layout Standard
21109 dunno what comes here - this warning appears to be unused altogether
21118 [left/right] shifting more than size of object changed to zero
21126 integer overflow in expression
21130 unmatched #pragma save and #pragma restore
21134 comparison of 'signed char' with 'unsigned char' requires promotion to int
21138 ISO C90 does not support flexible array members
21142 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21146 \begin_inset Note Note
21149 \begin_layout Standard
21150 appears to be always blank - what was supposed to be here?
21159 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21160 complexity [number]
21165 \begin_layout Itemize
21171 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21175 - the compiler will not warn you anymore about warning number <nnnn>.
21178 \begin_layout Itemize
21184 \begin_inset LatexCommand \index{\#pragma nogcse}
21188 - will stop global common subexpression elimination.
21191 \begin_layout Itemize
21197 \begin_inset LatexCommand \index{\#pragma noinduction}
21201 - will stop loop induction optimizations.
21204 \begin_layout Itemize
21210 \begin_inset LatexCommand \index{\#pragma noinvariant}
21214 - will not do loop invariant optimizations.
21215 For more details see Loop Invariants in section
21216 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21223 \begin_layout Itemize
21229 \begin_inset LatexCommand \index{\#pragma noiv}
21233 - Do not generate interrupt
21234 \begin_inset LatexCommand \index{interrupt}
21239 \begin_inset LatexCommand \index{interrupt vector table}
21243 entries for all ISR functions defined after the pragma.
21244 This is useful in cases where the interrupt vector table must be defined
21245 manually, or when there is a secondary, manually defined interrupt vector
21247 for the autovector feature of the Cypress EZ-USB FX2).
21248 More elegantly this can be achieved by obmitting the optional interrupt
21249 number after the interrupt keyword, see section
21250 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21258 \begin_layout Itemize
21264 \begin_inset LatexCommand \index{\#pragma nojtbound}
21268 - will not generate code for boundary value checking, when switch statements
21269 are turned into jump-tables (dangerous).
21270 For more details see section
21271 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21278 \begin_layout Itemize
21284 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21288 - Will not do loop reversal optimization
21291 \begin_layout Itemize
21297 \begin_inset LatexCommand \index{\#pragma nooverlay}
21301 - the compiler will not overlay the parameters and local variables of a
21305 \begin_layout Itemize
21311 \begin_inset LatexCommand \index{\#pragma stackauto}
21319 \begin_layout Standard
21329 \begin_inset LatexCommand \index{-\/-stack-auto}
21334 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21338 Parameters and Local Variables.
21341 \begin_layout Itemize
21347 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21351 - The compiler will optimize code generation towards fast code, possibly
21352 at the expense of code size.
21353 Currently this has little effect.
21356 \begin_layout Itemize
21362 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21366 - The compiler will optimize code generation towards compact code, possibly
21367 at the expense of code speed.
21368 Currently this has little effect.
21371 \begin_layout Itemize
21377 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21381 - The compiler will attempt to generate code that is both compact and fast,
21382 as long as meeting one goal is not a detriment to the other (this is the
21387 \begin_layout Itemize
21393 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21397 - Generally follow the C89 standard, but allow SDCC features that conflict
21398 with the standard (default).
21401 \begin_layout Itemize
21407 \begin_inset LatexCommand \index{\#pragma std\_c89}
21411 - Follow the C89 standard and disable SDCC features that conflict with the
21415 \begin_layout Itemize
21421 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21425 - Generally follow the C99 standard, but allow SDCC features that conflict
21426 with the standard (incomplete support).
21429 \begin_layout Itemize
21435 \begin_inset LatexCommand \index{\#pragma std\_c99}
21439 - Follow the C99 standard and disable SDCC features that conflict with the
21440 standard (incomplete support).
21443 \begin_layout Itemize
21449 \begin_inset LatexCommand \index{\#pragma codeseg}
21453 - Use this name (max.
21454 8 characters) for the code segment.
21459 \begin_layout Standard
21471 \begin_layout Itemize
21477 \begin_inset LatexCommand \index{\#pragma constseg}
21481 - Use this name (max.
21482 8 characters) for the const segment.
21487 \begin_layout Standard
21499 \begin_layout Standard
21500 The preprocessor SDCPP
21501 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21505 supports the following #pragma directives:
21508 \begin_layout Itemize
21511 pedantic_parse_number
21514 \begin_inset LatexCommand \index{pedantic}
21519 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21524 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21528 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21529 properly and the macro LO_B(3) gets expanded.
21535 \begin_layout Standard
21544 -pedantic-parse-number command line option
21545 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21552 Below is an example on how to use this pragma.
21555 Note: this functionality is not in conformance with standard!
21558 \begin_layout Verse
21561 #pragma pedantic_parse_number +
21562 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21570 #define LO_B(x) ((x) & 0xff)
21574 unsigned char foo(void)
21581 unsigned char c=0xfe-LO_B(3)
21596 \begin_layout Itemize
21602 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21606 (+ | -) - switch _asm _endasm block preprocessing on / off.
21608 You use this prama to define multilines of assembly code.
21609 This will prevent the preprocessor from changing the formating required
21611 Below is an example on how to use this pragma.
21614 \begin_layout Verse
21617 #pragma preproc_asm -
21618 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21624 #define MYDELAY _asm
21629 nop ;my assembly comment...
21643 #pragma preproc_asm
21674 \begin_layout Itemize
21680 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21684 (+ | -) - Allow "naked" hash in macro definition, for example:
21688 #define DIR_LO(x) #(x & 0xff)
21693 Below is an example on how to use this pragma.
21696 \begin_layout Verse
21699 #pragma preproc_asm +
21701 #pragma sdcc_hash +
21702 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21717 mov R6_B3, #(x & 0xff)
21724 mov R7_B3, #((x >> 8) & 0xff)
21748 \begin_layout Standard
21749 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21750 ons which might cause the compiler to generate extra stack and/or data space
21751 to store compiler generated temporary variables.
21752 This usually happens in large functions.
21753 Pragma directives should be used as shown in the following example, they
21754 are used to control options and optimizations for a given function.
21758 \begin_layout Verse
21762 \begin_inset LatexCommand \index{\#pragma save}
21773 /* save the current settings */
21776 \begin_inset LatexCommand \index{\#pragma nogcse}
21785 /* turnoff global subexpression elimination */
21787 #pragma noinduction
21788 \begin_inset LatexCommand \index{\#pragma noinduction}
21792 /* turn off induction optimizations */
21815 \begin_inset LatexCommand \index{\#pragma restore}
21819 /* turn the optimizations back on */
21822 \begin_layout Standard
21823 The compiler will generate a warning message when extra space is allocated.
21824 It is strongly recommended that the save and restore pragma's be used when
21825 changing options for a function.
21834 \begin_layout Section
21835 Defines Created by the Compiler
21838 \begin_layout Standard
21839 The compiler creates the following #defines
21840 \begin_inset LatexCommand \index{\#defines}
21845 \begin_inset LatexCommand \index{Defines created by the compiler}
21854 \begin_layout Standard
21855 \begin_inset Tabular
21856 <lyxtabular version="3" rows="11" columns="2">
21858 <column alignment="left" valignment="top" leftline="true" width="3in">
21859 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21860 <row topline="true" bottomline="true">
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21864 \begin_layout Standard
21872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21875 \begin_layout Standard
21884 <row topline="true">
21885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21888 \begin_layout Standard
21890 \begin_inset LatexCommand \index{SDCC}
21899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21902 \begin_layout Standard
21904 Since version 2.5.6 the version number as an int (ex.
21911 <row topline="true">
21912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21915 \begin_layout Standard
21917 \begin_inset LatexCommand \index{SDCC\_mcs51}
21922 \begin_inset LatexCommand \index{SDCC\_ds390}
21927 \begin_inset LatexCommand \index{SDCC\_z80}
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21939 \begin_layout Standard
21940 depending on the model used (e.g.: -mds390)
21946 <row topline="true">
21947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21950 \begin_layout Standard
21952 \begin_inset LatexCommand \index{\_\_mcs51}
21957 \begin_inset LatexCommand \index{\_\_ds390}
21962 \begin_inset LatexCommand \index{\_\_hc08}
21967 \begin_inset LatexCommand \index{\_\_z80}
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21979 \begin_layout Standard
21980 depending on the model used (e.g.
21987 <row topline="true">
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21991 \begin_layout Standard
21993 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22005 \begin_layout Standard
22012 \begin_layout Standard
22029 <row topline="true">
22030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22033 \begin_layout Standard
22035 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22047 \begin_layout Standard
22054 \begin_layout Standard
22071 <row topline="true">
22072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22075 \begin_layout Standard
22077 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22089 \begin_layout Standard
22096 \begin_layout Standard
22113 <row topline="true">
22114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22117 \begin_layout Standard
22119 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22131 \begin_layout Standard
22138 \begin_layout Standard
22155 <row topline="true">
22156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22159 \begin_layout Standard
22161 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22173 \begin_layout Standard
22180 \begin_layout Standard
22197 <row topline="true">
22198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22201 \begin_layout Standard
22203 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22215 \begin_layout Standard
22226 <row topline="true" bottomline="true">
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22230 \begin_layout Standard
22232 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22244 \begin_layout Standard
22262 \begin_layout Chapter
22263 Notes on supported Processors
22266 \begin_layout Section
22268 \begin_inset LatexCommand \label{sub:MCS51-variants}
22273 \begin_inset LatexCommand \index{MCS51 variants}
22280 \begin_layout Standard
22281 MCS51 processors are available from many vendors and come in many different
22283 While they might differ considerably in respect to Special Function Registers
22284 the core MCS51 is usually not modified or is kept compatible.
22288 \begin_layout Subsection
22289 pdata access by SFR
22292 \begin_layout Standard
22293 With the upcome of devices with internal xdata and flash memory devices
22295 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22299 as dedicated I/O port is becoming more popular.
22300 Switching the high byte for pdata
22301 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22305 access which was formerly done by port P2 is then achieved by a Special
22307 \begin_inset LatexCommand \index{sfr}
22312 In well-established MCS51 tradition the address of this
22316 is where the chip designers decided to put it.
22317 Needless to say that they didn't agree on a common name either.
22318 So that the startup code can correctly initialize xdata variables, you
22319 should define an sfr with the name _XPAGE
22322 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22328 at the appropriate location if the default, port P2, is not used for this.
22332 \begin_layout Verse
22335 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22339 \begin_layout Verse
22342 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22347 \begin_layout Verse
22350 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22354 \begin_layout Verse
22357 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22361 \begin_layout Verse
22364 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22368 \begin_layout Standard
22369 For more exotic implementations further customizations may be needed.
22371 \begin_inset LatexCommand \ref{sub:Startup-Code}
22375 for other possibilities.
22378 \begin_layout Subsection
22379 Other Features available by SFR
22382 \begin_layout Standard
22383 Some MCS51 variants offer features like Double DPTR
22384 \begin_inset LatexCommand \index{DPTR}
22388 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22389 These are currently not used for the MCS51 port.
22390 If you absolutely need them you can fall back to inline assembly or submit
22392 \begin_inset VSpace bigskip
22398 \begin_layout Section
22402 \begin_layout Standard
22404 \begin_inset LatexCommand \index{DS80C400}
22409 \begin_inset LatexCommand \index{DS400}
22413 microcontroller has a rich set of peripherals.
22414 In its built-in ROM library it includes functions to access some of the
22415 features, among them is a TCP stack with IP4 and IP6 support.
22416 Library headers (currently in beta status) and other files are provided
22420 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22426 \begin_inset VSpace bigskip
22432 \begin_layout Section
22433 The Z80 and gbz80 port
22436 \begin_layout Standard
22437 SDCC can target both the Zilog Z80
22438 \begin_inset LatexCommand \index{Z80}
22442 and the Nintendo Gameboy's Z80-like gbz80
22443 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22448 The Z80 port is passed through the same
22451 \begin_inset LatexCommand \index{Regression test}
22458 \begin_inset LatexCommand \ref{sec:Quality-control}
22462 ) as the MCS51 and DS390 ports, so floating point support, support for long
22463 variables and bitfield support is fine.
22464 See mailing lists and forums about interrupt routines.
22467 \begin_layout Standard
22468 As always, the code is the authoritative reference - see z80/ralloc.c and
22471 \begin_inset LatexCommand \index{Z80!stack}
22475 frame is similar to that generated by the IAR Z80 compiler.
22476 IX is used as the base pointer, HL and IY are used as a temporary registers,
22477 and BC and DE are available for holding variables.
22479 \begin_inset LatexCommand \index{Z80!return value}
22483 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22485 The gbz80 port use the same set of registers for the return values, but
22486 in a different order of significance: E (one byte), DE (two bytes), or
22488 \begin_inset VSpace bigskip
22494 \begin_layout Section
22498 \begin_layout Standard
22499 The port to the Freescale/Motorola HC08
22500 \begin_inset LatexCommand \index{HC08}
22504 family has been added in October 2003, and is still undergoing some basic
22506 The code generator is complete, but the register allocation is still quite
22508 Some of the SDCC's standard C library functions have embedded non-HC08
22509 inline assembly and so are not yet usable.
22512 \begin_layout Standard
22513 The HC08 port passes the regression test suite (see section
22514 \begin_inset LatexCommand \ref{sec:Quality-control}
22519 \begin_inset VSpace bigskip
22527 \begin_layout Section
22531 \begin_layout Standard
22533 \begin_inset LatexCommand \index{PIC14}
22537 port still requires a major effort from the development community.
22538 However it can work for simple code.
22539 It passes its (smaller set of) regression tests
22540 \begin_inset LatexCommand \index{Regression test (PIC14)}
22546 sdcc/src/regression
22551 \begin_layout Subsection
22552 C code and 14bit PIC code page
22553 \begin_inset LatexCommand \index{code page (pic14)}
22558 \begin_inset LatexCommand \index{RAM bank (pic14)}
22565 \begin_layout Standard
22566 The linker organizes allocation for the code page and RAM banks.
22567 It does not have intimate knowledge of the code flow.
22568 It will put all the code section of a single asm file into a single code
22570 In order to make use of multiple code pages, separate asm files must be
22572 The compiler treats all functions of a single C file as being in the same
22573 code page unless it is non static.
22577 To get the best follow these guide lines:
22580 \begin_layout Enumerate
22581 Make local functions static, as non static functions require code page selection
22585 \begin_layout Enumerate
22586 For devices that have multiple code pages it is more efficient to use the
22587 same number of files as pages, i.e.
22588 for the 16F877 use 4 separate files and i.e.
22589 for the 16F874 use 2 separate files.
22590 This way the linker can put the code for each file into different code
22591 pages and there's less page selection overhead.
22594 \begin_layout Enumerate
22595 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22596 instruction set), use 'unsigned char' whereever possible instead of 'int'.
22599 \begin_layout Subsection
22600 Creating a device include file
22603 \begin_layout Standard
22604 For generating a device include file
22605 \begin_inset LatexCommand \index{PIC14!Header files}
22609 use the support perl script inc2h.pl kept in directory support/script.
22612 \begin_layout Subsection
22616 \begin_layout Standard
22617 For the interrupt function, use the keyword '__interrupt'
22618 \begin_inset LatexCommand \index{PIC14!interrupt}
22622 with level number of 0 (PIC14 only has 1 interrupt so this number is only
22623 there to avoid a syntax error - it ought to be fixed).
22627 \begin_layout Verse
22630 void Intr(void) __interrupt 0
22636 T0IF = 0; /* Clear timer interrupt */
22641 \begin_layout Subsection
22642 Linking and assembling
22645 \begin_layout Standard
22646 For assembling you can use either GPUTILS'
22647 \begin_inset LatexCommand \index{gputils (pic tools)}
22651 gpasm.exe or MPLAB's mpasmwin.exe.
22652 GPUTILS is available from
22653 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22658 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22659 If you use MPLAB and an interrupt function then the linker script file
22660 vectors section will need to be enlarged to link with mplink.
22671 \begin_layout Verse
22684 sdcc -S -V -mpic14 -p16F877 $<
22698 $(PRJ).hex: $(OBJS)
22709 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22712 \begin_layout Standard
22720 \begin_layout Verse
22733 sdcc -S -V -mpic14 -p16F877 $<
22743 mpasmwin /q /o $*.asm
22747 $(PRJ).hex: $(OBJS)
22758 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22761 \begin_layout Standard
22762 Please note that indentations within a
22766 have to be done with a tabulator character.
22769 \begin_layout Subsection
22770 Command-line options
22773 \begin_layout Standard
22774 Besides the switches common to all SDCC backends, the PIC14 port accepts
22775 the following options (for an updated list see sdcc -
22779 \begin_layout Standard
22792 \labelwidthstring 00.00.0000
22797 \begin_layout Standard
22807 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22811 emit debug info in assembly output
22815 \labelwidthstring 00.00.0000
22820 \begin_layout Standard
22830 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22834 disable (slightly faulty) optimization on pCode
22838 \labelwidthstring 00.00.0000
22843 \begin_layout Standard
22853 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22857 sets the lowest address of the argument passing stack (defaults to a suitably
22858 large shared databank to reduce BANKSEL overhead)
22862 \labelwidthstring 00.00.0000
22867 \begin_layout Standard
22877 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22881 sets the size if the argument passing stack (default: 16, minimum: 4)
22884 \begin_layout Subsection
22888 \begin_layout Subsubsection
22889 error: missing definition for symbol
22890 \begin_inset Quotes sld
22894 \begin_inset Quotes srd
22900 \begin_layout Standard
22901 The PIC14 port uses library routines to provide more complex operations
22902 like multiplication, division/modulus and (generic) pointer dereferencing.
22903 In order to add these routines to your project, you must link with PIC14's
22909 For single source file projects this is done automatically, more complex
22914 to the linker's arguments.
22915 Make sure you also add an include path for the library (using the -I switch
22919 \begin_layout Subsubsection
22920 Processor mismatch in file
22921 \begin_inset Quotes sld
22925 \begin_inset Quotes srd
22931 \begin_layout Standard
22932 This warning can usually be ignored due to the very good compatibility amongst
22934 \begin_inset LatexCommand \index{PIC14}
22941 \begin_layout Standard
22942 You might also consider recompiling the library for your specific device
22943 by changing the ARCH=p16f877 (default target) entry in
22945 device/lib/pic/Makefile.in
22949 device/lib/pic/Makefile
22951 to reflect your device.
22952 This might even improve performance for smaller devices as unneccesary
22953 BANKSELs migth be removed.
22956 \begin_layout Subsection
22960 \begin_layout Subsubsection
22964 \begin_layout Standard
22965 Currently, data can only be initialized if it resides in the source file
22971 Data in other source files will silently
22979 \begin_inset Marginal
22982 \begin_layout Standard
22998 \begin_layout Section
23000 \begin_inset LatexCommand \index{PIC16}
23007 \begin_layout Standard
23009 \begin_inset LatexCommand \index{PIC16}
23013 port is the portion of SDCC that is responsible to produce code for the
23015 \begin_inset LatexCommand \index{Microchip}
23019 (TM) microcontrollers with 16 bit core.
23020 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23021 Currently supported devices are:
23024 \begin_layout Standard
23026 \begin_inset Tabular
23027 <lyxtabular version="3" rows="4" columns="6">
23029 <column alignment="center" valignment="top" leftline="true" width="0">
23030 <column alignment="center" valignment="top" leftline="true" width="0">
23031 <column alignment="center" valignment="top" leftline="true" width="0">
23032 <column alignment="center" valignment="top" leftline="true" width="0">
23033 <column alignment="center" valignment="top" leftline="true" width="0">
23034 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23035 <row topline="true">
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23039 \begin_layout Standard
23045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23048 \begin_layout Standard
23054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23057 \begin_layout Standard
23063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23066 \begin_layout Standard
23072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23075 \begin_layout Standard
23081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23084 \begin_layout Standard
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23095 \begin_layout Standard
23101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23104 \begin_layout Standard
23110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23113 \begin_layout Standard
23119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23122 \begin_layout Standard
23128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23131 \begin_layout Standard
23137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23140 \begin_layout Standard
23147 <row topline="true">
23148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_layout Standard
23157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23160 \begin_layout Standard
23166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23169 \begin_layout Standard
23175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23178 \begin_layout Standard
23184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23187 \begin_layout Standard
23193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23196 \begin_layout Standard
23203 <row topline="true" bottomline="true">
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23207 \begin_layout Standard
23213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23216 \begin_layout Standard
23222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23225 \begin_layout Standard
23231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23234 \begin_layout Standard
23240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23243 \begin_layout Standard
23249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23252 \begin_layout Standard
23266 \begin_layout Subsection
23270 \begin_layout Standard
23271 PIC16 port supports the standard command line arguments as supposed, with
23272 the exception of certain cases that will be mentioned in the following
23277 \labelwidthstring 00.00.0000
23282 \begin_layout Standard
23292 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23300 \begin_layout Standard
23313 \labelwidthstring 00.00.0000
23318 \begin_layout Standard
23327 -fommit-frame-pointer
23328 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23332 Frame pointer will be omitted when the function uses no local variables.
23335 \begin_layout Subsection
23336 Port Specific Options
23337 \begin_inset LatexCommand \index{Options PIC16}
23344 \begin_layout Standard
23345 The port specific options appear after the global options in the sdcc --help
23349 \begin_layout Subsubsection
23353 \begin_layout Standard
23354 General options enable certain port features and optimizations.
23358 \labelwidthstring 00.00.0000
23363 \begin_layout Standard
23372 -pstack-model=[model] Used in conjuction with the command above.
23373 Defines the stack model to be used, valid stack models are :
23378 \labelwidthstring 00.00.0000
23383 Selects small stack model.
23384 8 bit stack and frame pointers.
23385 Supports 256 bytes stack size.
23389 \labelwidthstring 00.00.0000
23394 Selects large stack model.
23395 16 bit stack and frame pointers.
23396 Supports 65536 bytes stack size.
23401 \labelwidthstring 00.00.0000
23406 \begin_layout Standard
23415 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23416 unitialized data variables with [kword].
23417 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23421 \labelwidthstring 00.00.0000
23426 \begin_layout Standard
23435 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23436 Useful for bootloaders.
23440 \labelwidthstring 00.00.0000
23445 \begin_layout Standard
23454 -asm= sets the full path and name of an external assembler to call.
23458 \labelwidthstring 00.00.0000
23463 \begin_layout Standard
23472 -link= sets the full path and name of an external linker to call.
23476 \labelwidthstring 00.00.0000
23481 \begin_layout Standard
23491 \begin_inset LatexCommand \index{PIC16!MPLAB}
23495 compatibility option.
23496 Currently only suppresses special gpasm directives.
23499 \begin_layout Subsubsection
23500 Optimization Options
23504 \labelwidthstring 00.00.0000
23509 \begin_layout Standard
23518 -optimize-goto Try to use (conditional) BRA instead of GOTO
23522 \labelwidthstring 00.00.0000
23527 \begin_layout Standard
23536 -optimize-cmp Try to optimize some compares.
23540 \labelwidthstring 00.00.0000
23545 \begin_layout Standard
23554 -optimize-df Analyze the dataflow of the generated code and improve it.
23558 \labelwidthstring 00.00.0000
23563 \begin_layout Standard
23572 -obanksel=nn Set optimization level for inserting BANKSELs.
23579 \labelwidthstring 00.00.0000
23584 \labelwidthstring 00.00.0000
23585 1 checks previous used register and if it is the same then does not emit
23586 BANKSEL, accounts only for labels.
23590 \labelwidthstring 00.00.0000
23591 2 tries to check the location of (even different) symbols and removes BANKSELs
23592 if they are in the same bank.
23597 Important: There might be problems if the linker script has data sections
23598 across bank borders!
23602 \begin_layout Subsubsection
23607 \labelwidthstring 00.00.0000
23612 \begin_layout Standard
23621 -nodefaultlibs do not link default libraries when linking
23625 \labelwidthstring 00.00.0000
23630 \begin_layout Standard
23639 -no-crt Don't link the default run-time modules
23643 \labelwidthstring 00.00.0000
23648 \begin_layout Standard
23657 -use-crt= Use a custom run-time module instead of the defaults.
23660 \begin_layout Subsubsection
23664 \begin_layout Standard
23665 Debugging options enable extra debugging information in the output files.
23669 \labelwidthstring 00.00.0000
23674 \begin_layout Standard
23683 -debug-xtra Similar to -
23687 \begin_layout Standard
23697 \begin_inset LatexCommand \index{-\/-debug}
23701 , but dumps more information.
23705 \labelwidthstring 00.00.0000
23710 \begin_layout Standard
23719 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23721 <source> is the name of the file compiled.
23725 \labelwidthstring 00.00.0000
23730 \begin_layout Standard
23739 -pcode-verbose Enable pcode debugging information in translation.
23743 \labelwidthstring 00.00.0000
23748 \begin_layout Standard
23757 -denable-peeps Force the usage of peepholes.
23762 \labelwidthstring 00.00.0000
23767 \begin_layout Standard
23776 -gstack Trace push/pops for stack pointer overflow
23780 \labelwidthstring 00.00.0000
23785 \begin_layout Standard
23794 -call-tree dump call tree in .calltree file
23797 \begin_layout Subsection
23798 Enviromental Variables
23801 \begin_layout Standard
23802 There is a number of enviromental variables that can be used when running
23803 SDCC to enable certain optimizations or force a specific program behaviour.
23804 these variables are primarily for debugging purposes so they can be enabled/dis
23808 \begin_layout Standard
23809 Currently there is only two such variables available:
23813 \labelwidthstring 00.00.0000
23814 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23815 bitfields is optimized by directly loading FSR0 with the address of the
23816 bitfield structure.
23817 Normally SDCC will cast the bitfield structure to a bitfield pointer and
23819 This step saves data ram and code space for functions that perform heavy
23822 80 bytes of code space are saved when compiling malloc.c with this option).
23827 \labelwidthstring 00.00.0000
23828 NO_REG_OPT do not perform pCode registers optimization.
23829 This should be used for debugging purposes.
23830 In some where bugs in the pcode optimizer are found, users can benefit
23831 from temporarily disabling the optimizer until the bug is fixed.
23834 \begin_layout Subsection
23835 Preprocessor Macros
23838 \begin_layout Standard
23840 \begin_inset LatexCommand \index{PIC16}
23844 port defines the following preprocessor macros while translating a source.
23847 \begin_layout Standard
23849 \begin_inset Tabular
23850 <lyxtabular version="3" rows="6" columns="2">
23852 <column alignment="center" valignment="top" leftline="true" width="0">
23853 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23854 <row topline="true" bottomline="true">
23855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23858 \begin_layout Standard
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23867 \begin_layout Standard
23874 <row topline="true">
23875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23878 \begin_layout Standard
23884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23887 \begin_layout Standard
23888 Port identification
23894 <row topline="true">
23895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23898 \begin_layout Standard
23903 \begin_layout Standard
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23920 \begin_layout Standard
23921 Port identification (same as above)
23927 <row topline="true">
23928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23931 \begin_layout Standard
23937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23940 \begin_layout Standard
23941 MCU Identification.
23946 is the microcontrol identification number, i.e.
23953 <row topline="true">
23954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23957 \begin_layout Standard
23962 \begin_layout Standard
23976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23979 \begin_layout Standard
23980 MCU Identification (same as above)
23986 <row topline="true" bottomline="true">
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23990 \begin_layout Standard
23996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23999 \begin_layout Standard
24000 nnn = SMALL or LARGE respectively according to the stack model used
24013 \begin_layout Standard
24014 In addition the following macros are defined when calling assembler:
24017 \begin_layout Standard
24019 \begin_inset Tabular
24020 <lyxtabular version="3" rows="4" columns="2">
24022 <column alignment="center" valignment="top" leftline="true" width="0">
24023 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24024 <row topline="true" bottomline="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
24044 <row topline="true">
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24048 \begin_layout Standard
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24057 \begin_layout Standard
24058 MCU Identification.
24063 is the microcontrol identification number, i.e.
24070 <row topline="true">
24071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24074 \begin_layout Standard
24080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24083 \begin_layout Standard
24084 nnn = SMALL or LARGE respectively according to the memory model used for
24091 <row topline="true" bottomline="true">
24092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24095 \begin_layout Standard
24101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24104 \begin_layout Standard
24105 nnn = SMALL or LARGE respectively according to the stack model used
24118 \begin_layout Subsection
24122 \begin_layout Standard
24124 \begin_inset LatexCommand \index{PIC16}
24128 port uses the following directories for searching header files and libraries.
24131 \begin_layout Standard
24133 \begin_inset Tabular
24134 <lyxtabular version="3" rows="3" columns="4">
24136 <column alignment="center" valignment="top" leftline="true" width="0">
24137 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24138 <column alignment="center" valignment="top" width="0">
24139 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24140 <row topline="true" bottomline="true">
24141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24144 \begin_layout Standard
24150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24153 \begin_layout Standard
24159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24162 \begin_layout Standard
24168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24171 \begin_layout Standard
24178 <row topline="true">
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24182 \begin_layout Standard
24183 PREFIX/sdcc/include/pic16
24188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24191 \begin_layout Standard
24192 PIC16 specific headers
24197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24200 \begin_layout Standard
24206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24209 \begin_layout Standard
24216 <row topline="true" bottomline="true">
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24220 \begin_layout Standard
24221 PREFIX/sdcc/lib/pic16
24226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24229 \begin_layout Standard
24230 PIC16 specific libraries
24235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24238 \begin_layout Standard
24244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24247 \begin_layout Standard
24261 \begin_layout Subsection
24263 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24270 \begin_layout Standard
24272 \begin_inset LatexCommand \index{PIC16}
24276 port currently supports the following pragmas:
24280 \labelwidthstring 00.00.0000
24282 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24287 \begin_inset LatexCommand \index{PIC16!stack}
24291 forces the code generator to initialize the stack & frame pointers at a
24293 This is an adhoc solution for cases where no STACK directive is available
24294 in the linker script or gplink is not instructed to create a stack section.
24297 stack pragma should be used only once in a project.
24298 Multiple pragmas may result in indeterminate behaviour of the program.
24302 \begin_layout Standard
24303 The old format (ie.
24304 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24305 cross page boundaries (or even exceed the available data RAM) and crash
24307 Make sure that stack does not cross page boundaries when using the SMALL
24315 The format is as follows:
24318 \begin_layout LyX-Code
24319 #pragma stack bottom_address [stack_size]
24322 \begin_layout Standard
24327 is the lower bound of the stack section.
24328 The stack pointer initially will point at address (bottom_address+stack_size-1).
24331 \begin_layout LyX-Code
24335 \begin_layout LyX-Code
24339 \begin_layout LyX-Code
24340 /* initializes stack of 100 bytes at RAM address 0x200 */
24343 \begin_layout LyX-Code
24344 #pragma stack 0x200 100
24347 \begin_layout Standard
24348 If the stack_size field is omitted then a stack is created with the default
24350 This size might be enough for most programs, but its not enough for operations
24351 with deep function nesting or excessive stack usage.
24355 \labelwidthstring 00.00.0000
24357 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24361 place a function symbol at static FLASH address
24364 \begin_layout LyX-Code
24368 \begin_layout LyX-Code
24372 \begin_layout LyX-Code
24373 /* place function test_func at 0x4000 */
24376 \begin_layout LyX-Code
24377 #pragma code test_func 0x4000
24380 \begin_layout LyX-Code
24385 \labelwidthstring 00.00.0000
24386 library instructs the linker to use a library module.
24391 \begin_layout LyX-Code
24392 #pragma library module_name
24395 \begin_layout Standard
24400 can be any library or object file (including its path).
24401 Note that there are four reserved keywords which have special meaning.
24405 \begin_layout Standard
24407 \begin_inset Tabular
24408 <lyxtabular version="3" rows="6" columns="3">
24410 <column alignment="center" valignment="top" leftline="true" width="0">
24411 <column alignment="block" valignment="top" leftline="true" width="20page%">
24412 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24413 <row topline="true" bottomline="true">
24414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24417 \begin_layout Standard
24423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24426 \begin_layout Standard
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24435 \begin_layout Standard
24442 <row topline="true">
24443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24446 \begin_layout Standard
24454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24457 \begin_layout Standard
24458 ignore all library pragmas
24463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24466 \begin_layout Standard
24475 <row topline="true">
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24479 \begin_layout Standard
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24490 \begin_layout Standard
24496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24499 \begin_layout Standard
24510 <row topline="true">
24511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24514 \begin_layout Standard
24522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24525 \begin_layout Standard
24526 link the Math libarary
24531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24534 \begin_layout Standard
24545 <row topline="true">
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24549 \begin_layout Standard
24557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24560 \begin_layout Standard
24561 link the I/O library
24566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24569 \begin_layout Standard
24580 <row topline="true" bottomline="true">
24581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24584 \begin_layout Standard
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24595 \begin_layout Standard
24596 link the debug library
24601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24604 \begin_layout Standard
24621 * is the device number, i.e.
24622 452 for PIC18F452 MCU.
24625 \begin_layout Standard
24626 This feature allows for linking with specific libraries withoug having to
24627 explicit name them in the command line.
24632 keyword will reject all modules specified by the library pragma.
24636 \labelwidthstring 00.00.0000
24637 udata pragma udata instructs the compiler to emit code so that linker will
24638 place a variable at a specific memory bank
24641 \begin_layout LyX-Code
24645 \begin_layout LyX-Code
24649 \begin_layout LyX-Code
24650 /* places variable foo at bank2 */
24653 \begin_layout LyX-Code
24654 #pragma udata bank2 foo
24657 \begin_layout LyX-Code
24661 \begin_layout Standard
24662 In order for this pragma to work extra SECTION directives should be added
24663 in the .lkr script.
24664 In the following example a sample .lkr file is shown:
24667 \begin_layout LyX-Code
24671 \begin_layout LyX-Code
24672 // Sample linker script for the PIC18F452 processor
24675 \begin_layout LyX-Code
24679 \begin_layout LyX-Code
24680 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24683 \begin_layout LyX-Code
24684 CODEPAGE NAME=page START=0x2A END=0x7FFF
24687 \begin_layout LyX-Code
24688 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24691 \begin_layout LyX-Code
24692 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24695 \begin_layout LyX-Code
24696 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24699 \begin_layout LyX-Code
24700 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24703 \begin_layout LyX-Code
24704 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24707 \begin_layout LyX-Code
24711 \begin_layout LyX-Code
24712 DATABANK NAME=gpr0 START=0x80 END=0xFF
24715 \begin_layout LyX-Code
24716 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24719 \begin_layout LyX-Code
24720 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24723 \begin_layout LyX-Code
24724 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24727 \begin_layout LyX-Code
24728 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24731 \begin_layout LyX-Code
24732 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24735 \begin_layout LyX-Code
24736 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24739 \begin_layout LyX-Code
24743 \begin_layout LyX-Code
24744 SECTION NAME=CONFIG ROM=config
24747 \begin_layout LyX-Code
24751 \begin_layout LyX-Code
24752 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
24755 \begin_layout LyX-Code
24756 SECTION NAME=bank1 RAM=gpr1 # should be added to link
24759 \begin_layout LyX-Code
24760 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
24763 \begin_layout LyX-Code
24764 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
24767 \begin_layout LyX-Code
24768 SECTION NAME=bank4 RAM=gpr4
24771 \begin_layout LyX-Code
24772 SECTION NAME=bank5 RAM=gpr5
24775 \begin_layout Standard
24776 The linker will recognise the section name set in the pragma statement and
24777 will position the variable at the memory bank set with the RAM field at
24778 the SECTION line in the linker script file.
24781 \begin_layout Subsection
24783 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24790 \begin_layout Standard
24791 There is one main header file
24792 \begin_inset LatexCommand \index{PIC16!Header files}
24796 that can be included to the source files using the pic16
24797 \begin_inset LatexCommand \index{PIC16}
24807 This header file contains the definitions for the processor special registers,
24808 so it is necessary if the source accesses them.
24809 It can be included by adding the following line in the beginning of the
24813 \begin_layout LyX-Code
24814 #include <pic18fregs.h>
24817 \begin_layout Standard
24818 The specific microcontroller is selected within the pic18fregs.h automatically,
24819 so the same source can be used with a variety of devices.
24822 \begin_layout Subsection
24826 \begin_layout Standard
24828 \begin_inset LatexCommand \index{PIC16!Libraries}
24833 \begin_inset LatexCommand \index{PIC16}
24837 port depends on are the microcontroller device libraries which contain
24838 the symbol definitions for the microcontroller special function registers.
24839 These libraries have the format pic18fxxxx.lib, where
24843 is the microcontroller identification number.
24844 The specific library is selected automatically by the compiler at link
24845 stage according to the selected device.
24848 \begin_layout Standard
24849 Libraries are created with gplib which is part of the gputils package
24850 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24857 \begin_layout Subsubsection*
24858 Building the libraries
24861 \begin_layout Standard
24862 Before using SDCC/pic16 there are some libraries that need to be compiled.
24863 This process is not done automatically by SDCC since not all users use
24864 SDCC for pic16 projects.
24865 So each user should compile the libraries separately.
24868 \begin_layout Standard
24869 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24872 \begin_layout LyX-Code
24873 cd device/lib/pic16
24876 \begin_layout LyX-Code
24880 \begin_layout LyX-Code
24884 \begin_layout LyX-Code
24888 \begin_layout LyX-Code
24892 \begin_layout LyX-Code
24893 su -c 'make install' # install the libraries, you need the root password
24896 \begin_layout Standard
24897 If you need to install the headers too, do:
24900 \begin_layout LyX-Code
24904 \begin_layout LyX-Code
24905 su -c 'make install' # install the headers, you need the root password
24908 \begin_layout Standard
24909 There exist a special target to build the I/O libraries.
24910 This target is not automatically build because it will build the I/O library
24916 This way building will take quite a lot of time.
24917 Users are advised to edit the
24919 device/lib/pic16/pics.build
24921 file and then execute:
24924 \begin_layout LyX-Code
24928 \begin_layout Subsection
24932 \begin_layout Standard
24933 The following memory models are supported by the PIC16 port:
24936 \begin_layout Itemize
24940 \begin_layout Itemize
24944 \begin_layout Standard
24945 Memory model affects the default size of pointers within the source.
24946 The sizes are shown in the next table:
24949 \begin_layout Standard
24951 \begin_inset Tabular
24952 <lyxtabular version="3" rows="3" columns="3">
24954 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24955 <column alignment="center" valignment="top" leftline="true" width="0">
24956 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24957 <row topline="true" bottomline="true">
24958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24961 \begin_layout Standard
24962 Pointer sizes according to memory model
24967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24970 \begin_layout Standard
24976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24979 \begin_layout Standard
24986 <row topline="true" bottomline="true">
24987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24990 \begin_layout Standard
24996 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24999 \begin_layout Standard
25005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25008 \begin_layout Standard
25015 <row topline="true" bottomline="true">
25016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25019 \begin_layout Standard
25025 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25028 \begin_layout Standard
25034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25037 \begin_layout Standard
25051 \begin_layout Standard
25052 It is advisable that all sources within a project are compiled with the
25054 If one wants to override the default memory model, this can be done by
25055 declaring a pointer as
25064 Far selects large memory model's pointers, while near selects small memory
25068 \begin_layout Standard
25069 The standard device libraries (see
25070 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25074 ) contain no reference to pointers, so they can be used with both memory
25078 \begin_layout Subsection
25082 \begin_layout Standard
25084 \begin_inset LatexCommand \index{PIC16!stack}
25088 implementation for the PIC16 port uses two indirect registers, FSR1 and
25093 \labelwidthstring 00.00.0000
25094 FSR1 is assigned as stack pointer
25098 \labelwidthstring 00.00.0000
25099 FSR2 is assigned as frame pointer
25102 \begin_layout Standard
25103 The following stack models are supported by the PIC16 port
25106 \begin_layout Itemize
25114 \begin_layout Itemize
25122 \begin_layout Standard
25127 model means that only the FSRxL byte is used to access stack and frame,
25134 uses both FSRxL and FSRxH registers.
25135 The following table shows the stack/frame pointers sizes according to stack
25136 model and the maximum space they can address:
25139 \begin_layout Standard
25141 \begin_inset Tabular
25142 <lyxtabular version="3" rows="3" columns="3">
25144 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25145 <column alignment="center" valignment="top" leftline="true" width="0">
25146 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25147 <row topline="true" bottomline="true">
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25151 \begin_layout Standard
25152 Stack & Frame pointer sizes according to stack model
25157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25160 \begin_layout Standard
25166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25169 \begin_layout Standard
25176 <row topline="true">
25177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25180 \begin_layout Standard
25186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25189 \begin_layout Standard
25195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25198 \begin_layout Standard
25205 <row topline="true" bottomline="true">
25206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25209 \begin_layout Standard
25215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25218 \begin_layout Standard
25224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25227 \begin_layout Standard
25241 \begin_layout Standard
25246 stack model is currently not working properly throughout the code generator.
25247 So its use is not advised.
25248 Also there are some other points that need special care:
25253 \begin_layout Enumerate
25254 Do not create stack sections with size more than one physical bank (that
25258 \begin_layout Enumerate
25259 Stack sections should no cross physical bank limits (i.e.
25260 #pragma stack 0x50 0x100)
25263 \begin_layout Standard
25264 These limitations are caused by the fact that only FSRxL is modified when
25265 using SMALL stack model, so no more than 256 bytes of stack can be used.
25266 This problem will disappear after LARGE model is fully implemented.
25269 \begin_layout Subsection
25273 \begin_layout Standard
25274 In addition to the standard SDCC function keywords, PIC16
25275 \begin_inset LatexCommand \index{PIC16}
25279 port makes available two more:
25283 \labelwidthstring 00.00.0000
25285 \begin_inset LatexCommand \index{PIC16!wparam}
25289 Use the WREG to pass one byte of the first function argument.
25290 This improves speed but you may not use this for functions with arguments
25291 that are called via function pointers, otherwise the first byte of the
25292 first parameter will get lost.
25296 \begin_layout LyX-Code
25297 void func_wparam(int a) wparam
25300 \begin_layout LyX-Code
25304 \begin_layout LyX-Code
25305 /* WREG hold the lower part of a */
25308 \begin_layout LyX-Code
25309 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25313 \begin_layout LyX-Code
25317 \begin_layout LyX-Code
25322 \labelwidthstring 00.00.0000
25324 \begin_inset LatexCommand \index{PIC16!shadowregs}
25328 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25329 hardware shadow registers which hold the values of WREG, STATUS and BSR
25331 This can be done by adding the keyword
25339 keyword in the function's header.
25342 \begin_layout LyX-Code
25343 void isr_shadow(void) shadowregs interrupt 1
25346 \begin_layout LyX-Code
25350 \begin_layout LyX-Code
25354 \begin_layout LyX-Code
25358 \begin_layout Standard
25363 instructs the code generator not to store/restore WREG, STATUS, BSR when
25364 entering/exiting the ISR.
25367 \begin_layout Subsection
25368 Function return values
25371 \begin_layout Standard
25372 Return values from functions are placed to the appropriate registers following
25373 a modified Microchip policy optimized for SDCC.
25374 The following table shows these registers:
25377 \begin_layout Standard
25379 \begin_inset Tabular
25380 <lyxtabular version="3" rows="6" columns="2">
25382 <column alignment="center" valignment="top" leftline="true" width="0">
25383 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25384 <row topline="true" bottomline="true">
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25388 \begin_layout Standard
25394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25397 \begin_layout Standard
25398 destination register
25404 <row topline="true">
25405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25408 \begin_layout Standard
25414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25417 \begin_layout Standard
25424 <row topline="true">
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25428 \begin_layout Standard
25434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25437 \begin_layout Standard
25444 <row topline="true">
25445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25448 \begin_layout Standard
25454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25457 \begin_layout Standard
25464 <row topline="true">
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25468 \begin_layout Standard
25474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25477 \begin_layout Standard
25478 FSR0L:PRODH:PRODL:WREG
25484 <row topline="true" bottomline="true">
25485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25488 \begin_layout Standard
25494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25497 \begin_layout Standard
25498 on stack, FSR0 points to the beginning
25511 \begin_layout Subsection
25515 \begin_layout Standard
25517 \begin_inset LatexCommand \index{PIC16!interrupt}
25521 service routine (ISR) is declared using the
25528 \begin_layout LyX-Code
25529 void isr(void) interrupt
25534 \begin_layout LyX-Code
25538 \begin_layout LyX-Code
25542 \begin_layout LyX-Code
25546 \begin_layout Standard
25551 is the interrupt number, which for PIC18F devices can be:
25554 \begin_layout Standard
25556 \begin_inset Tabular
25557 <lyxtabular version="3" rows="4" columns="3">
25559 <column alignment="center" valignment="top" leftline="true" width="0">
25560 <column alignment="center" valignment="top" leftline="true" width="0">
25561 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25562 <row topline="true" bottomline="true">
25563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25566 \begin_layout Standard
25574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25577 \begin_layout Standard
25583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25586 \begin_layout Standard
25587 Interrupt Vector Address
25593 <row topline="true">
25594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25597 \begin_layout Standard
25603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25606 \begin_layout Standard
25612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25615 \begin_layout Standard
25622 <row topline="true">
25623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25626 \begin_layout Standard
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25644 \begin_layout Standard
25654 HIGH priority interrupts
25659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25662 \begin_layout Standard
25669 <row topline="true" bottomline="true">
25670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25673 \begin_layout Standard
25679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25682 \begin_layout Standard
25683 LOW priority interrupts
25688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25691 \begin_layout Standard
25705 \begin_layout Standard
25706 When generating assembly code for ISR the code generator places a
25712 Interrupt Vector Address
25714 which points at the genetated ISR.
25715 This single GOTO instruction is part of an automatically generated
25717 interrupt entry point
25720 The actuall ISR code is placed as normally would in the code space.
25721 Upon interrupt request, the GOTO instruction is executed which jumps to
25723 When declaring interrupt functions as _naked this GOTO instruction is
25728 The whole interrupt functions is therefore placed at the Interrupt Vector
25729 Address of the specific interrupt.
25730 This is not a problem for the LOW priority interrupts, but it is a problem
25731 for the RESET and the HIGH priority interrupts because code may be written
25732 at the next interrupt´s vector address and cause undeterminate program
25733 behaviour if that interrupt is raised.
25737 \begin_layout Standard
25738 This is not a problem when
25741 \begin_layout Enumerate
25742 this is a HIGH interrupt ISR and LOW interrupts are
25749 \begin_layout Enumerate
25750 when the ISR is small enough not to reach the next interrupt´s vector address.
25758 \begin_layout Standard
25763 is possible to be omitted.
25764 This way a function is generated similar to an ISR, but it is not assigned
25768 \begin_layout Standard
25769 When entering an interrupt, currently the PIC16
25770 \begin_inset LatexCommand \index{PIC16}
25774 port automatically saves the following registers:
25777 \begin_layout Itemize
25781 \begin_layout Itemize
25785 \begin_layout Itemize
25789 \begin_layout Itemize
25790 PROD (PRODL and PRODH)
25793 \begin_layout Itemize
25794 FSR0 (FSR0L and FSR0H)
25797 \begin_layout Standard
25798 These registers are restored upon return from the interrupt routine.
25802 \begin_layout Standard
25803 NOTE that when the _naked attribute is specified for an interrupt routine,
25804 then NO registers are stored or restored.
25812 \begin_layout Subsection
25816 \begin_layout Standard
25817 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25818 There are 3 types of generic pointers currently implemented data, code
25819 and eeprom pointers.
25820 They are differentiated by the value of the 7th and 6th bits of the upper
25824 \begin_layout Standard
25826 \begin_inset Tabular
25827 <lyxtabular version="3" rows="5" columns="5">
25829 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25830 <column alignment="center" valignment="top" width="0">
25831 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25832 <column alignment="center" valignment="top" width="0">
25833 <column alignment="left" valignment="top" rightline="true" width="0">
25834 <row topline="true" bottomline="true">
25835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25838 \begin_layout Standard
25844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25847 \begin_layout Standard
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25856 \begin_layout Standard
25862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25865 \begin_layout Standard
25866 rest of the pointer
25871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25874 \begin_layout Standard
25881 <row topline="true" bottomline="true">
25882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25885 \begin_layout Standard
25891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25894 \begin_layout Standard
25900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25903 \begin_layout Standard
25909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25912 \begin_layout Standard
25917 uuuuuu uuuuxxxx xxxxxxxx
25922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25925 \begin_layout Standard
25926 a 12-bit data pointer in data RAM memory
25932 <row bottomline="true">
25933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25936 \begin_layout Standard
25942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25945 \begin_layout Standard
25951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25954 \begin_layout Standard
25960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25963 \begin_layout Standard
25968 uxxxxx xxxxxxxx xxxxxxxx
25973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25976 \begin_layout Standard
25977 a 21-bit code pointer in FLASH memory
25983 <row bottomline="true">
25984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25987 \begin_layout Standard
25993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25996 \begin_layout Standard
26002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26005 \begin_layout Standard
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26014 \begin_layout Standard
26019 uuuuuu uuuuuuxx xxxxxxxx
26024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26027 \begin_layout Standard
26028 a 10-bit eeprom pointer in EEPROM memory
26034 <row bottomline="true">
26035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26038 \begin_layout Standard
26044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26047 \begin_layout Standard
26053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26056 \begin_layout Standard
26062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26065 \begin_layout Standard
26070 xxxxxx xxxxxxxx xxxxxxxx
26075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26078 \begin_layout Standard
26079 unimplemented pointer type
26092 \begin_layout Standard
26093 Generic pointer are read and written with a set of library functions which
26094 read/write 1, 2, 3, 4 bytes.
26097 \begin_layout Subsection
26101 \begin_layout Subsubsection
26102 Standard I/O Streams
26105 \begin_layout Standard
26110 the type FILE is defined as:
26113 \begin_layout LyX-Code
26114 typedef char * FILE;
26117 \begin_layout Standard
26118 This type is the stream type implemented I/O in the PIC18F devices.
26119 Also the standard input and output streams are declared in stdio.h:
26122 \begin_layout LyX-Code
26123 extern FILE * stdin;
26126 \begin_layout LyX-Code
26127 extern FILE * stdout;
26130 \begin_layout Standard
26131 The FILE type is actually a generic pointer which defines one more type
26132 of generic pointers, the
26137 This new type has the format:
26140 \begin_layout Standard
26142 \begin_inset Tabular
26143 <lyxtabular version="3" rows="2" columns="7">
26145 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26146 <column alignment="center" valignment="top" width="0">
26147 <column alignment="center" valignment="top" leftline="true" width="0">
26148 <column alignment="center" valignment="top" leftline="true" width="0">
26149 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26150 <column alignment="center" valignment="top" width="0">
26151 <column alignment="left" valignment="top" rightline="true" width="0">
26152 <row topline="true" bottomline="true">
26153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26156 \begin_layout Standard
26162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26165 \begin_layout Standard
26171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26174 \begin_layout Standard
26180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26183 \begin_layout Standard
26189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26192 \begin_layout Standard
26198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26201 \begin_layout Standard
26202 rest of the pointer
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26210 \begin_layout Standard
26217 <row topline="true" bottomline="true">
26218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26221 \begin_layout Standard
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26230 \begin_layout Standard
26236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26239 \begin_layout Standard
26245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26248 \begin_layout Standard
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26257 \begin_layout Standard
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26266 \begin_layout Standard
26276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26279 \begin_layout Standard
26280 upper byte high nubble is 0x2n, the rest are zeroes
26293 \begin_layout Standard
26294 Currently implemented there are 3 types of streams defined:
26297 \begin_layout Standard
26299 \begin_inset Tabular
26300 <lyxtabular version="3" rows="4" columns="4">
26302 <column alignment="center" valignment="top" leftline="true" width="0">
26303 <column alignment="center" valignment="top" leftline="true" width="0">
26304 <column alignment="center" valignment="top" leftline="true" width="0">
26305 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26306 <row topline="true" bottomline="true">
26307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26310 \begin_layout Standard
26316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26319 \begin_layout Standard
26325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26328 \begin_layout Standard
26334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26337 \begin_layout Standard
26344 <row topline="true">
26345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26348 \begin_layout Standard
26354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26357 \begin_layout Standard
26365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26368 \begin_layout Standard
26374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26377 \begin_layout Standard
26378 Writes/Reads characters via the USART peripheral
26384 <row topline="true">
26385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26388 \begin_layout Standard
26394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26397 \begin_layout Standard
26405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26408 \begin_layout Standard
26414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26417 \begin_layout Standard
26418 Writes/Reads characters via the MSSP peripheral
26424 <row topline="true" bottomline="true">
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26428 \begin_layout Standard
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26437 \begin_layout Standard
26445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26448 \begin_layout Standard
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26457 \begin_layout Standard
26458 Writes/Reads characters via used defined functions
26471 \begin_layout Standard
26472 The stream identifiers are declared as macros in the stdio.h header.
26475 \begin_layout Standard
26476 In the libc library there exist the functions that are used to write to
26477 each of the above streams.
26482 \labelwidthstring 00.00.0000
26487 \begin_layout Standard
26496 _stream_usart_putchar writes a character at the USART stream
26500 \labelwidthstring 00.00.0000
26505 \begin_layout Standard
26514 _stream_mssp_putchar writes a character at the MSSP stream
26518 \labelwidthstring 00.00.0000
26519 putchar dummy function.
26520 This writes a character to a user specified manner.
26523 \begin_layout Standard
26524 In order to increase performance
26528 is declared in stdio.h as having its parameter in WREG (it has the wparam
26530 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26531 in a user-friendly way.
26536 is the name of the variable that holds the character to print.
26537 An example follows:
26540 \begin_layout LyX-Code
26541 #include <pic18fregs.h>
26550 \begin_layout LyX-Code
26554 \begin_layout LyX-Code
26555 PORTA = c; /* dump character c to PORTA */
26558 \begin_layout LyX-Code
26566 \begin_layout LyX-Code
26570 \begin_layout LyX-Code
26571 stdout = STREAM_USER; /* this is not necessary, since stdout points
26574 \begin_layout LyX-Code
26575 * by default to STREAM_USER */
26578 \begin_layout LyX-Code
26579 printf (¨This is a printf test
26584 \begin_layout LyX-Code
26588 \begin_layout LyX-Code
26592 \begin_layout Subsubsection
26596 \begin_layout Standard
26597 PIC16 contains an implementation of the printf-family of functions.
26598 There exist the following functions:
26601 \begin_layout LyX-Code
26602 extern unsigned int sprintf(char *buf, char *fmt, ...);
26605 \begin_layout LyX-Code
26606 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26609 \begin_layout LyX-Code
26613 \begin_layout LyX-Code
26614 extern unsigned int printf(char *fmt, ...);
26617 \begin_layout LyX-Code
26618 extern unsigned int vprintf(char *fmt, va_lista ap);
26621 \begin_layout LyX-Code
26625 \begin_layout LyX-Code
26626 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26629 \begin_layout LyX-Code
26630 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26633 \begin_layout Standard
26634 For sprintf and vsprintf
26638 should normally be a data pointer where the resulting string will be placed.
26639 No range checking is done so the user should allocate the necessery buffer.
26640 For fprintf and vfprintf
26644 should be a stream pointer (i.e.
26645 stdout, STREAM_MSSP, etc...).
26648 \begin_layout Subsubsection
26652 \begin_layout Standard
26653 The PIC18F family of microcontrollers supports a number of interrupt sources.
26654 A list of these interrupts is shown in the following table:
26657 \begin_layout Standard
26659 \begin_inset Tabular
26660 <lyxtabular version="3" rows="11" columns="4">
26662 <column alignment="left" valignment="top" leftline="true" width="0">
26663 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26664 <column alignment="left" valignment="top" leftline="true" width="0">
26665 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26666 <row topline="true" bottomline="true">
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26670 \begin_layout Standard
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_layout Standard
26685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26688 \begin_layout Standard
26694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26697 \begin_layout Standard
26704 <row topline="true">
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26708 \begin_layout Standard
26714 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26717 \begin_layout Standard
26718 PORTB change interrupt
26723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26726 \begin_layout Standard
26732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26735 \begin_layout Standard
26736 EEPROM/FLASH write complete interrupt
26742 <row topline="true">
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26746 \begin_layout Standard
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26755 \begin_layout Standard
26756 INT0 external interrupt
26761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26764 \begin_layout Standard
26770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26773 \begin_layout Standard
26774 Bus collision interrupt
26780 <row topline="true">
26781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26784 \begin_layout Standard
26790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26793 \begin_layout Standard
26794 INT1 external interrupt
26799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26802 \begin_layout Standard
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26811 \begin_layout Standard
26812 Low voltage detect interrupt
26818 <row topline="true">
26819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26822 \begin_layout Standard
26828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26831 \begin_layout Standard
26832 INT2 external interrupt
26837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26840 \begin_layout Standard
26846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26849 \begin_layout Standard
26850 Parallel slave port interrupt
26856 <row topline="true">
26857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26860 \begin_layout Standard
26866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26869 \begin_layout Standard
26870 CCP1 module interrupt
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26878 \begin_layout Standard
26884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26887 \begin_layout Standard
26888 AD convertion complete interrupt
26894 <row topline="true">
26895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26898 \begin_layout Standard
26904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26907 \begin_layout Standard
26908 CCP2 module interrupt
26913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26916 \begin_layout Standard
26922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26925 \begin_layout Standard
26926 USART receive interrupt
26932 <row topline="true">
26933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26936 \begin_layout Standard
26942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26945 \begin_layout Standard
26946 TMR0 overflow interrupt
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26954 \begin_layout Standard
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26963 \begin_layout Standard
26964 USART transmit interrupt
26970 <row topline="true">
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26974 \begin_layout Standard
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26983 \begin_layout Standard
26984 TMR1 overflow interrupt
26989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26992 \begin_layout Standard
26998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27001 \begin_layout Standard
27002 SSP receive/transmit interrupt
27008 <row topline="true">
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27012 \begin_layout Standard
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_layout Standard
27022 TMR2 matches PR2 interrupt
27027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27030 \begin_layout Standard
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27039 \begin_layout Standard
27046 <row topline="true" bottomline="true">
27047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27050 \begin_layout Standard
27056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27059 \begin_layout Standard
27060 TMR3 overflow interrupt
27065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27068 \begin_layout Standard
27074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27077 \begin_layout Standard
27091 \begin_layout Standard
27092 The prototypes for these names are defined in the header file
27099 \begin_layout Standard
27100 In order to simplify signal handling, a number of macros is provided:
27104 \labelwidthstring 00.00.0000
27105 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27106 high priority interrupts.
27111 is the function name to use.
27115 \labelwidthstring 00.00.0000
27116 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27117 low priority interrupt.
27122 is the function name to use.
27126 \labelwidthstring 00.00.0000
27127 DEF_HANDLER(sig,handler) define a handler for signal
27133 \labelwidthstring 00.00.0000
27134 END_DEF end the declaration of the dispatch table.
27137 \begin_layout Standard
27138 Additionally there are two more macros to simplify the declaration of the
27143 \labelwidthstring 00.00.0000
27146 SIGHANDLER(handler)
27148 this declares the function prototype for the
27156 \labelwidthstring 00.00.0000
27157 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27160 \begin_layout Standard
27161 An example of using the macros above is shown below:
27164 \begin_layout LyX-Code
27165 #include <pic18fregs.h>
27168 \begin_layout LyX-Code
27169 #include <signal.h>
27173 DEF_INTHIGH(high_int)
27176 \begin_layout LyX-Code
27177 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27180 \begin_layout LyX-Code
27181 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27184 \begin_layout LyX-Code
27189 SIGHANDLER(_tmr0_handler)
27192 \begin_layout LyX-Code
27196 \begin_layout LyX-Code
27197 /* action to be taken when timer 0 overflows */
27200 \begin_layout LyX-Code
27205 SIGHANDLERNAKED(_bcol_handler)
27208 \begin_layout LyX-Code
27212 \begin_layout LyX-Code
27216 \begin_layout LyX-Code
27217 /* action to be taken when bus collision occurs */
27220 \begin_layout LyX-Code
27224 \begin_layout LyX-Code
27228 \begin_layout LyX-Code
27232 \begin_layout Standard
27237 Special care should be taken when using the above scheme:
27240 \begin_layout Itemize
27241 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27244 \begin_layout Itemize
27245 when declaring SIGHANDLERNAKED handler never forget to use
27249 for proper returning.
27252 \begin_layout Subsection
27256 \begin_layout Standard
27257 Here you can find some general tips for compiling programs with SDCC/pic16.
27260 \begin_layout Subsubsection
27264 \begin_layout Standard
27266 \begin_inset LatexCommand \index{PIC16!stack}
27270 size (that is 64 bytes) probably is enough for many programs.
27271 One must take care that when there are many levels of function nesting,
27272 or there is excessive usage of stack, its size should be extended.
27273 An example of such a case is the printf/sprintf family of functions.
27274 If you encounter problems like not being able to print integers, then you
27275 need to set the stack size around the maximum (256 for small stack model).
27276 The following diagram shows what happens when calling printf to print an
27280 \begin_layout LyX-Code
27281 printf () --> ltoa () --> ultoa () --> divschar ()
27284 \begin_layout Standard
27285 It is should be understood that stack is easily consumed when calling complicate
27287 Using command line arguments like -
27291 \begin_layout Standard
27300 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27302 Other ways to reduce stack usage may exist.
27305 \begin_layout Subsection
27309 \begin_layout Standard
27310 The PIC16 Port currently does not pass SDCC's regression test
27311 \begin_inset LatexCommand \index{Regression test (PIC16)}
27316 \begin_inset LatexCommand \ref{sec:Quality-control}
27320 ) and thus the snapshot build regression tests for the PIC16 target are
27321 currently disabled for all hosts
27326 \begin_layout Chapter
27330 \begin_layout Standard
27331 There are several approaches to debugging your code.
27332 This chapter is meant to show your options and to give detail on some of
27337 When writing your code:
27340 \begin_layout Itemize
27341 write your code with debugging in mind (avoid duplicating code, put conceptually
27342 similar variables into structs, use structured code, have strategic points
27343 within your code where all variables are consistent, ...)
27346 \begin_layout Itemize
27347 run a syntax-checking tool like splint
27348 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27353 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27361 \begin_layout Standard
27371 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27378 \begin_layout Itemize
27379 for the high level code use a C-compiler (like f.e.
27380 GCC) to compile run and debug the code on your host.
27385 \begin_layout Standard
27395 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27399 ) on how to handle syntax extensions like __xdata, __at(), ...
27403 \begin_layout Itemize
27404 use another C-compiler to compile code for your target.
27405 Always an option but not recommended:) And not very likely to help you.
27406 If you seriously consider walking this path you should at least occasionally
27407 check portability of your code.
27408 Most commercial compiler vendors will offer an evaluation version so you
27409 can test compile your code or snippets of your code.
27412 \begin_layout Standard
27413 Debugging on a simulator:
27416 \begin_layout Itemize
27417 there is a separate section about SDCDB (section
27418 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27425 \begin_layout Itemize
27426 or (8051 specific) use a freeware/commercial simulator which interfaces
27428 \begin_inset LatexCommand \index{AOMF, AOMF51}
27433 \begin_inset LatexCommand \ref{OMF file}
27437 ) optionally generated by SDCC.
27440 \begin_layout Standard
27441 Debugging On-target:
27444 \begin_layout Itemize
27445 use a MCU port pin to serially output debug data to the RS232 port of your
27447 You'll probably want some level shifting device typically involving a MAX232
27449 If the hardware serial port of the MCU is not available search for 'Software
27450 UART' in your favourite search machine.
27453 \begin_layout Itemize
27454 use an on-target monitor.
27455 In this context a monitor is a small program which usually accepts commands
27456 via a serial line and allows to set program counter, to single step through
27457 a program and read/write memory locations.
27458 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27460 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27467 \begin_layout Itemize
27468 toggle MCU port pins at strategic points within your code and use an oscilloscop
27472 digital oscilloscope
27475 \begin_inset LatexCommand \index{Oscilloscope}
27479 with deep trace memory is really helpful especially if you have to debug
27480 a realtime application.
27481 If you need to monitor more pins than your oscilloscope provides you can
27482 sometimes get away with a small R-2R network.
27483 On a single channel oscilloscope you could f.e.
27484 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27486 \begin_inset Formula $\Omega$
27489 resistor and the other one by a 5\InsetSpace ~
27491 \begin_inset Formula $\Omega$
27494 resistor to the oscilloscope probe (check output drive capability of the
27495 pins you want to monitor).
27496 If you need to monitor many more pins a
27503 \begin_layout Itemize
27517 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27522 Usually very expensive.
27523 And very nice to have too.
27524 And usually locks you (for years...) to the devices the ICE can emulate.
27528 \begin_layout Itemize
27529 use a remote debugger.
27530 In most 8-bit systems the symbol information is not available on the target,
27531 and a complete debugger is too bulky for the target system.
27532 Therefore usually a debugger on the host system connects to an on-target
27533 debugging stub which accepts only primitive commands.
27536 Terms to enter into your favourite search engine could be 'remote debugging',
27537 'gdb stub' or 'inferior debugger'.
27541 \begin_layout Itemize
27542 use an on target hardware debugger.
27543 Some of the more modern MCUs include hardware support for setting break
27544 points and monitoring/changing variables by using dedicated hardware pins.
27545 This facility doesn't require additional code to run on the target and
27550 doesn't affect runtime behaviour until a breakpoint is hit.
27551 For the mcs51 most hardware debuggers use the AOMF
27552 \begin_inset LatexCommand \index{AOMF, AOMF51}
27557 \begin_inset LatexCommand \ref{OMF file}
27565 \begin_layout Standard
27569 \begin_layout Itemize
27570 if you are not familiar with any of the following terms you're likely to
27571 run into problems rather sooner than later:
27588 As an embedded programmer you
27592 to know them so why not look them up
27596 you have problems?)
27599 \begin_layout Itemize
27600 tell someone else about your problem (actually this is a surprisingly effective
27601 means to hunt down the bug even if the listener is not familiar with your
27603 As 'failure to communicate' is probably one of the job-induced deformations
27604 of an embedded programmer this is highly encouraged.
27607 \begin_layout Section
27608 Debugging with SDCDB
27609 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27614 \begin_inset LatexCommand \index{SDCDB (debugger)}
27621 \begin_layout Standard
27622 SDCC is distributed with a source level debugger
27623 \begin_inset LatexCommand \index{Debugger}
27628 The debugger uses a command line interface, the command repertoire of the
27629 debugger has been kept as close to gdb
27630 \begin_inset LatexCommand \index{gdb}
27634 (the GNU debugger) as possible.
27635 The configuration and build process is part of the standard compiler installati
27636 on, which also builds and installs the debugger in the target directory
27637 specified during configuration.
27638 The debugger allows you debug BOTH at the C source and at the ASM source
27642 \begin_layout Subsection
27643 Compiling for Debugging
27646 \begin_layout Standard
27651 \begin_layout Standard
27661 \begin_inset LatexCommand \index{-\/-debug}
27665 option must be specified for all files for which debug information is to
27667 The compiler generates a .adb file for each of these files.
27668 The linker creates the .cdb
27669 \begin_inset LatexCommand \index{<file>.cdb}
27674 \begin_inset LatexCommand \index{<file>.adb}
27678 files and the address information.
27679 This .cdb is used by the debugger.
27682 \begin_layout Subsection
27683 How the Debugger Works
27686 \begin_layout Standard
27691 \begin_layout Standard
27700 -debug option is specified the compiler generates extra symbol information
27701 some of which are put into the assembler source and some are put into the
27703 Then the linker creates the .cdb file from the individual .adb files with
27704 the address information for the symbols.
27705 The debugger reads the symbolic information generated by the compiler &
27706 the address information generated by the linker.
27707 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27708 execution is controlled by the debugger.
27709 When a command is issued for the debugger, it translates it into appropriate
27710 commands for the simulator.
27711 (Currently SDCDM only connects to the simulator but
27716 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27720 is an effort to connect directly to the hardware.)
27723 \begin_layout Subsection
27724 Starting the Debugger SDCDB
27727 \begin_layout Standard
27728 The debugger can be started using the following command line.
27729 (Assume the file you are debugging has the file name foo).
27743 The debugger will look for the following files.
27746 \begin_layout Itemize
27747 foo.c - the source file.
27750 \begin_layout Itemize
27751 foo.cdb - the debugger symbol information file.
27754 \begin_layout Itemize
27755 foo.ihx - the Intel hex format
27756 \begin_inset LatexCommand \index{Intel hex format}
27763 \begin_layout Subsection
27764 SDCDB Command Line Options
27767 \begin_layout Itemize
27772 \begin_layout Standard
27781 -directory=<source file directory> this option can used to specify the directory
27783 The debugger will look into the directory list specified for source, cdb
27785 The items in the directory list must be separated by ':', e.g.
27786 if the source files can be in the directories /home/src1 and /home/src2,
27791 \begin_layout Standard
27800 -directory option should be -
27804 \begin_layout Standard
27813 -directory=/home/src1:/home/src2.
27814 Note there can be no spaces in the option.
27818 \begin_layout Itemize
27819 -cd <directory> - change to the <directory>.
27822 \begin_layout Itemize
27823 -fullname - used by GUI front ends.
27826 \begin_layout Itemize
27827 -cpu <cpu-type> - this argument is passed to the simulator please see the
27828 simulator docs for details.
27831 \begin_layout Itemize
27832 -X <Clock frequency > this options is passed to the simulator please see
27833 the simulator docs for details.
27836 \begin_layout Itemize
27837 -s <serial port file> passed to simulator see the simulator docs for details.
27840 \begin_layout Itemize
27841 -S <serial in,out> passed to simulator see the simulator docs for details.
27844 \begin_layout Itemize
27845 -k <port number> passed to simulator see the simulator docs for details.
27848 \begin_layout Subsection
27849 SDCDB Debugger Commands
27852 \begin_layout Standard
27853 As mentioned earlier the command interface for the debugger has been deliberatel
27854 y kept as close the GNU debugger gdb, as possible.
27855 This will help the integration with existing graphical user interfaces
27856 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27857 If you use a graphical user interface for the debugger you can skip this
27861 \begin_layout Subsubsection*
27862 break [line | file:line | function | file:function]
27865 \begin_layout Standard
27866 Set breakpoint at specified line or function:
27875 sdcdb>break foo.c:100
27877 sdcdb>break funcfoo
27879 sdcdb>break foo.c:funcfoo
27882 \begin_layout Subsubsection*
27883 clear [line | file:line | function | file:function ]
27886 \begin_layout Standard
27887 Clear breakpoint at specified line or function:
27896 sdcdb>clear foo.c:100
27898 sdcdb>clear funcfoo
27900 sdcdb>clear foo.c:funcfoo
27903 \begin_layout Subsubsection*
27907 \begin_layout Standard
27908 Continue program being debugged, after breakpoint.
27911 \begin_layout Subsubsection*
27915 \begin_layout Standard
27916 Execute till the end of the current function.
27919 \begin_layout Subsubsection*
27923 \begin_layout Standard
27924 Delete breakpoint number 'n'.
27925 If used without any option clear ALL user defined break points.
27928 \begin_layout Subsubsection*
27929 info [break | stack | frame | registers ]
27932 \begin_layout Itemize
27933 info break - list all breakpoints
27936 \begin_layout Itemize
27937 info stack - show the function call stack.
27940 \begin_layout Itemize
27941 info frame - show information about the current execution frame.
27944 \begin_layout Itemize
27945 info registers - show content of all registers.
27948 \begin_layout Subsubsection*
27952 \begin_layout Standard
27953 Step program until it reaches a different source line.
27954 Note: pressing <return> repeats the last command.
27957 \begin_layout Subsubsection*
27961 \begin_layout Standard
27962 Step program, proceeding through subroutine calls.
27965 \begin_layout Subsubsection*
27969 \begin_layout Standard
27970 Start debugged program.
27973 \begin_layout Subsubsection*
27977 \begin_layout Standard
27978 Print type information of the variable.
27981 \begin_layout Subsubsection*
27985 \begin_layout Standard
27986 print value of variable.
27989 \begin_layout Subsubsection*
27993 \begin_layout Standard
27994 load the given file name.
27995 Note this is an alternate method of loading file for debugging.
27998 \begin_layout Subsubsection*
28002 \begin_layout Standard
28003 print information about current frame.
28006 \begin_layout Subsubsection*
28010 \begin_layout Standard
28011 Toggle between C source & assembly source.
28014 \begin_layout Subsubsection*
28015 ! simulator command
28018 \begin_layout Standard
28019 Send the string following '!' to the simulator, the simulator response is
28021 Note the debugger does not interpret the command being sent to the simulator,
28022 so if a command like 'go' is sent the debugger can loose its execution
28023 context and may display incorrect values.
28026 \begin_layout Subsubsection*
28030 \begin_layout Standard
28033 My name is Bobby Brown"
28036 \begin_layout Subsection
28037 Interfacing SDCDB with DDD
28040 \begin_layout Standard
28041 \begin_inset Note Note
28044 \begin_layout Standard
28045 The screenshot was converted from png to eps with:
28046 \begin_inset Quotes sld
28049 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28050 \begin_inset Quotes srd
28053 which produces a pretty compact eps file which is free from compression
28057 \begin_layout Standard
28058 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28059 as this broke the build system on Sourceforge (pdf-file was broken.
28060 pdflatex does not accept eps files).
28068 \begin_layout Standard
28084 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28090 shows a screenshot of a debugging session with DDD
28091 \begin_inset LatexCommand \index{DDD (debugger)}
28095 (Unix only) on a simulated 8032.
28096 The debugging session might not run as smoothly as the screenshot suggests.
28097 The debugger allows setting of breakpoints, displaying and changing variables,
28098 single stepping through C and assembler code.
28101 The source was compiled with
28115 \begin_layout Standard
28127 -debug ddd_example.c
28140 and DDD was invoked with
28147 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28150 \begin_layout Standard
28151 \begin_inset Note Note
28154 \begin_layout Standard
28155 Check that the double quotes or an apostroph within the command line survive
28156 the LyX tool chain.
28157 Previously the apostrophs got slanted in the PDF output so a cut and paste
28166 \begin_layout Subsection
28167 Interfacing SDCDB with XEmacs
28168 \begin_inset LatexCommand \index{XEmacs}
28173 \begin_inset LatexCommand \index{Emacs}
28180 \begin_layout Standard
28181 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28182 sdcdb.el and sdcdbsrc.el.
28183 These two files can be found in the $(prefix)/bin directory after the installat
28185 These files need to be loaded into XEmacs for the interface to work.
28186 This can be done at XEmacs startup time by inserting the following into
28187 your '.xemacs' file (which can be found in your HOME directory):
28193 (load-file sdcdbsrc.el)
28199 .xemacs is a lisp file so the () around the command is REQUIRED.
28200 The files can also be loaded dynamically while XEmacs is running, set the
28201 environment variable 'EMACSLOADPATH' to the installation bin directory
28202 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28203 To start the interface enter the following command:
28217 You will prompted to enter the file name to be debugged.
28222 The command line options that are passed to the simulator directly are
28223 bound to default values in the file sdcdbsrc.el.
28224 The variables are listed below, these values maybe changed as required.
28227 \begin_layout Itemize
28228 sdcdbsrc-cpu-type '51
28231 \begin_layout Itemize
28232 sdcdbsrc-frequency '11059200
28235 \begin_layout Itemize
28236 sdcdbsrc-serial nil
28239 \begin_layout Standard
28240 The following is a list of key mapping for the debugger interface.
28243 \begin_layout Standard
28266 binding\InsetSpace ~
28304 -------\InsetSpace ~
28375 sdcdb-back-from-src\InsetSpace ~
28404 rom-src\InsetSpace ~
28414 SDCDB continue command
28432 sdcdb-step-from-src\InsetSpace ~
28461 hatis-c-sexp\InsetSpace ~
28471 SDCDB ptypecommand for data at
28538 sdcdbsrc-delete\InsetSpace ~
28553 B Delete all breakpoints if no arg
28602 given or delete arg (C-u arg x)
28621 -frame\InsetSpace ~
28636 SDCDB Display current frame if no arg,
28685 given or display frame arg
28753 sdcdbsrc-goto-sdcdb\InsetSpace ~
28763 Goto the SDCDB output buffer
28782 t-c-sexp\InsetSpace ~
28793 SDCDB print command for data at
28860 sdcdbsrc-goto-sdcdb\InsetSpace ~
28871 o the SDCDB output buffer
28889 sdcdbsrc-mode\InsetSpace ~
28905 Toggles Sdcdbsrc mode (turns it
28921 sdcdb-finish-from-src\InsetSpace ~
28929 SDCDB finish command
28963 Set break for line with point
28978 sdcdbsrc-mode\InsetSpace ~
28994 Toggle Sdcdbsrc mode
29010 dbsrc-srcmode\InsetSpace ~
29034 \begin_layout Chapter
29038 \begin_layout Standard
29039 Here are a few guidelines that will help the compiler generate more efficient
29040 code, some of the tips are specific to this compiler others are generally
29041 good programming practice.
29044 \begin_layout Itemize
29045 Use the smallest data type to represent your data-value.
29046 If it is known in advance that the value is going to be less than 256 then
29047 use an 'unsigned char' instead of a 'short' or 'int'.
29048 Please note, that ANSI C requires both signed and unsigned chars to be
29049 promoted to 'signed int'
29050 \begin_inset LatexCommand \index{promotion to signed int}
29055 \begin_inset Marginal
29058 \begin_layout Standard
29067 before doing any operation.
29069 \begin_inset LatexCommand \index{type promotion}
29074 \begin_inset LatexCommand \label{type promotion}
29078 can be omitted, if the result is the same.
29079 The effect of the promotion rules together with the sign-extension is often
29084 \begin_layout Verse
29087 unsigned char uc = 0xfe;
29089 if (uc * uc < 0) /* this is true! */
29102 \begin_layout Standard
29109 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29117 \begin_layout Verse
29120 (unsigned char) -12 / (signed char) -3 = ...
29123 \begin_layout Standard
29124 No, the result is not 4:
29127 \begin_layout Verse
29130 (int) (unsigned char) -12 / (int) (signed char) -3 =
29132 (int) (unsigned char)
29133 0xf4 / (int) (signed char) 0xfd =
29135 (int) 0x00f4 / (int) 0xfffd =
29140 (int) 244 / (int) -3 =
29142 (int) -81 = (int) 0xffaf;
29145 \begin_layout Standard
29146 Don't complain, that gcc gives you a different result.
29147 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29148 Therefore the results are different.
29151 \begin_inset Quotes sld
29155 \begin_inset Quotes srd
29161 \begin_layout Quote
29164 If well-defined overflow characteristics are important and negative values
29165 are not, or if you want to steer clear of sign-extension problems when
29166 manipulating bits or bytes, use one of the corresponding unsigned types.
29167 (Beware when mixing signed and unsigned values in expressions, though.)
29170 character types (especially unsigned char) can be used as "tiny" integers,
29171 doing so is sometimes more trouble than it's worth, due to unpredictable
29172 sign extension and increased code size.
29176 \begin_layout Itemize
29177 Use unsigned when it is known in advance that the value is not going to
29179 This helps especially if you are doing division or multiplication, bit-shifting
29180 or are using an array index.
29183 \begin_layout Itemize
29184 NEVER jump into a LOOP.
29187 \begin_layout Itemize
29188 Declare the variables to be local
29189 \begin_inset LatexCommand \index{local variables}
29193 whenever possible, especially loop control variables (induction).
29196 \begin_layout Itemize
29197 Have a look at the assembly listing to get a
29198 \begin_inset Quotes sld
29202 \begin_inset Quotes srd
29205 for the code generation.
29208 \begin_layout Section
29209 Porting code from or to other compilers
29210 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29217 \begin_layout Itemize
29218 check whether endianness of the compilers differs and adapt where needed.
29221 \begin_layout Itemize
29222 check the device specific header files
29223 \begin_inset LatexCommand \index{Header files}
29228 \begin_inset LatexCommand \index{Include files}
29232 for compiler specific syntax.
29233 Eventually include the file <compiler.h
29234 \begin_inset LatexCommand \index{compiler.h (include file)}
29239 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29243 to allow using common header files.
29246 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29253 \begin_layout Itemize
29254 check whether the startup code contains the correct initialization (watchdog,
29258 \begin_layout Itemize
29259 check whether the sizes of short, int, long match.
29262 \begin_layout Itemize
29263 check if some 16 or 32 bit hardware registers require a specific addressing
29264 order (least significant or most significant byte first) and adapt if needed
29273 relate to time and not to lower/upper memory location here, so this is
29278 the same as endianness).
29281 \begin_layout Itemize
29282 check whether the keyword
29286 is used where needed.
29287 The compilers might differ in their optimization characteristics (as different
29288 versions of the same compiler might also use more clever optimizations
29289 this is good idea anyway).
29291 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29298 \begin_layout Itemize
29299 check that the compilers are not told to supress warnings.
29302 \begin_layout Itemize
29303 check and convert compiler specific extensions (interrupts, memory areas,
29307 \begin_layout Itemize
29308 check for differences in type promotion.
29309 Especially check for math operations on
29318 For the sake of C99 compatibility SDCC will probably promote these to
29322 more often than other compilers.
29323 Eventually insert explicit casts to
29332 Also check that the ~\InsetSpace ~
29334 \begin_inset LatexCommand \index{\~\/ Operator}
29341 \begin_inset LatexCommand \index{bit}
29347 variables, use the !\InsetSpace ~
29350 \begin_inset LatexCommand \ref{type promotion}
29355 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29362 \begin_layout Itemize
29363 check the assembly code generated for interrupt routines (f.e.
29364 for calls to possibly non-reentrant library functions).
29367 \begin_layout Itemize
29368 check whether timing loops result in proper timing (or preferably consider
29369 a rewrite of the code with timer based delays instead).
29372 \begin_layout Itemize
29373 check for differences in printf parameters (some compilers push (va_arg
29374 \begin_inset LatexCommand \index{vararg, va\_arg}
29378 ) char variables as
29382 others push them as
29388 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29395 \begin_layout Itemize
29396 check the resulting memory map
29397 \begin_inset LatexCommand \index{Memory map}
29402 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29403 ly idata, pdata, xdata).
29404 Eventually check if unexpected library functions are included.
29407 \begin_layout Section
29409 \begin_inset LatexCommand \index{Tools}
29413 included in the distribution
29416 \begin_layout Standard
29418 \begin_inset Tabular
29419 <lyxtabular version="3" rows="12" columns="3">
29421 <column alignment="left" valignment="top" leftline="true" width="0pt">
29422 <column alignment="left" valignment="top" leftline="true" width="0pt">
29423 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29424 <row topline="true" bottomline="true">
29425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29428 \begin_layout Standard
29436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29439 \begin_layout Standard
29447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29450 \begin_layout Standard
29459 <row topline="true">
29460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29463 \begin_layout Standard
29465 \begin_inset LatexCommand \index{uCsim}
29474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29477 \begin_layout Standard
29478 Simulator for various architectures
29483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29486 \begin_layout Standard
29493 <row topline="true">
29494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_layout Standard
29503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29506 \begin_layout Standard
29508 \begin_inset LatexCommand \index{Header files}
29513 \begin_inset LatexCommand \index{Include files}
29522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29525 \begin_layout Standard
29526 sdcc/support/scripts
29532 <row topline="true">
29533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29536 \begin_layout Standard
29542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29545 \begin_layout Standard
29546 header file conversion
29551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29554 \begin_layout Standard
29555 sdcc/support/scripts
29561 <row topline="true">
29562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29565 \begin_layout Standard
29571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29574 \begin_layout Standard
29580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29583 \begin_layout Standard
29599 <row topline="true">
29600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29603 \begin_layout Standard
29609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29612 \begin_layout Standard
29618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29621 \begin_layout Standard
29637 <row topline="true">
29638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29641 \begin_layout Standard
29647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29650 \begin_layout Standard
29656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29659 \begin_layout Standard
29675 <row topline="true">
29676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29679 \begin_layout Standard
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29688 \begin_layout Standard
29694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29697 \begin_layout Standard
29713 <row topline="true">
29714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29717 \begin_layout Standard
29723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29726 \begin_layout Standard
29732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29735 \begin_layout Standard
29751 <row topline="true">
29752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29755 \begin_layout Standard
29761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29764 \begin_layout Standard
29770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29773 \begin_layout Standard
29789 <row topline="true">
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29793 \begin_layout Standard
29799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29802 \begin_layout Standard
29808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29811 \begin_layout Standard
29827 <row topline="true" bottomline="true">
29828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29831 \begin_layout Standard
29837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29840 \begin_layout Standard
29842 \begin_inset LatexCommand \index{packihx (tool)}
29851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29854 \begin_layout Standard
29879 \begin_layout Section
29881 \begin_inset LatexCommand \index{Documentation}
29885 included in the distribution
29888 \begin_layout Standard
29890 \begin_inset Tabular
29891 <lyxtabular version="3" rows="10" columns="2">
29893 <column alignment="block" valignment="top" leftline="true" width="40col%">
29894 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29895 <row topline="true" bottomline="true" endhead="true">
29896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29899 \begin_layout Standard
29907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29910 \begin_layout Standard
29913 Filename / Where to get
29919 <row topline="true">
29920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29923 \begin_layout Standard
29924 SDCC Compiler User Guide
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29932 \begin_layout Standard
29933 You're reading it right now
29945 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29955 <row topline="true">
29956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29959 \begin_layout Standard
29965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29968 \begin_layout Standard
29981 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29991 <row topline="true">
29992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29995 \begin_layout Standard
29997 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30002 \begin_inset LatexCommand \index{Assembler documentation}
30009 \begin_inset LatexCommand \index{aslink}
30014 \begin_inset LatexCommand \index{Linker documentation}
30023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30026 \begin_layout Standard
30027 sdcc/as/doc/asxhtm.html
30039 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30049 <row topline="true">
30050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30053 \begin_layout Standard
30054 SDCC regression test
30055 \begin_inset LatexCommand \index{Regression test}
30064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30067 \begin_layout Standard
30068 sdcc/doc/test_suite_spec.pdf
30080 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30090 <row topline="true">
30091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30094 \begin_layout Standard
30100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30103 \begin_layout Standard
30116 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30126 <row topline="true">
30127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30130 \begin_layout Standard
30131 Notes on debugging with SDCDB
30132 \begin_inset LatexCommand \index{SDCDB (debugger)}
30141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30144 \begin_layout Standard
30145 sdcc/debugger/README
30157 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30167 <row topline="true">
30168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30171 \begin_layout Standard
30173 \begin_inset LatexCommand \index{uCsim}
30177 Software simulator for microcontrollers
30182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30185 \begin_layout Standard
30215 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30225 <row topline="true">
30226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30229 \begin_layout Standard
30230 Temporary notes on the pic16
30231 \begin_inset LatexCommand \index{PIC16}
30240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30243 \begin_layout Standard
30244 sdcc/src/pic16/NOTES
30256 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30266 <row topline="true" bottomline="true">
30267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30270 \begin_layout Standard
30271 SDCC internal documentation (debugging file format)
30276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30279 \begin_layout Standard
30309 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30328 \begin_layout Section
30329 Related open source tools
30330 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30335 \begin_inset LatexCommand \index{Related tools}
30342 \begin_layout Standard
30344 \begin_inset Tabular
30345 <lyxtabular version="3" rows="14" columns="3">
30347 <column alignment="left" valignment="top" leftline="true" width="0pt">
30348 <column alignment="block" valignment="top" leftline="true" width="30line%">
30349 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30350 <row topline="true" bottomline="true">
30351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30354 \begin_layout Standard
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30365 \begin_layout Standard
30373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30376 \begin_layout Standard
30385 <row topline="true">
30386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30389 \begin_layout Standard
30391 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30403 \begin_layout Standard
30409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30412 \begin_layout Standard
30413 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30423 <row topline="true">
30424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30427 \begin_layout Standard
30429 \begin_inset LatexCommand \index{gputils (pic tools)}
30438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30441 \begin_layout Standard
30447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30450 \begin_layout Standard
30451 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30461 <row topline="true">
30462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30465 \begin_layout Standard
30471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30474 \begin_layout Standard
30480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30483 \begin_layout Standard
30484 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30494 <row topline="true">
30495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30498 \begin_layout Standard
30504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30507 \begin_layout Standard
30508 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30517 \begin_layout Standard
30518 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30528 <row topline="true">
30529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30532 \begin_layout Standard
30534 \begin_inset LatexCommand \index{indent (source formatting tool)}
30543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30546 \begin_layout Standard
30547 Formats C source - Master of the white spaces
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30555 \begin_layout Standard
30556 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30566 <row topline="true">
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30570 \begin_layout Standard
30572 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30584 \begin_layout Standard
30585 Object file conversion, checksumming, ...
30590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30593 \begin_layout Standard
30594 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30604 <row topline="true">
30605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30608 \begin_layout Standard
30610 \begin_inset LatexCommand \index{objdump (tool)}
30619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30622 \begin_layout Standard
30623 Object file conversion, ...
30628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30631 \begin_layout Standard
30632 Part of binutils (should be there anyway)
30638 <row topline="true">
30639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30642 \begin_layout Standard
30648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30651 \begin_layout Standard
30652 8051 monitor (hex up-/download, single step, disassemble)
30657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30660 \begin_layout Standard
30661 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30671 <row topline="true">
30672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30675 \begin_layout Standard
30677 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30689 \begin_layout Standard
30690 Source code documentation system
30695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30698 \begin_layout Standard
30699 \begin_inset LatexCommand \url{http://www.doxygen.org}
30709 <row topline="true">
30710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30713 \begin_layout Standard
30719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30722 \begin_layout Standard
30723 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30731 \begin_layout Standard
30732 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30742 <row topline="true">
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30746 \begin_layout Standard
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30755 \begin_layout Standard
30756 8051 monitor (hex up-/download, single step, disassemble)
30761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30764 \begin_layout Standard
30765 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30775 <row topline="true">
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30779 \begin_layout Standard
30781 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30793 \begin_layout Standard
30794 Statically checks c sources (see
30795 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30807 \begin_layout Standard
30808 \begin_inset LatexCommand \url{http://www.splint.org}
30818 <row topline="true" bottomline="true">
30819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30822 \begin_layout Standard
30824 \begin_inset LatexCommand \index{DDD (debugger)}
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30836 \begin_layout Standard
30837 Debugger, serves nicely as GUI to SDCDB
30838 \begin_inset LatexCommand \index{SDCDB (debugger)}
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30850 \begin_layout Standard
30851 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30870 \begin_layout Section
30871 Related documentation / recommended reading
30874 \begin_layout Standard
30876 \begin_inset Tabular
30877 <lyxtabular version="3" rows="7" columns="3">
30879 <column alignment="left" valignment="top" leftline="true" width="0pt">
30880 <column alignment="left" valignment="top" leftline="true" width="0">
30881 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30882 <row topline="true" bottomline="true">
30883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30886 \begin_layout Standard
30894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30897 \begin_layout Standard
30905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30908 \begin_layout Standard
30917 <row topline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30921 \begin_layout Standard
30936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30939 \begin_layout Standard
30941 \begin_inset LatexCommand \index{C Reference card}
30950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30953 \begin_layout Standard
30954 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30964 <row topline="true">
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30968 \begin_layout Standard
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30977 \begin_layout Standard
30979 \begin_inset LatexCommand \index{C FAQ}
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30991 \begin_layout Standard
30992 \begin_inset LatexCommand \url{http://www.c-faq.com}
31002 <row topline="true">
31003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31006 \begin_layout Standard
31012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31015 \begin_layout Standard
31016 \begin_inset Quotes sld
31020 \begin_inset Quotes srd
31028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31031 \begin_layout Standard
31034 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31044 <row topline="true">
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31048 \begin_layout Standard
31054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31057 \begin_layout Standard
31058 \begin_inset Quotes sld
31061 Extensions for Embedded C
31062 \begin_inset Quotes srd
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31073 \begin_layout Standard
31076 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31086 <row topline="true">
31087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31090 \begin_layout Standard
31096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31099 \begin_layout Standard
31100 Latest datasheet of target CPU
31105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31108 \begin_layout Standard
31115 <row topline="true" bottomline="true">
31116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31119 \begin_layout Standard
31125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31128 \begin_layout Standard
31129 Revision history of datasheet
31134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31137 \begin_layout Standard
31153 \begin_layout Section
31154 Application notes specifically for SDCC
31157 \begin_layout Standard
31158 SDCC makes no claims about the completeness of this list and about up-to-datenes
31159 s or correctness of the application notes
31160 \begin_inset LatexCommand \index{Application notes}
31167 \begin_layout Standard
31171 \begin_inset Tabular
31172 <lyxtabular version="3" rows="7" columns="3">
31174 <column alignment="block" valignment="top" leftline="true" width="17col%">
31175 <column alignment="block" valignment="top" leftline="true" width="27col%">
31176 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31177 <row topline="true" bottomline="true">
31178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_layout Standard
31190 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31193 \begin_layout Standard
31202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31205 \begin_layout Standard
31215 <row topline="true">
31216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31219 \begin_layout Standard
31227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31230 \begin_layout Standard
31233 Using the SDCC Compiler for the DS80C400
31234 \begin_inset LatexCommand \index{DS80C400}
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31246 \begin_layout Standard
31249 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31259 <row topline="true">
31260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31263 \begin_layout Standard
31271 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31274 \begin_layout Standard
31277 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31278 \begin_inset LatexCommand \index{DS89C4x0}
31282 Family of Microcontrollers
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31290 \begin_layout Standard
31293 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31303 <row topline="true">
31304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31307 \begin_layout Standard
31310 Silicon Laboratories / Cygnal
31315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31318 \begin_layout Standard
31321 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31322 \begin_inset LatexCommand \index{IDE}
31331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31334 \begin_layout Standard
31337 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31347 <row topline="true">
31348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31351 \begin_layout Standard
31354 Ramtron / Goal Semiconductor
31359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_layout Standard
31365 Interfacing SDCC to Syn and Textpad
31370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31373 \begin_layout Standard
31376 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31386 <row topline="true">
31387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31390 \begin_layout Standard
31393 Ramtron / Goal Semiconductor
31398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31401 \begin_layout Standard
31404 Installing and Configuring SDCC and Crimson Editor
31409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31412 \begin_layout Standard
31415 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31425 <row topline="true" bottomline="true">
31426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31429 \begin_layout Standard
31437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31440 \begin_layout Standard
31443 MSC12xx Programming with SDCC
31448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31451 \begin_layout Standard
31454 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31471 \begin_layout Section
31475 \begin_layout Standard
31476 Some questions answered, some pointers given - it might be time to in turn
31484 \begin_layout Itemize
31485 can you solve your project with the selected microcontroller? Would you
31486 find out early or rather late that your target is too small/slow/whatever?
31487 Can you switch to a slightly better device if it doesn't fit?
31490 \begin_layout Itemize
31491 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31492 and/or another programming language be more adequate? Would an operating
31493 system on the target device help?
31496 \begin_layout Itemize
31497 if you solved the problem, will the marketing department be happy?
31500 \begin_layout Itemize
31501 if the marketing department is happy, will customers be happy?
31504 \begin_layout Itemize
31505 if you're the project manager, marketing department and maybe even the customer
31506 in one person, have you tried to see the project from the outside?
31509 \begin_layout Itemize
31510 is the project done if you think it is done? Or is just that other interface/pro
31511 tocol/feature/configuration/option missing? How about website, manual(s),
31512 internationali(z|s)ation, packaging, labels, 2nd source for components,
31513 electromagnetic compatability/interference, documentation for production,
31514 production test software, update mechanism, patent issues?
31517 \begin_layout Itemize
31518 is your project adequately positioned in that magic triangle: fame, fortune,
31522 \begin_layout Standard
31523 Maybe not all answers to these questions are known and some answers may
31528 , nevertheless knowing these questions may help you to avoid burnout
31532 \begin_layout Standard
31533 burnout is bad for electronic devices, programmers and motorcycle tyres
31539 Chances are you didn't want to hear some of them...
31542 \begin_layout Chapter
31544 \begin_inset LatexCommand \index{Support}
31551 \begin_layout Standard
31552 SDCC has grown to be a large project.
31553 The compiler alone (without the preprocessor, assembler and linker) is
31554 well over 150,000 lines of code (blank stripped).
31555 The open source nature of this project is a key to its continued growth
31557 You gain the benefit and support of many active software developers and
31559 Is SDCC perfect? No, that's why we need your help.
31560 The developers take pride in fixing reported bugs.
31561 You can help by reporting the bugs and helping other SDCC users.
31562 There are lots of ways to contribute, and we encourage you to take part
31563 in making SDCC a great software package.
31567 \begin_layout Standard
31568 The SDCC project is hosted on the SDCC sourceforge site at
31569 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31574 You'll find the complete set of mailing lists
31575 \begin_inset LatexCommand \index{Mailing list(s)}
31579 , forums, bug reporting system, patch submission
31580 \begin_inset LatexCommand \index{Patch submission}
31585 \begin_inset LatexCommand \index{download}
31589 area and Subversion code repository
31590 \begin_inset LatexCommand \index{Subversion code repository}
31597 \begin_layout Section
31599 \begin_inset LatexCommand \index{Bug reporting}
31604 \begin_inset LatexCommand \index{Reporting bugs}
31611 \begin_layout Standard
31612 The recommended way of reporting bugs is using the infrastructure of the
31614 You can follow the status of bug reports there and have an overview about
31618 \begin_layout Standard
31619 Bug reports are automatically forwarded to the developer mailing list and
31620 will be fixed ASAP.
31621 When reporting a bug, it is very useful to include a small test program
31622 (the smaller the better) which reproduces the problem.
31623 If you can isolate the problem by looking at the generated assembly code,
31624 this can be very helpful.
31625 Compiling your program with the -
31629 \begin_layout Standard
31639 \begin_inset LatexCommand \index{-\/-dumpall}
31643 option can sometimes be useful in locating optimization problems.
31644 When reporting a bug please make sure you:
31647 \begin_layout Enumerate
31648 Attach the code you are compiling with SDCC.
31652 \begin_layout Enumerate
31653 Specify the exact command you use to run SDCC, or attach your Makefile.
31657 \begin_layout Enumerate
31658 Specify the SDCC version (type "
31664 "), your platform, and operating system.
31668 \begin_layout Enumerate
31669 Provide an exact copy of any error message or incorrect output.
31673 \begin_layout Enumerate
31674 Put something meaningful in the subject of your message.
31677 \begin_layout Standard
31678 Please attempt to include these 5 important parts, as applicable, in all
31679 requests for support or when reporting any problems or bugs with SDCC.
31680 Though this will make your message lengthy, it will greatly improve your
31681 chance that SDCC users and developers will be able to help you.
31682 Some SDCC developers are frustrated by bug reports without code provided
31683 that they can use to reproduce and ultimately fix the problem, so please
31684 be sure to provide sample code if you are reporting a bug!
31687 \begin_layout Standard
31688 Please have a short check that you are using a recent version of SDCC and
31689 the bug is not yet known.
31690 This is the link for reporting bugs:
31691 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31696 With SDCC on average having more than 200 downloads
31697 \begin_inset LatexCommand \index{download}
31701 on sourceforge per day
31705 \begin_layout Standard
31706 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31707 between 2002 and 2005.
31708 This does not include other methods of distribution.
31713 there must be some users.
31714 So it's not exactly easy to find a new bug.
31715 If you find one we need it:
31717 reporting bugs is good
31722 \begin_layout Section
31723 Requesting Features
31724 \begin_inset LatexCommand \label{sub:Requesting-Features}
31729 \begin_inset LatexCommand \index{Feature request}
31734 \begin_inset LatexCommand \index{Requesting features}
31741 \begin_layout Standard
31742 Like bug reports feature requests are forwarded to the developer mailing
31744 This is the link for requesting features:
31745 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31752 \begin_layout Section
31756 \begin_layout Standard
31757 Like bug reports contributed patches are forwarded to the developer mailing
31759 This is the link for submitting patches
31760 \begin_inset LatexCommand \index{Patch submission}
31765 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31772 \begin_layout Standard
31773 You need to specify some parameters to the
31777 command for the patches to be useful.
31778 If you modified more than one file a patch created f.e.
31783 \begin_inset Quotes sld
31786 diff -Naur unmodified_directory modified_directory >my_changes.patch
31787 \begin_inset Quotes srd
31793 will be fine, otherwise
31797 \begin_inset Quotes sld
31800 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31801 \begin_inset Quotes srd
31811 \begin_layout Section
31815 \begin_layout Standard
31816 These links should take you directly to the
31817 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31825 \begin_layout Standard
31826 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31827 automated messages (mid 2003)
31833 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31838 \begin_inset LatexCommand \index{Mailing list(s)}
31842 and forums are archived and searchable so if you are lucky someone already
31843 had a similar problem.
31844 While mails to the lists themselves are delivered promptly their web front
31845 end on sourceforge sometimes shows a severe time lag (up to several weeks),
31846 if you're seriously using SDCC please consider subscribing to the lists.
31849 \begin_layout Section
31853 \begin_layout Standard
31854 You can follow the status of the Subversion version
31855 \begin_inset LatexCommand \index{version}
31859 of SDCC by watching the Changelog
31860 \begin_inset LatexCommand \index{Changelog}
31864 in the Subversion repository
31867 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31874 \begin_layout Section
31875 Subversion Source Code Repository
31878 \begin_layout Standard
31885 or the filenames of the snapshot versions of SDCC include date and its
31887 \begin_inset LatexCommand \index{Subversion code repository}
31892 Subversion allows to download the source of recent or previous versions
31894 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31898 (by number or by date).
31899 An on-line source code browser and detailled instructions are also available
31901 SDCC versions starting from 1999 up to now are available (currently the
31902 versions prior to the conversion from cvs
31903 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31907 to Subversion (April 2006) are either by accessible by Subversion or by
31911 \begin_layout Section
31913 \begin_inset LatexCommand \index{Release policy}
31920 \begin_layout Standard
31921 Historically there often were long delays between official releases and
31922 the sourceforge download area tends to get not updated at all.
31923 Excuses in the past might have referred to problems with live range analysis,
31924 but as this was fixed a while ago, the current problem is that another
31925 excuse has to be found.
31926 Kidding aside, we have to get better there! On the other hand there are
31927 daily snapshots available at
31928 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31932 , and you can always build the very last version (hopefully with many bugs
31933 fixed, and features added) from the source code available at
31934 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31940 \begin_inset LatexCommand \index{wiki}
31945 \begin_inset LatexCommand \index{Release wiki}
31950 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31954 also holds some information about past and future releases.
31957 \begin_layout Section
31959 \begin_inset LatexCommand \index{Examples}
31966 \begin_layout Standard
31967 You'll find some small examples in the directory
31969 sdcc/device/examples/.
31972 More examples and libraries are available at
31974 The SDCC Open Knowledge Resource
31975 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31982 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31989 \begin_layout Standard
31990 \begin_inset Note Note
31993 \begin_layout Standard
31994 I did insert a reference to Paul's web site here although it seems rather
31995 dedicated to a specific 8032 board (I think it's okay because it f.e.
31996 shows LCD/Harddisc interface and has a free 8051 monitor.
31997 Independent 8032 board vendors face hard competition of heavily subsidized
31998 development boards anyway).
32001 \begin_layout Standard
32002 Maybe we should include some links to real world applications.
32003 Preferably pointer to pointers (one for each architecture) so this stays
32012 \begin_layout Section
32014 \begin_inset LatexCommand \label{sec:Quality-control}
32019 \begin_inset LatexCommand \index{Quality control}
32026 \begin_layout Standard
32027 The compiler is passed through snaphot build compile and build checks.
32033 \begin_inset LatexCommand \index{Regression test}
32037 check that SDCC itself compiles flawlessly on several host platforms (i386,
32038 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32039 the quality of the code generated by SDCC by running the code for several
32040 target platforms through simulators.
32041 The regression test suite comprises more than 100 files which expand to
32042 more than 500 test cases which include more than 4500 tests.
32043 The results of these tests are published daily on SDCC's snapshot page
32044 (click on the red or green symbols on the right side of
32045 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32052 \begin_layout Standard
32053 There is a separate document
32056 \begin_inset LatexCommand \index{Test suite}
32063 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32067 about the regression test suite.
32070 \begin_layout Standard
32071 You'll find the test code in the directory
32073 sdcc/support/regression
32076 You can run these tests manually by running
32080 in this directory (or f.e.
32085 \begin_inset Quotes sld
32089 \begin_inset Quotes srd
32095 if you don't want to run the complete tests).
32096 The test code might also be interesting if you want to look for examples
32097 \begin_inset LatexCommand \index{Examples}
32101 checking corner cases of SDCC or if you plan to submit patches
32102 \begin_inset LatexCommand \index{Patch submission}
32109 \begin_layout Standard
32110 The 14bit pic port uses a different set of regression tests
32111 \begin_inset LatexCommand \index{Regression test (PIC14)}
32115 , you'll find them in the directory
32117 sdcc/src/regression
32122 \begin_layout Section
32123 Use of SDCC in Education
32126 \begin_layout Standard
32135 \begin_layout Standard
32136 the phrase "use in education" might evoke the association "
32140 fit for use in education".
32141 This connotation is not intended but nevertheless risked as the licensing
32142 of SDCC makes it difficult to offer educational discounts
32148 If your rationales are to:
32151 \begin_layout Enumerate
32152 give students a chance to understand the
32156 steps of code generation
32159 \begin_layout Enumerate
32160 have a curriculum that can be extended for years.
32161 Then you could use an fpga board as target and your curriculum will seamlessly
32162 extend from logic synthesis (
32163 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32168 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32172 ), over assembly programming, to C to FPGA compilers (
32173 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32180 \begin_layout Enumerate
32181 be able to insert excursions about skills like using a revision control
32182 system, submitting/applying patches, using a type-setting (as opposed to
32183 word-processing) engine LyX/LaTeX, using
32184 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32189 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32193 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32194 Source Software, CPU simulation, compiler regression tests
32195 \begin_inset LatexCommand \index{Regression test}
32202 And if there should be a shortage of ideas then you can always point students
32203 to the ever-growing feature request list
32204 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32211 \begin_layout Enumerate
32212 not tie students to a specific host platform and instead allow them to use
32217 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32219 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32226 \begin_layout Enumerate
32227 not encourage students to use illegal copies of educational software
32230 \begin_layout Enumerate
32231 be immune to licensing/availability/price changes of the chosen tool chain
32234 \begin_layout Enumerate
32235 be able to change to a new target platform without having to adopt a new
32239 \begin_layout Enumerate
32240 have complete control over and insight into the tool chain
32243 \begin_layout Enumerate
32244 make your students aware about the pros and cons of open source software
32248 \begin_layout Enumerate
32249 give back to the public as you are probably at least partially publically
32253 \begin_layout Enumerate
32254 give students a chance to publically prove their skills and to possibly
32255 see a world wide impact
32258 \begin_layout Standard
32259 then SDCC is probably among the first choices.
32260 Well, probably SDCC might be the only choice.
32265 \begin_layout Chapter
32266 SDCC Technical Data
32269 \begin_layout Section
32271 \begin_inset LatexCommand \index{Optimizations}
32278 \begin_layout Standard
32279 SDCC performs a host of standard optimizations in addition to some MCU specific
32284 \begin_layout Subsection
32285 Sub-expression Elimination
32286 \begin_inset LatexCommand \index{Subexpression elimination}
32293 \begin_layout Standard
32294 The compiler does local and
32313 \begin_layout Verse
32321 \begin_layout Standard
32322 will be translated to
32325 \begin_layout Verse
32335 \begin_layout Standard
32336 Some subexpressions are not as obvious as the above example, e.g.:
32339 \begin_layout Verse
32347 \begin_layout Standard
32348 In this case the address arithmetic a->b[i] will be computed only once;
32349 the equivalent code in C would be.
32352 \begin_layout Verse
32362 \begin_layout Standard
32363 The compiler will try to keep these temporary variables in registers.
32366 \begin_layout Subsection
32367 Dead-Code Elimination
32368 \begin_inset LatexCommand \index{Dead-code elimination}
32375 \begin_layout Verse
32390 i = 1; \InsetSpace ~
32399 global = 1;\InsetSpace ~
32413 global = 3;\InsetSpace ~
32419 \begin_layout Standard
32423 \begin_layout Verse
32439 \begin_layout Subsection
32441 \begin_inset LatexCommand \index{Copy propagation}
32448 \begin_layout Verse
32472 \begin_layout Standard
32476 \begin_layout Verse
32500 \begin_layout Standard
32501 Note: the dead stores created by this copy propagation will be eliminated
32502 by dead-code elimination.
32505 \begin_layout Subsection
32507 \begin_inset LatexCommand \index{Loop optimization}
32512 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32519 \begin_layout Standard
32520 Two types of loop optimizations are done by SDCC
32528 of loop induction variables.
32529 In addition to the strength reduction the optimizer marks the induction
32530 variables and the register allocator tries to keep the induction variables
32531 in registers for the duration of the loop.
32532 Because of this preference of the register allocator
32533 \begin_inset LatexCommand \index{Register allocation}
32537 , loop induction optimization causes an increase in register pressure, which
32538 may cause unwanted spilling of other temporary variables into the stack
32539 \begin_inset LatexCommand \index{stack}
32544 The compiler will generate a warning message when it is forced to allocate
32545 extra space either on the stack or data space.
32546 If this extra space allocation is undesirable then induction optimization
32547 can be eliminated either for the entire source file (with -
32551 \begin_layout Standard
32560 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32562 \begin_inset LatexCommand \index{\#pragma noinduction}
32573 \begin_layout Verse
32576 for (i = 0 ; i < 100 ; i ++)
32585 \begin_layout Standard
32589 \begin_layout Verse
32594 for (i = 0; i < 100; i++)
32603 \begin_layout Standard
32604 As mentioned previously some loop invariants are not as apparent, all static
32605 address computations are also moved out of the loop.
32610 \begin_inset LatexCommand \index{Strength reduction}
32614 , this optimization substitutes an expression by a cheaper expression:
32617 \begin_layout Verse
32620 for (i=0;i < 100; i++)
32629 \begin_layout Standard
32633 \begin_layout Verse
32640 for (i=0;i< 100;i++) {
32646 ar[itemp1] = itemp2;
32664 \begin_layout Standard
32665 The more expensive multiplication
32666 \begin_inset LatexCommand \index{Multiplication}
32670 is changed to a less expensive addition.
32673 \begin_layout Subsection
32675 \begin_inset LatexCommand \index{Loop reversing}
32682 \begin_layout Standard
32683 This optimization is done to reduce the overhead of checking loop boundaries
32684 for every iteration.
32685 Some simple loops can be reversed and implemented using a
32686 \begin_inset Quotes eld
32689 decrement and jump if not zero
32690 \begin_inset Quotes erd
32694 SDCC checks for the following criterion to determine if a loop is reversible
32695 (note: more sophisticated compilers use data-dependency analysis to make
32696 this determination, SDCC uses a more simple minded analysis).
32699 \begin_layout Itemize
32700 The 'for' loop is of the form
32706 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32716 \begin_layout Itemize
32717 The <for body> does not contain
32718 \begin_inset Quotes eld
32722 \begin_inset Quotes erd
32726 \begin_inset Quotes erd
32732 \begin_layout Itemize
32733 All goto's are contained within the loop.
32736 \begin_layout Itemize
32737 No function calls within the loop.
32740 \begin_layout Itemize
32741 The loop control variable <sym> is not assigned any value within the loop
32744 \begin_layout Itemize
32745 The loop control variable does NOT participate in any arithmetic operation
32749 \begin_layout Itemize
32750 There are NO switch statements in the loop.
32753 \begin_layout Subsection
32754 Algebraic Simplifications
32757 \begin_layout Standard
32758 SDCC does numerous algebraic simplifications, the following is a small sub-set
32759 of these optimizations.
32762 \begin_layout Verse
32765 i = j + 0;\InsetSpace ~
32769 /* changed to: */\InsetSpace ~
32775 i /= 2;\InsetSpace ~
32782 /* changed to: */\InsetSpace ~
32789 = j - j;\InsetSpace ~
32793 /* changed to: */\InsetSpace ~
32799 i = j / 1;\InsetSpace ~
32803 /* changed to: */\InsetSpace ~
32810 \begin_layout Standard
32811 Note the subexpressions
32812 \begin_inset LatexCommand \index{Subexpression}
32816 given above are generally introduced by macro expansions or as a result
32817 of copy/constant propagation.
32820 \begin_layout Subsection
32821 'switch' Statements
32822 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32827 \begin_inset LatexCommand \index{switch statement}
32834 \begin_layout Standard
32835 SDCC can optimize switch statements to jump tables
32836 \begin_inset LatexCommand \index{jump tables}
32841 It makes the decision based on an estimate of the generated code size.
32842 SDCC is quite liberal in the requirements for jump table generation:
32845 \begin_layout Itemize
32846 The labels need not be in order, and the starting number need not be one
32847 or zero, the case labels are in numerical sequence or not too many case
32848 labels are missing.
32852 \begin_layout Verse
32855 switch(i) {\InsetSpace ~
32886 case 4: ...\InsetSpace ~
32918 case 5: ...\InsetSpace ~
32950 case 3: ...\InsetSpace ~
32981 case 6: ...\InsetSpace ~
33013 case 7: ...\InsetSpace ~
33045 case 8: ...\InsetSpace ~
33077 case 9: ...\InsetSpace ~
33109 case 10: ...\InsetSpace ~
33140 case 11: ...\InsetSpace ~
33207 \begin_layout Standard
33208 Both the above switch statements will be implemented using a jump-table.
33209 The example to the right side is slightly more efficient as the check for
33210 the lower boundary of the jump-table is not needed.
33214 \begin_layout Itemize
33215 The number of case labels is not larger than supported by the target architectur
33219 \begin_layout Itemize
33220 If the case labels are not in numerical sequence ('gaps' between cases)
33221 SDCC checks whether a jump table with additionally inserted dummy cases
33222 is still attractive.
33226 \begin_layout Itemize
33227 If the starting number is not zero and a check for the lower boundary of
33228 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33233 \begin_layout Standard
33234 Switch statements which have large gaps in the numeric sequence or those
33235 that have too many case labels can be split into more than one switch statement
33236 for efficient code generation, e.g.:
33239 \begin_layout Verse
33317 \begin_layout Standard
33318 If the above switch statement is broken down into two switch statements
33321 \begin_layout Verse
33364 \begin_layout Standard
33368 \begin_layout Verse
33411 \begin_layout Standard
33412 then both the switch statements will be implemented using jump-tables whereas
33413 the unmodified switch statement will not be.
33416 \begin_layout Standard
33417 \begin_inset Note Note
33420 \begin_layout Standard
33421 There might be reasons which SDCC cannot know about to either favour or
33422 not favour jump tables.
33423 If the target system has to be as quick for the last switch case as for
33424 the first (pro jump table), or if the switch argument is known to be zero
33425 in the majority of the cases (contra jump table).
33433 \begin_layout Standard
33434 The pragma nojtbound
33435 \begin_inset LatexCommand \index{\#pragma nojtbound}
33439 can be used to turn off checking the
33452 It has no effect if a default label is supplied.
33453 Use of this pragma is dangerous: if the switch
33454 \begin_inset LatexCommand \index{switch statement}
33458 argument is not matched by a case statement the processor will happily
33462 \begin_layout Subsection
33463 Bit-shifting Operations
33464 \begin_inset LatexCommand \index{Bit shifting}
33471 \begin_layout Standard
33472 Bit shifting is one of the most frequently used operation in embedded programmin
33474 SDCC tries to implement bit-shift operations in the most efficient way
33478 \begin_layout Verse
33491 \begin_layout Standard
33492 generates the following code:
33495 \begin_layout Verse
33510 \begin_layout Standard
33511 In general SDCC will never setup a loop if the shift count is known.
33515 \begin_layout Verse
33528 \begin_layout Standard
33532 \begin_layout Verse
33556 \begin_layout Subsection
33558 \begin_inset LatexCommand \index{Bit rotation}
33565 \begin_layout Standard
33566 A special case of the bit-shift operation is bit rotation
33567 \begin_inset LatexCommand \index{rotating bits}
33571 , SDCC recognizes the following expression to be a left bit-rotation:
33574 \begin_layout Verse
33582 char i;\InsetSpace ~
33593 /* unsigned is needed for rotation */
33598 i = ((i << 1) | (i >> 7));
33607 \begin_layout Standard
33608 will generate the following code:
33611 \begin_layout Verse
33628 \begin_layout Standard
33629 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33630 ns of this case will also be recognized as bit-rotation, i.e.:
33633 \begin_layout Verse
33636 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33639 \begin_layout Subsection
33640 Nibble and Byte Swapping
33643 \begin_layout Standard
33644 Other special cases of the bit-shift operations are nibble or byte swapping
33645 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33649 , SDCC recognizes the following expressions:
33652 \begin_layout Verse
33673 i = ((i << 4) | (i >> 4));
33679 j = ((j << 8) | (j >> 8));
33682 \begin_layout Standard
33683 and generates a swap instruction for the nibble swapping
33684 \begin_inset LatexCommand \index{Nibble swapping}
33688 or move instructions for the byte swapping
33689 \begin_inset LatexCommand \index{Byte swapping}
33695 \begin_inset Quotes sld
33699 \begin_inset Quotes srd
33702 example can be used to convert from little to big-endian or vice versa.
33703 If you want to change the endianness of a
33707 integer you have to cast to
33714 \begin_layout Standard
33715 Note that SDCC stores numbers in little-endian
33719 \begin_layout Standard
33720 Usually 8-bit processors don't care much about endianness.
33721 This is not the case for the standard 8051 which only has an instruction
33727 \begin_inset LatexCommand \index{DPTR}
33735 so little-endian is the more efficient byte order.
33741 \begin_inset LatexCommand \index{little-endian}
33746 \begin_inset LatexCommand \index{Endianness}
33751 lowest order first).
33754 \begin_layout Subsection
33756 \begin_inset LatexCommand \index{Highest Order Bit}
33761 \begin_inset LatexCommand \index{Any Order Bit}
33768 \begin_layout Standard
33769 It is frequently required to obtain the highest order bit of an integral
33770 type (long, int, short or char types).
33771 Also obtaining any other order bit is not uncommon.
33772 SDCC recognizes the following expressions to yield the highest order bit
33773 and generates optimized code for it, e.g.:
33776 \begin_layout Verse
33787 unsigned char hob1, aob1;
33791 bit hob2, hob3, aob2,
33801 hob1 = (gint >> 15) & 1;
33805 hob2 = (gint >> 15) & 1;
33809 hob3 = gint & 0x8000;
33814 aob1 = (gint >> 9) & 1;
33818 aob2 = (gint >> 8) & 1;
33822 aob3 = gint & 0x0800;
33832 \begin_layout Standard
33833 will generate the following code:
33836 \begin_layout Verse
33867 000A E5*01\InsetSpace ~
33894 000C 23\InsetSpace ~
33925 000D 54 01\InsetSpace ~
33953 000F F5*02\InsetSpace ~
34008 0011 E5*01\InsetSpace ~
34036 0013 33\InsetSpace ~
34066 0014 92*00\InsetSpace ~
34122 0016 E5*01\InsetSpace ~
34149 0018 33\InsetSpace ~
34179 0019 92*01\InsetSpace ~
34235 001B E5*01\InsetSpace ~
34294 001E 54 01\InsetSpace ~
34321 0020 F5*03\InsetSpace ~
34377 0022 E5*01\InsetSpace ~
34404 0024 13\InsetSpace ~
34434 0025 92*02\InsetSpace ~
34490 0027 E5*01\InsetSpace ~
34545 002B 92*03\InsetSpace ~
34573 \begin_layout Standard
34574 Other variations of these cases however will
34579 They are standard C expressions, so I heartily recommend these be the only
34580 way to get the highest order bit, (it is portable).
34581 Of course it will be recognized even if it is embedded in other expressions,
34585 \begin_layout Verse
34588 xyz = gint + ((gint >> 15) & 1);
34591 \begin_layout Standard
34592 will still be recognized.
34595 \begin_layout Subsection
34597 \begin_inset LatexCommand \index{Higher Order Byte}
34601 / Higher Order Word
34602 \begin_inset LatexCommand \index{Higher Order Word}
34609 \begin_layout Standard
34610 It is also frequently required to obtain a higher order byte or word of
34611 a larger integral type (long, int or short types).
34612 SDCC recognizes the following expressions to yield the higher order byte
34613 or word and generates optimized code for it, e.g.:
34616 \begin_layout Verse
34621 unsigned long int glong;
34629 unsigned char hob1,
34634 unsigned int how1, how2;
34643 hob1 = (gint >> 8) & 0xFF;
34647 hob2 = glong >> 24;
34651 how1 = (glong >> 16) & 0xFFFF;
34666 \begin_layout Standard
34667 will generate the following code:
34670 \begin_layout Verse
34701 0037 85*01*06\InsetSpace ~
34723 _foo_hob1_1_1,(_gint + 1)
34754 003A 85*05*07\InsetSpace ~
34776 _foo_hob2_1_1,(_glong + 3)
34806 003D 85*04*08\InsetSpace ~
34829 _foo_how1_1_1,(_glong + 2)
34831 0040 85*05*09\InsetSpace ~
34856 0043 85*03*0A\InsetSpace ~
34878 _foo_how2_1_1,(_glong + 1)
34880 0046 85*04*0B\InsetSpace ~
34903 (_foo_how2_1_1 + 1),(_glong + 2)
34906 \begin_layout Standard
34907 Again, variations of these cases may
34912 They are standard C expressions, so I heartily recommend these be the only
34913 way to get the higher order byte/word, (it is portable).
34914 Of course it will be recognized even if it is embedded in other expressions,
34918 \begin_layout Verse
34921 xyz = gint + ((gint >> 8) & 0xFF);
34924 \begin_layout Standard
34925 will still be recognized.
34928 \begin_layout Subsection
34930 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34935 \begin_inset LatexCommand \index{Peephole optimizer}
34942 \begin_layout Standard
34943 The compiler uses a rule based, pattern matching and re-writing mechanism
34944 for peep-hole optimization.
34949 a peep-hole optimizer by Christopher W.
34950 Fraser (cwfraser\InsetSpace ~
34953 A default set of rules are compiled into the compiler, additional rules
34954 may be added with the
34960 \begin_layout Standard
34970 \begin_inset LatexCommand \index{-\/-peep-file}
34977 The rule language is best illustrated with examples.
34980 \begin_layout Verse
35002 \begin_layout Standard
35003 The above rule will change the following assembly
35004 \begin_inset LatexCommand \index{Assembler routines}
35011 \begin_layout Verse
35019 \begin_layout Standard
35023 \begin_layout Verse
35029 \begin_layout Standard
35030 Note: All occurrences of a
35034 (pattern variable) must denote the same string.
35035 With the above rule, the assembly sequence:
35038 \begin_layout Verse
35046 \begin_layout Standard
35047 will remain unmodified.
35051 Other special case optimizations may be added by the
35058 \begin_layout Standard
35071 some variants of the 8051 MCU
35072 \begin_inset LatexCommand \index{MCS51 variants}
35085 The following two rules will change all
35102 \begin_layout Verse
35105 replace { lcall %1 } by { acall %1 }
35107 replace { ljmp %1 } by { ajmp %1 }
35110 \begin_layout Standard
35113 inline-assembler code
35115 is also passed through the peep hole optimizer, thus the peephole optimizer
35116 can also be used as an assembly level macro expander.
35117 The rules themselves are MCU dependent whereas the rule language infra-structur
35118 e is MCU independent.
35119 Peephole optimization rules for other MCU can be easily programmed using
35124 The syntax for a rule is as follows:
35127 \begin_layout Verse
35130 rule := replace [ restart ] '{' <assembly sequence> '
35168 <assembly sequence> '
35186 '}' [if <functionName> ] '
35191 \begin_layout Standard
35192 <assembly sequence> := assembly instruction (each instruction including
35193 labels must be on a separate line).
35197 The optimizer will apply to the rules
35198 one by one from the top in the sequence of their appearance, it will terminate
35199 when all rules are exhausted.
35200 If the 'restart' option is specified, then the optimizer will start matching
35201 the rules again from the top, this option for a rule is expensive (performance)
35202 , it is intended to be used in situations where a transformation will trigger
35203 the same rule again.
35204 An example of this (not a good one, it has side effects) is the following
35208 \begin_layout Verse
35228 \begin_layout Standard
35229 Note that the replace pattern cannot be a blank, but can be a comment line.
35230 Without the 'restart' option only the innermost 'pop' 'push' pair would
35231 be eliminated, i.e.:
35234 \begin_layout Verse
35246 \begin_layout Standard
35250 \begin_layout Verse
35260 \begin_layout Standard
35265 the restart option the rule will be applied again to the resulting code
35266 and then all the pop-push pairs will be eliminated to yield:
35269 \begin_layout Verse
35277 \begin_layout Standard
35278 A conditional function can be attached to a rule.
35279 Attaching rules are somewhat more involved, let me illustrate this with
35283 \begin_layout Verse
35307 \begin_layout Standard
35308 The optimizer does a look-up of a function name table defined in function
35313 in the source file SDCCpeeph.c, with the name
35318 If it finds a corresponding entry the function is called.
35319 Note there can be no parameters specified for these functions, in this
35324 is crucial, since the function
35328 expects to find the label in that particular variable (the hash table containin
35329 g the variable bindings is passed as a parameter).
35330 If you want to code more such functions, take a close look at the function
35331 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35332 Currently implemented are
35334 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35335 24bitMode, portIsDS390, 24bitModeAndPortDS390
35344 \begin_layout Standard
35345 I know this whole thing is a little kludgey, but maybe some day we will
35346 have some better means.
35347 If you are looking at this file, you will see the default rules that are
35348 compiled into the compiler, you can add your own rules in the default set
35349 there if you get tired of specifying the -
35353 \begin_layout Standard
35365 \begin_layout Section
35367 \begin_inset LatexCommand \index{ANSI-compliance}
35372 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35379 \begin_layout Standard
35380 The latest publically available version of the standard
35382 ISO/IEC 9899 - Programming languages - C
35384 should be available at:
35385 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35394 \begin_layout Standard
35395 Deviations from the compliance:
35398 \begin_layout Itemize
35399 functions are not reentrant
35400 \begin_inset LatexCommand \index{reentrant}
35404 unless explicitly declared as such or the
35410 \begin_layout Standard
35420 \begin_inset LatexCommand \index{-\/-stack-auto}
35426 command line option is specified.
35429 \begin_layout Itemize
35431 \begin_inset LatexCommand \index{struct}
35436 \begin_inset LatexCommand \index{union}
35440 cannot be assigned values directly, cannot be passed as function parameters
35441 or assigned to each other and cannot be a return value
35442 \begin_inset LatexCommand \index{return value}
35446 from a function, e.g.:
35450 \begin_layout Verse
35473 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35492 s parms) /* invalid in SDCC although allowed in ANSI */
35514 return rets; /* is invalid in SDCC although allowed in ANSI */
35520 \begin_layout Itemize
35521 initialization of structure arrays must be fully braced.
35525 \begin_layout Verse
35528 struct s { char x } a[] = {1, 2};\InsetSpace ~
35533 /* invalid in SDCC */
35536 } a[] = {{1}, {2}}; /* OK */
35540 \begin_layout Itemize
35542 \begin_inset LatexCommand \index{long long (not supported)}
35547 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35554 \begin_layout Itemize
35556 \begin_inset LatexCommand \index{double (not supported)}
35560 ' precision floating point
35561 \begin_inset LatexCommand \index{Floating point support}
35568 \begin_layout Itemize
35570 \begin_inset LatexCommand \index{K\&R style}
35574 function declarations are NOT allowed.
35578 \begin_layout Verse
35581 foo(i,j) /* this old style of function declarations */
35583 int i,j; /* are valid
35584 in ANSI but not valid in SDCC */
35599 \begin_layout Itemize
35600 Most enhancements in C99 are not supported, f.e.:
35604 \begin_layout Verse
35609 \begin_inset LatexCommand \index{inline (not supported)}
35615 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35621 can be used as a work around */
35629 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35633 \begin_layout Itemize
35634 Certain words that are valid identifiers in the standard may be reserved
35635 words in SDCC unless the
35641 \begin_layout Standard
35651 \begin_inset LatexCommand \index{-\/-std-c89}
35659 \begin_layout Standard
35669 \begin_inset LatexCommand \index{-\/-std-c99}
35675 command line options are used.
35676 These may include (depending on the selected processor): 'at', 'banked',
35677 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35678 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35679 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35681 Compliant equivalents of these keywords are always available in a form
35682 that begin with two underscores
35683 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35688 '__data' instead of 'data'.
35691 \begin_layout Section
35692 Cyclomatic Complexity
35693 \begin_inset LatexCommand \index{Cyclomatic complexity}
35700 \begin_layout Standard
35701 Cyclomatic complexity of a function is defined as the number of independent
35702 paths the program can take during execution of the function.
35703 This is an important number since it defines the number test cases you
35704 have to generate to validate the function.
35705 The accepted industry standard for complexity number is 10, if the cyclomatic
35706 complexity reported by SDCC exceeds 10 you should think about simplification
35707 of the function logic.
35708 Note that the complexity level is not related to the number of lines of
35709 code in a function.
35710 Large functions can have low complexity, and small functions can have large
35716 SDCC uses the following formula to compute the complexity:
35721 \begin_layout Standard
35722 complexity = (number of edges in control flow graph) - (number of nodes
35723 in control flow graph) + 2;
35727 Having said that the industry standard is 10,
35728 you should be aware that in some cases it be may unavoidable to have a
35729 complexity level of less than 10.
35730 For example if you have switch statement with more than 10 case labels,
35731 each case label adds one to the complexity level.
35732 The complexity level is by no means an absolute measure of the algorithmic
35733 complexity of the function, it does however provide a good starting point
35734 for which functions you might look at for further optimization.
35737 \begin_layout Section
35738 Retargetting for other Processors
35741 \begin_layout Standard
35742 The issues for retargetting the compiler are far too numerous to be covered
35744 What follows is a brief description of each of the seven phases of the
35745 compiler and its MCU dependency.
35748 \begin_layout Itemize
35749 Parsing the source and building the annotated parse tree.
35750 This phase is largely MCU independent (except for the language extensions).
35751 Syntax & semantic checks are also done in this phase, along with some initial
35752 optimizations like back patching labels and the pattern matching optimizations
35753 like bit-rotation etc.
35756 \begin_layout Itemize
35757 The second phase involves generating an intermediate code which can be easy
35758 manipulated during the later phases.
35759 This phase is entirely MCU independent.
35760 The intermediate code generation assumes the target machine has unlimited
35761 number of registers, and designates them with the name iTemp.
35762 The compiler can be made to dump a human readable form of the code generated
35767 \begin_layout Standard
35779 \begin_layout Itemize
35780 This phase does the bulk of the standard optimizations and is also MCU independe
35782 This phase can be broken down into several sub-phases:
35786 Break down intermediate
35787 code (iCode) into basic blocks.
35789 Do control flow & data flow analysis on the
35792 Do local common subexpression elimination, then global subexpressio
35795 Dead code elimination
35799 If loop optimizations
35800 caused any changes then do 'global subexpression elimination' and 'dead
35801 code elimination' again.
35804 \begin_layout Itemize
35805 This phase determines the live-ranges; by live range I mean those iTemp
35806 variables defined by the compiler that still survive after all the optimization
35808 Live range analysis
35809 \begin_inset LatexCommand \index{Live range analysis}
35813 is essential for register allocation, since these computation determines
35814 which of these iTemps will be assigned to registers, and for how long.
35817 \begin_layout Itemize
35818 Phase five is register allocation.
35819 There are two parts to this process.
35823 The first part I call 'register packing'
35824 (for lack of a better term).
35825 In this case several MCU specific expression folding is done to reduce
35830 The second part is more MCU independent and deals with
35831 allocating registers to the remaining live ranges.
35832 A lot of MCU specific code does creep into this phase because of the limited
35833 number of index registers available in the 8051.
35836 \begin_layout Itemize
35837 The Code generation phase is (unhappily), entirely MCU dependent and very
35838 little (if any at all) of this code can be reused for other MCU.
35839 However the scheme for allocating a homogenized assembler operand for each
35840 iCode operand may be reused.
35843 \begin_layout Itemize
35844 As mentioned in the optimization section the peep-hole optimizer is rule
35845 based system, which can reprogrammed for other MCUs.
35848 \begin_layout Standard
35849 More information is available in a wiki
35850 \begin_inset LatexCommand \index{wiki}
35855 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35859 ) and in the thread
35860 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35867 \begin_layout Chapter
35869 \begin_inset LatexCommand \index{Compiler internals}
35876 \begin_layout Section
35877 The anatomy of the compiler
35878 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35885 \begin_layout Standard
35888 This is an excerpt from an article published in Circuit Cellar Magazine
35894 It's a little outdated (the compiler is much more efficient now and user/develo
35895 per friendly), but pretty well exposes the guts of it all.
35901 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35902 It is fairly easy to retarget for other 8-bit MCU.
35903 Here we take a look at some of the internals of the compiler.
35907 \begin_layout Paragraph*
35909 \begin_inset LatexCommand \index{Parsing}
35916 \begin_layout Standard
35917 Parsing the input source file and creating an AST (Annotated Syntax Tree
35918 \begin_inset LatexCommand \index{Annotated syntax tree}
35923 This phase also involves propagating types (annotating each node of the
35924 parse tree with type information) and semantic analysis.
35925 There are some MCU specific parsing rules.
35926 For example the storage classes, the extended storage classes are MCU specific
35927 while there may be a xdata storage class for 8051 there is no such storage
35928 class for z80 or Atmel AVR.
35929 SDCC allows MCU specific storage class extensions, i.e.
35930 xdata will be treated as a storage class specifier when parsing 8051 C
35931 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35935 \begin_layout Paragraph*
35937 \begin_inset LatexCommand \index{iCode}
35944 \begin_layout Standard
35945 Intermediate code generation.
35946 In this phase the AST is broken down into three-operand form (iCode).
35947 These three operand forms are represented as doubly linked lists.
35948 ICode is the term given to the intermediate form generated by the compiler.
35949 ICode example section shows some examples of iCode generated for some simple
35950 C source functions.
35953 \begin_layout Paragraph*
35955 \begin_inset LatexCommand \index{Optimizations}
35962 \begin_layout Standard
35963 Bulk of the target independent optimizations is performed in this phase.
35964 The optimizations include constant propagation, common sub-expression eliminati
35965 on, loop invariant code movement, strength reduction of loop induction variables
35966 and dead-code elimination.
35969 \begin_layout Paragraph*
35970 Live range analysis
35971 \begin_inset LatexCommand \index{Live range analysis}
35978 \begin_layout Standard
35979 During intermediate code generation phase, the compiler assumes the target
35980 machine has infinite number of registers and generates a lot of temporary
35982 The live range computation determines the lifetime of each of these compiler-ge
35983 nerated temporaries.
35984 A picture speaks a thousand words.
35985 ICode example sections show the live range annotations for each of the
35987 It is important to note here, each iCode is assigned a number in the order
35988 of its execution in the function.
35989 The live ranges are computed in terms of these numbers.
35990 The from number is the number of the iCode which first defines the operand
35991 and the to number signifies the iCode which uses this operand last.
35994 \begin_layout Paragraph*
35995 Register Allocation
35996 \begin_inset LatexCommand \index{Register allocation}
36003 \begin_layout Standard
36004 The register allocation determines the type and number of registers needed
36006 In most MCUs only a few registers can be used for indirect addressing.
36007 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36008 address the internal ram and DPTR to indirectly address the external ram.
36009 The compiler will try to allocate the appropriate register to pointer variables
36011 ICode example section shows the operands annotated with the registers assigned
36013 The compiler will try to keep operands in registers as much as possible;
36014 there are several schemes the compiler uses to do achieve this.
36015 When the compiler runs out of registers the compiler will check to see
36016 if there are any live operands which is not used or defined in the current
36017 basic block being processed, if there are any found then it will push that
36018 operand and use the registers in this block, the operand will then be popped
36019 at the end of the basic block.
36023 \begin_layout Standard
36024 There are other MCU specific considerations in this phase.
36025 Some MCUs have an accumulator; very short-lived operands could be assigned
36026 to the accumulator instead of a general-purpose register.
36029 \begin_layout Paragraph*
36033 \begin_layout Standard
36034 Figure II gives a table of iCode
36035 \begin_inset LatexCommand \index{iCode}
36039 operations supported by the compiler.
36040 The code generation involves translating these operations into corresponding
36041 assembly code for the processor.
36042 This sounds overly simple but that is the essence of code generation.
36043 Some of the iCode operations are generated on a MCU specific manner for
36044 example, the z80 port does not use registers to pass parameters so the
36045 SEND and RECV iCode operations will not be generated, and it also does
36046 not support JUMPTABLES.
36052 \begin_layout Standard
36056 \begin_inset Tabular
36057 <lyxtabular version="3" rows="39" columns="4">
36058 <features islongtable="true" headBottomDL="true">
36059 <column alignment="block" valignment="top" leftline="true" width="13col%">
36060 <column alignment="left" valignment="top" leftline="true" width="13col%">
36061 <column alignment="block" valignment="top" leftline="true" width="22col%">
36062 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36063 <row topline="true" bottomline="true" endhead="true">
36064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36067 \begin_layout Standard
36073 \begin_inset LatexCommand \index{iCode}
36082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36085 \begin_layout Standard
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
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
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 Bitwise complement of
36196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36199 \begin_layout Standard
36202 IC_RESULT = ~IC_LEFT;
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 right 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 << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-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 Rotate left with carry
36288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36291 \begin_layout Standard
36294 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 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
36329 Get the highest order bit of IC_LEFT
36334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36337 \begin_layout Standard
36340 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
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
36364 IC_LEFT() IC_RESULT()
36369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36372 \begin_layout Standard
36380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36383 \begin_layout Standard
36386 IC_RESULT = - IC_LEFT;
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 Push the operand into 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
36461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36464 \begin_layout Standard
36467 Pop the operand from the stack
36472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36475 \begin_layout Standard
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 the function represented by IC_LEFT
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
36548 IC_LEFT() IC_RESULT()
36553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36556 \begin_layout Standard
36559 Call via function pointer
36564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36567 \begin_layout Standard
36570 IC_RESULT = (*IC_LEFT)();
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
36605 Return the value in operand IC_LEFT
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
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
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
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 and 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
37157 Logical or operation
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
37370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37373 \begin_layout Standard
37376 IC_LEFT() IC_RIGHT() IC_RESULT()
37381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37384 \begin_layout Standard
37392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37395 \begin_layout Standard
37398 IC_RESULT = IC_LEFT >> IC_RIGHT
37404 <row topline="true">
37405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37408 \begin_layout Standard
37418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37421 \begin_layout Standard
37424 IC_LEFT() 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_LEFT);
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_RIGHT() IC_RESULT()
37521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37524 \begin_layout Standard
37532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37535 \begin_layout Standard
37538 IC_RESULT = IC_RIGHT;
37544 <row topline="true">
37545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37548 \begin_layout Standard
37556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37559 \begin_layout Standard
37562 IC_COND IC_TRUE IC_LABEL
37567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37570 \begin_layout Standard
37574 If true label is present then jump to true label if condition is true else
37575 jump to false label if condition is false
37580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37583 \begin_layout Standard
37586 if (IC_COND) goto IC_TRUE;
37592 If (!IC_COND) goto IC_FALSE;
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_LEFT() IC_RESULT()
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37624 \begin_layout Standard
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37635 \begin_layout Standard
37638 IC_RESULT = &IC_LEFT();
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_JTCOND IC_JTLABELS
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37670 \begin_layout Standard
37673 Jump to list of labels depending on the value of JTCOND
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37681 \begin_layout Standard
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
37708 IC_RIGHT() IC_LEFT() IC_RESULT()
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37716 \begin_layout Standard
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37727 \begin_layout Standard
37730 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37736 <row topline="true">
37737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37740 \begin_layout Standard
37748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37751 \begin_layout Standard
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_layout Standard
37765 This is used for passing parameters in registers;
37767 move IC_LEFT to the next
37768 available parameter register.
37773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37776 \begin_layout Standard
37785 <row topline="true">
37786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37789 \begin_layout Standard
37797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37800 \begin_layout Standard
37808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37811 \begin_layout Standard
37814 This is used for receiving parameters passed in registers;
37817 in the next parameter register to IC_RESULT
37822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37825 \begin_layout Standard
37834 <row topline="true" bottomline="true">
37835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37838 \begin_layout Standard
37842 (some more have been added)
37847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37850 \begin_layout Standard
37856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37859 \begin_layout Standard
37865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37868 \begin_layout Standard
37892 \begin_layout Standard
37893 \begin_inset Note Note
37896 \begin_layout Standard
37897 In the original article Figure II was announced to be downloadable on
37902 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37910 \begin_layout Paragraph*
37912 \begin_inset LatexCommand \index{iCode}
37919 \begin_layout Standard
37920 This section shows some details of iCode.
37921 The example C code does not do anything useful; it is used as an example
37922 to illustrate the intermediate code generated by the compiler.
37925 \begin_layout Verse
37935 /* This function does nothing useful.
37942 for the purpose of explaining iCode */
37945 short function (data
37954 short i=10; \InsetSpace ~
37956 /* dead initialization eliminated */
37962 /* dead initialization eliminated */
37990 /* compiler detects i,j to be induction
37995 for (i = 0, j = 10 ; i < 10 ; i++, j
38001 \begin_layout Standard
38024 mul += i * 3; \InsetSpace ~
38026 /* this multiplication remains */
38033 j * 3;\InsetSpace ~
38035 /* this multiplication changed to addition */
38049 \begin_layout Standard
38050 In addition to the operands each iCode contains information about the filename
38051 and line it corresponds to in the source file.
38052 The first field in the listing should be interpreted as follows:
38057 Filename(linenumber: iCode Execution sequence number : ICode hash table
38058 key : loop depth of the iCode).
38063 Then follows the human readable form of the ICode operation.
38064 Each operand of this triplet form can be of three basic types a) compiler
38065 generated temporary b) user defined variable c) a constant value.
38066 Note that local variables and parameters are replaced by compiler generated
38069 \begin_inset LatexCommand \index{Live range analysis}
38073 are computed only for temporaries (i.e.
38074 live ranges are not computed for global variables).
38076 \begin_inset LatexCommand \index{Register allocation}
38080 are allocated for temporaries only.
38081 Operands are formatted in the following manner:
38086 Operand Name [lr live-from : live-to ] { type information } [ registers
38092 As mentioned earlier the live ranges are computed in terms of the execution
38093 sequence number of the iCodes, for example
38095 the iTemp0 is live from (i.e.
38096 first defined in iCode with execution sequence number 3, and is last used
38097 in the iCode with sequence number 5).
38098 For induction variables such as iTemp21 the live range computation extends
38099 the lifetime from the start to the end of the loop.
38101 The register allocator
38102 used the live range information to allocate registers, the same registers
38103 may be used for different temporaries if their live ranges do not overlap,
38104 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38105 ranges do not overlap.
38106 In addition the allocator also takes into consideration the type and usage
38107 of a temporary, for example itemp6 is a pointer to near space and is used
38108 as to fetch data from (i.e.
38109 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38110 Some short lived temporaries are allocated to special registers which have
38111 meaning to the code generator e.g.
38112 iTemp13 is allocated to a pseudo register CC which tells the back end that
38113 the temporary is used only for a conditional jump the code generation makes
38114 use of this information to optimize a compare and jump ICode.
38118 \begin_inset LatexCommand \index{Loop optimization}
38122 performed by the compiler.
38123 It can detect induction variables iTemp21(i) and iTemp23(j).
38124 Also note the compiler does selective strength reduction
38125 \begin_inset LatexCommand \index{Strength reduction}
38130 the multiplication of an induction variable in line 18 (gint = j * 3) is
38131 changed to addition, a new temporary iTemp17 is allocated and assigned
38132 a initial value, a constant 3 is then added for each iteration of the loop.
38133 The compiler does not change the multiplication
38134 \begin_inset LatexCommand \index{Multiplication}
38138 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38141 Note the dead code elimination
38142 \begin_inset LatexCommand \index{Dead-code elimination}
38146 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38152 \begin_layout Standard
38155 Sample.c (5:1:0:0) _entry($9) :
38158 \begin_layout Standard
38161 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38164 \begin_layout Standard
38167 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38170 \begin_layout Standard
38173 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38176 \begin_layout Standard
38179 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38183 \begin_layout Standard
38186 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38189 \begin_layout Standard
38192 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38196 \begin_layout Standard
38199 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38202 \begin_layout Standard
38205 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38209 \begin_layout Standard
38212 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38216 \begin_layout Standard
38219 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38223 \begin_layout Standard
38226 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38230 \begin_layout Standard
38233 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38234 * int}[r0] + 0x2 {short}
38237 \begin_layout Standard
38240 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38243 \begin_layout Standard
38246 Sample.c(11:17:21:0)_whilebreak_0($3) :
38249 \begin_layout Standard
38252 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38255 \begin_layout Standard
38258 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38261 \begin_layout Standard
38264 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38267 \begin_layout Standard
38270 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38273 \begin_layout Standard
38276 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38279 \begin_layout Standard
38282 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38285 \begin_layout Standard
38288 Sample.c(15:24:26:1)_forcond_0($4) :
38291 \begin_layout Standard
38294 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38298 \begin_layout Standard
38301 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38304 \begin_layout Standard
38307 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38308 + ITemp21 [lr21:38]{short}[r4]
38311 \begin_layout Standard
38314 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38318 \begin_layout Standard
38321 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38322 + iTemp15 [lr29:30]{short}[r1]
38325 \begin_layout Standard
38328 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38332 \begin_layout Standard
38335 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38339 \begin_layout Standard
38342 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38346 \begin_layout Standard
38349 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38353 \begin_layout Standard
38356 Sample.c(19:38:47:1) goto _forcond_0($4)
38359 \begin_layout Standard
38362 Sample.c(19:39:48:0)_forbreak_0($7) :
38365 \begin_layout Standard
38368 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38369 + ITemp11 [lr19:40]{short}[r3]
38372 \begin_layout Standard
38375 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38378 \begin_layout Standard
38381 Sample.c(20:42:51:0)_return($8) :
38384 \begin_layout Standard
38387 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38393 Finally the code generated for this function:
38398 \begin_layout Standard
38404 \begin_layout Standard
38410 \begin_layout Standard
38418 \begin_layout Standard
38424 \begin_layout Standard
38432 \begin_layout Standard
38438 \begin_layout Standard
38441 ; ----------------------------------------------
38444 \begin_layout Standard
38447 ; function function
38450 \begin_layout Standard
38453 ; ----------------------------------------------
38456 \begin_layout Standard
38462 \begin_layout Standard
38465 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38468 \begin_layout Standard
38476 \begin_layout Standard
38479 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38482 \begin_layout Standard
38490 \begin_layout Standard
38493 ;_whilecontinue_0($1) :
38496 \begin_layout Standard
38502 \begin_layout Standard
38505 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38508 \begin_layout Standard
38511 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38514 \begin_layout Standard
38522 \begin_layout Standard
38530 \begin_layout Standard
38538 \begin_layout Standard
38546 \begin_layout Standard
38554 \begin_layout Standard
38562 \begin_layout Standard
38570 \begin_layout Standard
38576 \begin_layout Standard
38579 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38582 \begin_layout Standard
38590 \begin_layout Standard
38598 \begin_layout Standard
38601 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38604 \begin_layout Standard
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 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38658 \begin_layout Standard
38666 \begin_layout Standard
38674 \begin_layout Standard
38682 \begin_layout Standard
38690 \begin_layout Standard
38698 \begin_layout Standard
38701 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38704 \begin_layout Standard
38712 \begin_layout Standard
38720 \begin_layout Standard
38728 \begin_layout Standard
38731 ; iTemp6 [lr5:16]{_near * int}[r0] =
38734 \begin_layout Standard
38737 ; iTemp6 [lr5:16]{_near * int}[r0] +
38740 \begin_layout Standard
38746 \begin_layout Standard
38754 \begin_layout Standard
38757 ; goto _whilecontinue_0($1)
38760 \begin_layout Standard
38768 \begin_layout Standard
38771 ; _whilebreak_0($3) :
38774 \begin_layout Standard
38780 \begin_layout Standard
38783 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38786 \begin_layout Standard
38794 \begin_layout Standard
38797 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38800 \begin_layout Standard
38808 \begin_layout Standard
38811 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38814 \begin_layout Standard
38822 \begin_layout Standard
38825 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38828 \begin_layout Standard
38836 \begin_layout Standard
38844 \begin_layout Standard
38847 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38850 \begin_layout Standard
38858 \begin_layout Standard
38866 \begin_layout Standard
38872 \begin_layout Standard
38878 \begin_layout Standard
38881 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38884 \begin_layout Standard
38887 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38890 \begin_layout Standard
38898 \begin_layout Standard
38906 \begin_layout Standard
38914 \begin_layout Standard
38922 \begin_layout Standard
38930 \begin_layout Standard
38936 \begin_layout Standard
38939 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
38942 \begin_layout Standard
38945 ; iTemp21 [lr21:38]{short}[r4]
38948 \begin_layout Standard
38956 \begin_layout Standard
38964 \begin_layout Standard
38972 \begin_layout Standard
38975 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38978 \begin_layout Standard
38986 \begin_layout Standard
38994 \begin_layout Standard
39002 \begin_layout Standard
39010 \begin_layout Standard
39013 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39016 \begin_layout Standard
39019 ; iTemp15 [lr29:30]{short}[r1]
39022 \begin_layout Standard
39030 \begin_layout Standard
39038 \begin_layout Standard
39041 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39044 \begin_layout Standard
39052 \begin_layout Standard
39060 \begin_layout Standard
39068 \begin_layout Standard
39076 \begin_layout Standard
39084 \begin_layout Standard
39092 \begin_layout Standard
39095 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39098 \begin_layout Standard
39106 \begin_layout Standard
39114 \begin_layout Standard
39122 \begin_layout Standard
39130 \begin_layout Standard
39138 \begin_layout Standard
39146 \begin_layout Standard
39149 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39152 \begin_layout Standard
39160 \begin_layout Standard
39163 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39166 \begin_layout Standard
39174 \begin_layout Standard
39179 cjne r5,#0xff,00104$
39182 \begin_layout Standard
39190 \begin_layout Standard
39193 ; goto _forcond_0($4)
39196 \begin_layout Standard
39204 \begin_layout Standard
39207 ; _forbreak_0($7) :
39210 \begin_layout Standard
39216 \begin_layout Standard
39219 ; ret iTemp24 [lr40:41]{short}
39222 \begin_layout Standard
39230 \begin_layout Standard
39238 \begin_layout Standard
39246 \begin_layout Standard
39252 \begin_layout Standard
39258 \begin_layout Standard
39268 \begin_layout Section
39269 A few words about basic block successors, predecessors and dominators
39272 \begin_layout Standard
39273 Successors are basic blocks
39274 \begin_inset LatexCommand \index{Basic blocks}
39278 that might execute after this basic block.
39280 Predecessors are basic blocks
39281 that might execute before reaching this basic block.
39283 Dominators are basic
39284 blocks that WILL execute before reaching this basic block.
39289 \begin_layout Standard
39293 \begin_layout Standard
39297 \begin_layout Standard
39305 \begin_layout Standard
39309 \begin_layout Standard
39317 \begin_layout Standard
39323 \begin_layout Standard
39324 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39327 \begin_layout Standard
39328 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39331 \begin_layout Standard
39332 c) domVect of [BB4] = BB1 ...
39333 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39337 \begin_layout Chapter
39341 \begin_layout Standard
39342 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39352 Thanks to all the other volunteer developers who have helped with coding,
39353 testing, web-page creation, distribution sets, etc.
39354 You know who you are :-)
39362 Also thanks to Sourceforge
39363 \begin_inset LatexCommand \url{http://www.sf.net}
39367 which has hosted the project since 1999 and donates significant download
39368 bandwidth and probably more than
39372 \begin_layout Standard
39379 CPU cycles per day.
39382 \begin_inset Note Note
39385 \begin_layout Standard
39386 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39387 minutes for (configure+make+regression test), and there is (i386, amd64,
39388 alpha, ppc64, (mingw32), sparc, Mac OS X).
39397 \begin_layout Standard
39398 This document was initially written by Sandeep Dutta
39401 \begin_layout Standard
39402 All product names mentioned herein may be trademarks
39403 \begin_inset LatexCommand \index{Trademarks}
39407 of their respective companies.
39411 \begin_layout Section*
39415 \begin_layout Standard
39416 To avoid confusion, the installation and building options for SDCC itself
39417 (chapter 2) are not part of the index.
39420 \begin_layout Standard
39421 \begin_inset LatexCommand \printindex{}