\graphics default
\paperfontsize default
\spacing single
-\papersize Default
+\papersize letterpaper
\paperpackage a4
\use_geometry 1
\use_amsmath 0
extra long dash.
\layout Comment
-This document would need some rework: The Installation section is much to
-
-\layout Comment
-
-intimidating (as is the section about sdcdb).
-\layout Comment
-
Architecture specific stuff (like memory models, code examples) should maybe
go
\layout Comment
\end_inset
, etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
- It can be retargetted for other microprocessors, support for PIC, AVR is
- under development.
+ 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.
SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
SDCC has extensive language extensions suitable for utilizing various microcont
support for mcs51
\newline
+\newline
+
\family default
If you can think of some more, please see the chapter 9 about filing feature
requests
\end_inset
+\layout Standard
+
+For most users it is sufficient to skip to either section
+\begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
+
+\end_inset
+
+ or section
+\begin_inset LatexCommand \ref{sub:Windows-Install}
+
+\end_inset
+
+.
+ More detailled instructions follow below.
\layout Subsection
Configure Options
\layout Subsubsection
Building SDCC on Linux
+\begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
+
+\end_inset
+
+
\layout Enumerate
They use Unix-sockets, which are not available on Win32.
\layout Subsubsection
-Windows Install Using a Binary Package
-\layout Enumerate
-
-Download the binary package and unpack it using your favorite unpacking
- tool (gunzip, WinZip, etc).
- This should unpack to a group of sub-directories.
- An example directory structure after unpacking the mingw32 package is:
- c:
-\backslash
-sdcc
-\backslash
-bin for the executables, c:
-\backslash
-sdcc
-\backslash
-include and c:
-\backslash
-sdcc
-\backslash
-lib for the include and libraries.
-\layout Enumerate
-
-Adjust your environment variable PATH to include the location of the bin
- directory or start sdcc using the full path.
-\layout Subsubsection
-
Building SDCC using Cygwin and Mingw32
\layout Standard
\layout Standard
SDCC sources use the unix line ending LF.
- Life is much easier, if you store the source tree on a drive, which is
- mount in binary mode.
+ Life is much easier, if you store the source tree on a drive which is mounted
+ in binary mode.
And use an editor which can handle LF-only line endings.
Make sure not to commit files with windows line endings.
+ The tabulator spacing used in the project is 8.
\layout Subsubsection
Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
If you modify any source files and need to rebuild, be aware that the dependenci
es may not be correctly calculated.
The safest option is to delete all .obj files and run the build again.
- From a Cygwin BASH prompt, this can easily be done with the command:
+ From a Cygwin BASH prompt, this can easily be done with the command (be
+ sure you are in the sdcc directory):
\newline
\newline
\family default
\series default
from the sdcc directory.
+\layout Subsubsection
+
+Windows Install Using a Binary Package
+\begin_inset LatexCommand \label{sub:Windows-Install}
+
+\end_inset
+
+
+\layout Enumerate
+
+Download the binary package and unpack it using your favorite unpacking
+ tool (gunzip, WinZip, etc).
+ This should unpack to a group of sub-directories.
+ An example directory structure after unpacking the mingw32 package is:
+ c:
+\backslash
+sdcc
+\backslash
+bin for the executables, c:
+\backslash
+sdcc
+\backslash
+include and c:
+\backslash
+sdcc
+\backslash
+lib for the include and libraries.
+\layout Enumerate
+
+Adjust your environment variable PATH to include the location of the bin
+ directory or start sdcc using the full path.
\layout Subsection
Building the Documentation
\layout Standard
-...
- coming soon
+If the necessary tools are installed it is as easy as changing into the
+ doc directory and typing
+\family sans
+\series bold
+
+\begin_inset Quotes srd
+\end_inset
+
+make
+\begin_inset Quotes srd
+\end_inset
+
+
+\family default
+\series default
+ there.
+ If you want to avoid installing the tools you will have some success with
+ a bootable Knoppix CD
+\begin_inset LatexCommand \url{http://www.knopper.net}
+
+\end_inset
+
+.
\layout Subsection
-Testing out the SDCC Compiler
+Testing the SDCC Compiler
\layout Standard
The first thing you should do after installing your SDCC compiler is to
\layout Standard
This will install the compiler, other executables libraries and include
- files in to the appropriate directories.
+ files into the appropriate directories.
See section
\begin_inset Quotes sld
\end_inset
This is retargettable assembler & linkage editor, it was developed by Alan
Baldwin.
John Hartman created the version for 8051, and I (Sandeep) have made some
- enhancements and bug fixes for it to work properly with the SDCC.
+ enhancements and bug fixes for it to work properly with SDCC.
\layout Subsubsection
s51 - The Simulator
\end_inset
.
- It currently support the core mcs51, the Dallas DS80C390 and the Phillips
+ It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
XA51 family.
\layout Subsubsection
\end_inset
.
- If you need another format you might want to use objdump
+ If you need another format you might want to use
+\family sans
+\shape italic
+objdump
+\family default
+\shape default
+
\begin_inset LatexCommand \index{objdump}
\end_inset
- or srecord
+ or
+\family sans
+\shape italic
+ srecord
+\family default
+\shape default
+
\begin_inset LatexCommand \index{srecord}
\end_inset
\end_inset
- An optional AOMF51 file containing debug information (with -
+ An optional AOMF51
+\begin_inset LatexCommand \index{AOMF51}
+
+\end_inset
+
+ file containing debug information (with -
\begin_inset ERT
status Collapsed
/
\end_inset
--debug)
+-debug).
+ This format is commonly used by third party tools (debuggers
+\begin_inset LatexCommand \index{Debugger}
+
+\end_inset
+
+, simulators, emulators)
\layout Itemize
sourcefile.dump*
\series default
- Generate code for the DS80C390
+ Generate code for the Dallas DS80C390
\begin_inset LatexCommand \index{DS80C390}
\end_inset
\series default
- Generate code for the DS80C400
+ Generate code for the Dallas DS80C400
\begin_inset LatexCommand \index{DS80C400}
\end_inset
\series default
- Generate code for the Z80
+ Generate code for the Zilog Z80
\begin_inset LatexCommand \index{Z80}
\end_inset
\series default
- Generate code for the PIC 14
+ Generate code for the Microchip PIC 14
\begin_inset LatexCommand \index{PIC14}
\end_inset
--bit processors (Microchip p16f84 and variants).
+-bit processors (p16f84 and variants).
\layout Comment
p16f627 p16f628 p16f84 p16f873 p16f877?
\series default
- Generate code for the PIC 16
+ Generate code for the Microchip PIC 16
\begin_inset LatexCommand \index{PIC16}
\end_inset
--bit processors (Microchip p18f452 and variants).
+-bit processors (p18f452 and variants).
\layout List
\labelwidthstring 00.00.0000
\series default
Command line definition of macros.
- Passed to the pre processor.
+ Passed to the preprocessor.
\layout List
\labelwidthstring 00.00.0000
'-newline if it is long.
The list of rules is printed on standard output instead of the preprocessed
C program.
- `-M' implies `-E'.
+ `-M' implies `-E
+\begin_inset LatexCommand \index{-E}
+
+\end_inset
+
+'.
\layout List
\labelwidthstring 00.00.0000
\labelwidthstring 00.00.0000
-\series bold
--Aquestion
-\series default
- (answer) Assert the answer answer for question, in case it is tested with
- a preprocessor conditional such as `#if #question(answer)'.
- `-A-' disables the standard assertions that normally describe the target
- machine.
-\layout List
-\labelwidthstring 00.00.0000
-
-
\series bold
-Umacro
\begin_inset LatexCommand \index{-Umacro}
\labelwidthstring 00.00.0000
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-model-small
+\begin_inset LatexCommand \index{-\/-model-small}
+
+\end_inset
+
+
+\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.
+\layout List
+\labelwidthstring 00.00.0000
+
+
\series bold
-
\begin_inset ERT
details.
If this option is used all source files in the project should be compiled
with this option.
- In addition the standard library routines are compiled with small model,
- they will need to be recompiled.
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--model-small
-\begin_inset LatexCommand \index{-\/-model-small}
+-xstack
+\begin_inset LatexCommand \index{-\/-xstack}
\end_inset
\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.
+ Uses a pseudo stack in the first 256 bytes in the external ram for allocating
+ variables and passing parameters.
+ See section on external stack for more details.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-iram-size
+\series default
+<Value>
+\begin_inset LatexCommand \index{-\/-iram-size<Value>}
+
+\end_inset
+
+ Causes the linker to check if the internal ram usage is within limits of
+ the given value.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-xram-size
+\series default
+<Value>
+\begin_inset LatexCommand \index{-\/-xram-size<Value>}
+
+\end_inset
+
+ Causes the linker to check if the external ram usage is within limits of
+ the given value.
\layout Subsubsection
DS390 Options
\series default
- Will not memcpy initialized data in far space from code space.
+ 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.
\layout Subsubsection
/
\end_inset
--xstack
-\begin_inset LatexCommand \index{-\/-xstack}
+-callee-saves
+\begin_inset LatexCommand \index{-\/-callee-saves}
\end_inset
+ function1[,function2][,function3]....
\series default
- Uses a pseudo stack in the first 256 bytes in the external ram for allocating
- variables and passing parameters.
- See section on external stack for more details.
-\layout List
-\labelwidthstring 00.00.0000
-
-
+ The compiler by default uses a caller saves convention for register saving
+ across function calls, however this can cause unnecessary register pushing
+ & popping when calling small functions from larger functions.
+ This option can be used to switch the register saving convention for the
+ function names specified.
+ The compiler will not save registers when calling these functions, no extra
+ code will be generated at the entry & exit (function prologue
\series bold
--
-\begin_inset ERT
-status Collapsed
-\layout Standard
+\begin_inset LatexCommand \index{function prologue}
-\backslash
-/
\end_inset
--callee-saves
-\begin_inset LatexCommand \index{-\/-callee-saves}
-
-\end_inset
+\series default
+ & epilogue
+\series bold
-\begin_inset LatexCommand \index{function prologue}
+\begin_inset LatexCommand \index{function epilogue}
\end_inset
- function1[,function2][,function3]....
\series default
- The compiler by default uses a caller saves convention for register saving
- across function calls, however this can cause unnecessary register pushing
- & popping when calling small functions from larger functions.
- This option can be used to switch the register saving convention for the
- function names specified.
- The compiler will not save registers when calling these functions, no extra
- code will be generated at the entry & exit for these functions to save
- & restore the registers used by these functions, this can SUBSTANTIALLY
- reduce code & improve run time performance of the generated code.
+) for these functions to save & restore the registers used by these functions,
+ this can SUBSTANTIALLY reduce code & improve run time performance of the
+ generated code.
In the future the compiler (with inter procedural analysis) will be able
to determine the appropriate scheme to use for each function call.
DO NOT use this option for built-in functions such as _mulint..., if this
\labelwidthstring 00.00.0000
-\series bold
--
-\begin_inset ERT
-status Collapsed
-
-\layout Standard
-
-\backslash
-/
-\end_inset
-
--peep-file
-\series default
-
-\begin_inset LatexCommand \index{-\/-peep-file}
-
-\end_inset
-
-<filename> This option can be used to use additional rules to be used by
- the peep hole optimizer.
- See section Peep Hole optimizations for details on how to write these rules.
-\layout List
-\labelwidthstring 00.00.0000
-
-
\series bold
-S
\begin_inset LatexCommand \index{-S}
/
\end_inset
--no-peep
-\begin_inset LatexCommand \index{-\/-no-peep}
+-peep-file
+\series default
-\end_inset
+\begin_inset LatexCommand \index{-\/-peep-file}
+\end_inset
-\series default
- Disable peep-hole optimization.
+<filename> This option can be used to use additional rules to be used by
+ the peep hole optimizer.
+ See section Peep Hole optimizations for details on how to write these rules.
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--peep-asm
-\begin_inset LatexCommand \index{-\/-peep-asm}
+-no-peep
+\begin_inset LatexCommand \index{-\/-no-peep}
\end_inset
\series default
- Pass the inline assembler code through the peep hole optimizer.
- This can cause unexpected changes to inline assembler code, please go through
- the peephole optimizer
-\begin_inset LatexCommand \index{Peephole optimizer}
-
-\end_inset
-
- rules defined in the source file tree '<target>/peeph.def' before using
- this option.
+ Disable peep-hole optimization.
\layout List
\labelwidthstring 00.00.0000
/
\end_inset
--iram-size
-\series default
-<Value>
-\begin_inset LatexCommand \index{-\/-iram-size<Value>}
+-peep-asm
+\begin_inset LatexCommand \index{-\/-peep-asm}
\end_inset
- Causes the linker to check if the internal ram usage is within limits of
- the given value.
-\layout List
-\labelwidthstring 00.00.0000
-
-\series bold
--
-\begin_inset ERT
-status Collapsed
-
-\layout Standard
-
-\backslash
-/
-\end_inset
-
--xram-size
\series default
-<Value>
-\begin_inset LatexCommand \index{-\/-xram-size<Value>}
+ Pass the inline assembler code through the peep hole optimizer.
+ This can cause unexpected changes to inline assembler code, please go through
+ the peephole optimizer
+\begin_inset LatexCommand \index{Peephole optimizer}
\end_inset
- Causes the linker to check if the external ram usage is within limits of
- the given value.
+ rules defined in the source file tree '<target>/peeph.def' before using
+ this option.
\layout List
\labelwidthstring 00.00.0000
\series bold
-TMP
-\begin_inset LatexCommand \index{TMP}
-
-\end_inset
-
-,\SpecialChar ~
-TEMP
-\begin_inset LatexCommand \index{TEMP}
-
-\end_inset
-
-,\SpecialChar ~
+TMP,\SpecialChar ~
+TEMP,\SpecialChar ~
TMPDIR
-\begin_inset LatexCommand \index{TMPDIR}
+\begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
\end_inset
specific storage classes.
\layout Subsubsection
+data
+\begin_inset LatexCommand \index{data}
+
+\end_inset
+
+
+\layout Standard
+
+This is the
+\series bold
+default
+\series default
+ storage class for Small Memory model.
+ Variables declared with this storage class will be allocated in the directly
+ addressable portion of the internal RAM of a 8051, e.g.:
+\layout Verse
+
+
+\family typewriter
+data unsigned char test_data;
+\layout Standard
+
+Writing 0x01 to this variable generates the assembly code:
+\layout Verse
+
+
+\family typewriter
+75*00 01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+\SpecialChar ~
+_test_data,#0x01
+\layout Subsubsection
+
xdata
\begin_inset LatexCommand \index{xdata}
\family typewriter
-xdata unsigned char xduc;
+xdata unsigned char test_xdata;
+\layout Standard
+
+Writing 0x01 to this variable generates the assembly code:
+\layout Verse
+
+
+\family typewriter
+90s00r00\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+\SpecialChar ~
+dptr,#_test_xdata
+\newline
+74\SpecialChar ~
+01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+\SpecialChar ~
+a,#0x01
+\newline
+F0\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+movx\SpecialChar ~
+@dptr,a
+\layout Subsubsection
+
+idata
+\begin_inset LatexCommand \index{idata}
+
+\end_inset
+
+
+\layout Standard
+
+Variables declared with this storage class will be allocated into the indirectly
+ addressable portion of the internal ram of a 8051, e.g.:
+\layout Verse
+
+
+\family typewriter
+idata unsigned char test_idata;
+\layout Standard
+
+Writing 0x01 to this variable generates the assembly code:
+\layout Verse
+
+
+\family typewriter
+78r00\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+\SpecialChar ~
+r0,#_test_idata
+\newline
+76\SpecialChar ~
+01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+\SpecialChar ~
+@r0,#0x01
\layout Subsubsection
-data
-\begin_inset LatexCommand \index{data}
+pdata
+\begin_inset LatexCommand \index{pdata}
\end_inset
\layout Standard
-This is the
-\series bold
-default
-\series default
- storage class for Small Memory model.
- Variables declared with this storage class will be allocated in the directly
- addressable portion of the internal RAM of a 8051, e.g.:
+Paged xdata access is currently not as straightforward as using the other
+ addressing modes of a 8051.
+ The following example writes 0x01 to the address pointed to.
+ Please note, pdata access physically accesses xdata memory.
+ The high byte of the address is determined by port P2 (or in case of some
+ 8051 variants by a separate Special Function Register).
\layout Verse
\family typewriter
-data int iramdata;
+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
+}
+\layout Standard
+
+Generates the assembly code:
+\layout Verse
+
+
+\family typewriter
+75*01 FE\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+ _test_pdata_ptr,#0xFE
+\newline
+78 FE\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+ r0,#0xFE
+\newline
+74 01\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov\SpecialChar ~
+ a,#0x01
+\newline
+F2\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+movx @r0,a
+\layout Standard
+
+Be extremely carefull if you use pdata together with the -
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-xstack
+\begin_inset LatexCommand \index{-\/-xstack}
+
+\end_inset
+
+ option.
\layout Subsubsection
-idata
-\begin_inset LatexCommand \index{idata}
+code
+\begin_inset LatexCommand \index{code}
\end_inset
\layout Standard
-Variables declared with this storage class will be allocated into the indirectly
- addressable portion of the internal ram of a 8051, e.g.:
+'Variables' declared with this storage class will be placed in the code
+ memory:
+\layout Verse
+
+
+\family typewriter
+code unsigned char test_code;
+\layout Standard
+
+Read access to this variable generates the assembly code:
\layout Verse
\family typewriter
-idata int idi;
+90s00r6F\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+mov dptr,#_test_code
+\newline
+E4\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+clr a
+\newline
+93\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+movc a,@a+dptr
\layout Subsubsection
bit
\family typewriter
-bit iFlag;
+bit test_bit;
+\layout Standard
+
+Writing 1 to this variable generates the assembly code:
+\layout Verse
+
+
+\family typewriter
+D2*00\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+setb\SpecialChar ~
+_test_bit
\layout Subsubsection
sfr
\end_inset
- 0x80 P0; /* special function register P0 at location 0x80 */
+ 0x80 P0;\SpecialChar ~
+ /* special function register P0 at location 0x80 */
\newline
sbit at 0xd7 CY; /* CY (Carry Flag
\begin_inset LatexCommand \index{Flags}
\newline
{
\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
...
\newline
\family typewriter
-unsigned char foo() {
+unsigned char foo()
+\newline
+{
\newline
\SpecialChar ~
\SpecialChar ~
\layout Subsection
Overlaying
+\begin_inset LatexCommand \label{sub:Overlaying}
+
+\end_inset
+
+
\begin_inset LatexCommand \index{Overlaying}
\end_inset
\end_inset
- 2 using
-\begin_inset LatexCommand \index{using}
-
-\end_inset
-
- 1
+ 2
\newline
{
\newline
\newline
{
\newline
-..
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+...
\newline
}
\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 vector table for the interrupt number specified.
+ When present, the compiler will insert a call to this routine in the interrupt
+ vector table for the interrupt number specified.
The
\emph on
using
Calling other functions from an interrupt service routine is not recommended,
avoid it if possible.
\newline
+For some pitfalls see section
+\begin_inset LatexCommand \ref{sub:Overlaying}
+
+\end_inset
+
+about Overlaying and section
+\begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
+
+\end_inset
+about Functions using private banks.
\newline
-Also see the _naked modifier.
+
\layout Subsection
Critical Functions
\newline
{
\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
...
\newline
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
...
\newline
\layout Subsection
Naked Functions
+\begin_inset LatexCommand \label{sub:Naked-Functions}
+
+\end_inset
+
+
\begin_inset LatexCommand \index{Naked functions}
\end_inset
data unsigned char counter;
\newline
+
+\newline
void simpleInterrupt(void) interrupt
\begin_inset LatexCommand \index{interrupt}
\family typewriter
-_simpleIterrupt:
+_simpleInterrupt:
\newline
\SpecialChar ~
\SpecialChar ~
reti\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-; MUST explicitly include ret(i) in _naked function.
+; MUST explicitly include ret or reti in _naked function.
+\layout Standard
+
+The #pragma directive EXCLUDE
+\begin_inset LatexCommand \index{\#pragma EXCLUDE}
+
+\end_inset
+
+ also allows to reduce pushing & popping the registers.
\layout Standard
While there is nothing preventing you from writing C code inside a _naked
\layout Subsection
Functions using private banks
+\begin_inset LatexCommand \label{sub:Functions-using-private-banks}
+
+\end_inset
+
+
\begin_inset LatexCommand \index{bank}
\end_inset
One possible use would be to write hardware portable code.
For example, if you have a routine that uses one or more of the microcontroller
I/O pins, and such pins are different for two different hardwares, you
- can declare the I/O pins in you routine using
+ can declare the I/O pins in your routine using:
\layout Verse
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-/*I/O port 0, bit 0*/
+/* I/O port 0, bit 0 */
\newline
bit at 0x81 SCLK;\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-/*I/O port 0, bit 1*/
+/* I/O port 0, bit 1 */
\newline
bit CPOL;\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-/*This is a variable, let the linker allocate this one*/
+/* This is a variable, let the linker allocate this one */
\layout Standard
Similarly, for the second hardware you would use
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-/*I/O port 0, bit 3*/
+/* I/O port 0, bit 3 */
\newline
bit at 0x91 SCLK;\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-/*I/O port 1, bit 1*/
+/* I/O port 1, bit 1 */
\newline
bit CPOL;\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-/*This is a variable, let the linker allocate this one*/
+/* This is a variable, let the linker allocate this one */
\layout Standard
and you can use the same hardware dependent routine without changes, as
.
By default this routine returns 0, if this routine returns a non-zero value,
the static & global variable initialization will be skipped and the function
- main will be invoked Other wise static & global variables will be initialized
- before the function main is invoked.
+ main will be invoked.
+ Otherwise static & global variables will be initialized before the function
+ main is invoked.
You could add a
\emph on
_sdcc_external_startup()
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.
+ See also the compiler option
+\emph on
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash
+/
+\end_inset
+
+-no-xinit
+\emph default
+-
+\emph on
+opt
+\emph default
+
+\begin_inset LatexCommand \index{-\/-no-xinit-opt}
+
+\end_inset
+
+.
\layout Subsection
Inline Assembler Code
.
It is strongly recommended that each assembly instruction (including labels)
be placed in a separate line (as the example shows).
- When the
-\emph on
--
+ When the -
\begin_inset ERT
status Collapsed
/
\end_inset
--peep-asm
+-
+\emph on
+peep-asm
\begin_inset LatexCommand \index{-\/-peep-asm}
\end_inset
assembly within the scope of the function.
The same goes the other way, ie.
labels defines in inline assembly CANNOT be accessed by C statements.
+\layout Standard
+
+An example acessing a C variable is in section
+\begin_inset LatexCommand \ref{sub:Naked-Functions}
+
+\end_inset
+
+.
\layout Subsection
int (16 bit)
These support routines are all developed in ANSI-C to facilitate porting
to other MCUs, although some model specific assembler optimizations are
used.
- The following files contain the described routine, all of them can be found
- in <installdir>/share/sdcc/lib.
+ The following files contain the described routines, all of them can be
+ found in <installdir>/share/sdcc/lib.
\newline
\layout Standard
\layout Standard
-SDCC allows two memory models for MCS51 code, small and large.
+SDCC allows two memory models for MCS51 code,
+\shape slanted
+small
+\shape default
+ and
+\shape slanted
+large
+\shape default
+.
Modules compiled with different memory models should
\emph on
never
See the data sheets at www.dalsemi.com for further information on this part.
\newline
-\newline
-In older versions of the compiler, this option was used with the MCS51 code
- generator (
-\emph on
--mmcs51
-\emph default
-).
- Now, however, the '390 has it's own code generator, selected by the
-\emph on
--mds390
-\emph default
- switch.
-
-\newline
-
\newline
Note that the compiler does not generate any code to place the processor
into 24 bitmode (although
\family typewriter
-iTemp = x + y
+iTemp = x + y;
\newline
-i = iTemp + 1
+i = iTemp + 1;
\newline
-j = iTemp
+j = iTemp;
\layout Standard
Some subexpressions are not as obvious as the above example, e.g.:
\family typewriter
-int global;
+int global;
+\newline
+
\newline
void f () {
\newline
\SpecialChar ~
\SpecialChar ~
i = 1; \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
/* dead store */
\newline
\SpecialChar ~
\family typewriter
-int global; void f ()
+int global;
\newline
-{
+
+\newline
+void f () {
\newline
\SpecialChar ~
\SpecialChar ~
\newline
\SpecialChar ~
\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
f += k + l;
\layout Standard
\newline
\SpecialChar ~
\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
f += itemp;
\layout Standard
\newline
\SpecialChar ~
\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
ar[i*5] = i*3;
\layout Standard
\family typewriter
i = j + 0 ; /* changed to */ i = j;
\newline
-i /= 2; /* changed to */ i >>= 1;
+i /= 2;\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+ /* changed to */ i >>= 1;
\newline
i = j - j ; /* changed to */ i = 0;
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-case 1: ...
+case 0: ...
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-case 2: ...
+case 1: ...
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-case 3: ...
+case 2: ...
\newline
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
\SpecialChar ~
-case 4: ...
+case 3: ...
\newline
}\SpecialChar ~
\layout Standard
Both the above switch statements will be implemented using a jump-table.
+ The example to the right side is slightly more efficient as the check for
+ the lower bound of the jump-table is not needed.
\end_deeper
\layout Itemize
then both the switch statements will be implemented using jump-tables whereas
the unmodified switch statement will not be.
+ You might also consider dummy cases 0 and 5 to 8 in this example.
The pragma NOJTBOUND
\begin_inset LatexCommand \index{\#pragma NOJTBOUND}
...
\newline
-i>>= 4;
+i >>= 4;
\newline
...
\layout Standard
\family typewriter
-mov a,(_i + 1)
+mov\SpecialChar ~
+\SpecialChar ~
+a,(_i + 1)
\newline
-mov (_i + 1),#0x00
+mov\SpecialChar ~
+\SpecialChar ~
+(_i + 1),#0x00
\newline
-clr c
+clr\SpecialChar ~
+\SpecialChar ~
+c
\newline
-rrc a
+rrc\SpecialChar ~
+\SpecialChar ~
+a
\newline
-mov _i,a
+mov\SpecialChar ~
+\SpecialChar ~
+_i,a
\layout Standard
Note that SDCC stores numbers in little-endian format (i.e.
\family typewriter
-mov a,_i
+mov\SpecialChar ~
+\SpecialChar ~
+a,_i
\newline
-rl a
+rl\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+a
\newline
-mov _i,a
+mov\SpecialChar ~
+\SpecialChar ~
+_i,a
\layout Standard
SDCC uses pattern matching on the parse tree to determine this operation.Variatio
\newline
foo () {
\newline
+\SpecialChar ~
+\SpecialChar ~
unsigned char hob;
\newline
\SpecialChar ~
g the variable bindings is passed as a parameter).
If you want to code more such functions, take a close look at the function
labelInRange and the calling mechanism in source file SDCCpeeph.c.
- I know this whole thing is a little kludgey, but maybe some day we will
+ Currently implemented are
+\emph on
+labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
+ 24bitMode, portIsDS390, 24bitModeAndPortDS390
+\emph default
+and
+\emph on
+ notVolatile
+\emph default
+.
+\layout Standard
+
+I know this whole thing is a little kludgey, but maybe some day we will
have some better means.
- If you are looking at this file, you will also see the default rules that
- are compiled into the compiler, you can add your own rules in the default
- set there if you get tired of specifying the -
+ If you are looking at this file, you will see the default rules that are
+ compiled into the compiler, you can add your own rules in the default set
+ there if you get tired of specifying the -
\begin_inset ERT
status Collapsed
\end_inset
- - will stop global subexpression elimination.
+ - will stop global common subexpression elimination.
\layout Itemize
NOINDUCTION
\end_inset
- will not generate code for boundary value checking, when switch statements
- are turned into jump-tables.
+ are turned into jump-tables (dangerous).
+
\layout Itemize
NOOVERLAY
\end_inset
- /* save the current settings */
+ \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/* save the current settings */
\newline
#pragma NOGCSE
\begin_inset LatexCommand \index{\#pragma NOGCSE}
\end_inset
- /* turnoff global subexpression elimination */
+ \SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+/* turnoff global subexpression elimination */
\newline
#pragma NOINDUCTION
\begin_inset LatexCommand \index{\#pragma NOINDUCTION}
Library Routines
\emph on
- <pending: this is messy and incomplete>
+
+\layout Standard
+
+
+\emph on
+<pending: this is messy and incomplete>
\emph default
\layout Enumerate
\layout Enumerate
Math functions (sin, pow, sqrt etc)
+\layout Standard
+
+Libraries included in SDCC should have a license at least as liberal as
+ the GNU Lesser General Public License
+\begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
+
+\end_inset
+
+
+\emph on
+LGPL
+\emph default
+.
\layout Comment
-license statements for the libraries are missing
+license statements for the libraries are missing.
+ sdcc/device/lib/ser_ir.c f.e.
+ comes with a GPL (as opposed to LGPL) License - this will not be liberal
+ enough for many embedded programmers.
\layout Subsection
Interfacing with Assembly Routines
/
\end_inset
--stack-auto is used) or in the internal / external ram (depending on the
- memory model).
+-stack-auto is used) or in data / xdata memory (depending on the memory
+ model).
\layout Subsubsection
\layout Subsection
External Stack
+\begin_inset LatexCommand \label{sub:External-Stack}
+
+\end_inset
+
+
\begin_inset LatexCommand \index{stack}
\end_inset
It would substantially reduce the code generated (future versions of the
compiler will be smart enough to detect such optimization opportunities).
\end_deeper
+\layout Itemize
+
+Have a look at the assembly listing to get a
+\begin_inset Quotes sld
+\end_inset
+
+feeling
+\begin_inset Quotes srd
+\end_inset
+
+ for the code generation.
\layout Subsection
Notes on MCS51 memory
data
\emph default
).
- Usually this built in
+ Sometimes this built in
\emph on
xdata
\emph default
\end_inset
included in the distribution
-\newline
-
\layout Standard
\align center
\end_inset
-\newline
-
\layout Standard
\align center
\end_inset
-
-\begin_inset Foot
-collapsed false
-
-\layout Standard
-
-(sdcdb and ddd are available for Unix only)
-\end_inset
-
-
+ (Unix only)
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\layout Subsection
Related documentation / recommended reading
-\newline
-
\layout Standard
\align center
The Z80 and gbz80 port
\layout Standard
-SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
+SDCC can target both the Zilog
+\begin_inset LatexCommand \index{Z80}
+
+\end_inset
+
+ and the Nintendo Gameboy's Z80-like gbz80
+\begin_inset LatexCommand \index{GameBoy Z80}
+
+\end_inset
+
+.
The port is incomplete - long support is incomplete (mul, div and mod are
unimplemented), and both float and bitfield support is missing.
Apart from that the code generated is correct.
\layout Standard
-As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
+As always, the code is the authoritative reference - see z80/ralloc.c and
+ z80/gen.c.
The stack frame is similar to that generated by the IAR Z80 compiler.
IX is used as the base pointer, HL is used as a temporary register, and
BC and DE are available for holding variables.
if (something)
\layout Standard
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
[basic block 2]
\layout Standard
else
\layout Standard
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
+\SpecialChar ~
[basic block 3]
\layout Standard