4

If part of the assembly code is as following:

xor %ebp,%ebx
jle some address

does this jle means that it will jump when (%ebx ^ %ebp == 0) because that would set ZF to 1?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

5

That's one of the ways JLE can be true. The other is SF≠ OF, as per the manual: https://www.felixcloutier.com/x86/jcc

Since XOR always clears OF, SF != OF reduces to just SF.

jle after a boolean op will be taken if SF | ZF, i.e. if the result is <= 0.

Interesting optimization to avoid test %ebx,%ebx to compare the result against zero (AND or TEST same,same sets FLAGS identically to cmp reg,0).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    So it will jump if `%ebp` and `%ebx` differ in their most-significant bits or are equal? It's hard to imagine when that would be useful except as an exam question. – Nate Eldredge Nov 07 '20 at 15:01
  • @NateEldredge: I thought about saying something in my answer about it not telling you much about the inputs, because yeah it doesn't seem like a meaningful thing to test, unless maybe one of the registers can only have its sign bit set or not, or something like that. But it seems plausible you could do something with the result of an XOR that would make a compiler want to test it for `>0`. Doing something else with the result, treating it as a signed integer, can certainly lead to a compiler optimizing that along with the xor; that kind of thing is exactly why we use compilers. – Peter Cordes Nov 07 '20 at 19:25