How to use Inline assembly on C64x+

  • Follow


Hi,
    i am trying to write inline assembly in my C code using asm(" ");
    but it is not accepting the variable names as inputs. 
    
    Is it possible to write inline assembly which accepts variables as
    arguments?

    func()
    {
       int a,b;
       asm(" add a,b,a");         //it is not accepting this format       
   
    }        

  

 Thank You,
 Hiten 


0
Reply Hithendra 1/8/2010 12:57:29 PM

Hithendra wrote:

>     Is it possible to write inline assembly which accepts variables as
>     arguments?
> 
>     func()
>     {
>        int a,b;
>        asm(" add a,b,a");         //it is not accepting this format       
>    
>     }        

No, it is not.

The compiler will just copy all the inline assembler that you write into
the assembler-source verbatim.
Variable names don't exist during the assemble stage anymore, and the
variable you're refering to may exist on the stack or inside several
registers at the same time.

Since the optimizer is very aggressive there is no way to guess where
the variable is.

If you really need assembler (why? - the compiler is excellent) put your
code into an external assembler file. There are two kinds of them:
linear (easier to write) and scheduled assembler.

Check the SPRU187.pdf file for more details.

Cheers,
	Nils Pipenbrinck
0
Reply Nils 1/8/2010 1:24:57 PM



Hithendra wrote:

> Hi,
>     i am trying to write inline assembly in my C code using asm(" ");
>     but it is not accepting the variable names as inputs. 
>     
>     Is it possible to write inline assembly which accepts variables as
>     arguments?
> 
>     func()
>     {
>        int a,b;
>        asm(" add a,b,a");         //it is not accepting this format       
>    
>     }        

1. Inline assembler is misnomer. It should never be used. If you need to 
  code something in assembly, make a separate assembly module.

2. Usually, the inline assembler supports GNU style argument passing:

#define fubar(fu, bar, blablabla)
asm ("r0=%1;"
"r1=%2;"
"%0=r0+r1;"
: "=d" (result)
: "d" (x), "d" (y)
: "r0", "r1");

Ugly, isn't it?

3. RTFM




Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
0
Reply Vladimir 1/8/2010 3:03:09 PM

On Fri, 08 Jan 2010 09:03:09 -0600, Vladimir Vassilevsky wrote:

> Hithendra wrote:
> 
>> Hi,
>>     i am trying to write inline assembly in my C code using asm(" ");
>>     but it is not accepting the variable names as inputs.
>>     
>>     Is it possible to write inline assembly which accepts variables as
>>     arguments?
>> 
>>     func()
>>     {
>>        int a,b;
>>        asm(" add a,b,a");         //it is not accepting this format
>>    
>>     }
> 
> 1. Inline assembler is misnomer. It should never be used. If you need to
>   code something in assembly, make a separate assembly module.

I could argue with that -- specifically it sometimes makes sense to put 
inline assembly as the only content in a function, and let the compiler 
deal with proper linkage &c.

> 2. Usually, the inline assembler supports GNU style argument passing:
> 
> #define fubar(fu, bar, blablabla)
> asm ("r0=%1;"
> "r1=%2;"
> "%0=r0+r1;"
> : "=d" (result)
> : "d" (x), "d" (y)
> : "r0", "r1");
> 
> Ugly, isn't it?

In my experience you can't count on this -- I see Gnu-style parameter 
passing about 30% of the time.

> 3. RTFM

Or at least it's your only hope.  Compiler manufacturers dedication to 
inline assembly varies wildly, the 'FM' often falls flat at giving 
sufficient information, and if you _do_ need to use inline assembly you 
often have to experiment around quite a bit.

Mostly I do with you say, though I'll often start by compiling a small 
'c' program with an "empty" function to assembly, then I'll use that 
output as a starting point for my code (be sure to recognize and strip 
the debugging directives, though).

-- 
www.wescottdesign.com
0
Reply Tim 1/8/2010 3:44:44 PM

Nils wrote:
> Hithendra wrote:
> 
>>     Is it possible to write inline assembly which accepts variables as
>>     arguments?
>>
>>     func()
>>     {
>>        int a,b;
>>        asm(" add a,b,a");         //it is not accepting this format       
>>    
>>     }        
> 
> No, it is not.
> 
> The compiler will just copy all the inline assembler that you write into
> the assembler-source verbatim.
> Variable names don't exist during the assemble stage anymore,

Not even as _a and _b ?

> and the
> variable you're refering to may exist on the stack or inside several
> registers at the same time.
> 
> Since the optimizer is very aggressive there is no way to guess where
> the variable is.
> 
> If you really need assembler (why? - the compiler is excellent) put your
> code into an external assembler file. There are two kinds of them:
> linear (easier to write) and scheduled assembler.
> 
> Check the SPRU187.pdf file for more details.
> 
> Cheers,
> 	Nils Pipenbrinck

--
Les Cargill
0
Reply Les 1/8/2010 10:13:27 PM

4 Replies
496 Views

(page loaded in 0.06 seconds)

Similiar Articles:













7/22/2012 4:27:26 AM


Reply: