2017-04-08 88 views
0

我有一個字符串,我試圖找出它的長度。我正在使用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 lenght of string is 50 
    mov ebx,ecx 
    cld 
    repe scasb 
    sub ebx, ecx 
    mov eax,ebx 
    call WriteUInt8 

    ret 

回答

1

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]