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

前端 未结 2 961
伪装坚强ぢ
伪装坚强ぢ 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 02:59

    As you state, the execution of the OR operation sets the status flags, which you test with the following JNZ (Jump if Not Zero) conditional branch.

    The OR opcode on many processors with implicit register addressing (though not on the x86) can be encoded into a single opcode.

    Using CMP al, 0 takes the opcode plus uses additional memory for the immediate parameter. So it is basically just to save a little memory and possibly gain a bit of speed.

    Those were common practices in early assembly language development when memory was scarce. But the practices have carried through to even today.

提交回复
热议问题