选择排序
题目:内存中有1个32位整数数组,编程用选择排序方法对该整数数组排序,并在屏幕显示该数组排序前后的值
实现代码(无注释)
include irvine32.inc
.data
arr dd 10 dup(?)
count dd ($-arr)/4
.code
main proc
mov edx,offset arr
mov ecx,count
call inarr
call sort
mov ecx,count
call output
exit
main endp
sort proc
sub ecx,1
L1:
call max
mov ebx,[edx+4*ecx]
mov [edx+4*ecx],eax
mov [edx+4*esi],ebx
loop L1
ret
sort endp
max proc
mov ebx,0
mov eax,[edx]
mov esi,0
again:
cmp ebx,ecx
ja final
cmp eax,[edx+ebx*4]
ja next
mov eax,[edx+ebx*4]
mov esi,ebx
next:
add ebx,1
jmp again
final:
ret
max endp
output proc
mov ebx,0
L2:
mov eax,[edx+4*ebx]
call writeint
add ebx,1
mov al,' '
call writechar
loop L2
ret
output endp
inarr proc
mov ebx,0
again1:
cmp ebx,ecx
jz final1
call readint
mov arr[ebx*4],eax
inc ebx
jmp again1
final1:ret
inarr endp
end main
运行结果示例