Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Linux Others Videos
Advertisement

Article by Ayman Alheraki on January 11 2026 10:38 AM

#20 Mastering GAS A Complete Guide to the GNU Assembler

#20 Mastering GAS: A Complete Guide to the GNU Assembler.

 

Series for explaining and teaching GNU GAS Assembler using AT&T syntax – all codes are reviewed and tested daily on

Fedora Linux 42

GNU Assembler version 2.44-6

Jump Instructions (jmp, je, jne, call, ret)

Jump instructions are critical for controlling the flow of execution in an assembly program. They enable branching, allowing the program to make decisions, loop, or call functions. In GAS (GNU Assembler), jump instructions are used to transfer control from one point in the program to another. They are essential for conditional branching, function calls, and returning from functions.

2.1 jmp (Unconditional Jump)

The jmp instruction is the simplest jump instruction, providing an unconditional transfer of control to the target address specified in the instruction. This instruction is used to jump to another part of the program, effectively skipping over instructions or loops.

Syntax:

  • target: The location (address or label) to which control is transferred. The target can be an immediate address, a register, or a label within the code.

Example (x86):

In this example:

  • The control is transferred unconditionally to the label _my_label, and the program execution continues from there.

Key Points:

  • The jmp instruction does not check any flags or conditions; it simply jumps to the specified location.

  • It is often used in loops, infinite loops, or to skip over blocks of code.

2.2 je (Jump if Equal)

The je (Jump if Equal) instruction is a conditional jump. It transfers control to the specified target if the zero flag (ZF) is set. The zero flag is typically set by a previous comparison or arithmetic operation that results in two equal values (i.e., a comparison with zero).

This instruction is equivalent to jne (Jump if Not Equal) but is used when the comparison results in equality. It is frequently used after instructions that perform comparisons (cmp), enabling conditional execution based on whether two operands are equal.

Syntax:

  • target: The target address or label to which the program control is transferred if the zero flag is set (i.e., if the previous comparison resulted in equality).

Example (x86):

In this example:

  • The cmp instruction sets the zero flag (ZF) based on the result of comparing the values in registers EAX and EBX.

  • If the values are equal, je jumps to the label _equal_case.

Key Points:

  • The je instruction only jumps if the zero flag is set, meaning the operands being compared are equal.

  • It is a vital instruction in conditional logic and decision-making in assembly programming.

2.3 jne (Jump if Not Equal)

The jne (Jump if Not Equal) instruction is the inverse of je (Jump if Equal). It transfers control to the specified target if the zero flag (ZF) is clear, meaning the comparison or operation resulted in two different values.

Syntax:

  • target: The target address or label to which control is transferred if the zero flag is clear (i.e., if the operands are not equal).

Example (x86):

In this example:

  • The cmp instruction compares EAX and EBX, setting the zero flag based on the result.

  • If the values are not equal, jne will cause a jump to the _not_equal label.

Key Points:

  • The jne instruction checks the zero flag to determine if the values are different, allowing conditional branching based on inequality.

  • It is widely used for loops, error handling, and comparisons.

2.4 call (Call a Function)

The call instruction is used to call a function or procedure in assembly language. It saves the current address of the program counter (the address of the instruction after the call) onto the stack and then jumps to the target address (function or procedure) to start execution. After the function finishes, the ret (return) instruction is used to return control to the instruction following the call.

The call instruction is critical for implementing functions, subroutines, and modular code in assembly.

Syntax:

  • target: The address or label of the function or procedure to call.

Example (x86):

In this example:

  • The program will push the current instruction pointer (return address) onto the stack and jump to the address of my_function.

  • When the function completes, control will return to the instruction following the call instruction.

Key Points:

  • The call instruction automatically saves the return address on the stack, enabling function calls and returns.

  • It is essential for implementing structured, modular programs where you call functions from various points in the code.

2.5 ret (Return from Function)

The ret instruction is used to return from a function or procedure that was called using the call instruction. It pops the return address from the stack and transfers control back to that address, resuming execution from where the function was called.

This instruction is crucial for implementing function return and maintaining the flow of execution between different parts of a program.

Syntax:

  • No operands: The return address is automatically popped from the stack.

Example (x86):

In this example:

  • The ret instruction pops the return address from the stack and transfers control back to the instruction following the call to my_function.

Key Points:

  • The ret instruction is used at the end of a function to return control to the calling code.

  • It is crucial for properly managing function calls and returning from functions in assembly programs.

Jump Instructions Summary

  • jmp: Unconditionally jumps to the specified target address, altering the program flow.

  • je: Conditionally jumps if the zero flag (ZF) is set, which typically happens after a comparison that results in equality.

  • jne: Conditionally jumps if the zero flag (ZF) is clear, meaning the comparison resulted in inequality.

  • call: Used to call a function or procedure, saving the return address on the stack and jumping to the function.

  • ret: Used to return from a function, popping the return address from the stack and resuming execution at the point after the call.

These jump instructions form the foundation of control flow in assembly programming. They enable branching, conditional execution, function calls, and returns, which are all necessary for building complex algorithms and applications in low-level programming. Understanding how and when to use each of these instructions is essential for anyone working with GAS, whether in debugging, optimizing, or implementing algorithms.

 

Advertisements

Responsive Counter
General Counter
1000765
Daily Counter
2385