Trouble with inline void function using asm

Alexandre Oliva aoliva@redhat.com
Tue Jan 23 18:09:00 GMT 2001


On Jan 23, 2001, "Jeff Hammond" <jshammond@my-deja.com> wrote:

>     asm("SALT   r%0,r%1,0  ; write_altmem" 
>                             : "r"(data) : "r"(addr) );

> I get the error message:
> memaccess.c:11: output operand constraint lacks `='

> I didn't think that I would need a '=' since there are no output
> variables.

Then why is `data' in the output operands section (i.e., between the
first and the second `:')?

Maybe you mean:

>     asm("SALT   r%0,r%1,0  ; write_altmem" 
>                             : : "r"(data), "r"(addr) );

> When I put an '=' in the first argument there are no compiler errors
> but the compiler decides that this function doesn't do anything and
> optimizes it out.

It probably optimizes it out because then the output operand is
unused.

Maybe you should instead indicate that the memory area pointed to by
addr is modified (in which case you'd use a `=m' constraint)?  Or
maybe you should make the asm statement volatile, so that GCC doesn't
optimize it away.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me


More information about the Gcc mailing list