views:

44

answers:

1

Hi all,

We are trying to implement levensteing distance algorithm in assembly and calling the assembly function from C code. But we have some char comparison problem and could not solve the problem.

Function takes two char* parameters. In the first two lines i mov the these addressess to ecx and edx. iminusOne and jminusOne are indexes to get the current(the code block is a part of loop) chars.After finding the addres of the characters i mov the characters into registers and compare them using cmp. But for example when i compare the two string "apple" and "apple" the first three character seemed to be equal but other two not. I print to the console the chars at the addresses hold by ecx and edx, they also seemed to be equal.

  mov ecx,[esp+4]
  mov edx,[esp+8]

  mov ebx,[iminusOne]
  add ecx,ebx
  mov ebx,[jminusOne]      
  add edx,ebx
  call printCurrentChars
  mov edx,[edx]; bellekteki veriyi direk register a yüklüyoruz çünkü karşılaştırma 
       ; işlemine parametre olarak iki adres alanı veremiyoruz
  mov ecx,[ecx]
  cmp edx,ecx
  jne notEqual
  call printHello
  mov ebx,eax

Print Result of Current Chars:

appleapple
aa
Hello, world! //OK
ap
ap
al
ae
pa
pp
Hello, world! //OK
pp
// this should be equal but not
pl
pe
pa
pp
// this should be equal but not
pp
Hello, world!
pl
pe
la
lp
lp
ll
// this should be equal but not
le
ea
ep
ep
el
ee
// this should be equal but not

+3  A: 
mov edx,[edx]
mov ecx,[ecx]
cmp edx,ecx

I think you're comparing dwords instead of bytes.

Try

mov dh, byte ptr [edx]
mov ch, byte ptr [ecx]
cmp dh, ch
Nick D
we used cl and dl thanks
mehmet6parmak