【发布时间】:2018-11-16 14:28:33
【问题描述】:
我正在玩弄 GCC 程序集输出,尝试使用快速整数平均值。这是我最初使用的 C 代码:
unsigned int average (unsigned int x, unsigned int y) {
return (x&y)+((x^y)>>1);
}
这是它发出的程序集(使用 Intel 语法):
average:
mov edx, edi
and edi, esi
xor edx, esi
shr edx
lea eax, [rdx+rdi]
ret
当我为 NASM 翻译它时:
average:
mov edx, edi
and edi, esi
xor edx, esi
shr edx, 1
lea eax, [rdx+rdi]
ret
它抱怨这个错误,与lea:
<source>:6: error: impossible combination of address sizes
<source>:6: error: invalid effective address
我对汇编并不超级熟悉,但这似乎非常奇怪。有人可以向我解释一下这里到底发生了什么吗?
【问题讨论】:
-
从 GCC 输出翻译/插入 NASM 时是否有其他输出有效?
-
根据我的经验,它通常有,但不是 100% 的时间。我只是好奇是什么使 this 示例不起作用。
-
我更新了问题名称和标签,以澄清我问的是失败的代码翻译,而不是简单的插入输出到输入。
标签: assembly compiler-errors nasm x86-64 code-translation