[問題] selection Sort
以下是我寫的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
→
05/08 16:04, , 1F
05/08 16:04, 1F
ASM 近期熱門文章
PTT數位生活區 即時熱門文章