汇编——冒泡排序

;zxy03.asm 冒泡排序

    include io32.inc
    .data

arr dword 4, 1, 2, 5, 8, 7, 3
msg byte ' ', 0
haha byte 'lala', 0
count dword lengthof arr + 1
tmp dword 1
    .code
start:
    mov eax, lengthof arr
    
    mov ecx, eax
    xor ebx, ebx
    xor edx, edx
again1:
    mov ecx, lengthof arr - 1
    xor ebx, ebx
    again:
        mov eax, arr[ebx*4]
        inc ebx
        cmp eax, arr[ebx*4]
        
        js chg
        mov eax, arr[ebx*4]     ;arr[1]
        mov tmp, eax            ;tmp = arr[1]
        dec ebx                 ; ebx = 0
        mov eax, arr[ebx*4]     ; eax = arr[0]
        inc ebx                 ; ebx = 1
        mov arr[ebx*4], eax     ; arr[1] = eax
        mov eax, tmp            ; eax = arr[1]

        dec ebx
        mov arr[ebx*4], eax
        inc ebx
        
        chg:
        dec ecx
        jz over1
        jmp again
    over1:
    dec count
    jz over
    jmp again1

over:
mov ecx, lengthof arr
    xor ebx, ebx
    
    again2:
    mov eax, arr[ebx*4]
    inc ebx
    call dispsid
    
    mov eax, offset msg
    call dispmsg
    loop again2     
    
    exit 0
end start

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值