WCU / Cybersecurity
~/CSC 471/Class 02/KP 12
Class 02 · KP 12 / 23

Logic and the XOR Zeroing Idiom

and  rax, 0xff      ; keep low byte (mask)
or   rax, rbx       ; bitwise or
xor  rax, rbx       ; bitwise xor
not  rax            ; flip all bits
shr  rax, 1         ; logical shift right (unsigned /2)
sar  rax, 1         ; arithmetic shift right (signed /2)

xor  eax, eax       ; <-- IDIOM: set eax = 0
  • xor reg, reg is the standard, compact way to zero a register (smaller/faster than mov reg, 0).
  • xor also appears in string/payload de-obfuscation — a red flag when analyzing malware.