SDCC Compiler User Guide

SDCC Compiler User Guide

Chapter 1



About SDCC

SDCC (Small Device C Compiler) is an open source, retargettable, optimizing ANSI-C compiler by Sandeep

Dutta designed for 8 bit Microprocessors.

The current version targets Intel MCS51 based Microprocessors

(8031, 8032, 8051, 8052, 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. SDCC uses ASXXXX & ASLINK, an open source retargettable assembler & linker. SDCC has extensive language extensions suitable for utilizing various microcontrollers and underlying hardware effectively.

In addition to the MCU specific optimizations SDCC also does a host of standard optimizations like:

• global sub expression elimination,

• loop optimizations (loop invariant, strength reduction of induction variables and loop reversing),

• constant folding & propagation,

• copy propagation,

• dead code elimination

• jump tables for switch statements.

For the back-end SDCC uses a global register allocation scheme which should be well suited for other 8 bit MCUs.

The peep hole optimizer uses a rule based substitution mechanism which is MCU independent.

Supported data-types are:

• char (8 bits, 1 byte),

• short and int (16 bits, 2 bytes),

• long (32 bit, 4 bytes)

• float (4 byte IEEE).

The compiler also allows inline assembler code to be embedded anywhere in a function. In addition, routines developed in assembly can also be called.

SDCC also provides an option (--cyclomatic) to report the relative complexity of a function.

These functions can then be further optimized, or hand coded in assembly if needed.

SDCC also comes with a companion source level debugger SDCDB, the debugger currently uses ucSim a freeware


1.2. OPEN SOURCE CHAPTER 1. INTRODUCTION simulator for 8051 and other micro-controllers. SDCDB and ucSim are currently not available on Win32 platforms.

The latest version can be downloaded from


Please note: the

compiler will probably always be some steps ahead of this documentation




Open Source

All packages used in this compiler system are open source and freeware; source code for all the sub-packages

(pre-processor, assemblers, linkers etc) is distributed with the package. This documentation is maintained using a freeware word processor (LYX).

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public

License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA

02111-1307, USA. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding!


Typographic conventions

Throughout this manual, we will use the following convention. Commands you have to type in are printed in



Code samples are printed in typewriter font. Interesting items and new terms are printed in italic.


Compatibility with previous versions

This version has numerous bug fixes compared with the previous version. But we also introduced some incompatibilities with older versions. Not just for the fun of it, but to make the compiler more stable, efficient and ANSI compliant (see section


for ANSI-Compliance).

• short is now equivalent to int (16 bits), it used to be equivalent to char (8 bits) which is not ANSI compliant.

• the default directory for gcc-builds where include, library and documentation files are stored is now in


• char type parameters to vararg functions are casted to int unless explicitly casted, e.g.: char a=3; printf ("%d %c\n", a, (char)a); will push a as an int and as a char resp.

• option --regextend has been removed.

• option --noregparms has been removed.

• option --stack-after-data has been removed.

• bit and sbit types now consistently behave like the C99 _Bool type with respect to type conversion. The most common incompatibility resulting from this change is related to bit toggling idioms, e.g.: bit b; b = ~b; /* equivalent to b=1 instead of toggling b */ b = !b; /* toggles b */

In previous versions, both forms would have toggled the bit.

<pending: more incompatibilities?>


Obviously this has pros and cons




System Requirements

What do you need before you start installation of SDCC? A computer, and a desire to compute. The preferred method of installation is to compile SDCC from source using GNU gcc and make. For Windows some pre-compiled binary distributions are available for your convenience. You should have some experience with command line tools and compiler use.


Other Resources

The SDCC home page at is a great place to find distribution sets. You can also find links to the user mailing lists that offer help or discuss SDCC with other SDCC users. Web links to other SDCC related sites can also be found here. This document can be found in the DOC directory of the source package as a text or HTML file. A pdf version of this document is available at doc/sdccman.pdf

. Some of the other tools (simulator and assembler) included with SDCC contain their own documentation and can be found in the source distribution. If you want the latest unreleased software, the complete source package is available directly by anonymous CVS on


Wishes for the future

There are (and always will be) some things that could be done. Here are some I can think of: char KernelFunction3(char p) at 0x340; better code banking support for mcs51

If you can think of some more, please see the section


about filing feature requests.


Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF


Table of contents