汇编语言 SCAS 指令
SCAS 指令用于搜索字符串中的特定字符或一组字符。要搜索的数据项应该在 AL(对于 SCASB),AX(对于 SCASW)或 EAX(对于 SCASD)寄存器中。要搜索的字符串应在内存中,并由 ES:DI(或 EDI)寄存器指向。
参考以下实例来了解概念:
section .textglobal _start ;must be declared for using gcc_start: ;tell linker entry pointmov ecx,lenmov edi,my_stringmov al , 'e'cldrepne scasbje found ; when found; If not not then the following codemov eax,4mov ebx,1mov ecx,msg_notfoundmov edx,len_notfoundint 80hjmp exitfound:mov eax,4mov ebx,1mov ecx,msg_foundmov edx,len_foundint 80hexit:mov eax,1mov ebx,0int 80hsection .datamy_string db 'hello world', 0len equ $-my_stringmsg_found db 'found!', 0xalen_found equ $-msg_foundmsg_notfound db 'not found!'len_notfound equ $-msg_notfound
结果如下:
found!