Hello, I written simple c program mention below by selecting the lpc2148 chip but not include its startup file in the project. when i run it will go in infinite loop. I also put the break point but i think its not coming to that execution line. Is it necessary to include startup file? void main() { int a=2,b=3,c; c= a+b; }
but not include its startup file in the project.
That makes less of a difference than you think. The linker will insist on having some startup file. If you refuse to put one in the project, it'll still pick one from the library. Go figure.
so how do you stop it gettnig the library?
Why the great debate to a simple problem? Just add the startup file to your project and compile it and, guess what? your code will startup. Why are you trying so hard to avoid using the startup file. It is required to setup vectors, stack, heap, and initialise data etc. In theory you could locate your main() at the processor's start address but then you would still end up having to do what the startup files does at the beginning of your main() function.
Just use the startup file and stop wasting your time trying to avoid it!
can i write my own start up codes and librarys?
Yes. But why would you?
Why the great debate to a simple problem?
I guess you don't like schools or knowledge. Why understand things when you can just follow a magic recipe? Problem is, you need to understand things to be able to take later steps and be able to deduce where these steps will lead you.
In the end, a problem is only simple if you already know the answer - or have failed to see the real problem that needs to be solved.
Per, you guessed wrong!
The question asked was "Is it necessary to include startup file?" and the simple answer is yes because of the need to set up stack, heap, vars etc. It didn't require you to show off your superior knowledge and confuse this beginner even more.
Also this forum is meant to be for Keil/ARM related issues so the answer to the newbie's question is "yes, you need to use the startup file - go and read a decent 'C' book or visit a 'C' forum if you want to know why startup code is required for processors".
This forum would be more useful if all the 'C' questions were blocked and the posts were limited to Keil/ARM issuess.
There is a description of the start up file in the manuals. Here's the one for the 8051.
http://www.keil.com/support/man/docs/c251/c251_ap_startup.htm
can i write my own start up codes
Yes and no. Yes because the tools do indeed allow it, and no because if you had to ask, that pretty much proves you don't have what it takes to do it.
and librarys?
Yes. But it might still be rather spectacularly unwise to actually do so, depending on which libraries you're talking about.
Here's the one for the 8051.
Close, but no cigar. ;-)
the simple answer is yes because of the need to set up stack, heap, vars etc.
That answer is simple --- but wrong. No, it is not (always) necessary to include it. Because some of the various tools in question (note that the OP didn't specify an architecture) can make do without one, and others supply their own if the user didn't include one.
But I didn't guess.
The question itself is also meaningless because it isn't accompanied with a proper definition of what a startup file really is.
If it is the file that contains the first instructions the processor should run, then it obviously has to be there - if not, then the processor would either have zero instructions or would have instructions only at a place it doesn't know how to reach.
If a "startup file" is considered an assembler file that sets up the environment, then the answer is no. A Cortex-M3 can manage with C functions for interrupt handlers, and for initialize the processor. The processor itself sets up an initial stack. So the same source file that contains main() can contain a C function that initializes RAM, sets up a heap, configures the oscillators, etc. The only special about this function is that it is called before main(), and the hardware state does not fulfill the requirements of the C standard regarding global variables or access to runtime library.
In the end, the question can only be answered if the question is expanded to actually tell what is specifically intended with the question.
You want to block all C questions and only allow questions relative to Keil/ARM issues. But while a startup file is outside the scope on a PC, because anything before main() is basically irrelevant, it is not so for embedded prorams.
Keil can't know what requirements the hardware has. And on the other hand, Keil supports Cortex chips.
So in the end, it is very relevant to know what is the normal requirements from a startup file - the user is likely to have to modify a startup file supplied by Keil.
And on the other hand, you can have C-only startup code.
Per, again you just waffle on. The newbie is writing in 'C' so the case on whether it is required for assembly programs is not relevant to the question. If you look at my previous posts you will see that I also stated the same as you in that it could be incorporated into main(). All this newbie wants is to get their simple program up and running and wants to know if the startup file is required. He doesn't need a lecture on the pros/cons and the various ways to avoid using one. Just help the guy and tell him "yes" and he can learn about the rest as and when he gets more experience. One day he may be as clever as you think you are!
Can I assume that you have just been assigned as official moderator?
Have you asked the OP if he wants black magic?
And by the way - why unprovoked ad hominem?
girls, girls. please behave with a degree of decorum.
o.k. Thanks to all. mostly understood. rest i will manage.