为什么在汇编中交换(xchg)寄存器后,程序显示不正确的值?

时间:2019-03-23 20:08:55

标签: assembly x86 nasm

因此,我想对3个值进行排序,但是在交换程序后,这些值将以随机顺序显示。哪里可能有问题。在下面,我向您展示我的代码。所有代码:https://pastebin.com/jp8t8BEb

    mov eax,[var1]
    sub eax,'0'
    mov ebx,[var2]
    sub ebx,'0'
    mov ecx,[var3]
    sub ecx,'0'

    cmp eax,ebx
    jna _instruct1      ;jump if not above tzn mniejsze lub rowne
    xchg eax,ebx

_instruct1:
    cmp eax,ecx
    jna _instruct2
    xchg eax,ecx
_instruct2:
    cmp ebx,ecx
    jna _instruct3
    xchg ebx,ecx
_instruct3:
    add eax,'0'
    mov [small],eax
    add ebx,'0'
    mov [mid],ebx
    add ecx,'0'
    mov [big],ecx

...

section .bss
    var1 resb 2
    var2 resb 2
    var3 resb 2
    small resb 1
    mid resb 1
    big resb 1

0 个答案:

没有答案