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