How can I do calling for external address in my "C" programm by inline GAS?

Ian Lance Taylor iant@google.com
Tue Mar 27 12:46:00 GMT 2012


Dmitrij K <kdiman1982@gmail.com> writes:

> 7       asm volatile (
> 8           "movq %0, %%rcx;" /* str into RCX is first integer argument (amd64 
> notation) */
> 9           "movq %1, %%rdi;" /* address of PRINTF into RDI is Must be 
> preserved by called function (amd64 notation) */
> 10          "call * %%rdi;" /* call PRINTF */
> 11       :  /* no output */
> 12       :"r"(str),"r"(p_printf)         /* input */
> 13       : "rcx", "rdi", "memory" /* clobbered register */
> 14      );
> 15      }

On x86_64 the first parameter should go into %rdi, not %rcx.  You are
putting the function address into %rdi, so in effect you are treating
the function address as a printf format string.

Ian



More information about the Binutils mailing list