Intel x86 Assembly Language & Microarchitecture Unconditional jumps


Example

jmp a_label                      ;Jump to a_label
jmp bx                           ;Jump to address in BX
jmp WORD [aPointer]              ;Jump to address in aPointer
jmp 7c0h:0000h                   ;Jump to segment 7c0h and offset 0000h
jmp FAR WORD [aFarPointer]       ;Jump to segment:offset in aFarPointer

Relative near jumps

jmp a_label is:

  • near
    It only specify the offset part of the logical address of destination. The segment is assumed to be CS.
  • relative
    The instruction semantic is jump rel bytes forward1 from next instruction address or IP = IP + rel.

The instruction is encoded as either EB <rel8> or EB <rel16/32>, the assembler picking up the most appropriate form, usually preferring a shorter one.
Per assembler overriding is possible, for example with NASM jmp SHORT a_label, jmp WORD a_label and jmp DWORD a_label generate the three possible forms.

Absolute indirect near jumps

jmp bx and jmp WORD [aPointer] are:

  • near
    They only specify the offset part of the logical address of destination. The segment is assumed to be CS.
  • absolute indirect
    The semantic of the instructions is jump to the address in reg or mem or IP = reg, IP = mem.

The instruction is encoded as FF /4, for memory indirect the size of the operand is determined as for every other memory access.

Absolute far jumps

jmp 7c0h:0000h is:

  • far
    It specifies both parts of the logical address: the segment and the offset.

  • absolute The semantic of the instruction is jump to the address segment:offset or CS = segment, IP = offset.

The instruction is encoded as EA <imm32/48> depending on the code size.
It is possible to choose between the two forms in some assembler, for example with NASM jmp 7c0h: WORD 0000h and jmp 7c0h: DWORD 0000h generate the first and second form.

Absolute indirect far jumps

jmp FAR WORD [aFarPointer] is:

  • far It specifies both parts of the logical address: the segment and the offset.

  • Absolute indirect The semantic of the instruction is jump to the segment:offset stored in mem2 or CS = mem[23:16/32], IP = [15/31:0].

The instruction is encoded as FF /5, the size of the operand can be controller with the size specifiers.
In NASM, a little bit non intuitive, they are jmp FAR WORD [aFarPointer] for a 16:16 operand and jmp FAR DWORD [aFarPointer] for a 16:32 operand.


Missing jumps

  • near absolute
    Can be emulated with a near indirect jump.

      mov bx, target            ;BX = absolute address of target
      jmp bx
    
  • far relative
    Make no sense or too narrow of use anyway.


1 Two complement is used to specify a signed offset and thus jump backward.
2 Which can be a seg16:off16 or a seg16:off32, of sizes 16:16 and 16:32.