Intel汇编-字符串的不等和相等比较

# 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
#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值