assemblymicrocontrollersdccc51

SDCC/C51: Redefine SDCC symbols


I want to compile a program under the SDCC that I used to compile under C51..

// Somewhere in a header file for C51:
sfr TCON = 0xA8; // C51 syntax

// somewhere in a .c-file
#pragma asm

    mov     TCON, #0

#pragma endasm

This will be translated to 75A800 (hex)

     opcode  direct, #immed
mov: 75      A8      00

As I compile this under SDCC this

     opcode  direct, #immed
mov: 75      88      00

which looks like to me that the SDCC ignores my definition of the TCON register which looks like this:

// Somewhere in a header file for SDCC
__sfr __at(0xa8) TCON; // SDCC syntax

So here is my question:

How can I tell the SDCC to use the address which I defined in another header file?

The whole thing of course looks like this:

#include "the-header-file-that-defines-my-registers.h" // defines TCON

void main(void)
{
 // code ..
 #pragma asm

   // more code ..

    mov     TCON, #0

 #pragma endasm

 // more and more code ..
}

Solution

  • I've contacted the SDCC-Dev Team

    On Sat, 27 Jul 2013, Stefan Falk wrote:

    Hello to everyone who receives this!

    I'm sorry to ask that probably rather simple question about the ASXXXX Cross Assembler but I was wondering if or how I could change the standard SFR addresses?

    The processor that I am using is based on the Intel 8051 but a lot of its registers do have new addresses.

    So, is there a way to tell the SDCC to tell the ASXXXX to ignore the predefined SFR and to use mine instead?


    The answer

    I don't think you can without editing the ASXXXX source. However, SDCC only uses a few of the assembler's built-in symbols (from memory, I think it's just ACC, B, DPL, DPH, PSW, and SP) in its code generator. I would be extremely surprised if anyone moved these fundamental CPU related registers. All of the SFR registers defined as the C level (for example, by using #include ) will be explicitly defined at the assembly level, but with an underscore prefix, so it's possible to change the addresses for these symbols to whatever you need, and ignore the predefined symbols. You just need to make sure any assembly you write uses the symbols with the underscore prefix (i.e. "mov a,_P2" rather than "mov a,P2").

    Erik