Multi-File Assembly Program

Demonstration of assembly-language procedures, which perform simple I/O operations. This version of the program splits the procedures into two files:

This program can be assembled by the MASM assembler, with this command:

  C:\>  ml  fileA.asm  fileB.asm   
The resulting program will be named fileA.exe.

(See procdemo.html for the single-file version of this program.)


The main procedure, in one file.
  • Note that other procedures, which are in a different file, must be identified by the extern directive. This serves the same purpose as a C++ prototype.
  • All the procedures are in the same code segment, so they are identified as :near procedures. (This is consistent with the ".model small" directive.)
;---------------------------------------------------------------------------
; Demo of character I/O in assembly from class examples
;
; 2001-02-14 -bob,mon.
;---------------------------------------------------------------------------

        .model small
        .stack 100h

        .data
msg1    db  "Enter a character: $"
ch1     db  ?
msg2    db  "You entered '$"
msg3    db  "'.$"

        .code
        extern DOSstr:near
        extern getChr:near, putChr:near
        extern doCRLF:near

main    proc
        mov  dx, @data
        mov  ds, dx

        mov  ax, offset msg1
        call DOSstr

        call getChr
        mov  ch1, al
        call doCRLF

        mov  ax, offset msg2
        call DOSstr
        mov  al, ch1
        call putChr
        mov  ax, offset msg3
        call DOSstr
        call doCRLF

        mov  al, 0
        mov  ah, 4Ch
        int  21h
main    endp
;---------------------------------------------------------------------------

        end main    ; program will start w/ "main" proc.
;---------------------------------------------------------------------------

A number of procedures, collected in a secondary file.
  • These procedures can be called from procedures in other files, so their procedure names must be declared with the public directive.
  • (The procedures must also be declared "extern" in any files that call them.)
  • The memory model must also be specified (by ".model small" directive), and any calling procedures will have to use the same model.
;---------------------------------------------------------------------------
; some I/O procedures, in assembly.
; version 1:
;       unprotected registers
;       args passed in AX, BX, ... as needed
;
; 2001-02-14 -bob,mon.
;---------------------------------------------------------------------------
        public DOSstr, getChr, doCRLF, DOSstr, putChr

        .model small

        .code
doCRLF  proc
        mov  dl, 0Dh
        mov  ah, 02h
        int  21h
        mov  dl, 0Ah
        int  21h
        ret
doCRLF  endp
;---------------------------------------------------------------------------

DOSstr  proc
        mov  dx, ax
        mov  ah, 09h
        int  21h
        ret
DOSstr  endp
;---------------------------------------------------------------------------

; Get DOS-processed keyboard character, w/ echo
;
getChr  proc
        mov  ah, 01h
        int  21h
        ret
getChr  endp
;---------------------------------------------------------------------------

putChr  proc
        mov  dl, al
        mov  ah, 02h
        int  21h
        ret
putChr  endp
;---------------------------------------------------------------------------
        end    ; no proc name here: none of these proc's start a program
;---------------------------------------------------------------------------