- 彙編教程
- 彙編 - 首頁
- 彙編 - 簡介
- 彙編 - 環境設定
- 彙編 - 基本語法
- 彙編 - 記憶體片段
- 彙編 - 暫存器
- 彙編 - 系統呼叫
- 彙編 - 定址模式
- 彙編 - 變數
- 彙編 - 常量
- 彙編 - 算術指令
- 彙編 - 邏輯指令
- 彙編 - 條件
- 彙編 - 迴圈
- 彙編 - 數字
- 彙編 - 字串
- 彙編 - 陣列
- 彙編 - 過程
- 彙編 - 遞迴
- 彙編 - 宏
- 彙編 - 檔案管理
- 彙編 - 記憶體管理
- 彙編有用的資源
- 彙編 - 快速指南
- 彙編 - 有用的資源
- 彙編 - 討論
彙編 - 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!
assembly_strings.htm
廣告