冒泡排序实现数字升序排序

data segment
    table db 'HGFEDCBA'
    sign db 0
    new db 8 dup(0),'$'
    how dw 0
data ends
code segment
    assume cs:code,ds:data
start:
    mov ax,data
    mov ds,ax
    mov cx,sign-table
    mov how,cx
    dec cx
loop1:
    push cx
    mov bx,0
loop2:
    mov al,table[bx]
    cmp al,table[bx+1]
    jle next
    xchg al,table[bx+1]
    mov table[bx],al
next:
    add bx,1
    loop loop2
    pop cx
    loop loop1    
    mov bx,0
    mov cx,how
    jnz out1
chuan:
    mov al,table[bx]
    mov new[bx],al
    inc bx
out1:
    loop chuan
    lea dx,new
    mov ah,9
    int 21h
    mov ah,4ch
    int 21h
code ends
end start

你可能感兴趣的:(汇编语言)