Assembly login program always returning "true" -
i'm working on presentation , came across code great addition presentation. problem if enter "hello123" (for example), program assumes "hello123" , "hello" matched.
this code came here. wasn't able comment code because of low rep. did research , tried myself can't sort out problem. grateful if can me.
.model small .stack 100h .data db "hello$" login db "please log in: $" lg db 21 ;<=== maximum number of chars allowed (20). db ? ;<=== number of chars user entered (?). db 21 dup(0) ;<=== array of chars (finish 0dh=13). hellomsg db 0dh, 0ah, "hello message$" .code main proc mov ax, @data mov ds, ax mov ah, 09h lea dx, login int 21h mov ah, 0ah mov dx, offset lg ;<=== tell int 21h store captured string here. int 21h mov si, offset lg + 2 ;<=== point array of chars. mov di, offset ;<=== point user. ck: ;check end of user. mov dh, [di] cmp dh, '$' je hi ;<=== end reached. chars match. ;check end of input. mov dl, [si] ;<=== current entered char. cmp dl, 13 je bye ;<=== end reached. input shorter. ;compare current entered char current user char. cmp dl, dh jne bye ;<=== current chars different. inc si ;<== next entered char. inc di ;<== next user char. jmp ck ;<== repeat. hi: mov ah, 09h lea dx, hellomsg int 21h bye: mov ah, 4ch int 21h main endp end main
so time burned not knowing 1 line of code end all.
cmp byte ptr lg + 1, 5
add before ck:
ck: ;check end of user. mov dh, [di] cmp dh, '$' je hi ;<=== end reached. chars match.
Comments
Post a Comment