Varible
Varible
采纳率61.3%
2020-02-09 18:15 浏览 663

C++嵌入Assembler(汇编)汇编内出错?

我在C++中插入了汇编代码,但汇编代码老报错,不知什么原因。求各位大神帮助!

代码:

#include <iostream>
using namespace std; 
int main(int argc,char *argv[]) {
 volatile int a[3] = {0,0,0};
 for (int i = 0;i < 3;i ++)
  cout << a[i] << ends;
 cout << endl;
 asm ("inc [esp + 2]");//Assembler:inc [esp + 2]   (++ a[1];)
 for (int i = 0;i < 3;i ++)
  cout << a[i] << ends;
 cout << endl;
 return 0;
}

报错信息:

(File(C:\Users\ADMINI~1\AppData\Local\Temp\ccR9LmJd.s)) Assembler messages:
(Line(42)) (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccR9LmJd.s)) Error: invalid char '[' beginning operand 1 `[esp+2]'

之后我想是不是这个汇编器不支持Intel,就把那一行汇编改成了AT&T格式的:

asm ("inc [esp + 2]");//Assembler:inc [esp + 2]   (++ a[1];)

| |

\/

asm ("inc 2(%esp)");//Assembler:inc 2(%esp)   (++ a[1];)

但还是报错了:

(File(C:\Users\ADMINI~1\AppData\Local\Temp\ccEzueAV.s)) Assembler messages:
(Line(42)) (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccEzueAV.s)) Error: no instruction mnemonic suffix given and no register operands; can't size instruction

本人对AT&T不熟悉,麻烦大家看看哪错了,致以感谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

相关推荐