Howdy, Stranger!

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

Categories

Compare String, Need HELP!!

Hi

I have been trying to compare two predefined strings, but for some reason it wont let me do it. Here is my code, I get the "NOT CORRECT" message and I cant figure out why.

The program is a lot longer, but when it comes to string comparison it is not doing what it should do.

Thanks for your help and guidance in advance.

By the way I am using TASM/TLINK.

[code].MODEL SMALL
.STACK 100h
.DATA
input DB 'pass','$'
passd DB 'pass','$'
same DB ' CORRECT ',13,10,'$'
notsame DB ' NOT CORRECT ',13,10,'$'

.CODE

lea si, input
lea di, passd
mov cx, 4
cld
repe cmpsb
je SUCCESS
jne UNSUCCESS

SUCCESS:
; Prompt correct
mov ax,@data ;move the data segment address to AX
mov ds,ax ;make DS point to the data segment
mov ah,09h
mov dx,OFFSET same
int 21h
mov ax,4c00h
int 21h

UNSUCCESS:
; Prompt the input on the screen
mov ax,@data ;move the data segment address to AX
mov ds,ax ;make DS point to the data segment
mov ah,09h
mov dx,OFFSET notsame
int 21h
mov ax,4c00h
int 21h

END
[/code]

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hi
    :
    : I have been trying to compare two predefined strings, but for some
    : reason it wont let me do it. Here is my code, I get the "NOT
    : CORRECT" message and I cant figure out why.
    :
    : The program is a lot longer, but when it comes to string comparison
    : it is not doing what it should do.
    :
    : Thanks for your help and guidance in advance.
    :
    : By the way I am using TASM/TLINK.
    :
    : [code]: .MODEL SMALL
    : .STACK 100h
    : .DATA
    : input DB 'pass','$'
    : passd DB 'pass','$'
    : same DB ' CORRECT ',13,10,'$'
    : notsame DB ' NOT CORRECT ',13,10,'$'
    :
    : .CODE
    : [color=Red]mov ax,@data ;move the data segment address to AX
    : mov ds,ax ;make DS point to the data segment
    : mov es,ax ;make ES point to the data segment[/color]
    : [color=Green]; These lines must be done ONCE before any other code is written![/color]
    :
    : lea si, input
    : lea di, passd
    : mov cx, 4
    : cld
    : repe cmpsb
    [color=Green]; The comparison here ^^^ goes on as DS:SI against ES:DI, so
    ; if DS, ES are not set properly then you are comparing wrong things.[/color]
    : je SUCCESS
    : jne UNSUCCESS
    :
    : SUCCESS:
    : ; Prompt correct
    : mov ah,09h
    : mov dx,OFFSET same
    : int 21h
    : mov ax,4c00h
    : int 21h
    :
    : UNSUCCESS:
    : ; Prompt the input on the screen
    : mov ah,09h
    : mov dx,OFFSET notsame
    : int 21h
    : mov ax,4c00h
    : int 21h
    :
    : END
    : [/code]:
    :
  • havalhaval Member Posts: 2
    Thanks very much indeed. You have no idea how much time I have spent on it trying to solve it.

    Thanks once again
Sign In or Register to comment.