
Odd ways to zeroing some x86_64 registers - geyslan
http://hackingbits.github.io/blog/odd-ways-to-zeroing-some-x8664-registers/
======
Rarebox
If you're wondering why this is useful, the reason is buffer overflow
exploits. Strings in C are null-terminated, so having a null in your code may
stop it from getting copied.

~~~
userbinator
I think obfuscation is another reason, since the classic "xor reg, reg" (31 C0
is xor eax, eax) does not have any nulls either.

~~~
ithkuil
yeah, nor it does on x64_64 since it's the same encoding but prefixed by a
REX: `48 31 c0 xor %rax,%rax`

------
gane5h
I've used this in the past, in high performance math.

If you have data (vectors, matrices, etc.) that doesn't fit neatly into a SIMD
block size, you'll have to zero out fields after the calculation. At this
point, it's cheaper to generate a zero on the register than load via memory
(cheaper as in the number of CPU instructions.)

------
geyslan
New link: [http://hackingbits.github.io/blog/odd-ways-to-zeroing-
some-x...](http://hackingbits.github.io/blog/odd-ways-to-zeroing-
some-x8664-registers/)

------
geyslan
It began as an obsfucation method then I realized more implications.

