Hi AH,
You don't mention which C compiler you use. This makes
a big difference to how you include inline assembly code.
Attached is an example of something that gcc likes (as
supplied with Rowley Crossworks).
Key points:
volatile should discourage the compiler from re-ordering
and optimising the assembly away. But so fat I have not
turned on the optimiser.
C merges the assembly code into a single line, so you must
supply the "\n" to separate assembly instructions.
The subroutine relies on the fact that FIQ does not (yet)
occur in my system.
I do not fully understand the information you should put
in the : : : sections.
The first couple of lines of assembly code pass a value from
assembly to C, using the %0 and the "=r" (irqstat) phrases.
The last part is registers you use (warning the compiler not
to rely on values in those registers remaining constant).
void Watchdog_Feed(void) { /* NOT fiq safe! */
int irqStat;
asm volatile (
" mrs r0, cpsr\n"
" mov %0,r0\n" : "=r" (irqStat) : : "r0" );
if (128 & ~irqStat)
__ARMLIB_disableIRQ();
asm volatile (
"WDFEED = 0xE0000008\n"
" LDR r0, =WDFEED\n"
" MOV r1,#0xAA\n"
" MOV r2,#0x55\n"
" STRB r1,[r0]\n"
" STRB r2,[r0]\n" : : : "r0", "r1", "r2");
if (128 & ~irqStat)
__ARMLIB_enableIRQ();
}
Hope this helps,
Danish
--- In lpc2000@yahoogroups.com, "ah_sandiego" <ah_sandiego@...> wrote:
>
> Can someone post a simple example of C and inline ASM in a single
> file. I use the LPC2148 but any LPC board example would be helpful.
>
> Thanks,
> AH
>Message
Re: Example of C and inline ASM in a file?
2006-04-07 by Danish Ali
Attachments
- No local attachments were found for this message.