Yahoo Groups archive

Lpc2000

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

Message

RE: [lpc2000] Re: Example of C and inline ASM in a file?

2006-04-10 by Paul Curtis

Jaya, 

> > You're acting like a spoilt child.
> 
> I will ignore this comment knowing you for what you are :)

We all have opinions about each other here.  You don't know what I am,
I've never met you, so how you know what I am is just more supposition
on your part, just like your CRP "facts".

> > Something concrete:
> > 
> > void do_something_nasty(void)
> > {
> >   // I need to do something fast without a call, I need a register,
> >   // so I'll pick r5 as the/ code generator seems it's not 
> using that
> >   // one when I run it under the debugger.
> >   asm("ldr r5, =0x12345678");
> > 
> >   // Now do soemthing with r5 because I did something above.
> > }
> 
> Excellent example of INCORRECT use of inline assembly.

Yes, of course it is incorrect, that's the whole f'ing point.

> You want to use "r5" for your own purpose but have chosen not 
> to tell the compiler.  You appear not to know, or to have 
> forgotten, that the compiler is responsible for allocation of 
> registers.

Too bloody true.  The whole point is that customers write this shit and
don't have a clue.  It might work when debugging, but it won't work when
you turn the optimizer on.  And it won't work when you change the
function.

> Although I question the validity your particular requirement 
> (as I can gather from your comments), the compiler 
> nonetheless will accodomate your requirement (subject to 
> reasonable limits) if you were to include the following 
> declaraction in your function:
> 
> > register int r5 asm ("r5");
> 
> If you do not tell the compiler you are using a register that 
> it also uses, you should not be surprised at what happens as a result.
> 
> While the reference to "r5" in the ASM statement may be 
> obvious to you as a human, the compiler does not parse this 
> string at all.

Yawn.  I know all this.  This is an example of stuff customers will
write.  The point is that customers write this crap without knowing what
they're doing.  It's not enough that they can screw themselves with
non-portable C, now inline assembler has given them yet another
dimension to screw around and "solve" problems with.  The problems, of
course, come when somebody has to maintain it, move it to a new
compiler, or even move to a new architecture as has been pointed out.

In short, I have never used inline assembler and I see no reason to
start using it.  Our own compilers do not offer this feature and with
the wealth of customers we have, each time they ask for it I show them
why they don't need it.

--
Paul Curtis, Rowley Associates Ltd   http://www.rowley.co.uk 
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors

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.