inline asm

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Thu May 18 07:47:10 GMT 2000


> Is there any effort currently underway to expand the functionality
> of the inline assembly in gnu c?  

In general, no. We are quite happy with it.

> For example, the ability to do
> asm{
>    movl %eax,%eax
>    movl foo,%ecx
> };
> would be wonderful (get rid of annoying "\n\t"s).  

What's wrong with

int main()
{
  asm("
      movl %eax,%eax
      movl foo,%ecx
      ");
}

Multiline strings are non-standard, but you are asking for an
extension, anyway.


> Also, simple things
> like the ability to resolve memory locations would help alot, for 
> example:
> 
> struct foo{
>    int a,b;
> } foo;
> main(){
>   foo.a=1;
>   asm(  "movl " foo.a ",%eax\n\t" );
> }
> 
> This would only make things about 3 billion times easier.

How about

struct foo{
   int a,b;
} foo;
main(){
  foo.b=1;
  asm(  "movl %0,%%eax": : "m"(foo.b));
}

This compiles to

#APP
        movl foo+4,%eax
#NO_APP


> you can do this with the funky asm syntax, but then you don't have
> complete control over which registers you can use, and I don't like
> that.  

You don't use any registers here; this is a memory reference.

> If these features aren't currently in egcs, I would be glad to add
> them if someone could point me to the correct location in the source
> code.

While contributions are highly appreciated, they also require that the
contributor becomes familiar with the compiler on her own. Much of the
work of enhancing gcc is to find the right way to implement the
enhancement (i.e. in a way that is maintainable, works on all targets,
etc.). So, whoever would tell you how to do something is often then at
about 50% of doing it herself.

Regards,
Martin



More information about the Docbook-tools-discuss mailing list