Jon, > I understand some of Paul's desire to avoid inline assembler > and, personally, I tend to prefer using a real assembler as > part of the mix. But there are times when uncomplicated > access to C-symbols and the need for a tiny snippet of > assembly arises. It can be done in other ways, usually, but > the convenience is a plus. Paul's comments, "I've never > really understood the fascination with inline assembler at > all," and "we build for the common case," are exactly the > kind of comments which leave me just a little 'cold.' Well, nobody has asked for inline assembler so, I don't feel bad not offering it. I feel better that we have not wasted our effort on providing something that's not used. If we had everybody knocking on our door telling us that they just can't get by without it, then I'd be the first to implement it. > Thanks for the extra effort on this score, Michel. There are a few problems introduced by the MSP430's assembler syntax. I'd want to write: void foo(register int *x) { /$ ... mov.w @@x+, r4 ... $/ } But it won't work. Other than that, it's nicely implemented! If I were to implement inline assembler, and I'm not considering it yet, I'd use an "__asm" keyword and the old Inmos implementation as a guideline as that was pretty elegant. -- Paul.
inline assembler
Started by ●September 8, 2003
Reply by ●September 8, 20032003-09-08
Reply by ●September 8, 20032003-09-08
On Mon, 08 Sep 2003 13:11:45 -0700, Richard wrote:
>At 12:55 PM 9/8/2003 +0000, ahmeto77 wrote:
>>Hello everybody,
>>
>> I want to ask if we can use inline assembly code for a c compiler.
>
>As others mentioned, it depends on the compiler. Our ImageCraft ICC430 does
>it like this:
>
> asm("mov #3,$a\n"
> "mov #5,$b\n"
> "mov $a,$b");
>
>a bit more cumbersome than your example, but not by much. You can access
>any C variable inside the string.
><snip>
Nifty. Looks like at least two compilers have it.
Which, of course, begs another question.
Is register use of inline assembly seemlessly blended into the
register allocation process? Or how exactly is it handled? Is
this a thing where the coder needs to follow some strict rules
to avoid a conflict? Is there a blanket prologue and epilogue
used to put things into "known states" in order to work around
tiny fragments like this? Or is there some parsing intelligence
operating on the inline assembly, as well?
Jon
Reply by ●September 8, 20032003-09-08
Jonathan Kirwan wrote: > Is register use of inline assembly seemlessly blended into the > register allocation process? An example from ImageCraft ICC430 manual: register unsigned uc; asm("mov %uc,R10\n" "sleep\n"); Indrek -- Indrek Rebane | OU Borthwick-Pignon Electronics Engineer | Tartu Science Park Phone: (+372) 7 302 641 | Riia 185, 51014 Tartu Fax: (+372) 7 383 041 | Estonia indrek@indr... | http://www.bps.co.ee
Reply by ●September 8, 20032003-09-08
At 01:21 PM 9/8/2003 -0700, Jonathan Kirwan wrote: >....Which, of course, begs another question. > >Is register use of inline assembly seemlessly blended into the >register allocation process? Or how exactly is it handled? Is >this a thing where the coder needs to follow some strict rules >to avoid a conflict? Is there a blanket prologue and epilogue >used to put things into "known states" in order to work around >tiny fragments like this? Or is there some parsing intelligence >operating on the inline assembly, as well? > >Jon >... No, we aren't too smart peeking inside the asm strings. So the MSP430 is nice in that almost all addressing modes are valid in most instructions. On the Atmel AVR, you do have to be careful if a local var does not end up in register and you use a register only instruction. You will of course get an assembly error of course. // richard <http://www.imagecraft.com> <http://www.dragonsgate.net/mailman/listinfo>
Reply by ●September 8, 20032003-09-08
Hi Preston,
> > There are a few problems introduced by the
MSP430's
> assembler syntax.
> > I'd want to write:
> >
> > void foo(register int *x)
> > {
> > /$
> > ...
> > mov.w @@x+, r4
> > ...
> > $/
> > }
> >
> > But it won't work. Other than that, it's nicely
implemented!
>
> Thanks, Paul.
>
> It will work if you write
>
> mov.w \@@x+, r4
Ahh. Good to know you've covered that base. :-)
-- Paul.
Reply by ●September 8, 20032003-09-08
> There are a few problems introduced by the
MSP430's assembler syntax.
> I'd want to write:
>
> void foo(register int *x)
> {
> /$
> ...
> mov.w @@x+, r4
> ...
> $/
> }
>
> But it won't work. Other than that, it's nicely implemented!
Thanks, Paul.
It will work if you write
mov.w \@@x+, r4
Preston Gurd
Archelon Inc.
(AQ430 C compiler guy)