Jaya, In the interests of following your lead and sticking to positive rather than negative contributions, some may find the following example useful too. It is actually a very similar example, based on a `C' API used by an RTOS I was involved in a while ago. The ARM implementation is as follows: /* * Disable/Restore interrupt processing * * Use as: * int disabled = HwIntrDisable(); * /* Critical section that needs interrupts OFF */ * .... * HwIntrRestore(disabled); */ HwIntrDisable: mrs r1, cpsr /* get CPSR into work register */ mov r0, r1 /* return copy of original CPSR to caller */ orr r1, r1, #0x80 msr cpsr_c, r1 /* update CPSR with I=1 */ bx lr /* return to caller */ HwIntrRestore: msr cpsr_c, r0 /* update CPSR with value supplied by caller */ bx lr /* return to caller */ You'll notice they can be called from Thumb mode as well. There are versions for NEC NV850, MIPS and (used for development, debug and test) Win32 (the Win32 version is coded in `C' and uses critical sections). The main-body of the RTOS itself is 100% ANSI `C' and just needs a compile to get it up on a new platform, once the functions above and any other assembler has been written (about 10-50 lines, depending on platform). Although this portability is useful, the biggest win we found with this approach was the speed of development and ease of maintenance. Basically, our experience is that separating out portable from non-portable code will generally simplify ongoing maintenance and support. This helps guarentee high-quality software which we regard as being far more important than saving one ot two cycles where it won't be noticed in any case. Brendan --- In lpc2000@yahoogroups.com, "jayasooriah" <jayasooriah@...> wrote: > > This is an add-on to Danish Ali's contribution to AH's original question. > > I hope it will show how one can use GCC's inline assembly features in > an effective way to produce code that is both readable *and* efficient. >
Message
Re: Example of C and inline ASM in a file?
2006-04-10 by brendanmurphy37
Attachments
- No local attachments were found for this message.