This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

startup.asm

Hi,
I am starting studying 8051 uC and want to learn 8051 embedded programming, I have silabs 8051f340dk to use.
Just want to ask this, why I should use startup.asm? I've seen a lot of program did use this startup.asm, the bootloader has one and the firmware also has startup.asm loaded.
I am just a little confused since my very basic program that don't use startup.asm run smoothly.
How does startup.asm affect my firmware if I'm gonna use it?

thanks
gi

Parents
  • Indeed. That's because the Keil C51 tools do not use the name "startup.asm" - they use "startup.a51" or similar.

    It should be obvious that, if you ask questions on the Keil forum, you will get answers that are specific to (or, at least, focussed on) Keil!

    http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm does tell you exactly what startup.a51 does - it gives you an 8-point list!!

    In addition, you can add any other initialisations that are either necessary or useful before the rest of the code runs; eg, to enable external memory, do a memory test,...

Reply
  • Indeed. That's because the Keil C51 tools do not use the name "startup.asm" - they use "startup.a51" or similar.

    It should be obvious that, if you ask questions on the Keil forum, you will get answers that are specific to (or, at least, focussed on) Keil!

    http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm does tell you exactly what startup.a51 does - it gives you an 8-point list!!

    In addition, you can add any other initialisations that are either necessary or useful before the rest of the code runs; eg, to enable external memory, do a memory test,...

Children
  • Thanks Andy for clarifying,
    One question though, Am I not able to clear internal and external data memory, initializes the small model re-entrant stack and pointer, etc, in my C code not in startup.a51?

    thanks
    gi


  • No.

    The 'C' code relies upon all those things having been done before it starts!

    This is true of the vast majority of all 'C' compilers - not just 8051; not just Keil; not even just embedded.

    (if you don't explicitly include a startup.a51 in your project, the Keil tools implicitly includes the deault).

    http://www.keil.com/books

  • Thank you very much for such a reply.
    Now I can continue...

    thanks for helping.
    gp

  • A C program uses variables.

    What would happen if your initialization code requires variables that are stored in RAM and not in registers, and you then tries to initialize all your variables? Wouldn't your initialization code then get into serious troubles?

    What would happen if main() tries to call a function called init(), if you don't already have set up a stack, so the processor knows where to store the return address and where to save any registers that should be retained after the call?

    What would happen if main() would try to call malloc() to allocate some memory, if you hadn't already setup any heep for malloc() to carve memory from?

    How would the processor know where main() is located, if you don't have a startup file that hooks the reset vector and somewhere during the startup performs a jump to main()?

    There are a number of reasons for having a startup file. One of them is that the C language standard requires that some things should have already been fixed before you enter main(). Having all global variables having received an initial value is such a language standard requirement.

  • Well explained. Thank you sir.
    Is there a need for my firmware to use Init.a51? Some firmware code I have seen they initialize variables(bit, data, idata, pdata, xdata, and far) in there C code not in Init.a51 I may think this file is optional, is my understanding correct?

    I will document this for future use for beginners like me that is eager to learn uC programming.

    thanks
    gp

  • ... is documented here: http://www.keil.com/support/man/docs/c51/c51_ap_init.htm

    "I will document this for future use"

    That is noble of you, but have you studied any of the books mentioned earlier?
    Or any other books on the subject?

    It would be a shame to spend time repeating what is already widely available...

  • Ok, I have seen it.
    "[Keil] strongly recommend that you do not modify the INIT.A51 file."

    thanks for the help.
    gp