SCAS指令用於搜索一個特定的字元或字串中的字元集。要搜索的資料項目應該是在AL,AX(SCASW)或EAX寄存器(SCASD)的(SCASB)。被搜索的字串應該是在內存中,並指出由ES:DI(或EDI)寄存器。
看看下麵的程式的概念來理解:
section .text global _start ;must be declared for using gcc _start: ;tell linker entry zaixian mov ecx,len mov edi,my_string mov al , 'e' cld repne scasb je found ; when found ; If not not then the following code mov eax,4 mov ebx,1 mov ecx,msg_notfound mov edx,len_notfound int 80h jmp exit found: mov eax,4 mov ebx,1 mov ecx,msg_found mov edx,len_found int 80h exit: mov eax,1 mov ebx,0 int 80h section .data my_string db 'hello world', 0 len equ $-my_string msg_found db 'found!', 0xa len_found equ $-msg_found msg_notfound db 'not found!' len_notfound equ $-msg_notfound
上面的代碼編譯和執行時,它會產生以下結果:
found!
上一篇:
Assembly彙編 CMPS指令
下一篇:
Assembly彙編 數組