> In-line assembler isn't evil, you just have to be able to > make a good case for it, and that case has to include > maintenance and portability. I'll agree with this conclusion. In most embedded applications I avoid it for two reasons: 1) Portability issues. I often find myself re-using code again on another project/environment, even if I didn't expect to initially. 2) Learning curve. Inline assembler means you have to learn the syntax, probably study up on how to reserve the registers you need or find out what the compiler doesn't use. If it doesn't use it, you need to then be careful that your own interrupt routines are saving all the context they have to (especially if you use inline in them too). All in all, there are certainly more chances to stuff up with inline unless you've gone into it properly. That said, I have had application where inline was very handy. It was a gcc C compiler for a motorola DSP. The DSP assembler allowed many instructions in the one line, and the inline syntax was powerful enough to support this. The C compiler itself rarely generated code that was that smart. If a time critical task was big enough you were better off using an assembler subroutine (but for this also you have to be aware of the C compiler calling and return methods and what has to be saved). For simple things the inline was very useful (eg. Divide by a constant was one I remember using where it was more efficient to multiply by the reciprical of the constant fractionally). I wrote a fixed-point complex number library that was a mixture of C, inline and assembly routines. The efficiency argument only really applies where the routine calling overhead is large compared to the task your assembly is performing. Interestingly this library was ported....by rewriting entirely in C with no regard for efficiency. We wanted to test all the higher level algorithms on the PC where it was much easier to develop at the time than on the DSP. So, there is a case for inline in some specific applications, where the case can be made. Even when it can, try to isolate the inline into one easily replaceable library which you can unplug. There is no justifcation for inline assembly in main.c ! It all comes down to how you design your project from the start. Cheers, Bruce
Message
RE: [lpc2000] Re: Example of C and inline ASM in a file?
2006-04-11 by Bruce Paterson
Attachments
- No local attachments were found for this message.