好友
阅读权限10
听众
最后登录1970-1-1
|
汇编的冒泡排序
冒泡排序是一个程序员所必须写的程序
代码:
data segment
array dw 0001h,0002h,0003h,0005h,0000h
count equ ($-array)/2
table dw count dup(?)
flag db 0
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov es,ax
lea si,array
lea di,table
mov cx,count
rep movsw
mov bx,offset table
mov cx,count
call display
l3:
mov cx,count
lea si,array
sub cx,1
mov flag,0
l0:
mov bx,[si]
cmp bx,[si+2]
jnc l2
mov dx,[si]
mov di,[si+2]
mov [si],di
mov [si+2],dx
mov flag,1
l2:
add si,2
loop l0
cmp flag,1
jnc l3
mov bx,offset array
mov cx,count
call display
mov ah,4ch
int 21h
display proc
ll:
mov dl,' '
mov ah,2
int 21h
mov si,[bx]
mov dx,si
mov dl,dh
shr dl,1
shr dl,1
shr dl,1
shr dl,1
add dl,30h
cmp dl,3ah
jc l31
add dl,07h
l31:
mov ah,2
int 21h
mov dl,dh
and dl,0fh
add dl,30h
cmp dl,3ah
jc l4
add dl,07h
l4:
mov ah,2
int 21h
mov dx,si
shr dl,1
shr dl,1
shr dl,1
shr dl,1
add dl,30h
cmp dl,3ah
jc l5
add dl,07h
l5:
mov ah,2
int 21h
mov dx,si
and dl,0fh
add dl,30h
cmp dl,3ah
jc l6
add dl,07h
l6:
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
add bx,2
loop ll
ret
display endp
code ends
end start |
|