Herbert Graf farcite.net> writes: > On Sat, 2007-03-10 at 11:43 -0800, Don French wrote: > > I see a lot of posts on this list that indicate that people are programming in Assembly. So, I wonder why. > Except for really tight timing situations, why not use C, which is one heck of a lot easier to write, read, > maintain, etc.? And the optimizing compilers probably do at least as good a job of saving bytes as most > people can do by writing in Assembly. So, what is the point? > > Well, main reasons I can see are: > > - person doesn't know C (there are alot out there that don't) That is a reason I do not agree with. I don't think that one can even get hired for an embedded job without knowing C. C is the common denominator of programming, especially low level, and has been for 20 years. Not knowing C is about the same as going out of fashion whenever an architecture is retired. That happens every six months or so now. > - established ASM codebase - alot of people have been using ASM for a > LONG time, and have a codebase that covers many things, why change to C > if you already have most of the code written in ASM? Because most of the valid reasons to use the old codebase were a lot of time spent on optimization and cleaning up things. Because C has a math package built in (well almost, with -lm) most of the old codebase that was calculations-related can be duplicated in 5 seconds, the time to compile an expression. And peripherals have changed enough that old code for peripherals makes little sense imho. I see it that way while cleaning things in my computer, things which are 10+ years old. My code was valid then, and it worked well, but today it's just two more lines of C buried in the rest of what I am doing, and it's likely faster than the way I coded it then. Compilers are written by very clever people. > - PIC projects are often small enough not to get many benefits from an > HLL - for example a recent project I did was a "flickering candle", it's > about 20 lines of ASM, hardly worth going to C What happens if you have to add a USB interface in 2 weeks ? Or port it to something else ? C would have used about 5 lines of code for that. Would it 'not have been worth it' ? Try to think how long it took you to make the program work. How long would it have taken in C ? Statistics say that American programmers produce about 50 lines of 'good' code per day (including debug time). So your asm program should have taken almost half a day, and the C program a tenth of a day. Afaik, the rule of thumb is to use the highest level programming language available for the task. > - compiler bugs - every compiler has bugs, and debugging compiler bugs > can get very frustrating. Yes, but so does everything else. Including one's own code. Assembly requires 5-10 times more source statements to achieve what C achieves. The programmer's error rate is proportional to the number of lines of code he writes, not to the language used. > I still at least get an idea for how the ASM works for a given platform, > that way when you hit a compiler bug (and you will) you'll be prepared > to sift through the ASM listing to figure out what's going on. Every man should know his compiler's output ;-) Peter P. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist