x86-64 Assembly While Loops Explained Step by Step in YASM - From Concept to Working Program

5 days ago
2

In this detailed tutorial I walk you through exactly how to implement while loops in x86-64 assembly language using YASM. We start with the basic concept of a while loop as it exists in higher-level languages like C/C++, then break it down into labels, conditional jumps, and unconditional jumps so you can see exactly how the control flow works at the assembly level.

I explain why we usually put the condition check at the top, how to handle the jump distances (especially the ~128-byte limit of conditional branches), why unconditional jumps are preferred for the loop-back, and how to structure init / top / body / done sections clearly.

We then build a complete, runnable hybrid program (assembly + tiny C++ driver) that:
- prints an intro message
- repeatedly asks the user to enter numbers
- echoes each number back
- continues until the user enters 99
- prints a goodbye message when finished

Lots of practical tips about label naming conventions, register preservation (R12 in this case), and debugging flow are included along the way.

Assumed knowledge: basic x86-64 assembly, how to use a makefile, simple system calls, and calling external functions. If you're new to those topics, check my earlier videos first.

Hope this helps someone finally "get" while loops in assembly!
Thanks for watching - subscribe if these kinds of low-level explanations are useful to you.

Introduction to While Loops in x86-64 YASM 00:00:00
While Loop Concept in High-Level Languages 00:00:56
Breaking Down While Loop Structure 00:02:00
Labeling Key Sections Top Body Done 00:02:40
Conditional and Unconditional Jumps Explained 00:03:26
Why Prefer Shorter Conditional Jumps 00:04:40
Diagram of While Loop Flow 00:06:52
Alternative While True with Internal Break 00:08:08
Do-While vs Regular While Difference 00:09:32
Program Setup and Data Section Overview 00:09:53
Hybrid Program Structure and External Functions 00:10:56
Main Function and While Test Call 00:12:56
While Test Function Prologue 00:13:21
CRLF Helper Function 00:14:00
Intro Message and Loop Initialization 00:14:50
While Top Comparison with 99 00:16:57
Entering the Loop Body 00:19:08
User Input and Echo Output 00:19:38
Jump Back to While Top 00:20:29
Exit to While Done Section 00:21:39
Goodbye Message and Function Epilogue 00:22:14
Live Demo Running the Program 00:22:30
Summary and Closing Remarks 00:23:12
Call to Subscribe and Website Mention 00:23:46

=-=-=-=-=-=-=-=-=

Thanks for watching!

Find us on other social media here:
- https://www.NeuralLantern.com/social
- Twitter / X: https://x.com/NeuralLantern
- Rumble: https://rumble.com/c/c-3696939
- BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt
- Daily Motion: https://www.dailymotion.com/neurallantern
- Minds: https://www.minds.com/neurallantern/
- Odysee: https://odysee.com/@NeuralLantern:5

Please show your support!

- Buy me a coffee: https://ko-fi.com/neurallantern

- Subscribe + Sharing on Social Media
- Leave a comment or suggestion
- Subscribe to Blog: https://www.NeuralLantern.com
- Watching the main "pinned" video of this channel for offers and extras

Loading comments...