You are on page 1of 6

LAB ASSESSMENT - 05

SATYARAJ RANJAN
REG. NO – 19BCB0140

Qn - Write an assembly language program to create a file and


store data of size 16 bytes .

Solution :-

AIM:- To create a file and store data of size 16 bytes using emu8086.

PROCEDURE:-
1. START
2. First Initialize all models and stack.
3. In the Data Segment initialize filename as ‘19BCE0059_DA5.txt’. 4.
Initialize a variable ‘filehandle’ that will store the location of the file.
5. Initialize a msg to be displayed to “Enter the Data” and a buffer to
store 16 bytes of Data (the data to be written in the file).
6. Create a New file by using the Service no. 3CH .
7. Store the offset address of the fname into DX
8. Use interrupt 21H.
9. Address of File which is stored in the AX is moved to ‘fhandle’.
10. Display the message in the emulator screen and enter the Data
to write in the TXT file.
11. The message is stored in the buffer and the address is incremented
using si register.
12. Close the file.
13. Exit
14. END

CODE :-

.model small
.stack 100h
.data
fname db '19BCB0140_DA5.txt',0
fhandle dw ?
msg db 'Enter the Data: $'
buffer db 16 dup('$')
.code
main proc
mov ax,@data
mov ds, ax

;Create a new file


mov ah,3ch
lea
dx,fname
mov cl,0
int 21h
mov

fhandle,ax
;Display Msg

lea dx,msg
mov ah,09h
int 21h
mov si,0
mov cx,0
again:
mov ah,01h
int 21h
cmp al,13
je exit
mov
buffer[si],al inc
si
inc cx
jmp again
exit:

; write text in File


mov ah,40h
mov bx,fhandle
lea dx,buffer
;mov cx,number of characters
int 21h

;Close a file
mov ah,3eh
mov bx,fhandle
int 21h

;EXIT
mov ah,4ch
int 21h
main endp
end main
OUTPUT :-
After Taking Input from The User :-

File Named “ 19BCB0140”_DA5 ” being created with user


input written.

You might also like