+ -
当前位置:首页 → 问答吧 → 汇编 选择排序

汇编 选择排序

时间:2010-12-28

来源:互联网

Assembly code
;有一个首地址为A的N字无序数组,编制程序采用选择排序法使该数组中的数按照从大到小的次序排序输出
DATAS SEGMENT
a dw 1,7,2,9,4,8,7,6,3
mess1 db 'the array preinstalled is:12,7,22,19,14,48,37,33,66,31$'
mess2 db 0ah,0dh,'Already sorted array is:','$'
DATAS ENDS
CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS
START:
    MOV AX,DATAS
    MOV DS,AX
    lea dx,mess1
    mov ah,09h
    int 21h
    lea dx,mess2
    mov ah,09h
    int 21h
    mov ax,mess1-a
    mov dl,2
    div dl
    cbw
    xor ah,ah
    mov cx,ax
    mov si,0
loop1:
    mov di,cx
    inc si
    sub si,1
    push si
    mov bx,si
loop2:
    mov ax,a[si+2]   
    cmp ax,a[bx]
    jb continue
    add si,2
    mov bx,si
continue:
    add si,2
    loop loop2    
    pop si
    mov ax,a[si]
    xchg ax,a[bx]
    mov a[si],ax
    mov dx,a[si]
    add dx,30h
    mov ah,02h
    int 21h
    sub di,1
    mov cx,di
    add si,2
    loop loop1
    MOV AH,4CH
    INT 21H
CODES ENDS
    END START



求教 为什么会错误

作者: Nicolealan   发布时间: 2010-12-28

楼主,请看这个贴子
http://topic.csdn.net/u/20101226/23/da6bb313-3e38-47e0-abc6-111ad0ab9cbd.html?62753

作者: abgood   发布时间: 2010-12-28

热门下载

更多