#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");
}
我是一个相当的新手,我复制了昨天买的书中的示例代码,但是当我编译我的第一个asm代码时,我只是从下面列出的GCC-mingw32编译器中报告了一些警告和错误:
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
如何才能编译成功?提前感谢:-)
asm代码的前两行必须有开头和结尾引号,如下所示:
#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");
}