assemblyx86x86-64

Conditional jump to register


I want to get these commands:

jl some_label(%rip)
# or
jl *%rax

in my asm program that I am writing for Intel x64 architecture.

GCC says that "operand type mismatch for jl" when I try to compile this code.


Solution

  • Conditional jumps are relative on x86. You can use an "inverted" conditional jump followed by an unconditional jump:

      jge   skip_jump
      jmp   *%rax       # AT&T syntax
    skip_jump:
    

    The equivalent NASM syntax is jmp rax. Either way, it sets RIP = RAX, so it's a register-indirect jump.