作者NOtWorThy (天意不可微 可微则连续)
看板ASM
标题[问题] selection Sort
时间Wed May 6 22:26:44 2009
以下是我写的code
结果是有sort拉
不过有些值重复,有些值被盖掉
不知错在哪 烦请各位先进 指引一下
TITLE MASM Template (main.asm)
INCLUDE Irvine32.inc
.data
string BYTE 2, 3, 11, 16, 15, 55, 1, 4, 14, 38, 26, 8, 100, 29, 34, 19, 0, 11
str1 byte "Before sort : ", 0
str2 BYTE "After sort : ", 0
str3 BYTE " ", 0
temp1 dword ?
temp2 dword ?
temp3 dword ?
temp4 dword ?
min byte ?
index dword ?
.code
main PROC
mov edx, OFFSET str1
call writestring
call crlf
mov esi, OFFSET string
mov ecx, SIZEOF string
lp_1:
movzx eax, byte ptr [esi]
call writedec
mov edx, OFFSET str3
call writestring
inc esi
loop lp_1
call crlf
;----------------------------
; S O R T
;----------------------------
mov esi, OFFSET string
mov ecx, SIZEOF string
dec ecx
L1:
mov al, byte ptr[esi]
mov min, al
mov temp1, ecx
mov temp2, esi
mov temp3, esi
mov temp4, esi
;-------------------
L2:
inc esi
mov al, byte ptr[esi]
cmp al, min
jae LP
mov min, al
mov index, esi
LP:
loop L2
;-------------------
;----swap-----
mov esi, temp4
mov al, byte ptr[esi]
mov esi, index
mov byte ptr[esi], al
mov esi, temp3
mov al, min
mov byte ptr[esi], al
;---end swap---
mov esi, temp2
inc esi
mov ecx, temp1
loop L1
mov esi, OFFSET string
mov ecx, SIZEOF string
lp_2:
movzx eax, byte ptr [esi]
call writedec
mov edx, OFFSET str3
call writestring
inc esi
loop lp_2
call crlf
ENDD:
exit
main ENDP
END main
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.91.18
1F:→ NOtWorThy:已解 05/08 16:04