标签:
|
指令
|
描述
|
|
repe
|
等于时重复
|
|
repne
|
不等于时重复
|
|
repnz
|
不为零时重复
|
|
repz
|
为零时重复
|
#cmps.s
.section .data
val1:
.ascii "Hello as!"
val2:
.ascii "Hello wd!"
.section .text
.globl _start
_start:
nop
movl $1, %eax #system call SYS_exit()
leal val1, %esi
leal val2, %edi
movl $9, %ecx
cld
repe cmpsb
je equal
movl %ecx, %ebx
int $0x80
equal:
movl $0, %ebx
int $0x80
$ ./cmps $ echo $? 2
# scas.s
.section .data
string:
.asciz "this is a test string!\n"
.section .text
.globl _start
_start:
nop
leal string, %edi #将要用于查找的字符串的内存地址加载到edi寄存器中
movl $0xffff, %ecx #0xffff表明这个程序只能用于长度最大为65535的字符串
movb $0, %al #将要搜索的字符加载到al寄存器中
cld
repne scasb #使用repne指令扫描字符串,获得搜索位置
jne notfound #如果没找到,跳转到notfound分支
subw $0xffff, %cx #如果找到了,那么其距离字符串末尾的位置就存放在cx寄存器中,从cx寄存器的值中减去字符串的长度
neg %cx #使用neg指令改变结果的值的符号
dec %cx #因为该长度包含表示结尾的0,所以最终值必须减1才能显示字符串的真正长度。
movl $1, %eax
movl %ecx, %ebx #将计算结果存放在ebx寄存器中。
int $0x80
notfound:
movl $1, %eax
movl $0, %ebx
int $0x80
$ ./scas $ echo $? 23
标签:
原文地址:http://blog.csdn.net/shallnet/article/details/45625089