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