assemblyx86x86-64attconditional-execution

How does conditional jump of x86-64 works?


I'm so confused about conditional branch while I was studying x86-64.

compq %rax,%rdi
jl .L2

Which one is the correct understanding?

  1. if %rax < %rdi, jump to L2
  2. if %rax > %rdi, jump to L2

Solution

  • There's no compq in x86-64. There's CMP which will be cmpq when comparing 64-bit operands in AT&T syntax.

    It'll be clearer when using Intel syntax, because AT&T swaps the destination and source which will be more confusing on instructions like cmp and sub

    cmp rdi, rax
    jl .L2
    

    Jcc instructions always compare the first operand with the second one. In this case it'll jump when rdi < rax