| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 656 人关注过本帖
标题:汇编 选择排序
只看楼主 加入收藏
xiaoxun_1122
Rank: 1
来 自:地球
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-18
结帖率:50%
收藏
已结贴  问题点数:6 回复次数:1 
汇编 选择排序
程序代码:
;有一个首地址为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
求教 为什么会错误
2010-12-28 14:29
xiaomarn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:348
专家分:2026
注 册:2009-3-18
收藏
得分:6 
程序代码:
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,offset mess1-offset a
    mov dl,2
    div dl
    cbw
    xor ah,ah
    mov cx,ax
   

    mov si,0
loop1:
    mov di,cx
  

    push si
    mov bx,si
    dec cx
    or cx,cx
    jz ze
loop2:
    mov ax,a[si+2] 

    cmp ax,a[bx]
    jb continue
    lea bx,[si+2]
continue:
    add si,2
    loop loop2
   

    pop si
    mov ax,a[si]
    xchg ax,a[bx]
    mov a[si],ax
ze:
    mov dx,a[si]
    call dishex
    ;dec di
    mov cx,di
    inc si
    inc si
    loop loop1
   

    MOV AH,4CH
    INT 21H
   

dishex proc near
    push cx
    mov cx,0404h
print:
    rol dx,cl
    push dx
    and dl,0fh
    cmp dl,0ah
    jb next
    add dl,7
next:
    add dl,30h
    mov ah,2
    int 21h
    pop dx
    dec ch
    jnz print
    mov dl,' '
    mov ah,2
    int 21h
    pop cx
    ret
dishex endp
CODES ENDS
    END START

2010-12-29 10:42
快速回复:汇编 选择排序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016827 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved