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?


On Tuesday 27 March 2012 13:09:59 Andrew Burgess wrote:
> On 27/03/2012 17:53, Dmitrij K wrote:
> > Ian wrote:
> >> 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.
> > 
> > I did as you told me, but it is not working too :( (I had used %r15
> > instead %rdi for p_printf, and %rdi for str)...
> > 
> > I have not ideas how I can to call func by the address.
> > I can't find examples of calling functions with args by address (as needs
> > me). I had seen examples without args only (abi, internet)...
> > I need help still.
> > 
> > 
> > Maybe you have a something tips/examples for me ?
> 
> Why not compile up a C/C++ program that does what you want, then
> disassemble it to figure out what it's doing - reference the ABI
> document as you go.

and perhaps even use the -S flag with gcc to output the assembly
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


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