Two resp.
three consecutive dashes simply result in a long resp.
extra long dash.
+\layout Comment
+
+This document would need some rework: The Installation section is much to
+
+\layout Comment
+
+intimidating (as is the section about sdcdb).
+\layout Comment
+
+Architecture specific stuff (like memory models, code examples) should maybe
+ go
+\layout Comment
+
+into seperate sections/chapters/appendices (it is hard to document PIC or
+ Z80 in
+\layout Comment
+
+a 8051 centered document)
\layout Title
SDCC Compiler User Guide
-\layout Standard
-\align center
-2003-06-02
\layout Comment
The strings enclosed in $ are automatically updated by cvs:
\layout Standard
\align center
-\size scriptsize
-cvs: $Revision$ $Date$
+\size footnotesize
+$Date$
+\layout Standard
+\align center
+
+\size footnotesize
+$Revision$
\layout Standard
\end_inset
, etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
- It can be retargetted for other microprocessors, support for PIC, AVR and
- 186 is under development.
+ It can be retargetted for other microprocessors, support for PIC, AVR is
+ under development.
The entire source code for the compiler is distributed under GPL.
SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
SDCC has extensive language extensions suitable for utilizing various microcont
dead code elimination
\layout Itemize
-jumptables for
+jump tables for
\emph on
switch
\emph default
\newline
The latest version can be downloaded from
-\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
+\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
\end_inset
(8 bits) which is not ANSI compliant
\layout Itemize
-the default directory for gcc-builds where include, library and documention
+the default directory for gcc-builds where include, library and documentation
files are stored is now in /usr/local/share
\layout Itemize
their own documentation and can be found in the source distribution.
If you want the latest unreleased software, the complete source package
is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
-\layout Comment
-
-ANSI C reference / related tools / recommended reading / compiler building:
- Muchnik?
\layout Subsection
Wishes for the future
The install paths, search paths and other options are defined when running
'configure'.
- The defaults can be overriden by:
+ The defaults can be overridden by:
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--prefix see tabel below
+-prefix see table below
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--exec_prefix see tabel below
+-exec_prefix see table below
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--bindir see tabel below
+-bindir see table below
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--datadir see tabel below
+-datadir see table below
\layout List
\labelwidthstring 00.00.0000
-docdir environment variable, see tabel below
+docdir environment variable, see table below
\layout List
\labelwidthstring 00.00.0000
-include_dir_suffix environment variable, see tabel below
+include_dir_suffix environment variable, see table below
\layout List
\labelwidthstring 00.00.0000
-lib_dir_suffix environment variable, see tabel below
+lib_dir_suffix environment variable, see table below
\layout List
\labelwidthstring 00.00.0000
These defaults are:
\newline
-\newline
+\layout Standard
+\align center
\begin_inset Tabular
<lyxtabular version="3" rows="8" columns="3">
\newline
-\newline
-
-\newline
+\layout Standard
+\noindent
'configure' also computes relative paths.
This is needed for full relocatability of a binary package and to complete
search paths (see section search paths below):
\newline
-\newline
+\layout Standard
+\align center
\begin_inset Tabular
<lyxtabular version="3" rows="4" columns="3">
\newline
-\newline
+\layout Standard
+\noindent
Examples:
\layout LyX-Code
./configure
-\layout LyX-Code
+\newline
+./configure -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
-./configure --prefix=
+-prefix=
\begin_inset Quotes srd
\end_inset
\begin_inset Quotes srd
\end_inset
- --datadir=
+ -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-datadir=
\begin_inset Quotes srd
\end_inset
\end_inset
-\layout LyX-Code
+\newline
+./configure -
+\begin_inset ERT
+status Collapsed
-./configure --disable-avr-port --disable-xa51-port
\layout Standard
-To crosscompile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw3
-2'):
-\layout LyX-Code
+\backslash
+/
+\end_inset
+
+-disable-avr-port -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
-./configure
\backslash
+/
+\end_inset
+
+-disable-xa51-port
+\layout Standard
+To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
+32'):
\layout LyX-Code
- CC=
+./configure
+\backslash
+
+\newline
+CC=
\begin_inset Quotes srd
\end_inset
\backslash
-
-\layout LyX-Code
-
- RANLIB=
+
+\newline
+RANLIB=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- STRIP=
+\newline
+STRIP=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
- --prefix=
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-prefix=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
- --datadir=
+-datadir=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- docdir=
+\newline
+docdir=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- include_dir_suffix=
+\newline
+include_dir_suffix=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- lib_dir_suffix=
+\newline
+lib_dir_suffix=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- sdccconf_h_dir_separator=
+\newline
+sdccconf_h_dir_separator=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
- --disable-device-lib-build
\backslash
+/
+\end_inset
-\layout LyX-Code
+-disable-device-lib-build
+\backslash
- --disable-ucsim
+\newline
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-disable-ucsim
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
- --host=i586-mingw32msvc --build=unknown-unknown-linux-gnu
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-host=i586-mingw32msvc -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-build=unknown-unknown-linux-gnu
\layout Standard
To
./configure -C
\backslash
-\layout LyX-Code
-
- CFLAGS=
+\newline
+CFLAGS=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- LDFLAGS=
+\newline
+LDFLAGS=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
- --prefix=
+-prefix=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
- --datadir=
+-datadir=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- docdir=
+\newline
+docdir=
\begin_inset Quotes srd
\end_inset
\backslash
-
-\layout LyX-Code
-
- include_dir_suffix=
+
+\newline
+include_dir_suffix=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- lib_dir_suffix=
+\newline
+lib_dir_suffix=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
-
- sdccconf_h_dir_separator=
+\newline
+sdccconf_h_dir_separator=
\begin_inset Quotes srd
\end_inset
\backslash
-\layout LyX-Code
+\newline
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
- --disable-ucsim
+\backslash
+/
+\end_inset
+
+-disable-ucsim
\layout Standard
'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
\layout Standard
-
-1.
- Binary files (preprocessor, assembler and linker)
-\layout Standard
-
+\added_space_top medskip \align center
\begin_inset Tabular
-<lyxtabular version="3" rows="2" columns="3">
+<lyxtabular version="3" rows="5" columns="4">
<features>
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="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
+
+\series bold
+Description
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold
Path
\end_inset
</cell>
\layout Standard
-default
+
+\series bold
+Default
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\layout Standard
+
+\series bold
Win32 builds
\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
+
+Binary files*
+\end_inset
+</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\end_inset
</cell>
</row>
-</lyxtabular>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+Include files
\end_inset
-
-
-\newline
-
-\newline
-2.
- Include files
-\layout Standard
-
-
-\begin_inset Tabular
-<lyxtabular version="3" rows="2" columns="3">
-<features>
-<column alignment="block" valignment="top" leftline="true" width="1.6in">
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" 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
-
-Path
-\end_inset
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
-
-\layout Standard
-
-default
-\end_inset
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
-
-\layout Standard
-
-Win32 builds
-\end_inset
-</cell>
-</row>
-<row topline="true" bottomline="true">
-<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
\layout Standard
\emph on
-$DATADIR/
-\newline
-$INCLUDE_DIR_SUFFIX
+$DATADIR/ $INCLUDE_DIR_SUFFIX
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\end_inset
</cell>
</row>
-</lyxtabular>
-
-\end_inset
-
-
-\newline
-
-\newline
-3.
- Library files (the
-\shape italic
-model
-\shape default
- is auto-appended by the compiler, e.g.
- small, large, z80, ds390 etc.)
-\layout Standard
-
-
-\begin_inset Tabular
-<lyxtabular version="3" rows="2" columns="3">
-<features>
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" 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
-
-Path
-\end_inset
-</cell>
+<row topline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
-default
-\end_inset
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
-
-\layout Standard
-
-Win32 builds
+Library file**
\end_inset
</cell>
-</row>
-<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\end_inset
</cell>
</row>
-</lyxtabular>
-
-\end_inset
-
-
-\newline
-
-\newline
-4.
- Documentation
-\layout Standard
-
-
-\begin_inset Tabular
-<lyxtabular version="3" rows="2" columns="3">
-<features>
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" 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
-Path
-\end_inset
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
-
-\layout Standard
-
-default
-\end_inset
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
-
-\layout Standard
-
-Win32 builds
+Documentation
\end_inset
</cell>
-</row>
-<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\end_inset
-\newline
+\layout Verse
+
+\size footnotesize
+*compiler, preprocessor, assembler, and linker
\newline
+**the
+\shape italic
+model
+\shape default
+ is auto-appended by the compiler, e.g.
+ small, large, z80, ds390 etc
+\layout Standard
+\noindent
The install paths can still be changed during `make install` with e.g.:
\layout LyX-Code
1.
Binary files (preprocessor, assembler and linker)
\newline
-
+
+\layout Standard
+\align center
+
\begin_inset Tabular
<lyxtabular version="3" rows="4" columns="3">
<features>
\newline
-\newline
+\layout Standard
+\noindent
2.
Include files
\newline
-
+
+\layout Standard
+\align center
+
\begin_inset Tabular
<lyxtabular version="3" rows="6" columns="3">
<features>
\newline
-\newline
- The option -
+\layout Standard
+\noindent
+The option -
\begin_inset ERT
status Collapsed
3.
Library files
\newline
+
+\layout Standard
+
With the exception of
\begin_inset Quotes sld
\end_inset
\newline
+\layout Standard
+\align center
+
\begin_inset Tabular
<lyxtabular version="3" rows="6" columns="3">
<features>
\end_inset
+\newline
+
\layout Comment
Don't delete any of the stray spaces in the table above without checking
./configure CC=gcc2 CXX=g++2
\layout Subsubsection
-Crosscompiling SDCC on Linux for Windows
+Cross compiling SDCC on Linux for Windows
\layout Standard
-With the Mingw32 gcc crosscompiler it's easy to compile SDCC for Win32.
+With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
See section 'Configure Options'.
\layout Subsubsection
Replace in your cygwin.bat the line
\layout LyX-Code
-bash --login -i
+bash -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-login -i
\layout Standard
with (one line):
rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
\layout LyX-Code
- -bg black -fg white -geometry 100x65 -e bash --login
+ -bg black -fg white -geometry 100x65 -e bash -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-login
\layout Standard
Text selected with the mouse is automatically copied to the clipboard, pasting
Make sure not to commit files with windows line endings.
\layout Subsubsection
-Windows Install Using Microsoft Visual C++ 6.0/NET
+Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
\layout Standard
\series default
SDCC is distributed with all the projects, workspaces, and files you need
- to build it using Visual C++ 6.0/NET.
+ to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
+ doesn't build under MSVC).
The workspace name is 'sdcc.dsw'.
Please note that as it is now, all the executables are created in a folder
called sdcc
\backslash
bin_vc to sdcc
\backslash
-bin before runnng SDCC.
+bin before running SDCC.
\newline
\newline
-In order to build SDCC with Visual C++ 6.0/NET you need win32 executables
- of bison.exe, flex.exe, and gawk.exe.
+In order to build SDCC with MSVC you need win32 executables of bison.exe,
+ flex.exe, and gawk.exe.
One good place to get them is
\begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
\end_inset
.zip.
- Now you have to install the utilities and setup Visual C++ so it can locate
- the required programs.
+ Now you have to install the utilities and setup MSVC so it can locate the
+ required programs.
Here there are two alternatives (choose one!):
\layout Enumerate
bin, and you can compile using sdcc.
\layout Subsubsection
-Windows Install Using Borland
+Building SDCC Using Borland
\layout Enumerate
From the sdcc directory, run the command "make -f Makefile.bcc".
sdcdb.exe (which currently doesn't build under Borland C++).
\layout Enumerate
-If you modify any source files and need to rebuild, be aware that the dependanci
+If you modify any source files and need to rebuild, be aware that the dependenci
es may not be correctly calculated.
The safest option is to delete all .obj files and run the build again.
- From a Cygwin BASH prompt, this can easily be done with the commmand:
+ From a Cygwin BASH prompt, this can easily be done with the command:
\newline
\newline
\newline
\newline
-or on Windows NT/2000/XP from the command prompt with the commmand:
+or on Windows NT/2000/XP from the command prompt with the command:
\newline
\family sans
Make sure the compiler works on a very simple example.
Type in the following test.c program using your favorite
\series default
-ascii
+ASCII
\series medium
editor:
-\series default
+\layout Verse
-\newline
\family typewriter
-
-\newline
char test;
\newline
test=0;
\newline
}
-\family default
-
-\newline
-
-\emph on
+\layout Standard
-\newline
\series medium
-\emph default
Compile this using the following command:
\family sans
\series bold
\series medium
header files and libraries.
Edit test.c and change it to the following:
-\series default
+\layout Verse
-\newline
-
-\newline
\family typewriter
#include <string.h>
strcpy(str1, "testing");
\newline
}
-\newline
+\layout Standard
-\newline
-\family default
\series medium
Compile this by typing
\family sans
\series medium
(see the Install trouble-shooting section for suggestions).
+
+\series default
+ Use option
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-print-search-dirs
+\series default
+
+\begin_inset LatexCommand \index{-\/-print-search-dirs}
+
+\end_inset
+
+ to find exactly where SDCC is looking for the include and lib files.
\layout Subsection
Install Trouble-shooting
.
\newline
-On most systems you will need super-user privilages to do this.
+On most systems you will need super-user privileges to do this.
\layout Subsection
Components of SDCC
).
The simulator is built as part of the build process.
- For more information visit Daniel's website at:
+ For more information visit Daniel's web site at:
\begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
\end_inset
.
- It currently support the core mcs51, the Dallas DS80C390 and the Philips
+ It currently support the core mcs51, the Dallas DS80C390 and the Phillips
XA51 family.
\layout Subsubsection
\layout Standard
Sdcdb is the companion source level debugger.
- The current version of the debugger uses Daniel's Simulator S51, but can
- be easily changed to use other simulators.
+ The current version of the debugger uses Daniel's Simulator S51
+\begin_inset LatexCommand \index{s51}
+
+\end_inset
+
+, but can be easily changed to use other simulators.
\layout Section
\pagebreak_top
Using SDCC
\noun default
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}
+
+\end_inset
+
+.
+ You can view this file to troubleshoot linking problems such as those arising
+ from missing libraries.
\layout Subsubsection
Projects with Additional Libraries
\newline
\newline
-The most efficient way to use libraries is to keep seperate modules in seperate
+The most efficient way to use libraries is to keep separate modules in separate
source files.
- The lib file now should name all the modules.rel files.
+ The lib file now should name all the modules.rel
+\begin_inset LatexCommand \index{rel}
+
+\end_inset
+
+ files.
For an example see the standard library file
\emph on
libsdcc.lib
processor (In development, not complete).
AVR users should probably have a look at avr-gcc
-\begin_inset LatexCommand \url[FIXME: official URL?]{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
+\begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
\end_inset
\end_inset
--bit processors (In development, not complete).
+-bit processors (Microchip p16f84 and variants).
\layout Comment
p16f627 p16f628 p16f84 p16f873 p16f877?
\labelwidthstring 00.00.0000
+\series bold
+-mpic16
+\begin_inset LatexCommand \index{-mpic16}
+
+\end_inset
+
+
+\series default
+ Generate code for the PIC 16
+\begin_inset LatexCommand \index{PIC16}
+
+\end_inset
+
+-bit processors (Microchip p18f452 and variants).
+\layout List
+\labelwidthstring 00.00.0000
+
+
\series bold
-mtlcs900h
\series default
\series default
- Generate code for the Philips XA51
+ Generate code for the Phillips XA51
\begin_inset LatexCommand \index{XA51}
\end_inset
).
\layout Subsubsection
-Optimization Options
-\begin_inset LatexCommand \index{Options optimization}
+Z80 Options
+\begin_inset LatexCommand \index{Options Z80}
\end_inset
-\begin_inset LatexCommand \index{Optimization options}
+\begin_inset LatexCommand \index{Z80 options}
\end_inset
/
\end_inset
--nogcse
-\begin_inset LatexCommand \index{-\/-nogcse}
-
-\end_inset
-
-
+-callee-saves-bc
\series default
- Will not do global subexpression elimination, this option may be used when
- the compiler creates undesirably large stack/data spaces to store compiler
- temporaries.
- A warning message will be generated when this happens and the compiler
- will indicate the number of extra bytes it allocated.
- It recommended that this option NOT be used, #pragma\SpecialChar ~
-NOGCSE
-\begin_inset LatexCommand \index{\#pragma NOGCSE}
+
+\begin_inset LatexCommand \index{-\/-callee-saves-bc}
\end_inset
- can be used to turn off global subexpression elimination
-\begin_inset LatexCommand \index{Subexpression elimination}
+
+\size large
+\emph on
+
+\size default
+\emph default
+Force a called function to always save BC.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-no-std-crt0
+\series default
+
+\begin_inset LatexCommand \index{-\/-no-std-crt0}
+
+\end_inset
+
+ When linking, skip the standard crt0.o object file.
+ You must provide your own crt0.o for your system when linking.
+
+\layout Subsubsection
+
+Optimization Options
+\begin_inset LatexCommand \index{Options optimization}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{Optimization options}
+
+\end_inset
+
+
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-nogcse
+\begin_inset LatexCommand \index{-\/-nogcse}
+
+\end_inset
+
+
+\series default
+ Will not do global subexpression elimination, this option may be used when
+ the compiler creates undesirably large stack/data spaces to store compiler
+ temporaries.
+ A warning message will be generated when this happens and the compiler
+ will indicate the number of extra bytes it allocated.
+ It recommended that this option NOT be used, #pragma\SpecialChar ~
+NOGCSE
+\begin_inset LatexCommand \index{\#pragma NOGCSE}
+
+\end_inset
+
+ can be used to turn off global subexpression elimination
+\begin_inset LatexCommand \index{Subexpression elimination}
\end_inset
\series default
The compiler by default uses a caller saves convention for register saving
- across function calls, however this can cause unneccessary register pushing
+ across function calls, however this can cause unnecessary register pushing
& popping when calling small functions from larger functions.
This option can be used to switch the register saving convention for the
function names specified.
code will be generated at the entry & exit for these functions to save
& restore the registers used by these functions, this can SUBSTANTIALLY
reduce code & improve run time performance of the generated code.
- In the future the compiler (with interprocedural analysis) will be able
+ In the future the compiler (with inter procedural analysis) will be able
to determine the appropriate scheme to use for each function call.
DO NOT use this option for built-in functions such as _mulint..., if this
option is used for a library function the appropriate library function
\series default
Include i-codes in the asm file.
- Sounds like noise but is most helpfull for debugging the compiler itself.
+ Sounds like noise but is most helpful for debugging the compiler itself.
\layout List
\labelwidthstring 00.00.0000
\series default
Display the directories in the compiler's search path
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-vc
+\begin_inset LatexCommand \index{-\/-vc}
+
+\end_inset
+
+
+\series default
+ Display errors and warnings using MSVC style, so you can use SDCC with
+ visual studio
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-use-stderr
+\begin_inset LatexCommand \index{-\/-use-stdout}
+
+\end_inset
+
+
+\series default
+ Send errors and warnings to stdout instead of stderr
\layout Subsubsection
Intermediate Dump Options
There are some more environment variables recognized by SDCC, but these
are solely used for debugging purposes.
- They can change or disappear very quickly, and will never be documentated.
+ They can change or disappear very quickly, and will never be documented.
\layout Subsection
MCS51/DS390 Storage Class
\layout Standard
-Variables declared with this storage class will be placed in the extern
+Variables declared with this storage class will be placed in the external
RAM.
This is the
\series bold
default
\series default
storage class for Large Memory model, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
xdata unsigned char xduc;
default
\series default
storage class for Small Memory model.
- Variables declared with this storage class will be allocated in the internal
- RAM, e.g.:
-\newline
+ Variables declared with this storage class will be allocated in the directly
+ addressable portion of the internal RAM of a 8051, e.g.:
+\layout Verse
-\newline
\family typewriter
data int iramdata;
Variables declared with this storage class will be allocated into the indirectly
addressable portion of the internal ram of a 8051, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
idata int idi;
This is a data-type and a storage class specifier.
When a variable is declared as a bit, it is allocated into the bit addressable
memory of 8051, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
bit iFlag;
\emph default
signifies both a data-type and storage class, they are used to describe
the special function registers and special bit variables of a 8051, eg:
-\newline
+\layout Verse
-\newline
\family typewriter
-sfr at 0x80 P0; /* special function register P0 at location 0x80 */
+sfr at
+\begin_inset LatexCommand \index{at}
+
+\end_inset
+
+ 0x80 P0; /* special function register P0 at location 0x80 */
\newline
sbit at 0xd7 CY; /* CY (Carry Flag
\begin_inset LatexCommand \index{Flags}
\newline
Pointer declaration examples:
-\newline
-
-\size small
+\layout Verse
-\newline
\family typewriter
-\size default
/* pointer physically in xternal ram pointing to object in internal ram
*/
\newline
\newline
\newline
-/* the folowing is a generic pointer physically located in xdata space */
+/* the following is a generic pointer physically located in xdata space
+ */
\newline
char * xdata p;
-\family default
-\size small
-
-\newline
-
-\newline
+\layout Standard
-\size default
Well you get the idea.
\newline
\emph default
keyword in the function declaration, e.g.:
-\newline
-
-\size small
+\layout Verse
-\newline
\family typewriter
-\size default
unsigned char foo(char i) reentrant
\newline
{
\newline
}
-\newline
-
-\family default
+\layout Standard
-\newline
Since stack space on 8051 is limited, the
\emph on
reentrant
\end_inset
addresses, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
unsigned char foo() {
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-data at 0x31 unsiged char j;
+data at 0x31 unsigned char j;
\newline
\SpecialChar ~
\SpecialChar ~
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
In the above example the variable
\emph on
i
will NOT be overlayed since these are implemented using external functions,
e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
#pragma SAVE
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
In the above example the parameter
\emph on
errcd
SDCC allows interrupt service routines to be coded in C, with some extended
keywords.
-\newline
+\layout Verse
-\newline
\family typewriter
-void timer_isr (void) interrupt 2 using 1
+void timer_isr (void) interrupt 1 using 1
\newline
{
\newline
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
-The number following the
+The optional number following the
\emph on
interrupt
\begin_inset LatexCommand \index{interrupt}
\emph default
keyword is the interrupt number this routine will service.
- The compiler will insert a call to this routine in the interrupt vector
- table for the interrupt number specified.
+ When present, the compiler will insert a call to this routine in the
+ interrupt vector table for the interrupt number specified.
The
\emph on
using
\emph default
- keyword is used to tell the compiler to use the specified register bank
- (8051 specific) when generating code for this function.
+ keyword can be used to tell the compiler to use the specified register
+ bank (8051 specific) when generating code for this function.
Note that when some function is called from an interrupt service routine
it should be preceded by a #pragma\SpecialChar ~
NOOVERLAY
\end_inset
if it is not reentrant.
- A special note here, int (16 bit) and long (32 bit) integer division
+ Furthermore nonreentrant functions should not be called from the main program
+ while the interrupt service routine might be active.
+ 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}
+
+\end_inset
+
+.
+
+\layout Standard
+
+A special note here, int (16 bit) and long (32 bit) integer division
\begin_inset LatexCommand \index{Division}
\end_inset
.
\layout Standard
-Interrupt Numbers and the corresponding address & descriptions for the Standard
- 8051 are listed below.
+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="6" columns="3">
+<lyxtabular version="3" rows="7" columns="3">
<features>
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" valignment="top" leftline="true" width="0in">
-<column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
+<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
\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
\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
+
+5
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Timer 2 (8052)
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0x002B
+\end_inset
+</cell>
+</row>
</lyxtabular>
\end_inset
\newline
-\newline
+\layout Standard
+
If the interrupt service routine is defined without
\emph on
using
SDCC will generate code to disable all interrupts upon entry to a critical
function and enable them back before returning.
Note that nesting critical functions may cause unpredictable results.
-\newline
-
-\size small
+\layout Verse
-\newline
\family typewriter
-\size default
int foo () critical
\newline
{
\newline
}
-\newline
-
-\family default
+\layout Standard
-\newline
The critical attribute maybe used with other attributes like
\emph on
reentrant.
This is particularly useful for interrupt functions, which can have a large
(and often unnecessary) prologue/epilogue.
For example, compare the code generated by these two functions:
-\newline
+\layout Verse
-\newline
\family typewriter
-data unsigned char counter;
+volatile
+\begin_inset LatexCommand \index{volatile}
+
+\end_inset
+
+ data unsigned char counter;
\newline
void simpleInterrupt(void) interrupt
\begin_inset LatexCommand \index{interrupt}
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-; MUST explicitly include ret in _naked function.
+; MUST explicitly include ret or reti in _naked function.
\newline
\SpecialChar ~
\SpecialChar ~
;
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
For an 8051 target, the generated simpleInterrupt looks like:
-\newline
+\layout Verse
-\newline
\family typewriter
_simpleIterrupt:
\SpecialChar ~
\SpecialChar ~
reti
-\family default
-
-\newline
+\layout Standard
-\newline
whereas nakedInterrupt looks like:
-\newline
+\layout Verse
-\newline
\family typewriter
_nakedInterrupt:
\SpecialChar ~
\SpecialChar ~
; MUST explicitly include ret(i) in _naked function.
-\family default
-
-\newline
+\layout Standard
-\newline
While there is nothing preventing you from writing C code inside a _naked
function, there are many ways to shoot yourself in the foot doing this,
and it is recommended that you stick to inline assembler.
\emph default
function (but may occasionally be useful anyway
\begin_inset Foot
-collapsed true
+collapsed false
\layout Standard
<address>
\emph default
keyword, in addition to a storage class, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
xdata
\end_inset
- 0x8000 unsigned char PORTA_8255 ;
-\newline
-
-\family default
+ 0x7ffe unsigned int chksum;
+\layout Standard
-\newline
-In the above example the PORTA_8255 will be allocated to the location 0x8000
+In the above example the variable chksum will located at 0x7ffe and 0x7fff
of the external ram.
- Note that this feature is provided to give the programmer access to
-\emph on
-memory mapped
-\emph default
- devices attached to the controller.
The compiler does not actually reserve any space for variables declared
in this way (they are implemented with an equate in the assembler).
Thus it is left to the programmer to make sure there are no overlaps with
\end_inset
-) are a good places to look for such overlaps.
-\newline
+) are good places to look for such overlaps.
+\layout Standard
+
+In case of memory mapped I/O devices the keyword
+\emph on
+volatile
+\emph default
+ should be used to tell the compiler that accesses might not be optimized
+ away:
+\layout Verse
+
+
+\family typewriter
+volatile
+\begin_inset LatexCommand \index{volatile}
+
+\end_inset
+
+ xdata
+\begin_inset LatexCommand \index{xdata}
+
+\end_inset
+
+ at
+\begin_inset LatexCommand \index{at}
+
+\end_inset
+
+ 0x8000 unsigned char PORTA_8255;
+\layout Standard
-\newline
Absolute address can be specified for variables in all storage classes,
e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
bit
\end_inset
0x02 bvar;
-\newline
-
-\newline
+\layout Standard
-\family default
The above example will allocate the variable at offset 0x02 in the bit-addressab
le space.
There is no real advantage to assigning absolute addresses to variables
in this manner, unless you want strict control over all the variables allocated.
+ One possible use would be to write hardware portable code.
+ For example, if you have a routine that uses one or more of the microcontroller
+ I/O pins, and such pins are different for two different hardwares, you
+ can declare the I/O pins in you routine using
+\layout Verse
+
+
+\family typewriter
+extern bit SDI;
+\newline
+extern bit SCLK;
+\newline
+extern bit CPOL;
+\newline
+
+\newline
+void DS1306_put(unsigned char value)
+\newline
+{
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+unsigned char mask=0x80;
+\newline
+
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+while(mask)
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+{
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+SDI=(value & mask)?1:0;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+SCLK=!CPOL;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+SCLK=CPOL;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mask/=2;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+}
+\newline
+}
+\layout Standard
+
+Then, someplace in the code for the first hardware you would use
+\layout Verse
+
+
+\family typewriter
+bit at 0x80 SDI;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/*I/O port 0, bit 0*/
+\newline
+bit at 0x81 SCLK;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/*I/O port 0, bit 1*/
+\newline
+bit CPOL;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/*This is a variable, let the linker allocate this one*/
+\layout Standard
+
+Similarly, for the second hardware you would use
+\layout Verse
+
+
+\family typewriter
+bit at 0x83 SDI;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/*I/O port 0, bit 3*/
+\newline
+bit at 0x91 SCLK;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/*I/O port 1, bit 1*/
+\newline
+bit CPOL;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/*This is a variable, let the linker allocate this one*/
+\layout Standard
+
+and you can use the same hardware dependent routine without changes, as
+ for example in a library.
+ This is somehow similar to sbit, but only one absolute address has to be
+ specified in the whole project.
\layout Subsection
Startup Code
.
This might cause some unexpected changes in the inline assembler code.
- Please go throught the peephole optimizer rules defined in file
+ Please go through the peephole optimizer rules defined in file
\emph on
SDCCpeeph.def
\emph default
carefully before using this option.
-\newline
+\layout Verse
-\newline
\family typewriter
_asm
\end_inset
;
-\family default
-\size small
-
-\newline
-
-\newline
+\layout Standard
-\size default
The inline assembler code can contain any valid code understood by the assembler
, this includes any assembler directives and comment lines.
The compiler does not do any validation of the code within the
\end_inset
defined by the inline assembler, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
foo() {
/* some more c code */
\newline
}
-\newline
-
-\newline
-
-\family default
-In other words inline assembly code can access labels defined in inline
- assembly within the scope of the funtion.
-
\layout Standard
-The same goes the other way, ie.
+In other words inline assembly code can access labels defined in inline
+ assembly within the scope of the function.
+ The same goes the other way, ie.
labels defines in inline assembly CANNOT be accessed by C statements.
\layout Subsection
For signed & unsigned int (16 bit) and long (32 bit) variables, division,
multiplication and modulus operations are implemented by support routines.
These support routines are all developed in ANSI-C to facilitate porting
- to other MCUs, although some model specific assembler optimations are used.
+ to other MCUs, although some model specific assembler optimizations are
+ used.
The following files contain the described routine, all of them can be found
in <installdir>/share/sdcc/lib.
\newline
-\newline
-
-\emph on
-<pending: tabularise this>
-\emph default
+\layout Standard
+\align center
-\newline
+\begin_inset Tabular
+<lyxtabular version="3" rows="11" 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
-\newline
-_mulint.c - 16 bit multiplication
-\newline
-_divsint.c - signed 16 bit division (calls _divuint)
-\newline
-_divuint.c - unsigned 16 bit division
-\newline
-_modsint.c - signed 16 bit modulus (call _moduint)
-\newline
-_moduint.c - unsigned 16 bit modulus
-\newline
-_mullong.c - 32 bit multiplication
-\newline
-_divslong.c - signed 32 division (calls _divulong)
-\newline
-_divulong.c - unsigned 32 division
-\newline
-_modslong.c - signed 32 bit modulus (calls _modulong)
-\newline
-_modulong.c - unsigned 32 bit modulus
-\size footnotesize
+\layout Standard
-\newline
-\newline
+\series bold
+Function
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
-\size default
-Since they are compiled as
-\emph on
-non-reentrant
-\emph default
+\layout Standard
-\begin_inset LatexCommand \index{reentrant}
+\series bold
+Description
\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
-, interrupt
-\begin_inset LatexCommand \index{interrupt}
+\layout Standard
+_mulint.c
\end_inset
-
- service routines should not do any of the above operations.
- If this is unavoidable then the above routines will need to be compiled
- with the
-\emph on
--
-\begin_inset ERT
-status Collapsed
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
\layout Standard
-\backslash
-/
+16 bit multiplication
\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
--stack-auto
-\begin_inset LatexCommand \index{-\/-stack-auto}
+\layout Standard
+_divsint.c
\end_inset
-
-
-\emph default
- option, after which the source program will have to be compiled with
-\emph on
--
-\begin_inset ERT
-status Collapsed
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
\layout Standard
-\backslash
-/
+ signed 16 bit division (calls _divuint)
\end_inset
-
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_divuint.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+ unsigned 16 bit division
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_modsint.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+signed 16 bit modulus (calls _moduint)
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_moduint.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+unsigned 16 bit modulus
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_mullong.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+32 bit multiplication
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_divslong.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+ signed 32 division (calls _divulong)
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_divulong.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+unsigned 32 division
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+_modslong.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+ signed 32 bit modulus (calls _modulong)
+\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
+
+_modulong.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+unsigned 32 bit modulus
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\newline
+
+\layout Standard
+
+Since they are compiled as
+\emph on
+non-reentrant
+\emph default
+
+\begin_inset LatexCommand \index{reentrant}
+
+\end_inset
+
+, interrupt
+\begin_inset LatexCommand \index{interrupt}
+
+\end_inset
+
+ service routines should not do any of the above operations.
+ If this is unavoidable then the above routines will need to be compiled
+ with 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, after which the source program will have to be compiled with
+\emph on
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
-int-long-rent
\begin_inset LatexCommand \index{-\/-int-long-rent}
\emph default
option.
+ Notice that you don't have to call this routines directly.
+ The compiler will use them automatically every time a integer operation
+ is required.
\layout Subsection
Floating Point Support
\layout Standard
-SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
- point support routines are derived from gcc's floatlib.c and consists of
- the following routines:
+SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
+ floating point support routines are derived from gcc's floatlib.c and consists
+ of the following routines:
\newline
-\newline
+\layout Standard
+\align center
-\emph on
-<pending: tabularise this>
-\emph default
+\size footnotesize
-\newline
+\begin_inset Tabular
+<lyxtabular version="3" rows="17" 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
-\newline
-_fsadd.c - add floating point numbers
-\newline
-_fssub.c - subtract floating point numbers
-\newline
-_fsdiv.c - divide floating point numbers
-\newline
-_fsmul.c - multiply floating point numbers
-\newline
-_fs2uchar.c - convert floating point to unsigned char
-\newline
-_fs2char.c - convert floating point to signed char
-\newline
-_fs2uint.c - convert floating point to unsigned int
-\newline
-_fs2int.c - convert floating point to signed int
-\newline
-_fs2ulong.c - convert floating point to unsigned long
-\newline
-_fs2long.c - convert floating point to signed long
-\newline
-_uchar2fs.c - convert unsigned char to floating point
-\newline
-_char2fs.c - convert char to floating point number
-\newline
-_uint2fs.c - convert unsigned int to floating point
-\newline
-_int2fs.c - convert int to floating point numbers
-\newline
-_ulong2fs.c - convert unsigned long to floating point number
-\newline
-_long2fs.c - convert long to floating point number
-\size footnotesize
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+Function
+\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">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fsadd.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+add floating point numbers
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fssub.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+subtract floating point numbers
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fsdiv.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+divide floating point numbers
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fsmul.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+multiply floating point numbers
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fs2uchar.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert floating point to unsigned char
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fs2char.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert floating point to signed char
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fs2uint.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert floating point to unsigned int
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fs2int.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert floating point to signed int
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fs2ulong.
+\family default
+\series default
+\shape default
+\size default
+\emph default
+\bar default
+\noun default
+\color default
+c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert floating point to unsigned long
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_fs2long.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert floating point to signed long
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_uchar2fs.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert unsigned char to floating point
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_char2fs.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert char to floating point number
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_uint2fs.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert unsigned int to floating point
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_int2fs.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert int to floating point numbers
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_ulong2fs.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert unsigned long to floating point number
+\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
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+_long2fs.c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+convert long to floating point number
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
-\newline
\newline
-\size default
+\layout Standard
+
Note if all these routines are used simultaneously the data space might
overflow.
For serious floating point usage it is strongly recommended that the large
model be used.
+ Also notice that you don't have to call this routines directly.
+ The compiler will use them automatically every time a floating point operation
+ is required.
\layout Subsection
MCS51 Memory Models
be combined together or the results would be unpredictable.
The library routines supplied with the compiler are compiled as both small
and large.
- The compiled library modules are contained in seperate directories as small
+ The compiled library modules are contained in separate directories as small
and large so that you can link to either set.
\layout Standard
and the 'reentrant' function type will yield much more efficient code,
than using the large model.
Several optimizations are disabled when the program is compiled using the
- large model, it is therefore strongly recommdended that the small model
+ large model, it is therefore strongly recommended that the small model
be used unless absolutely required.
\layout Subsection
\layout Standard
-The compiler creates the following #defines
-\begin_inset LatexCommand \index{\#defines}
+The compiler creates the following #defines
+\begin_inset LatexCommand \index{\#defines}
+
+\end_inset
+
+:
+\newline
+
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="10" 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
+
+
+\series bold
+#define
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold
+Description
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+SDCC
+\begin_inset LatexCommand \index{SDCC}
+
+\end_inset
+
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+this Symbol is always defined
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+SDCC_mcs51
+\begin_inset LatexCommand \index{SDCC\_mcs51}
+
+\end_inset
+
+ or SDCC_ds390
+\begin_inset LatexCommand \index{SDCC\_ds390}
+
+\end_inset
+
+ or SDCC_z80
+\begin_inset LatexCommand \index{SDCC\_z80}
+
+\end_inset
+
+, etc
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+depending on the model used (e.g.: -mds390
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+__mcs51
+\begin_inset LatexCommand \index{\_\_mcs51}
+
+\end_inset
+
+ or __ds390
+\begin_inset LatexCommand \index{\_\_ds390}
+
+\end_inset
+
+ or __z80
+\begin_inset LatexCommand \index{\_\_z80}
+
+\end_inset
+
+, etc
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+depending on the model used (e.g.
+ -mz80)
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+SDCC_STACK_AUTO
+\begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
+
+\end_inset
+
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+when
+\emph on
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-stack-auto
+\emph default
+ option is used
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+SDCC_MODEL_SMALL
+\begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
+
+\end_inset
+
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+when
+\emph on
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-model-small
+\emph default
+ is used
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+SDCC_MODEL_LARGE
+\begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
+
+\end_inset
+
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+when
+\emph on
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-model-large
+\emph default
+ is used
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+SDCC_USE_XSTACK
+\begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
+
+\end_inset
+
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+when
+\emph on
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+-xstack
+\emph default
+ option is used
\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
-.
-\layout Itemize
+\layout Standard
-SDCC
-\begin_inset LatexCommand \index{SDCC}
+SDCC_STACK_TENBIT
+\begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
\end_inset
- - this Symbol is always defined.
-\layout Itemize
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
-SDCC_mcs51
-\begin_inset LatexCommand \index{SDCC\_mcs51}
+\layout Standard
+when
+\emph on
+-mds390
+\emph default
+ is used
\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
- or SDCC_ds390
-\begin_inset LatexCommand \index{SDCC\_ds390}
+\layout Standard
+
+SDCC_MODEL_FLAT24
+\begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
\end_inset
- or SDCC_z80
-\begin_inset LatexCommand \index{SDCC\_z80}
\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
-, etc - depending on the model used (e.g.: -mds390)
-\layout Itemize
+\layout Standard
-__mcs51
-\begin_inset LatexCommand \index{\_\_mcs51}
+when
+\emph on
+-mds390
+\emph default
+ is used
+\end_inset
+</cell>
+</row>
+</lyxtabular>
\end_inset
- or __ds390
-\begin_inset LatexCommand \index{\_\_ds390}
-\end_inset
+\newline
- or __z80
-\begin_inset LatexCommand \index{\_\_z80}
+\layout Subsection
+Redirecting output on Windows Shells
+\layout Standard
+
+By default SDCC writes it's error messages to
+\begin_inset Quotes sld
\end_inset
-, etc - depending on the model used (e.g.
- -mz80)
-\layout Itemize
+standard error
+\begin_inset Quotes srd
+\end_inset
-SDCC_STACK_AUTO
-\begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
+.
+ To force all messages to
+\begin_inset Quotes sld
+\end_inset
+standard output
+\begin_inset Quotes srd
\end_inset
- - this symbol is defined when
-\emph on
+ use
+\series bold
-
+\series default
+\emph on
+
\begin_inset ERT
status Collapsed
/
\end_inset
--stack-auto
-\emph default
- option is used.
-\layout Itemize
-SDCC_MODEL_SMALL
-\begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
+\series bold
+\emph default
+-
+\series default
+use-stdout
+\begin_inset LatexCommand \index{-\/-use-stdout}
\end_inset
- - when
+.
+ Aditionaly, if you happen to have visual studio installed in your windows
+ machine, you can use it to compile your sources using a custom build and
+ the SDCC -
\emph on
--
+
\begin_inset ERT
status Collapsed
/
\end_inset
--model-small
-\emph default
- is used.
-\layout Itemize
-SDCC_MODEL_LARGE
-\begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
+\emph default
+-vc
+\begin_inset LatexCommand \index{-\/-vc}
\end_inset
- - when
+ option.
+ Something like this should work:
+\newline
+
+\newline
+
+\series bold
+c:
+\backslash
+sdcc
+\backslash
+bin
+\backslash
+sdcc.exe -
+\series default
\emph on
--
+
\begin_inset ERT
status Collapsed
/
\end_inset
--model-large
-\emph default
- is used.
-\layout Itemize
-
-SDCC_USE_XSTACK
-\begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
-
-\end_inset
- - when
+\series bold
+\emph default
+-vc -
+\series default
\emph on
--
+
\begin_inset ERT
status Collapsed
/
\end_inset
--xstack
-\emph default
- option is used.
-\layout Itemize
-
-SDCC_STACK_TENBIT
-\begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
-
-\end_inset
-
- - when
-\emph on
--mds390
-\emph default
- is used
-\layout Itemize
-
-SDCC_MODEL_FLAT24
-\begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
-
-\end_inset
- - when
-\emph on
--mds390
+\series bold
\emph default
- is used
+-model-large -c $(InputPath)
\layout Section
\pagebreak_top
SDCC Technical Data
The compiler does local and global common subexpression elimination, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
i = x + y + 1;
\newline
j = x + y;
-\family default
-
-\newline
+\layout Standard
-\newline
will be translated to
-\newline
+\layout Verse
-\newline
\family typewriter
iTemp = x + y
i = iTemp + 1
\newline
j = iTemp
-\newline
-
-\family default
+\layout Standard
-\newline
Some subexpressions are not as obvious as the above example, e.g.:
-\newline
+\layout Verse
-\newline
\family typewriter
a->b[i].c = 10;
\newline
a->b[i].d = 11;
-\family default
-
-\newline
+\layout Standard
-\newline
In this case the address arithmetic a->b[i] will be computed only once;
the equivalent code in C would be.
-\newline
+\layout Verse
-\newline
\family typewriter
iTemp = a->b[i];
iTemp.c = 10;
\newline
iTemp.d = 11;
-\family default
-
-\newline
+\layout Standard
-\newline
The compiler will try to keep these temporary variables in registers.
\layout Subsubsection
\end_inset
-\layout Standard
+\layout Verse
\family typewriter
/* unreachable */
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
will be changed to
-\newline
+\layout Verse
-\newline
\family typewriter
int global; void f ()
\end_inset
-\layout Standard
+\layout Verse
\family typewriter
return j;
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
will be changed to
-\newline
+\layout Verse
-\newline
\family typewriter
int f() {
\newline
\SpecialChar ~
- \SpecialChar ~
- int i,j;
+\SpecialChar ~
+int i, j;
\newline
\SpecialChar ~
- \SpecialChar ~
- i = 10;
+\SpecialChar ~
+i = 10;
\newline
\SpecialChar ~
- \SpecialChar ~
- j = 10;
+\SpecialChar ~
+j = 10;
\newline
\SpecialChar ~
- \SpecialChar ~
- return 10;
+\SpecialChar ~
+return 10;
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
Note: the dead stores created by this copy propagation will be eliminated
by dead-code elimination.
\layout Subsubsection
\newline
Loop Invariant:
-\newline
+\layout Verse
-\newline
\family typewriter
for (i = 0 ; i < 100 ; i ++)
\newline
- \SpecialChar ~
- \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
f += k + l;
-\family default
-
-\newline
+\layout Standard
-\newline
changed to
-\newline
+\layout Verse
-\newline
\family typewriter
itemp = k + l;
\SpecialChar ~
\SpecialChar ~
f += itemp;
-\family default
-
-\newline
+\layout Standard
-\newline
As mentioned previously some loop invariants are not as apparent, all static
address computations are also moved out of the loop.
\newline
\end_inset
, this optimization substitutes an expression by a cheaper expression:
-\newline
+\layout Verse
-\newline
\family typewriter
for (i=0;i < 100; i++)
\SpecialChar ~
\SpecialChar ~
ar[i*5] = i*3;
-\family default
-
-\newline
+\layout Standard
-\newline
changed to
-\newline
+\layout Verse
-\newline
\family typewriter
itemp1 = 0;
\newline
for (i=0;i< 100;i++) {
\newline
- \SpecialChar ~
- \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
ar[itemp1] = itemp2;
\newline
- \SpecialChar ~
- \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
itemp1 += 5;
\newline
- \SpecialChar ~
- \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
itemp2 += 3;
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
The more expensive multiplication
\begin_inset LatexCommand \index{Multiplication}
\newline
\family typewriter
-for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
- <sym> += 1])
+for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
+ += 1])
\newline
\SpecialChar ~
\SpecialChar ~
SDCC does numerous algebraic simplifications, the following is a small sub-set
of these optimizations.
-\newline
+\layout Verse
-\newline
\family typewriter
i = j + 0 ; /* changed to */ i = j;
i = j - j ; /* changed to */ i = 0;
\newline
i = j / 1 ; /* changed to */ i = j;
-\family default
-
-\newline
+\layout Standard
-\newline
Note the subexpressions
\begin_inset LatexCommand \index{Subexpression}
The case labels are in numerical sequence, the labels need not be in order,
and the starting number need not be one or zero.
-\newline
+\begin_deeper
+\layout Verse
-\newline
\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 ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
switch (i) {
\newline
-case 4:...
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
+\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 1: ...
\newline
-case 5:...
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
+\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 2: ...
\newline
-case 3:...
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
+\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 3: ...
\newline
-case 6:...
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
- \SpecialChar ~
+\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 4: ...
\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 ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
}
-\newline
-
-\newline
+\layout Standard
-\family default
Both the above switch statements will be implemented using a jump-table.
+\end_deeper
\layout Itemize
The number of case labels is at least three, since it takes two conditional
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.:
-\newline
+\layout Verse
-\newline
\family typewriter
switch (i) {
\newline
+\SpecialChar ~
+\SpecialChar ~
case 1: ...
\newline
+\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 ~
case 12: ...
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
If the above switch statement is broken down into two switch statements
-\newline
+\layout Verse
-\newline
\family typewriter
switch (i) {
\newline
+\SpecialChar ~
+\SpecialChar ~
case 1: ...
\newline
+\SpecialChar ~
+\SpecialChar ~
case 2: ...
\newline
+\SpecialChar ~
+\SpecialChar ~
case 3: ...
\newline
+\SpecialChar ~
+\SpecialChar ~
case 4: ...
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
and
-\family typewriter
+\layout Verse
-\newline
-\newline
+\family typewriter
switch (i) {
\newline
+\SpecialChar ~
+\SpecialChar ~
case 9: \SpecialChar ~
...
\newline
+\SpecialChar ~
+\SpecialChar ~
case 10: ...
\newline
+\SpecialChar ~
+\SpecialChar ~
case 11: ...
\newline
+\SpecialChar ~
+\SpecialChar ~
case 12:\SpecialChar ~
...
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
then both the switch statements will be implemented using jump-tables whereas
the unmodified switch statement will not be.
+ 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.
\layout Subsubsection
Bit-shifting Operations
g.
SDCC tries to implement bit-shift operations in the most efficient way
possible, e.g.:
-\newline
+\layout Verse
-\family typewriter
-\newline
+\family typewriter
unsigned char i;
\newline
...
i>>= 4;
\newline
...
-\newline
-
-\family default
+\layout Standard
-\newline
generates the following code:
-\newline
+\layout Verse
-\family typewriter
-\newline
+\family typewriter
mov a,_i
\newline
swap a
anl a,#0x0f
\newline
mov _i,a
-\family default
-
-\newline
+\layout Standard
-\newline
In general SDCC will never setup a loop if the shift count is known.
Another example:
-\newline
+\layout Verse
-\newline
\family typewriter
unsigned int i;
i >>= 9;
\newline
...
-\family default
-
-\newline
+\layout Standard
-\newline
will generate:
-\newline
+\layout Verse
-\newline
\family typewriter
mov a,(_i + 1)
rrc a
\newline
mov _i,a
-\family default
-
-\newline
+\layout Standard
-\newline
Note that SDCC stores numbers in little-endian format (i.e.
lowest order first).
\layout Subsubsection
A special case of the bit-shift operation is bit rotation, SDCC recognizes
the following expression to be a left bit-rotation:
-\newline
+\layout Verse
-\newline
\family typewriter
unsigned char i;
\family default
\newline
+
+\family typewriter
...
-\newline
+\layout Standard
-\newline
will generate the following code:
-\newline
+\layout Verse
-\newline
\family typewriter
mov a,_i
rl a
\newline
mov _i,a
-\family default
-
-\newline
+\layout Standard
-\newline
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.:
-\newline
+\layout Verse
-\newline
\family typewriter
i = ((i >> 7) | (i << 1)); /* left-bit rotation */
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.:
-\newline
+\layout Verse
+
-\newline
-
\family typewriter
unsigned int gint;
\newline
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
will generate the following code:
-\newline
+\layout Verse
-\family typewriter
-\newline
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
+\family typewriter
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
61 ;\SpecialChar ~
hob.c 7
\newline
-\SpecialChar ~
-\SpecialChar ~
- 000A E5*01\SpecialChar ~
+000A E5*01\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
mov\SpecialChar ~
+\SpecialChar ~
a,(_gint + 1)
\newline
-\SpecialChar ~
-\SpecialChar ~
- 000C 33\SpecialChar ~
+000C 23\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- rlc\SpecialChar ~
- a
-\newline
-\SpecialChar ~
-\SpecialChar ~
- 000D E4\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
+ rl\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- 64\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- clr\SpecialChar ~
a
\newline
-\SpecialChar ~
-\SpecialChar ~
- 000E 13\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
+000D 54 01\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ 64\SpecialChar ~
\SpecialChar ~
- 65\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ anl\SpecialChar ~
\SpecialChar ~
- rrc\SpecialChar ~
- a
+ a,#0x01
\newline
+000F F5*02\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- 000F F5*02\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
- 66\SpecialChar ~
+ 65\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
mov\SpecialChar ~
+\SpecialChar ~
_foo_hob_1_1,a
-\newline
-
-\newline
+\layout Standard
-\family default
Variations of this case however will
\emph on
not
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.:
-\newline
+\layout Verse
-\newline
\family typewriter
xyz = gint + ((gint >> 15) & 1);
-\family default
-
-\newline
+\layout Standard
-\newline
will still be recognized.
\layout Subsubsection
\emph default
option.
The rule language is best illustrated with examples.
-\newline
+\layout Verse
-\newline
\family typewriter
replace {
mov %1,a
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
The above rule will change the following assembly
\begin_inset LatexCommand \index{Assembler routines}
\end_inset
sequence:
-\newline
+\layout Verse
-\newline
\family typewriter
-\SpecialChar ~
-\SpecialChar ~
mov r1,a
\newline
-\SpecialChar ~
-\SpecialChar ~
mov a,r1
-\family default
-
-\newline
+\layout Standard
-\newline
to
-\newline
+\layout Verse
-\newline
\family typewriter
mov r1,a
-\family default
-
-\newline
+\layout Standard
-\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:
-\newline
+\layout Verse
-\newline
\family typewriter
-\SpecialChar ~
-\SpecialChar ~
mov r1,a
\newline
-\SpecialChar ~
-\SpecialChar ~
mov a,r2
-\family default
-
-\newline
+\layout Standard
-\newline
will remain unmodified.
\newline
and
\family typewriter
acall
-\family default
-
-\newline
+\layout Verse
-\newline
\family typewriter
replace { lcall %1 } by { acall %1 }
\newline
-replace { ljmp %1 } by { ajmp %1 }
-\family default
-
-\newline
+replace { ljmp %1 } by { ajmp %1 }
+\layout Standard
-\newline
The
\emph on
inline-assembler code
\newline
The syntax for a rule is as follows:
-\newline
+\layout Verse
-\newline
\family typewriter
rule := replace [ restart ] '{' <assembly sequence> '
'}' [if <functionName> ] '
\backslash
n'
-\newline
-
-\family default
+\layout Standard
-\newline
<assembly sequence> := assembly instruction (each instruction including
labels must be on a separate line).
\newline
the same rule again.
An example of this (not a good one, it has side effects) is the following
rule:
-\newline
+\layout Verse
-\newline
\family typewriter
replace restart {
; nop
\newline
}
-\family default
-
-\newline
+\layout Standard
-\newline
Note that the replace pattern cannot be a blank, but can be a comment line.
Without the 'restart' option only the inner most 'pop' 'push' pair would
be eliminated, i.e.:
-\newline
+\layout Verse
-\newline
\family typewriter
-\SpecialChar ~
-\SpecialChar ~
pop ar1
\newline
-\SpecialChar ~
-\SpecialChar ~
pop ar2
\newline
-\SpecialChar ~
-\SpecialChar ~
push ar2
\newline
-\SpecialChar ~
-\SpecialChar ~
push ar1
-\family default
-
-\newline
+\layout Standard
-\newline
would result in:
-\newline
+\layout Verse
-\newline
\family typewriter
-\SpecialChar ~
-\SpecialChar ~
pop ar1
\newline
-\SpecialChar ~
-\SpecialChar ~
; nop
\newline
-\SpecialChar ~
-\SpecialChar ~
push ar1
-\family default
-
-\newline
+\layout Standard
-\newline
\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:
-\newline
+\layout Verse
-\newline
\family typewriter
-\SpecialChar ~
-\SpecialChar ~
; nop
\newline
-\SpecialChar ~
-\SpecialChar ~
; nop
-\family default
-
-\newline
+\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.
-\newline
+\layout Verse
-\newline
\family typewriter
replace {
%2:
\newline
} if labelInRange
-\family default
-
-\newline
+\layout Standard
-\newline
The optimizer does a look-up of a function name table defined in function
\emph on
function1[,function2[,function3...]] - The compiler by default uses a caller
saves convention for register saving across function calls, however this
- can cause unneccessary register pushing & popping when calling small functions
+ can cause unnecessary register pushing & popping when calling small functions
from larger functions.
This option can be used to switch off the register saving convention for
the function names specified.
code need to be manually inserted at the entry & exit for these functions
to save & restore the registers used by these functions, this can SUBSTANTIALLY
reduce code & improve run time performance of the generated code.
- In the future the compiler (with interprocedural analysis) may be able
+ In the future the compiler (with inter procedural analysis) may be able
to determine the appropriate scheme to use for each function call.
If -
\begin_inset ERT
are used to control options & optimizations for a given function; pragmas
should be placed before and/or after a function, placing pragma's inside
a function body could have unpredictable results.
-\newline
+\layout Verse
-\newline
\family typewriter
#pragma SAVE
\end_inset
/* turn the optimizations back on */
-\family default
-
-\newline
+\layout Standard
-\newline
The compiler will generate a warning message when extra space is allocated.
It is strongly recommended that the SAVE and RESTORE pragma's be used when
changing options for a function.
\layout Standard
-In the following example the function cfunc calls an assembler routine asm_func,
- which takes two parameters.
-\newline
+In the following example the function c_func calls an assembler routine
+ asm_func, which takes two parameters.
+\layout Verse
-\newline
\family typewriter
extern int asm_func(unsigned char, unsigned char);
return c_func(10,9);
\newline
}
-\newline
-
-\newline
+\layout Standard
-\family default
The corresponding assembler function is:
-\newline
+\layout Verse
-\newline
\family typewriter
.globl _asm_func_PARM_2
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-.ds 1
+.ds 1
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-mov dpl,a
+mov dpl,a
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-mov dpl
+mov\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+dpl
\begin_inset LatexCommand \index{DPTR, DPH, DPL}
\end_inset
\SpecialChar ~
\SpecialChar ~
ret
-\newline
-
-\newline
+\layout Standard
-\family default
Note here that the return values are placed in 'dpl' - One byte return value,
'dpl' LSB & 'dph' MSB for two byte values.
'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
\begin_inset Quotes erd
\end_inset
- for four bytes, the varible name for the second parameter will be _<function_na
-me>_PARM_2.
+ for four bytes, the variable name for the second parameter will be _<function_n
+ame>_PARM_2.
\newline
\newline
parameters are pushed from right to left i.e.
after the call the left most parameter will be on the top of the stack.
Here is an example:
-\newline
+\layout Verse
-\newline
\family typewriter
extern int asm_func(unsigned char, unsigned char);
return c_func(10,9);
\newline
}
-\newline
-
-\family default
+\layout Standard
-\newline
The corresponding assembler routine is:
-\newline
+\layout Verse
-\newline
\family typewriter
.globl _asm_func
\SpecialChar ~
\SpecialChar ~
ret
-\newline
-
-\newline
+\layout Standard
-\family default
The compiling and linking procedure remains the same, however note the extra
entry & exit linkage required for the assembler code, _bp is the stack
frame pointer and is used to compute the offset into the stack for parameters
\layout Standard
-Deviations from the compliancy.
+Deviations from the compliance:
\layout Itemize
functions are not always reentrant.
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.:
-\family typewriter
+\begin_deeper
+\layout Verse
-\newline
-\newline
+\family typewriter
struct s { ...
};
\newline
\newline
}
\newline
-struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
- ANSI */
+struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
+ */
\newline
{
\newline
return rets;/* is invalid in SDCC although allowed in ANSI */
\newline
}
+\end_deeper
\layout Itemize
'long long
\end_inset
function declarations are NOT allowed.
-\newline
+\begin_deeper
+\layout Verse
-\family typewriter
-\newline
+\family typewriter
foo(i,j) /* this old style of function declarations */
\newline
int i,j; /* are valid in ANSI but not valid in SDCC */
\newline
}
+\end_deeper
\layout Itemize
functions declared as pointers must be dereferenced during the call.
-\newline
+\begin_deeper
+\layout Verse
-\family typewriter
-\newline
+\family typewriter
int (*foo)();
\newline
...
\newline
/* has to be called like this */
\newline
-(*foo)(); /* ansi standard allows calls to be made like 'foo()' */
+(*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
+\end_deeper
\layout Subsection
Cyclomatic Complexity
Reducing the size of division, multiplication & modulus operations can reduce
code size substantially.
Take the following code for example.
-\family typewriter
+\begin_deeper
+\layout Verse
-\newline
-\newline
+\family typewriter
foobar(unsigned int p1, unsigned char ch)
\newline
{
\newline
- unsigned char ch1 = p1 % ch ;
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+unsigned char ch1 = p1 % ch ;
\newline
- ....
-
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+....
\newline
}
-\newline
-
-\family default
+\layout Standard
-\newline
For the modulus operation the variable ch will be promoted to unsigned int
first then the modulus operation will be performed (this will lead to a
call to support routine _moduint()), and the result will be casted to a
char.
If the code is changed to
-\newline
+\layout Verse
-\family typewriter
-\newline
+\family typewriter
foobar(unsigned int p1, unsigned char ch)
\newline
{
\newline
- unsigned char ch1 = (unsigned char)p1 % ch ;
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+unsigned char ch1 = (unsigned char)p1 % ch ;
\newline
- ....
-
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+....
\newline
}
-\newline
-
-\family default
+\layout Standard
-\newline
It would substantially reduce the code generated (future versions of the
- compiler will be smart enough to detect such optimization oppurtunities).
+ compiler will be smart enough to detect such optimization opportunities).
+\end_deeper
\layout Subsection
Notes on MCS51 memory
\newline
- Bytes 20-2F - 16 bytes to hold 128 bit variables and,
\newline
-- Bytes 30-7F - 60 bytes for general purpose use.
+- Bytes 30-7F - 80 bytes for general purpose use.
\newline
\layout Standard
-Adittionally some members of the MCS51 family may have up to 128 bytes of
+Additionally some members of the MCS51 family may have up to 128 bytes of
additional, indirectly addressable, internal RAM memory (
\emph on
idata
\emph default
).
- Furtermore, some chips may have some built in external memory (
+ Furthermore, some chips may have some built in external memory (
\emph on
xdata
\emph default
-) which should not be confused with the internal, direclty addressable RAM
+) which should not be confused with the internal, directly addressable RAM
memory (
\emph on
data
\end_inset
grows, it will use up the remaining register banks, and the 16 bytes used
- by the 128 bit variables, and 60 bytes for general purpose use.
+ by the 128 bit variables, and 80 bytes for general purpose use.
If any bit variables are used, the data variables will be placed after
the byte holding the last bit variable.
For example, if register banks 0 and 1 are used, and there are 9 bit variables
allows you to specify the start of the stack, i.e.
you could start it after any data in the general purpose area.
- If your microcontroller has aditional indirectly addressable internal RAM
- (
+ If your microcontroller has additional indirectly addressable internal
+ RAM (
\emph on
idata
\emph default
.
If in doubt, don't specify any options and see if the resulting memory
- layout is appropiate, then you can twik it.
+ layout is appropriate, then you can adjust it.
\layout Standard
The 8051 linker generates two files with memory allocation information.
\end_inset
included in the distribution
-\layout Standard
+\newline
+\layout Standard
+\align center
\begin_inset Tabular
<lyxtabular version="3" rows="12" columns="3">
\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
\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
\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
\end_inset
+\newline
+
\layout Subsection
Related open source tools
\end_inset
-\layout Standard
+\newline
+\layout Standard
+\align center
\begin_inset Tabular
-<lyxtabular version="3" rows="7" columns="3">
+<lyxtabular version="3" rows="8" columns="3">
<features>
<column alignment="center" valignment="top" leftline="true" width="0pt">
-<column alignment="center" valignment="top" leftline="true" width="0pt">
+<column alignment="block" valignment="top" leftline="true" width="30line%">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\end_inset
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+flP5
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+PIC programmer
+\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://digilander.libero.it/fbradasc/FLP5.html}
+
+\end_inset
+
+
\end_inset
</cell>
</row>
\end_inset
+\begin_inset Foot
+collapsed false
+
+\layout Standard
+
+(sdcdb and ddd are available for Unix only)
+\end_inset
+
+
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\end_inset
+\newline
+
\layout Subsection
Related documentation / recommended reading
-\layout Standard
+\newline
+\layout Standard
+\align center
\begin_inset Tabular
<lyxtabular version="3" rows="5" columns="3">
<features>
<column alignment="center" valignment="top" leftline="true" width="0pt">
-<column alignment="center" valignment="top" leftline="true" width="0pt">
+<column alignment="block" valignment="top" leftline="true" width="30line%">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\end_inset
+\newline
+
\layout Section
\pagebreak_top
Retargetting for other MCUs.
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 Subsection
Compiling for Debugging
foo.cdb - the debugger symbol information file.
\layout Itemize
-foo.ihx - the intel hex format
+foo.ihx - the Intel hex format
\begin_inset LatexCommand \index{Intel hex format}
\end_inset
SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
The port is incomplete - long support is incomplete (mul, div and mod are
- unimplimented), and both float and bitfield support is missing.
+ unimplemented), and both float and bitfield support is missing.
Apart from that the code generated is correct.
\layout Standard
As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
The stack 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 varibles.
- IY is currently unusued.
+ BC and DE are available for holding variables.
+ IY is currently unused.
Return values 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.
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
- which reproduces the problem.
+ (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 -
\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
a similar problem.
\layout Subsection
-Changelog
+ChangeLog
\begin_inset LatexCommand \index{Changelog}
\end_inset
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!
+ 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
+
+, 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}
+
+\end_inset
+
+.
\layout Subsection
Examples
\layout Comment
Maybe we should include some links to real world applications.
- Preferrably pointer to pointers (one for each architecture) so this stays
+ Preferably pointer to pointers (one for each architecture) so this stays
manageable here?
\layout Subsection
\shape italic
-This is an excerpt from an atricle published in Circuit Cellar MagaZine
+This is an excerpt from an article published in Circuit Cellar Magazine
in august 2000.
It's a little outdated (the compiler is much more efficient now and user/develo
per friendly), but pretty well exposes the guts of it all.
This section shows some details of iCode.
The example C code does not do anything useful; it is used as an example
to illustrate the intermediate code generated by the compiler.
-\newline
+\layout Verse
-\newline
\family typewriter
1.\SpecialChar ~
\newline
15.\SpecialChar ~
\SpecialChar ~
-for (i = 0, j = 10 ; i < 10 ; i++, j--) {
+for (i = 0, j = 10 ; i < 10 ; i++, j
+\family default
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-
+\family typewriter
+) {
\newline
16.\SpecialChar ~
\SpecialChar ~
\newline
21.\SpecialChar ~
}
-\newline
-
-\newline
+\layout Standard
-\family default
In addition to the operands each iCode contains information about the filename
and line it corresponds to in the source file.
The first field in the listing should be interpreted as follows: