Questions tagged [sdcc]

SDCC is a retargettable, optimizing ANSI - C compiler suite that targets the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), Maxim (formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) HC08 based (hc08, s08) and Zilog Z80 based MCUs (Z80, Z180, GBZ80, Rabbit 2000/3000, and Rabbit 3000A). Work is in progress on supporting the Microchip PIC16 and PIC18 targets. It can be retargeted for other microprocessors.

SDCC is a retargettable, optimizing ANSI - C compiler suite that targets the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), Maxim (formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) HC08 based (hc08, s08) and Zilog Z80 based MCUs (Z80, Z180, GBZ80, Rabbit 2000/3000, and Rabbit 3000A). Work is in progress on supporting the Microchip PIC16 and PIC18 targets. It can be retargeted for other microprocessors.

The SDCC suite is a collection of several components derived from different sources with different FOSS licenses. The SDCC compiler suite includes:

  • sdas and sdld, a retargettable assembler and linker, based on ASXXXX, written by Alan Baldwin; (GPL).
  • sdcpp preprocessor, based on GCC cpp; (GPL).
  • ucsim simulators, originally written by Daniel Drotos; (GPL).
  • sdcdb source level debugger, originally written by Sandeep Dutta; (GPL).
  • sdbinutils library archive utilities, including sdar, sdranlib and sdnm, derived from GNU Binutils; (GPL)
  • SDCC run-time libraries; (GPL+LE). PIC device libraries and header files are derived from Microchip header (.inc) and linker script (.lkr) files. Microchip requires that "The header files should state that they are only to be used with authentic Microchip devices" which makes them incompatible with the GPL.
  • gcc-test regression tests, derived from gcc-testsuite; (no license explicitely specified, but since it is a part of GCC is probably GPL licensed)
  • packihx; (public domain)
  • makebin; (zlib/libpng License)
  • sdcc C compiler, originally written by Sandeep Dutta; (GPL). Some of the features include: extensive MCU specific language extensions, allowing effective use of the underlying hardware. a host of standard optimizations such as global sub expression elimination, loop optimizations (loop invariant, strength reduction of induction variables and loop reversing), constant folding and propagation, copy propagation, dead code elimination and jump tables for 'switch' statements. MCU specific optimizations, including a global register allocator. Adaptable MCU specific backend that should be well suited for other 8 bit MCUs. Independent rule based peep hole optimizer. A full range of data types: char (8 bits, 1 byte), short (16 bits, 2 bytes), int (16 bits, 2 bytes), long (32 bit, 4 bytes), float (4 byte IEEE) and _Bool/bool; Basic (no integer constants) support for long long (64 bit, 8 bytes) data types for the z80, z180, r2k, r3ka, gbz80, hc08 and s08 targets. The ability to add inline assembler code anywhere in a function. The ability to report on the complexity of a function to help decide what should be re-written in assembler. A good selection of automated regression tests.

SDCC was written by Sandeep Dutta and released under a GPL license. Since its initial release there have been numerous bug fixes and improvements. As of December 1999, the code was moved to SourceForge where all the "users turned developers" can access the same source tree. SDCC is constantly being updated with all the users' and developers' input.

100 questions
6
votes
2 answers

Want to scale int to int with integer math

I am on SDCC 2.8.0, so very limited in memory and code size. Say I have an input value that ranges between 0 and 127, I want to scale it to 20 - 100. Normally I would do: int scale(int input, int min, int max) { // assuming max is always greater…
Mark Miles
  • 706
  • 8
  • 20
5
votes
2 answers

SDCC and malloc() - allocating much less memory than is available

When I run compile this code with SDCC 3.1.0, and run it on an Amstrad CPC 464 (under emulation, with WinCPC 0.9.26 running on Wine): void _test_malloc() { long idx = 0; while (1) { if (malloc(5)) { printf("%ld\r\n", ++idx); …
Duncan Bayne
  • 3,870
  • 4
  • 39
  • 64
5
votes
1 answer

Setup Xcode for using external compiler

I am trying to use Xcode as an editor for microcontroller code. I want to use the Build, Run buttons. How can i use those to trigger a script that compiles the program ? I already have a script that works on the command line. I need to pass some…
jelipito
  • 171
  • 2
  • 2
  • 12
4
votes
2 answers

How does C programming work with no headers?

I'm familiar with the C programming language and z80 assembly and I have made a simple z80 "computer" with just the cpu with 32k of ram, 32k of rom, and an 8255 pia for io control. I have gotten the 8255 to bling an LED with my system through an…
4
votes
1 answer

Problems combining SDCC and ASM code compiling on the Intel 8051

We are trying to compile our C code which includes a lot of assembly for various operations (timing, producing output waveforms, and measuring input frequency). We keep getting the same error for a few of our ASM operations: ".org in REL area or…
Russell
  • 368
  • 2
  • 4
  • 17
4
votes
1 answer

Can't figure out how to write interrupt handler for Z80 using SDCC

I'm developing a program in C for the Z80 and compiling using SDCC. I can't figure out how to create interrupt handlers for the NMI interrupt that starts at 0x0066 and the IM1 interrupt that starts at 0x0038. I'm using these calls: void…
ajcrm125
  • 323
  • 2
  • 12
4
votes
4 answers

Ways to divide the high/low byte from a 16bit address?

I'm developing a software on 8051 processor. A frequent job is to divide the high and low byte of a 16bit address. I want to see there are how many ways to achieve it. The ways I come up so far are: (say ptr is a 16bit pointer, and int is 16bit int)…
Grissiom
  • 11,355
  • 3
  • 18
  • 23
4
votes
2 answers

uploading a compiled program to a C51 microcontroller

I'm trying to upload a compiled program to a microcontroller.. well my problem is not in programming or uploading things.. my problem is what to upload u.u The program is in C and was compiled with SDCC. The mcu is an AT89S8252 by ATMEL. I built a…
royconejo
  • 2,213
  • 3
  • 24
  • 29
4
votes
2 answers

Code Banking with SDCC

I need to use code banking in an 8051 microcontroller to fit all the code. SDCC says it supports it, but I'm having trouble at the linking step. I have a test project with 3 files: main.c, func1.c, and bank.asm. The main function should call…
Robert Deml
  • 12,390
  • 20
  • 65
  • 92
3
votes
1 answer

SDCC assign memory address to pointer, no effect

I've been mulling over this for the last couple of days, and i cant see what is wrong with my code. Really just looking to assign two memory addresses to two pointers. ROM at 0x0000 and RAM at 0x7000. The program compiles, but instead of writing…
eJm
  • 109
  • 2
  • 9
3
votes
1 answer

VScode: Disable syntax highlighting for a range of lines

I'm using SDCC's inline assembly syntax for my project: void delay_ms(uint16_t ms) { _ms = ms; __asm ldw y, __ms ; Load ms counter into y register: 2 cycles 0000$: ldw x, _CYCLES_PER_MS ; Load tick counter into…
CTXz
  • 716
  • 5
  • 5
3
votes
3 answers

Why and when malloc() will not be available in C?

I've been given a 8051 based board with an embedded in-house operating system. I am using SDCC to create applications above the OS. And malloc is not available so I have to allocate memory statically. Why is that? Isn't malloc supposed to be on a…
3
votes
0 answers

Compiling for PIC16F with SDCC: on RPi: libsdcc.lib: no such file or directory

I've compiled SDCC 3.7.0 on a Raspberry Pi 2. But I'm having diffuculty with the next step: compiling a blink.c with SDCC: sdcc -mpic14 -p16f887 blink.c --use-non-free It just returns "libsdcc.lib: no such file or directory". Please help!
Jodes
  • 14,118
  • 26
  • 97
  • 156
3
votes
0 answers

How can I handle 'processor mismatch' warnings without silencing them or including custom built copies of the dependencies?

I have a C project for a PIC that I am building with SDCC 3.6.3 and gputils 1.5.0, both of which I built from source. When linking my project, I get the following error messages from gplink: warning: Processor mismatch in "streams.o". warning:…
EchoLynx
  • 410
  • 5
  • 11
3
votes
2 answers

Performing an action over each source file with make

I have created a Makefile like this CC = sdcc SRCS = $(PNAME).c\ ../../src/gpio.c ../../src/timers.c ../../src/i2c.c $HDRS = -I../../headers all: mkdir -p ./output $(CC) $(SRCS) -lstm8 -mstm8 $(HDRS) The problem is, sdcc can…
Dumbo
  • 13,555
  • 54
  • 184
  • 288
1
2 3 4 5 6 7