作者zha0 (zha0)
站内ASM
标题Re: [问题] 泡沫排序法
时间Wed Oct 31 10:12:57 2007
※ 引述《dream3325 (忧郁蓝调)》之铭言:
: 可以请教各位
: 如何用组合语言写出泡沫排序法吗
: 如果可以的话 希望能顺便附上注解让我更了解 XD
: 感谢大家
以前二专写的 PO 出来给高手笑笑 XD
注解靠你了 XDXD
.model tiny
.data
array dw 3333h, 1111h, 2222h, 1111h, 4444h
len dw $-array-1
.code
org 100h
start:
mov cx, len ; cx = len
mov si, offset array ; si = n
mov di, si ; di = n+1
one:
push cx
mov bx, [si]
two:
inc di
inc di
cmp bx, [di]
jle next
xchg bx, [di]
mov [si], bx
next:
loop two
pop cx
inc si ; si = n + 1
inc si
mov di, si ; di = n + 2
; inc di
; inc di
loop one
int 20h
end start
过了不知多久後,在一个 vxer 的网站上,也看到他有写一个,
看来在碰 vx 的写法都一样 XD
;
; BUBBE SORT
; PARAMETER 1. THE ADDRESS OF NUMBER ARRAY
; 2. THE LENGTH OF SORTING ARRAY
;
code segment
assume cs:code,ds:code,es:code
org 100h
begin proc far
push bp
mov sp, bp
mov di, [bp+8] ; the number array's data address
mov si, [bp+6] ; the first number's data address
; the # of sorting address.
mov cx, [si] ; cx = the number of sorting.
dec cx
mov ax, di
inc ax
inc ax
mov si,ax ; the second number's data address
mov ax, ds ; es = ds
mov es,ax
one:
push cx
mov bx, word ptr es:[di] ; bx = first number.
two:
cmp bx, word ptr ds:[si] ; compare the first and second number.
jle ok ; if first <= second , goto ok
xchg bx, word ptr ds:[si] ; else, exchange two data
mov word ptr es:[di], bx ; move back to it's address
ok:
inc si
inc si ; next number
loop two
pop cx ; sort one data ok!
inc di
inc di
mov ax, 2
add ax, di
mov si, ax
loop one
pop bp
ret 4
begin endp
code ends
end begin
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.68.29.67
※ 编辑: zha0 来自: 210.68.29.67 (10/31 10:14)
1F:推 fmdjyl:什麽是泡沫排序法呢? 11/03 19:47
2F:→ rockyup:bubble sort!? 11/04 11:20