Why would you OR a value with itself before a call to jnz?

前端 未结 2 938
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 02:17

I\'m reading some code that does the following:

OR al, al
JNZ loc_123456

If I am reading this correctly, the OR command just s

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-20 03:00

    Using or x, x to test for zero is a common idiom, so it's perfectly readable.

    You should prefer test x, x (also a common idiom) though, it macro-fuses with the branch on many processors.

    Avoid cmp reg, 0. Having a lot of memory is no reason to waste it, and there's nothing to gain here. Even if there was a readability difference - this is assembly, readability is not the point. And cache space and instruction fetch bandwidth are still limited resources.

提交回复
热议问题