From time to time we have to analyze pieces of assembler code (IA32),
and more than often i come across an instruction that looks like this:
xor ax, ax
or with other registers aswell: xor dx, dx, xor al, al, …
What exactly does this do ? (ax xor ax always gives 0 ?)
It’s a common assembler idiom to set a register to 0.
xor ax, axcorresponds toax = ax ^ axwhich, as you already noticed, is effectivelyax = 0.If I recall correctly the main advantage is that its code-size is smaller than
mov ax, 0