冒泡排序(汇编代码)
include irvine32.inc
.data
count dd lengthof arr ;lengthof arr == ($-arr)/4
arr dd 78, 25, -56, 0, 49, 32, 100, 6542, 231
.code
main proc
mov eax, count
mov esi, 0 ;call dumpregs
again_1:
cmp esi, count
jae final
call BubbleSort
add esi, 1
jmp again_1
final:
call output
exit
main endp
BubbleSort proc
mov edi, 0
mov ebx, 1
again_2:
cmp ebx, count
jae last
mov eax, arr[4*edi]
cmp eax, arr[4*ebx]
jl next
call swap
next: add edi, 1
add ebx, 1
jmp again_2
last:
ret
BubbleSort endp
swap proc
push arr[4*edi]
push arr[4*ebx]
pop arr[4*edi]
pop arr[4*ebx]
ret
swap endp
output proc
mov esi, 0
again_3:
cmp esi, count
jae tail
mov eax, arr[4*esi]
call writeint
mov al, ' '
call writechar
add esi, 1
jmp again_3
tail:
ret
output endp
end main