[問題] selection Sort

看板ASM (組合語言)作者 (天意不可微 可微則連續)時間15年前 (2009/05/06 22:26), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
以下是我寫的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
文章代碼(AID): #1A0Pub3U (ASM)
文章代碼(AID): #1A0Pub3U (ASM)