Jumps in Assembly Language

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

JUMPS IN ASSEMBLY LANGUAGE

Jumps are instructions used to alter the flow of execution in assembly language programs. They allow the program
to transfer control to a different part of the code based on specific conditions or requirements.

TYPES OF JUMPS

 UNCONDITIONAL JUMP
 CONDITIONAL JUMP
CONDITIONAL JUMPS

Conditional jumps are instructions in assembly language that allow the program to change its flow of execution
based on certain conditions. They are used to create decision-making and branching in the program.

In MASM, conditional jumps are typically used after a comparison operation (such as CMP) to determine whether
to jump to a different location in the code or continue executing the next instruction.

Here are some commonly used conditional jump instructions in MASM:

- JE (Jump if equal): Jumps if the previous comparison was equal.

- JNE (Jump if Not Equal): Jumps if the previous comparison was not equal.

- JG (Jump if Greater): Jumps if the previous comparison was greater.

- JGE (Jump if Greater or Equal): Jumps if the previous comparison was greater or equal.

- JL (Jump if less): Jumps if the previous comparison was less.

- JLE (Jump if Less or Equal): Jumps if the previous comparison was less or equal.

EXAMPLES:

Camp eFax, ebb ; Compare EAX and EBX

Je equal label ; Jump to equal label if they are equal

Jig greater label; Jump to greater label if EAX is greater than EBX

Jell less label ; Jump to less label if EAX is less than EBX

the JG (Jump if Greater) and JL (Jump if Less) instructions are used to perform conditional jumps based on the
comparison of two values. These instructions are commonly used in assembly language programming to
implement decision-making and branching.
Here's how they work:

- JG (Jump if Greater): This instruction jumps to a specified label or memory address if the previous comparison
was greater. It is typically used to perform a jump when the first value is greater than the second value.

- JL (Jump if Less): This instruction jumps to a specified label or memory address if the previous comparison was
less. It is typically used to perform a jump when the first value is less than the second value.

Both JG and JL instructions are used in combination with the CMP (Compare) instruction, which compares two
values and sets the appropriate flags in the processor's status register based on the result of the comparison.

EXAMPLES:

Here's an example that demonstrates the usage of JG and JL instructions:

mov eax, 10 ; Assign a value of 10 to EAX

mov ebx, 5 ; Assign a value of 5 to EBX

cmp eax, ebx ; Compare the values in EAX and EBX

jg greater ; Jump to the 'greater' label if EAX is greater than EBX

jl less ; Jump to the 'less' label if EAX is less than EBX

; Code continues here if none of the jumps were taken

greater:

; Code for when EAX is greater than EBX

jump end

less:

; Code for when EAX is less than EBX


jump end

End:

; Code continues here after the jumps

In this example, the CMP instruction compares the values in EAX and EBX. If EAX is greater than EBX, the JG
instruction jumps to the 'greater' label. If EAX is less than EBX, the JL instruction jumps to the 'less' label. If neither
condition is met, the code continues executing after the jumps.

These instructions provide a way to implement branching and decision-making logic in assembly language
programs based on the comparison of values.

You might also like