Arrays x86程序集与以null结尾的数组进行比较

Arrays x86程序集与以null结尾的数组进行比较,arrays,assembly,x86,compare,Arrays,Assembly,X86,Compare,我正在汇编中处理一个函数,其中我需要计算以null结尾的数组中的字符数。我正在使用VisualStudio。该数组是用C++编写的,内存地址传递给了我的汇编函数。问题是我的循环在达到null(00)时并没有结束。我尝试过使用test和cmp,但似乎比较的是4个字节,而不是1个字节(字符大小) 我的代码: _arraySize PROC ;name of function start: ;ebx holds address of the

我正在汇编中处理一个函数,其中我需要计算以null结尾的数组中的字符数。我正在使用VisualStudio。该数组是用C++编写的,内存地址传递给了我的汇编函数。问题是我的循环在达到null(00)时并没有结束。我尝试过使用
test
cmp
,但似乎比较的是4个字节,而不是1个字节(字符大小)

我的代码:

_arraySize PROC              ;name of function

start:                  ;ebx holds address of the array
    push ebp            ;Save caller's frame pointer
    mov ebp, esp        ;establish this frame pointer
    xor eax, eax        ;eax = 0, array counter
    xor ecx, ecx        ;ecx = 0, offset counter

arrCount:                       ;Start of array counter loop

    ;test [ebx+eax], [ebx+eax]  ;array address + counter(char = 1 byte)
    mov ecx, [ebx + eax]        ;move element into ecx to be compared
    test ecx, ecx               ; will be zero when ecx = 0 (null)
    jz countDone
    inc eax                     ;Array Counter and offset counter
    jmp arrCount

countDone:

    pop ebp
    ret


_arraySize ENDP

如何仅比较1个字节?我只是想转移不需要的字节,但这似乎是在浪费指令。

如果要比较单个字节,请使用单个字节指令:

mov  cl, [ebx + eax]        ;move element to be compared
test  cl, cl                ; will be zero when NUL

(请注意,零字符是ASCII NUL,而不是ANSI NULL值。)

如果要比较单个字节,请使用单字节指令:

mov  cl, [ebx + eax]        ;move element to be compared
test  cl, cl                ; will be zero when NUL

(请注意,零字符是ASCII NUL,而不是ANSI NULL值。)

谢谢,这是一个非常简单的修复方法,我现在对汇编有了更好的理解。我不知道我只能指定寄存器的1字节,现在我想这很有意义。@soda:请通过向上投票并接受答案来感谢我。还不能向上投票,我没有足够的代表。刚刚了解了如何选择答案。谢谢,这么简单的修复,我现在对汇编有了更好的理解。我不知道我只能指定寄存器的1个字节,现在我想这很有意义。@soda:请通过向上投票并接受答案来感谢我。还不能向上投票,我没有足够的代表。刚刚了解如何选择答案。