Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 如何在汇编中使用scasb查找字符串长度_Assembly_X86_Nasm_Strlen - Fatal编程技术网

Assembly 如何在汇编中使用scasb查找字符串长度

Assembly 如何在汇编中使用scasb查找字符串长度,assembly,x86,nasm,strlen,Assembly,X86,Nasm,Strlen,我有一根绳子,正在试着找出它的长度。我使用的是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

我有一根绳子,正在试着找出它的长度。我使用的是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
对于SCA,您应该将字符串的地址放在EDI中,而不是ESI中。而不是重复你想要重复而不是相等和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]
对于SCA,您应该将字符串的地址放在EDI中,而不是ESI中。而不是重复你想要重复而不是相等和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]

对于汇编时间常量字符串,汇编程序可以将长度计算为常量整数:

string1 db "how long is this string",0
len equ $-string1       ; len = current position - start of string
为len指定长度,包括0字节。如果仅对字符串使用显式长度操作(如写系统调用),或者至少使0不属于计数长度的一部分,则可能希望省略终止0字节

您可以将其用作立即常数:

mov edx, len

对于汇编时间常量字符串,汇编程序可以将长度计算为常量整数:

string1 db "how long is this string",0
len equ $-string1       ; len = current position - start of string
为len指定长度,包括0字节。如果仅对字符串使用显式长度操作(如写系统调用),或者至少使0不属于计数长度的一部分,则可能希望省略终止0字节

您可以将其用作立即常数:

mov edx, len