by unoti · 15y ago · 0 comments
mov $1, %eax
xorl %ebx, %ebx # Why not mov for this one?
mov $0, %ebx # Wouldn't this work as well?
I'm guessing mov would work in either case, but there's some reason people always do the xorl instead?It is not 100% a "smaller is better" choice. You also will want to check whether an instruction depends on an earlier one (for example, the XOR technically needs to read the register; if the CPU does not know that that is not actually the case, a self-XOR may introduce pipeline bubbles), what instruction unit (if any) it uses, and whether you want to preserve flags.