How could I compare C and Assempler on a 8051. What are the advantages and disadvantages of each Programming language. I'm happy if anyone knows something about that or even know some good Homepages where I can find some useful information thanks
"1. Are you under any kind of time constraint?" Here, Jon is talking about a time constraint on you the programmer; ie, have you got to get this code written in a restricted timescale? This is different to asking if the execution of your code is time-critical; ie, does your code need to run fast? "A good assembly programmer can frequently beat the C compiler in terms of code size and execution speed. A great assembly programmer can do this most all the time." I've added my emphasis there to Jon's exellent statement. You will often hear people say things like, "Assembly is faster than 'C'" - but that is only true if the Assembly is well-written in a good, efficient manner. Sure, in Assembly you can agonise over which instruction to use, which addressing mode to use; you can count the bytes & the clock cycles - and if you really know your stuff you can end up with a really fast, tight, efficient bit of code - but it might take you all day to write just one function! Jon's approach is good advice: get it working first in 'C', then optimise your 'C', then go to Assembly for any bits which still really need that extra bit of performance
I'll add to the previous replies that IMHO another important reason to know assembly-level programming is so that you can understand what the processor is doing when it's running your C code and doesn't do what you expect ... The trouble is, you don't reach that level of understanding until you've written a moderate amount of assembly that works. Writing very short assembly code is quite different from writing 64+ KBytes of working assembly. I wrote embedded code in assembly for some 15+ years -- now, I start everything in C. But I do still write assembly when it's required, especially when doing things that C does not inherently support (e.g. playing with the stack). And I examine a lot of C compiler output (in assembly) to judge the quality (and sometimes correctness) of the compiler's output. In short, I think that you will be a better C programmer if you have a working knowledge of assembly-level programming. Perhaps a good way to start is do your work in C, and fiddle around after hours in assembly. Regards,