logoalt Hacker News

Dwedittoday at 1:41 PM2 repliesview on HN

Because "sub eax,eax" looks stupid. (and also clears the carry flag, unlike "xor eax, eax")


Replies

tom_today at 2:00 PM

xor clears the carry as well? In fact, looks like xor and sub affect the same set of flags!

xor:

> The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result. The state of the AF flag is undefined.

sub:

> The OF, SF, ZF, AF, PF, and CF flags are set according to the result.

(I don't have an x64 system handy, but hopefully the reference manual can be trusted. I dimly remembered this, or something like it, tripping me up after coming from programming for the 6502.)

show 1 reply
HackerThemAlltoday at 3:25 PM

If I remember correctly, sub used to be slower than xor on some ancient architectures.