我有一个字符串,正在尝试找出它的长度。我正在使用 rw32-2017。我尝试使用 repe scasb
扫描字符串,但它根本没有改变 ZF。
有没有更简单的方法来查找字符串的长度?
我的程序:
%include "rw32-2017.inc"
section .data
; write your data here
string1 db "how long is this string",0
section .text
main:
mov ebp, esp
; write your code here
mov esi,string1
mov eax,0
mov ecx,50 ;max length of string is 50
mov ebx,ecx
cld
repe scasb
sub ebx, ecx
mov eax,ebx
call WriteUInt8
ret
最佳答案
对于 SCAS
,您应该将字符串的地址放在 EDI
中,而不是 ESI
。而不是 REPE
你想要 REPNE
(当不等于和 ecx!=0 时重复)。
mov edi,string1
mov eax,0
mov ecx,50 ;max lenght of string is 50
mov ebx,ecx
cld
repne scasb ; find AL (0), starting at [ES:EDI]
关于assembly - 如何在 Assembly 中使用 scasb 查找字符串长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43292525/