In assembly language, the JUMP instruction (or its variants, like JMP, JE, JNE, etc.) is used to transfer control to another part of the program. This can be done in various ways, depending on the condition you want to set for the jump. Here’s how to use the JMP instruction in assembly:
1. Unconditional Jump: This jumps to the specified address or label unconditionally.
JMP label ; Jump to ‘label’
2. Conditional Jump: These jumps occur only if a specific condition is met, such as equality or inequality after a comparison.
JE label ; Jump to ‘label’ if equal
JNE label ; Jump to ‘label’ if not equal
JL label ; Jump to ‘label’ if less than
JG label ; Jump to ‘label’ if greater than
3. Example: A simple comparison followed by a conditional jump.
CMP AX, BX ; Compare AX with BX
JE equal ; Jump to ‘equal’ if AX == BX
JMP done ; Jump to ‘done’ if not equal
equal:
; Code to execute if equal
done:
In this example, the program compares two values, and based on the result, either jumps to the equal label or the done label.