??? 07/20/09 18:35 Read: times |
#167627 - that whooshing sound .. Responding to: ???'s previous message |
Richard Erlacher said:
Andy Peters said:
As for the size, the problem is that, once one is using 'C', the tendency is to use its libraries and other conveniences without regard for impact on the size of the work product. If you were an actual C programmer, you would know that most of the standard library functions are not only quite useful, they are also optimized by the compiler vendor for the platform. Consider: you need to compare two strings. Would you rather roll your own function, or use the pre-existing strcmp() from string.h? Most of the functions in the C standard library fall into this category. Comparing two strings isn't a big deal in ASM. So you figure strcmp, or whatever it's called, creates less binary? IIRC, string comparison takes fewer than a dozen lines of ASM, including the setup. You're missing my point (as usual). The string-comparison example was just that, a simple example. The point being that I could use the known and tested strcmp() library function and use it because I know that it is small and useful and I don't have to write my own. The function itself is quite minimal, I think it's three lines of C code, including the return statement, and probably does compile down to a dozen ASM lines. But it's ONE line in my application source. ONE. So, hey, it compiles to a dozen bytes. Is that the code bloat you decry? And the larger point here is that the professional embedded developer knows the size of the library functions he uses. If they are too large, then it is worthwhile trying to optimize either the library function (maybe it handles cases the specific use will never see?) or the code that needs to use that function. Most of the time, the standard library functions are optimal for size and efficiency, and you can't do better even if you write them in assembly. ------------------------------------------------------------------------------- So I did a little thing in a Xilinx PicoBlaze, which is programmed only in assembly. As part of this thing, I had to implement some 32-bit counters that test against zero. Now in an 8-bit processor, a 32-bit decrement requires four instructions for the subtract-with-borrow, the test requires a fifth instruction, and the conditional branch requires a sixth. So, if I were to write this in C on the 8051, would you agree that the instruction: while (--ctr) ; would be any worse than the assembly version? And really, what would you rather write? -a |