masm - Checking if two strings are equal in assembly -
the program check if user entered password matches 1 specified directly in program. not able understand why happen 'password incorrect' when try input directly keyboard. when specifying 'src' directly in program output seems perfect though.
.model small .stack 1000h disp macro msg ;macro display string of characters lea dx,msg mov ah,09h int 21h endm input macro ;macro input character character mov ah,01h int 21h endm data segment cr equ 0dh lf equ 0ah msg db 'enter password please : ',cr,lf,'$' tru db 'password correct$' fal db 'password incorrect$' src db 10 dup('$') dest db 'yo$' len equ ($-dest) data ends code segment assume cs:code,ds:data,es:data start: mov ax,data mov ds,ax mov es,ax mov si,offset src mov di,offset dest cld mov cx,len xor bx,bx disp msg re: input mov [si],al inc si inc bx cmp al,cr jne re cmp bx,cx ;if string lengths dont match strings unequal jne l1 mov si,offset src repe cmpsb jnz l1 l2: disp tru jmp exit l1: disp fal exit: mov ah,4ch int 21h code ends end start
your check whether read character carriage return placed after character has been written src
buffer. when compare 2 strings later on, src
contain cr character dest
doesn't contain.
that is, if entered yo you'll have dest = 'yo$'
, src = 'yo\r', , len = 3
.
here's modified version of input loop works (new code in lowercase):
re: input cmp al,cr je got_input ; exit loop if read cr character mov [si],al inc si inc bx jmp re got_input: inc bx ; len includes '$' character after 'yo', increase bx 1 match cmp bx,cx ; if string lengths dont match strings unequal
Comments
Post a Comment