1

I have the following code:

or edx,edx          (0 Or 0 would equal 0)
jz InvalidDivisor

If i change the code to this:

AND edx,edx            (0 and 0 would equal 0)
jz InvalidDivisor

Wouldnt both ways work for checking to see if the product is 0?

Csaas33
  • 5
  • 2

1 Answers1

4

These both work, but test edx, edx does the same and is more idiomatic than either one of them.

It may also be more efficient because I would guess that either or or and would appear to the CPU as though they possibly modify the value of the register, since or edx, XXX would do so in general, and the CPU probably doesn't check for this special case. This could mean that later instructions using the value of edx have to stall until the or/and finishes executing, whereas with test those later instructions can go ahead and execute out-of-order without waiting for test to finish.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • Yes, `test` is more efficient in many cases, including allowing fusion with JCC on AMD CPUs, and earlier Intel. There's a canonical duplicate for this: [Test whether a register is zero with CMP reg,0 vs OR reg,reg?](https://stackoverflow.com/a/33724806) – Peter Cordes Aug 01 '21 at 02:59