<?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>assembly control flow Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/assembly-control-flow/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/assembly-control-flow/</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=6.9.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>assembly control flow Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/assembly-control-flow/</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>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>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>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>Lots of practical tips about label naming conventions, register preservation (R12 in this case), and debugging flow are included along the way.</p>



<p>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>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>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>=-=-=-=-=-=-=-=-=</p>



<p>Thanks for watching!</p>



<p>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>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>All right, hello there. In this video, I&#8217;m going to teach you how to implement while loops in YASM</p>



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



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



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



<p>assembly program, if you don&#8217;t know how to make a make file, if you don&#8217;t know a lot</p>



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



<p>videos because I explain all of those things at length.</p>



<p>For this video, I&#8217;m just going to be talking about while loops only.</p>



<p>So for starters, let&#8217;s see here and open up a little notepad here and just type a while</p>



<p>loop and try to explain a little bit about it conceptually.</p>



<p>And then after that, we&#8217;re going to, we&#8217;re going to write a program in Yasm to show that</p>



<p>we can get this to work.</p>



<p>So what is a while loop in a higher level language?</p>



<p>We&#8217;ll just suppose C or C++.</p>



<p>You can imagine whatever language you want, but typically in a while loop,</p>



<p>we&#8217;re not talking about a do while loop, although that would be really easy</p>



<p>to implement after watching this video.</p>



<p>But in a regular while loop, you have the keyword while usually,</p>



<p>and then you have some sort of an expression like does a equal B or whatever.</p>



<p>So maybe I&#8217;ll just say does a equal B?</p>



<p>Expression evaluates to true then the body of the while loop will execute and then when it&#8217;s done executing</p>



<p>Execution will go back up to look at the expression again and make sure that it&#8217;s still true</p>



<p>So the loop will run forever until that expression evaluates to false</p>



<p>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>And that means the body runs an endless number of times</p>



<p>Also, if the expression evaluates to false on the very first run</p>



<p>then the body of the while loop will just never run at all.</p>



<p>So that&#8217;s, you know, a basic idea of a while loop in a higher level language.</p>



<p>Hopefully you kind of already know that.</p>



<p>So let&#8217;s look at the parts right here.</p>



<p>If we imagine this as assembly,</p>



<p>then probably the first thing we should do is label the part</p>



<p>where we look at the expression and decide whether we&#8217;re going to continue or not, right?</p>



<p>So I&#8217;m going to put a little label here</p>



<p>and maybe we&#8217;ll call it a while top or something.</p>



<p>You know, whatever you want to do.</p>



<p>just to label the part of the code</p>



<p>So that we know when we write assembly</p>



<p>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>The while loop that we&#8217;re implementing in assembly</p>



<p>So I&#8217;m gonna say this is the top or you can call it the eval part whatever you want</p>



<p>Then we&#8217;ll make another label down here. We&#8217;ll call it</p>



<p>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>expression, we just have to basically jump to that label called while top.</p>



<p>And if we want to jump to the body to actually execute the code,</p>



<p>then we just have to jump to that other label instead. We should also have a label at the</p>



<p>very bottom after the whole while loop is over and we&#8217;ll call it, you know, while finished</p>



<p>or while, whoops, finished or while done or while over something like that. So I&#8217;m just going to</p>



<p>Now you can imagine that when we&#8217;re at the top of the while loop and we see that the</p>



<p>expression is false, then we can just jump down to the done label, thereby exiting the</p>



<p>entire while loop.</p>



<p>Then of course we probably want to have some jump statements in here.</p>



<p>So for example, the expression part here, it&#8217;s probably going to jump either to the</p>



<p>body or either to the done area based on whether or not the expression evaluated to true or</p>



<p>false.</p>



<p>label while top you know which contains a conditional branch and then like an unconditional</p>



<p>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>through to the next statement and do an unconditional jump to the done label if you don&#8217;t</p>



<p>know conditional branching this is another one of the topics that i&#8217;ve covered in previous videos</p>



<p>as we implement the while loop.</p>



<p>So just keep in mind, there are other videos that I have</p>



<p>that you should watch first</p>



<p>if you don&#8217;t understand conditional branching or jumps.</p>



<p>The reason that I&#8217;m going to kind of design</p>



<p>the jumps like this where I&#8217;m going to say,</p>



<p>let&#8217;s do a conditional branch.</p>



<p>And basically if the loop evaluates to true,</p>



<p>we&#8217;ll jump into the body of the loop.</p>



<p>And if it doesn&#8217;t evaluate to true,</p>



<p>then the conditional branch will allow execution</p>



<p>to fall through down to the next statement,</p>



<p>which will simply contain a jump to the done portion.</p>



<p>to the done portion so basically as soon as the while loop is ready to break it gets uh implemented</p>



<p>by an unconditional jump which was fallen through to by the conditional branch that would only jump</p>



<p>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>uh to jump to the true area you know the the body of the while loop and remember conditional</p>



<p>branching instructions have a maximum you know jump reach of about 128 bytes so if you try to</p>



<p>128 bytes. So if you try to jump too far, like for example, if you wanted to, you could reverse</p>



<p>the logic to where you could say, if an expression is true, let&#8217;s jump to the done portion and say,</p>



<p>we&#8217;re going to break the loop. If the expression was false, we&#8217;ll jump into the body. You could</p>



<p>do that. But then if the body of your while loop was too long, maybe it was so long that the last</p>



<p>instruction was greater than 128 bytes away from the top. Then by the time you wanted to</p>



<p>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>instructions away so that&#8217;s a limitation of contentional branching so I just I want to put</p>



<p>the biggest jump on an unconditional jump instruction because it doesn&#8217;t have a limitation</p>



<p>like that I was having a hard time imagining what I was about to say just now for the</p>



<p>the reversal I guess I&#8217;m just going to ignore the reversal scenario and we&#8217;ll just do it the</p>



<p>and we&#8217;ll just do it the regular way.</p>



<p>Anyway, so we want to have a conditional jump that either jumps into the body or to the done area.</p>



<p>And then at the very bottom, we want to have an unconditional jump to the top,</p>



<p>which basically means every time we get to the bottom of the while loop body,</p>



<p>we&#8217;re just going to jump up to the while top.</p>



<p>Actually, I&#8217;ll just say to while top.</p>



<p>Remember again, the regular jump instructions,</p>



<p>maybe I&#8217;ll take out the U here.</p>



<p>The regular jump instructions don&#8217;t have a limitation</p>



<p>on how far they can jump.</p>



<p>So that should be fine.</p>



<p>And that&#8217;s the basic idea of implementing a while loop.</p>



<p>Maybe I should draw just a quick diagram</p>



<p>before we start looking at the code,</p>



<p>just to make sure everybody of different learning styles</p>



<p>understands what I&#8217;m talking about.</p>



<p>So we&#8217;ll, let&#8217;s see, eval.</p>



<p>I&#8217;m still adjusting my pen and you know what?</p>



<p>You know what? It looked a lot better before I hit record.</p>



<p>Eval the expression.</p>



<p>So I&#8217;m going to first evaluate the expression.</p>



<p>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>Then this will be the body of the while loop.</p>



<p>I&#8217;ll say like the body.</p>



<p>If it evaluates to false, let&#8217;s see.</p>



<p>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>right so you can imagine we evaluate an expression using the compare instruction in assembly and</p>



<p>based on the results of comparing something whatever it is that your condition is then we</p>



<p>you know we we either branch to the done area or we branch to the to the body area</p>



<p>want to have a more complicated while loop and you don&#8217;t want to put a huge</p>



<p>amount of expressions or if you don&#8217;t want to logically concatenate a bunch of</p>



<p>different components into the expression you know that&#8217;s fair I usually write my</p>



<p>while loops in real life as just while true and then I break when certain</p>



<p>conditions are met you can do that too we&#8217;re not going to talk about that in</p>



<p>this video but you could just have a while true so you always jump to the top</p>



<p>and there&#8217;s no branching that goes to while done but then throughout the loop</p>



<p>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>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>loop then it just automatically jumps to the top although you got to make sure with the the reach</p>



<p>of conditional branching you probably want to test to see if your condition is true or false or</p>



<p>whatever if it means we&#8217;re going to continue the loop then you probably just want to do a conditional</p>



<p>then you probably just want to do a conditional branch that jumps down a little bit</p>



<p>so that it can continue the body of the loop.</p>



<p>And then the part that it skipped over,</p>



<p>just a little part should be an unconditional jump that jumps out of the loop.</p>



<p>That way, it doesn&#8217;t matter how big your while loop body is,</p>



<p>you can always jump out of the loop.</p>



<p>But we&#8217;re not going to talk about that in this video.</p>



<p>Anyway, so we evaluate the expression.</p>



<p>If it&#8217;s true, we go to the body.</p>



<p>If it&#8217;s false, we go to done.</p>



<p>After the body is done executing,</p>



<p>then we just jump back up to the top where we evaluate the expression.</p>



<p>where we evaluate the expression.</p>



<p>I&#8217;ll put while here just to make it more clear that we&#8217;re talking about the basic</p>



<p>idea of a while loop.</p>



<p>Not too hard, you know.</p>



<p>And then if you wanted to implement a do while loop, just make sure that you always</p>



<p>evaluate the body at least once.</p>



<p>That&#8217;s really the only difference.</p>



<p>But that&#8217;s up to you.</p>



<p>This is just a regular while loop video.</p>



<p>Okay.</p>



<p>So we&#8217;ve kind of talked about it a little bit.</p>



<p>We&#8217;ve sort of, you know, drawn it out in a diagram and put some regular code in.</p>



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



<p>again i&#8217;m not going to show you my make file because i&#8217;ve already made other videos where i</p>



<p>explained how to make a make file from scratch same thing goes for hybrid programs i&#8217;m going</p>



<p>to have a driver which is a c plus plus module that just sort of calls on this assembly module</p>



<p>if you want to know how to make hybrid programs or you know drivers or you know whatever see my</p>



<p>to be talking about looping only. Okay, so let me get my solution up here. My source code is called</p>



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



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



<p>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>like the actual array of bytes and then a length and all I&#8217;m doing is printing out messages you</p>



<p>know begin the wild test your numbers will be printed back to you until you decide to quit so</p>



<p>that&#8217;s going to be printed to the user right away then every time the program wants a number from</p>



<p>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>the echo back it&#8217;ll say you entered and then it will actually print the number and then when you</p>



<p>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>like input and output numbers this video is not about uh input and outputting and external libraries</p>



<p>if you&#8217;re interested you could probably just link a hybrid program and use printf and scan</p>



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



<p>then i have crlf which is just a carriage return in line feed uh you know select the cursor goes</p>



<p>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>Then a file descriptor just to print a standard output again. That&#8217;s explained in other videos</p>



<p>So now I&#8217;m ready to start copy pasting the main portion of my program</p>



<p>So first off I&#8217;m going to start the text section, which is where the instructions go in the ASM</p>



<p>So there it is and then I&#8217;m going to copy paste</p>



<p>of external symbols. So I just have a little library that I&#8217;m using that makes it easier for</p>



<p>me to input and output integers. So you can do this any way you want, or you can hard code a</p>



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



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



<p>looper. So this is my function. And again, this is a hybrid program. So the main function or the</p>



<p>be present in my assembly module the driver is going to be a c plus plus module that just calls</p>



<p>on a function named looper so that means this function is going to get called from another</p>



<p>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>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>other functions that i&#8217;m about to create one is called while test which is going to actually do</p>



<p>the while loop and the other is called crlf which just print which just prints a new line for me i</p>



<p>which just prints a new line for me.</p>



<p>I don&#8217;t know why I do it that way, but I want to.</p>



<p>Sorry, not sorry.</p>



<p>So this is the real meat of the function here.</p>



<p>Let&#8217;s start, well, the real meat of the code or the video.</p>



<p>Let&#8217;s start a function called while test.</p>



<p>You can see it&#8217;s got a void signature with no arguments,</p>



<p>so it doesn&#8217;t really, you know, take anything or return anything.</p>



<p>I&#8217;m going to use register R12 to hold the user&#8217;s input</p>



<p>so that I can, you know, print it out and stuff.</p>



<p>print it out and stuff so that means I have to do a preservation of R12 because it&#8217;s a</p>



<p>callee saved for the ABI which you should respect so I&#8217;m going to push it at the beginning</p>



<p>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>at the end of the function let me just double check that there&#8217;s nothing else weird at the</p>



<p>bottom of that nope okay so we&#8217;ve got the prologue and epilogue the wild test function</p>



<p>maybe I should copy paste my crlf real fast my crlf function it&#8217;s just sad but</p>



<p>it&#8217;s also kind of cute right it does nothing except just print out a new line</p>



<p>that&#8217;s all it does this video is not about that so at this point I should</p>



<p>have a program that probably works let&#8217;s see if it does I&#8217;m gonna do clear and</p>



<p>make run again if you want to know how to use make files or compile or link or</p>



<p>anything like that see my other videos so I&#8217;m gonna run it and it just says</p>



<p>which is some code that we&#8217;re not looking at.</p>



<p>And then it says it&#8217;s regain control.</p>



<p>And this line in the middle, which is just an empty new line,</p>



<p>that&#8217;s definitely from the assembly program.</p>



<p>Because at the top here we have CRLF.</p>



<p>If I call it multiple times CRLF,</p>



<p>then you&#8217;ll see there are multiple blank lines.</p>



<p>All right, I&#8217;m gonna take that out.</p>



<p>Now let&#8217;s continue with while test.</p>



<p>So what should we do here?</p>



<p>The first thing that we should do is print an intro message</p>



<p>message just to let the user know that we&#8217;re about to you know begin our while</p>



<p>tests and if we run the program one more time we should see that message now</p>



<p>begin the while test your numbers will be printed back to you system calls and</p>



<p>simple printing is covered in other videos so now uh you know for me I kind</p>



<p>of like to init all of my loops even if it&#8217;s a while loop and not just a for</p>



<p>loop or anything so I always have an extra label that I like to call init</p>



<p>or before or something like that.</p>



<p>So I have a label now called while test underscore init,</p>



<p>and it&#8217;s just where I&#8217;m gonna initialize</p>



<p>whatever it is that I think I need to initialize</p>



<p>so that the loop will actually work.</p>



<p>If you look here, all I&#8217;m really doing is setting R12 to zero</p>



<p>because what I&#8217;m gonna do is stop the loop.</p>



<p>I&#8217;m gonna break the loop whenever the user enters a 99.</p>



<p>So I don&#8217;t know what&#8217;s inside of R12</p>



<p>when we first start this function.</p>



<p>And I just wanna make sure that it&#8217;s not 99,</p>



<p>the stopping number at the very start so I&#8217;m just going to set it to zero. So</p>



<p>another note about my labels you don&#8217;t have to do it this way but I love to</p>



<p>write labels where the first part of the label is always the function that the</p>



<p>label is inside of so notice how the function is named while test and so my</p>



<p>label is always while test underscore something and I&#8217;m putting init here</p>



<p>just to say we&#8217;re initializing the loop but if you had a function that had a</p>



<p>had a lot of stuff going on in it for starters you should probably be breaking up that function</p>



<p>into multiple functions but but assuming you didn&#8217;t uh you should probably do another underscore</p>



<p>and then like another component and then another underscore based on what giant chunk of your</p>



<p>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>you probably want to you know stick that into your labels your labels will get huge but for me</p>



<p>infused in assembly and this makes it easier.</p>



<p>So we&#8217;re going to initialize so that we can run our while loop and then the next thing</p>



<p>we&#8217;re going to do is implement the top of the while loop.</p>



<p>So remember if we looked at this code up here, maybe if I drag this over to the side and</p>



<p>pin it to the top for a little while, you can see that the top of the while loop is</p>



<p>where we kind of evaluate the expression to see if we need to keep going or not.</p>



<p>jump into the ending area, the done area. So the top, whoops, the top is always for that.</p>



<p>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>In this particular while loop, we want to compare the user&#8217;s input, which is R12 to the number 99.</p>



<p>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>So by the way, you&#8217;re probably wondering how did R12 get the user&#8217;s input?</p>



<p>Well, we&#8217;re going to do that as the next step.</p>



<p>And of course, your design pattern may vary a little bit.</p>



<p>No, that&#8217;s okay.</p>



<p>I just like to implement it this way.</p>



<p>So first thing we&#8217;re going to do is compare R12 with 99.</p>



<p>And that&#8217;s why I&#8217;ve written this comment here, just like the blank while comparison part.</p>



<p>And I guess I could have put this R12 not equal to 99 up at the top, but then it kind</p>



<p>of feels like I&#8217;m leaving these other two instructions.</p>



<p>So I moved it down one.</p>



<p>these other two instructions so I moved it down one so basically as long as you know we compare</p>



<p>R12 and 99 compare and conditional branching is covered in other videos but we compare those two</p>



<p>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>will be like a short jump which will be within the range of a conditional branch</p>



<p>So anyway, if the not equal branch didn&#8217;t happen, that means R12 is equal to 99.</p>



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



<p>So basically we&#8217;re saying, if it&#8217;s true, we continue looping.</p>



<p>If it&#8217;s not true, we just jump outside of the loop.</p>



<p>We&#8217;re just totally done with the while loop.</p>



<p>Okay.</p>



<p>So then we need a body, because obviously we&#8217;re going to jump into the body here.</p>



<p>that means I&#8217;m going to just copy paste another little set of code here.</p>



<p>Right after that unconditional jump.</p>



<p>So now we got the body.</p>



<p>Notice how I put a little comment here that has a brace just to indicate to you,</p>



<p>hey, this is the beginning of the actual while loop body,</p>



<p>just to make it a little bit more clear.</p>



<p>And what are we going to do inside of the body?</p>



<p>We&#8217;re just going to ask the user for some input.</p>



<p>So I&#8217;m printing a simple message here,</p>



<p>and then I&#8217;m calling on my helper function</p>



<p>to just actually input a number from the user.</p>



<p>I&#8217;m going to store that number into R12.</p>



<p>So that&#8217;s how R12 gets the numbers, gets the user&#8217;s input.</p>



<p>And the way I&#8217;ve written this, if the user enters a 99,</p>



<p>it&#8217;ll echo it back to the user and then it&#8217;ll break the loop afterwards.</p>



<p>So, you know, if you wanted to rearrange things like I talked about before,</p>



<p>where you input before you check to see if you&#8217;re going to keep going, you could do that.</p>



<p>But it would be a little harder to echo the user&#8217;s input back to them before you break.</p>



<p>I don&#8217;t know. It&#8217;s up to you.</p>



<p>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>message basically saying here&#8217;s the thing that you inputted no problem and then again we use</p>



<p>one of my helper functions to actually spit the number back out at them so this is not</p>



<p>a very complicated body it&#8217;s just asking for a number and then printing the number back to them</p>



<p>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>we don&#8217;t really have to do this label but for clarity I think it&#8217;s probably a good idea</p>



<p>I think it&#8217;s probably a good idea.</p>



<p>So the very bottom of the while loop&#8217;s body is usually where you don&#8217;t do any more instructions</p>



<p>that are part of the work of the while loop&#8217;s body,</p>



<p>but just sort of the place where you jump back up to the top</p>



<p>so you can evaluate and decide to continue or not again.</p>



<p>So notice how I&#8217;m using an unconditional jump here.</p>



<p>That&#8217;s a good idea because again, if you have like a huge while loop body,</p>



<p>you might end up surpassing the threshold of 128 bytes</p>



<p>of 128 bytes and then you&#8217;ll get a assembler error that says</p>



<p>I can never remember this. It&#8217;s like a</p>



<p>jump out of range error or something like that. Basically, if you do a conditional branch to jump up the top</p>



<p>because some people like to check to see</p>



<p>if they should continue the loop, they like to check for that at the bottom. I&#8217;ve done that before.</p>



<p>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>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>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>end of the body. Okay, no problem. Now let&#8217;s do the done label, which is basically where we jump</p>



<p>if the loop is actually finished. So remember, if this expression right here evaluates to false,</p>



<p>then execution is going to fall through to line 84, where we jump to this while test done label.</p>



<p>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>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>here on line nine of the little notepad. And we can just kind of do whatever we want. At that</p>



<p>point, we can return to a caller, we can just do other stuff, we can, you know, do a different</p>



<p>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>goodbye with this little print to just sort of like, you know, print an exit message. And then</p>



<p>we&#8217;ll do the epilogue where we restore R12. And then we just return to the caller,</p>



<p>the driver worry about exiting the program okay so if we&#8217;ve done this correctly we should now have</p>



<p>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>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>99 the program will just continue forever so this is a while loop if i want to quit i do 99</p>



<p>breaks at the top it breaks by jumping down to the done area where we print our goodbye message</p>



<p>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>immediately breaks you know it prints out what you entered but then it immediately breaks</p>



<p>and that&#8217;s it that&#8217;s uh the basics for how to write a while loop you just use basically</p>



<p>layered on top of an abstract concept of what you think a while loop is,</p>



<p>or what I guess the world thinks a while loop is.</p>



<p>Okay, thank you so much for watching this video.</p>



<p>I hope you learned a little bit of stuff and had a little bit of fun.</p>



<p>I&#8217;ll see you in the next video.</p>



<p>Hey everybody.</p>



<p>Thanks for watching this video again from the bottom of my heart.</p>



<p>I really appreciate it.</p>



<p>I do hope you did learn something and have some fun.</p>



<p>if you could do me a please a small little favor could you please subscribe and follow this channel</p>



<p>or these videos or whatever it is you do on the current social media website that you&#8217;re looking</p>



<p>at right now it would really mean the world to me and it&#8217;ll help make more videos and grow this</p>



<p>community so we&#8217;ll be able to do more videos longer videos better videos or just i&#8217;ll be able</p>



<p>to keep making videos in general so please do do me a kindness and uh and subscribe you know</p>



<p>I&#8217;m sleeping in the middle of the night and I just wake up because I know somebody subscribed or followed.</p>



<p>It just wakes me up and I get filled with joy.</p>



<p>That&#8217;s exactly what happens every single time.</p>



<p>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>Just subscribe and then I&#8217;ll just wake up.</p>



<p>I promise that&#8217;s what will happen.</p>



<p>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>which I think is also named somewhere at the bottom of this video.</p>



<p>and it&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p>i published and the services and tutorials and things that i offer and all that good stuff and</p>



<p>if you have a suggestion for uh uh clarifications or errata or just future videos that you want to</p>



<p>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>just send me a comment whatever i also wake up for those in the middle of the night i get</p>



<p>it would really mean the world to me. I would really appreciate it.</p>



<p>So again, thank you so much for watching this video and</p>



<p>enjoy the cool music as I fade into</p>



<p>the darkness which is coming for us all.</p>



<p>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>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>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>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>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>Next video will cover conditional jumps (je, jne, jg, jl, etc.) and their limitations.</p>



<p>Enjoy the video and happy coding at the machine level!</p>



<p>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>Thanks for watching!</p>



<p>Find us on other social media here:</p>



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



<p>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>Hello there.</p>



<p>In this video, we&#8217;re going to be talking about jump instructions in assembly.</p>



<p>This video is going to be about x86-64 Yasm assembly,</p>



<p>but I think probably anyone who&#8217;s interested in jump instructions</p>



<p>will benefit from this video because the concept is usually the same</p>



<p>throughout any system that you might use.</p>



<p>So for starters, I want to direct your attention to a textbook</p>



<p>that I think is wonderful.</p>



<p>This is an open source free textbook that will help you become an expert in assembly.</p>



<p>It&#8217;s not mine, I didn&#8217;t write it.</p>



<p>The author is Professor Ed Jorgensen, PhD.</p>



<p>He releases this textbook for free.</p>



<p>It&#8217;s under a copyleft license so you can literally just go to his website and download it and</p>



<p>send it to your friends and everything and it&#8217;s wonderful.</p>



<p>This book will take you from zero to hero when it comes to Yasm Assembly.</p>



<p>It&#8217;s wonderful and amazing.</p>



<p>This is the book and I just want to show you the section on jump instructions real fast</p>



<p>and then I&#8217;ll talk about them a little bit and then I&#8217;ll show you a sample program that</p>



<p>uses jump instructions.</p>



<p>So this version of the book that I&#8217;m working with right now is May 2024 version 1.1.56.</p>



<p>I&#8217;m going to go down to let&#8217;s see section 7 instruction set overview.</p>



<p>Inside of there there&#8217;s another subsection called where the heck is it control instructions</p>



<p>instructions 7.7 within that there&#8217;s a another subsection called 7.7.2 that&#8217;s</p>



<p>why I look this other not one of the many reasons that I love this book it</p>



<p>has so many subsections there&#8217;s just so many yummy subsections to organize</p>



<p>everything in a way that you can find it all so fast and okay so we&#8217;re looking</p>



<p>at unconditional control instructions in other words a jump instruction if</p>



<p>you&#8217;re an old-school programmer especially if you use some sort of like</p>



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



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



<p>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>and we will literally just change execution to to jump to some other location just kind of go there</p>



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



<p>instruction that told us to jump back.</p>



<p>So we&#8217;re not calling and returning.</p>



<p>We&#8217;re just going somewhere and that&#8217;s it.</p>



<p>Obviously it&#8217;s a little bit more convenient to be able to call functions,</p>



<p>but that&#8217;s sort of like an abstraction that has to be implemented after we</p>



<p>understand how to jump. So anyway, the jump instruction is pretty simple.</p>



<p>You just put JMP in Yasm anyway, and then follow it with a label.</p>



<p>So, you know, just as a quick little recap here, what&#8217;s a label?</p>



<p>imagine we have an assembly program here and maybe here&#8217;s our text section and we put some</p>



<p>instructions maybe there&#8217;s like an entry point right here I&#8217;ll say a global entry point and</p>



<p>literally just taking the word entry point and putting a colon after it now makes that a label</p>



<p>so if there are any instructions underneath I&#8217;m gonna put a bunch of nopes then if someone somewhere</p>



<p>to say jump entry point they should be able to go right here to instruction 8 and then start</p>



<p>executing downward. I guess maybe I didn&#8217;t need to put the global keyword global just means let&#8217;s</p>



<p>make this label available to other modules within the same program so if you have a multi-source</p>



<p>program or a hybrid program with multiple different languages then you know you should do this but if</p>



<p>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>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>So imagine on line 16, you add some instructions just to kind of exit.</p>



<p>If I wanted to skip all these nope instructions for some reason, I could just do this.</p>



<p>I could say jump hello.</p>



<p>And what would happen is execution.</p>



<p>Oh, I can use my pen.</p>



<p>Execution would just sort of, you know, it would come into the text section.</p>



<p>you know, it&#8217;d come into the text section.</p>



<p>It would go down through the label and it would execute this first jump</p>



<p>instruction and then execution would jump over the nopes into the hello label.</p>



<p>And then, you know, if there was other stuff here, then it would get executed.</p>



<p>So by jumping over the nopes,</p>



<p>I&#8217;m essentially saying that the nopes should not actually end up being</p>



<p>executed. They&#8217;ll be there in the program, but they won&#8217;t actually execute.</p>



<p>So that&#8217;s the basics of a jump instruction. Okay.</p>



<p>So what else do I need to tell you real fast?</p>



<p>What else do I need to tell you real fast?</p>



<p>Oh, one thing that&#8217;s really good about jump instructions is they have unlimited jump range.</p>



<p>So you can jump from a place at the very, very beginning of your assembly program and</p>



<p>jump to a place that is at the very, very, very end of your assembly program.</p>



<p>There&#8217;s not going to be a limitation on how far you can jump.</p>



<p>I mean, in theory, there&#8217;s a limit, but practically speaking, there&#8217;s not a limit.</p>



<p>Why would you care that there&#8217;s not a limit?</p>



<p>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>conditional branching which is sort of a jump that only jumps if a certain condition is true</p>



<p>and those have limited ranges where they can jump so there&#8217;s going to be a bunch of different</p>



<p>instructions but one of the conditional branching instructions is jne and another one is jge and</p>



<p>there&#8217;s another one that&#8217;s je basically you know jump if something is equal jump if something is</p>



<p>can only jump about 128 bytes away.</p>



<p>So after your assembler assembles and compiles</p>



<p>down to object code,</p>



<p>and then after your linker links your final executable,</p>



<p>wherever it is that the instructions happen to end up</p>



<p>inside of your program,</p>



<p>the conditional jumps,</p>



<p>the conditional branching instructions,</p>



<p>they can&#8217;t jump more than 128 bytes away</p>



<p>to some other instruction.</p>



<p>So keep that in mind.</p>



<p>Even if later on you graduate</p>



<p>to making decisions in your program,</p>



<p>like I&#8217;m going to do in the next video,</p>



<p>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>jump too far you actually might not be able to jump at all unless you jump a very short jump</p>



<p>to a regular jump instruction and then that jump instruction jumps very very far away that&#8217;s kind</p>



<p>of the workaround for it i&#8217;m not going to talk about that in this video though this is not a</p>



<p>video for uh conditional branching i just wanted you to be aware of one of the benefits of regular</p>



<p>Okay, so we&#8217;re looking at the book here.</p>



<p>There&#8217;s not really a whole lot to the jump instruction, just jump and then a label.</p>



<p>We talked about its benefit over conditional branch instructions,</p>



<p>but we also talked about its, I guess, its shortcoming,</p>



<p>meaning it can&#8217;t actually make a decision.</p>



<p>It will always jump to a label no matter what.</p>



<p>There&#8217;s no condition.</p>



<p>So there&#8217;s the book there, and now I&#8217;m going to make a sample program</p>



<p>and show you how to run it.</p>



<p>I&#8217;m just going to run it.</p>



<p>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>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>not going to be talking about that in this video this is also a hybrid program so there&#8217;s a C++</p>



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



<p>want to know how to make hybrid programs you want to generate make files you want to learn the basics</p>



<p>videos for now we&#8217;re only going to be talking about jump instructions so I&#8217;m</p>



<p>going to skip a lot of information okay so for starters I&#8217;m going to make a</p>



<p>little data section here and again this is explained in other videos but for now</p>



<p>we&#8217;ll just trust that we can make a data section that contains strings C strings</p>



<p>and other values so pretty much I&#8217;m just going to make a string called begin jump</p>



<p>test just to announce to the user that we&#8217;re we&#8217;re going to start doing this</p>



<p>We&#8217;re going to start doing this and then I&#8217;m going to make a string called this message</p>



<p>should not appear.</p>



<p>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>the call to print it just to prove to you that there are instructions that would print</p>



<p>that message, but we&#8217;re jumping over them with the jump instruction.</p>



<p>And then there&#8217;s like an exit message.</p>



<p>And then there&#8217;s a CRLF, which is just a carriage return line feed.</p>



<p>Again, all of this stuff is in other videos already.</p>



<p>So we&#8217;re going to use system call one to print.</p>



<p>We&#8217;re going to print a file descriptor one, which is just standard output for your program.</p>



<p>Then we&#8217;re going to start the text section where the actual code lives.</p>



<p>So this text section is here and it&#8217;s supposed to be at line 37 already.</p>



<p>I think I missed a bunch of lines.</p>



<p>Oh no, I think I missed some comments.</p>



<p>Anyway, so we have a text section here and an entry point and I&#8217;m calling it cool.</p>



<p>calling it cool and I am marking it as global because in this particular program that I&#8217;m</p>



<p>building it&#8217;s a hybrid program there&#8217;s going to be a C++ module that will call on our cool</p>



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



<p>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>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>finished we&#8217;re going to return to the caller which is going to be the driver and that&#8217;ll</p>



<p>pretty much be it.</p>



<p>So if I comment this out real fast, let&#8217;s see,</p>



<p>this might actually work.</p>



<p>Let&#8217;s see if I can get it to run in the terminal.</p>



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



<p>So let&#8217;s do clear and make run.</p>



<p>And it seems to not have a shared object directory.</p>



<p>Let me pause the video while I copy paste one of my stupid libraries into the</p>



<p>program. You don&#8217;t need this library.</p>



<p>It just helps me print things.</p>



<p>okay so now I have copy pasted my shared object which allows me to do extra printing stuffs</p>



<p>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>it to to learn jump instructions anyway so I&#8217;m going to do that again and now it actually prints</p>



<p>something okay so hello from the main CPP driver and then it says the driver has regained control</p>



<p>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>well I guess this thing is kind of short I could copy paste the whole thing all at once.</p>



<p>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>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>It&#8217;s just a convenience function that I made so I can print a carriage return line feed.</p>



<p>The real interesting thing here is the jump test function.</p>



<p>So we were just making a call to jump test.</p>



<p>Now we&#8217;re making the actual jump test function.</p>



<p>It&#8217;s got a signature of just void with no arguments.</p>



<p>So it&#8217;s not super interesting from the caller&#8217;s perspective, but it does some stuff.</p>



<p>So for starters, it has an intro message.</p>



<p>So this will print, you know, hello, welcome to the jump test.</p>



<p>jump test. In fact, if I do a return call here,</p>



<p>it should actually just print that and do nothing else. Right. Okay.</p>



<p>Notice how it printed, begin the jump test.</p>



<p>And then right after that,</p>



<p>there&#8217;s a jump instruction just proving to you that we can jump over other</p>



<p>instructions. So look at this,</p>



<p>this piece of code should never actually be called because we&#8217;re going to jump</p>



<p>over it. What it is, is it&#8217;s printing that jump shouldn&#8217;t happen message.</p>



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



<p>but we&#8217;re going to jump over that by using this jump instruction here on line 66.</p>



<p>Again note that the jump instruction is just jmp followed by a label the label specified has to be</p>



<p>where you want to jump it&#8217;s never going to return from that place unless you specifically jump back</p>



<p>somehow later on like i guess if we wanted to we could put a label on line 67 call it the return</p>



<p>call it the return point and then jump back from it after the jump point in fact maybe that would</p>



<p>be kind of interesting to do at the end of this video but otherwise we&#8217;re gonna you know just</p>



<p>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>so imagine execution uh comes into this program you know we&#8217;re executing uh instructions we&#8217;re</p>



<p>calling crlf we&#8217;re just executing executing as soon as we hit this jump instruction then execution</p>



<p>then execution jumps over into the label that I specified.</p>



<p>So this whole code section here just never even gets called.</p>



<p>So that&#8217;s why we will not see that message.</p>



<p>And then at the very end, all I&#8217;m doing is I&#8217;m just properly,</p>



<p>you know, I&#8217;m printing the exit message.</p>



<p>So I&#8217;m just printing another string saying the exit or the jump test is done.</p>



<p>I return to the caller execution goes all the way back up to just you know right here right after</p>



<p>call jump test was executed and then the cool function will return to the caller and that&#8217;s</p>



<p>just a c++ main function that does nothing so at this point we should see the whole entire point of</p>



<p>the program and then I&#8217;ll start tweaking it so you can kind of see the difference with the jump</p>



<p>instruction uh there and not there so let&#8217;s run one more time and notice how it says begin the</p>



<p>says begin the jump test and then end jump test and then it goes back to the driver that is</p>



<p>regain control it never says this message should not be printed so this whole section was just</p>



<p>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>see that that message does get printed so notice how it says this message should not appear okay</p>



<p>and then run the program one more time.</p>



<p>Now that message does not appear.</p>



<p>Pretty cool.</p>



<p>Now let&#8217;s do that double jumping thing just to show you.</p>



<p>I mean, this is not something that you actually want to do.</p>



<p>You probably want to write functions and function calls,</p>



<p>but if you wanted to, you could do something like this.</p>



<p>Here&#8217;s the exiting.</p>



<p>And maybe right after this, let&#8217;s make another label.</p>



<p>Let&#8217;s do, oh gosh, what am I going to do?</p>



<p>what am I going to do? Because if I jump after the exiting label and I jump back up to some label</p>



<p>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>if I make another label down at the bottom, you&#8217;ll kind of think it&#8217;s a function just without</p>



<p>a return statement. So let&#8217;s actually jump within the same function. Let&#8217;s do, um,</p>



<p>over the never area.</p>



<p>So I&#8217;m going to say jump test and I&#8217;m going to write never.</p>



<p>So now we have a label that tells us where the never printed message actually starts.</p>



<p>So if we jump over it to the exiting, then we&#8217;re good.</p>



<p>But then if I up here, if I say jump instruction that subverts</p>



<p>never message so I&#8217;m just I&#8217;m just leaving a comment not code I could then</p>



<p>say let&#8217;s jump to jump test never and what will happen now is we&#8217;ll still see</p>



<p>the never message because what will happen is execution comes down you know</p>



<p>through here all these instructions are executing and then we see a jump that</p>



<p>tells us to go to the the never label so we actually jump over this exiting jump</p>



<p>over this exiting jump or this like the skipping jump,</p>



<p>the jump that skips the message.</p>



<p>And then we actually do print the never message</p>



<p>and we just keep going down and down and down</p>



<p>until we&#8217;re finished with that.</p>



<p>And we end up just sort of exiting normally.</p>



<p>So that means the only code that doesn&#8217;t get executed</p>



<p>in this case is the one right here</p>



<p>that skips over the never message.</p>



<p>Hopefully that makes sense.</p>



<p>Let&#8217;s run the program just to prove it real fast.</p>



<p>So I&#8217;m going to do this again.</p>



<p>And now you see the message should not appear.</p>



<p>This message should not appear.</p>



<p>You see that message.</p>



<p>So again, if we comment out that jump that subverts the skip, then execution will fall</p>



<p>through and we&#8217;ll end up executing line 69, the skipping instruction.</p>



<p>again now that message does not appear.</p>



<p>We could jump back and forth if we wanted to.</p>



<p>I don&#8217;t know.</p>



<p>Should I do a back and forth?</p>



<p>I don&#8217;t really want to.</p>



<p>I think at this point you understand we can jump anywhere we want, right?</p>



<p>I could take a bunch of time in this video to rewrite this program and have it say,</p>



<p>let&#8217;s jump downward and then let&#8217;s jump upward again and let&#8217;s let it fall through</p>



<p>and then let&#8217;s jump over something and whatever.</p>



<p>let&#8217;s jump over something and whatever. I mean, just wherever you want to jump,</p>



<p>just make a label and then jump to it. Then you have to figure out what your execution path is</p>



<p>actually going to be. And maybe that&#8217;ll be complicated, but I hope I&#8217;ve made my point by</p>



<p>now. Anyway, so that&#8217;s the basics of just jumping around. It&#8217;s not super useful. Conditional</p>



<p>branching is a lot better. So see my next video. And I thank you for watching this and I hope you</p>



<p>learned a little bit and had a little fun. See you soon.</p>



<p>See you soon.</p>



<p>longer videos, better videos, or just I&#8217;ll be able to keep making videos in general.</p>



<p>So please do me a kindness and subscribe. You know sometimes I&#8217;m sleeping in the</p>



<p>middle of the night and I just wake up because I know somebody subscribed or</p>



<p>followed. It just wakes me up and I get filled with joy. That&#8217;s exactly what</p>



<p>happens every single time. So you could do it as a nice favor to me or you could</p>



<p>you could troll me if you want to just wake me up in the middle of the night.</p>



<p>Just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen.</p>



<p>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>which I think is also named somewhere at the bottom of this video and</p>



<p>It&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p>I published and the services and tutorials and things that I offer and all that good stuff and</p>



<p>If you have a suggestion for</p>



<p>Clarifications or errata or just future videos that you want to see</p>



<p>please leave a comment or if you just want to say, Hey, what&#8217;s up, what&#8217;s going on?</p>



<p>You know, just send me a comment, whatever. I also wake up for those in the middle of the night.</p>



<p>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>I would really appreciate it. So again, thank you so much for watching this video and, um,</p>



<p>enjoy the cool music as, as I fade into the darkness, which is coming for us all.</p>



<p>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>
	</channel>
</rss>
