我无法在masm x86中进行选择排序

时间:2019-11-18 14:11:25

标签: masm

我尝试使选择在masm中排序,但是我的源打印仅显示错误短语 也许findMin PROC出错,但是我无法修改该块 你能帮我吗? :(((

INCLUDE Irvine32.inc
.data
intArray DWORD - 117, 10, -1231, 2, 5, -11, -16, 7, 8, 9, 10, 1231, 123, 2, 123, 1, -123, 123, 12333, 875, 844, 111
.code
main PROC
    mov ecx, LENGTHOF intArray
    mov esi, 0
    mov edi, 1
    mov eax, 0
outer:
    call findMin
    call swap
    inc esi
    mov edi,esi
    inc edi
loop outer
call printArray
exit
main ENDP

printArray PROC
    mov ecx, LENGTHOF intArray
    mov esi, 0
L1:
    mov eax, intArray[esi * 4]
    call writeInt
    mov al, ' '
    call writeChar
    inc esi
Loop L1
    call crlf
    ret
printArray ENDP

findMin PROC USES esi ecx edi
    mov ecx, LENGTHOF intArray
    sub ecx, esi; dec unnecessary loop count 
inner :
    mov eax, intArray[esi * 4]
    cmp eax, intArray[edi * 4]
    JG tmp
    inc edi
    loop inner
    mov edi, ebx; save min element index to edi
    ret
findMin ENDP

tmp : ; save min element index to ebx and change esi
    mov ebx, edi
    mov esi, edi
    ret

swap PROC
    mov eax, intArray[esi * 4]
    mov ebx, intArray[edi * 4]
    xchg eax, ebx
    mov intArray[esi * 4], eax
    mov intArray[edi * 4], ebx
    ret
swap ENDP

END main
main PROC

我知道jmp不是保存返回地址,然后如何从jmp返回? (对不起大家,我真的对eng grammer不好;()

0 个答案:

没有答案