----- Original Message ----- From: "Gerhard Fiedler" Subject: Re: [PIC] Any advantage of using assembler? > There may be inefficiencies. But so far I haven't run into a problem with > compiler efficiency. I don't care for the word "inefficiencies". On average, most of the compilers I've looked at write reasonably efficient code most of the time. The problem comes from an inexperienced user writing code that might make perfect sense on some other processor, but that is difficult to implement on a PIC. In these cases, some of these compilers will silently generate truly horrid code. Not inefficient, amazingly awful. It wouldn't be so bad if the compiler would at least say something like "boy that was stupid", but they don't (not sure if the ANSI standard allows that anyway, and most make valiant attempts at following the standard even when it doesn't make sense). An experienced PIC developer likely wouldn't even consider some of those constructs, but they are perfectly good C, so the C programmer who perhaps doesn't understand the PIC will have no idea that was a bad thing to say. > I carefully disagree... :) When I started out with the PIC, I was an > experienced C programmer. Ok, I knew other micros, but didn't know the PIC > architecture. And it /is/ a bit, hum, different. uhh --- yeah > After reading up on it, I knew enough to be somewhat > familiar with it, but not enough to write decent-sized programs > efficiently in assembler. Sure, but your experience with other architectures allowed you to quickly understand the major PIC issues, and likely many of the habits you learned on other small architectures DID carry over to the PIC. > But that was enough to get > me going quickly with a C compiler. I learned pretty much all of the > assembler I know from looking at generated code (or at code written by > others), not from writing it myself. Again, someone with experience can get a huge productivity benefit from a compiler. On an architecture like the PIC where so much of the application itself tends to be pretty specific to the iron, I don't think the productivity advantage is anything like it would be for application programming on, say, a PC, but it is still an advantage. And if you are moving between a number of architectures, then the different assemblers can really be an issue. Within some bounds, C is C. (FWIW, I consider C to be my "native" language although it was not my first. On any other architecture I reach out for the C compiler first, and write in C unless I have a compelling reason to pick something else.) > Exactly -- just because you're writing in C doesn't mean you won't have to > apply common sense and acquire a certain level of understanding the > architecture. But for me, that's not an argument against using a compiler; I think we all look for excuses to check our common sense at the door, and you are correct that you need to understand the platform, even when writing in a HLL. I write for and mostly talk to PIC hobbyists. Many, many of these folks (and way back at the beginning of this thread the OP sounded like a hobbyist new to the PIC) have a very limited understanding of microcontrollers in general, let alone the PIC. For them, the PIC is very alien territory, and very hard to grasp. Putting a layer of abstraction in there (the compiler) BEFORE they understand the architecture make it a LOT harder. If, on top of that, they are pretty competent C programmers, it gets even worse because they make assumptions that simply aren't valid on the PIC platform. MOST people (and obviously PIClisters aren't most people) have very little grasp of what is going on behind the compiler. Some time back I taught an assembly language course at a local university. The students were fourth year computer science students, and even at that point, they had absolutely no concept of the underlying hardware. The average software hobbyist has even less concept, and often a lot less confidence that he is able to grasp it. > I generally use the compiler to help me in acquiring that understanding. > When writing for a different architecture, I usually take quite a few > peeks > at the generated code in the beginning, to get an understanding of how it > performs the normal stuff, like branching, looping, argument passing, and > so on, and how it changes the code when optimizing. And clearly, because you are comfortable looking at what the compiler does, the compiler itself can be a valuable learning tool. Surprisingly few people are able to do that. It works the other way, too. For some people, especially people coming from the hardware side, C can be an amazingly difficult language to learn, but assembler, to them, makes a lot of sense. Again, it depends on where you are coming from. Anyway, we see this differently, although perhaps not all THAT differently. --McD -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist