-#LyX 1.1 created this file. For more info see http://www.lyx.org/
+#This file was created by <kvigor> Wed Oct 4 16:57:26 2000
+#LyX 1.0 (C) 1995-1999 Matthias Ettrich and the LyX Team
\lyxformat 2.15
-\textclass linuxdoc
+\textclass article
\language english
\inputencoding default
\fontscheme default
\layout Standard
SDCC is a Free ware , retargettable, optimizing ANSI-C compiler.
- The current version targets Intel 8051 based MCUs, it can be retargetted
- for other 8 bit MCUs or PICs.
+ The current version targets Intel 8051 based MCUs, including the Dallas
+ 80C390 variant, as well as the Zilog Z80 family.
+ It can be retargetted for other 8 bit MCUs or PICs.
The entire source code for the compiler is distributed under GPL.
- SDCC used ASXXXX & ASLINK a Free ware, retargettable assembler & linker.
+ SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
SDCC has extensive MCU (8051) specific language extensions, which lets
it utilize the underlying hardware effectively.
The front-end (parser) will be enhanced to handle language extensions for
to use other simulators.
The latest version can be downloaded from
\series bold
-http://www.geocities.com/ResearchTriangle/Forum/1353
+http://sdcc.sourceforge.net
\layout Standard
All packages used in this compiler system are
What you need before you start installation of SDCC ? A C Compiler, not
just any C Compiler, gcc to be exact, you can get adventurous and try another
compiler , I HAVEN'T tried it.
- GCC is free , and is available for almost all major platforms, if you are
- using
+ GCC is free , and is available for almost all major platforms.
+ If you are using
\emph on
linux
\emph default
you probably already have it, if you are using
\emph on
-Windows 95/NT
+Windows 9x/NT
\emph default
go to
\emph on
-www.cygnus.com
+http://sources.redhat.com/
\emph default
and download
\emph on
-CYGWIN32
-\emph default
- you will need the full development version of their tool (
-\emph on
-full.exe)
-\emph default
-, follow their instructions for installation (this is also free and is very
- easy to install),
-\emph on
-Windows
+Cygwin.
+
\emph default
-\emph on
-95/NT
-\emph default
-users be aware that the compiler runs substantially slower on the Windows
- platform, I am not sure why.
\layout Standard
After you have installed
CYGWIN shell)
\emph default
, change to the directory where you extracted the package and give the command.
-\layout Verbatim
+\layout Standard
./sdccbuild.sh
\layout Standard
for the sdcc executables and libraries, (default location is /usr/local).
The installation process will create the following directory structure
under the <directory name> specified.
-\layout Verbatim
+
+\layout Standard
bin/ - binary exectables (add to PATH environment variable)
\newline
\protected_separator
\protected_separator
-large/ - Object & library files for large model library
+large/ - Object & library files for large model library
+\newline
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+
+\protected_separator
+ds390/ - Object & library files forDS80C390 library
+\newline
+
\layout Standard
The command
Provided by Michael Jamet[ mjamet@computer.org]
\layout Standard
+Please note: these instructions are valid for Cygwin versions prior to 1.0.
+ If you have Cygwin 1.0 or later, the generic
+\begin_inset Quotes eld
+\end_inset
+
+configure/make/make install
+\begin_inset Quotes erd
+\end_inset
+
+ procedure described above should work as expected from the Cygwin shell.
+ If you have an earlier version of Cygwin, I strongly recommend upgrading.
+ If, however, you insist on using an earlier version, the following instructions
+ should prove helpful.
+\layout Standard
+
\protected_separator
\protected_separator
to the list.
-
+\layout Subsubsection
+
+FreeBSD and other non-GNU unixes
+\layout Standard
+
+Note that the SDCC build environment uses Gnu make.
+ If this is not the default 'make' on your system, you may need to install
+ it.
+ On many systems, Gnu make is installed as 'gmake'.
\layout Section
Compiling.
For single source file projects the process is very simple.
Compile your programs with the following command
-\layout Verbatim
+\layout Standard
\size footnotesize
SDCC can compile only ONE file at a time.
Let us for example assume that you have a project containing the following
files.
-\layout Verbatim
+\layout Standard
\size footnotesize
foo1.c ( contains some functions )
-\layout Verbatim
+\layout Standard
\size footnotesize
foo2.c (contains some more functions)
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
The first two files will need to be compiled separately with the commands
-\layout Verbatim
+\layout Standard
\size footnotesize
sdcc -c foo1.c
-\layout Verbatim
+\layout Standard
\size footnotesize
Then compile the source file containing main and link the other files together
with the following command.
-\layout Verbatim
+\layout Standard
\size footnotesize
foomain.c
\emph default
can be separately compiled as well
-\layout Verbatim
+\layout Standard
\size footnotesize
sdcc -c foomain.c
-\layout Verbatim
+\layout Standard
\size footnotesize
'mylib'
\emph default
.
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Itemize
+-mmcs51
+\begin_inset LatexCommand \label{-mmcs51}
+
+\end_inset
+
+Generate code for the MCS51 (8051) family of processors.
+ This is the default processor target.
+\layout Itemize
+
+-mz80
+\begin_inset LatexCommand \label{-mz80}
+
+\end_inset
+
+Generate code for the Z80 family of processors.
+ Various other options may not be applicable in this mode.
+
+\layout Itemize
+
+
+\series bold
+-mds390
+\series default
+
+\begin_inset LatexCommand \label{-mds390}
+
+\end_inset
+
+Generate code for the DS80C390 processor.
+ Various other options may not be applicable in this mode.
+\layout Itemize
+
\series bold
\size large
\layout Itemize
+\series bold
+\size large
+\bar under
+--model-flat24
+\series default
+\emph on
+\bar default
+
+\size default
+\emph default
+
+\begin_inset LatexCommand \ref[--model-flat24]{--model-flat24}
+
+\end_inset
+
+Generate code forDS80C390 24-bit flat mode.
+ See section Memory Models for more details.
+\layout Itemize
+
+
\series bold
\size large
\bar under
\size scriptsize
eg.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
will be translated to
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size small
a->b[i]
\emph default
will be computed only once; the equivalent code in C would be.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
will be changed to
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
will be changed to
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
changed to
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
changed to
-\layout Verbatim
+\layout Standard
\size small
SDCC does numerous algebraic simplifications, the following is a small sub-set
of these optimizations.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
If the above switch statement is broken down into two switch statements
-\layout Verbatim
+\layout Standard
\size small
\newline
}
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size small
unsigned short i;
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
generates the following code.
-\layout Verbatim
+\layout Standard
\size small
In general SDCC will never setup a loop if the shift count is known.
Another example
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
will generate
-\layout Verbatim
+\layout Standard
\size small
A special case of the bit-shift operation is bit rotation, SDCC recognizes
the following expression to be a left bit-rotation.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
will generate the following code.
-\layout Verbatim
+\layout Standard
\size small
type (int,long,short or char types).
SDCC recognizes the following expression to yield the highest order bit
and generates optimized code for it.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
Will generate the following code.
-\layout Verbatim
+\layout Standard
\size small
It is a standard C expression , so I heartily recommend this be the only
way to get the highest order bit, (it is portable).
Of course it will be recognized even if it is embedded in other expressions.
-\layout Verbatim
+\layout Standard
\size small
eg.
-\layout Verbatim
+\layout Standard
\size small
A default set of rules are compiled into the compiler, additional rules
may be added with the --peep-file <filename> option.
The rule language is best illustrated with examples.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
The above rule will the following assembly sequence
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
to
-\layout Verbatim
+\layout Standard
\size small
Note: All occurrences of a '%n' ( pattern variable ) must denote the same
string.
With the above rule, the assembly sequence
-\layout Verbatim
+\layout Standard
\size small
option), eg.
some variants of the 8051 MCU allow only 'AJMP' and 'ACALL' , the following
two rules will change all 'LJMP' & 'LCALL' to 'AJMP' & 'ACALL'.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
The syntax for a rule is as follows ,
-\layout Verbatim
+\layout Standard
\size small
it is intended to be used in situations where a transformation will trigger
the same rule again.
A good example of this the following rule.
-\layout Verbatim
+\layout Standard
\size small
\emph default
' option only the inner most 'pop' 'push' pair would be eliminated.
i.e.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
would result in
-\layout Verbatim
+\layout Standard
\size small
pop' 'push'
\emph default
pairs will be eliminated to yield
-\layout Verbatim
+\layout Standard
\size small
A conditional function can be attached to a rule.
Attaching rules are somewhat more involved, let me illustrate this with
an example.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
Pointer declaration examples.
-\layout Verbatim
+\layout Standard
\size small
data unsigned char * xdata p;
\newline
-\layout Verbatim
+\layout Standard
\size small
xdata unsigned char * code p;
\newline
-\layout Verbatim
+\layout Standard
\size small
syntax for pointer declaration is also supported.
Note the above examples will be portable to other commercially available
compilers.
-\layout Verbatim
+\layout Standard
\size small
All unqualified pointers are treated as 3 - byte '_generic' pointers.
These type of pointers can also to be explicitly declared.
-\layout Verbatim
+\layout Standard
\size small
\family typewriter
\size scriptsize
eg
-\layout Verbatim
+\layout Standard
\size small
\family typewriter
\size scriptsize
eg
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
eg
-\layout Verbatim
+\layout Standard
\size small
at <address>
\emph default
keyword, in addition to a storage class.
-\layout Verbatim
+\layout Standard
eg.
-\layout Verbatim
+\layout Standard
\size small
\layout Standard
Absolute address can be specified for variables in all storage classes.
-\layout Verbatim
+\layout Standard
\size small
eg.
-\layout Verbatim
+\layout Standard
\size small
SDCC allows interrupt service routines to be coded in C, with some extended
keywords.
-\layout Verbatim
+\layout Standard
\size small
8051 are listed below.
SDCC will automatically adjust the interrupt vector table to the maximum
interrupt number specified.
-\layout Verbatim
+\layout Standard
Interrupt #
\protected_separator
the peephole optimizer, this might cause some unexpected changes in the
inline assembler code, please go throught the peephole optimizer rules
defined in file 'SDCCpeeph.def' carefully before using this option.
-\layout Verbatim
+\layout Standard
\size small
eg
-\layout Verbatim
+\layout Standard
\size small
Inline assembler code cannot reference any C-Labels however it can reference
labels defined by the inline assembler.
-\layout Verbatim
+\layout Standard
\size small
eg
-\layout Verbatim
+\layout Standard
\size small
overflow.
For serious floating point usage it is strongly recommended that the Large
model be used (in which case the floating point routines mentioned above
- will need to recompiled with the --model-Large option).
+ will need to recompiled with the --model-Large option)
\layout Section
Memory Models
\layout Standard
-SDCC allows two memory models, modules compiled with different memory models
- should be combined together, the results would be unpredictable.
+SDCC allows two memory models for MCS51 code.
+ Modules compiled with different memory models should be combined together,
+ the results would be unpredictable.
The support routines supplied with the compiler are compiled in small-model
by default, and will need to be recompiled using the large model if the
large model is used.
be used unless absolutely required.
\layout Section
+Flat 24 bit addressing model.
+\begin_inset LatexCommand \label{--model-flat24}
+
+\end_inset
+
+
+\layout Standard
+
+This option generates code for the 24 bit contiguous addressing mode of
+ the Dallas DS80C390 part.
+ In this mode, up to four meg of external RAM or code space can be directly
+ addressed.
+ See the data sheets at www.dalsemi.com for further information on this part.
+\layout Standard
+
+In older versions of the compiler, this option was used with the MCS51 code
+ generator (-mmcs51).
+ Now, however, the '390 has it's own code generator, selected by the -mds390
+ switch.
+ This code generator currently supports only the flat24 model, but the --model-f
+lat24 switch is still required, in case later versions of the code generator
+ support other models (such as the paged mode of the '390).
+ The combination of -mmcs51 and --model-flat24 is now depracated.
+\layout Standard
+
+Note that the compiler does not generate any code to place the processor
+ into24 bitmode (it defaults to 8051 compatible mode).
+ Boot loader or similar code must ensure that the processor is in 24 bit
+ contiguous addressing mode before calling the SDCC startup code.
+\layout Standard
+
+Like the --model-large option, variables will by default be placed into
+ the XDATA segment.
+
+\layout Standard
+
+Segments may be placed anywhere in the 4 meg address space using the usual
+ --*-loc options.
+ Note that if any segments are located above 64K, the -r flag must be passed
+ to the linker to generate the proper segment relocations, and the Intel
+ HEX output format must be used.
+ The -r flag can be passed to the linker by using the option -Wl-r on the
+ sdcc command line.
+\layout Standard
+
+--stack-10bit:
+\layout Standard
+
+This option generates code for the 10 bit stack mode of the Dallas DS80C390
+ part.
+ In this mode, the stack is located in the lower 1K of the internal RAM,
+ which is mapped to 0x400000.
+\layout Standard
+
+With this option, sdcc will generate the proper addressing for stack variables.
+\layout Standard
+
+Note that the support is incomplete, since it still uses a single byte as
+ the stack pointer.
+ This means that only the lower 256 bytes of the potential 1K stack space
+ can actually be used.
+ However, this does allow you to reclaim the precious 256 bytes of low RAM
+ for use for the DATA and IDATA segments.
+\layout Standard
+
+The compiler will not generate any code to put the processor into 10 bit
+ stack mode.
+ It is important to ensure that the processor is in this mode before calling
+ any re-entrant functions compiled with this option.
+\layout Standard
+
+In principle, this should work with the --stack-auto option, but that has
+ not been tested.
+ It is incompatible with the --xstack option.
+ It also only makes sense if the processor is in 24 bit contiguous addressing
+ mode (see the --model-flat24 option).
+\layout Section
+
Defines created by the compiler.
\begin_inset LatexCommand \label{Defines.}
\noun default
a function, placing pragma's inside a function body could have unpredictable
results.
-\layout Verbatim
+\layout Standard
\size scriptsize
eg
-\layout Verbatim
+\layout Standard
\size scriptsize
\emph on
Martijn van Balen <balen@natlab.research.philips.com>.
-\layout Verbatim
+\layout Standard
\size scriptsize
%[flags][width][b|B|l|L]type
-\layout Verbatim
+\layout Standard
\size scriptsize
\series default
).
This simplified version of printf supports only the following formats.
-\layout Verbatim
+\layout Standard
\size scriptsize
\protected_separator
_generic pointer
-\begin_deeper
\layout Standard
The routine is
When using the %s format the string / pointer should be cast to a generic
pointer.
eg.
-\layout Verbatim
+\layout Standard
\size scriptsize
\end_inset
,(char _generic *)mystr,myint);
-\end_deeper
\layout Itemize
These routines will allocate memory from the external ram.
Here is a description on how to use them (as described by the author).
\begin_deeper
-\layout Verbatim
+\layout Standard
\size scriptsize
\size footnotesize
extern int asm_func( unsigned short, unsigned short);
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
The corresponding assembler function is:-
-\layout Verbatim
+\layout Standard
\size scriptsize
\layout Standard
Assemble the assembler routine with the following command.
-\layout Verbatim
+\layout Standard
asx8051 -losg asmfunc.asm
\layout Standard
Then compile and link the assembler routine to the C source file with the
following command,
-\layout Verbatim
+\layout Standard
sdcc cfunc.c asmfunc.rel
\layout Subsubsection
\size footnotesize
extern int asm_func( unsigned short, unsigned short);
-\layout Verbatim
+\layout Standard
\size footnotesize
\protected_separator
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
The corresponding assembler routine is.
-\layout Verbatim
+\layout Standard
\size scriptsize
asm_func
\series default
, which takes two parameters.
-\layout Verbatim
+\layout Standard
\size footnotesize
extern int asm_func( unsigned short, unsigned short);
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
The corresponding assembler function is:-
-\layout Verbatim
+\layout Standard
\size scriptsize
\layout Standard
Assemble the assembler routine with the following command.
-\layout Verbatim
+\layout Standard
asx8051 -losg asmfunc.asm
\layout Standard
Then compile and link the assembler routine to the C source file with the
following command,
-\layout Verbatim
+\layout Standard
sdcc cfunc.c asmfunc.rel
\layout Subsubsection
\size footnotesize
extern int asm_func( unsigned short, unsigned short);
-\layout Verbatim
+\layout Standard
\size footnotesize
\protected_separator
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
The corresponding assembler routine is.
-\layout Verbatim
+\layout Standard
\size scriptsize
parameters or assigned to each other and cannot be a return value from
a function.
\begin_deeper
-\layout Verbatim
+\layout Standard
\size small
eg
\end_deeper
-\layout Verbatim
+\layout Standard
\size small
\newline
}
-\layout Verbatim
+\layout Standard
\size small
\layout Enumerate
Old K&R style function declarations are NOT allowed.
-\layout Verbatim
+\layout Standard
\size footnotesize
functions declared as pointers must be dereferenced during the call.
\begin_deeper
-\layout Verbatim
+\layout Standard
\size small
int (*foo)();
\end_deeper
-\layout Verbatim
+\layout Standard
\size small
Large functions can have low complexity, and small functions can have large
complexity levels.
SDCC uses the following formula to compute the complexity.
-\layout Verbatim
+\layout Standard
\size small
reduce code size substantially.
Take the following code for example.
\begin_deeper
-\layout Verbatim
+\layout Standard
\size footnotesize
first then the modulus operation will be performed (this will lead to a
call to a support routine).
If the code is changed to
-\layout Verbatim
+\layout Standard
\size footnotesize
\layout Standard
the file name foo).
-\layout Verbatim
+\layout Standard
>sdcdb foo
\layout Standard
\layout Standard
Set breakpoint at specified line or function.
-\layout Verbatim
+\layout Standard
sdcdb>break 100
\newline
\layout Standard
Clear breakpoint at specified line or function.
-\layout Verbatim
+\layout Standard
sdcdb>clear 100
\newline
\layout Standard
The following is a list of key mapping for the debugger interface.
-\layout Verbatim
+\layout Standard
\protected_separator