Thursday, November 7, 2024
HomeComputer programmingAssembly: Conditional jmp Statements (MASM/TASM)

Assembly: Conditional jmp Statements (MASM/TASM)

This tutorial explains how to use the conditional jmp jumps (je, jg, jl, jne, etc.).


A conditional jump is just what its name implies. It jumps on a condition. If the condition is false, then if continues with the next line.
Example:

cmp 0,1
je one_equals_0
mov AX,0

If je returns true, which it will not, then the mov statement is run. (This code should not work at all, actually.) If it had returned true, then transfer of control would be moved to one_equals_0 label, wherever that is.

Arithmetic Jumps:
je – jump if equal, takes two parameters
jne – jump if not equal, takes two parameters
jl – jump if less than, if second parameter is less than the first
jg – jump if greater than, if second parameter is larger than the first

*NOTE: There are many other jmps available as well. Some are redundant or uncommon.

Flag Jumps:
jz – jump if the last cmp or operation set the zero flag
jnz – jump if result is not zero

*Truthfully, it is a flag or a combination of flags that determines if the jump is taken or not in every case.

You can combine nearly any jump statement without its j-prefix to a single j and gain a new jmp statement. Take for instance the following example:
jnle – jump if not less than or equal (the same as jg)

These conditional jumps allow for loops and if statements in Assembly language.

Questions/Comments: [email protected]
-William. § (marvin_gohan)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!