
TITLE SWRIT.ASM -- Write squential records
dseg	segment
	fcb	equ	5ch
	org	6ah
recsz	dw	?
	org	7ch
recno	db	?
	org	7eh
maxlen	db	31
actlen	db	?
	org	80h
dta	db	31 dup(' ')
prompt	db	'input name__age__tel.'
	db	0dh,0ah,'$'
errmsg	db	'error !'
dseg	ends
;--------------------------------------------------
cseg	segment
main	proc	far
	assume	cs:cseg, ds:dseg
start:	push	ds
	sub	ax,ax
	push	ax
	mov	dx,fcb		;create file func.
	mov	ah,16h
	int	21h
	cmp	al,0
	jnz	error		;create file error
	mov	recsz,30	;record size
	mov	recno,0		;record number
	lea	dx,dta		;set address of DTA
	mov	ah,1ah
	int	21h
disp:	push	ds
	mov	ax,dseg		;set DS to dseg
	mov	ds,ax
	mov	ah,09h
	lea	dx,prompt
	int	21h
	pop	ds
input:	lea	dx,maxlen	 ;input record
	mov	ah,0ah
	int	21h
	cmp	actlen,1
	jle	exit		;no chars input
write:	mov	ah,15h		;squent write func.
	mov	dx,fcb
	int	21h
	cmp	al,0
	jnz	error
	cld
	lea	di,dta		;clear DTA with
	mov	al,20h		;  space
	mov	cx,31
	rep	stosb
	jmp	input		;get another record
exit:	mov	dta,1ah		;set EOF mark
	mov	ah,15h		;write EOF
	mov	dx,fcb
	int	21h
	cmp	al,0
	jnz	error
	mov	ah,10h		;close file func.
	mov	dx,fcb
	int	21h
	ret
error:	push	ds
	mov	ax,dseg
	mov	ds,ax
	lea	dx,errmsg	;display error
	mov	ah,09h		;  message
	int	21h
	pop	ds
	ret
main	endp
cseg	ends
;--------------------------------------------------
	end	start

