<<< Jump Instructions | Index | Jump with Indirect Operand >>> |
The JMP instruction transfers control unconditionally to another instruction.
JMP corresponds to goto statements in high-level languages.
Unconditional jumps skip over code that should not be executed, for example,
; Handle one case label1: . . . jmp done ; Handle second case label2: . . . jmp done . . done:
The assembler determines the smallest encoding possible for the direct unconditional jump.
The assembler determines the correct distance of the jump.
Unconditional jumps to labels are relative jumps.
Each relative jump instruction contains the displacement of the target from the JMP instruction itself.
This displacement is added to the address of the next instruction to find the address of the target.
The displacement is a signed number, positive for a forward reference and negative for a backward reference.
For the relative short version of the instruction, only a single byte of displacement is stored; this is changed to a sign-extended to a doubleword before the addition.
The relative near format includes a 32-bit displacement.
The 8-bit displacement in a relative short jump can serve for a target statement up to 128 bytes before or 127 bytes after the jmp instruction.
(This displacement is measured from the byte following the object code of the jmp itself since at the time an instruction is being executed, EIP logically contains the address of the next instruction to be executed.)
The 32-bit displacement in a relative near jump instruction can serve for a target statement up to 2,147,483,648 bytes before or 2,147,483,647 bytes after the jmp instruction.
There is no difference in the coding for a relative short jump and for a relative near jump.
The assembler uses a short jump if the target is within the small range in order to generate more compact code.
A near jump is used automatically if the target is more than 128 bytes away.
<<< Jump Instructions | Index | Jump with Indirect Operand >>> |