My program won't sort arrays that are larger than 130

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 11:02:29

If you look at your registers, you'll see that edx is 0fA4h, which is larger than it should be at the line it crashes on. ecx is a negative number. This is a clue that your loop is executing after it should have stopped.

The problem is that the greater branch will fall thru to the lesser branch. This will decrement ecx again, causing it to go negative and your loop will just keep running until you get the access violation.

The quick fix is to put an unconditional jmp after the loop instruction under the greater label.

A better fix is to combine the tails of the loops into a simpler conditional:

    cmp     esi, [edi + (eax * 4)] ; compare array[j] and array[i]
    jle     lesser
    mov     eax, edx
lesser:
    inc     edx
    loop    secondLoop
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!