Search code examples
assemblyx86masm

Does MASM assembling multiple source files and linking them together?


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

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

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?


Solution

  • 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.

    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.