This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
How can I do calling for external address in my "C" programm by inline GAS?
- From: Dmitrij K <kdiman1982 at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 26 Mar 2012 12:36:13 +0400
- Subject: How can I do calling for external address in my "C" programm by inline GAS?
Hi all!
I have a programm, but it do not work for me...
Please, looks it, and give me a help.
+++++++++++++CODE++++++++++++++++++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// gcc -g call_pr.c -o call_pr && ./call_pr
int main(){
void *p_printf = (void *)&printf;
const char *str = "Hello";
// printf("addr of printf=%p\n", &printf); // 0x400490
asm ("movq (%0), %%rax;" /* str into RAX */
"movq (%1), %%rcx;" /* address of printf into RCX */
"pushq %%rax;" /* store RAX into stack*/
"call *%%rcx;" /* calling the "printf" */
// "addq $8, %%rsp;"
: /* output */
:"r"(str),"r"(p_printf) /* input */
: "rax", "rcx" /*, "st(1)","memory"*/ /* clobbered register */
);
return 0;
}
+++++++++++++CODE++++++++++++++++++
--
The best Regards.