JMP puts a new address into IP (and, for a far jump, into CS too) and execution carries on from there. It tests nothing, pushes nothing and changes no flag. It is the glue of assembly control flow: the jump over the "else" part, the jump back to the top of a loop, the way out of the middle of a block.
Forms
| Form | Encoding | Reach |
|---|---|---|
| JMP SHORT label | EBh + 8-bit displacement | −128..+127 bytes from the next instruction |
| JMP label | E9h + 16-bit displacement | anywhere in the current code segment |
| JMP BX, JMP WORD PTR [x] | FFh /4 | near: IP = the register or the word in memory |
| JMP FAR PTR label | EAh + offset + segment | any segment:offset |
| JMP DWORD PTR [x] | FFh /5 | far: offset, then segment, read from memory |
The direct near and short forms store a displacement, the distance from the end of the JMP to the target, so the code works wherever it is loaded. MASM chooses the shortest encoding that reaches; write SHORT to insist on two bytes, and MASM reports an error if the target is too far. The indirect forms read the destination at run time, which is how jump tables and dispatchers work:
MOV BX, 2 ; case 1, times 2: the table holds wordsJMP WORD PTR [JTAB1+BX] ; near, indirect: IP = the word at JTAB1+BXPICK0:MOV AL, 0JMP SHOW1PICK1:MOV AL, 1 ; this case runsJMP SHOW1PICK2:MOV AL, 2SHOW1:ADD AL, "0" ; digit -> characterMOV DL, ALMOV AH, 02h ; DOS: print the character in DLINT 21hJTAB1 DW PICK0, PICK1, PICK2
Pitfalls
A .COM file has no relocation table, so a far jump whose segment part names your own program cannot be linked into one; JMP FAR PTR to a label of your program belongs in .EXE programs. A far jump through a doubleword in memory (JMP DWORD PTR [OLDVEC1], the usual way to chain to a saved interrupt vector) is fine anywhere. JMP $ jumps to itself: an endless loop. Code right after a JMP never runs unless some label leads to it.
Later CPUs
In 16-bit code later processors behave the same. The 386 adds 32-bit displacements and offsets for 32-bit code, and in protected mode a far jump loads a selector instead of a segment.