\lyxformat 221
\textclass book
\begin_preamble
-
-
+\pdfoptionpdfminorversion=3
\usepackage[
pdftitle={SDCC Compiler User Guide},
pdfauthor={SDCC development team},
pdfsubject={installation, user manual},
- pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
- embedded, GPL, HC08, manual, mcs51, PIC, Z80},
+ pdfkeywords={8032 8051 ansi c compiler CPU DS390
+ embedded GPL HC08 manual mcs51 microcontroller PIC Z80},
colorlinks=true,
linkcolor=blue] {hyperref}
%
\size normal
-SDCC 2.4.8
+SDCC 2.5.4
\size footnotesize
\newline
\end_inset
-, etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
+, etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
+ Zilog Z80 based MCUs.
It can be retargetted for other microprocessors, support for Microchip
PIC, Atmel AVR is under development.
The entire source code for the compiler is distributed under GPL.
\newline
SDCC also comes with a companion source level debugger SDCDB, the debugger
currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
+ SDCDB and ucSim are currently not available on Win32 platforms.
\newline
\layout Section
Compatibility with previous versions
+\begin_inset LatexCommand \index{Compatibility with previous versions}
+
+\end_inset
+
+
\layout Standard
This version has numerous bug fixes compared with the previous version.
\layout Itemize
short is now equivalent to int (16 bits), it used to be equivalent to char
- (8 bits) which is not ANSI compliant
+ (8 bits) which is not ANSI compliant.
\layout Itemize
the default directory for gcc-builds where include, library and documentation
- files are stored is now in /usr/local/share
+ files are stored is now in /usr/local/share.
\layout Itemize
char type parameters to vararg functions are casted to int unless explicitly
/
\end_inset
--regextend has been removed
+-regextend has been removed.
\layout Itemize
option -
/
\end_inset
--noregparms has been removed
+-noregparms has been removed.
\layout Itemize
option -
/
\end_inset
--stack-after-data has been removed
+-stack-after-data has been removed.
+\layout Itemize
+
+bit
+\begin_inset LatexCommand \index{bit}
+
+\end_inset
+
+ and sbit
+\begin_inset LatexCommand \index{sbit}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sbit}
+
+\end_inset
+
+ types now consistently behave like the C99 _Bool type with respect to type
+ conversion
+\begin_inset LatexCommand \index{type conversion}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{type promotion}
+
+\end_inset
+
+.
+ The most common incompatibility resulting from this change is related to
+ bit toggling
+\begin_inset LatexCommand \index{Bit toggling}
+
+\end_inset
+
+ idioms, e.g.:
+\newline
+
+\family typewriter
+\SpecialChar ~
+\SpecialChar ~
+bit b;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+b = ~b; /* equivalent to b=1 instead of toggling b */
+\newline
+\SpecialChar ~
+\SpecialChar ~
+b = !b; /* toggles b */
+\newline
+
+\family default
+In previous versions, both forms would have toggled the bit.
\layout Standard
\family typewriter
-code banking
-\begin_inset LatexCommand \index{code banking (not supported)}
+better code banking
+\begin_inset LatexCommand \index{code banking (limited support)}
\end_inset
\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.
- If you are getting a message such as "This makefile was not generated by
- Developer Studio etc.
+ When using the CVS repository it's easiest to configure the cvs client
+ to convert automatically for you.
+ If however you are getting a message such as "This makefile was not generated
+ by Developer Studio etc.
etc.
\begin_inset Quotes srd
\end_inset
from the sdcc directory.
\layout Subsection
-Windows Install Using a Binary Package
-\begin_inset LatexCommand \label{sub:Windows-Install}
-
-\end_inset
-
-
+Windows Install Using a ZIP Package
\layout Enumerate
-Download the binary package from
-\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
+Download the binary zip package from
+\begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
\end_inset
Adjust your environment variable PATH to include the location of the bin
directory or start sdcc using the full path.
+\layout Subsection
+
+Windows Install Using the Setup Program
+\begin_inset LatexCommand \label{sub:Windows-Install}
+
+\end_inset
+
+
+\layout Standard
+
+Download the setup program
+\emph on
+sdcc-x.y.z-setup.exe
+\emph default
+ for an official release from
+\newline
+
+\begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
+
+\end_inset
+
+ or a setup program for one of the snapshots
+\emph on
+sdcc_yyyymmdd_setup.exe
+\emph default
+ from
+\begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
+
+\end_inset
+
+ and execute it.
+ A windows typical installer will guide you through the installation process.
\layout Section
Building the Documentation
You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
x).
Using LyX
-\begin_inset LatexCommand \url{www.lyx.org}
+\begin_inset LatexCommand \url{http://www.lyx.org}
\end_inset
as editor this is straightforward.
Prebuilt documentation in html and pdf format is available from
-\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
+\begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
\end_inset
\end_inset
.
- You'll find the pdf version at
-\begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
+
+\newline
+You'll find the pdf version
+\begin_inset LatexCommand \index{PDF version of this document}
+
+\end_inset
+
+ at
+\begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
+
+\end_inset
+
+.
+
+\newline
+A html version
+\begin_inset LatexCommand \index{HTML version of this document}
+
+\end_inset
+
+ should be online at
+\begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
\end_inset
Don't let this distract you.
If there f.e.
was a reference like
-\begin_inset LatexCommand \url{www.opencores.org}
+\begin_inset LatexCommand \url{http://www.opencores.org}
\end_inset
\layout Itemize
s51 - The ucSim 8051 simulator.
+ Not available on Win32 platforms.
\layout Itemize
sdcdb - The source debugger.
+ Not available on Win32 platforms.
\layout Itemize
packihx - A tool to pack (compress) Intel hex files.
\end_inset
- is a freeware, opensource simulator developed by Daniel Drotos (
-\begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
-
-\end_inset
-
-).
+ is a freeware, opensource simulator developed by Daniel Drotos.
The simulator is built as part of the build process.
For more information visit Daniel's web site at:
\begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
.
It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
XA51 family.
+ S51 is currently not available on Win32 platfors.
\layout Subsection
sdcdb - Source Level Debugger
\end_inset
, but can be easily changed to use other simulators.
-
+ Sdcdb is currently not available on Win32 platfors.
\layout Chapter
Using SDCC
\family default
\shape default
-\begin_inset LatexCommand \index{srecord (tool)}
+\begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
\end_inset
).
Both formats are documented in the documentation of srecord
-\begin_inset LatexCommand \index{srecord (tool)}
+\begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
\end_inset
\end_inset
-debug) containing debug information.
- The format is documented in cdbfileformat.pdf.
+ The format is documented in cdbfileformat.pdf
\layout Itemize
sourcefile.
\series default
- Generate code for the Motorola HC08
+ Generate code for the Freescale/Motorola HC08
\begin_inset LatexCommand \index{HC08}
\end_inset
- family of processors (added Oct 2003).
+ family of processors.
\layout List
\labelwidthstring 00.00.0000
\end_inset
processor (In development, not complete).
- AVR users should probably have a look at avr-gcc
-\begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
+ AVR users should probably have a look at winavr
+\begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
\end_inset
- or winavr
-\begin_inset LatexCommand \url{http://winavr.sourceforge.net}
+ or
+\begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
\end_inset
The provided value should not overlap any other memory areas such as used
register banks or the data segment and with enough space for the current
application.
+ The
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-pack-iram
+\series default
+\SpecialChar ~
+
+\begin_inset LatexCommand \index{-\/-pack-iram}
+
+\end_inset
+
+ option (which is now a default setting) will override this setting, so
+ you should also specify the
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-no-pack-iram
+\series default
+\SpecialChar ~
+
+\begin_inset LatexCommand \index{-\/-no-pack-iram}
+
+\end_inset
+
+ option if you need to manually place the stack.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-xstack-loc
+\series default
+
+\begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
+
+\end_inset
+
+\SpecialChar ~
+<Value> By default the external stack
+\begin_inset LatexCommand \index{xstack}
+
+\end_inset
+
+ is placed after the pdata segment.
+ Using this option the xstack can be placed anywhere in the external memory
+ space of the 8051.
+ The value entered can be in Hexadecimal or Decimal format, e.g.
+ -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-xstack-loc 0x8000 or -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-stack-loc 32768.
+ The provided value should not overlap any other memory areas such as the
+ pdata or xdata segment and with enough space for the current application.
\layout List
\labelwidthstring 00.00.0000
This is the default option.
The format itself is documented in the documentation of srecord
-\begin_inset LatexCommand \index{srecord (tool)}
+\begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
\end_inset
\labelwidthstring 00.00.0000
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-out-fmt-elf
+\begin_inset LatexCommand \index{-\/-out-fmt-s19}
+
+\end_inset
+
+
+\bar under
+
+\series default
+\bar default
+The linker output (final object code) is in ELF format
+\begin_inset LatexCommand \index{ELF format}
+
+\end_inset
+
+.
+ (Currently only supported for the HC08 processors)
+\layout List
+\labelwidthstring 00.00.0000
+
+
\series bold
-Wl\SpecialChar ~
linkOption[,linkOption]
\labelwidthstring 00.00.0000
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-model-medium
+\begin_inset LatexCommand \index{-\/-model-medium}
+
+\end_inset
+
+
+\series default
+ Generate code for Medium model programs, see section Memory Models for
+ more details.
+ If this option is used all source files in the project have to be compiled
+ with this option.
+ It must also be used when invoking the linker.
+\layout List
+\labelwidthstring 00.00.0000
+
+
\series bold
-
\begin_inset ERT
details.
If this option is used all source files in the project have to be compiled
with this option.
+ It must also be used when invoking the linker.
\layout List
\labelwidthstring 00.00.0000
\series default
\SpecialChar ~
-\begin_inset LatexCommand \index{-\/-pack-iram}
+\begin_inset LatexCommand \index{-\/-no-pack-iram}
\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.
+ temporaries (
+\emph on
+s
+\emph default
+pill
+\emph on
+loc
+\emph default
+ations, sloc
+\begin_inset LatexCommand \index{sloc (spill location)}
+
+\end_inset
+
+).
A warning message will be generated when this happens and the compiler
will indicate the number of extra bytes it allocated.
It is recommended that this option NOT be used, #pragma\SpecialChar ~
\series default
Will not memcpy initialized data from code space into xdata space.
- This saves a few bytes in code space if you don't have initialized data.
+ This saves a few bytes in code space if you don't have initialized data
+\begin_inset LatexCommand \index{Variable initialization}
+
+\end_inset
+
+.
\layout List
\labelwidthstring 00.00.0000
\end_inset
(jwk burps: please be more specific here, please!).
- If you want rather more than less warnings you should consider using a
- separate tool dedicated to syntax checking like splint
-\begin_inset LatexCommand \url{www.splint.org}
-
-\end_inset
-
-.
\layout List
\labelwidthstring 00.00.0000
\end_inset
.
- See file sdcc/as/doc/asxhtm.html for assembler options.
-\layout Subsection
+ See file sdcc/as/doc/asxhtm.html for assembler options.cd
+\layout List
+\labelwidthstring 00.00.0000
-Intermediate Dump Options
-\begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
-\end_inset
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-std-sdcc89
+\begin_inset LatexCommand \index{-\/-std-sdcc89}
+
+\end_inset
+
+
+\series default
+ Generally follow the C89 standard, but allow SDCC features that conflict
+ with the standard (default).
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-std-c89
+\begin_inset LatexCommand \index{-\/-std-c89}
+
+\end_inset
+
+
+\series default
+ Follow the C89 standard and disable SDCC features that conflict with the
+ standard.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-std-sdcc99
+\begin_inset LatexCommand \index{-\/-std-sdcc99}
+
+\end_inset
+
+
+\series default
+ Generally follow the C99 standard, but allow SDCC features that conflict
+ with the standard (incomplete support).
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-std-c99
+\begin_inset LatexCommand \index{-\/-std-sdcc99}
+
+\end_inset
+
+
+\series default
+ Follow the C99 standard and disable SDCC features that conflict with the
+ standard (incomplete support).
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-codeseg
+\series default
+
+\begin_inset LatexCommand \index{-\/-codeseg <Value>}
+
+\end_inset
+
+\SpecialChar ~
+<Name> The name to be used for the code
+\begin_inset LatexCommand \index{code}
+
+\end_inset
+
+ segment, default CSEG.
+ This is useful if you need to tell the compiler to put the code in a special
+ segment so you can later on tell the linker to put this segment in a special
+ place in memory.
+ Can be used for instance when using bank switching to put the code in a
+ bank.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-constseg
+\series default
+
+\begin_inset LatexCommand \index{-\/-constseg <Value>}
+
+\end_inset
+
+\SpecialChar ~
+<Name> The name to be used for the const
+\begin_inset LatexCommand \index{code}
+
+\end_inset
+
+ segment, default CONST.
+ This is useful if you need to tell the compiler to put the const data in
+ a special segment so you can later on tell the linker to put this segment
+ in a special place in memory.
+ Can be used for instance when using bank switching to put the const data
+ in a bank.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+more-pedantic
+\series default
+ Actually this is
+\series bold
+\emph on
+not
+\series default
+\emph default
+ a SDCC compiler option but if you want
+\emph on
+more
+\emph default
+ warnings you can use a separate tool dedicated to syntax checking like
+ splint
+\begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{lint (syntax checking tool)}
+
+\end_inset
+
+
+\begin_inset LatexCommand \url{http://www.splint.org}
+
+\end_inset
+
+.
+ To make your source files parseable by splint you will have to include
+
+\family sans
+lint.h
+\family default
+
+\begin_inset LatexCommand \index{splint (syntax checking tool)}
+
+\end_inset
+
+ in your source file and add brackets around extended keywords (like
+\family sans
+
+\begin_inset Quotes sld
+\end_inset
+
+__at\SpecialChar ~
+
+\series bold
+(
+\series default
+0xab
+\series bold
+)
+\series default
+
+\begin_inset Quotes srd
+\end_inset
+
+
+\family default
+ and
+\family sans
+
+\begin_inset Quotes sld
+\end_inset
+
+__interrupt\SpecialChar ~
+(2)
+\begin_inset Quotes srd
+\end_inset
+
+
+\family default
+).
+
+\newline
+Splint has an excellent on line manual at
+\begin_inset LatexCommand \url{http://www.splint.org/manual/}
+
+\end_inset
+
+ and it's capabilities go beyond pure syntax checking.
+ You'll need to tell splint the location of SDCC's include files so a typical
+ command line could look like this:
+\newline
+
+\family sans
+splint\SpecialChar ~
+-I\SpecialChar ~
+/usr/local/share/sdcc/include/mcs51/\SpecialChar ~
+\SpecialChar ~
+myprogram.c
+\layout Subsection
+
+Intermediate Dump Options
+\begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
+
+\end_inset
\begin_inset LatexCommand \index{Options intermediate dump}
The following options are provided for the purpose of retargetting and debugging
the compiler.
- These provided a means to dump the intermediate code (iCode
+ They provide a means to dump the intermediate code (iCode
\begin_inset LatexCommand \index{iCode}
\end_inset
data
\begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
+
\end_inset
/ near
\end_inset
+\begin_inset LatexCommand \index{\_\_near (storage class)}
+
+\end_inset
+
+
\layout Standard
This is the
xdata
\begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
+
\end_inset
/ far
\end_inset
+\begin_inset LatexCommand \index{\_\_far (storage class)}
+
+\end_inset
+
+
\layout Standard
Variables declared with this storage class will be placed in the external
\end_inset
+\begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
+
+\end_inset
+
+
\layout Standard
Variables declared with this storage class will be allocated into the indirectly
\end_inset
+\begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
+
+\end_inset
+
+
\layout Standard
Paged xdata access is just as straightforward as using the other addressing
modes of a 8051.
It is typically located at the start of xdata and has a maximum size of
256 bytes.
- The following example writes 0x01 to the address pointed to.
+ The following example writes 0x01 to the pdata variable.
Please note, pdata access physically accesses xdata memory.
The high byte of the address is determined by port P2
\begin_inset LatexCommand \index{P2 (mcs51 sfr)}
\end_inset
).
+ This is the
+\series bold
+default
+\series default
+ storage class for the Medium Memory model, e.g.:
\layout Verse
\family typewriter
-pdata unsigned char *test_pdata_ptr;
-\newline
-
-\newline
-void main()
-\newline
-{
-\newline
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-test_pdata_ptr = (pdata *)0xfe;
-\newline
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-*test_pdata_ptr = 1;
-\newline
-}
+pdata unsigned char test_pdata;
\layout Standard
-Generates the assembly code:
+Writing 0x01 to this variable generates the assembly code:
\layout Verse
\family typewriter
-75*01 FE\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
-mov\SpecialChar ~
- _test_pdata_ptr,#0xFE
-\newline
-78 FE\SpecialChar ~
+78r00\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-mov\SpecialChar ~
- r0,#0xFE
+mov r0,#_test_pdata
\newline
74 01\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-mov\SpecialChar ~
- a,#0x01
+mov a,#0x01
\newline
F2\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-movx @r0,a
+movx @r0,a
\layout Standard
If the -
\end_inset
+\begin_inset LatexCommand \index{\_\_code}
+
+\end_inset
+
+
\layout Standard
'Variables' declared with this storage class will be placed in the code
\end_inset
+\begin_inset LatexCommand \index{\_\_bit}
+
+\end_inset
+
+
\layout Standard
This is a data-type and a storage class specifier.
sfr
\begin_inset LatexCommand \index{sfr}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sfr}
+
+\end_inset
+
+ / sfr16
+\begin_inset LatexCommand \index{sfr16}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sfr16}
+
+\end_inset
+
+ / sfr32
+\begin_inset LatexCommand \index{sfr32}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sfr32}
+
\end_inset
/ sbit
-\begin_inset LatexCommand \index{sbit}
+\begin_inset LatexCommand \index{\_\_sbit}
\end_inset
Like the bit keyword,
\emph on
-sfr / sbit
+sfr / sfr16 / sfr32 / sbit
\emph default
-signifies both a data-type and storage class, they are used to describe
- the
+signify both a data-type and storage class, they are used to describe the
+
\emph on
s
\emph default
sfr at
\begin_inset LatexCommand \index{at}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
\end_inset
0x80 P0;\SpecialChar ~
/* special function register P0 at location 0x80 */
\newline
+/* 16 bit special function register combination for timer 0 */
+\newline
+/* with the high byte at location 0x8C and the low byte at location 0x8A
+ */
+\newline
+sfr16 at
+\begin_inset LatexCommand \index{at}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
+\end_inset
+
+ 0x8C8A TMR0;
+\newline
sbit at 0xd7 CY; /* CY (Carry Flag
\begin_inset LatexCommand \index{Flags}
sbit
\emph default
addresses a specific bit within these sfr.
+\newline
+16 Bit and 32 bit special function register combinations which require a
+ certain access order are better not declared using
+\emph on
+sfr16
+\emph default
+ or
+\emph on
+sfr32.
+
+\emph default
+ Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
+ this is not guaranteed.
\layout Subsubsection
Pointers
*/
\newline
char * xdata p;
+\newline
+
+\newline
+/* the following is a function pointer physically located in data space
+ */
+\newline
+char (* data fp)(void);
\layout Standard
Well you get the idea.
\end_inset
+
+\begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
+
+\end_inset
+
).
Furthermore, some chips may have some built in external memory (
\emph on
\end_inset
+
+\begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
+
+\end_inset
+
) which should not be confused with the internal, directly addressable RAM
memory (
\emph on
\end_inset
+
+\begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
+
+\end_inset
+
).
Sometimes this built in
\emph on
\end_inset
of registers (register bank 0), but it is possible to specify that other
- banks of registers should be used in interrupt
+ banks of registers (keyword
+\emph on
+using
+\emph default
+
+\emph on
+
+\begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
+
+\end_inset
+
+
+\emph default
+) should be used in interrupt
\begin_inset LatexCommand \index{interrupt}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_interrupt}
+
\end_inset
routines.
\end_inset
-data-loc
-\begin_inset LatexCommand \index{-\/-data-loc<Value>}
+\begin_inset LatexCommand \index{-\/-data-loc <Value>}
\end_inset
/
\end_inset
--iram-size to specify the size of the total internal RAM (
+-iram-size
+\begin_inset LatexCommand \index{-\/-iram-size <Value>}
+
+\end_inset
+
+ to specify the size of the total internal RAM (
\emph on
data
\emph default
\end_inset
-stack-loc
-\begin_inset LatexCommand \index{-\/-stack-loc<Value>}
+\begin_inset LatexCommand \index{-\/-stack-loc <Value>}
\end_inset
\end_inset
-xram-size
-\begin_inset LatexCommand \index{-\/-data-loc}
+\begin_inset LatexCommand \index{-\/-xram-size <Value>}
\end_inset
\end_inset
-code-loc
-\begin_inset LatexCommand \index{-\/-data-loc}
+\begin_inset LatexCommand \index{-\/-code-loc <Value>}
\end_inset
\end_inset
-code-size
-\begin_inset LatexCommand \index{-\/-data-loc}
+\begin_inset LatexCommand \index{-\/-code-size <Value>}
\end_inset
sfr
\begin_inset LatexCommand \index{sfr}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sfr}
+
\end_inset
(in/out to 8-bit addresses)
banked sfr
\begin_inset LatexCommand \index{sfr}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sfr}
+
\end_inset
(in/out to 16-bit addresses)
sfr banked at
\begin_inset LatexCommand \index{at}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
\end_inset
0x123 IoPort;
sfr
\begin_inset LatexCommand \index{sfr}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_sfr}
+
\end_inset
(in0/out0 to 8 bit addresses on Z180
\layout Subsubsection
data
-\begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
+\begin_inset LatexCommand \index{data (hc08 storage class)}
\end_inset
+\begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
+
+\end_inset
+
+
\layout Standard
The data storage class declares a variable that resides in the first 256
\layout Subsubsection
xdata
-\begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
+\begin_inset LatexCommand \index{xdata (hc08 storage class)}
\end_inset
+\begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
+
+\end_inset
+
+
\layout Standard
The xdata storage class declares a variable that can reside anywhere in
at
\begin_inset LatexCommand \index{at}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
\end_inset
<address>
xdata
\begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
+
\end_inset
at
\begin_inset LatexCommand \index{at}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
\end_inset
0x7ffe unsigned int chksum;
\family typewriter
-extern volatile bit MOSI;\SpecialChar ~
+extern volatile
+\begin_inset LatexCommand \index{volatile}
+
+\end_inset
+
+ bit MOSI;\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\family typewriter
-bit at 0x80 MOSI;\SpecialChar ~
+bit at
+\begin_inset LatexCommand \index{at}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
+\end_inset
+
+ 0x80 MOSI;\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
, (storage classes for parameters will be ignored), their allocation is
governed by the memory model in use, and the reentrancy options.
+\layout Standard
+
+It is however allowed to use bit parameters in reentrant functions and also
+ non-static local bit variables are supported.
+ Efficient use is limited to 8 semi-bitregisters in bit space.
+ They are pushed and popped to stack as a single byte just like the normal
+ registers.
\layout Section
Overlaying
\end_inset
+\begin_inset LatexCommand \index{\_\_interrupt}
+
+\end_inset
+
+
\emph default
keyword is the interrupt number this routine will service.
When present, the compiler will insert a call to this routine in the interrupt
main
\emph default
.
- The
+ The optional
\emph on
using
+\begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
+
+\end_inset
+
+
\emph default
keyword can be used to tell the compiler to use the specified register
bank (8051 specific) when generating code for this function.
if it is not reentrant.
Furthermore nonreentrant functions should not be called from the main program
while the interrupt service routine might be active.
-
+ They also must not be called from low priority interrupt service routines
+ while a high priority interrupt service routine might be active. You could use
+ semaphores or make the function
+\emph on
+ critical
+\emph default
+ if all parameters are passed in registers.
\newline
\newline
\end_inset
+\begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
+
+\end_inset
+
+
\emph default
a register bank or with register bank 0 (
\emph on
\end_inset
+
+\begin_inset LatexCommand \index{\_\_critical}
+
+\end_inset
+
\newline
{
\family typewriter
-volatile bit resource_is_free;
+volatile
+\begin_inset LatexCommand \index{volatile}
+
+\end_inset
+
+ bit resource_is_free;
\newline
\newline
\end_inset
+\begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
+
+\end_inset
+
+
\emph default
attribute (which tells the compiler to use a register bank
\begin_inset LatexCommand \index{register bank (mcs51, ds390)}
function using a non-zero bank will assume that it can trash that register
bank, and will not save it.
Since high-priority interrupts
+\begin_inset LatexCommand \index{interrupts}
+
+\end_inset
+
+
\begin_inset LatexCommand \index{interrupt priority}
\end_inset
\emph default
routine to your program to override the default if you need to setup hardware
or perform some other critical operation prior to static & global variable
- initialization.
- On some mcs51 variants xdata has to be explicitly enabled before it can
- be accessed or if the watchdog needs to be disabled, this is the place
- to do it.
+ initialization
+\begin_inset LatexCommand \index{Variable initialization}
+
+\end_inset
+
+.
+ On some mcs51 variants xdata
+\begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
+
+\end_inset
+
+ memory has to be explicitly enabled before it can be accessed or if the
+ watchdog needs to be disabled, this is the place to do it.
The startup code clears all internal data memory, 256 bytes by default,
but from 0 to n-1 if
\emph on
\end_inset
-iram-size
-\begin_inset LatexCommand \index{-\/-iram-size}
+\begin_inset LatexCommand \index{-\/-iram-size <Value>}
\end_inset
unsigned char far
\begin_inset LatexCommand \index{far (storage class)}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_far (storage class)}
+
\end_inset
at
\begin_inset LatexCommand \index{at}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_at}
+
\end_inset
0x7f00 buf[0x100];
\end_inset
+\begin_inset LatexCommand \index{\_\_asm}
+
+\end_inset
+
+
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-_endasm;
+_endasm
+\begin_inset LatexCommand \index{\_endasm}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_endasm}
+
+\end_inset
+
+;
\newline
}
\layout Standard
\end_inset
+\begin_inset LatexCommand \index{\_\_asm}
+
+\end_inset
+
+
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-_endasm;
+_endasm
+\begin_inset LatexCommand \index{\_endasm}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_endasm}
+
+\end_inset
+
+;
\newline
}
\newline
The assembler does not like some characters like ':' or ''' in comments.
You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
+\begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{Assembler documentation}
+
+\end_inset
+
+
\end_inset
.
\end_inset
- ...
- _endasm;
-\family default
- keyword pair.
- Specifically it will not know which registers are used and thus register
- pushing/popping
-\begin_inset LatexCommand \index{push/pop}
+
+\begin_inset LatexCommand \index{\_\_asm}
+
+\end_inset
+
+ ...
+ _endasm
+\size footnotesize
+
+\begin_inset LatexCommand \index{\_endasm}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_endasm}
+
+\end_inset
+
+
+\size default
+;
+\family default
+ keyword pair.
+ Specifically it will not know which registers are used and thus register
+ pushing/popping
+\begin_inset LatexCommand \index{push/pop}
\end_inset
\end_inset
+
+\begin_inset LatexCommand \index{\_\_naked}
+
+\end_inset
+
.
\emph default
void simpleInterrupt(void) interrupt
\begin_inset LatexCommand \index{interrupt}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_interrupt}
+
\end_inset
1
\end_inset
+\begin_inset LatexCommand \index{\_\_asm}
+
+\end_inset
+
+
\newline
\SpecialChar ~
\SpecialChar ~
\end_inset
+
+\begin_inset LatexCommand \index{\_\_endasm}
+
+\end_inset
+
;
\newline
}
\end_inset
+
+\begin_inset LatexCommand \index{\_\_asm}
+
+\end_inset
+
\newline
\SpecialChar ~
_endasm
\begin_inset LatexCommand \index{\_endasm}
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_endasm}
+
\end_inset
;
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-_endasm ;
+_endasm
+\begin_inset LatexCommand \index{\_endasm}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{\_\_endasm}
+
+\end_inset
+
+ ;
\newline
\SpecialChar ~
\SpecialChar ~
\layout Standard
These support routines are developed in ANSI-C so there is room for space
- and speed improvement.
+ and speed improvement
+\begin_inset Foot
+collapsed false
+
+\layout Standard
+
+The floating point routines for the mcs51 are implemented in assembler
+\end_inset
+
+.
Note if all these routines are used simultaneously the data space might
overflow.
- For serious floating point usage it is recommended that the large model
- be used.
+ For serious floating point usage the large model might be needed.
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.
If you're short on memory you might want to use
\family typewriter
printf_small()
+\begin_inset LatexCommand \index{printf\_small()}
+
+\end_inset
+
+
\family default
\emph on
printf().
\family default
- For the mcs51 there is an assembly version
+ For the mcs51 there additionally are assembly versions
+\family typewriter
+printf_tiny()
+\begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
+
+\end_inset
+
+
+\family default
+ and
\family typewriter
printf_fast()
+\begin_inset LatexCommand \index{printf\_fast() (mcs51)}
+
+\end_inset
+
+
+\family default
+and
+\family typewriter
+ printf_fast_f()
+\begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
+
+\end_inset
+
+
\family default
- which should fit the requirements of many embedded systems (by unsetting
- #defines it can be customized to
+ which should fit the requirements of many embedded systems (printf_fast()
+ can be customized by unsetting #defines to
\emph on
not
\emph default
\layout Subsubsection
-Small and Large
+Small, Medium and Large
\layout Standard
-SDCC allows two memory models for MCS51 code,
+SDCC allows three memory models for MCS51 code,
\shape slanted
-small
+small, medium
\shape default
and
\shape slanted
never
\emph default
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 separate directories as small
- and large so that you can link to either set.
-
+ The library routines supplied with the compiler are compiled as small,
+ medium and large.
+ The compiled library modules are contained in separate directories as small,
+ medium and large so that you can link to the appropriate set.
\layout Standard
-When the large model is used all variables declared without a storage class
- will be allocated into the external ram, this includes all parameters and
- local variables (for non-reentrant
+When the medium or large model is used all variables declared without a
+ storage class will be allocated into the external ram, this includes all
+ parameters and local variables (for non-reentrant
\begin_inset LatexCommand \index{reentrant}
\end_inset
\end_inset
+
+\begin_inset LatexCommand \index{\_\_naked}
+
+\end_inset
+
.
\layout Itemize
as long as meeting one goal is not a detriment to the other (this is the
default).
+\layout Itemize
+
+std_sdcc89
+\begin_inset LatexCommand \index{\#pragma std\_sdcc89}
+
+\end_inset
+
+- Generally follow the C89 standard, but allow SDCC features that conflict
+ with the standard (default).
+\layout Itemize
+
+std_c89
+\begin_inset LatexCommand \index{\#pragma std\_c89}
+
+\end_inset
+
+- Follow the C89 standard and disable SDCC features that conflict with the
+ standard.
+\layout Itemize
+
+std_sdcc99
+\begin_inset LatexCommand \index{\#pragma std\_sdcc99}
+
+\end_inset
+
+- Generally follow the C99 standard, but allow SDCC features that conflict
+ with the standard (incomplete support).
+\layout Itemize
+
+std_c99
+\begin_inset LatexCommand \index{\#pragma std\_c99}
+
+\end_inset
+
+- Follow the C99 standard and disable SDCC features that conflict with the
+ standard (incomplete support).
+\layout Itemize
+
+codeseg <name>
+\begin_inset LatexCommand \index{\#pragma codeseg}
+
+\end_inset
+
+- Use this name (max.
+ 8 characters) for the code segment.
+\layout Itemize
+
+constseg <name>
+\begin_inset LatexCommand \index{\#pragma constseg}
+
+\end_inset
+
+- Use this name (max.
+ 8 characters) for the const segment.
\layout Standard
SDCPP supports the following #pragma directives:
\begin_inset Tabular
-<lyxtabular version="3" rows="10" columns="2">
+<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">
\layout Standard
+SDCC_MODEL_MEDIUM
+\begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
+
+\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-medium
+\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}
gpasm.exe or MPLAB's mpasmwin.exe.
GPUTILS is available from
-\begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
+\begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
\end_inset
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
+gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
\layout Standard
Here is a
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
+mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
\layout Standard
Please note that indentations within a
Makefile
\family default
have to be done with a tabulator character.
+\layout Subsection
+
+Command-line options
+\layout Standard
+
+Besides the switches common to all SDCC backends, the PIC14 port accepts
+ the following options (for an updated list see sdcc -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-help):
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-debug-extra emit debug info in assembly output
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-no-pcode-opt disable (slightly faulty) optimization on pCode
+\layout Subsection
+
+The library
+\layout Subsubsection
+
+error: missing definition for symbol
+\begin_inset Quotes sld
+\end_inset
+
+__gptrget1
+\begin_inset Quotes srd
+\end_inset
+
+
+\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
+.
+ For single source file projects this is done automatically, more complex
+ projects must add
+\family typewriter
+libsdcc.lib
+\family default
+ to the linker's arguments.
+ Make sure you also add an include path for the library (using the -I switch
+ to the linker)!
+\layout Subsubsection
+
+Processor mismatch in file
+\begin_inset Quotes sld
+\end_inset
+
+XXX
+\begin_inset Quotes srd
+\end_inset
+
+.
+\layout Standard
+
+This warning can usually be ignored due to the very good compatibility amongst
+ 14 bit PIC devices.
+\layout Standard
+
+You might also consider recompiling the library for your specific device
+ by changing the ARCH=p16f877 (default target) entry in
+\family typewriter
+device/lib/pic/Makefile.in
+\family default
+ and
+\family typewriter
+device/lib/pic/Makefile
+\family default
+ to reflect your device.
+ This might even improve performance for smaller devices as unneccesary
+ BANKSELs migth be removed.
+\layout Subsection
+
+Known bugs
+\layout Subsubsection
+
+initialized data
+\layout Standard
+
+Currently, data can only be initialized if it resides in the source file
+ together with
+\emph on
+main()
+\emph default
+.
+ Data in other source files will silently
+\series bold
+not
+\series default
+ be initialized.
\layout Section
The PIC16
/
\end_inset
--obanksel=nn Set optimization level for inserting BANKSELs.
-\newline
-
-\begin_deeper
-\layout List
-\labelwidthstring 00.00.0000
-
-0 no optimization
+-optimize-df Analyze the dataflow of the generated code and improve it.
+\layout List
+\labelwidthstring 00.00.0000
+
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-obanksel=nn Set optimization level for inserting BANKSELs.
+\newline
+
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+0 no optimization
\layout List
\labelwidthstring 00.00.0000
\layout Standard
Libraries are created with gplib which is part of the gputils package
-\begin_inset LatexCommand \url{http://gputils.sourceforge.net}
+\begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
\end_inset
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.
+ Sdcdb is currently not available on Win32 platforms.
\layout Section
Compiling for Debugging
object file.
\layout Section
-Command Line Options.
+Command Line Options
\layout Itemize
-
-k <port number> passed to simulator see the simulator docs for details.
\layout Section
-Debugger Commands.
+Debugger Commands
\layout Standard
As mentioned earlier the command interface for the debugger has been deliberatel
y kept as close the GNU debugger gdb, as possible.
This will help the integration with existing graphical user interfaces
(like ddd, xxgdb or xemacs) existing for the GNU debugger.
- If you use a graphical user interface for the debugger you can skip the
- next sections.
+ If you use a graphical user interface for the debugger you can skip this
+ section.
\layout Subsubsection*
break [line | file:line | function | file:function]
My name is Bobby Brown"
\layout Section
+Interfacing with DDD
+\layout Comment
+
+The screenshot was converted from png to eps with:
+\begin_inset Quotes sld
+\end_inset
+
+bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
+\begin_inset Quotes srd
+\end_inset
+
+ which produces a pretty compact eps file which is free from compression
+ artifacts.
+\layout Comment
+
+The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
+ as this broke the build system on Sourceforge (pdf-file was broken).
+\layout Standard
+
+The .eps File
+\size footnotesize
+
+\begin_inset LatexCommand \url{http://cvs.sourceforge.net/viewcvs.py/*checkout*/sdcc/sdcc/doc/figures/ddd_example.eps}
+
+\end_inset
+
+
+\size default
+ shows a screenshot of a debugging session with DDD
+\begin_inset LatexCommand \index{DDD (debugger)}
+
+\end_inset
+
+ (Unix only) on a simulated 8032.
+ 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
+\series bold
+
+\newline
+
+\newline
+sdcc -
+\family default
+\series default
+
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+
+\family sans
+\series bold
+-debug ddd_example.c
+\family default
+\series default
+
+\family sans
+\series bold
+
+\newline
+
+\family default
+\series default
+
+\newline
+and DDD was invoked with
+\family sans
+\series bold
+
+\newline
+
+\newline
+ddd -debugger 'sdcdb -cpu 8032 ddd_example'
+\layout Section
+
Interfacing with XEmacs
\begin_inset LatexCommand \index{XEmacs}
\end_inset
-.
+
\layout Standard
Two files (in emacs lisp) are provided for the interfacing with XEmacs,
use an 'unsigned char' instead of a 'short' or 'int'.
Please note, that ANSI C requires both signed and unsigned chars to be
promoted to 'signed int' before doing any operation.
- This promotion can be omitted, if the result is the same.
+ This promotion
+\begin_inset LatexCommand \index{type promotion}
+
+\end_inset
+
+ can be omitted, if the result is the same.
The effect of the promotion rules together with the sign-extension is often
surprising:
\begin_deeper
<features>
<column alignment="center" valignment="top" leftline="true" width="0pt">
<column alignment="center" valignment="top" leftline="true" width="0pt">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
+<column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
<features>
<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">
+<column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
-\begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
+\begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
\end_inset
\layout Standard
-\begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
+\begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
\end_inset
\layout Standard
-\begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
+\begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
\end_inset
\layout Standard
srecord
-\begin_inset LatexCommand \index{srecord (tool)}
+\begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
\end_inset
\layout Standard
-\begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
+\begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
\end_inset
\layout Standard
-Statically checks c sources (has anyone adapted splint for SDCC?)
+Statically checks c sources (see
+\begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
+
+\end_inset
+
+)
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\layout Standard
-\begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
+\begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
\end_inset
\size footnotesize
-\begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
+\begin_inset LatexCommand \htmlurl{http://cvs.sf.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
\end_inset
More examples and libraries are available at
\emph on
The SDCC Open Knowledge Resource
-\begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
+\begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
\end_inset
\emph default
aries.
It has no effect if a default label is supplied.
- Use of this pragma is dangerous: if the switch argument is not matched
- by a case statement the processor will happily jump into Nirvana.
+ Use of this pragma is dangerous: if the switch
+\begin_inset LatexCommand \index{switch statement}
+
+\end_inset
+
+ argument is not matched by a case statement the processor will happily
+ jump into Nirvana.
\layout Subsection
Bit-shifting Operations
\layout Standard
-Usually 8-bit processors don't care much about endianness.
- This is not the case for the standard 8051 which only has an instruction
- to increment its
-\emph on
-dptr
-\emph default
-
-\begin_inset LatexCommand \index{DPTR}
-
-\end_inset
-
--datapointer
+Usually 8-bit processors don't care much about endianness.
+ This is not the case for the standard 8051 which only has an instruction
+ to increment its
+\emph on
+dptr
+\emph default
+
+\begin_inset LatexCommand \index{DPTR}
+
+\end_inset
+
+-datapointer
+\emph on
+
+\emph default
+so little-endian is the more efficient byte order.
+\end_inset
+
+
+\begin_inset LatexCommand \index{little-endian}
+
+\end_inset
+
+
+\begin_inset LatexCommand \index{Endianness}
+
+\end_inset
+
+ format (i.e.
+ lowest order first).
+\layout Subsection
+
+Highest Order Bit
+\begin_inset LatexCommand \index{Highest Order Bit}
+
+\end_inset
+
+ / Any Order Bit
+\begin_inset LatexCommand \index{Any Order Bit}
+
+\end_inset
+
+
+\layout Standard
+
+It is frequently required to obtain the highest order bit of an integral
+ type (long, int, short or char types).
+ Also obtaining any other order bit is not uncommon.
+ SDCC recognizes the following expressions to yield the highest order bit
+ and generates optimized code for it, e.g.:
+\layout Verse
+
+
+\family typewriter
+unsigned int gint;
+\newline
+
+\newline
+foo () {
+\newline
+\SpecialChar ~
+\SpecialChar ~
+unsigned char hob1, aob1;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+bit hob2, hob3, aob2, aob3;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+...
+
+\newline
+\SpecialChar ~
+\SpecialChar ~
+hob1 = (gint >> 15) & 1;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+hob2 = (gint >> 15) & 1;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+hob3 = gint & 0x8000;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+aob1 = (gint >> 9) & 1;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+aob2 = (gint >> 8) & 1;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+aob3 = gint & 0x0800;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+..
+
+\newline
+}
+\layout Standard
+
+will generate the following code:
+\layout Verse
+
+
+\family typewriter
+\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 ~
+ 61 ;\SpecialChar ~
+ hob.c 7
+\newline
+000A E5*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 62\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1)
+\newline
+000C 23\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 63\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ rl\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ a
+\newline
+000D 54 01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 64\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ anl\SpecialChar ~
+\SpecialChar ~
+ a,#0x01
+\newline
+000F F5*02\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 65\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_hob1_1_1,a
+\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 ~
+ 66 ;\SpecialChar ~
+ hob.c 8
+\newline
+0011 E5*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 67\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1)
+\newline
+0013 33\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 68\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ rlc\SpecialChar ~
+\SpecialChar ~
+ a
+\newline
+0014 92*00\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 69\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_hob2_1_1,c
+\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 ~
+ 66 ;\SpecialChar ~
+ hob.c 9
+\newline
+0016 E5*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 67\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1)
+\newline
+0018 33\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 68\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ rlc\SpecialChar ~
+\SpecialChar ~
+ a
+\newline
+0019 92*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 69\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_hob3_1_1,c
+\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 ~
+ 70 ;\SpecialChar ~
+ hob.c 10
+\newline
+001B E5*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 71\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1)
+\newline
+001D 03\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 72\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ rr\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ a
+\newline
+001E 54 01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 73\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ anl\SpecialChar ~
+\SpecialChar ~
+ a,#0x01
+\newline
+0020 F5*03\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 74\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_aob1_1_1,a
+\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 ~
+ 75 ;\SpecialChar ~
+ hob.c 11
+\newline
+0022 E5*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 76\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1)
+\newline
+0024 13\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 77\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ rrc\SpecialChar ~
+\SpecialChar ~
+ a
+\newline
+0025 92*02\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 78\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_aob2_1_1,c
+\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 ~
+ 79 ;\SpecialChar ~
+ hob.c 12
+\newline
+0027 E5*01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 80\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ a,(_gint + 1)
+\newline
+0029 A2 E3\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 81\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ c,acc[3]
+\newline
+002B 92*03\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 82\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_aob3_1_1,c
+\layout Standard
+
+Other variations of these cases however will
\emph on
-
+not
\emph default
-so little-endian is the more efficient byte order.
-\end_inset
-
+ be recognized.
+ They are standard C expressions, so I heartily recommend these be the only
+ way to get the highest order bit, (it is portable).
+ Of course it will be recognized even if it is embedded in other expressions,
+ e.g.:
+\layout Verse
-\begin_inset LatexCommand \index{little-endian}
-\end_inset
+\family typewriter
+xyz = gint + ((gint >> 15) & 1);
+\layout Standard
+will still be recognized.
+\layout Subsection
-\begin_inset LatexCommand \index{Endianness}
+Higher Order Byte
+\begin_inset LatexCommand \index{Higher Order Byte}
\end_inset
- format (i.e.
- lowest order first).
-\layout Subsection
-
-Highest Order Bit
-\begin_inset LatexCommand \index{Highest Order Bit}
+ / Higher Order Word
+\begin_inset LatexCommand \index{Higher Order Word}
\end_inset
\layout Standard
-It is frequently required to obtain the highest order bit of an integral
- type (long, int, short or char types).
- SDCC recognizes the following expression to yield the highest order bit
- and generates optimized code for it, e.g.:
+It is also frequently required to obtain a higher order byte or word of
+ a larger integral type (long, int or short types).
+ SDCC recognizes the following expressions to yield the higher order byte
+ or word and generates optimized code for it, e.g.:
\layout Verse
\family typewriter
unsigned int gint;
\newline
+unsigned long int glong;
+\newline
\newline
foo () {
\newline
\SpecialChar ~
\SpecialChar ~
-unsigned char hob;
+unsigned char hob1, hob2;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+unsigned int how1, how2;
\newline
\SpecialChar ~
\SpecialChar ~
\newline
\SpecialChar ~
\SpecialChar ~
-hob = (gint >> 15) & 1;
+hob1 = (gint >> 8) & 0xFF;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+hob2 = glong >> 24;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+how1 = (glong >> 16) & 0xFFFF;
+\newline
+\SpecialChar ~
+\SpecialChar ~
+how2 = glong >> 8;
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- 61 ;\SpecialChar ~
- hob.c 7
+ 91 ;\SpecialChar ~
+ hob.c 15
\newline
-000A E5*01\SpecialChar ~
+0037 85*01*06\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ 92\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- 62\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ mov\SpecialChar ~
\SpecialChar ~
+ _foo_hob1_1_1,(_gint + 1)
+\newline
\SpecialChar ~
\SpecialChar ~
- mov\SpecialChar ~
\SpecialChar ~
- a,(_gint + 1)
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 93 ;\SpecialChar ~
+ hob.c 16
\newline
-000C 23\SpecialChar ~
+003A 85*05*07\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ 94\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- 63\SpecialChar ~
\SpecialChar ~
+ mov\SpecialChar ~
\SpecialChar ~
+ _foo_hob2_1_1,(_glong + 3)
+\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- rl\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- a
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 95 ;\SpecialChar ~
+ hob.c 17
\newline
-000D 54 01\SpecialChar ~
+003D 85*04*08\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ 96\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- 64\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ mov\SpecialChar ~
\SpecialChar ~
+ _foo_how1_1_1,(_glong + 2)
+\newline
+0040 85*05*09\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- anl\SpecialChar ~
\SpecialChar ~
- a,#0x01
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 97\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ (_foo_how1_1_1 + 1),(_glong + 3)
\newline
-000F F5*02\SpecialChar ~
+0043 85*03*0A\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
+ 98\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
- 65\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ mov\SpecialChar ~
+\SpecialChar ~
+ _foo_how2_1_1,(_glong + 1)
+\newline
+0046 85*04*0B\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ 99\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
mov\SpecialChar ~
\SpecialChar ~
- _foo_hob_1_1,a
+ (_foo_how2_1_1 + 1),(_glong + 2)
\layout Standard
-Variations of this case however will
+Again, variations of these cases may
\emph on
not
\emph default
be recognized.
- It is a standard C expression, so I heartily recommend this be the only
- way to get the highest order bit, (it is portable).
+ They are standard C expressions, so I heartily recommend these be the only
+ way to get the higher order byte/word, (it is portable).
Of course it will be recognized even if it is embedded in other expressions,
e.g.:
\layout Verse
\family typewriter
-xyz = gint + ((gint >> 15) & 1);
+xyz = gint + ((gint >> 8) & 0xFF);
\layout Standard
will still be recognized.
copt
\emph default
a peep-hole optimizer by Christopher W.
- Fraser (cwfraser@microsoft.com).
+ Fraser (cwfraser\SpecialChar ~
+@\SpecialChar ~
+microsoft.com).
A default set of rules are compiled into the compiler, additional rules
may be added with the
\emph on
Deviations from the compliance:
\layout Itemize
-functions are not always reentrant
+functions are not reentrant
\begin_inset LatexCommand \index{reentrant}
\end_inset
-.
+ unless explicitly declared as such or the
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-stack-auto
+\begin_inset LatexCommand \index{-\/-stack-auto}
+
+\end_inset
+
+
+\series default
+ command line option is specified.
\layout Itemize
-structures cannot be assigned values directly, cannot be passed as function
- parameters or assigned to each other and cannot be a return value from
- a function, e.g.:
+structures and unions cannot be assigned values directly, cannot be passed
+ as function parameters or assigned to each other and cannot be a return
+ value from a function, e.g.:
\begin_deeper
\layout Verse
\end_deeper
\layout Itemize
+initialization of structure arrays must be fully braced.
+\begin_deeper
+\layout Verse
+
+
+\family typewriter
+struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
+\newline
+struct s { char x } a[] = {{1}, {2}}; /* OK */
+\end_deeper
+\layout Itemize
+
'long long
\begin_inset LatexCommand \index{long long (not supported)}
not supported.
\layout Itemize
-No support for setjmp
-\begin_inset LatexCommand \index{setjmp (not supported)}
-
-\end_inset
-
- and longjmp
-\begin_inset LatexCommand \index{longjmp (not supported)}
-
-\end_inset
-
- (for now).
-\layout Itemize
-
Old K&R style
\begin_inset LatexCommand \index{K\&R style}
\newline
}
\end_deeper
+\layout Itemize
+
+Most enhancements in C99 are not supported, f.e.:
+\begin_deeper
+\layout Verse
+
+
+\family typewriter
+\series bold
+inline
+\series default
+ int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
+ in C99 */
+\newline
+for (
+\series bold
+int
+\series default
+ i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
+\end_deeper
+\layout Itemize
+
+Certain words that are valid identifiers in the standard may be reserved
+ words in SDCC unless the
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-std-c89
+\begin_inset LatexCommand \index{-\/-std-c89}
+
+\end_inset
+
+ or -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-std-c99
+\begin_inset LatexCommand \index{-\/-std-c99}
+
+\end_inset
+
+
+\series default
+ command line options are used.
+ These may include (depending on the selected processor): 'at', 'banked',
+ 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
+t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
+ 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
+ '_naked'.
+ Compliant equivalents of these keywords are always available in a form
+ that begin with two underscores
+\begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
+
+\end_inset
+
+, f.e.
+ '__data' instead of 'data'.
\layout Section
Cyclomatic Complexity
\shape italic
This is an excerpt from an article published in Circuit Cellar Magazine
- in august 2000.
+ in
+\series bold
+August 2000
+\series default
+.
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.
\shape default