.section .data
string1:
.ascii "This is a test - a long text string to scan."
length:
.int 44
string2:
.ascii "-"
.section .text
.global _start
_start:
nop
leal string1, %edi
leal string2, %esi
movl length, %ecx
lodsb #将 "-" 加载到 AL
cld
repne scasb #从 string1 的末尾开始扫描,同时EDI递增
jne notfound
subw length, %cx #CX中的值为28
neg %cx
movl $1, %eax
movl %ecx, %ebx
int $0x80
notfound:
movl $1, %eax
movl $0, %ebx
int $0x80
$ ./scas
$ echo $?
16
.section .data
string1:
.ascii "This is a test - a long text string to scan."
length:
.int 11
string2:
.ascii "test"
.section .text
.global _start
_start:
nop
leal string1, %edi
leal string2, %esi
movl length, %ecx
lodsl #装test到EAX
cld
repne scasl
jne notfound
subw length, %cx
neg %cx
movl $1, %eax
movl %ecx, %ebx
int $0x80
notfound:
movl $1, %eax
movl $0, %ebx
int $0x80
$ ./scas2
$ echo $?
0
.section .data
string1:
.asciz "Testing, one, two, three, testing.\n"
.section .text
.global _start
_start:
nop
leal string1, %edi
movl $0xffff, %ecx #假设字符串的长度不超过0xffff个字符
movb $0, %al
cld
repne scasb
jne notfound
subw $0xffff, %cx
neg %cx
dec %cx #长度中包含了结尾的0所以这里要减1
movl $1, %eax
movl %ecx, %ebx
int $0x80
notfound:
movl $1, %eax
movl $0, %ebx
int $0x80
$ ./strsize
$ echo $?
35
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |