Loading formats...
Complex If-ElseIf-Else in x86-64 YASM Assembly - Full Guide with Code Examples
N
Neural Lantern
4 views • Jan 04, 2026
Description
In this in-depth x86-64 assembly tutorial using YASM, we dive deep into implementing complex if-else and if-elseif-else control structures from scratch. Starting with the fundamentals of conditional branching, we build up to full chained if-elseif-else blocks with multiple conditions - exactly how high-level languages handle them under the hood.
You'll see real working code that:
- Takes user integer input
- Tests against specific values (5, 6, etc.)
- Handles greater-than/less-than comparisons
- Properly branches so only one block executes
- Uses labels, cmp, conditional jumps (je, jl), and unconditional jumps (jmp) correctly
We cover the classic pattern: compare to conditional jump to true block to execute true code to jmp to end to false block falls through or jumps in. Everything is shown step-by-step with live compilation and runtime demos.
Perfect for anyone learning low-level programming, reverse engineering, or wanting to understand how compilers translate if-else chains into machine code. Prerequisites: basic conditional jumps (see my earlier videos).
Code shown works on Linux x86-64 with YASM/NASM syntax. Grab the concepts and apply them anywhere.
Introduction to If-Else in Assembly 00:00:00
Explaining the If-Else Design Pattern 00:00:56
Drawing the Basic If-Else Flow 00:01:01
Comparison and Conditional Jumps 00:02:30
Labels for True and False Blocks 00:03:07
Unconditional Jump to End 00:04:50
Diagram of Execution Flow 00:05:51
Alternative Pattern with Inverted Jump 00:07:00
Recapping the If-Else Pattern 00:08:45
Starting the Code Example 00:09:16
Setting Up Input and Strings 00:09:40
Calling External Functions 00:10:57
Entry Point and Prologue 00:11:40
Asking User for Integer Input 00:13:09
Creating the if_test Function 00:14:56
Preserving Callee-Saved Registers 00:15:51
Printing Begin Message 00:17:03
Implementing Simple If Block 00:18:29
Comparison and je Jump 00:19:18
True Block: Equality Message 00:21:08
Testing Simple If Examples 00:23:48
Transition to If-Else Blocks 00:24:21
Creating if_else_test Function 00:24:47
Setting Up Complex If-Else 00:26:25
First If: Equal to 5 00:27:22
True Block for Equal 5 00:28:33
Else If: Equal to 6 00:30:29
Else If: Less Than 10 00:34:17
Final Else Block 00:37:33
Done Label and Goodbye 00:38:23
Recap of Full Flow 00:39:06
Live Demo of All Branches 00:40:54
Signed vs Unsigned Jumps Note 00:43:38
Recommended Assembly Book 00:44:12
Conditional Jump Families 00:45:05
Closing and Practice Advice 00:46:48
Thanks for watching!
Find us on other social media here:
- https://www.NeuralLantern.com/social
Please help support us!
- Subscribing + Sharing on Social Media
- Leaving a comment or suggestion
- Subscribing to our Blog
- Watching the main "pinned" video of this channel for offers and extras
You'll see real working code that:
- Takes user integer input
- Tests against specific values (5, 6, etc.)
- Handles greater-than/less-than comparisons
- Properly branches so only one block executes
- Uses labels, cmp, conditional jumps (je, jl), and unconditional jumps (jmp) correctly
We cover the classic pattern: compare to conditional jump to true block to execute true code to jmp to end to false block falls through or jumps in. Everything is shown step-by-step with live compilation and runtime demos.
Perfect for anyone learning low-level programming, reverse engineering, or wanting to understand how compilers translate if-else chains into machine code. Prerequisites: basic conditional jumps (see my earlier videos).
Code shown works on Linux x86-64 with YASM/NASM syntax. Grab the concepts and apply them anywhere.
Introduction to If-Else in Assembly 00:00:00
Explaining the If-Else Design Pattern 00:00:56
Drawing the Basic If-Else Flow 00:01:01
Comparison and Conditional Jumps 00:02:30
Labels for True and False Blocks 00:03:07
Unconditional Jump to End 00:04:50
Diagram of Execution Flow 00:05:51
Alternative Pattern with Inverted Jump 00:07:00
Recapping the If-Else Pattern 00:08:45
Starting the Code Example 00:09:16
Setting Up Input and Strings 00:09:40
Calling External Functions 00:10:57
Entry Point and Prologue 00:11:40
Asking User for Integer Input 00:13:09
Creating the if_test Function 00:14:56
Preserving Callee-Saved Registers 00:15:51
Printing Begin Message 00:17:03
Implementing Simple If Block 00:18:29
Comparison and je Jump 00:19:18
True Block: Equality Message 00:21:08
Testing Simple If Examples 00:23:48
Transition to If-Else Blocks 00:24:21
Creating if_else_test Function 00:24:47
Setting Up Complex If-Else 00:26:25
First If: Equal to 5 00:27:22
True Block for Equal 5 00:28:33
Else If: Equal to 6 00:30:29
Else If: Less Than 10 00:34:17
Final Else Block 00:37:33
Done Label and Goodbye 00:38:23
Recap of Full Flow 00:39:06
Live Demo of All Branches 00:40:54
Signed vs Unsigned Jumps Note 00:43:38
Recommended Assembly Book 00:44:12
Conditional Jump Families 00:45:05
Closing and Practice Advice 00:46:48
Thanks for watching!
Find us on other social media here:
- https://www.NeuralLantern.com/social
Please help support us!
- Subscribing + Sharing on Social Media
- Leaving a comment or suggestion
- Subscribing to our Blog
- Watching the main "pinned" video of this channel for offers and extras
Discover more
Keywords & tags
#x86-64 assembly
#yasm assembly
#nasm assembly
#assembly language tutorial
#if else assembly
#conditional branching assembly
#control flow assembly
#assembly programming
#low level programming
#x86 assembly tutorial
#cmp instruction
#je jmp assembly
#assembly language if statement
#chained if else assembly
#intel assembly
More from this user
20:46
Graph Basics in Data Structures: Nodes, Edges, and Representations
Neural Lantern
26:46
4 Graph Types: Undirected vs Directed, Weighted vs Unweighted
Neural Lantern
25:33
AVL Trees: Adding Linear Data and Performing Rotations
Neural Lantern
36:36
AVL Tree Rotations Practice: Balancing a Huge Linear Tree Step by Step
Neural Lantern
16:03
How to Perform AVL Tree Rotations - Step By Step Example
Neural Lantern
25:14
AVL Tree Rotations Tutorial: Fixing Imbalance After Adding a Node
Neural Lantern
Related videos
41:43
x86-64 Assembly: Floating Point Registers Basics with YASM (MOVSD, MULSD, CVTSI2SD)
Neural Lantern
38:46
x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)
Neural Lantern
32:58
x86-64 Assembly Pointers & Dereferencing Explained - Hybrid C++/YASM Example
Neural Lantern
50:14
Mastering x86-64 YASM Assembly: Functions Made Simple
Neural Lantern
22:37
x86-64 Assembly Jump Instructions Explained: Unconditional JMP with Full Example in Yasm
Neural Lantern
55:44
YASM x86-64 Assembly Functions Tutorial - Integers, Floats, Pointers, ABI, C++ Interoperability
Neural Lantern