2011-12-11 194 views
0

我与一些AT & T汇编语法问题所困扰。不区分大小写字符串匹配

进出口使用在Linux x86 “视” 的编译器。

林做一个密码程序,但它必须是不区分大小写。澄清一下,无论任何特定角色的情况如何,它都应评估真实。

我有正常的评估程序正常工作,我有它设置为通过字符串进行迭代。

#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 

这是部分IM着,我无法弄清楚如何真正转换的情况下的字符挣扎。我知道我需要添加或减去32,但有些不对。任何意见或建议都会非常有帮助。谢谢。

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

这是coverting的情况下的部分,我已经试过addsubandor,我只是无法得到它的工作。这并不是必然的,我意识到jz SkipCase

的比较例程在很大程度上是基于对关在这里另外一个问题,我会如果nessessary链接。

道歉布局和过度的哈希值,坏的评论风格,我知道。

+0

你的问题的标题是有点误导,因为你的问题显然不是语法 – hirschhornsalz

+0

的问题是,我不知道什么语法使用。我认为程序的逻辑很好,我只需要澄清哪些代码在哪里使用。 – TheoVate

+0

嗯,我会建议使用_cmp_代替_sub_甚至_xor_。它具有不改变操作数的优点(像sub一样)。对于从小写到大写的转换,我建议'sub $ 20h'而不是'xor $ 20h',除非你想混淆你的代码。但是,这一切与AT&T语法无关。 – hirschhornsalz

回答

1

我看到你第一次尝试将角色“严格”匹配,并且当你失败时继续进行区分大小写的匹配。

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 

希望帮助,我觉得真的很难在很短的帖子是这样解释的位操作。 :)


另外,我想这是任何家庭作业或某种锻炼; Tibial,因为一个真正的密码程序就必须更聪明 - 例如只对字母,数字或其他字符执行不区分大小写的检查。

+0

非常感谢你,这完美地工作,确切地说我正在寻找。是的,而不是它是一个可用的产品,它更多的是为了展示组装的使用。我想如果我能厚脸皮和要求你有一个快速浏览一下这其中也http://stackoverflow.com/questions/8182165/att-assembly-masked-input涉及我AT&T之间的差异之间遇到问题英特尔汇编。感谢您的完美回复。 – TheoVate

+0

@TheoVate遗憾的是,其他问题似乎与DOS系统调用,我不知道任何有关 – Martin

相关问题