目录

SCAS

SCAS指令用于搜索字符串中的特定字符或字符集。 要搜索的数据项应在AL(对于SCASB),AX(对于SCASW)或EAX(对于SCASD)寄存器中。 要搜索的字符串应该在内存中,并由ES:DI(或EDI)寄存器指向。

看下面的程序来理解这个概念 -

section .text
   global _start        ;must be declared for using gcc
_start:	                ;tell linker entry point
   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!
↑回到顶部↑
WIKI教程 @2018