Search code examples
assemblymasm32dosbox

Creating a library in MASM while using dosbox


I have a question, i have been given an assignment to make a static library in assembly language i.e. MASM, but all the tutorials i find on the internet are either incomplete or too hard for me to understand. I am using dosbox since i have a 64 bit windows. Please help step by step Please and thank you


Solution

  • I suggest using DosBox only for running the final executable. You don't need DosBox to produce this executable, since Masm32 runs under 64 bit Windows. But the lib.exe shipped with Masm32 doesn't produce a OMF-Library suitable for link16.exe. So you have to get a lib.exe which "speaks" OMF, e.g. the lib.exe by DigitalMars (http://www.digitalmars.com/ctg/lib.html).

    Example:

    main.asm:

    .MODEL small
    
    .code
    EXTERN sub1:NEAR
    main PROC
        mov ax, @data
        mov ds, ax
    
        call sub1
    
        mov ax, 4C00h
        int 21h
    main ENDP
    
    .stack 1000h
    
    END main
    

    function.asm:

    .MODEL small
    
    .data
        text db "This is sub1.",13,10,"$"
    
    .code
    sub1 PROC
        push ax
        push dx
    
        mov ah, 09h
        mov dx, OFFSET text
        int 21h
    
        pop dx
        pop ax
        ret
    sub1 ENDP
    
    END
    

    build.cmd:

    @ECHO OFF
    SET PATH=C:\masm32\bin
    
    ml.exe /c function.asm
    ml.exe /c main.asm
    
    <Path to DigitalMars>\dm\bin\lib.exe -c main.lib main.obj function.obj
    link16.exe main.lib ;
    

    Build it in a console of Windows and run main.exe in DosBox.