EmbeddedRelated.com
Forums

inline assembler

Started by ahmeto77 September 8, 2003
Hello everybody,

  I want to ask if we can use inline assembly code for a c compiler.

i.e

main()
{
  a=b ;

  asm  // inline assembly code here
 begin
    mov #3,a
    mov #5,b
    mov a,b
 end ;

  b = a ;
}

Thank you all.




Beginning Microcontrollers with the MSP430

Hi,

> Hello everybody,
> 
>   I want to ask if we can use inline assembly code for a c compiler.
> 
> i.e
> 
> main()
> {
>   a=b ;
> 
>   asm  // inline assembly code here
>  begin
>     mov #3,a
>     mov #5,b
>     mov a,b
>  end ;
> 
>   b = a ;
> }
> 
> Thank you all.

I've never really understood the fascination with inline assembler at
all.  Can't afford a function call and return?  Gee, people in that
situation must be right up against it on their time and processor
budget.  Common thins are usually provided as either intrinsics or can
be synthesized using _OPC().  Code generation has come on a long way, so
the need for inline assembler has somewhat fallen by the wayside.

We build for the common case: straight C code.  Thus, our compiler
doesn't emit assembly code to be assembled, it goes straight to object
code, which is why it's fairly nippy.  But it's also the reason why
inline assembler isn't supported.

-- Paul.

With the AQ430 tools, in-line assembly is supported as follows (from 
your example):
 main()
 {
   a=b ;
 
  /$   // inline assembly code here introduced by "slash dollar sign"
      mov #3,a
     mov #5,b
     mov a,b
 $/   // end of inline assembly: "dollar sign slash "
   b = a ;
 }
 
Michel (from Quadravox, home of AQ430)


--- In msp430@msp4..., "ahmeto77" <aozsoy@s...> wrote:
> Hello everybody,
> 
>   I want to ask if we can use inline assembly code for a c compiler.
> 
> i.e
> 
> main()
> {
>   a=b ;
> 
>   asm  // inline assembly code here
>  begin
>     mov #3,a
>     mov #5,b
>     mov a,b
>  end ;
> 
>   b = a ;
> }
> 
> Thank you all.


Dimitry,

> > I've never really understood the
fascination with inline 
> assembler at 
> > all.  Can't afford a function call and return?  Gee, people in
that 
> > situation must be right up against it on their time and processor 
> > budget.  Common thins are usually provided as either 
> intrinsics or can 
> > be synthesized using _OPC().  Code generation has come on a 
> long way, 
> > so the need for inline assembler has somewhat fallen by the wayside.
> 
> well, 
> probably binary to bcd conversion can be done via inline 
> assembly bit faster. i think your c compiler does not 
> generate dadd and dadc instructions nativly.

Sure, dadd isn't generated natively.  But them how often do you use it?
;-)

-- Paul.

> I've never really understood the fascination
with inline assembler at
> all.  Can't afford a function call and return?  Gee, people in that
> situation must be right up against it on their time and processor
> budget.  Common thins are usually provided as either intrinsics or can
> be synthesized using _OPC().  Code generation has come on a long way, so
> the need for inline assembler has somewhat fallen by the wayside.

well, 
probably binary to bcd conversion can be done via inline assembly bit faster.
i think your c compiler does not generate dadd and dadc instructions nativly.

~d



>From: "ahmeto77" <aozsoy@aozs...>
>Reply-To: msp430@msp4...
>To: msp430@msp4...
>Subject: [msp430] inline assembler
>Date: Mon, 08 Sep 2003 12:55:43 -0000
>
>Hello everybody,
>
>   I want to ask if we can use inline assembly code for a c compiler.
>
>i.e
>
>main()
>{
>   a=b ;
>
>   asm  // inline assembly code here
>  begin
>     mov #3,a
>     mov #5,b
>     mov a,b
>  end ;
>
>   b = a ;
>}
>
>Thank you all.
>
>
>

Depends...
which compiler are you using?  Which version?  (old IAR does not support 
inline assembler)
The syntax for inserting the assembler into the code is highly compiler 
dependant.

Ian

_________________________________________________________________
Use MSN Messenger to send music and pics to your friends 
http://www.msn.co.uk/messenger


On Monday 08 September 2003 17:46, Paul Curtis wrote:
> Sure, dadd isn't generated natively.  But
them how often do you use it?
> ;-)

these are very usefull bits when interfacing LCDs, or for 
in-system-uart-debugging (do not tell about jtag debugging - timer interrupts 
eat everything ;), when info being output strait to the terminal.

~d

-- 
/*****************************************************************
     ("`-''-/").___..--''"`-._     (\   Dimmy
the Wild     UA1ACZ
      `6_ 6  )   `-.  (     ).`-.__.`)  State Polytechnical Univ.
      (_Y_.)'  ._   )  `._ `. ``-..-'   Radio-Physics Departament
    _..`--'_..-_/  /--'_.' ,'           Saint Petersburg, 
Russia
   (il),-''  (li),'  ((!.-'             +7 (812)
5403923, 5585314
 *****************************************************************/


On Mon, 08 Sep 2003 13:45:59 -0000, you wrote:

>With the AQ430 tools, in-line assembly is supported
as follows (from 
>your example):
> main()
> {
>   a=b ;
> 
>  /$   // inline assembly code here introduced by "slash dollar
sign"
>      mov #3,a
>     mov #5,b
>     mov a,b
> $/   // end of inline assembly: "dollar sign slash "
>   b = a ;
> }
> 
>Michel (from Quadravox, home of AQ430)

Excellent.

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.'

Thanks for the extra effort on this score, Michel.

Jon


Well, actually, Preston and Co  are the ones who made the extra 
effort. I'm just happy to report the result ;-). The Archelon C 
compiler also gives access to C variables in in-line assembly code, 
BTW.

Michel

--- In msp430@msp4..., Jonathan Kirwan <jkirwan@e...> wrote:
> On Mon, 08 Sep 2003 13:45:59 -0000, you wrote:
> 
> >With the AQ430 tools, in-line assembly is supported as follows 
(from 
> >your example):
> > main()
> > {
> >   a=b ;
> > 
> >  /$   // inline assembly code here introduced by "slash dollar 
sign"
> >      mov #3,a
> >     mov #5,b
> >     mov a,b
> > $/   // end of inline assembly: "dollar sign slash "
> >   b = a ;
> > }
> > 
> >Michel (from Quadravox, home of AQ430)
> 
> Excellent.
> 
> 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.'
> 
> Thanks for the extra effort on this score, Michel.
> 
> Jon


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. Let me know direct if you have further 
questions.

>i.e
>
>main()
>{
>   a=b ;
>
>   asm  // inline assembly code here
>  begin
>     mov #3,a
>     mov #5,b
>     mov a,b
>  end ;
>
>   b = a ;
>}
>...

// richard <http://www.imagecraft.com/software> 
<http://www.imagecraft.com/software/FAQ.html>
<http://www.dragonsgate.net/mailman/listinfo> On-line orders, support, and

listservers available on web site.
[ For technical support on ImageCraft products, please include all previous 
replies in your msgs. ]