Next:
Contents
Contents
Index
SDCC Compiler User Guide
SDCC
$Date:: 2018-08-20 #$
$Revision: 10509 $
Contents
1
. Introduction
1
.
1
About SDCC
1
.
2
SDCC Suite Licenses
1
.
3
Documentation
1
.
4
Typographic conventions
1
.
5
Compatibility with previous versions
1
.
6
System Requirements
1
.
7
Other Resources
2
. Installing SDCC
2
.
1
Configure Options
2
.
2
Install paths
2
.
3
Search Paths
2
.
4
Building SDCC
2
.
4
.
1
Building SDCC on Linux
2
.
4
.
2
Building SDCC on Mac OS X
2
.
4
.
3
Cross compiling SDCC on Linux for Windows
2
.
4
.
4
Building SDCC using Cygwin and Mingw32
2
.
4
.
5
Building SDCC Using Microsoft Visual C++ 2010 (MSVC)
2
.
4
.
6
Windows Install Using a ZIP Package
2
.
4
.
7
Windows Install Using the Setup Program
2
.
4
.
8
VPATH feature
2
.
5
Building the Documentation
2
.
6
Reading the Documentation
2
.
7
Testing the SDCC Compiler
2
.
8
Install Trouble-shooting
2
.
8
.
1
If SDCC does not build correctly
2
.
8
.
2
What the ”./configure” does
2
.
8
.
3
What the ”make” does
2
.
8
.
4
What the ”make install” command does.
2
.
9
Components of SDCC
2
.
9
.
1
sdcc - The Compiler
2
.
9
.
2
sdcpp - The C-Preprocessor
2
.
9
.
3
sdas, sdld - The Assemblers and Linkage Editors
2
.
9
.
4
s51, sz80, shc08, sstm8 - The Simulators
2
.
9
.
5
sdcdb - Source Level Debugger
3
. Using SDCC
3
.
1
Standard-Compliance
3
.
1
.
1
ISO C90 and ANSI C89
3
.
1
.
2
ISO C95
3
.
1
.
3
ISO C99
3
.
1
.
4
ISO C11
3
.
1
.
5
ISO C2X
3
.
1
.
6
Embedded C
3
.
2
Compiling
3
.
2
.
1
Single Source File Projects
3
.
2
.
2
Postprocessing the Intel Hex file
3
.
2
.
3
Projects with Multiple Source Files
3
.
2
.
4
Projects with Additional Libraries
3
.
2
.
5
Using sdar to Create and Manage Libraries
3
.
2
.
6
Using sdcclib to Create and Manage Libraries (deprecated)typeset@protect @@footnote SF@gobble@opt With SDCC version 3.2.0 the sdcclib utility is deprecated. Sdar utility should be used to create sdcc object file archives. Sdcclib utility will become obsolete in one of next sdcc releases and will be removed from sdcc packages.
3
.
3
Command Line Options
3
.
3
.
1
Processor Selection Options
3
.
3
.
2
Preprocessor Options
3
.
3
.
3
Optimization Options
3
.
3
.
4
Other Options
3
.
3
.
5
Linker Options
3
.
3
.
6
MCS51 Options
3
.
3
.
7
DS390 / DS400 Options
3
.
3
.
8
Options common to all z80-related ports (z80, z180, r2k, r3ka, gbz80)
3
.
3
.
9
Z80 Options (apply to z80, z180, r2k and r3ka port)
3
.
3
.
10
GBZ80 Options
3
.
3
.
11
Intermediate Dump Options
3
.
3
.
12
Redirecting output on Windows Shells
3
.
4
Environment variables
3
.
5
SDCC Language Extensions
3
.
5
.
1
MCS51/DS390 intrinsic named address spaces
3
.
5
.
1
.
1
__data / __near
3
.
5
.
1
.
2
__xdata / __far
3
.
5
.
1
.
3
__idata
3
.
5
.
1
.
4
__pdata
3
.
5
.
1
.
5
__code
3
.
5
.
1
.
6
__bit
3
.
5
.
1
.
7
__sfr / __sfr16 / __sfr32 / __sbit
3
.
5
.
1
.
8
Pointers to MCS51/DS390 intrinsic named address spaces
3
.
5
.
1
.
9
Notes on MCS51 memory layout
3
.
5
.
2
Z80/Z180 intrinsic named address spaces
3
.
5
.
2
.
1
__sfr (in/out to 8-bit addresses)
3
.
5
.
2
.
2
__banked __sfr (in/out to 16-bit addresses)
3
.
5
.
2
.
3
__sfr (in0/out0 to 8 bit addresses on Z180/HD64180)
3
.
5
.
3
HC08/S08 intrinsic named address spaces
3
.
5
.
3
.
1
__data
3
.
5
.
3
.
2
__xdata
3
.
5
.
4
Non-intrinsic named address spaces
3
.
5
.
5
Absolute Addressing
3
.
5
.
6
Preserved register specification
3
.
5
.
7
Binary constants
3
.
5
.
8
Returning void
3
.
5
.
9
Omitting promotion on arguments of vararg function
3
.
6
Parameters and Local Variables
3
.
7
Overlaying
3
.
8
Interrupt Service Routines
3
.
8
.
1
General Information
3
.
8
.
1
.
1
Common interrupt pitfall: variable not declared
volatile
3
.
8
.
1
.
2
Common interrupt pitfall:
non-atomic access
3
.
8
.
1
.
3
Common interrupt pitfall:
stack overflow
3
.
8
.
1
.
4
Common interrupt pitfall:
use of non-reentrant functions
3
.
8
.
2
MCS51/DS390 Interrupt Service Routines
3
.
8
.
3
HC08 Interrupt Service Routines
3
.
8
.
4
Z80 and Z180 Interrupt Service Routines
3
.
8
.
5
Rabbit 2000, 3000, 3000A and 4000 Interrupt Service Routines
3
.
8
.
6
GBZ80 and TLCS-90 Interrupt Service Routines
3
.
8
.
7
STM8 Interrupt Service Routines
3
.
9
Enabling and Disabling Interrupts
3
.
9
.
1
Critical Functions and Critical Statements
3
.
9
.
2
Enabling and Disabling Interrupts directly
3
.
9
.
3
Semaphore locking (mcs51/ds390)
3
.
10
Functions using private register banks(mcs51/ds390)
3
.
11
Inline Assembler Code
3
.
11
.
1
Inline Assembler Code Formats
3
.
11
.
1
.
1
Old __asm ... __endasm; Format
3
.
11
.
1
.
2
New __asm__ (”inline_assembler_code”) Format
3
.
11
.
2
A Step by Step Introduction
3
.
11
.
3
Naked Functions
3
.
11
.
4
Use of Labels within Inline Assembler
3
.
12
Interfacing with Assembler Code
3
.
12
.
1
Global Registers used for Parameter Passing (8051)
3
.
12
.
2
Registers usage (8051)
3
.
12
.
3
Assembler Routine (non-reentrant) (8051)
3
.
12
.
4
Assembler Routine (reentrant) (8051)
3
.
12
.
5
Small-C calling convention
3
.
13
Support routines for integer multiplicative operators
3
.
14
Floating Point Support
3
.
15
Library Routines
3
.
15
.
1
Compiler support routines (_gptrget, _mulint etc.)
3
.
15
.
2
Stdclib functions (puts, printf, strcat etc.)
3
.
15
.
2
.
1
<stdio.h>
3
.
15
.
2
.
2
<malloc.h>
3
.
15
.
3
Math functions (sinf, powf, sqrtf etc.)
3
.
15
.
3
.
1
<math.h>
3
.
15
.
4
Other libraries
3
.
16
Memory Models
3
.
16
.
1
MCS51 Memory Models
3
.
16
.
1
.
1
Small, Medium, Large and Huge
3
.
16
.
1
.
2
External Stack
3
.
16
.
2
DS390 Memory Model
3
.
16
.
3
STM8 Memory Models
3
.
17
Pragmas
3
.
18
Defines Created by the Compiler
4
. Notes on supported Processors
4
.
1
MCS51 variants
4
.
1
.
1
pdata access by SFR
4
.
1
.
2
Other Features available by SFR
4
.
1
.
3
Bankswitching
4
.
1
.
3
.
1
Hardware
4
.
1
.
3
.
2
Software
4
.
1
.
4
MCS51/DS390 Startup Code
4
.
2
DS400 port
4
.
3
The Z80, Z180, Rabbit 2000/3000, Rabbit 3000A and GBZ80 ports
4
.
3
.
1
Startup Code
4
.
3
.
2
Complex instructions
4
.
3
.
3
Calling convention
4
.
3
.
4
Unsafe reads
4
.
4
The HC08 and S08 ports
4
.
4
.
1
Startup Code
4
.
5
The PIC14 port
4
.
5
.
1
PIC Code Pages and Memory Banks
4
.
5
.
2
Adding New Devices to the Port
4
.
5
.
3
Interrupt Code
4
.
5
.
4
Configuration Bits
4
.
5
.
5
Linking and Assembling
4
.
5
.
6
Command-Line Options
4
.
5
.
7
Environment Variables
4
.
5
.
8
The Library
4
.
5
.
8
.
1
Enhanced cores
4
.
5
.
8
.
2
Accessing bits of special function registers
4
.
5
.
8
.
3
Naming of special function registers
4
.
5
.
8
.
4
error: missing definition for symbol “__gptrget1”
4
.
5
.
8
.
5
Processor mismatch in file “XXX”.
4
.
5
.
9
Known Bugs
4
.
5
.
9
.
1
Function arguments
4
.
5
.
9
.
2
Regression tests fail
4
.
6
The PIC16 port
4
.
6
.
1
Global Options
4
.
6
.
2
Port Specific Options
4
.
6
.
2
.
1
Code Generation Options
4
.
6
.
2
.
2
Optimization Options
4
.
6
.
2
.
3
Assembling Options
4
.
6
.
2
.
4
Linking Options
4
.
6
.
2
.
5
Debugging Options
4
.
6
.
3
Environment Variables
4
.
6
.
4
Preprocessor Macros
4
.
6
.
5
Directories
4
.
6
.
6
Pragmas
4
.
6
.
7
Header Files and Libraries
4
.
6
.
8
Header Files
4
.
6
.
9
Libraries
Building the libraries
Output of float values via printf()
4
.
6
.
10
Adding New Devices to the Port
4
.
6
.
11
Memory Models
4
.
6
.
12
Stack
4
.
6
.
13
Functions
4
.
6
.
14
Function return values
4
.
6
.
15
Interrupts
4
.
6
.
16
Generic Pointers
4
.
6
.
17
Configuration Bits
4
.
6
.
18
PIC16 C Libraries
4
.
6
.
18
.
1
Standard I/O Streams
4
.
6
.
18
.
2
Printing functions
4
.
6
.
18
.
3
Signals
4
.
6
.
19
PIC16 Port – Tips
4
.
6
.
19
.
1
Stack size
4
.
6
.
20
Known Bugs
4
.
6
.
20
.
1
Extended Instruction Set
4
.
6
.
20
.
2
Regression Tests
5
. Debugging
5
.
1
Debugging with SDCDB
5
.
1
.
1
Compiling for Debugging
5
.
1
.
2
How the Debugger Works
5
.
1
.
3
Starting the Debugger SDCDB
5
.
1
.
4
SDCDB Command Line Options
5
.
1
.
5
SDCDB Debugger Commands
break [line | file:line | function | file:function]
clear [line | file:line | function | file:function ]
continue
finish
delete [n]
info [break | stack | frame | registers ]
step
next
run
ptype variable
print variable
file filename
frame
set srcmode
! simulator command
quit
5
.
1
.
6
Interfacing SDCDB with DDD
5
.
1
.
7
Interfacing SDCDB with XEmacs
6
. TIPS
6
.
1
Porting code from or to other compilers
6
.
2
Tools included in the distribution
6
.
3
Documentation included in the distribution
6
.
4
Communication online at SourceForge
6
.
5
Related open source tools
6
.
6
Related documentation / recommended reading
6
.
7
Application notes specifically for SDCC
6
.
8
Some Questions
7
. Support
7
.
1
Reporting Bugs
7
.
2
Requesting Features
7
.
3
Submitting patches
7
.
4
Getting Help
7
.
5
ChangeLog
7
.
6
Subversion Source Code Repository
7
.
7
Release policy
7
.
8
Quality control
7
.
9
Examples
7
.
10
Use of SDCC in Education
8
. SDCC Technical Data
8
.
1
Optimizations
8
.
1
.
1
Sub-expression Elimination
8
.
1
.
2
Dead-Code Elimination
8
.
1
.
3
Copy-Propagation
8
.
1
.
4
Loop Optimizations
8
.
1
.
5
Loop Reversing
8
.
1
.
6
Algebraic Simplifications
8
.
1
.
7
'switch' Statements
8
.
1
.
8
Bit-shifting Operations.
8
.
1
.
9
Bit-rotation
8
.
1
.
10
Nibble and Byte Swapping
8
.
1
.
11
Highest Order Bit / Any Order Bit
8
.
1
.
12
Higher Order Byte / Higher Order Word
8
.
1
.
13
Placement of Bank-Selection Instructions
8
.
1
.
14
Lifetime-Optimal Speculative Partial Redundancy Elimination
8
.
1
.
15
Register Allocation
8
.
1
.
16
Peephole Optimizer
8
.
2
Cyclomatic Complexity
8
.
3
Retargetting for other Processors
9
. Compiler internals
9
.
1
The anatomy of the compiler
9
.
2
A few words about basic block successors, predecessors and dominators
10
. Acknowledgments
Alphabetical index
Index