??? 06/20/09 00:27 Read: times |
#166272 - I can't totally disagree ... it's a matter of degree Responding to: ???'s previous message |
David Prentice said:
As Per and Andy have noted, it is not difficult to write portable code. High level logic is generally independent of a compiler or platform.
The low-level differences can still be covered in C in most cases with some conditional code and use of a "compatibility.h" header. This is not to say that there is no room for ASM, but the programmer who writes the portable code in the first place is a lot more desirable. He still has to know the specific operation of the target microcontroller. But there is nothing to stop Richard writing non-portable code that requires his excellent skill to maintain. And if it is ever necessary to move to another architecture, his excellent skills at re-writing in a completely new non-portable way can be used again. As any assembler programmer is well aware, 90% of the cpu time is taken up by 10% or less of the code. The application written in the HLL can often achieve very respectable efficiency with some minor tweaking in ASM. Experience has taught me that it's seldom a matter of "tweaking" and that no more than half the number of lines of code are in whichever HLL one chooses. The rest is in ASM, because one needs ASM to control the hardware. That's one reason I'd prefer to write the "main" function in ASM and have callable routines in 'C' where it is easier to express a computation in 'C' than in ASM, which is often the case. However, much of the time, when one does that, the routine could be expressed quite concisely in ASM and end up quite a bit smaller and faster. When it's not time- or size-critical, I think the HLL might be a wise choice. I've seen examples, however, where a <10-line 'C' segment compiles into a 60-line ASM code block ... one that, by hand, can be reduced to <10 lines of ASM consuming less time and code space. Now I don't care about compatibility between compilers. I want ONE compiler to handle all the cores I use. That will probably never happen. I don't even have total compatibility between the various assemblers I use. David. If the 10% of the code to which you refer is doing useful work, I'd be happy, but often it's auto-generated code that suffers in performance from the overhead imposed by the compiler. It doesn't always matter, but it certainly can matter. RE |