MASM是否组装多个源文件并将它们链接在一起? [英] Does MASM assembling multiple source files and linking them together?
问题描述
我试图查看asm语言是否支持基于链接的功能,例如"C"语言.例如.我有"m.asm":
I was trying to see if asm language support function based linked like "C" language. E.g. I have got "m.asm":
assume cs:code
code segment
start:
mov ax,20h
call s
mov ah,4ch
int 21h
code ends
end start
其中"s"是源代码中不存在的符号,然后我有了n.asm文件来定义符号(实际上是标签)
In which "s" is a symbol not existing in the source code, then I've got n.asm file to define a symbol (a label in fact)
code segment
s:
mov bx,4h
div bx
code ends
实际上m.asm无法编译,告诉我"s"是未定义的符号.如何解决此问题并满足我的要求?
In fact m.asm fails to compile, telling me that "s" is a symbol not defined. How can I resolve this problem and meet my request?
推荐答案
您需要声明函数s
对于希望使用public
在n.asm
中访问其他模块(例如,通过call
)的其他模块可见>指令,则需要使用m.asm
中的extern
指令将s
声明为外部引用.
You need to declare function s
as visible to other modules that wish to access it (e.g. via call
) in n.asm
using the public
directive and you need to declare s
as an external reference using the extern
directive in m.asm
.
这对于少量的声明是很好的,但是如果您的模块增长到足够大的大小,则可能需要使用include
头文件来进行管理.
This is fine for a small number of declarations but if your modules grow to any substantial size you may want to use an include
header files to manage that.
这篇关于MASM是否组装多个源文件并将它们链接在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!