0

So I'm having trouble figuring out how to call a function using in line assembly

void print_test(const char* str1, int int1) {
printf("%s-%d", str1, int1);
}

int main() {
   const char * str1 = "test"
   int int1 = 1;
   //asm function call here
}

I tried doing the following:

asm(
"push %1;"
"push %0;"
"call *%2;"
:"=r"(str1), "=r"(int1)
:"1"(str1), "0"(int1)
:
);

If someone could explain why this isn't working/how to go about doing this, that'd be greatly appreciated.

  • please specify which kind of trouble you have and provide all code to support you case. – Serge Sep 01 '17 at 00:41
  • 3
    Umm, you forgot to pass in the function address? Anyway, this is a bad idea. You will also need to clobber all registers that the calling convention designates caller-saved and in case of cdecl you will need to remove the arguments you put on the stack. – Jester Sep 01 '17 at 00:55
  • 3
    Calling functions from inline asm is a bad idea. Why do you think you need to do this? – David Wohlferd Sep 01 '17 at 00:57
  • What architecture is this? Also, “it doesn't work” is not an error. Description. What exactly happens? What did you expect to happen? – fuz Sep 01 '17 at 01:00
  • 1
    don't do this it is far more complex than you realize to call a function from inline unless you have a good idea what you are doing. – Michael Petch Sep 01 '17 at 01:17

0 Answers0