试图做组装不区分大小写和我的code不起作用 [英] Trying to do case insensitive search in assembly and my code doesn't work

查看:106
本文介绍了试图做组装不区分大小写和我的code不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有结构的每个元素的数组是一个数字,街道名称

 结构的房子
{
    INT编号;
    炭streetName [20];
}

我要在通过令牌搜索。这是我的code,我不知道为什么它不工作。请帮助!

  MOV EAX,0;零出结果
MOV ESI,清单;移动列表指针ESI
MOV EDI,令牌;移动令牌字符串的指针EDI
MOV EDX,0;复位EDX计数器
MOV ECX,0;复位ECX计数器
L1:
MOV EAX,[ESI + 4];阅读街头数到EAX
加ESI,4;移动指针4个字节开始读取街道名称
L2:
MOV人,字节PTR [ESI + ECX]; MOV街道名称的每个字符由数组人
MOV BL,字节PTR [EDI + ECX]; MOV搜索令牌的每个字符为BL
或人,20小时;转换人(不区分大小写)
或者BL,20H;转换BL(不区分大小写)
INC ECX; prepare下一个字符
CMP AL,BL; CMP A1和B1
JNE不同。跳转到不同的是否不同
CMP BL,0;检查BL达到串的结尾
JE完成的;跳如果所有比赛DONE
JMP L2;跳回L2检查下一个字符
不同:
加ESI,24;添加ESI 24字节的指针移动到结构数组的下一个项目
MOV ECX,0;重置计数器ECX
INC EDX; INC为结构数组的EDX计数器
CMP EDX,计数;检查它是否到达数组的尾部
JE NOT_FOUND;如果达到最终却一无所获然后JMP到未找到
JMP L1;跳回L1
未找到:
MOV EAX,0;设置EAX为0表示没有找到
完成:


解决方案

  L1:
MOV EAX,[ESI + 4];阅读街头数到EAX
加ESI,4;移动指针4个字节开始读取街道名称
L2:
MOV人,字节PTR [ESI + ECX]; MOV街道名称的每个字符由数组人

在您的code,这部分是没用的,读的街道的数的,因为你使用的AL事后处理的字符。

正因为如此,你有什么希望这个节目产生在字符串匹配吗?至少AL是0(街道号码通常是小数字?),你定义的EAX = 0作为信号未找到!

我提出以下EAX寄存器留下一个合理的值:

  L2:
MOV BH,字节PTR [ESI + ECX]; MOV街道名称的每个字符从Array波黑
MOV BL,字节PTR [EDI + ECX]; MOV搜索令牌的每个字符为BL
CMP BL,0;检查BL达到串的结尾
JE完成的;跳如果所有比赛DONE
或BX,2020h;在一次转换两个字符(不区分大小写)
INC ECX; prepare下一个字符
CMP BH,BL; CMP BH和BL
JE L2;跳回L2检查下一个字符
不同:

您只为的标记字符串的的终止零测试。但是,会发生什么,当的字符串数组的不具有相同的长度?当两个字符串的长度相同的程序才能进行。

I have an array of structures with each element is a number and street name

struct house
{
    int number;
    char streetName[20];
}

I want to search it with a token passed in. Here is my code, and I don't know why it does not work. Please help!

mov eax, 0   ; zero out the result
mov esi, list    ; move the list pointer to ESI
mov edi, token   ; move the pointer of token string to edi
mov edx, 0       ; reset edx counter
mov ecx, 0       ; reset ecx counter
L1:
mov eax, [esi+4] ; read number of street into eax
add esi, 4       ; move pointer 4 bytes to start reading street name
L2:
mov al, byte ptr[esi + ecx]; mov each char of street name from array to al
mov bl, byte ptr[edi + ecx]; mov each char of search token to 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 and bl
jne DIFFERENT    ; jump to DIFFERENT if different
cmp bl, 0        ; check if bl reaches to the end of the string
je done          ; jump if all match to done
jmp L2           ; jump back to L2 to check the next char
DIFFERENT:
add esi, 24      ; add esi 24 bytes to move the pointer to the next item of structure array
mov ecx, 0       ; reset the counter ecx
inc edx          ; inc the edx counter for structure array
cmp edx, count   ; check if it reaches the end of array
je not_found     ; if reaching the end but found nothing then jmp to not found
jmp L1           ; jump back to L1
not_found: 
mov eax, 0       ; set eax to 0 to indicate not found
done:

解决方案

L1:
mov eax, [esi+4] ; read number of street into eax
add esi, 4       ; move pointer 4 bytes to start reading street name
L2:
mov al, byte ptr[esi + ecx]; mov each char of street name from array to al

In this part of your code it is useless to read the number of street since you use AL afterwards to process the characters.

Because of this, what do you hope this program to produce when the strings match? At least AL would be 0 (street numbers are usually small numbers?) and you defined EAX=0 as the signal for not found!

I propose the following to leave a sensible value in the EAX register:

L2:
mov bh, byte ptr[esi + ecx]; mov each char of street name from array to bh
mov bl, byte ptr[edi + ecx]; mov each char of search token to bl
cmp bl, 0        ; check if bl reaches to the end of the string
je done          ; jump if all match to done
or bx, 2020h     ; convert both characters at once (case insensitive)
inc ecx          ; prepare next char
cmp bh, bl       ; cmp bh and bl
je L2            ; jump back to L2 to check the next char
DIFFERENT:

You only test for the terminating zero of the token string. But what happens when the array string does not have the same length? Your program can only work when both strings have the same length.

这篇关于试图做组装不区分大小写和我的code不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆