\emph default
evice
\emph on
-C
-\emph default
-
-\emph on
-C
+CC
\emph default
ompiler) is free open source, retargettable, optimizing ANSI-C compiler
by
, an open source retargetable assembler & linker.
SDCC has extensive language extensions suitable for utilizing various microcont
rollers and underlying hardware effectively.
-
\newline
\newline
-In addition to the MCU specific optimizations SDCC also does a host of
- standard optimizations like:
+In addition to the MCU specific
+ optimizations SDCC also does a host of standard optimizations like:
\end_layout
\begin_layout Itemize
\begin_layout Standard
For the back-end SDCC uses a global register allocation scheme which should
be well suited for other 8 bit MCUs.
-
\newline
\newline
-The peep hole optimizer uses a rule based substitution mechanism which
- is MCU independent.
-
+The peep hole optimizer uses a rule
+ based substitution mechanism which is MCU independent.
\newline
\newline
-Supported data-types are:
+Supported data-types
+ are:
\end_layout
\begin_layout Standard
-cyclomatic) to report the relative complexity of a function.
These functions can then be further optimized, or hand coded in assembly
if needed.
-
\newline
\newline
\newline
The latest SDCC version can be downloaded from
-
\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
\end_inset
.
-
-\series bold
-
-\series default
\emph on
Please note: the compiler will probably always be some steps ahead of this
documentation
\end_inset
for ANSI-Compliance).
-
\begin_inset Note Note
status collapsed
\emph default
, see section above).
Further search paths are determined by environment variables during runtime.
-
\newline
-The paths searched when running the compiler are as follows (the first
- catch wins):
+The
+ paths searched when running the compiler are as follows (the first catch
+ wins):
\newline
\newline
\shape default
is auto-appended by the compiler (e.g.
small, large, z80, ds390 etc.).
-
\newline
\end_layout
bin_vc to sdcc
\backslash
bin before running SDCC.
-
\newline
\newline
-WARNING: Visual studio is very picky with line terminations; it expects
- the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
+WARNING: Visual studio is very picky with line terminatio
+ns; it expects the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix
+ style line endings.
When using the Subversion repository it's easiest to configure the svn
client to convert automatically for you.
If however you are getting a message such as "This makefile was not generated
\family sans
\series bold
find .
-
\backslash
( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
\backslash
file untouched in the source directory.
Simply copy it to the build directory, edit it, enter `make clean', `rm
Makefile.dep' and `make'.
-
\series bold
make
\series default
\end_inset
.
-
\newline
You'll find the pdf version
\begin_inset LatexCommand \index{PDF version of this document}
\end_inset
.
-
\newline
A html version
\begin_inset LatexCommand \index{HTML version of this document}
.
\newline
This documentation is in some aspects different from a commercial documentation:
-
\end_layout
\begin_layout Itemize
\family default
\series default
at the prompt, and the program should run and output its version like:
-
\newline
\family typewriter
\family sans
\series bold
"sdcc -c test.c".
-
\family default
-\series default
-
\series medium
If all goes well, the compiler will generate a test.asm and test.rel file.
Congratulations, you've just compiled your first program with SDCC.
.
If all goes well the compiler will link with the libraries and produce
a test.ihx output file.
- If this step fails
-\series default
-
-\series medium
-(no test.ihx, and the linker generates warnings), then the problem is most
- likely that
+ If this step fails(no test.ihx, and the linker generates warnings), then
+ the problem is most likely that
\series default
SDCC
\series medium
\series default
/
\series medium
-usr/local/share/sdcc/lib directory
-\series default
-
-\series medium
-(see
+usr/local/share/sdcc/lib directory(see
\series default
section
\begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
\series default
SDCC
\series medium
- cannot find the /usr/local/share/sdcc/include directory
-\series default
-
-\series medium
-(see the
+ cannot find the /usr/local/share/sdcc/include directory(see the
\series default
section
\begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
At the time of this writing, we find the following programs for gcc-builds:
\newline
-
\newline
-In <installdir>/bin:
+In
+ <installdir>/bin:
\end_layout
\begin_layout Itemize
which is generated by SDCC might include lines of varying length and the
addresses within the file are not guaranteed to be strictly ascending.
If your toolchain or a bootloader does not like this you can use the tool
-
\family typewriter
packihx
\family default
of various flavours (crc, add, xor) and to perform other manipulations
(convert, split, crop, offset, ...).
-
\newline
\newline
\size default
The first two files will need to be compiled separately with the commands:
-\size footnotesize
-
-\size default
-
\newline
\newline
main()
\emph default
function
-\emph on
-
-\emph default
\noun on
must
\noun default
\end_inset
-\size large
-\bar under
-
\series default
-\size default
-\bar default
Like `-M' but the output mentions only the user header files included with
`#include
\begin_inset Quotes eld
\end_inset
-\size large
-\bar under
-
\series default
-\size default
-\bar default
Like `-dD' except that the macro arguments and contents are omitted.
Only `#define name' is included in the output.
\end_layout
\end_inset
-\bar under
-
\series default
-\bar default
The linker output (final object code) is in Intel Hex format.
\begin_inset LatexCommand \index{Intel hex format}
\end_inset
-\bar under
-
\series default
-\bar default
The linker output (final object code) is in Motorola S19 format
\begin_inset LatexCommand \index{Motorola S19 format}
\end_inset
-\bar under
-
\series default
-\bar default
The linker output (final object code) is in ELF format
\begin_inset LatexCommand \index{ELF format}
\series default
-\size large
-\emph on
-
-\size default
-\emph default
Generate code for Small Model programs, see section Memory Models for more
details.
This is the default model.
\end_inset
-
-\size large
-\emph on
-
-\size default
-\emph default
Generate 24-bit flat mode code.
This is the one and only that the ds390 code generator supports right now
and is default when using
\series default
<nnnn> LibraryID used in -mTININative.
-
\end_layout
\begin_layout List
\series default
generate code for DS390 Arithmetic Accelerator.
-
\end_layout
\begin_layout Standard
\end_inset
-
-\size large
-\emph on
-
-\size default
-\emph default
Force a called function to always save BC.
\end_layout
\end_inset
-
-\size large
-\emph on
-
-\size default
-\emph default
Force a called function to always save BC.
\end_layout
\end_inset
-\size large
-\bar under
-
\series default
-\size default
-\bar default
Will not generate boundary condition check when switch statements
\begin_inset LatexCommand \index{switch statement}
\series default
-\size large
-
-\size default
Will not do loop reversal
\begin_inset LatexCommand \index{Loop reversing}
The output path where everything will be placed or the file name used for
all generated output files.
If the parameter is a path, it must have a trailing slash (or backslash
- for the Windows binaries) to be recognized as a path.
-
-\emph on
-
-\emph default
-Note for Windows users: if the path contains spaces, it should be surrounded
- by quotes.
+ for the Windows binaries) to be recognized as a path.Note for Windows users:
+ if the path contains spaces, it should be surrounded by quotes.
The trailing backslash should be doubled in order to prevent escaping the
final quote, for example:
\emph on
\emph default
.
The path using slashes for directory delimiters can be used too, for example:
-
\emph on
-o
\begin_inset Quotes sld
\series default
-\size large
-\emph on
-
-\size default
-\emph default
All functions in the source file will be compiled as
\emph on
reentrant
\series default
-float-reent.
-
\end_layout
\begin_layout List
\series default
-Function of
-\series bold
-
-\series default
--
+Function of-
\begin_inset ERT
status collapsed
\end_inset
-\bar under
-
\series default
-\bar default
When this option is used the compiler will generate debug information.
The debug information collected in a file with .cdb extension can be used
with the SDCDB.
\end_inset
-\size large
-\bar under
-
\series default
-\size default
-\bar default
Stop after the stage of compilation proper; do not assemble.
The output is an assembler code file for the input file specified.
\end_layout
\end_inset
-\bar under
-
\series default
-\bar default
This option will cause the compiler to generate an information message for
each function in the source file.
The message contains some
.
To make your source files parseable by splint you will have to include
-
\family sans
lint.h
\family default
\family default
).
-
\newline
Splint has an excellent on line manual at
\begin_inset LatexCommand \url{http://www.splint.org/manual/}
\series default
-\size large
-
-\size default
Will create a dump of iCodes, after loop optimizations
\begin_inset LatexCommand \index{Loop optimization}
\series default
-\size large
-
-\size default
Will create a dump of iCodes, after live range analysis
\begin_inset LatexCommand \index{Live range analysis}
\end_inset
-\bar under
-
\series default
-\bar default
Will create a dump of iCodes, after register assignment
\begin_inset LatexCommand \index{Register assignment}
\end_inset
-\size large
-\bar under
-
\series default
-\size default
-\bar default
Will cause all the above mentioned dumps to be created.
\end_layout
\begin_layout Standard
The bit addressable memory consists of 128 bits which are located from 0x20
to 0x2f in data memory.
-
\newline
-Apart from this 8051 specific storage class most architectures support
- ANSI-C bitfields
+Apart from this 8051 specific storage class most
+ architectures support ANSI-C bitfields
\begin_inset LatexCommand \index{bitfields}
\end_inset
sfr / sfr16 / sfr32 / sbit
\emph default
signify both a data-type and storage class, they are used to describe the
-
\emph on
s
\emph default
\end_inset
.
-
\family default
Nevertheless it is possible to write header files
\begin_inset LatexCommand \index{Header files}
\end_inset
).
-
\end_layout
\begin_layout Subsubsection
\begin_layout Standard
Well you get the idea.
-
\newline
\newline
-All unqualified pointers are treated as 3-byte (4-byte for the ds390)
+All unqualified pointers are treated as 3-byte (4-byte
+ for the ds390)
\emph on
generic
\emph default
pointers.
-
\size small
\newline
banks of registers (keyword
\emph on
using
-\emph default
-
-\emph on
-
\begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
\end_inset
idata
\emph default
).
-
\newline
\end_layout
sfr at 0x78 IoPort;\InsetSpace ~
\InsetSpace ~
/* define a var in I/O space at 78h called IoPort */
-
\end_layout
\begin_layout Standard
The xdata storage class declares a variable that can reside anywhere in
memory.
This is the default if no storage class is specified.
-
\begin_inset VSpace bigskip
\end_inset
*/
\newline
unsigned char spi_io(unsigned char out_byte)
-
\newline
{
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-unsigned char i=8;
+un
+signed char i=8;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-MCLK =
- 1;
+MCLK = 1;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-/* _asm nop _endasm; */\InsetSpace ~
+/* _asm
+ nop _endasm; */\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-out_byte +=
- 1;
+out_byte += 1;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-} while(--i);
+}
+ while(--i);
\newline
\InsetSpace ~
\InsetSpace ~
\end_inset
.
-
\newline
\newline
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
\newline
\newline
-void
- some_isr () __interrupt
+void some_isr
+ () __interrupt
\begin_inset LatexCommand \index{interrupt}
\end_inset
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
\emph default
can be used to tell the compiler to use the specified register bank when
generating code for this function.
-
\newline
-Interrupt service routines open the door for some very interesting bugs:
+Interrupt service routines open the door
+ for some very interesting bugs:
\end_layout
\begin_layout Subsubsection
the processor needs more than one instruction for the access and could
be interrupted while accessing the variable) the interrupt must be disabled
during the access to avoid inconsistent data.
-
\newline
-Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
- and should be protected by disabling interrupts.
+Access to 16 or 32 bit variables
+ is obviously not atomic on 8 bit CPUs and should be protected by disabling
+ interrupts.
You're not automatically on the safe side if you use 8 bit variables though.
We need an example here: f.e.
on the 8051 the harmless looking
from within an interrupt routine might get lost if the interrupt occurs
at the wrong time.
-
\begin_inset Quotes sld
\end_inset
\newline
Bugs like these are hard to reproduce and can
cause a lot of trouble.
-
\end_layout
\begin_layout Subsubsection
\end_inset
compiler option.
-
\newline
Note, the type promotion
\begin_inset LatexCommand \index{type promotion}
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
\emph default
register.
-
\end_layout
\begin_layout Standard
\end_inset
and don't add complexity unless you have to.
-
\end_layout
\begin_layout Subsection
\end_inset
- bit test and
-\emph on
-
-\emph default
-clear
-\emph on
-
-\emph default
-instruction.
+ bit test andclearinstruction.
These type of instructions are typically used in preemptive multitasking
systems, where a routine f.e.
claims the use of a data structure ('acquires a lock
\end_inset
don't have to be disabled for the locking operation.
-
\end_layout
\begin_layout Standard
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-resource_is_free=1;
+resource_is_free=
+1;
\newline
\InsetSpace ~
\InsetSpace ~
\emph default
using
\emph on
- attribute has an effect on
-\emph default
-
-\emph on
-the generated code for a
+ attribute has an effect onthe generated code for a
\emph default
non-interrupt
\emph on
called functions use bank zero.
It is very inefficient to call a function using a different, non-zero bank
from an ISR.
-
\begin_inset VSpace bigskip
\end_inset
\end_inset
-\series bold
\emph default
-
-\series default
at the start of the CODE area.
This routine is also in the runtime library
\begin_inset LatexCommand \index{Runtime library}
\end_inset
and provide your own crt0.o.
-
\begin_inset VSpace bigskip
\end_inset
ret
\newline
00106$:
-
\newline
-;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
+;buffer.c
+ buf[ head++ ] = c; /* access to a 256 byte aligned array */
\begin_inset LatexCommand \index{Aligned array}
\end_inset
\InsetSpace ~
\InsetSpace ~
movx @dptr,a
-
\newline
00103$:
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-_endasm
+_end
+asm
\begin_inset LatexCommand \index{\_endasm}
\end_inset
\InsetSpace ~
\InsetSpace ~
; save used registers here.
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-; If we were still using r2,r3 we would have to push them here.
-
+; If we were still using r2,r3 we would have to
+ push them here.
\newline
; if( head != (unsigned char)(tail-1) )
\newline
\InsetSpace ~
\InsetSpace ~
xrl\InsetSpace ~
+
a,_head
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-; we
- could do an ANL a,#0x0f here to use a smaller buffer (see below)
+; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
jz\InsetSpace ~
\InsetSpace ~
+
t_b_end$
\newline
\InsetSpace ~
\InsetSpace ~
;
\newline
-;
- buf[ head++ ] = c;
+; buf[ head++ ] = c;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-; dpl holds lower byte of function argument
+; dpl holds lower byte of function
+ argument
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
mov\InsetSpace ~
-
dpl,_head \InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-mov\InsetSpace ~
- dph,#(_bu
-f>>8)
+m
+ov\InsetSpace ~
+ dph,#(_buf>>8)
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-; we could do an ANL _head,#0x0f here to use a
- smaller buffer (see above)
+; we could do an ANL _head,#0x0f here
+ to use a smaller buffer (see above)
\newline
t_b_end$:
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-_endasm
+_endas
+m
\begin_inset LatexCommand \index{\_endasm}
\end_inset
\end_inset
has to be done manually.
-
\end_layout
\begin_layout Standard
\end_inset
.
-
\emph default
The
\emph on
SDCC allows the use of in-line assembler with a few restrictions regarding
labels.
All labels defined within inline assembler code have to be of the form
-
\emph on
nnnnn$
\emph default
\InsetSpace ~
\InsetSpace ~
_endasm;
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-/* some more c code */
+/* some
+ more c code */
\newline
clabel:\InsetSpace ~
\InsetSpace ~
-/* inline assembler cannot reference this
- label */
+/* inline assembler cannot reference this label */
\begin_inset Foot
status open
\end_inset
of function; according to the following scheme: one byte return value in
-
\emph on
DPL
\emph default
_using
\family default
modifier).
-
\end_layout
\begin_layout Standard
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-.ds
- 1
+.ds 1
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-.area CSEG
+.area
+ CSEG
\newline
_asm_func:
\newline
c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
\newline
{
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-return asm_func(i,j,k);
+return
+ asm_func(i,j,k);
\newline
}
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-;stack contains: _bp, return
- address, second parameter, third parameter
+;stack contains: _bp, return address,
+ second parameter, third parameter
\newline
\InsetSpace ~
\InsetSpace ~
not
\emph default
sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
-
\end_layout
\end_inset
\family default
-
\emph on
instead
\emph default
-model-large
\emph default
option, variables will by default be placed into the XDATA segment.
-
\newline
\newline
-Segments may be placed anywhere in the 4 meg address space using the usual
- -
+Segments
+ may be placed anywhere in the 4 meg address space using the usual -
\begin_inset ERT
status collapsed
\end_inset
.
-
\newline
More specifically, the following warnings will be disabled:
\shape italic
function '[function name]' must return value
\shape default
(59).
-
\newline
Furthermore, warnings of less importance (of PEDANTIC and INFO warning
level) are disabled, too, namely:
- The compiler will attempt to generate code that is both compact and fast,
as long as meeting one goal is not a detriment to the other (this is the
default).
-
\end_layout
\begin_layout Itemize
\end_inset
.
-
\newline
Below is an example on how to use this pragma.
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\newline
This usually happens in large functions.
Pragma directives should be used as shown in the following example, they
are used to control options and optimizations for a given function.
-
\end_layout
\begin_layout Verse
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\newline
\InsetSpace ~
\InsetSpace ~
- ...
+ ...
\newline
}
\newline
flavours.
While they might differ considerably in respect to Special Function Registers
the core MCS51 is usually not modified or is kept compatible.
-
\end_layout
\begin_layout Subsection
\end_inset
.
-
\begin_inset VSpace bigskip
\end_inset
These files primarily define SFRs, structs to access their bits, and symbolic
configuration options.
Both files can be generated from gputils' .inc files using the perl script
-
\family typewriter
support/scripts/inc2h.pl
\family default
\newline
$(PRJ).hex: $(OBJS)
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
+mplink
+ /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
\end_layout
\begin_layout Standard
The PIC14 port uses library routines to provide more complex operations
like multiplication, division/modulus and (generic) pointer dereferencing.
In order to add these routines to your project, you must link with PIC14's
-
\family typewriter
libsdcc.lib
\family default
\labelwidthstring 00.00.0000
2 tries to check the location of (even different) symbols and removes BANKSELs
if they are in the same bank.
-
\newline
\emph on
of bitfields.
(i.e., 80 bytes of code space are saved when compiling malloc.c with this
option).
-
\end_layout
\begin_layout Description
\begin_layout Standard
MCU Identification.
-
\emph on
xxxx
\emph default
\begin_layout Standard
MCU Identification.
-
\emph on
xxxx
\emph default
keyword).
In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
in a user-friendly way.
-
\emph on
arg
\emph default
\labelwidthstring 00.00.0000
DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
high priority interrupts.
-
\emph on
name
\emph default
\labelwidthstring 00.00.0000
DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
low priority interrupt.
-
\emph on
name
\emph default
\end_inset
) on how to handle syntax extensions like __xdata, __at(), ...
-
\end_layout
\begin_layout Itemize
via a serial line and allows to set program counter, to single step through
a program and read/write memory locations.
For the 8051 good examples of monitors are paulmon and cmon51 (see section
-
\begin_inset LatexCommand \ref{sec:Related-open-source-tools}
\end_inset
Usually very expensive.
And very nice to have too.
And usually locks you (for years...) to the devices the ICE can emulate.
-
\end_layout
\begin_layout Itemize
and a complete debugger is too bulky for the target system.
Therefore usually a debugger on the host system connects to an on-target
debugging stub which accepts only primitive commands.
-
\newline
-Terms to enter into your favourite search engine could be 'remote debugging',
- 'gdb stub' or 'inferior debugger'.
+Terms to enter into
+ your favourite search engine could be 'remote debugging', 'gdb stub' or
+ 'inferior debugger'.
(is there one?)
\end_layout
Some of the more modern MCUs include hardware support for setting break
points and monitoring/changing variables by using dedicated hardware pins.
This facility doesn't require additional code to run on the target and
-
\emph on
usually
\emph default
\end_inset
) as input file.
-
\end_layout
\begin_layout Standard
-directory=/home/src1:/home/src2.
Note there can be no spaces in the option.
-
\end_layout
\begin_layout Itemize
The debugging session might not run as smoothly as the screenshot suggests.
The debugger allows setting of breakpoints, displaying and changing variables,
single stepping through C and assembler code.
-
\newline
The source was compiled with
\family sans
\family sans
\series bold
-debug ddd_example.c
-\family default
-\series default
-
-\family sans
-\series bold
-
\newline
\family default
\newline
You will prompted to enter the file name to be debugged.
-
\newline
\newline
-The command line options that are passed to the simulator directly are
- bound to default values in the file sdcdbsrc.el.
+The command line
+ options that are passed to the simulator directly are bound to default
+ values in the file sdcdbsrc.el.
The variables are listed below, these values maybe changed as required.
\end_layout
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdcdb-next-fro
-m-src\InsetSpace ~
+sdcdb-next-from-s
+rc\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdcdb-cont-f
-rom-src\InsetSpace ~
+sdcdb-cont-from-s
+rc\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdcdb-w
-hatis-c-sexp\InsetSpace ~
+sdcdb-whatis-
+c-sexp\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-SDCD
-B Delete all breakpoints if no arg
+SDCDB
+ Delete all breakpoints if no arg
\newline
;;\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdcdbsrc
--frame\InsetSpace ~
+sdcdbsrc-fr
+ame\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
given or display frame arg
-
\newline
;;\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-buffer point
+buffer
+ point
\newline
;;\InsetSpace ~
!\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdcdb-prin
-t-c-sexp\InsetSpace ~
+sdcdb-print-c-sexp\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-SDCDB print command for data at
+SDC
+DB print command for data at
\newline
;;\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-Got
-o the SDCDB output buffer
+Goto the
+ SDCDB output buffer
\newline
;;\InsetSpace ~
t\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-Toggles Sdcdbsrc mode (turns it
- off)
+Toggles Sdcdbsrc mode (turns it off)
\newline
;;
\newline
;;\InsetSpace ~
C-c\InsetSpace ~
-C-f\InsetSpace ~
+C
+-f\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdcdb-brea
-k\InsetSpace ~
+sdcdb-break\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-Set break for line with point
+Set break
+ for line with point
\newline
;;\InsetSpace ~
ESC\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-sdc
-dbsrc-srcmode\InsetSpace ~
+sdcdbsrc-srcmod
+e\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
(int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
\family default
.
-
\newline
Another one:
\end_layout
last
\emph default
relate to time and not to lower/upper memory location here, so this is
-
\emph on
not
\emph default
You can help by reporting the bugs and helping other SDCC users.
There are lots of ways to contribute, and we encourage you to take part
in making SDCC a great software package.
-
\end_layout
\begin_layout Standard
\begin_layout Enumerate
Attach the code you are compiling with SDCC.
-
\end_layout
\begin_layout Enumerate
Specify the exact command you use to run SDCC, or attach your Makefile.
-
\end_layout
\begin_layout Enumerate
\family default
\series default
"), your platform, and operating system.
-
\end_layout
\begin_layout Enumerate
Provide an exact copy of any error message or incorrect output.
-
\end_layout
\begin_layout Enumerate
\end_inset
-\series default
-
\family default
+\series default
will do.
\end_layout
number.
Subversion allows to download the source of recent or previous versions
-
\begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
\end_inset
You'll find some small examples in the directory
\emph on
sdcc/device/examples/.
-
\emph default
More examples and libraries are available at
\emph on
make
\family default
in this directory (or f.e.
-
\family sans
\series bold
\end_inset
.
-
\newline
And if there should be a shortage of ideas then you can always point students
to the ever-growing feature request list
\begin_layout Standard
SDCC performs a host of standard optimizations in addition to some MCU specific
optimizations.
-
\end_layout
\begin_layout Subsection
\InsetSpace ~
\InsetSpace ~
global = 1;\InsetSpace ~
-/* dead
- store */
+/* dead store
+ */
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-itemp1
- += 5;
+itemp1 +=
+ 5;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
i >>= 1;
\newline
-i
- = j - j;\InsetSpace ~
+i =
+ j - j;\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 0: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 1: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-case 3: ...
-
+case
+ 3: ...
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 4: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 5: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 6: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 7: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-case 11: ...\InsetSpace ~
+case
+ 11: ...\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
case 8: ...
-
\newline
}\InsetSpace ~
\InsetSpace ~
If the case labels are not in numerical sequence ('gaps' between cases)
SDCC checks whether a jump table with additionally inserted dummy cases
is still attractive.
-
\end_layout
\begin_layout Itemize
\InsetSpace ~
\InsetSpace ~
case 1: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 2: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 3: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 4: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 5: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 6: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 7: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
-case 101: ...
-
+case
+ 101: ...
\newline
\InsetSpace ~
\InsetSpace ~
case 102: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 103: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 104: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 105: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 106: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 107: ...
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
case 1: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 2: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 3: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 4: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 5: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 6: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 7: ...
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
case 101: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 102: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 103: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 104: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
case 105: ...
-
\newline
\InsetSpace ~
\InsetSpace ~
-case 106: ...
-
+case 106:
+ ...
\newline
\InsetSpace ~
\InsetSpace ~
case 107: ...
-
\newline
}
\end_layout
unsigned char i;
\newline
...
-
\newline
i >>= 4;
\newline
unsigned int i;
\newline
...
-
\newline
i >>= 9;
\newline
/* unsigned is needed for rotation */
\newline
...
-
\newline
i = ((i << 1) | (i >> 7));
\family default
int j;
\newline
...
-
\newline
i = ((i << 4) | (i >> 4));
\family default
\end_inset
--datapointer
-\emph on
-
-\emph default
-so little-endian is the more efficient byte order.
+-datapointerso little-endian is the more efficient byte order.
\end_layout
\end_inset
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
hob3 = gint & 0x8000;
-
\newline
\InsetSpace ~
\InsetSpace ~
-aob1 = (gint >> 9) & 1;
+aob1
+ = (gint >> 9) & 1;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
..
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-
64\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
+
anl\InsetSpace ~
\InsetSpace ~
a,#0x01
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-
67\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
mov\InsetSpace ~
\InsetSpace ~
+
a,(_gint + 1)
\newline
0013 33\InsetSpace ~
mov\InsetSpace ~
\InsetSpace ~
_foo_hob2_1_1,c
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
66 ;\InsetSpace ~
- hob.c 9
+ hob.c
+ 9
\newline
0016 E5*01\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-
69\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
mov\InsetSpace ~
\InsetSpace ~
- _foo_hob3_1_1,c
+ _foo_hob3_1_1
+,c
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
a,(_gint + 1)
\newline
-001D
- 03\InsetSpace ~
+001D 03\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
+
73\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
mov\InsetSpace ~
\InsetSpace ~
_foo_aob1_1_1,a
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
+
76\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-
78\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
- 79 ;\InsetSpace ~
+ 79
+ ;\InsetSpace ~
hob.c 12
\newline
0027 E5*01\InsetSpace ~
\InsetSpace ~
a,(_gint + 1)
\newline
-0029
- A2 E3\InsetSpace ~
+0029 A2 E3\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
c,acc[3]
\newline
-002B 92*03\InsetSpace ~
+002B
+ 92*03\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\newline
\InsetSpace ~
\InsetSpace ~
-unsigned char hob1,
- hob2;
+unsigned char hob1, hob2;
\newline
\InsetSpace ~
\InsetSpace ~
-unsigned int how1, how2;
+unsig
+ned int how1, how2;
\newline
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\newline
\InsetSpace ~
\InsetSpace ~
-how1 = (glong >> 16) & 0xFFFF;
-
+how1 = (glong
+ >> 16) & 0xFFFF;
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
..
-
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
93 ;\InsetSpace ~
- hob.c
- 16
+ hob.c 16
\newline
-003A 85*05*07\InsetSpace ~
+003A
+ 85*05*07\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-
96\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
+
mov\InsetSpace ~
\InsetSpace ~
_foo_how1_1_1,(_glong + 2)
\InsetSpace ~
mov\InsetSpace ~
\InsetSpace ~
- (_foo_how1_1_1 +
- 1),(_glong + 3)
+ (_foo_how1_1_1 + 1),(_glong
+ + 3)
\newline
0043 85*03*0A\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-
99\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
mov\InsetSpace ~
\InsetSpace ~
+
(_foo_how2_1_1 + 1),(_glong + 2)
\end_layout
\begin_layout Standard
The optimizer does a look-up of a function name table defined in function
-
\emph on
callFuncByName
\emph default
\begin_layout Standard
The latest publically available version of the standard
\emph on
-ISO/IEC 9899 - Programming languages - C
+ ISO/IEC 9899 - Programming languages - C
\emph default
should be available at:
\begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
+s1 = s2 ; /* is invalid in SDCC although allowed
+ in ANSI */
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\newline
\InsetSpace ~
\InsetSpace ~
struct s rets;
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
...
-
\newline
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
\InsetSpace ~
-return rets; /* is invalid in SDCC although allowed in ANSI */
+return
+ rets; /* is invalid in SDCC although allowed in ANSI */
\newline
}
\end_layout
\InsetSpace ~
\InsetSpace ~
...
-
\newline
}
\end_layout
Certain words that are valid identifiers in the standard may be reserved
words in SDCC unless the
\series bold
--
+ -
\begin_inset ERT
status collapsed
'__data' instead of 'data'.
\end_layout
+\begin_layout Itemize
+integer promotion of variable arguments is not performed if the argument
+ is explicitly taypecasted unless the
+\series bold
+ -
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-std-c89
+\begin_inset LatexCommand \index{-\/-std-c89}
+
+\end_inset
+
+ or -
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-std-c99
+\begin_inset LatexCommand \index{-\/-std-c99}
+
+\end_inset
+
+
+\series default
+ command line options are used.
+\end_layout
+
+\begin_deeper
+\begin_layout Verse
+
+\family typewriter
+void vararg_func (char *str, ...) { atr; }
+\newline
+
+\newline
+void main (void)
+\newline
+{
+\newline
+\InsetSpace ~
+\InsetSpace ~
+char c = 10;
+\newline
+
+\newline
+\InsetSpace ~
+\InsetSpace ~
+/* argument
+ u is promoted to int before
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+* passing to function */
+\newline
+\InsetSpace ~
+\InsetSpace ~
+vararg_func (
+\begin_inset Quotes sld
+\end_inset
+
+%c
+\begin_inset Quotes srd
+\end_inset
+
+, c);
+\newline
+
+\newline
+\InsetSpace ~
+\InsetSpace ~
+/* argument u is not promoted to int,
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+* it is passed as char to function
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+*
+ if --std-cXX is not defined;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+* is promoted to int before passing
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+* to function
+ if --std-cXX is defined */
+\newline
+\InsetSpace ~
+\InsetSpace ~
+vararg_func (
+\begin_inset Quotes sld
+\end_inset
+
+%bc
+\begin_inset Quotes srd
+\end_inset
+
+, (char)u);
+\newline
+}
+\end_layout
+
+\end_deeper
\begin_layout Section
Cyclomatic Complexity
\begin_inset LatexCommand \index{Cyclomatic complexity}
code in a function.
Large functions can have low complexity, and small functions can have large
complexity levels.
-
\newline
\newline
The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
It is fairly easy to retarget for other 8-bit MCU.
Here we take a look at some of the internals of the compiler.
-
\end_layout
\begin_layout Paragraph*
basic block being processed, if there are any found then it will push that
operand and use the registers in this block, the operand will then be popped
at the end of the basic block.
-
\end_layout
\begin_layout Standard
example, the z80 port does not use registers to pass parameters so the
SEND and RECV iCode operations will not be generated, and it also does
not support JUMPTABLES.
-
\newline
\end_layout
\shape slanted
\size footnotesize
see f.e.
-
\family typewriter
gen51Code()
\family default
\newline
14.\InsetSpace ~
\InsetSpace ~
-/* compiler detects i,j to be induction
- variables */
+/* compiler detects i,j to be induction variables
+ */
\newline
15.\InsetSpace ~
\InsetSpace ~
\end_inset
of their respective companies.
-
\end_layout
\begin_layout Section*