0

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 ..
}
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • But I wonder, where is SDCC getting the 0x88 that it actually uses from? If it simply ignores your definition TCON should be undefined. Unless there's another definition hiding in the code somewhere? – Simon Jenkins Jul 26 '13 at 11:46
  • SDCC uses some standard includes and standard libs. The documentation says that using --nostdinc as paramete should prevent the linker of using e.g. 8051.h (which defines all registers - including TCON). But even when I'm using this.. the listing file tells me that I have defined a symbol TCON == 0xA8 but > in the same listing < the instruction `mov TCON, #0x0` is translated to `758800`instead of `75A800` .. – Stefan Falk Jul 26 '13 at 12:02
  • Well 8051.h is defining TCON as 0x88, so it does look like that's the definition that's getting used somehow or other. – Simon Jenkins Jul 26 '13 at 12:28
  • No, I've changed - even deleted this file - but it does not seem to affect anythin. there is a `.sym` file generated. I can find my symbol there defined as `_TCON = 00A8 G` but some lines under I find `TCON = 0088 L` and I still got no idea how to prevent the SDCC on doing that .. – Stefan Falk Jul 26 '13 at 12:57

1 Answers1

0

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

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378