(x % 2), What's all this and-ing and or-ing?

Posted on Thu 24 February 2011 in blog

While trying to understand some x86 disassembly, I came across one particularly confusing bit of code (modified for this example):

mov   eax, edx
  L0:
     and   eax, -2147483647        ; 80000001H
  L1:
     jns   SHORT L4
     dec   eax
  L2:
     or    eax, -2                 ; fffffffeH
  L3:
     inc   eax
  L4:
     mov   DWORD PTR _r$[ebp], eax

I …


Continue reading