Re: [問題] 泡沫排序法
※ 引述《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)
推
11/03 19:47, , 1F
11/03 19:47, 1F
→
11/04 11:20, , 2F
11/04 11:20, 2F
討論串 (同標題文章)
ASM 近期熱門文章
PTT數位生活區 即時熱門文章