jmp

Jump unconditionally

Jumps unconditionally to the given address.

8086 and later

Intel's reference: JMP

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

  • jmp short
  • jmp
  • jmp near 386 and later
  • jmp near

Operands

imm8
A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. The displacement must fit a signed byte, -128 to 127.
imm
A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. NASM selects a short or near encoding according to the target’s reach and any size constraint.
imm32
A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. In 64-bit mode the encoded displacement is signed 32-bit, -2147483648 to 2147483647, even though the target address is 64-bit.
r/m64
A 64-bit general-purpose register or quadword in memory, for example rax or qword [rsi].
mem
A memory location addressed with square brackets, for example [rbx+8] or [label].

jmp target names a label or target address; NASM calculates a displacement from the end of the instruction. A short jump uses a signed 8-bit displacement (−128 through 127 bytes); the ordinary longer near form in 64-bit mode uses a signed 32-bit displacement (about ±2 GiB), not an absolute 64-bit address.

NASM normally chooses a short encoding when the target fits. short requires that range; strict near prevents shortening to the 8-bit form.

jmp rax takes the full target address from the register, and jmp [pointer] reads an 8-byte target address from memory. These indirect near jumps have no relative displacement limit.

A far jump also changes cs. A far memory pointer contains the offset first, then a 16-bit selector: 16-, 32- and 64-bit offsets occupy 4, 6 and 10 bytes in total. Immediate segment:offset jumps are unavailable in 64-bit mode. Far transfers require valid operating-system segment descriptors and are not ordinary branches in a Linux program.

global _start

section .text
_start:
        mov rax, 1
        jmp skip
        mov rax, 99         ; never runs
skip:
        mov rbx, rax

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall