SDCC

From OLPC
Revision as of 17:18, 9 June 2007 by RafaelOrtiz (talk | contribs) (Multiple Source file proyects)
Jump to: navigation, search

SDCC is a small Device C Compiler that was specifically designed to the needs of 8 Bit Micros like Intel 8051, Maxim 80DS390, Zilog Z80 among others. SDCC comes with SDCDB a source level debugger and ucSim a free open source simulator for Intel 8051 and other micro-controllers

Installation

Debian

apt-get install sdcc

Working with SDCC

Compiling a program

Write this in an ASCII editor and call the archive test.c (Or wathever name you want):

char test;
void main(void) {
   test=0;
}

Then:

sdcc -c test.c

The -c option is for disable the linker, the next step is trying without the linker:

sdcc test.c

Final test, modify the test file and include the following (if all goes without warnings SDCC is well instaled):

#include <string.h>
char str1[10];
void main(void) {
 strcpy(str1, "testing");
}

this is needed to test that SDCC supports libraries.

For OLPC we are going to work with the 8051 processor, for single source file 8051 projects you can Compile your programs with the following command:

sdcc sourcefile.c   

When doing this command the output files are as follows:

  • sourcefile.asm - Assembler source file created by the compiler
  • sourcefile.lst - Assembler listing file created by the Assembler
  • sourcefile.rst - Assembler listing file updated with linkedit information, created by linkage editor
  • sourcefile.sym - symbol listing for the sourcefile, created by the assembler
  • sourcefile.rel or sourcefile.o - Object file created by the assembler, input to Linkage editor
  • sourcefile.map - The memory map for the load module, created by the Linker
  • sourcefile.mem - A file with a summary of the memory usage
  • sourcefile.ihx - The load module in Intel hex format (you can select the Motorola S19 format with --out-fmt-s19. If you need another format you might want to use objdump or srecord).
  • sourcefile.adb - An intermediate file containing debug information needed to create the .cdb file (with --debug)
  • sourcefile.cdb - An optional file (with --debug) containing debug information.
  • sourcefile. - (no extension) An optional AOMF or AOMF51 file containing debug information (generated with option --debug). The (Intel) absolute object module format is a sub-format of the OMF51 format and is commonly used by third party tools (debuggers, simulators, emulators).
  • sourcefile.dump* - Dump file to debug the compiler itself (generated with option --dumpall)

Multiple Source file proyects

SDCC can compile only ONE file at a time. For example assume that you have a project containing the following files:

  • Ex1.c (contains some functions)
  • Ex2.c (contains some more functions)
  • Exmain.c (with more functions and the function main)

The first two files will need to be compiled separately with the commands:

  • sdcc -c Ex1.c
  • sdcc -c Ex2.c

Then compile the source file containing the main() function and link the files together with the following command: sdcc Exmain.c Ex1.rel Ex2.rel Alternatively, Exmain.c can be separately compiled as well:

  • sdcc -c Exmain.c
  • sdcc Exmain.rel Ex1.rel Ex2.rel

The file containing the main() function Must be the First file specified in the command line, since the linkage editor processes file in the order they are presented to it. The linker is invoked from SDCC using a script file with extension .lnk. You can view this file to troubleshoot linking problems such as those arising from missing libraries.

Related Documentation

If you want to see more documentation specifically for the 8051 try this file:

/usr/share/sdcc/include/mcs51/

SDCDB

Compilling for Debugging

--debug When this option is used the compiler will generate debug information. The debug information collected in a file with .cdb extension can be used with the SDCDB. Another file with no extension contains debug information in AOMF or AOMF51 format which is commonly used by third party tools.

Ucsim

Links