SDCC Compiler User Guide

SDCC Compiler User Guide

SDCC Compiler User Guide SDCC 3.7.1 $Date:: 2018-02-28 #$ $Revision: 10247 $ Contents 1 Introduction 6 1.1 About SDCC.............................................6 1.2 SDCC Suite Licenses.........................................7 1.3 Documentation............................................8 1.4 Typographic conventions.......................................8 1.5 Compatibility with previous versions.................................8 1.6 System Requirements......................................... 10 1.7 Other Resources............................................ 10 2 Installing SDCC 11 2.1 Configure Options........................................... 11 2.2 Install paths.............................................. 13 2.3 Search Paths.............................................. 14 2.4 Building SDCC............................................ 16 2.4.1 Building SDCC on Linux.................................. 16 2.4.2 Building SDCC on Mac OS X................................ 17 2.4.3 Cross compiling SDCC on Linux for Windows....................... 17 2.4.4 Building SDCC using Cygwin and Mingw32........................ 17 2.4.5 Building SDCC Using Microsoft Visual C++ 2010 (MSVC)................ 18 2.4.6 Windows Install Using a ZIP Package............................ 19 2.4.7 Windows Install Using the Setup Program.......................... 19 2.4.8 VPATH feature........................................ 19 2.5 Building the Documentation..................................... 20 2.6 Reading the Documentation..................................... 20 2.7 Testing the SDCC Compiler..................................... 20 2.8 Install Trouble-shooting........................................ 21 2.8.1 If SDCC does not build correctly............................... 21 2.8.2 What the ”./configure” does................................. 21 2.8.3 What the ”make” does.................................... 21 2.8.4 What the ”make install” command does............................ 21 2.9 Components of SDCC........................................ 22 2.9.1 sdcc - The Compiler..................................... 23 2.9.2 sdcpp - The C-Preprocessor................................. 23 2.9.3 sdas, sdld - The Assemblers and Linkage Editors...................... 23 2.9.4 s51, sz80, shc08, sstm8 - The Simulators.......................... 23 2.9.5 sdcdb - Source Level Debugger............................... 23 3 Using SDCC 24 3.1 Standard-Compliance......................................... 24 3.1.1 ISO C90 and ANSI C89................................... 24 3.1.2 ISO C95........................................... 25 3.1.3 ISO C99........................................... 25 3.1.4 ISO C11........................................... 25 3.1.5 Embedded C......................................... 25 3.2 Compiling............................................... 25 1 CONTENTS CONTENTS 3.2.1 Single Source File Projects.................................. 25 3.2.2 Postprocessing the Intel Hex file............................... 26 3.2.3 Projects with Multiple Source Files............................. 26 3.2.4 Projects with Additional Libraries.............................. 27 3.2.5 Using sdar to Create and Manage Libraries......................... 27 3.2.6 Using sdcclib to Create and Manage Libraries (deprecated)1 ................ 27 3.3 Command Line Options........................................ 29 3.3.1 Processor Selection Options................................. 29 3.3.2 Preprocessor Options..................................... 29 3.3.3 Optimization Options..................................... 30 3.3.4 Other Options......................................... 31 3.3.5 Linker Options........................................ 33 3.3.6 MCS51 Options....................................... 34 3.3.7 DS390 / DS400 Options................................... 35 3.3.8 Options common to all z80-related ports (z80, z180, r2k, r3ka, gbz80)........... 35 3.3.9 Z80 Options (apply to z80, z180, r2k and r3ka port)..................... 35 3.3.10 GBZ80 Options........................................ 36 3.3.11 Intermediate Dump Options................................. 36 3.3.12 Redirecting output on Windows Shells............................ 36 3.4 Environment variables........................................ 36 3.5 SDCC Language Extensions..................................... 36 3.5.1 MCS51/DS390 intrinsic named address spaces....................... 37 3.5.1.1 __data / __near.................................. 37 3.5.1.2 __xdata / __far................................... 37 3.5.1.3 __idata....................................... 37 3.5.1.4 __pdata...................................... 37 3.5.1.5 __code....................................... 38 3.5.1.6 __bit........................................ 38 3.5.1.7 __sfr / __sfr16 / __sfr32 / __sbit......................... 38 3.5.1.8 Pointers to MCS51/DS390 intrinsic named address spaces............ 39 3.5.1.9 Notes on MCS51 memory layout......................... 39 3.5.2 Z80/Z180 intrinsic named address spaces.......................... 40 3.5.2.1 __sfr (in/out to 8-bit addresses).......................... 40 3.5.2.2 __banked __sfr (in/out to 16-bit addresses).................... 40 3.5.2.3 __sfr (in0/out0 to 8 bit addresses on Z180/HD64180).............. 41 3.5.3 HC08/S08 intrinsic named address spaces.......................... 41 3.5.3.1 __data....................................... 41 3.5.3.2 __xdata...................................... 41 3.5.4 Non-intrinsic named address spaces............................. 41 3.5.5 Absolute Addressing..................................... 42 3.5.6 Preserved register specification................................ 43 3.5.7 Binary constants....................................... 43 3.5.8 Returning void........................................ 43 3.5.9 Omitting promotion on arguments of vararg function.................... 43 3.6 Parameters and Local Variables.................................... 43 3.7 Overlaying.............................................. 44 3.8 Interrupt Service Routines...................................... 44 3.8.1 General Information..................................... 44 3.8.1.1 Common interrupt pitfall: variable not declared volatile ............. 45 3.8.1.2 Common interrupt pitfall: non-atomic access ................... 45 3.8.1.3 Common interrupt pitfall: stack overflow ..................... 45 3.8.1.4 Common interrupt pitfall: use of non-reentrant functions ............ 45 3.8.2 MCS51/DS390 Interrupt Service Routines.......................... 45 3.8.3 HC08 Interrupt Service Routines............................... 46 1With 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. 2 CONTENTS CONTENTS 3.8.4 Z80 and Z180 Interrupt Service Routines.......................... 46 3.8.5 Rabbit 2000, 3000, 3000A and 4000 Interrupt Service Routines.............. 46 3.8.6 GBZ80 and TLCS-90 Interrupt Service Routines...................... 47 3.8.7 STM8 Interrupt Service Routines.............................. 47 3.9 Enabling and Disabling Interrupts.................................. 47 3.9.1 Critical Functions and Critical Statements.......................... 47 3.9.2 Enabling and Disabling Interrupts directly.......................... 47 3.9.3 Semaphore locking (mcs51/ds390).............................. 48 3.10 Functions using private register banks (mcs51/ds390)........................ 48 3.11 Inline Assembler Code........................................ 49 3.11.1 Inline Assembler Code Formats............................... 49 3.11.1.1 Old __asm ... __endasm; Format......................... 49 3.11.1.2 New __asm__ (”inline_assembler_code”) Format................ 49 3.11.2 A Step by Step Introduction................................. 49 3.11.3 Naked Functions....................................... 51 3.11.4 Use of Labels within Inline Assembler............................ 52 3.12 Interfacing with Assembler Code................................... 53 3.12.1 Global Registers used for Parameter Passing (8051)..................... 53 3.12.2 Registers usage (8051).................................... 53 3.12.3 Assembler Routine (non-reentrant) (8051).......................... 53 3.12.4 Assembler Routine (reentrant) (8051)............................ 54 3.12.5 Small-C calling convention.................................. 55 3.13 Support routines for integer multiplicative operators......................... 55 3.14 Floating Point Support........................................ 55 3.15 Library Routines........................................... 56 3.15.1 Compiler support routines (_gptrget, _mulint etc.)..................... 56 3.15.2 Stdclib functions (puts, printf, strcat etc.).......................... 56 3.15.2.1 <stdio.h>...................................... 56 3.15.2.2 <malloc.h>..................................... 57 3.15.3 Math functions (sinf, powf, sqrtf etc.)............................ 57 3.15.3.1 <math.h>...................................... 57 3.15.4 Other libraries........................................ 58 3.16 Memory Models............................................ 58 3.16.1 MCS51 Memory Models................................... 58 3.16.1.1 Small, Medium, Large and Huge......................... 58 3.16.1.2 External Stack................................... 58 3.16.2 DS390 Memory Model.................................... 58 3.16.3

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    126 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us