<?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 assembly tutorial Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/x86-assembly-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/x86-assembly-tutorial/</link>
	<description></description>
	<lastBuildDate>Mon, 16 Mar 2026 06:39:34 +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>x86 assembly tutorial Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/x86-assembly-tutorial/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>x86-64 Assembly: Local Variables, Stack Frames &#038; Alignment Explained</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-local-variables-stack-frames-alignment-explained/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-local-variables-stack-frames-alignment-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 16 Mar 2026 06:39:32 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[16 byte alignment]]></category>
		<category><![CDATA[assembly array on stack]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[assembly stack allocation]]></category>
		<category><![CDATA[calling convention]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[local variables stack]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[NASM tutorial]]></category>
		<category><![CDATA[printf crash assembly]]></category>
		<category><![CDATA[rbp rbp stack]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[stack alignment]]></category>
		<category><![CDATA[stack frame assembly]]></category>
		<category><![CDATA[sub rsp assembly]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[x64 assembly]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=317</guid>

					<description><![CDATA[<p>Learn how local variables are allocated on the stack in x86-64 assembly using YASM. See exactly how to reserve space, address variables with offsets, understand downward stack growth, and fix mysterious printf segfaults caused by 16-byte stack misalignment. Includes two alignment solutions and a complete working example with a local integer array.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-local-variables-stack-frames-alignment-explained/">x86-64 Assembly: Local Variables, Stack Frames &amp; Alignment Explained</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: Local Variables, Stack Frames &amp; Alignment Explained" width="1380" height="776" src="https://www.youtube.com/embed/woCCcOlopNo?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>Quick but deep look at local variables on the stack in x86-64 assembly (YASM). We cover allocation with sub rsp, accessing via offsets, why the stack must be 16-byte aligned when calling libc functions like printf, and two practical ways to fix alignment crashes. Includes live segfault debugging and a full working example with a local array.</p>



<p>Great for anyone studying systems programming, computer architecture, or just trying to figure out why their assembly program randomly crashes on a library call.</p>



<p>Like + subscribe if you want more clear, practical assembly tutorials!</p>



<p>00:00 Introduction to Local Variables on the Stack<br>00:28 C++ Example of Function and Local Variables<br>01:06 Incoming Arguments in RDI vs Stack Variables<br>03:24 Pointers as Local Variables on Stack<br>04:34 Why the Stack – Recursion and Multiple Calls<br>05:18 Visualizing Multiple Stack Frames<br>09:24 How Function Returns Adjust RSP<br>10:35 Stack Grows Downward in Memory<br>11:33 Program Setup – Hybrid C++/Assembly<br>12:46 Assembly Module Overview<br>14:00 Function Prologue – Register Push &amp; Alignment<br>15:30 Allocating Stack Space for Local Array<br>17:45 Initializing Array in Loop<br>20:10 Printing Loop with printf<br>49:48 First Run – Segfault Observed<br>51:00 16-Byte Stack Alignment Requirement<br>51:55 Fix 1 – Extra Push/Pop in Prologue/Epilogue<br>53:15 Fix 2 – Push/Pop Around Each printf Call<br>55:04 Testing Different Array Sizes<br>56:52 Debugging Alignment Behavior<br>58:54 Summary – Creating Any Local Data on Stack<br>59:59 Closing Remarks &amp; Subscribe Call</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 the Blog: https://www.NeuralLantern.com</li>



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



<p>Hi there! Today I&#8217;d like to talk to you about local variables on the stack</p>



<p>in an x8664 assembly program written in YASM.</p>



<p>If you don&#8217;t understand assembly or local variables or other things like that you might</p>



<p>want to see my other videos but I&#8217;m just going to give you a quick example. So what am I talking</p>



<p>about with local variables on the stack? For starters forget what you&#8217;re seeing here for a</p>



<p>blank code page and pretend that we&#8217;re coding in c plus plus just for a moment this is an assembly</p>



<p>video but pretend this is c plus plus so suppose you have c plus plus you have a main function here</p>



<p>and at the end of it you know this is your entry point for your program we return zero and maybe</p>



<p>above it there&#8217;s a function called f i&#8217;m putting it above because i don&#8217;t want to use prototypes</p>



<p>in this video but you should probably use prototypes um maybe main calls on f and so then</p>



<p>what happens? I don&#8217;t know. Maybe we have some arguments. We&#8217;ll call this integer argument A</p>



<p>that comes in. If you&#8217;ve watched my other videos, hopefully you have by now,</p>



<p>you&#8217;ll know that A comes into the function as RDI because that&#8217;s the first integer argument</p>



<p>register. But then when we start creating local variables, we&#8217;ll say integer B equals, let&#8217;s say,</p>



<p>a five and then integer C is equal to an eight for whatever reason. Maybe there will be an array.</p>



<p>So I&#8217;ll call this a int array, I guess.</p>



<p>We&#8217;ll say that we have 100 integers in our array.</p>



<p>We could also have a pointer, int pointer p,</p>



<p>and then allocate it to some kind of new memory just to prove a point.</p>



<p>And then, you know, later in your function,</p>



<p>you&#8217;re probably going to want to do something with your data.</p>



<p>So I don&#8217;t know, maybe a, how about like b is plus equal to a,</p>



<p>of C++ and then oh C++ C is plus equal to B for some reason I&#8217;m just making random nonsense up</p>



<p>honestly I&#8217;m just showing you that we use our variables and then maybe you want to build an</p>



<p>array so we just declared the array up here on line six but maybe you want to actually do something</p>



<p>with it you want to fill it with data maybe so I&#8217;ll do size type I is zero keep going until I</p>



<p>is less than as long as I is less than 100 I plus plus and now I&#8217;m going through every single index</p>



<p>array maybe I&#8217;ll say the array at index i is equal to c and then we&#8217;ll just say c is plus equal to b</p>



<p>and then we&#8217;ll do b plus plus just to have something in there okay so let me explain the</p>



<p>parts of your program real fast if you haven&#8217;t watched my other videos please do because this</p>



<p>should help a little bit anyway so a is an incoming argument like I said before that&#8217;s</p>



<p>usually coming to you in the RDI register because it&#8217;s the first integer argument so we don&#8217;t need</p>



<p>to worry too much about that we know that a is actually just a register in your CPU and b that&#8217;s</p>



<p>created on the stack and c is created on the stack also and the array is created on the stack by the</p>



<p>way I could name the array anything if I wanted to like just v I&#8217;m using the name array because</p>



<p>Notice also that we have a pointer here. I just wanted to make a point that the pointers we make in our function are considered local variables.</p>



<p>And that means they do sit on the stack because what I&#8217;m trying to say is that local variables that are not arguments, they sit on the stack.</p>



<p>But the memory we allocated and then gave to the pointer, that&#8217;s sitting in the heap somewhere.</p>



<p>So when you use the new operator or the malloc operator, or you&#8217;re just like making dynamic memory,</p>



<p>that dynamic memory sits in the heap, but the pointer itself, since we just declared it here,</p>



<p>that sits on the stack. That means later on when your function ends, the p pointer itself will get</p>



<p>cleaned up automatically and itself won&#8217;t be leaked memory. But if you forget to clean up your memory</p>



<p>here, like I did, you&#8217;ll have a memory leak. But I&#8217;m going to talk about memory leaks probably in</p>



<p>some other videos somewhere else at another time. Anyway, so then we have our local variables here.</p>



<p>remember B and C and array are all on the stack and well we just have our</p>



<p>for loop here where we just kind of start modifying data so why would we use</p>



<p>the stack let me just do a quick tutorial this is not a stack video I&#8217;m</p>



<p>gonna make a stack video in the future but I&#8217;ll just do like a quick little</p>



<p>rundown of what is the stack and why is it really good for function calls</p>



<p>consider that sometimes F might want to call itself maybe it&#8217;s a recursive</p>



<p>be like a long chain of function calls like f calls g and g calls h and h calls you know whatever</p>



<p>and it just goes on and on and on as long as it&#8217;s not infinite recursion like all the functions are</p>



<p>calling themselves in one circle that never ends you should be allowed to do that we should be</p>



<p>allowed to have a function f that sometimes calls itself or other functions or maybe it&#8217;s called</p>



<p>multiple times within our giant call stack our call graph and this will work because these</p>



<p>you know a b and c and array are sitting on the stack and the stack allows you to have sort of</p>



<p>different instances of variables so for example and this is just a quick thing i&#8217;m not this is</p>



<p>not supposed to be a full stack tutorial here but um you know if we have like the function f</p>



<p>and let&#8217;s say we call it at some point maybe uh maybe main calls f uh and then let&#8217;s let&#8217;s pretend</p>



<p>f and then f calls h and then maybe h calls f and um did i write an h there no i think that&#8217;s</p>



<p>supposed to be a parenthesis i&#8217;m sorry i have bad penmanship oh god it&#8217;s even worse hang on let me</p>



<p>let me do another h here i&#8217;ll just do it i&#8217;ll just do a g about that f g and then uh</p>



<p>F again. Let&#8217;s just pretend that we can have a call graph where F is sometimes called by something</p>



<p>and sometimes called something else or maybe sometimes F is called by a different thing. So</p>



<p>like I guess this was supposed to be the G function. So maybe that&#8217;s why down here was the H.</p>



<p>Should I delete this video? I don&#8217;t know. You know what? I&#8217;m going to start. I&#8217;m going to delete this</p>



<p>and then G calls H and then H calls F and then F calls I I guess and then</p>



<p>eventually these functions start returning right oops how come my greens</p>



<p>not working green there we go too late now so we can have like a really</p>



<p>complicated call graph and F might appear in there multiple times and the</p>



<p>Each call to F along the call graph should have its own copy, unique copy of local variables.</p>



<p>So the B for this first F call, let me just do an arrow here, will have a B.</p>



<p>And you can imagine it as B subscript 1.</p>



<p>And down here when F executes, you can imagine that it&#8217;s got its own copy of B.</p>



<p>So we can imagine this as B subscript 2.</p>



<p>So these are two totally different Bs.</p>



<p>If you tried to use global variables for this, it would be really, really, really hard to get the code to work.</p>



<p>get the code to work and it would be really, really hard to debug.</p>



<p>So that&#8217;s kind of why we have local variables.</p>



<p>The stack allows us to do this.</p>



<p>So what is the stack itself?</p>



<p>Again, this is not a full tutorial on the stack,</p>



<p>but I just want you to kind of see what&#8217;s happening.</p>



<p>Imagine a data structure that kind of grows upward.</p>



<p>I&#8217;ll say that here&#8217;s the floor at the bottom.</p>



<p>And when you put an item onto the stack,</p>



<p>the items kind of stack on top of each other.</p>



<p>So imagine that this is the call to F.</p>



<p>is the call to f and embedded within this little stack frame area we&#8217;ll call it a stack frame but</p>



<p>actually the stack continues to grow as you create and destroy local variables within a function call</p>



<p>we&#8217;ll just imagine that there&#8217;s i don&#8217;t know a mini stack sitting inside of the stack that</p>



<p>contains all the local variables i&#8217;ll just put i&#8217;m not going to put a because a is an argument so</p>



<p>it&#8217;s sitting in a register but we could do dude i got to learn how to how to draw with this tablet</p>



<p>We got to do B and C and the array.</p>



<p>I&#8217;ll put AR for array.</p>



<p>Sitting in, you know, their own little spots on the stack within the major portion of the stack that is designated for that first F call.</p>



<p>And then, you know, maybe F calls G and some other stuff happens.</p>



<p>I&#8217;ll just pretend that a bunch of other stuff happened.</p>



<p>And then eventually F is called again.</p>



<p>But there&#8217;s a different, this is a different instance of the call to F.</p>



<p>it&#8217;s got its own little area that is separate from the the previous call to f and again we&#8217;ll</p>



<p>also have variables that we can create locally that are supposed to be separate from the original</p>



<p>variables oh god that&#8217;s awful and ugly i need to maybe decrease the size of my eraser or something</p>



<p>but imagine this is uh you know these are two separate copies so that&#8217;s like what i said before</p>



<p>when we have like a b1 and a b2 basically they&#8217;re not going to be called b1 and b2 but they&#8217;re just</p>



<p>They&#8217;re not going to be called B1 and B2, but they&#8217;re just two separate instances.</p>



<p>And I just want you to know.</p>



<p>So then when we start returning from functions, like when this F eventually returns, and by</p>



<p>the way, I know that what I&#8217;m drawing on the right doesn&#8217;t match the code because this</p>



<p>is not a function that calls itself, but just suppose that your code is a lot more complicated</p>



<p>than what I drew up.</p>



<p>When it eventually returns, all that happens is those items on the stack just sort of get</p>



<p>not necessarily deallocated, but ignored.</p>



<p>We&#8217;ll just say that they&#8217;re gone.</p>



<p>They&#8217;re still sitting as junk data in system RAM somewhere.</p>



<p>And in assembly talk, we know that we have a stack pointer called RSP.</p>



<p>We have a register called RSP that just sort of points to the location in the</p>



<p>stack that is considered the top of the stack, like the most recent piece of data</p>



<p>that we have available.</p>



<p>So all the other data is actually still kind of above, but we&#8217;re not pointing to it</p>



<p>anymore, so we consider that it doesn&#8217;t exist.</p>



<p>So then when G eventually returns, you know, we just change the stack pointer,</p>



<p>Rsp, to point to that other piece of data.</p>



<p>The G data frame and the other F data frame are still sitting above somewhere in memory,</p>



<p>but we just ignore them, right?</p>



<p>So that&#8217;s how the stack works.</p>



<p>And that&#8217;s how we have local function call copies of all of our local variables.</p>



<p>Something to note.</p>



<p>Something to note, this is not a stack video, but you know, just something to note that</p>



<p>even though I draw the stack visually as growing vertically up, when you actually manipulate</p>



<p>the stack in assembly or just like in any language, the stack grows downward in terms</p>



<p>of memory locations.</p>



<p>So you can imagine, I&#8217;m trying so hard not to make this like a huge stack video.</p>



<p>Imagine this is a memory location 80, we&#8217;ll say.</p>



<p>You would think that memory location 81 would be the next item of the stack, or I guess</p>



<p>the stack or i guess if you if you&#8217;re considering the fact that the items on the stack are quad words</p>



<p>we would say it goes up to 88 but that&#8217;s not true it goes down to 72 so the memory location goes down</p>



<p>even though we imagine the stack growing uh upward vertically just so you know that&#8217;s the kind of</p>



<p>thing we&#8217;re going to do so what i&#8217;m going to do is just show you an assembly program where we can</p>



<p>create local variables and i&#8217;m just going to show you how to create an array because this array is</p>



<p>just like a bunch of integers and you can imagine it would be really easy to create only one integer</p>



<p>by just imagining an example where the array is a size of one so keep that in mind and i&#8217;m not going</p>



<p>to show you malloc or anything like that we&#8217;re just going to look at the local variables okay</p>



<p>so for starters i have a make file here that&#8217;s just going to compile a hybrid program if you don&#8217;t</p>



<p>know make files or you don&#8217;t know hybrid programs that&#8217;s okay just see my other videos i&#8217;ve explained</p>



<p>The first source code file here is just driver.cpp.</p>



<p>Again, this is a hybrid program,</p>



<p>so I&#8217;m going to mix my C++ modules with my assembly modules,</p>



<p>which is pretty cool.</p>



<p>The whole point of the driver is just to contain the entry point, you know, main.</p>



<p>And I&#8217;m just going to print a hello message.</p>



<p>And then I&#8217;m going to call the real function that I&#8217;m interested in,</p>



<p>which I&#8217;ve named local underscore varrs.</p>



<p>And that&#8217;s going to be all the assembly stuff that we talked about.</p>



<p>block so that C++ can call an assembly module that&#8217;s explained in other videos. And then</p>



<p>here&#8217;s the real heart of what we got to do. Let&#8217;s write up an assembly module</p>



<p>that can do local variables. Okay. So again, if you don&#8217;t know assembly, that&#8217;s okay,</p>



<p>but you need to watch my other videos before you can understand this one. So I&#8217;m going to just</p>



<p>copy paste some starter code here. This is Yasm assembly in x86-64. So I&#8217;ve got a data section up</p>



<p>So I&#8217;ve got a data section up top and I&#8217;m just going to define some messages.</p>



<p>So, you know, I&#8217;ve got like an intro message that just says, hello, I&#8217;m so and so.</p>



<p>And that&#8217;s not my name, but I like those kinds of names.</p>



<p>And then over here, I&#8217;m going to do some printf formatted strings.</p>



<p>That&#8217;s why I&#8217;m using a hybrid program for this video.</p>



<p>I don&#8217;t want to import my own personal library.</p>



<p>I want you to be able to do this at home with just the GCC libraries.</p>



<p>link a hybrid library you know linking against gcc instead of linking against ld again if you don&#8217;t</p>



<p>know that stuff check my other videos then we&#8217;re allowed to call c functions in this case we&#8217;re</p>



<p>going to call printf and we&#8217;re just going to give it the string percent lu meaning i would like you</p>



<p>to print just you know an unsigned long integer so i&#8217;m going to give it a value at some point on the</p>



<p>stack representing a local variable and then i want it to print as just like a long like a string</p>



<p>along like a string that a human can read then after that this is the carriage return line feed</p>



<p>the crlf printf won&#8217;t flush its output unless that is sitting at the very end of the string so</p>



<p>i&#8217;m just going to use printf to also print my new lines and then i&#8217;m going to null terminate the</p>



<p>string so that printf doesn&#8217;t freak out and try to print a bunch of stuff after the crlf and uh</p>



<p>oh i this was from another video let me get rid of that we don&#8217;t really need crlf in this video</p>



<p>CRLF in this video because we&#8217;re just putting it directly inside of the printf string we&#8217;re not</p>



<p>making our own function to do that so then I&#8217;m going to make some defines I&#8217;m going to define</p>



<p>that we&#8217;re going to have 50 integers so I&#8217;m calling this define 50 I&#8217;m calling it num integers</p>



<p>and I&#8217;m saying that it has a value of 50 so I want to make an array that has 50 integers I don&#8217;t</p>



<p>know maybe if you want to imagine 100 you know like the example that I just showed I&#8217;m going to</p>



<p>going to define what is the integer size so i&#8217;m going to use quad words which are 64 bit integers</p>



<p>so i&#8217;m just going to say that there are eight bytes per integer that will help me multiply later</p>



<p>and then i&#8217;m going to decide to fill up the array on the stack with just some numbers just to prove</p>



<p>that i can just to prove that we can like uh you know manipulate and and fetch the values</p>



<p>of all this stuff going on in the stack and i&#8217;m going to say that the starting value is seven so</p>



<p>with this we should expect to see like an array of numbers that starts with seven and it just</p>



<p>kind of increases somehow then i&#8217;m going to do some system call codes we talked about that in</p>



<p>a different video and then some file descriptors i don&#8217;t think we actually need anything but standard</p>



<p>output but i put it in there anyway then the next thing we&#8217;re going to add is the text section</p>



<p>let me just do copy paste on my solution here so here&#8217;s the text section section text</p>



<p>section text in Yasm and I&#8217;m going to let my module know that I want to be able to call printf</p>



<p>which is a function sitting in the GCC libraries when I link against a GCC I have the ability to</p>



<p>do that that way I don&#8217;t have to come up with like a complicated printing method or use one</p>



<p>of my own shared libraries or something so we can just ask printf to do everything so now here&#8217;s the</p>



<p>entry point for the module it&#8217;s just a function called local VAERS I mark it as global so it&#8217;s</p>



<p>it&#8217;s accessible to outside modules ie or eg driver dot cpp and then so here&#8217;s the label saying the</p>



<p>function starts and here&#8217;s the return statement saying that we&#8217;re done with the function i&#8217;m not</p>



<p>going to manipulate any registers inside of the function so i don&#8217;t really need to do any push pop</p>



<p>to preserve them first thing i&#8217;m going to do is call a welcome let me comment this part out by</p>



<p>the way i&#8217;m going to call a welcome a function and the whole job of the welcome function is just to</p>



<p>is just to, you know, print a welcome message to the user.</p>



<p>So nothing that I haven&#8217;t talked about before in other videos.</p>



<p>So it&#8217;s just we&#8217;re using a system call to print a string.</p>



<p>Okay, so with that in mind, let me open this up here and see if this is going to work.</p>



<p>I just want to basically print the welcome message at this point.</p>



<p>Clear and make run.</p>



<p>And again, if you don&#8217;t know make files or anything like that, see my other videos.</p>



<p>So this is the driver, I think, that prints.</p>



<p>think that Prince maybe I should change the driver&#8217;s message to make it more</p>



<p>clear hello about this is the driver and my name is whatever I&#8217;m gonna do it again</p>



<p>and now it says hello this is the driver okay so that&#8217;s the CPP module and then</p>



<p>here is the assembly module and then finally the driver gets control back and</p>



<p>then the program exits so nothing really happened so now let&#8217;s upgrade the</p>



<p>So now let&#8217;s upgrade the assembly module a little bit.</p>



<p>Next thing I want to add is the actual demo function, which is going to be absolutely huge.</p>



<p>So first I&#8217;m going to start off with, how about just the signature here?</p>



<p>Let&#8217;s go right after the welcome module.</p>



<p>And I&#8217;m just going to copy paste the signature, put a return at the end of it.</p>



<p>So we&#8217;ll consider this a function that can be called.</p>



<p>instruction on line 47 of the entry point and then now we have a demo</p>



<p>function that is being called but it does nothing for starters you know I in</p>



<p>my comments I like to put the signature of the function and I like to remind</p>



<p>myself of how I&#8217;m using my registers hopefully I&#8217;m not using the same</p>



<p>register in two different ways but you know sometimes it happens if it does and</p>



<p>I&#8217;m able to break my function up into multiple parts I&#8217;ll probably do it</p>



<p>you know with modular thinking modular programming but in this case I&#8217;m just</p>



<p>using these registers it&#8217;s fine to use them they are all designated per the ABI</p>



<p>as callee saved so that means the callee which is the demo function is</p>



<p>responsible for preserving them so if you don&#8217;t remember that or if you don&#8217;t</p>



<p>know about that see my other videos this is not an ABI video so I&#8217;m just going to</p>



<p>push all of them to make sure that they&#8217;re preserved I&#8217;m gonna call this</p>



<p>call this the prolog then at the end of my function i&#8217;m going to call this the epilog where</p>



<p>i just restore them in reverse order because that&#8217;s the way the stack returns data to you</p>



<p>the stack returns data to you in reverse order so i have to pop in the reverse register order to</p>



<p>un-reverse the reversal if that makes sense pop r13 pop r12 okay so i think 15 14 13 okay</p>



<p>so i got that next thing we&#8217;ll do is um let&#8217;s remember where the stack pointer started because</p>



<p>started because we have our register here that we&#8217;re going to mess with let me just type rsp</p>



<p>real fast so this is the stack pointer register rsp this helps all programs know where where</p>



<p>they&#8217;re looking at in the stack all of your functions have to be really really careful about</p>



<p>messing with the stack pointer if you do it wrong you will crash the entire program because not only</p>



<p>will your local function not really know where its local variables end and begin it probably also</p>



<p>It&#8217;s return address when you try to return from the function because that is also sitting on the stack</p>



<p>And even if you were lucky enough to be able to jump back correctly to whoever called you</p>



<p>If you messed up the stack pointer then you&#8217;ve also messed it up for any caller of you and any of their callers</p>



<p>So the whole program is ruined. So we&#8217;ll start off by trying to remember where the stack pointer was</p>



<p>We&#8217;ll move</p>



<p>The stack pointer into the base pointer</p>



<p>didn&#8217;t do here that I that I want to do we should since we&#8217;re messing with the</p>



<p>base pointer and other programs sorry other functions or modules might also</p>



<p>rely on the base pointer and it&#8217;s considered callie saved we probably also</p>



<p>want to preserve that too so I&#8217;m going to do push RBP to basically say I would</p>



<p>like to restore I would like to preserve the base pointer so I don&#8217;t mess it up</p>



<p>for my callers so that means I have to restore it with the pop so RBP the base</p>



<p>The base pointer isn&#8217;t necessarily a pointer to the stack, but it&#8217;s often used as kind of like a bookmark.</p>



<p>So we have RBP at the front and the back there.</p>



<p>Let&#8217;s see.</p>



<p>Next thing I want to add is, so now that we&#8217;ve restored it, we&#8217;re allowed to just overwrite it because, you know, we&#8217;re kind of like keeping its value at the top.</p>



<p>Then we&#8217;re restoring its value at the bottom.</p>



<p>And that means we can actually mess it up in the middle if we want to, and it&#8217;ll be fine.</p>



<p>let me show you real fast what happens what happens is nothing the program is</p>



<p>still okay because we we restored it so now we&#8217;re using the base pointer to</p>



<p>remember where the stack was now we&#8217;ve got to sort of calculate how much room</p>



<p>we want to make on the stack let me show you what I&#8217;m talking about here</p>



<p>remember all of our local variables are going to be on the stack and before we</p>



<p>drew this thing where it was like well we&#8217;ve got like a stack sitting here and</p>



<p>let&#8217;s just pretend that there&#8217;s some kind of data sitting on the stack data</p>



<p>data data right if the stack pointer dude green green there we go oh I erased my</p>



<p>green RSP if the stack pointer is currently pointing to this frame then</p>



<p>in order for us to make room on the stack to hold our array well if the</p>



<p>whole array is going to be sitting on the stack that just basically means</p>



<p>have five integers suppose five suppose that we want to make five integers on the stack that just</p>



<p>means we need to do five extra slots let me draw it in red here well let&#8217;s see can we get a green</p>



<p>no how about a yellow my green is just having a hard time we can do it in red even though this is</p>



<p>not a bad thing to do so i&#8217;ll just draw like five extra frames on top of on top of the stack here</p>



<p>imagine these are all 64-bit integers and so they take eight bytes on the stack even though in our</p>



<p>previous example we were using just regular ints which are 32 we&#8217;ll just say we&#8217;re going to make</p>



<p>five 64-bit integers because that&#8217;s easier so they&#8217;re quad words so every frame is actually</p>



<p>eight bytes and not just four bytes and it&#8217;s definitely not one byte so we make five of those</p>



<p>how do we make five slots it&#8217;s pretty easy we we literally just move the stack pointer let&#8217;s see</p>



<p>we just move the stack pointer to or the you know the rsp register to just say let&#8217;s let&#8217;s point you</p>



<p>know further out and how do we get that number we&#8217;re just going to multiply the size of one</p>



<p>integer so you know the size of one integer here we know it&#8217;s going to be eight bytes we just</p>



<p>multiply that by the number of integers that we want you know that&#8217;s going to be 40 so we&#8217;ll just</p>



<p>increase uh sorry decrease the stack pointers value by 40 because remember again when the</p>



<p>vertically, it&#8217;s actually growing downward in memory. So we&#8217;re going to decrease by 40 there,</p>



<p>at least in this drawing example. And that gives us a bunch of junk data, you know, because there</p>



<p>is always going to be some kind of a value sitting at every memory location in your computer.</p>



<p>It&#8217;s impossible that there is literally nothing at some memory location,</p>



<p>unless you&#8217;re trying to go beyond your RAM stick. But then the system will still acknowledge that,</p>



<p>you know, you&#8217;ve done that and it won&#8217;t just give you back nothing if you try to read</p>



<p>nothing if you try to read.</p>



<p>So there&#8217;s going to be junk data sitting on there and then we&#8217;ll loop</p>



<p>through all those slots on the stack and we&#8217;ll just modify the data one by one</p>



<p>so that we can control what it is instead of just printing whatever junk data we end</p>



<p>up with.</p>



<p>So really, we&#8217;re just moving the stack pointer, just making room and then just</p>



<p>remembering where our array is.</p>



<p>We could put, you know, another frame on top if we wanted to make just like one</p>



<p>integer as a local variable.</p>



<p>You just got to remember where it is.</p>



<p>You know, what is it?</p>



<p>What is its offset?</p>



<p>is it what is its offset okay so i&#8217;m going to erase this because we&#8217;re going to do a lot more than</p>



<p>than five uh integers on the stack but i just want you to understand what we&#8217;re doing before we do it</p>



<p>okay so the next thing i&#8217;m going to grab is a move instruction and i&#8217;m going to put it right here so</p>



<p>to move the stack pointer rsp so the first thing i&#8217;m going to do is i&#8217;m going to use a temporary</p>



<p>register we don&#8217;t need to preserve this in the push and pop because it&#8217;s marked as temp so we&#8217;re</p>



<p>not responsible for preserving it and so i&#8217;m going to say r10 is just going to be the number of</p>



<p>integers that we want to create if you recall at the top of our program here num integers is just</p>



<p>50 okay so then the next thing that i&#8217;m going to grab is well i&#8217;m not going to grab it i&#8217;m going</p>



<p>it I&#8217;m going to straight multiply by integer size so again if you look at integer size that&#8217;s going</p>



<p>to be eight because we&#8217;re using quad words for our integers so we&#8217;re really just going to take</p>



<p>50 times 8 whatever number that is is that 400 tell me in the comments if that&#8217;s a right or wrong</p>



<p>and so uh you may or may not know if you don&#8217;t see more videos see more textbooks you may or may not</p>



<p>instruction just multiplies two numbers.</p>



<p>If you use the three operand format,</p>



<p>then the last two operands get multiplied</p>



<p>and the results stored in the first operand.</p>



<p>But if we use the two operand format like I&#8217;ve done here,</p>



<p>then both of those operands get multiplied</p>



<p>and then the result gets stored in the first operand.</p>



<p>So basically at this point,</p>



<p>R10 should hold the number of memory locations</p>



<p>that we should move the stack pointer</p>



<p>in order to make room for all those integers</p>



<p>like I showed you a second ago.</p>



<p>showed you a second ago. So then we&#8217;re going to move the stack pointer.</p>



<p>And maybe I&#8217;ll leave a little comment here. Remember, the stack grows downward</p>



<p>in memory. And so all I&#8217;m doing is subtracting the stack pointer. Remember the stack pointer</p>



<p>register, it just holds a number, which is a memory location. So if you subtract some numbers</p>



<p>from it, you&#8217;re really having it go downward in memory. And that&#8217;s what we want to do</p>



<p>memory and that&#8217;s what we want to do to you know grow the stack for a local variable so I&#8217;m going</p>



<p>to say well I should also say that we&#8217;re using the two operand version so just like I&#8217;m all if we</p>



<p>had the three operand version then the last two operands would have one subtracted from the other</p>



<p>and the result will be stored in the first one but since I&#8217;m using the two operand version</p>



<p>basically it&#8217;s taking RSP minus R10 and then storing it in RSP so this this instruction just</p>



<p>this instruction just says let&#8217;s move the stack pointer downward in memory</p>



<p>enough times that we have room for all of our integers okay no problem next thing that we&#8217;re</p>



<p>going to do is um we&#8217;re going to move r12 we&#8217;re going to move into r12 the current value of rsp</p>



<p>word in memory right less okay so the first integer you know it&#8217;s up to you</p>



<p>how you style this because once we do the subtraction then RSP is actually</p>



<p>going to be pointing towards an integer you could consider that to be the first</p>



<p>integer or the last integer because all we have is an array of integers so you</p>



<p>you know rsp wherever it&#8217;s sitting when we&#8217;re finished we could say that&#8217;s pointing to the</p>



<p>first integer or we could say it&#8217;s pointing to the last integer but um if we decide to say that it is</p>



<p>pointing to the let&#8217;s see yeah if we&#8217;re deciding that it points to the first integer let me just do</p>



<p>a little comment here first integer it just makes it a little bit easier for me to write our loop</p>



<p>You could start by pointing to the one that RSP is pointing to,</p>



<p>or you could start by pointing to the other one that was like the first one that you added onto the stack.</p>



<p>You could call either one of those the first integer, as long as you remember where you started.</p>



<p>So you can increase or decrease the memory location to get to the next integer.</p>



<p>So I&#8217;m just going to do it in this style.</p>



<p>But keep in mind, as long as the only thing that you modify and read is within that range, it&#8217;s okay.</p>



<p>So let&#8217;s remember where is RSP.</p>



<p>So that&#8217;s like the top of the stack.</p>



<p>We&#8217;re going to say R12 holds the stack pointer so that we can use R12 as sort of a running</p>



<p>pointer.</p>



<p>I think that&#8217;s the way I&#8217;m going to use it.</p>



<p>Let me just double check my solution.</p>



<p>Yeah.</p>



<p>Okay.</p>



<p>a calculation where we remember where the last integer is so we know where the first integer</p>



<p>we&#8217;re just going to call this the first integer i&#8217;ll put it in quotes just to remind you that</p>



<p>this is just the style i happen to be using so here we&#8217;re going to say that the first integer</p>



<p>is wherever rsp is pointing and then in r13 we&#8217;re going to remember where the other side of the</p>



<p>array is in this case we&#8217;re calling it the last integer and pretty much it&#8217;s just r12 which is</p>



<p>And then we add to it a memory location.</p>



<p>So remember we said before that the stack grows downward in memory.</p>



<p>So if we consider the top of the stack to be the first integer,</p>



<p>then that means previous items, maybe I should draw this,</p>



<p>are going to be increased memory locations.</p>



<p>So that&#8217;s kind of like the backwards of what you imagine a stack is doing,</p>



<p>but it&#8217;s kind of the way that I like it sometimes.</p>



<p>So imagine just in a very simple stack,</p>



<p>let&#8217;s pretend that the stack has one byte values,</p>



<p>one byte of values, which it doesn&#8217;t, but let&#8217;s pretend if you, if you do it,</p>



<p>I got to learn how to draw. I can&#8217;t get that five right. Okay. I&#8217;m defeated. So let&#8217;s pretend</p>



<p>that that address on the thing sitting at the bottom of the stack is five. So then that means</p>



<p>the next address would be four, right? But if we decided, let&#8217;s say that the, well, let&#8217;s do like</p>



<p>like a few more just to make it a little bit more interesting.</p>



<p>Let&#8217;s do a total of five.</p>



<p>So we&#8217;ll say four, three, two, one.</p>



<p>Maybe I should just add some numbers in front of those values.</p>



<p>So it doesn&#8217;t feel like we&#8217;re hitting zero.</p>



<p>But so just pretend we have a memory location of 15.</p>



<p>That&#8217;s not going to be the case in real life.</p>



<p>Pretend that we have one byte integers on the stack, which is not going to be the case.</p>



<p>We&#8217;re going to have quad words.</p>



<p>But you can see the memory locations go downward, right?</p>



<p>to the stack pointer is pointing to the topmost location we have to remember that anything up here</p>



<p>might exist in system ram but it&#8217;s not considered valid data because we didn&#8217;t</p>



<p>you know make it part of the stack by by growing the stack pointer so that means uh these</p>



<p>these items well maybe i&#8217;ll do a check instead of an x because x looks bad i&#8217;ll do a check</p>



<p>check and a check and a check and a check these items are okay to use so if I have</p>



<p>RSP or in this case we just remembered where RSP was by storing r12 if we have</p>



<p>that memory location 11 and we want to get an additional integer like somewhere</p>



<p>else like the next integer well that would be you know this one down here we</p>



<p>wouldn&#8217;t go in the other direction we wouldn&#8217;t go you know up we would just go</p>



<p>know up we would just go down in the stack but down visually is actually growing upwards in memory</p>



<p>because remember when we grow upwards visually we&#8217;re growing downward in memory so and you can</p>



<p>see here too if we&#8217;re if we&#8217;re increasing 11 to 12 that means we&#8217;re adding memory locations to get</p>



<p>to the next uh integer that we have in the stack so that&#8217;s why here my green is just like frustrating</p>



<p>fix this yeah so that&#8217;s why here we&#8217;re adding a little formula instead of subtracting because</p>



<p>the rsp started there we&#8217;re saying that the top of the stack is the first integer</p>



<p>just so we can add in a more convenient nice way so what are we adding to it we&#8217;re just adding to it</p>



<p>the number of integers minus one and then so that&#8217;s that&#8217;s the number of slots that</p>



<p>size. So if you imagine, you know, if we had 10 integers, then, you know, 10 minus one is nine</p>



<p>slots. So if you imagine that zero is the first integer, let&#8217;s say the memory location again,</p>



<p>then that means one, two, three, four, five, six, seven, eight, nine, 10 minus one is nine. So if we</p>



<p>added the number of integers minus one from the start, which we&#8217;ll consider zero here, that means</p>



<p>directly so that&#8217;s just like a little math because sometimes when you when you</p>



<p>think of adding two numbers together or taking the difference or including the</p>



<p>first number or not including the first number it&#8217;s a little confusing right so</p>



<p>keep in mind for this particular calculation we are adding to it the</p>



<p>number of integers minus one so that will be sitting on the last integer</p>



<p>rather than going past it so start with the first integers memory location and</p>



<p>the number of integers minus one or size minus one times the integer size,</p>



<p>because remember, every integer is going to be eight bytes.</p>



<p>And that will give us the memory location of the last integer in R13.</p>



<p>And then I&#8217;ve said this in other videos,</p>



<p>but basically you&#8217;re only allowed to make these sorts of calculations in Yasm</p>



<p>when you have the calculation inside of brackets,</p>



<p>but brackets will automatically dereference the value on the inside.</p>



<p>It&#8217;ll consider it as a pointer that needs to be dereferenced,</p>



<p>but we don&#8217;t want to dereference anything.</p>



<p>anything we don&#8217;t want to go to a memory location and take a value the memory location is the value</p>



<p>so these dereferencing brackets which are required for the formula are kind of bad so that&#8217;s why we</p>



<p>use the lea instruction instead of the move instruction if i put move there it would</p>



<p>definitely dereference the memory location and give me a value in r13 so r13 wouldn&#8217;t actually</p>



<p>be a pointer it would just be the value of the junk data of the last integer keep that in mind</p>



<p>keep that in mind okay so uh where&#8217;s RSP so we got that so now let&#8217;s do a loop</p>



<p>I&#8217;m gonna start off with a label called demo loop init so for me personally when</p>



<p>I&#8217;m looping you know I like to make my labels inside of my loops start with a</p>



<p>prefix that matches the function so it&#8217;s like demo and then everything else is</p>



<p>gonna be demo underscore something so uh init loop init I&#8217;m gonna make a loop</p>



<p>to make a loop where i initialize the values of the array so i&#8217;m calling this loop the init loop</p>



<p>and then the last part is just like this is the initialization part of the loop this is where we</p>



<p>sort of like set up the initial values to loop so we have r12 and 13 that point to the first</p>



<p>and last integers now we&#8217;re going to set up r14 and 15 where r14 is the running pointer i think</p>



<p>before i might have accidentally said that r13 is the running pointer it just points to the last</p>



<p>it just points to the last integer but if you look back up at my comments r14 is the running pointer</p>



<p>to the current integer what is a running pointer it&#8217;s just a pointer that runs it&#8217;s just a pointer</p>



<p>that just keeps increasing so we can look at different data values so i&#8217;m going to start it</p>



<p>by looking at the first integer so now r14 is pointing to the first integer and then r15 is</p>



<p>going to be the value that i want to put into that position in the array so like the first integer</p>



<p>integer I want to put some kind of a starting value into it you can put the</p>



<p>number zero or whatever you want I just wanted to have a start value so that it</p>



<p>sort of looks more like I&#8217;m putting data and less like I have a loop counter so</p>



<p>remember the integer start value up here is just seven so I&#8217;m just going to start</p>



<p>at the number seven and now I&#8217;m done initializing my loop then the next thing</p>



<p>I&#8217;m going to add is the top of my loop so you can imagine this as the top of a</p>



<p>top of a while loop where you start comparing some sort of an expression maybe i&#8217;ll say uh</p>



<p>you know expr to say that we&#8217;re comparing some sort of an expression</p>



<p>and if that expression evaluates to true the loop continues if it evaluates to false</p>



<p>then the loop does not continue let&#8217;s see so i&#8217;m going to compare r14 with r13 inside of the</p>



<p>and 13 remember R14 is the running pointer and R13 is the last integer so basically I&#8217;m trying to</p>



<p>figure out am I looking at or like let&#8217;s compare the running pointer with the pointer of the last</p>



<p>integer then I&#8217;m going to say if the running pointer has a greater memory location than than</p>



<p>the last integer that means I&#8217;ve gone beyond the last integer and again the way I arranged the first</p>



<p>last integers just makes it easier for me to think of them as having increasing</p>



<p>memory locations so I&#8217;m going to jump if the running pointer has already</p>



<p>surpassed the last integer by saying let&#8217;s jump if it&#8217;s greater than so you</p>



<p>can imagine maybe in the expression here I should probably say while not</p>



<p>r14 is greater than r13 not a great expression but it&#8217;ll do so that&#8217;s what</p>



<p>up there at the top let me just put that into my notes too so that my notes match</p>



<p>the video okay so we are comparing and then we&#8217;re jumping to the end of the</p>



<p>loop if we end up you know going beyond the last integer so that labels not</p>



<p>created yet I&#8217;ll create that in a moment but pretty much that&#8217;s a label that&#8217;s</p>



<p>just going to be below the loop just to say like we&#8217;re finished with the loop</p>



<p>the loop body I like to put comments here to help myself remember oh this is</p>



<p>the part of the while loop that I&#8217;m currently inside of just makes things a</p>



<p>little bit easier to understand you know you put a block comment up top of every</p>



<p>label or every you know chunk of instructions just to let you know the</p>



<p>general idea and then you know sometimes you put comments also on the right side</p>



<p>to help you remember what each instruction is actually doing so then</p>



<p>what am I going to do here remember R14 is the running pointer if I D ref R14</p>



<p>ref r14 that means i want to move an actual value into that memory location rather than changing the</p>



<p>memory location that r14 points to so r15 is going to be the uh the integer that we want to</p>



<p>write into the array so all i&#8217;m doing here is i&#8217;m saying let&#8217;s take that value seven which is what</p>



<p>it starts as and just move it in to you know the ram stick at that memory location so i&#8217;m setting</p>



<p>seven right now then I&#8217;m going to increase our 15 so that means every time</p>



<p>we iterate the loop we should see that the value increases so the first integer</p>



<p>should be seven the second one should be eight next one should be nine and so</p>



<p>forth so just a simple loop where I&#8217;m just writing data into my array so now</p>



<p>that we&#8217;ve ended the loop body let&#8217;s write the bottom of the loop which is</p>



<p>just going to increase the running pointer and jump back up to the top and</p>



<p>And this is not necessarily the only style for translating while loops.</p>



<p>I&#8217;m just doing it.</p>



<p>And, you know, I&#8217;m going to make another video in the future where we talk about, you know, for loops and while loops and all that stuff.</p>



<p>But this video is just really about local variables on the stack.</p>



<p>So I&#8217;m not going to go over all the different ways you can do it.</p>



<p>Anyway, so R14 is the running pointer.</p>



<p>So I&#8217;m going to just make the running pointer jump to the next integer.</p>



<p>And we can do that by increasing its memory location by the size of one integer.</p>



<p>Again, this is another benefit of the first and last pointers that I chose at the beginning.</p>



<p>I can just increase to go to the next integer.</p>



<p>So we&#8217;re going to increase by 8 bytes to just go to the next integer.</p>



<p>If you increase by 1 byte, you&#8217;ll probably have a huge corrupted mess because you&#8217;re</p>



<p>messing with 8 byte integers but you&#8217;re only increasing by 1 byte.</p>



<p>And then after we increase, we&#8217;re just going to jump to the top of the loop.</p>



<p>So notice how I have a jump statement here.</p>



<p>It&#8217;s going to go just to loop top.</p>



<p>loop top. So now this part is here is basically just going to execute over and over and over again</p>



<p>until we finally scan through all of the integers in our array. So that&#8217;s the bottom of the loop.</p>



<p>And then I&#8217;ll make the label for the loop being done. It&#8217;s not really going to do anything</p>



<p>except just be done. And do you, you know, I don&#8217;t know, depending on your style, maybe you can let</p>



<p>drop through if the loop&#8217;s done rather than always jumping to the top but i&#8217;m just going to say when</p>



<p>we&#8217;re done we jump to the loop done label and therefore there&#8217;s no more looping of that</p>



<p>initialization loop okay so we got that done let me just run the program real fast to make sure</p>



<p>that i haven&#8217;t screwed it up we actually should not see anything right now oh what did i do</p>



<p>must have done something naughty maybe if i finish</p>



<p>uh this program then everything will be okay oh my gosh what did i even do</p>



<p>well i&#8217;ve got a working solution in the other window so hopefully when i paste all the extra</p>



<p>steps everything will be fine you never know subtract the stack pointer oh did i forget to</p>



<p>oh did i forget to restore something at the very end print body move the base pointer into the</p>



<p>RSP stack pointer oh yeah okay that&#8217;s definitely what you got that&#8217;s why I</p>



<p>crashed okay so um remember I said you got to be very careful about the stack</p>



<p>this is a great lesson so I did preserve the base pointer but I didn&#8217;t actually</p>



<p>preserve the stack pointer notice how right here I subtracted from the stack</p>



<p>pointer but I did not restore the stack pointer anywhere so that means I</p>



<p>corrupted the stack for anyone that called me and also for my return address</p>



<p>address. So I&#8217;m kind of trying to copy paste my instructions from top to bottom, but I think I&#8217;m</p>



<p>just going to copy paste something else to make sure that we can actually run this. So I&#8217;m going</p>



<p>to copy paste into the epilog a restoration of the stack pointer. And that&#8217;s why we saved the</p>



<p>stack pointer in the base pointer, just to remember where it was when we originally started our</p>



<p>function. So now on line 128, it should be restored and the program should work. Let me just double</p>



<p>yeah it worked okay nothing happened that we can see but it did write values</p>



<p>into the array now let&#8217;s do another loop where we just print the array so let&#8217;s</p>



<p>see loop in it done looping it bottom and looping it done okay so now there&#8217;s</p>



<p>like gonna be another loop here we&#8217;re gonna call this the print loop and so</p>



<p>the print loop is gonna be kind of the same pattern we&#8217;re just gonna loop</p>



<p>going to loop through all the integers in the array but instead of modifying them we&#8217;re just</p>



<p>going to print them so now you know the first thing we&#8217;ll do is we&#8217;ll set r12 we&#8217;ll store that</p>



<p>inside of r14 in order to start the loop at the first integer what was r14 again that was the</p>



<p>running pointer remember let&#8217;s see where is that yeah it was the running pointer so now we&#8217;re</p>



<p>resetting the r14 running pointer to the very beginning of the array and we know where the</p>



<p>thing we&#8217;ll do is we will set up the top of the loop and the body so I&#8217;m just</p>



<p>going to copy paste again this stuff right here</p>



<p>right there okay so the top of the loop we&#8217;re asking ourselves you know we&#8217;re</p>



<p>gonna compare I&#8217;m not gonna put all the extra while stuff that I put in the</p>



<p>previous loop because hopefully by now you understand loops a little bit better</p>



<p>and if we&#8217;re beyond the last integer because the running point of r14 is beyond the memory</p>



<p>location of r13 that means we&#8217;re totally done so we should jump if it&#8217;s greater than</p>



<p>now i feel bad let&#8217;s uh let&#8217;s put a comment in here on the top let&#8217;s go uh</p>



<p>basically that you know if uh keep going as long as r14 is not greater than r13 so if it is</p>



<p>in the body and in the body all i&#8217;m going to do is use r14 the running pointer to print uh you know</p>



<p>whatever value is sitting in that particular integer so how do we do that i&#8217;m just going to</p>



<p>use the printf statement or sorry the printf function which is provided by the c libraries</p>



<p>that&#8217;s why we&#8217;re doing you know a modular or a hybrid program with multiple modules and c linking</p>



<p>very quickly there is a function called printf which I can call it it takes multiple arguments</p>



<p>but the first two arguments that I can give it are the string that represents the formatting</p>



<p>that I want to print like I could do like a regular string message I could do tokens</p>



<p>to format some data inside of them and then the second argument is going to be the piece of data</p>



<p>that I actually want to use let me see if I can just type that up for you real fast</p>



<p>So, you know, the printf instruction, or sorry, this is not an instruction.</p>



<p>This is a function in C.</p>



<p>We would typically, you know, give it some kind of string.</p>



<p>The string should be null terminated, and it should have a new line at the very end of it</p>



<p>to make sure that printf actually flushes.</p>



<p>It won&#8217;t flush if you don&#8217;t have a new line, so the program will look really weird.</p>



<p>But I guess it&#8217;s more performant if you have a way to delay the flushing,</p>



<p>flushing and you know that you can flush it later at the very end but for now i&#8217;m just going to</p>



<p>flush every time and then every argument after that is some sort of you know data that we can</p>



<p>print so imagine we have a long and we&#8217;ll call it a and we&#8217;ll say that it has like some giant value</p>



<p>so that means we would give that long as the next argument the rsi argument and then for the string</p>



<p>what I&#8217;m using right here %lu so you can imagine instead of this string it is this</p>



<p>string right here whoops too many too many quotes it&#8217;s just this string right</p>



<p>here and then instead of a 10 13 that&#8217;s the same thing as just doing an or if</p>



<p>you want to be you know more of a windows windows person slash r slash n</p>



<p>it&#8217;s all good and the zero is not needed because the string if you put a string</p>



<p>literal it&#8217;s automatically going to be null terminated which means there&#8217;s just</p>



<p>null terminated which means there&#8217;s just a zero at the end of the string in memory so this is</p>



<p>basically what I&#8217;m doing I&#8217;m making a an integer in the case of the assembly program it&#8217;s going to</p>



<p>grab an integer from that position in the array that we&#8217;re looking at and it&#8217;s going to give it</p>



<p>as an argument and then the first argument is going to say let&#8217;s just print this as a unsigned</p>



<p>long so that&#8217;s why I have that string here let me search for it and go down a little bit again so</p>



<p>I&#8217;m saying first argument is this the format that I want to be printed second argument is the actual</p>



<p>is the actual value and then I&#8217;m gonna make a call to printf why do I have this</p>



<p>weird push and pop pair sitting around printf so this is not a video about</p>



<p>stack alignment in GCC but basically the GCC libraries expect that your stack is</p>



<p>aligned to I think 16 bytes but since we use 8 byte integers every single time we</p>



<p>address to the stack which is eight bytes and then every time we do one single push or pop</p>



<p>we&#8217;re modifying the alignment of the stack by eight bytes so if you think about it when we&#8217;re</p>



<p>programming in assembly for the most part the stack is going in and out of alignment because</p>



<p>every time we modify it by eight bytes it it might line up with a 16 byte alignment or it might not</p>



<p>it&#8217;s just kind of like oscillating right so when I first wrote this solution I wasn&#8217;t doing the</p>



<p>what happened oh actually maybe i guess i don&#8217;t need to jump to the top right now i don&#8217;t need</p>



<p>to finish the loop let&#8217;s see if this prints just one number well let me let me let me see if this</p>



<p>prints one number certainly and if it&#8217;s an okay assembly program just to print one number is it</p>



<p>going to work okay we got to do the done symbol okay so i&#8217;ll show you in a minute why we need</p>



<p>that for stack alignment but i guess i&#8217;ll just finish the loop so demo print loop done so we</p>



<p>just did print loop top and that means we need the bottom and the done so i&#8217;m just going to copy paste</p>



<p>into program here i&#8217;ll just say nada because we&#8217;re not really doing anything and then at the bottom</p>



<p>you know that&#8217;s the epilogue that&#8217;s separate from the the other label so basically now let me finish</p>



<p>know we already know the loops but I&#8217;ll just I&#8217;ll just say it at the bottom of</p>



<p>the loop we do the same thing that we did with the initialization loop we just</p>



<p>increase the running pointer you know we move it along to the next integer and</p>



<p>then we jump to the top of the loop that&#8217;s it and then the done label we</p>



<p>don&#8217;t really do anything we&#8217;re just letting execution drop through down to</p>



<p>that point so that the loop doesn&#8217;t continue so now we should be able to run</p>



<p>the program don&#8217;t get excited oh actually you know what get excited I</p>



<p>was gonna say don&#8217;t get excited because it was gonna totally work now but now</p>



<p>because it was going to totally work now,</p>



<p>but now I think we can just say that it&#8217;s going to crash.</p>



<p>So if I run it, notice how there&#8217;s a segpult.</p>



<p>So the GCC libraries, many functions expect your stack</p>



<p>to be aligned to 16 bytes.</p>



<p>So if you see mysterious crashes</p>



<p>and you are absolutely sure that you&#8217;re not ruining</p>



<p>the stack pointer or ruining something else,</p>



<p>you&#8217;re doing everything correctly,</p>



<p>but the program still crashes, it might be stack alignment.</p>



<p>So one way to get around stack alignment</p>



<p>is just to move the stack pointer.</p>



<p>move the stack pointer like at the top here we could have said oh we&#8217;ve got one two three four</p>



<p>five we&#8217;ve got five pushes and then here we&#8217;re moving the stack by I don&#8217;t know how many other</p>



<p>addresses the stack might be out of alignment somehow so we could add an extra push up here</p>



<p>and then add a corresponding pop down at the bottom like we could easily do this let me just</p>



<p>show you real fast we could push r15 twice for no reason I acknowledge and then at the bottom</p>



<p>and then at the bottom we pop R15 twice,</p>



<p>that would change the alignment because that&#8217;s one more 8 byte push.</p>



<p>But in my case, and actually that would be a little bit smarter</p>



<p>because if you have our loop where it&#8217;s constantly calling on printf,</p>



<p>this is a lot of hits to memory, right?</p>



<p>This is like 100 hits to memory because every single time we do a push-pop pair</p>



<p>around a call to printf, we&#8217;re like touching memory.</p>



<p>Whereas if I did it at the beginning and the end,</p>



<p>Maybe I should just do it this way.</p>



<p>I want to do it both ways so you understand, but it&#8217;s more efficient, I think, if we do</p>



<p>it this way.</p>



<p>Anyway, so we&#8217;ll do pop twice at the bottom and then push twice at the top.</p>



<p>And so then we don&#8217;t really need to surround it with a push-pop pair.</p>



<p>I think I haven&#8217;t tested this.</p>



<p>We&#8217;ll hope now that the stack is in alignment at all times in our functions so that it doesn&#8217;t</p>



<p>crash.</p>



<p>Yeah, so now see how the program works.</p>



<p>So I&#8217;m going to do it the other way now, which is the less efficient way, because here</p>



<p>now which is the less efficient way because here we just have one extra push</p>



<p>pop pair but if we do it the other way it&#8217;ll still work but we&#8217;ll be hitting</p>



<p>memory much more often so I&#8217;m just gonna do it this way just to show you you can</p>



<p>surround any call because sometimes in your programs you might have the stack</p>



<p>like you know modified throughout the function many different times so it</p>



<p>wouldn&#8217;t make too much sense for you to add an extra push pop pair in the prologue</p>



<p>and epilogue because that might not solve it for all of your calls to all of</p>



<p>to all of your seed library functions.</p>



<p>So in that case,</p>



<p>where you can&#8217;t really predict the stack well enough,</p>



<p>you can just surround your call with a push-pop pair.</p>



<p>It hits memory more, but it&#8217;ll work.</p>



<p>So this is basically, you can imagine,</p>



<p>by the time we get to line 139,</p>



<p>the stack is out of alignment.</p>



<p>So I just do a push that puts it into alignment.</p>



<p>And then after the call comes back,</p>



<p>I just pop it so it&#8217;s back out of alignment again,</p>



<p>but I don&#8217;t have extra erroneous data sitting on the stack.</p>



<p>Because if I only had push and not pop,</p>



<p>then it&#8217;s going to push it more and more out of alignment.</p>



<p>It&#8217;s going to push it in and out and in and out,</p>



<p>but it&#8217;s going to add a bunch of junk data to the stack</p>



<p>that I&#8217;ll never recover from.</p>



<p>Or actually, I guess I will recover at the very end</p>



<p>when I restore the stack pointer, but it&#8217;s pointless.</p>



<p>It&#8217;s going to consume too much memory.</p>



<p>What if I was writing like a billion</p>



<p>or like a million items on the stack, right?</p>



<p>a billion iterations of the loop would probably be a bad idea to start adding onto the stack</p>



<p>we&#8217;ll probably end up stack overflowing probably with far less than a billion items so anyway i&#8217;m</p>



<p>going to surround the call with the push pop pair and then at the bottom we just do the same thing</p>



<p>you know increase the integer and then go to the top and so now we you know you already can see it</p>



<p>it starts off printing well it starts off initializing the array but then the thing that we</p>



<p>can see starts off printing the first integer and then the next iteration of the loop prints the</p>



<p>second integer and the third and the fourth and so forth until we get all the way down just to</p>



<p>prove to you maybe we can increase it by two instead of one each time I&#8217;ll just modify that</p>



<p>Oh no, that&#8217;s the print loop. Let&#8217;s do the init loop.</p>



<p>Init loop bottom.</p>



<p>Oh, right there, when we&#8217;re in the body.</p>



<p>So I&#8217;m just going to increase R15 twice.</p>



<p>Just to show you, you know, we can kind of control what&#8217;s going inside of the local array.</p>



<p>So see how it goes from 7 to 9 to 11 instead of 7, 8, 9.</p>



<p>So I&#8217;m going to take that out and then just show you that we can control</p>



<p>how many integers we have in our local array with just the number of integers.</p>



<p>just the number of integers so I&#8217;m going to change the 50 to a 5 and run it again and you can see</p>



<p>what the dang did I do number of integers is 5 and then it was 50 did I put the stack out of</p>



<p>alignment no I I have a push put pair there number 50 is not hard-coded anywhere anywhere</p>



<p>there. Oh, I have a bug that I can debug. That&#8217;s nice. I guess the bug debugging is not for this</p>



<p>video. I wonder if some other value would work for that. There&#8217;s a number of things that could</p>



<p>be the problem. It could be like stack alignment somehow. It could also be, let&#8217;s see, am I making</p>



<p>any calls here inside of my function demo? I&#8217;m saying sub and LEA and then start and then jump</p>



<p>and start and then jump and increase and jump and then RDI.</p>



<p>Not really doing anything else.</p>



<p>So I don&#8217;t think it&#8217;s stack alignment.</p>



<p>I must have miscalculated somewhere somehow for changing that.</p>



<p>All right.</p>



<p>Well, if I figured it out, then I will release another video.</p>



<p>But basically, this is the idea.</p>



<p>100 works, 50 works.</p>



<p>What about 99?</p>



<p>Would that work?</p>



<p>Save faults on 99.</p>



<p>faults on 99 and then 98. 98 works so like every two seems to work but that is</p>



<p>two quad words or 16 oh right so like a hundred integers if we assume that</p>



<p>that&#8217;s in alignment then 99 would be eight bytes less that we&#8217;re moving the</p>



<p>98, notice how it is okay.</p>



<p>And then 97, it&#8217;s going to segfault again.</p>



<p>Watch.</p>



<p>This is a great stack alignment video, I guess.</p>



<p>96, it won&#8217;t segfault.</p>



<p>So it&#8217;s going in and out of alignment.</p>



<p>I think I figured it out.</p>



<p>So if we use the number 100, it&#8217;s in alignment.</p>



<p>Sorry, it&#8217;s out of alignment.</p>



<p>If we use the number 100, the program works because the number 100 throws it out of alignment.</p>



<p>number 100 throws it out of alignment but then we have this push pop pair here around the call to</p>



<p>printf which puts it back in alignment so if I change the number of integers I&#8217;m actually</p>



<p>changing the number of memory locations that I modify the stack pointer so I have to do it by</p>



<p>twos if I wanted to do 99 here then that means the stack is in alignment by the time I call</p>



<p>by the time I&#8217;m getting ready to call printf which means the push pop pair around it throws</p>



<p>push pop pair around it throws the stack out of alignment so just watch here I&#8217;ll</p>



<p>prove it okay so it&#8217;s sake false I comment that out now it won&#8217;t throw it</p>



<p>out of alignment okay should have known that before I recorded the video it&#8217;s</p>



<p>fun to guess sometimes though you know I get a little nervous oh no my program</p>



<p>broke on camera can I debug it live well I guess I can but kind of slowly</p>



<p>anyway so we I think we&#8217;ve gone over every single part that I wanted to show you</p>



<p>we know how to create a local array on the stack and and therefore you also know how to create like</p>



<p>any other data type on the stack if you want you want to create a long a 64-bit integer</p>



<p>just move it by eight bytes instead of moving it by eight times however many integers we were doing</p>



<p>in this video you want to I don&#8217;t know put a character on the stack you can do that if you</p>



<p>Just, you know, move it by one memory location instead of eight memory locations.</p>



<p>So, you know, one byte instead of eight bytes.</p>



<p>You want to store a short, you know, a two byte integer?</p>



<p>Well, just move it by two bytes instead of eight bytes, right?</p>



<p>So you can do this as many times as you want.</p>



<p>You want to have several local variables?</p>



<p>Just move it one time for every local variable.</p>



<p>Same thing for accessing.</p>



<p>You just have to remember where everything is.</p>



<p>offset of the of the first variable local variable and then the offset of the second</p>



<p>local variable you can store those in globals or store those in registers if you can you just</p>



<p>got to remember somehow where everything starts but it&#8217;s all sitting on the stack if it&#8217;s a local</p>



<p>variable okay I guess that&#8217;s everything that I really have to say I hope you enjoyed this video</p>



<p>I hope you learned a little bit of stuff and had a little bit of fun I&#8217;ll see you in the next video</p>



<p>have a good one</p>



<p>you</p>



<p>Hey everybody, thanks for watching this video again from the bottom of my heart. 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</p>



<p>Could you please subscribe and follow this channel or these videos or whatever it is?</p>



<p>You do on the current social media website that you&#8217;re looking at right now</p>



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



<p>more videos, 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 middle of</p>



<p>the night and I just wake up because I know somebody subscribed or followed. It just wakes</p>



<p>me up and I get filled with joy. That&#8217;s exactly what happens every single time. So you could do</p>



<p>it as a nice favor to me or you could troll me if you want to just wake me up in the middle of</p>



<p>the night, 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>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. I&#8217;m like</p>



<p>It would really it really mean the world to me. I would really appreciate it. So again, thank you so much for watching this video and</p>



<p>Enjoy the cool music 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-local-variables-stack-frames-alignment-explained/">x86-64 Assembly: Local Variables, Stack Frames &amp; Alignment Explained</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-local-variables-stack-frames-alignment-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>x86-64 Assembly Pointers &#038; Dereferencing Explained &#8211; Hybrid C++/YASM Example</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 22 Feb 2026 03:21:32 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly C++ interop]]></category>
		<category><![CDATA[assembly data section]]></category>
		<category><![CDATA[assembly memory addresses]]></category>
		<category><![CDATA[assembly pointers]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[dereferencing assembly]]></category>
		<category><![CDATA[extern C assembly]]></category>
		<category><![CDATA[hybrid C++ assembly]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[passing pointers assembly]]></category>
		<category><![CDATA[stack alignment assembly]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[x86-64 calling convention]]></category>
		<category><![CDATA[x86-64 pointers]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=305</guid>

					<description><![CDATA[<p>This video explains pointers and dereferencing in x86-64 YASM assembly and demonstrates passing pointers between assembly and C++ in a hybrid program. We show how to read a C string from assembly, modify a long via pointer dereference so the change is visible in C++, and send assembly-owned data (string, long, double) back to C++ using pointers.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/">x86-64 Assembly Pointers &amp; Dereferencing Explained &#8211; Hybrid C++/YASM Example</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 Pointers &amp; Dereferencing Explained - Hybrid C++/YASM Example" width="1380" height="776" src="https://www.youtube.com/embed/jzj0iqC-XJI?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>Learn pointers &amp; dereferencing in x86-64 YASM assembly and how to pass them correctly between assembly and C++ in a hybrid program. We build a small working example that sends strings, longs, and doubles both directions using pointers, modifies values across module boundaries, and explains why pointer-to-double still uses general-purpose registers. Includes a quick demo of stack misalignment crash + fix.</p>



<p>Great for assembly beginners moving to real programs, systems programming students, or anyone curious how low-level code talks to C/C++.</p>



<p>00:00 Introduction to Pointers and Dereferencing in x86-64 Assembly<br>00:28 Pointers explained in C++<br>01:02 Changing values via pointers in C++<br>01:43 Pointers in assembly basics<br>02:09 Defining variables and pointers in YASM data section<br>03:23 Pointers are always integers even to doubles<br>04:20 Function arguments are pointers treated as 64-bit integers<br>05:00 Driver C++ code overview<br>05:58 Marking extern &#8220;C&#8221; functions<br>06:40 Local stack variables and passing pointers<br>07:51 Stack lifetime warning<br>08:34 Assembly data section strings and numbers<br>09:39 Print null-terminated string helper functions<br>10:38 External symbols and hey_driver_print_this<br>11:29 Point function prologue and stack alignment<br>13:04 Extra push for 16-byte alignment<br>14:20 Printing welcome message from assembly<br>16:00 Driver sees initial long value<br>16:58 Printing received string from C++<br>18:20 Using received char pointer without dereference<br>20:21 Modifying incoming long via dereference<br>21:46 Driver sees modified long value 101<br>22:43 Calling back to C++ to print assembly-owned data<br>23:48 Passing pointers to assembly string long and double<br>25:08 Driver prints assembly-owned values and addresses<br>26:14 Summary of pointer passing between modules<br>26:36 Stack alignment crash demonstration<br>27:39 Adding extra push/pop fixes segfault<br>28:00 Closing remarks and call to subscribe</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>Hey there! In this video we&#8217;re going to talk about pointers and dereferencing in a YASM x8664</p>



<p>assembly program, also as a hybrid program so that assembly and C++ can talk to each other</p>



<p>and send each other pointers and send each other data and things like that.</p>



<p>for what pointers are.</p>



<p>I&#8217;m going to write in C++ for a second.</p>



<p>Suppose you have a pointer for an integer.</p>



<p>We&#8217;ll call it P.</p>



<p>Suppose you have an integer by itself.</p>



<p>We&#8217;ll call it A.</p>



<p>Let&#8217;s say that the value of A is 5.</p>



<p>And if you wanted to say that P points to A,</p>



<p>you could say P equals the address of A.</p>



<p>I&#8217;ll put C++ at the top here.</p>



<p>And so now if I set A to 6</p>



<p>then I print P a dereference of P this is not like a full pointers tutorial</p>



<p>but basically by changing a I&#8217;m changing what P thinks it sees as a value</p>



<p>assuming ID reference it I could also let me do a print 6 here I could also</p>



<p>just change the value through P I could say dereference P and I could say equals</p>



<p>would actually print a seven right so you know you can have regular variables global variables</p>



<p>whatever kind of you know memory stuff on the stack and to get a pointer to it you really just</p>



<p>need to get its memory location in c++ it&#8217;s kind of easy syntactically you can see what&#8217;s happening</p>



<p>in assembly you really just need the memory location stored somewhere you could store that</p>



<p>variable that just simply stored the memory location of some other variable.</p>



<p>You could have a 64-bit register store the value of a variable.</p>



<p>Let&#8217;s say we have like a, I don&#8217;t know, my whatever, my number let&#8217;s say inside of assembly.</p>



<p>I&#8217;ll do ASM here and we say it&#8217;s a quad word and it starts off as this number or whatever.</p>



<p>So if you haven&#8217;t seen my previous videos, go see them for the basics of assembly and</p>



<p>of assembly and linking and make files and all that stuff but you know if you</p>



<p>have an assembly program and you have a data section and you define a global</p>



<p>variable like this what you&#8217;re basically saying is I want to take this giant</p>



<p>number and I want to write it into eight bytes that&#8217;s the DQ it says data quad</p>



<p>word I want to write that giant number across eight bytes and then I want to</p>



<p>get a pointer to it stored in the my number symbol so my number is not</p>



<p>actually the value it&#8217;s a pointer to the value so you know later if you want to</p>



<p>you know later if you want to move you know something into a register if you did this</p>



<p>that would move the pointer into rax but if you did this</p>



<p>with deref symbols after it or around it then you would move</p>



<p>maybe i&#8217;ll put that into rex you&#8217;d move that actual number that we specified into rex</p>



<p>into Rx. It&#8217;s important to understand also that pointers are integers even when we&#8217;re pointing to</p>



<p>doubles. So for example sometimes people make this mistake they&#8217;ll say you know my double</p>



<p>and they&#8217;ll say it&#8217;s a quad word meaning this is going to be a 64-bit double precision floating</p>



<p>point number and they&#8217;ll do like 44.55 or whatever. So that is a double and it is in memory</p>



<p>you know what is the symbol of my double remember it&#8217;s supposed to be just a</p>



<p>pointer right it can&#8217;t be an actual double because a memory location is not</p>



<p>a double a memory location is an integer so that means if you wanted to move a</p>



<p>pointer into a register you would only be able to move the pointer into a</p>



<p>regular general purpose register not a floating point register and you should</p>



<p>use the regular movement instructions for just regular general purpose</p>



<p>So keep that in mind if you see a signature like this like let&#8217;s say function F and we have</p>



<p>You know, let&#8217;s say long a and long B and actually let&#8217;s do pointers</p>



<p>Let&#8217;s say long pointer a and long pointer</p>



<p>B and double pointer C all three of those arguments are actually 64 bit integers</p>



<p>Because they&#8217;re all pointers even if one of the pointers points to adult a double</p>



<p>double why did I say dull pointers aren&#8217;t dull they&#8217;re exciting okay so I&#8217;m gonna open up some</p>



<p>code here real fast so usually I don&#8217;t explain my uh my driver I&#8217;m gonna explain it to you this time</p>



<p>because it&#8217;s kind of doing a little bit more than my other videos um again if you don&#8217;t have uh the</p>



<p>knowledge of how to make a make file see my other videos because that&#8217;s explained there for now I&#8217;m</p>



<p>what we really need to do is write a driver and an assembly module for a</p>



<p>hybrid program again hybrid programs covered in other videos so the driver is</p>



<p>pretty easy I&#8217;m just going to copy paste it honestly here and then just kind of</p>



<p>explain it to you the driver is pretty easy we&#8217;re going to do I O stream so we</p>



<p>can print stuff we&#8217;re going to mark an external function called point as extern</p>



<p>C so that just disables name mangling which means the C++ module will be able</p>



<p>will be able to call on this function called point and it won&#8217;t expect that</p>



<p>the point function has its name mangled like C++ does the reason being is that</p>



<p>point is actually going to be in a side it&#8217;s going to be inside assembly where</p>



<p>its name will not be mangled this disables the ability to overload but</p>



<p>that&#8217;s okay we don&#8217;t care it&#8217;s going to take two pointers a pointer to a character</p>



<p>and a pointer to a long since both of those are pointers they&#8217;re both</p>



<p>64-bit integers even the character pointer and then we have a function that is internal to this</p>



<p>module called hey driver print this remember we&#8217;re inside of the driver program right now</p>



<p>so if you look at the bottom it&#8217;s just a function that takes in some pointers</p>



<p>and then prints some stuff so it&#8217;s going to print like it&#8217;s going to print what the string is</p>



<p>it&#8217;s going to print what the long is my dog&#8217;s growling at me i&#8217;m going to ignore him because</p>



<p>i literally just let him pee and poop at this point now he&#8217;s harassing me for treats</p>



<p>now he&#8217;s harassing me for treats he always does this okay so uh the string the long the double</p>



<p>this function expects to receive three pointers to different data types it&#8217;s just going to print</p>



<p>all of them and the point get it the point of this function is we&#8217;re going to go inside of</p>



<p>the assembly module and then have the assembly module call on this function so that we can we</p>



<p>can prove that we can have stuff sent from assembly to c plus plus or c using pointers</p>



<p>using pointers we can have data sent over so anyway that&#8217;s why both of these</p>



<p>are in here the point needs to be marked as no name mangling because point is</p>



<p>inside of assembly which will not name mangle and then hey driver print this</p>



<p>that needs to have name mangling disabled also so that the assembly</p>



<p>module can call on this other than that we&#8217;re just basically inside of a main</p>



<p>saying hey this is the c string we&#8217;re making a c string inside of the main function notice how</p>



<p>this is a local variable so that c string is going to show up on the stack it&#8217;s going to show up in</p>



<p>the area that is owned by main for main stack area same thing for my long that&#8217;s a local variable on</p>



<p>the stack um and but then we can actually send pointers to those pieces of data to another</p>



<p>function in another module you don&#8217;t have to only transport globals or stuff on the heap</p>



<p>or stuff on the heap, you can transport pointers to local variables. Just make sure that by the</p>



<p>time this function finishes, then nowhere else is actually using that data because,</p>



<p>well, being on the stack, once main function or once any function finishes, then its portion of</p>



<p>the stack will be cleaned up and removed and it&#8217;ll be junk data. You&#8217;ll probably get a seg fault.</p>



<p>But for now, we&#8217;re not going to use anything on the stack. We&#8217;re not going to use these local</p>



<p>just going to use them quickly on this call to point and then we&#8217;re going to return to the</p>



<p>operating system and finish the program. So that&#8217;s the driver. Now the hard part. Let&#8217;s do this in</p>



<p>assembly. So for starters, I&#8217;m going to make a data section and just explain it to you very,</p>



<p>very quickly. Again, if you don&#8217;t understand the basics of YASM x86-64 assembly, did I mention</p>



<p>that that&#8217;s what this language is at the beginning of the video? I guess I should put that in the</p>



<p>put that in the description or record an announcement that I can tack on at the beginning</p>



<p>or something. Anyway, so if you don&#8217;t understand how to do this, see my other videos, but basically</p>



<p>we&#8217;re going to make a data section. We&#8217;re going to define some strings. Here&#8217;s like an announcement.</p>



<p>Oh, we&#8217;re inside of, you know, the module now, the assembly module. And now we&#8217;re going to print</p>



<p>the received string. And then we&#8217;re going to make a string that is owned by assembly, which we can</p>



<p>into C++ when we call the function inside of the driver.</p>



<p>So this string is owned by the assembly module.</p>



<p>Notice how these are null terminated strings.</p>



<p>I just have like a comma zero there,</p>



<p>which means I have some extra functions</p>



<p>I&#8217;m gonna paste in that we&#8217;re not really gonna talk about</p>



<p>because they&#8217;ve been discussed in other videos</p>



<p>just so that we can print null terminated strings.</p>



<p>Then I&#8217;ve got a new line here,</p>



<p>you know, carriage return line feed.</p>



<p>And then I&#8217;ve just got some numbers</p>



<p>that are owned by the assembly module.</p>



<p>Then I&#8217;ve got a system write call,</p>



<p>call code one for the system call writes and file descriptor standard output so I</p>



<p>can print just to the terminal again if you don&#8217;t understand this see my other</p>



<p>videos so now let&#8217;s start the actual text section so this is where our</p>



<p>instructions start so we got the text section here and we&#8217;re going to use some</p>



<p>external symbols don&#8217;t worry about these I&#8217;m just using my own little library to</p>



<p>and input integers if you have access to this library use it if you don&#8217;t if you&#8217;re watching</p>



<p>at home and you don&#8217;t have this library then that&#8217;s fine you can use you know printf or</p>



<p>scanf or something like that to get and print floats from and to the user</p>



<p>but yeah I&#8217;m just using that and then I&#8217;m marking an external function here called hey driver print</p>



<p>this if you recall the driver module has a function called hey driver print this so</p>



<p>just allows my assembly code to call on that external function. Okay now next</p>



<p>piece of code. This is going to be… actually I&#8217;m going to paste the print</p>



<p>null terminated string function and related code because it&#8217;s just like a</p>



<p>big giant mess and we&#8217;re mostly going to ignore it. So just to show you what I&#8217;m</p>



<p>doing here I have a function called print null terminated string so that I</p>



<p>can print these strings up here and then I have it rely on a function called</p>



<p>string length that I have implemented up here and all it does is just</p>



<p>implemented up here and all it does just calculates the length of the string and</p>



<p>then a crlf function so I can just call that so that&#8217;s all explained in other</p>



<p>videos don&#8217;t worry about it for now we&#8217;re going to start the actual entry</p>



<p>point remember the driver was just gonna call point right so now we just have to</p>



<p>implement point in the assembly module so that&#8217;s gonna be like down here our</p>



<p>our entry point so the signature for this function is going to be character</p>



<p>pointer and then a long pointer and it doesn&#8217;t return anything and remember</p>



<p>that if we look back at the driver that should match the signature right it&#8217;s a</p>



<p>character pointer and a long pointer and of course this is just a comment that</p>



<p>reminds me of what to do in assembly you don&#8217;t really have a signature you just</p>



<p>sort of use registers but I&#8217;m reminding myself that RDI is going to be a</p>



<p>character pointer and RSI is going to be a long pointer.</p>



<p>Here&#8217;s a note to myself that I&#8217;m going to use R12 and R13, which means</p>



<p>the first thing that I should do, well actually before I even do that, I should</p>



<p>return from this function because it is a function. I marked it as global</p>



<p>so that the other module could call it, the driver module could call it. Again,</p>



<p>see my other videos for hybrid programs.</p>



<p>But so now the, you know, if the driver calls this function, then now we&#8217;re inside of</p>



<p>and there&#8217;s a return statement so it&#8217;s a valid function I should preserve the</p>



<p>registers that I&#8217;m going to use that are marked as Kali saved for the ABI so I&#8217;m</p>



<p>going to go prologue and then an epilogue and I&#8217;m going to say push r12 and push</p>



<p>r13 and then I&#8217;m going to pop r13 pop r12 they should be in reverse order if</p>



<p>you&#8217;ve seen my other videos you&#8217;ll know this and the the thing about this</p>



<p>the thing about this particular program is we&#8217;re going to run into stack alignment issues</p>



<p>so uh if you don&#8217;t know about stack alignment and how it can crash your program without you</p>



<p>realizing what&#8217;s wrong see my other videos but for now we&#8217;ll assume you know that and uh i i</p>



<p>already know from running this program in advance that it&#8217;s going to be out of alignment by eight</p>



<p>bytes so i&#8217;m just going to push an extra register onto the stack and that&#8217;s going to put it back</p>



<p>I know it looks weird, but this is going to work.</p>



<p>Let me get rid of this here.</p>



<p>Okay, so.</p>



<p>And then maybe if I can remember at the end of the video,</p>



<p>I can just remove that extra push-pop pair,</p>



<p>and you&#8217;ll see the program starts crashing.</p>



<p>But at home, you can do it just to double check.</p>



<p>So the first thing I really want to do is,</p>



<p>after I push and pop,</p>



<p>is save our incoming arguments.</p>



<p>Remember, the first integer argument</p>



<p>and the second integer argument,</p>



<p>argument they come in as RDI and RSI in assembly per the ABI if both of these</p>



<p>things are pointers it doesn&#8217;t matter what the data type is it could be</p>



<p>pointing to anything including a double and these would still be considered</p>



<p>integer arguments because well RDI and RSI are just going to be loaded up with</p>



<p>memory locations which which are integers so I&#8217;m going to save our</p>



<p>arguments to R12 and R13 now justifying our push and pop pair then I&#8217;m going to</p>



<p>little welcome message so print a little welcome message again you don&#8217;t need to know about this</p>



<p>function but it&#8217;s explained in other videos that I&#8217;ve already published we&#8217;re going to print our</p>



<p>hello beginning message I&#8217;m getting nervous he needs to take a second poop sometimes it&#8217;s poopoo</p>



<p>number two time for him and he&#8217;s not really just lying about a treat but he did go pee and poop</p>



<p>But he did go pee and poop already.</p>



<p>Okay, he just left and walked away.</p>



<p>Okay, if he comes back, I&#8217;m letting him out this time.</p>



<p>I&#8217;ll pause the video if he does it again.</p>



<p>Okay, I&#8217;m pausing the video.</p>



<p>No pee lied.</p>



<p>He went outside, lifted up his little leg, and a couple of drops of pee came out.</p>



<p>Now he&#8217;s staring at me like he deserves a treat.</p>



<p>Sorry, buddy.</p>



<p>I wish I could eat constantly all day long, too.</p>



<p>But life isn&#8217;t always fair.</p>



<p>isn&#8217;t always fair anyway let&#8217;s see I might even lined up on the camera</p>



<p>anymore I don&#8217;t even know so we&#8217;re looking at this code here is going to</p>



<p>print a welcome message let&#8217;s see if that actually works so I&#8217;m gonna do make</p>



<p>run again make files are whoops what did I do loader dot asm what did I do what</p>



<p>did I do I somehow copy pasted the wrong make file</p>



<p>What&#8217;s the name of my source code file?</p>



<p>It&#8217;s point.</p>



<p>I guess I&#8217;ll just change it, and then it&#8217;ll probably work.</p>



<p>It&#8217;s still in assembly module.</p>



<p>Hopefully that didn&#8217;t mess it up too bad by copy-pasting the wrong source code.</p>



<p>Okay.</p>



<p>What is going on here?</p>



<p>Floater.</p>



<p>Oh, I need to change that.</p>



<p>Hang on.</p>



<p>Let me fix this.</p>



<p>I don&#8217;t know if I&#8217;m going to edit this out.</p>



<p>out. It&#8217;s fun to watch me struggle sometimes. There we go.</p>



<p>Point.</p>



<p>Alright, let&#8217;s give it another try.</p>



<p>Oh no, star dot so no such file a directory. Dang it.</p>



<p>Okay, now this seems to work. I may or may not have edited</p>



<p>that out. I copy pasted the wrong source code into my make</p>



<p>file. So I had to manually adjust it. Then I forgot to</p>



<p>copy paste my library file into the build directory. So I had</p>



<p>The driver sees my long as whatever.</p>



<p>What&#8217;s going on?</p>



<p>Print an alternate string begin.</p>



<p>Oh, the driver is printing a bunch of stuff.</p>



<p>Okay.</p>



<p>I started to think, why does it look like the program has a lot of stuff going on?</p>



<p>Oh, that&#8217;s the driver.</p>



<p>Okay.</p>



<p>So the driver says it sees its long as 100.</p>



<p>And then now we&#8217;re inside of the point module.</p>



<p>So that&#8217;s the only thing we&#8217;ve done in assembly so far.</p>



<p>so far then the driver has regained control maybe I should add a couple of</p>



<p>new lines in there so I don&#8217;t get confused again we will do a C out and L</p>



<p>and we&#8217;ll do two of those run the program again and then I won&#8217;t get</p>



<p>confused about the messages okay so now we&#8217;re inside of the point module and</p>



<p>nothing is happening so points let me get rid of the make file here and</p>



<p>and we&#8217;re just printing a welcome message nothing else so now let&#8217;s print</p>



<p>the received string so what am I talking about so we&#8217;re gonna print a prefix</p>



<p>basically saying hey we received the following string right so if you look at</p>



<p>the symbol message received string it&#8217;s just gonna say we&#8217;re now printing the</p>



<p>received string and then it&#8217;ll print it so what are we actually printing we&#8217;re</p>



<p>What is R12? R12 is a character pointer to the print me string. And so basically this</p>



<p>function print null terminated string, it takes a character pointer. So we&#8217;re giving it a character</p>



<p>pointer that we received. When point was called by the driver, notice how it gave a pointer to</p>



<p>the C string. You know, all arrays are basically pointers. They&#8217;re just different syntactically</p>



<p>just different syntactically sometimes so if i declare an array of some length and i give the</p>



<p>symbol somewhere that symbol is really a character pointer so um by calling point with my c string</p>



<p>i&#8217;m calling point inside of the assembly module with this character pointer so that means even</p>



<p>though this c string is owned by the driver by the c plus plus module the assembly module has access</p>



<p>So that means we should be able to print it right now already.</p>



<p>So just the rest of it is just like giving a pointer.</p>



<p>And notice how I&#8217;m not dereferencing R12.</p>



<p>If I did dereferencing around R12, then we would be looking to that address and seeing what&#8217;s there,</p>



<p>which wouldn&#8217;t work for printing a null terminated string.</p>



<p>So let&#8217;s just run it again.</p>



<p>I don&#8217;t know if you can hear him.</p>



<p>This dude is growling at me still because he wants another treat.</p>



<p>He just got denied.</p>



<p>He&#8217;s trying to do it again.</p>



<p>do it again. I let him outside people. He&#8217;s been outside like three times already and he just went</p>



<p>out like two minutes ago. Okay. I love him so much. It hurts my heart and he knows eventually he&#8217;s</p>



<p>going to break me because it hurts my heart or I&#8217;m like too distracted. It&#8217;s like, you know,</p>



<p>pulling the crank on a slot machine in Vegas. You know, eventually something comes out.</p>



<p>That&#8217;s what he does to me. I&#8217;ve accidentally trained him. So now printing the received</p>



<p>Now printing the received string and notice how it prints.</p>



<p>Hello, this is a C string owned by me.</p>



<p>So our assembly module is able to print a C string that was created locally by a C++ module.</p>



<p>So we&#8217;re handing around pointers.</p>



<p>Nice.</p>



<p>Can you hear me?</p>



<p>He&#8217;s getting louder.</p>



<p>So now let&#8217;s modify the incoming long.</p>



<p>Can you shush your freaking pants, please?</p>



<p>Shush your pants.</p>



<p>shush your pants you know the sad thing also is he&#8217;s so old that he&#8217;s deaf now</p>



<p>so he used to know what shush your pants meant it meant I&#8217;m not listening to you</p>



<p>and you might as well stop because I&#8217;m not gonna do anything based on your</p>



<p>harassment but now he can&#8217;t hear me say shush your pants so he just harasses me</p>



<p>all day and all night okay um so I&#8217;m gonna copy paste a little bit more code</p>



<p>Modify the incoming long.</p>



<p>So remember again that the point function, it received a pointer to a long.</p>



<p>We&#8217;re calling the long change me on the inside of this, but it&#8217;s coming in as R13.</p>



<p>And if you notice what I&#8217;m doing here is I&#8217;m just saying let&#8217;s increase the long.</p>



<p>So I&#8217;m going to dereference R13 because R13 is a pointer.</p>



<p>So I&#8217;m saying let&#8217;s go to the memory and change the long that is inside of memory.</p>



<p>And we have to specify that it is a keyword.</p>



<p>it as a keyword so that we you know we don&#8217;t confuse the system the system might think are</p>



<p>you modifying a keyword or like a double word or like a word like how big is your data all we know</p>



<p>is it&#8217;s an integer because it&#8217;s the increase instruction so I&#8217;m saying we got a keyword you</p>



<p>know a 64-bit integer sitting at that memory location I want you to dereference it and increase</p>



<p>it and going back to the driver we&#8217;re providing a pointer to our long so the long starts off is 100</p>



<p>and we&#8217;re just giving a pointer to it the next thing that we can do is we can</p>



<p>ask the driver to print our own stuff actually you know what let&#8217;s run the program right now</p>



<p>just to show that the driver can see the change in the long so i&#8217;m going to run it again notice how</p>



<p>first when the driver says hello it sees its own long as 100 then we&#8217;re inside the assembly module</p>



<p>long and then we return to the caller which is the driver notice how at the</p>



<p>very end of the program the driver sees its long as being 101 so we were able to</p>



<p>modify data that was owned by a different module just by passing pointers</p>



<p>and de-referencing them okay cool so now the next thing that we should do is let&#8217;s</p>



<p>ask the driver to print our own stuff that we own because remember if you go</p>



<p>to the very top you know we own some stuff we own some we own a long we own</p>



<p>float, right? So we want to be able to do something with that. So I&#8217;m going to copy paste this,</p>



<p>ask the driver to print our own stuff. So I&#8217;m going to move three items inside of arguments</p>



<p>for a function call. And then I&#8217;m going to make a function call calling the function,</p>



<p>Hey driver, print this again, Hey driver, print this is actually owned by the C++ module.</p>



<p>a pointer to a long and a pointer to a double remember even pointers to doubles are actually</p>



<p>integers so they use the general purpose register so that&#8217;s the three arguments right there rdi rsi</p>



<p>and rdx m and then we&#8217;re giving the first pointer is going to be the c string so message string</p>



<p>inside asm so you can see that&#8217;s this right here and then the next pointer is the long</p>



<p>inside ASM and the third is the float where did I just go I&#8217;m getting confused my dog is harassing</p>



<p>me right now so bad notice how I&#8217;m not dereferencing so like if when we were increasing the incoming</p>



<p>long before R13 was a pointer so we dereferenced while we increased so that we would increase the</p>



<p>actual value and not the pointer and not the pointer&#8217;s memory location but here we&#8217;re not</p>



<p>C++ module the actual pointers to our data. We don&#8217;t want to give it the data itself. We want</p>



<p>to give pointers to the data so we&#8217;re not derefing with the brackets. So then we call it and when we</p>



<p>get back in here it should just be able to print everything. So I&#8217;m going to run it one more time.</p>



<p>We&#8217;re going to make it and run it and so now let&#8217;s see. So here we&#8217;re inside of our assembly module</p>



<p>And then here the assembly module has just called on hey driver print this.</p>



<p>Remember the C++ module doesn&#8217;t actually call this function.</p>



<p>The assembly module calls it.</p>



<p>So we&#8217;re like going back and forth.</p>



<p>We&#8217;re kind of crisscrossing.</p>



<p>So now the drivers print this function says we got the following string.</p>



<p>Notice how that&#8217;s the string that is owned by assembly.</p>



<p>So we define that inside of our data section in the assembly module.</p>



<p>And then it prints the long.</p>



<p>It prints it as hex.</p>



<p>And it just sort of prints the value.</p>



<p>it just sort of prints the value then it prints it as hex again and then prints at the value</p>



<p>i think actually not hex i think this prints the memory location let&#8217;s double check real fast</p>



<p>yeah so remember um in c plus plus i know this is not like a c plus plus video but um</p>



<p>if the long is a pointer then if we just print it without dereferencing it we should see a memory</p>



<p>location so it&#8217;s telling us uh that the long&#8217;s memory location is this and the doubles memory</p>



<p>location is that and if you stare at those two numbers long enough and you understand hex which</p>



<p>And do you understand hex, which you can see my other videos for?</p>



<p>You&#8217;ll see that those memory locations are right next to each other because that&#8217;s the way we define them inside of assembly.</p>



<p>So we now have the ability to have data that is owned by assembly and give it to C++ or C using pointers.</p>



<p>No problem at all.</p>



<p>And then the printing driver thing exits and then the actual driver regains control.</p>



<p>And it just says that it sees it&#8217;s long as 101.</p>



<p>it sees it&#8217;s long as 101 so uh yeah that&#8217;s that&#8217;s pretty much all i wanted to show you for this</p>



<p>now you hopefully are an expert at passing data back and forth between various modules using</p>



<p>pointers we&#8217;re not using references because references are like a little bit a little bit</p>



<p>less compatible pointers are just really easy they totally work in assembly no problem</p>



<p>one more thing i just wanted to show you real fast before we go even though there&#8217;s another</p>



<p>video you should check out for stack alignment I just want you to see what</p>



<p>happens if I remove this extra push-pop pair so now my stack is about eight</p>



<p>bytes off of its previous alignment because you know we&#8217;re not pushing an</p>



<p>extra eight byte value and somewhere inside of the let&#8217;s see print null</p>



<p>terminated string and then the hey driver print this oh and then we go into</p>



<p>like a bunch of C stuff the program should probably crash because anytime</p>



<p>you use a GCC function or a GCC library or something like that the stack has to</p>



<p>be aligned to 16 bytes so if it&#8217;s off by 8 then it&#8217;ll crash and how did I know</p>



<p>that I needed this well I just ran it first and it crashed and then I added</p>



<p>the extra push pop pair and it didn&#8217;t crash and I realized it was definitely</p>



<p>one more time we should get a seg fault yeah we get a seg fault stack alignment oh no with no</p>



<p>description of what&#8217;s going on if you were in gcc you could i mean sorry if you were in gdb you</p>



<p>could probably figure that out eventually but why not just give it a try add another push pop pair</p>



<p>run the program again with no other modifications now it totally works</p>



<p>okay well uh i think that&#8217;s uh that&#8217;s all i have for this video thank you so much for watching i</p>



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



<p>I will 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,</p>



<p>could you please subscribe and follow this channel or these videos</p>



<p>or whatever it is you do on the current social media website</p>



<p>that you&#8217;re looking at right now.</p>



<p>It would really mean the world to me</p>



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



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



<p>or just I&#8217;ll be able to keep making videos in general so please do do me a</p>



<p>kindness and and subscribe you know sometimes I&#8217;m sleeping in the middle of</p>



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



<p>just wakes me up and I get filled with joy that&#8217;s exactly what happens every</p>



<p>single time so you could do it as a nice favor to me or you could you control me</p>



<p>up in the middle of the night just subscribe and then I&#8217;ll just wake up I promise that&#8217;s what will</p>



<p>happen also if you look at the middle of the screen right now you should see a QR code which</p>



<p>you can scan in order to go to the website which I think is also named somewhere at the bottom of</p>



<p>this video 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>for</p>



<p>Clarifications or errata or just future videos that you want to see please leave a comment or if you just want to say hey</p>



<p>What&#8217;s up? What&#8217;s going on? You know, just send me a comment, whatever</p>



<p>I also wake up for those in the middle of the night. I get I wake up in a cold sweat. I&#8217;m like this</p>



<p>It would really it really mean the world to me. I would really appreciate it. So again, thank you so much for watching this video and</p>



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



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/">x86-64 Assembly Pointers &amp; Dereferencing Explained &#8211; Hybrid C++/YASM Example</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-pointers-dereferencing-explained-hybrid-c-yasm-example/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>
		<item>
		<title>Complex If-ElseIf-Else in x86-64 YASM Assembly &#8211; Full Guide with Code Examples</title>
		<link>https://www.NeuralLantern.com/complex-if-elseif-else-in-x86-64-yasm-assembly-full-guide-with-code-examples/</link>
					<comments>https://www.NeuralLantern.com/complex-if-elseif-else-in-x86-64-yasm-assembly-full-guide-with-code-examples/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 04 Jan 2026 18:55:39 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly language if statement]]></category>
		<category><![CDATA[assembly language tutorial]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[chained if else assembly]]></category>
		<category><![CDATA[cmp instruction]]></category>
		<category><![CDATA[conditional branching assembly]]></category>
		<category><![CDATA[control flow assembly]]></category>
		<category><![CDATA[if else assembly]]></category>
		<category><![CDATA[intel assembly]]></category>
		<category><![CDATA[je jmp assembly]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[nasm assembly]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=275</guid>

					<description><![CDATA[<p>Step-by-step x86-64 YASM assembly tutorial showing how to implement complex if-else and if-elseif-else control flow structures with multiple chained conditions, proper labels, conditional jumps, and fall-through logic. Includes complete working code and live execution.</p>
<p>The post <a href="https://www.NeuralLantern.com/complex-if-elseif-else-in-x86-64-yasm-assembly-full-guide-with-code-examples/">Complex If-ElseIf-Else in x86-64 YASM Assembly &#8211; Full Guide with Code Examples</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 loading="lazy" title="Complex If-ElseIf-Else in x86-64 YASM Assembly - Full Guide with Code Examples" width="1380" height="776" src="https://www.youtube.com/embed/G7am7avKi9w?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 in-depth x86-64 assembly tutorial using YASM, we dive deep into implementing complex if-else and if-elseif-else control structures from scratch. Starting with the fundamentals of conditional branching, we build up to full chained if-elseif-else blocks with multiple conditions &#8211; exactly how high-level languages handle them under the hood.</p>



<p>You&#8217;ll see real working code that:</p>



<ul class="wp-block-list">
<li>Takes user integer input</li>



<li>Tests against specific values (5, 6, etc.)</li>



<li>Handles greater-than/less-than comparisons</li>



<li>Properly branches so only one block executes</li>



<li>Uses labels, cmp, conditional jumps (je, jl), and unconditional jumps (jmp) correctly</li>
</ul>



<p>We cover the classic pattern: compare to conditional jump to true block to execute true code to jmp to end to false block falls through or jumps in. Everything is shown step-by-step with live compilation and runtime demos.</p>



<p>Perfect for anyone learning low-level programming, reverse engineering, or wanting to understand how compilers translate if-else chains into machine code. Prerequisites: basic conditional jumps (see my earlier videos).</p>



<p>Code shown works on Linux x86-64 with YASM/NASM syntax. Grab the concepts and apply them anywhere.</p>



<p>Introduction to If-Else in Assembly 00:00:00<br>Explaining the If-Else Design Pattern 00:00:56<br>Drawing the Basic If-Else Flow 00:01:01<br>Comparison and Conditional Jumps 00:02:30<br>Labels for True and False Blocks 00:03:07<br>Unconditional Jump to End 00:04:50<br>Diagram of Execution Flow 00:05:51<br>Alternative Pattern with Inverted Jump 00:07:00<br>Recapping the If-Else Pattern 00:08:45<br>Starting the Code Example 00:09:16<br>Setting Up Input and Strings 00:09:40<br>Calling External Functions 00:10:57<br>Entry Point and Prologue 00:11:40<br>Asking User for Integer Input 00:13:09<br>Creating the if_test Function 00:14:56<br>Preserving Callee-Saved Registers 00:15:51<br>Printing Begin Message 00:17:03<br>Implementing Simple If Block 00:18:29<br>Comparison and je Jump 00:19:18<br>True Block: Equality Message 00:21:08<br>Testing Simple If Examples 00:23:48<br>Transition to If-Else Blocks 00:24:21<br>Creating if_else_test Function 00:24:47<br>Setting Up Complex If-Else 00:26:25<br>First If: Equal to 5 00:27:22<br>True Block for Equal 5 00:28:33<br>Else If: Equal to 6 00:30:29<br>Else If: Less Than 10 00:34:17<br>Final Else Block 00:37:33<br>Done Label and Goodbye 00:38:23<br>Recap of Full Flow 00:39:06<br>Live Demo of All Branches 00:40:54<br>Signed vs Unsigned Jumps Note 00:43:38<br>Recommended Assembly Book 00:44:12<br>Conditional Jump Families 00:45:05<br>Closing and Practice Advice 00:46:48</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 talk about implementing simple if-else blocks in YASM x86-64 assembly.</p>



<p>Although if you&#8217;re writing in a different assembly language, this video will probably</p>



<p>still be useful to you because I&#8217;m going to explain the design pattern or how we can achieve</p>



<p>that at the assembly level.</p>



<p>So x86-64 YASM assembly, also known as AMD64 YASM assembly.</p>



<p>So if you have not seen my other videos about how to do conditional branching in the first</p>



<p>place, you probably want to go check that first because that knowledge is required for</p>



<p>this video.</p>



<p>There&#8217;s also a lot of other stuff that I&#8217;m just not going to explain in this video, such</p>



<p>as creating a make file, you know, compiling and linking your executable and so forth.</p>



<p>So see my other videos where all those concepts are explained already.</p>



<p>how to implement a simple if-else block.</p>



<p>So for starters, maybe let me draw a little bit.</p>



<p>Suppose we had, let me get rid of this thing</p>



<p>and then I&#8217;ll just do a regular notepad.</p>



<p>Suppose we had a higher level language,</p>



<p>just so you know what I&#8217;m talking about.</p>



<p>Suppose we had a higher level language</p>



<p>and we wanted to say if, you know, some expression is true.</p>



<p>We wanted to say if expression is true,</p>



<p>then print, you know, it was true.</p>



<p>Anybody remember that old movie, Little Nicky?</p>



<p>Somebody got exploded and then the guy next to him goes it&#8217;s not true</p>



<p>Okay, it was not true</p>



<p>So this is the basic idea of what we&#8217;re going to implement in assembly</p>



<p>I&#8217;m going to write a full program for assembly to show you this but um</p>



<p>You know you&#8217;re in C++ you&#8217;re in C you&#8217;re in I don&#8217;t know whatever language you&#8217;re in and</p>



<p>You obviously know how to use if-else blocks at this point hopefully</p>



<p>And now we&#8217;re going to just try to figure out how to implement them in assembly</p>



<p>So it&#8217;s important to understand that really under the hood</p>



<p>really under the hood there&#8217;s a bunch of stuff happening surprise right okay so</p>



<p>first off we look at this expression which could be I don&#8217;t know let&#8217;s say</p>



<p>five is greater than ten or a is equal to B or whatever it is that you put in</p>



<p>there you could make a very complicated expression we&#8217;re going to use simple</p>



<p>expressions for this video so if we&#8217;re comparing a to B we&#8217;ll end up using the</p>



<p>compare instruction remember there are two steps to conditional branching and</p>



<p>in YASM we first use the compare instruction against two operands and then that will end up</p>



<p>filling up the rflags register so that we can later conditionally jump based on the results</p>



<p>of the comparison. So we do a comparison and then you can imagine that the beginning of this</p>



<p>you know the the true body notice how it has a scope I&#8217;m going to just put this brace on another</p>



<p>line here to indicate that there is a scope from line four to six indicating all this code in here</p>



<p>in here is executed only if the if statement was true and then all of this other stuff is executed</p>



<p>only if the original comparison was false right so you can imagine now label is something like</p>



<p>my if was true so we can make a label for where that body starts and another label for where the</p>



<p>label is something like if was false and then what will happen is we can use a</p>



<p>conditional jump instruction after we do our comparison maybe I should put to</p>



<p>compare right here oh I&#8217;m using I&#8217;m using assembly style comments I should</p>



<p>be using a C style comments if I&#8217;m actually writing C++ here let me just do</p>



<p>that okay so this is the comparison instruction here and then here&#8217;s the</p>



<p>here and then here&#8217;s the beginning of the body of stuff to execute if it was true you can imagine</p>



<p>that there could be many statements here um if it was true or if it was false</p>



<p>just to prove to you that we can execute like a full body of stuff so we have a label that</p>



<p>designates when that body starts and then we have another label designating when the else body</p>



<p>starts and then we should have a label that uh that designates when the whole thing is over</p>



<p>label is something like if and or if is done or something like that so basically what we want to</p>



<p>do is to implement an if else a simple if else in assembly we&#8217;re going to say let&#8217;s do a comparison</p>



<p>and then we&#8217;ll do a conditional jump where are we going to conditionally jump well if the comparison</p>



<p>was true label. And then what will happen is execution will fall through.</p>



<p>When it reaches the end, we want to have another jump statement that unconditionally jumps</p>



<p>to the end of the if statement. If we didn&#8217;t, then whenever the expression was true,</p>



<p>we would end up executing all of the true statements and then it would fall through</p>



<p>to all of the false statements or the not true statements. So we have to have many jumps in here</p>



<p>let&#8217;s get into the body and then let&#8217;s finish and jump out of the body on the other hand if the</p>



<p>expression was false then our jump instruction is going to jump you know over the true body so</p>



<p>it&#8217;s not even going to do that at all it&#8217;s going to execute all of the else stuff and then it&#8217;s</p>



<p>you know sometimes a good idea if you have another jump here that just jumps to the end but you can</p>



<p>kind of see by the way i&#8217;ve written this out that there&#8217;s not going to be anything between the end</p>



<p>you know place where we&#8217;re finished with everything which means we don&#8217;t really</p>



<p>need an unconditional jump at the end of the else body we can just let the</p>



<p>execution fall through so maybe if I can draw a little diagram here I&#8217;ll say I</p>



<p>don&#8217;t know I&#8217;ll do like if put it in a little bubble and we&#8217;ll say that if it</p>



<p>was false we jump to one place and if it was true we jump to another place</p>



<p>we jump to another place.</p>



<p>I hope you&#8217;ve already started to understand this by now.</p>



<p>So we&#8217;ll say if the expression is true, we jump here.</p>



<p>If the expression is false, we jump over here.</p>



<p>And so true would be saying, let&#8217;s jump to the if was true.</p>



<p>So we&#8217;re going to jump to if was,</p>



<p>I&#8217;ll put a T there because I&#8217;m running out of space.</p>



<p>If was true.</p>



<p>was I&#8217;ll put an F false and then at the end of the true we jump to the done</p>



<p>label so I&#8217;m just gonna put done maybe down here</p>



<p>so at the end of the true we just unconditionally jump to the done area</p>



<p>and then at the end of the false we jump unconditionally to the done area as well</p>



<p>here&#8217;s something interesting though when we have a comparison instruction and</p>



<p>conditional branch instruction let&#8217;s say uh let&#8217;s say a equals b we did that comparison and then we</p>



<p>wanted to jump into the true area if a equals b was true so that means we&#8217;ll say jump</p>



<p>equal so if a is equal to b after we compare well let&#8217;s say a comma b we&#8217;re going to use registers</p>



<p>when we come to the code we&#8217;ll say compare a and b and then jump if they&#8217;re equal to some label</p>



<p>but the conditional branching instructions they only jump to one</p>



<p>potential place or fall through so if the comparison was false meaning if those</p>



<p>two things were not equal then we&#8217;re not going to actually be able to jump to a</p>



<p>different label we&#8217;re going to simply fall through to the next instruction so</p>



<p>in that case the very next instruction would get executed let&#8217;s just put a jump</p>



<p>was</p>



<p>false.</p>



<p>Meaning</p>



<p>we compare A and B</p>



<p>and if the two things are equal</p>



<p>we&#8217;ll jump into the true block.</p>



<p>Otherwise we fall through to the next instruction</p>



<p>which</p>



<p>that&#8217;s a very poorly written J</p>



<p>but we&#8217;re going to unconditionally jump to false.</p>



<p>So if we did not</p>



<p>jump to the true area we fall through to the next</p>



<p>instruction where we will always</p>



<p>jump to false and that implements the diagram</p>



<p>that implements the diagram that you see up above.</p>



<p>I mean, you know, if we have if statement, we compare,</p>



<p>maybe I&#8217;ll do, you know, A equals B.</p>



<p>We jumped to true, if was true.</p>



<p>And otherwise we end up falling through</p>



<p>and then jumping to if was false.</p>



<p>And then at the end of both of those,</p>



<p>we have an unconditional jump instruction</p>



<p>that jumps to the done.</p>



<p>So I&#8217;ll put JMP down here just to let you know,</p>



<p>you know, at the end of each of these blocks,</p>



<p>that they are jumping out of themselves at the very end to the done area maybe</p>



<p>I&#8217;ll put an arrow here so that we know both of these jumps end up jumping to</p>



<p>the done area that&#8217;s the basic idea for how to implement an if-else block a very</p>



<p>basic one we&#8217;re gonna do more complicated ones later but for now we</p>



<p>kind of have the idea down I think let&#8217;s look at some code dang I blew 10 minutes</p>



<p>already on that okay so I&#8217;m gonna copy paste some code from my solution here</p>



<p>code for my solution here this again this is not like a beginner&#8217;s assembly</p>



<p>video if you need to learn how to write assembly in the first place how to</p>



<p>compile you know link create a make file and so forth you need to see my other</p>



<p>videos first but for now we&#8217;re just going to assume that you know how to</p>



<p>make a data section in Yasm and we&#8217;re gonna say let&#8217;s make a bunch of strings</p>



<p>so first I&#8217;m gonna ask the user for an integer and then I&#8217;m gonna make a bunch</p>



<p>of decisions like I&#8217;m gonna do you know an if-else block to test what kind of</p>



<p>what kind of number they put you know did they make a number that uh</p>



<p>equal one if it was equal to something oh did I ask twice I can&#8217;t remember what I&#8217;m doing</p>



<p>but basically we&#8217;re going to print something if their number was equal to something else</p>



<p>we&#8217;re going to print uh something if their number that they inputted was equal to five we&#8217;re going</p>



<p>to print something else if their number was equal to six we&#8217;re going to print again something else</p>



<p>a bunch of stuff and then wait isn&#8217;t this the complicated example oh no i think i am using code</p>



<p>for my more complicated example else less than 10 i don&#8217;t know maybe this is the simple one</p>



<p>let&#8217;s double check i guess if i put more complicated code in here you&#8217;ll probably be happy</p>



<p>but whatever i thought this was going to be a simple example so i&#8217;m just defining strings at</p>



<p>codes stuff that is covered in other videos now i&#8217;m going to start my text section so my text</p>



<p>section begins with a declaration that i&#8217;m going to use two external functions so this video is</p>



<p>not about this library that takes input and sends output i have other videos for that but basically</p>



<p>i&#8217;m just using a library that lets you type an integer into the terminal and then it will print</p>



<p>a different number to the terminal for you so you can imagine if you wanted to follow along</p>



<p>imagine if you wanted to follow along with this code at home and you don&#8217;t</p>



<p>have this library you can just hard code your numbers just to prove to yourself</p>



<p>that you can get it to work or you can use a different library if you have a</p>



<p>hybrid program and you&#8217;re linking against GCC you can just use scanf and</p>



<p>printf pretty much those take a little bit more work to do but you can do it</p>



<p>anyway so our entry point is going to be called if tester it&#8217;s a function called</p>



<p>Again, this is a hybrid program and hybrid programs are not covered in this video, but you can imagine that there is a C++ module elsewhere in my source that is just going to call on a function called if tester.</p>



<p>And so that&#8217;s why I&#8217;m marking this as global so that other modules in my program can call on if tester.</p>



<p>So it&#8217;s just a little label that we can jump into or in this case call into.</p>



<p>Let me go down to the bottom of that.</p>



<p>We&#8217;ll put a return statement at the very end.</p>



<p>very end so now this is officially a function and notice how i made a note here that says r12 is</p>



<p>the user&#8217;s inputted integer so that means i&#8217;m going to be using r12 and since r12 is designated</p>



<p>in the abi the application binary interface as callee saved or callee preserved that means i</p>



<p>have to do a push pop pair to preserve it or i&#8217;ll get in lots and lots of trouble my program will</p>



<p>prologue which my favorite book also calls the prologue and then I&#8217;m going to</p>



<p>say epilogue and so now we have a function that basically doesn&#8217;t do</p>



<p>anything but we can at least jump into it let&#8217;s see if this compiles as is I</p>



<p>think it probably will yeah so the driver just says hello that&#8217;s the C++</p>



<p>program with the actual main function and it calls my if tester function but</p>



<p>nothing happens the if tester function returns control to the driver and then</p>



<p>the driver just says okay i got control back so nothing really happened so now let&#8217;s ask the user</p>



<p>for some input so again this is not a video about this library or how to print with this with system</p>



<p>calls see my other videos if you need help on that but basically we&#8217;re going to print a message to</p>



<p>the user hey please input an integer and then we&#8217;re going to call on a library function that</p>



<p>lets them type in a number and then returns it to us in rax we&#8217;re then going to store it</p>



<p>well just basic stuff right so if I run this again it&#8217;s going to ask for an</p>



<p>integer please enter an integer if I can type that and then nothing else happens</p>



<p>okay now we can kind of start making more decisions so I&#8217;m going to let&#8217;s see</p>



<p>if test if test if test okay so what I need to do now is run another function</p>



<p>called if tests several times and I&#8217;m going to compare the number that the</p>



<p>times and I&#8217;m going to compare the number that the user inputted so remember r12 is the user&#8217;s</p>



<p>input so I&#8217;m going to load that as the first argument of a function call and then I&#8217;m going</p>



<p>to load the number five as the second argument of a function call probably not a great idea to hard</p>



<p>code numbers in your assembly you should probably define them up in the globals or the the data</p>



<p>section at least as just regular defines and not numbers in memory but I&#8217;m going to just keep these</p>



<p>So three times we&#8217;re gonna call if test and then also another function called CRLF. So first I&#8217;m gonna paste in</p>



<p>CRLF</p>



<p>Where the heck is that? Oh, dude?</p>



<p>Again, this is not a video about the basics</p>



<p>So you&#8217;re just gonna have to trust me or go watch my other videos if you don&#8217;t understand what I&#8217;m doing here</p>



<p>But I have a function called</p>



<p>CRLF and its whole job in life is just to print a new line for me just because I like to do it that way</p>



<p>handles the CRLF call. Now let&#8217;s make another function called if test.</p>



<p>So I&#8217;m going to start that by designating its label right after this block of</p>



<p>code here, maybe before CRLF.</p>



<p>So we have like a basic if test function and here&#8217;s my prototype just to remind</p>



<p>myself what I&#8217;m going to be doing.</p>



<p>It&#8217;s going to take an input and it&#8217;s going to take another input for a test</p>



<p>against me. So the first one is like the user&#8217;s input.</p>



<p>The second one is the number that I want to test it against.</p>



<p>number that I want to test it against they&#8217;re both longs which means they are both integers</p>



<p>which means the incoming arguments are going to be rdi and rsi if you&#8217;re respecting the abi</p>



<p>and then some notes to remind myself I&#8217;m going to be using r12 and r13 inside of this function so</p>



<p>I&#8217;m going to start by putting a return statement there since that is what it takes to make a label</p>



<p>into a return into into a function then I&#8217;m going to preserve the callee saved registers again if</p>



<p>don&#8217;t know what i&#8217;m talking about see my other videos we&#8217;re going to push r12 and push r13 so</p>



<p>that they are not ruined for the caller we call this the prolog then at the very bottom of the</p>



<p>function we have the epilog which just restores uh the registers in reverse order you&#8217;ve got to</p>



<p>do it in reverse order see my other videos if you don&#8217;t understand why okay so that&#8217;s basically a</p>



<p>function that can get called it doesn&#8217;t do anything let me double check that the program still actually</p>



<p>works. 66 and nothing happens. We just printed CRLF a bunch of times. Okay, so now we&#8217;re ready</p>



<p>to continue. So let&#8217;s grab the function arguments. Remember we were going to use R12 and R13 for the</p>



<p>user&#8217;s input and the number we will test against. Those came into our function with RDI and RSI.</p>



<p>So I&#8217;m just going to copy those two incoming arguments into R12 and R13. And you&#8217;re supposed</p>



<p>keep the user&#8217;s input in RDI then the moment I call any other function or system call I&#8217;m just</p>



<p>going to lose that data so I&#8217;m going to keep it inside of R12 and R13 so I grab the function</p>



<p>arguments and then I print a begin message just to let the user know that we&#8217;re going to start</p>



<p>you know making tests against our number so this is just basically a message saying hey begin the</p>



<p>if test and then print what we&#8217;re going to check against so the next thing is</p>



<p>I&#8217;m going to let the user know what the second incoming argument was.</p>



<p>If you look at R13 here, that was RSI, which was the second argument.</p>



<p>So the test against me number.</p>



<p>So we&#8217;re going to check the user&#8217;s input against whatever we called for the second argument.</p>



<p>So I just wanted to print it out.</p>



<p>You know, like we&#8217;re testing your number against whatever.</p>



<p>So that means I need to make another call to my little printing library here.</p>



<p>To RDI which is the first argument notice how we already we already destroyed RDI. That&#8217;s why I&#8217;m keeping the input in our 12 and our 13</p>



<p>And then we&#8217;re gonna make that call and we can just assume everything will go according to plan at that point and then</p>



<p>Then we&#8217;re gonna print a special message only if something actually happens</p>



<p>So we&#8217;re gonna implement the if else block in a moment. Let me just run this real fast</p>



<p>and then it says we&#8217;re calling the function three times and we&#8217;re saying the basic test has begun</p>



<p>we&#8217;ll test against this number five so we&#8217;re testing your input against five and then six and</p>



<p>then seven and then we didn&#8217;t actually do anything we&#8217;re about to okay so then the next thing is we&#8217;re</p>



<p>going to print a special message only if the user entered the right number so first off remember we</p>



<p>see if else block and converting it into assembly so i&#8217;m sort of placing that in comments for you</p>



<p>so the comparison instruction i i didn&#8217;t want to put the r12 equals r13 inside of the same comment</p>



<p>that lines up with the the compare instruction because the compare instruction as i&#8217;ve said in</p>



<p>other videos already it doesn&#8217;t actually check to see if something&#8217;s equal it just makes a bunch of</p>



<p>called r flags with information that we can later use to decide if the two things were equal or not</p>



<p>equal or greater than or less than or whatever so that&#8217;s why i chose to put that on on the next line</p>



<p>so at this point we&#8217;re saying if those two things were equal and that&#8217;s how i implement the expression</p>



<p>in the middle then let&#8217;s jump to a special label called if test if was equal so you can come up</p>



<p>with any scheme you want for your labels but for me when i have when i have sub labels inside of a</p>



<p>when i have sub labels inside of a function i like to just suffix the function&#8217;s name with an</p>



<p>underscore and then start thinking of sub labels after that so everything&#8217;s like kind of clean</p>



<p>there&#8217;s less chance of overlap in labels if you have like a giant module with tons of functions</p>



<p>so i&#8217;m going to say this is like my main if that i&#8217;m checking and uh i&#8217;m going to jump to a label</p>



<p>called was equal meaning you know this evaluated to true that means that should be the true part</p>



<p>block let&#8217;s see do i still have that code here yeah right so here i&#8217;m going to jump to</p>



<p>the true block so you know if was true in the first example that we talked about so i&#8217;m going</p>



<p>to say if it&#8217;s if those things were equal jump to the code for the true block okay that means i</p>



<p>actually need the true block uh but i guess we&#8217;re going to set that up in a second otherwise if that</p>



<p>did not jump away it means that those two things are not equal so i said i should jump to the</p>



<p>I should jump to the else block or the false block.</p>



<p>Wait, do I have else in this example?</p>



<p>Oh, okay, okay.</p>



<p>This first thing that we&#8217;re looking at is only if.</p>



<p>So we don&#8217;t even have an else block yet.</p>



<p>We&#8217;re going to do that as the second example.</p>



<p>So we&#8217;re basically going to jump to the done area</p>



<p>if we didn&#8217;t jump into the true area.</p>



<p>And then at the end of the true area,</p>



<p>we can either jump to the done area</p>



<p>or we can let the execution fall through.</p>



<p>fall through okay so now that means i need if was equal and if i just copy paste a big giant</p>



<p>block of code and try to explain it to you real fast let&#8217;s do this</p>



<p>okay so we were going to jump to if was equal if r12 was equal to r13 and then um</p>



<p>we uh have this you know label here and notice how i&#8217;ve kind of like put a brace here indicating</p>



<p>like put a brace here indicating hey this is the beginning of the true block body you should</p>



<p>consider doing this too when you&#8217;re first learning and even after you&#8217;ve learned because let&#8217;s face</p>



<p>it assembly is tough and so in the true area i&#8217;m just going to print the equality message i&#8217;m going</p>



<p>to say hey your number was equal to you know whatever and then uh i&#8217;m going to actually print</p>



<p>the let&#8217;s see r13 number so that was uh i think the number to compare against the test against</p>



<p>against me number so that means here in this message we&#8217;re going to say hey your number was</p>



<p>equal to the number that we tested against so then otherwise let&#8217;s see or sorry after that</p>



<p>we&#8217;ll print the suffix of the message um and so you know i just i just like to make pretty</p>



<p>pretty uh printed messages so let&#8217;s see where&#8217;s the suffix here i can&#8217;t even find it um how about</p>



<p>oh i should have put suffix instead of the number two that would have been better so what i wanted</p>



<p>to do is say your input was equal to and then print the number and then after that print an</p>



<p>exclamation just to prove to you how easy it is to to make a pretty message that&#8217;s formatted nicely</p>



<p>for the user um or your professor or whoever so uh you know you basically just print a number and</p>



<p>then you or sorry you print the prefix and then you print the number and then you print the suffix</p>



<p>suffix and then that&#8217;s the end of the true body and then since we&#8217;re done with the true body we</p>



<p>can basically just say all right now we&#8217;re done with the if so the next instruction that follows</p>



<p>is the done area again looking back at the example here that would be sort of like here after the</p>



<p>whole entire block was finished we&#8217;re ignoring the else in this code but you can imagine we&#8217;ll do</p>



<p>that soon so if the user&#8217;s number matched something we execute a true body if not we jump to the done</p>



<p>to the done area and if the user&#8217;s uh number did not match then we just immediately jump to the</p>



<p>done area so that we don&#8217;t do the true area and then we write comments to ourselves to help us</p>



<p>remember oh look here&#8217;s like the comparison and then here&#8217;s the body of true and then uh the done</p>



<p>area is like we could put another comment if we want we could say like this is done but i kind of</p>



<p>think like i kind of think the label is self-explanatory so let&#8217;s see if this worked it&#8217;s</p>



<p>was talking too fast we&#8217;ll run it and we&#8217;ll say 44. okay so nothing matched any of the numbers so</p>



<p>let&#8217;s type the number six so that we get a little message on the second one so i&#8217;m going to type the</p>



<p>number six and you can see it did not match the number five and it did match the number six so</p>



<p>we got that true block executing when we called on that function where the number to compare to</p>



<p>nothing there. So now we know simple if blocks.</p>



<p>The next thing we&#8217;re going to do is if else blocks.</p>



<p>All right.</p>



<p>So let&#8217;s see.</p>



<p>Not sure if I&#8217;m going to cut the video and split this up into multiple parts.</p>



<p>Probably would have been a smart idea.</p>



<p>Let me know if I ended up doing it.</p>



<p>We&#8217;re at about 25 minutes now.</p>



<p>But anyway,</p>



<p>so now we&#8217;re going to look at if else blocks.</p>



<p>if else blocks.</p>



<p>So I&#8217;m going to start off with another function.</p>



<p>I&#8217;m going to call it if else test.</p>



<p>So here&#8217;s the tester.</p>



<p>It called on if test.</p>



<p>And then I&#8217;m going to, you know, I had the if test function that I did previously.</p>



<p>And so now we&#8217;re just going to make an if else test function.</p>



<p>The if else test, it just has one input, one argument for input.</p>



<p>And we&#8217;re going to just sort of compare it against different values.</p>



<p>of compare it against different values we&#8217;re not going to call this multiple times with different</p>



<p>values to compare against so that means let&#8217;s see we only need to use one register so</p>



<p>i&#8217;ve designated r12 as the user&#8217;s input so that&#8217;s where we&#8217;re going to store it which means we</p>



<p>should preserve it in the prologue so i&#8217;m going to push r12 and then again if you don&#8217;t understand</p>



<p>some of the basic stuff that i&#8217;m that i&#8217;m skipping over see my other videos where i explained</p>



<p>to know to actually have this kind of a program. So I&#8217;m going to have a function that enters and</p>



<p>it returns at the end. It uses R12 so we will preserve it with a push pop pair.</p>



<p>And then the first thing that I should do is grab the user&#8217;s input from the first argument.</p>



<p>And if you&#8217;re respecting the ABI that means it should come from RDI. So I&#8217;m going to move RDI</p>



<p>somebody remind me that the first part of the program has to actually call this function or</p>



<p>nothing will happen. So we&#8217;re going to say hello. That&#8217;s just a simple message that we talked about</p>



<p>before. And then now we&#8217;re going to actually implement the if else block. So it&#8217;s like a</p>



<p>little bit more complicated than just the simple if block. It&#8217;s going to be this whole example that</p>



<p>we talked about before. Let me see. Maybe I should add the calls to this block real fast. So we have</p>



<p>to this block real fast so we have the if tester and then run the complex if else tests</p>



<p>right before r12 okay let me just double check that i&#8217;m making a call at the right spot here</p>



<p>so we have r12 and 7 and then epilog okay so now finally in our program we&#8217;re going to have a call</p>



<p>to um the if else test function that we&#8217;re just making right now</p>



<p>Okay, so we have that.</p>



<p>And let me find that source again real fast.</p>



<p>If else test, we got the prologue.</p>



<p>We take their input and then we say hello.</p>



<p>Okay, so now we need another label that begins the if block.</p>



<p>So what we&#8217;re doing is we&#8217;re checking to see if the user&#8217;s input was equal to five.</p>



<p>And then we&#8217;re going to say something if it was.</p>



<p>And otherwise, we&#8217;re going to do an else block on that.</p>



<p>block on that so again i like to write my comparison instructions with a blank expression</p>



<p>in terms of the c equivalent comment so notice how the we&#8217;re checking to see if r12 is equal to</p>



<p>five i put that on the next block because we&#8217;re going to jump to the to the true part of the if</p>



<p>block if it equals five so that&#8217;s why i put that there the comparison instruction pretty much just</p>



<p>compares r12 with five sets a bunch of values into the r flags registers so that we can later</p>



<p>so that we can later conditionally jump if we want to.</p>



<p>So basically we&#8217;ll jump to the true place if that was true.</p>



<p>And then if not, execution falls through to the next statement,</p>



<p>which will just jump to the else place.</p>



<p>So we need more labels is what I&#8217;m saying.</p>



<p>So now we need a body for if the statement was true</p>



<p>or the expression was true,</p>



<p>we want to be able to execute the true portion of the if block.</p>



<p>the if block so that&#8217;s this right here so we&#8217;re going to jump to if it did equal to five you</p>



<p>could imagine you know making a better label instead of equal five you could say first if</p>



<p>first else if complicated block true scope or true block or something but i just put equal to five</p>



<p>basically saying we&#8217;ll execute this code if it was equal to five so again we&#8217;re just kind of like</p>



<p>into this label equal five if r12 was indeed equal to five so that means if it was we execute</p>



<p>all this code right here we know we&#8217;re finished when we have the very last line saying let&#8217;s jump</p>



<p>to finish the the if else block again just just to clarify</p>



<p>we do the comparison first and if the comparison was true then we&#8217;ll jump into the true area so</p>



<p>you know we&#8217;ll jump into the true area and then all of these uh instructions get executed</p>



<p>instructions get executed but if we don&#8217;t have a way to jump out of that block then whoops</p>



<p>all of the else statements are going to get executed too right so we don&#8217;t want that</p>



<p>we don&#8217;t want to execute both the true and the false statements we want to have a jump instruction</p>



<p>at the very end i&#8217;ll put jmp just so that we jump to the to the end of the if else block</p>



<p>you know jump to the place where it&#8217;s just all over and finished</p>



<p>Okay, so now I&#8217;m going to look at, whoops, turn that off.</p>



<p>So we have equal five.</p>



<p>So we&#8217;re going to jump to if else test if done.</p>



<p>Let me just double check to make sure I&#8217;m not forgetting anything.</p>



<p>Oh, we need to jump here.</p>



<p>Basically meaning we&#8217;re going to jump into the else portion.</p>



<p>So here we covered jumping into the true portion, you know, the regular top block.</p>



<p>Now here we&#8217;re going to jump into the else portion.</p>



<p>We need a label and some code for that.</p>



<p>code for that so this is the else six begin i copy that oh man it&#8217;s starting to get kind of</p>



<p>hectic in my brain here the copy pasting is worse than actually writing the program</p>



<p>so uh if the comparison was not equal like if r12 was not equal then execution falls through</p>



<p>to line 216 and then we unconditionally jump to the l6 begin area which is like down here</p>



<p>like down here and then we&#8217;ll print something else.</p>



<p>We&#8217;ll, oh, we&#8217;ll, we&#8217;ll check again.</p>



<p>So we&#8217;re doing like, um, if else, if else.</p>



<p>Okay. So originally when I was talking about the, uh,</p>



<p>if else block, I didn&#8217;t do a,</p>



<p>I didn&#8217;t do like a very complex if else statement.</p>



<p>We&#8217;ll say a is greater than B something like that.</p>



<p>So I&#8217;ll just put a more code here just so you know that we can do if else,</p>



<p>if else blocks but just you know again keep in mind that every scope here that you&#8217;re going to</p>



<p>try to run based on some condition you just make it its own label and make sure that at the very</p>



<p>end of the scope you jump away so that you reach the very end of all this stuff because just as a</p>



<p>quick review if we are just writing in c or c plus plus only one of these blocks is going to execute</p>



<p>right like if a is equal to b then only that first block will execute the second and third blocks</p>



<p>will not execute it&#8217;ll jump after that all the way down to line 21 only if a does not equal b</p>



<p>do we even have the chance of checking to see if a is more than b if it&#8217;s false then we&#8217;ll have the</p>



<p>chance to check the else and if it&#8217;s true we will only execute the code in the line 12 block you</p>



<p>know imagine there are more statements there and when that block is done then we will jump to line</p>



<p>to b and a is not greater than b so just a quick uh you know c plus plus uh you know design pattern</p>



<p>review if else block review so we have like an else if here we&#8217;re going to say check if the input</p>



<p>was equal to six so we just do the same thing that we did before we compare r12 the user&#8217;s input with</p>



<p>six we jump if they were equal to the else if equals true block and if not execution falls</p>



<p>Less than 10 begin block. So this is going to be like really complicated</p>



<p>How many lines did I actually I think I got excited when I wrote this</p>



<p>Okay, else if equal six true</p>



<p>My challenge to you is to come up with labels that are like way easier than the labels that I came up with</p>



<p>All right, so we&#8217;re gonna do this I</p>



<p>Can almost guarantee that when I&#8217;m done copy pasting everything something is not going to compile because I forgot a label somewhere</p>



<p>Else if equals six true, okay</p>



<p>equals six true okay so what&#8217;s happening here again um uh so at this point you know the first</p>



<p>if uh expression was not true r12 was definitely not equal to five so we jumped down to else if</p>



<p>equal six begin which was here and so then we just make another comparison to see well okay it was</p>



<p>those two things weren&#8217;t equal it wasn&#8217;t equal to five so let&#8217;s check to see if it was equal to six</p>



<p>to yet another scope.</p>



<p>If it was false, we go down to line 237</p>



<p>and jump to yet another scope.</p>



<p>So here is what will get executed</p>



<p>if R12 was indeed equal to six,</p>



<p>and then we&#8217;re just basically gonna say it to the user</p>



<p>and then jump to the done label,</p>



<p>meaning like we&#8217;re totally done with our if else block.</p>



<p>Notice how the first if here,</p>



<p>when it was totally finished, it jumped to the done area.</p>



<p>this else if block is also jumping down to the if done area.</p>



<p>So eventually we&#8217;re going to need that label.</p>



<p>Okay.</p>



<p>So then next we&#8217;re going to check to see if the user&#8217;s input was equal to a 10.</p>



<p>So like kind of the same thing here.</p>



<p>We&#8217;re going to do another copy paste and we&#8217;re going to say, all right.</p>



<p>So if the user&#8217;s input was not equal to, let&#8217;s see,</p>



<p>if it was not equal to five, then we jump down here for our next comparison.</p>



<p>comparison we check to see if it&#8217;s equal to six if it was not equal to six then we jump down to</p>



<p>the less 10 begin line which is like all the way down here we do another comparison to see all right</p>



<p>well is it less than 10 you know if it was not equal to five or not equal to six then we check</p>



<p>is it less than 10 if it uh if it is then we uh jump to the else if equal less 10 true block which</p>



<p>I made this way too complicated. I realize that now, but it&#8217;s too late. I&#8217;m going for it, man.</p>



<p>Anyway, so if that statement is true, if R12 was indeed less than 10, then we jump to this block</p>



<p>and we basically just say that to the user and then we jump to the done. So finally, notice how</p>



<p>this part right here on line 259, it&#8217;s basically saying if R12 was not less than 10, then we&#8217;ll</p>



<p>then we&#8217;ll jump somewhere else notice how it&#8217;s just else right so this is like the very the very</p>



<p>bottom so i think the way that i wrote this uh code is uh we have two else ifs right we have like</p>



<p>an if five else if six else if less than 10 so maybe i could do something like this um if r12</p>



<p>r12 I think I said six just now right hopefully I actually did say six</p>



<p>otherwise if r12 is less than 10 then do some stuff otherwise if nothing else</p>



<p>matched then we&#8217;ll execute you know this block right here so again remember</p>



<p>every single scope has to have its own label so that you know where to jump and</p>



<p>it&#8217;s also a really really smart idea for every single scope to have you know</p>



<p>to have a little jump instruction that jumps past all of the if else if else if else stuff</p>



<p>so we&#8217;ll say like you know label you know done so that we can make sure that only one of these</p>



<p>blocks actually executes which is how you&#8217;re supposed to imagine c and c plus plus work</p>



<p>um and so it&#8217;s just complicated because there&#8217;s a lot of stuff to copy paste but you can just</p>



<p>still see you know only one of these blocks ever is supposed to execute so we give the first one</p>



<p>we jump into it if it&#8217;s true if it&#8217;s not true then we give the second one a chance</p>



<p>we jump into it if it&#8217;s true if not we jump to compare the third one if it&#8217;s true then we jump</p>



<p>to its scope if not we jump to the else and the else always executes if nothing else above</p>



<p>was true so that&#8217;s the basic idea here oh dear i&#8217;ve probably lost my place</p>



<p>looks like i just copy pasted less 10 true which was this right here so</p>



<p>so um less than true or less than 10 true okay so we told the user your stuff is less than 10</p>



<p>and then we jumped to the done area so that means we are probably working on the else area okay let</p>



<p>me grab that so now finally we&#8217;re going to have the else area which is going to you know finish</p>



<p>this all up that&#8217;s going to be after the if done so if nothing else matched then we will end up</p>



<p>nothing else matched then we will end up jumping to the else area and then we&#8217;ll basically</p>



<p>just tell the user none of the conditions seemed to have applied and then even at the</p>



<p>end of the else block even though you could probably get away with just letting execution</p>



<p>fall through just to save yourself one instruction you know you could comment that out assuming</p>



<p>you were sure that the very next instruction was the beginning of the done area but otherwise</p>



<p>I&#8217;m just going to play it safe and jump directly there then we have to make the actual done</p>



<p>So, just so you know, a label doesn&#8217;t have to have any instructions.</p>



<p>We could have something like this, if else test say goodbye.</p>



<p>We could have two labels right next to each other and one doesn&#8217;t actually have instructions.</p>



<p>That&#8217;s totally fine.</p>



<p>If you jumped to the done area, then execution would just fall through to the next valid</p>



<p>instruction which could go through another label.</p>



<p>So you know, we could have a say goodbye label and an if done label.</p>



<p>if done label, I&#8217;m just going to have the goodbye stuff happening inside of the done.</p>



<p>But for clarity&#8217;s sake, you might want to keep that label in there that I just deleted.</p>



<p>And all that we need to do at the very end when we&#8217;re done with everything is just say goodbye.</p>



<p>So I&#8217;m just printing a message.</p>



<p>So just to do a quick recap here, let&#8217;s see.</p>



<p>We come in with the user&#8217;s input as R12.</p>



<p>We ask, does R12 equal five?</p>



<p>If that&#8217;s true, we&#8217;ll say that it was equal to 5, and then we&#8217;ll go to the done area,</p>



<p>meaning we&#8217;ll skip past all the other blocks for the if-else block, or all the other scopes.</p>



<p>But if that did not equal 5, then we&#8217;ll fall through to that jump instruction,</p>



<p>which takes us to the next test, which is going to be our else-if equals 6.</p>



<p>So we are checking now to see if R12 is equal to 6.</p>



<p>If that&#8217;s true, we jump to this next block.</p>



<p>Why do we need to jump to a block that&#8217;s so close?</p>



<p>Well, if we don&#8217;t, then we&#8217;re going to end up definitely jumping to the next comparison</p>



<p>and you know, that wouldn&#8217;t work.</p>



<p>So we&#8217;re just kind of jumping over this unconditional jump statement and we&#8217;re saying, all right,</p>



<p>your input was definitely equal to six.</p>



<p>And then we&#8217;re jumping to the done area just past everything.</p>



<p>But if that wasn&#8217;t true, then we hit this unconditional jump that takes us to the next</p>



<p>comparison to see if the user&#8217;s input was less than 10.</p>



<p>You know, if that&#8217;s true, then we go to the true area to print another message and then</p>



<p>go to the done area.</p>



<p>If it was false, we fall through to the else jump, which will take us to here.</p>



<p>And notice how the else scope doesn&#8217;t actually make any comparisons because, you know, when</p>



<p>you have like an if else, sorry, when you have an if else if else if else if, you know,</p>



<p>any number of else if blocks, the else will always be executed if nothing above it actually</p>



<p>did execute.</p>



<p>execute so if you have an else block that means something will execute so we&#8217;re not doing any</p>



<p>comparisons we&#8217;re just saying you know when that scope is done we&#8217;re just going to jump to the done</p>



<p>area so all of these different scopes they&#8217;re jumping to the done area when they finish and</p>



<p>the done area is just this label right here where we say goodbye and that&#8217;s it let&#8217;s see did i copy</p>



<p>paste everything that i was supposed to i think so probably so let&#8217;s run the program and see if it</p>



<p>All right, it at least compiled.</p>



<p>So the basic if test, that was the first part of either this video or the previous video,</p>



<p>depending on whether I chose to split this up.</p>



<p>So let me comment out those calls real fast.</p>



<p>So I&#8217;m going to just comment out these calls real quick so we can only deal with the complicated</p>



<p>if else block.</p>



<p>So I&#8217;m going to enter like a three.</p>



<p>Whoops, let me do it again.</p>



<p>Three.</p>



<p>And so begin the if else test.</p>



<p>test your input was definitely less than 10 and then we end the if-else test so notice how only</p>



<p>one scope executed three was definitely less than 10 what other numbers did we have let me write</p>



<p>them down somewhere so I don&#8217;t forget oh they&#8217;re written down right here so we entered a three</p>



<p>which was definitely not a five and not a six so that&#8217;s why the less than 10 block executed maybe</p>



<p>only the first scope should execute so it says your input was equal to five notice how it didn&#8217;t</p>



<p>mention that it was a six or less than ten and then if we do a six it should just tell us that</p>



<p>we have a six it will not mention the five it will not mention the ten so we did we did five</p>



<p>already and then we did six and we did like a two which was less than ten we could also do a one</p>



<p>which was less than ten we can do anything that was less than ten and then the else would be if</p>



<p>And then the else would be if our input is probably like 11 or greater,</p>



<p>meaning it&#8217;s not less than 10 and it&#8217;s also not five or six.</p>



<p>Just we can see the else block.</p>



<p>So I&#8217;m going to do 11, which is the first number that should trigger the else block.</p>



<p>And it says no conditions were satisfied,</p>



<p>which was the message inside of our else block.</p>



<p>Let me just show you that again real fast.</p>



<p>This was the else block.</p>



<p>So message if else else or labeling on my port, I realize that.</p>



<p>But it basically says no conditions were satisfied.</p>



<p>The if else else.</p>



<p>I think that&#8217;s basically everything that I wanted to show you.</p>



<p>At this point, you should feel like you&#8217;re starting to become an expert at complicated</p>



<p>if else if else blocks, converting those from a higher level language into assembly.</p>



<p>assembly and I honestly recommend that you practice this like crazy while you&#8217;re trying</p>



<p>to get more used to it but you know hopefully you have everything you need at this point</p>



<p>keep in mind I&#8217;ve said this at the beginning I&#8217;ve actually I think I said this in a different video</p>



<p>when we use these branching instructions notice how I have jump equal to where&#8217;s that less than</p>



<p>yeah notice how I have a instruction jump less than the the family of conditional branching</p>



<p>conditional branching instructions that compares less than greater than less than or equal to</p>



<p>greater than or equal to the ones that I&#8217;m using here apply to signed integers and they won&#8217;t</p>



<p>necessarily work with unsigned integers and they won&#8217;t work with floats if you compare floats later</p>



<p>so just keep that in mind let me pull up my favorite book again real fast</p>



<p>where what the heck is that book oh dude where&#8217;s my document viewer document viewer can I get</p>



<p>document viewer can I get there there we go so I guess I didn&#8217;t introduce this</p>



<p>book at the beginning of this video but I probably should have this is my</p>



<p>favorite assembly book you can turn yourself into an expert with this book</p>



<p>by just on its own it&#8217;s open source and free the author gives this away he&#8217;s a</p>



<p>genius the person who wrote this book is a dr. Ed Jorgensen he&#8217;s a professor he</p>



<p>wrote this for his own classes and again it&#8217;s like a free open source book you</p>



<p>download a copy from his website if you look this up and and convert yourself</p>



<p>into an expert so let me collapse everything here and then I&#8217;ll go to</p>



<p>instruction set overview control instructions conditional control</p>



<p>instructions and I just want you to see real fast just as a recap I talked about</p>



<p>this in a previous video but when it comes to comparing things and checking</p>



<p>operands because if you want to see if two operands are equal you just check to see if</p>



<p>all of their bits are equal you don&#8217;t even really care whether they&#8217;re both integers or not</p>



<p>on the other hand notice how there is like a family here jump less than jump less than equal</p>



<p>to jump greater than jump greater than equal to that those instructions apply only if your</p>



<p>if they are unsigned or if you&#8217;re using floats for your comparisons you have to use this other family</p>



<p>of jump conditional branching instructions called jump below jump below equal jump above jump above</p>



<p>equal and i&#8217;m sure you can infer that jump below is the same thing as jump less than right jump</p>



<p>less than or equal to is the same thing as jump below or equal to it&#8217;s just that you need to use</p>



<p>a different instruction uh if you&#8217;re using signed integers or floats versus sorry sorry</p>



<p>a versus sorry sorry you need to use different instructions if you&#8217;re using signed integers</p>



<p>versus unsigned integers or floats so keep that in mind the code demo that i just showed you it&#8217;s</p>



<p>for signed integers if you were going to use unsigned integers or floats you would this</p>



<p>program wouldn&#8217;t work for you you&#8217;d need to replace my my branching instructions with the</p>



<p>the unsigned versions which i mean they work the same thing you&#8217;re still going to do a comparison</p>



<p>it still works. Anyway, so after having shown you that and making sure that everything actually</p>



<p>did work, I think we&#8217;ve talked about everything that we need to for this video. So yeah, I hope</p>



<p>you feel like an expert practice this on your own, you know, write your own programs just to make</p>



<p>sure you know how to convert a higher level language block into an assembly block. And you</p>



<p>should be on your way. Thank you for watching this video. I hope you learned a little bit of</p>



<p>bit of stuff and had a little bit of fun tell your friends and i&#8217;ll see you in the next video</p>



<p>hey everybody thanks for watching this video again from the bottom of my heart i really</p>



<p>appreciate it i do hope you did learn something and have some fun uh if you could do me a please</p>



<p>a small little favor could you please subscribe and follow this channel or these videos or whatever</p>



<p>it is you do on the current social media website that you&#8217;re looking at right now</p>



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



<p>So we&#8217;ll be able to do more videos, 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.</p>



<p>You know, sometimes 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 wake me up in the middle of the night just subscribe and then I&#8217;ll just wake up I promise</p>



<p>that&#8217;s what will happen also uh if you look at the middle of the screen right now you should see a</p>



<p>QR code which you can scan in order to go to the website which I think is also named somewhere at</p>



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



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



<p>for clarifications or errata or just future videos that you want to see please leave a comment or if</p>



<p>you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I</p>



<p>also wake up for those in the middle of the night I get I wake up in a cold sweat and I&#8217;m like</p>



<p>it would really it really mean the world to me I would really appreciate it so again thank you so</p>



<p>much for watching this video and enjoy the cool music as as I fade into the darkness which is</p>



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



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/complex-if-elseif-else-in-x86-64-yasm-assembly-full-guide-with-code-examples/">Complex If-ElseIf-Else in x86-64 YASM Assembly &#8211; Full Guide with Code Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/complex-if-elseif-else-in-x86-64-yasm-assembly-full-guide-with-code-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Tue, 23 Dec 2025 13:22:17 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[dereferencing assembly]]></category>
		<category><![CDATA[gdb debugging assembly]]></category>
		<category><![CDATA[general purpose registers]]></category>
		<category><![CDATA[integer data movement]]></category>
		<category><![CDATA[lea instruction]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[mov instruction assembly]]></category>
		<category><![CDATA[pointer arithmetic assembly]]></category>
		<category><![CDATA[pointers in assembly]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[ubuntu assembly programming]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=269</guid>

					<description><![CDATA[<p>This practical x86-64 assembly language tutorial explains integer data movement between registers and memory, the importance of data size specifiers (byte, word, dword, qword), the difference between pointers and dereferenced values, pointer arithmetic for array access, and using LEA for address calculation - all demonstrated with YASM on Ubuntu Linux and inspected via GDB.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/">x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)</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 loading="lazy" title="x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)" width="1380" height="776" src="https://www.youtube.com/embed/zGrnEPrpmeg?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 hands-on x86-64 assembly tutorial, we dive deep into moving integer data between registers and memory, working with pointers, dereferencing, and pointer arithmetic using YASM on Ubuntu.</p>



<p>You&#8217;ll see practical examples of:</p>



<ul class="wp-block-list">
<li>Moving immediates and data between general-purpose registers</li>



<li>Loading different sized integers (byte, word, dword, qword) from memory</li>



<li>Why data size specifiers matter and what happens with overflow/underflow</li>



<li>The difference between moving a pointer vs dereferencing it</li>



<li>Pointer arithmetic to access array elements</li>



<li>Using LEA for address calculation without dereferencing</li>



<li>Debugging with GDB to inspect registers step-by-step</li>
</ul>



<p>Perfect for anyone learning low-level programming, systems programming, or wanting to truly understand how pointers work at the assembly level. No prior expert knowledge required &#8211; we build it up with clear examples.</p>



<p>Code and examples are shown live, compiled with YASM, linked with LD, and debugged with GDB.</p>



<p>If you&#8217;re into assembly, reverse engineering, operating systems, or just love understanding how computers really work, this one is for you.</p>



<p>Introduction to Integer Data Movement and Pointers 00:00:00<br>Program Setup and Makefile 00:01:16<br>Data Section Definitions 00:01:38<br>System Calls for Output and Exit 00:01:52<br>Text Section and Entry Point 00:04:21<br>Printing Hello String 00:05:05<br>Moving Immediates to Registers 00:06:04<br>Copying Between Registers 00:06:27<br>Dereferencing Pointers from Memory 00:07:16<br>Specifying Data Sizes 00:08:01<br>Register Size Variants 00:09:45<br>Reference Book Explanation 00:10:50<br>Loading Words and Bytes 00:13:25<br>Debugger Breakpoint and Registers 00:14:28<br>Overflow Demonstration 00:16:25<br>Makefile Adjustments for Warnings 00:17:44<br>Proving Data Size Importance 00:20:32<br>Underflow and Overflow Examples 00:21:34<br>Symbols as Pointers 00:24:16<br>Array Definitions and Access 00:25:20<br>Pointer to Array Items 00:26:08<br>LEA Instruction for Addresses 00:27:32<br>Dereferencing Manipulated Pointers 00:29:01<br>Final Register Inspection 00:29:50<br>Conclusion and Subscribe Request 00:33:26</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>Hey everybody! In this video I&#8217;m going to talk to you about integer data movement and pointers</p>



<p>in an x86-64 YASM assembly program within Ubuntu but this should work for all of you x86 YASM people.</p>



<p>Okay so what am I talking about for starters? I&#8217;m just talking about moving data pretty much. If you</p>



<p>from one integer register to another or from one general purpose register to another.</p>



<p>And if you know how to manipulate pointers in assembly and all that stuff,</p>



<p>you probably don&#8217;t need this video.</p>



<p>But if you are not an expert, then this will probably help you.</p>



<p>Let me start off by saying, of course, that there are going to be lots of concepts in this video</p>



<p>that I don&#8217;t actually explain because I&#8217;ve explained them in other videos.</p>



<p>For example, this is not a Hello World tutorial where I show you how to actually,</p>



<p>you know, build a basic Yasm assembly program.</p>



<p>a basic yasm assembly program you can probably infer that just from this video but i&#8217;m not going</p>



<p>to explain it also this is not a debugging video so i&#8217;m not really going to explain too much about</p>



<p>gdb which is something i&#8217;m going to use to look at the registers but it might be nice for you to</p>



<p>get a little preview i will record a full gdb tutorial in another video anyway so let&#8217;s see</p>



<p>here uh for starters i&#8217;ve just kind of like created a little sample program here um well</p>



<p>a make file which will just compile and execute my program again this is not a</p>



<p>make file video tutorial check my other videos for that I&#8217;ve already made one</p>



<p>for now I&#8217;m just gonna start making a program and I&#8217;m gonna give it a data</p>



<p>section so first thing I&#8217;m gonna give it is like well let&#8217;s say I&#8217;ll give it a</p>



<p>bunch of data then I&#8217;ll kind of explain what I gave it again this is not a</p>



<p>basics Yasum tutorial so see my other videos but you know just simply put I&#8217;m</p>



<p>You know just simply put I&#8217;m gonna write to standard output so I do I remember the system call code for for writing</p>



<p>And then I&#8217;m gonna exit because this is a pure assembly program that I&#8217;m compiling. There&#8217;s this is not a hybrid program</p>



<p>We&#8217;re not doing GCC. We&#8217;re just doing LD</p>



<p>So I&#8217;m just gonna say a call code 60 to exit a file descriptor for stdin actually I don&#8217;t really need that</p>



<p>Let me just double check that I don&#8217;t need that in my solution</p>



<p>Yeah, I like to reuse these things so we don&#8217;t really need standard input</p>



<p>standard input. We&#8217;re just going to do standard output, you know, printing to the terminal.</p>



<p>We&#8217;re going to exit with a success code of zero. And then I made a couple of, well, just one C</p>



<p>string where I&#8217;m just basically saying, hello, my name is so-and-so. So you can know that the</p>



<p>program actually started in case it crashes later. That&#8217;s not my name. I just love those kinds of</p>



<p>names. And then I&#8217;m just going to make a bunch of integers of different data sizes. So this is kind</p>



<p>sizes but just real fast because these are going to be directly used in our video we uh we have a</p>



<p>quad word here so i&#8217;m defining an integer called my long int and i&#8217;m saying that it&#8217;s a quad word</p>



<p>with dq q for quad word and then i&#8217;m just giving a pretty big integer same thing for a regular d</p>



<p>word which is just a double word so that&#8217;s half of a quad word and then another thing with a whoops</p>



<p>w not a q let me just fix that in my solution oh dear then i&#8217;m going to do a word which is a six two</p>



<p>one one one a word is two bytes of data we&#8217;re starting to get dangerously into overflow territory</p>



<p>when i was originally writing this solution i had like a bunch of nines up here and the number that</p>



<p>i ended up seeing on the screen was totally different and i forgot oh a word is just two bytes</p>



<p>so even if it&#8217;s unsigned the highest thing that it can actually represent is um</p>



<ol start="65535" class="wp-block-list">
<li>So that&#8217;s not good. Then I&#8217;m going to just store a byte here with DB and put some twos there.</li>
</ol>



<p>And then I&#8217;m going to make an array of integers. Putting an array, making an array in the regular</p>



<p>data section, that&#8217;s not as good as putting it in the BSS section if you want a lot of integers.</p>



<p>But I&#8217;m just going to specify a small number of integers so I can just put it directly into the</p>



<p>BSS is for like giant arrays of uninitialized data and the data section is for whatever you can handle typing pretty much of initialized data.</p>



<p>So now I&#8217;m going to start my text section and my program&#8217;s entry point.</p>



<p>Again, this is not a Yasm basics tutorial. See my other videos.</p>



<p>And so we&#8217;re going to start by just saying here&#8217;s my entry point where the operating system can sort of jump into my program.</p>



<p>to just you know exit the program let&#8217;s actually see if that works so far it</p>



<p>should do nothing but but at least exit with success I&#8217;m gonna go clear and make</p>



<p>run and notice how it just kind of like ran it and then nothing happened okay so</p>



<p>that&#8217;s great how come it didn&#8217;t print though what did I do wrong oh I forgot</p>



<p>to copy paste the code that prints something okay let me get my solution up</p>



<p>here so the first thing we&#8217;re really going to do is just use a system call to</p>



<p>call to print the word hello again this is not a system call video see my other videos</p>



<p>and um so now we&#8217;re just we&#8217;re just going to print our hello string</p>



<p>with a system call let me run it one more time we should see like a quick hello</p>



<p>yeah okay my name is uh chaplain mondover it&#8217;s not maybe i should change that to it&#8217;s not my name is</p>



<p>not no i don&#8217;t want to do that sometimes i like to pretend that my name is chaplain mondover</p>



<p>name is check lane Mondover you should too it&#8217;s fun anyway so the first thing that I&#8217;m going to</p>



<p>do here is I&#8217;m going to move an immediate well let me copy paste a whole chunk of code and then</p>



<p>I&#8217;ll explain it one by one I&#8217;m basically going to use data movement instructions to move a bunch of</p>



<p>data into a bunch of registers and then I&#8217;m going to hit a break point or I&#8217;m going to I&#8217;m going to</p>



<p>sort of do like a non-operation piece of code so that I can easily break on it in my debugger so</p>



<p>the results. Okay so first off I&#8217;m going to move an immediate into R12. The</p>



<p>instruction for moving data into general purpose registers or the integer</p>



<p>registers is just MOV so that&#8217;s fine probably you should know that by now but</p>



<p>I&#8217;m going to move an immediate into R10 and I&#8217;m going to move 12876 into R10.</p>



<p>So that&#8217;s how you move an immediate no problem. Then I&#8217;m going to first clear</p>



<p>out R11 and then I&#8217;m going to move R10 into it. The reason I&#8217;m clearing out R11</p>



<p>reason i&#8217;m clearing out r11 first is just to prove to you that we are actually moving data from one</p>



<p>register into another because if i just i don&#8217;t know if i didn&#8217;t do that you might be tempted to</p>



<p>to think well um maybe r11 already had that data in it so first it&#8217;s going to be just a zero and</p>



<p>then it&#8217;s going to actually be whatever r10 had so we should see r10 and 11 both have one two eight</p>



<p>register or a pointer register from one to another. And by the way, integers, those are</p>



<p>pointers, or rather, should I say, pointers are integers. So if you&#8217;re moving an integer or you&#8217;re</p>



<p>moving a pointer, the system just kind of sees that as a number either way. So you can use the</p>



<p>move instruction for it. So now let&#8217;s use the pointer that was assigned to our long integer</p>



<p>to move that number into R12. So let me just go up real fast. My long int up here,</p>



<p>my long int up here it&#8217;s like a gigantic number and remember I said before that my long int is</p>



<p>actually just a pointer to the memory location that begins to hold the quad word so my long</p>



<p>int is really a pointer to one byte and there&#8217;s an eight byte allocation because it&#8217;s a quad word</p>



<p>so when you sort of put this into your code and you let the system know that you want to move a</p>



<p>then the system will scan eight bytes and interpret that as an integer so</p>



<p>putting the the keyword quad word here I don&#8217;t think that&#8217;s necessary I usually</p>



<p>do it anyway but you&#8217;ll see in the next few instructions that it&#8217;s a really</p>



<p>really good idea to specify the data size because if you don&#8217;t you&#8217;re gonna</p>



<p>actually get something wrong in other words if for some reason I moved I don&#8217;t</p>



<p>into R12 I could do it if I if I wrote it correctly but then I would be taking</p>



<p>part of a quad word and trying to interpret that as the entire number and</p>



<p>it&#8217;s probably going to be totally wrong we&#8217;ll have an example for that in a</p>



<p>moment but anyway so that&#8217;s how we move a quad word we just specify keyword right</p>



<p>before the memory location and we use the brackets to dereference if we</p>



<p>didn&#8217;t dereference then we would actually be moving a pointer to the long</p>



<p>integer into R12 we&#8217;ll do that soon too I&#8217;m going to try to do everything in this</p>



<p>to do everything in this video then we&#8217;ll move a d word from uh from memory into r13 this is a</p>



<p>little bit different notice how uh here on line 60 i kind of have to specify d word because that&#8217;s</p>



<p>the data size that i&#8217;m trying to move into the r13 register so this is telling the system that</p>



<p>there&#8217;s about four bytes that i need to scan not eight bytes and interpret those four bytes as an</p>



<p>Moving it into R13, you know, I could have sworn a long time ago, you could just move that sort of thing directly into R13.</p>



<p>But when I tried my solution before recording this video, I kept getting assembler errors until I added the D at the end.</p>



<p>And so I just want you to know, oh, you know what, let&#8217;s look at a book real fast.</p>



<p>Let&#8217;s look at my favorite book.</p>



<p>I just want you to know that there are other forms of every register that can specify the register&#8217;s data size.</p>



<p>What do I mean by that?</p>



<p>itself then the system thinks you&#8217;re talking about all 64 bits of the 13 register the r13 register</p>



<p>but if you type whoops if you type r13d then the system thinks you&#8217;re only talking about the lowest</p>



<p>32 bits of that register so you&#8217;re also able to specify the data size of a register again i thought</p>



<p>you should should a long time ago i thought i remembered moving a d word directly into r13 and</p>



<p>it would just clear out the extra bits but i got warnings this time maybe that&#8217;s for the best</p>



<p>that&#8217;s for the best forcing us to be more precise, but this will solve it. R13 just says,</p>



<p>let&#8217;s only talk about a D word. So let me go, let me go to my favorite book here.</p>



<p>Where the heck is my favorite book? Okay. I guess I have to like, there we go.</p>



<p>Okay. There&#8217;s my favorite book. So, um, I&#8217;m going to go to, uh, let&#8217;s, let me just search for,</p>



<p>just search for I can&#8217;t remember where it is our 13 D yeah there it is okay so</p>



<p>what we&#8217;re looking for is 2.3.1.1 let me show you real fast the top of the book</p>



<p>just to give a shout out to the person who wrote this book I did not write this</p>



<p>book this is a free and open source book that you can download for free</p>



<p>everybody should get a copy to turn yourselves into an expert it&#8217;s called</p>



<p>x86 64 assembly language programming with Ubuntu it&#8217;s written by a brilliant</p>



<p>professor. This is like a semi recent version. There&#8217;s probably a newer one now, but yeah,</p>



<p>it&#8217;s a great book. I love it. So I&#8217;m going to go back to what the heck was I just doing?</p>



<p>Was it 2.3.1.1? Yeah. Okay. So in this book section 2.3.1.1, the section entitled general</p>



<p>purpose registers, notice how there are a bunch of different versions of each register. So if you</p>



<p>So if you look in this column right here, we have, oh, I get to use my annotator.</p>



<p>We have a, what were we just looking at?</p>



<p>R12.</p>



<p>Notice how R12 here is a designated as a 64 bit register.</p>



<p>But if you wanted to use the R12 register and only use 32 bits of it, the lowest 32</p>



<p>bits, then this is the form you would use for the R12 register.</p>



<p>So 32 bits.</p>



<p>And if you wanted to use only a word&#8217;s worth, you know, 16 bits.</p>



<p>Well there you go.</p>



<p>two bytes on these systems or 16 bits and then if you just wanted to use one</p>



<p>byte of the register well you can you just put a B at the end of it it&#8217;s</p>



<p>pretty sweet and convenient it&#8217;s not too hard to remember that D is for D word and</p>



<p>W is for word and B is for bytes it just gets a little confusing when you&#8217;re</p>



<p>using the other registers like the the RAX register it&#8217;s got EAX as its 32-bit</p>



<p>version and then AX as its 16-bit version and AL as its 8-bit version if</p>



<p>it&#8217;s a 8-bit version if you can remember that there&#8217;s an L I guess that&#8217;s not too bad but you</p>



<p>know remembering the X and then it changes to an I over here and a P over here I&#8217;m personally not</p>



<p>a fan so I always come back to this book to try and remember what I&#8217;m supposed to be putting for</p>



<p>these registers because I can&#8217;t remember all the time or rather I can almost never remember but we</p>



<p>So, I want to take a D word from memory and load it up into the R13 register.</p>



<p>So I got to specify the R13D.</p>



<p>And, you know, maybe I&#8217;ll take that out and show you that it doesn&#8217;t compile later, if I can remember.</p>



<p>But I&#8217;m going to now take a D word, do the same thing into R13.</p>



<p>Oh, sorry, no.</p>



<p>I&#8217;m going to take a regular word and do the same thing basically into R14.</p>



<p>But it&#8217;s just going to be a word instead of a D word.</p>



<p>And then I&#8217;m going to take a single byte and load it up into R15.</p>



<p>single byte and load it up into R15. Then I&#8217;m going to call Nope, which is an instruction that</p>



<p>just does nothing. And it&#8217;s useful sometimes if you want to have a place where you can stop your</p>



<p>program and sort of inspect the results of your program in your debugger. So there&#8217;s a lot more</p>



<p>to this program. I&#8217;m going to go ahead and just run it right now, just to make sure that it compiles.</p>



<p>And then maybe I&#8217;ll add a breakpoint here. Let&#8217;s go clear and make run. Okay, so it ran,</p>



<p>Okay, so it ran, it compiled, it was fine.</p>



<p>And now I&#8217;m going to open up a new little window and I&#8217;m going to launch the program.</p>



<p>Notice how the program that has been compiled is called main.</p>



<p>So I&#8217;m going to launch the program into the GDB debugger.</p>



<p>This is not a GDB video.</p>



<p>So I&#8217;m going to be skimming over this, check future videos for a full GDB tutorial.</p>



<p>So I&#8217;m going to do a break point right there at line 72.</p>



<p>So that I can just kind of inspect the state of the register.</p>



<p>break at main.asm line 72 and then just to be sure I did that correctly I&#8217;m going to say info</p>



<p>breakpoints or just a b is fine and it&#8217;s like looks like I set it up correctly then I can type</p>



<p>run to see what&#8217;s up notice how it starts to run and immediately stops at that breakpoint</p>



<p>you can tell it stops there because it&#8217;s at line 72 then I&#8217;m just going to do info registers or</p>



<p>info r just to print out all my registers and we should see a confirmation of what we were hoping</p>



<p>so if I kind of like maybe I&#8217;ll pin this to the top for a second always on top how about that</p>



<p>so first we moved an immediate into r10 so notice how 12876 is in r10 right there and then on line</p>



<p>53 we basically copied r10 into r11 so that means in r11 we see the same value</p>



<p>and then we&#8217;ll move a quad word from the long integer we&#8217;ll dereference that pointer</p>



<p>at R12 it&#8217;s like this gigantic number if I scroll all the way up it&#8217;s the same number here as in our</p>



<p>source code so that seemed to work and then we&#8217;re going to move the D word next I guess into R13</p>



<p>so that&#8217;s this number right here so that seemed to have worked it&#8217;s this number right here the</p>



<p>D word and I&#8217;m going to get lost so fast scrolling up and down like this now we&#8217;re going to move a</p>



<p>one one and there it is right there and then r15 is just gonna take a bite and</p>



<p>it&#8217;s gonna take a bite oh now I&#8217;m hungry now I&#8217;m hungry that activated it it&#8217;s</p>



<p>only been like think four or five hours since I ate I guess that is usually when</p>



<p>I need to eat again even though I gorge and fall asleep on the floor because I</p>



<p>home r15 anyway holds the correct value it&#8217;s 222 i just want to show you overflow real fast</p>



<p>we look at r14 uh we&#8217;re using the word version so it&#8217;s only going to read you know uh two bytes</p>



<p>from that memory location and it&#8217;s only going to consider uh you know 16 bits as being valid in uh</p>



<p>in that register so if i use a number that&#8217;s too big it&#8217;ll overflow two bytes the maximum number</p>



<p>three, five or from zero to that number or six, five, five, three, six combinations.</p>



<p>So if I just stick a nine in front of that right now, that should overflow the system.</p>



<p>So let me try it one more time.</p>



<p>I want to do Q because that was the last thing we needed to look at.</p>



<p>And then I&#8217;m going to do make.</p>



<p>Oh gosh, what&#8217;s happening here?</p>



<p>Okay.</p>



<p>How about I do clear and make build, which is in my make file and GDB main.</p>



<p>So I don&#8217;t have to type all this stuff out again every single time.</p>



<p>have to type all this stuff out again every single time what did i just do oh nice okay you know what</p>



<p>i swear it didn&#8217;t used to do this before it&#8217;s giving me a nice warning saying that value does</p>



<p>not fit in a 16-bit field i guess if i turned warnings off which i don&#8217;t want to do then the</p>



<p>program would run and it would overflow eh do you want to turn it off let&#8217;s turn off warnings okay</p>



<p>much attention to it. Um, where the heck are the warnings? Where&#8217;s the assembler running? There it</p>



<p>is. Yasum flags. And that&#8217;s, so that&#8217;s my variable up there. There we go. Okay. So I&#8217;m just going to</p>



<p>make a copy of this line, comment out the original, and then I&#8217;m going to take out, uh, the command</p>



<p>that says, or the flag that says convert warnings into errors. Your compiler is your friend. It was</p>



<p>So I am now going to do a breakpoint at 72.</p>



<p>So break at main.asm972 and then run and then it breaks.</p>



<p>And then I go input registers.</p>



<p>Then if I look at, what was I just talking about?</p>



<p>R14, was that it?</p>



<p>Notice how 44607 for the word, that&#8217;s a totally different value, right?</p>



<p>So this is what happens when you overflow or underflow.</p>



<p>You got to be careful about your data sizes.</p>



<p>I&#8217;m just going to do this again one more time just to make sure.</p>



<p>one more time just to make sure that it&#8217;s fixed now that I moved it and I&#8217;m</p>



<p>gonna I&#8217;m gonna read that part about warnings because I love converting</p>



<p>warnings to errors as just a way to help myself write better code okay so let&#8217;s</p>



<p>do that and you know what I&#8217;m gonna do too I added another target here again</p>



<p>this is not a Yasm or sorry this is not this is kind of a Yasm video this is not</p>



<p>extra file called gdb.txt where I can stick gdb commands and so I don&#8217;t want</p>



<p>to continue to type my breakpoints over and over over again every single time so</p>



<p>I know for sure I&#8217;m not going to change the program anymore at least I&#8217;m not</p>



<p>going to shift the lines up and down before 72 so I&#8217;m going to do breakpoint</p>



<p>you can type like break or I think you can type either break or the full word</p>



<p>breakpoint but I just type B name of the source code file a.asm at line 72 and so</p>



<p>And so this file right here, again, this is not a GDB tutorial, but in my make file, I have it set up so that GDB will execute whatever commands I put into this text file.</p>



<p>So it just kind of saves me typing.</p>



<p>So let&#8217;s put a breakpoint there and then we&#8217;ll say info breakpoints and then we&#8217;ll just run the program in that way.</p>



<p>I can have a little bit more information.</p>



<p>So I&#8217;m going to do make build instead of make build and then running GDB.</p>



<p>I&#8217;m going to say make debug.</p>



<p>That&#8217;s another target in my make file.</p>



<p>make file so then you can see it added the breakpoint for me and then it</p>



<p>immediately broke on that and you know what yeah I guess I&#8217;ll just leave it in</p>



<p>where I have to type info registers okay so we&#8217;re just making sure I think that</p>



<p>R14 is still a valid value and that it was fixed okay so we&#8217;ve gotten this far</p>



<p>the next thing we need to do is prove that data size matters by specifying a</p>



<p>specifying a bad data size for our long and then for our byte. So I&#8217;m going to copy paste a little</p>



<p>proof here that is followed by another non-operation. So I&#8217;m going to do this. And so</p>



<p>I&#8217;m going to try to prove to you that the data size matters by specifying a bad data size. I</p>



<p>just proved to you that it kind of mattered or it definitely mattered in terms of overflow and</p>



<p>underflow, but I&#8217;m trying to prove to you now that it matters when you&#8217;re reading. So I&#8217;m going to</p>



<p>I&#8217;m going to clear out r12 and then I&#8217;m going to move a byte from the long integer into r12b</p>



<p>and you know this would be a warning or I think it this wouldn&#8217;t compile or wouldn&#8217;t assemble if</p>



<p>I didn&#8217;t have the b there so I&#8217;m basically telling the computer all right I want you to use only a</p>



<p>byte of r12 and I want you to take one byte from memory and just put it in there but I&#8217;m taking it</p>



<p>awful. And then right after that, I&#8217;m going to do another naughty thing. I&#8217;m going to move</p>



<p>something into R15 and I&#8217;m going to word, I&#8217;m going to move a keyword of memory into R15,</p>



<p>but I&#8217;m going to be taking it from the bytes memory. So remember a byte is just one byte.</p>



<p>And so the next seven bytes that come after it definitely have nothing to do with that byte,</p>



<p>but I&#8217;m going to interpret them all as a quad word. So we should get nonsense data</p>



<p>also R15. I don&#8217;t really need to zero out R15 because the fact that I&#8217;m specifying R15 means</p>



<p>I want to use all 64 bits. So it is going to definitely zero it out. And whatever we see in</p>



<p>R15 is going to be the real thing. But in terms of R12B, we&#8217;re only going to be loading up one</p>



<p>byte&#8217;s worth of that register. So that&#8217;s why I&#8217;m zeroing out the rest of it just to prove to you</p>



<p>that we are truly getting nonsense. So now there&#8217;s going to be another break point at 82.</p>



<p>I&#8217;m not going to break anymore at 72. I&#8217;m going to break at 82. So let&#8217;s do that.</p>



<p>What&#8217;s going on here? We got that.</p>



<p>Oh gosh. Okay. Quit. I guess that means I need to comment this out. Let me do that.</p>



<p>We&#8217;ll do break at main.asm at 82. And you could, you could do both of these two. Actually,</p>



<p>let me do it first. We could, we could do multiple break points. Yeah, I&#8217;ll just do it first,</p>



<p>So notice how it first breaks at the 72 and then I do C to continue and then suddenly</p>



<p>it breaks at the 82.</p>



<p>But I don&#8217;t want to have to hit continue a bunch of times so I&#8217;m going to comment that</p>



<p>out for the future.</p>



<p>Let me quit real fast to make sure I remember what GDB expects as a comment.</p>



<p>Yeah, okay.</p>



<p>82.</p>



<p>Okay, so then I&#8217;m going to print the registers info registers.</p>



<p>And we&#8217;re looking at R12 and R15.</p>



<p>You can see R12 has the number 144, which definitely doesn&#8217;t make sense because there&#8217;s</p>



<p>no 144 anywhere in our original data.</p>



<p>in our original data so hopefully that&#8217;s proof to you that we&#8217;ve grabbed some junk</p>



<p>sometimes maybe when you&#8217;re doing this at home if you&#8217;re just going to grab one bite</p>



<p>maybe accidentally um no no that would definitely still look bad but for the r15</p>



<p>if you&#8217;re going to grab a q words worth of data i don&#8217;t know maybe the junk data is like</p>



<p>accidentally correct in a way where it would it would still make it look like the intended value</p>



<p>the intended value no it wouldn&#8217;t there&#8217;s no way that would even happen no i guess the junk data</p>



<p>could could work that way anyway so we&#8217;ll look at r15 two eight and a bunch of fours and then a two</p>



<p>three eight um that value does not exist up here so again junk data mixed in with real data is is</p>



<p>bad news okay so now let&#8217;s do another proof i want to prove to you that symbols are pointers</p>



<p>you know like I&#8217;ve been saying and they need to be dereferenced so let&#8217;s first start off by</p>



<p>moving the raw pointer for my long int into r10 and then into r11 we will dereference that</p>



<p>pointer so in r10 we should see something that looks like a memory location or at least a relative</p>



<p>memory location and then in r11 we should see the actual long integer like we saw before</p>



<p>And then I&#8217;m going to mess around with some arrays.</p>



<p>So remember up here we made an array.</p>



<p>Let me minimize that real fast.</p>



<p>We made an array, a very small array.</p>



<p>I just specified a bunch of ones and then specified a bunch of twos.</p>



<p>So it should be contiguous memory since it&#8217;s been allocated as an array with that comma</p>



<p>there.</p>



<p>We should see if we looked inside of the system inside of memory, we should see eight bytes</p>



<p>representing the ones.</p>



<p>And then right next to that, we should see eight bytes representing the twos.</p>



<p>easy for us to sort of move our pointer around a little bit. So what else do I need to copy paste</p>



<p>here? We got that long int. Okay. So I&#8217;m going to grab the first item and the second item in those</p>



<p>arrays just using some pointer manipulation. So you know how to do this already. You just take</p>



<p>like the pointer to some number and you just dereference it and you end up getting a number.</p>



<p>I understand your feeling because you might be thinking, wait a minute, wait a minute.</p>



<p>I understood it when it was dereferencing just one number, but didn&#8217;t you say this is an array?</p>



<p>Why is it we can dereference the array and just get one number still?</p>



<p>Well, remember, a pointer to an array is really a pointer to the first item in the array.</p>



<p>That&#8217;s kind of how it works.</p>



<p>So either way, whether you consider that to be a pointer to one number or a pointer to array,</p>



<p>when we dereference it, we&#8217;ll get one number.</p>



<p>If you want to get the other numbers, then you have to start manipulating the pointer</p>



<p>or derefing in different ways.</p>



<p>So here&#8217;s how we can get the second item.</p>



<p>We deref the original pointer plus 8.</p>



<p>8 because it&#8217;s a quad word.</p>



<p>So, you know, it probably would be a little smarter to put that 8 up into a define somewhere</p>



<p>so you&#8217;re not hard coding numbers, but I&#8217;m not going to do it.</p>



<p>So basically in R12, we should see the 1s.</p>



<p>In R13, we should see the 2s.</p>



<p>And then a couple more things.</p>



<p>Next, we will grab a pointer to the first item in the small array.</p>



<p>And we&#8217;ll just stick that into R14.</p>



<p>So, you know, we kind of did that with R10 already.</p>



<p>But now I just want a pointer to the small array.</p>



<p>And I&#8217;m going to keep it in R14 just so you can see the memory location.</p>



<p>And then after that, we&#8217;re going to grab an actual pointer to the second item.</p>



<p>hey how do you get a pointer to the second item well it&#8217;s that but then what</p>



<p>if you didn&#8217;t want to dereference the pointer like what if R13 you know here</p>



<p>clearly because we have these brackets for dereferencing you&#8217;re allowed to put</p>



<p>the formulas inside of the brackets what if I wanted to get the address to the</p>



<p>second item and not actually the second item we would not be allowed to remove</p>



<p>the brackets the assembler wouldn&#8217;t like that so without another instruction</p>



<p>way to actually get a pointer with a complicated mathematical formula. You know, you can do like</p>



<p>multiplication inside of here and other things in parentheses. So we wouldn&#8217;t be able to do that</p>



<p>without the other instruction that I&#8217;m introducing now called LEA. LEA just means, yeah, sure, we&#8217;re</p>



<p>still going to use the brackets to figure out where the pointer is, like figure out what memory</p>



<p>location we want with some sort of a formula. But then what will be stored in the first operand is</p>



<p>This LEA won&#8217;t dereference just because there are brackets.</p>



<p>LEA will keep the pointer.</p>



<p>And then finally, once we actually have a pointer to the second item in R15,</p>



<p>then we can move the second item into another register.</p>



<p>And this is like an LOL because I ran out of registers already.</p>



<p>So I&#8217;m just going to use RDI, which is usually the first argument.</p>



<p>It doesn&#8217;t matter. It&#8217;s fine.</p>



<p>So if we dereference R15, it&#8217;s the same thing as dereferencing this.</p>



<p>We could have also just dereferenced R14,</p>



<p>and it would have been the same thing as just getting the value of the first item.</p>



<p>But I hope you can see now that, you know,</p>



<p>that expression is going to be a pointer to the second item in the array,</p>



<p>and that&#8217;s going to be stuck into R15.</p>



<p>So if we dereference that, we can treat R15 like a pointer.</p>



<p>It&#8217;s just, you know, it&#8217;s a general purpose register.</p>



<p>it doesn&#8217;t only need to hold integer values it can also hold pointers because pointers are integers</p>



<p>they&#8217;re just unsigned so we deref the pointer that is stored inside of r15 now put it inside</p>



<p>of rdi and then we should see that rdi actually holds the second item which should be a bunch of</p>



<p>twos so the last thing that i&#8217;m going to copy paste in here is another nope so i&#8217;m going to</p>



<p>break at 108 just so we can see the rest of it so i&#8217;m going to open up this right here and i&#8217;m</p>



<p>open up this right here and I&#8217;m going to comment that out and I&#8217;m gonna say break at 108.</p>



<p>Whoops.</p>



<p>Okay.</p>



<p>There we go.</p>



<p>But, but, but quitsies.</p>



<p>Now I&#8217;m just going to run make debug again so that I can enter GDB.</p>



<p>And we&#8217;ve, we&#8217;ve, we&#8217;ve hit our break points.</p>



<p>And now I&#8217;m going to go info registers and just talk about the stuff that we&#8217;re seeing.</p>



<p>Okay.</p>



<p>So the first thing I think this is all on one page, right?</p>



<p>I don&#8217;t need to scroll.</p>



<p>Yeah.</p>



<p>one page right I don&#8217;t need to scroll yeah okay this is all on one page first thing we see is r10</p>



<p>holds this value right here that&#8217;s a pointer to the my long int that kind of looks like a pointer</p>



<p>if you consider that it could be relative and then r11 holds the actual integer and if you recall</p>



<p>that is the gigantic long that we put in there great so now that&#8217;s the difference between a</p>



<p>pointer and its value or in its dereference value so then we&#8217;re going to grab the first item in the</p>



<p>So then we&#8217;re going to grab the first item in the small array.</p>



<p>So R12 should have the ones.</p>



<p>If we look at R12 here, it&#8217;s got the ones.</p>



<p>Again, just trying to prove to you that if you dereference a pointer to an array,</p>



<p>you&#8217;re actually dereferencing a pointer to the first item.</p>



<p>And then on R13, we&#8217;re going to make a pointer to the second item.</p>



<p>Then with the brackets and the move instruction, we dereference that and it should become the twos.</p>



<p>So if we look at R13, notice how it&#8217;s the twos.</p>



<p>Then we&#8217;re going to grab a pointer to the first item in the small array.</p>



<p>Hang on a second.</p>



<p>What did I want to say about that?</p>



<p>In the small array to R14.</p>



<p>Okay.</p>



<p>So again, we&#8217;re just going to grab an actual pointer to the small array.</p>



<p>And so the difference between R12 and R14 is the dereft value or the pointer.</p>



<p>So if we look at R12, that&#8217;s the actual value that we&#8217;re pointing at.</p>



<p>And then R14 is the memory location that we have in there.</p>



<p>And then notice how it&#8217;s kind of similar.</p>



<p>Notice how it&#8217;s kind of similar.</p>



<p>Maybe this proves a little bit more that these are pointers that we&#8217;re looking at.</p>



<p>R10 was supposed to be a pointer and now R14 is also a pointer.</p>



<p>Notice how those numbers are pretty close together.</p>



<p>I&#8217;m sure if we looked back up in the data section and we calculated an offset based</p>



<p>on how big each data item was, we could probably predict what the memory location of R14 should</p>



<p>have been based on R10 because you can see it&#8217;s like only increased by a little bit,</p>



<p>by a little bit right it was like 534 to 49 what is that 10 plus 5 so that&#8217;s like 15 is that correct</p>



<p>oh I guess I had a byte in there so maybe it&#8217;s that&#8217;s why it&#8217;s kind of odd but yeah we can we</p>



<p>can just compute the offset and then we&#8217;ll grab a pointer to the second item using the LEA</p>



<p>instruction remember we have to use brackets if we&#8217;re going to do an expression but then the</p>



<p>dereferencing in the move instruction so we just use LEA to not dereference.</p>



<p>So we should see that R15 is about 8 bytes further along in RAM than R14 because both of those items</p>



<p>are contiguous in memory and they should only be about you know a quad word apart 8 bytes.</p>



<p>So if we look at R14 it&#8217;s got this number so it&#8217;s a pointer and then if we look at R15</p>



<p>you know what&#8217;s 49 plus 8 it&#8217;s 57 so you can see that the pointer to the second item is only</p>



<p>pointer to the second item is only eight bytes further in memory yay contiguousness and then</p>



<p>sorry i can&#8217;t resist so then finally we will uh we&#8217;ll look at the dereference to r15 because it&#8217;s</p>



<p>now a pointer what was it it was the it was a pointer to the second item that should be a bunch</p>



<p>of twos right because remember in our array we had a bunch of twos here as our second item</p>



<p>have a bunch of twos inside of it so if i look at rdi where the heck is that right there has a</p>



<p>bunch of twos inside of it rdi baby oh my gosh why did i say that anyway so that&#8217;s our non-operation</p>



<p>instruction and i think that&#8217;s everything that i wanted to talk to you about in this video so now</p>



<p>i hope you feel like you&#8217;re an expert in moving integers and moving pointers and</p>



<p>dereferencing pointers and manipulating pointers so you can get a pointer to something else and</p>



<p>pointer to something else and de-referencing those pointers or not whenever you choose.</p>



<p>Thank you so much for watching this video. I hope you learned a little bit of stuff</p>



<p>and you had a little bit of fun. I&#8217;ll see you in the next video. Limit out. I&#8217;ll never say that</p>



<p>again. Hey everybody, thanks for watching this video again from the bottom of my heart. I really</p>



<p>appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p>could do me a please a small little favor could you please subscribe and</p>



<p>follow this channel or these videos or whatever it is you do on the current</p>



<p>social media website that you&#8217;re looking at right now it would really mean the</p>



<p>world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll</p>



<p>be able to do more videos longer videos better videos or just I&#8217;ll be able to</p>



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



<p>you know sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p>night and I just wake up because I know somebody subscribed or followed it just</p>



<p>wakes me up and I get filled with joy that&#8217;s exactly what happens every single</p>



<p>time so you could do it as a nice favor to me or you could you control me if you</p>



<p>want to just wake me up in the middle of night just subscribe and then I&#8217;ll just</p>



<p>wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p>the screen right now you should see a QR code which you can scan in order to go</p>



<p>to the website which I think is also named somewhere at the bottom of this</p>



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



<p>my main website where you can just kind of like see all the videos I published and the services</p>



<p>and tutorials and things that I offer and all that good stuff and uh if you have a suggestion</p>



<p>for uh uh clarifications or errata or just future videos that you want to see please leave a comment</p>



<p>or if you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever</p>



<p>I also wake up for those in the middle of the night I get I wake up in a cold sweat and I&#8217;m like</p>



<p>It would really mean the world to me.</p>



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



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



<p>And enjoy the cool music 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-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/">x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)</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-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
