Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Example of C and inline ASM in a file?

2006-04-11 by Stephen Pelc

> unsigned key0(void)
> {
>   unsigned char ch;
>   for (;;)
>     {
>       __disable_interrupts();
>       if (rx0_avail)
>         {
>           ch = rx0_char;
>           rx0_avail = 0;
>           __enable_interrupts();
>           return ch;
>         }
>       __bis_SR_register(CPUOFF + GIE);
>     }
> }

> I believe this is pretty good code from our CrossWorks MSP430 compiler.
> :-)  No assembly inserts in sight.

I'm not complaining about your code generators, Paul. Remember 
that you've written compilers for MPE!

I'll requote my post:
> Putting in a single assembler instruction 
> achieves that objective and documents everything the user 
> needs to know.
> 
> I could have tweaked the compiler to do this, but I prefer to 
> do that only when the required functionality is itself 
> portable across CPUs. 

[asm  bis # _cpuoff _gie + sr  asm]
versus
__bis_SR_register(CPUOFF + GIE);

Not much difference either in terms of readability or of 
keystrokes. As I implied above, it's a qualitative/subjective 
decision, and I personally don't find CPU-dependent pseudo-
portability attractive.

The advantage of your intrinsics is in the protection for the 
user against resource usage by the compiler.

[AD] IAR vs Crossworks snipped!

Stephen


--
Stephen Pelc, stephen@...
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.