x86 - Trying to do case insensitive search in assembly and my code doesn't work -
i have array of structures each element number , street name
struct house { int number; char streetname[20]; }
i want search token passed in. here code, , don't know why not work. please help!
mov eax, 0 ; 0 out result mov esi, list ; move list pointer esi mov edi, token ; move pointer of token string edi mov edx, 0 ; reset edx counter mov ecx, 0 ; reset ecx counter l1: mov eax, [esi+4] ; read number of street eax add esi, 4 ; move pointer 4 bytes start reading street name l2: mov al, byte ptr[esi + ecx]; mov each char of street name array al mov bl, byte ptr[edi + ecx]; mov each char of search token bl or al, 20h ; convert al (case insensitive) or bl, 20h ; convert bl (case insensitive) inc ecx ; prepare next char cmp al, bl ; cmp al , bl jne different ; jump different if different cmp bl, 0 ; check if bl reaches end of string je done ; jump if match done jmp l2 ; jump l2 check next char different: add esi, 24 ; add esi 24 bytes move pointer next item of structure array mov ecx, 0 ; reset counter ecx inc edx ; inc edx counter structure array cmp edx, count ; check if reaches end of array je not_found ; if reaching end found nothing jmp not found jmp l1 ; jump l1 not_found: mov eax, 0 ; set eax 0 indicate not found done:
l1: mov eax, [esi+4] ; read number of street eax add esi, 4 ; move pointer 4 bytes start reading street name l2: mov al, byte ptr[esi + ecx]; mov each char of street name array al
in part of code useless read number of street since use al afterwards process characters.
because of this, hope program produce when strings match? @ least al 0 (street numbers small numbers?) , defined eax=0 signal not found!
i propose following leave sensible value in eax register:
l2: mov bh, byte ptr[esi + ecx]; mov each char of street name array bh mov bl, byte ptr[edi + ecx]; mov each char of search token bl cmp bl, 0 ; check if bl reaches end of string je done ; jump if match done or bx, 2020h ; convert both characters @ once (case insensitive) inc ecx ; prepare next char cmp bh, bl ; cmp bh , bl je l2 ; jump l2 check next char different:
you test terminating 0 of token string. happens when array string not have same length? program can work when both strings have same length.
Comments
Post a Comment