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

Dmitrij K kdiman1982@gmail.com
Mon Mar 26 08:36:00 GMT 2012


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.



More information about the Binutils mailing list