【问题标题】:Inline Assembly in CC中的内联汇编
【发布时间】:2013-11-26 01:38:45
【问题描述】:
#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

如何编译成功?在此先感谢:-)

【问题讨论】:

标签: c gcc assembly x86 inline-assembly


【解决方案1】:

每条指令都应该放在双引号中 "" as "movl %1, %%eax;"

【讨论】:

  • 很好,感谢您的帮助>_
【解决方案2】:

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");
}

【讨论】:

  • 太好了,感谢您的帮助>_
猜你喜欢
  • 2013-07-23
  • 2017-11-01
  • 1970-01-01
  • 2021-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
  • 1970-01-01
相关资源
最近更新 更多