Search code examples
cassemblyx86attinstruction-set

xorl %eax - Instruction set architecture in IA-32


I am experiencing some difficulties interpreting this exercise;

What does exactly xorl does in this assembly snippet?

C Code:

int i = 0;
if (i>=55)
    i++;
else
    i--;

Assembly

xorl ____ , %ebx
cmpl ____ , %ebx
Jel  .L2
____ %ebx
.L2:
____ %ebx
.L3:

What's happening on the assembly part?


Solution

  • It's probably:

    xorl %ebx, %ebx
    

    This is a common idiom for zeroing a register on x86. This would correspond with i = 0 in the C code.


    If you are curious "but why ?" the short answer is that the xor instruction is fewer bytes than mov $0, %ebx. The long answer includes other subtle reasons.

    I am leaving out the rest of the exercise since there's nothing idiosyncratic left.