Page 1 of 1

Compare Strings in NASM

Posted: Sun Apr 20, 2003 3:41 pm
by Paeron
I wonder if anyone knows a good routine for comparing two Strings in NASM. I'd like it to take two strings and then return true or false to ax. It would help me alot!

Re:Compare Strings in NASM

Posted: Sun Apr 20, 2003 4:16 pm
by df
you'll have to write a string compare routine.

Re:Compare Strings in NASM

Posted: Mon Apr 21, 2003 4:57 am
by distantvoices
may be something like this?
int strcmp(char *string1,char *string2,int length);

in nasm:

[global strcmp]
strcmp:
push ebp
mov ebp,esp
mov esi,[ebp+8] ->string1
mov edi,[ebp+12] ->string2
mov ebx,[ebp+16] ->length
mov eax,0
compare:
cmp esi,edi
jne not_equal
inc esi ->increment
inc edi ->each adress by a byte
sub ebx,1 ->and length decrement by one
jnz compare
not_equal:
mov eax,-1
end:
pop ebp
retn

This function lack some IMPORTANT things, mark this! It is just a rough sketch of how such a thing can be written. I won't chew it for you. Okej?

Re:Compare Strings in NASM

Posted: Sun May 18, 2003 9:29 am
by Mr_Spam
the way i do is in nasm:

mov esi, (address of string1)
mov edi, (address of string2)
mov ecx, (lenth of shortest string + 1[for null]) ;rep needs the lenth of strings to test
rep cmpsb ;compare strings
je true ;excute what u want if its true
;execute what u want if its false