在单独的文件中编译程序集时出现编译错误

Getting compilation errors when compiling assembly in separate file

本文关键字:编译 错误 程序集 编译程序 文件 单独      更新时间:2023-10-16

这是我的(非常简单的(程序。当函数function在我自己的.cpp文件中时,它工作得很好,但当我将它链接到另一个.asm文件时,我会收到错误。我正在使用Visual C++2010学习版进行编译,我相信这是我正在使用的32位程序集。

#include <iostream>
extern "C" int function();
int main() {
    std::cout << function();
    std::cin.get();
}

function定义为:

.code
function proc
    mov eax, 50
    ret
function endp
end

我得到了错误:

error A2013: .MODEL must precede this directive
error A2034: must be in segment block : function
error A2034: must be in segment block
error A2034: must be in segment block
fatal error A1010: unmatched block nesting : function

这是我第一次使用Assembly,所以我不熟悉这些错误。它们是什么意思?我如何让这个程序发挥作用?

您应该有一个.model和一个cpu声明,通常还有一个堆栈声明。看看这里:http://www.talreg.com/?cat=58