<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>x86-64 programming Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/x86-64-programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/x86-64-programming/</link>
	<description></description>
	<lastBuildDate>Sun, 25 Jan 2026 01:02:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>x86-64 programming Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/x86-64-programming/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>x86-64 Assembly While Loops Explained Step by Step in YASM &#8211; From Concept to Working Program</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-while-loops-explained-step-by-step-in-yasm-from-concept-to-working-program/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-while-loops-explained-step-by-step-in-yasm-from-concept-to-working-program/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 25 Jan 2026 01:02:57 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly control flow]]></category>
		<category><![CDATA[assembly language loops]]></category>
		<category><![CDATA[assembly language tutorial]]></category>
		<category><![CDATA[assembly while loop example]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[conditional jump assembly]]></category>
		<category><![CDATA[learn assembly language]]></category>
		<category><![CDATA[low level loops]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[NASM vs YASM]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[unconditional jump]]></category>
		<category><![CDATA[while loop assembly]]></category>
		<category><![CDATA[x86 assembly loops]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[x86-64 linux assembly]]></category>
		<category><![CDATA[x86-64 programming]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=291</guid>

					<description><![CDATA[<p>This video teaches how to implement a classic while loop structure in x86-64 assembly language using YASM. We cover the conceptual mapping from C-style while(condition) { body } to assembly labels (while_top, while_body, while_done), conditional jumps (jne, je, etc.), and the unconditional jump back to the top of the loop. A complete runnable example repeatedly reads integers from the user and echoes them until 99 is entered.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-while-loops-explained-step-by-step-in-yasm-from-concept-to-working-program/">x86-64 Assembly While Loops Explained Step by Step in YASM &#8211; From Concept to Working Program</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="x86-64 Assembly While Loops Explained Step by Step in YASM - From Concept to Working Program" width="1380" height="776" src="https://www.youtube.com/embed/JnkyFMw09Us?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">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.</p>



<p class="wp-block-paragraph">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.</p>



<p class="wp-block-paragraph">We then build a complete, runnable hybrid program (assembly + tiny C++ driver) that:</p>



<ul class="wp-block-list">
<li>prints an intro message</li>



<li>repeatedly asks the user to enter numbers</li>



<li>echoes each number back</li>



<li>continues until the user enters 99</li>



<li>prints a goodbye message when finished</li>
</ul>



<p class="wp-block-paragraph">Lots of practical tips about label naming conventions, register preservation (R12 in this case), and debugging flow are included along the way.</p>



<p class="wp-block-paragraph">Assumed knowledge: basic x86-64 assembly, how to use a makefile, simple system calls, and calling external functions. If you&#8217;re new to those topics, check my earlier videos first.</p>



<p class="wp-block-paragraph">Hope this helps someone finally &#8220;get&#8221; while loops in assembly!<br>Thanks for watching &#8211; subscribe if these kinds of low-level explanations are useful to you.</p>



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



<p class="wp-block-paragraph">=-=-=-=-=-=-=-=-=</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>



<li>Twitter / X: https://x.com/NeuralLantern</li>



<li>Rumble: https://rumble.com/c/c-3696939</li>



<li>BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt</li>



<li>Daily Motion: https://www.dailymotion.com/neurallantern</li>



<li>Minds: https://www.minds.com/neurallantern/</li>



<li>Odysee: https://odysee.com/@NeuralLantern:5</li>
</ul>



<p class="wp-block-paragraph">Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: https://ko-fi.com/neurallantern</li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to Blog: https://www.NeuralLantern.com</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">All right, hello there. In this video, I&#8217;m going to teach you how to implement while loops in YASM</p>



<p class="wp-block-paragraph">x86-64 assembly. Although you probably don&#8217;t need to be using YASM assembly to understand</p>



<p class="wp-block-paragraph">this video or to benefit from it. So what am I talking about? First off, okay, so we&#8217;re going</p>



<p class="wp-block-paragraph">to do while loops. There&#8217;s a lot of assumed knowledge in this video. If you don&#8217;t know how</p>



<p class="wp-block-paragraph">assembly program, if you don&#8217;t know how to make a make file, if you don&#8217;t know a lot</p>



<p class="wp-block-paragraph">of the basics that I&#8217;m just skimming over in this video, you&#8217;ll need to see my other</p>



<p class="wp-block-paragraph">videos because I explain all of those things at length.</p>



<p class="wp-block-paragraph">For this video, I&#8217;m just going to be talking about while loops only.</p>



<p class="wp-block-paragraph">So for starters, let&#8217;s see here and open up a little notepad here and just type a while</p>



<p class="wp-block-paragraph">loop and try to explain a little bit about it conceptually.</p>



<p class="wp-block-paragraph">And then after that, we&#8217;re going to, we&#8217;re going to write a program in Yasm to show that</p>



<p class="wp-block-paragraph">we can get this to work.</p>



<p class="wp-block-paragraph">So what is a while loop in a higher level language?</p>



<p class="wp-block-paragraph">We&#8217;ll just suppose C or C++.</p>



<p class="wp-block-paragraph">You can imagine whatever language you want, but typically in a while loop,</p>



<p class="wp-block-paragraph">we&#8217;re not talking about a do while loop, although that would be really easy</p>



<p class="wp-block-paragraph">to implement after watching this video.</p>



<p class="wp-block-paragraph">But in a regular while loop, you have the keyword while usually,</p>



<p class="wp-block-paragraph">and then you have some sort of an expression like does a equal B or whatever.</p>



<p class="wp-block-paragraph">So maybe I&#8217;ll just say does a equal B?</p>



<p class="wp-block-paragraph">Expression evaluates to true then the body of the while loop will execute and then when it&#8217;s done executing</p>



<p class="wp-block-paragraph">Execution will go back up to look at the expression again and make sure that it&#8217;s still true</p>



<p class="wp-block-paragraph">So the loop will run forever until that expression evaluates to false</p>



<p class="wp-block-paragraph">Maybe that&#8217;s what you want. Maybe that&#8217;s not what you want, but that&#8217;s what it&#8217;ll do</p>



<p class="wp-block-paragraph">And that means the body runs an endless number of times</p>



<p class="wp-block-paragraph">Also, if the expression evaluates to false on the very first run</p>



<p class="wp-block-paragraph">then the body of the while loop will just never run at all.</p>



<p class="wp-block-paragraph">So that&#8217;s, you know, a basic idea of a while loop in a higher level language.</p>



<p class="wp-block-paragraph">Hopefully you kind of already know that.</p>



<p class="wp-block-paragraph">So let&#8217;s look at the parts right here.</p>



<p class="wp-block-paragraph">If we imagine this as assembly,</p>



<p class="wp-block-paragraph">then probably the first thing we should do is label the part</p>



<p class="wp-block-paragraph">where we look at the expression and decide whether we&#8217;re going to continue or not, right?</p>



<p class="wp-block-paragraph">So I&#8217;m going to put a little label here</p>



<p class="wp-block-paragraph">and maybe we&#8217;ll call it a while top or something.</p>



<p class="wp-block-paragraph">You know, whatever you want to do.</p>



<p class="wp-block-paragraph">just to label the part of the code</p>



<p class="wp-block-paragraph">So that we know when we write assembly</p>



<p class="wp-block-paragraph">We&#8217;ll be able to put the appropriate labels on the different parts of the while loop and we&#8217;ll be able to imagine</p>



<p class="wp-block-paragraph">The while loop that we&#8217;re implementing in assembly</p>



<p class="wp-block-paragraph">So I&#8217;m gonna say this is the top or you can call it the eval part whatever you want</p>



<p class="wp-block-paragraph">Then we&#8217;ll make another label down here. We&#8217;ll call it</p>



<p class="wp-block-paragraph">You know while body something like that and so basically if we want to jump up to the top of the while loop to evaluate the</p>



<p class="wp-block-paragraph">expression, we just have to basically jump to that label called while top.</p>



<p class="wp-block-paragraph">And if we want to jump to the body to actually execute the code,</p>



<p class="wp-block-paragraph">then we just have to jump to that other label instead. We should also have a label at the</p>



<p class="wp-block-paragraph">very bottom after the whole while loop is over and we&#8217;ll call it, you know, while finished</p>



<p class="wp-block-paragraph">or while, whoops, finished or while done or while over something like that. So I&#8217;m just going to</p>



<p class="wp-block-paragraph">Now you can imagine that when we&#8217;re at the top of the while loop and we see that the</p>



<p class="wp-block-paragraph">expression is false, then we can just jump down to the done label, thereby exiting the</p>



<p class="wp-block-paragraph">entire while loop.</p>



<p class="wp-block-paragraph">Then of course we probably want to have some jump statements in here.</p>



<p class="wp-block-paragraph">So for example, the expression part here, it&#8217;s probably going to jump either to the</p>



<p class="wp-block-paragraph">body or either to the done area based on whether or not the expression evaluated to true or</p>



<p class="wp-block-paragraph">false.</p>



<p class="wp-block-paragraph">label while top you know which contains a conditional branch and then like an unconditional</p>



<p class="wp-block-paragraph">jump so if a condition is true maybe we can jump into the body if the condition is false we&#8217;ll fall</p>



<p class="wp-block-paragraph">through to the next statement and do an unconditional jump to the done label if you don&#8217;t</p>



<p class="wp-block-paragraph">know conditional branching this is another one of the topics that i&#8217;ve covered in previous videos</p>



<p class="wp-block-paragraph">as we implement the while loop.</p>



<p class="wp-block-paragraph">So just keep in mind, there are other videos that I have</p>



<p class="wp-block-paragraph">that you should watch first</p>



<p class="wp-block-paragraph">if you don&#8217;t understand conditional branching or jumps.</p>



<p class="wp-block-paragraph">The reason that I&#8217;m going to kind of design</p>



<p class="wp-block-paragraph">the jumps like this where I&#8217;m going to say,</p>



<p class="wp-block-paragraph">let&#8217;s do a conditional branch.</p>



<p class="wp-block-paragraph">And basically if the loop evaluates to true,</p>



<p class="wp-block-paragraph">we&#8217;ll jump into the body of the loop.</p>



<p class="wp-block-paragraph">And if it doesn&#8217;t evaluate to true,</p>



<p class="wp-block-paragraph">then the conditional branch will allow execution</p>



<p class="wp-block-paragraph">to fall through down to the next statement,</p>



<p class="wp-block-paragraph">which will simply contain a jump to the done portion.</p>



<p class="wp-block-paragraph">to the done portion so basically as soon as the while loop is ready to break it gets uh implemented</p>



<p class="wp-block-paragraph">by an unconditional jump which was fallen through to by the conditional branch that would only jump</p>



<p class="wp-block-paragraph">into the body if uh expression was true i&#8217;m doing it this way because it&#8217;s usually a shorter jump</p>



<p class="wp-block-paragraph">uh to jump to the true area you know the the body of the while loop and remember conditional</p>



<p class="wp-block-paragraph">branching instructions have a maximum you know jump reach of about 128 bytes so if you try to</p>



<p class="wp-block-paragraph">128 bytes. So if you try to jump too far, like for example, if you wanted to, you could reverse</p>



<p class="wp-block-paragraph">the logic to where you could say, if an expression is true, let&#8217;s jump to the done portion and say,</p>



<p class="wp-block-paragraph">we&#8217;re going to break the loop. If the expression was false, we&#8217;ll jump into the body. You could</p>



<p class="wp-block-paragraph">do that. But then if the body of your while loop was too long, maybe it was so long that the last</p>



<p class="wp-block-paragraph">instruction was greater than 128 bytes away from the top. Then by the time you wanted to</p>



<p class="wp-block-paragraph">let&#8217;s see yeah if you have if you have too long of while loops you can&#8217;t jump more than 128</p>



<p class="wp-block-paragraph">instructions away so that&#8217;s a limitation of contentional branching so I just I want to put</p>



<p class="wp-block-paragraph">the biggest jump on an unconditional jump instruction because it doesn&#8217;t have a limitation</p>



<p class="wp-block-paragraph">like that I was having a hard time imagining what I was about to say just now for the</p>



<p class="wp-block-paragraph">the reversal I guess I&#8217;m just going to ignore the reversal scenario and we&#8217;ll just do it the</p>



<p class="wp-block-paragraph">and we&#8217;ll just do it the regular way.</p>



<p class="wp-block-paragraph">Anyway, so we want to have a conditional jump that either jumps into the body or to the done area.</p>



<p class="wp-block-paragraph">And then at the very bottom, we want to have an unconditional jump to the top,</p>



<p class="wp-block-paragraph">which basically means every time we get to the bottom of the while loop body,</p>



<p class="wp-block-paragraph">we&#8217;re just going to jump up to the while top.</p>



<p class="wp-block-paragraph">Actually, I&#8217;ll just say to while top.</p>



<p class="wp-block-paragraph">Remember again, the regular jump instructions,</p>



<p class="wp-block-paragraph">maybe I&#8217;ll take out the U here.</p>



<p class="wp-block-paragraph">The regular jump instructions don&#8217;t have a limitation</p>



<p class="wp-block-paragraph">on how far they can jump.</p>



<p class="wp-block-paragraph">So that should be fine.</p>



<p class="wp-block-paragraph">And that&#8217;s the basic idea of implementing a while loop.</p>



<p class="wp-block-paragraph">Maybe I should draw just a quick diagram</p>



<p class="wp-block-paragraph">before we start looking at the code,</p>



<p class="wp-block-paragraph">just to make sure everybody of different learning styles</p>



<p class="wp-block-paragraph">understands what I&#8217;m talking about.</p>



<p class="wp-block-paragraph">So we&#8217;ll, let&#8217;s see, eval.</p>



<p class="wp-block-paragraph">I&#8217;m still adjusting my pen and you know what?</p>



<p class="wp-block-paragraph">You know what? It looked a lot better before I hit record.</p>



<p class="wp-block-paragraph">Eval the expression.</p>



<p class="wp-block-paragraph">So I&#8217;m going to first evaluate the expression.</p>



<p class="wp-block-paragraph">If it evaluates to true, we&#8217;ll put a green arrow here and I&#8217;ll put like a T for true.</p>



<p class="wp-block-paragraph">Then this will be the body of the while loop.</p>



<p class="wp-block-paragraph">I&#8217;ll say like the body.</p>



<p class="wp-block-paragraph">If it evaluates to false, let&#8217;s see.</p>



<p class="wp-block-paragraph">I&#8217;ll just put that in red and I&#8217;ll put an F here then this is just going to be the done area</p>



<p class="wp-block-paragraph">right so you can imagine we evaluate an expression using the compare instruction in assembly and</p>



<p class="wp-block-paragraph">based on the results of comparing something whatever it is that your condition is then we</p>



<p class="wp-block-paragraph">you know we we either branch to the done area or we branch to the to the body area</p>



<p class="wp-block-paragraph">want to have a more complicated while loop and you don&#8217;t want to put a huge</p>



<p class="wp-block-paragraph">amount of expressions or if you don&#8217;t want to logically concatenate a bunch of</p>



<p class="wp-block-paragraph">different components into the expression you know that&#8217;s fair I usually write my</p>



<p class="wp-block-paragraph">while loops in real life as just while true and then I break when certain</p>



<p class="wp-block-paragraph">conditions are met you can do that too we&#8217;re not going to talk about that in</p>



<p class="wp-block-paragraph">this video but you could just have a while true so you always jump to the top</p>



<p class="wp-block-paragraph">and there&#8217;s no branching that goes to while done but then throughout the loop</p>



<p class="wp-block-paragraph">loop you can just sort of check to see if certain conditions are met and if they are then you&#8217;ll do</p>



<p class="wp-block-paragraph">a branch to the done area and if they&#8217;re not then by the time you make it down to the bottom of the</p>



<p class="wp-block-paragraph">loop then it just automatically jumps to the top although you got to make sure with the the reach</p>



<p class="wp-block-paragraph">of conditional branching you probably want to test to see if your condition is true or false or</p>



<p class="wp-block-paragraph">whatever if it means we&#8217;re going to continue the loop then you probably just want to do a conditional</p>



<p class="wp-block-paragraph">then you probably just want to do a conditional branch that jumps down a little bit</p>



<p class="wp-block-paragraph">so that it can continue the body of the loop.</p>



<p class="wp-block-paragraph">And then the part that it skipped over,</p>



<p class="wp-block-paragraph">just a little part should be an unconditional jump that jumps out of the loop.</p>



<p class="wp-block-paragraph">That way, it doesn&#8217;t matter how big your while loop body is,</p>



<p class="wp-block-paragraph">you can always jump out of the loop.</p>



<p class="wp-block-paragraph">But we&#8217;re not going to talk about that in this video.</p>



<p class="wp-block-paragraph">Anyway, so we evaluate the expression.</p>



<p class="wp-block-paragraph">If it&#8217;s true, we go to the body.</p>



<p class="wp-block-paragraph">If it&#8217;s false, we go to done.</p>



<p class="wp-block-paragraph">After the body is done executing,</p>



<p class="wp-block-paragraph">then we just jump back up to the top where we evaluate the expression.</p>



<p class="wp-block-paragraph">where we evaluate the expression.</p>



<p class="wp-block-paragraph">I&#8217;ll put while here just to make it more clear that we&#8217;re talking about the basic</p>



<p class="wp-block-paragraph">idea of a while loop.</p>



<p class="wp-block-paragraph">Not too hard, you know.</p>



<p class="wp-block-paragraph">And then if you wanted to implement a do while loop, just make sure that you always</p>



<p class="wp-block-paragraph">evaluate the body at least once.</p>



<p class="wp-block-paragraph">That&#8217;s really the only difference.</p>



<p class="wp-block-paragraph">But that&#8217;s up to you.</p>



<p class="wp-block-paragraph">This is just a regular while loop video.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So we&#8217;ve kind of talked about it a little bit.</p>



<p class="wp-block-paragraph">We&#8217;ve sort of, you know, drawn it out in a diagram and put some regular code in.</p>



<p class="wp-block-paragraph">and put some regular code in let&#8217;s set up an actual assembly program that will do this so for starters</p>



<p class="wp-block-paragraph">again i&#8217;m not going to show you my make file because i&#8217;ve already made other videos where i</p>



<p class="wp-block-paragraph">explained how to make a make file from scratch same thing goes for hybrid programs i&#8217;m going</p>



<p class="wp-block-paragraph">to have a driver which is a c plus plus module that just sort of calls on this assembly module</p>



<p class="wp-block-paragraph">if you want to know how to make hybrid programs or you know drivers or you know whatever see my</p>



<p class="wp-block-paragraph">to be talking about looping only. Okay, so let me get my solution up here. My source code is called</p>



<p class="wp-block-paragraph">looper. And I&#8217;m just going to copy paste the data section for my program real fast, just so you can</p>



<p class="wp-block-paragraph">see it. Okay, so here&#8217;s the data section. Again, this is not a basics for assembly video. If you</p>



<p class="wp-block-paragraph">don&#8217;t know how to do a data section in Yasm, see my other videos. But for now, I&#8217;m just going to say</p>



<p class="wp-block-paragraph">like the actual array of bytes and then a length and all I&#8217;m doing is printing out messages you</p>



<p class="wp-block-paragraph">know begin the wild test your numbers will be printed back to you until you decide to quit so</p>



<p class="wp-block-paragraph">that&#8217;s going to be printed to the user right away then every time the program wants a number from</p>



<p class="wp-block-paragraph">the user it&#8217;ll just ask you know please enter a number or 99 to quit and then it&#8217;ll prefix</p>



<p class="wp-block-paragraph">the echo back it&#8217;ll say you entered and then it will actually print the number and then when you</p>



<p class="wp-block-paragraph">we&#8217;re done and i&#8217;m going to use an external uh function that i have available to just kind of</p>



<p class="wp-block-paragraph">like input and output numbers this video is not about uh input and outputting and external libraries</p>



<p class="wp-block-paragraph">if you&#8217;re interested you could probably just link a hybrid program and use printf and scan</p>



<p class="wp-block-paragraph">f to very easily do input and output but that&#8217;s not what this video is about see my other videos</p>



<p class="wp-block-paragraph">then i have crlf which is just a carriage return in line feed uh you know select the cursor goes</p>



<p class="wp-block-paragraph">You know select the cursor goes to the next line and then I have like a system call code to just print and</p>



<p class="wp-block-paragraph">Then a file descriptor just to print a standard output again. That&#8217;s explained in other videos</p>



<p class="wp-block-paragraph">So now I&#8217;m ready to start copy pasting the main portion of my program</p>



<p class="wp-block-paragraph">So first off I&#8217;m going to start the text section, which is where the instructions go in the ASM</p>



<p class="wp-block-paragraph">So there it is and then I&#8217;m going to copy paste</p>



<p class="wp-block-paragraph">of external symbols. So I just have a little library that I&#8217;m using that makes it easier for</p>



<p class="wp-block-paragraph">me to input and output integers. So you can do this any way you want, or you can hard code a</p>



<p class="wp-block-paragraph">number in the globals area. If you don&#8217;t want to deal with input and output while you&#8217;re learning</p>



<p class="wp-block-paragraph">how to do loops, that&#8217;s totally fine. But then the entry point is going to be a function called</p>



<p class="wp-block-paragraph">looper. So this is my function. And again, this is a hybrid program. So the main function or the</p>



<p class="wp-block-paragraph">be present in my assembly module the driver is going to be a c plus plus module that just calls</p>



<p class="wp-block-paragraph">on a function named looper so that means this function is going to get called from another</p>



<p class="wp-block-paragraph">module and that&#8217;s why i have to mark it as global and then it is a function so i&#8217;m going to call</p>



<p class="wp-block-paragraph">return at the end of it to say we&#8217;re done and then within this function i&#8217;m just going to call two</p>



<p class="wp-block-paragraph">other functions that i&#8217;m about to create one is called while test which is going to actually do</p>



<p class="wp-block-paragraph">the while loop and the other is called crlf which just print which just prints a new line for me i</p>



<p class="wp-block-paragraph">which just prints a new line for me.</p>



<p class="wp-block-paragraph">I don&#8217;t know why I do it that way, but I want to.</p>



<p class="wp-block-paragraph">Sorry, not sorry.</p>



<p class="wp-block-paragraph">So this is the real meat of the function here.</p>



<p class="wp-block-paragraph">Let&#8217;s start, well, the real meat of the code or the video.</p>



<p class="wp-block-paragraph">Let&#8217;s start a function called while test.</p>



<p class="wp-block-paragraph">You can see it&#8217;s got a void signature with no arguments,</p>



<p class="wp-block-paragraph">so it doesn&#8217;t really, you know, take anything or return anything.</p>



<p class="wp-block-paragraph">I&#8217;m going to use register R12 to hold the user&#8217;s input</p>



<p class="wp-block-paragraph">so that I can, you know, print it out and stuff.</p>



<p class="wp-block-paragraph">print it out and stuff so that means I have to do a preservation of R12 because it&#8217;s a</p>



<p class="wp-block-paragraph">callee saved for the ABI which you should respect so I&#8217;m going to push it at the beginning</p>



<p class="wp-block-paragraph">and then I&#8217;m going to pop it at the end and then this is a function so I have to return</p>



<p class="wp-block-paragraph">at the end of the function let me just double check that there&#8217;s nothing else weird at the</p>



<p class="wp-block-paragraph">bottom of that nope okay so we&#8217;ve got the prologue and epilogue the wild test function</p>



<p class="wp-block-paragraph">maybe I should copy paste my crlf real fast my crlf function it&#8217;s just sad but</p>



<p class="wp-block-paragraph">it&#8217;s also kind of cute right it does nothing except just print out a new line</p>



<p class="wp-block-paragraph">that&#8217;s all it does this video is not about that so at this point I should</p>



<p class="wp-block-paragraph">have a program that probably works let&#8217;s see if it does I&#8217;m gonna do clear and</p>



<p class="wp-block-paragraph">make run again if you want to know how to use make files or compile or link or</p>



<p class="wp-block-paragraph">anything like that see my other videos so I&#8217;m gonna run it and it just says</p>



<p class="wp-block-paragraph">which is some code that we&#8217;re not looking at.</p>



<p class="wp-block-paragraph">And then it says it&#8217;s regain control.</p>



<p class="wp-block-paragraph">And this line in the middle, which is just an empty new line,</p>



<p class="wp-block-paragraph">that&#8217;s definitely from the assembly program.</p>



<p class="wp-block-paragraph">Because at the top here we have CRLF.</p>



<p class="wp-block-paragraph">If I call it multiple times CRLF,</p>



<p class="wp-block-paragraph">then you&#8217;ll see there are multiple blank lines.</p>



<p class="wp-block-paragraph">All right, I&#8217;m gonna take that out.</p>



<p class="wp-block-paragraph">Now let&#8217;s continue with while test.</p>



<p class="wp-block-paragraph">So what should we do here?</p>



<p class="wp-block-paragraph">The first thing that we should do is print an intro message</p>



<p class="wp-block-paragraph">message just to let the user know that we&#8217;re about to you know begin our while</p>



<p class="wp-block-paragraph">tests and if we run the program one more time we should see that message now</p>



<p class="wp-block-paragraph">begin the while test your numbers will be printed back to you system calls and</p>



<p class="wp-block-paragraph">simple printing is covered in other videos so now uh you know for me I kind</p>



<p class="wp-block-paragraph">of like to init all of my loops even if it&#8217;s a while loop and not just a for</p>



<p class="wp-block-paragraph">loop or anything so I always have an extra label that I like to call init</p>



<p class="wp-block-paragraph">or before or something like that.</p>



<p class="wp-block-paragraph">So I have a label now called while test underscore init,</p>



<p class="wp-block-paragraph">and it&#8217;s just where I&#8217;m gonna initialize</p>



<p class="wp-block-paragraph">whatever it is that I think I need to initialize</p>



<p class="wp-block-paragraph">so that the loop will actually work.</p>



<p class="wp-block-paragraph">If you look here, all I&#8217;m really doing is setting R12 to zero</p>



<p class="wp-block-paragraph">because what I&#8217;m gonna do is stop the loop.</p>



<p class="wp-block-paragraph">I&#8217;m gonna break the loop whenever the user enters a 99.</p>



<p class="wp-block-paragraph">So I don&#8217;t know what&#8217;s inside of R12</p>



<p class="wp-block-paragraph">when we first start this function.</p>



<p class="wp-block-paragraph">And I just wanna make sure that it&#8217;s not 99,</p>



<p class="wp-block-paragraph">the stopping number at the very start so I&#8217;m just going to set it to zero. So</p>



<p class="wp-block-paragraph">another note about my labels you don&#8217;t have to do it this way but I love to</p>



<p class="wp-block-paragraph">write labels where the first part of the label is always the function that the</p>



<p class="wp-block-paragraph">label is inside of so notice how the function is named while test and so my</p>



<p class="wp-block-paragraph">label is always while test underscore something and I&#8217;m putting init here</p>



<p class="wp-block-paragraph">just to say we&#8217;re initializing the loop but if you had a function that had a</p>



<p class="wp-block-paragraph">had a lot of stuff going on in it for starters you should probably be breaking up that function</p>



<p class="wp-block-paragraph">into multiple functions but but assuming you didn&#8217;t uh you should probably do another underscore</p>



<p class="wp-block-paragraph">and then like another component and then another underscore based on what giant chunk of your</p>



<p class="wp-block-paragraph">function you&#8217;re inside of so if there was like an if part a while part an input part an output part</p>



<p class="wp-block-paragraph">you probably want to you know stick that into your labels your labels will get huge but for me</p>



<p class="wp-block-paragraph">infused in assembly and this makes it easier.</p>



<p class="wp-block-paragraph">So we&#8217;re going to initialize so that we can run our while loop and then the next thing</p>



<p class="wp-block-paragraph">we&#8217;re going to do is implement the top of the while loop.</p>



<p class="wp-block-paragraph">So remember if we looked at this code up here, maybe if I drag this over to the side and</p>



<p class="wp-block-paragraph">pin it to the top for a little while, you can see that the top of the while loop is</p>



<p class="wp-block-paragraph">where we kind of evaluate the expression to see if we need to keep going or not.</p>



<p class="wp-block-paragraph">jump into the ending area, the done area. So the top, whoops, the top is always for that.</p>



<p class="wp-block-paragraph">We&#8217;ll say first, I&#8217;m going to ask, are we done? So, you know, how do we know if we&#8217;re done?</p>



<p class="wp-block-paragraph">In this particular while loop, we want to compare the user&#8217;s input, which is R12 to the number 99.</p>



<p class="wp-block-paragraph">And if it&#8217;s equal, then we will quit, which means also if it&#8217;s not equal, we will jump into the</p>



<p class="wp-block-paragraph">So by the way, you&#8217;re probably wondering how did R12 get the user&#8217;s input?</p>



<p class="wp-block-paragraph">Well, we&#8217;re going to do that as the next step.</p>



<p class="wp-block-paragraph">And of course, your design pattern may vary a little bit.</p>



<p class="wp-block-paragraph">No, that&#8217;s okay.</p>



<p class="wp-block-paragraph">I just like to implement it this way.</p>



<p class="wp-block-paragraph">So first thing we&#8217;re going to do is compare R12 with 99.</p>



<p class="wp-block-paragraph">And that&#8217;s why I&#8217;ve written this comment here, just like the blank while comparison part.</p>



<p class="wp-block-paragraph">And I guess I could have put this R12 not equal to 99 up at the top, but then it kind</p>



<p class="wp-block-paragraph">of feels like I&#8217;m leaving these other two instructions.</p>



<p class="wp-block-paragraph">So I moved it down one.</p>



<p class="wp-block-paragraph">these other two instructions so I moved it down one so basically as long as you know we compare</p>



<p class="wp-block-paragraph">R12 and 99 compare and conditional branching is covered in other videos but we compare those two</p>



<p class="wp-block-paragraph">values and then we say if R12 is not equal to 99 then jump to the body and we expect that the body</p>



<p class="wp-block-paragraph">will be like a short jump which will be within the range of a conditional branch</p>



<p class="wp-block-paragraph">So anyway, if the not equal branch didn&#8217;t happen, that means R12 is equal to 99.</p>



<p class="wp-block-paragraph">At that point, execution falls through to line 84, and we&#8217;ll just unconditionally jump out of the while loop.</p>



<p class="wp-block-paragraph">So basically we&#8217;re saying, if it&#8217;s true, we continue looping.</p>



<p class="wp-block-paragraph">If it&#8217;s not true, we just jump outside of the loop.</p>



<p class="wp-block-paragraph">We&#8217;re just totally done with the while loop.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So then we need a body, because obviously we&#8217;re going to jump into the body here.</p>



<p class="wp-block-paragraph">that means I&#8217;m going to just copy paste another little set of code here.</p>



<p class="wp-block-paragraph">Right after that unconditional jump.</p>



<p class="wp-block-paragraph">So now we got the body.</p>



<p class="wp-block-paragraph">Notice how I put a little comment here that has a brace just to indicate to you,</p>



<p class="wp-block-paragraph">hey, this is the beginning of the actual while loop body,</p>



<p class="wp-block-paragraph">just to make it a little bit more clear.</p>



<p class="wp-block-paragraph">And what are we going to do inside of the body?</p>



<p class="wp-block-paragraph">We&#8217;re just going to ask the user for some input.</p>



<p class="wp-block-paragraph">So I&#8217;m printing a simple message here,</p>



<p class="wp-block-paragraph">and then I&#8217;m calling on my helper function</p>



<p class="wp-block-paragraph">to just actually input a number from the user.</p>



<p class="wp-block-paragraph">I&#8217;m going to store that number into R12.</p>



<p class="wp-block-paragraph">So that&#8217;s how R12 gets the numbers, gets the user&#8217;s input.</p>



<p class="wp-block-paragraph">And the way I&#8217;ve written this, if the user enters a 99,</p>



<p class="wp-block-paragraph">it&#8217;ll echo it back to the user and then it&#8217;ll break the loop afterwards.</p>



<p class="wp-block-paragraph">So, you know, if you wanted to rearrange things like I talked about before,</p>



<p class="wp-block-paragraph">where you input before you check to see if you&#8217;re going to keep going, you could do that.</p>



<p class="wp-block-paragraph">But it would be a little harder to echo the user&#8217;s input back to them before you break.</p>



<p class="wp-block-paragraph">I don&#8217;t know. It&#8217;s up to you.</p>



<p class="wp-block-paragraph">I don&#8217;t know it&#8217;s up to you anyway so we grab input from the user and then we print another</p>



<p class="wp-block-paragraph">message basically saying here&#8217;s the thing that you inputted no problem and then again we use</p>



<p class="wp-block-paragraph">one of my helper functions to actually spit the number back out at them so this is not</p>



<p class="wp-block-paragraph">a very complicated body it&#8217;s just asking for a number and then printing the number back to them</p>



<p class="wp-block-paragraph">and then after that I&#8217;m going to do another label and I&#8217;m going to call it the body bottom</p>



<p class="wp-block-paragraph">we don&#8217;t really have to do this label but for clarity I think it&#8217;s probably a good idea</p>



<p class="wp-block-paragraph">I think it&#8217;s probably a good idea.</p>



<p class="wp-block-paragraph">So the very bottom of the while loop&#8217;s body is usually where you don&#8217;t do any more instructions</p>



<p class="wp-block-paragraph">that are part of the work of the while loop&#8217;s body,</p>



<p class="wp-block-paragraph">but just sort of the place where you jump back up to the top</p>



<p class="wp-block-paragraph">so you can evaluate and decide to continue or not again.</p>



<p class="wp-block-paragraph">So notice how I&#8217;m using an unconditional jump here.</p>



<p class="wp-block-paragraph">That&#8217;s a good idea because again, if you have like a huge while loop body,</p>



<p class="wp-block-paragraph">you might end up surpassing the threshold of 128 bytes</p>



<p class="wp-block-paragraph">of 128 bytes and then you&#8217;ll get a assembler error that says</p>



<p class="wp-block-paragraph">I can never remember this. It&#8217;s like a</p>



<p class="wp-block-paragraph">jump out of range error or something like that. Basically, if you do a conditional branch to jump up the top</p>



<p class="wp-block-paragraph">because some people like to check to see</p>



<p class="wp-block-paragraph">if they should continue the loop, they like to check for that at the bottom. I&#8217;ve done that before.</p>



<p class="wp-block-paragraph">And then if true, then we&#8217;ll jump to the top of the loop. But if the loop is too big, that won&#8217;t work. So</p>



<p class="wp-block-paragraph">I just like to take a long jump to the top of the loop and then decide if I&#8217;m going to keep going at the very top.</p>



<p class="wp-block-paragraph">if I&#8217;m going to keep going at the very top. And then there&#8217;s a comment saying, hey, that&#8217;s the</p>



<p class="wp-block-paragraph">end of the body. Okay, no problem. Now let&#8217;s do the done label, which is basically where we jump</p>



<p class="wp-block-paragraph">if the loop is actually finished. So remember, if this expression right here evaluates to false,</p>



<p class="wp-block-paragraph">then execution is going to fall through to line 84, where we jump to this while test done label.</p>



<p class="wp-block-paragraph">And so I&#8217;m just going to put the while test done label right here. So we&#8217;re done. So the done is</p>



<p class="wp-block-paragraph">So we&#8217;re done. So the done is not part of the loop. It comes after the loop. That&#8217;s this right</p>



<p class="wp-block-paragraph">here on line nine of the little notepad. And we can just kind of do whatever we want. At that</p>



<p class="wp-block-paragraph">point, we can return to a caller, we can just do other stuff, we can, you know, do a different</p>



<p class="wp-block-paragraph">loop or, you know, whatever, we&#8217;re just done with the original loop. For me, I&#8217;m just going to say</p>



<p class="wp-block-paragraph">goodbye with this little print to just sort of like, you know, print an exit message. And then</p>



<p class="wp-block-paragraph">we&#8217;ll do the epilogue where we restore R12. And then we just return to the caller,</p>



<p class="wp-block-paragraph">the driver worry about exiting the program okay so if we&#8217;ve done this correctly we should now have</p>



<p class="wp-block-paragraph">a working program let&#8217;s see let&#8217;s see okay let&#8217;s enter a number let&#8217;s do 22 and it says you enter</p>



<p class="wp-block-paragraph">22 and let&#8217;s do 55 and we just we can enter any numbers we want and as long as we&#8217;re not entering</p>



<p class="wp-block-paragraph">99 the program will just continue forever so this is a while loop if i want to quit i do 99</p>



<p class="wp-block-paragraph">breaks at the top it breaks by jumping down to the done area where we print our goodbye message</p>



<p class="wp-block-paragraph">which just is end while test and then if we run this again if i do 99 from the start then it just</p>



<p class="wp-block-paragraph">immediately breaks you know it prints out what you entered but then it immediately breaks</p>



<p class="wp-block-paragraph">and that&#8217;s it that&#8217;s uh the basics for how to write a while loop you just use basically</p>



<p class="wp-block-paragraph">layered on top of an abstract concept of what you think a while loop is,</p>



<p class="wp-block-paragraph">or what I guess the world thinks a while loop is.</p>



<p class="wp-block-paragraph">Okay, thank you so much for watching this video.</p>



<p class="wp-block-paragraph">I hope you learned a little bit of stuff and had a little bit of fun.</p>



<p class="wp-block-paragraph">I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">Hey everybody.</p>



<p class="wp-block-paragraph">Thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">if you could do me a please a small little favor could you please subscribe and follow this channel</p>



<p class="wp-block-paragraph">or these videos or whatever it is you do on the current social media website that you&#8217;re looking</p>



<p class="wp-block-paragraph">at right now it would really mean the world to me and it&#8217;ll help make more videos and grow this</p>



<p class="wp-block-paragraph">community so we&#8217;ll be able to do more videos longer videos better videos or just i&#8217;ll be able</p>



<p class="wp-block-paragraph">to keep making videos in general so please do do me a kindness and uh and subscribe you know</p>



<p class="wp-block-paragraph">I&#8217;m sleeping in the middle of the night and I just wake up because I know somebody subscribed or followed.</p>



<p class="wp-block-paragraph">It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could troll me if you want to just wake me up in the middle of the night.</p>



<p class="wp-block-paragraph">Just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">I promise that&#8217;s what will happen.</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now, you should see a QR code which you can scan in order to go to the website,</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video.</p>



<p class="wp-block-paragraph">and it&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p class="wp-block-paragraph">i published and the services and tutorials and things that i offer and all that good stuff and</p>



<p class="wp-block-paragraph">if you have a suggestion for uh uh clarifications or errata or just future videos that you want to</p>



<p class="wp-block-paragraph">see please leave a comment or if you just want to say hey what&#8217;s up what&#8217;s going on you know</p>



<p class="wp-block-paragraph">just send me a comment whatever i also wake up for those in the middle of the night i get</p>



<p class="wp-block-paragraph">it would really mean the world to me. I would really appreciate it.</p>



<p class="wp-block-paragraph">So again, thank you so much for watching this video and</p>



<p class="wp-block-paragraph">enjoy the cool music as I fade into</p>



<p class="wp-block-paragraph">the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-while-loops-explained-step-by-step-in-yasm-from-concept-to-working-program/">x86-64 Assembly While Loops Explained Step by Step in YASM &#8211; From Concept to Working Program</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/x86-64-assembly-while-loops-explained-step-by-step-in-yasm-from-concept-to-working-program/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>x86-64 Assembly Jump Instructions Explained: Unconditional JMP with Full Example in Yasm</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 11 Jan 2026 01:54:51 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly control flow]]></category>
		<category><![CDATA[assembly jump instructions]]></category>
		<category><![CDATA[assembly language basics]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[ed jorgensen textbook]]></category>
		<category><![CDATA[jmp instruction]]></category>
		<category><![CDATA[learning assembly]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[unconditional jump]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[x86-64 programming]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=278</guid>

					<description><![CDATA[<p>Learn how unconditional jump instructions (JMP) work in x86-64 assembly language using Yasm. This tutorial explains labels, unlimited jump range, and demonstrates skipping code sections with practical examples. Essential knowledge before studying conditional branching in modern assembly programming.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/">x86-64 Assembly Jump Instructions Explained: Unconditional JMP with Full Example in Yasm</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="x86-64 Assembly Jump Instructions Explained: Unconditional JMP with Full Example in Yasm" width="1380" height="776" src="https://www.youtube.com/embed/jkc7ydqAp7M?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">In this beginner-to-intermediate assembly language tutorial, we dive deep into unconditional jump instructions (JMP) in x86-64 assembly using Yasm syntax.</p>



<p class="wp-block-paragraph">We cover:</p>



<ul class="wp-block-list">
<li>What unconditional jumps really are (basically a &#8220;go to&#8221; for assembly)</li>



<li>How labels work and how to create them</li>



<li>Why JMP has unlimited range (unlike conditional jumps)</li>



<li>Practical demo showing how to skip code sections using jumps</li>



<li>Comparison between jumping over code vs letting it execute</li>



<li>Quick look at why this matters before learning conditional branching</li>
</ul>



<p class="wp-block-paragraph">We also reference the excellent free open-source textbook by Professor Ed Jorgensen (May 2024 version) which is highly recommended for anyone serious about learning x86-64 assembly.</p>



<p class="wp-block-paragraph">Whether you&#8217;re preparing for university courses, reverse engineering, operating systems development, or just love low-level programming, this video will give you a clear understanding of how unconditional control flow works in modern x86-64 assembly.</p>



<p class="wp-block-paragraph">Next video will cover conditional jumps (je, jne, jg, jl, etc.) and their limitations.</p>



<p class="wp-block-paragraph">Enjoy the video and happy coding at the machine level!</p>



<p class="wp-block-paragraph">Introduction to Jump Instructions 00:00:00<br>Recommended Free Assembly Textbook 00:00:23<br>What Unconditional Jumps Actually Do 00:01:27<br>Labels Explained with Examples 00:02:40<br>Unlimited Jump Range Advantage 00:04:43<br>Overview of the Demonstration Program 00:06:56<br>Building and Running the Jump Test 00:09:21<br>Live Jump Test Demonstration 00:10:53<br>Effect of Removing the Jump Instruction 00:13:50<br>Jumping in Different Directions Example 00:14:58<br>Summary and Next Video Teaser 00:17:28<br>Closing Remarks and Call to Action 00:17:44</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there.</p>



<p class="wp-block-paragraph">In this video, we&#8217;re going to be talking about jump instructions in assembly.</p>



<p class="wp-block-paragraph">This video is going to be about x86-64 Yasm assembly,</p>



<p class="wp-block-paragraph">but I think probably anyone who&#8217;s interested in jump instructions</p>



<p class="wp-block-paragraph">will benefit from this video because the concept is usually the same</p>



<p class="wp-block-paragraph">throughout any system that you might use.</p>



<p class="wp-block-paragraph">So for starters, I want to direct your attention to a textbook</p>



<p class="wp-block-paragraph">that I think is wonderful.</p>



<p class="wp-block-paragraph">This is an open source free textbook that will help you become an expert in assembly.</p>



<p class="wp-block-paragraph">It&#8217;s not mine, I didn&#8217;t write it.</p>



<p class="wp-block-paragraph">The author is Professor Ed Jorgensen, PhD.</p>



<p class="wp-block-paragraph">He releases this textbook for free.</p>



<p class="wp-block-paragraph">It&#8217;s under a copyleft license so you can literally just go to his website and download it and</p>



<p class="wp-block-paragraph">send it to your friends and everything and it&#8217;s wonderful.</p>



<p class="wp-block-paragraph">This book will take you from zero to hero when it comes to Yasm Assembly.</p>



<p class="wp-block-paragraph">It&#8217;s wonderful and amazing.</p>



<p class="wp-block-paragraph">This is the book and I just want to show you the section on jump instructions real fast</p>



<p class="wp-block-paragraph">and then I&#8217;ll talk about them a little bit and then I&#8217;ll show you a sample program that</p>



<p class="wp-block-paragraph">uses jump instructions.</p>



<p class="wp-block-paragraph">So this version of the book that I&#8217;m working with right now is May 2024 version 1.1.56.</p>



<p class="wp-block-paragraph">I&#8217;m going to go down to let&#8217;s see section 7 instruction set overview.</p>



<p class="wp-block-paragraph">Inside of there there&#8217;s another subsection called where the heck is it control instructions</p>



<p class="wp-block-paragraph">instructions 7.7 within that there&#8217;s a another subsection called 7.7.2 that&#8217;s</p>



<p class="wp-block-paragraph">why I look this other not one of the many reasons that I love this book it</p>



<p class="wp-block-paragraph">has so many subsections there&#8217;s just so many yummy subsections to organize</p>



<p class="wp-block-paragraph">everything in a way that you can find it all so fast and okay so we&#8217;re looking</p>



<p class="wp-block-paragraph">at unconditional control instructions in other words a jump instruction if</p>



<p class="wp-block-paragraph">you&#8217;re an old-school programmer especially if you use some sort of like</p>



<p class="wp-block-paragraph">if you use some sort of like a basic language or a language with go-to&#8217;s you might recognize jumps</p>



<p class="wp-block-paragraph">as just being a go-to meaning we&#8217;re not actually going to call a function and then return from it</p>



<p class="wp-block-paragraph">which is what the modern programs tend to do we&#8217;re just going to say let&#8217;s write a jump instruction</p>



<p class="wp-block-paragraph">and we will literally just change execution to to jump to some other location just kind of go there</p>



<p class="wp-block-paragraph">forever maybe we come back but if we do it&#8217;s going to be because there was a different jump instruction</p>



<p class="wp-block-paragraph">instruction that told us to jump back.</p>



<p class="wp-block-paragraph">So we&#8217;re not calling and returning.</p>



<p class="wp-block-paragraph">We&#8217;re just going somewhere and that&#8217;s it.</p>



<p class="wp-block-paragraph">Obviously it&#8217;s a little bit more convenient to be able to call functions,</p>



<p class="wp-block-paragraph">but that&#8217;s sort of like an abstraction that has to be implemented after we</p>



<p class="wp-block-paragraph">understand how to jump. So anyway, the jump instruction is pretty simple.</p>



<p class="wp-block-paragraph">You just put JMP in Yasm anyway, and then follow it with a label.</p>



<p class="wp-block-paragraph">So, you know, just as a quick little recap here, what&#8217;s a label?</p>



<p class="wp-block-paragraph">imagine we have an assembly program here and maybe here&#8217;s our text section and we put some</p>



<p class="wp-block-paragraph">instructions maybe there&#8217;s like an entry point right here I&#8217;ll say a global entry point and</p>



<p class="wp-block-paragraph">literally just taking the word entry point and putting a colon after it now makes that a label</p>



<p class="wp-block-paragraph">so if there are any instructions underneath I&#8217;m gonna put a bunch of nopes then if someone somewhere</p>



<p class="wp-block-paragraph">to say jump entry point they should be able to go right here to instruction 8 and then start</p>



<p class="wp-block-paragraph">executing downward. I guess maybe I didn&#8217;t need to put the global keyword global just means let&#8217;s</p>



<p class="wp-block-paragraph">make this label available to other modules within the same program so if you have a multi-source</p>



<p class="wp-block-paragraph">program or a hybrid program with multiple different languages then you know you should do this but if</p>



<p class="wp-block-paragraph">it&#8217;s just a pure assembly program and there&#8217;s only one source code filed you don&#8217;t need to mark a</p>



<p class="wp-block-paragraph">Just as a quick example here, entry points, I&#8217;ll just put hello as a label and I&#8217;ll say like do exit stuff.</p>



<p class="wp-block-paragraph">So imagine on line 16, you add some instructions just to kind of exit.</p>



<p class="wp-block-paragraph">If I wanted to skip all these nope instructions for some reason, I could just do this.</p>



<p class="wp-block-paragraph">I could say jump hello.</p>



<p class="wp-block-paragraph">And what would happen is execution.</p>



<p class="wp-block-paragraph">Oh, I can use my pen.</p>



<p class="wp-block-paragraph">Execution would just sort of, you know, it would come into the text section.</p>



<p class="wp-block-paragraph">you know, it&#8217;d come into the text section.</p>



<p class="wp-block-paragraph">It would go down through the label and it would execute this first jump</p>



<p class="wp-block-paragraph">instruction and then execution would jump over the nopes into the hello label.</p>



<p class="wp-block-paragraph">And then, you know, if there was other stuff here, then it would get executed.</p>



<p class="wp-block-paragraph">So by jumping over the nopes,</p>



<p class="wp-block-paragraph">I&#8217;m essentially saying that the nopes should not actually end up being</p>



<p class="wp-block-paragraph">executed. They&#8217;ll be there in the program, but they won&#8217;t actually execute.</p>



<p class="wp-block-paragraph">So that&#8217;s the basics of a jump instruction. Okay.</p>



<p class="wp-block-paragraph">So what else do I need to tell you real fast?</p>



<p class="wp-block-paragraph">What else do I need to tell you real fast?</p>



<p class="wp-block-paragraph">Oh, one thing that&#8217;s really good about jump instructions is they have unlimited jump range.</p>



<p class="wp-block-paragraph">So you can jump from a place at the very, very beginning of your assembly program and</p>



<p class="wp-block-paragraph">jump to a place that is at the very, very, very end of your assembly program.</p>



<p class="wp-block-paragraph">There&#8217;s not going to be a limitation on how far you can jump.</p>



<p class="wp-block-paragraph">I mean, in theory, there&#8217;s a limit, but practically speaking, there&#8217;s not a limit.</p>



<p class="wp-block-paragraph">Why would you care that there&#8217;s not a limit?</p>



<p class="wp-block-paragraph">not a limit well because in a future video that i&#8217;m going to release we&#8217;re going to talk about</p>



<p class="wp-block-paragraph">conditional branching which is sort of a jump that only jumps if a certain condition is true</p>



<p class="wp-block-paragraph">and those have limited ranges where they can jump so there&#8217;s going to be a bunch of different</p>



<p class="wp-block-paragraph">instructions but one of the conditional branching instructions is jne and another one is jge and</p>



<p class="wp-block-paragraph">there&#8217;s another one that&#8217;s je basically you know jump if something is equal jump if something is</p>



<p class="wp-block-paragraph">can only jump about 128 bytes away.</p>



<p class="wp-block-paragraph">So after your assembler assembles and compiles</p>



<p class="wp-block-paragraph">down to object code,</p>



<p class="wp-block-paragraph">and then after your linker links your final executable,</p>



<p class="wp-block-paragraph">wherever it is that the instructions happen to end up</p>



<p class="wp-block-paragraph">inside of your program,</p>



<p class="wp-block-paragraph">the conditional jumps,</p>



<p class="wp-block-paragraph">the conditional branching instructions,</p>



<p class="wp-block-paragraph">they can&#8217;t jump more than 128 bytes away</p>



<p class="wp-block-paragraph">to some other instruction.</p>



<p class="wp-block-paragraph">So keep that in mind.</p>



<p class="wp-block-paragraph">Even if later on you graduate</p>



<p class="wp-block-paragraph">to making decisions in your program,</p>



<p class="wp-block-paragraph">like I&#8217;m going to do in the next video,</p>



<p class="wp-block-paragraph">in your program like i&#8217;m going to do in the next video you can only jump so far and if you have to</p>



<p class="wp-block-paragraph">jump too far you actually might not be able to jump at all unless you jump a very short jump</p>



<p class="wp-block-paragraph">to a regular jump instruction and then that jump instruction jumps very very far away that&#8217;s kind</p>



<p class="wp-block-paragraph">of the workaround for it i&#8217;m not going to talk about that in this video though this is not a</p>



<p class="wp-block-paragraph">video for uh conditional branching i just wanted you to be aware of one of the benefits of regular</p>



<p class="wp-block-paragraph">Okay, so we&#8217;re looking at the book here.</p>



<p class="wp-block-paragraph">There&#8217;s not really a whole lot to the jump instruction, just jump and then a label.</p>



<p class="wp-block-paragraph">We talked about its benefit over conditional branch instructions,</p>



<p class="wp-block-paragraph">but we also talked about its, I guess, its shortcoming,</p>



<p class="wp-block-paragraph">meaning it can&#8217;t actually make a decision.</p>



<p class="wp-block-paragraph">It will always jump to a label no matter what.</p>



<p class="wp-block-paragraph">There&#8217;s no condition.</p>



<p class="wp-block-paragraph">So there&#8217;s the book there, and now I&#8217;m going to make a sample program</p>



<p class="wp-block-paragraph">and show you how to run it.</p>



<p class="wp-block-paragraph">I&#8217;m just going to run it.</p>



<p class="wp-block-paragraph">I&#8217;m just gonna run it I&#8217;m show you what it does in order to implement conditional branches so for</p>



<p class="wp-block-paragraph">starters I want you to know that there&#8217;s a make file that I&#8217;ve generated under the hood and we&#8217;re</p>



<p class="wp-block-paragraph">not going to be talking about that in this video this is also a hybrid program so there&#8217;s a C++</p>



<p class="wp-block-paragraph">entry point a driver module under the hood of this we&#8217;re not going to talk about that if you</p>



<p class="wp-block-paragraph">want to know how to make hybrid programs you want to generate make files you want to learn the basics</p>



<p class="wp-block-paragraph">videos for now we&#8217;re only going to be talking about jump instructions so I&#8217;m</p>



<p class="wp-block-paragraph">going to skip a lot of information okay so for starters I&#8217;m going to make a</p>



<p class="wp-block-paragraph">little data section here and again this is explained in other videos but for now</p>



<p class="wp-block-paragraph">we&#8217;ll just trust that we can make a data section that contains strings C strings</p>



<p class="wp-block-paragraph">and other values so pretty much I&#8217;m just going to make a string called begin jump</p>



<p class="wp-block-paragraph">test just to announce to the user that we&#8217;re we&#8217;re going to start doing this</p>



<p class="wp-block-paragraph">We&#8217;re going to start doing this and then I&#8217;m going to make a string called this message</p>



<p class="wp-block-paragraph">should not appear.</p>



<p class="wp-block-paragraph">So in the code, I&#8217;m going to try to print that message, but then I&#8217;m going to jump over</p>



<p class="wp-block-paragraph">the call to print it just to prove to you that there are instructions that would print</p>



<p class="wp-block-paragraph">that message, but we&#8217;re jumping over them with the jump instruction.</p>



<p class="wp-block-paragraph">And then there&#8217;s like an exit message.</p>



<p class="wp-block-paragraph">And then there&#8217;s a CRLF, which is just a carriage return line feed.</p>



<p class="wp-block-paragraph">Again, all of this stuff is in other videos already.</p>



<p class="wp-block-paragraph">So we&#8217;re going to use system call one to print.</p>



<p class="wp-block-paragraph">We&#8217;re going to print a file descriptor one, which is just standard output for your program.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to start the text section where the actual code lives.</p>



<p class="wp-block-paragraph">So this text section is here and it&#8217;s supposed to be at line 37 already.</p>



<p class="wp-block-paragraph">I think I missed a bunch of lines.</p>



<p class="wp-block-paragraph">Oh no, I think I missed some comments.</p>



<p class="wp-block-paragraph">Anyway, so we have a text section here and an entry point and I&#8217;m calling it cool.</p>



<p class="wp-block-paragraph">calling it cool and I am marking it as global because in this particular program that I&#8217;m</p>



<p class="wp-block-paragraph">building it&#8217;s a hybrid program there&#8217;s going to be a C++ module that will call on our cool</p>



<p class="wp-block-paragraph">function so cool has to be global and then I&#8217;m just going to call on a method called jump test</p>



<p class="wp-block-paragraph">I don&#8217;t know I have the words load there I&#8217;m just going to get rid of that real fast locally and in</p>



<p class="wp-block-paragraph">my solution up above and so we&#8217;re going to call a function called jump test and then when we&#8217;re</p>



<p class="wp-block-paragraph">finished we&#8217;re going to return to the caller which is going to be the driver and that&#8217;ll</p>



<p class="wp-block-paragraph">pretty much be it.</p>



<p class="wp-block-paragraph">So if I comment this out real fast, let&#8217;s see,</p>



<p class="wp-block-paragraph">this might actually work.</p>



<p class="wp-block-paragraph">Let&#8217;s see if I can get it to run in the terminal.</p>



<p class="wp-block-paragraph">But there&#8217;s a bunch more code that we have to add, so I&#8217;m not really sure.</p>



<p class="wp-block-paragraph">So let&#8217;s do clear and make run.</p>



<p class="wp-block-paragraph">And it seems to not have a shared object directory.</p>



<p class="wp-block-paragraph">Let me pause the video while I copy paste one of my stupid libraries into the</p>



<p class="wp-block-paragraph">program. You don&#8217;t need this library.</p>



<p class="wp-block-paragraph">It just helps me print things.</p>



<p class="wp-block-paragraph">okay so now I have copy pasted my shared object which allows me to do extra printing stuffs</p>



<p class="wp-block-paragraph">just for just to make this demo easier for me but you don&#8217;t need to know it or you don&#8217;t need to have</p>



<p class="wp-block-paragraph">it to to learn jump instructions anyway so I&#8217;m going to do that again and now it actually prints</p>



<p class="wp-block-paragraph">something okay so hello from the main CPP driver and then it says the driver has regained control</p>



<p class="wp-block-paragraph">make a call to jump test here and then let&#8217;s start the actual jump test function. So I&#8217;m going to do</p>



<p class="wp-block-paragraph">well I guess this thing is kind of short I could copy paste the whole thing all at once.</p>



<p class="wp-block-paragraph">So let&#8217;s do yeah let&#8217;s just jump let&#8217;s just call the whole thing. Okay I&#8217;m going to copy paste the</p>



<p class="wp-block-paragraph">whole thing then I&#8217;ll explain it a little bit to you. So there is a function that I have in here</p>



<p class="wp-block-paragraph">It&#8217;s just a convenience function that I made so I can print a carriage return line feed.</p>



<p class="wp-block-paragraph">The real interesting thing here is the jump test function.</p>



<p class="wp-block-paragraph">So we were just making a call to jump test.</p>



<p class="wp-block-paragraph">Now we&#8217;re making the actual jump test function.</p>



<p class="wp-block-paragraph">It&#8217;s got a signature of just void with no arguments.</p>



<p class="wp-block-paragraph">So it&#8217;s not super interesting from the caller&#8217;s perspective, but it does some stuff.</p>



<p class="wp-block-paragraph">So for starters, it has an intro message.</p>



<p class="wp-block-paragraph">So this will print, you know, hello, welcome to the jump test.</p>



<p class="wp-block-paragraph">jump test. In fact, if I do a return call here,</p>



<p class="wp-block-paragraph">it should actually just print that and do nothing else. Right. Okay.</p>



<p class="wp-block-paragraph">Notice how it printed, begin the jump test.</p>



<p class="wp-block-paragraph">And then right after that,</p>



<p class="wp-block-paragraph">there&#8217;s a jump instruction just proving to you that we can jump over other</p>



<p class="wp-block-paragraph">instructions. So look at this,</p>



<p class="wp-block-paragraph">this piece of code should never actually be called because we&#8217;re going to jump</p>



<p class="wp-block-paragraph">over it. What it is, is it&#8217;s printing that jump shouldn&#8217;t happen message.</p>



<p class="wp-block-paragraph">at the top here jumps shouldn&#8217;t happen so it&#8217;s trying to print out this message should not appear</p>



<p class="wp-block-paragraph">but we&#8217;re going to jump over that by using this jump instruction here on line 66.</p>



<p class="wp-block-paragraph">Again note that the jump instruction is just jmp followed by a label the label specified has to be</p>



<p class="wp-block-paragraph">where you want to jump it&#8217;s never going to return from that place unless you specifically jump back</p>



<p class="wp-block-paragraph">somehow later on like i guess if we wanted to we could put a label on line 67 call it the return</p>



<p class="wp-block-paragraph">call it the return point and then jump back from it after the jump point in fact maybe that would</p>



<p class="wp-block-paragraph">be kind of interesting to do at the end of this video but otherwise we&#8217;re gonna you know just</p>



<p class="wp-block-paragraph">let&#8217;s see we&#8217;re gonna end up jumping over so let me reduce the front size just for a second here</p>



<p class="wp-block-paragraph">so imagine execution uh comes into this program you know we&#8217;re executing uh instructions we&#8217;re</p>



<p class="wp-block-paragraph">calling crlf we&#8217;re just executing executing as soon as we hit this jump instruction then execution</p>



<p class="wp-block-paragraph">then execution jumps over into the label that I specified.</p>



<p class="wp-block-paragraph">So this whole code section here just never even gets called.</p>



<p class="wp-block-paragraph">So that&#8217;s why we will not see that message.</p>



<p class="wp-block-paragraph">And then at the very end, all I&#8217;m doing is I&#8217;m just properly,</p>



<p class="wp-block-paragraph">you know, I&#8217;m printing the exit message.</p>



<p class="wp-block-paragraph">So I&#8217;m just printing another string saying the exit or the jump test is done.</p>



<p class="wp-block-paragraph">I return to the caller execution goes all the way back up to just you know right here right after</p>



<p class="wp-block-paragraph">call jump test was executed and then the cool function will return to the caller and that&#8217;s</p>



<p class="wp-block-paragraph">just a c++ main function that does nothing so at this point we should see the whole entire point of</p>



<p class="wp-block-paragraph">the program and then I&#8217;ll start tweaking it so you can kind of see the difference with the jump</p>



<p class="wp-block-paragraph">instruction uh there and not there so let&#8217;s run one more time and notice how it says begin the</p>



<p class="wp-block-paragraph">says begin the jump test and then end jump test and then it goes back to the driver that is</p>



<p class="wp-block-paragraph">regain control it never says this message should not be printed so this whole section was just</p>



<p class="wp-block-paragraph">skipped let&#8217;s comment out line 66 so that we don&#8217;t actually jump over that code and then now you&#8217;ll</p>



<p class="wp-block-paragraph">see that that message does get printed so notice how it says this message should not appear okay</p>



<p class="wp-block-paragraph">and then run the program one more time.</p>



<p class="wp-block-paragraph">Now that message does not appear.</p>



<p class="wp-block-paragraph">Pretty cool.</p>



<p class="wp-block-paragraph">Now let&#8217;s do that double jumping thing just to show you.</p>



<p class="wp-block-paragraph">I mean, this is not something that you actually want to do.</p>



<p class="wp-block-paragraph">You probably want to write functions and function calls,</p>



<p class="wp-block-paragraph">but if you wanted to, you could do something like this.</p>



<p class="wp-block-paragraph">Here&#8217;s the exiting.</p>



<p class="wp-block-paragraph">And maybe right after this, let&#8217;s make another label.</p>



<p class="wp-block-paragraph">Let&#8217;s do, oh gosh, what am I going to do?</p>



<p class="wp-block-paragraph">what am I going to do? Because if I jump after the exiting label and I jump back up to some label</p>



<p class="wp-block-paragraph">up here, it&#8217;s just going to be an infinite loop. So maybe, um, I don&#8217;t know, let&#8217;s make a, I mean,</p>



<p class="wp-block-paragraph">if I make another label down at the bottom, you&#8217;ll kind of think it&#8217;s a function just without</p>



<p class="wp-block-paragraph">a return statement. So let&#8217;s actually jump within the same function. Let&#8217;s do, um,</p>



<p class="wp-block-paragraph">over the never area.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say jump test and I&#8217;m going to write never.</p>



<p class="wp-block-paragraph">So now we have a label that tells us where the never printed message actually starts.</p>



<p class="wp-block-paragraph">So if we jump over it to the exiting, then we&#8217;re good.</p>



<p class="wp-block-paragraph">But then if I up here, if I say jump instruction that subverts</p>



<p class="wp-block-paragraph">never message so I&#8217;m just I&#8217;m just leaving a comment not code I could then</p>



<p class="wp-block-paragraph">say let&#8217;s jump to jump test never and what will happen now is we&#8217;ll still see</p>



<p class="wp-block-paragraph">the never message because what will happen is execution comes down you know</p>



<p class="wp-block-paragraph">through here all these instructions are executing and then we see a jump that</p>



<p class="wp-block-paragraph">tells us to go to the the never label so we actually jump over this exiting jump</p>



<p class="wp-block-paragraph">over this exiting jump or this like the skipping jump,</p>



<p class="wp-block-paragraph">the jump that skips the message.</p>



<p class="wp-block-paragraph">And then we actually do print the never message</p>



<p class="wp-block-paragraph">and we just keep going down and down and down</p>



<p class="wp-block-paragraph">until we&#8217;re finished with that.</p>



<p class="wp-block-paragraph">And we end up just sort of exiting normally.</p>



<p class="wp-block-paragraph">So that means the only code that doesn&#8217;t get executed</p>



<p class="wp-block-paragraph">in this case is the one right here</p>



<p class="wp-block-paragraph">that skips over the never message.</p>



<p class="wp-block-paragraph">Hopefully that makes sense.</p>



<p class="wp-block-paragraph">Let&#8217;s run the program just to prove it real fast.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do this again.</p>



<p class="wp-block-paragraph">And now you see the message should not appear.</p>



<p class="wp-block-paragraph">This message should not appear.</p>



<p class="wp-block-paragraph">You see that message.</p>



<p class="wp-block-paragraph">So again, if we comment out that jump that subverts the skip, then execution will fall</p>



<p class="wp-block-paragraph">through and we&#8217;ll end up executing line 69, the skipping instruction.</p>



<p class="wp-block-paragraph">again now that message does not appear.</p>



<p class="wp-block-paragraph">We could jump back and forth if we wanted to.</p>



<p class="wp-block-paragraph">I don&#8217;t know.</p>



<p class="wp-block-paragraph">Should I do a back and forth?</p>



<p class="wp-block-paragraph">I don&#8217;t really want to.</p>



<p class="wp-block-paragraph">I think at this point you understand we can jump anywhere we want, right?</p>



<p class="wp-block-paragraph">I could take a bunch of time in this video to rewrite this program and have it say,</p>



<p class="wp-block-paragraph">let&#8217;s jump downward and then let&#8217;s jump upward again and let&#8217;s let it fall through</p>



<p class="wp-block-paragraph">and then let&#8217;s jump over something and whatever.</p>



<p class="wp-block-paragraph">let&#8217;s jump over something and whatever. I mean, just wherever you want to jump,</p>



<p class="wp-block-paragraph">just make a label and then jump to it. Then you have to figure out what your execution path is</p>



<p class="wp-block-paragraph">actually going to be. And maybe that&#8217;ll be complicated, but I hope I&#8217;ve made my point by</p>



<p class="wp-block-paragraph">now. Anyway, so that&#8217;s the basics of just jumping around. It&#8217;s not super useful. Conditional</p>



<p class="wp-block-paragraph">branching is a lot better. So see my next video. And I thank you for watching this and I hope you</p>



<p class="wp-block-paragraph">learned a little bit and had a little fun. See you soon.</p>



<p class="wp-block-paragraph">See you soon.</p>



<p class="wp-block-paragraph">longer videos, better videos, or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">So please do me a kindness and subscribe. You know sometimes I&#8217;m sleeping in the</p>



<p class="wp-block-paragraph">middle of the night and I just wake up because I know somebody subscribed or</p>



<p class="wp-block-paragraph">followed. It just wakes me up and I get filled with joy. That&#8217;s exactly what</p>



<p class="wp-block-paragraph">happens every single time. So you could do it as a nice favor to me or you could</p>



<p class="wp-block-paragraph">you could troll me if you want to just wake me up in the middle of the night.</p>



<p class="wp-block-paragraph">Just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen.</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now, you should see a QR code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video and</p>



<p class="wp-block-paragraph">It&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p class="wp-block-paragraph">I published and the services and tutorials and things that I offer and all that good stuff and</p>



<p class="wp-block-paragraph">If you have a suggestion for</p>



<p class="wp-block-paragraph">Clarifications or errata or just future videos that you want to see</p>



<p class="wp-block-paragraph">please leave a comment or if you just want to say, Hey, what&#8217;s up, what&#8217;s going on?</p>



<p class="wp-block-paragraph">You know, just send me a comment, whatever. I also wake up for those in the middle of the night.</p>



<p class="wp-block-paragraph">I get, I wake up in a cold sweat and I&#8217;m like, it would really, it really mean the world to me.</p>



<p class="wp-block-paragraph">I would really appreciate it. So again, thank you so much for watching this video and, um,</p>



<p class="wp-block-paragraph">enjoy the cool music as, as I fade into the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/">x86-64 Assembly Jump Instructions Explained: Unconditional JMP with Full Example in Yasm</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</title>
		<link>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/</link>
					<comments>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 14 Sep 2025 23:46:11 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[argv argc]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[command line args]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[GCC assembly]]></category>
		<category><![CDATA[GCC linking]]></category>
		<category><![CDATA[hybrid programming]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming guide]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[x86 assembly]]></category>
		<category><![CDATA[x86-64 programming]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=227</guid>

					<description><![CDATA[<p>Learn to process command line arguments in Yasm assembly with GCC. Practical x86-64 guide for hybrid programs with clear examples. #Assembly #Programming</p>
<p>The post <a href="https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/">Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Command Line Arguments in Yasm Assembly with GCC: A Practical Guide" width="1380" height="776" src="https://www.youtube.com/embed/r5K10mL2OPE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Want to master command line arguments in Yasm assembly? This video breaks down how to access and process args in x86-64 hybrid programs linked with GCC. From understanding argv and argc to looping through arguments, we cover it all with practical examples. Perfect for programmers diving into assembly or looking to level up their low-level coding skills. Check out my other videos for more on Yasm and pure assembly! Subscribe for more coding tutorials. #AssemblyProgramming #YasmAssembly #GCC #x86_64</p>



<p class="wp-block-paragraph">Introduction 00:00:00<br>Command Line Arguments Overview 00:00:03<br>Yasm Assembly and GCC Linking 00:00:07<br>Hybrid Program Explanation 00:01:27<br>Makefile Overview 00:02:16<br>Assembly Program Structure 00:03:16<br>Main Entry Point and Registers 00:03:51<br>Accessing Command Line Arguments 00:04:26<br>Argument Count and Pointers 00:05:03<br>Loop Initialization for Arguments 00:08:57<br>Loop Logic and Dereferencing 00:10:52<br>Printing Arguments 00:13:02<br>Incrementing Pointers in Loop 00:14:08<br>Running the Program 00:15:35<br>Practical Application of Arguments 00:17:24<br>Conclusion and Next Steps 00:17:51<br>Call to Subscribe and Outro 00:18:22</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there. In this video,</p>



<p class="wp-block-paragraph">I&#8217;m going to talk to you about how to accept incoming command line arguments to</p>



<p class="wp-block-paragraph">an x86-64 Yasm assembly program that is probably linking to</p>



<p class="wp-block-paragraph">GCC and is thus probably a hybrid program under the hood.</p>



<p class="wp-block-paragraph">If you don&#8217;t know how to program in Yasm assembly yet,</p>



<p class="wp-block-paragraph">check out my other videos. If you don&#8217;t understand command line arguments yet,</p>



<p class="wp-block-paragraph">yet check my other videos I&#8217;m going to assume a lot of knowledge here I&#8217;m</p>



<p class="wp-block-paragraph">really just going to show you how to pull the arguments inside of assembly</p>



<p class="wp-block-paragraph">using using the GCC setup that they&#8217;ve given you so just a quick just a very</p>



<p class="wp-block-paragraph">quick recap this is not a command line arguments video if we have the program</p>



<p class="wp-block-paragraph">echo and we give it like one argument of just the word hello then it&#8217;s it&#8217;s</p>



<p class="wp-block-paragraph">going to receive one command line argument in addition to its program</p>



<p class="wp-block-paragraph">echo as argument zero and hello as argument index one.</p>



<p class="wp-block-paragraph">And it&#8217;s just going to be able to look at them and say,</p>



<p class="wp-block-paragraph">oh, the user wants me to print this hello string.</p>



<p class="wp-block-paragraph">So it just prints it.</p>



<p class="wp-block-paragraph">And so that&#8217;s kind of how you can tell a program what to do,</p>



<p class="wp-block-paragraph">either when you&#8217;re running them directly</p>



<p class="wp-block-paragraph">or having one program automate another program.</p>



<p class="wp-block-paragraph">Anyway, so in our Yasm assembly programs,</p>



<p class="wp-block-paragraph">how do we actually get that out?</p>



<p class="wp-block-paragraph">Well, for starters, we are dynamically linking.</p>



<p class="wp-block-paragraph">Sorry, not dynamically linking.</p>



<p class="wp-block-paragraph">We are linking a hybrid program.</p>



<p class="wp-block-paragraph">So I just want to make sure that you understand this is the right video for you.</p>



<p class="wp-block-paragraph">If you&#8217;re trying to do this in pure assembly, or if you need to know that for some reason,</p>



<p class="wp-block-paragraph">then you&#8217;ll probably want to watch the next video that I publish.</p>



<p class="wp-block-paragraph">But for now, this is a hybrid program.</p>



<p class="wp-block-paragraph">Hybrid programs, for those of you who don&#8217;t know, it just means you have modules that</p>



<p class="wp-block-paragraph">are written in different source code and they&#8217;re compiled differently, different source code</p>



<p class="wp-block-paragraph">languages.</p>



<p class="wp-block-paragraph">So you might have a source code file that&#8217;s written in C++ another one that&#8217;s written in C another one that&#8217;s written in assembly</p>



<p class="wp-block-paragraph">And you compile them all down to their own object files and then you link them together into an executable</p>



<p class="wp-block-paragraph">If GCC is part of the linking process</p>



<p class="wp-block-paragraph">Then it&#8217;s going to end up giving you a main function as your entry point and it&#8217;s going to make things a little bit easier</p>



<p class="wp-block-paragraph">Here&#8217;s my make file. I&#8217;m just going to skim through it real fast. This is not a make file video</p>



<p class="wp-block-paragraph">So if you don&#8217;t understand it go look at my other videos</p>



<p class="wp-block-paragraph">But basically I&#8217;m just going to assemble with Yasm and I&#8217;m going to use G++ as the linker</p>



<p class="wp-block-paragraph">and I&#8217;m going to gobble up all of the object files. Here&#8217;s like a little menu.</p>



<p class="wp-block-paragraph">I have a target for running and building only. And here&#8217;s the main thing that I&#8217;m doing. This</p>



<p class="wp-block-paragraph">is not really a hybrid program. This is just kind of a pure assembly program that is linked with GCC,</p>



<p class="wp-block-paragraph">but you can imagine you could add other source files in C and C++ and still totally get away</p>



<p class="wp-block-paragraph">GCC. But anyway, I&#8217;m just compiling one source code of assembly and,</p>



<p class="wp-block-paragraph">and compiling it down to an object file right here.</p>



<p class="wp-block-paragraph">And then when it comes time to linking, uh, you can kind of tell here, uh,</p>



<p class="wp-block-paragraph">especially if you&#8217;re familiar with make files that I&#8217;m just gobbling up all the</p>



<p class="wp-block-paragraph">object files and linking them together into the executable.</p>



<p class="wp-block-paragraph">So that&#8217;s as far as I&#8217;ll go there again,</p>



<p class="wp-block-paragraph">I&#8217;ve got another video that totally explains a lot more in my assembly program.</p>



<p class="wp-block-paragraph">video just for pure assembly so if you don&#8217;t understand assembly see my other videos but for</p>



<p class="wp-block-paragraph">now we&#8217;re just going to say i&#8217;ve got a data section it&#8217;s got a couple of null terminated strings we&#8217;ve</p>



<p class="wp-block-paragraph">got a hello message a begin message a goodbye message carriage return line feed string i&#8217;ve</p>



<p class="wp-block-paragraph">got the system call codes for you know printing to standard output and to exit the program and then</p>



<p class="wp-block-paragraph">i&#8217;ve got the standard output file handle and then my exit code zero for success again this is all</p>



<p class="wp-block-paragraph">other videos. So because I&#8217;m linking with GCC, my text section here, the actual place where the</p>



<p class="wp-block-paragraph">instructions are, not the data, is going to have a main entry point. So of course, if you had a</p>



<p class="wp-block-paragraph">hybrid program, you could have main somewhere else in a different module and then just call on a</p>



<p class="wp-block-paragraph">function that was inside of assembly. You could totally do that. But for now, I&#8217;m just going to</p>



<p class="wp-block-paragraph">say this is the only source code file. So I mark main as global and I put main right here. And then</p>



<p class="wp-block-paragraph">I preserve all of the Kali saved registers that I&#8217;m supposed to by pushing them at the beginning and popping them in reverse order at the end.</p>



<p class="wp-block-paragraph">And then I return a return value.</p>



<p class="wp-block-paragraph">Standard assembly stuff covered in other videos.</p>



<p class="wp-block-paragraph">But here&#8217;s the key for getting command line arguments in assembly.</p>



<p class="wp-block-paragraph">If you recall, the ABI specifies that in x86-64 programs, the first argument is always supposed to come into a function as RDI in the RDI register.</p>



<p class="wp-block-paragraph">register or rather I should say the first integer argument I haven&#8217;t talked</p>



<p class="wp-block-paragraph">about to float arguments in any of my videos yet in the future you should</p>



<p class="wp-block-paragraph">probably search for other videos that that explain how to do float arguments</p>



<p class="wp-block-paragraph">but for now all of the arguments I&#8217;m talking about in this video are just</p>



<p class="wp-block-paragraph">integer arguments and pointer arguments which is kind of the same thing a</p>



<p class="wp-block-paragraph">pointer is an integer it&#8217;s a 64-bit integer but we&#8217;ll just use it as a</p>



<p class="wp-block-paragraph">using it as an integer so anyway first argument comes in on RDI second argument</p>



<p class="wp-block-paragraph">comes in on RSI and you can imagine that basically this is the thing you&#8217;re</p>



<p class="wp-block-paragraph">probably used to seeing in your C++ programs if we do this int main and then</p>



<p class="wp-block-paragraph">integer arg C and then a character pointer arg V and then an array those are</p>



<p class="wp-block-paragraph">those two registers right there I probably want to change this into long</p>



<p class="wp-block-paragraph">because you know rdi is in 64-bit form but an integer is an unsigned 32-bit int.</p>



<p class="wp-block-paragraph">I don&#8217;t like that so I&#8217;m just going to put long. I probably should put unsigned but I don&#8217;t really</p>



<p class="wp-block-paragraph">care. Anyway so we&#8217;re just going to grab those two things so obviously rdi is probably pretty</p>



<p class="wp-block-paragraph">easy for you to guess how to use it&#8217;s just the number of arguments. In this program we&#8217;re going</p>



<p class="wp-block-paragraph">to use it to control a loop counter that&#8217;s going to loop through all incoming arguments.</p>



<p class="wp-block-paragraph">which is going to be the name of the program in this case it&#8217;ll be I think</p>



<p class="wp-block-paragraph">just main is what I called it which is confusing against the entry point I</p>



<p class="wp-block-paragraph">admit it but imagine that my main program that sits in the file system is</p>



<p class="wp-block-paragraph">actually called program or hello or whatever so that&#8217;s the number of</p>



<p class="wp-block-paragraph">arguments in RDI and then RSI notice how it&#8217;s a character pointer to an array of</p>



<p class="wp-block-paragraph">characters that means it&#8217;s actually a pointer to a pointer and the reason for</p>



<p class="wp-block-paragraph">every argument on the command line like for instance if i went back here and i said echo</p>



<p class="wp-block-paragraph">hello let&#8217;s just do without quotes hello you i&#8217;ve given it two arguments and so when the program</p>



<p class="wp-block-paragraph">launches it&#8217;s going to receive three total it&#8217;s going to receive its own program name at index zero</p>



<p class="wp-block-paragraph">echo it&#8217;s going to receive at index one the first argument hello and it&#8217;s going to receive at index</p>



<p class="wp-block-paragraph">two the second argument as you it prints them both so how does echo know how many arguments i have</p>



<p class="wp-block-paragraph">strings. Remember argc is the number of arguments so that&#8217;s kind of easy but how does it dereference</p>



<p class="wp-block-paragraph">all of the strings if there could be any number of strings? Well that&#8217;s this right here.</p>



<p class="wp-block-paragraph">This whole symbol argv is a pointer and it points to an array of pointers, of character</p>



<p class="wp-block-paragraph">pointers. That&#8217;s why it&#8217;s written like this like an array. So it&#8217;s a pointer that points</p>



<p class="wp-block-paragraph">points to an array.</p>



<p class="wp-block-paragraph">So like if you go to that location in memory,</p>



<p class="wp-block-paragraph">then what you will see there for the first eight bytes</p>



<p class="wp-block-paragraph">is just the address of some other memory location where a string has been stored.</p>



<p class="wp-block-paragraph">Then if you advance that pointer another eight bytes for it,</p>



<p class="wp-block-paragraph">you know, in memory, because all pointers are eight bytes or 64 bits,</p>



<p class="wp-block-paragraph">then again, you&#8217;ll see that that value of that next eight bytes</p>



<p class="wp-block-paragraph">is actually a memory location that points to another string somewhere else.</p>



<p class="wp-block-paragraph">So these strings could be all over the place,</p>



<p class="wp-block-paragraph">But the pointers to those strings are contiguous in memory starting with what you were given in RSI.</p>



<p class="wp-block-paragraph">So it&#8217;s a character pointer pointer or an array of character pointers, however you want to imagine that.</p>



<p class="wp-block-paragraph">Anyway, so we&#8217;ll grab those and then I&#8217;ll just show you how to use them down further in the code.</p>



<p class="wp-block-paragraph">For starters, I&#8217;m calling on an intro function which just basically prints some stuff.</p>



<p class="wp-block-paragraph">I have a custom function that I wrote called print null terminated string.</p>



<p class="wp-block-paragraph">That&#8217;s not the point of this video.</p>



<p class="wp-block-paragraph">I have that explained in other videos a little bit.</p>



<p class="wp-block-paragraph">So it&#8217;s up to you if you want to even care.</p>



<p class="wp-block-paragraph">Right now I just want to be able to print something.</p>



<p class="wp-block-paragraph">And then let&#8217;s see.</p>



<p class="wp-block-paragraph">So after we print our welcome message in the intro, then we print another message basically</p>



<p class="wp-block-paragraph">saying okay now we&#8217;re about to start printing all the arguments.</p>



<p class="wp-block-paragraph">Okay cool.</p>



<p class="wp-block-paragraph">Nothing complicated at this point.</p>



<p class="wp-block-paragraph">Then I have another label here with my preferred style of adding a suffix after the function</p>



<p class="wp-block-paragraph">after the function that I&#8217;m currently inside of.</p>



<p class="wp-block-paragraph">And I&#8217;m going to say, all right, this is where I initialize my loop.</p>



<p class="wp-block-paragraph">This is not a looping video, so I&#8217;m going to skim through it kind of.</p>



<p class="wp-block-paragraph">But I&#8217;m basically going to say, let&#8217;s start the loop as basically saying</p>



<p class="wp-block-paragraph">the index of the argument that we&#8217;re currently looking at is zero</p>



<p class="wp-block-paragraph">because we&#8217;ll start with zero.</p>



<p class="wp-block-paragraph">So that means we&#8217;ll print like if we were going to, if our program was named Echo,</p>



<p class="wp-block-paragraph">we would also print Echo itself and not just all the incoming arguments</p>



<p class="wp-block-paragraph">that the user might have typed.</p>



<p class="wp-block-paragraph">index zero and then we&#8217;re going to use r15 as the current character pointer so r15 its current</p>



<p class="wp-block-paragraph">character pointer is going to be coming from r13 which was the argv argument so that means</p>



<p class="wp-block-paragraph">r15 is now going to hold a pointer uh let&#8217;s see it&#8217;s going to hold</p>



<p class="wp-block-paragraph">when you have an array and the array is contiguous in memory then the pointer itself that points to</p>



<p class="wp-block-paragraph">the array is also a pointer to the first item that&#8217;s just kind of the way it works like if we</p>



<p class="wp-block-paragraph">have 10 items and it&#8217;s an array then your pointer to that array is also a pointer to the first item</p>



<p class="wp-block-paragraph">in the array if that makes sense so if r13 was a pointer to an array it&#8217;s also a pointer to the</p>



<p class="wp-block-paragraph">go off to a null terminated string i know that sounds weird you got to get used to double dereferencing</p>



<p class="wp-block-paragraph">here so all we really need to do to access uh the first pointer to the actual string is take the</p>



<p class="wp-block-paragraph">array pointer that we have and dereference it one time so remember we&#8217;re receiving an argv</p>



<p class="wp-block-paragraph">a pointer to a pointer or like a you know a double pointer if we dereference it once then we should</p>



<p class="wp-block-paragraph">terminated string. Anyway, so that&#8217;s the initialization part. I&#8217;m going to start looking</p>



<p class="wp-block-paragraph">at the first string here and I&#8217;m going to say we&#8217;re at index zero. And then here&#8217;s the top of</p>



<p class="wp-block-paragraph">my loop. You can imagine this is a while loop. This is not a while video, but you know, there it is.</p>



<p class="wp-block-paragraph">And we&#8217;re just going to ask first, are we actually done? Do we need to break the loop? I like to do</p>



<p class="wp-block-paragraph">that at the top of my while loop. And how we&#8217;ll do that is we&#8217;ll say, all right, R14 is the index</p>



<p class="wp-block-paragraph">the number of arguments so notice how like right here we grabbed RDI right</p>



<p class="wp-block-paragraph">into R12 right away so basically I&#8217;m saying if the index we&#8217;re currently</p>



<p class="wp-block-paragraph">looking at is greater than or equal to the number of arguments then we&#8217;re</p>



<p class="wp-block-paragraph">actually already done remember if we&#8217;re using zero based indexing and you</p>



<p class="wp-block-paragraph">suppose that you have three items in your array their indexes would be zero</p>



<p class="wp-block-paragraph">So that means if the size of your array is three, like the count, like the RFC, that</p>



<p class="wp-block-paragraph">means the last valid index is two.</p>



<p class="wp-block-paragraph">It&#8217;s one less than the size.</p>



<p class="wp-block-paragraph">You know, it&#8217;s one less than the count.</p>



<p class="wp-block-paragraph">So I&#8217;m saying at this point that if we ever reach an index number that is equal to the</p>



<p class="wp-block-paragraph">size, then we&#8217;ve already finished.</p>



<p class="wp-block-paragraph">We do not need to look at the current item.</p>



<p class="wp-block-paragraph">So I&#8217;m comparing those two registers.</p>



<p class="wp-block-paragraph">You know, where are we looking at versus what is the count?</p>



<p class="wp-block-paragraph">You know, what is the index we&#8217;re looking at versus the count?</p>



<p class="wp-block-paragraph">If the index we&#8217;re looking at is greater than or equal to the count, then that means we&#8217;re done.</p>



<p class="wp-block-paragraph">I&#8217;m going to jump out of the loop to a label called main loop done.</p>



<p class="wp-block-paragraph">So then, you know, that&#8217;s down here.</p>



<p class="wp-block-paragraph">Basically, we just say goodbye and then we jump to our exit function.</p>



<p class="wp-block-paragraph">And all that does is it just returns from main with some kind of a success code.</p>



<p class="wp-block-paragraph">You know, so just you can imagine in C++, it&#8217;s just return zero.</p>



<p class="wp-block-paragraph">So, you know, breaking the loop doesn&#8217;t really do anything except end the program and say goodbye.</p>



<p class="wp-block-paragraph">However, if we did not jump, then the, let&#8217;s see if we did not jump, let&#8217;s, let&#8217;s see if</p>



<p class="wp-block-paragraph">we did jump, we compared it, we realized that we&#8217;re done.</p>



<p class="wp-block-paragraph">Then it&#8217;s going to jump down to the, to the done.</p>



<p class="wp-block-paragraph">But if we&#8217;re not done, execution is going to fall through to the next statement.</p>



<p class="wp-block-paragraph">So that means we&#8217;re going to end up doing something with the current item inside of</p>



<p class="wp-block-paragraph">our loop.</p>



<p class="wp-block-paragraph">So what are we going to do?</p>



<p class="wp-block-paragraph">We&#8217;re going to dereference R15.</p>



<p class="wp-block-paragraph">was your pointer to a pointer it was your double pointer there if we dereference it once then</p>



<p class="wp-block-paragraph">instead of being a pointer to an array of pointers it&#8217;s going to be a pointer to one string one one</p>



<p class="wp-block-paragraph">character that starts one string so dereferencing it once means you know i put brackets around the</p>



<p class="wp-block-paragraph">double pointer it&#8217;s now dereferenced once that means rdi is going to receive a pointer to one</p>



<p class="wp-block-paragraph">into my function my function takes two arguments it wants a pointer to a string and it wants</p>



<p class="wp-block-paragraph">the file descriptor to print to again other videos explain you know printing to standard</p>



<p class="wp-block-paragraph">output but i&#8217;m just going to print the string so this part right here should actually print</p>



<p class="wp-block-paragraph">the argument and then after we&#8217;re done with that uh well maybe i should change this</p>



<p class="wp-block-paragraph">so that it&#8217;s a little bit more clear i&#8217;m going to maybe push this down and say</p>



<p class="wp-block-paragraph">these lines up here actually do something they do the printing by</p>



<p class="wp-block-paragraph">dereferencing and then here we just sort of increment along the array of pointers</p>



<p class="wp-block-paragraph">and jump back to the top of the loop so what are we doing here with r14</p>



<p class="wp-block-paragraph">remember r14 was the index that we&#8217;re currently looking at so we we start</p>



<p class="wp-block-paragraph">looking at index 0 line 83 is going to say let&#8217;s next look at index 1 and then</p>



<p class="wp-block-paragraph">this part right here add 8 to r15 that just basically means remember r15 was</p>



<p class="wp-block-paragraph">remember r15 was the double pointer the double pointer like i said before it&#8217;s looking at an</p>



<p class="wp-block-paragraph">array of pointers so it&#8217;s actually a pointer to a pointer if i increase the memory location that</p>



<p class="wp-block-paragraph">r15 holds then it&#8217;s now looking at the next pointer it&#8217;s moving through the array r15 at</p>



<p class="wp-block-paragraph">that point would no longer be a valid pointer to the original array it&#8217;s sort of like a running</p>



<p class="wp-block-paragraph">pointer it&#8217;s kind of like scanning all of the pointers but a pointer is eight bytes so if we&#8217;re</p>



<p class="wp-block-paragraph">a pointer is eight bytes so if we&#8217;re just looking at the first pointer and we increase the memory</p>



<p class="wp-block-paragraph">location that we&#8217;re looking at by eight bytes now we&#8217;re looking at the second pointer so then on the</p>



<p class="wp-block-paragraph">next iteration of the loop if we dereference then we&#8217;re going to end up dereferencing to the second</p>



<p class="wp-block-paragraph">string then i just print a little new line here honestly probably should have put that up top</p>



<p class="wp-block-paragraph">sloppy code i was doing this quickly and then we jump to the top of the loop so then we just</p>



<p class="wp-block-paragraph">going up to the top of the loop and printing arguments and advancing to the</p>



<p class="wp-block-paragraph">next pointer. And we just keep going at it.</p>



<p class="wp-block-paragraph">Let me see if this works. Hopefully I didn&#8217;t mess this up while I was screwing</p>



<p class="wp-block-paragraph">around. All right. So I&#8217;m going to do this make run. Okay.</p>



<p class="wp-block-paragraph">So under the hood inside of my make file,</p>



<p class="wp-block-paragraph">maybe let&#8217;s open the make file real fast just so you can see.</p>



<p class="wp-block-paragraph">I&#8217;m just going to nano it real fast here under the hood.</p>



<p class="wp-block-paragraph">So when I call the program to run, notice how I&#8217;m giving it arguments.</p>



<p class="wp-block-paragraph">You can see right here on this line, or actually let me get the line numbers up.</p>



<p class="wp-block-paragraph">You can see on line 48, I am calling my executable, which is named main.</p>



<p class="wp-block-paragraph">In the make file, I&#8217;m using a variable, so don&#8217;t worry about that.</p>



<p class="wp-block-paragraph">But I&#8217;m giving it four arguments.</p>



<p class="wp-block-paragraph">And I&#8217;m just saying first arg, second arg, third arg, fourth arg.</p>



<p class="wp-block-paragraph">So that&#8217;s why you see that printed in the previous screen.</p>



<p class="wp-block-paragraph">screen it&#8217;s just going through all the arguments that I gave it it&#8217;s saying</p>



<p class="wp-block-paragraph">first arg second arg third arg fourth arg notice how it knows when to stop</p>



<p class="wp-block-paragraph">because of the argc that came in on RDI now that the program is built you know</p>



<p class="wp-block-paragraph">I&#8217;ve got my main executable which I named main which I said before was kind</p>



<p class="wp-block-paragraph">of confusing now that I&#8217;ve got it I can just execute it again and give it like</p>



<p class="wp-block-paragraph">one argument of like hello notice how it prints hello on a line by itself you do</p>



<p class="wp-block-paragraph">do it again dudes and notice how every argument I give it it just prints it no</p>



<p class="wp-block-paragraph">matter how many I do I can go a b c d e f g I could probably do this so many</p>



<p class="wp-block-paragraph">times that I exhaust you know a long integer which is would be a horrible</p>



<p class="wp-block-paragraph">endeavor but yeah everything that I put on there it just loops through it and</p>



<p class="wp-block-paragraph">prints it so when you are linking with GCC because you&#8217;re probably using a</p>



<p class="wp-block-paragraph">if you&#8217;re just linking with GCC.</p>



<p class="wp-block-paragraph">GCC makes it really, really easy</p>



<p class="wp-block-paragraph">to access the command line arguments.</p>



<p class="wp-block-paragraph">Imagine now instead of just printing these things,</p>



<p class="wp-block-paragraph">you used them to somehow decide</p>



<p class="wp-block-paragraph">what your program was gonna do.</p>



<p class="wp-block-paragraph">Maybe the user will give you a sub command.</p>



<p class="wp-block-paragraph">Like if you&#8217;re a Git user, we say Git status, right?</p>



<p class="wp-block-paragraph">So the Git says like, oh, you Git launches</p>



<p class="wp-block-paragraph">and it goes, you want the status of something?</p>



<p class="wp-block-paragraph">Yeah, sure.</p>



<p class="wp-block-paragraph">So in your program now,</p>



<p class="wp-block-paragraph">you could read what the user typed,</p>



<p class="wp-block-paragraph">figure out a way to parse it and interpret it</p>



<p class="wp-block-paragraph">have your program&#8217;s behavior adjust to whatever the user typed in okay that&#8217;s it for this video</p>



<p class="wp-block-paragraph">the next video I&#8217;m going to post is how to do basically exactly the same thing but using pure</p>



<p class="wp-block-paragraph">assembly without linking against GCC so like LD is going to be the linker just like pure assembly</p>



<p class="wp-block-paragraph">no extra libraries okay thank you so much for watching this video I hope you learned a little</p>



<p class="wp-block-paragraph">tell your friends and i&#8217;ll see you in the next video</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really appreciate it</p>



<p class="wp-block-paragraph">i do hope you did learn something and have some fun uh if you could do me a please a small little</p>



<p class="wp-block-paragraph">favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p class="wp-block-paragraph">and grow this community so we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general. So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



<p class="wp-block-paragraph">somebody subscribed or followed. It just wakes me up and I get filled with joy. That&#8217;s exactly</p>



<p class="wp-block-paragraph">what happens every single time. So you could do it as a nice favor to me or you could troll me if</p>



<p class="wp-block-paragraph">you want to just wake me up in the middle of the night, just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">just wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



<p class="wp-block-paragraph">to the website which I think is also named somewhere at the bottom of this</p>



<p class="wp-block-paragraph">video and it&#8217;ll take you to my main website where you can just kind of like</p>



<p class="wp-block-paragraph">see all the videos I published and the services and tutorials and things that I</p>



<p class="wp-block-paragraph">offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me i would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/">Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
