When comparing two strings of different lengths, the comparison is based on the number of characters in the shorter string.
Using this rule, the following examples would be true:
❑ “test” is greater than “boomerang”
❑ “test” is less than “velocity”
1:If the shorter string would be greater than the same number of characters in the longer string, then the shorter string is greater than the longer string.
2:If the shorter string would be less than the same number of characters in the longer string, then the shorter string would be less than the longer string.
:3:If the shorter string is equal to the same number of characters in the longer string, the longer string is greater than the shorter string.
Using this rule, the following examples would be true:
❑ “test” is greater than “boomerang”
❑ “test” is less than “velocity”
❑ “test” is less than “test1”
.section .data
string1:
.ascii “test”
length1:
.int 4
string2:
.ascii “test1”
length2:
.int 5
.section .text
.globl _start
_start:
nop
lea string1, %esi
lea 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