x86 jnz after xor?

小太郎 picture 小太郎 · Jun 6, 2010 · Viewed 8k times · Source

After using IDA Pro to disassemble a x86 dll, I found this code (Comments added by me in pusedo-c code. I hope they're correct):

test    ebx, ebx        ; if (ebx == false)
jz      short loc_6385A34B ; Jump to 0x6385a34b
mov     eax, [ebx+84h]  ; eax = *(ebx+0x84)
mov     ecx, [esi+84h]  ; ecx = *(esi+0x84)
mov     al, [eax+30h]   ; al = *(*(ebx+0x84)+0x30)
xor     al, [ecx+30h]   ; al = al XOR *(*(esi+0x84)+0x30)
jnz     loc_6385A453

Lets make it simpler for me to understand:

mov     eax, b3h
xor     eax, d6h
jnz     ...

How does the conditional jump instruction work after a xor instruction?

Answer

Greg Hewgill picture Greg Hewgill · Jun 6, 2010

Like most instructions, xor sets the processor condition flags depending on the result of the previous operation. In this case, the Z flag will be set if the result of the xor is zero. The jnz instruction tests the Z flag and branches if it is not set.