VIEWER


    DOSSEG
    .MODEL SMALL
    .STACK 200h
    .CODE
    

;===- Data -===

BufferSeg   dw  0

ErrMsgOpen  db  "Error opening `"
FileName    db  "TST.TXT",0,8,"'$"     ;8 is a delete character
                                        ;0 is required for filename 
                                        ;(displays a space)
FileLength dw 0

;===- Subroutines -===

;;PROC DisplayFile NEAR
 
;;ENDP DisplayFile

;===- Main Program -===

START:
    mov     ax,cs
    mov     ds,ax
    mov     bx,ss
    add     bx,200h/10h     ;get past the end of the file
    mov     [BufferSeg],bx  ;store the buffer segment

    push    ds
    mov     ax,cs
    mov     ds,ax
    mov     ax,3d00h    ;open file (ah=3dh)
    mov     dx,offset FileName
    int     21h		;BIOS ISR
    jc      OpenError
    mov     bx,ax       ;move the file handle into bx

    mov     ds,[BufferSeg]
    mov     dx,0            ;load to [BufferSeg]:0000
    mov     ah,3fh
    mov     cx,0FFFFh       ;try reading a segment 
    int     21h

    mov     [cs:FileLength],ax

    mov     ah,3eh
    int     21h             ;close file

    cld
    mov     si,0
    mov     cx,[cs:FileLength]

PrintLoop:
    mov     ah,2
    lodsb
    mov     dl,al
    int     21h         ;print a character

    dec     cx
    jne     PrintLoop
    
    pop     ds
    ret

OpenError:
    mov     ah,9
    mov     dx,offset ErrMsgOpen
    int     21h

    pop     ds
    ret
    mov     ax,4c00h
    int     21h
END START