汇编——冒泡排序

;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

你可能感兴趣的:(汇编——冒泡排序)