* sim/ucsim/configure.in,
[fw/sdcc] / doc / sdccman.lyx
index 2582b044957f921d6f4b727f56a85a22b603e24d..8b6f8ed12c22e92cf6f27d65ab4e5cb67bb3eb58 100644 (file)
@@ -81,7 +81,7 @@ SDCC Compiler User Guide
 
 
 \size normal 
-SDCC 2.3.7
+SDCC 2.4.0
 \size footnotesize 
 
 \newline 
@@ -490,7 +490,7 @@ code banking
 \newline 
 
 \family default 
-If you can think of some more, please see the chapter 
+If you can think of some more, please see the section 
 \begin_inset LatexCommand \ref{sub:Requesting-Features}
 
 \end_inset 
@@ -3395,7 +3395,7 @@ Adjust your environment variable PATH to include the location of the bin
 Building the Documentation
 \layout Standard
 
-If the necessary tools (LyX, LaTeX, latex2html) are installed it is as easy
+If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
  as changing into the doc directory and typing 
 \family sans 
 \series bold 
@@ -3411,7 +3411,8 @@ make
 \family default 
 \series default 
  there.
- You're invited to make changes and additions to this manual.
+ You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
+x).
  Using LyX 
 \begin_inset LatexCommand \url{www.lyx.org}
 
@@ -3438,7 +3439,22 @@ Reading the Documentation
 
 Currently reading the document in pdf format is recommended, as for unknown
  reason the hyperlinks are working there whereas in the html version they
- are not.
+ are not
+\begin_inset Foot
+collapsed false
+
+\layout Standard
+
+If you should know why please drop us a note
+\end_inset 
+
+.
+ You'll find the pdf version at 
+\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
+
+\end_inset 
+
+.
 \newline 
 This documentation is in some aspects different from a commercial documentation:
  
@@ -3453,7 +3469,7 @@ It tries to document SDCC for several processor architectures in one document
 
  currently matches SDCC for mcs51 and DS390 best and does give too few informati
 on about f.e.
- Z80, PIC and HC08.
+ Z80, PIC14, PIC16 and HC08.
 \layout Itemize
 
 There are many references pointing away from this documentation.
@@ -4212,7 +4228,7 @@ objdump
 \end_inset 
 
 ).
- Both formats are documented in the the documentation of srecord
+ Both formats are documented in the documentation of srecord
 \begin_inset LatexCommand \index{srecord (tool)}
 
 \end_inset 
@@ -4221,7 +4237,7 @@ objdump
 \layout Itemize
 
 sourcefile.adb
-\begin_inset LatexCommand \index{.adb}
+\begin_inset LatexCommand \index{<file>.adb}
 
 \end_inset 
 
@@ -4471,7 +4487,7 @@ first
  file specified in the command line, since the linkage editor processes
  file in the order they are presented to it.
  The linker is invoked from SDCC using a script file with extension .lnk
-\begin_inset LatexCommand \index{.lnk}
+\begin_inset LatexCommand \index{<file>.lnk}
 
 \end_inset 
 
@@ -4493,7 +4509,7 @@ Some reusable routines may be compiled into a library, see the documentation
  for how to create a 
 \emph on 
 .lib
-\begin_inset LatexCommand \index{.lib}
+\begin_inset LatexCommand \index{<file>.lib}
 
 \end_inset 
 
@@ -4550,6 +4566,243 @@ The most efficient way to use libraries is to keep separate modules in separate
 libsdcc.lib
 \emph default 
  in the directory <installdir>/share/lib/small.
+\layout Subsection
+
+Using sdcclib to Create and Manage Libraries
+\begin_inset LatexCommand \index{sdcclib}
+
+\end_inset 
+
+
+\layout Standard
+
+Alternatively, instead of having a .rel file for each entry on the library
+ file as described in the preceding section, sdcclib can be used to embed
+ all the modules belonging to such library in the library file itself.
+ This results in a larger library file, but it greatly reduces the number
+ of disk files accessed by the linker.
+  Additionally, the packed library file contains an index of all include
+ modules and symbols that significantly speeds up the linking process.
+ To display a list of options supported by sdcclib type:
+\newline 
+
+\layout Standard
+
+
+\family sans 
+\series bold 
+sdcclib -?
+\begin_inset LatexCommand \index{sdcclib}
+
+\end_inset 
+
+
+\newline 
+
+\newline 
+
+\family default 
+\series default 
+To create a new library file, start by compiling all the required modules.
+ For example:
+\newline 
+
+\layout Standard
+
+
+\series bold 
+sdcc -c _divsint.c
+\layout Standard
+
+
+\series bold 
+sdcc -c _divuint.c
+\layout Standard
+
+
+\series bold 
+sdcc -c _modsint.c
+\layout Standard
+
+
+\series bold 
+sdcc -c _moduint.c
+\layout Standard
+
+
+\series bold 
+sdcc -c _mulint.c
+\newline 
+
+\layout Standard
+
+This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
+ and _mulint.rel.
+ The next step is to add the .rel files to the library file:
+\newline 
+
+\layout Standard
+
+
+\series bold 
+sdcclib libint.lib _divsint.rel
+\begin_inset LatexCommand \index{sdcclib}
+
+\end_inset 
+
+
+\layout Standard
+
+
+\series bold 
+sdcclib libint.lib _divuint.rel
+\layout Standard
+
+
+\series bold 
+sdcclib libint.lib _modsint.rel
+\layout Standard
+
+
+\series bold 
+sdcclib libint.lib _moduint.rel
+\layout Standard
+
+
+\series bold 
+sdcclib libint.lib _mulint.rel
+\series default 
+
+\newline 
+
+\layout Standard
+
+If the file already exists in the library, it will be replaced.
+ To see what modules and symbols are included in the library, options -s
+ and -m are available.
+ For example:
+\newline 
+
+\newline 
+
+\series bold 
+sdcclib -s libint.lib
+\begin_inset LatexCommand \index{sdcclib}
+
+\end_inset 
+
+
+\newline 
+_divsint.rel:
+\layout Standard
+
+
+\series bold 
+__divsint_a_1_1
+\layout Standard
+
+
+\series bold 
+__divsint_PARM_2
+\layout Standard
+
+
+\series bold 
+__divsint
+\newline 
+_divuint.rel:
+\layout Standard
+
+
+\series bold 
+__divuint_a_1_1
+\layout Standard
+
+
+\series bold 
+__divuint_PARM_2
+\layout Standard
+
+
+\series bold 
+__divuint_reste_1_1
+\layout Standard
+
+
+\series bold 
+__divuint_count_1_1
+\layout Standard
+
+
+\series bold 
+__divuint
+\newline 
+_modsint.rel:
+\layout Standard
+
+
+\series bold 
+__modsint_a_1_1
+\layout Standard
+
+
+\series bold 
+__modsint_PARM_2
+\layout Standard
+
+
+\series bold 
+__modsint
+\newline 
+_moduint.rel:
+\layout Standard
+
+
+\series bold 
+__moduint_a_1_1
+\layout Standard
+
+
+\series bold 
+__moduint_PARM_2
+\layout Standard
+
+
+\series bold 
+__moduint_count_1_1
+\layout Standard
+
+
+\series bold 
+__moduint
+\newline 
+_mulint.rel:
+\layout Standard
+
+
+\series bold 
+__mulint_PARM_2
+\layout Standard
+
+
+\series bold 
+__mulint
+\newline 
+
+\layout Standard
+
+If the source files are compiled using --debug, the corresponding debug
+ information file .adb will be include in the library file as well.
+ The library files created with sdcclib are plain text files, so they can
+ be viewed with a text editor.
+ It is not recomended to modify a library file created with sdcclib using
+ a text editor, as there are file indexes numbers located accross the file
+ used by the linker to quickly locate the required module to link.
+ Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
+ it can be safely deleted, since all the information required for linking
+ is embedded in the library file itself.
+ Library files created using sdcclib are used as described in the preceding
+ sections.
 \layout Section
 
 Command Line Options
@@ -4794,6 +5047,11 @@ Preprocessor Options
 \end_inset 
 
 
+\begin_inset LatexCommand \index{sdcpp (preprocessor)}
+
+\end_inset 
+
+
 \layout List
 \labelwidthstring 00.00.0000
 
@@ -4988,7 +5246,24 @@ preprocessorOption[,preprocessorOption]
 \end_inset 
 
 ...
- Pass the preprocessorOption to the preprocessor.
+ Pass the preprocessorOption to the preprocessor 
+\family typewriter 
+sdcpp
+\family default 
+
+\begin_inset LatexCommand \index{sdcpp (preprocessor)}
+
+\end_inset 
+
+.
+ SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
+ Collection (gcc), if you need more dedicated options please refer to the
+ documentation at 
+\begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
+
+\end_inset 
+
+.
 \layout Subsection
 
 Linker Options
@@ -5613,6 +5888,54 @@ status Collapsed
 
  Causes the linker to check if the code memory usage is within limits of
  the given value.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-stack-size
+\series default 
+\SpecialChar ~
+<Value>
+\begin_inset LatexCommand \index{-\/-stack-size <Value>}
+
+\end_inset 
+
+ Causes the linker to check if there is at minimum <Value> bytes for stack.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pack-iram
+\series default 
+\SpecialChar ~
+
+\begin_inset LatexCommand \index{-\/-pack-iram}
+
+\end_inset 
+
+ Causes the linker use unused register banks for data variables or stack.
 \layout Subsection
 
 DS390 / DS400 Options
@@ -5855,13 +6178,13 @@ status Collapsed
  
 \layout Subsection
 
-PIC Options
-\begin_inset LatexCommand \index{Options PIC}
+Z80 Options
+\begin_inset LatexCommand \index{Options Z80}
 
 \end_inset 
 
 
-\begin_inset LatexCommand \index{PIC options}
+\begin_inset LatexCommand \index{Z80 options}
 
 \end_inset 
 
@@ -5881,46 +6204,10 @@ status Collapsed
 /
 \end_inset 
 
--gen-banksel
-\begin_inset LatexCommand \index{-\/-gen-banksel}
-
-\end_inset 
-
-
+-callee-saves-bc
 \series default 
- enable the generation of banksel assembler directives in the PIC16 port.
-\layout Subsection
 
-Z80 Options
-\begin_inset LatexCommand \index{Options Z80}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{Z80 options}
-
-\end_inset 
-
-
-\layout List
-\labelwidthstring 00.00.0000
-
-
-\series bold 
--
-\begin_inset ERT
-status Collapsed
-
-\layout Standard
-
-\backslash 
-/
-\end_inset 
-
--callee-saves-bc
-\series default 
-
-\begin_inset LatexCommand \index{-\/-callee-saves-bc}
+\begin_inset LatexCommand \index{-\/-callee-saves-bc}
 
 \end_inset 
 
@@ -7752,7 +8039,7 @@ Paged xdata access is currently not as straightforward as using the other
 \end_inset 
 
 (or in case of some 8051 variants by a separate Special Function Register,
- see section
+ see section 
 \begin_inset LatexCommand \ref{sub:MCS51-variants}
 
 \end_inset 
@@ -7988,7 +8275,16 @@ Apart from this 8051 specific storage class most architectures support ANSI-C
 
 \end_inset 
 
+
+\newline 
+
+\layout Standard
+
+In accordance with ISO/IEC 9899 bits and bitfields without an explicit signed
+ modifier are implemented as unsigned.
+\layout Standard
+
+
 \begin_inset Foot
 collapsed false
 
@@ -8521,7 +8817,12 @@ banked
 
 
 \family typewriter 
-sfr banked at 0x123 IoPort; 
+sfr banked at
+\begin_inset LatexCommand \index{at}
+
+\end_inset 
+
+ 0x123 IoPort; 
 \layout Standard
 
 Writing 0x01 to this variable generates the assembly code:
@@ -8596,6 +8897,42 @@ in/out
 \family default 
 .
  If you include the file z180.h this will be set automatically.
+\layout Subsection
+
+HC08 Storage Class
+\begin_inset LatexCommand \index{Storage class}
+
+\end_inset 
+
+ Language Extensions
+\layout Subsubsection
+
+data
+\begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
+
+\end_inset 
+
+
+\layout Standard
+
+The data storage class declares a variable that resides in the first 256
+ bytes of memory (the direct page).
+ The HC08 is most efficient at accessing variables (especially pointers)
+ stored here.
+\layout Subsubsection
+
+xdata
+\begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
+
+\end_inset 
+
+
+\layout Standard
+
+The xdata storage class declares a variable that can reside anywhere in
+ memory.
+ This is the default if no storage class is specified.
 \layout Section
 
 Absolute Addressing
@@ -8700,12 +9037,28 @@ volatile
 \layout Standard
 
 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
-r) array starts at a block (256 byte) boundary
+r) array
+\family typewriter 
+\size footnotesize 
+
+\begin_inset LatexCommand \index{Aligned array}
+
+\end_inset 
+
+
+\family default 
+\size default 
+ starts at a block (256 byte) boundary
 \begin_inset LatexCommand \index{block boundary}
 
 \end_inset 
 
-.
+ (section 
+\begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
+
+\end_inset 
+
+ has an example).
 \newline 
 Absolute addresses can be specified for variables in all storage classes,
  e.g.:
@@ -9051,7 +9404,12 @@ bit bvar;
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-data at 0x31 unsigned char j;
+data at
+\begin_inset LatexCommand \index{at}
+
+\end_inset 
+
+ 0x31 unsigned char j;
 \newline 
 \SpecialChar ~
 \SpecialChar ~
@@ -9272,6 +9630,9 @@ Interrupt Service Routines
 \end_inset 
 
 
+\layout Subsection
+
+General Information
 \layout Standard
 
 SDCC allows 
@@ -9335,134 +9696,326 @@ using
 
 \layout Standard
 
-Interrupt numbers and the corresponding address & descriptions for the Standard
- 8051/8052 are listed below.
- SDCC will automatically adjust the interrupt vector table to the maximum
- interrupt number specified.
-\newline 
-
+Interrupt service routines open the door for some very interesting bugs:
 \layout Standard
-\align center 
 
-\begin_inset  Tabular
-<lyxtabular version="3" rows="7" columns="3">
-<features>
-<column alignment="center" valignment="top" leftline="true" width="0in">
-<column alignment="center" valignment="top" leftline="true" width="0in">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
-<row topline="true" bottomline="true">
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
+If the interrupt service routines changes variables which are accessed by
+ other functions these variables should be declared 
+\emph on 
+volatile
+\emph default 
 
-\layout Standard
+\begin_inset LatexCommand \index{volatile}
 
-Interrupt #
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
 
+.
 \layout Standard
 
-Description
+If the access to these variables is not 
+\emph on 
+atomic
+\begin_inset LatexCommand \index{atomic access}
+
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
 
-Vector Address
+\emph default 
+ (i.e.
+ the processor needs more than one instruction for the access and could
+ be interrupted while accessing the variable) the interrupt must disabled
+ during the access to avoid inconsistent data.
+ Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
+ and should be protected by disabling interrupts.
+ You're not automatically on the safe side if you use 8 bit variables though.
+ We need an example here: f.e.
+ on the 8051 the harmless looking 
+\begin_inset Quotes srd
 \end_inset 
-</cell>
-</row>
-<row topline="true">
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
 
-0
-\end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
+\family typewriter 
+flags\SpecialChar ~
+|=\SpecialChar ~
+0x80;
+\family default 
 
-\layout Standard
+\begin_inset Quotes sld
+\end_inset 
 
-External 0
+ is not atomic if 
+\family typewriter 
+flags
+\family default 
+ resides in xdata.
+ Setting 
+\begin_inset Quotes srd
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
 
-0x0003
-\end_inset 
-</cell>
-</row>
-<row topline="true">
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
+\family typewriter 
+flags\SpecialChar ~
+|=\SpecialChar ~
+0x40;
+\family default 
 
-\layout Standard
+\begin_inset Quotes sld
+\end_inset 
 
-1
+ from within an interrupt routine might get lost if the interrupt occurs
+ at the wrong time.
+\begin_inset Quotes sld
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
 
-Timer 0
+\family typewriter 
+counter\SpecialChar ~
++=\SpecialChar ~
+8;
+\family default 
+
+\begin_inset Quotes srd
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
 
+ is not atomic on the 8051 even if 
+\family typewriter 
+counter
+\family default 
+ is located in data memory.
+ Bugs like these are hard to reproduce and can cause a lot of trouble.
 \layout Standard
 
-0x000B
+A special note here, int (16 bit) and long (32 bit) integer division
+\begin_inset LatexCommand \index{Division}
+
 \end_inset 
-</cell>
-</row>
-<row topline="true">
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
+, multiplication
+\begin_inset LatexCommand \index{Multiplication}
 
-2
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
+ & modulus
+\begin_inset LatexCommand \index{Modulus}
 
-External 1
 \end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
 
-\layout Standard
+ and floating-point
+\begin_inset LatexCommand \index{Floating point support}
 
-0x0013
 \end_inset 
-</cell>
-</row>
-<row topline="true">
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
+
+ operations are implemented using external support routines developed in
+ ANSI-C.
+ If an interrupt service routine needs to do any of these operations then
+ the support routines (as mentioned in a following section) will have to
+ be recompiled using the
+\emph on 
+ -
+\begin_inset ERT
+status Collapsed
 
 \layout Standard
 
-3
+\backslash 
+/
 \end_inset 
-</cell>
+
+-stack-auto
+\begin_inset LatexCommand \index{-\/-stack-auto}
+
+\end_inset 
+
+
+\emph default 
+ option and the source file will need to be compiled using the 
+\emph on 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-int-long-reent
+\emph default 
+
+\begin_inset LatexCommand \index{-\/-int-long-reent}
+
+\end_inset 
+
+ compiler option.
+\layout Standard
+
+Calling other functions from an interrupt service routine is not recommended,
+ avoid it if possible.
+ Note that when some function is called from an interrupt service routine
+ it should be preceded by a #pragma\SpecialChar ~
+nooverlay
+\begin_inset LatexCommand \index{\#pragma nooverlay}
+
+\end_inset 
+
+ if it is not reentrant.
+ Furthermore nonreentrant functions should not be called from the main program
+ while the interrupt service routine might be active.
+\newline 
+
+\newline 
+Also see section 
+\begin_inset LatexCommand \ref{sub:Overlaying}
+
+\end_inset 
+
+\SpecialChar ~
+about Overlaying and section 
+\begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
+
+\end_inset 
+
+\SpecialChar ~
+about Functions using private register banks.
+\layout Subsection
+
+MCS51/DS390 Interrupt Service Routines
+\layout Standard
+
+Interrupt numbers and the corresponding address & descriptions for the Standard
+ 8051/8052 are listed below.
+ SDCC will automatically adjust the interrupt vector table to the maximum
+ interrupt number specified.
+\newline 
+
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="7" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0in">
+<column alignment="center" valignment="top" leftline="true" width="0in">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Interrupt #
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Description
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Vector Address
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+External 0
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0x0003
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Timer 0
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0x000B
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+External 1
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0x0013
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset 
+</cell>
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
 
@@ -9567,233 +10120,62 @@ If the interrupt service routine is defined to be using a specific register
 \emph on 
 a, b, dptr
 \emph default 
- & psw are save and restored, if such an interrupt service routine calls
+ & psw are saved and restored, if such an interrupt service routine calls
  another function (using another register bank) then the entire register
  bank of the called function will be saved on the stack.
  This scheme is recommended for larger interrupt service routines.
-\layout Standard
+\layout Subsection
 
-Interrupt service routines open the door for some very interesting bugs:
+HC08 Interrupt Service Routines
 \layout Standard
 
-If the interrupt service routines changes variables which are accessed by
- other functions these variables should be declared 
-\emph on 
-volatile
-\emph default 
-
-\begin_inset LatexCommand \index{volatile}
+Since the number of interrupts available is chip specific and the interrupt
+ vector table always ends at the last byte of memory, the interrupt numbers
+ corresponds to the interrupt vectors in reverse order of address.
+ For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
+ 2 will use the interrupt vector at 0xfffa, and so on.
+ However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
+ this way; instead see section 
+\begin_inset LatexCommand \ref{sub:Startup-Code}
 
 \end_inset 
 
-.
+ for details on customizing startup.
+\layout Section
+
+Enabling and Disabling Interrupts
+\layout Subsection
+
+Critical Functions and Critical Statements
 \layout Standard
 
-If the access to these variables is not 
+A special keyword may be associated with a block or a function declaring
+ it as 
 \emph on 
-atomic
-\begin_inset LatexCommand \index{atomic access}
+critical
+\emph default 
+.
+ SDCC will generate code to disable all interrupts
+\begin_inset LatexCommand \index{interrupt}
 
 \end_inset 
 
+ upon entry to a critical function and restore the interrupt enable to the
+ previous state before returning.
+ Nesting critical functions will need one additional byte on the stack
+\begin_inset LatexCommand \index{stack}
 
-\emph default 
- (i.e.
- the processor needs more than one instruction for the access and could
- be interrupted while accessing the variable) the interrupt must disabled
- during the access to avoid inconsistent data.
- Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
- and should be protected by disabling interrupts.
- You're not automatically on the safe side if you use 8 bit variables though.
- We need an example here: f.e.
- on the 8051 the harmless looking 
-\begin_inset Quotes srd
 \end_inset 
 
+ for each call.
+\layout Verse
 
-\family typewriter 
-flags\SpecialChar ~
-|=\SpecialChar ~
-0x80;
-\family default 
-
-\begin_inset Quotes sld
-\end_inset 
 
- is not atomic if 
 \family typewriter 
-flags
-\family default 
- resides in xdata.
- Setting 
-\begin_inset Quotes srd
-\end_inset 
+int foo () critical
+\begin_inset LatexCommand \index{critical}
 
-
-\family typewriter 
-flags\SpecialChar ~
-|=\SpecialChar ~
-0x40;
-\family default 
-
-\begin_inset Quotes sld
-\end_inset 
-
- from within an interrupt routine might get lost if the interrupt occurs
- at the wrong time.
-\begin_inset Quotes sld
-\end_inset 
-
-
-\family typewriter 
-counter\SpecialChar ~
-+=\SpecialChar ~
-8;
-\family default 
-
-\begin_inset Quotes srd
-\end_inset 
-
- is not atomic on the 8051 even if 
-\family typewriter 
-counter
-\family default 
- is located in data memory.
- Bugs like these are hard to reproduce and can cause a lot of trouble.
-\layout Standard
-
-A special note here, int (16 bit) and long (32 bit) integer division
-\begin_inset LatexCommand \index{Division}
-
-\end_inset 
-
-, multiplication
-\begin_inset LatexCommand \index{Multiplication}
-
-\end_inset 
-
- & modulus
-\begin_inset LatexCommand \index{Modulus}
-
-\end_inset 
-
- and floating-point
-\begin_inset LatexCommand \index{Floating point support}
-
-\end_inset 
-
- operations are implemented using external support routines developed in
- ANSI-C.
- If an interrupt service routine needs to do any of these operations then
- the support routines (as mentioned in a following section) will have to
- be recompiled using the
-\emph on 
- -
-\begin_inset ERT
-status Collapsed
-
-\layout Standard
-
-\backslash 
-/
-\end_inset 
-
--stack-auto
-\begin_inset LatexCommand \index{-\/-stack-auto}
-
-\end_inset 
-
-
-\emph default 
- option and the source file will need to be compiled using the 
-\emph on 
--
-\begin_inset ERT
-status Collapsed
-
-\layout Standard
-
-\backslash 
-/
-\end_inset 
-
--int-long-reent
-\emph default 
-
-\begin_inset LatexCommand \index{-\/-int-long-reent}
-
-\end_inset 
-
- compiler option.
-\layout Standard
-
-Calling other functions from an interrupt service routine is not recommended,
- avoid it if possible.
- Note that when some function is called from an interrupt service routine
- it should be preceded by a #pragma\SpecialChar ~
-nooverlay
-\begin_inset LatexCommand \index{\#pragma nooverlay}
-
-\end_inset 
-
- if it is not reentrant.
- Furthermore nonreentrant functions should not be called from the main program
- while the interrupt service routine might be active.
-\newline 
-
-\newline 
-Also see section 
-\begin_inset LatexCommand \ref{sub:Overlaying}
-
-\end_inset 
-
-\SpecialChar ~
-about Overlaying and section 
-\begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
-
-\end_inset 
-
-\SpecialChar ~
-about Functions using private register banks.
-\layout Section
-
-Enabling and Disabling Interrupts
-\layout Subsection
-
-Critical Functions and Critical Statements
-\layout Standard
-
-A special keyword may be associated with a function declaring it as 
-\emph on 
-critical
-\emph default 
-.
- SDCC will generate code to disable all interrupts
-\begin_inset LatexCommand \index{interrupt}
-
-\end_inset 
-
- upon entry to a critical function and restore the interrupt enable to the
- previous state before returning.
- Nesting critical functions will need one additional byte on the stack
-\begin_inset LatexCommand \index{stack}
-
-\end_inset 
-
- for each call.
-\layout Verse
-
-
-\family typewriter 
-int foo () critical
-\begin_inset LatexCommand \index{critical}
-
-\end_inset 
+\end_inset 
 
  
 \newline 
@@ -10325,6 +10707,11 @@ Inline Assembler Code
 \layout Subsection
 
 A Step by Step Introduction
+\begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
+
+\end_inset 
+
+
 \layout Standard
 
 Starting from a small snippet of c-code this example shows for the MCS51
@@ -10337,7 +10724,22 @@ Starting from a small snippet of c-code this example shows for the MCS51
 
 \family typewriter 
 \size footnotesize 
-unsigned char xdata at 0x7f00 buf[0x100];
+unsigned char far
+\begin_inset LatexCommand \index{far (storage class)}
+
+\end_inset 
+
+ at
+\begin_inset LatexCommand \index{at}
+
+\end_inset 
+
+ 0x7f00 buf[0x100];
+\begin_inset LatexCommand \index{Aligned array}
+
+\end_inset 
+
+
 \newline 
 unsigned char head,tail;
 \newline 
@@ -10466,25 +10868,20 @@ a,_head
 \SpecialChar ~
 cjne a,ar3,00106$ 
 \newline 
-ret 00106$: 
-\newline 
-;buffer.c buf[ head++ ] = c; 
-\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-mov\SpecialChar ~
-\SpecialChar ~
-r3,_head 
+ret
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-inc\SpecialChar ~
-\SpecialChar ~
-_head 
+00106$: 
+\newline 
+;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
+\begin_inset LatexCommand \index{Aligned array}
+
+\end_inset 
+
+
 \newline 
 \SpecialChar ~
 \SpecialChar ~
@@ -10492,15 +10889,15 @@ _head
 \SpecialChar ~
 mov\SpecialChar ~
 \SpecialChar ~
-a,r3 
+r3,_head 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-add\SpecialChar ~
+inc\SpecialChar ~
 \SpecialChar ~
-a,#_buf 
+_head 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
@@ -10508,22 +10905,7 @@ a,#_buf
 \SpecialChar ~
 mov\SpecialChar ~
 \SpecialChar ~
-dpl,a 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-clr\SpecialChar ~
-\SpecialChar ~
-a 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-addc\SpecialChar ~
-a,#(_buf >> 8) 
+dpl,r3 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
@@ -10531,7 +10913,7 @@ a,#(_buf >> 8)
 \SpecialChar ~
 mov\SpecialChar ~
 \SpecialChar ~
-dph,a 
+dph,#(_buf >> 8) 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
@@ -10567,21 +10949,23 @@ _endasm;
 The new file buffer.c should compile with only one warning about the unreferenced
  function argument 'c'.
  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
- and finally have:
(1) and finally have:
 \layout Verse
 
 
 \family typewriter 
 \size footnotesize 
-unsigned char xdata at 0x7f00 buf[0x100];
+unsigned char far at 0x7f00 buf[0x100];
 \newline 
 unsigned char head,tail;
 \newline 
-#define USE_ASSEMBLY
+#define USE_ASSEMBLY (1)
 \newline 
 
 \newline 
-#ifndef USE_ASSEMBLY
+#if !USE_ASSEMBLY
+\newline 
+
 \newline 
 void to_buffer( unsigned char c )
 \newline 
@@ -12890,7 +13274,12 @@ instead
 \family typewriter 
 printf_fast()
 \family default 
- which should fit the requirements of many embedded systems.
+ which should fit the requirements of many embedded systems (by unsetting
+ #defines it can be customized to 
+\emph on 
+not
+\emph default 
+ support long variables and field widths).
 \layout Subsection
 
 Math functions (sin, pow, sqrt etc.)
@@ -13029,6 +13418,15 @@ External Stack
 
 \layout Standard
 
+
+\series bold 
+Attention
+\series default 
+: this option wasn't maintained for a long time and is quite buggy.
+ Small programs might work.
+ You've been warned!
+\layout Standard
+
 The external stack (-
 \begin_inset ERT
 status Collapsed
@@ -13095,7 +13493,12 @@ The compiler outputs the higher order address byte of the external ram segment
 
 \end_inset 
 
-, therefore when using the External Stack option, this port 
+ (see also section 
+\begin_inset LatexCommand \ref{sub:MCS51-variants}
+
+\end_inset 
+
+), therefore when using the External Stack option, this port 
 \emph on 
 may not
 \emph default 
 \end_inset 
 
 
-\newline 
-
 \layout Chapter
 
-Debugging with SDCDB
-\begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
+Notes on supported Processors
+\layout Section
+
+MCS51 variants
+\begin_inset LatexCommand \label{sub:MCS51-variants}
 
 \end_inset 
 
 
-\begin_inset LatexCommand \index{sdcdb (debugger)}
+\begin_inset LatexCommand \index{MCS51 variants}
 
 \end_inset 
 
+
+\layout Standard
+
+MCS51 processors are available from many vendors and come in many different
+ flavours.
+ While they might differ considerably in respect to Special Function Registers
+ the core MCS51 is usually not modified or is kept compatible.
  
+\layout Subsection
+
+pdata access by SFR 
 \layout Standard
 
-SDCC is distributed with a source level debugger
-\begin_inset LatexCommand \index{Debugger}
+With the upcome of devices with internal xdata and flash memory devices
+ using port P2
+\begin_inset LatexCommand \index{P2 (mcs51 sfr)}
 
 \end_inset 
 
-.
- The debugger uses a command line interface, the command repertoire of the
- debugger has been kept as close to gdb
-\begin_inset LatexCommand \index{gdb}
+ as dedicated I/O port is becoming more popular.
+ Switching the high byte for pdata
+\begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
 
 \end_inset 
 
- (the GNU debugger) as possible.
- The configuration and build process is part of the standard compiler installati
-on, which also builds and installs the debugger in the target directory
- specified during configuration.
- The debugger allows you debug BOTH at the C source and at the ASM source
- level.
- Sdcdb is available on Unix platforms only.
-\layout Section
+ access which was formerly done by port P2 is then achieved by a Special
+ Function Register
+\begin_inset LatexCommand \index{sfr}
 
-Compiling for Debugging
-\layout Standard
+\end_inset 
 
-The \SpecialChar \-
-\SpecialChar \-
-debug option must be specified for all files for which debug information
- is to be generated.
- The complier generates a .adb file for each of these files.
- The linker creates the .cdb file from the .adb files and the address information.
- This .cdb is used by the debugger.
-\layout Section
+.
+ In well-established MCS51 tradition the address of this 
+\emph on 
+sfr
+\emph default 
+ is where the chip designers decided to put it.
+ Needless to say that they didn't agree on a common name either.
+ As pdata addressing is used in the startup code for the initialization
+ of xdata variables a separate startup code should be used as described
+ in section 
+\begin_inset LatexCommand \ref{sub:Startup-Code}
 
-How the Debugger Works
-\layout Standard
+\end_inset 
 
-When the -
-\begin_inset ERT
-status Collapsed
+.
+\layout Subsection
 
+Other Features available by SFR
 \layout Standard
 
-\backslash 
-/
+Some MCS51 variants offer features like Double DPTR
+\begin_inset LatexCommand \index{DPTR}
+
 \end_inset 
 
--debug option is specified the compiler generates extra symbol information
- some of which are put into the assembler source and some are put into the
- .adb file.
-  Then the linker creates the .cdb file from the individual .adb files with
- the address information for the symbols.
- The debugger reads the symbolic information generated by the compiler &
- the address information generated by the linker.
- It uses the SIMULATOR (Daniel's S51) to execute the program, the program
- execution is controlled by the debugger.
- When a command is issued for the debugger, it translates it into appropriate
- commands for the simulator.
+, multiple DPTR, decrementing DPTR, 16x16 Multiply.
+ These are currently not used for the MCS51 port.
+ If you absolutely need them you can fall back to inline assembly or submit
+ a patch to SDCC.
 \layout Section
 
-Starting the Debugger
+The Z80 and gbz80 port
 \layout Standard
 
-The debugger can be started using the following command line.
- (Assume the file you are debugging has the file name foo).
-\newline 
+SDCC can target both the Zilog 
+\begin_inset LatexCommand \index{Z80}
 
-\newline 
+\end_inset 
 
-\family sans 
-\series bold 
-sdcdb foo
-\newline 
+ and the Nintendo Gameboy's Z80-like gbz80
+\begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
 
-\family default 
-\series default 
+\end_inset 
 
-\newline 
-The debugger will look for the following files.
-\layout Itemize
+.
+ The Z80 port is passed through the same 
+\emph on 
+regressions tests
+\begin_inset LatexCommand \index{Regression test}
 
-foo.c - the source file.
-\layout Itemize
+\end_inset 
 
-foo.cdb - the debugger symbol information file.
-\layout Itemize
 
-foo.ihx - the Intel hex format
-\begin_inset LatexCommand \index{Intel hex format}
+\emph default 
+ as the MCS51 and DS390 ports, so floating point support, support for long
+ variables and bitfield support is fine.
+ See mailing lists and forums about interrupt routines.
+\layout Standard
+
+As always, the code is the authoritative reference - see z80/ralloc.c and
+ z80/gen.c.
+ The stack
+\begin_inset LatexCommand \index{stack}
 
 \end_inset 
 
- object file.
-\layout Section
+ frame is similar to that generated by the IAR Z80 compiler.
+ IX is used as the base pointer, HL and IY are used as a temporary registers,
+ and BC and DE are available for holding variables.
+ Return values
+\begin_inset LatexCommand \index{return value}
 
-Command Line Options.
-\layout Itemize
+\end_inset 
 
--
-\begin_inset ERT
-status Collapsed
+ for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
+ bytes).
+ The gbz80 port use the same set of registers for the return values, but
+ in a different order of significance: E (one byte), DE (two bytes), or
+ HLDE (four bytes).
+\layout Section
 
+The HC08 port
 \layout Standard
 
-\backslash 
-/
+The port to the Motorola HC08
+\begin_inset LatexCommand \index{HC08}
+
 \end_inset 
 
--directory=<source file directory> this option can used to specify the directory
- search list.
- The debugger will look into the directory list specified for source, cdb
- & ihx files.
- The items in the directory list must be separated by ':', e.g.
- if the source files can be in the directories /home/src1 and /home/src2,
- the -
-\begin_inset ERT
-status Collapsed
+ family has been added in October 2003, and is still undergoing some basic
+ development.
+ The code generator is complete, but the register allocation is still quite
+ unoptimized.
+ Some of the SDCC's standard C library functions have embedded non-HC08
+ inline assembly and so are not yet usable.
+\newline 
+
+\newline 
+
+\layout Section
 
+The PIC14 port
 \layout Standard
 
-\backslash 
-/
+The 14bit PIC
+\begin_inset LatexCommand \index{PIC14}
+
 \end_inset 
 
--directory option should be -
-\begin_inset ERT
-status Collapsed
+ port still requires a major effort from the development community.
+ However it can work for very simple code.
+\layout Subsection
 
-\layout Standard
+C code and 14bit PIC code page
+\begin_inset LatexCommand \index{code page (pic14)}
 
-\backslash 
-/
 \end_inset 
 
--directory=/home/src1:/home/src2.
- Note there can be no spaces in the option.
-\layout Itemize
+ and RAM banks
+\begin_inset LatexCommand \index{RAM bank (pic14)}
 
--cd <directory> - change to the <directory>.
-\layout Itemize
+\end_inset 
 
--fullname - used by GUI front ends.
-\layout Itemize
 
--cpu <cpu-type> - this argument is passed to the simulator please see the
- simulator docs for details.
-\layout Itemize
+\layout Standard
 
--X <Clock frequency > this options is passed to the simulator please see
- the simulator docs for details.
-\layout Itemize
+The linker organizes allocation for the code page and RAM banks.
+ It does not have intimate knowledge of the code flow.
+ It will put all the code section of a single asm file into a single code
+ page.
+ In order to make use of multiple code pages, separate asm files must be
+ used.
+ The compiler treats all functions of a single C file as being in the same
+ code page unless it is non static.
+ The compiler treats all local variables of a single C file as being in
+ the same RAM bank unless it is an extern.
+\newline 
 
--s <serial port file> passed to simulator see the simulator docs for details.
-\layout Itemize
+\newline 
+To get the best follow these guide lines:
+\layout Enumerate
 
--S <serial in,out> passed to simulator see the simulator docs for details.
-\layout Itemize
+make local functions static, as non static functions require code page selection
+ overhead.
+\layout Enumerate
 
--k <port number> passed to simulator see the simulator docs for details.
-\layout Section
+Make local variables static as extern variables require RAM bank selection
+ overhead.
+\layout Enumerate
 
-Debugger Commands.
+For devices that have multiple code pages it is more efficient to use the
+ same number of files as pages, i.e.
+ for the 16F877 use 4 separate files and i.e.
+ for the 16F874 use 2 separate files.
+ This way the linker can put the code for each file into different code
+ pages and the compiler can allocate reusable variables more efficiently
+ and there's less page selection overhead.
+ And as for any 8 bit micro (especially for PIC 14 as they have a very simple
+ instruction set) use 'unsigned char' whereever possible instead of 'int'.
+\layout Subsection
+
+Creating a device include file 
 \layout Standard
 
-As mentioned earlier the command interface for the debugger has been deliberatel
-y kept as close the GNU debugger gdb, as possible.
- This will help the integration with existing graphical user interfaces
- (like ddd, xxgdb or xemacs) existing for the GNU debugger.
- If you use a graphical user interface for the debugger you can skip the
- next sections.
-\layout Subsubsection*
+For generating a device include file use the support perl script inc2h.pl
+ kept in directory support/script.
+\layout Subsection
 
-break [line | file:line | function | file:function]
+Interrupt code
 \layout Standard
 
-Set breakpoint at specified line or function:
-\newline 
+For the interrupt function, use the keyword 'interrupt'
+\begin_inset LatexCommand \index{interrupt}
 
-\newline 
+\end_inset 
 
-\family sans 
-\series bold 
-sdcdb>break 100 
+ with level number of 0 (PIC14 only has 1 interrupt so this number is only
+ there to avoid a syntax error - it ought to be fixed).
+ E.g.:
+\layout Verse
+
+
+\family typewriter 
+void Intr(void) interrupt 0
 \newline 
-sdcdb>break foo.c:100
+{
 \newline 
-sdcdb>break funcfoo
+\SpecialChar ~
+\SpecialChar ~
+T0IF = 0; /* Clear timer interrupt */
 \newline 
-sdcdb>break foo.c:funcfoo
-\layout Subsubsection*
-
-clear [line | file:line | function | file:function ]
+}
 \layout Standard
 
-Clear breakpoint at specified line or function:
+Linking and assembling
 \newline 
+For assembling you can use either GPUTILS'
+\begin_inset LatexCommand \index{gputils (pic tools)}
+
+\end_inset 
 
+ gpasm.exe or MPLAB's mpasmwin.exe.
+ For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
+ If you use MPLAB and an interrupt function then the linker script file
+ vectors section will need to be enlarged to link with mplink.
 \newline 
 
-\family sans 
-\series bold 
-sdcdb>clear 100
 \newline 
-sdcdb>clear foo.c:100
-\newline 
-sdcdb>clear funcfoo
-\newline 
-sdcdb>clear foo.c:funcfoo
-\layout Subsubsection*
-
-continue
-\layout Standard
-
-Continue program being debugged, after breakpoint.
-\layout Subsubsection*
-
-finish
-\layout Standard
-
-Execute till the end of the current function.
-\layout Subsubsection*
-
-delete [n]
-\layout Standard
-
-Delete breakpoint number 'n'.
- If used without any option clear ALL user defined break points.
-\layout Subsubsection*
-
-info [break | stack | frame | registers ]
-\layout Itemize
-
-info break - list all breakpoints
-\layout Itemize
-
-info stack - show the function call stack.
-\layout Itemize
-
-info frame - show information about the current execution frame.
-\layout Itemize
-
-info registers - show content of all registers.
-\layout Subsubsection*
-
-step
-\layout Standard
-
-Step program until it reaches a different source line.
- Note: pressing <return> repeats the last command.
-\layout Subsubsection*
-
-next
-\layout Standard
-
-Step program, proceeding through subroutine calls.
-\layout Subsubsection*
-
-run
-\layout Standard
-
-Start debugged program.
-\layout Subsubsection*
-
-ptype variable 
-\layout Standard
-
-Print type information of the variable.
-\layout Subsubsection*
-
-print variable
-\layout Standard
-
-print value of variable.
-\layout Subsubsection*
-
-file filename
-\layout Standard
-
-load the given file name.
- Note this is an alternate method of loading file for debugging.
-\layout Subsubsection*
-
-frame
-\layout Standard
-
-print information about current frame.
-\layout Subsubsection*
-
-set srcmode
-\layout Standard
-
-Toggle between C source & assembly source.
-\layout Subsubsection*
-
-! simulator command
-\layout Standard
-
-Send the string following '!' to the simulator, the simulator response is
- displayed.
- Note the debugger does not interpret the command being sent to the simulator,
- so if a command like 'go' is sent the debugger can loose its execution
- context and may display incorrect values.
-\layout Subsubsection*
-
-quit
-\layout Standard
-
-"Watch me now.
- Iam going Down.
- My name is Bobby Brown"
-\layout Section
-
-Interfacing with XEmacs
-\begin_inset LatexCommand \index{XEmacs}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{Emacs}
-
-\end_inset 
-
-.
-\layout Standard
-
-Two files (in emacs lisp) are provided for the interfacing with XEmacs,
- sdcdb.el and sdcdbsrc.el.
- These two files can be found in the $(prefix)/bin directory after the installat
-ion is complete.
- These files need to be loaded into XEmacs for the interface to work.
- This can be done at XEmacs startup time by inserting the following into
- your '.xemacs' file (which can be found in your HOME directory): 
-\newline 
-
-\newline 
-
+Here is a 
 \family typewriter 
-(load-file sdcdbsrc.el) 
-\family default 
-
-\newline 
-
-\newline 
-.xemacs is a lisp file so the () around the command is REQUIRED.
- The files can also be loaded dynamically while XEmacs is running, set the
- environment variable 'EMACSLOADPATH' to the installation bin directory
- (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
- To start the interface enter the following command: 
-\newline 
-
-\newline 
-
-\family sans 
-\series bold 
-ESC-x sdcdbsrc
+Makefile
 \family default 
-\series default 
-
-\newline 
-
-\newline 
-You will prompted to enter the file name to be debugged.
-\newline 
-
-\newline 
-The command line options that are passed to the simulator directly are bound
- to default values in the file sdcdbsrc.el.
- The variables are listed below, these values maybe changed as required.
-\layout Itemize
-
-sdcdbsrc-cpu-type '51
-\layout Itemize
-
-sdcdbsrc-frequency '11059200
-\layout Itemize
-
-sdcdbsrc-serial nil
-\layout Standard
-
-The following is a list of key mapping for the debugger interface.
-\layout Standard
+ using GPUTILS:
+\layout Verse
 
-\SpecialChar ~
 
 \family typewriter 
-
-\newline 
-;; Current Listing :: 
+.c.o:
 \newline 
-;;key\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-binding\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -14259,15 +14494,8 @@ binding\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-Comment 
+sdcc -S -V -mpic14 -p16F877 $< 
 \newline 
-;;---\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -14276,15 +14504,34 @@ Comment
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+gpasm -c $*.asm
+\newline 
+
+\newline 
+$(PRJ).hex: $(OBJS) 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-------\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
+\layout Standard
+
+Here is a 
+\family typewriter 
+Makefile
+\family default 
+ using MPLAB:
+\layout Verse
+
+
+\family typewriter 
+.c.o: 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -14293,6 +14540,8 @@ Comment
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+sdcc -S -V -mpic14 -p16F877 $< 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -14301,25 +14550,1538 @@ Comment
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
---------
+mpasmwin /q /o $*.asm
 \newline 
-;; 
+
+\newline 
+$(PRJ).hex: $(OBJS) 
 \newline 
-;; n\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- sdcdb-next-from-src\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
+\layout Section
+
+The PIC16
+\begin_inset LatexCommand \index{PIC16}
+
+\end_inset 
+
+ port
+\layout Standard
+
+The PIC16
+\begin_inset LatexCommand \index{PIC16}
+
+\end_inset 
+
+ port is the portion of SDCC that is responsible to produce code for the
+ Microchip
+\begin_inset LatexCommand \index{Microchip}
+
+\end_inset 
+
+(TM) microcontrollers with 16 bit core.
+ Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
+\layout Subsection
+
+Global Options
+\layout Standard
+
+PIC16 port supports the standard command line arguments as supposed, with
+ the exception of certain cases that will be mentioned in the following
+ list:
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-stack-auto Auto variables that are function parameters, will be saved on
+ stack by default.
+\emph on 
+There is no need to specify this in the command line.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-float-reent All floating point functions are reentrant by default.
+\emph on 
+There is no need to specifiy this in the command line.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-callee-saves See -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-all-callee-saves
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-all-callee-saves All function arguments are passed on stack by default.
+\emph on 
+There is no need to specify this in the command line.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-fommit-frame-pointer Frame pointer will be omitted when the function uses
+ no local variables.
+\layout Subsection
+
+Port Specific Options
+\layout Standard
+
+The port specific options appear after the global options in the sdcc --help
+ output.
+\layout Subsubsection
+
+General Options
+\layout Standard
+
+General options enable certain port features and optimizations.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pgen-bank Instructs the port to insert BANKSEL directives before instructions
+ that use the Bank Select Register (BSR).
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pomit-config-words Instructs the port to omit the generation of the configurati
+on words.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pomit-ivt Instructs the port to omit the generation of the interrupt vectors
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pleave-reset-vector Used in conjuction with the previous command, instructs
+ the port NOT to omit the reset vector.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-stack-model=[model] Used in conjuction with the command above.
+ Defines the stack model to be used, valid stack models are : 
+\begin_deeper 
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\emph on 
+small
+\emph default 
+ Selects small stack model.
+ 8 bit stack and frame pointers.
+ Supports 256 bytes stack size.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\emph on 
+large
+\emph default 
+ Selects large stack model.
+ 16 bit stack and frame pointers.
+ Supports 65536 bytes stack size.
+\end_deeper 
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-preplace-udata-with=[kword] Replaces the default udata keyword for allocating
+ unitialized data variables with [kword].
+ Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
+\layout Subsubsection
+
+Debugging Options
+\layout Standard
+
+Debugging options enable extra debugging information in the output files.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-debug-xtra Similar to --debug, but dumps more information.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-debug-ralloc Force register allocator to dump <source>.d file with debugging
+ information.
+ <source> is the name of the file compiled.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pcode-verbose Enable pcode debugging information in translation.
+\layout Subsection
+
+Preprocessor Macros
+\layout Standard
+
+PIC16 port defines the following preprocessor macros while translating a
+ source.
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="2" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Macro
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Description
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+pic18fxxxx
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+MCU Identification.
+\emph on 
+xxxx
+\emph default 
+ is the microcontrol identification number, i.e.
+ 452, 6620, etc
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\layout Subsection
+
+Directories
+\layout Standard
+
+PIC16 port uses the following directories for searching header files and
+ libraries.
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="3" columns="4">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Directory
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Description
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Target
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Command prefix
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PREFIX/sdcc/include/pic16
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PIC16 specific headers
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Compiler
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-I
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PREFIX/sdcc/lib/pic16
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PIC16 specific libraries
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Linker
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-L
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\layout Subsection
+
+Pragmas
+\layout Standard
+
+PIC16 port currently supports the following pragmas:
+\layout List
+\labelwidthstring 00.00.0000
+
+stack pragma stack forces the code generator to initialize the stack & frame
+ pointers at a specific address.
+ This is an adhoc solution since gplink does not support yet stack.
+ When the gplink issue is resolved the pragma will be deprecated
+\begin_inset Foot
+collapsed true
+
+\layout Standard
+
+
+\emph on 
+It is important to initialize the stack, otherwise strange things can happen.
+ Stack is not initialized by default because there are some sources that
+ do not require it.
+ (like library sources)
+\end_inset 
+
+.
+\newline 
+The stack pragma should be used only once in a project.
+ Multiple pragmas may result in indeterminate behaviour of the program.
+\newline 
+If you omit setting the pragma the port emits a warning message before linking.
+ If not initializing the stack is desired ignore the message.
+\layout LyX-Code
+
+Example:
+\layout LyX-Code
+
+\layout LyX-Code
+
+/* initializes stack at RAM address 0x5ff*/
+\layout LyX-Code
+
+#pragma stack 0x5ff
+\layout LyX-Code
+
+\layout Subsection
+
+Header Files
+\layout Standard
+
+There is one main header file that can be included to the source files using
+ the pic16 port.
+ That file is the 
+\series bold 
+pic18fregs.h
+\series default 
+.
+ This header file contains the definitions for the processor special registers,
+ so it is necessery if the soruce accesses them.
+ It can be included by adding the following line in the beginning of the
+ file:
+\layout LyX-Code
+
+#include <pic18fregs.h>
+\layout Standard
+
+The specific microcontroller is selected within the pic18fregs.h automatically,
+ so the same source can be used with a variety of devices.
+\layout Subsection
+
+Libraries
+\layout Standard
+
+The libraries that pic16 port depends on are the microcontroller device
+ libraries which contain the symbol definitions for the microcontroller
+ special function registers.
+ These libraries have the format pic18fxxxx.lib, where 
+\emph on 
+xxxx
+\emph default 
+ is the microcontroller identification number.
+ The specific library is selected automatically by the compiler at link
+ stage according to the selected device.
+\layout Standard
+
+Libraries are created with gplib which is part of the gputils package 
+\begin_inset LatexCommand \url{http://gputils.sourceforge.net}
+
+\end_inset 
+
+.
+\layout Subsection
+
+Memory Models
+\layout Standard
+
+The following memory models are supported by PIC16 port:
+\layout Itemize
+
+small model
+\layout Itemize
+
+large model
+\layout Standard
+
+Memory model affects the default size of pointers within the source.
+ The sizes are shown in the next table:
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="3" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Pointer sizes according to memory model
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+small model
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+large model
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+code pointers
+\end_inset 
+</cell>
+<cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+16-bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+24-bits
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+data pointers
+\end_inset 
+</cell>
+<cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+16-bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+16-bits
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\layout Standard
+
+It is advisable that all sources within a project are compiled with the
+ same memory model.
+ If one wants to override the default memory model, this can be done by
+ declaring a pointer as 
+\series bold 
+far
+\series default 
+ or 
+\series bold 
+near
+\series default 
+.
+ Far selects large memory model's pointers, while near selects small memory
+ model's pointers.
+\layout Standard
+
+The standard device libraries (see 4.5.6) contain no reference to pointers,
+ so they can be used with both memory models.
+\layout Subsection
+
+Stack
+\layout Standard
+
+The stack implementation for the PIC16 port uses two indirect registers,
+ FSR1 and FSR2.
+\layout List
+\labelwidthstring 00.00.0000
+
+FSR1 is assigned as stack pointer
+\layout List
+\labelwidthstring 00.00.0000
+
+FSR2 is assigned as frame pointer
+\layout Standard
+
+The following stack models are supported by PIC16 port
+\layout Itemize
+
+small model
+\layout Itemize
+
+large model
+\layout Standard
+
+
+\noun on 
+Small
+\noun default 
+ model means that only the FSRxL byte is used to access stack and frame,
+ while 
+\emph on 
+\noun on 
+large
+\emph default 
+\noun default 
+ uses both FSRxL and FSRxH registers.
+ The following table shows the stack/frame pointers sizes according to stack
+ model and the maximum space they can address:
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="3" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Stack & Frame pointer sizes according to stack model
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+small
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+large
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Stack pointer FSR1
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8-bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+16-bits
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Frame pointer FSR2
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8-bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+16-bits
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\layout Standard
+
+
+\series bold 
+Currently stack and frame pointers should be initialized explicit by the
+ user at the desired Data RAM position (see 4.5.5 Pragma Stack).
+ Uninitialized stack and frame pointers can result in unexpected behavior
+ of the resulting binary.
+\layout Subsection
+
+Function return values
+\layout Standard
+
+Return values from functions are placed to the appropriate registers following
+ a modified Microchip policy optimized for SDCC.
+ The following table shows these registers:
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="6" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+size
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+destination register
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8 bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+WREG
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+16 bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PRODL:WREG
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+24 bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PRODH:PRODL:WREG
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+32 bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+FSR0L:PRODH:PRODL:WREG
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+>32 bits
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+on stack, FSR0 points to the beginning
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\layout Subsection
+
+Interrupts
+\layout Standard
+
+When entering an interrupt, currently the PIC16 port automatically saves
+ the following registers:
+\layout Itemize
+
+WREG
+\layout Itemize
+
+STATUS
+\layout Itemize
+
+BSR
+\layout Itemize
+
+PROD (PRODL and PRODH)
+\layout Itemize
+
+FSR0 (FSR0L and FSR0H)
+\layout Standard
+
+These registers are restored upon return from the interrupt routine
+\begin_inset Foot
+collapsed false
+
+\layout Standard
+
+NOTE that when the _naked attribute is specified for an interrupt routine,
+ then NO registers are stored or restored.
+\end_inset 
+
+.
+\layout Chapter
+
+Debugging with SDCDB
+\begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
+
+\end_inset 
+
+
+\begin_inset LatexCommand \index{sdcdb (debugger)}
+
+\end_inset 
+
+\layout Standard
+
+SDCC is distributed with a source level debugger
+\begin_inset LatexCommand \index{Debugger}
+
+\end_inset 
+
+.
+ The debugger uses a command line interface, the command repertoire of the
+ debugger has been kept as close to gdb
+\begin_inset LatexCommand \index{gdb}
+
+\end_inset 
+
+ (the GNU debugger) as possible.
+ The configuration and build process is part of the standard compiler installati
+on, which also builds and installs the debugger in the target directory
+ specified during configuration.
+ The debugger allows you debug BOTH at the C source and at the ASM source
+ level.
+ Sdcdb is available on Unix platforms only.
+\layout Section
+
+Compiling for Debugging
+\layout Standard
+
+The \SpecialChar \-
+\SpecialChar \-
+debug option must be specified for all files for which debug information
+ is to be generated.
+ The complier generates a .adb file for each of these files.
+ The linker creates the .cdb
+\begin_inset LatexCommand \index{<file>.cdb}
+
+\end_inset 
+
+ file from the .adb
+\begin_inset LatexCommand \index{<file>.adb}
+
+\end_inset 
+
+ files and the address information.
+ This .cdb is used by the debugger.
+\layout Section
+
+How the Debugger Works
+\layout Standard
+
+When the -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-debug option is specified the compiler generates extra symbol information
+ some of which are put into the assembler source and some are put into the
+ .adb file.
+  Then the linker creates the .cdb file from the individual .adb files with
+ the address information for the symbols.
+ The debugger reads the symbolic information generated by the compiler &
+ the address information generated by the linker.
+ It uses the SIMULATOR (Daniel's S51) to execute the program, the program
+ execution is controlled by the debugger.
+ When a command is issued for the debugger, it translates it into appropriate
+ commands for the simulator.
+\layout Section
+
+Starting the Debugger
+\layout Standard
+
+The debugger can be started using the following command line.
+ (Assume the file you are debugging has the file name foo).
+\newline 
+
+\newline 
+
+\family sans 
+\series bold 
+sdcdb foo
+\newline 
+
+\family default 
+\series default 
+
+\newline 
+The debugger will look for the following files.
+\layout Itemize
+
+foo.c - the source file.
+\layout Itemize
+
+foo.cdb - the debugger symbol information file.
+\layout Itemize
+
+foo.ihx - the Intel hex format
+\begin_inset LatexCommand \index{Intel hex format}
+
+\end_inset 
+
+ object file.
+\layout Section
+
+Command Line Options.
+\layout Itemize
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-directory=<source file directory> this option can used to specify the directory
+ search list.
+ The debugger will look into the directory list specified for source, cdb
+ & ihx files.
+ The items in the directory list must be separated by ':', e.g.
+ if the source files can be in the directories /home/src1 and /home/src2,
+ the -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-directory option should be -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-directory=/home/src1:/home/src2.
+ Note there can be no spaces in the option.
+\layout Itemize
+
+-cd <directory> - change to the <directory>.
+\layout Itemize
+
+-fullname - used by GUI front ends.
+\layout Itemize
+
+-cpu <cpu-type> - this argument is passed to the simulator please see the
+ simulator docs for details.
+\layout Itemize
+
+-X <Clock frequency > this options is passed to the simulator please see
+ the simulator docs for details.
+\layout Itemize
+
+-s <serial port file> passed to simulator see the simulator docs for details.
+\layout Itemize
+
+-S <serial in,out> passed to simulator see the simulator docs for details.
+\layout Itemize
+
+-k <port number> passed to simulator see the simulator docs for details.
+\layout Section
+
+Debugger Commands.
+\layout Standard
+
+As mentioned earlier the command interface for the debugger has been deliberatel
+y kept as close the GNU debugger gdb, as possible.
+ This will help the integration with existing graphical user interfaces
+ (like ddd, xxgdb or xemacs) existing for the GNU debugger.
+ If you use a graphical user interface for the debugger you can skip the
+ next sections.
+\layout Subsubsection*
+
+break [line | file:line | function | file:function]
+\layout Standard
+
+Set breakpoint at specified line or function:
+\newline 
+
+\newline 
+
+\family sans 
+\series bold 
+sdcdb>break 100 
+\newline 
+sdcdb>break foo.c:100
+\newline 
+sdcdb>break funcfoo
+\newline 
+sdcdb>break foo.c:funcfoo
+\layout Subsubsection*
+
+clear [line | file:line | function | file:function ]
+\layout Standard
+
+Clear breakpoint at specified line or function:
+\newline 
+
+\newline 
+
+\family sans 
+\series bold 
+sdcdb>clear 100
+\newline 
+sdcdb>clear foo.c:100
+\newline 
+sdcdb>clear funcfoo
+\newline 
+sdcdb>clear foo.c:funcfoo
+\layout Subsubsection*
+
+continue
+\layout Standard
+
+Continue program being debugged, after breakpoint.
+\layout Subsubsection*
+
+finish
+\layout Standard
+
+Execute till the end of the current function.
+\layout Subsubsection*
+
+delete [n]
+\layout Standard
+
+Delete breakpoint number 'n'.
+ If used without any option clear ALL user defined break points.
+\layout Subsubsection*
+
+info [break | stack | frame | registers ]
+\layout Itemize
+
+info break - list all breakpoints
+\layout Itemize
+
+info stack - show the function call stack.
+\layout Itemize
+
+info frame - show information about the current execution frame.
+\layout Itemize
+
+info registers - show content of all registers.
+\layout Subsubsection*
+
+step
+\layout Standard
+
+Step program until it reaches a different source line.
+ Note: pressing <return> repeats the last command.
+\layout Subsubsection*
+
+next
+\layout Standard
+
+Step program, proceeding through subroutine calls.
+\layout Subsubsection*
+
+run
+\layout Standard
+
+Start debugged program.
+\layout Subsubsection*
+
+ptype variable 
+\layout Standard
+
+Print type information of the variable.
+\layout Subsubsection*
+
+print variable
+\layout Standard
+
+print value of variable.
+\layout Subsubsection*
+
+file filename
+\layout Standard
+
+load the given file name.
+ Note this is an alternate method of loading file for debugging.
+\layout Subsubsection*
+
+frame
+\layout Standard
+
+print information about current frame.
+\layout Subsubsection*
+
+set srcmode
+\layout Standard
+
+Toggle between C source & assembly source.
+\layout Subsubsection*
+
+! simulator command
+\layout Standard
+
+Send the string following '!' to the simulator, the simulator response is
+ displayed.
+ Note the debugger does not interpret the command being sent to the simulator,
+ so if a command like 'go' is sent the debugger can loose its execution
+ context and may display incorrect values.
+\layout Subsubsection*
+
+quit
+\layout Standard
+
+"Watch me now.
+ Iam going Down.
+ My name is Bobby Brown"
+\layout Section
+
+Interfacing with XEmacs
+\begin_inset LatexCommand \index{XEmacs}
+
+\end_inset 
+
+
+\begin_inset LatexCommand \index{Emacs}
+
+\end_inset 
+
+.
+\layout Standard
+
+Two files (in emacs lisp) are provided for the interfacing with XEmacs,
+ sdcdb.el and sdcdbsrc.el.
+ These two files can be found in the $(prefix)/bin directory after the installat
+ion is complete.
+ These files need to be loaded into XEmacs for the interface to work.
+ This can be done at XEmacs startup time by inserting the following into
+ your '.xemacs' file (which can be found in your HOME directory): 
+\newline 
+
+\newline 
+
+\family typewriter 
+(load-file sdcdbsrc.el) 
+\family default 
+
+\newline 
+
+\newline 
+.xemacs is a lisp file so the () around the command is REQUIRED.
+ The files can also be loaded dynamically while XEmacs is running, set the
+ environment variable 'EMACSLOADPATH' to the installation bin directory
+ (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
+ To start the interface enter the following command: 
+\newline 
+
+\newline 
+
+\family sans 
+\series bold 
+ESC-x sdcdbsrc
+\family default 
+\series default 
+
+\newline 
+
+\newline 
+You will prompted to enter the file name to be debugged.
+\newline 
+
+\newline 
+The command line options that are passed to the simulator directly are bound
+ to default values in the file sdcdbsrc.el.
+ The variables are listed below, these values maybe changed as required.
+\layout Itemize
+
+sdcdbsrc-cpu-type '51
+\layout Itemize
+
+sdcdbsrc-frequency '11059200
+\layout Itemize
+
+sdcdbsrc-serial nil
+\layout Standard
+
+The following is a list of key mapping for the debugger interface.
+\layout Standard
+
+\SpecialChar ~
+
+\family typewriter 
+
+\newline 
+;; Current Listing :: 
+\newline 
+;;key\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+binding\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+Comment 
+\newline 
+;;---\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+------\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+--------
+\newline 
+;; 
+\newline 
+;; n\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ sdcdb-next-from-src\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -15819,7 +17581,7 @@ Related open source tools
 \align center 
 
 \begin_inset  Tabular
-<lyxtabular version="3" rows="10" columns="3">
+<lyxtabular version="3" rows="11" columns="3">
 <features>
 <column alignment="center" valignment="top" leftline="true" width="0pt">
 <column alignment="block" valignment="top" leftline="true" width="30line%">
@@ -15844,9 +17606,45 @@ Purpose
 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
 \begin_inset Text
 
-\layout Standard
+\layout Standard
+
+Where to get
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+gpsim
+\begin_inset LatexCommand \index{gpsim (pic simulator)}
+
+\end_inset 
+
+
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PIC simulator
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
+
+\end_inset 
+
 
-Where to get
 \end_inset 
 </cell>
 </row>
@@ -15856,8 +17654,8 @@ Where to get
 
 \layout Standard
 
-gpsim
-\begin_inset LatexCommand \index{gpsim (PIC simulator)}
+gputils
+\begin_inset LatexCommand \index{gputils (pic tools)}
 
 \end_inset 
 
@@ -15869,7 +17667,7 @@ gpsim
 
 \layout Standard
 
-PIC simulator
+GNU PIC utilities
 \end_inset 
 </cell>
 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
@@ -15878,7 +17676,7 @@ PIC simulator
 \layout Standard
 
 
-\begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
+\begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
 
 \end_inset 
 
@@ -16178,7 +17976,7 @@ Related documentation / recommended reading
 \align center 
 
 \begin_inset  Tabular
-<lyxtabular version="3" rows="4" columns="3">
+<lyxtabular version="3" rows="6" columns="3">
 <features>
 <column alignment="center" valignment="top" leftline="true" width="0pt">
 <column alignment="block" valignment="top" leftline="true" width="30line%">
@@ -16285,1657 +18083,1167 @@ C-FAQ-list
 \end_inset 
 </cell>
 </row>
-<row topline="true" bottomline="true">
+<row topline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
 
 \layout Standard
 
-S.
- S.
- Muchnick
 \end_inset 
 </cell>
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
 
-\layout Standard
-
-Advanced Compiler Design and Implementation
-\end_inset 
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
-
-\layout Standard
-
-bookstore (very dedicated, probably read other books first)
-\end_inset 
-</cell>
-</row>
-</lyxtabular>
-
-\end_inset 
-
-
-\newline 
-
-\layout Section
-
-Some Questions
-\layout Standard
-
-Some questions answered, some pointers given - it might be time to in turn
- ask 
-\emph on 
-you
-\emph default 
- some questions: 
-\layout Itemize
-
-can you solve your project with the selected microcontroller? Would you
- find out early or rather late that your target is too small/slow/whatever?
- Can you switch to a slightly better device if it doesn't fit?
-\layout Itemize
-
-should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
- and/or another programming language be more adequate? Would an operating
- system on the target device help?
-\layout Itemize
-
-if you solved the problem, will the marketing department be happy?
-\layout Itemize
-
-if the marketing department is happy, will customers be happy?
-\layout Itemize
-
-if you're the project manager, marketing department and maybe even the customer
- in one person, have you tried to see the project from the outside?
-\layout Itemize
-
-is the project done if you think it is done? Or is just that other interface/pro
-tocol/feature/configuration/option missing? How about website, manual(s),
- internationalization, packaging, labels, electromagnetic compatability/interfer
-ence, documentation for production, production test software, update mechanism,
- patent issues?
-\layout Itemize
-
-is your project adequately positioned in that magic triangle: fame, fortune,
- fun?
-\layout Standard
-
-Maybe not all answers to these questions are known and some answers may
- even be 
-\emph on 
-no
-\emph default 
-, nevertheless knowing these questions may help you to avoid burnout
-\begin_inset Foot
-collapsed false
-
-\layout Standard
-
-burnout is bad for electronic devices, programmers and motorcycle tyres
-\end_inset 
-
-.
- Chances are you didn't want to hear some of them...
-\layout Chapter
-
-Support
-\begin_inset LatexCommand \index{Support}
-
-\end_inset 
-
-
-\layout Standard
-
-SDCC has grown to be a large project.
- The compiler alone (without the preprocessor, assembler and linker) is
- well over 100,000 lines of code (blank stripped).
- The open source nature of this project is a key to its continued growth
- and support.
- You gain the benefit and support of many active software developers and
- end users.
- Is SDCC perfect? No, that's why we need your help.
- The developers take pride in fixing reported bugs.
- You can help by reporting the bugs and helping other SDCC users.
- There are lots of ways to contribute, and we encourage you to take part
- in making SDCC a great software package.
-\layout Standard
-
-The SDCC project is hosted on the SDCC sourceforge site at 
-\begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
-
-\end_inset 
-
-.
- You'll find the complete set of mailing lists
-\begin_inset LatexCommand \index{Mailing list}
-
-\end_inset 
-
-, forums, bug reporting system, patch submission
-\begin_inset LatexCommand \index{Patch submission}
-
-\end_inset 
-
- system, download
-\begin_inset LatexCommand \index{download}
-
-\end_inset 
-
- area and cvs code repository
-\begin_inset LatexCommand \index{cvs code repository}
-
-\end_inset 
-
- there.
-\layout Section
-
-Reporting Bugs
-\begin_inset LatexCommand \index{Bug reporting}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{Reporting bugs}
-
-\end_inset 
-
-
-\layout Standard
-
-The recommended way of reporting bugs is using the infrastructure of the
- sourceforge site.
- You can follow the status of bug reports there and have an overview about
- the known bugs.
-\layout Standard
-
-Bug reports are automatically forwarded to the developer mailing list and
- will be fixed ASAP.
- When reporting a bug, it is very useful to include a small test program
- (the smaller the better) which reproduces the problem.
- If you can isolate the problem by looking at the generated assembly code,
- this can be very helpful.
- Compiling your program with the -
-\begin_inset ERT
-status Collapsed
-
-\layout Standard
-
-\backslash 
-/
-\end_inset 
-
--dumpall
-\begin_inset LatexCommand \index{-\/-dumpall}
-
-\end_inset 
-
- option can sometimes be useful in locating optimization problems.
- When reporting a bug please maker sure you:
-\layout Enumerate
-
-Attach the code you are compiling with SDCC.
-\layout Enumerate
-
-Specify the exact command you use to run SDCC, or attach your Makefile.
-\layout Enumerate
-
-Specify the SDCC version (type "sdcc -v"), your platform, and operating
- system.
-\layout Enumerate
-
-Provide an exact copy of any error message or incorrect output.
-\layout Enumerate
-
-Put something meaningful in the subject of your message.
-\layout Standard
-
-Please attempt to include these 5 important parts, as applicable, in all
- requests for support or when reporting any problems or bugs with SDCC.
- Though this will make your message lengthy, it will greatly improve your
- chance that SDCC users and developers will be able to help you.
- Some SDCC developers are frustrated by bug reports without code provided
- that they can use to reproduce and ultimately fix the problem, so please
- be sure to provide sample code if you are reporting a bug! 
-\layout Standard
-
-Please have a short check that you are using a recent version of SDCC and
- the bug is not yet known.
- This is the link for reporting bugs: 
-\begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
-
-\end_inset 
-
-.
-\layout Section
-
-Requesting Features
-\begin_inset LatexCommand \label{sub:Requesting-Features}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{Feature request}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{Requesting features}
-
-\end_inset 
-
-
-\layout Standard
-
-Like bug reports feature requests are forwarded to the developer mailing
- list.
- This is the link for requesting features: 
-\begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
-
-\end_inset 
-
-.
-\layout Section
-
-Getting Help
-\layout Standard
-
-These links should take you directly to the 
-\begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
+\layout Standard
 
+Latest datasheet of the target CPU
 \end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
 
+\layout Standard
 
-\begin_inset Foot
-collapsed false
+vendor
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
 
 \layout Standard
 
-Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
- automated messages (mid 2003)
 \end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
 
- and the 
-\begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
+\layout Standard
 
+Revision history of datasheet
 \end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
 
-, lists and forums are archived and searchable so if you are lucky someone
- already had a similar problem.
-\layout Section
-
-ChangeLog
 \layout Standard
 
-You can follow the status of the cvs version
-\begin_inset LatexCommand \index{version}
-
+vendor
 \end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
 
- of SDCC by watching the Changelog
-\begin_inset LatexCommand \index{Changelog}
+\layout Standard
 
+S.
+ S.
+ Muchnick
 \end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
 
- in the cvs-repository
-\newline 
+\layout Standard
 
-\size footnotesize 
+Advanced Compiler Design and Implementation
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
 
-\begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
+\layout Standard
 
+bookstore (very dedicated, probably read other books first)
 \end_inset 
+</cell>
+</row>
+</lyxtabular>
 
-.
-\layout Section
+\end_inset 
 
-Release policy
-\begin_inset LatexCommand \index{Release policy}
 
-\end_inset 
+\newline 
 
+\layout Section
 
+Some Questions
 \layout Standard
 
-Historically there often were long delays between official releases and
- the sourceforge download area tends to get not updated at all.
- Current excuses might refer to problems with live range analysis, but if
- this is fixed, the next problem rising is that another excuse will have
- to be found.
- Kidding aside, we have to get better there! On the other hand there are
- daily snapshots available at 
-\begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
-
-\end_inset 
+Some questions answered, some pointers given - it might be time to in turn
+ ask 
+\emph on 
+you
+\emph default 
+ some questions: 
+\layout Itemize
 
-, and you can always built the very last version (hopefully with many bugs
- fixed, and features added) from the source code available at 
-\begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
+can you solve your project with the selected microcontroller? Would you
+ find out early or rather late that your target is too small/slow/whatever?
+ Can you switch to a slightly better device if it doesn't fit?
+\layout Itemize
 
-\end_inset 
+should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
+ and/or another programming language be more adequate? Would an operating
+ system on the target device help?
+\layout Itemize
 
-.
-\layout Section
+if you solved the problem, will the marketing department be happy?
+\layout Itemize
 
-Examples
-\begin_inset LatexCommand \index{Examples}
+if the marketing department is happy, will customers be happy?
+\layout Itemize
 
-\end_inset 
+if you're the project manager, marketing department and maybe even the customer
+ in one person, have you tried to see the project from the outside?
+\layout Itemize
 
+is the project done if you think it is done? Or is just that other interface/pro
+tocol/feature/configuration/option missing? How about website, manual(s),
+ internationali(z|s)ation, packaging, labels, 2nd source for components,
+ electromagnetic compatability/interference, documentation for production,
+ production test software, update mechanism, patent issues?
+\layout Itemize
 
+is your project adequately positioned in that magic triangle: fame, fortune,
+ fun?
 \layout Standard
 
-You'll find some small examples in the directory 
+Maybe not all answers to these questions are known and some answers may
+ even be 
 \emph on 
-sdcc/device/examples/.
+no
 \emph default 
-More examples and libraries are available at
-\emph on 
- The SDCC Open Knowledge Resource 
-\begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
-
-\end_inset 
+, nevertheless knowing these questions may help you to avoid burnout
+\begin_inset Foot
+collapsed false
 
-\emph default 
-web site or at 
-\begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
+\layout Standard
 
+burnout is bad for electronic devices, programmers and motorcycle tyres
 \end_inset 
 
 .
-\layout Comment
-
-I did insert a reference to Paul's web site here although it seems rather
- dedicated to a specific 8032 board (I think it's okay because it f.e.
- shows LCD/Harddisc interface and has a free 8051 monitor.
- Independent 8032 board vendors face hard competition of heavily subsidized
- development boards anyway).
-\layout Comment
-
-Maybe we should include some links to real world applications.
- Preferably pointer to pointers (one for each architecture) so this stays
- manageable here?
-\layout Section
+ Chances are you didn't want to hear some of them...
+\layout Chapter
 
-Quality control
-\begin_inset LatexCommand \index{Quality control}
+Support
+\begin_inset LatexCommand \index{Support}
 
 \end_inset 
 
 
 \layout Standard
 
-The compiler is passed through nightly compile and build checks.
- The so called 
-\shape italic 
-regression tests
-\shape default 
+SDCC has grown to be a large project.
+ The compiler alone (without the preprocessor, assembler and linker) is
+ well over 100,000 lines of code (blank stripped).
+ The open source nature of this project is a key to its continued growth
+ and support.
+ You gain the benefit and support of many active software developers and
+ end users.
+ Is SDCC perfect? No, that's why we need your help.
+ The developers take pride in fixing reported bugs.
+ You can help by reporting the bugs and helping other SDCC users.
+ There are lots of ways to contribute, and we encourage you to take part
+ in making SDCC a great software package.
+\layout Standard
 
-\begin_inset LatexCommand \index{Regression test}
+The SDCC project is hosted on the SDCC sourceforge site at 
+\begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
 
 \end_inset 
 
- check that SDCC itself compiles flawlessly on several platforms and checks
- the quality of the code generated by SDCC by running the code through simulator
-s.
- There is a separate document 
-\shape italic 
-test_suite.pdf
-\begin_inset LatexCommand \index{Test suite}
+.
+ You'll find the complete set of mailing lists
+\begin_inset LatexCommand \index{Mailing list}
 
 \end_inset 
 
+, forums, bug reporting system, patch submission
+\begin_inset LatexCommand \index{Patch submission}
 
-\shape default 
- about this.
-\layout Standard
+\end_inset 
 
-You'll find the test code in the directory 
-\shape italic 
-sdcc/support/regression
-\shape default 
-.
- You can run these tests manually by running 
-\family sans 
-make
-\family default 
- in this directory (or f.e.
-\family sans 
-make test-mcs51
-\family default 
- if you don't want to run the complete tests).
- The test code might also be interesting if you want to look for examples
-\begin_inset LatexCommand \index{Examples}
+ system, download
+\begin_inset LatexCommand \index{download}
 
 \end_inset 
 
- checking corner cases of SDCC or if you plan to submit patches
-\begin_inset LatexCommand \index{Patch submission}
+ area and cvs code repository
+\begin_inset LatexCommand \index{cvs code repository}
 
 \end_inset 
 
-.
-\layout Standard
-
-The pic port uses a different set of regression tests, you'll find them
- in the directory 
-\shape italic 
-sdcc/src/regression
-\shape default 
-.
-\layout Chapter
-\pagebreak_top 
-SDCC Technical Data
+ there.
 \layout Section
 
-Optimizations
-\begin_inset LatexCommand \index{Optimizations}
+Reporting Bugs
+\begin_inset LatexCommand \index{Bug reporting}
+
+\end_inset 
+
+
+\begin_inset LatexCommand \index{Reporting bugs}
 
 \end_inset 
 
 
 \layout Standard
 
-SDCC performs a host of standard optimizations in addition to some MCU specific
- optimizations.
-\layout Subsection
+The recommended way of reporting bugs is using the infrastructure of the
+ sourceforge site.
+ You can follow the status of bug reports there and have an overview about
+ the known bugs.
+\layout Standard
+
+Bug reports are automatically forwarded to the developer mailing list and
+ will be fixed ASAP.
+ When reporting a bug, it is very useful to include a small test program
+ (the smaller the better) which reproduces the problem.
+ If you can isolate the problem by looking at the generated assembly code,
+ this can be very helpful.
+ Compiling your program with the -
+\begin_inset ERT
+status Collapsed
 
-Sub-expression Elimination
-\begin_inset LatexCommand \index{Subexpression elimination}
+\layout Standard
 
+\backslash 
+/
 \end_inset 
 
+-dumpall
+\begin_inset LatexCommand \index{-\/-dumpall}
 
-\layout Standard
+\end_inset 
 
-The compiler does local and 
-\emph on 
-g
-\emph default 
-lobal 
-\emph on 
-c
-\emph default 
-ommon 
-\emph on 
-s
-\emph default 
-ubexpression 
-\emph on 
-e
-\emph default 
-limination, e.g.: 
-\layout Verse
+ option can sometimes be useful in locating optimization problems.
+ When reporting a bug please maker sure you:
+\layout Enumerate
 
+Attach the code you are compiling with SDCC.
+\layout Enumerate
 
-\family typewriter 
-i = x + y + 1; 
-\newline 
-j = x + y;
-\layout Standard
+Specify the exact command you use to run SDCC, or attach your Makefile.
+\layout Enumerate
 
-will be translated to
-\layout Verse
+Specify the SDCC version (type "
+\family sans 
+\series bold 
+sdcc -v
+\family default 
+\series default 
+"), your platform, and operating system.
+\layout Enumerate
 
+Provide an exact copy of any error message or incorrect output.
+\layout Enumerate
 
-\family typewriter 
-iTemp = x + y; 
-\newline 
-i = iTemp + 1; 
-\newline 
-j = iTemp;
+Put something meaningful in the subject of your message.
 \layout Standard
 
-Some subexpressions are not as obvious as the above example, e.g.:
-\layout Verse
+Please attempt to include these 5 important parts, as applicable, in all
+ requests for support or when reporting any problems or bugs with SDCC.
+ Though this will make your message lengthy, it will greatly improve your
+ chance that SDCC users and developers will be able to help you.
+ Some SDCC developers are frustrated by bug reports without code provided
+ that they can use to reproduce and ultimately fix the problem, so please
+ be sure to provide sample code if you are reporting a bug! 
+\layout Standard
 
+Please have a short check that you are using a recent version of SDCC and
+ the bug is not yet known.
+ This is the link for reporting bugs: 
+\begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
 
-\family typewriter 
-a->b[i].c = 10; 
-\newline 
-a->b[i].d = 11;
-\layout Standard
+\end_inset 
 
-In this case the address arithmetic a->b[i] will be computed only once;
- the equivalent code in C would be.
-\layout Verse
+.
+\layout Section
 
+Requesting Features
+\begin_inset LatexCommand \label{sub:Requesting-Features}
 
-\family typewriter 
-iTemp = a->b[i]; 
-\newline 
-iTemp.c = 10; 
-\newline 
-iTemp.d = 11;
-\layout Standard
+\end_inset 
 
-The compiler will try to keep these temporary variables in registers.
-\layout Subsection
 
-Dead-Code Elimination
-\begin_inset LatexCommand \index{Dead-code elimination}
+\begin_inset LatexCommand \index{Feature request}
 
 \end_inset 
 
 
-\layout Verse
+\begin_inset LatexCommand \index{Requesting features}
 
+\end_inset 
 
-\family typewriter 
-int global;
-\newline 
 
-\newline 
-void f () { 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-int i; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-i = 1; \SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-/* dead store */ 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-global = 1;\SpecialChar ~
-/* dead store */ 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-global = 2; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-return; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-global = 3;\SpecialChar ~
-/* unreachable */ 
-\newline 
-}
 \layout Standard
 
-will be changed to
-\layout Verse
+Like bug reports feature requests are forwarded to the developer mailing
+ list.
+ This is the link for requesting features: 
+\begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
 
+\end_inset 
 
-\family typewriter 
-int global;
-\newline 
+.
+\layout Section
 
-\newline 
-void f () {
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-global = 2; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-return; 
-\newline 
-}
-\layout Subsection
+Submitting patches
+\layout Standard
 
-Copy-Propagation
-\begin_inset LatexCommand \index{Copy propagation}
+Like bug reports contributed patches are forwarded to the developer mailing
+ list.
+ This is the link for submitting patches
+\begin_inset LatexCommand \index{Patch submission}
 
 \end_inset 
 
+: 
+\begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
 
-\layout Verse
-
+\end_inset 
 
-\family typewriter 
-int f() { 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-int i, j; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-i = 10; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-j = i; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-return j; 
-\newline 
-}
+.
 \layout Standard
 
-will be changed to 
-\layout Verse
+You need to specify some parameters to the 
+\family typewriter 
+diff
+\family default 
+ command for the patches to be useful.
+ If you modified more than one file a patch created f.e.
+ with 
+\family sans 
+\series bold 
 
+\begin_inset Quotes sld
+\end_inset 
 
-\family typewriter 
-int f() { 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-int i, j; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-i = 10; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-j = 10; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-return 10; 
-\newline 
-}
-\layout Standard
+diff -Naur unmodified_directory modified_directory >my_changes.patch
+\begin_inset Quotes srd
+\end_inset 
 
-Note: the dead stores created by this copy propagation will be eliminated
- by dead-code elimination.
-\layout Subsection
 
-Loop Optimizations
-\begin_inset LatexCommand \index{Loop optimization}
+\family default 
+\series default 
+ will be fine, otherwise 
+\family sans 
+\series bold 
 
+\begin_inset Quotes sld
 \end_inset 
 
+diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
+\begin_inset Quotes srd
+\end_inset 
 
-\layout Standard
 
-Two types of loop optimizations are done by SDCC loop invariant lifting
- and strength reduction of loop induction variables.
- In addition to the strength reduction the optimizer marks the induction
- variables and the register allocator tries to keep the induction variables
- in registers for the duration of the loop.
- Because of this preference of the register allocator
-\begin_inset LatexCommand \index{Register allocation}
+\series default 
+\family default 
+will do.
+\layout Section
 
-\end_inset 
+Getting Help
+\layout Standard
 
-, loop induction optimization causes an increase in register pressure, which
- may cause unwanted spilling of other temporary variables into the stack
-\begin_inset LatexCommand \index{stack}
+These links should take you directly to the 
+\begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
 
 \end_inset 
 
- / data space.
- The compiler will generate a warning message when it is forced to allocate
- extra space either on the stack or data space.
- If this extra space allocation is undesirable then induction optimization
- can be eliminated either for the entire source file (with -
-\begin_inset ERT
-status Collapsed
+
+\begin_inset Foot
+collapsed false
 
 \layout Standard
 
-\backslash 
-/
+Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
+ automated messages (mid 2003)
 \end_inset 
 
--noinduction option) or for a given function only using #pragma\SpecialChar ~
-noinduction
-\begin_inset LatexCommand \index{\#pragma noinduction}
+ and the 
+\begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
 
 \end_inset 
 
-.
-\newline 
+, lists and forums are archived and searchable so if you are lucky someone
+ already had a similar problem.
+\layout Section
 
-\newline 
-Loop Invariant:
-\layout Verse
+ChangeLog
+\layout Standard
 
+You can follow the status of the cvs version
+\begin_inset LatexCommand \index{version}
 
-\family typewriter 
-for (i = 0 ; i < 100 ; i ++) 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-f += k + l;
-\layout Standard
+\end_inset 
 
-changed to
-\layout Verse
+ of SDCC by watching the Changelog
+\begin_inset LatexCommand \index{Changelog}
 
+\end_inset 
 
-\family typewriter 
-itemp = k + l; 
-\newline 
-for (i = 0; i < 100; i++) 
+ in the cvs-repository
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-f += itemp;
-\layout Standard
 
-As mentioned previously some loop invariants are not as apparent, all static
- address computations are also moved out of the loop.
-\newline 
+\size footnotesize 
 
-\newline 
-Strength Reduction
-\begin_inset LatexCommand \index{Strength reduction}
+\begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
 
 \end_inset 
 
-, this optimization substitutes an expression by a cheaper expression:
-\layout Verse
-
+.
+\layout Section
 
-\family typewriter 
-for (i=0;i < 100; i++)
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-ar[i*5] = i*3;
-\layout Standard
+Release policy
+\begin_inset LatexCommand \index{Release policy}
 
-changed to
-\layout Verse
+\end_inset 
 
 
-\family typewriter 
-itemp1 = 0; 
-\newline 
-itemp2 = 0; 
-\newline 
-for (i=0;i< 100;i++) { 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-ar[itemp1] = itemp2; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-itemp1 += 5; 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-itemp2 += 3; 
-\newline 
-}
 \layout Standard
 
-The more expensive multiplication
-\begin_inset LatexCommand \index{Multiplication}
+Historically there often were long delays between official releases and
+ the sourceforge download area tends to get not updated at all.
+ Excuses in the past might have referred to problems with live range analysis,
+ but as this was fixed a while ago, the current problem is that another
+ excuse has to be found.
+ Kidding aside, we have to get better there! On the other hand there are
+ daily snapshots available at 
+\begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
 
 \end_inset 
 
- is changed to a less expensive addition.
-\layout Subsection
-
-Loop Reversing
-\begin_inset LatexCommand \index{Loop reversing}
+, and you can always build the very last version (hopefully with many bugs
+ fixed, and features added) from the source code available at 
+\begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
 
 \end_inset 
 
+.
+\layout Section
 
-\layout Standard
-
-This optimization is done to reduce the overhead of checking loop boundaries
- for every iteration.
- Some simple loops can be reversed and implemented using a 
-\begin_inset Quotes eld
-\end_inset 
+Examples
+\begin_inset LatexCommand \index{Examples}
 
-decrement and jump if not zero
-\begin_inset Quotes erd
 \end_inset 
 
- instruction.
- SDCC checks for the following criterion to determine if a loop is reversible
- (note: more sophisticated compilers use data-dependency analysis to make
- this determination, SDCC uses a more simple minded analysis).
-\layout Itemize
-
-The 'for' loop is of the form 
-\newline 
 
-\newline 
+\layout Standard
 
-\family typewriter 
-for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
- += 1])
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-<for body>
-\layout Itemize
+You'll find some small examples in the directory 
+\emph on 
+sdcc/device/examples/.
+\emph default 
+More examples and libraries are available at
+\emph on 
+ The SDCC Open Knowledge Resource 
+\begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
 
-The <for body> does not contain 
-\begin_inset Quotes eld
 \end_inset 
 
-continue
-\begin_inset Quotes erd
-\end_inset 
+\emph default 
+web site or at 
+\begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
 
- or 'break
-\begin_inset Quotes erd
 \end_inset 
 
 .
-\layout Itemize
+\layout Comment
 
-All goto's are contained within the loop.
-\layout Itemize
+I did insert a reference to Paul's web site here although it seems rather
+ dedicated to a specific 8032 board (I think it's okay because it f.e.
+ shows LCD/Harddisc interface and has a free 8051 monitor.
+ Independent 8032 board vendors face hard competition of heavily subsidized
+ development boards anyway).
+\layout Comment
 
-No function calls within the loop.
-\layout Itemize
+Maybe we should include some links to real world applications.
+ Preferably pointer to pointers (one for each architecture) so this stays
+ manageable here?
+\layout Section
 
-The loop control variable <sym> is not assigned any value within the loop
-\layout Itemize
+Quality control
+\begin_inset LatexCommand \index{Quality control}
 
-The loop control variable does NOT participate in any arithmetic operation
- within the loop.
-\layout Itemize
+\end_inset 
 
-There are NO switch statements in the loop.
-\layout Subsection
 
-Algebraic Simplifications
 \layout Standard
 
-SDCC does numerous algebraic simplifications, the following is a small sub-set
- of these optimizations.
-\layout Verse
-
-
-\family typewriter 
-i = j + 0;\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- /* changed to: */\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- i = j; 
-\newline 
-i /= 2;\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- /* changed to: */\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- i >>= 1; 
-\newline 
-i = j - j;\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- /* changed to: */\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- i = 0; 
-\newline 
-i = j / 1;\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- /* changed to: */\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- i = j;
-\layout Standard
+The compiler is passed through nightly compile and build checks.
+ The so called 
+\shape italic 
+regression tests
+\shape default 
 
-Note the subexpressions
-\begin_inset LatexCommand \index{Subexpression}
+\begin_inset LatexCommand \index{Regression test}
 
 \end_inset 
 
- given above are generally introduced by macro expansions or as a result
- of copy/constant propagation.
-\layout Subsection
-
-'switch' Statements
-\begin_inset LatexCommand \label{sub:'switch'-Statements}
+ check that SDCC itself compiles flawlessly on several platforms and checks
+ the quality of the code generated by SDCC by running the code through simulator
+s.
+ There is a separate document 
+\shape italic 
+test_suite.pdf
+\begin_inset LatexCommand \index{Test suite}
 
 \end_inset 
 
 
-\begin_inset LatexCommand \index{switch statement}
+\shape default 
+ about this.
+\layout Standard
+
+You'll find the test code in the directory 
+\shape italic 
+sdcc/support/regression
+\shape default 
+.
+ You can run these tests manually by running 
+\family sans 
+make
+\family default 
+ in this directory (or f.e.
+\family sans 
+\series bold 
 
+\begin_inset Quotes sld
 \end_inset 
 
+make test-mcs51
+\begin_inset Quotes srd
+\end_inset 
 
-\layout Standard
 
-SDCC changes switch statements to jump tables
-\begin_inset LatexCommand \index{jump tables}
+\family default 
+\series default 
+ if you don't want to run the complete tests).
+ The test code might also be interesting if you want to look for examples
+\begin_inset LatexCommand \index{Examples}
 
 \end_inset 
 
- when the following conditions are true.
-\layout Itemize
+ checking corner cases of SDCC or if you plan to submit patches
+\begin_inset LatexCommand \index{Patch submission}
 
-The case labels are in numerical sequence, the labels need not be in order,
- and the starting number need not be one or zero.
-\begin_deeper 
-\layout Verse
+\end_inset 
+
+.
+\layout Standard
+
+The pic port uses a different set of regression tests, you'll find them
+ in the directory 
+\shape italic 
+sdcc/src/regression
+\shape default 
+.
+\layout Chapter
+\pagebreak_top 
+SDCC Technical Data
+\layout Section
+
+Optimizations
+\begin_inset LatexCommand \index{Optimizations}
+
+\end_inset 
 
 
-\family typewriter 
-switch(i) {\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-switch (i) { 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 4: ...\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 0: ...
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 5: ...\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 1: ...
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 3: ...\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 2: ...
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 6: ...\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-case 3: ...
-\newline 
-}\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-}
 \layout Standard
 
-Both the above switch statements will be implemented using a jump-table.
- The example to the right side is slightly more efficient as the check for
- the lower boundary of the jump-table is not needed.
-\end_deeper 
-\layout Itemize
+SDCC performs a host of standard optimizations in addition to some MCU specific
+ optimizations.
+\layout Subsection
+
+Sub-expression Elimination
+\begin_inset LatexCommand \index{Subexpression elimination}
+
+\end_inset 
 
-The number of case labels is at least three, since it takes two conditional
- statements to handle the boundary conditions.
-\layout Itemize
 
-The number of case labels is less than 84, since each label takes 3 bytes
- and a jump-table can be utmost 256 bytes long.
 \layout Standard
 
-Switch statements which have gaps in the numeric sequence or those that
- have more that 84 case labels can be split into more than one switch statement
- for efficient code generation, e.g.:
+The compiler does local and 
+\emph on 
+g
+\emph default 
+lobal 
+\emph on 
+c
+\emph default 
+ommon 
+\emph on 
+s
+\emph default 
+ubexpression 
+\emph on 
+e
+\emph default 
+limination, e.g.: 
 \layout Verse
 
 
 \family typewriter 
-switch (i) { 
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-case 1: ...
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-case 2: ...
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-case 3: ...
+i = x + y + 1; 
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-case 4: ...
+j = x + y;
+\layout Standard
+
+will be translated to
+\layout Verse
+
+
+\family typewriter 
+iTemp = x + y; 
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-case 9: ...
+i = iTemp + 1; 
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-case 10: ...
+j = iTemp;
+\layout Standard
+
+Some subexpressions are not as obvious as the above example, e.g.:
+\layout Verse
+
+
+\family typewriter 
+a->b[i].c = 10; 
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-case 11: ...
+a->b[i].d = 11;
+\layout Standard
+
+In this case the address arithmetic a->b[i] will be computed only once;
+ the equivalent code in C would be.
+\layout Verse
+
+
+\family typewriter 
+iTemp = a->b[i]; 
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-case 12: ...
+iTemp.c = 10; 
 \newline 
-}
+iTemp.d = 11;
 \layout Standard
 
-If the above switch statement is broken down into two switch statements
+The compiler will try to keep these temporary variables in registers.
+\layout Subsection
+
+Dead-Code Elimination
+\begin_inset LatexCommand \index{Dead-code elimination}
+
+\end_inset 
+
+
 \layout Verse
 
 
 \family typewriter 
-switch (i) { 
+int global;
+\newline 
+
+\newline 
+void f () { 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-case 1: ...
+int i; 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-case 2: ...
-\newline 
+i = 1; \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-case 3: ...
-\newline 
 \SpecialChar ~
 \SpecialChar ~
-case 4: ...
-\newline 
-}
-\layout Standard
-
-and
-\layout Verse
-
-
-\family typewriter 
-switch (i) { 
+/* dead store */ 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-case 9:\SpecialChar ~
-\SpecialChar ~
-...
+global = 1;\SpecialChar ~
+/* dead store */ 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-case 10:\SpecialChar ~
-...
+global = 2; 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-case 11:\SpecialChar ~
-...
+return; 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-case 12:\SpecialChar ~
-...
+global = 3;\SpecialChar ~
+/* unreachable */ 
 \newline 
 }
 \layout Standard
 
-then both the switch statements will be implemented using jump-tables whereas
- the unmodified switch statement will not be.
- You might also consider inserting dummy cases 0 and 5 to 8 in this example.
-\newline 
-The pragma nojtbound
-\begin_inset LatexCommand \index{\#pragma nojtbound}
-
-\end_inset 
-
- can be used to turn off checking the 
-\emph on 
-j
-\emph default 
-ump 
-\emph on 
-t
-\emph default 
-able 
-\emph on 
-bound
-\emph default 
-aries.
- It has no effect if a default label is supplied.
- Use of this pragma is dangerous: if the switch argument is not matched
- by a case statement the processor will happily jump into Nirvana.
-\layout Subsection
-
-Bit-shifting Operations
-\begin_inset LatexCommand \index{Bit shifting}
-
-\end_inset 
-
-.
-\layout Standard
-
-Bit shifting is one of the most frequently used operation in embedded programmin
-g.
- SDCC tries to implement bit-shift operations in the most efficient way
- possible, e.g.:
+will be changed to
 \layout Verse
 
 
 \family typewriter 
-unsigned char i;
-\newline 
-...
-\newline 
-i >>= 4; 
+int global;
 \newline 
-...
-\layout Standard
 
-generates the following code:
-\layout Verse
-
-
-\family typewriter 
-mov\SpecialChar ~
- a,_i 
 \newline 
-swap a 
+void f () {
 \newline 
-anl\SpecialChar ~
- a,#0x0f 
+\SpecialChar ~
+\SpecialChar ~
+global = 2; 
 \newline 
-mov\SpecialChar ~
- _i,a
-\layout Standard
+\SpecialChar ~
+\SpecialChar ~
+return; 
+\newline 
+}
+\layout Subsection
+
+Copy-Propagation
+\begin_inset LatexCommand \index{Copy propagation}
+
+\end_inset 
+
 
-In general SDCC will never setup a loop if the shift count is known.
- Another example:
 \layout Verse
 
 
 \family typewriter 
-unsigned int i; 
+int f() { 
 \newline 
-...
+\SpecialChar ~
+\SpecialChar ~
+int i, j; 
 \newline 
-i >>= 9; 
+\SpecialChar ~
+\SpecialChar ~
+i = 10; 
 \newline 
-...
+\SpecialChar ~
+\SpecialChar ~
+j = i; 
+\newline 
+\SpecialChar ~
+\SpecialChar ~
+return j; 
+\newline 
+}
 \layout Standard
 
-will generate:
+will be changed to 
 \layout Verse
 
 
 \family typewriter 
-mov\SpecialChar ~
-\SpecialChar ~
-a,(_i + 1) 
+int f() { 
 \newline 
-mov\SpecialChar ~
 \SpecialChar ~
-(_i + 1),#0x00 
+\SpecialChar ~
+int i, j; 
 \newline 
-clr\SpecialChar ~
 \SpecialChar ~
-c 
+\SpecialChar ~
+i = 10; 
 \newline 
-rrc\SpecialChar ~
 \SpecialChar ~
-a 
+\SpecialChar ~
+j = 10; 
 \newline 
-mov\SpecialChar ~
 \SpecialChar ~
-_i,a
+\SpecialChar ~
+return 10; 
+\newline 
+}
+\layout Standard
+
+Note: the dead stores created by this copy propagation will be eliminated
+ by dead-code elimination.
 \layout Subsection
 
-Bit-rotation
-\begin_inset LatexCommand \index{Bit rotation}
+Loop Optimizations
+\begin_inset LatexCommand \index{Loop optimization}
 
 \end_inset 
 
 
 \layout Standard
 
-A special case of the bit-shift operation is bit rotation
-\begin_inset LatexCommand \index{rotating bits}
+Two types of loop optimizations are done by SDCC loop invariant lifting
+ and strength reduction of loop induction variables.
+ In addition to the strength reduction the optimizer marks the induction
+ variables and the register allocator tries to keep the induction variables
+ in registers for the duration of the loop.
+ Because of this preference of the register allocator
+\begin_inset LatexCommand \index{Register allocation}
 
 \end_inset 
 
-, SDCC recognizes the following expression to be a left bit-rotation:
+, loop induction optimization causes an increase in register pressure, which
+ may cause unwanted spilling of other temporary variables into the stack
+\begin_inset LatexCommand \index{stack}
+
+\end_inset 
+
+ / data space.
+ The compiler will generate a warning message when it is forced to allocate
+ extra space either on the stack or data space.
+ If this extra space allocation is undesirable then induction optimization
+ can be eliminated either for the entire source file (with -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-noinduction option) or for a given function only using #pragma\SpecialChar ~
+noinduction
+\begin_inset LatexCommand \index{\#pragma noinduction}
+
+\end_inset 
+
+.
+\newline 
+
+\newline 
+Loop Invariant:
 \layout Verse
 
 
 \family typewriter 
-\series bold 
-unsigned
-\series default 
-\SpecialChar ~
-\SpecialChar ~
-char i;\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
+for (i = 0 ; i < 100 ; i ++) 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+f += k + l;
+\layout Standard
+
+changed to
+\layout Verse
+
+
+\family typewriter 
+itemp = k + l; 
+\newline 
+for (i = 0; i < 100; i++) 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-/* unsigned is needed for rotation */ 
-\newline 
-...
+f += itemp;
+\layout Standard
+
+As mentioned previously some loop invariants are not as apparent, all static
+ address computations are also moved out of the loop.
 \newline 
-i = ((i << 1) | (i >> 7)); 
-\family default 
 
 \newline 
+Strength Reduction
+\begin_inset LatexCommand \index{Strength reduction}
+
+\end_inset 
+
+, this optimization substitutes an expression by a cheaper expression:
+\layout Verse
+
 
 \family typewriter 
-...
+for (i=0;i < 100; i++)
+\newline 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ar[i*5] = i*3;
 \layout Standard
 
-will generate the following code:
+changed to
 \layout Verse
 
 
 \family typewriter 
-mov\SpecialChar ~
+itemp1 = 0; 
+\newline 
+itemp2 = 0; 
+\newline 
+for (i=0;i< 100;i++) { 
+\newline 
 \SpecialChar ~
-a,_i 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ar[itemp1] = itemp2; 
 \newline 
-rl\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-a 
+\SpecialChar ~
+\SpecialChar ~
+itemp1 += 5; 
 \newline 
-mov\SpecialChar ~
 \SpecialChar ~
-_i,a
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+itemp2 += 3; 
+\newline 
+}
 \layout Standard
 
-SDCC uses pattern matching on the parse tree to determine this operation.Variatio
-ns of this case will also be recognized as bit-rotation, i.e.: 
-\layout Verse
+The more expensive multiplication
+\begin_inset LatexCommand \index{Multiplication}
 
+\end_inset 
 
-\family typewriter 
-i = ((i >> 7) | (i << 1)); /* left-bit rotation */
+ is changed to a less expensive addition.
 \layout Subsection
 
-Nibble and Byte Swapping
+Loop Reversing
+\begin_inset LatexCommand \index{Loop reversing}
+
+\end_inset 
+
+
 \layout Standard
 
-Other special cases of the bit-shift operations are nibble or byte swapping
-\begin_inset LatexCommand \index{swapping nibbles/bytes}
+This optimization is done to reduce the overhead of checking loop boundaries
+ for every iteration.
+ Some simple loops can be reversed and implemented using a 
+\begin_inset Quotes eld
+\end_inset 
 
+decrement and jump if not zero
+\begin_inset Quotes erd
 \end_inset 
 
-, SDCC recognizes the following expressions:
-\layout Verse
+ instruction.
+ SDCC checks for the following criterion to determine if a loop is reversible
+ (note: more sophisticated compilers use data-dependency analysis to make
+ this determination, SDCC uses a more simple minded analysis).
+\layout Itemize
+
+The 'for' loop is of the form 
+\newline 
 
+\newline 
 
 \family typewriter 
-\series bold 
-unsigned
-\series default 
+for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
+ += 1])
+\newline 
 \SpecialChar ~
 \SpecialChar ~
-char i; 
-\newline 
-
-\series bold 
-unsigned
-\series default 
 \SpecialChar ~
 \SpecialChar ~
-int j; 
-\newline 
-...
-\newline 
-i = ((i << 4) | (i >> 4)); 
-\family default 
-
-\newline 
+<for body>
+\layout Itemize
 
-\family typewriter 
-j = ((j << 8) | (j >> 8)); 
-\layout Standard
+The <for body> does not contain 
+\begin_inset Quotes eld
+\end_inset 
 
-and generates a swap instruction for the nibble swapping
-\begin_inset LatexCommand \index{Nibble swapping}
+continue
+\begin_inset Quotes erd
+\end_inset 
 
+ or 'break
+\begin_inset Quotes erd
 \end_inset 
 
- or move instructions for the byte swapping
-\begin_inset LatexCommand \index{Byte swapping}
+.
+\layout Itemize
 
-\end_inset 
+All goto's are contained within the loop.
+\layout Itemize
 
-.
- The 
-\begin_inset Quotes sld
-\end_inset 
+No function calls within the loop.
+\layout Itemize
 
-j
-\begin_inset Quotes srd
-\end_inset 
+The loop control variable <sym> is not assigned any value within the loop
+\layout Itemize
 
- example can be used to convert from little to big-endian or vice versa.
- If you want to change the endianness of a 
-\emph on 
-signed
-\emph default 
- integer you have to cast to 
-\family typewriter 
-(unsigned int)
-\family default 
- first.
-\layout Standard
+The loop control variable does NOT participate in any arithmetic operation
+ within the loop.
+\layout Itemize
 
-Note that SDCC stores numbers in little-endian
-\begin_inset Foot
-collapsed false
+There are NO switch statements in the loop.
+\layout Subsection
 
+Algebraic Simplifications
 \layout Standard
 
-Usually 8-bit processors don't care much about endianness.
- This is not the case for the standard 8051 which only has an instruction
- to increment its 
-\emph on 
-dptr
-\emph default 
+SDCC does numerous algebraic simplifications, the following is a small sub-set
+ of these optimizations.
+\layout Verse
 
-\begin_inset LatexCommand \index{DPTR}
 
-\end_inset 
+\family typewriter 
+i = j + 0;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ /* changed to: */\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ i = j; 
+\newline 
+i /= 2;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ /* changed to: */\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ i >>= 1; 
+\newline 
+i = j - j;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ /* changed to: */\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ i = 0; 
+\newline 
+i = j / 1;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ /* changed to: */\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ i = j;
+\layout Standard
+
+Note the subexpressions
+\begin_inset LatexCommand \index{Subexpression}
 
--datapointer
-\emph on 
-\emph default 
-so little-endian is the more efficient byte order.
 \end_inset 
 
+ given above are generally introduced by macro expansions or as a result
+ of copy/constant propagation.
+\layout Subsection
 
-\begin_inset LatexCommand \index{little-endian}
+'switch' Statements
+\begin_inset LatexCommand \label{sub:'switch'-Statements}
 
 \end_inset 
 
 
-\begin_inset LatexCommand \index{Endianness}
+\begin_inset LatexCommand \index{switch statement}
 
 \end_inset 
 
- format (i.e.
- lowest order first).
-\layout Subsection
 
-Highest Order Bit
-\begin_inset LatexCommand \index{Highest Order Bit}
+\layout Standard
 
-\end_inset 
+SDCC changes switch statements to jump tables
+\begin_inset LatexCommand \index{jump tables}
 
+\end_inset 
 
-\layout Standard
+ when the following conditions are true.
+\layout Itemize
 
-It is frequently required to obtain the highest order bit of an integral
- type (long, int, short or char types).
- SDCC recognizes the following expression to yield the highest order bit
- and generates optimized code for it, e.g.:
+The case labels are in numerical sequence, the labels need not be in order,
+ and the starting number need not be one or zero.
+\begin_deeper 
 \layout Verse
 
 
 \family typewriter 
-unsigned int gint; 
-\newline 
-
-\newline 
-foo () { 
-\newline 
+switch(i) {\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-unsigned char hob; 
-\newline 
 \SpecialChar ~
 \SpecialChar ~
-...
-\newline 
 \SpecialChar ~
 \SpecialChar ~
-hob = (gint >> 15) & 1; 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+switch (i) { 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-..
+\SpecialChar ~
+case 4: ...\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+case 0: ...
  
 \newline 
-}
-\layout Standard
-
-will generate the following code:
-\layout Verse
-
-
-\family typewriter 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+case 5: ...\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -17958,13 +19266,16 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- 61 ;\SpecialChar ~
- hob.c 7 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+case 1: ...
 \newline 
-000A E5*01\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+case 3: ...\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -17976,7 +19287,6 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- 62\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -17984,14 +19294,21 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- mov\SpecialChar ~
 \SpecialChar ~
- a,(_gint + 1) 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+case 2: ...
 \newline 
-000C 23\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+case 6: ...\SpecialChar ~
+\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -18006,7 +19323,6 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- 63\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -18014,12 +19330,27 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- rl\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- a 
+\SpecialChar ~
+case 3: ...
 \newline 
-000D 54 01\SpecialChar ~
+}\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -18034,7 +19365,6 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- 64\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
@@ -18042,494 +19372,464 @@ will generate the following code:
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
- anl\SpecialChar ~
+}
+\layout Standard
+
+Both the above switch statements will be implemented using a jump-table.
+ The example to the right side is slightly more efficient as the check for
+ the lower boundary of the jump-table is not needed.
+\end_deeper 
+\layout Itemize
+
+The number of case labels is at least three, since it takes two conditional
+ statements to handle the boundary conditions.
+\layout Itemize
+
+The number of case labels is less than 84, since each label takes 3 bytes
+ and a jump-table can be utmost 256 bytes long.
+\layout Standard
+
+Switch statements which have gaps in the numeric sequence or those that
+ have more that 84 case labels can be split into more than one switch statement
+ for efficient code generation, e.g.:
+\layout Verse
+
+
+\family typewriter 
+switch (i) { 
+\newline 
+\SpecialChar ~
 \SpecialChar ~
- a,#0x01 
+case 1: ...
 \newline 
-000F F5*02\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+case 2: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 3: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 4: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 9: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 10: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 11: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
- 65\SpecialChar ~
+case 12: ...
+\newline 
+}
+\layout Standard
+
+If the above switch statement is broken down into two switch statements
+\layout Verse
+
+
+\family typewriter 
+switch (i) { 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 1: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 2: ...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
+case 3: ...
+\newline 
 \SpecialChar ~
- mov\SpecialChar ~
 \SpecialChar ~
- _foo_hob_1_1,a
-\layout Standard
-
-Variations of this case however will 
-\emph on 
-not
-\emph default 
- be recognized.
- It is a standard C expression, so I heartily recommend this be the only
- way to get the highest order bit, (it is portable).
- Of course it will be recognized even if it is embedded in other expressions,
- e.g.:
-\layout Verse
-
-
-\family typewriter 
-xyz = gint + ((gint >> 15) & 1);
-\layout Standard
-
-will still be recognized.
-\layout Subsection
-
-Peephole Optimizer
-\begin_inset LatexCommand \label{sub:Peephole-Optimizer}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{Peephole optimizer}
-
-\end_inset 
-
-
-\layout Standard
-
-The compiler uses a rule based, pattern matching and re-writing mechanism
- for peep-hole optimization.
- It is inspired by 
-\emph on 
-copt
-\emph default 
- a peep-hole optimizer by Christopher W.
- Fraser (cwfraser@microsoft.com).
- A default set of rules are compiled into the compiler, additional rules
- may be added with the 
-\emph on 
--
-\begin_inset ERT
-status Collapsed
-
+case 4: ...
+\newline 
+}
 \layout Standard
 
-\backslash 
-/
-\end_inset 
-
--peep-file
-\begin_inset LatexCommand \index{-\/-peep-file}
-
-\end_inset 
-
- <filename>
-\emph default 
- option.
- The rule language is best illustrated with examples.
+and
 \layout Verse
 
 
 \family typewriter 
-replace { 
+switch (i) { 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-mov %1,a 
+case 9:\SpecialChar ~
+\SpecialChar ~
+...
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-mov a,%1
+case 10:\SpecialChar ~
+...
 \newline 
-} by {
+\SpecialChar ~
+\SpecialChar ~
+case 11:\SpecialChar ~
+...
 \newline 
 \SpecialChar ~
 \SpecialChar ~
-mov %1,a
+case 12:\SpecialChar ~
+...
 \newline 
 }
 \layout Standard
 
-The above rule will change the following assembly
-\begin_inset LatexCommand \index{Assembler routines}
+then both the switch statements will be implemented using jump-tables whereas
+ the unmodified switch statement will not be.
+ You might also consider inserting dummy cases 0 and 5 to 8 in this example.
+\newline 
+The pragma nojtbound
+\begin_inset LatexCommand \index{\#pragma nojtbound}
 
 \end_inset 
 
- sequence:
-\layout Verse
+ can be used to turn off checking the 
+\emph on 
+j
+\emph default 
+ump 
+\emph on 
+t
+\emph default 
+able 
+\emph on 
+bound
+\emph default 
+aries.
+ It has no effect if a default label is supplied.
+ Use of this pragma is dangerous: if the switch argument is not matched
+ by a case statement the processor will happily jump into Nirvana.
+\layout Subsection
+
+Bit-shifting Operations
+\begin_inset LatexCommand \index{Bit shifting}
 
+\end_inset 
 
-\family typewriter 
-mov r1,a 
-\newline 
-mov a,r1
+.
 \layout Standard
 
-to
+Bit shifting is one of the most frequently used operation in embedded programmin
+g.
+ SDCC tries to implement bit-shift operations in the most efficient way
+ possible, e.g.:
 \layout Verse
 
 
 \family typewriter 
-mov r1,a
+unsigned char i;
+\newline 
+...
+\newline 
+i >>= 4; 
+\newline 
+...
 \layout Standard
 
-Note: All occurrences of a 
-\emph on 
-%n
-\emph default 
- (pattern variable) must denote the same string.
- With the above rule, the assembly sequence:
+generates the following code:
 \layout Verse
 
 
 \family typewriter 
-mov r1,a 
+mov\SpecialChar ~
+ a,_i 
 \newline 
-mov a,r2
-\layout Standard
-
-will remain unmodified.
+swap a 
 \newline 
-
+anl\SpecialChar ~
+ a,#0x0f 
 \newline 
-Other special case optimizations may be added by the user (via 
-\emph on 
--
-\begin_inset ERT
-status Collapsed
-
+mov\SpecialChar ~
+ _i,a
 \layout Standard
 
-\backslash 
-/
-\end_inset 
-
--peep-file option
-\emph default 
-).
- E.g.
- some variants of the 8051 MCU allow only 
-\family typewriter 
-ajmp
-\family default 
- and 
-\family typewriter 
-acall
-\family default 
-.
- The following two rules will change all 
-\family typewriter 
-ljmp
-\family default 
- and 
-\family typewriter 
-lcall
-\family default 
- to 
-\family typewriter 
-ajmp
-\family default 
- and 
-\family typewriter 
-acall
+In general SDCC will never setup a loop if the shift count is known.
+ Another example:
 \layout Verse
 
 
 \family typewriter 
-replace { lcall %1 } by { acall %1 } 
+unsigned int i; 
 \newline 
-replace { ljmp %1 } by { ajmp %1 }
-\layout Standard
-
-The 
-\emph on 
-inline-assembler code
-\emph default 
- is also passed through the peep hole optimizer, thus the peephole optimizer
- can also be used as an assembly level macro expander.
- The rules themselves are MCU dependent whereas the rule language infra-structur
-e is MCU independent.
- Peephole optimization rules for other MCU can be easily programmed using
- the rule language.
+...
 \newline 
-
+i >>= 9; 
 \newline 
-The syntax for a rule is as follows:
+...
+\layout Standard
+
+will generate:
 \layout Verse
 
 
 \family typewriter 
-rule := replace [ restart ] '{' <assembly sequence> '
-\backslash 
-n' 
+mov\SpecialChar ~
+\SpecialChar ~
+a,(_i + 1) 
 \newline 
+mov\SpecialChar ~
 \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- '}' by '{' '
-\backslash 
-n' 
+(_i + 1),#0x00 
 \newline 
+clr\SpecialChar ~
 \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- <assembly sequence> '
-\backslash 
-n' 
+c 
 \newline 
+rrc\SpecialChar ~
 \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- '}' [if <functionName> ] '
-\backslash 
-n' 
+a 
+\newline 
+mov\SpecialChar ~
+\SpecialChar ~
+_i,a
+\layout Subsection
+
+Bit-rotation
+\begin_inset LatexCommand \index{Bit rotation}
+
+\end_inset 
+
+
 \layout Standard
 
-<assembly sequence> := assembly instruction (each instruction including
- labels must be on a separate line).
-\newline 
+A special case of the bit-shift operation is bit rotation
+\begin_inset LatexCommand \index{rotating bits}
 
-\newline 
-The optimizer will apply to the rules one by one from the top in the sequence
- of their appearance, it will terminate when all rules are exhausted.
- If the 'restart' option is specified, then the optimizer will start matching
- the rules again from the top, this option for a rule is expensive (performance)
-, it is intended to be used in situations where a transformation will trigger
- the same rule again.
- An example of this (not a good one, it has side effects) is the following
- rule:
+\end_inset 
+
+, SDCC recognizes the following expression to be a left bit-rotation:
 \layout Verse
 
 
 \family typewriter 
-replace restart { 
-\newline 
+\series bold 
+unsigned
+\series default 
 \SpecialChar ~
 \SpecialChar ~
-pop %1 
-\newline 
+char i;\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-push %1 } by { 
-\newline 
 \SpecialChar ~
 \SpecialChar ~
-; nop 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/* unsigned is needed for rotation */ 
 \newline 
-}
-\layout Standard
-
-Note that the replace pattern cannot be a blank, but can be a comment line.
- Without the 'restart' option only the innermost 'pop' 'push' pair would
- be eliminated, i.e.:
-\layout Verse
+...
+\newline 
+i = ((i << 1) | (i >> 7)); 
+\family default 
 
+\newline 
 
 \family typewriter 
-pop ar1 
-\newline 
-pop ar2 
-\newline 
-push ar2 
-\newline 
-push ar1
+...
 \layout Standard
 
-would result in:
+will generate the following code:
 \layout Verse
 
 
 \family typewriter 
-pop ar1 
+mov\SpecialChar ~
+\SpecialChar ~
+a,_i 
 \newline 
-; nop 
+rl\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+a 
 \newline 
-push ar1
+mov\SpecialChar ~
+\SpecialChar ~
+_i,a
 \layout Standard
 
-
-\emph on 
-with
-\emph default 
- the restart option the rule will be applied again to the resulting code
- and then all the pop-push pairs will be eliminated to yield:
+SDCC uses pattern matching on the parse tree to determine this operation.Variatio
+ns of this case will also be recognized as bit-rotation, i.e.: 
 \layout Verse
 
 
 \family typewriter 
-; nop 
-\newline 
-; nop
+i = ((i >> 7) | (i << 1)); /* left-bit rotation */
+\layout Subsection
+
+Nibble and Byte Swapping
 \layout Standard
 
-A conditional function can be attached to a rule.
- Attaching rules are somewhat more involved, let me illustrate this with
- an example.
+Other special cases of the bit-shift operations are nibble or byte swapping
+\begin_inset LatexCommand \index{swapping nibbles/bytes}
+
+\end_inset 
+
+, SDCC recognizes the following expressions:
 \layout Verse
 
 
 \family typewriter 
-replace { 
-\newline 
+\series bold 
+unsigned
+\series default 
 \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
-ljmp %5 
-\newline 
-%2:
-\newline 
-} by { 
+\SpecialChar ~
+char i; 
 \newline 
+
+\series bold 
+unsigned
+\series default 
 \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
-sjmp %5 
+\SpecialChar ~
+int j; 
 \newline 
-%2:
+...
 \newline 
-} if labelInRange
-\layout Standard
+i = ((i << 4) | (i >> 4)); 
+\family default 
 
-The optimizer does a look-up of a function name table defined in function
-\emph on 
-callFuncByName
-\emph default 
- in the source file SDCCpeeph.c, with the name 
-\emph on 
-labelInRange
-\emph default 
-.
- If it finds a corresponding entry the function is called.
- Note there can be no parameters specified for these functions, in this
- case the use of 
-\emph on 
-%5
-\emph default 
- is crucial, since the function 
-\emph on 
-labelInRange
-\emph default 
- expects to find the label in that particular variable (the hash table containin
-g the variable bindings is passed as a parameter).
- If you want to code more such functions, take a close look at the function
- labelInRange and the calling mechanism in source file SDCCpeeph.c.
- Currently implemented are 
-\emph on 
-labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
- 24bitMode, portIsDS390, 24bitModeAndPortDS390 
-\emph default 
-and
+\newline 
+
+\family typewriter 
+j = ((j << 8) | (j >> 8)); 
+\layout Standard
+
+and generates a swap instruction for the nibble swapping
+\begin_inset LatexCommand \index{Nibble swapping}
+
+\end_inset 
+
+ or move instructions for the byte swapping
+\begin_inset LatexCommand \index{Byte swapping}
+
+\end_inset 
+
+.
+ The 
+\begin_inset Quotes sld
+\end_inset 
+
+j
+\begin_inset Quotes srd
+\end_inset 
+
+ example can be used to convert from little to big-endian or vice versa.
+ If you want to change the endianness of a 
 \emph on 
- notVolatile
+signed
 \emph default 
-.
+ integer you have to cast to 
+\family typewriter 
+(unsigned int)
+\family default 
+ first.
 \layout Standard
 
-I know this whole thing is a little kludgey, but maybe some day we will
- have some better means.
- If you are looking at this file, you will see the default rules that are
- compiled into the compiler, you can add your own rules in the default set
- there if you get tired of specifying the -
-\begin_inset ERT
-status Collapsed
+Note that SDCC stores numbers in little-endian
+\begin_inset Foot
+collapsed false
 
 \layout Standard
 
-\backslash 
-/
-\end_inset 
+Usually 8-bit processors don't care much about endianness.
+ This is not the case for the standard 8051 which only has an instruction
+ to increment its 
+\emph on 
+dptr
+\emph default 
 
--peep-file option.
-\layout Section
+\begin_inset LatexCommand \index{DPTR}
 
-ANSI-Compliance
-\begin_inset LatexCommand \index{ANSI-compliance}
+\end_inset 
 
+-datapointer
+\emph on 
+\emph default 
+so little-endian is the more efficient byte order.
 \end_inset 
 
 
-\begin_inset LatexCommand \label{sub:ANSI-Compliance}
+\begin_inset LatexCommand \index{little-endian}
 
 \end_inset 
 
 
-\layout Standard
+\begin_inset LatexCommand \index{Endianness}
 
-Deviations from the compliance:
-\layout Itemize
+\end_inset 
 
-functions are not always reentrant
-\begin_inset LatexCommand \index{reentrant}
+ format (i.e.
+ lowest order first).
+\layout Subsection
+
+Highest Order Bit
+\begin_inset LatexCommand \index{Highest Order Bit}
 
 \end_inset 
 
-.
-\layout Itemize
 
-structures cannot be assigned values directly, cannot be passed as function
- parameters or assigned to each other and cannot be a return value from
- a function, e.g.:
-\begin_deeper 
+\layout Standard
+
+It is frequently required to obtain the highest order bit of an integral
+ type (long, int, short or char types).
+ SDCC recognizes the following expression to yield the highest order bit
+ and generates optimized code for it, e.g.:
 \layout Verse
 
 
 \family typewriter 
-struct s { ...
- }; 
-\newline 
-struct s s1, s2; 
+unsigned int gint; 
 \newline 
-foo() 
+
 \newline 
-{ 
+foo () 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
+unsigned char hob; 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 ...
@@ -18537,505 +19837,801 @@ foo()
 \newline 
 \SpecialChar ~
 \SpecialChar ~
+hob = (gint >> 15) & 1; 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
-s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
+..
 \newline 
+}
+\layout Standard
+
+will generate the following code:
+\layout Verse
+
+
+\family typewriter 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-...
-\newline 
-}
-\newline 
-struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
- */
-\newline 
-{ 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 61 ;\SpecialChar ~
+ hob.c 7 
 \newline 
+000A E5*01\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-struct s rets; 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 62\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1) 
 \newline 
+000C 23\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-...
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 63\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ rl\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ a 
 \newline 
+000D 54 01\SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-return rets;/* is invalid in SDCC although allowed in ANSI */ 
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 64\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ anl\SpecialChar ~
+\SpecialChar ~
+ a,#0x01 
 \newline 
-}
-\end_deeper 
-\layout Itemize
-
-'long long
-\begin_inset LatexCommand \index{long long (not supported)}
+000F F5*02\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 65\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_hob_1_1,a
+\layout Standard
 
-\end_inset 
+Variations of this case however will 
+\emph on 
+not
+\emph default 
+ be recognized.
+ It is a standard C expression, so I heartily recommend this be the only
+ way to get the highest order bit, (it is portable).
+ Of course it will be recognized even if it is embedded in other expressions,
+ e.g.:
+\layout Verse
 
-' (64 bit integers
-\begin_inset LatexCommand \index{int (64 bit) (not supported)}
 
-\end_inset 
+\family typewriter 
+xyz = gint + ((gint >> 15) & 1);
+\layout Standard
 
-) not supported.
-\layout Itemize
+will still be recognized.
+\layout Subsection
 
-'double
-\begin_inset LatexCommand \index{double (not supported)}
+Peephole Optimizer
+\begin_inset LatexCommand \label{sub:Peephole-Optimizer}
 
 \end_inset 
 
-' precision floating point 
-\begin_inset LatexCommand \index{Floating point support}
+
+\begin_inset LatexCommand \index{Peephole optimizer}
 
 \end_inset 
 
-not supported.
-\layout Itemize
 
-No support for setjmp
-\begin_inset LatexCommand \index{setjmp (not supported)}
+\layout Standard
 
-\end_inset 
+The compiler uses a rule based, pattern matching and re-writing mechanism
+ for peep-hole optimization.
+ It is inspired by 
+\emph on 
+copt
+\emph default 
+ a peep-hole optimizer by Christopher W.
+ Fraser (cwfraser@microsoft.com).
+ A default set of rules are compiled into the compiler, additional rules
+ may be added with the 
+\emph on 
+-
+\begin_inset ERT
+status Collapsed
 
- and longjmp
-\begin_inset LatexCommand \index{longjmp (not supported)}
+\layout Standard
 
+\backslash 
+/
 \end_inset 
 
- (for now).
-\layout Itemize
-
-Old K&R style
-\begin_inset LatexCommand \index{K\&R style}
+-peep-file
+\begin_inset LatexCommand \index{-\/-peep-file}
 
 \end_inset 
 
- function declarations are NOT allowed.
-\begin_deeper 
+ <filename>
+\emph default 
+ option.
+ The rule language is best illustrated with examples.
 \layout Verse
 
 
 \family typewriter 
-foo(i,j) /* this old style of function declarations */ 
-\newline 
-int i,j; /* are valid in ANSI but not valid in SDCC */ 
+replace { 
 \newline 
-{ 
+\SpecialChar ~
+\SpecialChar ~
+mov %1,a 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
+mov a,%1
+\newline 
+} by {
+\newline 
 \SpecialChar ~
 \SpecialChar ~
-...
+mov %1,a
 \newline 
 }
-\end_deeper 
-\layout Itemize
-
-functions declared as pointers
-\begin_inset LatexCommand \index{Pointer (to function)}
-
-\end_inset 
-
+\layout Standard
 
-\begin_inset LatexCommand \index{function pointers}
+The above rule will change the following assembly
+\begin_inset LatexCommand \index{Assembler routines}
 
 \end_inset 
 
- must be dereferenced during the call.
-\begin_deeper 
+ sequence:
 \layout Verse
 
 
 \family typewriter 
-int (*foo)();
-\newline 
-...
-\newline 
-/* has to be called like this */ 
+mov r1,a 
 \newline 
-(*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
-\end_deeper 
-\layout Section
-
-Cyclomatic Complexity
-\begin_inset LatexCommand \index{Cyclomatic complexity}
+mov a,r1
+\layout Standard
 
-\end_inset 
+to
+\layout Verse
 
 
+\family typewriter 
+mov r1,a
 \layout Standard
 
-Cyclomatic complexity of a function is defined as the number of independent
- paths the program can take during execution of the function.
- This is an important number since it defines the number test cases you
- have to generate to validate the function.
- The accepted industry standard for complexity number is 10, if the cyclomatic
- complexity reported by SDCC exceeds 10 you should think about simplification
- of the function logic.
- Note that the complexity level is not related to the number of lines of
- code in a function.
- Large functions can have low complexity, and small functions can have large
- complexity levels.
-\newline 
+Note: All occurrences of a 
+\emph on 
+%n
+\emph default 
+ (pattern variable) must denote the same string.
+ With the above rule, the assembly sequence:
+\layout Verse
 
-\newline 
-SDCC uses the following formula to compute the complexity:
-\newline 
 
+\family typewriter 
+mov r1,a 
+\newline 
+mov a,r2
 \layout Standard
 
-complexity = (number of edges in control flow graph) - (number of nodes
- in control flow graph) + 2;
+will remain unmodified.
 \newline 
 
 \newline 
-Having said that the industry standard is 10, you should be aware that in
- some cases it be may unavoidable to have a complexity level of less than
- 10.
- For example if you have switch statement with more than 10 case labels,
- each case label adds one to the complexity level.
- The complexity level is by no means an absolute measure of the algorithmic
- complexity of the function, it does however provide a good starting point
- for which functions you might look at for further optimization.
-\layout Section
-
-Notes on supported Processors
-\layout Subsection
-
-MCS51 variants
-\begin_inset LatexCommand \label{sub:MCS51-variants}
-
-\end_inset 
-
-
-\begin_inset LatexCommand \index{MCS51 variants}
-
-\end_inset 
-
-
-\layout Standard
-
-MCS51 processors are available from many vendors and come in many different
- flavours.
- While they might differ considerably in respect to Special Function Registers
- the core MCS51 is usually not modified or is kept compatible.
-\layout Subsubsection*
+Other special case optimizations may be added by the user (via 
+\emph on 
+-
+\begin_inset ERT
+status Collapsed
 
-pdata access by SFR 
 \layout Standard
 
-With the upcome of devices with internal xdata and flash memory devices
- using port P2
-\begin_inset LatexCommand \index{P2 (mcs51 sfr)}
-
-\end_inset 
-
- as dedicated I/O port is becoming more popular.
- Switching the high byte for pdata
-\begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
-
-\end_inset 
-
- access which was formerly done by port P2 is then achieved by a Special
- Function Register
-\begin_inset LatexCommand \index{sfr}
-
+\backslash 
+/
 \end_inset 
 
-.
- In well-established MCS51 tradition the address of this 
-\emph on 
-sfr
+-peep-file option
 \emph default 
- is where the chip designers decided to put it.
- Needless to say that they didn't agree on a common name either.
- As pdata addressing is used in the startup code for the initialization
- of xdata variables a separate startup code should be used as described
- in section 
-\begin_inset LatexCommand \ref{sub:Startup-Code}
-
-\end_inset 
-
+).
+ E.g.
+ some variants of the 8051 MCU allow only 
+\family typewriter 
+ajmp
+\family default 
+ and 
+\family typewriter 
+acall
+\family default 
 .
-\layout Subsubsection*
-
-Other Features available by SFR
-\layout Standard
-
-Some MCS51 variants offer features like Double DPTR
-\begin_inset LatexCommand \index{DPTR}
-
-\end_inset 
-
-, multiple DPTR, decrementing DPTR, 16x16 Multiply.
- These are currently not used for the MCS51 port.
- If you absolutely need them you can fall back to inline assembly or submit
- a patch to SDCC.
-\layout Subsection
+ The following two rules will change all 
+\family typewriter 
+ljmp
+\family default 
+ and 
+\family typewriter 
+lcall
+\family default 
+ to 
+\family typewriter 
+ajmp
+\family default 
+ and 
+\family typewriter 
+acall
+\layout Verse
 
-The Z80 and gbz80 port
+
+\family typewriter 
+replace { lcall %1 } by { acall %1 } 
+\newline 
+replace { ljmp %1 } by { ajmp %1 }
 \layout Standard
 
-SDCC can target both the Zilog 
-\begin_inset LatexCommand \index{Z80}
+The 
+\emph on 
+inline-assembler code
+\emph default 
+ is also passed through the peep hole optimizer, thus the peephole optimizer
+ can also be used as an assembly level macro expander.
+ The rules themselves are MCU dependent whereas the rule language infra-structur
+e is MCU independent.
+ Peephole optimization rules for other MCU can be easily programmed using
+ the rule language.
+\newline 
 
-\end_inset 
+\newline 
+The syntax for a rule is as follows:
+\layout Verse
 
- and the Nintendo Gameboy's Z80-like gbz80
-\begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
 
-\end_inset 
+\family typewriter 
+rule := replace [ restart ] '{' <assembly sequence> '
+\backslash 
+n' 
+\newline 
+\SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ '}' by '{' '
+\backslash 
+n' 
+\newline 
+\SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ <assembly sequence> '
+\backslash 
+n' 
+\newline 
+\SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ '}' [if <functionName> ] '
+\backslash 
+n' 
+\layout Standard
 
-.
- The Z80 port is passed through the same 
-\emph on 
-regressions tests
-\begin_inset LatexCommand \index{Regression test}
+<assembly sequence> := assembly instruction (each instruction including
+ labels must be on a separate line).
+\newline 
 
-\end_inset 
+\newline 
+The optimizer will apply to the rules one by one from the top in the sequence
+ of their appearance, it will terminate when all rules are exhausted.
+ If the 'restart' option is specified, then the optimizer will start matching
+ the rules again from the top, this option for a rule is expensive (performance)
+, it is intended to be used in situations where a transformation will trigger
+ the same rule again.
+ An example of this (not a good one, it has side effects) is the following
+ rule:
+\layout Verse
 
 
-\emph default 
- as the MCS51 and DS390 ports, so floating point support, support for long
- variables and bitfield support is fine.
- See mailing lists and forums about interrupt routines.
+\family typewriter 
+replace restart { 
+\newline 
+\SpecialChar ~
+\SpecialChar ~
+pop %1 
+\newline 
+\SpecialChar ~
+\SpecialChar ~
+push %1 } by { 
+\newline 
+\SpecialChar ~
+\SpecialChar ~
+; nop 
+\newline 
+}
 \layout Standard
 
-As always, the code is the authoritative reference - see z80/ralloc.c and
- z80/gen.c.
- The stack
-\begin_inset LatexCommand \index{stack}
+Note that the replace pattern cannot be a blank, but can be a comment line.
+ Without the 'restart' option only the innermost 'pop' 'push' pair would
+ be eliminated, i.e.:
+\layout Verse
 
-\end_inset 
 
- frame is similar to that generated by the IAR Z80 compiler.
- IX is used as the base pointer, HL is used as a temporary register, and
- BC and DE are available for holding variables.
- IY is currently unused.
- Return values
-\begin_inset LatexCommand \index{return value}
+\family typewriter 
+pop ar1 
+\newline 
+pop ar2 
+\newline 
+push ar2 
+\newline 
+push ar1
+\layout Standard
 
-\end_inset 
+would result in:
+\layout Verse
 
- are stored in HL.
- One bad side effect of using IX as the base pointer is that a functions
- stack frame is limited to 127 bytes - this will be fixed in a later version.
-\layout Subsection
 
-The HC08 port
+\family typewriter 
+pop ar1 
+\newline 
+; nop 
+\newline 
+push ar1
 \layout Standard
 
-The port to the Motorola HC08
-\begin_inset LatexCommand \index{HC08}
-
-\end_inset 
 
- family has been added in October 2003, thank you Erik!
-\layout Subsection
+\emph on 
+with
+\emph default 
+ the restart option the rule will be applied again to the resulting code
+ and then all the pop-push pairs will be eliminated to yield:
+\layout Verse
 
-The PIC14 port
-\layout Standard
 
-The 14bit PIC port still requires a major effort from the development community.
- However it can work for very simple code.
+\family typewriter 
+; nop 
 \newline 
+; nop
+\layout Standard
 
-\newline 
+A conditional function can be attached to a rule.
+ Attaching rules are somewhat more involved, let me illustrate this with
+ an example.
+\layout Verse
 
-\bar under 
-C code and 14bit PIC code page and RAM banks
-\bar default 
 
+\family typewriter 
+replace { 
 \newline 
-The linker organizes allocation for the code page and RAM banks.
- It does not have intimate knowledge of the code flow.
- It will put all the code section of a single asm file into a single code
- page.
- In order to make use of multiple code pages, separate asm files must be
- used.
- The compiler treats all functions of a single C file as being in the same
- code page unless it is non static.
- The compiler treats all local variables of a single C file as being in
- the same RAM bank unless it is an extern.
+\SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+ljmp %5 
 \newline 
-
+%2:
 \newline 
-To get the best follow these guide lines:
-\layout Enumerate
-
-make local functions static, as non static functions require code page selection
- overhead.
-\layout Enumerate
+} by { 
+\newline 
+\SpecialChar ~
+ \SpecialChar ~
+ \SpecialChar ~
+sjmp %5 
+\newline 
+%2:
+\newline 
+} if labelInRange
+\layout Standard
 
-Make local variables static as extern variables require RAM bank selection
- overhead.
-\layout Enumerate
+The optimizer does a look-up of a function name table defined in function
+\emph on 
+callFuncByName
+\emph default 
+ in the source file SDCCpeeph.c, with the name 
+\emph on 
+labelInRange
+\emph default 
+.
+ If it finds a corresponding entry the function is called.
+ Note there can be no parameters specified for these functions, in this
+ case the use of 
+\emph on 
+%5
+\emph default 
+ is crucial, since the function 
+\emph on 
+labelInRange
+\emph default 
+ expects to find the label in that particular variable (the hash table containin
+g the variable bindings is passed as a parameter).
+ If you want to code more such functions, take a close look at the function
+ labelInRange and the calling mechanism in source file SDCCpeeph.c.
+ Currently implemented are 
+\emph on 
+labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
+ 24bitMode, portIsDS390, 24bitModeAndPortDS390 
+\emph default 
+and
+\emph on 
+ notVolatile
+\emph default 
+.
+\layout Standard
+
+I know this whole thing is a little kludgey, but maybe some day we will
+ have some better means.
+ If you are looking at this file, you will see the default rules that are
+ compiled into the compiler, you can add your own rules in the default set
+ there if you get tired of specifying the -
+\begin_inset ERT
+status Collapsed
 
-For devices that have multiple code pages it is more efficient to use the
- same number of files as pages, i.e.
- for the 16F877 use 4 separate files and i.e.
- for the 16F874 use 2 separate files.
- This way the linker can put the code for each file into different code
- pages and the compiler can allocate reusable variables more efficiently
- and there's less page selection overhead.
- And as for any 8 bit micro (especially for PIC 14 as they have a very simple
- instruction set) use 'unsigned char' whereever possible instead of 'int'.
 \layout Standard
 
+\backslash 
+/
+\end_inset 
 
-\bar under 
-Creating a device include file 
-\bar default 
+-peep-file option.
+\layout Section
 
-\newline 
-For generating a device include file use the support pearl script inc2h.pl
- kept in directory support/script.
-\newline 
+ANSI-Compliance
+\begin_inset LatexCommand \index{ANSI-compliance}
 
-\newline 
+\end_inset 
 
-\bar under 
-Interrupt code
-\bar default 
 
-\newline 
-For the interrupt function, use the keyword 'interrupt' with level number
- of 0 (PIC14 only has 1 interrupt so this number is only there to avoid
- a syntax error - it ought to be fixed).
- E.g.:
-\layout Verse
+\begin_inset LatexCommand \label{sub:ANSI-Compliance}
+
+\end_inset 
 
 
-\family typewriter 
-void Intr(void) interrupt 0
-\newline 
-{
-\newline 
-\SpecialChar ~
-\SpecialChar ~
-T0IF = 0; /* Clear timer interrupt */
-\newline 
-}
 \layout Standard
 
+Deviations from the compliance:
+\layout Itemize
 
-\bar under 
-Linking and assembling
-\bar default 
+functions are not always reentrant
+\begin_inset LatexCommand \index{reentrant}
 
-\newline 
-For assembling you can use either GPUTILS' gpasm.exe or MPLAB's mpasmwin.exe.
- For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
- If you use MPLAB and an interrupt function then the linker script file
- vectors section will need to be enlarged to link with mplink.
-\newline 
+\end_inset 
 
-\newline 
-Here is a makefile using GPUTILS:
+.
+\layout Itemize
+
+structures cannot be assigned values directly, cannot be passed as function
+ parameters or assigned to each other and cannot be a return value from
+ a function, e.g.:
+\begin_deeper 
 \layout Verse
 
 
 \family typewriter 
-.c.o:
+struct s { ...
+ }; 
+\newline 
+struct s s1, s2; 
+\newline 
+foo() 
+\newline 
+{ 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-sdcc -S -V -mpic14 -p16F877 $< 
+s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+...
+\newline 
+}
+\newline 
+struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
+ */
+\newline 
+{ 
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-gpasm -c $*.asm
-\newline 
-
-\newline 
-$(PRJ).hex: $(OBJS) 
+struct s rets; 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
+...
+\newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
-\layout Standard
+return rets;/* is invalid in SDCC although allowed in ANSI */ 
+\newline 
+}
+\end_deeper 
+\layout Itemize
+
+'long long
+\begin_inset LatexCommand \index{long long (not supported)}
+
+\end_inset 
+
+' (64 bit integers
+\begin_inset LatexCommand \index{int (64 bit) (not supported)}
+
+\end_inset 
+
+) not supported.
+\layout Itemize
+
+'double
+\begin_inset LatexCommand \index{double (not supported)}
 
-Here is a makefile using MPLAB:
+\end_inset 
+
+' precision floating point 
+\begin_inset LatexCommand \index{Floating point support}
+
+\end_inset 
+
+not supported.
+\layout Itemize
+
+No support for setjmp
+\begin_inset LatexCommand \index{setjmp (not supported)}
+
+\end_inset 
+
+ and longjmp
+\begin_inset LatexCommand \index{longjmp (not supported)}
+
+\end_inset 
+
+ (for now).
+\layout Itemize
+
+Old K&R style
+\begin_inset LatexCommand \index{K\&R style}
+
+\end_inset 
+
+ function declarations are NOT allowed.
+\begin_deeper 
 \layout Verse
 
 
 \family typewriter 
-.c.o: 
+foo(i,j) /* this old style of function declarations */ 
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-sdcc -S -V -mpic14 -p16F877 $< 
+int i,j; /* are valid in ANSI but not valid in SDCC */ 
+\newline 
+{ 
 \newline 
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
 \SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-mpasmwin /q /o $*.asm
+...
+\newline 
+}
+\end_deeper 
+\layout Itemize
+
+functions declared as pointers
+\begin_inset LatexCommand \index{Pointer (to function)}
+
+\end_inset 
+
+
+\begin_inset LatexCommand \index{function pointers}
+
+\end_inset 
+
+ must be dereferenced during the call.
+\begin_deeper 
+\layout Verse
+
+
+\family typewriter 
+int (*foo)();
+\newline 
+...
+\newline 
+/* has to be called like this */ 
+\newline 
+(*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
+\end_deeper 
+\layout Section
+
+Cyclomatic Complexity
+\begin_inset LatexCommand \index{Cyclomatic complexity}
+
+\end_inset 
+
+
+\layout Standard
+
+Cyclomatic complexity of a function is defined as the number of independent
+ paths the program can take during execution of the function.
+ This is an important number since it defines the number test cases you
+ have to generate to validate the function.
+ The accepted industry standard for complexity number is 10, if the cyclomatic
+ complexity reported by SDCC exceeds 10 you should think about simplification
+ of the function logic.
+ Note that the complexity level is not related to the number of lines of
+ code in a function.
+ Large functions can have low complexity, and small functions can have large
+ complexity levels.
 \newline 
 
 \newline 
-$(PRJ).hex: $(OBJS) 
+SDCC uses the following formula to compute the complexity:
 \newline 
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
-\layout Subsection
 
-The PIC16 port
 \layout Standard
 
-You'll find some additional notes about this port in the file src/pic16/NOTES.
+complexity = (number of edges in control flow graph) - (number of nodes
+ in control flow graph) + 2;
+\newline 
+
+\newline 
+Having said that the industry standard is 10, you should be aware that in
+ some cases it be may unavoidable to have a complexity level of less than
+ 10.
+ For example if you have switch statement with more than 10 case labels,
+ each case label adds one to the complexity level.
+ The complexity level is by no means an absolute measure of the algorithmic
+ complexity of the function, it does however provide a good starting point
+ for which functions you might look at for further optimization.
 \layout Section
 
 Retargetting for other Processors