How can I do calling for external address in my "C" programm by inline GAS?
Mike Frysinger
vapier@gentoo.org
Tue Mar 27 17:45:00 GMT 2012
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/binutils/attachments/20120327/f8745371/attachment.sig>
More information about the Binutils
mailing list