8051 linker problem?

  • I'm trying to build a simple LED blinking program for an 8051 based project. I made a small crtstart.asm that looks like...

        .area GSINIT0 (CODE)
        mov sp,#__start__stack - 1

        .area GSINIT2 (CODE)

    and main.c is...

    #include <stdint.h>
    #include <8051.h>

    void main()
        uint16_t    i;
        P0 = 0;
        P0DIR = 0;

        P0 ^= 0xFF;
        for(i=0; i<0xFF00; ++i);

    If I build like this...

    sdcc --no-xinit-opt --main-return --iram-size 0x80 --std-c99 crtstart.rel main.c

    ...I get a properly flashing LED. However, if I do this...

    sdcc -c --no-xinit-opt --main-return --iram-size 0x80 --std-c99 main.c
    sdcc --no-xinit-opt --main-return --iram-size 0x80 --std-c99 crtstart.rel main.rel

    ...I get a HEX file that doesn't work. What am I doing wrong?

    • Looks like I didn't read the manual...

      "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."

      Listing main.rel first seems to have fixed the problem.