我从上面的汇编器调用中得到了不需要的答案。
我正在使用 MASM 和 Visual Studio 2019 社区版。
; assembler code
Tester2 proc
mov ax, -100
cwd
mov cx, 3
idiv cx
ret
Tester2 endp
end
// c++ code
#include <iostream>
extern "C" int Tester2();
int main() {
auto rr = Tester2();
std::cout << rr;
return 0;
}
您已声明
Tester2
返回 int
,但这很可能是 short
,因为您只填写了 ax 并忽略了 eax 的其余部分。如果您将函数声明为返回短路,则问题应该消失。