j不跳? (程序集x86 NASM)

时间:2013-11-28 05:04:41

标签: assembly x86 nasm cmp

出于某种原因,我的cmp语句总是会导致jeDoubleScore,而jne函数永远不会RegularScore。我对装配很新,所以这可能是一个简单的错误。

  Approved:
                        mov eax,[prev]
                        mov edi,  dword[buffermaze+eax]
                        mov eax,edi
                        call print_nl
                        call print_int
                        mov eax, 45
                        call print_nl
                        call print_int

                        cmp eax,edi
                        je DoubleScore
                        dump_regs 1
                        jne RegularScore
                        dump_regs 2

                                DoubleScore:
                                        mov ebx,0
                                        ret
                                RegularScore:

                                        mov edx, 0
                                        mov eax,[new]

                                            ret


The Output for this part of the code is 
774778411
45
Register Dump # 1
EAX = 0000002D EBX = F7704FF4 ECX = 00000000 EDX = 00000000
ESI = 0804A434 EDI = 2E2E2E2B EBP = FFF2D4E8 ESP = FFF2D4C4
EIP = 080487B0 FLAGS = 0283       SF          CF

2 个答案:

答案 0 :(得分:0)

我认为这是因为代码片段

 call print_nl 
 call print_int

这两个函数可能对寄存器eax和edi做了些什么。您是否尝试过调试代码?

编辑: jne RegularScore指的是DumpRegs2,而不是cmp eax, edi

在我看来应该是这样的:

                cmp eax,edi
                je DoubleScore
                dump_regs 1
                ;here we will handle the regularScore


                                mov edx, 0
                                mov eax,[new]

                                    ret


                        DoubleScore:
                                mov ebx,0
                                ret

答案 1 :(得分:0)

这会有用吗;

    cmp eax,edi
    je DoubleScore // if equal jmps to DoubleScore and jmps back to passedNotEqual
    jmp RegularScore // if je fails, jmps to RegularScore and returns normal
passedNotEqual:

        DoubleScore:
                mov ebx,0
                dump_regs 1
                jmp passedNotEqual

        RegularScore:

                mov edx, 0
                mov eax,[new]
                dump_regs 2
                ret