assume cs:code,ds:data
data segment
dw 12,3,56,58,6,32,20,5
s_s dw 16 dup (0)
data ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,0b800h
mov es,ax
mov bx,0
mov si,0
mov di,0
;-------------------寄存器初始化
call dtoc
call show_str
;-------------------显示未排序字符
mov cx,7
p_p: call paixu
loop p_p
;--------------------排序完成
call dtoc
mov di,160
call show_str
;--------------------显示已排序字符
mov ah,01
int 21h
;========================Show_str显示字符↓========================
show_str:
push si
push di
push bx
;---------------------保存寄存器数据
mov bx,offset s_s
s_l: mov al,ds:[bx]
cmp al,0
je s_esc
mov es:[di],al
inc di
mov es:[di],2
inc di
inc bx
jmp s_l
s_esc: pop bx
pop di
pop si
ret
;=========================DToC字符换ASCII↓===========================
dtoc: ;把DATA数据中的8WROD数据转成
;字符,一次一个,循环8次
;写到要要s_s空间中,以0结尾
push bx
push cx
push si
push di
push bp
mov bx,10
;---------------------除数
xor di,di ;0
xor bp,bp
mov cx,8
mov bp,offset s_s
d_zxh: mov ax,ds:[si]
;---------------------主循环
push cx
xor dx,dx
d_xh: div bx
;cmp al,0
;je d_esc
add dx,30h
inc di
push dx
xor dx,dx
cmp al,0
jne d_xh
d_esc:
mov cx,di
d_cz: pop ax
mov ds:[bp],ax
add bp,1
loop d_cz
mov byte ptr ds:[bp],3
add bp,1
xor di,di
pop cx
add si,2
loop d_zxh
pop bp
pop di
pop si
pop cx
pop bx
ret
;=========================PAIXU排序↓=============================
paixu:
push si
push cx
mov cx,7
xh:
mov ax,ds:[si]
mov dx,ds:[si]2
cmp ax,dx
ja p_jh
jmp p_esc
p_jh: mov ds:[si]2,ax
mov ds:[si],dx
p_esc:
add si,2
loop xh
pop cx
pop si
ret ;
code ends
end start
纯手写的哦~~