Search code examples
assemblyx86nasmcmp

jne not jumping? (assembly x86 NASM)


For some reason my cmp statement here always causes a je to DoubleScore, and never jne to the RegularScore function. I am fairly new to assembly so it is probably a simple mistake.

  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

Solution

  • I think it's because the code fragment

     call print_nl 
     call print_int
    

    those two functions might do something to the registers eax and edi. Have you tried debugging the code ?

    Edit: jne RegularScore refers to DumpRegs2, not the cmp eax, edi

    in my opinion it should be like this:

                    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