0% found this document useful (0 votes)
42 views8 pages

Lab 7 Solution

This document contains solutions to two assembly language programming questions. The first solution takes a username and password from the user as input and verifies it against stored values. The second solution enhances this by allowing for longer username and password inputs of up to 32 characters.

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)
42 views8 pages

Lab 7 Solution

This document contains solutions to two assembly language programming questions. The first solution takes a username and password from the user as input and verifies it against stored values. The second solution enhances this by allowing for longer username and password inputs of up to 32 characters.

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/ 8

Lab 7 Q1: 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:

Lab 7 Q2: Solution


.model tiny
.data
msg1 db "enter User Name (max 32 chars): $"
usn1 db 33 dup('$')
max1 db 33
act1 db ?
inp1 db 33 dup('$')
fname1 db 'user.txt',0
handle1 dw ?
msg2 db "enter Password (max 32 chars): $"
pass1 db 33 dup('$')
inp2 db 33 dup('$')
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
int 21h
;reading stored username
mov ah,3dh
mov al,0h
lea dx,fname1
int 21h
mov handle1,ax
lea dx,usn1
mov cx,00
x1: push cx
mov ah,3fh
mov bx,handle1
mov cx,01h
int 21h
mov bx,dx
inc dx
pop cx
inc cx
cmp byte ptr[bx],'$'
jnz x1
mov ah,3eh
int 21h
;comparing usernames
cld
lea di,inp1
lea si,usn1
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
;reading stored password
mov ah,3dh
mov al,0h
lea dx,fname2
int 21h
mov handle2,ax
lea dx,pass1
mov cx,00
x2: push cx
mov ah,3fh
mov bx,handle2
mov cx,01h
int 21h
mov bx,dx
inc dx
pop cx
inc cx
cmp byte ptr[bx],'$'
jnz x2
mov ah,3eh
int 21h
;taking password from user
mov bx,cx
lea di,inp2
l2: mov ah,08h
int 21h
mov [di],al
mov dl,'*'
mov ah,02h
int 21h
inc di
dec cx
jnz l2
;compare passwords
cld
mov cx,bx
lea di,inp2
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:

You might also like