CompuServe Messages

C and Assembler

    25-Jan-89 19:02:36
Sb: #31970-C and Assembler
Fm: Bob Rakosky 75156,336
To: Drew Lucy 76337,75
Since I don't have/use Manx, I don't have the "luxury" of in-line asm, nor or easily tweaking the generated assembly code before assembling it. However, even if I had this ability, I wouldn't use it. I really think it's a bad habit to develop and sloppy technique. I have no problem with analyzing the way the compiler generates code, and learning to use C code constructs that "help" the compiler to optimize. I also have no problem with mixing C code with assembler code – I do it frequently. But the assembler modules I use _belong_ in a separate file from the C code. This assists the maintainability and portability of the code. Functions within a program should be either ALL C or ALL asm – never mixed. Inline assembler allows you to violate this (I know that you can have the entire function as inline assembler code, but it is still easier to maintain if it is kept in a separate file). As to taking the assembler output from the compiler and "tweaking" the code (hand-optimizing) – that works fine until you have to make a change to the logic in that module. Which version do you change? How do you remember which "tweaks" you made to the previous version? Which are still relevant? Major maintenance hassles! On top of which, if I have determined that there is a performance requirement for a certain module to be coded in assembler, I can almost always do a much better job of optimization if I simply code that function from the start in assembler. There's a price that you pay for using the higher-level language. You're just trying to short-change it, while I'm opting not to pay it. It'll cost you more now (performance-wise), and the time you save now (by letting the compiler do the preliminary leg-work) will be spent later three-fold when you have to modify your program. All code, unless it's a quick-'n'-dirty, throwaway, will need to be changed eventually — that's the nature of software. But I really don't have any opinions on this subject. <grin>