【发布时间】:2017-12-01 14:31:26
【问题描述】:
我想要 eflags 值,但出现错误
operand type mismatch for `mov'
这是我的代码:
int a0 = 0, b0 = 1; short c0;
// asm("cmp %1, %2\npushf\npop ax\nmov ax, $0": "=r" (c0): "r" (a0), "r" (b0));
asm("cmp %1, %2\n lahf\n mov %%ax, $0": "=r" (c0): "r" (a0), "r" (b0): "ax");
我也试过 movb 啊,但同样的错误。
【问题讨论】:
-
使用
"=a"(c0)而不是"=r"告诉编译器结果首先在RAX/EAX/AX/AL中,不需要MOV。每当您的内联汇编以 MOV 开头或结尾时,您的编写效率都可能很低。
标签: gcc assembly x86 x86-64 inline-assembly