A Three-Module Averaging Program
;*** Three-module program that averages a list of numbers
;*** avgmain.asm main module points si to list and calls avg procedure
;*** avgproc.asm module contains the definition of the avg procedure
;*** avgdata.asm module defines the list of numbers
;*** THESE WOULD BE IN DIFFERENT FILES AND WOULD BE ASSEMBLED SEPARATELY! 

 ; AVGMAIN.ASM -- Main module

 0000                           stk     segment stack
 0000     10 [ ???? ]                   dw      16 dup(?)
 0020                           stk     ends

 0000                           data    segment public
                                        extrn   table:word
 0000  ????                     result  dw      ?
 0002                           data    ends

 0000                           code    segment public
                                        extrn   avg:near
                                        assume  cs:code,ds:data
 0000                           main    proc    far
 0000  B8 ---- R                        mov     ax,data
 0003  8E D8                            mov     ds,ax
 0005  BE 0000 E                        mov     si,offset table
 0008  E8 0000 E                        call    avg
 000B  A3 0000 R                        mov     result,ax
 000E  B8 4C00                          mov     ax,4c00h
 0011  CD 21                            int     21h
 0013                           main    endp
 0013                           code    ends
                                        end     main

 ; AVGPROC.ASM -- defines the avg procedure

                                public  avg
 0000                           code    segment word    public
                                        assume  cs:code
 0000                           avg     proc    near
 0000  B8 0000                          mov     ax,0
 0003  B9 0000                          mov     cx,0
 0006  83 3C 00                 top:    cmp     word ptr [si],0
 0009  7C 08                            jl      done
 000B  03 04                            add     ax,[si]
 000D  41                               inc     cx
 000E  83 C6 02                         add     si,2
 0011  EB F3                            jmp     top
 0013  E3 05                    done:   jcxz    zdiv
 0015  BA 0000                          mov     dx,0
 0018  F7 F1                            div     cx
 001A  C3                       zdiv:   ret
 001B                           avg     endp
 001B                           code    ends
                                        end

 ; AVGDATA.ASM -- Defines the table of data

                                public  table
 0000                           data    segment word    public
 0000  0001 0002 0003 0004      table   dw      1,2,3,4,5,6,-1
       0005 0006 FFFF
 000E                           data    ends
                                        end