泡沫排序(bubble sort)使用組合語言

最近剛好有朋友在寫這個,所以我就幫忙寫了一下….

使用的組譯器是MASM 6.15版本的

 

INCLUDE Irvine32.inc
.data
inte DWORD 100 DUP(0)
count DWORD 0
msg1 BYTE “輸入要sort幾個數字:”,0
msg2 BYTE “輸入sort數字:”,0ah

 

.code
main PROC
mov edx,OFFSET msg1
call WriteString
call ReadInt
mov ebx,eax

 

mov edx,OFFSET msg2
call WriteString
mov edi,OFFSET inte
mov ecx,ebx
L1:
call ReadInt
mov [edi],eax
add edi,TYPE inte
loop L1

 

mov count,ebx
sub count,1
mov edi,OFFSET inte
mov ecx,ebx
LL1:
push edi
push ecx
mov ecx,count
LL2:
push edi
mov eax,[edi]
add edi,TYPE inte
mov edx,[edi]
pop edi

 

cmp edx,eax
JG continue

 

push edi
mov [edi],edx
add edi,TYPE inte
mov [edi],eax
pop edi

 

continue:
add edi,TYPE inte
loop LL2

 

pop ecx
pop edi
loop LL1

 

call Crlf
mov edi,OFFSET inte
mov ecx,ebx
L2:
mov eax,[edi]
call WriteInt
call Crlf
add edi,TYPE inte
loop L2

 

Exit
main ENDP
END main

Leave a Reply

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *