assemblycompilationlinkermasm

MASM: linking 2 asm files together failed: fatal error L1101: invalid object module?


I was trying to compile 2 .asm files using a function call and link them together, the main program(m.asm) is :

assume cs: code

  extrn s: near

code segment
start:
  mov ax,20h
  call s
  mov ah,4ch
  int 21h
code ends

  end start

And the function "s" is define in n.asm:

  assume cs: code

  public s

code segment
s:
  mov bx,4h
  div bx
  ret
code ends

  end

So in dosbox I used masm to compile them:

masm m.asm
masm n.asm

No problem, then I try to link them together:

link m.obj+n.obj m.exe

Now masm gives error:

M.EXE : fatal error L1011: invalid object module
 pos: 1 Record type: 4D

Why is that? Do I need any special compile/link flags to make it successful? Thanks.


Solution

  • You should declare the code segment as public in both modules:

    CODE SEGMENT PUBLIC 'CODE' and CODE SEGMENT PUBLIC 'CODE'

    Don't forget to provide for a stack segment: STACK SEGMENT WORD STACK 'STACK' DW 10 DUP 4855h STACK ENDS

    I assembled and linked the files with MASM v6.1 : no errors reported! The exe executes correctly.