.section .data
value1:
.ascii "Test"
value2:
.ascii "Test"
.section .text
.global _start
_start:
nop
movl $1, %eax
leal value1, %esi
leal value2, %edi
cld
cmpsl
je equal
movl $1, %ebx
int $0x80
equal:
movl $0, %ebx
int $0x80
$ ./cmps
$ echo $?
0
.section .data
value1:
.ascii "This is a test of the CMPS instrunctions"
value2:
.ascii "This is a test of the CMPS instrunctions"
.section .text
.global _start
_start:
nop
movl $1, %eax
leal value1, %esi
leal value2, %edi
movl $39, %ecx
cld
repe cmpsb
je equal
movl %ecx, %ebx
int $0x80
equal:
movl $0, %ebx
int $0x80
.section .data
string1:
.ascii "test"
length1:
.int 4
string2:
.ascii "uaaa"
length2:
.int 4
.section .text
.global _start
_start:
nop
leal string1, %esi
leal string2, %edi
movl length1, %ecx
movl length2, %eax
cmpl %eax, %ecx #比较两个字符串的长度
ja longer #以短字符串的长度为标准(短字符串长度放在ecx中)
xchg %ecx, %eax
longer:
cld
repe cmpsb
je equal
jg greater
less:
movl $1, %eax
movl $255, %ebx #255是返回值,表示 string1 小于 string2
int $0x80
greater:
movl $1, %eax
movl $1, %ebx #1是返回值,表示 string1 大于 string2
int $0x80
equal: #短字符串中所有字符(按照顺序)是长字符串的子集
movl length1, %ecx #比较两个字符串的长度,长的则大,否则为小
movl length2, %eax
jg greater
jl less
movl $1, %eax
movl $0, %ebx #如果两个字符串完全相等则返回 0
int $0x80
$ ./strcom
$ echo $?
255
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |