No Startup code in Hex file

scot satre
  • 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!   

  • Frieder Ferlemann

    > 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
    (RETurn is expected. If you cannot tolerate the ret instruction use __naked for the function)

    And the .ihx file reads:


  • Jesus Calvino-Fraga

        #include <8051.h>
        void nocrtinit (void) _naked
                ajmp _main
        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.


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

        sdcc -c nomain.c
        sdcc nomain.rel

  • Frieder Ferlemann

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

  • Jesus Calvino-Fraga

    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 :-)


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks