Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

No Startup code in Hex file

Help
scot satre
2010-01-04
2013-03-12
  • scot satre
    scot satre
    2010-01-04

    I do not want any "startup" code in my hex file.

    My simple program:

    void main(void) {
    P1 = 0x54;
    }

    The only code I want to see in my hex file is:
    75 90 54

    How do I accomplish this? Thanks!   

     
  • > The only code I want to see in my hex file is: 75 90 54

    There is no command line option to accomplish this but you can get there with some trickery.

    The idea is to let the linker only use the .rel file and link this as the only file.
    In detail:
    let's name the program "nostartup.c". Compile it using the -V option:

    > sdcc -V nostartup.c

    The linker command within the output is:
    <pre><code>"/usr/local/bin/sdld" -nf "nostartup.lnk"</code></pre>
    (line looks different if you're not on Unix).

    Copy the file "nostartup.lnk" to "nostartup.pure.lnk".

    Outcomment or remove all the lines in "nostartup.pure.lnk" that start with "-k" or "-l". (use ";" to outcomment)

    Then edit the file nostartup.c chainging the name "main" to something else (f.e. "nomain").

    Compile nostartup.c again using the -c option:
    > sdcc -c nostartup.c

    Then link the generated nostartup.rel file using the modified .lnk file:
    > "/usr/local/bin/sdld" -nf "nostartup.pure.lnk"

    Now the .rst file should show the expected:
    <pre><code>0000 75 90 54   mov     _P1,#0x54
    0003 22         ret
    </code></pre>
    (RETurn is expected. If you cannot tolerate the ret instruction use __naked for the function)

    And the .ihx file reads:
    <pre><code>:040000007590542281
    :00000001FF
    </code></pre>

    Greetings,
    Frieder

     
  •     #include <8051.h>
       
        void nocrtinit (void) _naked
        {
        _asm
        __mcs51_genXINIT::
        __mcs51_genXRAMCLEAR::
        __mcs51_genRAMCLEAR::
        __sdcc_gsinit_startup::
                ajmp _main
            _endasm;
        }
       
        void main(void)
        {
            P1 = 0x54;
        }

     
  • scot satre
    scot satre
    2010-01-05

    Thanks, frief and jesusc. I think a command line option to cancel the "startup" would be good. especially for those who want/need total control in how their micro starts…Scot

     
  • Maarten Brock
    Maarten Brock
    2010-01-05

    Whoah, such difficult solutions for such an easy problem!

    Just don't name your function "main" and compile it. Then link the resulting object.

    nomain.c:

        #include <8052.h>
       
        void nomain(void)
        {
            P1 = 0x54;
        }
    Then do:

        sdcc -c nomain.c
        sdcc nomain.rel
    Maarten   

     
  • Thanks that was a very enlightening thread!
    So easy - I'm still chuckling over my proposal!)

     
  • Good one Maarten!  Add "_naked" and the output is exactly what Scot wants:

        #include <8052.h>
       
        void nomain(void) _naked
        {
            P1 = 0x54;
        }

     
  • scot satre
    scot satre
    2010-01-07

    Excellent Maarten! Thanks :-)