Embed presentation
Download to read offline




![Open a file and write data in file
.MODEL SMALL
.STACK 100H
.DATA
FNAME DB 'SUHAIB.TXT',0
FHANDLE DW ?
MSG DB 'ENTER THE DATA $'
BUFFER DB 100 DUP('$') ;100 BYTE
.CODE
START:
MOV AX,@DATA
MOV DS,AX
;OPEN A EXISTING FILE
MOV AH,3DH
LEA DX,FNAME
MOV AL,2
INT 21H
MOV FHANDLE,AX
lea dx,msg
mov ah,09
int 21h
mov si,0
mov cx,0
again:
mov ah,01
int 21h
cmp al,13 ; asci code of enter
je exit
mov buffer[si],al
inc si
inc cx
jmp again
exit:
mov ah,40h
mov bx,fhandle
lea dx,buffer
int 21h
mov ah,4ch
int 21h
end start](https://image.slidesharecdn.com/filehandling-220614170853-c77eaadb/75/FILE-HANDLING-5-2048.jpg)


This document discusses how to write text data to a file in Assembly Language. It provides the steps to open an existing file, write a message prompting the user to enter data, accept input from the user into a buffer, and then write that buffered data to the opened file using DOS function calls before closing and exiting the program. The key steps are opening the file, prompting for and collecting user input, writing the input buffer to the file handle, and closing out.




![Open a file and write data in file
.MODEL SMALL
.STACK 100H
.DATA
FNAME DB 'SUHAIB.TXT',0
FHANDLE DW ?
MSG DB 'ENTER THE DATA $'
BUFFER DB 100 DUP('$') ;100 BYTE
.CODE
START:
MOV AX,@DATA
MOV DS,AX
;OPEN A EXISTING FILE
MOV AH,3DH
LEA DX,FNAME
MOV AL,2
INT 21H
MOV FHANDLE,AX
lea dx,msg
mov ah,09
int 21h
mov si,0
mov cx,0
again:
mov ah,01
int 21h
cmp al,13 ; asci code of enter
je exit
mov buffer[si],al
inc si
inc cx
jmp again
exit:
mov ah,40h
mov bx,fhandle
lea dx,buffer
int 21h
mov ah,4ch
int 21h
end start](https://image.slidesharecdn.com/filehandling-220614170853-c77eaadb/75/FILE-HANDLING-5-2048.jpg)

