【发布时间】:2023-03-15 13:40:01
【问题描述】:
我正在编写一个程序集函数,我需要计算一个以空字符结尾的数组中的字符。我正在使用视觉工作室。该数组是用 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 个字节?我只是想转移我不需要的字节,但这似乎是在浪费一条指令。
【问题讨论】:
标签: arrays assembly x86 compare