1 Replies - 211 Views - Last Post: 23 April 2014 - 07:41 PM

#1 Helegurbann  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 23-July 11

To call func with 2 or more than variables in gcc inline asm

Posted 22 April 2014 - 05:17 AM

Hi everybody,

I want to call this function:
int x86asm_add(int a,int B)/>/>
{asm( 
"addl %%ebx,%%eax" 
:"=a"(a) 
:"a"(a),"b"(B)/>/>
); 
} 


in here:
int x86asm_add_call(int a,int B)/>/>
{ 
   asm("x86asm_add %1,%2,%0" : "=r"(a):"r"(a),"r"(B)/>/>
   ); 
} 


But i taken this error:
no such instruction error in x86asm:`x86asm_add %eax,%edx,%eax' 



I looked and made like in here: http://webcache.goog...r&ct=clnk&gl=tr

Part: 4.1 Extended asm, an introduction.


How can i call this function?I am using dev-c++.And i want to learn this in gcc-inline-asm.Thank you for your helps

Note:It has not "/>" in my code.But i can not delete in here...

This post has been edited by Helegurbann: 22 April 2014 - 05:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: To call func with 2 or more than variables in gcc inline asm

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: To call func with 2 or more than variables in gcc inline asm

Posted 23 April 2014 - 07:41 PM

Quote

no such instruction error in x86asm:`x86asm_add %eax,%edx,%eax'

The Assembler is telling you that there is no such instruction named "x86asm_add" Assembly is not like C or other languages, if you want to "invoke" a function, you must call its address.

Before I show how to do it, let's get rid of the use of that ugly (and not for human consumption) AT&T syntax, add the following to the compiler options under Project Options:
-masm=intel
Now we can use the normal INTEL syntax. But first, why are you calling a function just to call another function? That kinda defeats the purpose of using Assembly. Anywhoo,

#include <stdio.h>

int x86asm_add (int a, int b);

int main (void)
{
  int  result = 0;
  printf ("Sum of 32+65 = %d\n",  x86asm_add (32, 65));

  asm (
    "push   30;"
    "push   60;"
    "lea    eax, _x86asm_add;"
    "call   eax;"
  :"=a" (result)
  );
  printf ("Sum of 30+60 = %d\n",  result);

  printf ("Sum of 100+65 = %d\n",  x86asm_add_call (100, 65));

  return 1;
}

int x86asm_add (int a, int b)
{
  asm (
    "mov eax, [esp + 8];"
    "add eax, [esp + 12];"
    "leave;"
    "ret;"
  );
  return 1;
}

int x86asm_add_call (int a, int b)
{
  asm (
    "mov    eax, [esp + 8];"
    "mov    ecx, [esp + 12];"
    "push   ecx;"
    "push   eax;"
    "lea    eax, _x86asm_add;"
    "call   eax;"
    "leave;"
    "ret;"
  );
  return 1;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1