0% found this document useful (0 votes)
8 views14 pages

Lab-6 Solution

The document shows code to open an existing file, read from it, and write data to a new file by splicing parts of data from multiple source files.

Uploaded by

f20221197
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Lab-6 Solution

The document shows code to open an existing file, read from it, and write data to a new file by splicing parts of data from multiple source files.

Uploaded by

f20221197
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

.

model tiny
.data
fname db 'test.txt',0
handle dw ?
.code
.startup

mov ah,3ch ; 3ch is for reading the file


lea dx,fname
mov cl,1h
int 21h
mov handle,ax

.exit
end

Output:
Code:

.model tiny
.data
fname db 'second.txt',0
handle dw ?
msg db 'MUP La=B'
.code
.startup

;creating a file if it is not existing


mov ah,3ch
lea dx,fname
mov cl,1h
int 21h
mov handle,ax
; open a file
mov ah,3dh
mov al,1h
lea dx,fname
int 21h
mov handle,ax
; write msg to file
mov ah,40h
mov bx,handle
mov cx,10
lea dx,msg
int 21h
;closing a file
mov ah,3eh
int 21h
.exit
end
Open existing file

Code

.model tiny
.data
fname db 'second.txt',0
handle dw ?
msg db 'MUP MSP'
.code
.startup

;creating a file if it is not existing


;mov ah,3ch
;lea dx,fname
;mov cl,1h
;int 21h
;mov handle,ax

;open existing file

; open a file
mov ah,3dh
mov al,1h
lea dx,fname
int 21h
mov handle,ax
; write msg to file
mov ah,40h
mov bx,handle
mov cx,10
lea dx,msg
int 21h
;closing a file
mov ah,3eh
int 21h
.exit
end
.model tiny
.data
str1 db 'Enter your name: $'

max1 db 32
act1 db ?
inp1 db 32 dup('$')
fname db 'testing.txt',0
handle dw ?
.code
.startup
; write to console
mov ah, 09h
lea dx, str1
int 21h

; read input from console


mov ah, 0ah
lea dx, max1
int 21h

; create file
mov ah, 3ch
lea dx, fname
mov cl, 0
int 21h
mov handle, ax

; write to file
mov ah, 40h
mov cx, 00h
mov cl, act1
mov bx, handle
lea dx, inp1
int 21h

; close file
mov ah, 3eh
mov bx, handle
int 21h
.exit
end
; *** Part A ***
.model tiny
.data
fname1 db 'name.txt',0
fname2 db 'id.txt',0
handle1 dw ?
handle2 dw ?

msg1 db 'Mritunjay'
len1 db 06h
msg2 db 'Shall'
len2 db 0dh
.code
.startup
; create name.txt
mov ah, 3ch
lea dx, fname1
mov cl, 1
int 21h

; create id.txt
mov ah, 3ch
lea dx, fname2
mov cl, 1
int 21h

; open name.txt
mov ah, 3dh
mov al, 1h
lea dx, fname1
int 21h
mov handle1, ax
; open id.txt
mov ah, 3dh
mov al, 1h
lea dx, fname2
int 21h
mov handle2, ax

; write to name.txt
mov ah, 40h
mov bx, handle1
mov cx, 00h
mov cl, len1
lea dx, msg1
int 21h

; write to id.txt
mov ah, 40h
mov bx, handle2
mov cx, 00h
mov cl, len2
lea dx, msg2
int 21h

; close all files


mov ax, 3eh
mov bx, handle1
int 21h

mov ax, 3eh


mov bx, handle2
int 21h
.exit
end
; *** Part B ***
.model tiny
.data
fname1 db 'name.txt',0
handle1 dw ?
fname2 db 'id.txt',0
handle2 dw ?
fname3 db 'splice.txt',0
handle3 dw ?

part1 db 8 dup('$')
part2 db 6 dup('$')

.code
.startup
; create splice.txt
mov ah, 3ch
lea dx, fname3
mov cl, 01h
int 21h

; open all files


mov ah, 3dh
mov al, 0h
lea dx, fname1
int 21h
mov handle1, ax

mov ah, 3dh


mov al, 0h
lea dx, fname2
int 21h
mov handle2, ax

mov ah, 3dh


mov al, 1h
lea dx, fname3
int 21h
mov handle3, ax

; read from id.txt and name.txt


mov ah, 3fh
mov bx, handle2
mov cx, 8
lea dx, part1
int 21h

mov ah, 3fh


mov bx, handle1
mov cx, 6
lea dx, part2
int 21h

; write to splice.txt
mov ah, 40h
mov bx, handle3
mov cx, 0eh
lea dx, part1
int 21h

; close splice.txt
mov ax, 3eh
mov bx, handle1
int 21h

mov ax, 3eh


mov bx, handle2
int 21h

mov ax, 3eh


mov bx, handle3
int 21h
.exit
end

You might also like