Lab 7 Solution
Lab 7 Solution
.model tiny
.data
msg1 db "Enter 10 character long User Name: $"
usn1 db 11 dup(?) ; Changed from '$' to '?'
max1 db 20
act1 db ?
inp1 db 10, ?, 10 dup('$') ; Changed to specify the maximum length as 10
characters
fname1 db 'user.txt',0
handle1 dw ?
msg2 db "Enter 5 character long Password: $"
pass1 db 6 dup(?) ; Changed from '$' to '?'
inp2 db 6, ?, 6 dup('$') ; Changed to specify the maximum length as 6 characters
fname2 db 'pswd.txt',0
handle2 dw ?
msg3 db "Hello $"
msg4 db "Wrong username$"
msg5 db "Wrong password$"
nline db 0ah,0dh,"$"
.code
.startup
lea dx,msg1
mov ah,09h
int 21h
lea dx,nline
mov ah,09h
int 21h
;taking username from user
lea dx,max1
mov ah,0ah
mov dx,offset inp1 ; Changed to specify input buffer
int 21h
;reading stored username
mov ah,3dh
mov al,0h
lea dx,fname1
int 21h
mov handle1,ax
mov ah,3fh
mov bx,handle1
mov cx,11
lea dx,usn1
int 21h
mov ah,3eh
int 21h
;comparing usernames
cld
lea di,inp1+2 ; Changed to start comparison from the actual username in the
buffer
lea si,usn1
mov cx,10 ; Changed to compare only up to 10 characters
repe cmpsb
jcxz l1
;incorrect username
lea dx,nline
mov ah,09h
int 21h
lea dx,msg4
mov ah,09h
int 21h
mov ah,4ch
int 21h
;correct username
l1: lea dx,nline
mov ah,09h
int 21h
lea dx,msg2
mov ah,09h
int 21h
lea dx,nline
mov ah,09h
int 21h
;taking password from user
mov cx,6
lea di,inp2+2 ; Changed to start storing password from the actual password in the
buffer
l2: mov ah,08h
int 21h
mov [di],al
mov dl,'*'
mov ah,02h
int 21h
inc di
loop l2 ; Changed to use loop instruction for repeated input
;reading stored password
mov ah,3dh
mov al,0h
lea dx,fname2
int 21h
mov handle2,ax
mov ah,3fh
mov bx,handle2
mov cx,6
lea dx,pass1
int 21h
mov ah,3eh
int 21h
;compare passwords
cld
mov cx,6
lea di,inp2+2 ; Changed to start comparison from the actual password in the
buffer
lea si,pass1
repe cmpsb
jcxz l3
;incorrect password
lea dx,nline
mov ah,09h
int 21h
lea dx,msg5
mov ah,09h
int 21h
mov ah,4ch
int 21h
;correct password
l3: lea dx,nline
mov ah,09h
int 21h
lea dx,msg3
mov ah,09h
int 21h
lea dx,usn1
mov ah,09h
int 21h
lea dx,nline
mov ah,09h
int 21h
.exit
end
Output:
Output: