Pregunta

#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 :-)

¿Fue útil?

Solución

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

Otros consejos

There must be opening and closing quotes on the first two rows of the asm code like this:

#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");
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top