1 #LyX 1.4.3 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 \labelwidthstring 00.00.0000
8449 \begin_layout Standard
8461 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8465 Determinate PORT I/O mode (<Value> is z80 or z180).
8469 \labelwidthstring 00.00.0000
8476 \begin_layout Standard
8488 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8492 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8496 \labelwidthstring 00.00.0000
8503 \begin_layout Standard
8516 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8520 Use <Value> for the code segment name.
8524 \labelwidthstring 00.00.0000
8531 \begin_layout Standard
8544 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8548 Use <Value> for the const segment name.
8552 \labelwidthstring 00.00.0000
8553 \begin_inset VSpace bigskip
8559 \begin_layout Subsection
8561 \begin_inset LatexCommand \index{Options GBZ80}
8566 \begin_inset LatexCommand \index{GBZ80}
8574 \labelwidthstring 00.00.0000
8581 \begin_layout Standard
8593 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8603 Force a called function to always save BC.
8607 \labelwidthstring 00.00.0000
8614 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8618 Use code bank <Num>.
8622 \labelwidthstring 00.00.0000
8629 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8633 Use data bank <Num>.
8637 \labelwidthstring 00.00.0000
8644 \begin_layout Standard
8657 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8661 Use <Value> for the code segment name.
8665 \labelwidthstring 00.00.0000
8672 \begin_layout Standard
8685 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8689 Use <Value> for the const segment name.
8692 \begin_layout Standard
8693 \begin_inset VSpace bigskip
8699 \begin_layout Subsection
8700 Optimization Options
8701 \begin_inset LatexCommand \index{Options optimization}
8706 \begin_inset LatexCommand \index{Optimization options}
8714 \labelwidthstring 00.00.0000
8721 \begin_layout Standard
8731 \begin_inset LatexCommand \index{-\/-nogcse}
8737 Will not do global subexpression elimination, this option may be used when
8738 the compiler creates undesirably large stack/data spaces to store compiler
8748 \begin_inset LatexCommand \index{sloc (spill location)}
8753 A warning message will be generated when this happens and the compiler
8754 will indicate the number of extra bytes it allocated.
8755 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8757 \begin_inset LatexCommand \index{\#pragma nogcse}
8761 can be used to turn off global subexpression elimination
8762 \begin_inset LatexCommand \index{Subexpression elimination}
8766 for a given function only.
8770 \labelwidthstring 00.00.0000
8777 \begin_layout Standard
8787 \begin_inset LatexCommand \index{-\/-noinvariant}
8793 Will not do loop invariant optimizations, this may be turned off for reasons
8794 explained for the previous option.
8795 For more details of loop optimizations performed see Loop Invariants in
8797 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8802 It is recommended that this option NOT be used, #pragma\InsetSpace ~
8804 \begin_inset LatexCommand \index{\#pragma noinvariant}
8808 can be used to turn off invariant optimizations for a given function only.
8812 \labelwidthstring 00.00.0000
8819 \begin_layout Standard
8829 \begin_inset LatexCommand \index{-\/-noinduction}
8835 Will not do loop induction optimizations, see section strength reduction
8837 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8839 \begin_inset LatexCommand \index{\#pragma noinduction}
8843 can be used to turn off induction optimizations for a given function only.
8847 \labelwidthstring 00.00.0000
8854 \begin_layout Standard
8864 \begin_inset LatexCommand \index{-\/-nojtbound}
8875 Will not generate boundary condition check when switch statements
8876 \begin_inset LatexCommand \index{switch statement}
8880 are implemented using jump-tables.
8882 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8887 Switch Statements for more details.
8888 It is recommended that this option is NOT used, #pragma\InsetSpace ~
8890 \begin_inset LatexCommand \index{\#pragma nojtbound}
8894 can be used to turn off boundary checking for jump tables for a given function
8899 \labelwidthstring 00.00.0000
8906 \begin_layout Standard
8916 \begin_inset LatexCommand \index{-\/-noloopreverse}
8925 Will not do loop reversal
8926 \begin_inset LatexCommand \index{Loop reversing}
8934 \labelwidthstring 00.00.0000
8939 \begin_layout Standard
8953 \begin_inset LatexCommand \index{-\/-nolabelopt }
8957 Will not optimize labels (makes the dumpfiles more readable).
8961 \labelwidthstring 00.00.0000
8968 \begin_layout Standard
8978 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8984 Will not memcpy initialized data from code space into xdata space.
8985 This saves a few bytes in code space if you don't have initialized data
8986 \begin_inset LatexCommand \index{Variable initialization}
8994 \labelwidthstring 00.00.0000
9001 \begin_layout Standard
9011 \begin_inset LatexCommand \index{-\/-nooverlay}
9017 The compiler will not overlay parameters and local variables of any function,
9018 see section Parameters and local variables for more details.
9022 \labelwidthstring 00.00.0000
9029 \begin_layout Standard
9039 \begin_inset LatexCommand \index{-\/-no-peep}
9045 Disable peep-hole optimization with built-in rules.
9049 \labelwidthstring 00.00.0000
9056 \begin_layout Standard
9068 \begin_inset LatexCommand \index{-\/-peep-file}
9073 <filename> This option can be used to use additional rules to be used by
9074 the peep hole optimizer.
9076 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9081 Peep Hole optimizations for details on how to write these rules.
9085 \labelwidthstring 00.00.0000
9092 \begin_layout Standard
9102 \begin_inset LatexCommand \index{-\/-peep-asm}
9108 Pass the inline assembler code through the peep hole optimizer.
9109 This can cause unexpected changes to inline assembler code, please go through
9110 the peephole optimizer
9111 \begin_inset LatexCommand \index{Peephole optimizer}
9115 rules defined in the source file tree '<target>/peeph.def' before using
9120 \labelwidthstring 00.00.0000
9127 \begin_layout Standard
9137 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9143 The compiler will optimize code generation towards fast code, possibly
9144 at the expense of code size.
9148 \labelwidthstring 00.00.0000
9155 \begin_layout Standard
9165 \begin_inset LatexCommand \index{-\/-opt-code-size}
9171 The compiler will optimize code generation towards compact code, possibly
9172 at the expense of code speed.
9175 \begin_layout Standard
9176 \begin_inset VSpace bigskip
9182 \begin_layout Subsection
9184 \begin_inset LatexCommand \index{Options other}
9192 \labelwidthstring 00.00.0000
9200 \begin_layout Standard
9210 \begin_inset LatexCommand \index{-\/-compile-only}
9215 \begin_inset LatexCommand \index{-c -\/-compile-only}
9221 will compile and assemble the source, but will not call the linkage editor.
9225 \labelwidthstring 00.00.0000
9234 \begin_layout Standard
9246 \begin_inset LatexCommand \index{-\/-c1mode}
9252 reads the preprocessed source from standard input and compiles it.
9253 The file name for the assembler output must be specified using the -o option.
9257 \labelwidthstring 00.00.0000
9261 \begin_inset LatexCommand \index{-E}
9267 Run only the C preprocessor.
9268 Preprocess all the C source files specified and output the results to standard
9273 \labelwidthstring 00.00.0000
9278 \begin_inset LatexCommand \index{-o <path/file>}
9284 The output path where everything will be placed or the file name used for
9285 all generated output files.
9286 If the parameter is a path, it must have a trailing slash (or backslash
9287 for the Windows binaries) to be recognized as a path.
9292 Note for Windows users: if the path contains spaces, it should be surrounded
9294 The trailing backslash should be doubled in order to prevent escaping the
9295 final quote, for example:
9298 \begin_inset Quotes sld
9312 \begin_inset Quotes srd
9317 or put after the final quote, for example:
9320 \begin_inset Quotes sld
9330 \begin_inset Quotes srd
9338 The path using slashes for directory delimiters can be used too, for example:
9342 \begin_inset Quotes sld
9345 F:/Projects/test3/output 1/
9346 \begin_inset Quotes srd
9355 \labelwidthstring 00.00.0000
9362 \begin_layout Standard
9372 \begin_inset LatexCommand \index{-\/-stack-auto}
9383 All functions in the source file will be compiled as
9388 \begin_inset LatexCommand \index{reentrant}
9393 the parameters and local variables will be allocated on the stack
9394 \begin_inset LatexCommand \index{stack}
9400 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9404 Parameters and Local Variables for more details.
9405 If this option is used all source files in the project should be compiled
9407 It automatically implies --int-long-reent and --float-reent.
9412 \labelwidthstring 00.00.0000
9419 \begin_layout Standard
9429 \begin_inset LatexCommand \index{-\/-callee-saves}
9434 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9438 function1[,function2][,function3]....
9441 The compiler by default uses a caller saves convention for register saving
9442 across function calls, however this can cause unnecessary register pushing
9443 and popping when calling small functions from larger functions.
9444 This option can be used to switch the register saving convention for the
9445 function names specified.
9446 The compiler will not save registers when calling these functions, no extra
9447 code will be generated at the entry and exit (function prologue
9450 \begin_inset LatexCommand \index{function prologue}
9459 \begin_inset LatexCommand \index{function epilogue}
9465 ) for these functions to save and restore the registers used by these functions,
9466 this can SUBSTANTIALLY reduce code and improve run time performance of
9468 In the future the compiler (with inter procedural analysis) will be able
9469 to determine the appropriate scheme to use for each function call.
9470 DO NOT use this option for built-in functions such as _mulint..., if this
9471 option is used for a library function the appropriate library function
9472 needs to be recompiled with the same option.
9473 If the project consists of multiple source files then all the source file
9474 should be compiled with the same -
9478 \begin_layout Standard
9487 -callee-saves option string.
9488 Also see #pragma\InsetSpace ~
9490 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9495 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9503 \labelwidthstring 00.00.0000
9510 \begin_layout Standard
9520 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9534 \begin_layout Standard
9543 -callee-saves will be applied to all functions by default.
9547 \labelwidthstring 00.00.0000
9554 \begin_layout Standard
9564 \begin_inset LatexCommand \index{-\/-debug}
9573 When this option is used the compiler will generate debug information.
9574 The debug information collected in a file with .cdb extension can be used
9576 For more information see documentation for SDCDB.
9577 Another file with no extension contains debug information in AOMF or AOMF51
9578 \begin_inset LatexCommand \index{AOMF, AOMF51}
9582 format which is commonly used by third party tools.
9586 \labelwidthstring 00.00.0000
9590 \begin_inset LatexCommand \index{-S}
9601 Stop after the stage of compilation proper; do not assemble.
9602 The output is an assembler code file for the input file specified.
9606 \labelwidthstring 00.00.0000
9613 \begin_layout Standard
9623 \begin_inset LatexCommand \index{-\/-int-long-reent}
9629 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9630 Note by default these libraries are compiled as non-reentrant.
9631 See section Installation for more details.
9635 \labelwidthstring 00.00.0000
9642 \begin_layout Standard
9652 \begin_inset LatexCommand \index{-\/-cyclomatic}
9661 This option will cause the compiler to generate an information message for
9662 each function in the source file.
9663 The message contains some
9667 information about the function.
9668 The number of edges and nodes the compiler detected in the control flow
9669 graph of the function, and most importantly the
9671 cyclomatic complexity
9672 \begin_inset LatexCommand \index{Cyclomatic complexity}
9678 see section on Cyclomatic Complexity for more details.
9682 \labelwidthstring 00.00.0000
9689 \begin_layout Standard
9699 \begin_inset LatexCommand \index{-\/-float-reent}
9705 Floating point library is compiled as reentrant
9706 \begin_inset LatexCommand \index{reentrant}
9711 See section Installation for more details.
9715 \labelwidthstring 00.00.0000
9722 \begin_layout Standard
9732 \begin_inset LatexCommand \index{-\/-funsigned-char}
9738 The default signedness for every type is
9743 In some embedded environments the default signedness of
9752 To set the signess for characters to unsigned, use the option --funsigned-char.
9753 If this option is set and no signedness keyword (unsigned/signed) is given,
9754 a char will be signed.
9755 All other types are unaffected.
9759 \labelwidthstring 00.00.0000
9766 \begin_layout Standard
9776 \begin_inset LatexCommand \index{-\/-main-return}
9782 This option can be used if the code generated is called by a monitor program
9783 or if the main routine includes an endless loop.
9784 This option results in slightly smaller code and saves two bytes of stack
9786 The return from the 'main'
9787 \begin_inset LatexCommand \index{main return}
9791 function will return to the function calling main.
9792 The default setting is to lock up i.e.
9801 \labelwidthstring 00.00.0000
9808 \begin_layout Standard
9818 \begin_inset LatexCommand \index{-\/-nostdinc}
9824 This will prevent the compiler from passing on the default include path
9825 to the preprocessor.
9829 \labelwidthstring 00.00.0000
9836 \begin_layout Standard
9846 \begin_inset LatexCommand \index{-\/-nostdlib}
9852 This will prevent the compiler from passing on the default library
9853 \begin_inset LatexCommand \index{Libraries}
9861 \labelwidthstring 00.00.0000
9868 \begin_layout Standard
9878 \begin_inset LatexCommand \index{-\/-verbose}
9884 Shows the various actions the compiler is performing.
9888 \labelwidthstring 00.00.0000
9892 \begin_inset LatexCommand \index{-V}
9898 Shows the actual commands the compiler is executing.
9902 \labelwidthstring 00.00.0000
9909 \begin_layout Standard
9919 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9925 Hides your ugly and inefficient c-code from the asm file, so you can always
9926 blame the compiler :)
9930 \labelwidthstring 00.00.0000
9937 \begin_layout Standard
9947 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9953 Include code generator and peep-hole comments in the generated asm files.
9957 \labelwidthstring 00.00.0000
9964 \begin_layout Standard
9974 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9980 Don't include peep-hole comments in the generated asm files even if --fverbose-
9981 asm option is specified.
9985 \labelwidthstring 00.00.0000
9992 \begin_layout Standard
10002 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10008 Include i-codes in the asm file.
10009 Sounds like noise but is most helpful for debugging the compiler itself.
10013 \labelwidthstring 00.00.0000
10020 \begin_layout Standard
10030 \begin_inset LatexCommand \index{pedantic}
10035 \begin_inset LatexCommand \index{-\/-less-pedantic}
10042 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10046 Disable some of the more pedantic warnings
10047 \begin_inset LatexCommand \index{Warnings}
10052 For more details, see the less_pedantic pragma
10053 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10061 \labelwidthstring 00.00.0000
10068 \begin_layout Standard
10077 -disable-warning\InsetSpace ~
10079 \begin_inset LatexCommand \index{-\/-disable-warning}
10085 Disable specific warning with number <nnnn>.
10089 \labelwidthstring 00.00.0000
10096 \begin_layout Standard
10106 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10112 Display the directories in the compiler's search path
10116 \labelwidthstring 00.00.0000
10123 \begin_layout Standard
10133 \begin_inset LatexCommand \index{-\/-vc}
10139 Display errors and warnings using MSVC style, so you can use SDCC with
10140 the visual studio IDE
10141 \begin_inset LatexCommand \index{IDE}
10146 With SDCC both offering a GCC-like (the default) and a MSVC-like
10147 \begin_inset LatexCommand \index{MSVC output style}
10151 output style, integration into most programming editors should be straightforwa
10156 \labelwidthstring 00.00.0000
10163 \begin_layout Standard
10173 \begin_inset LatexCommand \index{-\/-use-stdout}
10179 Send errors and warnings to stdout instead of stderr.
10183 \labelwidthstring 00.00.0000
10187 asmOption[,asmOption]
10190 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10195 Pass the asmOption to the assembler
10196 \begin_inset LatexCommand \index{Options assembler}
10201 \begin_inset LatexCommand \index{Assembler options}
10206 See file sdcc/as/doc/asxhtm.html for assembler options.cd
10210 \labelwidthstring 00.00.0000
10217 \begin_layout Standard
10227 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10233 Generally follow the C89 standard, but allow SDCC features that conflict
10234 with the standard (default).
10238 \labelwidthstring 00.00.0000
10245 \begin_layout Standard
10255 \begin_inset LatexCommand \index{-\/-std-c89}
10261 Follow the C89 standard and disable SDCC features that conflict with the
10266 \labelwidthstring 00.00.0000
10273 \begin_layout Standard
10283 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10289 Generally follow the C99 standard, but allow SDCC features that conflict
10290 with the standard (incomplete support).
10294 \labelwidthstring 00.00.0000
10301 \begin_layout Standard
10311 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10317 Follow the C99 standard and disable SDCC features that conflict with the
10318 standard (incomplete support).
10322 \labelwidthstring 00.00.0000
10329 \begin_layout Standard
10341 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10346 <Name> The name to be used for the code
10347 \begin_inset LatexCommand \index{code}
10351 segment, default CSEG.
10352 This is useful if you need to tell the compiler to put the code in a special
10353 segment so you can later on tell the linker to put this segment in a special
10355 Can be used for instance when using bank switching to put the code in a
10360 \labelwidthstring 00.00.0000
10367 \begin_layout Standard
10379 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10384 <Name> The name to be used for the const
10385 \begin_inset LatexCommand \index{const}
10389 segment, default CONST.
10390 This is useful if you need to tell the compiler to put the const data in
10391 a special segment so you can later on tell the linker to put this segment
10392 in a special place in memory.
10393 Can be used for instance when using bank switching to put the const data
10398 \labelwidthstring 00.00.0000
10405 \begin_layout Standard
10414 -fdollars-in-identifiers
10415 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10421 Permit '$' as an identifier character.
10425 \labelwidthstring 00.00.0000
10432 \begin_layout Standard
10444 \begin_inset LatexCommand \index{-\/-more-pedantic}
10449 \begin_inset LatexCommand \index{pedantic}
10459 a SDCC compiler option but if you want
10463 warnings you can use a separate tool dedicated to syntax checking like
10465 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10470 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10475 \begin_inset LatexCommand \url{http://www.splint.org}
10480 To make your source files parseable by splint you will have to include
10486 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10490 in your source file and add brackets around extended keywords (like
10493 \begin_inset Quotes sld
10506 \begin_inset Quotes srd
10514 \begin_inset Quotes sld
10517 __interrupt\InsetSpace ~
10519 \begin_inset Quotes srd
10527 Splint has an excellent on line manual at
10528 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10532 and it's capabilities go beyond pure syntax checking.
10533 You'll need to tell splint the location of SDCC's include files so a typical
10534 command line could look like this:
10538 splint\InsetSpace ~
10540 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10546 \labelwidthstring 00.00.0000
10553 \begin_layout Standard
10565 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10570 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10574 Treat short as 8-bit (for backward compatibility with older versions of
10575 compiler - see section
10576 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10583 \begin_layout Standard
10584 \begin_inset VSpace bigskip
10590 \begin_layout Subsection
10591 Intermediate Dump Options
10592 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10597 \begin_inset LatexCommand \index{Options intermediate dump}
10602 \begin_inset LatexCommand \index{Intermediate dump options}
10609 \begin_layout Standard
10610 The following options are provided for the purpose of retargetting and debugging
10612 They provide a means to dump the intermediate code (iCode
10613 \begin_inset LatexCommand \index{iCode}
10617 ) generated by the compiler in human readable form at various stages of
10618 the compilation process.
10619 More on iCodes see chapter
10620 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10625 \begin_inset Quotes srd
10628 The anatomy of the compiler
10629 \begin_inset Quotes srd
10636 \labelwidthstring 00.00.0000
10643 \begin_layout Standard
10653 \begin_inset LatexCommand \index{-\/-dumpraw}
10659 This option will cause the compiler to dump the intermediate code into
10662 <source filename>.dumpraw
10664 just after the intermediate code has been generated for a function, i.e.
10665 before any optimizations are done.
10667 \begin_inset LatexCommand \index{Basic blocks}
10671 at this stage ordered in the depth first number, so they may not be in
10672 sequence of execution.
10676 \labelwidthstring 00.00.0000
10683 \begin_layout Standard
10693 \begin_inset LatexCommand \index{-\/-dumpgcse}
10699 Will create a dump of iCode's, after global subexpression elimination
10700 \begin_inset LatexCommand \index{Global subexpression elimination}
10704 , into a file named
10706 <source filename>.dumpgcse.
10710 \labelwidthstring 00.00.0000
10717 \begin_layout Standard
10727 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10733 Will create a dump of iCode's, after deadcode elimination
10734 \begin_inset LatexCommand \index{Dead-code elimination}
10738 , into a file named
10740 <source filename>.dumpdeadcode.
10744 \labelwidthstring 00.00.0000
10751 \begin_layout Standard
10761 \begin_inset LatexCommand \index{-\/-dumploop}
10770 Will create a dump of iCode's, after loop optimizations
10771 \begin_inset LatexCommand \index{Loop optimization}
10775 , into a file named
10777 <source filename>.dumploop.
10781 \labelwidthstring 00.00.0000
10788 \begin_layout Standard
10798 \begin_inset LatexCommand \index{-\/-dumprange}
10807 Will create a dump of iCode's, after live range analysis
10808 \begin_inset LatexCommand \index{Live range analysis}
10812 , into a file named
10814 <source filename>.dumprange.
10818 \labelwidthstring 00.00.0000
10825 \begin_layout Standard
10835 \begin_inset LatexCommand \index{-\/-dumlrange}
10841 Will dump the life ranges
10842 \begin_inset LatexCommand \index{Live range analysis}
10850 \labelwidthstring 00.00.0000
10857 \begin_layout Standard
10867 \begin_inset LatexCommand \index{-\/-dumpregassign}
10876 Will create a dump of iCode's, after register assignment
10877 \begin_inset LatexCommand \index{Register assignment}
10881 , into a file named
10883 <source filename>.dumprassgn.
10887 \labelwidthstring 00.00.0000
10894 \begin_layout Standard
10904 \begin_inset LatexCommand \index{-\/-dumplrange}
10910 Will create a dump of the live ranges of iTemp's
10914 \labelwidthstring 00.00.0000
10921 \begin_layout Standard
10931 \begin_inset LatexCommand \index{-\/-dumpall}
10942 Will cause all the above mentioned dumps to be created.
10945 \begin_layout Standard
10946 \begin_inset VSpace bigskip
10952 \begin_layout Subsection
10953 Redirecting output on Windows Shells
10956 \begin_layout Standard
10957 By default SDCC writes it's error messages to
10958 \begin_inset Quotes sld
10962 \begin_inset Quotes srd
10966 To force all messages to
10967 \begin_inset Quotes sld
10971 \begin_inset Quotes srd
10983 \begin_layout Standard
10998 \begin_inset LatexCommand \index{-\/-use-stdout}
11003 Additionally, if you happen to have visual studio installed in your windows
11004 machine, you can use it to compile your sources using a custom build and
11011 \begin_layout Standard
11023 \begin_inset LatexCommand \index{-\/-vc}
11028 Something like this should work:
11047 \begin_layout Standard
11066 \begin_layout Standard
11078 -model-large -c $(InputPath)
11081 \begin_inset VSpace bigskip
11087 \begin_layout Section
11088 Environment variables
11089 \begin_inset LatexCommand \index{Environment variables}
11096 \begin_layout Standard
11097 SDCC recognizes the following environment variables:
11101 \labelwidthstring 00.00.0000
11105 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11111 SDCC installs a signal handler
11112 \begin_inset LatexCommand \index{signal handler}
11116 to be able to delete temporary files after an user break (^C) or an exception.
11117 If this environment variable is set, SDCC won't install the signal handler
11118 in order to be able to debug SDCC.
11122 \labelwidthstring 00.00.0000
11128 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11134 Path, where temporary files will be created.
11135 The order of the variables is the search order.
11136 In a standard *nix environment these variables are not set, and there's
11137 no need to set them.
11138 On Windows it's recommended to set one of them.
11142 \labelwidthstring 00.00.0000
11146 \begin_inset LatexCommand \index{SDCC\_HOME}
11153 \begin_inset LatexCommand \ref{sub:Install-paths}
11159 \begin_inset Quotes sld
11163 \begin_inset Quotes srd
11170 \labelwidthstring 00.00.0000
11174 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11181 \begin_inset LatexCommand \ref{sub:Search-Paths}
11187 \begin_inset Quotes sld
11191 \begin_inset Quotes srd
11198 \labelwidthstring 00.00.0000
11202 \begin_inset LatexCommand \index{SDCC\_LIB}
11209 \begin_inset LatexCommand \ref{sub:Search-Paths}
11215 \begin_inset Quotes sld
11219 \begin_inset Quotes srd
11225 \begin_layout Standard
11226 There are some more environment variables recognized by SDCC, but these
11227 are solely used for debugging purposes.
11228 They can change or disappear very quickly, and will never be documented.
11229 \begin_inset VSpace bigskip
11235 \begin_layout Section
11236 Storage Class Language Extensions
11239 \begin_layout Subsection
11240 MCS51/DS390 Storage Class
11241 \begin_inset LatexCommand \index{Storage class}
11245 Language Extensions
11248 \begin_layout Standard
11249 In addition to the ANSI storage classes SDCC allows the following MCS51
11250 specific storage classes:
11253 \begin_layout Subsubsection
11255 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11260 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11265 \begin_inset LatexCommand \index{near (storage class)}
11270 \begin_inset LatexCommand \index{\_\_near (storage class)}
11277 \begin_layout Standard
11282 storage class for the Small Memory model (
11290 or the more ANSI-C compliant forms
11298 can be used synonymously).
11299 Variables declared with this storage class will be allocated in the directly
11300 addressable portion of the internal RAM of a 8051, e.g.:
11303 \begin_layout Verse
11306 __data unsigned char test_data;
11309 \begin_layout Standard
11310 Writing 0x01 to this variable generates the assembly code:
11313 \begin_layout Verse
11316 75*00 01\InsetSpace ~
11324 \begin_layout Subsubsection
11326 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11331 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11336 \begin_inset LatexCommand \index{far (storage class)}
11341 \begin_inset LatexCommand \index{\_\_far (storage class)}
11348 \begin_layout Standard
11349 Variables declared with this storage class will be placed in the external
11355 storage class for the Large Memory model, e.g.:
11358 \begin_layout Verse
11361 __xdata unsigned char test_xdata;
11364 \begin_layout Standard
11365 Writing 0x01 to this variable generates the assembly code:
11368 \begin_layout Verse
11371 90s00r00\InsetSpace ~
11402 \begin_layout Subsubsection
11404 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11409 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11416 \begin_layout Standard
11417 Variables declared with this storage class will be allocated into the indirectly
11418 addressable portion of the internal ram of a 8051, e.g.:
11421 \begin_layout Verse
11424 __idata unsigned char test_idata;
11427 \begin_layout Standard
11428 Writing 0x01 to this variable generates the assembly code:
11431 \begin_layout Verse
11458 \begin_layout Standard
11459 Please note, the first 128 byte of idata physically access the same RAM
11460 as the data memory.
11461 The original 8051 had 128 byte idata memory, nowadays most devices have
11462 256 byte idata memory.
11464 \begin_inset LatexCommand \index{stack}
11468 is located in idata memory.
11471 \begin_layout Subsubsection
11473 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11478 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11485 \begin_layout Standard
11486 Paged xdata access is just as straightforward as using the other addressing
11488 It is typically located at the start of xdata and has a maximum size of
11490 The following example writes 0x01 to the pdata variable.
11491 Please note, pdata access physically accesses xdata memory.
11492 The high byte of the address is determined by port P2
11493 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11497 (or in case of some 8051 variants by a separate Special Function Register,
11499 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11508 storage class for the Medium Memory model, e.g.:
11511 \begin_layout Verse
11514 __pdata unsigned char test_pdata;
11517 \begin_layout Standard
11518 Writing 0x01 to this variable generates the assembly code:
11521 \begin_layout Verse
11530 mov r0,#_test_pdata
11552 \begin_layout Standard
11557 \begin_layout Standard
11567 \begin_inset LatexCommand \index{-\/-xstack}
11571 option is used the pdata memory area is followed by the xstack memory area
11572 and the sum of their sizes is limited to 256 bytes.
11575 \begin_layout Subsubsection
11577 \begin_inset LatexCommand \index{code}
11582 \begin_inset LatexCommand \index{\_\_code}
11589 \begin_layout Standard
11590 'Variables' declared with this storage class will be placed in the code
11594 \begin_layout Verse
11597 __code unsigned char test_code;
11600 \begin_layout Standard
11601 Read access to this variable generates the assembly code:
11604 \begin_layout Verse
11607 90s00r6F\InsetSpace ~
11610 mov dptr,#_test_code
11635 \begin_layout Standard
11640 indexed arrays of characters in code memory can be accessed efficiently:
11643 \begin_layout Verse
11646 __code char test_array[] = {'c','h','e','a','p'};
11649 \begin_layout Standard
11650 Read access to this array using an 8-bit unsigned index generates the assembly
11654 \begin_layout Verse
11666 \begin_layout Verse
11669 90s00r41\InsetSpace ~
11672 mov dptr,#_test_array
11675 \begin_layout Verse
11690 \begin_layout Subsubsection
11692 \begin_inset LatexCommand \index{bit}
11697 \begin_inset LatexCommand \index{\_\_bit}
11704 \begin_layout Standard
11705 This is a data-type and a storage class specifier.
11706 When a variable is declared as a bit, it is allocated into the bit addressable
11707 memory of 8051, e.g.:
11710 \begin_layout Verse
11716 \begin_layout Standard
11717 Writing 1 to this variable generates the assembly code:
11720 \begin_layout Verse
11734 \begin_layout Standard
11735 The bit addressable memory consists of 128 bits which are located from 0x20
11736 to 0x2f in data memory.
11739 Apart from this 8051 specific storage class most architectures support
11741 \begin_inset LatexCommand \index{bitfields}
11749 \begin_layout Standard
11750 Not really meant as examples, but nevertheless showing what bitfields are
11751 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11757 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11758 signed modifier are implemented as unsigned.
11761 \begin_layout Subsubsection
11763 \begin_inset LatexCommand \index{sfr}
11768 \begin_inset LatexCommand \index{\_\_sfr}
11773 \begin_inset LatexCommand \index{sfr16}
11778 \begin_inset LatexCommand \index{\_\_sfr16}
11783 \begin_inset LatexCommand \index{sfr32}
11788 \begin_inset LatexCommand \index{\_\_sfr32}
11793 \begin_inset LatexCommand \index{\_\_sbit}
11798 \begin_inset LatexCommand \index{sbit}
11805 \begin_layout Standard
11806 Like the bit keyword,
11808 sfr / sfr16 / sfr32 / sbit
11810 signify both a data-type and storage class, they are used to describe the
11831 variables of a 8051, eg:
11834 \begin_layout Verse
11838 \begin_inset LatexCommand \index{at}
11843 \begin_inset LatexCommand \index{\_\_at}
11847 (0x80) P0;\InsetSpace ~
11848 /* special function register P0 at location 0x80 */
11853 special function register combination for timer 0
11857 with the high byte at
11858 location 0x8C and the low byte at location 0x8A */
11860 __sfr16 __at (0x8C8A)
11866 \begin_inset LatexCommand \index{at}
11871 \begin_inset LatexCommand \index{\_\_at}
11875 (0xd7) CY;\InsetSpace ~
11877 \begin_inset LatexCommand \index{Flags}
11882 \begin_inset LatexCommand \index{Carry flag}
11889 \begin_layout Standard
11890 Special function registers which are located on an address dividable by
11891 8 are bit-addressable, an
11895 addresses a specific bit within these sfr.
11897 16 Bit and 32 bit special function
11898 register combinations which require a certain access order are better not
11908 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11909 this is not guaranteed.
11914 \begin_layout Standard
11915 Please note, if you use a header file which was written for another compiler
11916 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11922 Specifically the syntax
11925 sfr P0 = 0x80;\InsetSpace ~
11932 by SDCC to an assignment of 0x80 to a variable called P0
11935 \begin_inset Marginal
11938 \begin_layout Standard
11950 Nevertheless it is possible to write header files
11951 \begin_inset LatexCommand \index{Header files}
11956 \begin_inset LatexCommand \index{Include files}
11960 which can be shared among different compilers (see section
11961 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11969 \begin_layout Subsubsection
11971 \begin_inset LatexCommand \index{Pointer}
11975 to MCS51/DS390 specific memory spaces
11978 \begin_layout Standard
11979 SDCC allows (via language extensions) pointers to explicitly point to any
11980 of the memory spaces
11981 \begin_inset LatexCommand \index{Memory model}
11986 In addition to the explicit pointers, the compiler uses (by default) generic
11987 pointers which can be used to point to any of the memory spaces.
11992 declaration examples:
11995 \begin_layout Verse
11998 /* pointer physically in internal ram pointing to object in external ram
12001 __xdata unsigned char * __data p;
12005 /* pointer physically in external ram
12006 pointing to object in internal ram */
12008 __data unsigned char * __xdata p;
12013 pointer physically in code rom pointing to data in xdata space */
12016 unsigned char * __code p;
12020 /* pointer physically in code space pointing to
12021 data in code space */
12023 __code unsigned char * __code p;
12028 physically located in xdata space */
12030 unsigned char * __xdata p;
12035 pointer physically located in default memory space */
12042 the following is a function pointer
12043 \begin_inset LatexCommand \index{function pointer}
12047 physically located in data space */
12049 char (* __data fp)(void);
12052 \begin_layout Standard
12053 Well you get the idea.
12058 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
12071 The highest order byte of the
12075 pointers contains the data space information.
12076 Assembler support routines are called whenever data is stored or retrieved
12082 These are useful for developing reusable library
12083 \begin_inset LatexCommand \index{Libraries}
12088 Explicitly specifying the pointer
12089 \begin_inset LatexCommand \index{pointer}
12093 type will generate the most efficient code.
12096 \begin_layout Subsubsection
12097 Notes on MCS51 memory
12098 \begin_inset LatexCommand \index{MCS51 memory}
12105 \begin_layout Standard
12106 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12107 RAM memory which is structured as follows:
12111 - Bytes 00-1F - 32 bytes to hold
12112 up to 4 banks of the registers R0 to R7,
12114 - Bytes 20-2F - 16 bytes to hold
12116 \begin_inset LatexCommand \index{bit}
12122 - Bytes 30-7F - 80 bytes for general purpose use.
12127 \begin_layout Standard
12128 Additionally some members of the MCS51 family may have up to 128 bytes of
12129 additional, indirectly addressable, internal RAM memory (
12134 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12139 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12144 Furthermore, some chips may have some built in external memory (
12149 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12154 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12158 ) which should not be confused with the internal, directly addressable RAM
12164 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12169 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12174 Sometimes this built in
12178 memory has to be activated before using it (you can probably find this
12179 information on the datasheet of the microcontroller your are using, see
12181 \begin_inset LatexCommand \ref{sub:Startup-Code}
12189 \begin_layout Standard
12190 Normally SDCC will only use the first bank
12191 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12195 of registers (register bank 0), but it is possible to specify that other
12196 banks of registers (keyword
12203 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12208 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12214 ) should be used for example in interrupt
12215 \begin_inset LatexCommand \index{interrupt}
12220 \begin_inset LatexCommand \index{\_\_interrupt}
12225 By default, the compiler will place the stack after the last byte of allocated
12226 memory for variables.
12227 For example, if the first 2 banks of registers are used, and only four
12232 variables, it will position the base of the internal stack at address 20
12234 This implies that as the stack
12235 \begin_inset LatexCommand \index{stack}
12239 grows, it will use up the remaining register banks, and the 16 bytes used
12240 by the 128 bit variables, and 80 bytes for general purpose use.
12241 If any bit variables are used, the data variables will be placed in unused
12242 register banks and after the byte holding the last bit variable.
12243 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12248 variables will be placed starting from address 0x10 to 0x20 and continue
12254 \begin_layout Standard
12264 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12268 to specify the start address of the
12276 \begin_layout Standard
12286 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12290 to specify the size of the total internal RAM (
12304 \begin_layout Standard
12305 By default the 8051 linker will place the stack after the last byte of (i)data
12311 \begin_layout Standard
12321 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12325 allows you to specify the start of the stack, i.e.
12326 you could start it after any data in the general purpose area.
12327 If your microcontroller has additional indirectly addressable internal
12332 ) you can place the stack on it.
12333 You may also need to use -
12337 \begin_layout Standard
12347 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12351 to set the start address of the external RAM (
12359 \begin_layout Standard
12369 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12373 to specify its size.
12374 Same goes for the code memory, using -
12378 \begin_layout Standard
12388 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12396 \begin_layout Standard
12406 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12411 If in doubt, don't specify any options and see if the resulting memory
12412 layout is appropriate, then you can adjust it.
12415 \begin_layout Standard
12416 The linker generates two files with memory allocation information.
12417 The first, with extension .map
12418 \begin_inset LatexCommand \index{<file>.map}
12422 shows all the variables and segments.
12423 The second with extension .mem
12424 \begin_inset LatexCommand \index{<file>.mem}
12428 shows the final memory layout.
12429 The linker will complain either if memory segments overlap, there is not
12430 enough memory, or there is not enough space for stack.
12431 If you get any linking warnings and/or errors related to stack or segments
12432 allocation, take a look at either the .map or .mem files to find out what
12434 The .mem file may even suggest a solution to the problem.
12435 \begin_inset VSpace bigskip
12441 \begin_layout Subsection
12442 Z80/Z180 Storage Class
12443 \begin_inset LatexCommand \index{Z80!Storage class}
12447 Language Extensions
12450 \begin_layout Subsubsection
12452 \begin_inset LatexCommand \index{sfr}
12457 \begin_inset LatexCommand \index{\_\_sfr}
12461 (in/out to 8-bit addresses)
12464 \begin_layout Standard
12466 \begin_inset LatexCommand \index{Z80}
12470 family has separate address spaces for memory and
12480 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12485 \begin_inset LatexCommand \index{Z80!I/O memory}
12490 \begin_inset LatexCommand \index{Z180!I/O memory}
12494 is accessed with special instructions, e.g.:
12497 \begin_layout Verse
12500 sfr at 0x78 IoPort;\InsetSpace ~
12502 /* define a var in I/O space at 78h called IoPort */
12506 \begin_layout Standard
12507 Writing 0x01 to this variable generates the assembly code:
12510 \begin_layout Verse
12530 \begin_layout Subsubsection
12532 \begin_inset LatexCommand \index{sfr}
12537 \begin_inset LatexCommand \index{\_\_sfr}
12541 (in/out to 16-bit addresses)
12544 \begin_layout Standard
12549 is used to support 16 bit addresses in I/O memory e.g.:
12552 \begin_layout Verse
12556 \begin_inset LatexCommand \index{at}
12561 \begin_inset LatexCommand \index{\_\_at}
12568 \begin_layout Standard
12569 Writing 0x01 to this variable generates the assembly code:
12572 \begin_layout Verse
12575 01 23 01\InsetSpace ~
12597 \begin_layout Subsubsection
12599 \begin_inset LatexCommand \index{sfr}
12604 \begin_inset LatexCommand \index{\_\_sfr}
12608 (in0/out0 to 8 bit addresses on Z180
12609 \begin_inset LatexCommand \index{Z180}
12614 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12621 \begin_layout Standard
12622 The compiler option -
12626 \begin_layout Standard
12636 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12640 =180 (80) and a compiler #pragma\InsetSpace ~
12642 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12646 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12656 If you include the file z180.h this will be set automatically.
12657 \begin_inset VSpace bigskip
12663 \begin_layout Subsection
12665 \begin_inset LatexCommand \index{HC08!Storage class}
12669 Language Extensions
12672 \begin_layout Subsubsection
12674 \begin_inset LatexCommand \index{data (hc08 storage class)}
12679 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12686 \begin_layout Standard
12687 The data storage class declares a variable that resides in the first 256
12688 bytes of memory (the direct page).
12690 \begin_inset LatexCommand \index{HC08}
12694 is most efficient at accessing variables (especially pointers) stored here.
12697 \begin_layout Subsubsection
12699 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12704 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12711 \begin_layout Standard
12712 The xdata storage class declares a variable that can reside anywhere in
12714 This is the default if no storage class is specified.
12716 \begin_inset VSpace bigskip
12722 \begin_layout Section
12723 Absolute Addressing
12724 \begin_inset LatexCommand \index{Absolute addressing}
12731 \begin_layout Standard
12732 Data items can be assigned an absolute address with the
12735 \begin_inset LatexCommand \index{at}
12740 \begin_inset LatexCommand \index{\_\_at}
12746 keyword, in addition to a storage class, e.g.:
12749 \begin_layout Verse
12753 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12758 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12763 \begin_inset LatexCommand \index{at}
12768 \begin_inset LatexCommand \index{\_\_at}
12772 0x7ffe unsigned int chksum;
12775 \begin_layout Standard
12776 or, better conforming to ISO/IEC 9899 C:
12779 \begin_layout Verse
12782 __xdata __at (0x7ffe) unsigned int chksum;
12785 \begin_layout Standard
12786 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12787 of the external ram.
12792 reserve any space for variables declared in this way
12793 \begin_inset Marginal
12796 \begin_layout Standard
12805 (they are implemented with an equate in the assembler).
12806 Thus it is left to the programmer to make sure there are no overlaps with
12807 other variables that are declared without the absolute address.
12808 The assembler listing file (.lst
12809 \begin_inset LatexCommand \index{<file>.lst}
12813 ) and the linker output files (.rst
12814 \begin_inset LatexCommand \index{<file>.rst}
12819 \begin_inset LatexCommand \index{<file>.map}
12823 ) are good places to look for such overlaps.
12826 \begin_layout Standard
12827 If however you provide an initializer
12828 \begin_inset LatexCommand \index{Variable initialization}
12832 actual memory allocation will take place and overlaps will be detected
12837 \begin_layout Verse
12840 __code __at (0x7ff0) char Id[5] =
12841 \begin_inset Quotes sld
12845 \begin_inset Quotes srd
12851 \begin_layout Standard
12852 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
12856 \begin_layout Standard
12857 In case of memory mapped I/O devices the keyword
12861 has to be used to tell the compiler that accesses might not be removed:
12864 \begin_layout Verse
12868 \begin_inset LatexCommand \index{volatile}
12873 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12878 \begin_inset LatexCommand \index{at}
12882 (0x8000) unsigned char PORTA_8255;
12885 \begin_layout Standard
12886 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12891 \begin_inset LatexCommand \index{Aligned array}
12898 starts at a block (256 byte) boundary
12899 \begin_inset LatexCommand \index{block boundary}
12904 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12910 Absolute addresses can be specified for variables in all
12911 storage classes, e.g.:
12914 \begin_layout Verse
12918 \begin_inset LatexCommand \index{bit}
12923 \begin_inset LatexCommand \index{at}
12930 \begin_layout Standard
12931 The above example will allocate the variable at offset 0x02 in the bit-addressab
12933 There is no real advantage to assigning absolute addresses to variables
12934 in this manner, unless you want strict control over all the variables allocated.
12935 One possible use would be to write hardware portable code.
12936 For example, if you have a routine that uses one or more of the microcontroller
12937 I/O pins, and such pins are different for two different hardwares, you
12938 can declare the I/O pins in your routine using:
12941 \begin_layout Verse
12945 \begin_inset LatexCommand \index{volatile}
12949 __bit MOSI;\InsetSpace ~
12953 /* master out, slave in */
12955 extern volatile __bit MISO;\InsetSpace ~
12962 extern volatile __bit MCLK;\InsetSpace ~
12971 Output of a byte on a 3-wire serial bus.
12976 If needed adapt polarity of clock,
12977 polarity of data and bit order
12982 unsigned char spi_io(unsigned char out_byte)
13007 MOSI = out_byte & 0x80;
13038 /* _asm nop _endasm; */\InsetSpace ~
13046 /* for slow peripherals */
13098 \begin_layout Standard
13099 Then, someplace in the code for the first hardware you would use
13102 \begin_layout Verse
13106 \begin_inset LatexCommand \index{at}
13111 \begin_inset LatexCommand \index{\_\_at}
13115 (0x80) MOSI;\InsetSpace ~
13119 /* I/O port 0, bit 0 */
13121 __bit __at (0x81) MISO;\InsetSpace ~
13128 __bit __at (0x82) MCLK;\InsetSpace ~
13132 /* I/O port 0, bit 2 */
13135 \begin_layout Standard
13136 Similarly, for the second hardware you would use
13139 \begin_layout Verse
13142 __bit __at (0x83) MOSI;\InsetSpace ~
13146 /* I/O port 0, bit 3 */
13148 __bit __at (0x91) MISO;\InsetSpace ~
13153 I/O port 1, bit 1 */
13156 \begin_inset LatexCommand \index{bit}
13160 __at (0x92) MCLK;\InsetSpace ~
13164 /* I/O port 1, bit 2 */
13167 \begin_layout Standard
13168 and you can use the same hardware dependent routine without changes, as
13169 for example in a library.
13170 This is somehow similar to sbit, but only one absolute address has to be
13171 specified in the whole project.
13172 \begin_inset VSpace bigskip
13178 \begin_layout Section
13180 \begin_inset LatexCommand \index{Parameters}
13185 \begin_inset LatexCommand \index{function parameter}
13190 \begin_inset LatexCommand \index{local variables}
13195 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13202 \begin_layout Standard
13203 Automatic (local) variables and parameters to functions can either be placed
13204 on the stack or in data-space.
13205 The default action of the compiler is to place these variables in the internal
13206 RAM (for small model) or external RAM (for medium or large model).
13207 This in fact makes them similar to
13210 \begin_inset LatexCommand \index{static}
13216 so by default functions are non-reentrant
13217 \begin_inset LatexCommand \index{reentrant}
13226 They can be placed on the stack
13227 \begin_inset LatexCommand \index{stack}
13237 \begin_layout Standard
13247 \begin_inset LatexCommand \index{-\/-stack-auto}
13255 #pragma\InsetSpace ~
13259 \begin_inset LatexCommand \index{\#pragma stackauto}
13266 \begin_inset LatexCommand \index{reentrant}
13272 keyword in the function declaration, e.g.:
13275 \begin_layout Verse
13278 unsigned char foo(char i) __reentrant
13292 \begin_layout Standard
13293 Since stack space on 8051 is limited, the
13303 \begin_layout Standard
13314 option should be used sparingly.
13315 Note that the reentrant keyword just means that the parameters & local
13316 variables will be allocated to the stack, it
13320 mean that the function is register bank
13321 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13330 \begin_inset LatexCommand \index{local variables}
13334 can be assigned storage classes and absolute
13335 \begin_inset LatexCommand \index{Absolute addressing}
13342 \begin_layout Verse
13345 unsigned char foo()
13353 __xdata unsigned char i;
13366 \begin_inset LatexCommand \index{at}
13370 (0x31) unsigned char j;
13382 \begin_layout Standard
13383 In the above example the variable
13387 will be allocated in the external ram,
13391 in bit addressable space and
13402 \begin_layout Standard
13413 or when a function is declared as
13417 this should only be done for static variables.
13420 \begin_layout Standard
13422 \begin_inset LatexCommand \index{function parameter}
13426 however are not allowed any storage class
13427 \begin_inset LatexCommand \index{Storage class}
13431 , (storage classes for parameters will be ignored), their allocation is
13432 governed by the memory model in use, and the reentrancy options.
13435 \begin_layout Standard
13436 It is however allowed to use bit parameters in reentrant functions and also
13437 non-static local bit variables are supported.
13438 Efficient use is limited to 8 semi-bitregisters in bit space.
13439 They are pushed and popped to stack
13440 \begin_inset LatexCommand \index{stack}
13444 as a single byte just like the normal registers.
13447 \begin_layout Section
13449 \begin_inset LatexCommand \label{sub:Overlaying}
13454 \begin_inset LatexCommand \index{Overlaying}
13461 \begin_layout Standard
13463 \begin_inset LatexCommand \index{reentrant}
13467 functions SDCC will try to reduce internal ram space usage by overlaying
13468 parameters and local variables of a function (if possible).
13469 Parameters and local variables
13470 \begin_inset LatexCommand \index{local variables}
13474 of a function will be allocated to an overlayable segment if the function
13477 no other function calls and the function is non-reentrant and the memory
13479 \begin_inset LatexCommand \index{Memory model}
13486 If an explicit storage class
13487 \begin_inset LatexCommand \index{Storage class}
13491 is specified for a local variable, it will NOT be overlayed.
13494 \begin_layout Standard
13495 Note that the compiler (not the linkage editor) makes the decision for overlayin
13497 Functions that are called from an interrupt service routine
13498 \begin_inset Marginal
13501 \begin_layout Standard
13509 should be preceded by a #pragma\InsetSpace ~
13511 \begin_inset LatexCommand \index{\#pragma nooverlay}
13515 if they are not reentrant.
13518 \begin_layout Standard
13519 Also note that the compiler does not do any processing of inline assembler
13520 code, so the compiler might incorrectly assign local variables and parameters
13521 of a function into the overlay segment if the inline assembler code calls
13522 other c-functions that might use the overlay.
13523 In that case the #pragma\InsetSpace ~
13524 nooverlay should be used.
13527 \begin_layout Standard
13528 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13530 \begin_inset LatexCommand \index{Multiplication}
13535 \begin_inset LatexCommand \index{Division}
13539 will NOT be overlayed since these are implemented using external functions,
13543 \begin_layout Verse
13549 \begin_inset LatexCommand \index{\#pragma nooverlay}
13555 void set_error(unsigned char errcd)
13572 some_isr () __interrupt
13573 \begin_inset LatexCommand \index{interrupt}
13603 \begin_layout Standard
13604 In the above example the parameter
13612 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13614 not present, this could cause unpredictable runtime behavior when called
13615 from an interrupt service routine.
13616 The #pragma\InsetSpace ~
13617 nooverlay ensures that the parameters and local variables for
13618 the function are NOT overlayed.
13619 \begin_inset VSpace bigskip
13625 \begin_layout Section
13626 Interrupt Service Routines
13627 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13634 \begin_layout Subsection
13635 General Information
13638 \begin_layout Standard
13651 outines to be coded in C, with some extended keywords.
13654 \begin_layout Verse
13657 void timer_isr (void) __interrupt (1) __using (1)
13671 \begin_layout Standard
13672 The optional number following the
13675 \begin_inset LatexCommand \index{interrupt}
13680 \begin_inset LatexCommand \index{\_\_interrupt}
13686 keyword is the interrupt number this routine will service.
13687 When present, the compiler will insert a call to this routine in the interrupt
13689 \begin_inset LatexCommand \index{interrupt vector table}
13693 for the interrupt number specified.
13694 If you have multiple source files in your project, interrupt service routines
13695 can be present in any of them, but a prototype of the isr MUST be present
13696 or included in the file that contains the function
13701 The optional (8051 specific) keyword
13704 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13709 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13715 can be used to tell the compiler to use the specified register bank when
13716 generating code for this function.
13719 Interrupt service routines open the door for some very interesting bugs:
13722 \begin_layout Subsubsection
13723 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13727 Common interrupt pitfall: variable not declared
13732 \begin_layout Standard
13733 If an interrupt service routine changes variables which are accessed by
13734 other functions these variables have to be declared
13739 \begin_inset LatexCommand \index{volatile}
13745 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13752 \begin_layout Subsubsection
13753 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13757 Common interrupt pitfall:
13762 \begin_layout Standard
13763 If the access to these variables is not
13766 \begin_inset LatexCommand \index{atomic}
13773 the processor needs more than one instruction for the access and could
13774 be interrupted while accessing the variable) the interrupt must be disabled
13775 during the access to avoid inconsistent data.
13778 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13779 and should be protected by disabling interrupts.
13780 You're not automatically on the safe side if you use 8 bit variables though.
13781 We need an example here: f.e.
13782 on the 8051 the harmless looking
13783 \begin_inset Quotes srd
13793 \begin_inset Quotes sld
13802 \begin_inset Quotes srd
13812 \begin_inset Quotes sld
13815 from within an interrupt routine might get lost if the interrupt occurs
13818 \begin_inset Quotes sld
13823 counter\InsetSpace ~
13828 \begin_inset Quotes srd
13831 is not atomic on the 8051 even if
13835 is located in data memory.
13837 Bugs like these are hard to reproduce and can
13838 cause a lot of trouble.
13842 \begin_layout Subsubsection
13843 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13847 Common interrupt pitfall:
13852 \begin_layout Standard
13853 The return address and the registers used in the interrupt service routine
13854 are saved on the stack
13855 \begin_inset LatexCommand \index{stack}
13859 so there must be sufficient stack space.
13860 If there isn't variables or registers (or even the return address itself)
13867 \begin_inset LatexCommand \index{stack overflow}
13871 is most likely to happen if the interrupt occurs during the
13872 \begin_inset Quotes sld
13876 \begin_inset Quotes srd
13879 subroutine when the stack is already in use for f.e.
13880 many return addresses.
13883 \begin_layout Subsubsection
13884 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13888 Common interrupt pitfall:
13890 use of non-reentrant functions
13893 \begin_layout Standard
13894 A special note here, int (16 bit) and long (32 bit) integer division
13895 \begin_inset LatexCommand \index{Division}
13900 \begin_inset LatexCommand \index{Multiplication}
13905 \begin_inset LatexCommand \index{Modulus}
13910 \begin_inset LatexCommand \index{Floating point support}
13914 operations are implemented using external support routines.
13915 If an interrupt service routine needs to do any of these operations then
13916 the support routines (as mentioned in a following section) will have to
13917 be recompiled using the
13923 \begin_layout Standard
13933 \begin_inset LatexCommand \index{-\/-stack-auto}
13939 option and the source file will need to be compiled using the
13945 \begin_layout Standard
13957 \begin_inset LatexCommand \index{-\/-int-long-reent}
13964 Note, the type promotion
13965 \begin_inset LatexCommand \index{type promotion}
13969 required by ANSI C can cause 16 bit routines to be used
13970 \begin_inset Marginal
13973 \begin_layout Standard
13982 without the programmer being aware of it.
13986 (unsigned char)(tail-1)
13988 within the if clause in section
13989 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13996 \begin_layout Standard
13997 Calling other functions from an interrupt service routine is not recommended,
13998 avoid it if possible.
13999 Note that when some function is called from an interrupt service routine
14000 it should be preceded by a #pragma\InsetSpace ~
14002 \begin_inset LatexCommand \index{\#pragma nooverlay}
14006 if it is not reentrant.
14007 Furthermore nonreentrant functions should not be called from the main program
14008 while the interrupt service routine might be active.
14009 They also must not be called from low priority interrupt service routines
14010 while a high priority interrupt service routine might be active.
14011 You could use semaphores or make the function
14015 if all parameters are passed in registers.
14018 \begin_inset LatexCommand \ref{sub:Overlaying}
14023 about Overlaying and section
14024 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14029 about Functions using private register banks.
14030 \begin_inset VSpace bigskip
14036 \begin_layout Subsection
14037 MCS51/DS390 Interrupt Service Routines
14040 \begin_layout Standard
14042 \begin_inset LatexCommand \index{interrupt}
14046 numbers and the corresponding address & descriptions for the Standard 8051/8052
14048 SDCC will automatically adjust the
14049 \begin_inset LatexCommand \index{interrupt vector table}
14053 to the maximum interrupt number specified.
14058 \begin_layout Standard
14060 \begin_inset Tabular
14061 <lyxtabular version="3" rows="9" columns="3">
14063 <column alignment="center" valignment="top" leftline="true" width="0in">
14064 <column alignment="left" valignment="top" leftline="true" width="0in">
14065 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14066 <row topline="true" bottomline="true">
14067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14070 \begin_layout Standard
14076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14079 \begin_layout Standard
14085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14088 \begin_layout Standard
14095 <row topline="true">
14096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14099 \begin_layout Standard
14105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14108 \begin_layout Standard
14114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14117 \begin_layout Standard
14124 <row topline="true">
14125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14128 \begin_layout Standard
14134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14137 \begin_layout Standard
14143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14146 \begin_layout Standard
14153 <row topline="true">
14154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14157 \begin_layout Standard
14163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14166 \begin_layout Standard
14172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14175 \begin_layout Standard
14182 <row topline="true">
14183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14186 \begin_layout Standard
14192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14195 \begin_layout Standard
14201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14204 \begin_layout Standard
14211 <row topline="true">
14212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14215 \begin_layout Standard
14221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14224 \begin_layout Standard
14230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14233 \begin_layout Standard
14240 <row topline="true">
14241 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14244 \begin_layout Standard
14250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14253 \begin_layout Standard
14259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14262 \begin_layout Standard
14269 <row topline="true">
14270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14273 \begin_layout Standard
14279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14282 \begin_layout Standard
14288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14291 \begin_layout Standard
14298 <row topline="true" bottomline="true">
14299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14302 \begin_layout Standard
14308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14311 \begin_layout Standard
14317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14320 \begin_layout Standard
14336 \begin_layout Standard
14337 If the interrupt service routine is defined without
14340 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14345 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14351 a register bank or with register bank 0 (
14355 0), the compiler will save the registers used by itself on the stack upon
14356 entry and restore them at exit, however if such an interrupt service routine
14357 calls another function then the entire register bank will be saved on the
14359 This scheme may be advantageous for small interrupt service routines which
14360 have low register usage.
14363 \begin_layout Standard
14364 If the interrupt service routine is defined to be using a specific register
14369 & psw are saved and restored, if such an interrupt service routine calls
14370 another function (using another register bank) then the entire register
14371 bank of the called function will be saved on the stack
14372 \begin_inset LatexCommand \index{stack}
14377 This scheme is recommended for larger interrupt service routines.
14378 \begin_inset VSpace bigskip
14384 \begin_layout Subsection
14386 \begin_inset LatexCommand \index{HC08}
14390 Interrupt Service Routines
14393 \begin_layout Standard
14394 Since the number of interrupts
14395 \begin_inset LatexCommand \index{HC08!interrupt}
14399 available is chip specific and the interrupt vector table always ends at
14400 the last byte of memory, the interrupt numbers corresponds to the interrupt
14401 vectors in reverse order of address.
14402 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14403 2 will use the interrupt vector at 0xfffa, and so on.
14404 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14405 this way; instead see section
14406 \begin_inset LatexCommand \ref{sub:Startup-Code}
14410 for details on customizing startup.
14411 \begin_inset VSpace bigskip
14417 \begin_layout Subsection
14418 Z80 Interrupt Service Routines
14421 \begin_layout Standard
14423 \begin_inset LatexCommand \index{Z80}
14427 uses several different methods for determining the correct interrupt
14428 \begin_inset LatexCommand \index{Z80!interrupt}
14432 vector depending on the hardware implementation.
14433 Therefore, SDCC ignores the optional interrupt number and does not attempt
14434 to generate an interrupt vector table.
14437 \begin_layout Standard
14438 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14439 instruction to return from the interrupt.
14440 To write an interrupt handler for the non-maskable interrupt, which needs
14441 a RETN instruction instead, add the
14448 \begin_layout Verse
14451 void nmi_isr (void) critical interrupt
14465 \begin_layout Standard
14466 However if you need to create a non-interruptable interrupt service routine
14467 you would also require the
14472 To distinguish between this and an nmi_isr you must provide an interrupt
14474 \begin_inset VSpace bigskip
14480 \begin_layout Section
14481 Enabling and Disabling Interrupts
14484 \begin_layout Subsection
14485 Critical Functions and Critical Statements
14488 \begin_layout Standard
14489 A special keyword may be associated with a block or a function declaring
14495 SDCC will generate code to disable all interrupts
14496 \begin_inset LatexCommand \index{interrupt}
14500 upon entry to a critical function and restore the interrupt enable to the
14501 previous state before returning.
14502 Nesting critical functions will need one additional byte on the stack
14503 \begin_inset LatexCommand \index{stack}
14510 \begin_layout Verse
14513 int foo () __critical
14514 \begin_inset LatexCommand \index{critical}
14519 \begin_inset LatexCommand \index{\_\_critical}
14544 \begin_layout Standard
14545 The critical attribute maybe used with other attributes like
14555 may also be used to disable interrupts more locally:
14558 \begin_layout Verse
14564 \begin_layout Standard
14565 More than one statement could have been included in the block.
14568 \begin_layout Subsection
14569 Enabling and Disabling Interrupts directly
14572 \begin_layout Standard
14574 \begin_inset LatexCommand \index{interrupt}
14578 can also be disabled and enabled directly (8051):
14581 \begin_layout Verse
14584 EA = 0;\InsetSpace ~
14610 \begin_layout Verse
14646 \begin_layout Verse
14649 EA = 1;\InsetSpace ~
14678 \begin_layout Verse
14717 \begin_layout Standard
14718 On other architectures which have seperate opcodes for enabling and disabling
14719 interrupts you might want to make use of defines with inline assembly
14720 \begin_inset LatexCommand \index{Assembler routines}
14725 \begin_inset LatexCommand \index{HC08!interrupt}
14732 \begin_layout Verse
14736 \begin_inset LatexCommand \index{\_asm}
14745 \begin_inset LatexCommand \index{\_endasm}
14752 \begin_layout Verse
14755 #define SEI _asm\InsetSpace ~
14762 \begin_layout Verse
14768 \begin_layout Standard
14769 Note: it is sometimes sufficient to disable only a specific interrupt source
14771 a timer or serial interrupt by manipulating an
14774 \begin_inset LatexCommand \index{interrupt mask}
14784 \begin_layout Standard
14785 Usually the time during which interrupts are disabled should be kept as
14787 This minimizes both
14792 \begin_inset LatexCommand \index{interrupt latency}
14796 (the time between the occurrence of the interrupt and the execution of
14797 the first code in the interrupt routine) and
14802 \begin_inset LatexCommand \index{interrupt jitter}
14806 (the difference between the shortest and the longest interrupt latency).
14807 These really are something different, f.e.
14808 a serial interrupt has to be served before its buffer overruns so it cares
14809 for the maximum interrupt latency, whereas it does not care about jitter.
14810 On a loudspeaker driven via a digital to analog converter which is fed
14811 by an interrupt a latency of a few milliseconds might be tolerable, whereas
14812 a much smaller jitter will be very audible.
14815 \begin_layout Standard
14816 You can reenable interrupts within an interrupt routine and on some architecture
14817 s you can make use of two (or more) levels of
14819 interrupt priorities
14822 \begin_inset LatexCommand \index{interrupt priority}
14827 On some architectures which don't support interrupt priorities these can
14828 be implemented by manipulating the interrupt mask and reenabling interrupts
14829 within the interrupt routine.
14830 Check there is sufficient space on the stack
14831 \begin_inset LatexCommand \index{stack}
14835 and don't add complexity unless you have to.
14839 \begin_layout Subsection
14841 \begin_inset LatexCommand \index{semaphore}
14845 locking (mcs51/ds390)
14848 \begin_layout Standard
14849 Some architectures (mcs51/ds390) have an atomic
14850 \begin_inset LatexCommand \index{atomic}
14863 These type of instructions are typically used in preemptive multitasking
14864 systems, where a routine f.e.
14865 claims the use of a data structure ('acquires a lock
14866 \begin_inset LatexCommand \index{lock}
14870 on it'), makes some modifications and then releases the lock when the data
14871 structure is consistent again.
14872 The instruction may also be used if interrupt and non-interrupt code have
14873 to compete for a resource.
14874 With the atomic bit test and clear instruction interrupts
14875 \begin_inset LatexCommand \index{interrupt}
14879 don't have to be disabled for the locking operation.
14883 \begin_layout Standard
14884 SDCC generates this instruction if the source follows this pattern:
14887 \begin_layout Verse
14891 \begin_inset LatexCommand \index{volatile}
14895 bit resource_is_free;
14899 if (resource_is_free)
14909 resource_is_free=0;
14922 resource_is_free=1;
14929 \begin_layout Standard
14930 Note, mcs51 and ds390 support only an atomic
14931 \begin_inset LatexCommand \index{atomic}
14939 instruction (as opposed to atomic bit test and
14944 \begin_layout Section
14945 Functions using private register banks
14946 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14953 \begin_layout Standard
14954 Some architectures have support for quickly changing register sets.
14955 SDCC supports this feature with the
14958 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14963 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14969 attribute (which tells the compiler to use a register bank
14970 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14974 other than the default bank zero).
14975 It should only be applied to
14978 \begin_inset LatexCommand \index{interrupt}
14984 functions (see footnote below).
14985 This will in most circumstances make the generated ISR code more efficient
14986 since it will not have to save registers on the stack.
14989 \begin_layout Standard
14994 attribute will have no effect on the generated code for a
14998 function (but may occasionally be useful anyway
15002 \begin_layout Standard
15003 possible exception: if a function is called ONLY from 'interrupt' functions
15004 using a particular bank, it can be declared with the same 'using' attribute
15005 as the calling 'interrupt' functions.
15006 For instance, if you have several ISRs using bank one, and all of them
15007 call memcpy(), it might make sense to create a specialized version of memcpy()
15008 'using 1', since this would prevent the ISR from having to save bank zero
15009 to the stack on entry and switch to bank zero before calling the function
15018 (pending: Note, nowadays the
15022 attribute has an effect on
15026 the generated code for a
15037 \begin_layout Standard
15042 function using a non-zero bank will assume that it can trash that register
15043 bank, and will not save it.
15044 Since high-priority interrupts
15045 \begin_inset LatexCommand \index{interrupts}
15050 \begin_inset LatexCommand \index{interrupt priority}
15054 can interrupt low-priority ones on the 8051 and friends, this means that
15055 if a high-priority ISR
15059 a particular bank occurs while processing a low-priority ISR
15063 the same bank, terrible and bad things can happen.
15064 To prevent this, no single register bank should be
15068 by both a high priority and a low priority ISR.
15069 This is probably most easily done by having all high priority ISRs use
15070 one bank and all low priority ISRs use another.
15071 If you have an ISR which can change priority at runtime, you're on your
15072 own: I suggest using the default bank zero and taking the small performance
15076 \begin_layout Standard
15077 It is most efficient if your ISR calls no other functions.
15078 If your ISR must call other functions, it is most efficient if those functions
15079 use the same bank as the ISR (see note 1 below); the next best is if the
15080 called functions use bank zero.
15081 It is very inefficient to call a function using a different, non-zero bank
15084 \begin_inset VSpace bigskip
15090 \begin_layout Section
15092 \begin_inset LatexCommand \label{sub:Startup-Code}
15097 \begin_inset LatexCommand \index{Startup code}
15104 \begin_layout Subsection
15105 MCS51/DS390 Startup Code
15108 \begin_layout Standard
15109 The compiler triggers the linker to link certain initialization modules
15110 from the runtime library
15111 \begin_inset LatexCommand \index{Runtime library}
15115 called crt<something>.
15116 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15117 GSINIT5) is not linked unless the --xstack option is used.
15118 These modules are highly entangled by the use of special segments/areas,
15119 but a common layout is shown below:
15122 \begin_layout Verse
15130 \begin_layout Verse
15154 ljmp __sdcc_gsinit_startup
15157 \begin_layout Verse
15165 \begin_layout Verse
15177 .area GSINIT0 (CODE)
15179 __sdcc_gsinit_startup::
15189 mov sp,#__start__stack - 1
15192 \begin_layout Verse
15200 \begin_layout Verse
15212 .area GSINIT1 (CODE)
15214 __sdcc_init_xstack::
15216 ; Need to initialize in GSINIT1 in
15217 case the user's __sdcc_external_startup uses the xstack.
15227 mov __XPAGE,#(__start__x
15238 mov _spx,#__start__xstack
15241 \begin_layout Verse
15249 \begin_layout Verse
15261 .area GSINIT2 (CODE)
15271 lcall __sdcc_external_startup
15291 jz __sdcc_init_data
15302 __sdcc_program_startup
15307 \begin_layout Verse
15315 \begin_layout Verse
15327 .area GSINIT3 (CODE)
15380 mov r2,#((l_XINIT+255) >> 8)
15411 __XPAGE,#(s_XISEG >> 8)
15413 00001$:\InsetSpace ~
15477 00002$:\InsetSpace ~
15504 \begin_layout Verse
15512 \begin_layout Verse
15524 .area GSINIT4 (CODE)
15526 __mcs51_genRAMCLEAR::
15548 00004$:\InsetSpace ~
15562 ; _mcs51_genRAMCLEAR() end
15565 \begin_layout Verse
15573 \begin_layout Verse
15585 .area GSINIT4 (CODE)
15587 __mcs51_genXRAMCLEAR::
15638 mov __XPAGE,#(s_PSEG >> 8)
15650 00005$:\InsetSpace ~
15704 orl a,#(l_XSEG >> 8)
15747 00007$:\InsetSpace ~
15784 \begin_layout Verse
15792 \begin_layout Verse
15804 .area GSINIT5 (CODE)
15806 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15809 ; and __mcs51_genRAMCLEAR modifies _spx.
15819 mov __XPAGE,#(__start__x
15830 mov _spx,#__start__xstack
15833 \begin_layout Verse
15838 (application modules)
15841 \begin_layout Verse
15853 .area GSINIT (CODE)
15856 \begin_layout Verse
15864 \begin_layout Verse
15876 .area GSFINAL (CODE)
15886 ljmp __sdcc_program_startup
15888 ;---------------------------------
15889 -----------------------
15893 ;--------------------------------------------------
15916 __sdcc_program_startup:
15929 return from main will lock up
15942 \begin_layout Standard
15943 One of these modules (crtstart.asm) contains a call to the C routine
15945 _sdcc_external_startup()
15946 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15955 at the start of the CODE area.
15956 This routine is also in the runtime library
15957 \begin_inset LatexCommand \index{Runtime library}
15961 and returns 0 by default.
15962 If this routine returns a non-zero value, the static & global variable
15963 initialization will be skipped and the function main will be invoked.
15964 Otherwise static & global variables will be initialized before the function
15968 _sdcc_external_startup()
15970 routine to your program to override the default if you need to setup hardware
15971 or perform some other critical operation prior to static & global variable
15973 \begin_inset LatexCommand \index{Variable initialization}
15978 On some mcs51 variants xdata
15979 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15983 memory has to be explicitly enabled before it can be accessed or if the
15985 \begin_inset LatexCommand \index{watchdog}
15989 needs to be disabled, this is the place to do it.
15990 The startup code clears all internal data memory, 256 bytes by default,
15991 but from 0 to n-1 if
15997 \begin_layout Standard
16007 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16014 (recommended for Chipcon CC1010).
16017 \begin_layout Standard
16018 See also the compiler options
16024 \begin_layout Standard
16040 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16050 \begin_layout Standard
16062 \begin_inset LatexCommand \index{-\/-main-return}
16067 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16071 about MCS51-variants.
16072 \begin_inset VSpace bigskip
16078 \begin_layout Subsection
16082 \begin_layout Standard
16084 \begin_inset LatexCommand \index{HC08}
16088 startup code follows the same scheme as the MCS51 startup code.
16089 \begin_inset VSpace bigskip
16095 \begin_layout Subsection
16099 \begin_layout Standard
16101 \begin_inset LatexCommand \index{Z80}
16105 the startup code is inserted by linking with crt0.o which is generated from
16106 sdcc/device/lib/z80/crt0.s.
16107 If you need a different startup code you can use the compiler option
16116 \begin_layout Standard
16131 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16135 and provide your own crt0.o.
16137 \begin_inset VSpace bigskip
16143 \begin_layout Section
16144 Inline Assembler Code
16145 \begin_inset LatexCommand \index{Assembler routines}
16152 \begin_layout Subsection
16153 A Step by Step Introduction
16154 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16161 \begin_layout Standard
16162 Starting from a small snippet of c-code this example shows for the MCS51
16163 how to use inline assembly, access variables, a function parameter and
16164 an array in xdata memory.
16165 The example uses an MCS51 here but is easily adapted for other architectures.
16166 This is a buffer routine which should be optimized:
16169 \begin_layout Verse
16173 unsigned char __far
16174 \begin_inset LatexCommand \index{far (storage class)}
16179 \begin_inset LatexCommand \index{\_\_far (storage class)}
16184 \begin_inset LatexCommand \index{at}
16189 \begin_inset LatexCommand \index{\_\_at}
16193 (0x7f00) buf[0x100];
16194 \begin_inset LatexCommand \index{Aligned array}
16200 unsigned char head, tail;\InsetSpace ~
16218 \begin_inset LatexCommand \index{interrupt}
16270 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16282 void to_buffer( unsigned char c )
16290 if( head != (unsigned char)(tail-1)
16297 \begin_inset LatexCommand \index{promotion to signed int}
16302 \begin_inset LatexCommand \index{type promotion}
16307 \begin_inset Marginal
16310 \begin_layout Standard
16329 buf[ head++ ] = c;\InsetSpace ~
16345 /* access to a 256 byte aligned array */
16350 \begin_layout Standard
16351 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16352 then a corresponding buffer.asm file is generated.
16353 We define a new function
16357 in file buffer.c in which we cut and paste the generated code, removing
16358 unwanted comments and some ':'.
16360 \begin_inset Quotes sld
16368 \begin_inset Quotes srd
16372 \begin_inset Quotes sld
16380 \begin_inset Quotes srd
16387 \begin_layout Standard
16388 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16389 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16391 The latter is also used in the library functions.
16396 to the beginning and the end of the function body:
16399 \begin_layout Verse
16403 /* With a cut and paste from the .asm file, we have something to start with.
16409 function is not yet OK! (registers aren't saved) */
16411 void to_buffer_asm(
16421 \begin_inset LatexCommand \index{\_asm}
16426 \begin_inset LatexCommand \index{\_\_asm}
16440 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16446 \begin_inset LatexCommand \index{promotion to signed int}
16451 \begin_inset LatexCommand \index{type promotion}
16504 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16505 \begin_inset LatexCommand \index{Aligned array}
16571 \begin_inset LatexCommand \index{\_endasm}
16576 \begin_inset LatexCommand \index{\_\_endasm}
16585 \begin_layout Standard
16586 The new file buffer.c should compile with only one warning about the unreferenced
16587 function argument 'c'.
16588 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16589 (1) and finally have:
16592 \begin_layout Verse
16596 unsigned char __far __at(0x7f00) buf[0x100];
16598 unsigned char head, tail;
16609 void to_buffer( unsigned char c )
16618 head != (unsigned char)(tail-1) )
16647 c; // to avoid warning: unreferenced function argument
16654 \begin_inset LatexCommand \index{\_asm}
16659 \begin_inset LatexCommand \index{\_\_asm}
16673 ; save used registers here.
16684 ; If we were still using r2,r3 we would have to push them here.
16687 ; if( head != (unsigned char)(tail-1) )
16731 could do an ANL a,#0x0f here to use a smaller buffer (see below)
16767 a,dpl \InsetSpace ~
16774 ; dpl holds lower byte of function argument
16786 dpl,_head \InsetSpace ~
16789 ; buf is 0x100 byte aligned so head can be used directly
16832 ; we could do an ANL _head,#0x0f here to use a
16833 smaller buffer (see above)
16845 ; restore used registers here
16852 \begin_inset LatexCommand \index{\_endasm}
16857 \begin_inset LatexCommand \index{\_\_endasm}
16868 \begin_layout Standard
16869 The inline assembler code can contain any valid code understood by the assembler
16870 , this includes any assembler directives and comment lines.
16871 The assembler does not like some characters like ':' or ''' in comments.
16872 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16873 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16878 \begin_inset LatexCommand \index{Assembler documentation}
16883 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16891 \begin_layout Standard
16892 The compiler does not do any validation of the code within the
16895 \begin_inset LatexCommand \index{\_asm}
16900 \begin_inset LatexCommand \index{\_\_asm}
16908 \begin_inset LatexCommand \index{\_endasm}
16913 \begin_inset LatexCommand \index{\_\_endasm}
16922 Specifically it will not know which registers are used and thus register
16924 \begin_inset LatexCommand \index{push/pop}
16928 has to be done manually.
16932 \begin_layout Standard
16933 It is recommended that each assembly instruction (including labels) be placed
16934 in a separate line (as the example shows).
16939 \begin_layout Standard
16951 \begin_inset LatexCommand \index{-\/-peep-asm}
16957 command line option is used, the inline assembler code will be passed through
16958 the peephole optimizer
16959 \begin_inset LatexCommand \index{Peephole optimizer}
16964 There are only a few (if any) cases where this option makes sense, it might
16965 cause some unexpected changes in the inline assembler code.
16966 Please go through the peephole optimizer rules defined in file
16970 before using this option.
16973 \begin_layout Subsection
16975 \begin_inset LatexCommand \label{sub:Naked-Functions}
16980 \begin_inset LatexCommand \index{Naked functions}
16987 \begin_layout Standard
16988 A special keyword may be associated with a function declaring it as
16991 \begin_inset LatexCommand \index{\_naked}
16996 \begin_inset LatexCommand \index{\_\_naked}
17007 function modifier attribute prevents the compiler from generating prologue
17008 \begin_inset LatexCommand \index{function prologue}
17013 \begin_inset LatexCommand \index{function epilogue}
17017 code for that function.
17018 This means that the user is entirely responsible for such things as saving
17019 any registers that may need to be preserved, selecting the proper register
17020 bank, generating the
17024 instruction at the end, etc.
17025 Practically, this means that the contents of the function must be written
17026 in inline assembler.
17027 This is particularly useful for interrupt functions, which can have a large
17028 (and often unnecessary) prologue/epilogue.
17029 For example, compare the code generated by these two functions:
17032 \begin_layout Verse
17036 \begin_inset LatexCommand \index{volatile}
17040 data unsigned char counter;
17044 void simpleInterrupt(void) __interrupt
17045 \begin_inset LatexCommand \index{interrupt}
17050 \begin_inset LatexCommand \index{\_\_interrupt}
17068 void nakedInterrupt(void) __interrupt (2) __naked
17077 \begin_inset LatexCommand \index{\_asm}
17082 \begin_inset LatexCommand \index{\_\_asm}
17099 _counter ; does not change flags, no need to save psw
17112 include ret or reti in _naked function.
17119 \begin_inset LatexCommand \index{\_endasm}
17124 \begin_inset LatexCommand \index{\_\_endasm}
17133 \begin_layout Standard
17134 For an 8051 target, the generated simpleInterrupt looks like:
17137 \begin_layout Verse
17144 example, recent versions of SDCC generate
17150 code for simpleInterrupt() and nakedInterrupt()!
17291 \begin_layout Standard
17292 whereas nakedInterrupt looks like:
17295 \begin_layout Verse
17308 _counter ; does not change flags, no need to save psw
17327 MUST explicitly include ret or reti in _naked function
17330 \begin_layout Standard
17331 The related directive #pragma exclude
17332 \begin_inset LatexCommand \index{\#pragma exclude}
17336 allows a more fine grained control over pushing & popping
17337 \begin_inset LatexCommand \index{push/pop}
17344 \begin_layout Standard
17345 While there is nothing preventing you from writing C code inside a
17349 function, there are many ways to shoot yourself in the foot doing this,
17350 and it is recommended that you stick to inline assembler.
17353 \begin_layout Subsection
17354 Use of Labels within Inline Assembler
17357 \begin_layout Standard
17358 SDCC allows the use of in-line assembler with a few restrictions regarding
17360 All labels defined within inline assembler code have to be of the form
17365 where nnnnn is a number less than 100 (which implies a limit of utmost
17366 100 inline assembler labels
17377 \begin_layout Standard
17378 This is a slightly more stringent rule than absolutely necessary, but stays
17379 always on the safe side.
17380 Labels in the form of nnnnn$ are local labels in the assembler, locality
17381 of which is confined within two labels of the standard form.
17382 The compiler uses the same form for labels within a function (but starting
17383 from nnnnn=00100); and places always a standard label at the beginning
17384 of a function, thus limiting the locality of labels within the scope of
17386 So, if the inline assembler part would be embedded into C-code, an improperly
17387 placed non-local label in the assembler would break up the reference space
17388 for labels created by the compiler for the C-code, leading to an assembling
17392 \begin_layout Standard
17393 The numeric part of local labels does not need to have 5 digits (although
17394 this is the form of labels output by the compiler), any valid integer will
17396 Please refer to the assemblers documentation for further details.
17404 \begin_layout Verse
17408 \begin_inset LatexCommand \index{\_asm}
17413 \begin_inset LatexCommand \index{\_\_asm}
17443 \begin_inset LatexCommand \index{\_endasm}
17448 \begin_inset LatexCommand \index{\_\_endasm}
17455 \begin_layout Standard
17456 Inline assembler code cannot reference any C-labels, however it can reference
17458 \begin_inset LatexCommand \index{Labels}
17462 defined by the inline assembler, e.g.:
17465 \begin_layout Verse
17488 ; some assembler code
17509 /* some more c code */
17511 clabel:\InsetSpace ~
17513 /* inline assembler cannot reference this
17518 \begin_layout Standard
17523 is translated by the compiler into a local label, so the locality of labels
17524 within the function is not broken.
17541 0003$: ;label (can be referenced by inline assembler only)
17548 \begin_inset LatexCommand \index{\_endasm}
17553 \begin_inset LatexCommand \index{\_\_endasm}
17563 /* some more c code */
17568 \begin_layout Standard
17569 In other words inline assembly code can access labels defined in inline
17570 assembly within the scope of the function.
17571 The same goes the other way, i.e.
17572 labels defines in inline assembly can not be accessed by C statements.
17575 \begin_layout Section
17576 Interfacing with Assembler Code
17577 \begin_inset LatexCommand \index{Assembler routines}
17584 \begin_layout Subsection
17585 Global Registers used for Parameter Passing
17586 \begin_inset LatexCommand \index{Parameter passing}
17593 \begin_layout Standard
17594 The compiler always uses the global registers
17597 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17602 \begin_inset LatexCommand \index{DPTR}
17607 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17616 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17622 to pass the first (non-bit) parameter to a function, and also to pass the
17624 \begin_inset LatexCommand \index{return value}
17628 of function; according to the following scheme: one byte return value in
17633 , two byte value in
17642 three byte values (generic pointers) in
17654 , and four byte values in
17672 \begin_inset LatexCommand \index{generic pointer}
17676 contain type of accessed memory in
17697 \begin_inset Note Note
17700 \begin_layout Standard
17701 This might not be the case of certain memory models (medium???)
17709 \begin_layout Standard
17710 The second parameter onwards is either allocated on the stack (for reentrant
17715 \begin_layout Standard
17724 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17727 \begin_layout Standard
17728 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
17729 space for reentrant functions or allocated directly in bit memory otherwise.
17732 \begin_layout Standard
17733 Functions (with two or more parameters or bit parameters) that are called
17734 through function pointers
17735 \begin_inset LatexCommand \index{function pointers}
17739 must therefor be reentrant so the compiler knows how to pass the parameters.
17742 \begin_layout Subsection
17746 \begin_layout Standard
17747 Unless the called function is declared as
17752 \begin_inset LatexCommand \index{naked}
17760 \begin_layout Standard
17770 \begin_inset LatexCommand \index{-\/-callee-saves}
17778 \begin_layout Standard
17787 -all-callee-saves command line option or the corresponding callee_saves
17788 pragma are used, the caller will save the registers (
17792 ) around the call, so the called function can destroy they content freely.
17795 \begin_layout Standard
17796 If the called function is not declared as
17800 , the caller will swap register banks around the call, if caller and callee
17801 use different register banks (having them defined by the
17809 \begin_layout Standard
17810 The called function can also use
17826 observing that they are used for parameter/return value passing.
17829 \begin_layout Subsection
17830 Assembler Routine (non-reentrant)
17833 \begin_layout Standard
17834 In the following example
17835 \begin_inset LatexCommand \index{reentrant}
17840 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17844 the function c_func calls an assembler routine asm_func, which takes two
17846 \begin_inset LatexCommand \index{function parameter}
17853 \begin_layout Verse
17856 extern int asm_func(unsigned char, unsigned char);
17860 int c_func (unsigned char
17861 i, unsigned char j)
17869 return asm_func(i,j);
17883 return c_func(10,9);
17888 \begin_layout Standard
17889 The corresponding assembler function is:
17892 \begin_layout Verse
17895 .globl _asm_func_PARM_2
17997 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18014 \begin_layout Standard
18015 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18016 the parameter number starting from 1, and counting from the left.
18017 The first parameter is passed in
18033 according to the description above.
18034 The variable name for the second parameter will be _<function_name>_PARM_2.
18039 ble the assembler routine with the following command:
18046 asx8051 -losg asmfunc.asm
18053 Then compile and link the assembler routine to the C source file with the
18061 sdcc cfunc.c asmfunc.rel
18064 \begin_layout Subsection
18065 Assembler Routine (reentrant)
18068 \begin_layout Standard
18070 \begin_inset LatexCommand \index{reentrant}
18075 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18079 the second parameter
18080 \begin_inset LatexCommand \index{function parameter}
18084 onwards will be passed on the stack, the parameters are pushed from right
18086 before the call the second leftmost parameter will be on the top of the
18087 stack (the leftmost parameter is passed in registers).
18088 Here is an example:
18091 \begin_layout Verse
18094 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18099 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
18108 return asm_func(i,j,k);
18122 return c_func(10,9,8);
18127 \begin_layout Standard
18128 The corresponding (unoptimized) assembler routine is:
18131 \begin_layout Verse
18151 _bp,sp\InsetSpace ~
18157 ;stack contains: _bp, return
18158 address, second parameter, third parameter
18182 a,#0xfd\InsetSpace ~
18188 pointer to the second parameter
18212 a,#0xfc\InsetSpace ~
18218 to the rightmost parameter
18259 result (= sum of all three parameters)
18274 ;return value goes into dptr
18308 \begin_layout Standard
18309 The compiling and linking procedure remains the same, however note the extra
18310 entry & exit linkage required for the assembler code, _bp is the stack
18311 frame pointer and is used to compute the offset into the stack for parameters
18312 and local variables.
18313 \begin_inset VSpace bigskip
18319 \begin_layout Section
18321 \begin_inset LatexCommand \index{int (16 bit)}
18326 \begin_inset LatexCommand \index{long (32 bit)}
18333 \begin_layout Standard
18334 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18335 multiplication and modulus operations are implemented by support routines.
18336 These support routines are all developed in ANSI-C to facilitate porting
18337 to other MCUs, although some model specific assembler optimizations are
18339 The following files contain the described routines, all of them can be
18340 found in <installdir>/share/sdcc/lib.
18345 \begin_layout Standard
18347 \begin_inset Tabular
18348 <lyxtabular version="3" rows="11" columns="2">
18350 <column alignment="left" valignment="top" leftline="true" width="0">
18351 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18352 <row topline="true" bottomline="true">
18353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18356 \begin_layout Standard
18364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18367 \begin_layout Standard
18376 <row topline="true">
18377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18380 \begin_layout Standard
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18389 \begin_layout Standard
18390 16 bit multiplication
18396 <row topline="true">
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18400 \begin_layout Standard
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18409 \begin_layout Standard
18410 signed 16 bit division (calls _divuint)
18416 <row topline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18420 \begin_layout Standard
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18429 \begin_layout Standard
18430 unsigned 16 bit division
18436 <row topline="true">
18437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18440 \begin_layout Standard
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18449 \begin_layout Standard
18450 signed 16 bit modulus (calls _moduint)
18456 <row topline="true">
18457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18460 \begin_layout Standard
18466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18469 \begin_layout Standard
18470 unsigned 16 bit modulus
18476 <row topline="true">
18477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18480 \begin_layout Standard
18486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18489 \begin_layout Standard
18490 32 bit multiplication
18496 <row topline="true">
18497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18500 \begin_layout Standard
18506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18509 \begin_layout Standard
18510 signed 32 division (calls _divulong)
18516 <row topline="true">
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18520 \begin_layout Standard
18526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18529 \begin_layout Standard
18530 unsigned 32 division
18536 <row topline="true">
18537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18540 \begin_layout Standard
18546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18549 \begin_layout Standard
18550 signed 32 bit modulus (calls _modulong)
18556 <row topline="true" bottomline="true">
18557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18560 \begin_layout Standard
18566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18569 \begin_layout Standard
18570 unsigned 32 bit modulus
18585 \begin_layout Standard
18586 Since they are compiled as
18591 \begin_inset LatexCommand \index{reentrant}
18596 \begin_inset LatexCommand \index{interrupt}
18600 service routines should not do any of the above operations.
18601 If this is unavoidable then the above routines will need to be compiled
18608 \begin_layout Standard
18618 \begin_inset LatexCommand \index{-\/-stack-auto}
18624 option, after which the source program will have to be compiled with
18630 \begin_layout Standard
18640 \begin_inset LatexCommand \index{-\/-int-long-reent}
18647 Notice that you don't have to call these routines directly.
18648 The compiler will use them automatically every time an integer operation
18652 \begin_layout Section
18653 Floating Point Support
18654 \begin_inset LatexCommand \index{Floating point support}
18661 \begin_layout Standard
18662 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18663 The floating point support routines are derived from gcc's floatlib.c and
18664 consist of the following routines:
18669 \begin_layout Standard
18673 \begin_inset Tabular
18674 <lyxtabular version="3" rows="17" columns="2">
18676 <column alignment="left" valignment="top" leftline="true" width="0">
18677 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18678 <row topline="true" bottomline="true">
18679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18682 \begin_layout Standard
18697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18700 \begin_layout Standard
18707 <row topline="true">
18708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18711 \begin_layout Standard
18726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18729 \begin_layout Standard
18739 add floating point numbers
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 subtract floating point numbers
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 divide floating point numbers
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 multiply floating point numbers
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 floating point to unsigned char
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 floating point to signed char
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 floating point to unsigned int
18973 <row topline="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 floating point to signed int
19011 <row topline="true">
19012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19015 \begin_layout Standard
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19041 \begin_layout Standard
19051 convert floating point to unsigned long
19057 <row topline="true">
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19061 \begin_layout Standard
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19079 \begin_layout Standard
19089 convert floating point to signed long
19095 <row topline="true">
19096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19099 \begin_layout Standard
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19117 \begin_layout Standard
19127 convert unsigned char to floating point
19133 <row topline="true">
19134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19137 \begin_layout Standard
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19155 \begin_layout Standard
19165 convert char to floating point number
19171 <row topline="true">
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19175 \begin_layout Standard
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19193 \begin_layout Standard
19203 convert unsigned int to floating point
19209 <row topline="true">
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19213 \begin_layout Standard
19228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19231 \begin_layout Standard
19241 convert int to floating point numbers
19247 <row topline="true">
19248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19251 \begin_layout Standard
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19269 \begin_layout Standard
19279 convert unsigned long to floating point number
19285 <row topline="true" bottomline="true">
19286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19289 \begin_layout Standard
19304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19307 \begin_layout Standard
19317 convert long to floating point number
19332 \begin_layout Standard
19333 These support routines are developed in ANSI-C so there is room for space
19334 and speed improvement
19338 \begin_layout Standard
19339 These floating point routines (
19343 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19350 Note if all these routines are used simultaneously the data space might
19352 For serious floating point usage the large model might be needed.
19353 Also notice that you don't have to call this routines directly.
19354 The compiler will use them automatically every time a floating point operation
19356 \begin_inset VSpace bigskip
19362 \begin_layout Section
19364 \begin_inset LatexCommand \index{Libraries}
19371 \begin_layout Standard
19374 <pending: this is messy and incomplete - a little more information is in
19375 sdcc/doc/libdoc.txt
19380 \begin_layout Subsection
19381 Compiler support routines (_gptrget, _mulint etc.)
19384 \begin_layout Subsection
19385 Stdclib functions (puts, printf, strcat etc.)
19388 \begin_layout Subsubsection
19392 \begin_layout Paragraph
19393 getchar(), putchar()
19396 \begin_layout Standard
19397 \begin_inset LatexCommand \index{<stdio.h>}
19401 As usual on embedded systems you have to provide your own
19404 \begin_inset LatexCommand \index{getchar()}
19413 \begin_inset LatexCommand \index{putchar()}
19420 SDCC does not know whether the system connects to a serial line with or
19421 without handshake, LCD, keyboard or other device.
19435 You'll find examples for serial routines f.e.
19436 in sdcc/device/lib.
19437 For the mcs51 this minimalistic polling
19441 routine might be a start:
19444 \begin_layout Verse
19447 void putchar (char c) {
19453 while (!TI)\InsetSpace ~
19456 /* assumes UART is initialized */
19484 \begin_layout Paragraph
19488 \begin_layout Standard
19492 \begin_inset LatexCommand \index{printf()}
19502 does not support float (except on ds390).
19503 To enable this recompile it with the option
19509 \begin_layout Standard
19519 \begin_inset LatexCommand \index{USE\_FLOATS}
19525 on the command line.
19532 \begin_layout Standard
19542 \begin_inset LatexCommand \index{-\/-model-large}
19548 for the mcs51 port, since this uses a lot of memory.
19551 \begin_layout Standard
19552 If you're short on code memory you might want to use
19555 \begin_inset LatexCommand \index{printf\_small()}
19570 For the mcs51 there additionally are assembly versions
19573 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19579 (subset of printf using less than 270 bytes) and
19582 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19591 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19597 (floating-point aware version of printf_fast) which should fit the requirements
19598 of many embedded systems (printf_fast() can be customized by unsetting
19603 support long variables and field widths).
19604 Be sure to use only one of these printf options within a project.
19609 \begin_layout Standard
19610 Feature matrix of different
19617 \begin_layout Standard
19618 \begin_inset Tabular
19619 <lyxtabular version="3" rows="14" columns="7">
19620 <features islongtable="true">
19621 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19622 <column alignment="center" valignment="top" leftline="true" width="0">
19623 <column alignment="center" valignment="top" leftline="true" width="12col%">
19624 <column alignment="center" valignment="top" leftline="true" width="10col%">
19625 <column alignment="center" valignment="top" leftline="true" width="0">
19626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19627 <column alignment="center" valignment="top" rightline="true" width="0">
19628 <row topline="true" bottomline="true" endhead="true">
19629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19632 \begin_layout Standard
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19644 \begin_layout Standard
19646 \begin_inset LatexCommand \index{printf}
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19658 \begin_layout Standard
19666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19669 \begin_layout Standard
19675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19678 \begin_layout Standard
19684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19687 \begin_layout Standard
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19696 \begin_layout Standard
19703 <row topline="true" endhead="true">
19704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19707 \begin_layout Standard
19713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19716 \begin_layout Standard
19724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19727 \begin_layout Standard
19735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19738 \begin_layout Standard
19746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19749 \begin_layout Standard
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19760 \begin_layout Standard
19768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19771 \begin_layout Standard
19780 <row topline="true" endhead="true">
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19784 \begin_layout Standard
19785 \begin_inset Quotes sld
19789 \begin_inset Quotes srd
19795 \begin_layout Standard
19801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19804 \begin_layout Standard
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19813 \begin_layout Standard
19819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19822 \begin_layout Standard
19828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19831 \begin_layout Standard
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19840 \begin_layout Standard
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19849 \begin_layout Standard
19856 <row topline="true" endhead="true">
19857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19860 \begin_layout Standard
19864 \begin_layout Standard
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19873 \begin_layout Standard
19879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19882 \begin_layout Standard
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19891 \begin_layout Standard
19892 0.45k / 0.47k (+ _ltoa)
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19900 \begin_layout Standard
19906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19909 \begin_layout Standard
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19918 \begin_layout Standard
19925 <row topline="true">
19926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19929 \begin_layout Standard
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19938 \begin_layout Standard
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_layout Standard
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20001 \begin_layout Standard
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20043 \begin_layout Standard
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20052 \begin_layout Standard
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20061 \begin_layout Standard
20068 <row topline="true">
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20072 \begin_layout Standard
20073 long (32 bit) support
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20081 \begin_layout Standard
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20090 \begin_layout Standard
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20099 \begin_layout Standard
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20108 \begin_layout Standard
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20117 \begin_layout Standard
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20135 \begin_layout Standard
20142 <row topline="true">
20143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20146 \begin_layout Standard
20147 byte arguments on stack
20152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20155 \begin_layout Standard
20161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20164 \begin_layout Standard
20170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20173 \begin_layout Standard
20179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20182 \begin_layout Standard
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20191 \begin_layout Standard
20197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20200 \begin_layout Standard
20207 <row topline="true">
20208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20211 \begin_layout Standard
20213 \begin_inset LatexCommand \index{Floating point support}
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 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20280 \begin_layout Standard
20287 <row topline="true">
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20291 \begin_layout Standard
20292 float formats %e %g
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20300 \begin_layout Standard
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20309 \begin_layout Standard
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_layout Standard
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20327 \begin_layout Standard
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20336 \begin_layout Standard
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20345 \begin_layout Standard
20352 <row topline="true" bottomline="true">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_layout Standard
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_layout Standard
20371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_layout Standard
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20383 \begin_layout Standard
20389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20392 \begin_layout Standard
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20401 \begin_layout Standard
20407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20410 \begin_layout Standard
20417 <row bottomline="true">
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20421 \begin_layout Standard
20426 \begin_layout Standard
20427 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20431 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20439 \begin_layout Standard
20445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20448 \begin_layout Standard
20454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20457 \begin_layout Standard
20463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20466 \begin_layout Standard
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20475 \begin_layout Standard
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20484 \begin_layout Standard
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20493 \begin_layout Standard
20500 <row bottomline="true">
20501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20504 \begin_layout Standard
20509 \begin_layout Standard
20510 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20519 \begin_layout Standard
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20528 \begin_layout Standard
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20537 \begin_layout Standard
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20546 \begin_layout Standard
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20555 \begin_layout Standard
20561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20564 \begin_layout Standard
20570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20573 \begin_layout Standard
20578 \begin_layout Standard
20579 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20590 <row bottomline="true">
20591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20594 \begin_layout Standard
20599 \begin_layout Standard
20600 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20609 \begin_layout Standard
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20618 \begin_layout Standard
20624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20627 \begin_layout Standard
20633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20636 \begin_layout Standard
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20645 \begin_layout Standard
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20654 \begin_layout Standard
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20663 \begin_layout Standard
20670 <row bottomline="true">
20671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20674 \begin_layout Standard
20679 \begin_layout Standard
20680 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20689 \begin_layout Standard
20695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20698 \begin_layout Standard
20704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20707 \begin_layout Standard
20713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20716 \begin_layout Standard
20722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20725 \begin_layout Standard
20731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20734 \begin_layout Standard
20740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20743 \begin_layout Standard
20757 \begin_layout Subsubsection
20759 \begin_inset LatexCommand \index{malloc.h}
20766 \begin_layout Standard
20767 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20768 using dynamic memory allocation
20769 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20774 \begin_inset LatexCommand \index{heap (malloc)}
20778 space of 1024 bytes is provided for malloc to allocate memory from.
20779 If you need a different heap size you need to recompile _heap.c with the
20780 required size defined in HEAP_SIZE.
20781 It is recommended to make a copy of this file into your project directory
20782 and compile it there with:
20785 \begin_layout Verse
20788 sdcc -c _heap.c -D HEAD_SIZE=2048
20791 \begin_layout Standard
20792 And then link it with:
20795 \begin_layout Verse
20798 sdcc main.rel _heap.rel
20801 \begin_layout Subsection
20802 Math functions (sinf, powf, sqrtf etc.)
20805 \begin_layout Subsubsection
20809 \begin_layout Standard
20810 See definitions in file <math.h>.
20813 \begin_layout Subsection
20817 \begin_layout Standard
20819 \begin_inset LatexCommand \index{Libraries}
20823 included in SDCC should have a license at least as liberal as the GNU Lesser
20824 General Public License
20825 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20836 \begin_layout Standard
20837 \begin_inset Note Note
20840 \begin_layout Standard
20841 license statements for the libraries are missing.
20842 sdcc/device/lib/ser_ir.c
20845 \begin_layout Standard
20847 come with a GPL (as opposed to LGPL) License - this will not be liberal
20848 enough for many embedded programmers.
20856 \begin_layout Standard
20857 If you have ported some library or want to share experience about some code
20859 falls into any of these categories Busses (I
20860 \begin_inset Formula $^{\textrm{2}}$
20863 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20864 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20865 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
20866 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20871 would certainly like to hear about it.
20874 \begin_layout Standard
20875 Programmers coding for embedded systems are not especially famous for being
20876 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20877 e these references are very valuable.
20878 Let's help to create a climate where information is shared.
20879 \begin_inset VSpace bigskip
20885 \begin_layout Section
20889 \begin_layout Subsection
20890 MCS51 Memory Models
20891 \begin_inset LatexCommand \index{Memory model}
20896 \begin_inset LatexCommand \index{MCS51 memory model}
20903 \begin_layout Subsubsection
20904 Small, Medium and Large
20907 \begin_layout Standard
20908 SDCC allows three memory models for MCS51 code,
20917 Modules compiled with different memory models should
20921 be combined together or the results would be unpredictable.
20922 The library routines supplied with the compiler are compiled as small,
20924 The compiled library modules are contained in separate directories as small,
20925 medium and large so that you can link to the appropriate set.
20928 \begin_layout Standard
20929 When the medium or large model is used all variables declared without a
20930 storage class will be allocated into the external ram, this includes all
20931 parameters and local variables (for non-reentrant
20932 \begin_inset LatexCommand \index{reentrant}
20937 When the small model is used variables without storage class are allocated
20938 in the internal ram.
20941 \begin_layout Standard
20942 Judicious usage of the processor specific storage classes
20943 \begin_inset LatexCommand \index{Storage class}
20947 and the 'reentrant' function type will yield much more efficient code,
20948 than using the large model.
20949 Several optimizations are disabled when the program is compiled using the
20950 large model, it is therefore recommended that the small model be used unless
20951 absolutely required.
20954 \begin_layout Subsubsection
20956 \begin_inset LatexCommand \label{sub:External-Stack}
20961 \begin_inset LatexCommand \index{stack}
20966 \begin_inset LatexCommand \index{External stack (mcs51)}
20973 \begin_layout Standard
20974 The external stack (-
20978 \begin_layout Standard
20988 \begin_inset LatexCommand \index{-\/-xstack}
20992 ) is located in pdata
20993 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20997 memory (usually at the start of the external ram segment) and uses all
20998 unused space in pdata (max.
21004 \begin_layout Standard
21013 -xstack option is used to compile the program, the parameters and local
21015 \begin_inset LatexCommand \index{local variables}
21019 of all reentrant functions are allocated in this area.
21020 This option is provided for programs with large stack space requirements.
21021 When used with the -
21025 \begin_layout Standard
21035 \begin_inset LatexCommand \index{-\/-stack-auto}
21039 option, all parameters and local variables are allocated on the external
21040 stack (note: support libraries will need to be recompiled with the same
21042 There is a predefined target in the library makefile).
21045 \begin_layout Standard
21046 The compiler outputs the higher order address byte of the external ram segment
21048 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21053 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21057 ), therefore when using the External Stack option, this port
21061 be used by the application program.
21064 \begin_layout Subsection
21066 \begin_inset LatexCommand \index{Memory model}
21071 \begin_inset LatexCommand \index{DS390 memory model}
21078 \begin_layout Standard
21079 The only model supported is Flat 24
21080 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21085 This generates code for the 24 bit contiguous addressing mode of the Dallas
21087 In this mode, up to four meg of external RAM or code space can be directly
21089 See the data sheets at www.dalsemi.com for further information on this part.
21094 that the compiler does not generate any code to place the processor into
21095 24 bitmode (although
21099 in the ds390 libraries will do that for you).
21105 \begin_inset LatexCommand \index{Tinibios (DS390)}
21109 , the boot loader or similar code must ensure that the processor is in 24
21110 bit contiguous addressing mode before calling the SDCC startup code.
21121 \begin_layout Standard
21132 option, variables will by default be placed into the XDATA segment.
21137 Segments may be placed anywhere in the 4 meg address space using the usual
21142 \begin_layout Standard
21152 Note that if any segments are located above 64K, the -r flag must be passed
21153 to the linker to generate the proper segment relocations, and the Intel
21154 HEX output format must be used.
21155 The -r flag can be passed to the linker by using the option
21159 on the SDCC command line.
21160 However, currently the linker can not handle code segments > 64k.
21163 \begin_layout Section
21165 \begin_inset LatexCommand \label{sec:Pragmas}
21170 \begin_inset LatexCommand \index{Pragmas}
21177 \begin_layout Standard
21178 Pragmas are used to turn on and/or off certain compiler options.
21179 Some of them are closely related to corresponding command-line options
21181 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21187 Pragmas should be placed before and/or after a function, placing pragmas
21188 inside a function body could have unpredictable results.
21193 following #pragma directives:
21196 \begin_layout Itemize
21202 \begin_inset LatexCommand \index{\#pragma save}
21206 - this will save most current options to the save/restore stack.
21207 See #pragma\InsetSpace ~
21211 \begin_layout Itemize
21217 \begin_inset LatexCommand \index{\#pragma restore}
21221 - will restore saved options from the last save.
21222 saves & restores can be nested.
21223 SDCC uses a save/restore stack: save pushes current options to the stack,
21224 restore pulls current options from the stack.
21225 See #pragma\InsetSpace ~
21231 \begin_layout Itemize
21237 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21242 \begin_inset LatexCommand \index{function prologue}
21246 function1[,function2[,function3...]]
21247 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21251 - The compiler by default uses a caller saves convention for register saving
21252 across function calls, however this can cause unnecessary register pushing
21254 \begin_inset LatexCommand \index{push/pop}
21258 when calling small functions from larger functions.
21259 This option can be used to switch off the register saving convention for
21260 the function names specified.
21261 The compiler will not save registers when calling these functions, extra
21262 code need to be manually inserted at the entry and exit for these functions
21263 to save and restore the registers used by these functions, this can SUBSTANTIAL
21264 LY reduce code and improve run time performance of the generated code.
21265 In the future the compiler (with inter procedural analysis) may be able
21266 to determine the appropriate scheme to use for each function call.
21271 \begin_layout Standard
21280 -callee-saves command line option is used (see page
21281 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21285 ), the function names specified in #pragma\InsetSpace ~
21287 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21291 is appended to the list of functions specified in the command line.
21294 \begin_layout Itemize
21300 \begin_inset LatexCommand \index{\#pragma exclude}
21304 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21305 of pairs of push/pop
21306 \begin_inset LatexCommand \index{push/pop}
21315 \begin_inset LatexCommand \index{interrupt}
21328 The directive should be placed immediately before the ISR function definition
21329 and it affects ALL ISR functions following it.
21330 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21331 exclude\InsetSpace ~
21333 \begin_inset LatexCommand \index{\#pragma exclude}
21338 See also the related keyword _naked
21339 \begin_inset LatexCommand \index{\_naked}
21344 \begin_inset LatexCommand \index{\_\_naked}
21351 \begin_layout Itemize
21357 \begin_inset LatexCommand \index{pedantic}
21362 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21367 \begin_inset LatexCommand \label{ite:less_pedantic}
21371 - the compiler will not warn you anymore for obvious mistakes, you'r on
21373 See also the command line option -
21377 \begin_layout Standard
21387 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21394 More specifically, the following warnings will be disabled:
21396 comparison is always [true/false] due to limited range of data type
21400 overflow in implicit constant conversion
21402 (158); [the (in)famous]
21404 conditional flow changed by optimizer: so said EVELYN the modified DOG
21408 function '[function name]' must return value
21413 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21414 level) are disabled, too, namely:
21417 \begin_inset Note Note
21420 \begin_layout Standard
21421 dunno what comes here - this warning appears to be unused altogether
21430 [left/right] shifting more than size of object changed to zero
21438 integer overflow in expression
21442 unmatched #pragma save and #pragma restore
21446 comparison of 'signed char' with 'unsigned char' requires promotion to int
21450 ISO C90 does not support flexible array members
21454 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21458 \begin_inset Note Note
21461 \begin_layout Standard
21462 appears to be always blank - what was supposed to be here?
21471 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21472 complexity [number]
21477 \begin_layout Itemize
21483 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21487 - the compiler will not warn you anymore about warning number <nnnn>.
21490 \begin_layout Itemize
21496 \begin_inset LatexCommand \index{\#pragma nogcse}
21500 - will stop global common subexpression elimination.
21503 \begin_layout Itemize
21509 \begin_inset LatexCommand \index{\#pragma noinduction}
21513 - will stop loop induction optimizations.
21516 \begin_layout Itemize
21522 \begin_inset LatexCommand \index{\#pragma noinvariant}
21526 - will not do loop invariant optimizations.
21527 For more details see Loop Invariants in section
21528 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21535 \begin_layout Itemize
21541 \begin_inset LatexCommand \index{\#pragma noiv}
21545 - Do not generate interrupt
21546 \begin_inset LatexCommand \index{interrupt}
21551 \begin_inset LatexCommand \index{interrupt vector table}
21555 entries for all ISR functions defined after the pragma.
21556 This is useful in cases where the interrupt vector table must be defined
21557 manually, or when there is a secondary, manually defined interrupt vector
21559 for the autovector feature of the Cypress EZ-USB FX2).
21560 More elegantly this can be achieved by obmitting the optional interrupt
21561 number after the interrupt keyword, see section
21562 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21570 \begin_layout Itemize
21576 \begin_inset LatexCommand \index{\#pragma nojtbound}
21580 - will not generate code for boundary value checking, when switch statements
21581 are turned into jump-tables (dangerous).
21582 For more details see section
21583 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21590 \begin_layout Itemize
21596 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21600 - Will not do loop reversal optimization
21603 \begin_layout Itemize
21609 \begin_inset LatexCommand \index{\#pragma nooverlay}
21613 - the compiler will not overlay the parameters and local variables of a
21617 \begin_layout Itemize
21623 \begin_inset LatexCommand \index{\#pragma stackauto}
21631 \begin_layout Standard
21641 \begin_inset LatexCommand \index{-\/-stack-auto}
21646 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21650 Parameters and Local Variables.
21653 \begin_layout Itemize
21659 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21663 - The compiler will optimize code generation towards fast code, possibly
21664 at the expense of code size.
21665 Currently this has little effect.
21668 \begin_layout Itemize
21674 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21678 - The compiler will optimize code generation towards compact code, possibly
21679 at the expense of code speed.
21680 Currently this has little effect.
21683 \begin_layout Itemize
21689 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21693 - The compiler will attempt to generate code that is both compact and fast,
21694 as long as meeting one goal is not a detriment to the other (this is the
21699 \begin_layout Itemize
21705 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21709 - Generally follow the C89 standard, but allow SDCC features that conflict
21710 with the standard (default).
21713 \begin_layout Itemize
21719 \begin_inset LatexCommand \index{\#pragma std\_c89}
21723 - Follow the C89 standard and disable SDCC features that conflict with the
21727 \begin_layout Itemize
21733 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21737 - Generally follow the C99 standard, but allow SDCC features that conflict
21738 with the standard (incomplete support).
21741 \begin_layout Itemize
21747 \begin_inset LatexCommand \index{\#pragma std\_c99}
21751 - Follow the C99 standard and disable SDCC features that conflict with the
21752 standard (incomplete support).
21755 \begin_layout Itemize
21761 \begin_inset LatexCommand \index{\#pragma codeseg}
21765 - Use this name (max.
21766 8 characters) for the code segment.
21771 \begin_layout Standard
21783 \begin_layout Itemize
21789 \begin_inset LatexCommand \index{\#pragma constseg}
21793 - Use this name (max.
21794 8 characters) for the const segment.
21799 \begin_layout Standard
21811 \begin_layout Standard
21812 The preprocessor SDCPP
21813 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21817 supports the following #pragma directives:
21820 \begin_layout Itemize
21823 pedantic_parse_number
21826 \begin_inset LatexCommand \index{pedantic}
21831 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21836 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21840 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21841 properly and the macro LO_B(3) gets expanded.
21847 \begin_layout Standard
21856 -pedantic-parse-number command line option
21857 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21864 Below is an example on how to use this pragma.
21867 Note: this functionality is not in conformance with standard!
21870 \begin_layout Verse
21873 #pragma pedantic_parse_number +
21874 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21882 #define LO_B(x) ((x) & 0xff)
21886 unsigned char foo(void)
21893 unsigned char c=0xfe-LO_B(3)
21908 \begin_layout Itemize
21914 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21918 (+ | -) - switch _asm _endasm block preprocessing on / off.
21920 You use this prama to define multilines of assembly code.
21921 This will prevent the preprocessor from changing the formating required
21923 Below is an example on how to use this pragma.
21926 \begin_layout Verse
21929 #pragma preproc_asm -
21930 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21936 #define MYDELAY _asm
21941 nop ;my assembly comment...
21955 #pragma preproc_asm
21986 \begin_layout Itemize
21992 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21996 (+ | -) - Allow "naked" hash in macro definition, for example:
22000 #define DIR_LO(x) #(x & 0xff)
22005 Below is an example on how to use this pragma.
22008 \begin_layout Verse
22011 #pragma preproc_asm +
22013 #pragma sdcc_hash +
22014 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22029 mov R6_B3, #(x & 0xff)
22036 mov R7_B3, #((x >> 8) & 0xff)
22060 \begin_layout Standard
22061 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22062 ons which might cause the compiler to generate extra stack and/or data space
22063 to store compiler generated temporary variables.
22064 This usually happens in large functions.
22065 Pragma directives should be used as shown in the following example, they
22066 are used to control options and optimizations for a given function.
22070 \begin_layout Verse
22074 \begin_inset LatexCommand \index{\#pragma save}
22085 /* save the current settings */
22088 \begin_inset LatexCommand \index{\#pragma nogcse}
22097 /* turnoff global subexpression elimination */
22099 #pragma noinduction
22100 \begin_inset LatexCommand \index{\#pragma noinduction}
22104 /* turn off induction optimizations */
22127 \begin_inset LatexCommand \index{\#pragma restore}
22131 /* turn the optimizations back on */
22134 \begin_layout Standard
22135 The compiler will generate a warning message when extra space is allocated.
22136 It is strongly recommended that the save and restore pragma's be used when
22137 changing options for a function.
22146 \begin_layout Section
22147 Defines Created by the Compiler
22150 \begin_layout Standard
22151 The compiler creates the following #defines
22152 \begin_inset LatexCommand \index{\#defines}
22157 \begin_inset LatexCommand \index{Defines created by the compiler}
22166 \begin_layout Standard
22167 \begin_inset Tabular
22168 <lyxtabular version="3" rows="11" columns="2">
22170 <column alignment="left" valignment="top" leftline="true" width="3in">
22171 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22172 <row topline="true" bottomline="true">
22173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22176 \begin_layout Standard
22184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22187 \begin_layout Standard
22196 <row topline="true">
22197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22200 \begin_layout Standard
22202 \begin_inset LatexCommand \index{SDCC}
22211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22214 \begin_layout Standard
22216 Since version 2.5.6 the version number as an int (ex.
22223 <row topline="true">
22224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22227 \begin_layout Standard
22229 \begin_inset LatexCommand \index{SDCC\_mcs51}
22234 \begin_inset LatexCommand \index{SDCC\_ds390}
22239 \begin_inset LatexCommand \index{SDCC\_z80}
22248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22251 \begin_layout Standard
22252 depending on the model used (e.g.: -mds390)
22258 <row topline="true">
22259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22262 \begin_layout Standard
22264 \begin_inset LatexCommand \index{\_\_mcs51}
22269 \begin_inset LatexCommand \index{\_\_ds390}
22274 \begin_inset LatexCommand \index{\_\_hc08}
22279 \begin_inset LatexCommand \index{\_\_z80}
22288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22291 \begin_layout Standard
22292 depending on the model used (e.g.
22299 <row topline="true">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22303 \begin_layout Standard
22305 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22317 \begin_layout Standard
22324 \begin_layout Standard
22341 <row topline="true">
22342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22345 \begin_layout Standard
22347 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22359 \begin_layout Standard
22366 \begin_layout Standard
22383 <row topline="true">
22384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22387 \begin_layout Standard
22389 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22401 \begin_layout Standard
22408 \begin_layout Standard
22425 <row topline="true">
22426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22429 \begin_layout Standard
22431 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22443 \begin_layout Standard
22450 \begin_layout Standard
22467 <row topline="true">
22468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22471 \begin_layout Standard
22473 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22485 \begin_layout Standard
22492 \begin_layout Standard
22509 <row topline="true">
22510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22513 \begin_layout Standard
22515 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22527 \begin_layout Standard
22538 <row topline="true" bottomline="true">
22539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22542 \begin_layout Standard
22544 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22556 \begin_layout Standard
22574 \begin_layout Chapter
22575 Notes on supported Processors
22578 \begin_layout Section
22580 \begin_inset LatexCommand \label{sub:MCS51-variants}
22585 \begin_inset LatexCommand \index{MCS51 variants}
22592 \begin_layout Standard
22593 MCS51 processors are available from many vendors and come in many different
22595 While they might differ considerably in respect to Special Function Registers
22596 the core MCS51 is usually not modified or is kept compatible.
22600 \begin_layout Subsection
22601 pdata access by SFR
22604 \begin_layout Standard
22605 With the upcome of devices with internal xdata and flash memory devices
22607 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22611 as dedicated I/O port is becoming more popular.
22612 Switching the high byte for pdata
22613 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22617 access which was formerly done by port P2 is then achieved by a Special
22619 \begin_inset LatexCommand \index{sfr}
22624 In well-established MCS51 tradition the address of this
22628 is where the chip designers decided to put it.
22629 Needless to say that they didn't agree on a common name either.
22630 So that the startup code can correctly initialize xdata variables, you
22631 should define an sfr with the name _XPAGE
22634 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22640 at the appropriate location if the default, port P2, is not used for this.
22644 \begin_layout Verse
22647 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22651 \begin_layout Verse
22654 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22659 \begin_layout Verse
22662 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22666 \begin_layout Verse
22669 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22673 \begin_layout Verse
22676 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22680 \begin_layout Standard
22681 For more exotic implementations further customizations may be needed.
22683 \begin_inset LatexCommand \ref{sub:Startup-Code}
22687 for other possibilities.
22690 \begin_layout Subsection
22691 Other Features available by SFR
22694 \begin_layout Standard
22695 Some MCS51 variants offer features like Double DPTR
22696 \begin_inset LatexCommand \index{DPTR}
22700 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22701 These are currently not used for the MCS51 port.
22702 If you absolutely need them you can fall back to inline assembly or submit
22704 \begin_inset VSpace bigskip
22710 \begin_layout Section
22714 \begin_layout Standard
22716 \begin_inset LatexCommand \index{DS80C400}
22721 \begin_inset LatexCommand \index{DS400}
22725 microcontroller has a rich set of peripherals.
22726 In its built-in ROM library it includes functions to access some of the
22727 features, among them is a TCP stack with IP4 and IP6 support.
22728 Library headers (currently in beta status) and other files are provided
22732 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22738 \begin_inset VSpace bigskip
22744 \begin_layout Section
22745 The Z80 and gbz80 port
22748 \begin_layout Standard
22749 SDCC can target both the Zilog Z80
22750 \begin_inset LatexCommand \index{Z80}
22754 and the Nintendo Gameboy's Z80-like gbz80
22755 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22760 The Z80 port is passed through the same
22763 \begin_inset LatexCommand \index{Regression test}
22770 \begin_inset LatexCommand \ref{sec:Quality-control}
22774 ) as the MCS51 and DS390 ports, so floating point support, support for long
22775 variables and bitfield support is fine.
22776 See mailing lists and forums about interrupt routines.
22779 \begin_layout Standard
22780 As always, the code is the authoritative reference - see z80/ralloc.c and
22783 \begin_inset LatexCommand \index{Z80!stack}
22787 frame is similar to that generated by the IAR Z80 compiler.
22788 IX is used as the base pointer, HL and IY are used as a temporary registers,
22789 and BC and DE are available for holding variables.
22791 \begin_inset LatexCommand \index{Z80!return value}
22795 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22797 The gbz80 port use the same set of registers for the return values, but
22798 in a different order of significance: E (one byte), DE (two bytes), or
22800 \begin_inset VSpace bigskip
22806 \begin_layout Section
22810 \begin_layout Standard
22811 The port to the Freescale/Motorola HC08
22812 \begin_inset LatexCommand \index{HC08}
22816 family has been added in October 2003, and is still undergoing some basic
22818 The code generator is complete, but the register allocation is still quite
22820 Some of the SDCC's standard C library functions have embedded non-HC08
22821 inline assembly and so are not yet usable.
22824 \begin_layout Standard
22825 The HC08 port passes the regression test suite (see section
22826 \begin_inset LatexCommand \ref{sec:Quality-control}
22831 \begin_inset VSpace bigskip
22839 \begin_layout Section
22843 \begin_layout Standard
22844 The PIC14 port adds support for Microchip(TM)'s 14
22848 \begin_layout Standard
22858 \begin_inset LatexCommand \index{PIC14}
22863 This port is not yet mature and still lacks many features.
22864 However, it can work for simple code.
22867 \begin_layout Standard
22868 Currently supported devices include:
22871 \begin_layout Standard
22872 12F: 629, 635, 675, 683
22875 \begin_layout Standard
22879 \begin_layout Standard
22883 \begin_layout Standard
22884 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22887 \begin_layout Standard
22888 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22892 \begin_layout Standard
22896 \begin_layout Standard
22897 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22901 \begin_layout Standard
22902 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22905 \begin_layout Standard
22906 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22910 \begin_layout Standard
22911 16F: 913, 914, 916, 917
22914 \begin_layout Standard
22915 An up-to-date list of currently supported devices can be obtained via
22917 sdcc -mpic14 -phelp foo.c
22919 (foo.c must exist...).
22922 \begin_layout Subsection
22924 \begin_inset LatexCommand \index{code page (pic14)}
22929 \begin_inset LatexCommand \index{Memory bank (pic14)}
22936 \begin_layout Standard
22937 The linker organizes allocation for the code page and RAM banks.
22938 It does not have intimate knowledge of the code flow.
22939 It will put all the code section of a single .asm file into a single code
22941 In order to make use of multiple code pages, separate asm files must be
22943 The compiler assigns all
22947 functions of a single .c file into the same code page.
22951 To get the best results,
22952 follow these guidelines:
22955 \begin_layout Enumerate
22956 Make local functions static, as non static functions require code page selection
22959 Due to the way sdcc handles functions, place called functions prior
22960 to calling functions in the file wherever possible: Otherwise sdcc will
22961 insert unneccessary pagesel directives around the call, believing that
22962 the called function is externally defined.
22965 \begin_layout Enumerate
22966 For devices that have multiple code pages it is more efficient to use the
22967 same number of files as pages: Use up to 4 separate .c files for the 16F877,
22968 but only 2 files for the 16F874.
22969 This way the linker can put the code for each file into different code
22970 pages and there will be less page selection overhead.
22973 \begin_layout Enumerate
22974 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22975 instruction set), use 'unsigned char' wherever possible instead of 'int'.
22978 \begin_layout Subsection
22979 Adding New Devices to the Port
22982 \begin_layout Standard
22983 Adding support for a new 14
22987 \begin_layout Standard
22996 bit PIC MCU requires the following steps:
22999 \begin_layout Enumerate
23000 Create a new device description.
23002 Each device is described in two files: pic16f*.h
23004 These files primarily define SFRs, structs to access their bits, and symbolic
23005 configuration options.
23006 Both files can be generated from gputils' .inc files using the perl script
23009 support/scripts/inc2h.pl
23012 This file also contains further instructions on how to proceed.
23015 \begin_layout Enumerate
23016 Copy the .h file into SDCC's include path and either add the .c file to your
23017 project or copy it to
23019 device/lib/pic/libdev
23022 Afterwards, rebuild and install the libraries.
23025 \begin_layout Enumerate
23026 Edit pic14devices.txt in SDCC's include path (
23028 device/include/pic/
23030 in the source tree or
23032 /usr/local/share/sdcc/include/pic
23034 after installation).
23036 You need to add a device specification here to make
23037 the memory layout (code banks, RAM, aliased memory regions, ...) known to
23039 Probably you can copy and modify an existing entry.
23040 The file format is documented at the top of the file.
23043 \begin_layout Subsection
23047 \begin_layout Standard
23048 For the interrupt function, use the keyword '__interrupt'
23049 \begin_inset LatexCommand \index{PIC14!interrupt}
23053 with level number of 0 (PIC14 only has 1 interrupt so this number is only
23054 there to avoid a syntax error - it ought to be fixed).
23058 \begin_layout Verse
23061 void Intr(void) __interrupt 0
23067 T0IF = 0; /* Clear timer interrupt */
23072 \begin_layout Subsection
23073 Linking and Assembling
23076 \begin_layout Standard
23077 For assembling you can use either GPUTILS'
23078 \begin_inset LatexCommand \index{gputils (pic tools)}
23082 gpasm.exe or MPLAB's mpasmwin.exe.
23083 GPUTILS are available from
23084 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23089 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23090 If you use MPLAB and an interrupt function then the linker script file
23091 vectors section will need to be enlarged to link with mplink.
23102 \begin_layout Verse
23115 sdcc -V -mpic14 -p16f877 -c $<
23119 $(PRJ).hex: $(OBJS)
23129 gplink -m -s $(PRJ).lkr
23130 -o $(PRJ).hex $(OBJS) libsdcc.lib
23133 \begin_layout Standard
23141 \begin_layout Verse
23154 sdcc -S -V -mpic14 -p16f877 $<
23164 mpasmwin /q /o $*.asm
23168 $(PRJ).hex: $(OBJS)
23179 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23182 \begin_layout Standard
23183 Please note that indentations within a
23187 have to be done with a tabulator character.
23190 \begin_layout Subsection
23191 Command-Line Options
23194 \begin_layout Standard
23195 Besides the switches common to all SDCC backends, the PIC14 port accepts
23196 the following options (for an updated list see sdcc -
23200 \begin_layout Standard
23212 \begin_layout Description
23217 \begin_layout Standard
23227 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23231 emit debug info in assembly output
23234 \begin_layout Description
23239 \begin_layout Standard
23249 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23253 disable (slightly faulty) optimization on pCode
23256 \begin_layout Description
23261 \begin_layout Standard
23271 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23275 sets the lowest address of the argument passing stack (defaults to a suitably
23276 large shared databank to reduce BANKSEL overhead)
23279 \begin_layout Description
23284 \begin_layout Standard
23294 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23298 sets the size if the argument passing stack (default: 16, minimum: 4)
23301 \begin_layout Subsection
23302 Environment Variables
23305 \begin_layout Standard
23306 The PIC14 port recognizes the following environment variables:
23309 \begin_layout Description
23310 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23311 register (the ones called r0xNNNN) in a section of its own.
23312 By default (if this variable is unset), sdcc tries to cluster registers
23313 in sections in order to reduce the BANKSEL overhead when accessing them.
23316 \begin_layout Subsection
23320 \begin_layout Standard
23321 The PIC14 library currently only contains support routines required by the
23322 compiler to implement multiplication, division, and floating point support.
23323 No libc-like replacement is available at the moment, though many of the
23324 common sdcc library sources (in
23328 ) should also compile with the PIC14 port.
23331 \begin_layout Subsubsection
23332 error: missing definition for symbol
23333 \begin_inset Quotes sld
23337 \begin_inset Quotes srd
23343 \begin_layout Standard
23344 The PIC14 port uses library routines to provide more complex operations
23345 like multiplication, division/modulus and (generic) pointer dereferencing.
23346 In order to add these routines to your project, you must link with PIC14's
23352 For single source file projects this is done automatically, more complex
23357 to the linker's arguments.
23358 Make sure you also add an include path for the library (using the -I switch
23362 \begin_layout Subsubsection
23363 Processor mismatch in file
23364 \begin_inset Quotes sld
23368 \begin_inset Quotes srd
23374 \begin_layout Standard
23375 This warning can usually be ignored due to the very good compatibility amongst
23380 \begin_layout Standard
23390 \begin_inset LatexCommand \index{PIC14}
23397 \begin_layout Standard
23398 You might also consider recompiling the library for your specific device
23399 by changing the ARCH=p16f877 (default target) entry in
23401 device/lib/pic/Makefile.in
23405 device/lib/pic/Makefile
23407 to reflect your device.
23408 This might even improve performance for smaller devices as unneccesary
23409 BANKSELs might be removed.
23412 \begin_layout Subsection
23416 \begin_layout Subsubsection
23420 \begin_layout Standard
23421 Functions with variable argument lists (like printf) are not yet supported.
23422 Similarly, taking the argument of the first argument passed into a function
23423 does not work: It is currently passed in WREG and has no address...
23426 \begin_layout Subsubsection
23427 Regression tests fail
23430 \begin_layout Standard
23431 Though the small subset of regression tests in src/regression passes, SDCC
23432 regression test suite does not, indicating that there are still major bugs
23434 However, many smaller projects have successfully used SDCC in the past...
23437 \begin_layout Standard
23445 \begin_layout Section
23447 \begin_inset LatexCommand \index{PIC16}
23454 \begin_layout Standard
23456 \begin_inset LatexCommand \index{PIC16}
23460 port is the portion of SDCC that is responsible to produce code for the
23462 \begin_inset LatexCommand \index{Microchip}
23466 (TM) microcontrollers with 16 bit core.
23467 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23468 Currently supported devices are:
23471 \begin_layout Standard
23472 18F: 242, 248, 252, 258, 442, 448, 452, 458
23475 \begin_layout Standard
23479 \begin_layout Standard
23480 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23483 \begin_layout Standard
23484 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23487 \begin_layout Standard
23488 18F: 6520, 6620, 6680, 6720
23491 \begin_layout Standard
23492 18F: 8520, 8620, 8680, 8720
23495 \begin_layout Subsection
23499 \begin_layout Standard
23500 PIC16 port supports the standard command line arguments as supposed, with
23501 the exception of certain cases that will be mentioned in the following
23505 \begin_layout Description
23510 \begin_layout Standard
23520 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23528 \begin_layout Standard
23540 \begin_layout Description
23545 \begin_layout Standard
23554 -fommit-frame-pointer
23555 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23559 Frame pointer will be omitted when the function uses no local variables.
23562 \begin_layout Subsection
23563 Port Specific Options
23564 \begin_inset LatexCommand \index{Options PIC16}
23571 \begin_layout Standard
23572 The port specific options appear after the global options in the sdcc -
23576 \begin_layout Standard
23588 \begin_layout Subsubsection
23589 Code Generation Options
23592 \begin_layout Standard
23593 These options influence the generated assembler code.
23596 \begin_layout Description
23601 \begin_layout Standard
23610 -pstack-model=[model] Used in conjuction with the command above.
23611 Defines the stack model to be used, valid stack models are:
23616 \labelwidthstring 00.00.0000
23621 Selects small stack model.
23622 8 bit stack and frame pointers.
23623 Supports 256 bytes stack size.
23627 \labelwidthstring 00.00.0000
23632 Selects large stack model.
23633 16 bit stack and frame pointers.
23634 Supports 65536 bytes stack size.
23638 \begin_layout Description
23643 \begin_layout Standard
23652 -pno-banksel Do not generate BANKSEL assembler directives.
23655 \begin_layout Description
23660 \begin_layout Standard
23669 -extended Enable extended instruction set/literal offset addressing mode.
23673 \begin_layout Subsubsection
23674 Optimization Options
23677 \begin_layout Description
23682 \begin_layout Standard
23691 -obanksel=n Set optimization level for inserting BANKSELs.
23698 \labelwidthstring 00.00.0000
23703 \labelwidthstring 00.00.0000
23704 1 checks previous used register and if it is the same then does not emit
23705 BANKSEL, accounts only for labels.
23709 \labelwidthstring 00.00.0000
23710 2 tries to check the location of (even different) symbols and removes BANKSELs
23711 if they are in the same bank.
23716 Important: There might be problems if the linker script has data sections
23717 across bank borders!
23721 \begin_layout Description
23726 \begin_layout Standard
23735 -denable-peeps Force the usage of peepholes.
23739 \begin_layout Description
23744 \begin_layout Standard
23753 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23756 \begin_layout Description
23761 \begin_layout Standard
23770 -optimize-cmp Try to optimize some compares.
23773 \begin_layout Description
23778 \begin_layout Standard
23787 -optimize-df Analyze the dataflow of the generated code and improve it.
23790 \begin_layout Subsubsection
23794 \begin_layout Description
23799 \begin_layout Standard
23808 -asm= Sets the full path and name of an external assembler to call.
23811 \begin_layout Description
23816 \begin_layout Standard
23826 \begin_inset LatexCommand \index{PIC16!MPLAB}
23830 compatibility option.
23831 Currently only suppresses special gpasm directives.
23834 \begin_layout Subsubsection
23838 \begin_layout Description
23843 \begin_layout Standard
23852 -link= Sets the full path and name of an external linker to call.
23855 \begin_layout Description
23860 \begin_layout Standard
23869 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23870 unitialized data variables with [kword].
23871 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23874 \begin_layout Description
23879 \begin_layout Standard
23888 -ivt-loc=n Place the interrupt vector table at address
23893 Useful for bootloaders.
23896 \begin_layout Description
23901 \begin_layout Standard
23910 -nodefaultlibs Do not link default libraries when linking.
23913 \begin_layout Description
23918 \begin_layout Standard
23927 -use-crt= Use a custom run-time module instead of the defaults.
23930 \begin_layout Description
23935 \begin_layout Standard
23944 -no-crt Don't link the default run-time modules
23947 \begin_layout Subsubsection
23951 \begin_layout Standard
23952 Debugging options enable extra debugging information in the output files.
23955 \begin_layout Description
23960 \begin_layout Standard
23969 -debug-xtra Similar to -
23973 \begin_layout Standard
23983 \begin_inset LatexCommand \index{-\/-debug}
23987 , but dumps more information.
23990 \begin_layout Description
23995 \begin_layout Standard
24004 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24006 <source> is the name of the file being compiled.
24009 \begin_layout Description
24014 \begin_layout Standard
24023 -pcode-verbose Enable pcode debugging information in translation.
24026 \begin_layout Description
24031 \begin_layout Standard
24040 -calltree Dump call tree in .calltree file.
24043 \begin_layout Description
24048 \begin_layout Standard
24057 -gstack Trace push/pops for stack pointer overflow.
24060 \begin_layout Subsection
24061 Enviroment Variables
24064 \begin_layout Standard
24065 There is a number of enviromental variables that can be used when running
24066 SDCC to enable certain optimizations or force a specific program behaviour.
24067 these variables are primarily for debugging purposes so they can be enabled/dis
24071 \begin_layout Standard
24072 Currently there is only two such variables available:
24075 \begin_layout Description
24076 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24077 bitfields is optimized by directly loading FSR0 with the address of the
24078 bitfield structure.
24079 Normally SDCC will cast the bitfield structure to a bitfield pointer and
24081 This step saves data ram and code space for functions that make heavy use
24083 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24088 \begin_layout Description
24089 NO_REG_OPT Do not perform pCode registers optimization.
24090 This should be used for debugging purposes.
24091 If bugs in the pcode optimizer are found, users can benefit from temporarily
24092 disabling the optimizer until the bug is fixed.
24095 \begin_layout Subsection
24096 Preprocessor Macros
24099 \begin_layout Standard
24101 \begin_inset LatexCommand \index{PIC16}
24105 port defines the following preprocessor macros while translating a source.
24108 \begin_layout Standard
24110 \begin_inset Tabular
24111 <lyxtabular version="3" rows="6" columns="2">
24113 <column alignment="center" valignment="top" leftline="true" width="0">
24114 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24115 <row topline="true" bottomline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24119 \begin_layout Standard
24125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24128 \begin_layout Standard
24135 <row topline="true">
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24139 \begin_layout Standard
24145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24148 \begin_layout Standard
24149 Port identification
24155 <row topline="true">
24156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24159 \begin_layout Standard
24164 \begin_layout Standard
24178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24181 \begin_layout Standard
24182 Port identification (same as above)
24188 <row topline="true">
24189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24192 \begin_layout Standard
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24201 \begin_layout Standard
24202 MCU Identification.
24207 is the microcontrol identification number, i.e.
24214 <row topline="true">
24215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24218 \begin_layout Standard
24223 \begin_layout Standard
24237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24240 \begin_layout Standard
24241 MCU Identification (same as above)
24247 <row topline="true" bottomline="true">
24248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24251 \begin_layout Standard
24257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24260 \begin_layout Standard
24261 nnn = SMALL or LARGE respectively according to the stack model used
24274 \begin_layout Standard
24275 In addition the following macros are defined when calling assembler:
24278 \begin_layout Standard
24280 \begin_inset Tabular
24281 <lyxtabular version="3" rows="4" columns="2">
24283 <column alignment="center" valignment="top" leftline="true" width="0">
24284 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24285 <row topline="true" bottomline="true">
24286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24289 \begin_layout Standard
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24298 \begin_layout Standard
24305 <row topline="true">
24306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24309 \begin_layout Standard
24315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24318 \begin_layout Standard
24319 MCU Identification.
24324 is the microcontrol identification number, i.e.
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24335 \begin_layout Standard
24341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24344 \begin_layout Standard
24345 nnn = SMALL or LARGE respectively according to the memory model used for
24352 <row topline="true" bottomline="true">
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24356 \begin_layout Standard
24362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24365 \begin_layout Standard
24366 nnn = SMALL or LARGE respectively according to the stack model used
24379 \begin_layout Subsection
24383 \begin_layout Standard
24385 \begin_inset LatexCommand \index{PIC16}
24389 port uses the following directories for searching header files and libraries.
24392 \begin_layout Standard
24394 \begin_inset Tabular
24395 <lyxtabular version="3" rows="3" columns="4">
24397 <column alignment="center" valignment="top" leftline="true" width="0">
24398 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24399 <column alignment="center" valignment="top" width="0">
24400 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24401 <row topline="true" bottomline="true">
24402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24405 \begin_layout Standard
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24414 \begin_layout Standard
24420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24423 \begin_layout Standard
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24432 \begin_layout Standard
24439 <row topline="true">
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24443 \begin_layout Standard
24444 PREFIX/sdcc/include/pic16
24449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24452 \begin_layout Standard
24453 PIC16 specific headers
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24461 \begin_layout Standard
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24470 \begin_layout Standard
24477 <row topline="true" bottomline="true">
24478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24481 \begin_layout Standard
24482 PREFIX/sdcc/lib/pic16
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24490 \begin_layout Standard
24491 PIC16 specific libraries
24496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24499 \begin_layout Standard
24505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24508 \begin_layout Standard
24522 \begin_layout Subsection
24524 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24531 \begin_layout Standard
24533 \begin_inset LatexCommand \index{PIC16}
24537 port currently supports the following pragmas:
24540 \begin_layout Description
24542 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24546 This forces the code generator to initialize the stack & frame pointers
24547 at a specific address.
24548 This is an ad hoc solution for cases where no STACK directive is available
24549 in the linker script or gplink is not instructed to create a stack section.
24552 stack pragma should be used only once in a project.
24553 Multiple pragmas may result in indeterminate behaviour of the program.
24557 \begin_layout Standard
24558 The old format (ie.
24559 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24560 cross page boundaries (or even exceed the available data RAM) and crash
24562 Make sure that stack does not cross page boundaries when using the SMALL
24570 The format is as follows:
24575 \begin_layout LyX-Code
24576 #pragma stack bottom_address [stack_size]
24581 \begin_layout Standard
24586 is the lower bound of the stack section.
24587 The stack pointer initially will point at address (bottom_address+stack_size-1).
24590 \begin_layout LyX-Code
24594 \begin_layout LyX-Code
24598 \begin_layout LyX-Code
24599 /* initializes stack of 100 bytes at RAM address 0x200 */
24602 \begin_layout LyX-Code
24603 #pragma stack 0x200 100
24606 \begin_layout Standard
24607 If the stack_size field is omitted then a stack is created with the default
24609 This size might be enough for most programs, but its not enough for operations
24610 with deep function nesting or excessive stack usage.
24613 \begin_layout Description
24615 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24619 Force a function to a static FLASH address.
24622 \begin_layout LyX-Code
24626 \begin_layout LyX-Code
24630 \begin_layout LyX-Code
24631 /* place function test_func at 0x4000 */
24634 \begin_layout LyX-Code
24635 #pragma code test_func 0x4000
24638 \begin_layout LyX-Code
24642 \begin_layout Description
24643 library instructs the linker to use a library module.
24648 \begin_layout LyX-Code
24649 #pragma library module_name
24652 \begin_layout Standard
24657 can be any library or object file (including its path).
24658 Note that there are four reserved keywords which have special meaning.
24662 \begin_layout Standard
24664 \begin_inset Tabular
24665 <lyxtabular version="3" rows="6" columns="3">
24667 <column alignment="center" valignment="top" leftline="true" width="0">
24668 <column alignment="block" valignment="top" leftline="true" width="20page%">
24669 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24670 <row topline="true" bottomline="true">
24671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24674 \begin_layout Standard
24680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24683 \begin_layout Standard
24689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24692 \begin_layout Standard
24699 <row topline="true">
24700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24703 \begin_layout Standard
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24714 \begin_layout Standard
24715 ignore all library pragmas
24720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24723 \begin_layout Standard
24732 <row topline="true">
24733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24736 \begin_layout Standard
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24747 \begin_layout Standard
24753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24756 \begin_layout Standard
24767 <row topline="true">
24768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24771 \begin_layout Standard
24779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24782 \begin_layout Standard
24783 link the Math libarary
24788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24791 \begin_layout Standard
24802 <row topline="true">
24803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24806 \begin_layout Standard
24814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24817 \begin_layout Standard
24818 link the I/O library
24823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24826 \begin_layout Standard
24837 <row topline="true" bottomline="true">
24838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24841 \begin_layout Standard
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24852 \begin_layout Standard
24853 link the debug library
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24861 \begin_layout Standard
24878 * is the device number, i.e.
24879 452 for PIC18F452 MCU.
24882 \begin_layout Standard
24883 This feature allows for linking with specific libraries withoug having to
24884 explicit name them in the command line.
24889 keyword will reject all modules specified by the library pragma.
24892 \begin_layout Description
24893 udata The pragma udata instructs the compiler to emit code so that linker
24894 will place a variable at a specific memory bank.
24897 \begin_layout LyX-Code
24901 \begin_layout LyX-Code
24905 \begin_layout LyX-Code
24906 /* places variable foo at bank2 */
24909 \begin_layout LyX-Code
24910 #pragma udata bank2 foo
24913 \begin_layout LyX-Code
24917 \begin_layout Standard
24918 In order for this pragma to work extra SECTION directives should be added
24919 in the .lkr script.
24920 In the following example a sample .lkr file is shown:
24923 \begin_layout LyX-Code
24927 \begin_layout LyX-Code
24928 // Sample linker script for the PIC18F452 processor
24931 \begin_layout LyX-Code
24935 \begin_layout LyX-Code
24936 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
24939 \begin_layout LyX-Code
24940 CODEPAGE NAME=page START=0x2A END=0x7FFF
24943 \begin_layout LyX-Code
24944 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
24947 \begin_layout LyX-Code
24948 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
24951 \begin_layout LyX-Code
24952 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
24955 \begin_layout LyX-Code
24956 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
24959 \begin_layout LyX-Code
24960 ACCESSBANK NAME=accessram START=0x0 END=0x7F
24963 \begin_layout LyX-Code
24967 \begin_layout LyX-Code
24968 DATABANK NAME=gpr0 START=0x80 END=0xFF
24971 \begin_layout LyX-Code
24972 DATABANK NAME=gpr1 START=0x100 END=0x1FF
24975 \begin_layout LyX-Code
24976 DATABANK NAME=gpr2 START=0x200 END=0x2FF
24979 \begin_layout LyX-Code
24980 DATABANK NAME=gpr3 START=0x300 END=0x3FF
24983 \begin_layout LyX-Code
24984 DATABANK NAME=gpr4 START=0x400 END=0x4FF
24987 \begin_layout LyX-Code
24988 DATABANK NAME=gpr5 START=0x500 END=0x5FF
24991 \begin_layout LyX-Code
24992 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
24995 \begin_layout LyX-Code
24999 \begin_layout LyX-Code
25000 SECTION NAME=CONFIG ROM=config
25003 \begin_layout LyX-Code
25007 \begin_layout LyX-Code
25008 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
25011 \begin_layout LyX-Code
25012 SECTION NAME=bank1 RAM=gpr1 # should be added to link
25015 \begin_layout LyX-Code
25016 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
25019 \begin_layout LyX-Code
25020 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
25023 \begin_layout LyX-Code
25024 SECTION NAME=bank4 RAM=gpr4
25027 \begin_layout LyX-Code
25028 SECTION NAME=bank5 RAM=gpr5
25031 \begin_layout Standard
25032 The linker will recognise the section name set in the pragma statement and
25033 will position the variable at the memory bank set with the RAM field at
25034 the SECTION line in the linker script file.
25037 \begin_layout Subsection
25039 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25046 \begin_layout Standard
25047 There is one main header file
25048 \begin_inset LatexCommand \index{PIC16!Header files}
25052 that can be included to the source files using the pic16
25053 \begin_inset LatexCommand \index{PIC16}
25063 This header file contains the definitions for the processor special registers,
25064 so it is necessary if the source accesses them.
25065 It can be included by adding the following line in the beginning of the
25069 \begin_layout LyX-Code
25070 #include <pic18fregs.h>
25073 \begin_layout Standard
25074 The specific microcontroller is selected within the pic18fregs.h automatically,
25075 so the same source can be used with a variety of devices.
25078 \begin_layout Subsection
25082 \begin_layout Standard
25084 \begin_inset LatexCommand \index{PIC16!Libraries}
25089 \begin_inset LatexCommand \index{PIC16}
25093 port depends on are the microcontroller device libraries which contain
25094 the symbol definitions for the microcontroller special function registers.
25095 These libraries have the format pic18fxxxx.lib, where
25099 is the microcontroller identification number.
25100 The specific library is selected automatically by the compiler at link
25101 stage according to the selected device.
25104 \begin_layout Standard
25105 Libraries are created with gplib which is part of the gputils package
25106 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25113 \begin_layout Subsubsection*
25114 Building the libraries
25117 \begin_layout Standard
25118 Before using SDCC/pic16 there are some libraries that need to be compiled.
25119 This process is not done automatically by SDCC since not all users use
25120 SDCC for pic16 projects.
25121 So each user should compile the libraries separately.
25124 \begin_layout Standard
25125 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25128 \begin_layout LyX-Code
25129 cd device/lib/pic16
25132 \begin_layout LyX-Code
25136 \begin_layout LyX-Code
25140 \begin_layout LyX-Code
25144 \begin_layout LyX-Code
25148 \begin_layout LyX-Code
25149 su -c 'make install' # install the libraries, you need the root password
25152 \begin_layout Standard
25153 If you need to install the headers too, do:
25156 \begin_layout LyX-Code
25160 \begin_layout LyX-Code
25161 su -c 'make install' # install the headers, you need the root password
25164 \begin_layout Standard
25165 There exist a special target to build the I/O libraries.
25166 This target is not automatically build because it will build the I/O library
25172 This way building will take quite a lot of time.
25173 Users are advised to edit the
25175 device/lib/pic16/pics.build
25177 file and then execute:
25180 \begin_layout LyX-Code
25184 \begin_layout Subsection
25185 Adding New Devices to the Port
25188 \begin_layout Standard
25189 Adding support for a new 16
25193 \begin_layout Standard
25202 bit PIC MCU requires the following steps:
25205 \begin_layout Enumerate
25206 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25210 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25214 \begin_layout Enumerate
25217 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25220 \begin_layout Enumerate
25223 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25226 \begin_layout Enumerate
25229 /path/to/sdcc/device/lib/pics.all
25237 Note: No 18f prefix here!
25240 \begin_layout Enumerate
25243 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25247 Add your DEVICE if it does not compile in
25262 \begin_layout Enumerate
25265 /path/to/sdcc/device/include/pic16/pic18fregs.h
25268 The file format is self-explanatory, just add
25272 #elif defined(picDEVICE)
25274 # include <picDEVICE.h>
25278 at the right place (keep it sorted).
25281 \begin_layout Enumerate
25284 /path/to/sdcc/src/pic16/devices.inc
25287 Copy and modify an existing entry and insert it at the correct place (keep
25289 The file is hardly documented, look at the entries for the 18f2221...
25292 \begin_layout Enumerate
25293 Recompile SDCC, including the pic16 libraries.
25296 \begin_layout Subsection
25300 \begin_layout Standard
25301 The following memory models are supported by the PIC16 port:
25304 \begin_layout Itemize
25308 \begin_layout Itemize
25312 \begin_layout Standard
25313 Memory model affects the default size of pointers within the source.
25314 The sizes are shown in the next table:
25317 \begin_layout Standard
25319 \begin_inset Tabular
25320 <lyxtabular version="3" rows="3" columns="3">
25322 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25323 <column alignment="center" valignment="top" leftline="true" width="0">
25324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25325 <row topline="true" bottomline="true">
25326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25329 \begin_layout Standard
25330 Pointer sizes according to memory model
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25338 \begin_layout Standard
25344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25347 \begin_layout Standard
25354 <row topline="true" bottomline="true">
25355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25358 \begin_layout Standard
25364 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25367 \begin_layout Standard
25373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25376 \begin_layout Standard
25383 <row topline="true" bottomline="true">
25384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25387 \begin_layout Standard
25393 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25396 \begin_layout Standard
25402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25405 \begin_layout Standard
25419 \begin_layout Standard
25420 It is advisable that all sources within a project are compiled with the
25422 If one wants to override the default memory model, this can be done by
25423 declaring a pointer as
25432 Far selects large memory model's pointers, while near selects small memory
25436 \begin_layout Standard
25437 The standard device libraries (see
25438 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25442 ) contain no reference to pointers, so they can be used with both memory
25446 \begin_layout Subsection
25450 \begin_layout Standard
25452 \begin_inset LatexCommand \index{PIC16!stack}
25456 implementation for the PIC16 port uses two indirect registers, FSR1 and
25460 \begin_layout Description
25461 FSR1 is assigned as stack pointer
25464 \begin_layout Description
25465 FSR2 is assigned as frame pointer
25468 \begin_layout Standard
25469 The following stack models are supported by the PIC16 port
25472 \begin_layout Itemize
25480 \begin_layout Itemize
25488 \begin_layout Standard
25493 model means that only the FSRxL byte is used to access stack and frame,
25500 uses both FSRxL and FSRxH registers.
25501 The following table shows the stack/frame pointers sizes according to stack
25502 model and the maximum space they can address:
25505 \begin_layout Standard
25507 \begin_inset Tabular
25508 <lyxtabular version="3" rows="3" columns="3">
25510 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25511 <column alignment="center" valignment="top" leftline="true" width="0">
25512 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25513 <row topline="true" bottomline="true">
25514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25517 \begin_layout Standard
25518 Stack & Frame pointer sizes according to stack model
25523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25526 \begin_layout Standard
25532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25535 \begin_layout Standard
25542 <row topline="true">
25543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25546 \begin_layout Standard
25552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25555 \begin_layout Standard
25561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25564 \begin_layout Standard
25571 <row topline="true" bottomline="true">
25572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25575 \begin_layout Standard
25581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25584 \begin_layout Standard
25590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25593 \begin_layout Standard
25607 \begin_layout Standard
25612 stack model is currently not working properly throughout the code generator.
25613 So its use is not advised.
25614 Also there are some other points that need special care:
25619 \begin_layout Enumerate
25620 Do not create stack sections with size more than one physical bank (that
25624 \begin_layout Enumerate
25625 Stack sections should no cross physical bank limits (i.e.
25626 #pragma stack 0x50 0x100)
25629 \begin_layout Standard
25630 These limitations are caused by the fact that only FSRxL is modified when
25631 using SMALL stack model, so no more than 256 bytes of stack can be used.
25632 This problem will disappear after LARGE model is fully implemented.
25635 \begin_layout Subsection
25639 \begin_layout Standard
25640 In addition to the standard SDCC function keywords, PIC16
25641 \begin_inset LatexCommand \index{PIC16}
25645 port makes available two more:
25648 \begin_layout Description
25650 \begin_inset LatexCommand \index{PIC16!wparam}
25654 Use the WREG to pass one byte of the first function argument.
25655 This improves speed but you may not use this for functions with arguments
25656 that are called via function pointers, otherwise the first byte of the
25657 first parameter will get lost.
25661 \begin_layout LyX-Code
25662 void func_wparam(int a) wparam
25665 \begin_layout LyX-Code
25669 \begin_layout LyX-Code
25670 /* WREG hold the lower part of a */
25673 \begin_layout LyX-Code
25674 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25678 \begin_layout LyX-Code
25682 \begin_layout LyX-Code
25686 \begin_layout Description
25688 \begin_inset LatexCommand \index{PIC16!shadowregs}
25692 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25693 hardware shadow registers which hold the values of WREG, STATUS and BSR
25695 This can be done by adding the keyword
25703 keyword in the function's header.
25706 \begin_layout LyX-Code
25707 void isr_shadow(void) shadowregs interrupt 1
25710 \begin_layout LyX-Code
25714 \begin_layout LyX-Code
25718 \begin_layout LyX-Code
25722 \begin_layout Standard
25727 instructs the code generator not to store/restore WREG, STATUS, BSR when
25728 entering/exiting the ISR.
25731 \begin_layout Subsection
25732 Function return values
25735 \begin_layout Standard
25736 Return values from functions are placed to the appropriate registers following
25737 a modified Microchip policy optimized for SDCC.
25738 The following table shows these registers:
25741 \begin_layout Standard
25743 \begin_inset Tabular
25744 <lyxtabular version="3" rows="6" columns="2">
25746 <column alignment="center" valignment="top" leftline="true" width="0">
25747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25748 <row topline="true" bottomline="true">
25749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25752 \begin_layout Standard
25758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25761 \begin_layout Standard
25762 destination register
25768 <row topline="true">
25769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25772 \begin_layout Standard
25778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25781 \begin_layout Standard
25788 <row topline="true">
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25792 \begin_layout Standard
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25801 \begin_layout Standard
25808 <row topline="true">
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25812 \begin_layout Standard
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25821 \begin_layout Standard
25828 <row topline="true">
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25832 \begin_layout Standard
25838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25841 \begin_layout Standard
25842 FSR0L:PRODH:PRODL:WREG
25848 <row topline="true" bottomline="true">
25849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25852 \begin_layout Standard
25858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25861 \begin_layout Standard
25862 on stack, FSR0 points to the beginning
25875 \begin_layout Subsection
25879 \begin_layout Standard
25881 \begin_inset LatexCommand \index{PIC16!interrupt}
25885 service routine (ISR) is declared using the
25892 \begin_layout LyX-Code
25893 void isr(void) interrupt
25898 \begin_layout LyX-Code
25902 \begin_layout LyX-Code
25906 \begin_layout LyX-Code
25910 \begin_layout Standard
25915 is the interrupt number, which for PIC18F devices can be:
25918 \begin_layout Standard
25920 \begin_inset Tabular
25921 <lyxtabular version="3" rows="4" columns="3">
25923 <column alignment="center" valignment="top" leftline="true" width="0">
25924 <column alignment="center" valignment="top" leftline="true" width="0">
25925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25926 <row topline="true" bottomline="true">
25927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25930 \begin_layout Standard
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25941 \begin_layout Standard
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25950 \begin_layout Standard
25951 Interrupt Vector Address
25957 <row topline="true">
25958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25961 \begin_layout Standard
25967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25970 \begin_layout Standard
25976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25979 \begin_layout Standard
25986 <row topline="true">
25987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25990 \begin_layout Standard
26005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26008 \begin_layout Standard
26018 HIGH priority interrupts
26023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26026 \begin_layout Standard
26033 <row topline="true" bottomline="true">
26034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26037 \begin_layout Standard
26043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26046 \begin_layout Standard
26047 LOW priority interrupts
26052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26055 \begin_layout Standard
26069 \begin_layout Standard
26070 When generating assembly code for ISR the code generator places a
26076 Interrupt Vector Address
26078 which points at the genetated ISR.
26079 This single GOTO instruction is part of an automatically generated
26081 interrupt entry point
26084 The actuall ISR code is placed as normally would in the code space.
26085 Upon interrupt request, the GOTO instruction is executed which jumps to
26087 When declaring interrupt functions as _naked this GOTO instruction is
26092 The whole interrupt functions is therefore placed at the Interrupt Vector
26093 Address of the specific interrupt.
26094 This is not a problem for the LOW priority interrupts, but it is a problem
26095 for the RESET and the HIGH priority interrupts because code may be written
26096 at the next interrupt´s vector address and cause undeterminate program
26097 behaviour if that interrupt is raised.
26101 \begin_layout Standard
26102 This is not a problem when
26105 \begin_layout Enumerate
26106 this is a HIGH interrupt ISR and LOW interrupts are
26113 \begin_layout Enumerate
26114 when the ISR is small enough not to reach the next interrupt´s vector address.
26122 \begin_layout Standard
26127 is possible to be omitted.
26128 This way a function is generated similar to an ISR, but it is not assigned
26132 \begin_layout Standard
26133 When entering an interrupt, currently the PIC16
26134 \begin_inset LatexCommand \index{PIC16}
26138 port automatically saves the following registers:
26141 \begin_layout Itemize
26145 \begin_layout Itemize
26149 \begin_layout Itemize
26153 \begin_layout Itemize
26154 PROD (PRODL and PRODH)
26157 \begin_layout Itemize
26158 FSR0 (FSR0L and FSR0H)
26161 \begin_layout Standard
26162 These registers are restored upon return from the interrupt routine.
26166 \begin_layout Standard
26167 NOTE that when the _naked attribute is specified for an interrupt routine,
26168 then NO registers are stored or restored.
26176 \begin_layout Subsection
26180 \begin_layout Standard
26181 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26182 There are 3 types of generic pointers currently implemented data, code
26183 and eeprom pointers.
26184 They are differentiated by the value of the 7th and 6th bits of the upper
26188 \begin_layout Standard
26190 \begin_inset Tabular
26191 <lyxtabular version="3" rows="5" columns="5">
26193 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26194 <column alignment="center" valignment="top" width="0">
26195 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26196 <column alignment="center" valignment="top" width="0">
26197 <column alignment="left" valignment="top" rightline="true" width="0">
26198 <row topline="true" bottomline="true">
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26202 \begin_layout Standard
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26211 \begin_layout Standard
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26220 \begin_layout Standard
26226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26229 \begin_layout Standard
26230 rest of the pointer
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26238 \begin_layout Standard
26245 <row topline="true" bottomline="true">
26246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26249 \begin_layout Standard
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26258 \begin_layout Standard
26264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26267 \begin_layout Standard
26273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26276 \begin_layout Standard
26281 uuuuuu uuuuxxxx xxxxxxxx
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26289 \begin_layout Standard
26290 a 12-bit data pointer in data RAM memory
26296 <row bottomline="true">
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26300 \begin_layout Standard
26306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26309 \begin_layout Standard
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26318 \begin_layout Standard
26324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26327 \begin_layout Standard
26332 uxxxxx xxxxxxxx xxxxxxxx
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26340 \begin_layout Standard
26341 a 21-bit code pointer in FLASH memory
26347 <row bottomline="true">
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26351 \begin_layout Standard
26357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_layout Standard
26366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26369 \begin_layout Standard
26375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26378 \begin_layout Standard
26383 uuuuuu uuuuuuxx xxxxxxxx
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26391 \begin_layout Standard
26392 a 10-bit eeprom pointer in EEPROM memory
26398 <row bottomline="true">
26399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26402 \begin_layout Standard
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26411 \begin_layout Standard
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26420 \begin_layout Standard
26426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26429 \begin_layout Standard
26434 xxxxxx xxxxxxxx xxxxxxxx
26439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26442 \begin_layout Standard
26443 unimplemented pointer type
26456 \begin_layout Standard
26457 Generic pointer are read and written with a set of library functions which
26458 read/write 1, 2, 3, 4 bytes.
26461 \begin_layout Subsection
26465 \begin_layout Subsubsection
26466 Standard I/O Streams
26469 \begin_layout Standard
26474 the type FILE is defined as:
26477 \begin_layout LyX-Code
26478 typedef char * FILE;
26481 \begin_layout Standard
26482 This type is the stream type implemented I/O in the PIC18F devices.
26483 Also the standard input and output streams are declared in stdio.h:
26486 \begin_layout LyX-Code
26487 extern FILE * stdin;
26490 \begin_layout LyX-Code
26491 extern FILE * stdout;
26494 \begin_layout Standard
26495 The FILE type is actually a generic pointer which defines one more type
26496 of generic pointers, the
26501 This new type has the format:
26504 \begin_layout Standard
26506 \begin_inset Tabular
26507 <lyxtabular version="3" rows="2" columns="7">
26509 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26510 <column alignment="center" valignment="top" width="0">
26511 <column alignment="center" valignment="top" leftline="true" width="0">
26512 <column alignment="center" valignment="top" leftline="true" width="0">
26513 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26514 <column alignment="center" valignment="top" width="0">
26515 <column alignment="left" valignment="top" rightline="true" width="0">
26516 <row topline="true" bottomline="true">
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26520 \begin_layout Standard
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26529 \begin_layout Standard
26535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26538 \begin_layout Standard
26544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26547 \begin_layout Standard
26553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26556 \begin_layout Standard
26562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26565 \begin_layout Standard
26566 rest of the pointer
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26574 \begin_layout Standard
26581 <row topline="true" bottomline="true">
26582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26585 \begin_layout Standard
26591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26594 \begin_layout Standard
26600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26603 \begin_layout Standard
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26612 \begin_layout Standard
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26621 \begin_layout Standard
26627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26630 \begin_layout Standard
26640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26643 \begin_layout Standard
26644 upper byte high nubble is 0x2n, the rest are zeroes
26657 \begin_layout Standard
26658 Currently implemented there are 3 types of streams defined:
26661 \begin_layout Standard
26663 \begin_inset Tabular
26664 <lyxtabular version="3" rows="4" columns="4">
26666 <column alignment="center" valignment="top" leftline="true" width="0">
26667 <column alignment="center" valignment="top" leftline="true" width="0">
26668 <column alignment="center" valignment="top" leftline="true" width="0">
26669 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26670 <row topline="true" bottomline="true">
26671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26674 \begin_layout Standard
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26683 \begin_layout Standard
26689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26692 \begin_layout Standard
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26701 \begin_layout Standard
26708 <row topline="true">
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_layout Standard
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26721 \begin_layout Standard
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26732 \begin_layout Standard
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26741 \begin_layout Standard
26742 Writes/Reads characters via the USART peripheral
26748 <row topline="true">
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26752 \begin_layout Standard
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26761 \begin_layout Standard
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26772 \begin_layout Standard
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26781 \begin_layout Standard
26782 Writes/Reads characters via the MSSP peripheral
26788 <row topline="true" bottomline="true">
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26792 \begin_layout Standard
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26801 \begin_layout Standard
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26812 \begin_layout Standard
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26821 \begin_layout Standard
26822 Writes/Reads characters via used defined functions
26835 \begin_layout Standard
26836 The stream identifiers are declared as macros in the stdio.h header.
26839 \begin_layout Standard
26840 In the libc library there exist the functions that are used to write to
26841 each of the above streams.
26845 \begin_layout Description
26850 \begin_layout Standard
26859 _stream_usart_putchar writes a character at the USART stream
26862 \begin_layout Description
26867 \begin_layout Standard
26876 _stream_mssp_putchar writes a character at the MSSP stream
26879 \begin_layout Description
26880 putchar dummy function.
26881 This writes a character to a user specified manner.
26884 \begin_layout Standard
26885 In order to increase performance
26889 is declared in stdio.h as having its parameter in WREG (it has the wparam
26891 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26892 in a user-friendly way.
26897 is the name of the variable that holds the character to print.
26898 An example follows:
26901 \begin_layout LyX-Code
26902 #include <pic18fregs.h>
26911 \begin_layout LyX-Code
26915 \begin_layout LyX-Code
26916 PORTA = c; /* dump character c to PORTA */
26919 \begin_layout LyX-Code
26927 \begin_layout LyX-Code
26931 \begin_layout LyX-Code
26932 stdout = STREAM_USER; /* this is not necessary, since stdout points
26935 \begin_layout LyX-Code
26936 * by default to STREAM_USER */
26939 \begin_layout LyX-Code
26941 \begin_inset Quotes sld
26944 This is a printf test
26947 \begin_inset Quotes srd
26953 \begin_layout LyX-Code
26957 \begin_layout LyX-Code
26961 \begin_layout Subsubsection
26965 \begin_layout Standard
26966 PIC16 contains an implementation of the printf-family of functions.
26967 There exist the following functions:
26970 \begin_layout LyX-Code
26971 extern unsigned int sprintf(char *buf, char *fmt, ...);
26974 \begin_layout LyX-Code
26975 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26978 \begin_layout LyX-Code
26982 \begin_layout LyX-Code
26983 extern unsigned int printf(char *fmt, ...);
26986 \begin_layout LyX-Code
26987 extern unsigned int vprintf(char *fmt, va_lista ap);
26990 \begin_layout LyX-Code
26994 \begin_layout LyX-Code
26995 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26998 \begin_layout LyX-Code
26999 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27002 \begin_layout Standard
27003 For sprintf and vsprintf
27007 should normally be a data pointer where the resulting string will be placed.
27008 No range checking is done so the user should allocate the necessery buffer.
27009 For fprintf and vfprintf
27013 should be a stream pointer (i.e.
27014 stdout, STREAM_MSSP, etc...).
27017 \begin_layout Subsubsection
27021 \begin_layout Standard
27022 The PIC18F family of microcontrollers supports a number of interrupt sources.
27023 A list of these interrupts is shown in the following table:
27026 \begin_layout Standard
27028 \begin_inset Tabular
27029 <lyxtabular version="3" rows="11" columns="4">
27031 <column alignment="left" valignment="top" leftline="true" width="0">
27032 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27033 <column alignment="left" valignment="top" leftline="true" width="0">
27034 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27035 <row topline="true" bottomline="true">
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27039 \begin_layout Standard
27045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27048 \begin_layout Standard
27054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27057 \begin_layout Standard
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27066 \begin_layout Standard
27073 <row topline="true">
27074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27077 \begin_layout Standard
27083 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27086 \begin_layout Standard
27087 PORTB change interrupt
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27095 \begin_layout Standard
27101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27104 \begin_layout Standard
27105 EEPROM/FLASH write complete interrupt
27111 <row topline="true">
27112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27115 \begin_layout Standard
27121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27124 \begin_layout Standard
27125 INT0 external interrupt
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27133 \begin_layout Standard
27139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27142 \begin_layout Standard
27143 Bus collision interrupt
27149 <row topline="true">
27150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27153 \begin_layout Standard
27159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27162 \begin_layout Standard
27163 INT1 external interrupt
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27171 \begin_layout Standard
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27180 \begin_layout Standard
27181 Low voltage detect interrupt
27187 <row topline="true">
27188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27191 \begin_layout Standard
27197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27200 \begin_layout Standard
27201 INT2 external interrupt
27206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27209 \begin_layout Standard
27215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27218 \begin_layout Standard
27219 Parallel slave port interrupt
27225 <row topline="true">
27226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27229 \begin_layout Standard
27235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27238 \begin_layout Standard
27239 CCP1 module interrupt
27244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27247 \begin_layout Standard
27253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27256 \begin_layout Standard
27257 AD convertion complete interrupt
27263 <row topline="true">
27264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27267 \begin_layout Standard
27273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27276 \begin_layout Standard
27277 CCP2 module interrupt
27282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27285 \begin_layout Standard
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27294 \begin_layout Standard
27295 USART receive interrupt
27301 <row topline="true">
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27305 \begin_layout Standard
27311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27314 \begin_layout Standard
27315 TMR0 overflow interrupt
27320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27323 \begin_layout Standard
27329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27332 \begin_layout Standard
27333 USART transmit interrupt
27339 <row topline="true">
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27343 \begin_layout Standard
27349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27352 \begin_layout Standard
27353 TMR1 overflow interrupt
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27361 \begin_layout Standard
27367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27370 \begin_layout Standard
27371 SSP receive/transmit interrupt
27377 <row topline="true">
27378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27381 \begin_layout Standard
27387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27390 \begin_layout Standard
27391 TMR2 matches PR2 interrupt
27396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27399 \begin_layout Standard
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27408 \begin_layout Standard
27415 <row topline="true" bottomline="true">
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27419 \begin_layout Standard
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27428 \begin_layout Standard
27429 TMR3 overflow interrupt
27434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27437 \begin_layout Standard
27443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27446 \begin_layout Standard
27460 \begin_layout Standard
27461 The prototypes for these names are defined in the header file
27468 \begin_layout Standard
27469 In order to simplify signal handling, a number of macros is provided:
27473 \labelwidthstring 00.00.0000
27474 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27475 high priority interrupts.
27480 is the function name to use.
27484 \labelwidthstring 00.00.0000
27485 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27486 low priority interrupt.
27491 is the function name to use.
27495 \labelwidthstring 00.00.0000
27496 DEF_HANDLER(sig,handler) define a handler for signal
27502 \labelwidthstring 00.00.0000
27503 END_DEF end the declaration of the dispatch table.
27506 \begin_layout Standard
27507 Additionally there are two more macros to simplify the declaration of the
27512 \labelwidthstring 00.00.0000
27515 SIGHANDLER(handler)
27517 this declares the function prototype for the
27525 \labelwidthstring 00.00.0000
27526 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27529 \begin_layout Standard
27530 An example of using the macros above is shown below:
27533 \begin_layout LyX-Code
27534 #include <pic18fregs.h>
27537 \begin_layout LyX-Code
27538 #include <signal.h>
27542 DEF_INTHIGH(high_int)
27545 \begin_layout LyX-Code
27546 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27549 \begin_layout LyX-Code
27550 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27553 \begin_layout LyX-Code
27558 SIGHANDLER(_tmr0_handler)
27561 \begin_layout LyX-Code
27565 \begin_layout LyX-Code
27566 /* action to be taken when timer 0 overflows */
27569 \begin_layout LyX-Code
27574 SIGHANDLERNAKED(_bcol_handler)
27577 \begin_layout LyX-Code
27581 \begin_layout LyX-Code
27585 \begin_layout LyX-Code
27586 /* action to be taken when bus collision occurs */
27589 \begin_layout LyX-Code
27593 \begin_layout LyX-Code
27597 \begin_layout LyX-Code
27601 \begin_layout Standard
27606 Special care should be taken when using the above scheme:
27609 \begin_layout Itemize
27610 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27613 \begin_layout Itemize
27614 when declaring SIGHANDLERNAKED handler never forget to use
27618 for proper returning.
27621 \begin_layout Subsection
27625 \begin_layout Standard
27626 Here you can find some general tips for compiling programs with SDCC/pic16.
27629 \begin_layout Subsubsection
27633 \begin_layout Standard
27635 \begin_inset LatexCommand \index{PIC16!stack}
27639 size (that is 64 bytes) probably is enough for many programs.
27640 One must take care that when there are many levels of function nesting,
27641 or there is excessive usage of stack, its size should be extended.
27642 An example of such a case is the printf/sprintf family of functions.
27643 If you encounter problems like not being able to print integers, then you
27644 need to set the stack size around the maximum (256 for small stack model).
27645 The following diagram shows what happens when calling printf to print an
27649 \begin_layout LyX-Code
27650 printf () --> ltoa () --> ultoa () --> divschar ()
27653 \begin_layout Standard
27654 It is should be understood that stack is easily consumed when calling complicate
27656 Using command line arguments like -
27660 \begin_layout Standard
27669 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27671 Other ways to reduce stack usage may exist.
27674 \begin_layout Subsection
27678 \begin_layout Standard
27679 The PIC16 Port currently does not pass SDCC's regression test
27680 \begin_inset LatexCommand \index{Regression test (PIC16)}
27685 \begin_inset LatexCommand \ref{sec:Quality-control}
27689 ) and thus the snapshot build regression tests for the PIC16 target are
27690 currently disabled for all hosts
27695 \begin_layout Chapter
27699 \begin_layout Standard
27700 There are several approaches to debugging your code.
27701 This chapter is meant to show your options and to give detail on some of
27706 When writing your code:
27709 \begin_layout Itemize
27710 write your code with debugging in mind (avoid duplicating code, put conceptually
27711 similar variables into structs, use structured code, have strategic points
27712 within your code where all variables are consistent, ...)
27715 \begin_layout Itemize
27716 run a syntax-checking tool like splint
27717 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27722 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27730 \begin_layout Standard
27740 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27747 \begin_layout Itemize
27748 for the high level code use a C-compiler (like f.e.
27749 GCC) to compile run and debug the code on your host.
27754 \begin_layout Standard
27764 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27768 ) on how to handle syntax extensions like __xdata, __at(), ...
27772 \begin_layout Itemize
27773 use another C-compiler to compile code for your target.
27774 Always an option but not recommended:) And not very likely to help you.
27775 If you seriously consider walking this path you should at least occasionally
27776 check portability of your code.
27777 Most commercial compiler vendors will offer an evaluation version so you
27778 can test compile your code or snippets of your code.
27781 \begin_layout Standard
27782 Debugging on a simulator:
27785 \begin_layout Itemize
27786 there is a separate section about SDCDB (section
27787 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27794 \begin_layout Itemize
27795 or (8051 specific) use a freeware/commercial simulator which interfaces
27797 \begin_inset LatexCommand \index{AOMF, AOMF51}
27802 \begin_inset LatexCommand \ref{OMF file}
27806 ) optionally generated by SDCC.
27809 \begin_layout Standard
27810 Debugging On-target:
27813 \begin_layout Itemize
27814 use a MCU port pin to serially output debug data to the RS232 port of your
27816 You'll probably want some level shifting device typically involving a MAX232
27818 If the hardware serial port of the MCU is not available search for 'Software
27819 UART' in your favourite search machine.
27822 \begin_layout Itemize
27823 use an on-target monitor.
27824 In this context a monitor is a small program which usually accepts commands
27825 via a serial line and allows to set program counter, to single step through
27826 a program and read/write memory locations.
27827 For the 8051 good examples of monitors are paulmon and cmon51 (see section
27829 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27836 \begin_layout Itemize
27837 toggle MCU port pins at strategic points within your code and use an oscilloscop
27841 digital oscilloscope
27844 \begin_inset LatexCommand \index{Oscilloscope}
27848 with deep trace memory is really helpful especially if you have to debug
27849 a realtime application.
27850 If you need to monitor more pins than your oscilloscope provides you can
27851 sometimes get away with a small R-2R network.
27852 On a single channel oscilloscope you could f.e.
27853 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27855 \begin_inset Formula $\Omega$
27858 resistor and the other one by a 5\InsetSpace ~
27860 \begin_inset Formula $\Omega$
27863 resistor to the oscilloscope probe (check output drive capability of the
27864 pins you want to monitor).
27865 If you need to monitor many more pins a
27872 \begin_layout Itemize
27886 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27891 Usually very expensive.
27892 And very nice to have too.
27893 And usually locks you (for years...) to the devices the ICE can emulate.
27897 \begin_layout Itemize
27898 use a remote debugger.
27899 In most 8-bit systems the symbol information is not available on the target,
27900 and a complete debugger is too bulky for the target system.
27901 Therefore usually a debugger on the host system connects to an on-target
27902 debugging stub which accepts only primitive commands.
27905 Terms to enter into your favourite search engine could be 'remote debugging',
27906 'gdb stub' or 'inferior debugger'.
27910 \begin_layout Itemize
27911 use an on target hardware debugger.
27912 Some of the more modern MCUs include hardware support for setting break
27913 points and monitoring/changing variables by using dedicated hardware pins.
27914 This facility doesn't require additional code to run on the target and
27919 doesn't affect runtime behaviour until a breakpoint is hit.
27920 For the mcs51 most hardware debuggers use the AOMF
27921 \begin_inset LatexCommand \index{AOMF, AOMF51}
27926 \begin_inset LatexCommand \ref{OMF file}
27934 \begin_layout Standard
27938 \begin_layout Itemize
27939 if you are not familiar with any of the following terms you're likely to
27940 run into problems rather sooner than later:
27957 As an embedded programmer you
27961 to know them so why not look them up
27965 you have problems?)
27968 \begin_layout Itemize
27969 tell someone else about your problem (actually this is a surprisingly effective
27970 means to hunt down the bug even if the listener is not familiar with your
27972 As 'failure to communicate' is probably one of the job-induced deformations
27973 of an embedded programmer this is highly encouraged.
27976 \begin_layout Section
27977 Debugging with SDCDB
27978 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27983 \begin_inset LatexCommand \index{SDCDB (debugger)}
27990 \begin_layout Standard
27991 SDCC is distributed with a source level debugger
27992 \begin_inset LatexCommand \index{Debugger}
27997 The debugger uses a command line interface, the command repertoire of the
27998 debugger has been kept as close to gdb
27999 \begin_inset LatexCommand \index{gdb}
28003 (the GNU debugger) as possible.
28004 The configuration and build process is part of the standard compiler installati
28005 on, which also builds and installs the debugger in the target directory
28006 specified during configuration.
28007 The debugger allows you debug BOTH at the C source and at the ASM source
28011 \begin_layout Subsection
28012 Compiling for Debugging
28015 \begin_layout Standard
28020 \begin_layout Standard
28030 \begin_inset LatexCommand \index{-\/-debug}
28034 option must be specified for all files for which debug information is to
28036 The compiler generates a .adb file for each of these files.
28037 The linker creates the .cdb
28038 \begin_inset LatexCommand \index{<file>.cdb}
28043 \begin_inset LatexCommand \index{<file>.adb}
28047 files and the address information.
28048 This .cdb is used by the debugger.
28051 \begin_layout Subsection
28052 How the Debugger Works
28055 \begin_layout Standard
28060 \begin_layout Standard
28069 -debug option is specified the compiler generates extra symbol information
28070 some of which are put into the assembler source and some are put into the
28072 Then the linker creates the .cdb file from the individual .adb files with
28073 the address information for the symbols.
28074 The debugger reads the symbolic information generated by the compiler &
28075 the address information generated by the linker.
28076 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28077 execution is controlled by the debugger.
28078 When a command is issued for the debugger, it translates it into appropriate
28079 commands for the simulator.
28080 (Currently SDCDM only connects to the simulator but
28085 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28089 is an effort to connect directly to the hardware.)
28092 \begin_layout Subsection
28093 Starting the Debugger SDCDB
28096 \begin_layout Standard
28097 The debugger can be started using the following command line.
28098 (Assume the file you are debugging has the file name foo).
28112 The debugger will look for the following files.
28115 \begin_layout Itemize
28116 foo.c - the source file.
28119 \begin_layout Itemize
28120 foo.cdb - the debugger symbol information file.
28123 \begin_layout Itemize
28124 foo.ihx - the Intel hex format
28125 \begin_inset LatexCommand \index{Intel hex format}
28132 \begin_layout Subsection
28133 SDCDB Command Line Options
28136 \begin_layout Itemize
28141 \begin_layout Standard
28150 -directory=<source file directory> this option can used to specify the directory
28152 The debugger will look into the directory list specified for source, cdb
28154 The items in the directory list must be separated by ':', e.g.
28155 if the source files can be in the directories /home/src1 and /home/src2,
28160 \begin_layout Standard
28169 -directory option should be -
28173 \begin_layout Standard
28182 -directory=/home/src1:/home/src2.
28183 Note there can be no spaces in the option.
28187 \begin_layout Itemize
28188 -cd <directory> - change to the <directory>.
28191 \begin_layout Itemize
28192 -fullname - used by GUI front ends.
28195 \begin_layout Itemize
28196 -cpu <cpu-type> - this argument is passed to the simulator please see the
28197 simulator docs for details.
28200 \begin_layout Itemize
28201 -X <Clock frequency > this options is passed to the simulator please see
28202 the simulator docs for details.
28205 \begin_layout Itemize
28206 -s <serial port file> passed to simulator see the simulator docs for details.
28209 \begin_layout Itemize
28210 -S <serial in,out> passed to simulator see the simulator docs for details.
28213 \begin_layout Itemize
28214 -k <port number> passed to simulator see the simulator docs for details.
28217 \begin_layout Subsection
28218 SDCDB Debugger Commands
28221 \begin_layout Standard
28222 As mentioned earlier the command interface for the debugger has been deliberatel
28223 y kept as close the GNU debugger gdb, as possible.
28224 This will help the integration with existing graphical user interfaces
28225 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28226 If you use a graphical user interface for the debugger you can skip this
28230 \begin_layout Subsubsection*
28231 break [line | file:line | function | file:function]
28234 \begin_layout Standard
28235 Set breakpoint at specified line or function:
28244 sdcdb>break foo.c:100
28246 sdcdb>break funcfoo
28248 sdcdb>break foo.c:funcfoo
28251 \begin_layout Subsubsection*
28252 clear [line | file:line | function | file:function ]
28255 \begin_layout Standard
28256 Clear breakpoint at specified line or function:
28265 sdcdb>clear foo.c:100
28267 sdcdb>clear funcfoo
28269 sdcdb>clear foo.c:funcfoo
28272 \begin_layout Subsubsection*
28276 \begin_layout Standard
28277 Continue program being debugged, after breakpoint.
28280 \begin_layout Subsubsection*
28284 \begin_layout Standard
28285 Execute till the end of the current function.
28288 \begin_layout Subsubsection*
28292 \begin_layout Standard
28293 Delete breakpoint number 'n'.
28294 If used without any option clear ALL user defined break points.
28297 \begin_layout Subsubsection*
28298 info [break | stack | frame | registers ]
28301 \begin_layout Itemize
28302 info break - list all breakpoints
28305 \begin_layout Itemize
28306 info stack - show the function call stack.
28309 \begin_layout Itemize
28310 info frame - show information about the current execution frame.
28313 \begin_layout Itemize
28314 info registers - show content of all registers.
28317 \begin_layout Subsubsection*
28321 \begin_layout Standard
28322 Step program until it reaches a different source line.
28323 Note: pressing <return> repeats the last command.
28326 \begin_layout Subsubsection*
28330 \begin_layout Standard
28331 Step program, proceeding through subroutine calls.
28334 \begin_layout Subsubsection*
28338 \begin_layout Standard
28339 Start debugged program.
28342 \begin_layout Subsubsection*
28346 \begin_layout Standard
28347 Print type information of the variable.
28350 \begin_layout Subsubsection*
28354 \begin_layout Standard
28355 print value of variable.
28358 \begin_layout Subsubsection*
28362 \begin_layout Standard
28363 load the given file name.
28364 Note this is an alternate method of loading file for debugging.
28367 \begin_layout Subsubsection*
28371 \begin_layout Standard
28372 print information about current frame.
28375 \begin_layout Subsubsection*
28379 \begin_layout Standard
28380 Toggle between C source & assembly source.
28383 \begin_layout Subsubsection*
28384 ! simulator command
28387 \begin_layout Standard
28388 Send the string following '!' to the simulator, the simulator response is
28390 Note the debugger does not interpret the command being sent to the simulator,
28391 so if a command like 'go' is sent the debugger can loose its execution
28392 context and may display incorrect values.
28395 \begin_layout Subsubsection*
28399 \begin_layout Standard
28402 My name is Bobby Brown"
28405 \begin_layout Subsection
28406 Interfacing SDCDB with DDD
28409 \begin_layout Standard
28410 \begin_inset Note Note
28413 \begin_layout Standard
28414 The screenshot was converted from png to eps with:
28415 \begin_inset Quotes sld
28418 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28419 \begin_inset Quotes srd
28422 which produces a pretty compact eps file which is free from compression
28426 \begin_layout Standard
28427 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28428 as this broke the build system on Sourceforge (pdf-file was broken.
28429 pdflatex does not accept eps files).
28437 \begin_layout Standard
28453 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28459 shows a screenshot of a debugging session with DDD
28460 \begin_inset LatexCommand \index{DDD (debugger)}
28464 (Unix only) on a simulated 8032.
28465 The debugging session might not run as smoothly as the screenshot suggests.
28466 The debugger allows setting of breakpoints, displaying and changing variables,
28467 single stepping through C and assembler code.
28470 The source was compiled with
28484 \begin_layout Standard
28496 -debug ddd_example.c
28509 and DDD was invoked with
28516 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28519 \begin_layout Standard
28520 \begin_inset Note Note
28523 \begin_layout Standard
28524 Check that the double quotes or an apostroph within the command line survive
28525 the LyX tool chain.
28526 Previously the apostrophs got slanted in the PDF output so a cut and paste
28535 \begin_layout Subsection
28536 Interfacing SDCDB with XEmacs
28537 \begin_inset LatexCommand \index{XEmacs}
28542 \begin_inset LatexCommand \index{Emacs}
28549 \begin_layout Standard
28550 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28551 sdcdb.el and sdcdbsrc.el.
28552 These two files can be found in the $(prefix)/bin directory after the installat
28554 These files need to be loaded into XEmacs for the interface to work.
28555 This can be done at XEmacs startup time by inserting the following into
28556 your '.xemacs' file (which can be found in your HOME directory):
28562 (load-file sdcdbsrc.el)
28568 .xemacs is a lisp file so the () around the command is REQUIRED.
28569 The files can also be loaded dynamically while XEmacs is running, set the
28570 environment variable 'EMACSLOADPATH' to the installation bin directory
28571 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28572 To start the interface enter the following command:
28586 You will prompted to enter the file name to be debugged.
28591 The command line options that are passed to the simulator directly are
28592 bound to default values in the file sdcdbsrc.el.
28593 The variables are listed below, these values maybe changed as required.
28596 \begin_layout Itemize
28597 sdcdbsrc-cpu-type '51
28600 \begin_layout Itemize
28601 sdcdbsrc-frequency '11059200
28604 \begin_layout Itemize
28605 sdcdbsrc-serial nil
28608 \begin_layout Standard
28609 The following is a list of key mapping for the debugger interface.
28612 \begin_layout Standard
28635 binding\InsetSpace ~
28673 -------\InsetSpace ~
28744 sdcdb-back-from-src\InsetSpace ~
28773 rom-src\InsetSpace ~
28783 SDCDB continue command
28801 sdcdb-step-from-src\InsetSpace ~
28830 hatis-c-sexp\InsetSpace ~
28840 SDCDB ptypecommand for data at
28907 sdcdbsrc-delete\InsetSpace ~
28922 B Delete all breakpoints if no arg
28971 given or delete arg (C-u arg x)
28990 -frame\InsetSpace ~
29005 SDCDB Display current frame if no arg,
29054 given or display frame arg
29122 sdcdbsrc-goto-sdcdb\InsetSpace ~
29132 Goto the SDCDB output buffer
29151 t-c-sexp\InsetSpace ~
29162 SDCDB print command for data at
29229 sdcdbsrc-goto-sdcdb\InsetSpace ~
29240 o the SDCDB output buffer
29258 sdcdbsrc-mode\InsetSpace ~
29274 Toggles Sdcdbsrc mode (turns it
29290 sdcdb-finish-from-src\InsetSpace ~
29298 SDCDB finish command
29332 Set break for line with point
29347 sdcdbsrc-mode\InsetSpace ~
29363 Toggle Sdcdbsrc mode
29379 dbsrc-srcmode\InsetSpace ~
29403 \begin_layout Chapter
29407 \begin_layout Standard
29408 Here are a few guidelines that will help the compiler generate more efficient
29409 code, some of the tips are specific to this compiler others are generally
29410 good programming practice.
29413 \begin_layout Itemize
29414 Use the smallest data type to represent your data-value.
29415 If it is known in advance that the value is going to be less than 256 then
29416 use an 'unsigned char' instead of a 'short' or 'int'.
29417 Please note, that ANSI C requires both signed and unsigned chars to be
29418 promoted to 'signed int'
29419 \begin_inset LatexCommand \index{promotion to signed int}
29424 \begin_inset Marginal
29427 \begin_layout Standard
29436 before doing any operation.
29438 \begin_inset LatexCommand \index{type promotion}
29443 \begin_inset LatexCommand \label{type promotion}
29447 can be omitted, if the result is the same.
29448 The effect of the promotion rules together with the sign-extension is often
29453 \begin_layout Verse
29456 unsigned char uc = 0xfe;
29458 if (uc * uc < 0) /* this is true! */
29471 \begin_layout Standard
29478 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29486 \begin_layout Verse
29489 (unsigned char) -12 / (signed char) -3 = ...
29492 \begin_layout Standard
29493 No, the result is not 4:
29496 \begin_layout Verse
29499 (int) (unsigned char) -12 / (int) (signed char) -3 =
29501 (int) (unsigned char)
29502 0xf4 / (int) (signed char) 0xfd =
29504 (int) 0x00f4 / (int) 0xfffd =
29509 (int) 244 / (int) -3 =
29511 (int) -81 = (int) 0xffaf;
29514 \begin_layout Standard
29515 Don't complain, that gcc gives you a different result.
29516 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29517 Therefore the results are different.
29520 \begin_inset Quotes sld
29524 \begin_inset Quotes srd
29530 \begin_layout Quote
29533 If well-defined overflow characteristics are important and negative values
29534 are not, or if you want to steer clear of sign-extension problems when
29535 manipulating bits or bytes, use one of the corresponding unsigned types.
29536 (Beware when mixing signed and unsigned values in expressions, though.)
29539 character types (especially unsigned char) can be used as "tiny" integers,
29540 doing so is sometimes more trouble than it's worth, due to unpredictable
29541 sign extension and increased code size.
29545 \begin_layout Itemize
29546 Use unsigned when it is known in advance that the value is not going to
29548 This helps especially if you are doing division or multiplication, bit-shifting
29549 or are using an array index.
29552 \begin_layout Itemize
29553 NEVER jump into a LOOP.
29556 \begin_layout Itemize
29557 Declare the variables to be local
29558 \begin_inset LatexCommand \index{local variables}
29562 whenever possible, especially loop control variables (induction).
29565 \begin_layout Itemize
29566 Have a look at the assembly listing to get a
29567 \begin_inset Quotes sld
29571 \begin_inset Quotes srd
29574 for the code generation.
29577 \begin_layout Section
29578 Porting code from or to other compilers
29579 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29586 \begin_layout Itemize
29587 check whether endianness of the compilers differs and adapt where needed.
29590 \begin_layout Itemize
29591 check the device specific header files
29592 \begin_inset LatexCommand \index{Header files}
29597 \begin_inset LatexCommand \index{Include files}
29601 for compiler specific syntax.
29602 Eventually include the file <compiler.h
29603 \begin_inset LatexCommand \index{compiler.h (include file)}
29608 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29612 to allow using common header files.
29615 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29622 \begin_layout Itemize
29623 check whether the startup code contains the correct initialization (watchdog,
29627 \begin_layout Itemize
29628 check whether the sizes of short, int, long match.
29631 \begin_layout Itemize
29632 check if some 16 or 32 bit hardware registers require a specific addressing
29633 order (least significant or most significant byte first) and adapt if needed
29642 relate to time and not to lower/upper memory location here, so this is
29647 the same as endianness).
29650 \begin_layout Itemize
29651 check whether the keyword
29655 is used where needed.
29656 The compilers might differ in their optimization characteristics (as different
29657 versions of the same compiler might also use more clever optimizations
29658 this is good idea anyway).
29660 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29667 \begin_layout Itemize
29668 check that the compilers are not told to supress warnings.
29671 \begin_layout Itemize
29672 check and convert compiler specific extensions (interrupts, memory areas,
29676 \begin_layout Itemize
29677 check for differences in type promotion.
29678 Especially check for math operations on
29687 For the sake of C99 compatibility SDCC will probably promote these to
29691 more often than other compilers.
29692 Eventually insert explicit casts to
29701 Also check that the ~\InsetSpace ~
29703 \begin_inset LatexCommand \index{\~\/ Operator}
29710 \begin_inset LatexCommand \index{bit}
29716 variables, use the !\InsetSpace ~
29719 \begin_inset LatexCommand \ref{type promotion}
29724 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29731 \begin_layout Itemize
29732 check the assembly code generated for interrupt routines (f.e.
29733 for calls to possibly non-reentrant library functions).
29736 \begin_layout Itemize
29737 check whether timing loops result in proper timing (or preferably consider
29738 a rewrite of the code with timer based delays instead).
29741 \begin_layout Itemize
29742 check for differences in printf parameters (some compilers push (va_arg
29743 \begin_inset LatexCommand \index{vararg, va\_arg}
29747 ) char variables as
29751 others push them as
29757 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29764 \begin_layout Itemize
29765 check the resulting memory map
29766 \begin_inset LatexCommand \index{Memory map}
29771 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29772 ly idata, pdata, xdata).
29773 Eventually check if unexpected library functions are included.
29776 \begin_layout Section
29778 \begin_inset LatexCommand \index{Tools}
29782 included in the distribution
29785 \begin_layout Standard
29787 \begin_inset Tabular
29788 <lyxtabular version="3" rows="12" columns="3">
29790 <column alignment="left" valignment="top" leftline="true" width="0pt">
29791 <column alignment="left" valignment="top" leftline="true" width="0pt">
29792 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29793 <row topline="true" bottomline="true">
29794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29797 \begin_layout Standard
29805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29808 \begin_layout Standard
29816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29819 \begin_layout Standard
29828 <row topline="true">
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29832 \begin_layout Standard
29834 \begin_inset LatexCommand \index{uCsim}
29843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29846 \begin_layout Standard
29847 Simulator for various architectures
29852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29855 \begin_layout Standard
29862 <row topline="true">
29863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29866 \begin_layout Standard
29872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29875 \begin_layout Standard
29877 \begin_inset LatexCommand \index{Header files}
29882 \begin_inset LatexCommand \index{Include files}
29891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29894 \begin_layout Standard
29895 sdcc/support/scripts
29901 <row topline="true">
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29905 \begin_layout Standard
29911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29914 \begin_layout Standard
29915 header file conversion
29920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29923 \begin_layout Standard
29924 sdcc/support/scripts
29930 <row topline="true">
29931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29934 \begin_layout Standard
29940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29943 \begin_layout Standard
29949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29952 \begin_layout Standard
29968 <row topline="true">
29969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29972 \begin_layout Standard
29978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29981 \begin_layout Standard
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29990 \begin_layout Standard
30006 <row topline="true">
30007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30010 \begin_layout Standard
30016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30019 \begin_layout Standard
30025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30028 \begin_layout Standard
30044 <row topline="true">
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30048 \begin_layout Standard
30054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30057 \begin_layout Standard
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30066 \begin_layout Standard
30082 <row topline="true">
30083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30086 \begin_layout Standard
30092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30095 \begin_layout Standard
30101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30104 \begin_layout Standard
30120 <row topline="true">
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30124 \begin_layout Standard
30130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30133 \begin_layout Standard
30139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30142 \begin_layout Standard
30158 <row topline="true">
30159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30162 \begin_layout Standard
30168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30171 \begin_layout Standard
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30180 \begin_layout Standard
30196 <row topline="true" bottomline="true">
30197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30200 \begin_layout Standard
30206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30209 \begin_layout Standard
30211 \begin_inset LatexCommand \index{packihx (tool)}
30220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30223 \begin_layout Standard
30248 \begin_layout Section
30250 \begin_inset LatexCommand \index{Documentation}
30254 included in the distribution
30257 \begin_layout Standard
30259 \begin_inset Tabular
30260 <lyxtabular version="3" rows="10" columns="2">
30262 <column alignment="block" valignment="top" leftline="true" width="40col%">
30263 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30264 <row topline="true" bottomline="true" endhead="true">
30265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30268 \begin_layout Standard
30276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30279 \begin_layout Standard
30282 Filename / Where to get
30288 <row topline="true">
30289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30292 \begin_layout Standard
30293 SDCC Compiler User Guide
30298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30301 \begin_layout Standard
30302 You're reading it right now
30314 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30324 <row topline="true">
30325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30328 \begin_layout Standard
30334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30337 \begin_layout Standard
30350 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30360 <row topline="true">
30361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30364 \begin_layout Standard
30366 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30371 \begin_inset LatexCommand \index{Assembler documentation}
30378 \begin_inset LatexCommand \index{aslink}
30383 \begin_inset LatexCommand \index{Linker documentation}
30392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30395 \begin_layout Standard
30396 sdcc/as/doc/asxhtm.html
30408 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30418 <row topline="true">
30419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30422 \begin_layout Standard
30423 SDCC regression test
30424 \begin_inset LatexCommand \index{Regression test}
30433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30436 \begin_layout Standard
30437 sdcc/doc/test_suite_spec.pdf
30449 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30459 <row topline="true">
30460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30463 \begin_layout Standard
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30472 \begin_layout Standard
30485 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30495 <row topline="true">
30496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30499 \begin_layout Standard
30500 Notes on debugging with SDCDB
30501 \begin_inset LatexCommand \index{SDCDB (debugger)}
30510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30513 \begin_layout Standard
30514 sdcc/debugger/README
30526 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30536 <row topline="true">
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30540 \begin_layout Standard
30542 \begin_inset LatexCommand \index{uCsim}
30546 Software simulator for microcontrollers
30551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30554 \begin_layout Standard
30584 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30594 <row topline="true">
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30598 \begin_layout Standard
30599 Temporary notes on the pic16
30600 \begin_inset LatexCommand \index{PIC16}
30609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30612 \begin_layout Standard
30613 sdcc/src/pic16/NOTES
30625 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30635 <row topline="true" bottomline="true">
30636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30639 \begin_layout Standard
30640 SDCC internal documentation (debugging file format)
30645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30648 \begin_layout Standard
30678 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30697 \begin_layout Section
30698 Related open source tools
30699 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30704 \begin_inset LatexCommand \index{Related tools}
30711 \begin_layout Standard
30713 \begin_inset Tabular
30714 <lyxtabular version="3" rows="14" columns="3">
30716 <column alignment="left" valignment="top" leftline="true" width="0pt">
30717 <column alignment="block" valignment="top" leftline="true" width="30line%">
30718 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30719 <row topline="true" bottomline="true">
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30723 \begin_layout Standard
30731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30734 \begin_layout Standard
30742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30745 \begin_layout Standard
30754 <row topline="true">
30755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30758 \begin_layout Standard
30760 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30772 \begin_layout Standard
30778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30781 \begin_layout Standard
30782 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30792 <row topline="true">
30793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30796 \begin_layout Standard
30798 \begin_inset LatexCommand \index{gputils (pic tools)}
30807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30810 \begin_layout Standard
30816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30819 \begin_layout Standard
30820 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30830 <row topline="true">
30831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30834 \begin_layout Standard
30840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30843 \begin_layout Standard
30849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30852 \begin_layout Standard
30853 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30863 <row topline="true">
30864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30867 \begin_layout Standard
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30876 \begin_layout Standard
30877 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30886 \begin_layout Standard
30887 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30897 <row topline="true">
30898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30901 \begin_layout Standard
30903 \begin_inset LatexCommand \index{indent (source formatting tool)}
30912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30915 \begin_layout Standard
30916 Formats C source - Master of the white spaces
30921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30924 \begin_layout Standard
30925 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30935 <row topline="true">
30936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30939 \begin_layout Standard
30941 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30953 \begin_layout Standard
30954 Object file conversion, checksumming, ...
30959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30962 \begin_layout Standard
30963 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30973 <row topline="true">
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30977 \begin_layout Standard
30979 \begin_inset LatexCommand \index{objdump (tool)}
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30991 \begin_layout Standard
30992 Object file conversion, ...
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31000 \begin_layout Standard
31001 Part of binutils (should be there anyway)
31007 <row topline="true">
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31011 \begin_layout Standard
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31020 \begin_layout Standard
31021 8051 monitor (hex up-/download, single step, disassemble)
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31029 \begin_layout Standard
31030 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31040 <row topline="true">
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31044 \begin_layout Standard
31046 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31058 \begin_layout Standard
31059 Source code documentation system
31064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31067 \begin_layout Standard
31068 \begin_inset LatexCommand \url{http://www.doxygen.org}
31078 <row topline="true">
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31082 \begin_layout Standard
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31091 \begin_layout Standard
31092 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31100 \begin_layout Standard
31101 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31111 <row topline="true">
31112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31115 \begin_layout Standard
31121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31124 \begin_layout Standard
31125 8051 monitor (hex up-/download, single step, disassemble)
31130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31133 \begin_layout Standard
31134 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31144 <row topline="true">
31145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31148 \begin_layout Standard
31150 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31162 \begin_layout Standard
31163 Statically checks c sources (see
31164 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31176 \begin_layout Standard
31177 \begin_inset LatexCommand \url{http://www.splint.org}
31187 <row topline="true" bottomline="true">
31188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31191 \begin_layout Standard
31193 \begin_inset LatexCommand \index{DDD (debugger)}
31202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31205 \begin_layout Standard
31206 Debugger, serves nicely as GUI to SDCDB
31207 \begin_inset LatexCommand \index{SDCDB (debugger)}
31216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31219 \begin_layout Standard
31220 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31239 \begin_layout Section
31240 Related documentation / recommended reading
31243 \begin_layout Standard
31245 \begin_inset Tabular
31246 <lyxtabular version="3" rows="7" columns="3">
31248 <column alignment="left" valignment="top" leftline="true" width="0pt">
31249 <column alignment="left" valignment="top" leftline="true" width="0">
31250 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31251 <row topline="true" bottomline="true">
31252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31255 \begin_layout Standard
31263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31266 \begin_layout Standard
31274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31277 \begin_layout Standard
31286 <row topline="true">
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31290 \begin_layout Standard
31305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31308 \begin_layout Standard
31310 \begin_inset LatexCommand \index{C Reference card}
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31322 \begin_layout Standard
31323 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31333 <row topline="true">
31334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31337 \begin_layout Standard
31343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31346 \begin_layout Standard
31348 \begin_inset LatexCommand \index{C FAQ}
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31360 \begin_layout Standard
31361 \begin_inset LatexCommand \url{http://www.c-faq.com}
31371 <row topline="true">
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31375 \begin_layout Standard
31381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31384 \begin_layout Standard
31385 \begin_inset Quotes sld
31389 \begin_inset Quotes srd
31397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31400 \begin_layout Standard
31403 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31413 <row topline="true">
31414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31417 \begin_layout Standard
31423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31426 \begin_layout Standard
31427 \begin_inset Quotes sld
31430 Extensions for Embedded C
31431 \begin_inset Quotes srd
31439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31442 \begin_layout Standard
31445 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31455 <row topline="true">
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31459 \begin_layout Standard
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31468 \begin_layout Standard
31469 Latest datasheet of target CPU
31474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31477 \begin_layout Standard
31484 <row topline="true" bottomline="true">
31485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_layout Standard
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31497 \begin_layout Standard
31498 Revision history of datasheet
31503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31506 \begin_layout Standard
31522 \begin_layout Section
31523 Application notes specifically for SDCC
31526 \begin_layout Standard
31527 SDCC makes no claims about the completeness of this list and about up-to-datenes
31528 s or correctness of the application notes
31529 \begin_inset LatexCommand \index{Application notes}
31536 \begin_layout Standard
31540 \begin_inset Tabular
31541 <lyxtabular version="3" rows="7" columns="3">
31543 <column alignment="block" valignment="top" leftline="true" width="17col%">
31544 <column alignment="block" valignment="top" leftline="true" width="27col%">
31545 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31546 <row topline="true" bottomline="true">
31547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31550 \begin_layout Standard
31559 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31562 \begin_layout Standard
31571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31574 \begin_layout Standard
31584 <row topline="true">
31585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31588 \begin_layout Standard
31596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31599 \begin_layout Standard
31602 Using the SDCC Compiler for the DS80C400
31603 \begin_inset LatexCommand \index{DS80C400}
31612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31615 \begin_layout Standard
31618 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31628 <row topline="true">
31629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31632 \begin_layout Standard
31640 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31643 \begin_layout Standard
31646 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31647 \begin_inset LatexCommand \index{DS89C4x0}
31651 Family of Microcontrollers
31656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31659 \begin_layout Standard
31662 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31672 <row topline="true">
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31676 \begin_layout Standard
31679 Silicon Laboratories / Cygnal
31684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31687 \begin_layout Standard
31690 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31691 \begin_inset LatexCommand \index{IDE}
31700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31703 \begin_layout Standard
31706 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31716 <row topline="true">
31717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31720 \begin_layout Standard
31723 Ramtron / Goal Semiconductor
31728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31731 \begin_layout Standard
31734 Interfacing SDCC to Syn and Textpad
31739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31742 \begin_layout Standard
31745 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31755 <row topline="true">
31756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31759 \begin_layout Standard
31762 Ramtron / Goal Semiconductor
31767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31770 \begin_layout Standard
31773 Installing and Configuring SDCC and Crimson Editor
31778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31781 \begin_layout Standard
31784 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31794 <row topline="true" bottomline="true">
31795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31798 \begin_layout Standard
31806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31809 \begin_layout Standard
31812 MSC12xx Programming with SDCC
31817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31820 \begin_layout Standard
31823 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31840 \begin_layout Section
31844 \begin_layout Standard
31845 Some questions answered, some pointers given - it might be time to in turn
31853 \begin_layout Itemize
31854 can you solve your project with the selected microcontroller? Would you
31855 find out early or rather late that your target is too small/slow/whatever?
31856 Can you switch to a slightly better device if it doesn't fit?
31859 \begin_layout Itemize
31860 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31861 and/or another programming language be more adequate? Would an operating
31862 system on the target device help?
31865 \begin_layout Itemize
31866 if you solved the problem, will the marketing department be happy?
31869 \begin_layout Itemize
31870 if the marketing department is happy, will customers be happy?
31873 \begin_layout Itemize
31874 if you're the project manager, marketing department and maybe even the customer
31875 in one person, have you tried to see the project from the outside?
31878 \begin_layout Itemize
31879 is the project done if you think it is done? Or is just that other interface/pro
31880 tocol/feature/configuration/option missing? How about website, manual(s),
31881 internationali(z|s)ation, packaging, labels, 2nd source for components,
31882 electromagnetic compatability/interference, documentation for production,
31883 production test software, update mechanism, patent issues?
31886 \begin_layout Itemize
31887 is your project adequately positioned in that magic triangle: fame, fortune,
31891 \begin_layout Standard
31892 Maybe not all answers to these questions are known and some answers may
31897 , nevertheless knowing these questions may help you to avoid burnout
31901 \begin_layout Standard
31902 burnout is bad for electronic devices, programmers and motorcycle tyres
31908 Chances are you didn't want to hear some of them...
31911 \begin_layout Chapter
31913 \begin_inset LatexCommand \index{Support}
31920 \begin_layout Standard
31921 SDCC has grown to be a large project.
31922 The compiler alone (without the preprocessor, assembler and linker) is
31923 well over 150,000 lines of code (blank stripped).
31924 The open source nature of this project is a key to its continued growth
31926 You gain the benefit and support of many active software developers and
31928 Is SDCC perfect? No, that's why we need your help.
31929 The developers take pride in fixing reported bugs.
31930 You can help by reporting the bugs and helping other SDCC users.
31931 There are lots of ways to contribute, and we encourage you to take part
31932 in making SDCC a great software package.
31936 \begin_layout Standard
31937 The SDCC project is hosted on the SDCC sourceforge site at
31938 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31943 You'll find the complete set of mailing lists
31944 \begin_inset LatexCommand \index{Mailing list(s)}
31948 , forums, bug reporting system, patch submission
31949 \begin_inset LatexCommand \index{Patch submission}
31954 \begin_inset LatexCommand \index{download}
31958 area and Subversion code repository
31959 \begin_inset LatexCommand \index{Subversion code repository}
31966 \begin_layout Section
31968 \begin_inset LatexCommand \index{Bug reporting}
31973 \begin_inset LatexCommand \index{Reporting bugs}
31980 \begin_layout Standard
31981 The recommended way of reporting bugs is using the infrastructure of the
31983 You can follow the status of bug reports there and have an overview about
31987 \begin_layout Standard
31988 Bug reports are automatically forwarded to the developer mailing list and
31989 will be fixed ASAP.
31990 When reporting a bug, it is very useful to include a small test program
31991 (the smaller the better) which reproduces the problem.
31992 If you can isolate the problem by looking at the generated assembly code,
31993 this can be very helpful.
31994 Compiling your program with the -
31998 \begin_layout Standard
32008 \begin_inset LatexCommand \index{-\/-dumpall}
32012 option can sometimes be useful in locating optimization problems.
32013 When reporting a bug please make sure you:
32016 \begin_layout Enumerate
32017 Attach the code you are compiling with SDCC.
32021 \begin_layout Enumerate
32022 Specify the exact command you use to run SDCC, or attach your Makefile.
32026 \begin_layout Enumerate
32027 Specify the SDCC version (type "
32033 "), your platform, and operating system.
32037 \begin_layout Enumerate
32038 Provide an exact copy of any error message or incorrect output.
32042 \begin_layout Enumerate
32043 Put something meaningful in the subject of your message.
32046 \begin_layout Standard
32047 Please attempt to include these 5 important parts, as applicable, in all
32048 requests for support or when reporting any problems or bugs with SDCC.
32049 Though this will make your message lengthy, it will greatly improve your
32050 chance that SDCC users and developers will be able to help you.
32051 Some SDCC developers are frustrated by bug reports without code provided
32052 that they can use to reproduce and ultimately fix the problem, so please
32053 be sure to provide sample code if you are reporting a bug!
32056 \begin_layout Standard
32057 Please have a short check that you are using a recent version of SDCC and
32058 the bug is not yet known.
32059 This is the link for reporting bugs:
32060 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32065 With SDCC on average having more than 200 downloads
32066 \begin_inset LatexCommand \index{download}
32070 on sourceforge per day
32074 \begin_layout Standard
32075 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32076 between 2002 and 2005.
32077 This does not include other methods of distribution.
32082 there must be some users.
32083 So it's not exactly easy to find a new bug.
32084 If you find one we need it:
32086 reporting bugs is good
32091 \begin_layout Section
32092 Requesting Features
32093 \begin_inset LatexCommand \label{sub:Requesting-Features}
32098 \begin_inset LatexCommand \index{Feature request}
32103 \begin_inset LatexCommand \index{Requesting features}
32110 \begin_layout Standard
32111 Like bug reports feature requests are forwarded to the developer mailing
32113 This is the link for requesting features:
32114 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32121 \begin_layout Section
32125 \begin_layout Standard
32126 Like bug reports contributed patches are forwarded to the developer mailing
32128 This is the link for submitting patches
32129 \begin_inset LatexCommand \index{Patch submission}
32134 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32141 \begin_layout Standard
32142 You need to specify some parameters to the
32146 command for the patches to be useful.
32147 If you modified more than one file a patch created f.e.
32152 \begin_inset Quotes sld
32155 diff -Naur unmodified_directory modified_directory >my_changes.patch
32156 \begin_inset Quotes srd
32162 will be fine, otherwise
32166 \begin_inset Quotes sld
32169 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32170 \begin_inset Quotes srd
32180 \begin_layout Section
32184 \begin_layout Standard
32185 These links should take you directly to the
32186 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32194 \begin_layout Standard
32195 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32196 automated messages (mid 2003)
32202 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32207 \begin_inset LatexCommand \index{Mailing list(s)}
32211 and forums are archived and searchable so if you are lucky someone already
32212 had a similar problem.
32213 While mails to the lists themselves are delivered promptly their web front
32214 end on sourceforge sometimes shows a severe time lag (up to several weeks),
32215 if you're seriously using SDCC please consider subscribing to the lists.
32218 \begin_layout Section
32222 \begin_layout Standard
32223 You can follow the status of the Subversion version
32224 \begin_inset LatexCommand \index{version}
32228 of SDCC by watching the Changelog
32229 \begin_inset LatexCommand \index{Changelog}
32233 in the Subversion repository
32236 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32243 \begin_layout Section
32244 Subversion Source Code Repository
32247 \begin_layout Standard
32254 or the filenames of the snapshot versions of SDCC include date and its
32256 \begin_inset LatexCommand \index{Subversion code repository}
32261 Subversion allows to download the source of recent or previous versions
32263 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32267 (by number or by date).
32268 An on-line source code browser and detailled instructions are also available
32270 SDCC versions starting from 1999 up to now are available (currently the
32271 versions prior to the conversion from cvs
32272 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32276 to Subversion (April 2006) are either by accessible by Subversion or by
32280 \begin_layout Section
32282 \begin_inset LatexCommand \index{Release policy}
32289 \begin_layout Standard
32290 Historically there often were long delays between official releases and
32291 the sourceforge download area tends to get not updated at all.
32292 Excuses in the past might have referred to problems with live range analysis,
32293 but as this was fixed a while ago, the current problem is that another
32294 excuse has to be found.
32295 Kidding aside, we have to get better there! On the other hand there are
32296 daily snapshots available at
32297 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32301 , and you can always build the very last version (hopefully with many bugs
32302 fixed, and features added) from the source code available at
32303 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32309 \begin_inset LatexCommand \index{wiki}
32314 \begin_inset LatexCommand \index{Release wiki}
32319 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32323 also holds some information about past and future releases.
32326 \begin_layout Section
32328 \begin_inset LatexCommand \index{Examples}
32335 \begin_layout Standard
32336 You'll find some small examples in the directory
32338 sdcc/device/examples/.
32341 More examples and libraries are available at
32343 The SDCC Open Knowledge Resource
32344 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32351 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32358 \begin_layout Standard
32359 \begin_inset Note Note
32362 \begin_layout Standard
32363 I did insert a reference to Paul's web site here although it seems rather
32364 dedicated to a specific 8032 board (I think it's okay because it f.e.
32365 shows LCD/Harddisc interface and has a free 8051 monitor.
32366 Independent 8032 board vendors face hard competition of heavily subsidized
32367 development boards anyway).
32370 \begin_layout Standard
32371 Maybe we should include some links to real world applications.
32372 Preferably pointer to pointers (one for each architecture) so this stays
32381 \begin_layout Section
32383 \begin_inset LatexCommand \label{sec:Quality-control}
32388 \begin_inset LatexCommand \index{Quality control}
32395 \begin_layout Standard
32396 The compiler is passed through snaphot build compile and build checks.
32402 \begin_inset LatexCommand \index{Regression test}
32406 check that SDCC itself compiles flawlessly on several host platforms (i386,
32407 Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32408 the quality of the code generated by SDCC by running the code for several
32409 target platforms through simulators.
32410 The regression test suite comprises more than 100 files which expand to
32411 more than 500 test cases which include more than 4500 tests.
32412 The results of these tests are published daily on SDCC's snapshot page
32413 (click on the red or green symbols on the right side of
32414 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32421 \begin_layout Standard
32422 There is a separate document
32425 \begin_inset LatexCommand \index{Test suite}
32432 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32436 about the regression test suite.
32439 \begin_layout Standard
32440 You'll find the test code in the directory
32442 sdcc/support/regression
32445 You can run these tests manually by running
32449 in this directory (or f.e.
32454 \begin_inset Quotes sld
32458 \begin_inset Quotes srd
32464 if you don't want to run the complete tests).
32465 The test code might also be interesting if you want to look for examples
32466 \begin_inset LatexCommand \index{Examples}
32470 checking corner cases of SDCC or if you plan to submit patches
32471 \begin_inset LatexCommand \index{Patch submission}
32478 \begin_layout Standard
32479 The PIC14 port uses a different set of regression tests
32480 \begin_inset LatexCommand \index{Regression test (PIC14)}
32484 , you'll find them in the directory
32486 sdcc/src/regression
32491 \begin_layout Section
32492 Use of SDCC in Education
32495 \begin_layout Standard
32504 \begin_layout Standard
32505 the phrase "use in education" might evoke the association "
32509 fit for use in education".
32510 This connotation is not intended but nevertheless risked as the licensing
32511 of SDCC makes it difficult to offer educational discounts
32517 If your rationales are to:
32520 \begin_layout Enumerate
32521 give students a chance to understand the
32525 steps of code generation
32528 \begin_layout Enumerate
32529 have a curriculum that can be extended for years.
32530 Then you could use an fpga board as target and your curriculum will seamlessly
32531 extend from logic synthesis (
32532 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32537 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32541 ), over assembly programming, to C to FPGA compilers (
32542 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32549 \begin_layout Enumerate
32550 be able to insert excursions about skills like using a revision control
32551 system, submitting/applying patches, using a type-setting (as opposed to
32552 word-processing) engine LyX/LaTeX, using
32553 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32558 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32562 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32563 Source Software, CPU simulation, compiler regression tests
32564 \begin_inset LatexCommand \index{Regression test}
32571 And if there should be a shortage of ideas then you can always point students
32572 to the ever-growing feature request list
32573 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32580 \begin_layout Enumerate
32581 not tie students to a specific host platform and instead allow them to use
32586 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32588 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32595 \begin_layout Enumerate
32596 not encourage students to use illegal copies of educational software
32599 \begin_layout Enumerate
32600 be immune to licensing/availability/price changes of the chosen tool chain
32603 \begin_layout Enumerate
32604 be able to change to a new target platform without having to adopt a new
32608 \begin_layout Enumerate
32609 have complete control over and insight into the tool chain
32612 \begin_layout Enumerate
32613 make your students aware about the pros and cons of open source software
32617 \begin_layout Enumerate
32618 give back to the public as you are probably at least partially publically
32622 \begin_layout Enumerate
32623 give students a chance to publically prove their skills and to possibly
32624 see a world wide impact
32627 \begin_layout Standard
32628 then SDCC is probably among the first choices.
32629 Well, probably SDCC might be the only choice.
32634 \begin_layout Chapter
32635 SDCC Technical Data
32638 \begin_layout Section
32640 \begin_inset LatexCommand \index{Optimizations}
32647 \begin_layout Standard
32648 SDCC performs a host of standard optimizations in addition to some MCU specific
32653 \begin_layout Subsection
32654 Sub-expression Elimination
32655 \begin_inset LatexCommand \index{Subexpression elimination}
32662 \begin_layout Standard
32663 The compiler does local and
32682 \begin_layout Verse
32690 \begin_layout Standard
32691 will be translated to
32694 \begin_layout Verse
32704 \begin_layout Standard
32705 Some subexpressions are not as obvious as the above example, e.g.:
32708 \begin_layout Verse
32716 \begin_layout Standard
32717 In this case the address arithmetic a->b[i] will be computed only once;
32718 the equivalent code in C would be.
32721 \begin_layout Verse
32731 \begin_layout Standard
32732 The compiler will try to keep these temporary variables in registers.
32735 \begin_layout Subsection
32736 Dead-Code Elimination
32737 \begin_inset LatexCommand \index{Dead-code elimination}
32744 \begin_layout Verse
32759 i = 1; \InsetSpace ~
32768 global = 1;\InsetSpace ~
32782 global = 3;\InsetSpace ~
32788 \begin_layout Standard
32792 \begin_layout Verse
32808 \begin_layout Subsection
32810 \begin_inset LatexCommand \index{Copy propagation}
32817 \begin_layout Verse
32841 \begin_layout Standard
32845 \begin_layout Verse
32869 \begin_layout Standard
32870 Note: the dead stores created by this copy propagation will be eliminated
32871 by dead-code elimination.
32874 \begin_layout Subsection
32876 \begin_inset LatexCommand \index{Loop optimization}
32881 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32888 \begin_layout Standard
32889 Two types of loop optimizations are done by SDCC
32897 of loop induction variables.
32898 In addition to the strength reduction the optimizer marks the induction
32899 variables and the register allocator tries to keep the induction variables
32900 in registers for the duration of the loop.
32901 Because of this preference of the register allocator
32902 \begin_inset LatexCommand \index{Register allocation}
32906 , loop induction optimization causes an increase in register pressure, which
32907 may cause unwanted spilling of other temporary variables into the stack
32908 \begin_inset LatexCommand \index{stack}
32913 The compiler will generate a warning message when it is forced to allocate
32914 extra space either on the stack or data space.
32915 If this extra space allocation is undesirable then induction optimization
32916 can be eliminated either for the entire source file (with -
32920 \begin_layout Standard
32929 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32931 \begin_inset LatexCommand \index{\#pragma noinduction}
32942 \begin_layout Verse
32945 for (i = 0 ; i < 100 ; i ++)
32954 \begin_layout Standard
32958 \begin_layout Verse
32963 for (i = 0; i < 100; i++)
32972 \begin_layout Standard
32973 As mentioned previously some loop invariants are not as apparent, all static
32974 address computations are also moved out of the loop.
32979 \begin_inset LatexCommand \index{Strength reduction}
32983 , this optimization substitutes an expression by a cheaper expression:
32986 \begin_layout Verse
32989 for (i=0;i < 100; i++)
32998 \begin_layout Standard
33002 \begin_layout Verse
33009 for (i=0;i< 100;i++) {
33015 ar[itemp1] = itemp2;
33033 \begin_layout Standard
33034 The more expensive multiplication
33035 \begin_inset LatexCommand \index{Multiplication}
33039 is changed to a less expensive addition.
33042 \begin_layout Subsection
33044 \begin_inset LatexCommand \index{Loop reversing}
33051 \begin_layout Standard
33052 This optimization is done to reduce the overhead of checking loop boundaries
33053 for every iteration.
33054 Some simple loops can be reversed and implemented using a
33055 \begin_inset Quotes eld
33058 decrement and jump if not zero
33059 \begin_inset Quotes erd
33063 SDCC checks for the following criterion to determine if a loop is reversible
33064 (note: more sophisticated compilers use data-dependency analysis to make
33065 this determination, SDCC uses a more simple minded analysis).
33068 \begin_layout Itemize
33069 The 'for' loop is of the form
33075 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33085 \begin_layout Itemize
33086 The <for body> does not contain
33087 \begin_inset Quotes eld
33091 \begin_inset Quotes erd
33095 \begin_inset Quotes erd
33101 \begin_layout Itemize
33102 All goto's are contained within the loop.
33105 \begin_layout Itemize
33106 No function calls within the loop.
33109 \begin_layout Itemize
33110 The loop control variable <sym> is not assigned any value within the loop
33113 \begin_layout Itemize
33114 The loop control variable does NOT participate in any arithmetic operation
33118 \begin_layout Itemize
33119 There are NO switch statements in the loop.
33122 \begin_layout Subsection
33123 Algebraic Simplifications
33126 \begin_layout Standard
33127 SDCC does numerous algebraic simplifications, the following is a small sub-set
33128 of these optimizations.
33131 \begin_layout Verse
33134 i = j + 0;\InsetSpace ~
33138 /* changed to: */\InsetSpace ~
33144 i /= 2;\InsetSpace ~
33151 /* changed to: */\InsetSpace ~
33158 = j - j;\InsetSpace ~
33162 /* changed to: */\InsetSpace ~
33168 i = j / 1;\InsetSpace ~
33172 /* changed to: */\InsetSpace ~
33179 \begin_layout Standard
33180 Note the subexpressions
33181 \begin_inset LatexCommand \index{Subexpression}
33185 given above are generally introduced by macro expansions or as a result
33186 of copy/constant propagation.
33189 \begin_layout Subsection
33190 'switch' Statements
33191 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33196 \begin_inset LatexCommand \index{switch statement}
33203 \begin_layout Standard
33204 SDCC can optimize switch statements to jump tables
33205 \begin_inset LatexCommand \index{jump tables}
33210 It makes the decision based on an estimate of the generated code size.
33211 SDCC is quite liberal in the requirements for jump table generation:
33214 \begin_layout Itemize
33215 The labels need not be in order, and the starting number need not be one
33216 or zero, the case labels are in numerical sequence or not too many case
33217 labels are missing.
33221 \begin_layout Verse
33224 switch(i) {\InsetSpace ~
33255 case 4: ...\InsetSpace ~
33287 case 5: ...\InsetSpace ~
33319 case 3: ...\InsetSpace ~
33350 case 6: ...\InsetSpace ~
33382 case 7: ...\InsetSpace ~
33414 case 8: ...\InsetSpace ~
33446 case 9: ...\InsetSpace ~
33478 case 10: ...\InsetSpace ~
33509 case 11: ...\InsetSpace ~
33576 \begin_layout Standard
33577 Both the above switch statements will be implemented using a jump-table.
33578 The example to the right side is slightly more efficient as the check for
33579 the lower boundary of the jump-table is not needed.
33583 \begin_layout Itemize
33584 The number of case labels is not larger than supported by the target architectur
33588 \begin_layout Itemize
33589 If the case labels are not in numerical sequence ('gaps' between cases)
33590 SDCC checks whether a jump table with additionally inserted dummy cases
33591 is still attractive.
33595 \begin_layout Itemize
33596 If the starting number is not zero and a check for the lower boundary of
33597 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33602 \begin_layout Standard
33603 Switch statements which have large gaps in the numeric sequence or those
33604 that have too many case labels can be split into more than one switch statement
33605 for efficient code generation, e.g.:
33608 \begin_layout Verse
33686 \begin_layout Standard
33687 If the above switch statement is broken down into two switch statements
33690 \begin_layout Verse
33733 \begin_layout Standard
33737 \begin_layout Verse
33780 \begin_layout Standard
33781 then both the switch statements will be implemented using jump-tables whereas
33782 the unmodified switch statement will not be.
33785 \begin_layout Standard
33786 \begin_inset Note Note
33789 \begin_layout Standard
33790 There might be reasons which SDCC cannot know about to either favour or
33791 not favour jump tables.
33792 If the target system has to be as quick for the last switch case as for
33793 the first (pro jump table), or if the switch argument is known to be zero
33794 in the majority of the cases (contra jump table).
33802 \begin_layout Standard
33803 The pragma nojtbound
33804 \begin_inset LatexCommand \index{\#pragma nojtbound}
33808 can be used to turn off checking the
33821 It has no effect if a default label is supplied.
33822 Use of this pragma is dangerous: if the switch
33823 \begin_inset LatexCommand \index{switch statement}
33827 argument is not matched by a case statement the processor will happily
33831 \begin_layout Subsection
33832 Bit-shifting Operations
33833 \begin_inset LatexCommand \index{Bit shifting}
33840 \begin_layout Standard
33841 Bit shifting is one of the most frequently used operation in embedded programmin
33843 SDCC tries to implement bit-shift operations in the most efficient way
33847 \begin_layout Verse
33860 \begin_layout Standard
33861 generates the following code:
33864 \begin_layout Verse
33879 \begin_layout Standard
33880 In general SDCC will never setup a loop if the shift count is known.
33884 \begin_layout Verse
33897 \begin_layout Standard
33901 \begin_layout Verse
33925 \begin_layout Subsection
33927 \begin_inset LatexCommand \index{Bit rotation}
33934 \begin_layout Standard
33935 A special case of the bit-shift operation is bit rotation
33936 \begin_inset LatexCommand \index{rotating bits}
33940 , SDCC recognizes the following expression to be a left bit-rotation:
33943 \begin_layout Verse
33951 char i;\InsetSpace ~
33962 /* unsigned is needed for rotation */
33967 i = ((i << 1) | (i >> 7));
33976 \begin_layout Standard
33977 will generate the following code:
33980 \begin_layout Verse
33997 \begin_layout Standard
33998 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33999 ns of this case will also be recognized as bit-rotation, i.e.:
34002 \begin_layout Verse
34005 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34008 \begin_layout Subsection
34009 Nibble and Byte Swapping
34012 \begin_layout Standard
34013 Other special cases of the bit-shift operations are nibble or byte swapping
34014 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34018 , SDCC recognizes the following expressions:
34021 \begin_layout Verse
34042 i = ((i << 4) | (i >> 4));
34048 j = ((j << 8) | (j >> 8));
34051 \begin_layout Standard
34052 and generates a swap instruction for the nibble swapping
34053 \begin_inset LatexCommand \index{Nibble swapping}
34057 or move instructions for the byte swapping
34058 \begin_inset LatexCommand \index{Byte swapping}
34064 \begin_inset Quotes sld
34068 \begin_inset Quotes srd
34071 example can be used to convert from little to big-endian or vice versa.
34072 If you want to change the endianness of a
34076 integer you have to cast to
34083 \begin_layout Standard
34084 Note that SDCC stores numbers in little-endian
34088 \begin_layout Standard
34089 Usually 8-bit processors don't care much about endianness.
34090 This is not the case for the standard 8051 which only has an instruction
34096 \begin_inset LatexCommand \index{DPTR}
34104 so little-endian is the more efficient byte order.
34110 \begin_inset LatexCommand \index{little-endian}
34115 \begin_inset LatexCommand \index{Endianness}
34120 lowest order first).
34123 \begin_layout Subsection
34125 \begin_inset LatexCommand \index{Highest Order Bit}
34130 \begin_inset LatexCommand \index{Any Order Bit}
34137 \begin_layout Standard
34138 It is frequently required to obtain the highest order bit of an integral
34139 type (long, int, short or char types).
34140 Also obtaining any other order bit is not uncommon.
34141 SDCC recognizes the following expressions to yield the highest order bit
34142 and generates optimized code for it, e.g.:
34145 \begin_layout Verse
34156 unsigned char hob1, aob1;
34160 bit hob2, hob3, aob2,
34170 hob1 = (gint >> 15) & 1;
34174 hob2 = (gint >> 15) & 1;
34178 hob3 = gint & 0x8000;
34183 aob1 = (gint >> 9) & 1;
34187 aob2 = (gint >> 8) & 1;
34191 aob3 = gint & 0x0800;
34201 \begin_layout Standard
34202 will generate the following code:
34205 \begin_layout Verse
34236 000A E5*01\InsetSpace ~
34263 000C 23\InsetSpace ~
34294 000D 54 01\InsetSpace ~
34322 000F F5*02\InsetSpace ~
34377 0011 E5*01\InsetSpace ~
34405 0013 33\InsetSpace ~
34435 0014 92*00\InsetSpace ~
34491 0016 E5*01\InsetSpace ~
34518 0018 33\InsetSpace ~
34548 0019 92*01\InsetSpace ~
34604 001B E5*01\InsetSpace ~
34663 001E 54 01\InsetSpace ~
34690 0020 F5*03\InsetSpace ~
34746 0022 E5*01\InsetSpace ~
34773 0024 13\InsetSpace ~
34803 0025 92*02\InsetSpace ~
34859 0027 E5*01\InsetSpace ~
34914 002B 92*03\InsetSpace ~
34942 \begin_layout Standard
34943 Other variations of these cases however will
34948 They are standard C expressions, so I heartily recommend these be the only
34949 way to get the highest order bit, (it is portable).
34950 Of course it will be recognized even if it is embedded in other expressions,
34954 \begin_layout Verse
34957 xyz = gint + ((gint >> 15) & 1);
34960 \begin_layout Standard
34961 will still be recognized.
34964 \begin_layout Subsection
34966 \begin_inset LatexCommand \index{Higher Order Byte}
34970 / Higher Order Word
34971 \begin_inset LatexCommand \index{Higher Order Word}
34978 \begin_layout Standard
34979 It is also frequently required to obtain a higher order byte or word of
34980 a larger integral type (long, int or short types).
34981 SDCC recognizes the following expressions to yield the higher order byte
34982 or word and generates optimized code for it, e.g.:
34985 \begin_layout Verse
34990 unsigned long int glong;
34998 unsigned char hob1,
35003 unsigned int how1, how2;
35012 hob1 = (gint >> 8) & 0xFF;
35016 hob2 = glong >> 24;
35020 how1 = (glong >> 16) & 0xFFFF;
35035 \begin_layout Standard
35036 will generate the following code:
35039 \begin_layout Verse
35070 0037 85*01*06\InsetSpace ~
35092 _foo_hob1_1_1,(_gint + 1)
35123 003A 85*05*07\InsetSpace ~
35145 _foo_hob2_1_1,(_glong + 3)
35175 003D 85*04*08\InsetSpace ~
35198 _foo_how1_1_1,(_glong + 2)
35200 0040 85*05*09\InsetSpace ~
35225 0043 85*03*0A\InsetSpace ~
35247 _foo_how2_1_1,(_glong + 1)
35249 0046 85*04*0B\InsetSpace ~
35272 (_foo_how2_1_1 + 1),(_glong + 2)
35275 \begin_layout Standard
35276 Again, variations of these cases may
35281 They are standard C expressions, so I heartily recommend these be the only
35282 way to get the higher order byte/word, (it is portable).
35283 Of course it will be recognized even if it is embedded in other expressions,
35287 \begin_layout Verse
35290 xyz = gint + ((gint >> 8) & 0xFF);
35293 \begin_layout Standard
35294 will still be recognized.
35297 \begin_layout Subsection
35299 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35304 \begin_inset LatexCommand \index{Peephole optimizer}
35311 \begin_layout Standard
35312 The compiler uses a rule based, pattern matching and re-writing mechanism
35313 for peep-hole optimization.
35318 a peep-hole optimizer by Christopher W.
35319 Fraser (cwfraser\InsetSpace ~
35322 A default set of rules are compiled into the compiler, additional rules
35323 may be added with the
35329 \begin_layout Standard
35339 \begin_inset LatexCommand \index{-\/-peep-file}
35346 The rule language is best illustrated with examples.
35349 \begin_layout Verse
35371 \begin_layout Standard
35372 The above rule will change the following assembly
35373 \begin_inset LatexCommand \index{Assembler routines}
35380 \begin_layout Verse
35388 \begin_layout Standard
35392 \begin_layout Verse
35398 \begin_layout Standard
35399 Note: All occurrences of a
35403 (pattern variable) must denote the same string.
35404 With the above rule, the assembly sequence:
35407 \begin_layout Verse
35415 \begin_layout Standard
35416 will remain unmodified.
35420 Other special case optimizations may be added by the
35427 \begin_layout Standard
35440 some variants of the 8051 MCU
35441 \begin_inset LatexCommand \index{MCS51 variants}
35454 The following two rules will change all
35471 \begin_layout Verse
35474 replace { lcall %1 } by { acall %1 }
35476 replace { ljmp %1 } by { ajmp %1 }
35479 \begin_layout Standard
35482 inline-assembler code
35484 is also passed through the peep hole optimizer, thus the peephole optimizer
35485 can also be used as an assembly level macro expander.
35486 The rules themselves are MCU dependent whereas the rule language infra-structur
35487 e is MCU independent.
35488 Peephole optimization rules for other MCU can be easily programmed using
35493 The syntax for a rule is as follows:
35496 \begin_layout Verse
35499 rule := replace [ restart ] '{' <assembly sequence> '
35537 <assembly sequence> '
35555 '}' [if <functionName> ] '
35560 \begin_layout Standard
35561 <assembly sequence> := assembly instruction (each instruction including
35562 labels must be on a separate line).
35566 The optimizer will apply to the rules
35567 one by one from the top in the sequence of their appearance, it will terminate
35568 when all rules are exhausted.
35569 If the 'restart' option is specified, then the optimizer will start matching
35570 the rules again from the top, this option for a rule is expensive (performance)
35571 , it is intended to be used in situations where a transformation will trigger
35572 the same rule again.
35573 An example of this (not a good one, it has side effects) is the following
35577 \begin_layout Verse
35597 \begin_layout Standard
35598 Note that the replace pattern cannot be a blank, but can be a comment line.
35599 Without the 'restart' option only the innermost 'pop' 'push' pair would
35600 be eliminated, i.e.:
35603 \begin_layout Verse
35615 \begin_layout Standard
35619 \begin_layout Verse
35629 \begin_layout Standard
35634 the restart option the rule will be applied again to the resulting code
35635 and then all the pop-push pairs will be eliminated to yield:
35638 \begin_layout Verse
35646 \begin_layout Standard
35647 A conditional function can be attached to a rule.
35648 Attaching rules are somewhat more involved, let me illustrate this with
35652 \begin_layout Verse
35676 \begin_layout Standard
35677 The optimizer does a look-up of a function name table defined in function
35682 in the source file SDCCpeeph.c, with the name
35687 If it finds a corresponding entry the function is called.
35688 Note there can be no parameters specified for these functions, in this
35693 is crucial, since the function
35697 expects to find the label in that particular variable (the hash table containin
35698 g the variable bindings is passed as a parameter).
35699 If you want to code more such functions, take a close look at the function
35700 labelInRange and the calling mechanism in source file SDCCpeeph.c.
35701 Currently implemented are
35703 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35704 24bitMode, portIsDS390, 24bitModeAndPortDS390
35713 \begin_layout Standard
35714 I know this whole thing is a little kludgey, but maybe some day we will
35715 have some better means.
35716 If you are looking at this file, you will see the default rules that are
35717 compiled into the compiler, you can add your own rules in the default set
35718 there if you get tired of specifying the -
35722 \begin_layout Standard
35734 \begin_layout Section
35736 \begin_inset LatexCommand \index{ANSI-compliance}
35741 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35748 \begin_layout Standard
35749 The latest publically available version of the standard
35751 ISO/IEC 9899 - Programming languages - C
35753 should be available at:
35754 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35763 \begin_layout Standard
35764 Deviations from the compliance:
35767 \begin_layout Itemize
35768 functions are not reentrant
35769 \begin_inset LatexCommand \index{reentrant}
35773 unless explicitly declared as such or the
35779 \begin_layout Standard
35789 \begin_inset LatexCommand \index{-\/-stack-auto}
35795 command line option is specified.
35798 \begin_layout Itemize
35800 \begin_inset LatexCommand \index{struct}
35805 \begin_inset LatexCommand \index{union}
35809 cannot be assigned values directly, cannot be passed as function parameters
35810 or assigned to each other and cannot be a return value
35811 \begin_inset LatexCommand \index{return value}
35815 from a function, e.g.:
35819 \begin_layout Verse
35842 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
35861 s parms) /* invalid in SDCC although allowed in ANSI */
35883 return rets; /* is invalid in SDCC although allowed in ANSI */
35889 \begin_layout Itemize
35890 initialization of structure arrays must be fully braced.
35894 \begin_layout Verse
35897 struct s { char x } a[] = {1, 2};\InsetSpace ~
35902 /* invalid in SDCC */
35905 } a[] = {{1}, {2}}; /* OK */
35909 \begin_layout Itemize
35911 \begin_inset LatexCommand \index{long long (not supported)}
35916 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35923 \begin_layout Itemize
35925 \begin_inset LatexCommand \index{double (not supported)}
35929 ' precision floating point
35930 \begin_inset LatexCommand \index{Floating point support}
35937 \begin_layout Itemize
35939 \begin_inset LatexCommand \index{K\&R style}
35943 function declarations are NOT allowed.
35947 \begin_layout Verse
35950 foo(i,j) /* this old style of function declarations */
35952 int i,j; /* is valid
35953 in ANSI but not valid in SDCC */
35968 \begin_layout Itemize
35969 Most enhancements in C99 are not supported, e.g.:
35973 \begin_layout Verse
35980 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35984 \begin_layout Itemize
35985 But some have been added recently in SDCC 2.7.0.
35986 They must be considered alpha quality however.
35990 \begin_layout Verse
35995 \begin_inset LatexCommand \index{inline (not supported)}
36001 int increment (int a) { return a+1; } /* inlines the increment without
36002 function call overhead */
36007 \begin_inset LatexCommand \index{inline (not supported)}
36013 p; /* accepted but ignored */
36017 \begin_layout Itemize
36018 Certain words that are valid identifiers in the standard may be reserved
36019 words in SDCC unless the
36025 \begin_layout Standard
36035 \begin_inset LatexCommand \index{-\/-std-c89}
36043 \begin_layout Standard
36053 \begin_inset LatexCommand \index{-\/-std-c99}
36059 command line options are used.
36060 These may include (depending on the selected processor): 'at', 'banked',
36061 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36062 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36063 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36065 Compliant equivalents of these keywords are always available in a form
36066 that begin with two underscores
36067 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36072 '__data' instead of 'data'.
36075 \begin_layout Section
36076 Cyclomatic Complexity
36077 \begin_inset LatexCommand \index{Cyclomatic complexity}
36084 \begin_layout Standard
36085 Cyclomatic complexity of a function is defined as the number of independent
36086 paths the program can take during execution of the function.
36087 This is an important number since it defines the number test cases you
36088 have to generate to validate the function.
36089 The accepted industry standard for complexity number is 10, if the cyclomatic
36090 complexity reported by SDCC exceeds 10 you should think about simplification
36091 of the function logic.
36092 Note that the complexity level is not related to the number of lines of
36093 code in a function.
36094 Large functions can have low complexity, and small functions can have large
36100 SDCC uses the following formula to compute the complexity:
36105 \begin_layout Standard
36106 complexity = (number of edges in control flow graph) - (number of nodes
36107 in control flow graph) + 2;
36111 Having said that the industry standard is 10,
36112 you should be aware that in some cases it be may unavoidable to have a
36113 complexity level of less than 10.
36114 For example if you have switch statement with more than 10 case labels,
36115 each case label adds one to the complexity level.
36116 The complexity level is by no means an absolute measure of the algorithmic
36117 complexity of the function, it does however provide a good starting point
36118 for which functions you might look at for further optimization.
36121 \begin_layout Section
36122 Retargetting for other Processors
36125 \begin_layout Standard
36126 The issues for retargetting the compiler are far too numerous to be covered
36128 What follows is a brief description of each of the seven phases of the
36129 compiler and its MCU dependency.
36132 \begin_layout Itemize
36133 Parsing the source and building the annotated parse tree.
36134 This phase is largely MCU independent (except for the language extensions).
36135 Syntax & semantic checks are also done in this phase, along with some initial
36136 optimizations like back patching labels and the pattern matching optimizations
36137 like bit-rotation etc.
36140 \begin_layout Itemize
36141 The second phase involves generating an intermediate code which can be easy
36142 manipulated during the later phases.
36143 This phase is entirely MCU independent.
36144 The intermediate code generation assumes the target machine has unlimited
36145 number of registers, and designates them with the name iTemp.
36146 The compiler can be made to dump a human readable form of the code generated
36151 \begin_layout Standard
36163 \begin_layout Itemize
36164 This phase does the bulk of the standard optimizations and is also MCU independe
36166 This phase can be broken down into several sub-phases:
36170 Break down intermediate
36171 code (iCode) into basic blocks.
36173 Do control flow & data flow analysis on the
36176 Do local common subexpression elimination, then global subexpressio
36179 Dead code elimination
36183 If loop optimizations
36184 caused any changes then do 'global subexpression elimination' and 'dead
36185 code elimination' again.
36188 \begin_layout Itemize
36189 This phase determines the live-ranges; by live range I mean those iTemp
36190 variables defined by the compiler that still survive after all the optimization
36192 Live range analysis
36193 \begin_inset LatexCommand \index{Live range analysis}
36197 is essential for register allocation, since these computation determines
36198 which of these iTemps will be assigned to registers, and for how long.
36201 \begin_layout Itemize
36202 Phase five is register allocation.
36203 There are two parts to this process.
36207 The first part I call 'register packing'
36208 (for lack of a better term).
36209 In this case several MCU specific expression folding is done to reduce
36214 The second part is more MCU independent and deals with
36215 allocating registers to the remaining live ranges.
36216 A lot of MCU specific code does creep into this phase because of the limited
36217 number of index registers available in the 8051.
36220 \begin_layout Itemize
36221 The Code generation phase is (unhappily), entirely MCU dependent and very
36222 little (if any at all) of this code can be reused for other MCU.
36223 However the scheme for allocating a homogenized assembler operand for each
36224 iCode operand may be reused.
36227 \begin_layout Itemize
36228 As mentioned in the optimization section the peep-hole optimizer is rule
36229 based system, which can reprogrammed for other MCUs.
36232 \begin_layout Standard
36233 More information is available in a wiki
36234 \begin_inset LatexCommand \index{wiki}
36239 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36243 ) and in the thread
36244 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36251 \begin_layout Chapter
36253 \begin_inset LatexCommand \index{Compiler internals}
36260 \begin_layout Section
36261 The anatomy of the compiler
36262 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36269 \begin_layout Standard
36272 This is an excerpt from an article published in Circuit Cellar Magazine
36278 It's a little outdated (the compiler is much more efficient now and user/develo
36279 per friendly), but pretty well exposes the guts of it all.
36285 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36286 It is fairly easy to retarget for other 8-bit MCU.
36287 Here we take a look at some of the internals of the compiler.
36291 \begin_layout Paragraph*
36293 \begin_inset LatexCommand \index{Parsing}
36300 \begin_layout Standard
36301 Parsing the input source file and creating an AST (Annotated Syntax Tree
36302 \begin_inset LatexCommand \index{Annotated syntax tree}
36307 This phase also involves propagating types (annotating each node of the
36308 parse tree with type information) and semantic analysis.
36309 There are some MCU specific parsing rules.
36310 For example the storage classes, the extended storage classes are MCU specific
36311 while there may be a xdata storage class for 8051 there is no such storage
36312 class for z80 or Atmel AVR.
36313 SDCC allows MCU specific storage class extensions, i.e.
36314 xdata will be treated as a storage class specifier when parsing 8051 C
36315 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36319 \begin_layout Paragraph*
36321 \begin_inset LatexCommand \index{iCode}
36328 \begin_layout Standard
36329 Intermediate code generation.
36330 In this phase the AST is broken down into three-operand form (iCode).
36331 These three operand forms are represented as doubly linked lists.
36332 ICode is the term given to the intermediate form generated by the compiler.
36333 ICode example section shows some examples of iCode generated for some simple
36334 C source functions.
36337 \begin_layout Paragraph*
36339 \begin_inset LatexCommand \index{Optimizations}
36346 \begin_layout Standard
36347 Bulk of the target independent optimizations is performed in this phase.
36348 The optimizations include constant propagation, common sub-expression eliminati
36349 on, loop invariant code movement, strength reduction of loop induction variables
36350 and dead-code elimination.
36353 \begin_layout Paragraph*
36354 Live range analysis
36355 \begin_inset LatexCommand \index{Live range analysis}
36362 \begin_layout Standard
36363 During intermediate code generation phase, the compiler assumes the target
36364 machine has infinite number of registers and generates a lot of temporary
36366 The live range computation determines the lifetime of each of these compiler-ge
36367 nerated temporaries.
36368 A picture speaks a thousand words.
36369 ICode example sections show the live range annotations for each of the
36371 It is important to note here, each iCode is assigned a number in the order
36372 of its execution in the function.
36373 The live ranges are computed in terms of these numbers.
36374 The from number is the number of the iCode which first defines the operand
36375 and the to number signifies the iCode which uses this operand last.
36378 \begin_layout Paragraph*
36379 Register Allocation
36380 \begin_inset LatexCommand \index{Register allocation}
36387 \begin_layout Standard
36388 The register allocation determines the type and number of registers needed
36390 In most MCUs only a few registers can be used for indirect addressing.
36391 In case of 8051 for example the registers R0 & R1 can be used to indirectly
36392 address the internal ram and DPTR to indirectly address the external ram.
36393 The compiler will try to allocate the appropriate register to pointer variables
36395 ICode example section shows the operands annotated with the registers assigned
36397 The compiler will try to keep operands in registers as much as possible;
36398 there are several schemes the compiler uses to do achieve this.
36399 When the compiler runs out of registers the compiler will check to see
36400 if there are any live operands which is not used or defined in the current
36401 basic block being processed, if there are any found then it will push that
36402 operand and use the registers in this block, the operand will then be popped
36403 at the end of the basic block.
36407 \begin_layout Standard
36408 There are other MCU specific considerations in this phase.
36409 Some MCUs have an accumulator; very short-lived operands could be assigned
36410 to the accumulator instead of a general-purpose register.
36413 \begin_layout Paragraph*
36417 \begin_layout Standard
36418 Figure II gives a table of iCode
36419 \begin_inset LatexCommand \index{iCode}
36423 operations supported by the compiler.
36424 The code generation involves translating these operations into corresponding
36425 assembly code for the processor.
36426 This sounds overly simple but that is the essence of code generation.
36427 Some of the iCode operations are generated on a MCU specific manner for
36428 example, the z80 port does not use registers to pass parameters so the
36429 SEND and RECV iCode operations will not be generated, and it also does
36430 not support JUMPTABLES.
36436 \begin_layout Standard
36440 \begin_inset Tabular
36441 <lyxtabular version="3" rows="39" columns="4">
36442 <features islongtable="true" headBottomDL="true">
36443 <column alignment="block" valignment="top" leftline="true" width="13col%">
36444 <column alignment="left" valignment="top" leftline="true" width="13col%">
36445 <column alignment="block" valignment="top" leftline="true" width="22col%">
36446 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36447 <row topline="true" bottomline="true" endhead="true">
36448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36451 \begin_layout Standard
36457 \begin_inset LatexCommand \index{iCode}
36466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36469 \begin_layout Standard
36477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36480 \begin_layout Standard
36488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36491 \begin_layout Standard
36500 <row topline="true">
36501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36504 \begin_layout Standard
36512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36515 \begin_layout Standard
36518 IC_LEFT() IC_RESULT()
36523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36526 \begin_layout Standard
36534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36537 \begin_layout Standard
36540 IC_RESULT = ! IC_LEFT;
36546 <row topline="true">
36547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36550 \begin_layout Standard
36558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36561 \begin_layout Standard
36564 IC_LEFT() IC_RESULT()
36569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36572 \begin_layout Standard
36575 Bitwise complement of
36580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36583 \begin_layout Standard
36586 IC_RESULT = ~IC_LEFT;
36592 <row topline="true">
36593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36596 \begin_layout Standard
36604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36607 \begin_layout Standard
36610 IC_LEFT() IC_RESULT()
36615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36618 \begin_layout Standard
36621 Rotate right with carry
36626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36629 \begin_layout Standard
36632 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36638 <row topline="true">
36639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36642 \begin_layout Standard
36650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36653 \begin_layout Standard
36656 IC_LEFT() IC_RESULT()
36661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36664 \begin_layout Standard
36667 Rotate left with carry
36672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36675 \begin_layout Standard
36678 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36684 <row topline="true">
36685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36688 \begin_layout Standard
36696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36699 \begin_layout Standard
36702 IC_LEFT() IC_RESULT()
36707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36710 \begin_layout Standard
36713 Get the highest order bit of IC_LEFT
36718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36721 \begin_layout Standard
36724 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36730 <row topline="true">
36731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36734 \begin_layout Standard
36742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36745 \begin_layout Standard
36748 IC_LEFT() IC_RESULT()
36753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36756 \begin_layout Standard
36764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36767 \begin_layout Standard
36770 IC_RESULT = - IC_LEFT;
36776 <row topline="true">
36777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36780 \begin_layout Standard
36788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36791 \begin_layout Standard
36799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36802 \begin_layout Standard
36805 Push the operand into stack
36810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36813 \begin_layout Standard
36822 <row topline="true">
36823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36826 \begin_layout Standard
36834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36837 \begin_layout Standard
36845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36848 \begin_layout Standard
36851 Pop the operand from the stack
36856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36859 \begin_layout Standard
36868 <row topline="true">
36869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36872 \begin_layout Standard
36880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36883 \begin_layout Standard
36886 IC_LEFT() IC_RESULT()
36891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36894 \begin_layout Standard
36897 Call the function represented by IC_LEFT
36902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36905 \begin_layout Standard
36908 IC_RESULT = IC_LEFT();
36914 <row topline="true">
36915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36918 \begin_layout Standard
36926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36929 \begin_layout Standard
36932 IC_LEFT() IC_RESULT()
36937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36940 \begin_layout Standard
36943 Call via function pointer
36948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36951 \begin_layout Standard
36954 IC_RESULT = (*IC_LEFT)();
36960 <row topline="true">
36961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36964 \begin_layout Standard
36972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36975 \begin_layout Standard
36983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36986 \begin_layout Standard
36989 Return the value in operand IC_LEFT
36994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36997 \begin_layout Standard
37006 <row topline="true">
37007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37010 \begin_layout Standard
37018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37021 \begin_layout Standard
37029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37032 \begin_layout Standard
37040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37043 \begin_layout Standard
37052 <row topline="true">
37053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37056 \begin_layout Standard
37064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37067 \begin_layout Standard
37075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37078 \begin_layout Standard
37086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37089 \begin_layout Standard
37098 <row topline="true">
37099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37102 \begin_layout Standard
37110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37113 \begin_layout Standard
37116 IC_LEFT() IC_RIGHT() IC_RESULT()
37121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37124 \begin_layout Standard
37132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37135 \begin_layout Standard
37138 IC_RESULT = IC_LEFT + IC_RIGHT
37144 <row topline="true">
37145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37148 \begin_layout Standard
37156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37159 \begin_layout Standard
37162 IC_LEFT() IC_RIGHT() IC_RESULT()
37167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37170 \begin_layout Standard
37178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37181 \begin_layout Standard
37184 IC_RESULT = IC_LEFT - IC_RIGHT
37190 <row topline="true">
37191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37194 \begin_layout Standard
37202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37205 \begin_layout Standard
37208 IC_LEFT() IC_RIGHT() IC_RESULT()
37213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37216 \begin_layout Standard
37224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37227 \begin_layout Standard
37230 IC_RESULT = IC_LEFT * IC_RIGHT;
37236 <row topline="true">
37237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37240 \begin_layout Standard
37248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37251 \begin_layout Standard
37254 IC_LEFT() IC_RIGHT() IC_RESULT()
37259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37262 \begin_layout Standard
37270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37273 \begin_layout Standard
37276 IC_RESULT = IC_LEFT / IC_RIGHT;
37282 <row topline="true">
37283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37286 \begin_layout Standard
37294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37297 \begin_layout Standard
37300 IC_LEFT() IC_RIGHT() IC_RESULT()
37305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37308 \begin_layout Standard
37316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37319 \begin_layout Standard
37322 IC_RESULT = IC_LEFT % IC_RIGHT;
37328 <row topline="true">
37329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37332 \begin_layout Standard
37340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37343 \begin_layout Standard
37346 IC_LEFT() IC_RIGHT() IC_RESULT()
37351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37354 \begin_layout Standard
37362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37365 \begin_layout Standard
37368 IC_RESULT = IC_LEFT < IC_RIGHT;
37374 <row topline="true">
37375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37378 \begin_layout Standard
37386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37389 \begin_layout Standard
37392 IC_LEFT() IC_RIGHT() IC_RESULT()
37397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37400 \begin_layout Standard
37408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37411 \begin_layout Standard
37414 IC_RESULT = IC_LEFT > IC_RIGHT;
37420 <row topline="true">
37421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37424 \begin_layout Standard
37432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37435 \begin_layout Standard
37438 IC_LEFT() IC_RIGHT() IC_RESULT()
37443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37446 \begin_layout Standard
37454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37457 \begin_layout Standard
37460 IC_RESULT = IC_LEFT == IC_RIGHT;
37466 <row topline="true">
37467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37470 \begin_layout Standard
37478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37481 \begin_layout Standard
37484 IC_LEFT() IC_RIGHT() IC_RESULT()
37489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37492 \begin_layout Standard
37495 Logical and operation
37500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37503 \begin_layout Standard
37506 IC_RESULT = IC_LEFT && IC_RIGHT;
37512 <row topline="true">
37513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37516 \begin_layout Standard
37524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37527 \begin_layout Standard
37530 IC_LEFT() IC_RIGHT() IC_RESULT()
37535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37538 \begin_layout Standard
37541 Logical or operation
37546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37549 \begin_layout Standard
37552 IC_RESULT = IC_LEFT || IC_RIGHT;
37558 <row topline="true">
37559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37562 \begin_layout Standard
37570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37573 \begin_layout Standard
37576 IC_LEFT() IC_RIGHT() IC_RESULT()
37581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37584 \begin_layout Standard
37592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37595 \begin_layout Standard
37598 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37604 <row topline="true">
37605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37608 \begin_layout Standard
37616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37619 \begin_layout Standard
37622 IC_LEFT() IC_RIGHT() IC_RESULT()
37627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37630 \begin_layout Standard
37638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37641 \begin_layout Standard
37644 IC_RESULT = IC_LEFT | IC_RIGHT;
37650 <row topline="true">
37651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37654 \begin_layout Standard
37662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37665 \begin_layout Standard
37668 IC_LEFT() IC_RIGHT() IC_RESULT()
37673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37676 \begin_layout Standard
37684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37687 \begin_layout Standard
37690 IC_RESULT = IC_LEFT & IC_RIGHT;
37696 <row topline="true">
37697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37700 \begin_layout Standard
37708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37711 \begin_layout Standard
37714 IC_LEFT() IC_RIGHT() IC_RESULT()
37719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37722 \begin_layout Standard
37730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37733 \begin_layout Standard
37736 IC_RESULT = IC_LEFT << IC_RIGHT
37742 <row topline="true">
37743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37746 \begin_layout Standard
37754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37757 \begin_layout Standard
37760 IC_LEFT() IC_RIGHT() IC_RESULT()
37765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37768 \begin_layout Standard
37776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37779 \begin_layout Standard
37782 IC_RESULT = IC_LEFT >> IC_RIGHT
37788 <row topline="true">
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37792 \begin_layout Standard
37802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37805 \begin_layout Standard
37808 IC_LEFT() IC_RESULT()
37813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37816 \begin_layout Standard
37824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37827 \begin_layout Standard
37830 IC_RESULT = (*IC_LEFT);
37836 <row topline="true">
37837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37840 \begin_layout Standard
37848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37851 \begin_layout Standard
37854 IC_RIGHT() IC_RESULT()
37859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37862 \begin_layout Standard
37870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37873 \begin_layout Standard
37876 (*IC_RESULT) = IC_RIGHT;
37882 <row topline="true">
37883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37886 \begin_layout Standard
37894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37897 \begin_layout Standard
37900 IC_RIGHT() IC_RESULT()
37905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37908 \begin_layout Standard
37916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37919 \begin_layout Standard
37922 IC_RESULT = IC_RIGHT;
37928 <row topline="true">
37929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37932 \begin_layout Standard
37940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37943 \begin_layout Standard
37946 IC_COND IC_TRUE IC_LABEL
37951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37954 \begin_layout Standard
37958 If true label is present then jump to true label if condition is true else
37959 jump to false label if condition is false
37964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37967 \begin_layout Standard
37970 if (IC_COND) goto IC_TRUE;
37976 If (!IC_COND) goto IC_FALSE;
37982 <row topline="true">
37983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37986 \begin_layout Standard
37994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37997 \begin_layout Standard
38000 IC_LEFT() IC_RESULT()
38005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38008 \begin_layout Standard
38016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38019 \begin_layout Standard
38022 IC_RESULT = &IC_LEFT();
38028 <row topline="true">
38029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38032 \begin_layout Standard
38040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38043 \begin_layout Standard
38046 IC_JTCOND IC_JTLABELS
38051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38054 \begin_layout Standard
38057 Jump to list of labels depending on the value of JTCOND
38062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38065 \begin_layout Standard
38074 <row topline="true">
38075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38078 \begin_layout Standard
38086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38089 \begin_layout Standard
38092 IC_RIGHT() IC_LEFT() IC_RESULT()
38097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38100 \begin_layout Standard
38108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38111 \begin_layout Standard
38114 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38120 <row topline="true">
38121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38124 \begin_layout Standard
38132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38135 \begin_layout Standard
38143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38146 \begin_layout Standard
38149 This is used for passing parameters in registers;
38151 move IC_LEFT to the next
38152 available parameter register.
38157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38160 \begin_layout Standard
38169 <row topline="true">
38170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38173 \begin_layout Standard
38181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38184 \begin_layout Standard
38192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38195 \begin_layout Standard
38198 This is used for receiving parameters passed in registers;
38201 in the next parameter register to IC_RESULT
38206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38209 \begin_layout Standard
38218 <row topline="true" bottomline="true">
38219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38222 \begin_layout Standard
38226 (some more have been added)
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38234 \begin_layout Standard
38240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38243 \begin_layout Standard
38249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38252 \begin_layout Standard
38276 \begin_layout Standard
38277 \begin_inset Note Note
38280 \begin_layout Standard
38281 In the original article Figure II was announced to be downloadable on
38286 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38294 \begin_layout Paragraph*
38296 \begin_inset LatexCommand \index{iCode}
38303 \begin_layout Standard
38304 This section shows some details of iCode.
38305 The example C code does not do anything useful; it is used as an example
38306 to illustrate the intermediate code generated by the compiler.
38309 \begin_layout Verse
38319 /* This function does nothing useful.
38326 for the purpose of explaining iCode */
38329 short function (data
38338 short i=10; \InsetSpace ~
38340 /* dead initialization eliminated */
38346 /* dead initialization eliminated */
38374 /* compiler detects i,j to be induction
38379 for (i = 0, j = 10 ; i < 10 ; i++, j
38385 \begin_layout Standard
38408 mul += i * 3; \InsetSpace ~
38410 /* this multiplication remains */
38417 j * 3;\InsetSpace ~
38419 /* this multiplication changed to addition */
38433 \begin_layout Standard
38434 In addition to the operands each iCode contains information about the filename
38435 and line it corresponds to in the source file.
38436 The first field in the listing should be interpreted as follows:
38441 Filename(linenumber: iCode Execution sequence number : ICode hash table
38442 key : loop depth of the iCode).
38447 Then follows the human readable form of the ICode operation.
38448 Each operand of this triplet form can be of three basic types a) compiler
38449 generated temporary b) user defined variable c) a constant value.
38450 Note that local variables and parameters are replaced by compiler generated
38453 \begin_inset LatexCommand \index{Live range analysis}
38457 are computed only for temporaries (i.e.
38458 live ranges are not computed for global variables).
38460 \begin_inset LatexCommand \index{Register allocation}
38464 are allocated for temporaries only.
38465 Operands are formatted in the following manner:
38470 Operand Name [lr live-from : live-to ] { type information } [ registers
38476 As mentioned earlier the live ranges are computed in terms of the execution
38477 sequence number of the iCodes, for example
38479 the iTemp0 is live from (i.e.
38480 first defined in iCode with execution sequence number 3, and is last used
38481 in the iCode with sequence number 5).
38482 For induction variables such as iTemp21 the live range computation extends
38483 the lifetime from the start to the end of the loop.
38485 The register allocator
38486 used the live range information to allocate registers, the same registers
38487 may be used for different temporaries if their live ranges do not overlap,
38488 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38489 ranges do not overlap.
38490 In addition the allocator also takes into consideration the type and usage
38491 of a temporary, for example itemp6 is a pointer to near space and is used
38492 as to fetch data from (i.e.
38493 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38494 Some short lived temporaries are allocated to special registers which have
38495 meaning to the code generator e.g.
38496 iTemp13 is allocated to a pseudo register CC which tells the back end that
38497 the temporary is used only for a conditional jump the code generation makes
38498 use of this information to optimize a compare and jump ICode.
38502 \begin_inset LatexCommand \index{Loop optimization}
38506 performed by the compiler.
38507 It can detect induction variables iTemp21(i) and iTemp23(j).
38508 Also note the compiler does selective strength reduction
38509 \begin_inset LatexCommand \index{Strength reduction}
38514 the multiplication of an induction variable in line 18 (gint = j * 3) is
38515 changed to addition, a new temporary iTemp17 is allocated and assigned
38516 a initial value, a constant 3 is then added for each iteration of the loop.
38517 The compiler does not change the multiplication
38518 \begin_inset LatexCommand \index{Multiplication}
38522 in line 17 however since the processor does support an 8 * 8 bit multiplication.
38525 Note the dead code elimination
38526 \begin_inset LatexCommand \index{Dead-code elimination}
38530 optimization eliminated the dead assignments in line 7 & 8 to I and sum
38536 \begin_layout Standard
38539 Sample.c (5:1:0:0) _entry($9) :
38542 \begin_layout Standard
38545 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38548 \begin_layout Standard
38551 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
38554 \begin_layout Standard
38557 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38560 \begin_layout Standard
38563 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38567 \begin_layout Standard
38570 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38573 \begin_layout Standard
38576 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38580 \begin_layout Standard
38583 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38586 \begin_layout Standard
38589 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38593 \begin_layout Standard
38596 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38600 \begin_layout Standard
38603 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38607 \begin_layout Standard
38610 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38614 \begin_layout Standard
38617 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38618 * int}[r0] + 0x2 {short}
38621 \begin_layout Standard
38624 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38627 \begin_layout Standard
38630 Sample.c(11:17:21:0)_whilebreak_0($3) :
38633 \begin_layout Standard
38636 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38639 \begin_layout Standard
38642 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38645 \begin_layout Standard
38648 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38651 \begin_layout Standard
38654 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38657 \begin_layout Standard
38660 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38663 \begin_layout Standard
38666 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38669 \begin_layout Standard
38672 Sample.c(15:24:26:1)_forcond_0($4) :
38675 \begin_layout Standard
38678 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38682 \begin_layout Standard
38685 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38688 \begin_layout Standard
38691 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38692 + ITemp21 [lr21:38]{short}[r4]
38695 \begin_layout Standard
38698 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38702 \begin_layout Standard
38705 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38706 + iTemp15 [lr29:30]{short}[r1]
38709 \begin_layout Standard
38712 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38716 \begin_layout Standard
38719 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38723 \begin_layout Standard
38726 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38730 \begin_layout Standard
38733 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38737 \begin_layout Standard
38740 Sample.c(19:38:47:1) goto _forcond_0($4)
38743 \begin_layout Standard
38746 Sample.c(19:39:48:0)_forbreak_0($7) :
38749 \begin_layout Standard
38752 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38753 + ITemp11 [lr19:40]{short}[r3]
38756 \begin_layout Standard
38759 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38762 \begin_layout Standard
38765 Sample.c(20:42:51:0)_return($8) :
38768 \begin_layout Standard
38771 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38777 Finally the code generated for this function:
38782 \begin_layout Standard
38788 \begin_layout Standard
38794 \begin_layout Standard
38802 \begin_layout Standard
38808 \begin_layout Standard
38816 \begin_layout Standard
38822 \begin_layout Standard
38825 ; ----------------------------------------------
38828 \begin_layout Standard
38831 ; function function
38834 \begin_layout Standard
38837 ; ----------------------------------------------
38840 \begin_layout Standard
38846 \begin_layout Standard
38849 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
38852 \begin_layout Standard
38860 \begin_layout Standard
38863 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38866 \begin_layout Standard
38874 \begin_layout Standard
38877 ;_whilecontinue_0($1) :
38880 \begin_layout Standard
38886 \begin_layout Standard
38889 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38892 \begin_layout Standard
38895 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38898 \begin_layout Standard
38906 \begin_layout Standard
38914 \begin_layout Standard
38922 \begin_layout Standard
38930 \begin_layout Standard
38938 \begin_layout Standard
38946 \begin_layout Standard
38954 \begin_layout Standard
38960 \begin_layout Standard
38963 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38966 \begin_layout Standard
38974 \begin_layout Standard
38982 \begin_layout Standard
38985 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38988 \begin_layout Standard
38996 \begin_layout Standard
39004 \begin_layout Standard
39012 \begin_layout Standard
39020 \begin_layout Standard
39028 \begin_layout Standard
39036 \begin_layout Standard
39039 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39042 \begin_layout Standard
39050 \begin_layout Standard
39058 \begin_layout Standard
39066 \begin_layout Standard
39074 \begin_layout Standard
39082 \begin_layout Standard
39085 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39088 \begin_layout Standard
39096 \begin_layout Standard
39104 \begin_layout Standard
39112 \begin_layout Standard
39115 ; iTemp6 [lr5:16]{_near * int}[r0] =
39118 \begin_layout Standard
39121 ; iTemp6 [lr5:16]{_near * int}[r0] +
39124 \begin_layout Standard
39130 \begin_layout Standard
39138 \begin_layout Standard
39141 ; goto _whilecontinue_0($1)
39144 \begin_layout Standard
39152 \begin_layout Standard
39155 ; _whilebreak_0($3) :
39158 \begin_layout Standard
39164 \begin_layout Standard
39167 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39170 \begin_layout Standard
39178 \begin_layout Standard
39181 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39184 \begin_layout Standard
39192 \begin_layout Standard
39195 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39198 \begin_layout Standard
39206 \begin_layout Standard
39209 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39212 \begin_layout Standard
39220 \begin_layout Standard
39228 \begin_layout Standard
39231 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39234 \begin_layout Standard
39242 \begin_layout Standard
39250 \begin_layout Standard
39256 \begin_layout Standard
39262 \begin_layout Standard
39265 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39268 \begin_layout Standard
39271 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39274 \begin_layout Standard
39282 \begin_layout Standard
39290 \begin_layout Standard
39298 \begin_layout Standard
39306 \begin_layout Standard
39314 \begin_layout Standard
39320 \begin_layout Standard
39323 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
39326 \begin_layout Standard
39329 ; iTemp21 [lr21:38]{short}[r4]
39332 \begin_layout Standard
39340 \begin_layout Standard
39348 \begin_layout Standard
39356 \begin_layout Standard
39359 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39362 \begin_layout Standard
39370 \begin_layout Standard
39378 \begin_layout Standard
39386 \begin_layout Standard
39394 \begin_layout Standard
39397 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
39400 \begin_layout Standard
39403 ; iTemp15 [lr29:30]{short}[r1]
39406 \begin_layout Standard
39414 \begin_layout Standard
39422 \begin_layout Standard
39425 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39428 \begin_layout Standard
39436 \begin_layout Standard
39444 \begin_layout Standard
39452 \begin_layout Standard
39460 \begin_layout Standard
39468 \begin_layout Standard
39476 \begin_layout Standard
39479 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39482 \begin_layout Standard
39490 \begin_layout Standard
39498 \begin_layout Standard
39506 \begin_layout Standard
39514 \begin_layout Standard
39522 \begin_layout Standard
39530 \begin_layout Standard
39533 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39536 \begin_layout Standard
39544 \begin_layout Standard
39547 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39550 \begin_layout Standard
39558 \begin_layout Standard
39563 cjne r5,#0xff,00104$
39566 \begin_layout Standard
39574 \begin_layout Standard
39577 ; goto _forcond_0($4)
39580 \begin_layout Standard
39588 \begin_layout Standard
39591 ; _forbreak_0($7) :
39594 \begin_layout Standard
39600 \begin_layout Standard
39603 ; ret iTemp24 [lr40:41]{short}
39606 \begin_layout Standard
39614 \begin_layout Standard
39622 \begin_layout Standard
39630 \begin_layout Standard
39636 \begin_layout Standard
39642 \begin_layout Standard
39652 \begin_layout Section
39653 A few words about basic block successors, predecessors and dominators
39656 \begin_layout Standard
39657 Successors are basic blocks
39658 \begin_inset LatexCommand \index{Basic blocks}
39662 that might execute after this basic block.
39664 Predecessors are basic blocks
39665 that might execute before reaching this basic block.
39667 Dominators are basic
39668 blocks that WILL execute before reaching this basic block.
39673 \begin_layout Standard
39677 \begin_layout Standard
39681 \begin_layout Standard
39689 \begin_layout Standard
39693 \begin_layout Standard
39701 \begin_layout Standard
39707 \begin_layout Standard
39708 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39711 \begin_layout Standard
39712 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39715 \begin_layout Standard
39716 c) domVect of [BB4] = BB1 ...
39717 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39721 \begin_layout Chapter
39725 \begin_layout Standard
39726 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39736 Thanks to all the other volunteer developers who have helped with coding,
39737 testing, web-page creation, distribution sets, etc.
39738 You know who you are :-)
39746 Thanks to Sourceforge
39747 \begin_inset LatexCommand \url{http://www.sf.net}
39751 which has hosted the project since 1999 and donates significant download
39760 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39761 cycles and bandwidth for snapshot builds.
39766 \begin_layout Standard
39767 This document was initially written by Sandeep Dutta
39770 \begin_layout Standard
39771 All product names mentioned herein may be trademarks
39772 \begin_inset LatexCommand \index{Trademarks}
39776 of their respective companies.
39780 \begin_layout Section*
39784 \begin_layout Standard
39785 To avoid confusion, the installation and building options for SDCC itself
39786 (chapter 2) are not part of the index.
39789 \begin_layout Standard
39790 \begin_inset LatexCommand \printindex{}