TITLE TYPER.EXE -- Using file handles I/O
;--------------------------------------------------
keyboard  equ  0
crt	  equ  1
printer	  equ  4
;--------------------------------------------------
stack segment stack 'stack'
      db   64 dup(' ')
stack ends
;--------------------------------------------------
dseg segment 'data'
typebuff  db  130 dup(' ')
errmsg	  db  '*** error ***',0dh,0ah
dseg ends
;--------------------------------------------------
cseg segment 'code'
main proc far
     assume cs:cseg,ds:dseg,ss:stack,es:dseg
	push	ds
	sub	ax,ax
	push	ax
	mov	ax,dseg
	mov	ds,ax
	mov	es,ax
	sti
	cld
	mov	ah,0	      ;initializing printer
	mov	dx,0
	int	17h
input:	mov	bx,keyboard       ;handle 0      
	mov	ah,3fh            ;request read func.
	mov	cx,130            ;number of bytes
	lea	dx,typebuff       ;addr of input area
	int	21h               ;call DOS
	jc	error
	cmp	typebuff,0
	je	exit              ;end of kbd input
output:	mov	cx,ax             ;number of char.
	mov	bx,printer        ;handle 4
	mov	ah,40h            ;reguest write func.
	int	21h               ;call DOS
	jc	error
	jmp	input
error:	mov	bx,crt            ;handle 1
	mov	ah,40h            ;output function
	mov	cx,15             ;length of string
	lea	dx,errmsg         ;addr of string
	int	21h               ;call DOS
exit:	ret
main	endp
cseg	ends
;------------------------------------------------------
	end  main
