冒泡排序(汇编语言)

来源:百度知道 编辑:UC知道 时间:2024/06/02 04:19:19
请用冒泡方法对以BUFFER变量中存放的10个字节的数据进行排序。可在大数向上冒和向下沉中任选一种。变量定义如下
BUFFER DB 9,11,2,7,21,13,2,0,14,3

DSEG SEGMENT
n equ 10
BUFFER DB 9,11,2,7,21,13,2,0,14,3
DSEG ENDS
CSEG SEGMENT
assume cs:CSEG, ds:DSEG
MAIN PROC FAR ;主程序入口
mov ax, dseg
mov ds, ax
mov cx,n
dec cx
loop1: mov di,cx
mov bx,0
loop2: mov al,buffer[bx]
cmp al,buffer[bx+1]
jge continue
xchg al,buffer[bx+1]
mov buffer[bx],al
continue: add bx,1
loop loop2
mov cx,di
loop loop1
mov ah,1;按任意键退出
int 21h
mov ax, 4c00h ;程序结束,返回到操作系统系统
int 21h
MAIN ENDP
CSEG ENDS
END MAIN

; 冒泡法排序
Code Segment
Assume CS:Code,DS:Code
; -----------------------------------------
; 定义常量
Yes EQU 1
No EQU 0
On EQU 1
Off EQU 0
; -----------------------------------------
; 定义结构类型
Bubb_Para Struc ; 冒泡排序法参数表
Carry DB No ; 是否带符号。Yes:有符号数;No:无符号数
Sort DB No ; 升序/降序。Yes:升序;No:降序
Yes_No DB 73h,76h,7dh,7eh