Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline Assembly in C

#include<stdio.h>
#include<stdlib.h>

int main (void)
{
 int a=10, b;
 asm ("movl %1, %%eax;
       movl %%eax, %0;"
      :"=r"(b)        /* output */
      :"r"(a)         /* input */
      :"%eax"         /* clobbered register */
     );
 printf("%d", b);
 system("pause");
}

I am fairly a newbie, and I copy the sample code in the book bought yesterday, but when I compiled my first asm code, I just got some warnings and errors reported from GCC-mingw32 Compiler listed below:

In function 'main':
line 7 --> warning: missing terminating " character
line 7 --> error: missing terminating " character
line 8 --> error: expected string literal before 'movl'
line 8 --> warning: missing terminating " character
line 8 --> error: missing terminating " character

How can I compile it successfully? Thanks in advance :-)

like image 392
user2967915 Avatar asked Nov 13 '13 12:11

user2967915


1 Answers

Each instruction should be placed in double quotes "" as "movl %1, %%eax;"

like image 63
Sunil Bojanapally Avatar answered Sep 29 '22 22:09

Sunil Bojanapally