在寄存器中迭代字符串

时间:2014-11-08 09:56:50

标签: assembly

我在ebx寄存器中有一个字符串,我想迭代它的字节。我是集会的新手,如果这个概念有效,我想要。

#string is in ebx
movl (%ebx), %edi #put the adresse of the string to %edi
jmp looper

looper:

    cmpl $0, %edi             # check if byte at edi is 0 (it's a c conform string so 0 is the terminator)
    je exit 

    addl $8, %edi                # load next value, increment the edi by 8 to move it to the next byte of the string 
    jmp looper            # jump to loop beginning

1 个答案:

答案 0 :(得分:0)

如果字符串实际包含在EBX寄存器中,则无法计算地址。

如果字符串由EBX寄存器中的值指向,则

movl (%ebx), %edi #put the adresse of the string to %edi  

需要movl %ebx,%edi

代码cmpl $0, %edi不会检查EDI中的字节,而是测试EDI本身是否为零。更好地使用cmpb $0,(%edi)

为什么在检查字节时会向EDI寄存器添加8?