This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]