Assembly 不区分大小写的字符串匹配

Assembly 不区分大小写的字符串匹配,assembly,x86,Assembly,X86,我正在努力解决一些AT&T汇编语法的问题 我在linux x86上使用“as”编译器 我正在制作一个密码程序,但它需要不区分大小写。为了澄清,无论给定字符的情况如何,它都应该计算true 我让正常的评估过程正常工作,并将其设置为遍历字符串 #Comparison Routine movl $Password, %ebx #Move the entire hardcoded password into ebx movl $buffer_data, %edx #Move

我正在努力解决一些AT&T汇编语法的问题

我在linux x86上使用“as”编译器

我正在制作一个密码程序,但它需要不区分大小写。为了澄清,无论给定字符的情况如何,它都应该计算true

我让正常的评估过程正常工作,并将其设置为遍历字符串

#Comparison Routine

    movl $Password, %ebx     #Move the entire hardcoded password into ebx
    movl $buffer_data, %edx  #Move the entire input password into edx
    movl $Password_len, %ecx #Move the length of the input password into ecx

0:  
    movb (%ebx), %al         #Move one byte of the hardcoded password into al
    xorb (%edx), %al         #Compare one byte of the input password to one byte of the hardedcoded
    jz SkipCase              #If they match, jump to SkipCase

##### 

    andb $32, %al   # 
    xorb (%edx), %al

    jz SkipCase
    jnz IncorrectOutput #   

SkipCase:
    inc %ebx                #Iterate through the
    inc %edx                #strings and decrease
    dec %ecx                #the length variable
    jnz 0b                  #if we're not finished, continue
    jmp CorrectOutput       #If all is good, goto CorrectOutput
这是我正在努力解决的部分,我不知道如何在大小写之间转换字符。我知道我需要加上或减去32,但有点不对劲。任何意见或建议都会很有帮助。谢谢

andb $32, %al   # 
xorb (%edx), %al
这是隐藏案例的部分,我尝试了
add
sub
以及
,但我无法让它工作。我意识到这之后的
jz SkipCase
不是必须的

比较程序很大程度上是基于这里的另一个问题,如果必要的话,我将链接这个问题


对于布局和过多的散列、糟糕的评论风格,我深表歉意。

我看到您首先尝试“严格”匹配字符,如果失败,则继续进行不区分大小写的匹配

andb $32, %al     # this 'and' operation only leaves the $32 bit if it is 
                  # present in al, all other bits are set to 0

# al is now either 0 (for a lower case character)
# or $32 (for an upper case character)

xorb (%edx), %al  # so this operation will become zero if the upper case 
                  # bit ($32) is set in the hardcoded password character
相反,您需要做的是这样的事情:

xorb $32, %al     # invert case of the character by toggling the upper case bit
cmp (%edx), %al   # try to match again
je SkipCase
希望这能有所帮助,我发现在这样一篇短文中解释位操作真的很困难。:)



此外,我认为这可能是家庭作业或某种练习,因为真正的密码例程必须更聪明-例如,只对字母、数字或其他字符执行不区分大小写的检查。

您问题的标题有些误导,因为你的问题显然不是语法问题,问题是我不知道该用什么语法。我认为程序的逻辑很好,我只需要澄清在哪里使用什么代码。我建议使用cmp而不是sub甚至xor。它的优点是不改变操作数(就像sub那样)。对于从小写到大写的转换,我建议使用
sub$20h
而不是
xor$20h
,除非您想混淆代码。但所有这些都与AT&T的语法无关。非常感谢,这完全符合我的要求。是的,与其说它是一个可用的产品,不如说它是为了演示组装的使用。我不知道我是否可以厚颜无耻地请你快速看一下这一点,这也涉及到我在at&T和英特尔汇编之间的差异中遇到的一个问题。谢谢您的完美回复。@TheoVate很抱歉,其他问题似乎与DOS系统调用有关,我对此一无所知