Assembly-programming-assembly-scas-instruction

提供:Dev Guides
移動先:案内検索

アセンブリ-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!