Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help in TASM password protected program

chanrio13chanrio13 Posts: 2Member
hi to every one. im new here.

can anyone help me on my assignment.

were ask to create a program using TASM that will accept three letter password. if the password is correct it will display "CONGRATULATIONS"
and if it is wrong it will display "SORRY, Youre Out!!!!" and then terminate..

i know it simple "for masters like you"
but it is very hard for like me that has no background on assembly language.

pls help....


heres my code

ideal
model small
stack 1024
dataseg
password db 'rio$'
passwordInput db 100, 99 dup (0)
msg1 db 'Congratulations!$'
msg2 db ' Sorry Youre Out $'
cloneP db ?
clonePI db ?

codeseg
PROC main
mov ax,@data
mov ds,ax
mov es,ax

lea dx, [passwordInput]
mov ah, 0ah
int 21h

cld
mov cx,3
lea di, [passwordInput+2]
lea si, [password]
rep cmpsb
jne NOTEQUAL
lea dx, [msg1]
mov ah,9
int 21h
jmp exit
NOTEQUAL:
lea dx, [msg2]
mov ah,9
int 21h
EXIT:
mov ah,4ch
int 21h
endp
end main

thr problem here is when i input rio it says CONGRATULATIONS but when i put

rioasdasdqweq or anything but with rio on the first it accepts it and says congratulations...

pls help me debug my program...

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]I inserted some empty lines - code is unreadable. Here are some issues:

    1. When string is entered the byte at passwordInput+1 will have the count of characters entered. In your case if it is not 3, then you exit with "you are outta here!" message.

    2. If the count is 3, then you start your CMPSB checking. However to check ALL symbols, you need a REPE instruction. This means: "REPeat while Equal". See RED in your code:
    [/color]
    : [code][size=3]
    : ideal
    : model small
    : stack 1024

    : dataseg
    : password db 'rio$'
    : passwordInput db 100, 99 dup (0)
    : msg1 db 'Congratulations!$'
    : msg2 db ' Sorry Youre Out $'
    : cloneP db ?
    : clonePI db ?
    :
    : codeseg
    : PROC main
    : mov ax,@data
    : mov ds,ax
    : mov es,ax
    :
    : lea dx, [passwordInput]
    : mov ah, 0ah
    : int 21h

    [color=Red]cmp byte ptr [passwordInput+1], 3
    jne NOTEQUAL[/color]

    : cld
    : mov cx,3
    : lea di, [passwordInput+2]
    : lea si, [password]
    : rep[color=Red]e[/color] cmpsb

    : jne NOTEQUAL
    : lea dx, [msg1]
    : mov ah,9
    : int 21h
    : jmp exit

    : NOTEQUAL:
    : lea dx, [msg2]
    : mov ah,9
    : int 21h

    : EXIT:
    : mov ah,4ch
    : int 21h
    : endp
    : end main
    : [/size][/code]
Sign In or Register to comment.