# An example of comparing strings (字符串的不等和相等比较)
#
# 最常用于比较字符串的方法称为词典式顺序(lexicographical order)。这通常被称为字典顺序(dictionary order)。
#
# 比较长度不同的两个字符串时,按照长度短一些的字符串中的字符数里进行比较。
# 如果短字符串大于长字符串中相同数量的字符,那么短字符串就大于长字符串。
# 如果短字符串小于长字符串中相同数量的字符,那么短字符串就小于长字符串。
# 如果短字符串等于长字符串中相同数量的字符,那么长字符串就大于短字符串。
#
# 例:
# "test" 大于 "boomerang"
# "test" 小于 "velocity"
# "test" 小于 "test1"
#
.section .data
string1:
.ascii "test"
length1:
.int 4
string2:
.ascii "test1"
length2:
.int 5
.section .text
.globl main
main:
nop
leal string1, %esi
leal string2, %edi
movl length1, %ecx
movl length2, %eax
cmpl %eax, %ecx
ja longer
xchg %ecx, %eax
longer:
cld
repe cmpsb
je equal
jg greater
less:
movl $1, %eax
movl $255, %ebx
int $0x80
greater:
movl $1, %eax
movl $1, %ebx
int $0x80
equal:
movl length1, %ecx
movl length2, %eax
cmpl %ecx, %eax
jg greater
jl less
movl $1, %eax
movl $0, %ebx
int $0x80
# gcc -g -o 12 12-cmps.s -m32
# echo $?
# 255
#