randomuser
randomuser

Reputation: 63

How does the JE instruction work without CMP?

.L10:
    leal    (%rsi,%rsi,4), %edx
    movsbl  %al,%eax
    addq    $1, %rdi
    leal    -48(%rax,%rdx,2), %esi
    je  .L3

In the above there's no cmp preceding je. How does it work here?

Upvotes: 6

Views: 1317

Answers (3)

phihag
phihag

Reputation: 288298

je jumps if the ZF flag is set in the EFLAGS register. The value of the ZF flag is set by the previous (for example cmp) operation that modified it.

Since neither lea nor movsbl modify the ZF flag, but add does (compare Intel Developer's Manual, 3-36), je jumps to .L3 iff $1 + %rdi is zero.

Upvotes: 5

phoxis
phoxis

Reputation: 61991

  • je will jump is ZF = 1.
  • add modifies the ZF.
  • lea, movsb does not affect any flags.

Keep the Intel 64 and IA32 Architecture Developer's Manual in hand. You can find all the instruction details of Intel 64 and IA32 architecture in the manual Volume 2

Upvotes: 12

eddieantonio
eddieantonio

Reputation: 170

The preceding instruction sets a processor status flag. Each conditional jump checks a certain flag, even if a cmp was not executed. I believe je executes if the zero flag is set.

Upvotes: 1

Related Questions