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]

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.


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