<?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>Yasm assembly Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/yasm-assembly/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/yasm-assembly/</link>
	<description></description>
	<lastBuildDate>Sun, 22 Feb 2026 03:21:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>Yasm assembly Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/yasm-assembly/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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 class="wp-block-paragraph">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 class="wp-block-paragraph">Great for assembly beginners moving to real programs, systems programming students, or anyone curious how low-level code talks to C/C++.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">Hey there! In this video we&#8217;re going to talk about pointers and dereferencing in a YASM x8664</p>



<p class="wp-block-paragraph">assembly program, also as a hybrid program so that assembly and C++ can talk to each other</p>



<p class="wp-block-paragraph">and send each other pointers and send each other data and things like that.</p>



<p class="wp-block-paragraph">for what pointers are.</p>



<p class="wp-block-paragraph">I&#8217;m going to write in C++ for a second.</p>



<p class="wp-block-paragraph">Suppose you have a pointer for an integer.</p>



<p class="wp-block-paragraph">We&#8217;ll call it P.</p>



<p class="wp-block-paragraph">Suppose you have an integer by itself.</p>



<p class="wp-block-paragraph">We&#8217;ll call it A.</p>



<p class="wp-block-paragraph">Let&#8217;s say that the value of A is 5.</p>



<p class="wp-block-paragraph">And if you wanted to say that P points to A,</p>



<p class="wp-block-paragraph">you could say P equals the address of A.</p>



<p class="wp-block-paragraph">I&#8217;ll put C++ at the top here.</p>



<p class="wp-block-paragraph">And so now if I set A to 6</p>



<p class="wp-block-paragraph">then I print P a dereference of P this is not like a full pointers tutorial</p>



<p class="wp-block-paragraph">but basically by changing a I&#8217;m changing what P thinks it sees as a value</p>



<p class="wp-block-paragraph">assuming ID reference it I could also let me do a print 6 here I could also</p>



<p class="wp-block-paragraph">just change the value through P I could say dereference P and I could say equals</p>



<p class="wp-block-paragraph">would actually print a seven right so you know you can have regular variables global variables</p>



<p class="wp-block-paragraph">whatever kind of you know memory stuff on the stack and to get a pointer to it you really just</p>



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



<p class="wp-block-paragraph">in assembly you really just need the memory location stored somewhere you could store that</p>



<p class="wp-block-paragraph">variable that just simply stored the memory location of some other variable.</p>



<p class="wp-block-paragraph">You could have a 64-bit register store the value of a variable.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">So if you haven&#8217;t seen my previous videos, go see them for the basics of assembly and</p>



<p class="wp-block-paragraph">of assembly and linking and make files and all that stuff but you know if you</p>



<p class="wp-block-paragraph">have an assembly program and you have a data section and you define a global</p>



<p class="wp-block-paragraph">variable like this what you&#8217;re basically saying is I want to take this giant</p>



<p class="wp-block-paragraph">number and I want to write it into eight bytes that&#8217;s the DQ it says data quad</p>



<p class="wp-block-paragraph">word I want to write that giant number across eight bytes and then I want to</p>



<p class="wp-block-paragraph">get a pointer to it stored in the my number symbol so my number is not</p>



<p class="wp-block-paragraph">actually the value it&#8217;s a pointer to the value so you know later if you want to</p>



<p class="wp-block-paragraph">you know later if you want to move you know something into a register if you did this</p>



<p class="wp-block-paragraph">that would move the pointer into rax but if you did this</p>



<p class="wp-block-paragraph">with deref symbols after it or around it then you would move</p>



<p class="wp-block-paragraph">maybe i&#8217;ll put that into rex you&#8217;d move that actual number that we specified into rex</p>



<p class="wp-block-paragraph">into Rx. It&#8217;s important to understand also that pointers are integers even when we&#8217;re pointing to</p>



<p class="wp-block-paragraph">doubles. So for example sometimes people make this mistake they&#8217;ll say you know my double</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">point number and they&#8217;ll do like 44.55 or whatever. So that is a double and it is in memory</p>



<p class="wp-block-paragraph">you know what is the symbol of my double remember it&#8217;s supposed to be just a</p>



<p class="wp-block-paragraph">pointer right it can&#8217;t be an actual double because a memory location is not</p>



<p class="wp-block-paragraph">a double a memory location is an integer so that means if you wanted to move a</p>



<p class="wp-block-paragraph">pointer into a register you would only be able to move the pointer into a</p>



<p class="wp-block-paragraph">regular general purpose register not a floating point register and you should</p>



<p class="wp-block-paragraph">use the regular movement instructions for just regular general purpose</p>



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



<p class="wp-block-paragraph">You know, let&#8217;s say long a and long B and actually let&#8217;s do pointers</p>



<p class="wp-block-paragraph">Let&#8217;s say long pointer a and long pointer</p>



<p class="wp-block-paragraph">B and double pointer C all three of those arguments are actually 64 bit integers</p>



<p class="wp-block-paragraph">Because they&#8217;re all pointers even if one of the pointers points to adult a double</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">what we really need to do is write a driver and an assembly module for a</p>



<p class="wp-block-paragraph">hybrid program again hybrid programs covered in other videos so the driver is</p>



<p class="wp-block-paragraph">pretty easy I&#8217;m just going to copy paste it honestly here and then just kind of</p>



<p class="wp-block-paragraph">explain it to you the driver is pretty easy we&#8217;re going to do I O stream so we</p>



<p class="wp-block-paragraph">can print stuff we&#8217;re going to mark an external function called point as extern</p>



<p class="wp-block-paragraph">C so that just disables name mangling which means the C++ module will be able</p>



<p class="wp-block-paragraph">will be able to call on this function called point and it won&#8217;t expect that</p>



<p class="wp-block-paragraph">the point function has its name mangled like C++ does the reason being is that</p>



<p class="wp-block-paragraph">point is actually going to be in a side it&#8217;s going to be inside assembly where</p>



<p class="wp-block-paragraph">its name will not be mangled this disables the ability to overload but</p>



<p class="wp-block-paragraph">that&#8217;s okay we don&#8217;t care it&#8217;s going to take two pointers a pointer to a character</p>



<p class="wp-block-paragraph">and a pointer to a long since both of those are pointers they&#8217;re both</p>



<p class="wp-block-paragraph">64-bit integers even the character pointer and then we have a function that is internal to this</p>



<p class="wp-block-paragraph">module called hey driver print this remember we&#8217;re inside of the driver program right now</p>



<p class="wp-block-paragraph">so if you look at the bottom it&#8217;s just a function that takes in some pointers</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">i literally just let him pee and poop at this point now he&#8217;s harassing me for treats</p>



<p class="wp-block-paragraph">now he&#8217;s harassing me for treats he always does this okay so uh the string the long the double</p>



<p class="wp-block-paragraph">this function expects to receive three pointers to different data types it&#8217;s just going to print</p>



<p class="wp-block-paragraph">all of them and the point get it the point of this function is we&#8217;re going to go inside of</p>



<p class="wp-block-paragraph">the assembly module and then have the assembly module call on this function so that we can we</p>



<p class="wp-block-paragraph">can prove that we can have stuff sent from assembly to c plus plus or c using pointers</p>



<p class="wp-block-paragraph">using pointers we can have data sent over so anyway that&#8217;s why both of these</p>



<p class="wp-block-paragraph">are in here the point needs to be marked as no name mangling because point is</p>



<p class="wp-block-paragraph">inside of assembly which will not name mangle and then hey driver print this</p>



<p class="wp-block-paragraph">that needs to have name mangling disabled also so that the assembly</p>



<p class="wp-block-paragraph">module can call on this other than that we&#8217;re just basically inside of a main</p>



<p class="wp-block-paragraph">saying hey this is the c string we&#8217;re making a c string inside of the main function notice how</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">the stack um and but then we can actually send pointers to those pieces of data to another</p>



<p class="wp-block-paragraph">function in another module you don&#8217;t have to only transport globals or stuff on the heap</p>



<p class="wp-block-paragraph">or stuff on the heap, you can transport pointers to local variables. Just make sure that by the</p>



<p class="wp-block-paragraph">time this function finishes, then nowhere else is actually using that data because,</p>



<p class="wp-block-paragraph">well, being on the stack, once main function or once any function finishes, then its portion of</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">just going to use them quickly on this call to point and then we&#8217;re going to return to the</p>



<p class="wp-block-paragraph">operating system and finish the program. So that&#8217;s the driver. Now the hard part. Let&#8217;s do this in</p>



<p class="wp-block-paragraph">assembly. So for starters, I&#8217;m going to make a data section and just explain it to you very,</p>



<p class="wp-block-paragraph">very quickly. Again, if you don&#8217;t understand the basics of YASM x86-64 assembly, did I mention</p>



<p class="wp-block-paragraph">that that&#8217;s what this language is at the beginning of the video? I guess I should put that in the</p>



<p class="wp-block-paragraph">put that in the description or record an announcement that I can tack on at the beginning</p>



<p class="wp-block-paragraph">or something. Anyway, so if you don&#8217;t understand how to do this, see my other videos, but basically</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">Oh, we&#8217;re inside of, you know, the module now, the assembly module. And now we&#8217;re going to print</p>



<p class="wp-block-paragraph">the received string. And then we&#8217;re going to make a string that is owned by assembly, which we can</p>



<p class="wp-block-paragraph">into C++ when we call the function inside of the driver.</p>



<p class="wp-block-paragraph">So this string is owned by the assembly module.</p>



<p class="wp-block-paragraph">Notice how these are null terminated strings.</p>



<p class="wp-block-paragraph">I just have like a comma zero there,</p>



<p class="wp-block-paragraph">which means I have some extra functions</p>



<p class="wp-block-paragraph">I&#8217;m gonna paste in that we&#8217;re not really gonna talk about</p>



<p class="wp-block-paragraph">because they&#8217;ve been discussed in other videos</p>



<p class="wp-block-paragraph">just so that we can print null terminated strings.</p>



<p class="wp-block-paragraph">Then I&#8217;ve got a new line here,</p>



<p class="wp-block-paragraph">you know, carriage return line feed.</p>



<p class="wp-block-paragraph">And then I&#8217;ve just got some numbers</p>



<p class="wp-block-paragraph">that are owned by the assembly module.</p>



<p class="wp-block-paragraph">Then I&#8217;ve got a system write call,</p>



<p class="wp-block-paragraph">call code one for the system call writes and file descriptor standard output so I</p>



<p class="wp-block-paragraph">can print just to the terminal again if you don&#8217;t understand this see my other</p>



<p class="wp-block-paragraph">videos so now let&#8217;s start the actual text section so this is where our</p>



<p class="wp-block-paragraph">instructions start so we got the text section here and we&#8217;re going to use some</p>



<p class="wp-block-paragraph">external symbols don&#8217;t worry about these I&#8217;m just using my own little library to</p>



<p class="wp-block-paragraph">and input integers if you have access to this library use it if you don&#8217;t if you&#8217;re watching</p>



<p class="wp-block-paragraph">at home and you don&#8217;t have this library then that&#8217;s fine you can use you know printf or</p>



<p class="wp-block-paragraph">scanf or something like that to get and print floats from and to the user</p>



<p class="wp-block-paragraph">but yeah I&#8217;m just using that and then I&#8217;m marking an external function here called hey driver print</p>



<p class="wp-block-paragraph">this if you recall the driver module has a function called hey driver print this so</p>



<p class="wp-block-paragraph">just allows my assembly code to call on that external function. Okay now next</p>



<p class="wp-block-paragraph">piece of code. This is going to be… actually I&#8217;m going to paste the print</p>



<p class="wp-block-paragraph">null terminated string function and related code because it&#8217;s just like a</p>



<p class="wp-block-paragraph">big giant mess and we&#8217;re mostly going to ignore it. So just to show you what I&#8217;m</p>



<p class="wp-block-paragraph">doing here I have a function called print null terminated string so that I</p>



<p class="wp-block-paragraph">can print these strings up here and then I have it rely on a function called</p>



<p class="wp-block-paragraph">string length that I have implemented up here and all it does is just</p>



<p class="wp-block-paragraph">implemented up here and all it does just calculates the length of the string and</p>



<p class="wp-block-paragraph">then a crlf function so I can just call that so that&#8217;s all explained in other</p>



<p class="wp-block-paragraph">videos don&#8217;t worry about it for now we&#8217;re going to start the actual entry</p>



<p class="wp-block-paragraph">point remember the driver was just gonna call point right so now we just have to</p>



<p class="wp-block-paragraph">implement point in the assembly module so that&#8217;s gonna be like down here our</p>



<p class="wp-block-paragraph">our entry point so the signature for this function is going to be character</p>



<p class="wp-block-paragraph">pointer and then a long pointer and it doesn&#8217;t return anything and remember</p>



<p class="wp-block-paragraph">that if we look back at the driver that should match the signature right it&#8217;s a</p>



<p class="wp-block-paragraph">character pointer and a long pointer and of course this is just a comment that</p>



<p class="wp-block-paragraph">reminds me of what to do in assembly you don&#8217;t really have a signature you just</p>



<p class="wp-block-paragraph">sort of use registers but I&#8217;m reminding myself that RDI is going to be a</p>



<p class="wp-block-paragraph">character pointer and RSI is going to be a long pointer.</p>



<p class="wp-block-paragraph">Here&#8217;s a note to myself that I&#8217;m going to use R12 and R13, which means</p>



<p class="wp-block-paragraph">the first thing that I should do, well actually before I even do that, I should</p>



<p class="wp-block-paragraph">return from this function because it is a function. I marked it as global</p>



<p class="wp-block-paragraph">so that the other module could call it, the driver module could call it. Again,</p>



<p class="wp-block-paragraph">see my other videos for hybrid programs.</p>



<p class="wp-block-paragraph">But so now the, you know, if the driver calls this function, then now we&#8217;re inside of</p>



<p class="wp-block-paragraph">and there&#8217;s a return statement so it&#8217;s a valid function I should preserve the</p>



<p class="wp-block-paragraph">registers that I&#8217;m going to use that are marked as Kali saved for the ABI so I&#8217;m</p>



<p class="wp-block-paragraph">going to go prologue and then an epilogue and I&#8217;m going to say push r12 and push</p>



<p class="wp-block-paragraph">r13 and then I&#8217;m going to pop r13 pop r12 they should be in reverse order if</p>



<p class="wp-block-paragraph">you&#8217;ve seen my other videos you&#8217;ll know this and the the thing about this</p>



<p class="wp-block-paragraph">the thing about this particular program is we&#8217;re going to run into stack alignment issues</p>



<p class="wp-block-paragraph">so uh if you don&#8217;t know about stack alignment and how it can crash your program without you</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">already know from running this program in advance that it&#8217;s going to be out of alignment by eight</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">I know it looks weird, but this is going to work.</p>



<p class="wp-block-paragraph">Let me get rid of this here.</p>



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



<p class="wp-block-paragraph">And then maybe if I can remember at the end of the video,</p>



<p class="wp-block-paragraph">I can just remove that extra push-pop pair,</p>



<p class="wp-block-paragraph">and you&#8217;ll see the program starts crashing.</p>



<p class="wp-block-paragraph">But at home, you can do it just to double check.</p>



<p class="wp-block-paragraph">So the first thing I really want to do is,</p>



<p class="wp-block-paragraph">after I push and pop,</p>



<p class="wp-block-paragraph">is save our incoming arguments.</p>



<p class="wp-block-paragraph">Remember, the first integer argument</p>



<p class="wp-block-paragraph">and the second integer argument,</p>



<p class="wp-block-paragraph">argument they come in as RDI and RSI in assembly per the ABI if both of these</p>



<p class="wp-block-paragraph">things are pointers it doesn&#8217;t matter what the data type is it could be</p>



<p class="wp-block-paragraph">pointing to anything including a double and these would still be considered</p>



<p class="wp-block-paragraph">integer arguments because well RDI and RSI are just going to be loaded up with</p>



<p class="wp-block-paragraph">memory locations which which are integers so I&#8217;m going to save our</p>



<p class="wp-block-paragraph">arguments to R12 and R13 now justifying our push and pop pair then I&#8217;m going to</p>



<p class="wp-block-paragraph">little welcome message so print a little welcome message again you don&#8217;t need to know about this</p>



<p class="wp-block-paragraph">function but it&#8217;s explained in other videos that I&#8217;ve already published we&#8217;re going to print our</p>



<p class="wp-block-paragraph">hello beginning message I&#8217;m getting nervous he needs to take a second poop sometimes it&#8217;s poopoo</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">But he did go pee and poop already.</p>



<p class="wp-block-paragraph">Okay, he just left and walked away.</p>



<p class="wp-block-paragraph">Okay, if he comes back, I&#8217;m letting him out this time.</p>



<p class="wp-block-paragraph">I&#8217;ll pause the video if he does it again.</p>



<p class="wp-block-paragraph">Okay, I&#8217;m pausing the video.</p>



<p class="wp-block-paragraph">No pee lied.</p>



<p class="wp-block-paragraph">He went outside, lifted up his little leg, and a couple of drops of pee came out.</p>



<p class="wp-block-paragraph">Now he&#8217;s staring at me like he deserves a treat.</p>



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



<p class="wp-block-paragraph">I wish I could eat constantly all day long, too.</p>



<p class="wp-block-paragraph">But life isn&#8217;t always fair.</p>



<p class="wp-block-paragraph">isn&#8217;t always fair anyway let&#8217;s see I might even lined up on the camera</p>



<p class="wp-block-paragraph">anymore I don&#8217;t even know so we&#8217;re looking at this code here is going to</p>



<p class="wp-block-paragraph">print a welcome message let&#8217;s see if that actually works so I&#8217;m gonna do make</p>



<p class="wp-block-paragraph">run again make files are whoops what did I do loader dot asm what did I do what</p>



<p class="wp-block-paragraph">did I do I somehow copy pasted the wrong make file</p>



<p class="wp-block-paragraph">What&#8217;s the name of my source code file?</p>



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



<p class="wp-block-paragraph">I guess I&#8217;ll just change it, and then it&#8217;ll probably work.</p>



<p class="wp-block-paragraph">It&#8217;s still in assembly module.</p>



<p class="wp-block-paragraph">Hopefully that didn&#8217;t mess it up too bad by copy-pasting the wrong source code.</p>



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



<p class="wp-block-paragraph">What is going on here?</p>



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



<p class="wp-block-paragraph">Oh, I need to change that.</p>



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



<p class="wp-block-paragraph">Let me fix this.</p>



<p class="wp-block-paragraph">I don&#8217;t know if I&#8217;m going to edit this out.</p>



<p class="wp-block-paragraph">out. It&#8217;s fun to watch me struggle sometimes. There we go.</p>



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



<p class="wp-block-paragraph">Alright, let&#8217;s give it another try.</p>



<p class="wp-block-paragraph">Oh no, star dot so no such file a directory. Dang it.</p>



<p class="wp-block-paragraph">Okay, now this seems to work. I may or may not have edited</p>



<p class="wp-block-paragraph">that out. I copy pasted the wrong source code into my make</p>



<p class="wp-block-paragraph">file. So I had to manually adjust it. Then I forgot to</p>



<p class="wp-block-paragraph">copy paste my library file into the build directory. So I had</p>



<p class="wp-block-paragraph">The driver sees my long as whatever.</p>



<p class="wp-block-paragraph">What&#8217;s going on?</p>



<p class="wp-block-paragraph">Print an alternate string begin.</p>



<p class="wp-block-paragraph">Oh, the driver is printing a bunch of stuff.</p>



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



<p class="wp-block-paragraph">I started to think, why does it look like the program has a lot of stuff going on?</p>



<p class="wp-block-paragraph">Oh, that&#8217;s the driver.</p>



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



<p class="wp-block-paragraph">So the driver says it sees its long as 100.</p>



<p class="wp-block-paragraph">And then now we&#8217;re inside of the point module.</p>



<p class="wp-block-paragraph">So that&#8217;s the only thing we&#8217;ve done in assembly so far.</p>



<p class="wp-block-paragraph">so far then the driver has regained control maybe I should add a couple of</p>



<p class="wp-block-paragraph">new lines in there so I don&#8217;t get confused again we will do a C out and L</p>



<p class="wp-block-paragraph">and we&#8217;ll do two of those run the program again and then I won&#8217;t get</p>



<p class="wp-block-paragraph">confused about the messages okay so now we&#8217;re inside of the point module and</p>



<p class="wp-block-paragraph">nothing is happening so points let me get rid of the make file here and</p>



<p class="wp-block-paragraph">and we&#8217;re just printing a welcome message nothing else so now let&#8217;s print</p>



<p class="wp-block-paragraph">the received string so what am I talking about so we&#8217;re gonna print a prefix</p>



<p class="wp-block-paragraph">basically saying hey we received the following string right so if you look at</p>



<p class="wp-block-paragraph">the symbol message received string it&#8217;s just gonna say we&#8217;re now printing the</p>



<p class="wp-block-paragraph">received string and then it&#8217;ll print it so what are we actually printing we&#8217;re</p>



<p class="wp-block-paragraph">What is R12? R12 is a character pointer to the print me string. And so basically this</p>



<p class="wp-block-paragraph">function print null terminated string, it takes a character pointer. So we&#8217;re giving it a character</p>



<p class="wp-block-paragraph">pointer that we received. When point was called by the driver, notice how it gave a pointer to</p>



<p class="wp-block-paragraph">the C string. You know, all arrays are basically pointers. They&#8217;re just different syntactically</p>



<p class="wp-block-paragraph">just different syntactically sometimes so if i declare an array of some length and i give the</p>



<p class="wp-block-paragraph">symbol somewhere that symbol is really a character pointer so um by calling point with my c string</p>



<p class="wp-block-paragraph">i&#8217;m calling point inside of the assembly module with this character pointer so that means even</p>



<p class="wp-block-paragraph">though this c string is owned by the driver by the c plus plus module the assembly module has access</p>



<p class="wp-block-paragraph">So that means we should be able to print it right now already.</p>



<p class="wp-block-paragraph">So just the rest of it is just like giving a pointer.</p>



<p class="wp-block-paragraph">And notice how I&#8217;m not dereferencing R12.</p>



<p class="wp-block-paragraph">If I did dereferencing around R12, then we would be looking to that address and seeing what&#8217;s there,</p>



<p class="wp-block-paragraph">which wouldn&#8217;t work for printing a null terminated string.</p>



<p class="wp-block-paragraph">So let&#8217;s just run it again.</p>



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



<p class="wp-block-paragraph">This dude is growling at me still because he wants another treat.</p>



<p class="wp-block-paragraph">He just got denied.</p>



<p class="wp-block-paragraph">He&#8217;s trying to do it again.</p>



<p class="wp-block-paragraph">do it again. I let him outside people. He&#8217;s been outside like three times already and he just went</p>



<p class="wp-block-paragraph">out like two minutes ago. Okay. I love him so much. It hurts my heart and he knows eventually he&#8217;s</p>



<p class="wp-block-paragraph">going to break me because it hurts my heart or I&#8217;m like too distracted. It&#8217;s like, you know,</p>



<p class="wp-block-paragraph">pulling the crank on a slot machine in Vegas. You know, eventually something comes out.</p>



<p class="wp-block-paragraph">That&#8217;s what he does to me. I&#8217;ve accidentally trained him. So now printing the received</p>



<p class="wp-block-paragraph">Now printing the received string and notice how it prints.</p>



<p class="wp-block-paragraph">Hello, this is a C string owned by me.</p>



<p class="wp-block-paragraph">So our assembly module is able to print a C string that was created locally by a C++ module.</p>



<p class="wp-block-paragraph">So we&#8217;re handing around pointers.</p>



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



<p class="wp-block-paragraph">Can you hear me?</p>



<p class="wp-block-paragraph">He&#8217;s getting louder.</p>



<p class="wp-block-paragraph">So now let&#8217;s modify the incoming long.</p>



<p class="wp-block-paragraph">Can you shush your freaking pants, please?</p>



<p class="wp-block-paragraph">Shush your pants.</p>



<p class="wp-block-paragraph">shush your pants you know the sad thing also is he&#8217;s so old that he&#8217;s deaf now</p>



<p class="wp-block-paragraph">so he used to know what shush your pants meant it meant I&#8217;m not listening to you</p>



<p class="wp-block-paragraph">and you might as well stop because I&#8217;m not gonna do anything based on your</p>



<p class="wp-block-paragraph">harassment but now he can&#8217;t hear me say shush your pants so he just harasses me</p>



<p class="wp-block-paragraph">all day and all night okay um so I&#8217;m gonna copy paste a little bit more code</p>



<p class="wp-block-paragraph">Modify the incoming long.</p>



<p class="wp-block-paragraph">So remember again that the point function, it received a pointer to a long.</p>



<p class="wp-block-paragraph">We&#8217;re calling the long change me on the inside of this, but it&#8217;s coming in as R13.</p>



<p class="wp-block-paragraph">And if you notice what I&#8217;m doing here is I&#8217;m just saying let&#8217;s increase the long.</p>



<p class="wp-block-paragraph">So I&#8217;m going to dereference R13 because R13 is a pointer.</p>



<p class="wp-block-paragraph">So I&#8217;m saying let&#8217;s go to the memory and change the long that is inside of memory.</p>



<p class="wp-block-paragraph">And we have to specify that it is a keyword.</p>



<p class="wp-block-paragraph">it as a keyword so that we you know we don&#8217;t confuse the system the system might think are</p>



<p class="wp-block-paragraph">you modifying a keyword or like a double word or like a word like how big is your data all we know</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">know a 64-bit integer sitting at that memory location I want you to dereference it and increase</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">and we&#8217;re just giving a pointer to it the next thing that we can do is we can</p>



<p class="wp-block-paragraph">ask the driver to print our own stuff actually you know what let&#8217;s run the program right now</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">first when the driver says hello it sees its own long as 100 then we&#8217;re inside the assembly module</p>



<p class="wp-block-paragraph">long and then we return to the caller which is the driver notice how at the</p>



<p class="wp-block-paragraph">very end of the program the driver sees its long as being 101 so we were able to</p>



<p class="wp-block-paragraph">modify data that was owned by a different module just by passing pointers</p>



<p class="wp-block-paragraph">and de-referencing them okay cool so now the next thing that we should do is let&#8217;s</p>



<p class="wp-block-paragraph">ask the driver to print our own stuff that we own because remember if you go</p>



<p class="wp-block-paragraph">to the very top you know we own some stuff we own some we own a long we own</p>



<p class="wp-block-paragraph">float, right? So we want to be able to do something with that. So I&#8217;m going to copy paste this,</p>



<p class="wp-block-paragraph">ask the driver to print our own stuff. So I&#8217;m going to move three items inside of arguments</p>



<p class="wp-block-paragraph">for a function call. And then I&#8217;m going to make a function call calling the function,</p>



<p class="wp-block-paragraph">Hey driver, print this again, Hey driver, print this is actually owned by the C++ module.</p>



<p class="wp-block-paragraph">a pointer to a long and a pointer to a double remember even pointers to doubles are actually</p>



<p class="wp-block-paragraph">integers so they use the general purpose register so that&#8217;s the three arguments right there rdi rsi</p>



<p class="wp-block-paragraph">and rdx m and then we&#8217;re giving the first pointer is going to be the c string so message string</p>



<p class="wp-block-paragraph">inside asm so you can see that&#8217;s this right here and then the next pointer is the long</p>



<p class="wp-block-paragraph">inside ASM and the third is the float where did I just go I&#8217;m getting confused my dog is harassing</p>



<p class="wp-block-paragraph">me right now so bad notice how I&#8217;m not dereferencing so like if when we were increasing the incoming</p>



<p class="wp-block-paragraph">long before R13 was a pointer so we dereferenced while we increased so that we would increase the</p>



<p class="wp-block-paragraph">actual value and not the pointer and not the pointer&#8217;s memory location but here we&#8217;re not</p>



<p class="wp-block-paragraph">C++ module the actual pointers to our data. We don&#8217;t want to give it the data itself. We want</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">And then here the assembly module has just called on hey driver print this.</p>



<p class="wp-block-paragraph">Remember the C++ module doesn&#8217;t actually call this function.</p>



<p class="wp-block-paragraph">The assembly module calls it.</p>



<p class="wp-block-paragraph">So we&#8217;re like going back and forth.</p>



<p class="wp-block-paragraph">We&#8217;re kind of crisscrossing.</p>



<p class="wp-block-paragraph">So now the drivers print this function says we got the following string.</p>



<p class="wp-block-paragraph">Notice how that&#8217;s the string that is owned by assembly.</p>



<p class="wp-block-paragraph">So we define that inside of our data section in the assembly module.</p>



<p class="wp-block-paragraph">And then it prints the long.</p>



<p class="wp-block-paragraph">It prints it as hex.</p>



<p class="wp-block-paragraph">And it just sort of prints the value.</p>



<p class="wp-block-paragraph">it just sort of prints the value then it prints it as hex again and then prints at the value</p>



<p class="wp-block-paragraph">i think actually not hex i think this prints the memory location let&#8217;s double check real fast</p>



<p class="wp-block-paragraph">yeah so remember um in c plus plus i know this is not like a c plus plus video but um</p>



<p class="wp-block-paragraph">if the long is a pointer then if we just print it without dereferencing it we should see a memory</p>



<p class="wp-block-paragraph">location so it&#8217;s telling us uh that the long&#8217;s memory location is this and the doubles memory</p>



<p class="wp-block-paragraph">location is that and if you stare at those two numbers long enough and you understand hex which</p>



<p class="wp-block-paragraph">And do you understand hex, which you can see my other videos for?</p>



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



<p class="wp-block-paragraph">And then the printing driver thing exits and then the actual driver regains control.</p>



<p class="wp-block-paragraph">And it just says that it sees it&#8217;s long as 101.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">now you hopefully are an expert at passing data back and forth between various modules using</p>



<p class="wp-block-paragraph">pointers we&#8217;re not using references because references are like a little bit a little bit</p>



<p class="wp-block-paragraph">less compatible pointers are just really easy they totally work in assembly no problem</p>



<p class="wp-block-paragraph">one more thing i just wanted to show you real fast before we go even though there&#8217;s another</p>



<p class="wp-block-paragraph">video you should check out for stack alignment I just want you to see what</p>



<p class="wp-block-paragraph">happens if I remove this extra push-pop pair so now my stack is about eight</p>



<p class="wp-block-paragraph">bytes off of its previous alignment because you know we&#8217;re not pushing an</p>



<p class="wp-block-paragraph">extra eight byte value and somewhere inside of the let&#8217;s see print null</p>



<p class="wp-block-paragraph">terminated string and then the hey driver print this oh and then we go into</p>



<p class="wp-block-paragraph">like a bunch of C stuff the program should probably crash because anytime</p>



<p class="wp-block-paragraph">you use a GCC function or a GCC library or something like that the stack has to</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">that I needed this well I just ran it first and it crashed and then I added</p>



<p class="wp-block-paragraph">the extra push pop pair and it didn&#8217;t crash and I realized it was definitely</p>



<p class="wp-block-paragraph">one more time we should get a seg fault yeah we get a seg fault stack alignment oh no with no</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">could probably figure that out eventually but why not just give it a try add another push pop pair</p>



<p class="wp-block-paragraph">run the program again with no other modifications now it totally works</p>



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



<p class="wp-block-paragraph">I will see you in the next video.</p>



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



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



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



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



<p class="wp-block-paragraph">If you could do me a please, a small little favor,</p>



<p class="wp-block-paragraph">could you please subscribe and follow this channel or these videos</p>



<p class="wp-block-paragraph">or whatever it is you do on the current social media website</p>



<p class="wp-block-paragraph">that you&#8217;re looking at right now.</p>



<p class="wp-block-paragraph">It would really mean the world to me</p>



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



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



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general so please do do me a</p>



<p class="wp-block-paragraph">kindness and and subscribe you know sometimes I&#8217;m sleeping in the middle of</p>



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



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



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



<p class="wp-block-paragraph">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 class="wp-block-paragraph">happen also if you look at the middle of the screen right now you should see a QR code which</p>



<p class="wp-block-paragraph">you can scan in order to go to the website which I think is also named somewhere at the bottom of</p>



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



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



<p class="wp-block-paragraph">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 class="wp-block-paragraph">What&#8217;s up? What&#8217;s going on? You know, just send me a comment, whatever</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-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 class="wp-block-paragraph">In this beginner-to-intermediate assembly language tutorial, we dive deep into unconditional jump instructions (JMP) in x86-64 assembly using Yasm syntax.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/">x86-64 Assembly Jump Instructions Explained: Unconditional JMP with Full Example in Yasm</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/x86-64-assembly-jump-instructions-explained-unconditional-jmp-with-full-example-in-yasm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>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 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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">Code shown works on Linux x86-64 with YASM/NASM syntax. Grab the concepts and apply them anywhere.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">Thanks for watching!</p>



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



<p class="wp-block-paragraph">In this video we&#8217;re going to talk about implementing simple if-else blocks in YASM x86-64 assembly.</p>



<p class="wp-block-paragraph">Although if you&#8217;re writing in a different assembly language, this video will probably</p>



<p class="wp-block-paragraph">still be useful to you because I&#8217;m going to explain the design pattern or how we can achieve</p>



<p class="wp-block-paragraph">that at the assembly level.</p>



<p class="wp-block-paragraph">So x86-64 YASM assembly, also known as AMD64 YASM assembly.</p>



<p class="wp-block-paragraph">So if you have not seen my other videos about how to do conditional branching in the first</p>



<p class="wp-block-paragraph">place, you probably want to go check that first because that knowledge is required for</p>



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



<p class="wp-block-paragraph">There&#8217;s also a lot of other stuff that I&#8217;m just not going to explain in this video, such</p>



<p class="wp-block-paragraph">as creating a make file, you know, compiling and linking your executable and so forth.</p>



<p class="wp-block-paragraph">So see my other videos where all those concepts are explained already.</p>



<p class="wp-block-paragraph">how to implement a simple if-else block.</p>



<p class="wp-block-paragraph">So for starters, maybe let me draw a little bit.</p>



<p class="wp-block-paragraph">Suppose we had, let me get rid of this thing</p>



<p class="wp-block-paragraph">and then I&#8217;ll just do a regular notepad.</p>



<p class="wp-block-paragraph">Suppose we had a higher level language,</p>



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



<p class="wp-block-paragraph">Suppose we had a higher level language</p>



<p class="wp-block-paragraph">and we wanted to say if, you know, some expression is true.</p>



<p class="wp-block-paragraph">We wanted to say if expression is true,</p>



<p class="wp-block-paragraph">then print, you know, it was true.</p>



<p class="wp-block-paragraph">Anybody remember that old movie, Little Nicky?</p>



<p class="wp-block-paragraph">Somebody got exploded and then the guy next to him goes it&#8217;s not true</p>



<p class="wp-block-paragraph">Okay, it was not true</p>



<p class="wp-block-paragraph">So this is the basic idea of what we&#8217;re going to implement in assembly</p>



<p class="wp-block-paragraph">I&#8217;m going to write a full program for assembly to show you this but um</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">You obviously know how to use if-else blocks at this point hopefully</p>



<p class="wp-block-paragraph">And now we&#8217;re going to just try to figure out how to implement them in assembly</p>



<p class="wp-block-paragraph">So it&#8217;s important to understand that really under the hood</p>



<p class="wp-block-paragraph">really under the hood there&#8217;s a bunch of stuff happening surprise right okay so</p>



<p class="wp-block-paragraph">first off we look at this expression which could be I don&#8217;t know let&#8217;s say</p>



<p class="wp-block-paragraph">five is greater than ten or a is equal to B or whatever it is that you put in</p>



<p class="wp-block-paragraph">there you could make a very complicated expression we&#8217;re going to use simple</p>



<p class="wp-block-paragraph">expressions for this video so if we&#8217;re comparing a to B we&#8217;ll end up using the</p>



<p class="wp-block-paragraph">compare instruction remember there are two steps to conditional branching and</p>



<p class="wp-block-paragraph">in YASM we first use the compare instruction against two operands and then that will end up</p>



<p class="wp-block-paragraph">filling up the rflags register so that we can later conditionally jump based on the results</p>



<p class="wp-block-paragraph">of the comparison. So we do a comparison and then you can imagine that the beginning of this</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">line here to indicate that there is a scope from line four to six indicating all this code in here</p>



<p class="wp-block-paragraph">in here is executed only if the if statement was true and then all of this other stuff is executed</p>



<p class="wp-block-paragraph">only if the original comparison was false right so you can imagine now label is something like</p>



<p class="wp-block-paragraph">my if was true so we can make a label for where that body starts and another label for where the</p>



<p class="wp-block-paragraph">label is something like if was false and then what will happen is we can use a</p>



<p class="wp-block-paragraph">conditional jump instruction after we do our comparison maybe I should put to</p>



<p class="wp-block-paragraph">compare right here oh I&#8217;m using I&#8217;m using assembly style comments I should</p>



<p class="wp-block-paragraph">be using a C style comments if I&#8217;m actually writing C++ here let me just do</p>



<p class="wp-block-paragraph">that okay so this is the comparison instruction here and then here&#8217;s the</p>



<p class="wp-block-paragraph">here and then here&#8217;s the beginning of the body of stuff to execute if it was true you can imagine</p>



<p class="wp-block-paragraph">that there could be many statements here um if it was true or if it was false</p>



<p class="wp-block-paragraph">just to prove to you that we can execute like a full body of stuff so we have a label that</p>



<p class="wp-block-paragraph">designates when that body starts and then we have another label designating when the else body</p>



<p class="wp-block-paragraph">starts and then we should have a label that uh that designates when the whole thing is over</p>



<p class="wp-block-paragraph">label is something like if and or if is done or something like that so basically what we want to</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">and then we&#8217;ll do a conditional jump where are we going to conditionally jump well if the comparison</p>



<p class="wp-block-paragraph">was true label. And then what will happen is execution will fall through.</p>



<p class="wp-block-paragraph">When it reaches the end, we want to have another jump statement that unconditionally jumps</p>



<p class="wp-block-paragraph">to the end of the if statement. If we didn&#8217;t, then whenever the expression was true,</p>



<p class="wp-block-paragraph">we would end up executing all of the true statements and then it would fall through</p>



<p class="wp-block-paragraph">to all of the false statements or the not true statements. So we have to have many jumps in here</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">expression was false then our jump instruction is going to jump you know over the true body so</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">you know sometimes a good idea if you have another jump here that just jumps to the end but you can</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">you know place where we&#8217;re finished with everything which means we don&#8217;t really</p>



<p class="wp-block-paragraph">need an unconditional jump at the end of the else body we can just let the</p>



<p class="wp-block-paragraph">execution fall through so maybe if I can draw a little diagram here I&#8217;ll say I</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">was false we jump to one place and if it was true we jump to another place</p>



<p class="wp-block-paragraph">we jump to another place.</p>



<p class="wp-block-paragraph">I hope you&#8217;ve already started to understand this by now.</p>



<p class="wp-block-paragraph">So we&#8217;ll say if the expression is true, we jump here.</p>



<p class="wp-block-paragraph">If the expression is false, we jump over here.</p>



<p class="wp-block-paragraph">And so true would be saying, let&#8217;s jump to the if was true.</p>



<p class="wp-block-paragraph">So we&#8217;re going to jump to if was,</p>



<p class="wp-block-paragraph">I&#8217;ll put a T there because I&#8217;m running out of space.</p>



<p class="wp-block-paragraph">If was true.</p>



<p class="wp-block-paragraph">was I&#8217;ll put an F false and then at the end of the true we jump to the done</p>



<p class="wp-block-paragraph">label so I&#8217;m just gonna put done maybe down here</p>



<p class="wp-block-paragraph">so at the end of the true we just unconditionally jump to the done area</p>



<p class="wp-block-paragraph">and then at the end of the false we jump unconditionally to the done area as well</p>



<p class="wp-block-paragraph">here&#8217;s something interesting though when we have a comparison instruction and</p>



<p class="wp-block-paragraph">conditional branch instruction let&#8217;s say uh let&#8217;s say a equals b we did that comparison and then we</p>



<p class="wp-block-paragraph">wanted to jump into the true area if a equals b was true so that means we&#8217;ll say jump</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">but the conditional branching instructions they only jump to one</p>



<p class="wp-block-paragraph">potential place or fall through so if the comparison was false meaning if those</p>



<p class="wp-block-paragraph">two things were not equal then we&#8217;re not going to actually be able to jump to a</p>



<p class="wp-block-paragraph">different label we&#8217;re going to simply fall through to the next instruction so</p>



<p class="wp-block-paragraph">in that case the very next instruction would get executed let&#8217;s just put a jump</p>



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



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



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



<p class="wp-block-paragraph">we compare A and B</p>



<p class="wp-block-paragraph">and if the two things are equal</p>



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



<p class="wp-block-paragraph">Otherwise we fall through to the next instruction</p>



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



<p class="wp-block-paragraph">that&#8217;s a very poorly written J</p>



<p class="wp-block-paragraph">but we&#8217;re going to unconditionally jump to false.</p>



<p class="wp-block-paragraph">So if we did not</p>



<p class="wp-block-paragraph">jump to the true area we fall through to the next</p>



<p class="wp-block-paragraph">instruction where we will always</p>



<p class="wp-block-paragraph">jump to false and that implements the diagram</p>



<p class="wp-block-paragraph">that implements the diagram that you see up above.</p>



<p class="wp-block-paragraph">I mean, you know, if we have if statement, we compare,</p>



<p class="wp-block-paragraph">maybe I&#8217;ll do, you know, A equals B.</p>



<p class="wp-block-paragraph">We jumped to true, if was true.</p>



<p class="wp-block-paragraph">And otherwise we end up falling through</p>



<p class="wp-block-paragraph">and then jumping to if was false.</p>



<p class="wp-block-paragraph">And then at the end of both of those,</p>



<p class="wp-block-paragraph">we have an unconditional jump instruction</p>



<p class="wp-block-paragraph">that jumps to the done.</p>



<p class="wp-block-paragraph">So I&#8217;ll put JMP down here just to let you know,</p>



<p class="wp-block-paragraph">you know, at the end of each of these blocks,</p>



<p class="wp-block-paragraph">that they are jumping out of themselves at the very end to the done area maybe</p>



<p class="wp-block-paragraph">I&#8217;ll put an arrow here so that we know both of these jumps end up jumping to</p>



<p class="wp-block-paragraph">the done area that&#8217;s the basic idea for how to implement an if-else block a very</p>



<p class="wp-block-paragraph">basic one we&#8217;re gonna do more complicated ones later but for now we</p>



<p class="wp-block-paragraph">kind of have the idea down I think let&#8217;s look at some code dang I blew 10 minutes</p>



<p class="wp-block-paragraph">already on that okay so I&#8217;m gonna copy paste some code from my solution here</p>



<p class="wp-block-paragraph">code for my solution here this again this is not like a beginner&#8217;s assembly</p>



<p class="wp-block-paragraph">video if you need to learn how to write assembly in the first place how to</p>



<p class="wp-block-paragraph">compile you know link create a make file and so forth you need to see my other</p>



<p class="wp-block-paragraph">videos first but for now we&#8217;re just going to assume that you know how to</p>



<p class="wp-block-paragraph">make a data section in Yasm and we&#8217;re gonna say let&#8217;s make a bunch of strings</p>



<p class="wp-block-paragraph">so first I&#8217;m gonna ask the user for an integer and then I&#8217;m gonna make a bunch</p>



<p class="wp-block-paragraph">of decisions like I&#8217;m gonna do you know an if-else block to test what kind of</p>



<p class="wp-block-paragraph">what kind of number they put you know did they make a number that uh</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">but basically we&#8217;re going to print something if their number was equal to something else</p>



<p class="wp-block-paragraph">we&#8217;re going to print uh something if their number that they inputted was equal to five we&#8217;re going</p>



<p class="wp-block-paragraph">to print something else if their number was equal to six we&#8217;re going to print again something else</p>



<p class="wp-block-paragraph">a bunch of stuff and then wait isn&#8217;t this the complicated example oh no i think i am using code</p>



<p class="wp-block-paragraph">for my more complicated example else less than 10 i don&#8217;t know maybe this is the simple one</p>



<p class="wp-block-paragraph">let&#8217;s double check i guess if i put more complicated code in here you&#8217;ll probably be happy</p>



<p class="wp-block-paragraph">but whatever i thought this was going to be a simple example so i&#8217;m just defining strings at</p>



<p class="wp-block-paragraph">codes stuff that is covered in other videos now i&#8217;m going to start my text section so my text</p>



<p class="wp-block-paragraph">section begins with a declaration that i&#8217;m going to use two external functions so this video is</p>



<p class="wp-block-paragraph">not about this library that takes input and sends output i have other videos for that but basically</p>



<p class="wp-block-paragraph">i&#8217;m just using a library that lets you type an integer into the terminal and then it will print</p>



<p class="wp-block-paragraph">a different number to the terminal for you so you can imagine if you wanted to follow along</p>



<p class="wp-block-paragraph">imagine if you wanted to follow along with this code at home and you don&#8217;t</p>



<p class="wp-block-paragraph">have this library you can just hard code your numbers just to prove to yourself</p>



<p class="wp-block-paragraph">that you can get it to work or you can use a different library if you have a</p>



<p class="wp-block-paragraph">hybrid program and you&#8217;re linking against GCC you can just use scanf and</p>



<p class="wp-block-paragraph">printf pretty much those take a little bit more work to do but you can do it</p>



<p class="wp-block-paragraph">anyway so our entry point is going to be called if tester it&#8217;s a function called</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">So it&#8217;s just a little label that we can jump into or in this case call into.</p>



<p class="wp-block-paragraph">Let me go down to the bottom of that.</p>



<p class="wp-block-paragraph">We&#8217;ll put a return statement at the very end.</p>



<p class="wp-block-paragraph">very end so now this is officially a function and notice how i made a note here that says r12 is</p>



<p class="wp-block-paragraph">the user&#8217;s inputted integer so that means i&#8217;m going to be using r12 and since r12 is designated</p>



<p class="wp-block-paragraph">in the abi the application binary interface as callee saved or callee preserved that means i</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">prologue which my favorite book also calls the prologue and then I&#8217;m going to</p>



<p class="wp-block-paragraph">say epilogue and so now we have a function that basically doesn&#8217;t do</p>



<p class="wp-block-paragraph">anything but we can at least jump into it let&#8217;s see if this compiles as is I</p>



<p class="wp-block-paragraph">think it probably will yeah so the driver just says hello that&#8217;s the C++</p>



<p class="wp-block-paragraph">program with the actual main function and it calls my if tester function but</p>



<p class="wp-block-paragraph">nothing happens the if tester function returns control to the driver and then</p>



<p class="wp-block-paragraph">the driver just says okay i got control back so nothing really happened so now let&#8217;s ask the user</p>



<p class="wp-block-paragraph">for some input so again this is not a video about this library or how to print with this with system</p>



<p class="wp-block-paragraph">calls see my other videos if you need help on that but basically we&#8217;re going to print a message to</p>



<p class="wp-block-paragraph">the user hey please input an integer and then we&#8217;re going to call on a library function that</p>



<p class="wp-block-paragraph">lets them type in a number and then returns it to us in rax we&#8217;re then going to store it</p>



<p class="wp-block-paragraph">well just basic stuff right so if I run this again it&#8217;s going to ask for an</p>



<p class="wp-block-paragraph">integer please enter an integer if I can type that and then nothing else happens</p>



<p class="wp-block-paragraph">okay now we can kind of start making more decisions so I&#8217;m going to let&#8217;s see</p>



<p class="wp-block-paragraph">if test if test if test okay so what I need to do now is run another function</p>



<p class="wp-block-paragraph">called if tests several times and I&#8217;m going to compare the number that the</p>



<p class="wp-block-paragraph">times and I&#8217;m going to compare the number that the user inputted so remember r12 is the user&#8217;s</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">to load the number five as the second argument of a function call probably not a great idea to hard</p>



<p class="wp-block-paragraph">code numbers in your assembly you should probably define them up in the globals or the the data</p>



<p class="wp-block-paragraph">section at least as just regular defines and not numbers in memory but I&#8217;m going to just keep these</p>



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



<p class="wp-block-paragraph">Where the heck is that? Oh, dude?</p>



<p class="wp-block-paragraph">Again, this is not a video about the basics</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">But I have a function called</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">handles the CRLF call. Now let&#8217;s make another function called if test.</p>



<p class="wp-block-paragraph">So I&#8217;m going to start that by designating its label right after this block of</p>



<p class="wp-block-paragraph">code here, maybe before CRLF.</p>



<p class="wp-block-paragraph">So we have like a basic if test function and here&#8217;s my prototype just to remind</p>



<p class="wp-block-paragraph">myself what I&#8217;m going to be doing.</p>



<p class="wp-block-paragraph">It&#8217;s going to take an input and it&#8217;s going to take another input for a test</p>



<p class="wp-block-paragraph">against me. So the first one is like the user&#8217;s input.</p>



<p class="wp-block-paragraph">The second one is the number that I want to test it against.</p>



<p class="wp-block-paragraph">number that I want to test it against they&#8217;re both longs which means they are both integers</p>



<p class="wp-block-paragraph">which means the incoming arguments are going to be rdi and rsi if you&#8217;re respecting the abi</p>



<p class="wp-block-paragraph">and then some notes to remind myself I&#8217;m going to be using r12 and r13 inside of this function so</p>



<p class="wp-block-paragraph">I&#8217;m going to start by putting a return statement there since that is what it takes to make a label</p>



<p class="wp-block-paragraph">into a return into into a function then I&#8217;m going to preserve the callee saved registers again if</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">that they are not ruined for the caller we call this the prolog then at the very bottom of the</p>



<p class="wp-block-paragraph">function we have the epilog which just restores uh the registers in reverse order you&#8217;ve got to</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">function that can get called it doesn&#8217;t do anything let me double check that the program still actually</p>



<p class="wp-block-paragraph">works. 66 and nothing happens. We just printed CRLF a bunch of times. Okay, so now we&#8217;re ready</p>



<p class="wp-block-paragraph">to continue. So let&#8217;s grab the function arguments. Remember we were going to use R12 and R13 for the</p>



<p class="wp-block-paragraph">user&#8217;s input and the number we will test against. Those came into our function with RDI and RSI.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to copy those two incoming arguments into R12 and R13. And you&#8217;re supposed</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">arguments and then I print a begin message just to let the user know that we&#8217;re going to start</p>



<p class="wp-block-paragraph">you know making tests against our number so this is just basically a message saying hey begin the</p>



<p class="wp-block-paragraph">if test and then print what we&#8217;re going to check against so the next thing is</p>



<p class="wp-block-paragraph">I&#8217;m going to let the user know what the second incoming argument was.</p>



<p class="wp-block-paragraph">If you look at R13 here, that was RSI, which was the second argument.</p>



<p class="wp-block-paragraph">So the test against me number.</p>



<p class="wp-block-paragraph">So we&#8217;re going to check the user&#8217;s input against whatever we called for the second argument.</p>



<p class="wp-block-paragraph">So I just wanted to print it out.</p>



<p class="wp-block-paragraph">You know, like we&#8217;re testing your number against whatever.</p>



<p class="wp-block-paragraph">So that means I need to make another call to my little printing library here.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">Then we&#8217;re gonna print a special message only if something actually happens</p>



<p class="wp-block-paragraph">So we&#8217;re gonna implement the if else block in a moment. Let me just run this real fast</p>



<p class="wp-block-paragraph">and then it says we&#8217;re calling the function three times and we&#8217;re saying the basic test has begun</p>



<p class="wp-block-paragraph">we&#8217;ll test against this number five so we&#8217;re testing your input against five and then six and</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">going to print a special message only if the user entered the right number so first off remember we</p>



<p class="wp-block-paragraph">see if else block and converting it into assembly so i&#8217;m sort of placing that in comments for you</p>



<p class="wp-block-paragraph">so the comparison instruction i i didn&#8217;t want to put the r12 equals r13 inside of the same comment</p>



<p class="wp-block-paragraph">that lines up with the the compare instruction because the compare instruction as i&#8217;ve said in</p>



<p class="wp-block-paragraph">other videos already it doesn&#8217;t actually check to see if something&#8217;s equal it just makes a bunch of</p>



<p class="wp-block-paragraph">called r flags with information that we can later use to decide if the two things were equal or not</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">with any scheme you want for your labels but for me when i have when i have sub labels inside of a</p>



<p class="wp-block-paragraph">when i have sub labels inside of a function i like to just suffix the function&#8217;s name with an</p>



<p class="wp-block-paragraph">underscore and then start thinking of sub labels after that so everything&#8217;s like kind of clean</p>



<p class="wp-block-paragraph">there&#8217;s less chance of overlap in labels if you have like a giant module with tons of functions</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">called was equal meaning you know this evaluated to true that means that should be the true part</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">the true block so you know if was true in the first example that we talked about so i&#8217;m going</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">did not jump away it means that those two things are not equal so i said i should jump to the</p>



<p class="wp-block-paragraph">I should jump to the else block or the false block.</p>



<p class="wp-block-paragraph">Wait, do I have else in this example?</p>



<p class="wp-block-paragraph">Oh, okay, okay.</p>



<p class="wp-block-paragraph">This first thing that we&#8217;re looking at is only if.</p>



<p class="wp-block-paragraph">So we don&#8217;t even have an else block yet.</p>



<p class="wp-block-paragraph">We&#8217;re going to do that as the second example.</p>



<p class="wp-block-paragraph">So we&#8217;re basically going to jump to the done area</p>



<p class="wp-block-paragraph">if we didn&#8217;t jump into the true area.</p>



<p class="wp-block-paragraph">And then at the end of the true area,</p>



<p class="wp-block-paragraph">we can either jump to the done area</p>



<p class="wp-block-paragraph">or we can let the execution fall through.</p>



<p class="wp-block-paragraph">fall through okay so now that means i need if was equal and if i just copy paste a big giant</p>



<p class="wp-block-paragraph">block of code and try to explain it to you real fast let&#8217;s do this</p>



<p class="wp-block-paragraph">okay so we were going to jump to if was equal if r12 was equal to r13 and then um</p>



<p class="wp-block-paragraph">we uh have this you know label here and notice how i&#8217;ve kind of like put a brace here indicating</p>



<p class="wp-block-paragraph">like put a brace here indicating hey this is the beginning of the true block body you should</p>



<p class="wp-block-paragraph">consider doing this too when you&#8217;re first learning and even after you&#8217;ve learned because let&#8217;s face</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">to say hey your number was equal to you know whatever and then uh i&#8217;m going to actually print</p>



<p class="wp-block-paragraph">the let&#8217;s see r13 number so that was uh i think the number to compare against the test against</p>



<p class="wp-block-paragraph">against me number so that means here in this message we&#8217;re going to say hey your number was</p>



<p class="wp-block-paragraph">equal to the number that we tested against so then otherwise let&#8217;s see or sorry after that</p>



<p class="wp-block-paragraph">we&#8217;ll print the suffix of the message um and so you know i just i just like to make pretty</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">oh i should have put suffix instead of the number two that would have been better so what i wanted</p>



<p class="wp-block-paragraph">to do is say your input was equal to and then print the number and then after that print an</p>



<p class="wp-block-paragraph">exclamation just to prove to you how easy it is to to make a pretty message that&#8217;s formatted nicely</p>



<p class="wp-block-paragraph">for the user um or your professor or whoever so uh you know you basically just print a number and</p>



<p class="wp-block-paragraph">then you or sorry you print the prefix and then you print the number and then you print the suffix</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">can basically just say all right now we&#8217;re done with the if so the next instruction that follows</p>



<p class="wp-block-paragraph">is the done area again looking back at the example here that would be sort of like here after the</p>



<p class="wp-block-paragraph">whole entire block was finished we&#8217;re ignoring the else in this code but you can imagine we&#8217;ll do</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">to the done area and if the user&#8217;s uh number did not match then we just immediately jump to the</p>



<p class="wp-block-paragraph">done area so that we don&#8217;t do the true area and then we write comments to ourselves to help us</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">area is like we could put another comment if we want we could say like this is done but i kind of</p>



<p class="wp-block-paragraph">think like i kind of think the label is self-explanatory so let&#8217;s see if this worked it&#8217;s</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">number six and you can see it did not match the number five and it did match the number six so</p>



<p class="wp-block-paragraph">we got that true block executing when we called on that function where the number to compare to</p>



<p class="wp-block-paragraph">nothing there. So now we know simple if blocks.</p>



<p class="wp-block-paragraph">The next thing we&#8217;re going to do is if else blocks.</p>



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



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



<p class="wp-block-paragraph">Not sure if I&#8217;m going to cut the video and split this up into multiple parts.</p>



<p class="wp-block-paragraph">Probably would have been a smart idea.</p>



<p class="wp-block-paragraph">Let me know if I ended up doing it.</p>



<p class="wp-block-paragraph">We&#8217;re at about 25 minutes now.</p>



<p class="wp-block-paragraph">But anyway,</p>



<p class="wp-block-paragraph">so now we&#8217;re going to look at if else blocks.</p>



<p class="wp-block-paragraph">if else blocks.</p>



<p class="wp-block-paragraph">So I&#8217;m going to start off with another function.</p>



<p class="wp-block-paragraph">I&#8217;m going to call it if else test.</p>



<p class="wp-block-paragraph">So here&#8217;s the tester.</p>



<p class="wp-block-paragraph">It called on if test.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to, you know, I had the if test function that I did previously.</p>



<p class="wp-block-paragraph">And so now we&#8217;re just going to make an if else test function.</p>



<p class="wp-block-paragraph">The if else test, it just has one input, one argument for input.</p>



<p class="wp-block-paragraph">And we&#8217;re going to just sort of compare it against different values.</p>



<p class="wp-block-paragraph">of compare it against different values we&#8217;re not going to call this multiple times with different</p>



<p class="wp-block-paragraph">values to compare against so that means let&#8217;s see we only need to use one register so</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">some of the basic stuff that i&#8217;m that i&#8217;m skipping over see my other videos where i explained</p>



<p class="wp-block-paragraph">to know to actually have this kind of a program. So I&#8217;m going to have a function that enters and</p>



<p class="wp-block-paragraph">it returns at the end. It uses R12 so we will preserve it with a push pop pair.</p>



<p class="wp-block-paragraph">And then the first thing that I should do is grab the user&#8217;s input from the first argument.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">somebody remind me that the first part of the program has to actually call this function or</p>



<p class="wp-block-paragraph">nothing will happen. So we&#8217;re going to say hello. That&#8217;s just a simple message that we talked about</p>



<p class="wp-block-paragraph">before. And then now we&#8217;re going to actually implement the if else block. So it&#8217;s like a</p>



<p class="wp-block-paragraph">little bit more complicated than just the simple if block. It&#8217;s going to be this whole example that</p>



<p class="wp-block-paragraph">we talked about before. Let me see. Maybe I should add the calls to this block real fast. So we have</p>



<p class="wp-block-paragraph">to this block real fast so we have the if tester and then run the complex if else tests</p>



<p class="wp-block-paragraph">right before r12 okay let me just double check that i&#8217;m making a call at the right spot here</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">to um the if else test function that we&#8217;re just making right now</p>



<p class="wp-block-paragraph">Okay, so we have that.</p>



<p class="wp-block-paragraph">And let me find that source again real fast.</p>



<p class="wp-block-paragraph">If else test, we got the prologue.</p>



<p class="wp-block-paragraph">We take their input and then we say hello.</p>



<p class="wp-block-paragraph">Okay, so now we need another label that begins the if block.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">And then we&#8217;re going to say something if it was.</p>



<p class="wp-block-paragraph">And otherwise, we&#8217;re going to do an else block on that.</p>



<p class="wp-block-paragraph">block on that so again i like to write my comparison instructions with a blank expression</p>



<p class="wp-block-paragraph">in terms of the c equivalent comment so notice how the we&#8217;re checking to see if r12 is equal to</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">block if it equals five so that&#8217;s why i put that there the comparison instruction pretty much just</p>



<p class="wp-block-paragraph">compares r12 with five sets a bunch of values into the r flags registers so that we can later</p>



<p class="wp-block-paragraph">so that we can later conditionally jump if we want to.</p>



<p class="wp-block-paragraph">So basically we&#8217;ll jump to the true place if that was true.</p>



<p class="wp-block-paragraph">And then if not, execution falls through to the next statement,</p>



<p class="wp-block-paragraph">which will just jump to the else place.</p>



<p class="wp-block-paragraph">So we need more labels is what I&#8217;m saying.</p>



<p class="wp-block-paragraph">So now we need a body for if the statement was true</p>



<p class="wp-block-paragraph">or the expression was true,</p>



<p class="wp-block-paragraph">we want to be able to execute the true portion of the if block.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">could imagine you know making a better label instead of equal five you could say first if</p>



<p class="wp-block-paragraph">first else if complicated block true scope or true block or something but i just put equal to five</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">into this label equal five if r12 was indeed equal to five so that means if it was we execute</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">to finish the the if else block again just just to clarify</p>



<p class="wp-block-paragraph">we do the comparison first and if the comparison was true then we&#8217;ll jump into the true area so</p>



<p class="wp-block-paragraph">you know we&#8217;ll jump into the true area and then all of these uh instructions get executed</p>



<p class="wp-block-paragraph">instructions get executed but if we don&#8217;t have a way to jump out of that block then whoops</p>



<p class="wp-block-paragraph">all of the else statements are going to get executed too right so we don&#8217;t want that</p>



<p class="wp-block-paragraph">we don&#8217;t want to execute both the true and the false statements we want to have a jump instruction</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">you know jump to the place where it&#8217;s just all over and finished</p>



<p class="wp-block-paragraph">Okay, so now I&#8217;m going to look at, whoops, turn that off.</p>



<p class="wp-block-paragraph">So we have equal five.</p>



<p class="wp-block-paragraph">So we&#8217;re going to jump to if else test if done.</p>



<p class="wp-block-paragraph">Let me just double check to make sure I&#8217;m not forgetting anything.</p>



<p class="wp-block-paragraph">Oh, we need to jump here.</p>



<p class="wp-block-paragraph">Basically meaning we&#8217;re going to jump into the else portion.</p>



<p class="wp-block-paragraph">So here we covered jumping into the true portion, you know, the regular top block.</p>



<p class="wp-block-paragraph">Now here we&#8217;re going to jump into the else portion.</p>



<p class="wp-block-paragraph">We need a label and some code for that.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">hectic in my brain here the copy pasting is worse than actually writing the program</p>



<p class="wp-block-paragraph">so uh if the comparison was not equal like if r12 was not equal then execution falls through</p>



<p class="wp-block-paragraph">to line 216 and then we unconditionally jump to the l6 begin area which is like down here</p>



<p class="wp-block-paragraph">like down here and then we&#8217;ll print something else.</p>



<p class="wp-block-paragraph">We&#8217;ll, oh, we&#8217;ll, we&#8217;ll check again.</p>



<p class="wp-block-paragraph">So we&#8217;re doing like, um, if else, if else.</p>



<p class="wp-block-paragraph">Okay. So originally when I was talking about the, uh,</p>



<p class="wp-block-paragraph">if else block, I didn&#8217;t do a,</p>



<p class="wp-block-paragraph">I didn&#8217;t do like a very complex if else statement.</p>



<p class="wp-block-paragraph">We&#8217;ll say a is greater than B something like that.</p>



<p class="wp-block-paragraph">So I&#8217;ll just put a more code here just so you know that we can do if else,</p>



<p class="wp-block-paragraph">if else blocks but just you know again keep in mind that every scope here that you&#8217;re going to</p>



<p class="wp-block-paragraph">try to run based on some condition you just make it its own label and make sure that at the very</p>



<p class="wp-block-paragraph">end of the scope you jump away so that you reach the very end of all this stuff because just as a</p>



<p class="wp-block-paragraph">quick review if we are just writing in c or c plus plus only one of these blocks is going to execute</p>



<p class="wp-block-paragraph">right like if a is equal to b then only that first block will execute the second and third blocks</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">know imagine there are more statements there and when that block is done then we will jump to line</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">six we jump if they were equal to the else if equals true block and if not execution falls</p>



<p class="wp-block-paragraph">Less than 10 begin block. So this is going to be like really complicated</p>



<p class="wp-block-paragraph">How many lines did I actually I think I got excited when I wrote this</p>



<p class="wp-block-paragraph">Okay, else if equal six true</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">All right, so we&#8217;re gonna do this I</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">Else if equals six true, okay</p>



<p class="wp-block-paragraph">equals six true okay so what&#8217;s happening here again um uh so at this point you know the first</p>



<p class="wp-block-paragraph">if uh expression was not true r12 was definitely not equal to five so we jumped down to else if</p>



<p class="wp-block-paragraph">equal six begin which was here and so then we just make another comparison to see well okay it was</p>



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



<p class="wp-block-paragraph">If it was false, we go down to line 237</p>



<p class="wp-block-paragraph">and jump to yet another scope.</p>



<p class="wp-block-paragraph">So here is what will get executed</p>



<p class="wp-block-paragraph">if R12 was indeed equal to six,</p>



<p class="wp-block-paragraph">and then we&#8217;re just basically gonna say it to the user</p>



<p class="wp-block-paragraph">and then jump to the done label,</p>



<p class="wp-block-paragraph">meaning like we&#8217;re totally done with our if else block.</p>



<p class="wp-block-paragraph">Notice how the first if here,</p>



<p class="wp-block-paragraph">when it was totally finished, it jumped to the done area.</p>



<p class="wp-block-paragraph">this else if block is also jumping down to the if done area.</p>



<p class="wp-block-paragraph">So eventually we&#8217;re going to need that label.</p>



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



<p class="wp-block-paragraph">So then next we&#8217;re going to check to see if the user&#8217;s input was equal to a 10.</p>



<p class="wp-block-paragraph">So like kind of the same thing here.</p>



<p class="wp-block-paragraph">We&#8217;re going to do another copy paste and we&#8217;re going to say, all right.</p>



<p class="wp-block-paragraph">So if the user&#8217;s input was not equal to, let&#8217;s see,</p>



<p class="wp-block-paragraph">if it was not equal to five, then we jump down here for our next comparison.</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">the less 10 begin line which is like all the way down here we do another comparison to see all right</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">Anyway, so if that statement is true, if R12 was indeed less than 10, then we jump to this block</p>



<p class="wp-block-paragraph">and we basically just say that to the user and then we jump to the done. So finally, notice how</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">an if five else if six else if less than 10 so maybe i could do something like this um if r12</p>



<p class="wp-block-paragraph">r12 I think I said six just now right hopefully I actually did say six</p>



<p class="wp-block-paragraph">otherwise if r12 is less than 10 then do some stuff otherwise if nothing else</p>



<p class="wp-block-paragraph">matched then we&#8217;ll execute you know this block right here so again remember</p>



<p class="wp-block-paragraph">every single scope has to have its own label so that you know where to jump and</p>



<p class="wp-block-paragraph">it&#8217;s also a really really smart idea for every single scope to have you know</p>



<p class="wp-block-paragraph">to have a little jump instruction that jumps past all of the if else if else if else stuff</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">blocks actually executes which is how you&#8217;re supposed to imagine c and c plus plus work</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">still see you know only one of these blocks ever is supposed to execute so we give the first one</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">to its scope if not we jump to the else and the else always executes if nothing else above</p>



<p class="wp-block-paragraph">was true so that&#8217;s the basic idea here oh dear i&#8217;ve probably lost my place</p>



<p class="wp-block-paragraph">looks like i just copy pasted less 10 true which was this right here so</p>



<p class="wp-block-paragraph">so um less than true or less than 10 true okay so we told the user your stuff is less than 10</p>



<p class="wp-block-paragraph">and then we jumped to the done area so that means we are probably working on the else area okay let</p>



<p class="wp-block-paragraph">me grab that so now finally we&#8217;re going to have the else area which is going to you know finish</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">nothing else matched then we will end up jumping to the else area and then we&#8217;ll basically</p>



<p class="wp-block-paragraph">just tell the user none of the conditions seemed to have applied and then even at the</p>



<p class="wp-block-paragraph">end of the else block even though you could probably get away with just letting execution</p>



<p class="wp-block-paragraph">fall through just to save yourself one instruction you know you could comment that out assuming</p>



<p class="wp-block-paragraph">you were sure that the very next instruction was the beginning of the done area but otherwise</p>



<p class="wp-block-paragraph">I&#8217;m just going to play it safe and jump directly there then we have to make the actual done</p>



<p class="wp-block-paragraph">So, just so you know, a label doesn&#8217;t have to have any instructions.</p>



<p class="wp-block-paragraph">We could have something like this, if else test say goodbye.</p>



<p class="wp-block-paragraph">We could have two labels right next to each other and one doesn&#8217;t actually have instructions.</p>



<p class="wp-block-paragraph">That&#8217;s totally fine.</p>



<p class="wp-block-paragraph">If you jumped to the done area, then execution would just fall through to the next valid</p>



<p class="wp-block-paragraph">instruction which could go through another label.</p>



<p class="wp-block-paragraph">So you know, we could have a say goodbye label and an if done label.</p>



<p class="wp-block-paragraph">if done label, I&#8217;m just going to have the goodbye stuff happening inside of the done.</p>



<p class="wp-block-paragraph">But for clarity&#8217;s sake, you might want to keep that label in there that I just deleted.</p>



<p class="wp-block-paragraph">And all that we need to do at the very end when we&#8217;re done with everything is just say goodbye.</p>



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



<p class="wp-block-paragraph">So just to do a quick recap here, let&#8217;s see.</p>



<p class="wp-block-paragraph">We come in with the user&#8217;s input as R12.</p>



<p class="wp-block-paragraph">We ask, does R12 equal five?</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">meaning we&#8217;ll skip past all the other blocks for the if-else block, or all the other scopes.</p>



<p class="wp-block-paragraph">But if that did not equal 5, then we&#8217;ll fall through to that jump instruction,</p>



<p class="wp-block-paragraph">which takes us to the next test, which is going to be our else-if equals 6.</p>



<p class="wp-block-paragraph">So we are checking now to see if R12 is equal to 6.</p>



<p class="wp-block-paragraph">If that&#8217;s true, we jump to this next block.</p>



<p class="wp-block-paragraph">Why do we need to jump to a block that&#8217;s so close?</p>



<p class="wp-block-paragraph">Well, if we don&#8217;t, then we&#8217;re going to end up definitely jumping to the next comparison</p>



<p class="wp-block-paragraph">and you know, that wouldn&#8217;t work.</p>



<p class="wp-block-paragraph">So we&#8217;re just kind of jumping over this unconditional jump statement and we&#8217;re saying, all right,</p>



<p class="wp-block-paragraph">your input was definitely equal to six.</p>



<p class="wp-block-paragraph">And then we&#8217;re jumping to the done area just past everything.</p>



<p class="wp-block-paragraph">But if that wasn&#8217;t true, then we hit this unconditional jump that takes us to the next</p>



<p class="wp-block-paragraph">comparison to see if the user&#8217;s input was less than 10.</p>



<p class="wp-block-paragraph">You know, if that&#8217;s true, then we go to the true area to print another message and then</p>



<p class="wp-block-paragraph">go to the done area.</p>



<p class="wp-block-paragraph">If it was false, we fall through to the else jump, which will take us to here.</p>



<p class="wp-block-paragraph">And notice how the else scope doesn&#8217;t actually make any comparisons because, you know, when</p>



<p class="wp-block-paragraph">you have like an if else, sorry, when you have an if else if else if else if, you know,</p>



<p class="wp-block-paragraph">any number of else if blocks, the else will always be executed if nothing above it actually</p>



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



<p class="wp-block-paragraph">execute so if you have an else block that means something will execute so we&#8217;re not doing any</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">area so all of these different scopes they&#8217;re jumping to the done area when they finish and</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">paste everything that i was supposed to i think so probably so let&#8217;s run the program and see if it</p>



<p class="wp-block-paragraph">All right, it at least compiled.</p>



<p class="wp-block-paragraph">So the basic if test, that was the first part of either this video or the previous video,</p>



<p class="wp-block-paragraph">depending on whether I chose to split this up.</p>



<p class="wp-block-paragraph">So let me comment out those calls real fast.</p>



<p class="wp-block-paragraph">So I&#8217;m going to just comment out these calls real quick so we can only deal with the complicated</p>



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



<p class="wp-block-paragraph">So I&#8217;m going to enter like a three.</p>



<p class="wp-block-paragraph">Whoops, let me do it again.</p>



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



<p class="wp-block-paragraph">And so begin the if else test.</p>



<p class="wp-block-paragraph">test your input was definitely less than 10 and then we end the if-else test so notice how only</p>



<p class="wp-block-paragraph">one scope executed three was definitely less than 10 what other numbers did we have let me write</p>



<p class="wp-block-paragraph">them down somewhere so I don&#8217;t forget oh they&#8217;re written down right here so we entered a three</p>



<p class="wp-block-paragraph">which was definitely not a five and not a six so that&#8217;s why the less than 10 block executed maybe</p>



<p class="wp-block-paragraph">only the first scope should execute so it says your input was equal to five notice how it didn&#8217;t</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">we have a six it will not mention the five it will not mention the ten so we did we did five</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">which was less than ten we can do anything that was less than ten and then the else would be if</p>



<p class="wp-block-paragraph">And then the else would be if our input is probably like 11 or greater,</p>



<p class="wp-block-paragraph">meaning it&#8217;s not less than 10 and it&#8217;s also not five or six.</p>



<p class="wp-block-paragraph">Just we can see the else block.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do 11, which is the first number that should trigger the else block.</p>



<p class="wp-block-paragraph">And it says no conditions were satisfied,</p>



<p class="wp-block-paragraph">which was the message inside of our else block.</p>



<p class="wp-block-paragraph">Let me just show you that again real fast.</p>



<p class="wp-block-paragraph">This was the else block.</p>



<p class="wp-block-paragraph">So message if else else or labeling on my port, I realize that.</p>



<p class="wp-block-paragraph">But it basically says no conditions were satisfied.</p>



<p class="wp-block-paragraph">The if else else.</p>



<p class="wp-block-paragraph">I think that&#8217;s basically everything that I wanted to show you.</p>



<p class="wp-block-paragraph">At this point, you should feel like you&#8217;re starting to become an expert at complicated</p>



<p class="wp-block-paragraph">if else if else blocks, converting those from a higher level language into assembly.</p>



<p class="wp-block-paragraph">assembly and I honestly recommend that you practice this like crazy while you&#8217;re trying</p>



<p class="wp-block-paragraph">to get more used to it but you know hopefully you have everything you need at this point</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">when we use these branching instructions notice how I have jump equal to where&#8217;s that less than</p>



<p class="wp-block-paragraph">yeah notice how I have a instruction jump less than the the family of conditional branching</p>



<p class="wp-block-paragraph">conditional branching instructions that compares less than greater than less than or equal to</p>



<p class="wp-block-paragraph">greater than or equal to the ones that I&#8217;m using here apply to signed integers and they won&#8217;t</p>



<p class="wp-block-paragraph">necessarily work with unsigned integers and they won&#8217;t work with floats if you compare floats later</p>



<p class="wp-block-paragraph">so just keep that in mind let me pull up my favorite book again real fast</p>



<p class="wp-block-paragraph">where what the heck is that book oh dude where&#8217;s my document viewer document viewer can I get</p>



<p class="wp-block-paragraph">document viewer can I get there there we go so I guess I didn&#8217;t introduce this</p>



<p class="wp-block-paragraph">book at the beginning of this video but I probably should have this is my</p>



<p class="wp-block-paragraph">favorite assembly book you can turn yourself into an expert with this book</p>



<p class="wp-block-paragraph">by just on its own it&#8217;s open source and free the author gives this away he&#8217;s a</p>



<p class="wp-block-paragraph">genius the person who wrote this book is a dr. Ed Jorgensen he&#8217;s a professor he</p>



<p class="wp-block-paragraph">wrote this for his own classes and again it&#8217;s like a free open source book you</p>



<p class="wp-block-paragraph">download a copy from his website if you look this up and and convert yourself</p>



<p class="wp-block-paragraph">into an expert so let me collapse everything here and then I&#8217;ll go to</p>



<p class="wp-block-paragraph">instruction set overview control instructions conditional control</p>



<p class="wp-block-paragraph">instructions and I just want you to see real fast just as a recap I talked about</p>



<p class="wp-block-paragraph">this in a previous video but when it comes to comparing things and checking</p>



<p class="wp-block-paragraph">operands because if you want to see if two operands are equal you just check to see if</p>



<p class="wp-block-paragraph">all of their bits are equal you don&#8217;t even really care whether they&#8217;re both integers or not</p>



<p class="wp-block-paragraph">on the other hand notice how there is like a family here jump less than jump less than equal</p>



<p class="wp-block-paragraph">to jump greater than jump greater than equal to that those instructions apply only if your</p>



<p class="wp-block-paragraph">if they are unsigned or if you&#8217;re using floats for your comparisons you have to use this other family</p>



<p class="wp-block-paragraph">of jump conditional branching instructions called jump below jump below equal jump above jump above</p>



<p class="wp-block-paragraph">equal and i&#8217;m sure you can infer that jump below is the same thing as jump less than right jump</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">a different instruction uh if you&#8217;re using signed integers or floats versus sorry sorry</p>



<p class="wp-block-paragraph">a versus sorry sorry you need to use different instructions if you&#8217;re using signed integers</p>



<p class="wp-block-paragraph">versus unsigned integers or floats so keep that in mind the code demo that i just showed you it&#8217;s</p>



<p class="wp-block-paragraph">for signed integers if you were going to use unsigned integers or floats you would this</p>



<p class="wp-block-paragraph">program wouldn&#8217;t work for you you&#8217;d need to replace my my branching instructions with the</p>



<p class="wp-block-paragraph">the unsigned versions which i mean they work the same thing you&#8217;re still going to do a comparison</p>



<p class="wp-block-paragraph">it still works. Anyway, so after having shown you that and making sure that everything actually</p>



<p class="wp-block-paragraph">did work, I think we&#8217;ve talked about everything that we need to for this video. So yeah, I hope</p>



<p class="wp-block-paragraph">you feel like an expert practice this on your own, you know, write your own programs just to make</p>



<p class="wp-block-paragraph">sure you know how to convert a higher level language block into an assembly block. And you</p>



<p class="wp-block-paragraph">should be on your way. Thank you for watching this video. I hope you learned a little bit of</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really</p>



<p class="wp-block-paragraph">appreciate it i do hope you did learn something and have some fun uh if you could do me a please</p>



<p class="wp-block-paragraph">a small little favor could you please subscribe and follow this channel or these videos or whatever</p>



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



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



<p class="wp-block-paragraph">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 class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



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



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



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



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



<p class="wp-block-paragraph">just wake me up in the middle of the night just subscribe and then I&#8217;ll just wake up I promise</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">QR code which you can scan in order to go to the website which I think is also named somewhere at</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">all the videos I published and the services and tutorials and things that I offer and all that</p>



<p class="wp-block-paragraph">for clarifications or errata or just future videos that you want to see please leave a comment or if</p>



<p class="wp-block-paragraph">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 class="wp-block-paragraph">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 class="wp-block-paragraph">it would really it really mean the world to me I would really appreciate it so again thank you so</p>



<p class="wp-block-paragraph">much for watching this video and enjoy the cool music as as I fade into the darkness which is</p>



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/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 Bit Manipulation: AND, OR, XOR, NOT, Shifts &#038; Rotates Tutorial</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 29 Dec 2025 08:55:41 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[AND OR XOR]]></category>
		<category><![CDATA[arithmetic shift]]></category>
		<category><![CDATA[assembly language tutorial]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[bit manipulation]]></category>
		<category><![CDATA[bit rotation]]></category>
		<category><![CDATA[bit shifting]]></category>
		<category><![CDATA[bitwise operations]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[gdb debugging]]></category>
		<category><![CDATA[logical shift]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[two's complement]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=272</guid>

					<description><![CDATA[<p>Learn bitwise operations in x86-64 assembly language including AND, OR, XOR, NOT, logical and arithmetic shifts, and bit rotations with practical examples and GDB debugging.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/">x86-64 Assembly Bit Manipulation: AND, OR, XOR, NOT, Shifts &amp; Rotates Tutorial</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 Bit Manipulation: AND, OR, XOR, NOT, Shifts &amp; Rotates Tutorial" width="1380" height="776" src="https://www.youtube.com/embed/N8Nciq6l5IU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">In this hands-on tutorial, we dive into bit manipulation in x86-64 assembly using Yasm on Ubuntu. We cover the basics of logical operations like AND, OR, XOR, and NOT, then move into shifting (logical vs arithmetic), rotating bits, and why signed vs unsigned matters for shifts.</p>



<p class="wp-block-paragraph">I explain each concept on paper first, then show real code examples running in GDB to prove how the bits change. We look at patterns in registers, see what happens with negative numbers in two&#8217;s complement, and even touch on how shifts can multiply or divide by powers of 2.</p>



<p class="wp-block-paragraph">Perfect if you&#8217;re learning low-level programming, reverse engineering, or just curious about how bits work under the hood. No prior assembly knowledge needed, but it&#8217;ll help if you&#8217;ve seen my other videos.</p>



<p class="wp-block-paragraph">Like and subscribe for more assembly tutorials!</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



<p class="wp-block-paragraph">In this video, we&#8217;re going to talk all about manipulating bits in x86-64 Yasm assembly within</p>



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



<p class="wp-block-paragraph">But if you&#8217;re not using Yasm or you&#8217;re not on Ubuntu, this video is probably going to</p>



<p class="wp-block-paragraph">be pretty useful to you anyway, because I&#8217;m going to talk about the basic concept of manipulating</p>



<p class="wp-block-paragraph">bits in various ways.</p>



<p class="wp-block-paragraph">We&#8217;re going to talk about some basic logical operators like ANDing, ORing, XORing, and</p>



<p class="wp-block-paragraph">XORing, and then we&#8217;re going to talk about shifting the bits to the left and the right,</p>



<p class="wp-block-paragraph">and then we&#8217;re going to talk about the difference between shifting without any respect for whether</p>



<p class="wp-block-paragraph">the number inside of the bits is an actual integer, or whether we just consider them</p>



<p class="wp-block-paragraph">to just be bits by themselves, or whether we&#8217;re actually respecting the bits as numbers,</p>



<p class="wp-block-paragraph">and also we&#8217;re going to look at the rotation instruction.</p>



<p class="wp-block-paragraph">So first I&#8217;m going to explain this, I&#8217;m going to write it down in a pad, and then I&#8217;m going</p>



<p class="wp-block-paragraph">show you a program that actually does it just so we can prove that it all works.</p>



<p class="wp-block-paragraph">Okay, so for starters, let me open up a little notepad here.</p>



<p class="wp-block-paragraph">What the heck am I even talking about? Let me write this down because I forgot this on my</p>



<p class="wp-block-paragraph">first take I spent like five minutes, blew right past the explanation of and and or and xor because</p>



<p class="wp-block-paragraph">I forgot that that was supposed to be part of this video. We&#8217;re going to look at and or and xor</p>



<p class="wp-block-paragraph">at least for now and then we&#8217;re going to look at shifting and then we&#8217;re going to look at rotating.</p>



<p class="wp-block-paragraph">at rotating. Okay so first off what is anding? I&#8217;ve explained that in another video but long</p>



<p class="wp-block-paragraph">story short and just requires that two bits that you&#8217;re comparing against each other are both a one</p>



<p class="wp-block-paragraph">in order to receive a one and so any other pair like a zero versus a one or one versus a zero or</p>



<p class="wp-block-paragraph">two zeros are just going to be a zero. So and means both bits that you&#8217;re comparing have to be a one</p>



<p class="wp-block-paragraph">The OR is pretty easy.</p>



<p class="wp-block-paragraph">If either of the bits is a 1, then the result is going to be 1.</p>



<p class="wp-block-paragraph">So if I say 1 versus 1, the result is going to be 1.</p>



<p class="wp-block-paragraph">If I say 0 versus 1, the result is going to be a 1.</p>



<p class="wp-block-paragraph">Or if I say 1 versus 0, the result is going to be a 1.</p>



<p class="wp-block-paragraph">In the only case where you end up with a 0, it&#8217;s just going to be 0 versus 0 results in a 0.</p>



<p class="wp-block-paragraph">To upgrade to exclusive OR, basically exactly 1 bit needs to be a 1.</p>



<p class="wp-block-paragraph">bit needs to be a one and if two or zero are a one then the result is a zero which means here when</p>



<p class="wp-block-paragraph">we have the two ones at the top the answer is going to be a zero these are the two stay the</p>



<p class="wp-block-paragraph">same and this one stays the same so that&#8217;s xor again i have another video where i explain this</p>



<p class="wp-block-paragraph">a little bit better but i&#8217;m just doing like a quick overview shifting is pretty interesting</p>



<p class="wp-block-paragraph">because let me do a pattern let&#8217;s say zero one one zero suppose we just have four bits</p>



<p class="wp-block-paragraph">to the left or to the right. So imagine left, if I shift them to the left, then what I&#8217;m really</p>



<p class="wp-block-paragraph">doing is I&#8217;m just taking off that zero on the end and padding on the right with a zero. And then if</p>



<p class="wp-block-paragraph">I&#8217;m shifting to the right, then well, it&#8217;s to the right. I&#8217;m just going to, you know, take off,</p>



<p class="wp-block-paragraph">let&#8217;s see the zero on the right side and pad with the zero on the left. Be careful though, because</p>



<p class="wp-block-paragraph">or logical shifting. I haven&#8217;t actually shifted with respect to the original number. Think</p>



<p class="wp-block-paragraph">about this. That number right there on line three, if we just consider that an unsigned</p>



<p class="wp-block-paragraph">integer or just bits, then what I just did with the shifting is fine. But what if that</p>



<p class="wp-block-paragraph">was a two&#8217;s complement number that can represent a signed integer? If it&#8217;s two&#8217;s complement</p>



<p class="wp-block-paragraph">or if it&#8217;s just like a signed integer, then the leftmost bit being a zero tells me that</p>



<p class="wp-block-paragraph">result of my left shift, there&#8217;s a one now in that first position, which tells me that&#8217;s</p>



<p class="wp-block-paragraph">probably a negative number.</p>



<p class="wp-block-paragraph">We could face a similar problem with shifting to the right.</p>



<p class="wp-block-paragraph">I mean, we didn&#8217;t this time.</p>



<p class="wp-block-paragraph">It just looks like it actually shifted and the answer is going to end up being right.</p>



<p class="wp-block-paragraph">But what if we shifted something else right?</p>



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



<p class="wp-block-paragraph">One, one, zero, zero.</p>



<p class="wp-block-paragraph">What if I shifted that number one to the right?</p>



<p class="wp-block-paragraph">The answer would be zero, you know, one, one, zero, right?</p>



<p class="wp-block-paragraph">you know 110 right but then that&#8217;s wrong because the original number was negative because there&#8217;s</p>



<p class="wp-block-paragraph">a one in the first position but the result is a zero so if i&#8217;m not careful about what instructions</p>



<p class="wp-block-paragraph">i&#8217;m using and how to respect whether the number i&#8217;m shifting is actually considered an integer</p>



<p class="wp-block-paragraph">assigned integer or if it&#8217;s just bits if i don&#8217;t respect that then i could end up ruining the</p>



<p class="wp-block-paragraph">number so keep that in mind we&#8217;re going to do several examples of that i&#8217;m not going to show</p>



<p class="wp-block-paragraph">shift by hand I&#8217;m just going to show you what the instructions in the assembler</p>



<p class="wp-block-paragraph">will do so then the other thing that we should talk about is rotating so imagine</p>



<p class="wp-block-paragraph">that I rotate this number one to the right well nothing really happens</p>



<p class="wp-block-paragraph">visually but what you&#8217;re supposed to do if we rotate to the right you take the</p>



<p class="wp-block-paragraph">number on the very right side and you just pop it onto the front so it sort of</p>



<p class="wp-block-paragraph">it doesn&#8217;t fall off and get replaced by a zero or get replaced by a one depending</p>



<p class="wp-block-paragraph">moves to the other side so if I shift this again maybe let&#8217;s shift it one more</p>



<p class="wp-block-paragraph">time to the right I&#8217;m gonna take that one and pop it off the right side and</p>



<p class="wp-block-paragraph">put it on the very front so see do you see how there it&#8217;s kind of rotating I do</p>



<p class="wp-block-paragraph">this one more time actually let me copy paste this I&#8217;ll take that number on the</p>



<p class="wp-block-paragraph">right side pop it off put it back on the front then if I do it again take that</p>



<p class="wp-block-paragraph">zero pop it off put it back on the front notice how it eventually gets back to</p>



<p class="wp-block-paragraph">the original pattern and I would have to rotate you know exactly four times to</p>



<p class="wp-block-paragraph">to get that to happen same same thing applies for rotating to the left i&#8217;m not going to show you</p>



<p class="wp-block-paragraph">because uh it&#8217;s it&#8217;s the same thing as rotating to the right just in a different direction</p>



<p class="wp-block-paragraph">one thing that i forgot to say a moment ago when i was talking about shifting is uh think about this</p>



<p class="wp-block-paragraph">if we shift to the right pretend that uh we don&#8217;t really care that much let&#8217;s let me put some extra</p>



<p class="wp-block-paragraph">zeros here so that we don&#8217;t have to carry too much we don&#8217;t have to care too much about what&#8217;s</p>



<p class="wp-block-paragraph">happening with positive or negative. If you know how to convert to binary, which I&#8217;ve explained in</p>



<p class="wp-block-paragraph">other videos, then you&#8217;ll know this number is, let&#8217;s see, there&#8217;s a one and a two, and then these</p>



<p class="wp-block-paragraph">positions are four and eight. So this should be a 12, right? If I shift this to the right,</p>



<p class="wp-block-paragraph">I should be dividing this by two because the base of binary is two. So every time you kind of like</p>



<p class="wp-block-paragraph">move to the left in terms of what digit you&#8217;re looking at, you&#8217;re increasing the power of that</p>



<p class="wp-block-paragraph">every time you move to the right you&#8217;re decreasing the power of the digit by two</p>



<p class="wp-block-paragraph">so that means if I shift the entire thing to the right I should be dividing the whole thing by two</p>



<p class="wp-block-paragraph">right not just one bit so if I just take a zero off of there and put it on there I&#8217;ve now shifted</p>



<p class="wp-block-paragraph">all the bits shifted all the bits one to the right I should end up with the six let&#8217;s just</p>



<p class="wp-block-paragraph">compute what it is there&#8217;s a one there and there&#8217;s a two there and there&#8217;s a four there what&#8217;s four</p>



<p class="wp-block-paragraph">plus two that&#8217;s six so this is actually six in binary or the original number divided by two</p>



<p class="wp-block-paragraph">because we shifted to the right on the other hand if I take this number one more time and</p>



<p class="wp-block-paragraph">just kind of shift it to the left I should multiply it by two so that means I should</p>



<p class="wp-block-paragraph">expect to see a 24 let me just remove one of those zeros and put it on the right side there</p>



<p class="wp-block-paragraph">this is not a rotation I&#8217;m just kind of like filling in zeros I&#8217;m keeping it simple with</p>



<p class="wp-block-paragraph">the shifted number this is a 1, a 2, and a 4 again if you don&#8217;t know how to convert</p>



<p class="wp-block-paragraph">from binary to decimal or back see my other videos so then we basically have</p>



<p class="wp-block-paragraph">an 8 here and a 16 what&#8217;s 8 plus 16 that&#8217;s 24 24 is twice of 12 so we have</p>



<p class="wp-block-paragraph">multiplied by 2 so you could multiply by 4 by shifting twice multiply by 8 by</p>



<p class="wp-block-paragraph">shifting 3 times you know whatever you want to do but shifting is is like a</p>



<p class="wp-block-paragraph">is like a shortcut besides just to move the bits it&#8217;s also a shortcut to multiply and divide by two</p>



<p class="wp-block-paragraph">okay so that&#8217;s the basic idea let me start working on a little program here for you before I continue</p>



<p class="wp-block-paragraph">I just want you to know that my program it&#8217;s got stuff in it already we&#8217;ve got a make file here</p>



<p class="wp-block-paragraph">if I uh I edit the make file I just have a make file set up to build the program so again this</p>



<p class="wp-block-paragraph">is specific to just you know bits we&#8217;re not going to talk about make files see my other videos if</p>



<p class="wp-block-paragraph">you want to know how to make your own make file same thing for this gdb.txt file I&#8217;ve just put</p>



<p class="wp-block-paragraph">commands that I&#8217;m going to send to gdb my debugger of choice this is not a gdb video I haven&#8217;t</p>



<p class="wp-block-paragraph">actually made my gdb video yet so look out for that in this in the somewhat near future</p>



<p class="wp-block-paragraph">so we&#8217;re just going to focus on the actual program for now anyway so I&#8217;ve got a solution</p>



<p class="wp-block-paragraph">Anyway, so I&#8217;ve got a solution already set up here.</p>



<p class="wp-block-paragraph">Let me start copy pasting some stuff in there.</p>



<p class="wp-block-paragraph">Going to copy paste my data section.</p>



<p class="wp-block-paragraph">So first off,</p>



<p class="wp-block-paragraph">my sample program is just gonna have codes for writing,</p>



<p class="wp-block-paragraph">you know, with the system call</p>



<p class="wp-block-paragraph">and exiting with the system call.</p>



<p class="wp-block-paragraph">And then I&#8217;m gonna output to standard output</p>



<p class="wp-block-paragraph">and I&#8217;m gonna do a zero return code.</p>



<p class="wp-block-paragraph">If you don&#8217;t know that,</p>



<p class="wp-block-paragraph">see my other videos that I&#8217;ve already put out.</p>



<p class="wp-block-paragraph">I&#8217;m gonna make a sample string where I just say,</p>



<p class="wp-block-paragraph">I just say hello my name is Gibson Montgomery Gibson that&#8217;s not my name but I love those names</p>



<p class="wp-block-paragraph">I&#8217;m just going to say hello basically when the program starts then I have some bit strings here</p>



<p class="wp-block-paragraph">that will help me with the you know help me demonstrate some of the bitwise operations</p>



<p class="wp-block-paragraph">the ending and the oring and the shifting and whatever and then I&#8217;m going to put a negative</p>



<p class="wp-block-paragraph">number here as a variable just to prove to you that sometimes the bitwise or logical shifting</p>



<p class="wp-block-paragraph">break a number if the number is supposed to actually be assigned integer and and use that</p>



<p class="wp-block-paragraph">as evidence for why you should use arithmetic shifting so now I&#8217;m going to start my program</p>



<p class="wp-block-paragraph">here let&#8217;s see my entry point should start at line 30 I got to be super careful about this</p>



<p class="wp-block-paragraph">because if I don&#8217;t know 26 if I don&#8217;t then all of my debug statements are going to have to be</p>



<p class="wp-block-paragraph">it lined up correctly so i&#8217;m basically just going to print the hello message and then maybe you know</p>



<p class="wp-block-paragraph">what at the very end i&#8217;m going to exit from the system with a system call so basically if we run</p>



<p class="wp-block-paragraph">this program again system calls and everything like that are not part of this video see my other</p>



<p class="wp-block-paragraph">videos but uh if this works we should see just like a simple message okay so that&#8217;s it my name</p>



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



<p class="wp-block-paragraph">So then the next thing that I&#8217;m going to do is I&#8217;m going to show you a bitwise</p>



<p class="wp-block-paragraph">and operation. So I&#8217;m going to copy paste that should start on line 42.</p>



<p class="wp-block-paragraph">And if I get this wrong, the debugging is going to be awful.</p>



<p class="wp-block-paragraph">I was trying to make this a pure assembly program without a bunch of extra work.</p>



<p class="wp-block-paragraph">I guess I could have linked GCC so I could just print results to the terminal,</p>



<p class="wp-block-paragraph">but whatever too late now. So it starts on 42.</p>



<p class="wp-block-paragraph">and ends on 51 okay so I think that&#8217;s good so the instruction for ending doing</p>



<p class="wp-block-paragraph">a logical and between two registers which are full of bits and then what</p>



<p class="wp-block-paragraph">will happen is every bit gets anded against its own course or I guess the</p>



<p class="wp-block-paragraph">corresponding bit in the other other register is just and so what I&#8217;m doing</p>



<p class="wp-block-paragraph">first is I&#8217;m gonna set up the registers so I&#8217;m gonna move the a sequence which</p>



<p class="wp-block-paragraph">sequence, which if you look up is just, you know, I put a bunch of bits. So like in hex,</p>



<p class="wp-block-paragraph">I like to type hex more than binary when I&#8217;m just kind of putting stuff in there.</p>



<p class="wp-block-paragraph">So, you know, each F is basically four ones. So it&#8217;s going to be like, I guess, 16 ones,</p>



<p class="wp-block-paragraph">and then a bunch of zeros, and then, you know, a few ones, and then some zeros and ones.</p>



<p class="wp-block-paragraph">So I&#8217;m just making a little pattern for bits A. Don&#8217;t think that they mean anything right now.</p>



<p class="wp-block-paragraph">And I&#8217;m going to make a different pattern with bits B. And when we look into the debugger,</p>



<p class="wp-block-paragraph">And when we look into the debugger, we should see the before and after patterns so we can kind of see what the AND instruction did.</p>



<p class="wp-block-paragraph">So I&#8217;m going to move bits A and bits B into R10 and R11.</p>



<p class="wp-block-paragraph">Then I&#8217;m going to move, so these are going to be like the original bits that we can inspect later.</p>



<p class="wp-block-paragraph">this AND instruction against R11 which is the B pattern. So I&#8217;m basically taking the A pattern</p>



<p class="wp-block-paragraph">and I&#8217;m ANDing it against the B pattern but I&#8217;m also loading up the registers so we can see</p>



<p class="wp-block-paragraph">the A pattern then the B pattern and then the result of ANDing them together.</p>



<p class="wp-block-paragraph">Finally on line 50 here I&#8217;m using a NOPE which is just a non-operation so that I can easily</p>



<p class="wp-block-paragraph">break the debugger so we can sort of inspect the program and see what&#8217;s going on inside of there.</p>



<p class="wp-block-paragraph">program and see what&#8217;s going on inside of there. You know what, let me, uh, let me open this up</p>



<p class="wp-block-paragraph">again here so that I can control where I&#8217;m breaking. So 48 is where the nope is. That&#8217;s</p>



<p class="wp-block-paragraph">totally wrong. I&#8217;ve already ruined my program somehow. It&#8217;s going to be 50, I guess. All right,</p>



<ol start="50" class="wp-block-list">
<li>And what I&#8217;m doing inside of this, and again, this is not a GDB video. I&#8217;m just saying,</li>
</ol>



<p class="wp-block-paragraph">let&#8217;s break at line 50 so I can kind of poke around. And I&#8217;m going to comment all these</p>



<p class="wp-block-paragraph">And I&#8217;m going to comment all these things out for now.</p>



<p class="wp-block-paragraph">That&#8217;s going to happen at the very end.</p>



<p class="wp-block-paragraph">It&#8217;s going to be majestic.</p>



<p class="wp-block-paragraph">How many different things we can look at.</p>



<p class="wp-block-paragraph">So I&#8217;m telling GDB not to execute any of these instructions, except for the, uh,</p>



<p class="wp-block-paragraph">the break point instructions.</p>



<p class="wp-block-paragraph">So we can just break on line 50.</p>



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



<p class="wp-block-paragraph">Hopefully this works.</p>



<p class="wp-block-paragraph">I&#8217;m going to now use make debug, which under the hood is just going to be compiling and</p>



<p class="wp-block-paragraph">then telling GDB to launch with the name of my program inside of it.</p>



<p class="wp-block-paragraph">And then to execute those things.</p>



<p class="wp-block-paragraph">and then to execute those things.</p>



<p class="wp-block-paragraph">So it hits breakpoint number 50.</p>



<p class="wp-block-paragraph">There&#8217;s a bunch of crap that gets printed.</p>



<p class="wp-block-paragraph">And I can now inspect my registers.</p>



<p class="wp-block-paragraph">I&#8217;m going to go info R for just info registers.</p>



<p class="wp-block-paragraph">And let&#8217;s see.</p>



<p class="wp-block-paragraph">So we had R10, 11, and 12.</p>



<p class="wp-block-paragraph">So if we look at the terminal, you can see that R10, the hex version,</p>



<p class="wp-block-paragraph">has the original pattern of the A sequence,</p>



<p class="wp-block-paragraph">and then R11 has the original pattern of the B sequence.</p>



<p class="wp-block-paragraph">original pattern of the b sequence if we do a logical and and put the result into r12 then</p>



<p class="wp-block-paragraph">you should see let me just double check that that&#8217;s definitely r12 yeah then you should see</p>



<p class="wp-block-paragraph">the result of ending all of the f&#8217;s together remember that an f is just four ones so i&#8217;m kind</p>



<p class="wp-block-paragraph">of simplifying it a little bit you could make yours more complicated with lots of randomness</p>



<p class="wp-block-paragraph">in your ones and zeros just to prove it to yourself but notice how r12 only has an f</p>



<p class="wp-block-paragraph">So like FF means F, F0 means 0, F0 means 0, you know, and so forth.</p>



<p class="wp-block-paragraph">0F means 0.</p>



<p class="wp-block-paragraph">So only where you see two Fs will you see an F in the final target pattern.</p>



<p class="wp-block-paragraph">So that&#8217;s a logical AND, and that&#8217;s how you do it in Yasm Assembly.</p>



<p class="wp-block-paragraph">You just load up a register with some bits, R12.</p>



<p class="wp-block-paragraph">We loaded them up with the first pattern.</p>



<p class="wp-block-paragraph">And then we take the second pattern and say that&#8217;s what I want to AND it against.</p>



<p class="wp-block-paragraph">that&#8217;s what I want to end it against. And you can have that in a register or I think an immediate</p>



<p class="wp-block-paragraph">or a memory location. So we&#8217;re just ending these registers together. And you know that they&#8217;re</p>



<p class="wp-block-paragraph">loaded up with patterns A and B. So nothing too hard at this point. Let&#8217;s do a, let&#8217;s look at</p>



<p class="wp-block-paragraph">bitwise or this should start on line 52 or I&#8217;m screwing myself. 52. Okay. 52. So same thing,</p>



<p class="wp-block-paragraph">up R10 and R11 with the bit patterns and then we&#8217;re going to move the first bit pattern</p>



<p class="wp-block-paragraph">into R12 so that we can or it against the second pattern and so basically R10 and 11</p>



<p class="wp-block-paragraph">will have the original bit patterns R12 will have the result of oring them.</p>



<p class="wp-block-paragraph">Then we&#8217;ll do a nope on line 60 so I want to break here on line 60.</p>



<p class="wp-block-paragraph">Yep I ruined all my line numbers. What did I do wrong? I think I just have it offset by 2 now</p>



<p class="wp-block-paragraph">two now for some reason so if we just kind of run the program now in the debugger again i&#8217;m going to</p>



<p class="wp-block-paragraph">quit and then yes if we clear and make debug probably clear was unnecessary we&#8217;re broken at</p>



<p class="wp-block-paragraph">line 60 if i say info registers the registers in question are oh shoot um 10 11 and 12 right so</p>



<p class="wp-block-paragraph">we look at 10 and 11 they have the same pattern as before and 12 has a lot more f&#8217;s because if</p>



<p class="wp-block-paragraph">has a lot more F&#8217;s because if either of the patterns had an F,</p>



<p class="wp-block-paragraph">then the resulting pattern would have an F.</p>



<p class="wp-block-paragraph">So this is a logical OR.</p>



<p class="wp-block-paragraph">Same idea as AND in terms of the way you format the instruction and the OPS,</p>



<p class="wp-block-paragraph">but it ORs instead of ANDs.</p>



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



<p class="wp-block-paragraph">Let&#8217;s move on.</p>



<p class="wp-block-paragraph">Next thing I want to show you is the XOR, which is pretty cool.</p>



<p class="wp-block-paragraph">By the way, so far we&#8217;re just operating on bits.</p>



<p class="wp-block-paragraph">We don&#8217;t consider these bits to actually be numbers.</p>



<p class="wp-block-paragraph">maybe they are but we should probably be careful about that anyway so I&#8217;m going to say let&#8217;s check</p>



<p class="wp-block-paragraph">out our bitwise xor which is exclusive or which means exactly one bit in any pair needs to be a</p>



<p class="wp-block-paragraph">one for the resulting bit to be a one and of course per usual all bits will be checked against each</p>



<p class="wp-block-paragraph">other in the pair of of bit patterns it&#8217;ll be one bit at a time from each pattern that gets checked</p>



<p class="wp-block-paragraph">Okay, so it starts on 62 and then we got a nope there.</p>



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



<p class="wp-block-paragraph">So same thing that we did before.</p>



<p class="wp-block-paragraph">We&#8217;re just loading up two registers with the bit patterns and then R12 is going to be the</p>



<p class="wp-block-paragraph">result of exclusive oring or X oring the two bit patterns.</p>



<p class="wp-block-paragraph">So that means we&#8217;re going to break on line 70.</p>



<p class="wp-block-paragraph">Now, let me just get rid of my other break point, change that 68 to a 70.</p>



<p class="wp-block-paragraph">And now I should quit.</p>



<p class="wp-block-paragraph">bug we&#8217;re at 70 good info registers so I think we said it was 10 and 11 had the original bit patterns</p>



<p class="wp-block-paragraph">and notice the resulting bit pattern it only has an f in a position where there was exactly</p>



<p class="wp-block-paragraph">one f between the two input patterns so</p>



<p class="wp-block-paragraph">wait did I just do something wrong here what did I just do wrong</p>



<p class="wp-block-paragraph">hang on a second I&#8217;m seeing something bad x or r12 am I looking at r12</p>



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



<p class="wp-block-paragraph">R10 and 11.</p>



<p class="wp-block-paragraph">Did I just do something wrong?</p>



<p class="wp-block-paragraph">10 and 11 and then we load 10 up into 12 and then we XOR it by 11 and then it stores it</p>



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



<p class="wp-block-paragraph">Something&#8217;s a little fishy here.</p>



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



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



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



<p class="wp-block-paragraph">Oh, I understand now.</p>



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



<p class="wp-block-paragraph">So that was a little scary.</p>



<p class="wp-block-paragraph">This has shifted because the printout is not great.</p>



<p class="wp-block-paragraph">Because the printout is not great. See how there&#8217;s like a blank space here?</p>



<p class="wp-block-paragraph">That threw me off. So you have to imagine that all of the bit patterns are kind of shifted.</p>



<p class="wp-block-paragraph">Maybe I should just copy paste this.</p>



<p class="wp-block-paragraph">I was worried that I suddenly didn&#8217;t know how to do an XOR in assembly.</p>



<p class="wp-block-paragraph">So let me get rid of these integers here.</p>



<p class="wp-block-paragraph">Notice how there&#8217;s just a blank space that shifted everything and threw it off in terms of the display.</p>



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



<p class="wp-block-paragraph">And what should really happen now is that there should be a zero here.</p>



<p class="wp-block-paragraph">A zero at the front.</p>



<p class="wp-block-paragraph">a zero at the front now everything would make more sense sometimes the display likes to just</p>



<p class="wp-block-paragraph">kind of truncate things and just assume that everything will be read correctly but it wasn&#8217;t</p>



<p class="wp-block-paragraph">so notice uh in the first position both of the uh both the input patterns are are an f so the</p>



<p class="wp-block-paragraph">output pattern will be a zero you can imagine under the hood there was a bunch of ones and</p>



<p class="wp-block-paragraph">then a bunch of ones and that resulted in a bunch of zeros uh here we&#8217;ve got like an f and a zero so</p>



<p class="wp-block-paragraph">the result is going to be an f and then f and a zero and after zero zero and an f is an f</p>



<p class="wp-block-paragraph">f um and then where you see zeros that means uh there was not exactly one uh one in each bit</p>



<p class="wp-block-paragraph">position so for the let&#8217;s say the first one that&#8217;s a bunch of zeros for both input patterns so that&#8217;s</p>



<p class="wp-block-paragraph">why there&#8217;s a zero there then for the next two each of them had all ones or just the two f&#8217;s</p>



<p class="wp-block-paragraph">uh so that&#8217;s why x or says it&#8217;s a zero and so forth right so like at the end two f&#8217;s making</p>



<p class="wp-block-paragraph">Okay, that was a little scary.</p>



<p class="wp-block-paragraph">I&#8217;m glad I figured that out quickly instead of taking a million years.</p>



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



<p class="wp-block-paragraph">So now let&#8217;s do another example.</p>



<p class="wp-block-paragraph">We&#8217;re done with XOR.</p>



<p class="wp-block-paragraph">Now let&#8217;s look at bitwise knot.</p>



<p class="wp-block-paragraph">I forgot to explain knot.</p>



<p class="wp-block-paragraph">I&#8217;m not going to redo this video.</p>



<p class="wp-block-paragraph">But let me just say that a knot is just inverting the bit.</p>



<p class="wp-block-paragraph">So if we have a zero, it becomes a one.</p>



<p class="wp-block-paragraph">And if we have a one, it becomes a zero.</p>



<p class="wp-block-paragraph">If you knot against a register that has lots of bits or a memory location that has lots</p>



<p class="wp-block-paragraph">of bits, you can do that and just every single bit in the sequence will just be flipped from</p>



<p class="wp-block-paragraph">a zero to a one or vice versa.</p>



<p class="wp-block-paragraph">So let&#8217;s see, we just did bitwise XOR.</p>



<p class="wp-block-paragraph">Now we&#8217;re going to do a knot starting on line 72, I guess.</p>



<p class="wp-block-paragraph">And then we&#8217;re going to do another nope there.</p>



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



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



<p class="wp-block-paragraph">So now let&#8217;s get rid of the break point at the line 70 and put it at line 78 instead.</p>



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



<p class="wp-block-paragraph">Oh man, this video is going to take forever.</p>



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



<p class="wp-block-paragraph">So now let&#8217;s check out bitwise knot.</p>



<p class="wp-block-paragraph">We&#8217;re going to have R10.</p>



<p class="wp-block-paragraph">Oh, I guess I should improve this because what I&#8217;m doing is I&#8217;m moving everything into</p>



<p class="wp-block-paragraph">everything into R10 and then I&#8217;m just nodding R10 so we can&#8217;t really compare R10 against itself.</p>



<p class="wp-block-paragraph">That&#8217;s not fun. Let me instead move R10 into R11 so that I can nod R11 so that we can</p>



<p class="wp-block-paragraph">see two different registers at least. Okay, so let me just update my solution real fast.</p>



<p class="wp-block-paragraph">move r11 r10 okay so now it stops at 75 and that one stops at 75 okay cool</p>



<p class="wp-block-paragraph">now we got our breakpoint should be at line 79 not 78 now we&#8217;re ready to run it and see what the</p>



<p class="wp-block-paragraph">does clear and make debug info registers so we should have r10 r11 again the formatting is a</p>



<p class="wp-block-paragraph">so I&#8217;m just going to copy paste it up here. I&#8217;m going to do this, get rid of the numbers,</p>



<p class="wp-block-paragraph">pad on the left for the missing zeros, and then now you can see clearly that all of the</p>



<p class="wp-block-paragraph">F&#8217;s were flipped to zero. Again, that means, you know, each F had four ones inside of it,</p>



<p class="wp-block-paragraph">so all those ones were flipped to a zero, so that&#8217;s why it&#8217;s a zero. Okay, so nodding, pretty easy,</p>



<p class="wp-block-paragraph">this and show the next example which was gonna be let&#8217;s see seven let&#8217;s check out bitwise rotation</p>



<p class="wp-block-paragraph">i&#8217;m going to copy paste all the way up to that nope there should start on line 81</p>



<p class="wp-block-paragraph">i paused before i took a drink of water hopefully i reminded myself later to edit the drink of water</p>



<p class="wp-block-paragraph">out i don&#8217;t know maybe you&#8217;ll be wondering why my mustache is wet right now if i did not edit it out</p>



<p class="wp-block-paragraph">I did not edit it out.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s check out bitwise rotation.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna set up R10 and 11 and 12 and 13 and 14,</p>



<p class="wp-block-paragraph">all with the A pattern.</p>



<p class="wp-block-paragraph">And then I&#8217;m gonna start rotating things.</p>



<p class="wp-block-paragraph">So first I&#8217;m gonna rotate to the left R11 and then R12.</p>



<p class="wp-block-paragraph">I&#8217;m gonna rotate by one position on R11</p>



<p class="wp-block-paragraph">and then two positions on R12.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to rotate</p>



<p class="wp-block-paragraph">rotate by one position for R13 and then two positions for R14 so we should see</p>



<p class="wp-block-paragraph">some interesting patterns. The NOPE is now on line 94 so I&#8217;m gonna break there</p>



<p class="wp-block-paragraph">instead whoops so I&#8217;m gonna change that and I&#8217;m now off by three it&#8217;s getting</p>



<p class="wp-block-paragraph">precarious and then I&#8217;m gonna uncomment all of my little print statements to</p>



<p class="wp-block-paragraph">show you the value of the registers after I rotate it so we should see like</p>



<p class="wp-block-paragraph">printed in the terminal just to prove to you what&#8217;s going to happen okay so man I got to</p>



<p class="wp-block-paragraph">remember what&#8217;s happening now first thing that I did was I printed r10 to show you one type of</p>



<p class="wp-block-paragraph">rotation and then I printed r10 again to show you another type of rotation so we should see the</p>



<p class="wp-block-paragraph">original and then the two rotated values and then the original again and then the other two rotated</p>



<p class="wp-block-paragraph">values so here&#8217;s the original we&#8217;re printing it in binary with the special print command in gdb</p>



<p class="wp-block-paragraph">in GDB, which is just like P slash T and then the register. So this is the original pattern</p>



<p class="wp-block-paragraph">right here. And if you just kind of squint at it for a while, you can realize that the dollar</p>



<p class="wp-block-paragraph">sign two pattern has been, uh, shifted once to the left. Actually, let me just make sure that</p>



<p class="wp-block-paragraph">I&#8217;m doing a shift and not a rotate. I&#8217;m accidentally saying the word, uh, rotate, I think. And, uh,</p>



<p class="wp-block-paragraph">that&#8217;s, oh no, no, it is rotate. Yeah. We&#8217;re going to shift later, I guess.</p>



<p class="wp-block-paragraph">I guess. Okay, so we are definitely rotating. So we should see some wrap around. I guess I used</p>



<p class="wp-block-paragraph">bad bit patterns for the wrap around. But just imagine that, you know, in this pattern right here,</p>



<p class="wp-block-paragraph">this one, if we&#8217;re rotating to the left, this one fell off and it got placed on the right side of</p>



<p class="wp-block-paragraph">of the next pattern it&#8217;s going to be the same thing basically so but this is rotation so we</p>



<p class="wp-block-paragraph">wouldn&#8217;t be reusing the bits that fell off but anyway you can see that if I rotated to the left</p>



<p class="wp-block-paragraph">by one position that whole thing is is kind of shifted to the left I shouldn&#8217;t use the word shift</p>



<p class="wp-block-paragraph">and then for the second pattern we did a rotation by two positions so all the bits are just kind of</p>



<p class="wp-block-paragraph">moved to the left compared to the very first pattern okay so no problem then the next thing</p>



<p class="wp-block-paragraph">that we&#8217;re looking at is just you know rotating to the right and you can tell that everything is</p>



<p class="wp-block-paragraph">offset by one here and it&#8217;s offset by two here so rotating to the left by one position by two</p>



<p class="wp-block-paragraph">positions rotating to the right by one position or by two positions that&#8217;s rotation in a nutshell</p>



<p class="wp-block-paragraph">okay so then the next thing that we&#8217;re going to do we&#8217;re on 94 now</p>



<p class="wp-block-paragraph">um let&#8217;s see logical shifting nope nope nope I&#8217;m gonna grab some code that will shift both</p>



<p class="wp-block-paragraph">logically and arithmetically so we can kind of see the difference</p>



<p class="wp-block-paragraph">okay so show maybe I should change this to show some some shifting</p>



<p class="wp-block-paragraph">because uh if I just say it&#8217;s logical then yeah sure uh the shift function uh the shift</p>



<p class="wp-block-paragraph">those are logical shifts but then down here when it&#8217;s a sal and sar those are arithmetic shifts</p>



<p class="wp-block-paragraph">I don&#8217;t know maybe maybe I can do that maybe I can just</p>



<p class="wp-block-paragraph">duplicate the comment maybe to make it more more intuitive so show arithmetic shifts</p>



<p class="wp-block-paragraph">Okay, I think that looks pretty good. Let me paste that into 105 on my solution so I don&#8217;t get out of sync here.</p>



<p class="wp-block-paragraph">So what&#8217;s going to happen here? We&#8217;re basically going to load up R10 with a negative number.</p>



<p class="wp-block-paragraph">I&#8217;ve chosen the number negative 12 because I kind of feel like it at least shows you a little bit for dividing and stuff like that.</p>



<p class="wp-block-paragraph">So we&#8217;re loading up R10 with a negative number, and then R11 is going to get R10, but then we&#8217;re going to shift it left by two positions.</p>



<p class="wp-block-paragraph">positions so that should be multiplying it by four but this is well a bitwise</p>



<p class="wp-block-paragraph">shifting so it it&#8217;s not going to necessarily respect the fact that the</p>



<p class="wp-block-paragraph">number is in twos complement so this is not a good idea if you consider r tend</p>



<p class="wp-block-paragraph">to be a number because sometimes the result might be right and sometimes the</p>



<p class="wp-block-paragraph">result might be wrong here it says math won&#8217;t work in my comment but sometimes</p>



<p class="wp-block-paragraph">it will accidentally work but you still want to consider it to be non-working</p>



<p class="wp-block-paragraph">It&#8217;s only good for bit shifting.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to put R12, we&#8217;re going to give it the same value as R10 and then we&#8217;re</p>



<p class="wp-block-paragraph">just going to shift it to the right by two positions.</p>



<p class="wp-block-paragraph">This will definitely break because when you shift to the right, the sine bit is going</p>



<p class="wp-block-paragraph">to get padded with a zero rather than what the actual sine bit was originally.</p>



<p class="wp-block-paragraph">So that will almost certainly break it almost every time.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to use arithmetic shifts which just respect the fact that the original</p>



<p class="wp-block-paragraph">number is two&#8217;s complement.</p>



<p class="wp-block-paragraph">two&#8217;s complement so you know like we have this negative 12 number it&#8217;s going to end up being</p>



<p class="wp-block-paragraph">bits but the uh the shl and the shr instructions are not going to respect the fact that it&#8217;s</p>



<p class="wp-block-paragraph">negative 12 they&#8217;re just going to consider them to be bits but the sal shifting to the left</p>



<p class="wp-block-paragraph">arithmetically and the sar shifting to the right arithmetically are going to respect that respect</p>



<p class="wp-block-paragraph">the fact that it&#8217;s two&#8217;s complement so let&#8217;s see we&#8217;ve got all this stuff and then we&#8217;ve got a</p>



<p class="wp-block-paragraph">We&#8217;ve got all this stuff and then we&#8217;ve got a non-operation here.</p>



<p class="wp-block-paragraph">You know, again, like per usual, when we&#8217;re shifting, when we&#8217;re rotating, when we&#8217;re</p>



<p class="wp-block-paragraph">oaring, anding, whatever, it&#8217;s just the instruction name followed by both the source and the</p>



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



<p class="wp-block-paragraph">And then the second operand is only going to be source.</p>



<p class="wp-block-paragraph">So if we have a shifting left R11, then the result is going to be stored in R11, but it&#8217;s</p>



<p class="wp-block-paragraph">going to take as the source R11 and shift it to the left by two positions.</p>



<p class="wp-block-paragraph">to the left by two positions and so forth.</p>



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



<p class="wp-block-paragraph">So we have all of that.</p>



<p class="wp-block-paragraph">We&#8217;re going to nope on line one of what is it?</p>



<p class="wp-block-paragraph">One, one 14.</p>



<p class="wp-block-paragraph">So that means I&#8217;m going to stop breaking on 94 and I&#8217;m going to break on one 14.</p>



<p class="wp-block-paragraph">I thought it was four lines off and now I&#8217;m only two lines off.</p>



<p class="wp-block-paragraph">I think I just did something else wrong here between my source.</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">Is the nope on one 14 up there?</p>



<p class="wp-block-paragraph">Yeah, it is.</p>



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



<p class="wp-block-paragraph">Guess I didn&#8217;t do that much wrong.</p>



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



<p class="wp-block-paragraph">Okay, so let&#8217;s run this, but this code up here was just going to print bit patterns</p>



<p class="wp-block-paragraph">related to our rotations.</p>



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



<p class="wp-block-paragraph">So I&#8217;m going to uncomment all of these other prints that relate to our shifts.</p>



<p class="wp-block-paragraph">And this is going to be a nightmare to read and interpret, but I&#8217;m going to try.</p>



<p class="wp-block-paragraph">I really should have written a more complicated program that can just print them in the terminal</p>



<p class="wp-block-paragraph">so I don&#8217;t have to like read the debugger.</p>



<p class="wp-block-paragraph">Whatever, it&#8217;s brain exercise.</p>



<p class="wp-block-paragraph">size. And I think this actually is the end of the program. 119 is the last line. Yeah. Okay.</p>



<p class="wp-block-paragraph">So we just need to run this and see what happens. So really we&#8217;re interested in these, uh, you know,</p>



<p class="wp-block-paragraph">shifting to the left twice, shifting to the right twice bit wise, and then shifting to the left</p>



<p class="wp-block-paragraph">twice, arithmetically shifting to the right twice, arithmetically. Okay. So we&#8217;ll go back to the</p>



<p class="wp-block-paragraph">terminal here and quit. And then I&#8217;m going to do make debug. And now there&#8217;s a bunch of junk.</p>



<p class="wp-block-paragraph">here&#8217;s the original number and then we&#8217;re gonna bitwise shift left binary</p>



<p class="wp-block-paragraph">notice how it just sort of you know it shifted everything to the left and you</p>



<p class="wp-block-paragraph">know we&#8217;re not using we&#8217;re not printing hex anymore because I want you to see</p>



<p class="wp-block-paragraph">the binary and then you know like the patterns are just shifted to to the left</p>



<p class="wp-block-paragraph">like see here&#8217;s the first one if we&#8217;re looking at the right side and then here</p>



<p class="wp-block-paragraph">is the first one if we&#8217;re looking at the right side for the shifted version</p>



<p class="wp-block-paragraph">A similar deal for shift right except we lost a couple of numbers there because of the display</p>



<p class="wp-block-paragraph">so I&#8217;m going to copy paste both of these real fast.</p>



<p class="wp-block-paragraph">Per usual we lost numbers due to the display so I&#8217;m going to say notice how we have two</p>



<p class="wp-block-paragraph">numbers missing here if I added zeros on the right side that&#8217;s going to change the actual</p>



<p class="wp-block-paragraph">value so I&#8217;m going to have to add them to the left and now we can clearly see that the</p>



<p class="wp-block-paragraph">shifted four positions I think to the left wait did I do that where did I where did I even just</p>



<p class="wp-block-paragraph">copy paste from original shift left and shift right okay so shift right is what it&#8217;s supposed</p>



<p class="wp-block-paragraph">to be doing let me just double check here shift right is printing r12 and what does r12 have it</p>



<p class="wp-block-paragraph">shifting right by two. Okay.</p>



<p class="wp-block-paragraph">Oh, I&#8217;m supposed to compare it to the very first one.</p>



<p class="wp-block-paragraph">Let me just double check that I have this correct now.</p>



<p class="wp-block-paragraph">Why is it</p>



<p class="wp-block-paragraph">shifting to the right? Oh gosh, I think I just lost track of myself. Let me just,</p>



<p class="wp-block-paragraph">give me a second here. Or 14.</p>



<p class="wp-block-paragraph">I&#8217;m forgetting where I copy and paste. Okay. Bitwise shift right is</p>



<p class="wp-block-paragraph">bitwise shift right is R12, not R14. Oh gosh. Did I do it wrong? Were you cringing at home?</p>



<p class="wp-block-paragraph">Maybe this will work. And the two, that&#8217;s kind of the same thing that I did before. No, no,</p>



<p class="wp-block-paragraph">it&#8217;s different. Okay. So I had it wrong before. Now I finally have it right. So you can see that</p>



<p class="wp-block-paragraph">So you can see that the bit pattern is shifted twice to the right and then on the left two zeros show up which would have destroyed a number.</p>



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



<p class="wp-block-paragraph">So we shift it to the right and now we&#8217;re ready to look at arithmetic shift to the left and right.</p>



<p class="wp-block-paragraph">And let&#8217;s see do we have enough bits to actually print everything?</p>



<p class="wp-block-paragraph">This one should look like it&#8217;s shifted to the right just because of the way it prints.</p>



<p class="wp-block-paragraph">So that means this one is totally lined up.</p>



<p class="wp-block-paragraph">Okay so let me grab the original pattern here.</p>



<p class="wp-block-paragraph">grab the original pattern here so this is the original pattern and then if I go shift left</p>



<p class="wp-block-paragraph">in binary I&#8217;ll just put an L here and then I&#8217;ll put shift right in binary</p>



<p class="wp-block-paragraph">there we have enough bits I think in both cases so we don&#8217;t have to pad</p>



<p class="wp-block-paragraph">so now if we look at the original pattern and then we shift left arithmetically twice</p>



<p class="wp-block-paragraph">twice notice how it does kind of look like it survived right like this one moved over to the</p>



<p class="wp-block-paragraph">left twice because the sine bits are just kind of falling off but there&#8217;s enough of them that it&#8217;s</p>



<p class="wp-block-paragraph">not going to change the sine bit thank you two&#8217;s complement but when we shift to the right</p>



<p class="wp-block-paragraph">arithmetically normally we would have padded on the left with zeros remember we had zeros there</p>



<p class="wp-block-paragraph">on the left before but now that we&#8217;re respecting the arithmetic uh the the padding is correct now</p>



<p class="wp-block-paragraph">is correct now for two&#8217;s complement so that&#8217;s why there are ones there instead of zeros</p>



<p class="wp-block-paragraph">and then if you kind of look at it it&#8217;s like well we shifted twice to the right let me get</p>



<p class="wp-block-paragraph">rid of the left because we already understand that now it seems to be that the pattern is uh</p>



<p class="wp-block-paragraph">every bit is shifted over to the right the correct number of times the zeros dropped off the side</p>



<p class="wp-block-paragraph">and um the sine bits were padded on the left so everything seems to be correct and then just to</p>



<p class="wp-block-paragraph">to kind of prove to you that what we&#8217;re seeing is real, I just have the same things printed</p>



<p class="wp-block-paragraph">all over again from scratch in decimal. So originally we had our R10 as negative 12.</p>



<p class="wp-block-paragraph">And then if we do a bitwise shift to the left, it multiplies it by four. And so we&#8217;re accidentally</p>



<p class="wp-block-paragraph">correct here. Remember, this is a bitwise shift, so it doesn&#8217;t respect two&#8217;s complement. So just,</p>



<p class="wp-block-paragraph">we happen to have a starting number that would end up looking correct after we shifted it to the left.</p>



<p class="wp-block-paragraph">And then when we do a bitwise shift to the right, again, this could be disaster because we&#8217;re not</p>



<p class="wp-block-paragraph">respecting two&#8217;s complement or the sine bit. And that&#8217;s exactly what happened. You know, definitely</p>



<p class="wp-block-paragraph">if we&#8217;re shifting to the right, that should be 12 divided by four equals three or negative three.</p>



<p class="wp-block-paragraph">But instead we get this gigantic huge number because the sine bit got killed with the zeros</p>



<p class="wp-block-paragraph">killed with the zeros that were padded on the left. And then we finally try to shift left</p>



<p class="wp-block-paragraph">arithmetically. We end up still with negative 48, which is the correct number. If we&#8217;re going to</p>



<p class="wp-block-paragraph">shift left twice, that&#8217;s multiplying 12 by 4 and that&#8217;s 48 or negative 48. And then when we shift</p>



<p class="wp-block-paragraph">to the right, that should divide it by 2 twice because we&#8217;re shifting to the right by two</p>



<p class="wp-block-paragraph">positions. So that should be 12 divided by 4, which is negative 3 or sorry, negative 12 divided</p>



<p class="wp-block-paragraph">which is negative three so everything seems to be working except for a couple of moments of</p>



<p class="wp-block-paragraph">stumbling on my part which i hope you laughed at um and i think this is the end of the program so</p>



<p class="wp-block-paragraph">now hopefully you&#8217;re an expert in uh ending oring x oring nodding shifting left and right uh bitwise</p>



<p class="wp-block-paragraph">rotating. We&#8217;ve done it all in this one video. How long did this video take? 40 minutes?</p>



<p class="wp-block-paragraph">Anyway, thank you so much for watching this video. I hope you learned a little bit of stuff</p>



<p class="wp-block-paragraph">and you had a little bit of fun. I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">Hey everybody, thanks for watching this video again from the bottom of my heart. I really</p>



<p class="wp-block-paragraph">appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p class="wp-block-paragraph">and follow this channel or these videos or whatever it is you do on the current social</p>



<p class="wp-block-paragraph">media website that you&#8217;re looking at right now. It would really mean the world to me and it&#8217;ll</p>



<p class="wp-block-paragraph">help make more videos and grow this community. So we&#8217;ll be able to do more videos, longer videos,</p>



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



<p class="wp-block-paragraph">and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



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



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



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



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



<p class="wp-block-paragraph">at the middle of the screen right now you should see a QR code which you can</p>



<p class="wp-block-paragraph">scan in order to go to the website which I think is also named somewhere at the</p>



<p class="wp-block-paragraph">bottom of this video and it&#8217;ll take you to my main website where you can just</p>



<p class="wp-block-paragraph">kind of like see all the videos I published and the services and tutorials</p>



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



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



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



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



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



<p class="wp-block-paragraph">I get I wake up in a cold sweat. I&#8217;m like</p>



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



<p class="wp-block-paragraph">Again, thank you so much for watching this video and enjoy the cool music as I fade into the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/">x86-64 Assembly Bit Manipulation: AND, OR, XOR, NOT, Shifts &amp; Rotates Tutorial</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-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Signed Integer Division in x86-64 Assembly with IDIV and CQO</title>
		<link>https://www.NeuralLantern.com/signed-integer-division-in-x86-64-assembly-with-idiv-and-cqo/</link>
					<comments>https://www.NeuralLantern.com/signed-integer-division-in-x86-64-assembly-with-idiv-and-cqo/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 14 Dec 2025 09:12:38 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[64-bit assembly]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[assembly language programming]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[cqo instruction]]></category>
		<category><![CDATA[idiv instruction]]></category>
		<category><![CDATA[integer division assembly]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[rax rdx division]]></category>
		<category><![CDATA[signed division]]></category>
		<category><![CDATA[ubuntu assembly programming]]></category>
		<category><![CDATA[x86 assembly]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=266</guid>

					<description><![CDATA[<p>Step-by-step tutorial on performing signed integer division in x86-64 assembly language using the IDIV instruction and CQO for sign extension. Includes complete working Yasm code on Ubuntu/Linux.</p>
<p>The post <a href="https://www.NeuralLantern.com/signed-integer-division-in-x86-64-assembly-with-idiv-and-cqo/">Signed Integer Division in x86-64 Assembly with IDIV and CQO</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="Signed Integer Division in x86-64 Assembly with IDIV and CQO" width="1380" height="776" src="https://www.youtube.com/embed/axasPyjJFAA?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">In this video, I walk through how to perform signed integer division in x86-64 assembly language using Yasm on Ubuntu/Linux.</p>



<p class="wp-block-paragraph">We focus on 64-bit signed integers and the IDIV instruction. I explain the setup: loading the dividend into RAX, using CQO for proper sign extension into RDX, loading the divisor, and executing IDIV. After division, the quotient ends up in RAX and the remainder in RDX.</p>



<p class="wp-block-paragraph">I reference the excellent free book &#8220;x86-64 Assembly Language Programming with Ubuntu&#8221; and show practical code examples, including a complete working program that prints both the quotient and remainder.</p>



<p class="wp-block-paragraph">We test with small numbers (256 / 233) and larger ones to see it in action. I also touch on the difference between signed (IDIV) and unsigned (DIV) division, and why CQO is needed for correct sign handling.</p>



<p class="wp-block-paragraph">Perfect for anyone learning low-level programming, assembly language, or wanting to understand how integer division really works under the hood.</p>



<p class="wp-block-paragraph">Introduction to Signed Division 00:00:00<br>Referencing the Assembly Book 00:00:28<br>IDIV Instruction Overview 00:01:16<br>Dividend and Divisor Setup 00:01:24<br>Sign Extension and CQO 00:04:18<br>Quotient and Remainder Results 00:04:40<br>Setting Up the Program 00:05:13<br>Data Section and Strings 00:06:22<br>Function Prologue and Preservation 00:09:20<br>Loading the Dividend into RAX 00:10:00<br>Sign Extension with CQO 00:11:24<br>Loading the Divisor 00:12:36<br>Performing IDIV 00:14:19<br>Saving Quotient and Remainder 00:16:48<br>Printing the Results 00:17:20<br>Running and Testing the Program 00:18:51<br>Testing Larger Numbers 00:19:48<br>Returning the Remainder 00:21:42<br>Signed vs Unsigned Division 00:23:48<br>Conclusion and Thanks 00:25:02</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



<p class="wp-block-paragraph">In this video, I&#8217;d like to talk to you about dividing signed integers in an x86-64 Yasm</p>



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



<p class="wp-block-paragraph">I&#8217;m going to be focusing on 64-bit integers and I&#8217;m going to use an instruction called</p>



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



<p class="wp-block-paragraph">Okay, so for starters, I just want to give you an overview of the process.</p>



<p class="wp-block-paragraph">I&#8217;m going to use an awesome book that I love to reference.</p>



<p class="wp-block-paragraph">awesome book that i love to reference i did not write this book the book is titled x86 64 assembly</p>



<p class="wp-block-paragraph">language programming with ubuntu i mention it in a lot of other videos the author here</p>



<p class="wp-block-paragraph">is a genius and this book is open source and freely available so go look it up get yourself a</p>



<p class="wp-block-paragraph">copy and become an assembly expert too anyway so what i&#8217;m going to do is go into this book</p>



<p class="wp-block-paragraph">instruction set overview and then inside of that i&#8217;m going to click on 7.5 integer arithmetic</p>



<p class="wp-block-paragraph">instructions or arithmetic i don&#8217;t know whatever you prefer to say it as but and then i&#8217;m going to</p>



<p class="wp-block-paragraph">go inside of there and i&#8217;m going to click on 754 integer division so you know the basic idea for</p>



<p class="wp-block-paragraph">dividing integers in a yasm assembly program on x86 64 is just to load up your dividend you know</p>



<p class="wp-block-paragraph">top portion I guess that is the numerator and then the divisor which</p>



<p class="wp-block-paragraph">would be the denominator with separate registers so load up the dividend with a</p>



<p class="wp-block-paragraph">register or put the dividend into a register and then put the divisor into</p>



<p class="wp-block-paragraph">another register they&#8217;re going to be special registers we&#8217;re going to be</p>



<p class="wp-block-paragraph">using the A and D registers you can kind of see that at the bottom already and</p>



<p class="wp-block-paragraph">then once that&#8217;s set up properly you just sort of use the IDIV function or</p>



<p class="wp-block-paragraph">instruction and there&#8217;s another instruction we can use to make things a</p>



<p class="wp-block-paragraph">little bit more simple because if you kind of notice what what this is saying</p>



<p class="wp-block-paragraph">here it&#8217;s saying that the the dividend usually needs to be stacked between two</p>



<p class="wp-block-paragraph">other registers at the same time and that&#8217;s a little bit confusing</p>



<p class="wp-block-paragraph">especially if these registers right here notice how a DX colon ax that means it</p>



<p class="wp-block-paragraph">16-bit versions of two different registers just sort of like pushed up against each other so</p>



<p class="wp-block-paragraph">Obviously if you know how to manipulate bits which I&#8217;m gonna do other videos for in the future</p>



<p class="wp-block-paragraph">Then you could do that with any size, but just I&#8217;m gonna make the easiest example that I can here. I</p>



<p class="wp-block-paragraph">Love this line. I just found it today</p>



<p class="wp-block-paragraph">As always division by zero will crash the program and damage the space-time continuum. So try not to divide by zero. I love it</p>



<p class="wp-block-paragraph">nifty little table inside of the book that sort of shows you how you&#8217;re supposed to set up the</p>



<p class="wp-block-paragraph">numerator and denominator or the divisor what was the other word that they used dividend and divisor</p>



<p class="wp-block-paragraph">i usually say numerator and denominator anyway so remember in in if you watched my previous videos</p>



<p class="wp-block-paragraph">then you&#8217;ll know that we have smaller versions of our registers like for example uh this eax right</p>



<p class="wp-block-paragraph">here that&#8217;s actually the rax register but it&#8217;s only about half of it uh half of those bytes are</p>



<p class="wp-block-paragraph">half of those bytes are being ignored so all of these different versions that you&#8217;re seeing are</p>



<p class="wp-block-paragraph">just different sizes of the a and d registers so i&#8217;m going to go to the simplest example here and</p>



<p class="wp-block-paragraph">just kind of show you that basically what they&#8217;re trying to do is force you to have a numerator that</p>



<p class="wp-block-paragraph">is bigger than the denominator that way it&#8217;s guaranteed you&#8217;ll have some kind of a quotient</p>



<p class="wp-block-paragraph">or you know more likely that you&#8217;ll have some kind of a quotient and and a remainder that kind of</p>



<p class="wp-block-paragraph">that kind of makes sense because if you divide a number that&#8217;s much smaller than</p>



<p class="wp-block-paragraph">the denominator then you&#8217;ll just end up with zero remainder the original number</p>



<p class="wp-block-paragraph">pretty much in integer division this video is not about float division float</p>



<p class="wp-block-paragraph">division is more precise so in other words if I want to divide something by a</p>



<p class="wp-block-paragraph">64-bit integer then I need to first set up a 128-bit integer and that means I</p>



<p class="wp-block-paragraph">and that means I have to take two 64-bit integers, the D register and the A register.</p>



<p class="wp-block-paragraph">I have to load both of those registers up with 64 bits each so that when you imagine them being combined,</p>



<p class="wp-block-paragraph">it&#8217;s a 128-bit register or 128-bit value.</p>



<p class="wp-block-paragraph">Once I have something that is sufficiently large, then I can divide it by something else.</p>



<p class="wp-block-paragraph">Then the result will show up in the A and D registers.</p>



<p class="wp-block-paragraph">the actual quotient, you know, the actual result of dividing without a fractional part at the end,</p>



<p class="wp-block-paragraph">just, you know, truncated data. Then the remainder will be in the D register, the RDX register. So at</p>



<p class="wp-block-paragraph">least for this form, I just want you to know you can do it with all these other forms if you want</p>



<p class="wp-block-paragraph">to. But in this example, I&#8217;m just going to take 128 bits, divide it by 64 bits, and then I&#8217;ll get</p>



<p class="wp-block-paragraph">So that&#8217;s the basic idea. Here&#8217;s some sample code in the book. I love it. It&#8217;s wonderful.</p>



<p class="wp-block-paragraph">But I&#8217;m going to go ahead and start writing my own program now.</p>



<p class="wp-block-paragraph">Okay, so I got a solution up here. I&#8217;m going to just copy paste my data section and explain it briefly.</p>



<p class="wp-block-paragraph">Okay, so here is, oh, maybe I should first say, here&#8217;s a sample program that I&#8217;m using.</p>



<p class="wp-block-paragraph">You don&#8217;t have to worry too much about what&#8217;s actually inside of it.</p>



<p class="wp-block-paragraph">The C module and the make file, they&#8217;re standard stuff that I usually use in all of my videos.</p>



<p class="wp-block-paragraph">all of my videos this is not a make file video see my other videos if you want to learn how to</p>



<p class="wp-block-paragraph">make your own make files but long story short i&#8217;m just going to type you know make run in order to</p>



<p class="wp-block-paragraph">just get this program to run and then for the c program i&#8217;m compiling a hybrid program so i mean</p>



<p class="wp-block-paragraph">it&#8217;s just easier for me to just kind of get started this way so i have my main entry point sitting</p>



<p class="wp-block-paragraph">inside of a c source code file that gets compiled and linked into my main program and it just calls</p>



<p class="wp-block-paragraph">a function called math right here which is just going to be you know this source code right here</p>



<p class="wp-block-paragraph">so if you want to make hybrid programs you want to learn the basics of assembly you want to learn</p>



<p class="wp-block-paragraph">anything that i&#8217;m not really talking about in this video see my other videos</p>



<p class="wp-block-paragraph">for today or for this video it&#8217;s just going to be integer division anyway i&#8217;m going to paste in</p>



<p class="wp-block-paragraph">some starter code here for my math module i&#8217;ve got a data section and i&#8217;ve got some strings</p>



<p class="wp-block-paragraph">strings or anything but just keep in mind I&#8217;m going to eventually print the division result</p>



<p class="wp-block-paragraph">quotient is and then I&#8217;m going to actually print it and then I&#8217;m going to print the division</p>



<p class="wp-block-paragraph">remainder is and then actually print it so I&#8217;m just I&#8217;m just setting up strings to make my</p>



<p class="wp-block-paragraph">results look a little bit prettier that&#8217;s all I&#8217;m really doing crlf that&#8217;s just new line stuff</p>



<p class="wp-block-paragraph">system calls here&#8217;s the system service code for writing to something writing to a file or standard</p>



<p class="wp-block-paragraph">standard output again that&#8217;s in another video file descriptor one another video and then return</p>



<p class="wp-block-paragraph">value I&#8217;m just choosing to return the number seven from this module I don&#8217;t know why I just</p>



<p class="wp-block-paragraph">I like to reuse code and I&#8217;m not going to change it and then we&#8217;re going to take two different</p>



<p class="wp-block-paragraph">integers here and uh 56 and oh I think in my starter code I actually hard-coded those numbers</p>



<p class="wp-block-paragraph">after everything is working so um i&#8217;m going to start my text section here by just copy pasting</p>



<p class="wp-block-paragraph">a little thing that says okay here&#8217;s where my code is going to go now all my instructions</p>



<p class="wp-block-paragraph">and then uh here&#8217;s my entry point which is just my function called math you want to write functions</p>



<p class="wp-block-paragraph">see my other videos but this is basically it you just kind of have something enter and then return</p>



<p class="wp-block-paragraph">from it when you&#8217;re done and if you mess up any registers you have to preserve them with push and</p>



<p class="wp-block-paragraph">you have to preserve them with push and pop pairs.</p>



<p class="wp-block-paragraph">Another thing that I&#8217;m going to add that I&#8217;m not going to explain in this video</p>



<p class="wp-block-paragraph">is I&#8217;m going to do calls to one of my own personal libraries.</p>



<p class="wp-block-paragraph">And basically I&#8217;m just going to mark two functions as external.</p>



<p class="wp-block-paragraph">They&#8217;re sitting in a shared object that I made.</p>



<p class="wp-block-paragraph">Don&#8217;t worry about that. This video is not about printing.</p>



<p class="wp-block-paragraph">It&#8217;s just about dividing. But I want to be able to easily print.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to use that library.</p>



<p class="wp-block-paragraph">So don&#8217;t worry about that.</p>



<p class="wp-block-paragraph">for this video is my function called divide test because notice how in the entry point of math</p>



<p class="wp-block-paragraph">remember the c module the driver it calls on this math function the math function eventually or</p>



<p class="wp-block-paragraph">immediately calls on divide test and so here&#8217;s the prototype basically for my divide test function</p>



<p class="wp-block-paragraph">I&#8217;m just going to say it&#8217;s void takes no arguments that way it can just do everything by itself</p>



<p class="wp-block-paragraph">as a little demo and it&#8217;s a little bit easier so that means I don&#8217;t really need to preserve any</p>



<p class="wp-block-paragraph">I am using them and if you see here well I guess if it was going to take arguments you don&#8217;t need</p>



<p class="wp-block-paragraph">to preserve the argument register so I should have just said yeah we are going to use some</p>



<p class="wp-block-paragraph">registers and therefore we&#8217;re going to preserve them so our 12 14 and 15 oh why am I not using</p>



<p class="wp-block-paragraph">13 I must have erased that at an earlier date whatever we&#8217;re going to use these three registers</p>



<p class="wp-block-paragraph">make this an official function and because I know I&#8217;m going to use r12 14 and 15 I&#8217;m just going to</p>



<p class="wp-block-paragraph">preserve them with a push pop pair so I&#8217;m going to say this is the prologue whoops and I&#8217;m going to</p>



<p class="wp-block-paragraph">push r12 push r14 push r15 respect the abi if you don&#8217;t other pro other parts of the program</p>



<p class="wp-block-paragraph">will probably crash epilogue is just popping all those in reverse order so that I can basically</p>



<p class="wp-block-paragraph">basically preserve them for the caller.</p>



<p class="wp-block-paragraph">Okay, so now we&#8217;re good with all our registers.</p>



<p class="wp-block-paragraph">Next thing I want to do is I want to load up, let&#8217;s see,</p>



<p class="wp-block-paragraph">I want to load up RAX with a number.</p>



<p class="wp-block-paragraph">Now maybe I&#8217;ll fix this right now.</p>



<p class="wp-block-paragraph">What was 256?</p>



<p class="wp-block-paragraph">It was the my integer B.</p>



<p class="wp-block-paragraph">So I&#8217;m going to hit main memory,</p>



<p class="wp-block-paragraph">which is a little slower than using an immediate,</p>



<p class="wp-block-paragraph">but hey, it&#8217;s more flexible.</p>



<p class="wp-block-paragraph">but hey it&#8217;s more flexible and so basically i&#8217;m going to set up rax which is the numerator if we</p>



<p class="wp-block-paragraph">go back to the book real fast if our intention is to divide a 128 bit uh uh like combined register</p>



<p class="wp-block-paragraph">by a 64 bit something then uh well rax is the lower 64 bit so that&#8217;s why i&#8217;m loading that up</p>



<p class="wp-block-paragraph">first i&#8217;m just saying well i&#8217;ve got 64 bits worth of stuff a quad word worth of stuff sitting in</p>



<p class="wp-block-paragraph">so i&#8217;m just going to load that into rax then i just have to somehow take care of rdx so obviously</p>



<p class="wp-block-paragraph">if you wanted to you could just you know take rdx and just set a bunch of zeros to it but that</p>



<p class="wp-block-paragraph">would probably only work if you were guaranteed that rax was a positive number so that its sign</p>



<p class="wp-block-paragraph">bit was zero at the very left if it was a negative number its sign bit would be a one at the very</p>



<p class="wp-block-paragraph">And that wouldn&#8217;t be very good if RDX plus RAX, you know, lined up are supposed to be a negative number because you would want ones all the way through to RDX.</p>



<p class="wp-block-paragraph">So there&#8217;s a special instruction we can use called CQO.</p>



<p class="wp-block-paragraph">I&#8217;m just going to paste that in here just to make things a little bit easier because I&#8217;m really trying to divide a 64-bit integer by something.</p>



<p class="wp-block-paragraph">The system wants a 128-bit integer.</p>



<p class="wp-block-paragraph">basically this instruction right here CQO whoops what happened how come it&#8217;s not lined up</p>



<p class="wp-block-paragraph">CQO basically just takes RAX whatever is in there and stretches it onto the 128 bit combination of</p>



<p class="wp-block-paragraph">RDX colon RAX so remember when you see this kind of thing remember when you see RDX colon RAX or</p>



<p class="wp-block-paragraph">just like a register colon another register that&#8217;s usually telling you that the system will think of</p>



<p class="wp-block-paragraph">in a combined way as one longer register so that&#8217;s really what it is cqo is going to say</p>



<p class="wp-block-paragraph">let&#8217;s look at rex and let&#8217;s uh you know fix it up and then also fix up uh rdx so that when they&#8217;re</p>



<p class="wp-block-paragraph">combined they make sense as just one number um and you know that that would work pretty easily</p>



<p class="wp-block-paragraph">like i said before if it was a positive number but not necessarily in all cases so we&#8217;ll just use</p>



<p class="wp-block-paragraph">is, let&#8217;s see, set up the denominator. So let&#8217;s see, here, I&#8217;m going to say set up denominator.</p>



<p class="wp-block-paragraph">And you know, we can hard code the 233 there, but I think I&#8217;ve already decided,</p>



<p class="wp-block-paragraph">let&#8217;s just use variables. So the A, I think has 233. Where the heck&#8217;s my A? There we go.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say my integer A. And here I&#8217;m going to put the pointer to the A variable,</p>



<p class="wp-block-paragraph">to the a variable and then i&#8217;m going to dereference it and um oh one thing that we have to remember is</p>



<p class="wp-block-paragraph">when the system is using your registers like rax here it knows rax is the 64-bit form of the a</p>



<p class="wp-block-paragraph">register so if you use different forms of your register then it knows how many bits you want</p>



<p class="wp-block-paragraph">like for example here we just kind of go back up uh this eax that&#8217;s still the a register but the e</p>



<p class="wp-block-paragraph">that it&#8217;s a you know 32 bits instead of 64 bits but there&#8217;s no there&#8217;s no way for</p>



<p class="wp-block-paragraph">the system to really know that that memory location is 64 bits how does it</p>



<p class="wp-block-paragraph">how does it know if I&#8217;m if I&#8217;m trying to load from memory a one byte integer or</p>



<p class="wp-block-paragraph">two byte integer or four bytes or eight bytes it doesn&#8217;t really know so I kind</p>



<p class="wp-block-paragraph">of have to specify what the data size is of the integer at that place in memory</p>



<p class="wp-block-paragraph">this probably wouldn&#8217;t even compile. But if it did compile, you probably should be nervous that</p>



<p class="wp-block-paragraph">it would compile and do something wrong. So I&#8217;m just going to specify exactly what the data size</p>



<p class="wp-block-paragraph">is for that. So now we&#8217;ve set up our numerator and also set up our denominator. And the next step is</p>



<p class="wp-block-paragraph">to just actually divide. Let me copy paste that real fast. So now we actually divide. Why is my</p>



<p class="wp-block-paragraph">Oh, I know what&#8217;s going on.</p>



<p class="wp-block-paragraph">I have the tab size set up differently between my two editors.</p>



<p class="wp-block-paragraph">I got to fix that.</p>



<p class="wp-block-paragraph">Or how about never fix it so I can always complain and you can laugh at me.</p>



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



<p class="wp-block-paragraph">So on line 85, we&#8217;re going to divide the numerator by the denominator.</p>



<p class="wp-block-paragraph">And we&#8217;ll say the numerator is, you know, RAX with RDX in front of it.</p>



<p class="wp-block-paragraph">the denominator is just one register which is uh what have I done wrong here oh no no I&#8217;m okay I&#8217;m</p>



<p class="wp-block-paragraph">okay r12 so if you look back at the I got a little confused here because uh the book you know it</p>



<p class="wp-block-paragraph">wants uh the d and the a registers as the numerator but then it says op64 as the denominator you can</p>



<p class="wp-block-paragraph">just kind of use a bunch of different stuff for that but I&#8217;m choosing to divide by another register</p>



<p class="wp-block-paragraph">So basically I&#8217;m taking the denominator and loading it up into R12.</p>



<p class="wp-block-paragraph">And then when I call my idiv instruction, I&#8217;m just saying integer division.</p>



<p class="wp-block-paragraph">And I want you to divide whatever&#8217;s in the RDX, RAX set as I want you to divide it by R12.</p>



<p class="wp-block-paragraph">At that point, RAX and RDX will be overwritten.</p>



<p class="wp-block-paragraph">So that data is now destroyed, but they contain the answer.</p>



<p class="wp-block-paragraph">So RAX now contains the answer.</p>



<p class="wp-block-paragraph">I&#8217;m just gonna say quotient and the RAX register contains the remainder so for</p>



<p class="wp-block-paragraph">example if you are familiar with the let me pull this up real fast is that the</p>



<p class="wp-block-paragraph">calculator no there is if you&#8217;re familiar with the modulo instruction like if we</p>



<p class="wp-block-paragraph">said let&#8217;s see what was it again 233 okay so let&#8217;s do 256 divided by 233 this</p>



<p class="wp-block-paragraph">this gives us the number one and then some sort of like a fractional remainder</p>



<p class="wp-block-paragraph">with integer division we&#8217;re not going to get the fractional remainder it&#8217;s just literally going to</p>



<p class="wp-block-paragraph">be the number one sitting in rax and then in rdx it&#8217;s going to give us the result of using the</p>



<p class="wp-block-paragraph">modulo operator which is going to be 23 so it&#8217;s going to be one remainder 23</p>



<p class="wp-block-paragraph">is what we should see unless i&#8217;m totally wrong so then right away</p>



<p class="wp-block-paragraph">of our division which is a good practice you know like the rex and rdx those are registers that</p>



<p class="wp-block-paragraph">could be quickly destroyed especially if you called another function or a system call or</p>



<p class="wp-block-paragraph">something so i&#8217;m just going to save them right away so that&#8217;s why we saved 14 and 15</p>



<p class="wp-block-paragraph">in addition to r12 so r12 we were using for the denominator and then we&#8217;re using 14 and 15 to</p>



<p class="wp-block-paragraph">save them real fast and now I&#8217;m just going to do easy stuff that I&#8217;ve talked about in other videos</p>



<p class="wp-block-paragraph">just to sort of print out an answer so I&#8217;m just going to I&#8217;m just going to write this up real</p>



<p class="wp-block-paragraph">fast copy paste this and then just kind of briefly talk about oh look I&#8217;m using a system call</p>



<p class="wp-block-paragraph">explained in another video to print out that little prefix message you know the result of your</p>



<p class="wp-block-paragraph">division here&#8217;s the quotient and then a colon and then I can actually print the number</p>



<p class="wp-block-paragraph">personal library to print a 64-bit integer and so that way it&#8217;s easy for me and notice how I&#8217;m</p>



<p class="wp-block-paragraph">printing r14 I&#8217;m giving it to the call to the function as the first argument which is rdi</p>



<p class="wp-block-paragraph">what is r14 again that&#8217;s just the quotient so here I&#8217;m printing the quotient and then I do the</p>



<p class="wp-block-paragraph">same thing for the remainder and then we&#8217;re going to do a paste here and I&#8217;m just going to print my</p>



<p class="wp-block-paragraph">prefix of the remainder you know here&#8217;s your remainder and then I&#8217;m going to actually print</p>



<p class="wp-block-paragraph">And then I&#8217;m going to actually print it.</p>



<p class="wp-block-paragraph">And the remainder was in R15.</p>



<p class="wp-block-paragraph">So 14 and 15 had the answer.</p>



<p class="wp-block-paragraph">And then the other register just kind of had, or the R12 just kind of had the denominator.</p>



<p class="wp-block-paragraph">So I think that&#8217;s pretty much all I need.</p>



<p class="wp-block-paragraph">Oh, there&#8217;s one more function that I forgot to put in there.</p>



<p class="wp-block-paragraph">I&#8217;m fond of writing a little CRLF function.</p>



<p class="wp-block-paragraph">This is not part of the video, really.</p>



<p class="wp-block-paragraph">But it&#8217;s just a special function that I can call on to do a carriage return line feed.</p>



<p class="wp-block-paragraph">And I&#8217;m just, I just can never stop using this.</p>



<p class="wp-block-paragraph">stop using this. I know I could just prefix or suffix my strings, you know, with like a CRLF,</p>



<p class="wp-block-paragraph">but I like to be able to call every time I want to see our lab. Okay. So we have the program now.</p>



<p class="wp-block-paragraph">Let&#8217;s see if it actually works. Is that my terminal? Yeah. Okay. I&#8217;m going to go clear</p>



<p class="wp-block-paragraph">and make, hopefully it actually works. So, oh yeah, there we are. Okay. So everything seemed</p>



<p class="wp-block-paragraph">It printed hello from the driver.</p>



<p class="wp-block-paragraph">And then when we went inside of the assembly module,</p>



<p class="wp-block-paragraph">this is really what we&#8217;re interested in.</p>



<p class="wp-block-paragraph">It said the division result, the quotient is the number one</p>



<p class="wp-block-paragraph">and the division remainder is the number 23.</p>



<p class="wp-block-paragraph">That&#8217;s what we said before, right?</p>



<p class="wp-block-paragraph">So it&#8217;s going to be 23 is the remainder.</p>



<p class="wp-block-paragraph">If you just do the modular operator or if you&#8217;re dividing,</p>



<p class="wp-block-paragraph">whoops, if you&#8217;re dividing, then you&#8217;ll just get a one.</p>



<p class="wp-block-paragraph">Remember like the quotient is just going to, you know,</p>



<p class="wp-block-paragraph">truncate or remove or throw away all the extra data.</p>



<p class="wp-block-paragraph">all the extra data it&#8217;s not going to round up or down or anything it&#8217;s just going to say</p>



<p class="wp-block-paragraph">anything past the decimal point is gone and that&#8217;s why the uh the remainder is pretty important</p>



<p class="wp-block-paragraph">then of course you know just for fun we could i don&#8217;t know put like some other numbers in here</p>



<p class="wp-block-paragraph">if we wanted to maybe i&#8217;ll copy paste this just put some other numbers let&#8217;s put like a giant</p>



<p class="wp-block-paragraph">number and see what happens because these are 64-bit numbers we can do it um i probably should</p>



<p class="wp-block-paragraph">have switched a and b right because doesn&#8217;t it kind of feel like a&#8217;s on top so it should be the</p>



<p class="wp-block-paragraph">top so it should be the numerator or whatever so I&#8217;m just gonna hit a bunch of stuff here and then</p>



<p class="wp-block-paragraph">divide that by some other stuff see if this comes up with a more fun answer so one more time clear</p>



<p class="wp-block-paragraph">and make and it&#8217;s telling me that uh whoa that&#8217;s the result I guess probably should have printed</p>



<p class="wp-block-paragraph">out the original numbers but let me just put that into the calculator just for fun we&#8217;ll say this</p>



<p class="wp-block-paragraph">just sort of go back to the calculator it enters so uh oh the squiggly lines</p>



<p class="wp-block-paragraph">that means that&#8217;s not exactly the result i got to figure out how to change the mode on</p>



<p class="wp-block-paragraph">this calculator so i can get precise let&#8217;s see can i do that right here</p>



<p class="wp-block-paragraph">exact no can i try it again with exact all right this is not a tutorial on the</p>



<p class="wp-block-paragraph">it as is maybe i&#8217;ll do can i do a slightly smaller number yeah there we go okay i&#8217;ll take</p>



<p class="wp-block-paragraph">off three digits so that the calculator will at least show me something okay run it one more time</p>



<p class="wp-block-paragraph">and then so now we have smaller stuff the answer should have been 38677662 38677662 yeah that looks</p>



<p class="wp-block-paragraph">the decimal point so the point six is not on there and then we run the modulo</p>



<p class="wp-block-paragraph">to see what the remainder is and it should say one two eight six three yeah</p>



<p class="wp-block-paragraph">okay and then the seven is getting returned I don&#8217;t know do you want to</p>



<p class="wp-block-paragraph">return the remainder for some reason we could do it let&#8217;s just return the</p>



<p class="wp-block-paragraph">remainder might as well make this video a little bit more fun so recall that in</p>



<p class="wp-block-paragraph">order to return something if the return value is an integer and not a float or</p>



<p class="wp-block-paragraph">float or if it&#8217;s a pointer then you&#8217;ll just use RAX as the return register so I&#8217;m just going to do</p>



<p class="wp-block-paragraph">move return the remainder to the color okay I&#8217;m going to move something into RAX it&#8217;s going to be</p>



<p class="wp-block-paragraph">R15 nice now this is a function with a return type I&#8217;m going to say along here and then</p>



<p class="wp-block-paragraph">up here, I guess, RAX is already going to be pre-filled now after that call.</p>



<p class="wp-block-paragraph">But you could imagine if you were doing more stuff between the call and the return,</p>



<p class="wp-block-paragraph">you would probably want to save the return value from RAX in some other register like R12.</p>



<p class="wp-block-paragraph">And then that means you got to add a push pop pair to preserve it.</p>



<p class="wp-block-paragraph">And then we&#8217;ll definitely just, well, maybe I&#8217;ll say move RAX into RAX</p>



<p class="wp-block-paragraph">totally useless. That&#8217;s why I&#8217;m commenting it out. So we&#8217;ll do one less instruction.</p>



<p class="wp-block-paragraph">So basically after we get back from divide test, RAX is going to have the</p>



<p class="wp-block-paragraph">return value and math, this function would also use RAX for its return value. So if we just sort</p>



<p class="wp-block-paragraph">of don&#8217;t do anything, we should now see that the driver receives the remainder as its return value.</p>



<p class="wp-block-paragraph">Let me open that up again real fast just to make sure we understand what&#8217;s going on with</p>



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



<p class="wp-block-paragraph">Even though this is not a driver video, it says external long math.</p>



<p class="wp-block-paragraph">It names that as a long function.</p>



<p class="wp-block-paragraph">And then when we call the function, we just kind of grab a long result, 64 bit int, and</p>



<p class="wp-block-paragraph">then we print it with printf because this is a C program, not C++.</p>



<p class="wp-block-paragraph">integers, assigned integers. Let&#8217;s see in assembly. Let&#8217;s see. Where&#8217;s that? Yeah, there we go.</p>



<p class="wp-block-paragraph">So just keep in mind what I&#8217;ve been showing you is idiv, which is a signed integer, which is what</p>



<p class="wp-block-paragraph">you probably want, which means the integer can be positive or negative. And, you know, if you know</p>



<p class="wp-block-paragraph">for sure that you&#8217;re going to be dividing two positive numbers, and there&#8217;s no chance that</p>



<p class="wp-block-paragraph">that the numerator or denominator or the quotient or you know any of those things are going to be</p>



<p class="wp-block-paragraph">negative then you could you could divide unsigned integers and then you can use larger values</p>



<p class="wp-block-paragraph">because remember when we have signed values we basically lose half of the I guess maximum</p>



<p class="wp-block-paragraph">possible value that we can represent because we lose one bit to the fact that the integer is signed</p>



<p class="wp-block-paragraph">is for signed sorry i div is for signed and regular div is for unsigned and then</p>



<p class="wp-block-paragraph">yeah i guess that&#8217;s basically all i really needed to show you there&#8217;s a bunch of nice code in this</p>



<p class="wp-block-paragraph">book i&#8217;m not gonna i&#8217;m not gonna look at it right now so okay thank you so much for watching this</p>



<p class="wp-block-paragraph">video i hope you learned a little bit of stuff and had a little bit of fun i&#8217;ll see you in the next</p>



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



<p class="wp-block-paragraph">appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p class="wp-block-paragraph">a small little favor, could you please subscribe and follow this channel or these videos or</p>



<p class="wp-block-paragraph">whatever it is you do on the current social media website that you&#8217;re looking at right now. It would</p>



<p class="wp-block-paragraph">really mean the world to me and it&#8217;ll help make more videos and grow this community. So we&#8217;ll be</p>



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



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



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up because I know somebody subscribed or followed.</p>



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



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



<p class="wp-block-paragraph">So you could do it as a nice favor to me</p>



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



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



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



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now,</p>



<p class="wp-block-paragraph">the screen right now you should see a qr code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which i think is also named somewhere at the bottom of this video and it&#8217;ll take you to my</p>



<p class="wp-block-paragraph">main website where you can just kind of like see all the videos i published and the services and</p>



<p class="wp-block-paragraph">tutorials and things that i offer and all that good stuff and uh if you have a suggestion for uh</p>



<p class="wp-block-paragraph">clarifications or errata or just future videos that you want to see please leave a comment or</p>



<p class="wp-block-paragraph">what&#8217;s going on you know just send me a comment whatever I also wake up for those in the middle</p>



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



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



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



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



<p class="wp-block-paragraph">you</p>
<p>The post <a href="https://www.NeuralLantern.com/signed-integer-division-in-x86-64-assembly-with-idiv-and-cqo/">Signed Integer Division in x86-64 Assembly with IDIV and CQO</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/signed-integer-division-in-x86-64-assembly-with-idiv-and-cqo/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Yasm x86-64 Assembly: Instruction Formats, Operands, MOV, ADD, Memory &#038; Registers Explained</title>
		<link>https://www.NeuralLantern.com/yasm-x86-64-assembly-instruction-formats-operands-mov-add-memory-registers-explained/</link>
					<comments>https://www.NeuralLantern.com/yasm-x86-64-assembly-instruction-formats-operands-mov-add-memory-registers-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 02 Nov 2025 12:20:23 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[add instruction]]></category>
		<category><![CDATA[asm programming]]></category>
		<category><![CDATA[assembly crash course]]></category>
		<category><![CDATA[assembly language tutorial]]></category>
		<category><![CDATA[assembly operands]]></category>
		<category><![CDATA[assembly registers]]></category>
		<category><![CDATA[inc rax]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[memory dereference]]></category>
		<category><![CDATA[mov instruction]]></category>
		<category><![CDATA[qword byte size]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[ubuntu assembly book]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=245</guid>

					<description><![CDATA[<p>Yasm assembly tutorial: decode instruction formats, operands, mov, add, memory sizes &#038; registers. Fix common crashes. Code-along x86-64 guide for beginners.</p>
<p>The post <a href="https://www.NeuralLantern.com/yasm-x86-64-assembly-instruction-formats-operands-mov-add-memory-registers-explained/">Yasm x86-64 Assembly: Instruction Formats, Operands, MOV, ADD, Memory &amp; Registers 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 loading="lazy" title="Yasm x86-64 Assembly: Instruction Formats, Operands, MOV, ADD, Memory &amp; Registers Explained" width="1380" height="776" src="https://www.youtube.com/embed/dXQQh_ppqPU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Ever stared at &#8220;mov rdi, rsi&#8221; and wondered WHO goes WHERE?<br>This 18-minute crash course turns confusion into confidence.</p>



<p class="wp-block-paragraph">We start with the world’s simplest instruction (inc rax) and level-up to:</p>



<ul class="wp-block-list">
<li>Zero, one, two, and three-operand formats</li>



<li>Why &#8220;mov rdi, 89&#8221; and “mov rdi, [someVar]” are NOT the same</li>



<li>Brackets = dereference, no brackets = pointer</li>



<li>When ADD destroys your register (and how to stop it)</li>



<li>The memory-size trap that crashes 90% of beginners</li>



<li>Byte / word / dword / qword prefixes that save your life</li>



<li>Pro tip: keep everything in registers until the last microsecond</li>
</ul>



<p class="wp-block-paragraph">Code is shown live in Yasm, every line explained like you’re sitting next to me.<br>No fluff, no 2-hour theory—just the exact mental model you need to read and write assembly tomorrow.</p>



<p class="wp-block-paragraph">Grab the free PDF cheat-sheet (link in first comment) and code along.<br>Hit Subscribe—next video we build a complete program from scratch.</p>



<h1 class="wp-block-heading">Assembly #x86_64 #Yasm #LowLevel</h1>



<p class="wp-block-paragraph">Introduction to Instruction Formats 00:00:00<br>Simple INC Example 00:00:28<br>Instruction and Operand Basics 00:00:47<br>Zero to Three Operands 00:01:14<br>MOV Instruction Explained 00:02:02<br>Immediates and Registers 00:02:44<br>Memory Variables and Pointers 00:03:16<br>Dereferencing with Brackets 00:05:08<br>ADD with Two Operands 00:05:32<br>ADD with Three Operands 00:06:55<br>Consulting the Ubuntu Book 00:07:45<br>MOV Source vs Destination 00:08:52<br>Memory Size Matters 00:09:07<br>Specifying Data Size 00:11:40<br>INC on Memory Locations 00:13:19<br>Why Size Prefixes Prevent Bugs 00:14:08<br>Performance Tip &#8211; Use Registers 00:15:12<br>Book Recommendation Wrap-up 00:16:04</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey there! Let&#8217;s talk about instruction formats in Yasm Assembly.</p>



<p class="wp-block-paragraph">So what am I talking about? Well, if we&#8217;re in Yasm Assembly and we&#8217;re going to learn how to</p>



<p class="wp-block-paragraph">use lots and lots of instructions, it&#8217;s probably a pretty good idea to understand the general idea</p>



<p class="wp-block-paragraph">of an instruction and its operands and the things that you can do to it. So the first thing I want</p>



<p class="wp-block-paragraph">show you is a really simple instruction called inc and we&#8217;ll put it we&#8217;ll put a</p>



<p class="wp-block-paragraph">register there we&#8217;ll say RAX we want to take whatever value is inside of the RAX</p>



<p class="wp-block-paragraph">register and just increase it by one simple enough but it&#8217;s important to</p>



<p class="wp-block-paragraph">understand that this is this follows a specific format the first thing that we</p>



<p class="wp-block-paragraph">put is the name of the instruction that we want to execute second thing we put</p>



<p class="wp-block-paragraph">is an operand you know what thing do we want to increase we could actually put</p>



<p class="wp-block-paragraph">We could actually put other types of operands there.</p>



<p class="wp-block-paragraph">We couldn&#8217;t put an immediate number, like just a hard-coded number,</p>



<p class="wp-block-paragraph">but we could put a memory location if we wanted to, and we were careful about it.</p>



<p class="wp-block-paragraph">So think about instructions as following this sort of format.</p>



<p class="wp-block-paragraph">Let&#8217;s see, INST, and then a space, and then, you know,</p>



<p class="wp-block-paragraph">sometimes instructions have zero operands, like there&#8217;s an instruction called CQO, I think,</p>



<p class="wp-block-paragraph">and it just takes two registers and sort of like lays them out against each other.</p>



<p class="wp-block-paragraph">against each other but for now we&#8217;ll just assume we&#8217;re going to write instructions that</p>



<p class="wp-block-paragraph">actually do something to named registers or memory locations or whatever.</p>



<p class="wp-block-paragraph">So the name of the instruction comes first and then we have an operand.</p>



<p class="wp-block-paragraph">One or more operands up to three actually.</p>



<p class="wp-block-paragraph">So basically the operands are separated by commas so we&#8217;ll say operand one, operand two,</p>



<p class="wp-block-paragraph">operand three and most instructions will follow this format.</p>



<p class="wp-block-paragraph">do what the operands are for it&#8217;s easy to tell that the first operand is the</p>



<p class="wp-block-paragraph">thing that will be increased in the increase operand but what about the move</p>



<p class="wp-block-paragraph">instruction what if we wanted to move you know one register to another let&#8217;s</p>



<p class="wp-block-paragraph">say RDI to RSI or sorry RDI from RSI or vice versa I mean how would you know</p>



<p class="wp-block-paragraph">remember this is the instruction and this is the first operand and then this</p>



<p class="wp-block-paragraph">And then this is the second operand.</p>



<p class="wp-block-paragraph">There&#8217;s not three operands in this instruction.</p>



<p class="wp-block-paragraph">Other instructions have three operands.</p>



<p class="wp-block-paragraph">The way it works with the move instruction,</p>



<p class="wp-block-paragraph">I hope you understand already at this point,</p>



<p class="wp-block-paragraph">is that operand two gets placed into operand one.</p>



<p class="wp-block-paragraph">So when this instruction is finished,</p>



<p class="wp-block-paragraph">then whatever value was inside of RSI is going to be inside of RDI.</p>



<p class="wp-block-paragraph">So they&#8217;re actually going to end up being copies of each other.</p>



<p class="wp-block-paragraph">Some instructions allow you to put immediates,</p>



<p class="wp-block-paragraph">like I could just put the number 89 right here and the number 89 will get loaded into RDI so I</p>



<p class="wp-block-paragraph">don&#8217;t really even need to use a register. Some instructions this one in particular also will</p>



<p class="wp-block-paragraph">allow you to place the name of some variable in brackets as the second operand and then what&#8217;ll</p>



<p class="wp-block-paragraph">happen is if you if you recall hopefully let me let me let me improve this a little bit.</p>



<p class="wp-block-paragraph">you have a data section and you have a text section.</p>



<p class="wp-block-paragraph">The text section is for your instructions.</p>



<p class="wp-block-paragraph">In the data section, we could say some variable</p>



<p class="wp-block-paragraph">and we could define this as data quad word, I guess,</p>



<p class="wp-block-paragraph">and put like a big giant number inside of there.</p>



<p class="wp-block-paragraph">And so now we have a variable, a global variable to that module</p>



<p class="wp-block-paragraph">that is sitting in memory somewhere and it&#8217;s got this value.</p>



<p class="wp-block-paragraph">So then what we can do is basically say,</p>



<p class="wp-block-paragraph">take the name of that variable, stick it inside of brackets,</p>



<p class="wp-block-paragraph">and then the move instruction will go grab that number, grab the value associated with that</p>



<p class="wp-block-paragraph">variable and then load that into RDI. What if we didn&#8217;t put brackets? What if we just said load and</p>



<p class="wp-block-paragraph">then some variable? This is how you place a pointer inside of a register. Remember all these registers,</p>



<p class="wp-block-paragraph">at least the general purpose registers with this R format, are 64-bit registers and in the 64-bit</p>



<p class="wp-block-paragraph">use that means you could hold a memory location in the register so it&#8217;s pretty convenient when</p>



<p class="wp-block-paragraph">when you define a variable up top here what you&#8217;re really doing is you&#8217;re saying i would like to</p>



<p class="wp-block-paragraph">allocate eight bytes for a quad word and i would like to fill it up with this data</p>



<p class="wp-block-paragraph">you know like let&#8217;s take eight bytes reserve it for us then we&#8217;ll convert all the ones and zeros</p>



<p class="wp-block-paragraph">appropriately so that it ends up equaling that value then when we&#8217;re done it&#8217;ll give us a pointer</p>



<p class="wp-block-paragraph">a normal variable that you usually would think of in C++ where it&#8217;s just like the variable is the</p>



<p class="wp-block-paragraph">variable and not a pointer to something. All these are actually just pointers. So if I load some</p>



<p class="wp-block-paragraph">variable into RDI I&#8217;m actually loading a pointer to RDI which by the way would make it pretty easy</p>



<p class="wp-block-paragraph">for you to pass a pointer into another function just by loading up RDI with some pointer to you</p>



<p class="wp-block-paragraph">know some of your data somewhere. But the moment I put the brackets around it it will dereference</p>



<p class="wp-block-paragraph">it will dereference the pointer for me</p>



<p class="wp-block-paragraph">and take the value and then send the value into that.</p>



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



<p class="wp-block-paragraph">Okay, so we got pointers, dereference pointers,</p>



<p class="wp-block-paragraph">immediates and registers.</p>



<p class="wp-block-paragraph">That actually went by pretty fast.</p>



<p class="wp-block-paragraph">I thought this was gonna be a long video.</p>



<p class="wp-block-paragraph">Well, let&#8217;s look at my favorite book here,</p>



<p class="wp-block-paragraph">the Ubuntu coding book.</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">Oh, maybe first let&#8217;s look at the add instruction</p>



<p class="wp-block-paragraph">because I wanted to get something with three operands.</p>



<p class="wp-block-paragraph">So let&#8217;s do an instruction with three operands.</p>



<p class="wp-block-paragraph">I&#8217;ll say INST and we&#8217;ll do operand one, operand two, operand three.</p>



<p class="wp-block-paragraph">So we have this add instruction here where we can just add two integers together.</p>



<p class="wp-block-paragraph">I could say let&#8217;s load the value of, you know what, let&#8217;s do this first with only two.</p>



<p class="wp-block-paragraph">Yeah, because that&#8217;ll be more fun.</p>



<p class="wp-block-paragraph">Let&#8217;s do RDI and RSI.</p>



<p class="wp-block-paragraph">Okay, so this is legal.</p>



<p class="wp-block-paragraph">You can have an instruction named add that uses either two or three operands.</p>



<p class="wp-block-paragraph">A lot of instructions do that.</p>



<p class="wp-block-paragraph">Usually in the two operand format, what they&#8217;re saying is,</p>



<p class="wp-block-paragraph">let&#8217;s do something with both of these values and then store the result</p>



<p class="wp-block-paragraph">of doing something in the first register.</p>



<p class="wp-block-paragraph">So for example, it&#8217;s going to take RDI and add it with RSI,</p>



<p class="wp-block-paragraph">assuming two&#8217;s complement integers.</p>



<p class="wp-block-paragraph">store the result of that addition inside of RDI. So if you think about it, it&#8217;s faster to type,</p>



<p class="wp-block-paragraph">but sometimes it might destroy data if you didn&#8217;t actually expect to modify RDI.</p>



<p class="wp-block-paragraph">If you wanted to store the result somewhere else, but still add RDI and RSI somewhere,</p>



<p class="wp-block-paragraph">then that wouldn&#8217;t work. So let&#8217;s do the three operand format, operand two, operand three.</p>



<p class="wp-block-paragraph">So now let&#8217;s say that we wanted to store in some other register without destroying</p>



<p class="wp-block-paragraph">RDI after we do the addition. So we can use the three operand format. Maybe I&#8217;ll</p>



<p class="wp-block-paragraph">hit space here a couple times just to make it a little more interesting. I</p>



<p class="wp-block-paragraph">guess I probably should have formatted the comment. Let me try to… No I guess I</p>



<p class="wp-block-paragraph">can&#8217;t. I don&#8217;t need to space it out. Well I could. I could anyway. So we&#8217;ll use the</p>



<p class="wp-block-paragraph">add instruction which is totally valid to use for three operands in addition to</p>



<p class="wp-block-paragraph">two operands. And what will happen now is it&#8217;ll take RDI and add it to RSI</p>



<p class="wp-block-paragraph">and add it to RSI and store the result in R11 in case you wanted to preserve the value of RDI and</p>



<p class="wp-block-paragraph">RSI. Lots and lots of different instructions with lots and lots of different things that you can do.</p>



<p class="wp-block-paragraph">Of course, we could put a memory location there. We could put like an immediate somewhere.</p>



<p class="wp-block-paragraph">But let me go to my favorite book here. Whoops, I already have it highlighted on the right section.</p>



<p class="wp-block-paragraph">x86 64 assembly language programming with Ubuntu by a brilliant doctor and I</p>



<p class="wp-block-paragraph">use his book all the time I&#8217;m not gonna say his name because I don&#8217;t want to</p>



<p class="wp-block-paragraph">accidentally mispronounce it I&#8217;m pretty sure I know how but I don&#8217;t even want to</p>



<p class="wp-block-paragraph">try because I suck at pronouncing things I&#8217;ve pronounced my own name wrong on</p>



<p class="wp-block-paragraph">many occasion so let&#8217;s see I&#8217;m gonna click on section 7 the instruction set</p>



<p class="wp-block-paragraph">the instruction set overview and basically you know it kind of goes over the fact that oh you</p>



<p class="wp-block-paragraph">know we can put registers as operands and we can do some certain things like if you see this</p>



<p class="wp-block-paragraph">notation it means you can put a register as an operand if you see this notation it means that&#8217;s</p>



<p class="wp-block-paragraph">going to be the source operand if you put if you see this notation it means you can put an immediate</p>



<p class="wp-block-paragraph">at that spot so the book just kind of tells you what to expect in terms of notation then if you</p>



<p class="wp-block-paragraph">go down it starts explaining a bunch of different instructions for example the move instruction</p>



<p class="wp-block-paragraph">instructions. For example, the move instruction that we&#8217;ve just been working with. Notice how it</p>



<p class="wp-block-paragraph">tells you the source is on the right, the destination is on the left. And if we are taking</p>



<p class="wp-block-paragraph">from a memory location, which I probably should have mentioned, let me see, did I mention that?</p>



<p class="wp-block-paragraph">No, I don&#8217;t think I did. If we&#8217;re taking from a memory location, it&#8217;s important to understand that</p>



<p class="wp-block-paragraph">the data size of the memory locations data and the register might actually be different. See,</p>



<p class="wp-block-paragraph">different. See here we kind of made a bad assumption. We made the assumption that RDI</p>



<p class="wp-block-paragraph">was a 64-bit register. That&#8217;s a good assumption. But then we also made the assumption that sitting</p>



<p class="wp-block-paragraph">at that pointer is eight bytes of memory. That&#8217;s a bad assumption. Up at the top, we know that</p>



<p class="wp-block-paragraph">when we put DQ for data quad word, then eight bytes are going to get allocated. But by the time we</p>



<p class="wp-block-paragraph">But by the time we get down to this instruction, you know assembly is not very smart.</p>



<p class="wp-block-paragraph">By the time we get down to this instruction, we can&#8217;t be sure if that pointer refers to</p>



<p class="wp-block-paragraph">something that is 8 bytes or 4 bytes or 2 bytes.</p>



<p class="wp-block-paragraph">We should be able to support loading a number.</p>



<p class="wp-block-paragraph">Like just as an example, I could lower this number, like let&#8217;s say with the number 25,</p>



<p class="wp-block-paragraph">but you know that the number 25 will fit into just a single byte.</p>



<p class="wp-block-paragraph">It&#8217;ll also fit into a word, 2 bytes.</p>



<p class="wp-block-paragraph">32 bit number, a D word, you know, four bytes.</p>



<p class="wp-block-paragraph">It&#8217;ll also fit into a quad word, 64 bits, eight bytes.</p>



<p class="wp-block-paragraph">So it&#8217;ll fit in different sizes of data.</p>



<p class="wp-block-paragraph">So what if you have a memory allocation,</p>



<p class="wp-block-paragraph">like instead of putting DQ,</p>



<p class="wp-block-paragraph">what if we put DB for just data byte?</p>



<p class="wp-block-paragraph">So just like one byte of memory to put that 25 in,</p>



<p class="wp-block-paragraph">that should work.</p>



<p class="wp-block-paragraph">But the point is this part of the code</p>



<p class="wp-block-paragraph">doesn&#8217;t actually know how big the memory location is.</p>



<p class="wp-block-paragraph">So it doesn&#8217;t know how many bytes to grab.</p>



<p class="wp-block-paragraph">many bytes to grab like what if we what if it just assumed that because we used a 64-bit register</p>



<p class="wp-block-paragraph">actually let&#8217;s go back up here let&#8217;s change this to a byte data byte so we know that the 25 occupies</p>



<p class="wp-block-paragraph">only one byte but here if we were unlucky then the assembler might assume oh they want to load</p>



<p class="wp-block-paragraph">eight bytes of memory interpreted as a number and then put that into a 64-bit register an eight</p>



<p class="wp-block-paragraph">But that probably wouldn&#8217;t work because we only actually modified one byte to make that 25.</p>



<p class="wp-block-paragraph">So there&#8217;s going to be seven other bytes of junk data.</p>



<p class="wp-block-paragraph">So now we just loaded RDI with some sort of a nonsense value.</p>



<p class="wp-block-paragraph">And even if it does work, it might not work on every run of the program.</p>



<p class="wp-block-paragraph">So then you have something which is probably undefined behavior,</p>



<p class="wp-block-paragraph">where it&#8217;s just like you made a bad mistake and your program&#8217;s going to work sometimes</p>



<p class="wp-block-paragraph">and maybe some other times not work.</p>



<p class="wp-block-paragraph">So how do we fix this?</p>



<p class="wp-block-paragraph">So how do we fix this? We just specify the size of the memory location or of</p>



<p class="wp-block-paragraph">the bytes that we&#8217;re going to grab at that memory location. So if I just put</p>



<p class="wp-block-paragraph">the word byte in front, now the assembler knows that I only want to grab</p>



<p class="wp-block-paragraph">one byte and interpret that as a number and then put that into RDI rather than</p>



<p class="wp-block-paragraph">all the extra junk data. So if I want to make sure that it understands that I want</p>



<p class="wp-block-paragraph">eight bytes and also to prevent it from refusing to compile, which it&#8217;s probably</p>



<p class="wp-block-paragraph">going to do if i don&#8217;t specify the size i&#8217;ll put q word to say yeah this 25 it&#8217;s uh it&#8217;s actually</p>



<p class="wp-block-paragraph">a q word it occupies eight bytes so i want you to load up eight bytes in ram and interpret all</p>



<p class="wp-block-paragraph">those bytes as just you know whatever numbers inside of them pretty sweet i love going to this</p>



<p class="wp-block-paragraph">book because i was going to forget to say that anyway just so you know there&#8217;s a bunch of</p>



<p class="wp-block-paragraph">instructions that you can look up i&#8217;m not going to go through all of them but um you know typically</p>



<p class="wp-block-paragraph">Leftmost operand in some sort of a modifying instruction is going to be the destination</p>



<p class="wp-block-paragraph">register or memory location.</p>



<p class="wp-block-paragraph">And if you have a two operand instruction, it&#8217;s probably going to take both operands</p>



<p class="wp-block-paragraph">and do something with them and then stick the result in the first operand.</p>



<p class="wp-block-paragraph">And then if you have a three operand instruction, it&#8217;s probably going to take the rightmost</p>



<p class="wp-block-paragraph">two operands, do something with them, store the result in the leftmost operand.</p>



<p class="wp-block-paragraph">wonderful, wonderful book will tell you exactly what to expect for every type of instruction.</p>



<p class="wp-block-paragraph">So there&#8217;s like move here, integer arithmetic. Oh yeah, there&#8217;s the add function or sorry,</p>



<p class="wp-block-paragraph">the add instruction. And then here&#8217;s like a bunch of sample code, which is awesome.</p>



<p class="wp-block-paragraph">And notice how here, if we want to increase something that is located at a memory location,</p>



<p class="wp-block-paragraph">we got to specify the size of the memory. Again, same problem that we just talked about up above.</p>



<p class="wp-block-paragraph">Did we do that at the beginning?</p>



<p class="wp-block-paragraph">I don&#8217;t remember if we did that.</p>



<p class="wp-block-paragraph">You know, if we have something where it&#8217;s like,</p>



<p class="wp-block-paragraph">if we said increase the RAX register,</p>



<p class="wp-block-paragraph">the computer knows that RAX is a 64-bit register</p>



<p class="wp-block-paragraph">because the way we typed it, RAX, that implies 64 bits.</p>



<p class="wp-block-paragraph">If we meant to only use 32 bits of the register,</p>



<p class="wp-block-paragraph">we would type a different, you know,</p>



<p class="wp-block-paragraph">set of letters to represent that register.</p>



<p class="wp-block-paragraph">But if we say, I would like you to increase</p>



<p class="wp-block-paragraph">the value sitting in memory at some variable,</p>



<p class="wp-block-paragraph">sitting in memory at some variable dereferenced, well then whoops,</p>



<p class="wp-block-paragraph">it doesn&#8217;t actually know how many bytes.</p>



<p class="wp-block-paragraph">If you increase a small</p>



<p class="wp-block-paragraph">value, like if it&#8217;s if you have one byte and you try to increase it,</p>



<p class="wp-block-paragraph">what if it overflows?</p>



<p class="wp-block-paragraph">Like, for example, if we had a one byte, if we had one byte of data here</p>



<p class="wp-block-paragraph">and we had the number, let&#8217;s say 255 already, that&#8217;s the highest value that a</p>



<p class="wp-block-paragraph">So if we then say let&#8217;s increase that,</p>



<p class="wp-block-paragraph">the computer is going to, you know, like overflow back down to just zero or not.</p>



<p class="wp-block-paragraph">What if it actually was a quad word?</p>



<p class="wp-block-paragraph">The computer didn&#8217;t understand whether it&#8217;s supposed to overflow or not overflow.</p>



<p class="wp-block-paragraph">Do you see what I&#8217;m saying?</p>



<p class="wp-block-paragraph">There&#8217;s lots of problems that can happen if you don&#8217;t know the size.</p>



<p class="wp-block-paragraph">So that just means we have to specify the size.</p>



<p class="wp-block-paragraph">Anytime we&#8217;re dealing with memory, we&#8217;ll say we&#8217;ll increase a keyword sitting at some</p>



<p class="wp-block-paragraph">variable. And of course, if you&#8217;re going to</p>



<p class="wp-block-paragraph">and of course if you&#8217;re gonna i don&#8217;t know why you&#8217;d want to do this but if you wanted to well</p>



<p class="wp-block-paragraph">i guess if you&#8217;re running through a string if you wanted to increase a pointer value uh then i think</p>



<p class="wp-block-paragraph">you don&#8217;t have to specify the data size although i&#8217;m not actually sure if you can change the value</p>



<p class="wp-block-paragraph">of that pointer i don&#8217;t know if it&#8217;s hard coded usually what i do is i would just move you know</p>



<p class="wp-block-paragraph">some kind of a i would move the pointer if we&#8217;re if we&#8217;re using a running pointer to run through</p>



<p class="wp-block-paragraph">I would load the pointers value into a register and then I would just start increasing the</p>



<p class="wp-block-paragraph">register just to make things a little bit easier because as I usually try to say it&#8217;s</p>



<p class="wp-block-paragraph">way slower to constantly be hitting memory.</p>



<p class="wp-block-paragraph">Anytime you can possibly keep all of your calculations and algorithms and stuff inside</p>



<p class="wp-block-paragraph">of only registers as long as possible, then your program will be way, way faster.</p>



<p class="wp-block-paragraph">So if you&#8217;re going to run through a bunch of data with a pointer, probably want to load</p>



<p class="wp-block-paragraph">it up into a register first and then keep increasing the register.</p>



<p class="wp-block-paragraph">When you finally figure out, you know, everything that&#8217;s calculated and finished,</p>



<p class="wp-block-paragraph">then go ahead and save it back to memory at the very end.</p>



<p class="wp-block-paragraph">But just to let you know, we&#8217;ve got lots of stuff.</p>



<p class="wp-block-paragraph">Okay, so there&#8217;s the add function.</p>



<p class="wp-block-paragraph">This is the two op version.</p>



<p class="wp-block-paragraph">You can see at the top there.</p>



<p class="wp-block-paragraph">Let&#8217;s see, where&#8217;s the three op version?</p>



<p class="wp-block-paragraph">Here&#8217;s somebody honking the horn outside.</p>



<p class="wp-block-paragraph">Someone&#8217;s upset with someone else.</p>



<p class="wp-block-paragraph">Someone&#8217;s upset.</p>



<p class="wp-block-paragraph">Someone&#8217;s upset. Do you ever honk the horn not angry, but just so that the other driver will think you&#8217;re angry and</p>



<p class="wp-block-paragraph">Then possibly be a good driver or a better driver later on in their life. I don&#8217;t know if that actually works. I have tried it</p>



<p class="wp-block-paragraph">And you do your eyebrows like this</p>



<p class="wp-block-paragraph">Even though you&#8217;re not upset</p>



<p class="wp-block-paragraph">I wonder if they just go home laughing and they&#8217;re like, yeah, you&#8217;re right. I was ridiculous</p>



<p class="wp-block-paragraph">Okay, so I guess I&#8217;m gonna stop scrolling</p>



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



<p class="wp-block-paragraph">A good coder always reads the documentation and studies ahead and things like that</p>



<p class="wp-block-paragraph">I know you were hoping for me to tell you everything in this video, but there&#8217;s just not enough time or energy to do that</p>



<p class="wp-block-paragraph">I just wanted you to understand</p>



<p class="wp-block-paragraph">How how to how to interpret instruction formats?</p>



<p class="wp-block-paragraph">I wanted to make that part easy for you</p>



<p class="wp-block-paragraph">but all the different instructions that are available to you to multiply to add to increase values to do all this stuff</p>



<p class="wp-block-paragraph">It&#8217;s all in this nice wonderful book</p>



<p class="wp-block-paragraph">okay anyway I think I&#8217;m gonna cut the video I hope you enjoyed what you have</p>



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



<p class="wp-block-paragraph">and I&#8217;ll see you in the next video hey everybody thanks for watching this video</p>



<p class="wp-block-paragraph">again from the bottom of my heart I really appreciate it I do hope you did</p>



<p class="wp-block-paragraph">learn something and have some fun if you could do me a please a small little</p>



<p class="wp-block-paragraph">favor could you please subscribe and follow this channel or these videos or</p>



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



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



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos,</p>



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



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up because I know somebody subscribed or followed.</p>



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



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



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



<p class="wp-block-paragraph">want to just wake me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake up i</p>



<p class="wp-block-paragraph">promise that&#8217;s what will happen also uh if you look at the middle of the screen right now you</p>



<p class="wp-block-paragraph">should see a qr code which you can scan in order to go to the website which i think is also named</p>



<p class="wp-block-paragraph">somewhere at the bottom of this video and it&#8217;ll take you to my main website where you can just</p>



<p class="wp-block-paragraph">kind of like see all the videos i published and the services and tutorials and things that i offer</p>



<p class="wp-block-paragraph">all that good stuff and uh if you have a suggestion for uh uh clarifications or errata or just future</p>



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/yasm-x86-64-assembly-instruction-formats-operands-mov-add-memory-registers-explained/">Yasm x86-64 Assembly: Instruction Formats, Operands, MOV, ADD, Memory &amp; Registers Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/yasm-x86-64-assembly-instruction-formats-operands-mov-add-memory-registers-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master File Copying with System Calls in x86-64 YASM Assembly</title>
		<link>https://www.NeuralLantern.com/master-file-copying-with-system-calls-in-x86-64-yasm-assembly/</link>
					<comments>https://www.NeuralLantern.com/master-file-copying-with-system-calls-in-x86-64-yasm-assembly/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 05 Oct 2025 11:22: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]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[file copying]]></category>
		<category><![CDATA[file handling]]></category>
		<category><![CDATA[file I/O]]></category>
		<category><![CDATA[file permissions]]></category>
		<category><![CDATA[Linux system calls]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[MD5 checksum]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[system calls]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=237</guid>

					<description><![CDATA[<p>Learn file copying in x86-64 YASM assembly with system calls. This tutorial covers opening files, using looping buffers, and verifying with MD5 checksums.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-file-copying-with-system-calls-in-x86-64-yasm-assembly/">Master File Copying with System Calls in x86-64 YASM Assembly</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="Master File Copying with System Calls in x86-64 YASM Assembly" width="1380" height="776" src="https://www.youtube.com/embed/hvq4VGqA6Ks?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Join me as I break down a simple yet powerful x86-64 YASM assembly program to copy files using system calls! Learn how to open input files, create output files, and use a looping buffer for efficient data transfer. I’ll demo the code, explain file handles, permissions, and error handling, and even verify the copy with MD5 checksums. Perfect for intermediate assembly programmers or anyone curious about low-level file operations. Check out my other videos for more assembly tips, and don’t forget to subscribe!</p>



<p class="wp-block-paragraph">Introduction to File Copy Program 00:00:00<br>System Calls in YASM Assembly 00:00:06<br>Opening Input File 00:00:17<br>Creating Output File 00:00:22<br>Using Looping Buffer 00:00:28<br>Assembly Program Prerequisites 00:00:37<br>Overview of Source File 00:00:53<br>Data Section and Strings 00:01:06<br>Copy Buffer Length 00:01:21<br>File Permissions Explanation 00:02:05<br>System Call Codes 00:02:57<br>File Descriptors and Exit Codes 00:03:24<br>Text Section and Entry Point 00:03:45<br>Welcome Message Function 00:04:01<br>Print Null Terminated String 00:04:16<br>Running Initial Program 00:06:26<br>MD5 Checksum Explanation 00:07:00<br>File Tests Function Introduction 00:07:28<br>Open File Read Function 00:09:52<br>Checking File Handle 00:14:00<br>File Handle Concept 00:14:25<br>Error Handling Importance 00:15:24<br>Testing File Open 00:23:00<br>Create File Function 00:31:16<br>Testing File Creation 00:32:36<br>Copy File Function 00:36:14<br>Stack Buffer Creation 00:38:16<br>While Loop for Copying 00:40:14<br>Read System Call 00:40:47<br>Write System Call 00:45:03<br>Checking Read/Write Operations 00:46:51<br>Final Program Run 00:49:00<br>Verifying File Copy with MD5 00:49:22<br>Testing with Larger Input 00:51:20<br>Optimizing Buffer Size 00:53:41<br>Conclusion and Call to Subscribe 00:54:41</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey everybody in this video i&#8217;m going to show and explain a simple program that copies a file</p>



<p class="wp-block-paragraph">using system calls in an x8664 yasm assembly program</p>



<p class="wp-block-paragraph">we&#8217;re going to use the system calls to open an input file and read characters from it we&#8217;re</p>



<p class="wp-block-paragraph">going to use another system call to create a destination file and write characters to it</p>



<p class="wp-block-paragraph">we&#8217;re going to use a looping buffer,</p>



<p class="wp-block-paragraph">which should be kind of fun in the middle.</p>



<p class="wp-block-paragraph">And I&#8217;m just going to do my best to explain as much as I can.</p>



<p class="wp-block-paragraph">I should say though that before you can watch this video,</p>



<p class="wp-block-paragraph">you probably already need to know how to program an assembly,</p>



<p class="wp-block-paragraph">at least in a basic level, Yasm assembly.</p>



<p class="wp-block-paragraph">And so if you don&#8217;t know how to do that yet,</p>



<p class="wp-block-paragraph">this video is probably going to be confusing for you.</p>



<p class="wp-block-paragraph">You probably need to look at my other videos dealing with Yasm assembly and</p>



<p class="wp-block-paragraph">system calls and so forth.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to show you real fast what&#8217;s actually going on in this source</p>



<p class="wp-block-paragraph">actually going on in this source file so far.</p>



<p class="wp-block-paragraph">So this is my assembly program.</p>



<p class="wp-block-paragraph">It&#8217;s not finished.</p>



<p class="wp-block-paragraph">I&#8217;m going to write it on screen for you.</p>



<p class="wp-block-paragraph">For the most part, you can see I&#8217;ve got a data section here and then I just have a</p>



<p class="wp-block-paragraph">bunch of null terminated strings.</p>



<p class="wp-block-paragraph">So I&#8217;ve got a string saying, hey, the module started.</p>



<p class="wp-block-paragraph">We&#8217;re about to open the file.</p>



<p class="wp-block-paragraph">We&#8217;re about to create the file.</p>



<p class="wp-block-paragraph">We failed to do something.</p>



<p class="wp-block-paragraph">We&#8217;re done copying.</p>



<p class="wp-block-paragraph">You know, we terminated the program, you know, whatever.</p>



<p class="wp-block-paragraph">Right. So I just have some strings.</p>



<p class="wp-block-paragraph">No big deal.</p>



<p class="wp-block-paragraph">Down here, I have something called the copy buffer length, which is which is just</p>



<p class="wp-block-paragraph">length with just which is just the size of the buffer that I&#8217;m going to use</p>



<p class="wp-block-paragraph">between the input file and the output file so a two byte buffer is really</p>



<p class="wp-block-paragraph">inefficient it&#8217;s too small but I made it two bytes just to show to you that are</p>



<p class="wp-block-paragraph">looping you know a read area is going to actually work because if I make a buffer</p>



<p class="wp-block-paragraph">that&#8217;s too big if it&#8217;s bigger than the file then we won&#8217;t actually know if the</p>



<p class="wp-block-paragraph">if the buffer loop works or not so I&#8217;m just gonna put two here could change</p>



<p class="wp-block-paragraph">that later if we wanted to we&#8217;re gonna be reading from a file called input and</p>



<p class="wp-block-paragraph">called input and writing to a file called output so that&#8217;s no big deal in order to open a file with</p>



<p class="wp-block-paragraph">a system call for read mode we&#8217;re just going to use a zero as the flags that just means read mode</p>



<p class="wp-block-paragraph">and then for the creation of the file we&#8217;re going to use some standard permissions this is not a</p>



<p class="wp-block-paragraph">permissions video I&#8217;m going to probably release a permissions video at some later point in time</p>



<p class="wp-block-paragraph">not too important right now but basically this 640 is the heart of what permissions we&#8217;re actually</p>



<p class="wp-block-paragraph">what permissions we&#8217;re actually looking at.</p>



<p class="wp-block-paragraph">Q is quad word.</p>



<p class="wp-block-paragraph">And six just means that the owner can read</p>



<p class="wp-block-paragraph">and write to the file.</p>



<p class="wp-block-paragraph">Four means that anyone who is in the same group</p>



<p class="wp-block-paragraph">as the file has been assigned to,</p>



<p class="wp-block-paragraph">which is usually the owner,</p>



<p class="wp-block-paragraph">can just read it but not write to it.</p>



<p class="wp-block-paragraph">And then everybody else,</p>



<p class="wp-block-paragraph">people who are not the owner</p>



<p class="wp-block-paragraph">and who are not in the right group,</p>



<p class="wp-block-paragraph">they have no access to it.</p>



<p class="wp-block-paragraph">Just a simple security feature of Linux</p>



<p class="wp-block-paragraph">for file permissions.</p>



<p class="wp-block-paragraph">You can go a lot further than this in the terminal,</p>



<p class="wp-block-paragraph">in the terminal, but for this assembly program,</p>



<p class="wp-block-paragraph">we&#8217;re just gonna use basics.</p>



<p class="wp-block-paragraph">We&#8217;re not gonna use ACLs.</p>



<p class="wp-block-paragraph">I don&#8217;t even know how to do that in assembly.</p>



<p class="wp-block-paragraph">System call codes.</p>



<p class="wp-block-paragraph">So again, if you don&#8217;t understand system calls,</p>



<p class="wp-block-paragraph">you gotta watch my other videos first,</p>



<p class="wp-block-paragraph">but we have a code of zero to read from a file,</p>



<p class="wp-block-paragraph">one to write to a file, two to open a file,</p>



<p class="wp-block-paragraph">three to close and open file.</p>



<p class="wp-block-paragraph">Probably should have put that one before create,</p>



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



<p class="wp-block-paragraph">85 is the code to create a file for writing,</p>



<p class="wp-block-paragraph">to create a file for writing and then 60 is the code to exit from the program.</p>



<p class="wp-block-paragraph">So then we have file descriptors.</p>



<p class="wp-block-paragraph">Descriptor number one is a standard output.</p>



<p class="wp-block-paragraph">Descriptor number two is standard error.</p>



<p class="wp-block-paragraph">And it&#8217;s always one and two, no matter what program you&#8217;re dealing with.</p>



<p class="wp-block-paragraph">Unless you have some kind of really crazy non-standard thing going on.</p>



<p class="wp-block-paragraph">And then for the exit codes, we&#8217;re just going to say exit zero for success and exit one</p>



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



<p class="wp-block-paragraph">Now to the actual tech section where our instructions are in the assembly program.</p>



<p class="wp-block-paragraph">in the assembly program.</p>



<p class="wp-block-paragraph">So you can see section text here.</p>



<p class="wp-block-paragraph">We&#8217;ve got a global entry point called underscore start.</p>



<p class="wp-block-paragraph">So this is not a GCC program that requires a main entry point.</p>



<p class="wp-block-paragraph">This is a pure assembly program that requires</p>



<p class="wp-block-paragraph">an underscore start entry point.</p>



<p class="wp-block-paragraph">Again, see my other videos for more assembly explanation.</p>



<p class="wp-block-paragraph">I&#8217;m gonna call on a method,</p>



<p class="wp-block-paragraph">well, not a method of regular function called welcome.</p>



<p class="wp-block-paragraph">Just to print a little welcome message,</p>



<p class="wp-block-paragraph">you can see right here, that&#8217;s all that&#8217;s doing.</p>



<p class="wp-block-paragraph">It&#8217;s just loading, you know, a string,</p>



<p class="wp-block-paragraph">sending it to standard output, and calling on a helper function that I made called print null</p>



<p class="wp-block-paragraph">terminated string. When it&#8217;s done with that, it just uses the call code to exit the program.</p>



<p class="wp-block-paragraph">No big deal. Nothing too advanced so far. I have the tests function commented out because I want</p>



<p class="wp-block-paragraph">to write that in front of you. And if you look at what I have inside of print null terminated string,</p>



<p class="wp-block-paragraph">this is not the point of the video, so I&#8217;m just going to skim it. It&#8217;s not super important.</p>



<p class="wp-block-paragraph">called print null terminated string that takes in a pointer to a character array</p>



<p class="wp-block-paragraph">and a file handle for where you want to print it and what it&#8217;ll do is it&#8217;ll come</p>



<p class="wp-block-paragraph">in grab the incoming arguments it&#8217;s only got two arguments so it uses r12 and r13</p>



<p class="wp-block-paragraph">to store those arguments and then r14 is the result of calling another helper</p>



<p class="wp-block-paragraph">called string length you can imagine my string length function just kind of</p>



<p class="wp-block-paragraph">scans the string until it finds a null terminator aka the number zero not the</p>



<p class="wp-block-paragraph">zero but actually a zero in order to figure out how long the string is and then it can use a</p>



<p class="wp-block-paragraph">regular system call to print the string to the right file descriptor so we&#8217;re going to be doing</p>



<p class="wp-block-paragraph">most mostly this kind of this exact same thing when we copy the file so I&#8217;m just definitely not</p>



<p class="wp-block-paragraph">going to explain it if you don&#8217;t know pushes and pops and epilogues and prologues see my other</p>



<p class="wp-block-paragraph">videos crlf is just going to print a carriage return new line so it or sorry carriage return</p>



<p class="wp-block-paragraph">sorry, carriage return line feed.</p>



<p class="wp-block-paragraph">So that&#8217;s just like making the cursor go to the next line.</p>



<p class="wp-block-paragraph">Not a big deal.</p>



<p class="wp-block-paragraph">We just print a string basically.</p>



<p class="wp-block-paragraph">And then I have a custom die function</p>



<p class="wp-block-paragraph">that allows us to die with a failure code of one.</p>



<p class="wp-block-paragraph">Oh, I forgot to mark that.</p>



<p class="wp-block-paragraph">Let&#8217;s see, 206 exit fail.</p>



<p class="wp-block-paragraph">I&#8217;m just gonna put that down here.</p>



<p class="wp-block-paragraph">Yeah, instead of hard coding values,</p>



<p class="wp-block-paragraph">it&#8217;s a lot better to use variables if you can or defines.</p>



<p class="wp-block-paragraph">So all that&#8217;s gonna do is just kind of print</p>



<p class="wp-block-paragraph">an error message and then exit</p>



<p class="wp-block-paragraph">then exit with the you know the appropriate</p>



<p class="wp-block-paragraph">Exit code which is just going to be one because this is a simple program</p>



<p class="wp-block-paragraph">So CRLF print an alternated string dying string length a welcome message all this fun pretty stuff</p>



<p class="wp-block-paragraph">That doesn&#8217;t really do anything except make the program more fun to look at so I&#8217;m going to run it here and make sure that actually works</p>



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



<p class="wp-block-paragraph">Nice, okay, so if I run it you can see that the the make file system again</p>



<p class="wp-block-paragraph">file system again this is not a make file video so I&#8217;m not going to show you</p>



<p class="wp-block-paragraph">my make file see my other videos if you want to learn more about make files but</p>



<p class="wp-block-paragraph">you can see that the assembly program says that it started and then it just</p>



<p class="wp-block-paragraph">exited then the make file continues to run these extra commands that I have</p>



<p class="wp-block-paragraph">set up so this is not part of the assembly program this is just taking a</p>



<p class="wp-block-paragraph">checksum an MD5 checksum of the input file and then an MD5 checksum of the</p>



<p class="wp-block-paragraph">what empty five checksums are i&#8217;ll probably release a video sometime in the future if you&#8217;re</p>



<p class="wp-block-paragraph">interested on all my platforms just talking about why we why you would use a checksum but for now</p>



<p class="wp-block-paragraph">just imagine this is a fingerprint so if the fingerprints don&#8217;t match that means the files</p>



<p class="wp-block-paragraph">don&#8217;t match right now the output file doesn&#8217;t even exist so it just is an error and that&#8217;s why the</p>



<p class="wp-block-paragraph">make file thinks there&#8217;s an error because the output file didn&#8217;t exist so that&#8217;s the basics</p>



<p class="wp-block-paragraph">of kind of getting started with this you know bare bones program now let&#8217;s start looking at running</p>



<p class="wp-block-paragraph">program. Now let&#8217;s start looking at running the file tests. So file tests, we got to make a new</p>



<p class="wp-block-paragraph">method. I&#8217;m going to stick it down here. Let&#8217;s see. I got a solution up so that I don&#8217;t have to</p>



<p class="wp-block-paragraph">spend too much time typing. I&#8217;m going to try my best to balance between copy pasting and just</p>



<p class="wp-block-paragraph">typing very quickly. But let&#8217;s see, where&#8217;s the file test? So we got this. I&#8217;m going to put the</p>



<p class="wp-block-paragraph">I&#8217;m feeling pretty lazy.</p>



<p class="wp-block-paragraph">I&#8217;m just going to copy paste the whole thing.</p>



<p class="wp-block-paragraph">Copy paste the whole thing.</p>



<p class="wp-block-paragraph">So now this method right here is going to get called the file tests.</p>



<p class="wp-block-paragraph">I keep saying method because I teach C++ a lot too.</p>



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



<p class="wp-block-paragraph">If we go down further, this function is called file tests.</p>



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



<p class="wp-block-paragraph">It doesn&#8217;t take any arguments.</p>



<p class="wp-block-paragraph">It just kind of does stuff.</p>



<p class="wp-block-paragraph">It doesn&#8217;t return anything.</p>



<p class="wp-block-paragraph">And here are the registers that I&#8217;m going to use.</p>



<p class="wp-block-paragraph">the input file handle, the output file handle, and then the count of bytes read from the input</p>



<p class="wp-block-paragraph">file at any given time inside of our looping buffer reader section. So the first thing I&#8217;ve</p>



<p class="wp-block-paragraph">got to do is I&#8217;ve got to open a file to read. The second thing I&#8217;ve got to do is create a file to</p>



<p class="wp-block-paragraph">write. And then I&#8217;m going to copy the input file to the output file. And then I&#8217;m going to print</p>



<p class="wp-block-paragraph">a message saying, hey, everything was successful. And then I&#8217;m going to close both files. Notice how</p>



<p class="wp-block-paragraph">anything i&#8217;m just sort of calling other functions do the work for me again if you don&#8217;t know the</p>



<p class="wp-block-paragraph">prologue and epilogue stuff or calling functions and returning you should see my other videos</p>



<p class="wp-block-paragraph">but i just like to use helper functions assembly is like so unwieldy right it&#8217;s it just gets out</p>



<p class="wp-block-paragraph">of control so quick and so confusing so fast so anytime you can just you know take a chunk out</p>



<p class="wp-block-paragraph">of your assembly code and move it somewhere to another module or to another function</p>



<p class="wp-block-paragraph">going to make your life a lot easier and make debugging a lot easier people who try to write</p>



<p class="wp-block-paragraph">the entire portion of their program in just one gigantic function those are the people who usually</p>



<p class="wp-block-paragraph">end up spending 10 times longer debugging for no reason at all so i believe in the power of modular</p>



<p class="wp-block-paragraph">thinking so anyway what are we going to do inside of the open file read function it&#8217;s not too bad</p>



<p class="wp-block-paragraph">to be honest let&#8217;s see if i can find it real quick open file read i&#8217;m going to copy paste it because</p>



<p class="wp-block-paragraph">Again, I&#8217;m pretty lazy.</p>



<p class="wp-block-paragraph">I&#8217;ll just explain what it is though.</p>



<p class="wp-block-paragraph">So down here we need a function called open file read.</p>



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



<p class="wp-block-paragraph">And you can see the signature that I&#8217;ve chosen for this is, you know, I like to</p>



<p class="wp-block-paragraph">write all my functions in C++, uh, kind of lingo or prototypes so that I can have a</p>



<p class="wp-block-paragraph">better understanding of what the assembly is actually supposed to do.</p>



<p class="wp-block-paragraph">So you can see the function called open file read.</p>



<p class="wp-block-paragraph">I want it to take two arguments.</p>



<p class="wp-block-paragraph">two arguments the first argument should be a pointer to a string that represents the file</p>



<p class="wp-block-paragraph">name that i want to open and it should be null terminated again if you look back at my uh at</p>



<p class="wp-block-paragraph">my strings up here they all have little zeros at the end so they are all null terminated anyway uh</p>



<p class="wp-block-paragraph">so that&#8217;s the first argument that&#8217;s going to show up as rdi in assembly and then the second argument</p>



<p class="wp-block-paragraph">is the flags for opening the file so i think probably that was redundant if i if i name this</p>



<p class="wp-block-paragraph">that was redundant if i if i name this open file read then i think it should be obvious that the</p>



<p class="wp-block-paragraph">flags are just going to be the read flags only so i probably didn&#8217;t even need to provide this</p>



<p class="wp-block-paragraph">that was bad design on my part you could write a better one on your own where it&#8217;s just one argument</p>



<p class="wp-block-paragraph">and if the name is read then just use the read flags but if the maybe if you want to leave the</p>



<p class="wp-block-paragraph">flags in there you could just say open file only it&#8217;s up to you anyway so it attempts to open a</p>



<p class="wp-block-paragraph">successful it&#8217;ll return the file handle that&#8217;s the long return type right here</p>



<p class="wp-block-paragraph">long file handle if it fails then it will just basically complain and exit</p>



<p class="wp-block-paragraph">the program you probably want a more sophisticated way of handling errors in</p>



<p class="wp-block-paragraph">your program I just decided to complain and exit the entire program because this</p>



<p class="wp-block-paragraph">is you know not supposed to be super complicated I just want to show you how</p>



<p class="wp-block-paragraph">to copy files and then for me I like to leave comments that just sort of explain</p>



<p class="wp-block-paragraph">And once my functions get so complicated that I actually run out of registers,</p>



<p class="wp-block-paragraph">then that tells me I probably need to just make another function,</p>



<p class="wp-block-paragraph">you know, split the work up in some way.</p>



<p class="wp-block-paragraph">So far, so good.</p>



<p class="wp-block-paragraph">I only end up reusing the same registers for multiple purposes occasionally.</p>



<p class="wp-block-paragraph">I&#8217;m not a hardcore assembly programmer.</p>



<p class="wp-block-paragraph">I&#8217;m just, you know, I&#8217;m like medium.</p>



<p class="wp-block-paragraph">So I&#8217;m going to use R12 and 13 and 14.</p>



<p class="wp-block-paragraph">That&#8217;s why we have the prolog pushing all those registers to preserve them</p>



<p class="wp-block-paragraph">pushing all those registers to preserve them because they&#8217;re callee saved and then the epilogue</p>



<p class="wp-block-paragraph">epilogue that just kind of pops them i&#8217;ve got a label here for the function remember a function</p>



<p class="wp-block-paragraph">is just a label and then a return statement as long as you obey and respect the abi like preserving</p>



<p class="wp-block-paragraph">certain registers then you should be okay first thing i&#8217;m going to do is grab the incoming</p>



<p class="wp-block-paragraph">arguments so i&#8217;m going to grab the file name which is a pointer which means it&#8217;s just a 64-bit</p>



<p class="wp-block-paragraph">integer i can stick that into a register and then the flags same thing so i&#8217;m going to grab</p>



<p class="wp-block-paragraph">rdi and rsi the incoming arguments i&#8217;m going to stick them into r12 and r13 so the character</p>



<p class="wp-block-paragraph">pointer in the flags and then i&#8217;m going to attempt to open the file with a system call so</p>



<p class="wp-block-paragraph">system call is right there line 168 if you look up the table for system calls in my favorite book</p>



<p class="wp-block-paragraph">that i usually recommend or any table that knows the system call codes for x86-64 assembly</p>



<p class="wp-block-paragraph">call code to open a file is some number i&#8217;ve assigned that to sys open if we look up here</p>



<p class="wp-block-paragraph">open is code 2 so that&#8217;s why i you know i don&#8217;t want to remember the numbers it&#8217;s bad to hard</p>



<p class="wp-block-paragraph">code number so i just i just put it as a define and then the first argument that it wants in rdi</p>



<p class="wp-block-paragraph">is the name of the file so i just gave it r12 i guess i probably could have just used rdi</p>



<p class="wp-block-paragraph">directly in the system call but that tends to make me nervous reusing the argument registers</p>



<p class="wp-block-paragraph">registers, I like to have them somewhere where they&#8217;re not going to be destroyed.</p>



<p class="wp-block-paragraph">If I like, let&#8217;s say I accidentally added some code here on line 163.</p>



<p class="wp-block-paragraph">If I wanted to reuse RDI and I accidentally added some code there,</p>



<p class="wp-block-paragraph">then RDI would have been destroyed.</p>



<p class="wp-block-paragraph">Would have cost me a bunch of time debugging my program.</p>



<p class="wp-block-paragraph">Although I admit it&#8217;s not super efficient to do it that way.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to do the file status</p>



<p class="wp-block-paragraph">flags as the second argument, and then we just do a system call right away.</p>



<p class="wp-block-paragraph">register gives you the result of your system call.</p>



<p class="wp-block-paragraph">Notice how we use RAX to send in the call code.</p>



<p class="wp-block-paragraph">And then the system call sends us back its return result also in the RAX</p>



<p class="wp-block-paragraph">register. So I&#8217;m just going to save that right away to R14.</p>



<p class="wp-block-paragraph">You can see up here, it&#8217;s just the file handle.</p>



<p class="wp-block-paragraph">So we can assume maybe at this point that we have a file handle sitting in R14.</p>



<p class="wp-block-paragraph">You know, what is a file handle when you ask the system to open a file for you?</p>



<p class="wp-block-paragraph">The operating system under the hood is just going to do a bunch of stuff to</p>



<p class="wp-block-paragraph">bunch of stuff to actually open a file it&#8217;s going to go it&#8217;s going to take the string</p>



<p class="wp-block-paragraph">that you sent it and it&#8217;s going to parse it and figure out you know how do i how do i interpret</p>



<p class="wp-block-paragraph">where that actually is on disk i&#8217;m going to look at like the file system in the past that you</p>



<p class="wp-block-paragraph">provided i&#8217;m going to look at the mount points and i&#8217;m going to figure out like where exactly on disk</p>



<p class="wp-block-paragraph">does that file start and then the operating system stores that the operating system stores the file</p>



<p class="wp-block-paragraph">name it stores where you&#8217;re looking at the file currently stores a bunch of stuff that you don&#8217;t</p>



<p class="wp-block-paragraph">a bunch of stuff that you don&#8217;t want to have to remember you know it creates data structures under</p>



<p class="wp-block-paragraph">the hood and all it&#8217;ll give you back in return is a file handle for simplicity because then later</p>



<p class="wp-block-paragraph">you can use that file handle to just sort of say I would like to write some bytes to a file or I</p>



<p class="wp-block-paragraph">would like to read some bytes from an open file here&#8217;s the handle you gave me previously and then</p>



<p class="wp-block-paragraph">it&#8217;ll just work assuming you have a valid handle so the handle is kind of the most important part</p>



<p class="wp-block-paragraph">failed because it&#8217;s a mistake i&#8217;ve said this in other videos it&#8217;s a mistake that new programmers</p>



<p class="wp-block-paragraph">make or lazy programmers make uh let&#8217;s suppose for the sake of argument uh uh file open sys call</p>



<p class="wp-block-paragraph">pretend we&#8217;re in c plus plus and there is some sort of an api function that we can call either</p>



<p class="wp-block-paragraph">directly to the system or some person&#8217;s library and it&#8217;ll open a file for us so maybe like a</p>



<p class="wp-block-paragraph">just say we call this right so i&#8217;m going to do like a little comment if inside of your program you just</p>



<p class="wp-block-paragraph">call it with the you know some some path and then you assume that what you have is a valid you know</p>



<p class="wp-block-paragraph">handle if you assume that what you got back is a valid handle or maybe this is not a function</p>



<p class="wp-block-paragraph">just assume that the call succeeded, your program is probably going to have errors when you least</p>



<p class="wp-block-paragraph">expect it. And it&#8217;s not going to look good. Especially if you release a function like this</p>



<p class="wp-block-paragraph">to the public, or if you have like a professor who&#8217;s like grading your code and they are testing</p>



<p class="wp-block-paragraph">to see if you&#8217;re checking for return codes and stuff like that. That&#8217;s not a smart idea, right?</p>



<p class="wp-block-paragraph">Like you shouldn&#8217;t, should not, shouldn&#8217;t proceed as if everything went according to plan. What,</p>



<p class="wp-block-paragraph">just proceeding as if everything went according to plan.</p>



<p class="wp-block-paragraph">You want to use an if statement, right?</p>



<p class="wp-block-paragraph">You want to say if the handle has some value that seems to be valid,</p>



<p class="wp-block-paragraph">like for example, more than zero in the case of opening a file,</p>



<p class="wp-block-paragraph">I would say probably more than two because all of our programs</p>



<p class="wp-block-paragraph">always have automatically assigned file handles of zero and one and two</p>



<p class="wp-block-paragraph">to represent standard input, standard output, and standard error.</p>



<p class="wp-block-paragraph">But I think usually people just say like,</p>



<p class="wp-block-paragraph">if it&#8217;s greater than zero, then it&#8217;s fine.</p>



<p class="wp-block-paragraph">zero then it&#8217;s fine uh you know for me i might put greater than two but more than zero is fine</p>



<p class="wp-block-paragraph">the point is check to make sure that it actually succeeded</p>



<p class="wp-block-paragraph">do i have spell check on this thing oh god you&#8217;re all going to see my true spelling let me see if i</p>



<p class="wp-block-paragraph">can get it on real fast plug-ins what how come this oh okay now it&#8217;s highlighted</p>



<p class="wp-block-paragraph">If we&#8217;ve succeeded based on some kind of a comparison of the return result,</p>



<p class="wp-block-paragraph">then we&#8217;ll proceed in one way.</p>



<p class="wp-block-paragraph">Otherwise we&#8217;ll respond to the error by, you know, doing something else.</p>



<p class="wp-block-paragraph">Somehow, like writing a log file, sending an email, complaining to the user,</p>



<p class="wp-block-paragraph">doing any number of things where you can actually respond to the error.</p>



<p class="wp-block-paragraph">Maybe you probably want to change your execution path.</p>



<p class="wp-block-paragraph">Like if the file successfully opened, then go ahead and start writing to it</p>



<p class="wp-block-paragraph">or reading from it or whatever.</p>



<p class="wp-block-paragraph">But if the file did not successfully open,</p>



<p class="wp-block-paragraph">want to do something else in the program and not just start trying to read from the file so anyway</p>



<p class="wp-block-paragraph">super super good idea and so that&#8217;s why i&#8217;m going to implement that inside of assembly 2. so instead</p>



<p class="wp-block-paragraph">of just immediately using the file handle i&#8217;m going to check it i&#8217;m going to say let&#8217;s compare</p>



<p class="wp-block-paragraph">it to the number zero if we succeeded then let&#8217;s go to another label called uh read success i</p>



<p class="wp-block-paragraph">personally when i&#8217;m doing branching logic i like to say open file read is the name of the function</p>



<p class="wp-block-paragraph">read is the name of the function and I&#8217;ll just I&#8217;ll just uh uh append some kind of a suffix</p>



<p class="wp-block-paragraph">to the original function name that way it&#8217;s it&#8217;s easier to avoid collisions when you have lots of</p>



<p class="wp-block-paragraph">functions and lots of labels and things like that so I&#8217;m basically saying if we succeeded I&#8217;m going</p>



<p class="wp-block-paragraph">to jump to this label which is down here and so uh this video also is not about branching logic</p>



<p class="wp-block-paragraph">and and how to implement those instructions you can probably infer it by looking at my code but</p>



<p class="wp-block-paragraph">it by looking at my code but you know see another video in the future for that topic anyway if we</p>



<p class="wp-block-paragraph">succeeded in opening the file handle then we&#8217;re just going to say oh we were successful and then</p>



<p class="wp-block-paragraph">we&#8217;re going to uh um let&#8217;s see we&#8217;re going to print the name of the file that we just successfully</p>



<p class="wp-block-paragraph">opened and then we&#8217;re going to send the file handle into rax so that this function has a return</p>



<p class="wp-block-paragraph">So when you open a file to read successfully, the caller will receive the file handle.</p>



<p class="wp-block-paragraph">You might be wondering yourself, wait a minute, wait a minute, wait a minute.</p>



<p class="wp-block-paragraph">It just gave us the file handle in RAX.</p>



<p class="wp-block-paragraph">Remember, we got to respect the ABI.</p>



<p class="wp-block-paragraph">Anytime we jump anywhere or call another function or call another syscall,</p>



<p class="wp-block-paragraph">which a lot of these things do,</p>



<p class="wp-block-paragraph">we will probably lose the value of registers that are not callee preserved.</p>



<p class="wp-block-paragraph">And that&#8217;s definitely RAX.</p>



<p class="wp-block-paragraph">I mean, just doing any system call like this print null terminated string function does.</p>



<p class="wp-block-paragraph">print null terminated string function does that&#8217;s going to destroy rex so that&#8217;s why i saved it away</p>



<p class="wp-block-paragraph">first in r14 then at the very end of the function right before i return i&#8217;m just going to grab r14</p>



<p class="wp-block-paragraph">and send it into rex again respect the abi do not return data as a return value in r14 or any other</p>



<p class="wp-block-paragraph">register you have to use the designated registers and in this case an integer that you&#8217;re returning</p>



<p class="wp-block-paragraph">x anyway so that&#8217;s the gist of that let me go back up for a second uh so notice how</p>



<p class="wp-block-paragraph">we&#8217;re we&#8217;re sort of comparing oh gosh i just i just reconfigured my annotator and i bought a</p>



<p class="wp-block-paragraph">new drawpad i wonder if this is going to work ah it works there&#8217;s a bunch of stuff i added too</p>



<p class="wp-block-paragraph">so notice how uh we try to open the file and then we sort of compare the file handle to see if we</p>



<p class="wp-block-paragraph">off to the success area down here oh my green&#8217;s not working oh it&#8217;s tricky it&#8217;s tricky i gotta</p>



<p class="wp-block-paragraph">hit it in a certain way there we go if it succeeds we go down here to the success label so we</p>



<p class="wp-block-paragraph">basically at that point um totally ignore all of the fail code right we&#8217;re just like branching</p>



<p class="wp-block-paragraph">around on the other hand if it fails then execution falls through because it&#8217;s not going to jump</p>



<p class="wp-block-paragraph">if uh if if r14 is not greater than or equal to zero so if we fail maybe i should put this in a</p>



<p class="wp-block-paragraph">red if we fail then it&#8217;s going to fall through to the next label and then the next instructions</p>



<p class="wp-block-paragraph">some people like to say let&#8217;s uh let&#8217;s jump to the success label and then if not let&#8217;s jump to</p>



<p class="wp-block-paragraph">the fail label that can buy you a little bit more uh i don&#8217;t know jump length if you have a giant</p>



<p class="wp-block-paragraph">program but in this case i&#8217;m just going to let it fall through it saves us one jump instruction</p>



<p class="wp-block-paragraph">and so if it fails then it&#8217;s going to say first off let&#8217;s print a message that we failed</p>



<p class="wp-block-paragraph">to standard error if you want a refresher on standard input standard output and standard error</p>



<p class="wp-block-paragraph">see my other videos and then it&#8217;s going to print the name of the file that failed so that&#8217;s this</p>



<p class="wp-block-paragraph">part right here it&#8217;s going to say hey we we failed to print or sorry we failed to open this file name</p>



<p class="wp-block-paragraph">for reading and it&#8217;s going to print a new line there with the crlf thing</p>



<p class="wp-block-paragraph">and then it&#8217;s actually going to exit the program at that point it&#8217;s going to say all right we</p>



<p class="wp-block-paragraph">failed and so the whole program just just quits and that&#8217;s my die function that i showed you</p>



<p class="wp-block-paragraph">earlier it&#8217;s just going to call the system call code for quitting and it&#8217;s going to give a return</p>



<p class="wp-block-paragraph">code of one to indicate to anyone automating our program including new make that well our program</p>



<p class="wp-block-paragraph">failed at least it failed okay so we got all that and then we got the success and so now you kind</p>



<p class="wp-block-paragraph">of know the idea behind opening a file let&#8217;s do that real fast just for fun so file tests</p>



<p class="wp-block-paragraph">um oh i know what to do i&#8217;ll just comment out these uh instructions just so that we&#8217;re only</p>



<p class="wp-block-paragraph">doing the file open yeah that&#8217;s pretty good and then we won&#8217;t close anything just yet</p>



<p class="wp-block-paragraph">so now let me run this in the terminal real fast make run it says it successfully opened</p>



<p class="wp-block-paragraph">it says it successfully opened the file input.txt</p>



<p class="wp-block-paragraph">and then the program exited.</p>



<p class="wp-block-paragraph">No problem, that error code one,</p>



<p class="wp-block-paragraph">that&#8217;s because the output file doesn&#8217;t actually exist.</p>



<p class="wp-block-paragraph">So don&#8217;t worry about that.</p>



<p class="wp-block-paragraph">And let&#8217;s change the name of the input file</p>



<p class="wp-block-paragraph">just to show you that it can fail and we can detect it.</p>



<p class="wp-block-paragraph">I&#8217;m gonna put a two there</p>



<p class="wp-block-paragraph">so that the program will try to open an input file</p>



<p class="wp-block-paragraph">that doesn&#8217;t actually exist.</p>



<p class="wp-block-paragraph">And then I&#8217;ll run it again.</p>



<p class="wp-block-paragraph">Notice how it says fail to open file input2.txt.</p>



<p class="wp-block-paragraph">And then it says terminating program after failure to open file.</p>



<p class="wp-block-paragraph">And then this time, notice how the make file never got far enough</p>



<p class="wp-block-paragraph">so that it tried to print the MD5 sums of the input and output files.</p>



<p class="wp-block-paragraph">The assembly program just failed.</p>



<p class="wp-block-paragraph">And so GNU make said, I&#8217;m not going to proceed any further.</p>



<p class="wp-block-paragraph">Kind of useful when your program gives good exit codes, right?</p>



<p class="wp-block-paragraph">Because then other programs know when to stop</p>



<p class="wp-block-paragraph">or maybe what to do depending on what&#8217;s happening.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to fix this real fast.</p>



<p class="wp-block-paragraph">down here and maybe the next thing I want to add is closing the files so we&#8217;ve got a function to</p>



<p class="wp-block-paragraph">open a file for reading and then we have a function down here that is not implemented yet</p>



<p class="wp-block-paragraph">for closing the files so I&#8217;m going to do let&#8217;s see what is r12 r12 is the input file so I&#8217;m</p>



<p class="wp-block-paragraph">going to close r12 so basically this function it&#8217;s going to it&#8217;s going to take one argument</p>



<p class="wp-block-paragraph">handle. So that&#8217;s why I&#8217;m giving the file handle of the input file as the first argument. And then</p>



<p class="wp-block-paragraph">I&#8217;m just going to call it. So let&#8217;s copy paste close file underneath this. So I&#8217;m going to do</p>



<p class="wp-block-paragraph">like some more space. And let me let me go get this from my solution close file.</p>



<p class="wp-block-paragraph">And it&#8217;s going to be a pretty simple one. Really nothing much to it. I&#8217;m just going to write my</p>



<p class="wp-block-paragraph">C++ prototype saying, well, it takes in one argument and it&#8217;s a handle. It doesn&#8217;t return</p>



<p class="wp-block-paragraph">argument and it&#8217;s a handle it doesn&#8217;t return anything it attempts to close a</p>



<p class="wp-block-paragraph">file and I&#8217;m just gonna use R12 to hold the incoming argument your programs at</p>



<p class="wp-block-paragraph">home should probably be a little bit better than mine you should check to see</p>



<p class="wp-block-paragraph">if the file successfully closed or not and respond in some kind of a way but</p>



<p class="wp-block-paragraph">for me I&#8217;m just saying I don&#8217;t really care I already showed you that we can</p>



<p class="wp-block-paragraph">check for a return value so I&#8217;m allowed to be lazy now and just sort of try to</p>



<p class="wp-block-paragraph">close it and then just assume it all went according to plan so grabbing the</p>



<p class="wp-block-paragraph">So grabbing the incoming arguments here.</p>



<p class="wp-block-paragraph">That&#8217;s why I&#8217;m using R12.</p>



<p class="wp-block-paragraph">That&#8217;s why I&#8217;m doing a push-pop pair.</p>



<p class="wp-block-paragraph">And then the system call code to close is pretty easy.</p>



<p class="wp-block-paragraph">You just say, here&#8217;s the code to close.</p>



<p class="wp-block-paragraph">Stick that in RAX.</p>



<p class="wp-block-paragraph">Let me go up real fast.</p>



<p class="wp-block-paragraph">Notice how sysclose is the call code number three</p>



<p class="wp-block-paragraph">on line 43 there.</p>



<p class="wp-block-paragraph">So I send it the call code three to say, let&#8217;s close a file.</p>



<p class="wp-block-paragraph">It only wants one argument, which is just,</p>



<p class="wp-block-paragraph">what is the file handle that you want me to close?</p>



<p class="wp-block-paragraph">what is the file handle that you want me to close remember before the operating system created a</p>



<p class="wp-block-paragraph">bunch of stuff under the hood and gave you a file handle you can then use the file handle</p>



<p class="wp-block-paragraph">to close a file read a file write to the file whatever to the file so it&#8217;s pretty easy once</p>



<p class="wp-block-paragraph">i&#8217;ve set up the incoming arguments to the system then i actually use the system call instruction</p>



<p class="wp-block-paragraph">syscall and then i can assume it&#8217;s probably closed at that point then a return statement at the end</p>



<p class="wp-block-paragraph">like any additional thing happening.</p>



<p class="wp-block-paragraph">It should just be, it said it successfully opened the file</p>



<p class="wp-block-paragraph">and then it just exited.</p>



<p class="wp-block-paragraph">Okay, now we&#8217;re ready to add a little bit more.</p>



<p class="wp-block-paragraph">Let&#8217;s create a file to write.</p>



<p class="wp-block-paragraph">So this is going to be the same thing basically</p>



<p class="wp-block-paragraph">as opening a file to read,</p>



<p class="wp-block-paragraph">except it&#8217;s going to be a different call code</p>



<p class="wp-block-paragraph">and we&#8217;ll give it initial file permissions</p>



<p class="wp-block-paragraph">rather than a read mode flag.</p>



<p class="wp-block-paragraph">But then we&#8217;ll just get a file handle in return.</p>



<p class="wp-block-paragraph">get a file handle in return.</p>



<p class="wp-block-paragraph">And I&#8217;ve also stuck this into another function, of course.</p>



<p class="wp-block-paragraph">So the file name to write line 109.</p>



<p class="wp-block-paragraph">If you just scroll up real fast here, or if I scroll up real fast,</p>



<p class="wp-block-paragraph">it&#8217;s a line 27 here, just output.txt.</p>



<p class="wp-block-paragraph">And then the file permissions that we want to use.</p>



<p class="wp-block-paragraph">I&#8217;m going to scroll up here.</p>



<p class="wp-block-paragraph">That&#8217;s the second argument to the system call code.</p>



<p class="wp-block-paragraph">That&#8217;s just the stuff that I talked about a little while ago where it&#8217;s like,</p>



<p class="wp-block-paragraph">we want the user to be able to read and write to the file.</p>



<p class="wp-block-paragraph">to be able to read and write to the file we want people in the same group to be able to read only</p>



<p class="wp-block-paragraph">and we want everyone else to not be able to do anything basic linux permissions not a big deal</p>



<p class="wp-block-paragraph">at the end you should probably maybe note that uh you know this q i think i might have said this</p>



<p class="wp-block-paragraph">before this q just means quad word and these zeros are always going to be the same so really it&#8217;s just</p>



<p class="wp-block-paragraph">like three numbers representing file permissions i&#8217;ll go over that in more detail in some other</p>



<p class="wp-block-paragraph">So for now, we know that we&#8217;re going to open a file name to we&#8217;re going to open a file</p>



<p class="wp-block-paragraph">for writing doesn&#8217;t have to exist yet.</p>



<p class="wp-block-paragraph">We&#8217;ll give it some default permissions.</p>



<p class="wp-block-paragraph">And those are the incoming arguments to the function that we&#8217;re going to call now called</p>



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



<p class="wp-block-paragraph">When that file when that function comes back, assuming it didn&#8217;t decide to exit the program</p>



<p class="wp-block-paragraph">because we failed to open the file, we will receive the file handle in our ex per usual.</p>



<p class="wp-block-paragraph">And so I&#8217;m just going to stash that away real fast into our 13.</p>



<p class="wp-block-paragraph">Remember R12 has the handle to the input file.</p>



<p class="wp-block-paragraph">R13 has the handle to the output file.</p>



<p class="wp-block-paragraph">And then, you know, for me personally,</p>



<p class="wp-block-paragraph">I put that in comments to help myself remember</p>



<p class="wp-block-paragraph">what I&#8217;m even doing,</p>



<p class="wp-block-paragraph">because things can get confusing really, really fast.</p>



<p class="wp-block-paragraph">And while we&#8217;re at it,</p>



<p class="wp-block-paragraph">before we even write the create file function,</p>



<p class="wp-block-paragraph">I might as well just uncomment these things at the bottom,</p>



<p class="wp-block-paragraph">just to say, let&#8217;s close both files properly.</p>



<p class="wp-block-paragraph">You always want to do that.</p>



<p class="wp-block-paragraph">let&#8217;s copy paste the create file function let&#8217;s see I didn&#8217;t do that already right yeah okay</p>



<p class="wp-block-paragraph">so let&#8217;s do that maybe like right here I&#8217;m going to go grab it from my solution real fast create</p>



<p class="wp-block-paragraph">file okay about as complicated as opening a file just because I put in some some checking logic to</p>



<p class="wp-block-paragraph">see if it successfully opened the file which is a good idea so here&#8217;s my function create file</p>



<p class="wp-block-paragraph">arguments. Oh shoot, file creation hand. Let&#8217;s see, am I using R13? Yeah, oh, I mislabeled that.</p>



<p class="wp-block-paragraph">Instead of saying flags, it should be permissions. So let me just do perms here. Long perms,</p>



<p class="wp-block-paragraph">file creation perms, perm. I wish I could get a perm, if you know what I mean. Anyway, so,</p>



<p class="wp-block-paragraph">you know, we just have like the file name that comes in and the permissions that come in,</p>



<p class="wp-block-paragraph">And it&#8217;s going to return a handle just like we did with the read file for opening function.</p>



<p class="wp-block-paragraph">But this time we&#8217;re going to do something slightly different.</p>



<p class="wp-block-paragraph">So the system call is going to be the code for creating a file.</p>



<p class="wp-block-paragraph">SYS create, which is not real unless you define it.</p>



<p class="wp-block-paragraph">So if we just look up, I define that as.</p>



<p class="wp-block-paragraph">Where is it?</p>



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



<p class="wp-block-paragraph">So like right here, code 85 for system create.</p>



<p class="wp-block-paragraph">Again, not a smart idea to hard code numbers.</p>



<p class="wp-block-paragraph">Defines are way better.</p>



<p class="wp-block-paragraph">numbers defines are way better. So then the first argument that it wants is the name of the file.</p>



<p class="wp-block-paragraph">That&#8217;s the incoming argument that I took into R12. It has to be a null terminated string. It&#8217;s going</p>



<p class="wp-block-paragraph">to be output.txt. Then the second argument is the file&#8217;s permissions. So that&#8217;s R13 that I took here</p>



<p class="wp-block-paragraph">from the second argument, long perms. Once I&#8217;ve set up those things, I can do the system call</p>



<p class="wp-block-paragraph">right away. The system, again, will try to open the file. It&#8217;ll try to create the file,</p>



<p class="wp-block-paragraph">set up some data structures under the hood. If it succeeds, it&#8217;ll give me a valid file handle</p>



<p class="wp-block-paragraph">in RAX, the return register. If not, then things have failed and I need to respond to that. So</p>



<p class="wp-block-paragraph">I&#8217;m just going to stash the file handle in R14 right away. That&#8217;s why I&#8217;m also preserving R14</p>



<p class="wp-block-paragraph">in the push pop pair that I have, R14 up at the top and the bottom.</p>



<p class="wp-block-paragraph">So now we got to check whether or not we successfully created the file. Again,</p>



<p class="wp-block-paragraph">logic is just opening up off a reading I&#8217;m going to compare our 14 to zero if</p>



<p class="wp-block-paragraph">it&#8217;s greater than zero I&#8217;m going to assume it&#8217;s a valid file handle so jump</p>



<p class="wp-block-paragraph">if it&#8217;s greater than or equal to to that label create file success I&#8217;m still</p>



<p class="wp-block-paragraph">using my appending can naming convention so the name of the function is create</p>



<p class="wp-block-paragraph">file so that means the success area is create file and then append underscore</p>



<p class="wp-block-paragraph">success and so then I&#8217;m just gonna you know print a cute message saying hey we</p>



<p class="wp-block-paragraph">successfully created the file. Yay.</p>



<p class="wp-block-paragraph">Same thing that we looked at before basically.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to return the file handle in RAX.</p>



<p class="wp-block-paragraph">If we fail, same thing that we did before when we were opening a read file,</p>



<p class="wp-block-paragraph">I&#8217;m just going to complain basically to the user and then call on my little</p>



<p class="wp-block-paragraph">die function to properly exit the assembly program with a</p>



<p class="wp-block-paragraph">exit code of one, you know,</p>



<p class="wp-block-paragraph">and I could enhance that to exit with different codes. Like maybe exit code.</p>



<p class="wp-block-paragraph">Maybe exit code one means the read file didn&#8217;t work and exit code two means the</p>



<p class="wp-block-paragraph">write file didn&#8217;t work and exit code three means we failed for some reason</p>



<p class="wp-block-paragraph">while we were copying the data, you know, whatever you want.</p>



<p class="wp-block-paragraph">I&#8217;m keeping it kind of simple.</p>



<p class="wp-block-paragraph">So we got all that.</p>



<p class="wp-block-paragraph">Again, this is not different than reading just, you know, the call codes pretty</p>



<p class="wp-block-paragraph">much and, you know, the arguments, but the idea is the same.</p>



<p class="wp-block-paragraph">So now we&#8217;re ready to uncomment.</p>



<p class="wp-block-paragraph">I think we actually already did that.</p>



<p class="wp-block-paragraph">We&#8217;re ready to let the program try to create the file.</p>



<p class="wp-block-paragraph">to create the file and the only thing we need to add after that is the copying portion and the</p>



<p class="wp-block-paragraph">successful message so let&#8217;s see if this works do clear and make run so you can see that the program</p>



<p class="wp-block-paragraph">starts running here and then it says okay the module started and then it says we successfully</p>



<p class="wp-block-paragraph">opened the read file and then we successfully created the output file notice how the make file</p>



<p class="wp-block-paragraph">doesn&#8217;t fail when it tries to call the md5 checksum of the output file because now it actually exists</p>



<p class="wp-block-paragraph">because now it actually exists if we list the program uh list the directory here you&#8217;ll see</p>



<p class="wp-block-paragraph">that the out file has actually been created it just has a length of zero because there&#8217;s nothing</p>



<p class="wp-block-paragraph">inside of it notice also that the permissions match what we intended the initial user can read</p>



<p class="wp-block-paragraph">and write or the owning user can read and write the group can only read and everybody else can do</p>



<p class="wp-block-paragraph">nothing to heck with you we could change that real fast just to show you i can get this r to</p>



<p class="wp-block-paragraph">show you i can get this r to turn into an rw just by modifying permissions up here</p>



<p class="wp-block-paragraph">you know giving permissions to a group uh just is a nice way of allowing multiple users</p>



<p class="wp-block-paragraph">to have a shared file location you know add them all to the same group and then set that group</p>



<p class="wp-block-paragraph">onto the file and then set the group permissions to allow people to do whatever you want them to</p>



<p class="wp-block-paragraph">do read or read and write or whatever so let&#8217;s see where the perms i&#8217;m going to change this</p>



<p class="wp-block-paragraph">So now the group people should be able to read and write.</p>



<p class="wp-block-paragraph">I can&#8217;t remember if this will work because the file already exists.</p>



<p class="wp-block-paragraph">Let me give it a try.</p>



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



<p class="wp-block-paragraph">I ran it one more time and it looks like it did not create the file because it already</p>



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



<p class="wp-block-paragraph">So let me just remove output.txt.</p>



<p class="wp-block-paragraph">There should be another system call code you could use to just check to see if a file</p>



<p class="wp-block-paragraph">exists or if you wanted to be kind of hacky, you could just try to open the file and see</p>



<p class="wp-block-paragraph">open the file and see if it succeeded and then close it right away.</p>



<p class="wp-block-paragraph">I wonder if there is a call code for just exists only.</p>



<p class="wp-block-paragraph">I don&#8217;t remember off the top of my head.</p>



<p class="wp-block-paragraph">So I&#8217;m going to remove it and then run the program again.</p>



<p class="wp-block-paragraph">And then we should see now.</p>



<p class="wp-block-paragraph">Yeah, now that the file didn&#8217;t exist and was newly created.</p>



<p class="wp-block-paragraph">Now those new permissions that we added are reflected.</p>



<p class="wp-block-paragraph">So the group, anybody who&#8217;s on the group can read and write.</p>



<p class="wp-block-paragraph">And obviously the group is just the same as my new user by default.</p>



<p class="wp-block-paragraph">But again, you could be more complicated than that.</p>



<p class="wp-block-paragraph">you were running a multi-user system</p>



<p class="wp-block-paragraph">and you wanted to share folders or whatever.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m gonna remove output real fast</p>



<p class="wp-block-paragraph">and I&#8217;m just gonna revert the permissions to 640</p>



<p class="wp-block-paragraph">so that the group really can&#8217;t do very much</p>



<p class="wp-block-paragraph">except just read it.</p>



<p class="wp-block-paragraph">And then if I, oh shoot.</p>



<p class="wp-block-paragraph">LS, okay, yeah.</p>



<p class="wp-block-paragraph">So now you can see it reverted.</p>



<p class="wp-block-paragraph">Okay, so we got the out file.</p>



<p class="wp-block-paragraph">I&#8217;m starting to get lost here.</p>



<p class="wp-block-paragraph">I&#8217;m starting to get lost here. What am I doing? I&#8217;m supposed to copy the data, I think. So file</p>



<p class="wp-block-paragraph">tests and we are copying the file. I think I just uncommented that. Really? Oh, no, no, no. I&#8217;m</p>



<p class="wp-block-paragraph">looking at my solution repo. Okay. That&#8217;s what I&#8217;m doing wrong. So we&#8217;ll look into your repo or your</p>



<p class="wp-block-paragraph">the copy file I was like what how did I how did that program run if I already uncommented that</p>



<p class="wp-block-paragraph">and we&#8217;ll we&#8217;ll uncomment this message for now no let&#8217;s leave it until we actually finish everything</p>



<p class="wp-block-paragraph">so now we got to do the copy file function so where&#8217;s that okay I&#8217;m going to copy paste this</p>



<p class="wp-block-paragraph">whole thing you know what this would have been like a five hour video if I actually had to type</p>



<p class="wp-block-paragraph">this by hand I can&#8217;t even remember how long it took me to write this program I think it was like</p>



<p class="wp-block-paragraph">off the top of my head. So this would be a nightmare to type, I think, on video, even if I</p>



<p class="wp-block-paragraph">kind of already know how to do it now. So let&#8217;s see, string length, print an alternated string.</p>



<p class="wp-block-paragraph">This is close file. This is create file. Okay, so I&#8217;m just going to do copy.</p>



<p class="wp-block-paragraph">File is going to be right before close file and right after create file. Okay, so copy file.</p>



<p class="wp-block-paragraph">Notice the signature that I&#8217;ve chosen for this one. It doesn&#8217;t return anything. So</p>



<p class="wp-block-paragraph">So that&#8217;s like not great design.</p>



<p class="wp-block-paragraph">You know, I need to check to see if the copying operations inside of my loop actually succeeded</p>



<p class="wp-block-paragraph">and maybe return something to indicate success or failure or at least exit the program.</p>



<p class="wp-block-paragraph">But I&#8217;m not doing that right now.</p>



<p class="wp-block-paragraph">I&#8217;m just keeping it a little bit more simple.</p>



<p class="wp-block-paragraph">It takes two arguments.</p>



<p class="wp-block-paragraph">The first thing is the input handle and the second thing is the output handle.</p>



<p class="wp-block-paragraph">Conveniently, we have both of those now at this point.</p>



<p class="wp-block-paragraph">And then here&#8217;s my register usage.</p>



<p class="wp-block-paragraph">through r15 to just sort of grab the incoming arguments here for r12 and 13 and then</p>



<p class="wp-block-paragraph">r14 grabs the beginning of the temporary buffer which i&#8217;m going to make on the stack because i</p>



<p class="wp-block-paragraph">think i&#8217;m so cool instead of making it as a global in the bss section and then uh</p>



<p class="wp-block-paragraph">r15 is going to hold the result from the copy operation or i guess the the write operation so</p>



<p class="wp-block-paragraph">Sorry, the read operation only.</p>



<p class="wp-block-paragraph">Oh, I think I&#8217;m only checking the read bytes instead of the read and the write bytes.</p>



<p class="wp-block-paragraph">I&#8217;ll talk about that in a second.</p>



<p class="wp-block-paragraph">So I could upgrade my program a little bit more if I wanted to.</p>



<p class="wp-block-paragraph">But basically R15 is going to be my temporary variable that looks at the return value to</p>



<p class="wp-block-paragraph">say, hey, did we do we read anything?</p>



<p class="wp-block-paragraph">Like how much did we read?</p>



<p class="wp-block-paragraph">So copy file.</p>



<p class="wp-block-paragraph">This is not a video about making local variables.</p>



<p class="wp-block-paragraph">So just trust me on this.</p>



<p class="wp-block-paragraph">so that I can use it to save the location of the stack pointer.</p>



<p class="wp-block-paragraph">Then I&#8217;m going to make a copy buffer on the stack</p>



<p class="wp-block-paragraph">just by subtracting the stack pointer</p>



<p class="wp-block-paragraph">because the stack grows downward in memory location numbers.</p>



<p class="wp-block-paragraph">And then the base pointer is going to help me remember</p>



<p class="wp-block-paragraph">where the stack was when I started.</p>



<p class="wp-block-paragraph">I&#8217;m just going to say that that&#8217;s going to be the first byte in my buffer.</p>



<p class="wp-block-paragraph">And I&#8217;m going to move that into R14.</p>



<p class="wp-block-paragraph">And let&#8217;s see, what did I do?</p>



<p class="wp-block-paragraph">Let&#8217;s see, what did I do?</p>



<p class="wp-block-paragraph">Think about from the stack.</p>



<p class="wp-block-paragraph">Oh, did I write like a good program or a bad program?</p>



<p class="wp-block-paragraph">I feel like I should have actually saved the base pointer and not the stack pointer there.</p>



<p class="wp-block-paragraph">Let me see if this runs.</p>



<p class="wp-block-paragraph">If it does run, I probably have a naughty program that might self-corrupt sometimes.</p>



<p class="wp-block-paragraph">And it might be a good idea to move the base pointer as the first.</p>



<p class="wp-block-paragraph">Because this is not a stack video, but basically the stack grows downward.</p>



<p class="wp-block-paragraph">that means you&#8217;re sort of like extending its reach you&#8217;re allocating like a free space</p>



<p class="wp-block-paragraph">if i take where the stack</p>



<p class="wp-block-paragraph">nope nope nope i got it right i&#8217;m sorry if i take where the stack ends up after i extend it then i</p>



<p class="wp-block-paragraph">have a lower address right because it grows downward to memory if i then say that the new</p>



<p class="wp-block-paragraph">tip where it grew not where it grew from but where it grew to if i say that&#8217;s the first bite in a</p>



<p class="wp-block-paragraph">in a buffer then when you&#8217;re actually using the buffer you increase memory locations as you&#8217;re</p>



<p class="wp-block-paragraph">filling up a buffer so then that&#8217;s going to grow back towards where the stack started so it should</p>



<p class="wp-block-paragraph">be fine i think if i if i did go ahead and reverse this if i used rbp instead of rsp there then i</p>



<p class="wp-block-paragraph">think i would be going in the wrong direction and just corrupting memory so just so you know</p>



<p class="wp-block-paragraph">this is not a stack video but just so you know so here&#8217;s a little label again i&#8217;m just kind of</p>



<p class="wp-block-paragraph">iteration label and at the bottom I&#8217;m just kind of jumping back up to that label so this is a loop</p>



<p class="wp-block-paragraph">you can imagine this is a while loop maybe I should draw that for fun I gotta find more excuses</p>



<p class="wp-block-paragraph">to use my drophead so this is kind of like a while loop I&#8217;ll say while true maybe and here&#8217;s like the</p>



<p class="wp-block-paragraph">body and then here&#8217;s like maybe the end of the body and so this jump statement just kind of goes back</p>



<p class="wp-block-paragraph">this thing&#8217;s going to frustrate me so the first thing that happens is we read a portion</p>



<p class="wp-block-paragraph">of the input file into the buffer so what are we doing we&#8217;re just using another system call</p>



<p class="wp-block-paragraph">we&#8217;re saying let&#8217;s use the call code for read I can&#8217;t remember what that was it might have been</p>



<p class="wp-block-paragraph">uh whoops oh I cleared the dang drawing oh hang on I have undo I think wait I have that I&#8217;m gonna</p>



<p class="wp-block-paragraph">Okay, I&#8217;m not going to mess with it because this will actually terminate my whole program.</p>



<p class="wp-block-paragraph">One of these keys, I forgot which one, will just kill the whole annotator.</p>



<p class="wp-block-paragraph">So if we go up to SYS read in the defines, you can see that it is just call code zero.</p>



<p class="wp-block-paragraph">So that means I&#8217;m telling the system I would like to read something.</p>



<p class="wp-block-paragraph">First argument it wants is a file descriptor for the input file.</p>



<p class="wp-block-paragraph">In a different video, I showed you how to use exactly this sort of thing to read standard</p>



<p class="wp-block-paragraph">of thing to read standard input from the user or from another program that launched your program</p>



<p class="wp-block-paragraph">but in this case r12 it&#8217;s not going to be the file handle zero for standard input it&#8217;s going</p>



<p class="wp-block-paragraph">to be the actual file handle of the file that you&#8217;re trying to read from whatever that may have</p>



<p class="wp-block-paragraph">been whatever the os gave you and then here here&#8217;s the address of where to store our characters and</p>



<p class="wp-block-paragraph">if you look up again we decided to remember where the first byte in our buffer on the stack was or</p>



<p class="wp-block-paragraph">like a local array like oh shoot let&#8217;s do it again let&#8217;s do more drawings you have like a function</p>



<p class="wp-block-paragraph">right in c and then here it&#8217;s like we declared a local variable maybe not int maybe a character</p>



<p class="wp-block-paragraph">array we&#8217;ll call it a or how about b for buffer and then we just gave it you know let&#8217;s say eight</p>



<p class="wp-block-paragraph">bytes or something for the buffer i think i still have it set to two bytes obviously you want to use</p>



<p class="wp-block-paragraph">more bytes for efficiency but just to prove that the loop actually works i&#8217;m keeping it small like</p>



<p class="wp-block-paragraph">keeping it small like I said before whoa what&#8217;s all that you see that it&#8217;s like smearing okay</p>



<p class="wp-block-paragraph">that&#8217;s not good so uh anyway we remembered where the uh buffer starts and it&#8217;s going to be r14</p>



<p class="wp-block-paragraph">and then the copy buffer length is being you know used here uh and I think I have that set up to uh</p>



<p class="wp-block-paragraph">from the input file and we want to read into our temporary buffer and we want to read at most</p>



<p class="wp-block-paragraph">this many characters and then we say system call and it does all the work for us to read that many</p>



<p class="wp-block-paragraph">characters and then we want to remember how many bytes were actually read because that could be</p>



<p class="wp-block-paragraph">different from the number of bytes we requested maybe we&#8217;re at the end of the file maybe the</p>



<p class="wp-block-paragraph">system is having like some kind of a buffer issue or something so we just want to remember how many</p>



<p class="wp-block-paragraph">this little token up there to remind myself the temporary bytes read should</p>



<p class="wp-block-paragraph">go there. Notice also that when we created the stack,</p>



<p class="wp-block-paragraph">this is not a stack video again,</p>



<p class="wp-block-paragraph">but like I made the stack buffer equal to the length of the buffer that I</p>



<p class="wp-block-paragraph">actually wanted to use. So I use the same symbol,</p>



<p class="wp-block-paragraph">copy buffer length and copy buffer length.</p>



<p class="wp-block-paragraph">So then it&#8217;s going to try to figure out, okay,</p>



<p class="wp-block-paragraph">how many bytes did we actually read? Let me,</p>



<p class="wp-block-paragraph">let me do that while loop thing again. Cause I&#8217;m, I&#8217;m feeling it.</p>



<p class="wp-block-paragraph">I&#8217;m feeling it.</p>



<p class="wp-block-paragraph">feeling it did i really have to write the word true especially my bad penmanship so we&#8217;re doing</p>



<p class="wp-block-paragraph">while true and then i&#8217;ll just say like read you know do some kind of a call to read maybe we&#8217;ll</p>



<p class="wp-block-paragraph">say n equals read like a long you know the the r15 uh register is like the number of bytes that we</p>



<p class="wp-block-paragraph">actually read and then we do a comparison here so we&#8217;re saying you know if you know n is um</p>



<p class="wp-block-paragraph">if it&#8217;s equal to zero then we&#8217;re going to jump to the position in the while loop where we&#8217;re</p>



<p class="wp-block-paragraph">um done which is actually past the while loop if you scroll down you&#8217;ll kind of see it so i&#8217;m just</p>



<p class="wp-block-paragraph">going to say break so basically if we read zero bytes then we&#8217;re done reading bytes we&#8217;re just</p>



<p class="wp-block-paragraph">finished so we just break the while loop and that&#8217;s what&#8217;s going to happen here when we say</p>



<p class="wp-block-paragraph">the end of the body and you&#8217;ll see that in a second so then otherwise if we&#8217;re not done that</p>



<p class="wp-block-paragraph">means execution is not going to jump it&#8217;s going to just fall through to the next statement here</p>



<p class="wp-block-paragraph">and that&#8217;s going to be another system call code to write to the output file and it&#8217;s going to be</p>



<p class="wp-block-paragraph">very similar we just load it up with the system call code for write let me just double check</p>



<p class="wp-block-paragraph">is code one and then we&#8217;re going to give it the target for output which is going to be</p>



<p class="wp-block-paragraph">a file handle so you know r13 r13 right here that&#8217;s a file handle that&#8217;s where we want to</p>



<p class="wp-block-paragraph">write and then the next argument that it wants is the buffer and that&#8217;s going to be r14 which</p>



<p class="wp-block-paragraph">is where we just what&#8217;s going on green grain there we go i&#8217;m having issues that&#8217;s uh the</p>



<p class="wp-block-paragraph">that&#8217;s uh the buffer that we just read into right so if you look here r14 green oh my gosh okay so</p>



<p class="wp-block-paragraph">green we uh read from uh the buffer pointed to by r14 and then we uh we read into the buffer</p>



<p class="wp-block-paragraph">pointed to by r14 and then we are using that same buffer pointed to by r14 in order to grab</p>



<p class="wp-block-paragraph">R15 says how many files or sorry, how many bytes?</p>



<p class="wp-block-paragraph">Green, I&#8217;m having such problems.</p>



<p class="wp-block-paragraph">R15 says how many bytes do you want to write to the file?</p>



<p class="wp-block-paragraph">That should be our return value from before, right?</p>



<p class="wp-block-paragraph">Because we want to read a certain number of bytes from the file</p>



<p class="wp-block-paragraph">and then write exactly that many bytes.</p>



<p class="wp-block-paragraph">If we did more, we would be writing some junk data probably.</p>



<p class="wp-block-paragraph">And if we wrote less, then we would be missing data in the output file</p>



<p class="wp-block-paragraph">that was originally in the input file.</p>



<p class="wp-block-paragraph">So you want to do it exactly.</p>



<p class="wp-block-paragraph">in the input file so you want to do it exactly and of course i&#8217;m just doing a system call here</p>



<p class="wp-block-paragraph">but like i said before your program should probably be a little bit smarter and check</p>



<p class="wp-block-paragraph">rax after you write to the file just to make sure that you know how many bytes were actually written</p>



<p class="wp-block-paragraph">like what if you what if you read a hundred bytes but then you wrote 90 bytes only right that would</p>



<p class="wp-block-paragraph">be like a bad situation so you&#8217;d want to do some branching logic there so that if you read 100 and</p>



<p class="wp-block-paragraph">100 and you wrote 90 you probably want to backtrack the position of the file by like 10.</p>



<p class="wp-block-paragraph">You know just to make sure that you can actually get all of the bytes into the output file</p>



<p class="wp-block-paragraph">and seeking backwards 10 that&#8217;s just another system call. It&#8217;s not in this program but it&#8217;s</p>



<p class="wp-block-paragraph">not too bad. You just make another system call give it the right call code tell it how far back</p>



<p class="wp-block-paragraph">you want to go no problem. So then when by the time we make it here we&#8217;re going to jump back</p>



<p class="wp-block-paragraph">We&#8217;re going to jump back up to the iterate label.</p>



<p class="wp-block-paragraph">Let&#8217;s see, where&#8217;s that?</p>



<p class="wp-block-paragraph">Yeah, right there.</p>



<p class="wp-block-paragraph">We&#8217;re going to jump back up to the iterate label.</p>



<p class="wp-block-paragraph">So basically this is how the while loop continues looping.</p>



<p class="wp-block-paragraph">So let me clear that real fast.</p>



<p class="wp-block-paragraph">Eventually when we&#8217;re out of data to read, you know, that&#8217;s because if we try to read</p>



<p class="wp-block-paragraph">and we end up with zero bytes, that means we&#8217;re done.</p>



<p class="wp-block-paragraph">We&#8217;ll break the while loop.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to go down here.</p>



<p class="wp-block-paragraph">Notice how it says copy file done.</p>



<p class="wp-block-paragraph">What I was talking about before, just sort of jumping past the end of the body.</p>



<p class="wp-block-paragraph">so if we are done we jump to copy file done and all it does is just restore a</p>



<p class="wp-block-paragraph">bunch of registers for us and then return to the caller so copy file we have that</p>



<p class="wp-block-paragraph">handled now and if I go back up here file tests I guess I can I feel bad about</p>



<p class="wp-block-paragraph">this I can uncomment the success message but we probably should have done more</p>



<p class="wp-block-paragraph">checking on the reads and the rights just to make sure that we actually wrote</p>



<p class="wp-block-paragraph">to make sure that we actually wrote the correct amount of characters and everything succeeded</p>



<p class="wp-block-paragraph">every time and if not we exit the program and only if everything went well then we print a</p>



<p class="wp-block-paragraph">successful message at this point in this program the way it&#8217;s written it could totally fail and</p>



<p class="wp-block-paragraph">it&#8217;ll still say that it was successful so just keep that in mind that&#8217;s bad bad for your users</p>



<p class="wp-block-paragraph">okay i think we have everything that we need now i can probably just run the program and</p>



<p class="wp-block-paragraph">run. Notice now, oh shoot, I didn&#8217;t even show this to you before. Let me just emphasize this</p>



<p class="wp-block-paragraph">one more time real fast. So I&#8217;m going to comment out the part where we actually copy the file</p>



<p class="wp-block-paragraph">and I&#8217;m going to remove the output file. Then I&#8217;m going to run the whole program again. Notice how</p>



<p class="wp-block-paragraph">the two MD5 sums are different. So remember before I said that MD5 sums, they&#8217;re basically</p>



<p class="wp-block-paragraph">fingerprints. They&#8217;re not actually considered secure in the modern era. I just use them because</p>



<p class="wp-block-paragraph">and fun if you are interested in security you probably want to use a</p>



<p class="wp-block-paragraph">modern hashing algorithm so don&#8217;t use md5 but I am but don&#8217;t but I am and it&#8217;s</p>



<p class="wp-block-paragraph">basically saying the fingerprint here of input is different than the fingerprint</p>



<p class="wp-block-paragraph">here of the output quickly indicating to me that the files are different so if I</p>



<p class="wp-block-paragraph">list the contents of the directory obviously that&#8217;s true because the output</p>



<p class="wp-block-paragraph">file is empty still but if I uncomment this part here where I&#8217;m actually</p>



<p class="wp-block-paragraph">here where I&#8217;m actually copying the file then I should see that the fingerprints</p>



<p class="wp-block-paragraph">match and then if I look at what&#8217;s inside of the output file it should match</p>



<p class="wp-block-paragraph">what&#8217;s inside of the input file really fast let me open up a terminal and I&#8217;ll</p>



<p class="wp-block-paragraph">just cat the input file so this is all I added you know why hello there add some</p>



<p class="wp-block-paragraph">stuff this is definitely more than two characters so we can be sure that our</p>



<p class="wp-block-paragraph">buffer loop is actually working and so I&#8217;m gonna do clear and make run and now</p>



<p class="wp-block-paragraph">And now the output file, notice how it has a matching file size.</p>



<p class="wp-block-paragraph">It&#8217;s got 38 bytes in there.</p>



<p class="wp-block-paragraph">Same thing for the input.</p>



<p class="wp-block-paragraph">And then the thumbprints or, you know, the signatures, whatever you want to call it,</p>



<p class="wp-block-paragraph">the hashes, they match exactly, indicating that we probably have two identical files.</p>



<p class="wp-block-paragraph">Even with MD5, even though it&#8217;s old and not considered secure,</p>



<p class="wp-block-paragraph">the chances of two files kind of having random differences,</p>



<p class="wp-block-paragraph">not hacked differences, but just like random differences,</p>



<p class="wp-block-paragraph">and having the same fingerprint is like astronomically almost impossible so if i do</p>



<p class="wp-block-paragraph">cat input oops input.txt that&#8217;s what&#8217;s in there like we showed before and if i cat the output</p>



<p class="wp-block-paragraph">now it is uh the same thing why hello there added some stuff for both i could make this as big as i</p>



<p class="wp-block-paragraph">wanted to just for fun maybe let&#8217;s do uh let&#8217;s do a nano on the input file</p>



<p class="wp-block-paragraph">I&#8217;ll just add like I don&#8217;t even know what I&#8217;m doing I&#8217;m just going to type a bunch of stuff</p>



<p class="wp-block-paragraph">oh wait what is this remember that thing that people got taught a long time ago it was like</p>



<p class="wp-block-paragraph">the quick brown fox jumped over the lazy dog and this was supposed to be all the letters of the</p>



<p class="wp-block-paragraph">alphabet there was an there&#8217;s another one that I just heard about and I don&#8217;t remember exactly</p>



<p class="wp-block-paragraph">look it up on the internet it&#8217;s it&#8217;s pretty cool i think i need to memorize this and stop using the</p>



<p class="wp-block-paragraph">lazy dog it was um something like those sphinx of quartz hear my vow or something like that</p>



<p class="wp-block-paragraph">you know what i&#8217;m gonna look it up for you right now i don&#8217;t want to do the wrong thing</p>



<p class="wp-block-paragraph">it&#8217;s really cool uh i&#8217;ll type brown fox and then uh</p>



<p class="wp-block-paragraph">Hear my vow.</p>



<p class="wp-block-paragraph">Oh, Sphinx of black quartz.</p>



<p class="wp-block-paragraph">Judge my vow.</p>



<p class="wp-block-paragraph">That&#8217;s what it is.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m going to go back to my little VM here.</p>



<p class="wp-block-paragraph">Sphinx of black quartz.</p>



<p class="wp-block-paragraph">Judge my…</p>



<p class="wp-block-paragraph">I didn&#8217;t even write vow correctly.</p>



<p class="wp-block-paragraph">Judge my vow.</p>



<p class="wp-block-paragraph">And I think that has all the letters in the alphabet too.</p>



<p class="wp-block-paragraph">probably less spaces. I wonder if that&#8217;s, I mean, that&#8217;s what the internet says. If this is true,</p>



<p class="wp-block-paragraph">and it has all the letters of the alphabet, that&#8217;s going to be awesome. I&#8217;m going to memorize that</p>



<p class="wp-block-paragraph">for sure. Sphinx of black quartz, judge my vow. Anyway, so I&#8217;m just kind of adding stuff into</p>



<p class="wp-block-paragraph">this file. And if I run, let me save that here. I&#8217;ll do a clear. And then I&#8217;ll do, um,</p>



<p class="wp-block-paragraph">I&#8217;ll cat the input file here, and then cat the output file. So you can see they&#8217;re different.</p>



<p class="wp-block-paragraph">again let me remove the output file just in case I can&#8217;t remember if I&#8217;m supposed</p>



<p class="wp-block-paragraph">to remove it manually or if I put that into the program we&#8217;ll just try it like</p>



<p class="wp-block-paragraph">this so now they match and then if I cat again the output file notice how it&#8217;s a</p>



<p class="wp-block-paragraph">perfect copy of the input file nice so I think that&#8217;s pretty much everything</p>



<p class="wp-block-paragraph">that I wanted to show you maybe um well maybe we can use a more efficient buffer</p>



<p class="wp-block-paragraph">we can use a more efficient buffer now that it&#8217;s done the copy buffer we could change this to like</p>



<p class="wp-block-paragraph">eight kilobytes or something we should end up with the same result let me run this just as is</p>



<p class="wp-block-paragraph">and see if it ends up being the same thing without erasing the file first yeah it looks good let me</p>



<p class="wp-block-paragraph">remove the output file and then run it one more time so make run and then uh cat the output file</p>



<p class="wp-block-paragraph">yeah okay so it still works but um you know whereas before we were just using a two byte buffer</p>



<p class="wp-block-paragraph">two byte buffer there&#8217;s like very little chance except maybe at the end of the file that we would</p>



<p class="wp-block-paragraph">request more data than the file had but using the return value of the read operation always told us</p>



<p class="wp-block-paragraph">exactly how much was read by the operating system on the other hand if we have a giant buffer we</p>



<p class="wp-block-paragraph">could request way more bytes than the file could ever have because that file is way less than eight</p>



<p class="wp-block-paragraph">kilobytes so again we still want to look at the return value to make sure we know how many bytes</p>



<p class="wp-block-paragraph">how many bytes should be sent into the right file.</p>



<p class="wp-block-paragraph">So I guess that&#8217;s everything that I wanted to tell you</p>



<p class="wp-block-paragraph">about reading and writing files using system calls.</p>



<p class="wp-block-paragraph">I hope you&#8217;ve learned a lot of stuff</p>



<p class="wp-block-paragraph">and you enjoyed this video and had a little bit of fun.</p>



<p class="wp-block-paragraph">Thank you so much for watching.</p>



<p class="wp-block-paragraph">I&#8217;m going to cut the video.</p>



<p class="wp-block-paragraph">I&#8217;ll see you, whoops.</p>



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



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



<p class="wp-block-paragraph">Thanks for watching this video again</p>



<p class="wp-block-paragraph">from the bottom of my heart.</p>



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



<p class="wp-block-paragraph">I do hope you did learn something</p>



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



<p class="wp-block-paragraph">If you could do me a please a small little favor. Could you please subscribe and follow this channel or these videos or</p>



<p class="wp-block-paragraph">Whatever it is you do on the current social media website that you&#8217;re looking at right now</p>



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



<p class="wp-block-paragraph">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 class="wp-block-paragraph">So please do do me a kindness and and subscribe</p>



<p class="wp-block-paragraph">and subscribe. You know sometimes I&#8217;m sleeping in the middle of the night and</p>



<p class="wp-block-paragraph">I just wake up because I know somebody subscribed or followed. It just wakes me</p>



<p class="wp-block-paragraph">up and I get filled with joy. That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could you control me if you want</p>



<p class="wp-block-paragraph">to just wake me up in the middle of the night just subscribe and then I&#8217;ll just</p>



<p class="wp-block-paragraph">wake up. I promise that&#8217;s what will happen. Also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



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



<p class="wp-block-paragraph">also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where you</p>



<p class="wp-block-paragraph">can just kind of like see all the videos I published and the services and tutorials and</p>



<p class="wp-block-paragraph">things that I offer and all that good stuff and uh if you have a suggestion for uh uh clarifications</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake up for</p>



<p class="wp-block-paragraph">I wake up in a cold sweat and I&#8217;m like,</p>



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-file-copying-with-system-calls-in-x86-64-yasm-assembly/">Master File Copying with System Calls in x86-64 YASM Assembly</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-file-copying-with-system-calls-in-x86-64-yasm-assembly/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly Examples</title>
		<link>https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/</link>
					<comments>https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 22 Sep 2025 11:53:48 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[file descriptors]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux pipes]]></category>
		<category><![CDATA[Linux tutorial]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standard error]]></category>
		<category><![CDATA[standard input]]></category>
		<category><![CDATA[standard output]]></category>
		<category><![CDATA[STDERR]]></category>
		<category><![CDATA[STDIN]]></category>
		<category><![CDATA[STDOUT]]></category>
		<category><![CDATA[system calls]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=230</guid>

					<description><![CDATA[<p>Explore Linux's STDIN, STDOUT, and STDERR pipes with a fun Yasm Assembly demo. Learn how programs communicate, redirect outputs, and handle inputs in this beginner-friendly guide.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/">Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly 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="Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly" width="1380" height="776" src="https://www.youtube.com/embed/8Jv1_q0cyaw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Get a clear, hands-on look at Linux&#8217;s standard input (STDIN), output (STDOUT), and error (STDERR) pipes! In this video, we explore how programs communicate using these essential streams, with practical examples in Yasm Assembly (no assembly knowledge needed!). Learn to redirect outputs, handle errors, and read inputs like a pro. Whether you&#8217;re a beginner or seasoned coder, this fun demo breaks down the basics of Linux pipes. Subscribe for more coding insights and check out the full tutorial on our site!</p>



<p class="wp-block-paragraph">Introduction to STDIN, STDOUT, STDERR 00:00:00<br>Overview of Pipes in Linux 00:00:07<br>Explanation of File Descriptors 00:01:12<br>Demonstrating Echo Command 00:01:24<br>Redirecting Standard Output 00:02:02<br>C++ Example with cout and cerr 00:02:48<br>Purpose of Separate Error Pipe 00:03:28<br>Assembly Program Introduction 00:04:55<br>Creating Data Section in Yasm 00:05:22<br>Writing Helper Functions 00:07:37<br>Printing to Standard Output and Error 00:11:29<br>Testing Output Redirection 00:12:43<br>Standard Input Explanation 00:14:54<br>Creating Stack Buffer for Input 00:16:03<br>Reading from Standard Input 00:17:28<br>Piping Input to Program 00:20:54<br>Handling Null Terminators 00:22:02<br>Conclusion and Call to Subscribe 00:23:53</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



<p class="wp-block-paragraph">In this video I&#8217;m going to talk to you a little bit about standard input, standard output,</p>



<p class="wp-block-paragraph">and standard error.</p>



<p class="wp-block-paragraph">Three pipes that every program has in Linux that allow it to just communicate in a very</p>



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



<p class="wp-block-paragraph">I&#8217;m going to show you some example code written in Yasm Assembly, but assembly knowledge is</p>



<p class="wp-block-paragraph">not necessarily required for this video.</p>



<p class="wp-block-paragraph">You can just sort of follow along.</p>



<p class="wp-block-paragraph">Anyway, what is standard input, standard output, and standard error?</p>



<p class="wp-block-paragraph">Well for starters, every program that gets launched, under the hood, the operating system</p>



<p class="wp-block-paragraph">will typically attach three pipes to it.</p>



<p class="wp-block-paragraph">Basically one for standard input, one for standard output, and one for standard error.</p>



<p class="wp-block-paragraph">the program pretty easily. So let&#8217;s see. Oh, I know what to do. There&#8217;s an echo command, right?</p>



<p class="wp-block-paragraph">So here&#8217;s the program called echo. When the program launches, it&#8217;s going to have three pipes</p>



<p class="wp-block-paragraph">attached to it, just like I told you before. These pipes also behave as file descriptors,</p>



<p class="wp-block-paragraph">as if you had opened a file, but their file descriptor numbers are always zero and one and two.</p>



<p class="wp-block-paragraph">Zero for standard input, one for standard output, and two for standard error. So if I launch the</p>



<p class="wp-block-paragraph">program it&#8217;s going to get those three pipes those three file descriptors and</p>



<p class="wp-block-paragraph">right away the standard output is going to get attached to the program running</p>



<p class="wp-block-paragraph">our terminal here well not necessarily the actual terminal but bash under the</p>



<p class="wp-block-paragraph">hood which is the program that we&#8217;re using to interact with the operating</p>



<p class="wp-block-paragraph">system so basically the program launches and based on this incoming argument that</p>



<p class="wp-block-paragraph">I give it hello then it&#8217;s going to print the string hello right but what it&#8217;s</p>



<p class="wp-block-paragraph">its standard output pipe its standard output file descriptor I can test this</p>



<p class="wp-block-paragraph">for sure by just sort of doing the command again and then muting its</p>



<p class="wp-block-paragraph">standard output pipe with this little shell trick I&#8217;ll do a arrow or a greater</p>



<p class="wp-block-paragraph">than angle bracket and I&#8217;ll just send the first pipe I&#8217;ll do one I&#8217;ll send it</p>



<p class="wp-block-paragraph">to dev null and on Linux dev null is just if you send anything there it just</p>



<p class="wp-block-paragraph">it&#8217;s just totally ignored so if i send uh the pipe labeled number one to just nowhere then notice how</p>



<p class="wp-block-paragraph">it doesn&#8217;t show on the terminal for me right it&#8217;s pretty cool let&#8217;s go a little bit deeper into this</p>



<p class="wp-block-paragraph">i just want you to see real fast before i write an example program in assembly what you would</p>



<p class="wp-block-paragraph">probably end up doing in c plus plus so we usually do something like iostream in germane you know</p>



<p class="wp-block-paragraph">We&#8217;ll say using std cout std c error std and l and so forth.</p>



<p class="wp-block-paragraph">And then if you actually want to print a message to the user, we&#8217;ll say cout this message prints</p>



<p class="wp-block-paragraph">to std out because that&#8217;s what cout does by default.</p>



<p class="wp-block-paragraph">And then if we do c error, a lot of people haven&#8217;t actually seen this and I personally</p>



<p class="wp-block-paragraph">always forget that it&#8217;s even there if you print to see error it prints a message to standard error</p>



<p class="wp-block-paragraph">why would you want two different pipes that printed messages and one is called output and</p>



<p class="wp-block-paragraph">one is called error well like i&#8217;ve said before in other videos it&#8217;s really convenient to be able to</p>



<p class="wp-block-paragraph">have programs automate other programs for example if you have a program that is launching you know</p>



<p class="wp-block-paragraph">a second program maybe the second program fails in some way or wants to complain to you in some way</p>



<p class="wp-block-paragraph">or wants to complain to you in some way, it would usually, if it&#8217;s smart,</p>



<p class="wp-block-paragraph">print the complaint to standard error.</p>



<p class="wp-block-paragraph">It may not actually use C error because maybe it&#8217;s not a C++ program,</p>



<p class="wp-block-paragraph">but it would print to pipe number two, file descriptor number two, standard error.</p>



<p class="wp-block-paragraph">And then that way, the program that&#8217;s launching it can just sort of ignore messages</p>



<p class="wp-block-paragraph">that happen on standard output because we can assume all of those messages</p>



<p class="wp-block-paragraph">are just normal info messages that a human might want to see.</p>



<p class="wp-block-paragraph">Or maybe you want to record to a log or something somewhere</p>



<p class="wp-block-paragraph">log or something somewhere and just kind of save it away.</p>



<p class="wp-block-paragraph">But the error messages are a little bit more important than the regular,</p>



<p class="wp-block-paragraph">you know, normal messages.</p>



<p class="wp-block-paragraph">So if you&#8217;re automating another program,</p>



<p class="wp-block-paragraph">then your program probably wants to take standard output and either ignore it or</p>



<p class="wp-block-paragraph">just kind of send it to a different file.</p>



<p class="wp-block-paragraph">And then it wants to take standard error and pay more attention to it.</p>



<p class="wp-block-paragraph">Write it to a log file, save it, maybe check that it&#8217;s actually blank.</p>



<p class="wp-block-paragraph">And if it&#8217;s not empty, then maybe alarm bells go off.</p>



<p class="wp-block-paragraph">Something went wrong.</p>



<p class="wp-block-paragraph">We have to alert someone or, you know, make a database entry, send an email, whatever.</p>



<p class="wp-block-paragraph">And yeah, just pipe one and pipe two is how you accomplish that.</p>



<p class="wp-block-paragraph">So this is what&#8217;s happening in C++ when you do that sort of thing.</p>



<p class="wp-block-paragraph">Okay, so now I would like to write a sample program that just kind of demonstrates this</p>



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



<p class="wp-block-paragraph">So please bear with me.</p>



<p class="wp-block-paragraph">I&#8217;m going to go really fast for the assembly portion because this is not an assembly video.</p>



<p class="wp-block-paragraph">to learn more about how to write assembly in the first place than see my other videos.</p>



<p class="wp-block-paragraph">For now, I&#8217;m just going to create a little blank file here.</p>



<p class="wp-block-paragraph">Let&#8217;s see where the heck is my window.</p>



<p class="wp-block-paragraph">I&#8217;m on a multi-window system here.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m just going to paste a little data section.</p>



<p class="wp-block-paragraph">This is Yasm assembly.</p>



<p class="wp-block-paragraph">A little data section.</p>



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



<p class="wp-block-paragraph">I&#8217;m going to make a string for the introduction.</p>



<p class="wp-block-paragraph">Hello, the module has started.</p>



<p class="wp-block-paragraph">A string announcing everything that we&#8217;re going to do.</p>



<p class="wp-block-paragraph">We&#8217;re going to begin printing to standard output and standard error,</p>



<p class="wp-block-paragraph">and then some messages that will go to each.</p>



<p class="wp-block-paragraph">And then some messages that will go to each and then a standard input string, which we&#8217;ll</p>



<p class="wp-block-paragraph">talk about after the standard output and standard error.</p>



<p class="wp-block-paragraph">So just a bunch of strings.</p>



<p class="wp-block-paragraph">I&#8217;m going to make a buffer size.</p>



<p class="wp-block-paragraph">I&#8217;m going to make system call codes for reading, writing and exiting.</p>



<p class="wp-block-paragraph">If you want to know more about system call codes, see my other videos and some file descriptors.</p>



<p class="wp-block-paragraph">This is exactly what I just talked about.</p>



<p class="wp-block-paragraph">The file descriptor for standard input is zero for standard output is one for standard</p>



<p class="wp-block-paragraph">for standard error is two.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to do a system exit code of zero,</p>



<p class="wp-block-paragraph">which actually doesn&#8217;t matter that much,</p>



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



<p class="wp-block-paragraph">So now I&#8217;m going to make a, let&#8217;s see,</p>



<p class="wp-block-paragraph">a global,</p>



<p class="wp-block-paragraph">hmm, make a global.</p>



<p class="wp-block-paragraph">Oh, did I already make the text section?</p>



<p class="wp-block-paragraph">Here we go.</p>



<p class="wp-block-paragraph">So there&#8217;s the text section.</p>



<p class="wp-block-paragraph">So the data section is over now.</p>



<p class="wp-block-paragraph">So data section is over now.</p>



<p class="wp-block-paragraph">I&#8217;m going to make the tech section.</p>



<p class="wp-block-paragraph">I&#8217;m going to make a global entry point called start.</p>



<p class="wp-block-paragraph">Again, if you want to know more about assembly programming in general,</p>



<p class="wp-block-paragraph">see my other videos.</p>



<p class="wp-block-paragraph">But so this is the entry point of our program.</p>



<p class="wp-block-paragraph">At the very end, we should probably just program that it exits with success</p>



<p class="wp-block-paragraph">and test it out real fast.</p>



<p class="wp-block-paragraph">So basically right now this program does nothing.</p>



<p class="wp-block-paragraph">Let me just double check.</p>



<p class="wp-block-paragraph">Clear and make run.</p>



<p class="wp-block-paragraph">I have a make file under the hood, but this is not a make file video.</p>



<p class="wp-block-paragraph">If you want to know more about make files, see my other videos.</p>



<p class="wp-block-paragraph">know more about make files see my other videos but basically it just starts running and then</p>



<p class="wp-block-paragraph">it just dies right away okay no problem let me actually can i i want to fix that make file</p>



<p class="wp-block-paragraph">because it&#8217;s it&#8217;s labeled after like a different project that i was doing let&#8217;s do</p>



<p class="wp-block-paragraph">there&#8217;s no need for me to even do this i&#8217;m just uh i just can&#8217;t help myself okay so there we go</p>



<p class="wp-block-paragraph">going back to the editor.</p>



<p class="wp-block-paragraph">We have a program that does nothing.</p>



<p class="wp-block-paragraph">I&#8217;m going to copy paste in a couple of useful functions that I use elsewhere.</p>



<p class="wp-block-paragraph">Again, this is not an assembly video.</p>



<p class="wp-block-paragraph">So, so you can look at my code if you want to, if you just kind of want to know how this</p>



<p class="wp-block-paragraph">works, but not the point of this video.</p>



<p class="wp-block-paragraph">So I&#8217;m not going to spend too much time.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll just briefly talk about what it does, but not the point of this video.</p>



<p class="wp-block-paragraph">So the first thing I&#8217;m doing is I&#8217;m adding a function called print null terminated string</p>



<p class="wp-block-paragraph">function called print null terminated string just you know it sweeps through a</p>



<p class="wp-block-paragraph">string or actually it asks another function I made to find out how long the</p>



<p class="wp-block-paragraph">string is and then it&#8217;ll print the string to some file handle that I gave</p>



<p class="wp-block-paragraph">it like standard output or standard error and you know it calls on this other</p>



<p class="wp-block-paragraph">function called string length which I just wrote in pure assembly for fun even</p>



<p class="wp-block-paragraph">though I didn&#8217;t need to and it just kind of sweeps through the string until it</p>



<p class="wp-block-paragraph">finds a zero and then it knows how long the string is and then CRLF just prints</p>



<p class="wp-block-paragraph">is and then crlf just prints a carriage return new line uh carriage return new line just um</p>



<p class="wp-block-paragraph">with the same idea with the print null terminated string function and you can see all my strings have</p>



<p class="wp-block-paragraph">null terminators that&#8217;s the dot zero at the very end of it okay so we got those helper functions</p>



<p class="wp-block-paragraph">uh the next thing that i need to add in here is</p>



<p class="wp-block-paragraph">do an intro like my growling i used to have a professor who would go</p>



<p class="wp-block-paragraph">and he would go oh god when something went wrong and i do that all the time even when things are</p>



<p class="wp-block-paragraph">going right okay so i&#8217;m going to paste a little function here called intro and this is not going</p>



<p class="wp-block-paragraph">to be anything important it&#8217;s just going to print a little hello message you know it just uses my</p>



<p class="wp-block-paragraph">intro string and then just prints it with those other functions i made so that means now my my</p>



<p class="wp-block-paragraph">I can call intro real fast and then it&#8217;ll return when it&#8217;s done.</p>



<p class="wp-block-paragraph">If I just sort of run the program again, you can see after all the build messages,</p>



<p class="wp-block-paragraph">it&#8217;s just printing that the module has started.</p>



<p class="wp-block-paragraph">Okay, so nothing super important yet.</p>



<p class="wp-block-paragraph">Now, what I&#8217;d like to do is capture some incoming arguments real quick because…</p>



<p class="wp-block-paragraph">Let&#8217;s see standard input.</p>



<p class="wp-block-paragraph">Well, that&#8217;s actually not going to work.</p>



<p class="wp-block-paragraph">Let&#8217;s see what I want to do here.</p>



<p class="wp-block-paragraph">No, I think that&#8217;s part of a different program.</p>



<p class="wp-block-paragraph">OK, I&#8217;m going to call a demo.</p>



<p class="wp-block-paragraph">I don&#8217;t think I need to add that one thing that I was just looking at.</p>



<p class="wp-block-paragraph">So I&#8217;m going to call a function that&#8217;s going to be our main demo.</p>



<p class="wp-block-paragraph">So it&#8217;s going to jump down somewhere.</p>



<p class="wp-block-paragraph">I&#8217;ll just create the function down later.</p>



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



<p class="wp-block-paragraph">Where is it?</p>



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



<p class="wp-block-paragraph">I&#8217;m going to start off by saying this is my standard input function which is this and</p>



<p class="wp-block-paragraph">is this pop p and then pop r12 and then it returns if you don&#8217;t know what a prologue</p>



<p class="wp-block-paragraph">and epilogue are or why I&#8217;m doing pushes and pops just see my other videos but basically</p>



<p class="wp-block-paragraph">I&#8217;m responsible for preserving it.</p>



<p class="wp-block-paragraph">And I&#8217;m going to use the base pointer to help me remember where the stack started.</p>



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



<p class="wp-block-paragraph">What did I do?</p>



<p class="wp-block-paragraph">I started the wrong function.</p>



<p class="wp-block-paragraph">I&#8217;m going to do that one later.</p>



<p class="wp-block-paragraph">Okay, for now, let me go find where that other one is.</p>



<p class="wp-block-paragraph">Oh, there it is.</p>



<p class="wp-block-paragraph">Should have double checked.</p>



<p class="wp-block-paragraph">I&#8217;m going way too fast.</p>



<p class="wp-block-paragraph">I&#8217;ll just copy paste this whole thing from my solution.</p>



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



<p class="wp-block-paragraph">This video is a mess.</p>



<p class="wp-block-paragraph">Honestly, it&#8217;s a mess, but that&#8217;s okay.</p>



<p class="wp-block-paragraph">I&#8217;m going to try my best to explain it.</p>



<p class="wp-block-paragraph">So I have this function standard output standard error and I&#8217;m calling it here.</p>



<p class="wp-block-paragraph">So it should jump right down there as soon as the program starts.</p>



<p class="wp-block-paragraph">The standard input one is not getting called yet, but we&#8217;ll call it at the end of this</p>



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



<p class="wp-block-paragraph">print null terminated string function to print a message to standard output.</p>



<p class="wp-block-paragraph">Remember standard output was just you know pipe one. Standard error is going to</p>



<p class="wp-block-paragraph">be pipe two. So if I go back here and I say I want to print this matches to that</p>



<p class="wp-block-paragraph">pipe then it&#8217;ll go to standard output just like the echo program was doing</p>



<p class="wp-block-paragraph">when we looked at it a moment ago. And then next we&#8217;re going to print to</p>



<p class="wp-block-paragraph">Oh, that was just an announcement that we&#8217;re going to begin.</p>



<p class="wp-block-paragraph">So this is the real message that will say this is definitely going to standard output.</p>



<p class="wp-block-paragraph">And then this other message is going to go to standard error, which is when we when we</p>



<p class="wp-block-paragraph">looked at C error or pipe number two a moment ago.</p>



<p class="wp-block-paragraph">So basically, I&#8217;m just printing an announcement and then two important messages.</p>



<p class="wp-block-paragraph">One is going to pipe one and one is going to pipe two for standard output and standard</p>



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



<p class="wp-block-paragraph">OK, like really not very complicated at all.</p>



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



<p class="wp-block-paragraph">So if I run this program now, hopefully I didn&#8217;t crash it by copy pasting out of order here.</p>



<p class="wp-block-paragraph">Yeah, there we go.</p>



<p class="wp-block-paragraph">Clear and make run.</p>



<p class="wp-block-paragraph">So notice how it says that the messages are going to be printed.</p>



<p class="wp-block-paragraph">And then notice that both of my messages actually show up on the terminal.</p>



<p class="wp-block-paragraph">The one that says this message will print to standard output, number one, pipe one.</p>



<p class="wp-block-paragraph">This message will print to standard error, pipe two.</p>



<p class="wp-block-paragraph">They both get printed to the terminal because by default, the terminal will just take both of those pipes.</p>



<p class="wp-block-paragraph">both of those pipes it&#8217;ll take one and two standard output and error but I can</p>



<p class="wp-block-paragraph">use those little redirection tricks to mute one or more of those pipes so I&#8217;m</p>



<p class="wp-block-paragraph">gonna say pipe one which is standard output I&#8217;m just gonna redirect that to</p>



<p class="wp-block-paragraph">dev null to say I don&#8217;t want to see standard output if I run it again</p>



<p class="wp-block-paragraph">notice how the only thing you can see on the string or on the screen is standard</p>



<p class="wp-block-paragraph">error pipe to file descriptor 2 on the other hand if I redirect file descriptor</p>



<p class="wp-block-paragraph">descriptor to pipe two to nothing then I should see all the normal messages and not see the error</p>



<p class="wp-block-paragraph">message notice right here it&#8217;s it prints all the regular you know make file stuff and then the</p>



<p class="wp-block-paragraph">welcome message and then here&#8217;s our message that says this is going to be printed to standard output</p>



<p class="wp-block-paragraph">so notice how the error message is missing so cool if I mute both of those I can do that I can</p>



<p class="wp-block-paragraph">then nothing gets printed at all because that&#8217;s all we really have is standard output and standard</p>



<p class="wp-block-paragraph">error all right not too bad right that&#8217;s the basic idea between redirecting and things you</p>



<p class="wp-block-paragraph">could also do things like this if I okay this is not part of my plan but suppose I wanted to take</p>



<p class="wp-block-paragraph">any error message and redirect it to instead of dev null I wanted to redirect it to some kind of</p>



<p class="wp-block-paragraph">standard error.txt.</p>



<p class="wp-block-paragraph">Notice how nothing seems to have shown up on the screen, but if I list the directory,</p>



<p class="wp-block-paragraph">now there&#8217;s a text file called standard error that contains the error message.</p>



<p class="wp-block-paragraph">So you can redirect pipes, you can reattach them if you&#8217;re like an elite hacker.</p>



<p class="wp-block-paragraph">You can do lots of things with them, but that&#8217;s as far as I&#8217;m going to take it right now.</p>



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



<p class="wp-block-paragraph">Now let&#8217;s look at standard input.</p>



<p class="wp-block-paragraph">How do you send input to the program?</p>



<p class="wp-block-paragraph">Remember when programs call other programs, they can send each other standard input too.</p>



<p class="wp-block-paragraph">It&#8217;s just that when I launch something on the terminal, I&#8217;m just, you know, I&#8217;m the</p>



<p class="wp-block-paragraph">human and so whatever I type or, you know, what command I type is going to go into standard</p>



<p class="wp-block-paragraph">input if I do it the right way.</p>



<p class="wp-block-paragraph">So let&#8217;s go back to the program here.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s finish up standard input.</p>



<p class="wp-block-paragraph">And let&#8217;s see the pre-made code that I had here.</p>



<p class="wp-block-paragraph">I had the prolog and the epilog, right?</p>



<p class="wp-block-paragraph">Move the base pointer</p>



<p class="wp-block-paragraph">RBP and R12. Oh, I got to put the</p>



<p class="wp-block-paragraph">Base pointer back into the stack pointer. Let&#8217;s see move</p>



<p class="wp-block-paragraph">Again, this is not an assembly video. So just try to hang on here. So what I&#8217;m gonna do in this video</p>



<p class="wp-block-paragraph">I thought I was cute when I was making this plan. I know I&#8217;m not like that clever, but um, I</p>



<p class="wp-block-paragraph">Thought hey wouldn&#8217;t it be fun instead of having a global</p>



<p class="wp-block-paragraph">or the BSS section. What if I just made the stack a buffer? This is kind of what you do when you make</p>



<p class="wp-block-paragraph">a local array in C++. You&#8217;re making a buffer on the stack. So this is not a stack pointer video.</p>



<p class="wp-block-paragraph">So long story short, I&#8217;m just going to keep track of where the stack pointer started with this base</p>



<p class="wp-block-paragraph">pointer. That&#8217;s why I have to preserve it there. And then I&#8217;m just going to subtract my buffer size</p>



<p class="wp-block-paragraph">from the stack pointer. And what is the buffer size? I&#8217;ve chosen to do a buffer size of about</p>



<p class="wp-block-paragraph">So that means the user or me, I could send about eight kilobytes, maybe eight kilobytes</p>



<p class="wp-block-paragraph">or less into standard input and be sure that it&#8217;s all actually going to be received by</p>



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



<p class="wp-block-paragraph">And then I&#8217;m just going to use R12 to remember where the start of the buffer is, which is</p>



<p class="wp-block-paragraph">just wherever the stack pointer started.</p>



<p class="wp-block-paragraph">Because if we subtract and then the data that increases is actually increasing in memory,</p>



<p class="wp-block-paragraph">but making room on the stack decreased, it&#8217;s just the way it works.</p>



<p class="wp-block-paragraph">There&#8217;s going to be another stack video out there.</p>



<p class="wp-block-paragraph">stack video out there anyway for now I just create a buffer on the stack and</p>



<p class="wp-block-paragraph">then I&#8217;m gonna print a little hello message so I&#8217;m gonna print this so just</p>



<p class="wp-block-paragraph">my message saying hey we&#8217;re about to do something from standard input and then</p>



<p class="wp-block-paragraph">I&#8217;m gonna send that to a standard output so the message is gonna go to standard</p>



<p class="wp-block-paragraph">output but I&#8217;m announcing that we&#8217;re about to read from standard input</p>



<p class="wp-block-paragraph">assuming I actually cleaned up correctly let me double check this this should</p>



<p class="wp-block-paragraph">It should just simply say that it&#8217;s going to without crashing.</p>



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



<p class="wp-block-paragraph">So then now I&#8217;m ready to actually read from standard input.</p>



<p class="wp-block-paragraph">We&#8217;re going to use a system call from this.</p>



<p class="wp-block-paragraph">If you want more information on system calls, see my other videos.</p>



<p class="wp-block-paragraph">But basically you just go to the system call codes table,</p>



<p class="wp-block-paragraph">look up appendix area of whatever textbook you&#8217;re using.</p>



<p class="wp-block-paragraph">And you say, what&#8217;s the code to read?</p>



<p class="wp-block-paragraph">I want the system to read.</p>



<p class="wp-block-paragraph">what you know i want the system to read so i define that as system read and if you look up</p>



<p class="wp-block-paragraph">here in my program it&#8217;s just call code zero so sys call code zero is to read from somewhere</p>



<p class="wp-block-paragraph">and then uh where do i want to read from that&#8217;s the second argument for the standard</p>



<p class="wp-block-paragraph">or for the system call i want to read from standard input that&#8217;s going to be the number zero</p>



<p class="wp-block-paragraph">if you recall and then here is a pointer to the first character of wherever i want it to</p>



<p class="wp-block-paragraph">read into. So it&#8217;s going to read from that pipe, but it has to, it has to write the data that it</p>



<p class="wp-block-paragraph">read somewhere so that I can save it and access it. So R12 is basically going to be a bunch of</p>



<p class="wp-block-paragraph">free bytes that I created on the stack. So I like, you know, I&#8217;m, I like made the stack bigger,</p>



<p class="wp-block-paragraph">but it&#8217;s mostly empty or with junk data. And R12 is just pointing to the first byte that I have</p>



<p class="wp-block-paragraph">reserved. So, you know, you could imagine maybe you make a global variable in the BSS section up</p>



<p class="wp-block-paragraph">up at the top, you know, like an eight kilobyte array of bytes, and then just sort of point</p>



<p class="wp-block-paragraph">it to that. But in my case, I&#8217;m just using the stack because I think it&#8217;s cooler. So</p>



<p class="wp-block-paragraph">I tell it, Hey, that&#8217;s the first bite on the stack that you want that I want you to start</p>



<p class="wp-block-paragraph">reading from. And then I give it the buffer size, which we just looked at. And then I</p>



<p class="wp-block-paragraph">do a system call and then the system now should do all the hard work for me. It&#8217;ll look at</p>



<p class="wp-block-paragraph">the pipe for standard input. It&#8217;ll grab all of it. And then it will only grab, you know,</p>



<p class="wp-block-paragraph">it&#8217;ll stop if the input ends before that and then when I&#8217;m done I should be able</p>



<p class="wp-block-paragraph">to actually read from the buffer which is sitting at R12 and print it to the</p>



<p class="wp-block-paragraph">screen so the next thing I&#8217;m gonna copy paste in there is I&#8217;m gonna print what</p>



<p class="wp-block-paragraph">I just read from standard input so this is another call to my function my little</p>



<p class="wp-block-paragraph">doggy wants to go pee even though he&#8217;s completely lying he just went pee so at</p>



<p class="wp-block-paragraph">wants to go outside and lift his leg and do nothing and then come back in and demand a treat.</p>



<p class="wp-block-paragraph">I&#8217;ll let him do it in a few minutes just in case but trust me he&#8217;s lying he&#8217;s laid like five times</p>



<p class="wp-block-paragraph">today. Anyway I sometimes I regret teaching him to growl at me. It&#8217;s so cute but like it&#8217;s not</p>



<p class="wp-block-paragraph">cute right now. I don&#8217;t know maybe it is. Let me know in the comments. So basically I&#8217;m going to</p>



<p class="wp-block-paragraph">take that R12 buffer that I just wrote to and I&#8217;m going to print that directly to standard output</p>



<p class="wp-block-paragraph">output and this is not really the important part of the video.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do that and then I&#8217;m going to kind of clean up here at the end of the</p>



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



<p class="wp-block-paragraph">And then maybe I&#8217;ll say goodbye.</p>



<p class="wp-block-paragraph">I think I just added a string for that.</p>



<p class="wp-block-paragraph">So maybe I&#8217;ll say goodbye.</p>



<p class="wp-block-paragraph">I&#8217;ll say goodbye before we end the function and then I&#8217;ll actually return.</p>



<p class="wp-block-paragraph">So let me go here and run the program.</p>



<p class="wp-block-paragraph">Let&#8217;s see, begin.</p>



<p class="wp-block-paragraph">printed because we didn&#8217;t send anything and we also didn&#8217;t call that let me call</p>



<p class="wp-block-paragraph">standard input call stdin and so now it&#8217;s actually gonna print basically</p>



<p class="wp-block-paragraph">nothing oh I didn&#8217;t send it anything so it&#8217;s just kind of hanging you probably</p>



<p class="wp-block-paragraph">want to check this sort of situation but that&#8217;s that&#8217;s not the point of this</p>



<p class="wp-block-paragraph">video let me show you how to pipe some some stuff into standard input real fast</p>



<p class="wp-block-paragraph">hello and then just put a little or bar in the shell this will take the output</p>



<p class="wp-block-paragraph">of echo and instead of printing it to the terminal it&#8217;ll attach its standard</p>



<p class="wp-block-paragraph">output into the standard input of make run pretty cool shell trick so now we</p>



<p class="wp-block-paragraph">should see the word hello the word hello printed and that&#8217;s what it does we have</p>



<p class="wp-block-paragraph">detected the following stdin and it says like here&#8217;s begin that&#8217;s just a string</p>



<p class="wp-block-paragraph">that I had that I print every time and then here&#8217;s the string that it actually</p>



<p class="wp-block-paragraph">And then it ends.</p>



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



<p class="wp-block-paragraph">I think maybe we could probably do the empty thing if I just started typing here.</p>



<p class="wp-block-paragraph">And then maybe I hit control D to detach the buffer.</p>



<p class="wp-block-paragraph">And yeah, that&#8217;s what it does.</p>



<p class="wp-block-paragraph">It sort of prints here and then it ends there.</p>



<p class="wp-block-paragraph">Didn&#8217;t do a new line.</p>



<p class="wp-block-paragraph">I think it probably doubled it for some reason because I…</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">I didn&#8217;t plan for this.</p>



<p class="wp-block-paragraph">Let me see.</p>



<p class="wp-block-paragraph">plan for this let me see it printed oh because I did I did not null terminate the string so</p>



<p class="wp-block-paragraph">actually what it did is it uh let&#8217;s see if we can do that real fast one more time I&#8217;m going to go</p>



<p class="wp-block-paragraph">one two three four five then I&#8217;m going to just disconnect the standard input buffer because the</p>



<p class="wp-block-paragraph">printing function needs a null terminator to know when to stop there&#8217;s not going to be a null</p>



<p class="wp-block-paragraph">terminator because I just typed and disconnected the uh the input so it&#8217;s actually going to just</p>



<p class="wp-block-paragraph">until it randomly finds a zero and then it&#8217;ll stop so if I disconnect it it</p>



<p class="wp-block-paragraph">that explanation was bunk let me try that one more time I&#8217;m gonna go a bunch</p>



<p class="wp-block-paragraph">of H&#8217;s I guess there is a null terminator I disconnect it no no see how</p>



<p class="wp-block-paragraph">yeah these little symbols there so it does kind of print until it finds a</p>



<p class="wp-block-paragraph">null terminator but I guess I was confused because it seemed like it</p>



<p class="wp-block-paragraph">like it printed it twice what&#8217;s actually happening is when i type then it&#8217;s getting sent to the</p>



<p class="wp-block-paragraph">terminal which and that&#8217;s not part of the program that we just wrote then when i disconnect standard</p>



<p class="wp-block-paragraph">input then the program finally prints everything that i actually typed until it hits a null</p>



<p class="wp-block-paragraph">terminator in this case it looks like it seems to have worked but uh if i just do like a couple</p>



<p class="wp-block-paragraph">sevens and then disconnect probably have to do this a bunch of times before we&#8217;ll see those weird</p>



<p class="wp-block-paragraph">What did I do? Hit enter. That seems to have worked. My dog is stressing me out</p>



<p class="wp-block-paragraph">but I love him. Alright anyway just trust me on this sometimes it&#8217;s hitting the</p>



<p class="wp-block-paragraph">null terminator in time sometimes it&#8217;s not. But I hope by now you understand the</p>



<p class="wp-block-paragraph">difference between standard input standard output and standard error. Thank</p>



<p class="wp-block-paragraph">you so much for watching this video that I&#8217;m recording and I hope you learned a</p>



<p class="wp-block-paragraph">little bit of stuff and had a little bit of fun. I&#8217;m gonna let my dog lie to me</p>



<p class="wp-block-paragraph">I&#8217;m gonna let my dog lie to me for a second and I&#8217;ll see you in the next video.</p>



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



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



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



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



<p class="wp-block-paragraph">this channel or these videos or whatever it is you do on the current social media website</p>



<p class="wp-block-paragraph">that you&#8217;re looking at right now.</p>



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



<p class="wp-block-paragraph">and grow this community so we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general. So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



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



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



<p class="wp-block-paragraph">want to just wake me up in the middle of the night, just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



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



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



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



<p class="wp-block-paragraph">offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me i would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/">Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</title>
		<link>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/</link>
					<comments>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 14 Sep 2025 23:46:11 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[argv argc]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[command line args]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[GCC assembly]]></category>
		<category><![CDATA[GCC linking]]></category>
		<category><![CDATA[hybrid programming]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming guide]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[x86 assembly]]></category>
		<category><![CDATA[x86-64 programming]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=227</guid>

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



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



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



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">points to an array.</p>



<p class="wp-block-paragraph">So like if you go to that location in memory,</p>



<p class="wp-block-paragraph">then what you will see there for the first eight bytes</p>



<p class="wp-block-paragraph">is just the address of some other memory location where a string has been stored.</p>



<p class="wp-block-paragraph">Then if you advance that pointer another eight bytes for it,</p>



<p class="wp-block-paragraph">you know, in memory, because all pointers are eight bytes or 64 bits,</p>



<p class="wp-block-paragraph">then again, you&#8217;ll see that that value of that next eight bytes</p>



<p class="wp-block-paragraph">is actually a memory location that points to another string somewhere else.</p>



<p class="wp-block-paragraph">So these strings could be all over the place,</p>



<p class="wp-block-paragraph">But the pointers to those strings are contiguous in memory starting with what you were given in RSI.</p>



<p class="wp-block-paragraph">So it&#8217;s a character pointer pointer or an array of character pointers, however you want to imagine that.</p>



<p class="wp-block-paragraph">Anyway, so we&#8217;ll grab those and then I&#8217;ll just show you how to use them down further in the code.</p>



<p class="wp-block-paragraph">For starters, I&#8217;m calling on an intro function which just basically prints some stuff.</p>



<p class="wp-block-paragraph">I have a custom function that I wrote called print null terminated string.</p>



<p class="wp-block-paragraph">That&#8217;s not the point of this video.</p>



<p class="wp-block-paragraph">I have that explained in other videos a little bit.</p>



<p class="wp-block-paragraph">So it&#8217;s up to you if you want to even care.</p>



<p class="wp-block-paragraph">Right now I just want to be able to print something.</p>



<p class="wp-block-paragraph">And then let&#8217;s see.</p>



<p class="wp-block-paragraph">So after we print our welcome message in the intro, then we print another message basically</p>



<p class="wp-block-paragraph">saying okay now we&#8217;re about to start printing all the arguments.</p>



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



<p class="wp-block-paragraph">Nothing complicated at this point.</p>



<p class="wp-block-paragraph">Then I have another label here with my preferred style of adding a suffix after the function</p>



<p class="wp-block-paragraph">after the function that I&#8217;m currently inside of.</p>



<p class="wp-block-paragraph">And I&#8217;m going to say, all right, this is where I initialize my loop.</p>



<p class="wp-block-paragraph">This is not a looping video, so I&#8217;m going to skim through it kind of.</p>



<p class="wp-block-paragraph">But I&#8217;m basically going to say, let&#8217;s start the loop as basically saying</p>



<p class="wp-block-paragraph">the index of the argument that we&#8217;re currently looking at is zero</p>



<p class="wp-block-paragraph">because we&#8217;ll start with zero.</p>



<p class="wp-block-paragraph">So that means we&#8217;ll print like if we were going to, if our program was named Echo,</p>



<p class="wp-block-paragraph">we would also print Echo itself and not just all the incoming arguments</p>



<p class="wp-block-paragraph">that the user might have typed.</p>



<p class="wp-block-paragraph">index zero and then we&#8217;re going to use r15 as the current character pointer so r15 its current</p>



<p class="wp-block-paragraph">character pointer is going to be coming from r13 which was the argv argument so that means</p>



<p class="wp-block-paragraph">r15 is now going to hold a pointer uh let&#8217;s see it&#8217;s going to hold</p>



<p class="wp-block-paragraph">when you have an array and the array is contiguous in memory then the pointer itself that points to</p>



<p class="wp-block-paragraph">the array is also a pointer to the first item that&#8217;s just kind of the way it works like if we</p>



<p class="wp-block-paragraph">have 10 items and it&#8217;s an array then your pointer to that array is also a pointer to the first item</p>



<p class="wp-block-paragraph">in the array if that makes sense so if r13 was a pointer to an array it&#8217;s also a pointer to the</p>



<p class="wp-block-paragraph">go off to a null terminated string i know that sounds weird you got to get used to double dereferencing</p>



<p class="wp-block-paragraph">here so all we really need to do to access uh the first pointer to the actual string is take the</p>



<p class="wp-block-paragraph">array pointer that we have and dereference it one time so remember we&#8217;re receiving an argv</p>



<p class="wp-block-paragraph">a pointer to a pointer or like a you know a double pointer if we dereference it once then we should</p>



<p class="wp-block-paragraph">terminated string. Anyway, so that&#8217;s the initialization part. I&#8217;m going to start looking</p>



<p class="wp-block-paragraph">at the first string here and I&#8217;m going to say we&#8217;re at index zero. And then here&#8217;s the top of</p>



<p class="wp-block-paragraph">my loop. You can imagine this is a while loop. This is not a while video, but you know, there it is.</p>



<p class="wp-block-paragraph">And we&#8217;re just going to ask first, are we actually done? Do we need to break the loop? I like to do</p>



<p class="wp-block-paragraph">that at the top of my while loop. And how we&#8217;ll do that is we&#8217;ll say, all right, R14 is the index</p>



<p class="wp-block-paragraph">the number of arguments so notice how like right here we grabbed RDI right</p>



<p class="wp-block-paragraph">into R12 right away so basically I&#8217;m saying if the index we&#8217;re currently</p>



<p class="wp-block-paragraph">looking at is greater than or equal to the number of arguments then we&#8217;re</p>



<p class="wp-block-paragraph">actually already done remember if we&#8217;re using zero based indexing and you</p>



<p class="wp-block-paragraph">suppose that you have three items in your array their indexes would be zero</p>



<p class="wp-block-paragraph">So that means if the size of your array is three, like the count, like the RFC, that</p>



<p class="wp-block-paragraph">means the last valid index is two.</p>



<p class="wp-block-paragraph">It&#8217;s one less than the size.</p>



<p class="wp-block-paragraph">You know, it&#8217;s one less than the count.</p>



<p class="wp-block-paragraph">So I&#8217;m saying at this point that if we ever reach an index number that is equal to the</p>



<p class="wp-block-paragraph">size, then we&#8217;ve already finished.</p>



<p class="wp-block-paragraph">We do not need to look at the current item.</p>



<p class="wp-block-paragraph">So I&#8217;m comparing those two registers.</p>



<p class="wp-block-paragraph">You know, where are we looking at versus what is the count?</p>



<p class="wp-block-paragraph">You know, what is the index we&#8217;re looking at versus the count?</p>



<p class="wp-block-paragraph">If the index we&#8217;re looking at is greater than or equal to the count, then that means we&#8217;re done.</p>



<p class="wp-block-paragraph">I&#8217;m going to jump out of the loop to a label called main loop done.</p>



<p class="wp-block-paragraph">So then, you know, that&#8217;s down here.</p>



<p class="wp-block-paragraph">Basically, we just say goodbye and then we jump to our exit function.</p>



<p class="wp-block-paragraph">And all that does is it just returns from main with some kind of a success code.</p>



<p class="wp-block-paragraph">You know, so just you can imagine in C++, it&#8217;s just return zero.</p>



<p class="wp-block-paragraph">So, you know, breaking the loop doesn&#8217;t really do anything except end the program and say goodbye.</p>



<p class="wp-block-paragraph">However, if we did not jump, then the, let&#8217;s see if we did not jump, let&#8217;s, let&#8217;s see if</p>



<p class="wp-block-paragraph">we did jump, we compared it, we realized that we&#8217;re done.</p>



<p class="wp-block-paragraph">Then it&#8217;s going to jump down to the, to the done.</p>



<p class="wp-block-paragraph">But if we&#8217;re not done, execution is going to fall through to the next statement.</p>



<p class="wp-block-paragraph">So that means we&#8217;re going to end up doing something with the current item inside of</p>



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



<p class="wp-block-paragraph">So what are we going to do?</p>



<p class="wp-block-paragraph">We&#8217;re going to dereference R15.</p>



<p class="wp-block-paragraph">was your pointer to a pointer it was your double pointer there if we dereference it once then</p>



<p class="wp-block-paragraph">instead of being a pointer to an array of pointers it&#8217;s going to be a pointer to one string one one</p>



<p class="wp-block-paragraph">character that starts one string so dereferencing it once means you know i put brackets around the</p>



<p class="wp-block-paragraph">double pointer it&#8217;s now dereferenced once that means rdi is going to receive a pointer to one</p>



<p class="wp-block-paragraph">into my function my function takes two arguments it wants a pointer to a string and it wants</p>



<p class="wp-block-paragraph">the file descriptor to print to again other videos explain you know printing to standard</p>



<p class="wp-block-paragraph">output but i&#8217;m just going to print the string so this part right here should actually print</p>



<p class="wp-block-paragraph">the argument and then after we&#8217;re done with that uh well maybe i should change this</p>



<p class="wp-block-paragraph">so that it&#8217;s a little bit more clear i&#8217;m going to maybe push this down and say</p>



<p class="wp-block-paragraph">these lines up here actually do something they do the printing by</p>



<p class="wp-block-paragraph">dereferencing and then here we just sort of increment along the array of pointers</p>



<p class="wp-block-paragraph">and jump back to the top of the loop so what are we doing here with r14</p>



<p class="wp-block-paragraph">remember r14 was the index that we&#8217;re currently looking at so we we start</p>



<p class="wp-block-paragraph">looking at index 0 line 83 is going to say let&#8217;s next look at index 1 and then</p>



<p class="wp-block-paragraph">this part right here add 8 to r15 that just basically means remember r15 was</p>



<p class="wp-block-paragraph">remember r15 was the double pointer the double pointer like i said before it&#8217;s looking at an</p>



<p class="wp-block-paragraph">array of pointers so it&#8217;s actually a pointer to a pointer if i increase the memory location that</p>



<p class="wp-block-paragraph">r15 holds then it&#8217;s now looking at the next pointer it&#8217;s moving through the array r15 at</p>



<p class="wp-block-paragraph">that point would no longer be a valid pointer to the original array it&#8217;s sort of like a running</p>



<p class="wp-block-paragraph">pointer it&#8217;s kind of like scanning all of the pointers but a pointer is eight bytes so if we&#8217;re</p>



<p class="wp-block-paragraph">a pointer is eight bytes so if we&#8217;re just looking at the first pointer and we increase the memory</p>



<p class="wp-block-paragraph">location that we&#8217;re looking at by eight bytes now we&#8217;re looking at the second pointer so then on the</p>



<p class="wp-block-paragraph">next iteration of the loop if we dereference then we&#8217;re going to end up dereferencing to the second</p>



<p class="wp-block-paragraph">string then i just print a little new line here honestly probably should have put that up top</p>



<p class="wp-block-paragraph">sloppy code i was doing this quickly and then we jump to the top of the loop so then we just</p>



<p class="wp-block-paragraph">going up to the top of the loop and printing arguments and advancing to the</p>



<p class="wp-block-paragraph">next pointer. And we just keep going at it.</p>



<p class="wp-block-paragraph">Let me see if this works. Hopefully I didn&#8217;t mess this up while I was screwing</p>



<p class="wp-block-paragraph">around. All right. So I&#8217;m going to do this make run. Okay.</p>



<p class="wp-block-paragraph">So under the hood inside of my make file,</p>



<p class="wp-block-paragraph">maybe let&#8217;s open the make file real fast just so you can see.</p>



<p class="wp-block-paragraph">I&#8217;m just going to nano it real fast here under the hood.</p>



<p class="wp-block-paragraph">So when I call the program to run, notice how I&#8217;m giving it arguments.</p>



<p class="wp-block-paragraph">You can see right here on this line, or actually let me get the line numbers up.</p>



<p class="wp-block-paragraph">You can see on line 48, I am calling my executable, which is named main.</p>



<p class="wp-block-paragraph">In the make file, I&#8217;m using a variable, so don&#8217;t worry about that.</p>



<p class="wp-block-paragraph">But I&#8217;m giving it four arguments.</p>



<p class="wp-block-paragraph">And I&#8217;m just saying first arg, second arg, third arg, fourth arg.</p>



<p class="wp-block-paragraph">So that&#8217;s why you see that printed in the previous screen.</p>



<p class="wp-block-paragraph">screen it&#8217;s just going through all the arguments that I gave it it&#8217;s saying</p>



<p class="wp-block-paragraph">first arg second arg third arg fourth arg notice how it knows when to stop</p>



<p class="wp-block-paragraph">because of the argc that came in on RDI now that the program is built you know</p>



<p class="wp-block-paragraph">I&#8217;ve got my main executable which I named main which I said before was kind</p>



<p class="wp-block-paragraph">of confusing now that I&#8217;ve got it I can just execute it again and give it like</p>



<p class="wp-block-paragraph">one argument of like hello notice how it prints hello on a line by itself you do</p>



<p class="wp-block-paragraph">do it again dudes and notice how every argument I give it it just prints it no</p>



<p class="wp-block-paragraph">matter how many I do I can go a b c d e f g I could probably do this so many</p>



<p class="wp-block-paragraph">times that I exhaust you know a long integer which is would be a horrible</p>



<p class="wp-block-paragraph">endeavor but yeah everything that I put on there it just loops through it and</p>



<p class="wp-block-paragraph">prints it so when you are linking with GCC because you&#8217;re probably using a</p>



<p class="wp-block-paragraph">if you&#8217;re just linking with GCC.</p>



<p class="wp-block-paragraph">GCC makes it really, really easy</p>



<p class="wp-block-paragraph">to access the command line arguments.</p>



<p class="wp-block-paragraph">Imagine now instead of just printing these things,</p>



<p class="wp-block-paragraph">you used them to somehow decide</p>



<p class="wp-block-paragraph">what your program was gonna do.</p>



<p class="wp-block-paragraph">Maybe the user will give you a sub command.</p>



<p class="wp-block-paragraph">Like if you&#8217;re a Git user, we say Git status, right?</p>



<p class="wp-block-paragraph">So the Git says like, oh, you Git launches</p>



<p class="wp-block-paragraph">and it goes, you want the status of something?</p>



<p class="wp-block-paragraph">Yeah, sure.</p>



<p class="wp-block-paragraph">So in your program now,</p>



<p class="wp-block-paragraph">you could read what the user typed,</p>



<p class="wp-block-paragraph">figure out a way to parse it and interpret it</p>



<p class="wp-block-paragraph">have your program&#8217;s behavior adjust to whatever the user typed in okay that&#8217;s it for this video</p>



<p class="wp-block-paragraph">the next video I&#8217;m going to post is how to do basically exactly the same thing but using pure</p>



<p class="wp-block-paragraph">assembly without linking against GCC so like LD is going to be the linker just like pure assembly</p>



<p class="wp-block-paragraph">no extra libraries okay thank you so much for watching this video I hope you learned a little</p>



<p class="wp-block-paragraph">tell your friends and i&#8217;ll see you in the next video</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really appreciate it</p>



<p class="wp-block-paragraph">i do hope you did learn something and have some fun uh if you could do me a please a small little</p>



<p class="wp-block-paragraph">favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p class="wp-block-paragraph">and grow this community so we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general. So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



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



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



<p class="wp-block-paragraph">you want to just wake me up in the middle of the night, just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">just wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



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



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



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



<p class="wp-block-paragraph">offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me i would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/">Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master Command Line Arguments in x86-64 Assembly with YASM</title>
		<link>https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/</link>
					<comments>https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 08 Sep 2025 07:44:41 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[argc argv]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[Linux programming]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[stack pointer]]></category>
		<category><![CDATA[system calls]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=221</guid>

					<description><![CDATA[<p>Learn to access command line arguments in x86-64 YASM assembly on Linux. Master stack handling and argv looping in this clear, practical tutorial!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/">Master Command Line Arguments in x86-64 Assembly with 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 loading="lazy" title="Master Command Line Arguments in x86-64 Assembly with YASM" width="1380" height="776" src="https://www.youtube.com/embed/hRl3hKvHiyM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Want to master command line arguments in pure x86-64 YASM assembly on Linux? This video breaks down how to access argc and argv directly from the stack, without GCC libraries. Follow along as we write a program to loop through and print user-provided arguments, complete with a visual stack explanation. Whether you&#8217;re new to assembly or leveling up, this tutorial offers clear, practical insights for coding low-level programs. Check out my other videos for more assembly tips, and subscribe for more coding goodness!</p>



<p class="wp-block-paragraph">Introduction to Command Line Arguments 00:00:00<br>Target Architecture and Assumptions 00:00:04<br>Recap of Command Line Arguments 00:00:56<br>Accessing Arguments in Pure Assembly 00:01:47<br>Program Structure and Data Section 00:02:19<br>Stack Pointer and Argument Count 00:04:16<br>Accessing Argument Vector (argv) 00:07:14<br>Looping Through Arguments 00:12:16<br>Incrementing to Next Argument 00:16:45<br>Visualizing the Stack 00:19:24<br>Running the Program with Arguments 00:21:56<br>Conclusion and Call to Subscribe 00:23:48</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">hey there let&#8217;s talk about accepting command line arguments in a pure assembly program</p>



<p class="wp-block-paragraph">written for x86-64 aka amd yasm assembly</p>



<p class="wp-block-paragraph">on linux anyway so uh there are going to be a lot of topics that i that i sort of mention in this</p>



<p class="wp-block-paragraph">video that are not actually covered in this video so if you feel yourself getting lost like for</p>



<p class="wp-block-paragraph">program in assembly in the first place.</p>



<p class="wp-block-paragraph">If you don&#8217;t know what command line arguments are,</p>



<p class="wp-block-paragraph">if you don&#8217;t know the terminal, things like that,</p>



<p class="wp-block-paragraph">you probably want to check out my previous videos</p>



<p class="wp-block-paragraph">because they will be explained in detail.</p>



<p class="wp-block-paragraph">For now, I&#8217;m just going to assume you know how to do all this basic stuff.</p>



<p class="wp-block-paragraph">And the only thing that I need to show you</p>



<p class="wp-block-paragraph">is how to write a program in Yasm assembly that can</p>



<p class="wp-block-paragraph">grab your command line arguments.</p>



<p class="wp-block-paragraph">So, you know, just to do a quick recap of what I&#8217;m even talking about.</p>



<p class="wp-block-paragraph">echo we can launch it with no arguments it doesn&#8217;t do anything but we can give</p>



<p class="wp-block-paragraph">it some arguments we can say hello and then we can say goodbye and that&#8217;s two</p>



<p class="wp-block-paragraph">arguments that I&#8217;m giving to echo echo will grab on to the arguments it was</p>



<p class="wp-block-paragraph">given it&#8217;s actually going to receive three arguments the index zero argument</p>



<p class="wp-block-paragraph">being the name of itself its own program and then the next two arguments being</p>



<p class="wp-block-paragraph">the stuff that I typed after the program but you can see that it somehow figured</p>



<p class="wp-block-paragraph">two arguments as strings and print them right so imagine you have an assembly</p>



<p class="wp-block-paragraph">program and you want the user to be able to launch your program and add</p>



<p class="wp-block-paragraph">arguments at the end of the command line and have your program behave in some</p>



<p class="wp-block-paragraph">certain way according to what the user wants the question then becomes how do</p>



<p class="wp-block-paragraph">you access those arguments it&#8217;s a little bit easier in GCC look at my other video</p>



<p class="wp-block-paragraph">that I posted about the topic for GCC linked assembly programs it&#8217;s a little</p>



<p class="wp-block-paragraph">You pretty much just look at RDI and RSI to get your argc and your character pointer array.</p>



<p class="wp-block-paragraph">When you&#8217;re dealing with pure assembly though, the GCC libraries don&#8217;t bundle up the command</p>



<p class="wp-block-paragraph">line arguments in a really convenient way for you.</p>



<p class="wp-block-paragraph">You&#8217;ve got to look for them elsewhere.</p>



<p class="wp-block-paragraph">It&#8217;s honestly not that much harder.</p>



<p class="wp-block-paragraph">It&#8217;s just a little, feels a little weird.</p>



<p class="wp-block-paragraph">I think at least for me, I was hoping to see the arguments in a register and I did not.</p>



<p class="wp-block-paragraph">But anyway, so here&#8217;s my program.</p>



<p class="wp-block-paragraph">Again, this is not an assembly programming video.</p>



<p class="wp-block-paragraph">an assembly programming video if you need to know how to program assembly see my other videos for</p>



<p class="wp-block-paragraph">now i&#8217;m just going to quickly go over it i&#8217;ve got my data section in yasm i am printing out a couple</p>



<p class="wp-block-paragraph">of strings or i i have a couple of strings defined i&#8217;m saying like the module has started i&#8217;m going</p>



<p class="wp-block-paragraph">to begin printing arguments i have some system call codes so that i can write just to standard</p>



<p class="wp-block-paragraph">output and so that i can exit the program this is pure assembly so we don&#8217;t actually return from</p>



<p class="wp-block-paragraph">we just get jumped into and then we call exit normally and then here&#8217;s the standard output pipe</p>



<p class="wp-block-paragraph">again another video covers that and then i&#8217;ve got the exit success code again another video covers</p>



<p class="wp-block-paragraph">that but basically you know exiting zero is usually what you do for success then i&#8217;ve got the</p>



<p class="wp-block-paragraph">text section which holds all my assembly instructions and this is my entry point we don&#8217;t</p>



<p class="wp-block-paragraph">really need to uh push and pop these registers because we&#8217;re just going to exit the program when</p>



<p class="wp-block-paragraph">it&#8217;s totally fine we would need to preserve Kali saved registers if we were</p>



<p class="wp-block-paragraph">jumping into a main function or if this was a different function that was being</p>



<p class="wp-block-paragraph">jumped into but we&#8217;re not so we don&#8217;t have to anyway here&#8217;s my entry point the</p>



<p class="wp-block-paragraph">underscore start for a pure assembly program and then I&#8217;m going to grab the</p>



<p class="wp-block-paragraph">incoming arguments when you&#8217;re linking with GCC which we&#8217;re not doing here in</p>



<p class="wp-block-paragraph">this video then the arguments come in very easily they just come in argc</p>



<p class="wp-block-paragraph">up in RDI and arg sorry argc comes into RDI and the character pointer array comes in as RSI so you</p>



<p class="wp-block-paragraph">can imagine in GCC this would be integer main and then integer argc character pointer array argv</p>



<p class="wp-block-paragraph">right hopefully you&#8217;ve done this in a higher level language so you have a better idea of what I&#8217;m</p>



<p class="wp-block-paragraph">talking about if not I guess that&#8217;s okay it will still allow you to grab even if you don&#8217;t</p>



<p class="wp-block-paragraph">it will still allow you to grab,</p>



<p class="wp-block-paragraph">even if you don&#8217;t understand this in C++.</p>



<p class="wp-block-paragraph">So argc is actually the stack pointer.</p>



<p class="wp-block-paragraph">The stack pointer register, RSP,</p>



<p class="wp-block-paragraph">always tells you where the top of the stack is,</p>



<p class="wp-block-paragraph">like what&#8217;s the last piece of data</p>



<p class="wp-block-paragraph">that we actually have sitting on the stack.</p>



<p class="wp-block-paragraph">So that&#8217;s gonna be the count of arguments.</p>



<p class="wp-block-paragraph">argc is always gonna be the stack pointer.</p>



<p class="wp-block-paragraph">So if you dereference the stack pointer register,</p>



<p class="wp-block-paragraph">pointer register then what you&#8217;re doing is you know the stack pointer register</p>



<p class="wp-block-paragraph">actually points to memory locations within the stack so if the memory</p>



<p class="wp-block-paragraph">location that it&#8217;s looking at is where argc is stored then you dereference it</p>



<p class="wp-block-paragraph">with the brackets and you&#8217;ll actually get argc so right away I&#8217;m just gonna</p>



<p class="wp-block-paragraph">steal argc off the top of the stack and this is a good idea to do right away</p>



<p class="wp-block-paragraph">because if you start doing other stuff you might end up modifying the stack</p>



<p class="wp-block-paragraph">especially if you start calling functions and things like that and and</p>



<p class="wp-block-paragraph">and and these these pieces of information will be lost or they&#8217;ll be a lot harder to find so right</p>



<p class="wp-block-paragraph">away i&#8217;m just going to say argc goes directly into r12 and i have a little comment reminder</p>



<p class="wp-block-paragraph">for myself at the top saying r12 is now argc same thing for uh r13 i&#8217;m going to say that&#8217;s a pointer</p>



<p class="wp-block-paragraph">to my character pointer array i talked about this in depth on my other video where we talked about</p>



<p class="wp-block-paragraph">an assembly program but basically if you look at uh if you look at argv right here it&#8217;s not just a</p>



<p class="wp-block-paragraph">pointer and it&#8217;s not just an array it&#8217;s a pointer to an array and if you recall in higher level</p>



<p class="wp-block-paragraph">languages or just i guess anything an array itself is a pointer because argv the symbol let&#8217;s say we</p>



<p class="wp-block-paragraph">were in a higher level language argv can only point to one thing so it&#8217;s going to point to the very</p>



<p class="wp-block-paragraph">but the beginning of your array is not going to be one string like one argument that the user gave</p>



<p class="wp-block-paragraph">you because the user could give you many arguments instead it&#8217;s an array of pointers</p>



<p class="wp-block-paragraph">so it&#8217;s a character pointer array meaning argv is a pointer to a pointer</p>



<p class="wp-block-paragraph">the first item in any array is what is pointed to by the symbol so like imagine if we had just</p>



<p class="wp-block-paragraph">had just for the sake of argument imagine if we had an integer array let&#8217;s say we had like 500</p>



<p class="wp-block-paragraph">integers in like a c++ program so the symbol a is what i&#8217;m trying to say the symbol a</p>



<p class="wp-block-paragraph">is really a pointer that points to the first integer in that array and then later of course</p>



<p class="wp-block-paragraph">you can dereference that pointer with some sort of an index to get the index 5 integer or the</p>



<p class="wp-block-paragraph">the array and a pointer to the first item.</p>



<p class="wp-block-paragraph">Or I guess you could say it&#8217;s both a pointer to the array</p>



<p class="wp-block-paragraph">and a pointer to the first item,</p>



<p class="wp-block-paragraph">because it&#8217;s kind of the same thing.</p>



<p class="wp-block-paragraph">So that means if we grab argv,</p>



<p class="wp-block-paragraph">then we&#8217;ll be grabbing a pointer.</p>



<p class="wp-block-paragraph">If we then dereference that pointer,</p>



<p class="wp-block-paragraph">it would tell us where another pointer is.</p>



<p class="wp-block-paragraph">And then that other pointer would point to a string</p>



<p class="wp-block-paragraph">representing the first argument.</p>



<p class="wp-block-paragraph">first argument so we&#8217;ll explain that more as i do this loop i&#8217;m going to i&#8217;m going to show you</p>



<p class="wp-block-paragraph">some code that actually loops through all the arguments anyway the thing about where to find</p>



<p class="wp-block-paragraph">that argv is it&#8217;s just the next pointer or i guess it&#8217;s the it&#8217;s the next item that the stack holds</p>



<p class="wp-block-paragraph">so remember i told you that rsp when this when this function comes in rsp is a pointer to wherever</p>



<p class="wp-block-paragraph">we&#8217;re we&#8217;re looking what memory location the top of the stack is so if we dereference that we get</p>



<p class="wp-block-paragraph">So if we dereference that, we get argc.</p>



<p class="wp-block-paragraph">Well, we just need to go find the next previous item in the stack</p>



<p class="wp-block-paragraph">and then dereference that so that we can get the first pointer or argv,</p>



<p class="wp-block-paragraph">you know, the first pointer to a pointer,</p>



<p class="wp-block-paragraph">or the first double pointer in your array of pointer to pointers.</p>



<p class="wp-block-paragraph">Why am I doing plus eight?</p>



<p class="wp-block-paragraph">This might actually make sense as is,</p>



<p class="wp-block-paragraph">sense as is but it&#8217;s important to understand that when you add stuff to the stack you&#8217;re actually</p>



<p class="wp-block-paragraph">decreasing the memory locations uh that you are pointing to so like if i if i increase a stack</p>



<p class="wp-block-paragraph">this is not a stack video there&#8217;s other videos that i have for that um if we add something to</p>



<p class="wp-block-paragraph">the top of a stack you imagine the stack growing visually in a in a vertical direction like it&#8217;s</p>



<p class="wp-block-paragraph">growing up right but inside of the computer the memory locations are actually going down</p>



<p class="wp-block-paragraph">If we&#8217;re looking at the stack pointer and we&#8217;re adding eight, what it&#8217;s saying is that</p>



<p class="wp-block-paragraph">we&#8217;re looking back into memory that was already added for the stack.</p>



<p class="wp-block-paragraph">So that&#8217;s like if we grew the stack, that would be subtracting from the memory location.</p>



<p class="wp-block-paragraph">So like looking further up in the stack would be subtracting from the memory location because</p>



<p class="wp-block-paragraph">the stack grows upward in the abstract, but downward in memory locations.</p>



<p class="wp-block-paragraph">So that means if we add eight, that means we&#8217;re going in the other direction.</p>



<p class="wp-block-paragraph">that means we&#8217;re going in the other direction.</p>



<p class="wp-block-paragraph">We&#8217;re looking downward into the stack.</p>



<p class="wp-block-paragraph">So what that means is that the top two items on the stack</p>



<p class="wp-block-paragraph">are first argc and then second, that first pointer,</p>



<p class="wp-block-paragraph">you know, the argv argument.</p>



<p class="wp-block-paragraph">And that&#8217;s how we access it with plus eight.</p>



<p class="wp-block-paragraph">Why is it a plus eight instead of plus something else?</p>



<p class="wp-block-paragraph">Because all pointers on 64-bit systems are 64-bit integers</p>



<p class="wp-block-paragraph">and 64-bit integers are eight bytes.</p>



<p class="wp-block-paragraph">If we&#8217;re talking about eight bytes, sorry,</p>



<p class="wp-block-paragraph">if we&#8217;re talking about eight bits per byte.</p>



<p class="wp-block-paragraph">So this is just how you access it.</p>



<p class="wp-block-paragraph">What about this other thing going on here?</p>



<p class="wp-block-paragraph">What&#8217;s this LEA instruction?</p>



<p class="wp-block-paragraph">Usually you see a move instruction, right?</p>



<p class="wp-block-paragraph">So we basically want to look at the stack pointer,</p>



<p class="wp-block-paragraph">but look one level lower.</p>



<p class="wp-block-paragraph">And each item on the stack is also going to be eight bytes.</p>



<p class="wp-block-paragraph">We want to look one item lower on the stack,</p>



<p class="wp-block-paragraph">and then we want to dereference it.</p>



<p class="wp-block-paragraph">but we don&#8217;t want to dereference and store the dereferenced value we still want to grab the</p>



<p class="wp-block-paragraph">actual pointer the thing is I shouldn&#8217;t have said dereference in the first place these are dereferencing</p>



<p class="wp-block-paragraph">brackets right so like up here on line 46 when you put brackets around rsp it dereferences whatever</p>



<p class="wp-block-paragraph">value rsp holds so therefore when you put brackets around this you kind of expect that you&#8217;re going</p>



<p class="wp-block-paragraph">to be dereferencing right but we don&#8217;t want to dereference we just want the original address that</p>



<p class="wp-block-paragraph">showing us. So the problem with this is that when we say RSP plus eight,</p>



<p class="wp-block-paragraph">we can&#8217;t actually do a mathematical formula unless we&#8217;re inside of brackets, which means we</p>



<p class="wp-block-paragraph">can&#8217;t do them in a move instruction without accidentally dereferencing and losing a pointer</p>



<p class="wp-block-paragraph">to the actual array of pointers. If we dereferenced like this, we would just end up with,</p>



<p class="wp-block-paragraph">you know, a pointer to one string. So the way around this is instead of using the move instruction,</p>



<p class="wp-block-paragraph">instead of using the move instruction we use the lea instruction the lea instruction allows us to</p>



<p class="wp-block-paragraph">put a formula inside of brackets so that the assembler won&#8217;t get confused but then it won&#8217;t</p>



<p class="wp-block-paragraph">put the dereferenced value into r13 it&#8217;ll just put the actual value of whatever we see</p>



<p class="wp-block-paragraph">with that formula meaning it&#8217;ll give us the memory location of the item sitting one under the top of</p>



<p class="wp-block-paragraph">this at this point r13 is now the memory location of the of the item sitting one underneath the top</p>



<p class="wp-block-paragraph">of the stack and then we can de-reference that later in order to look at all of our arguments</p>



<p class="wp-block-paragraph">so the next part of our code is just going to print an intro message so there&#8217;s like this intro</p>



<p class="wp-block-paragraph">string up here hello and um i&#8217;m basically going to call a custom function that i made to just sort of</p>



<p class="wp-block-paragraph">Printing. Don&#8217;t worry about this code right here.</p>



<p class="wp-block-paragraph">This is not the point of the video.</p>



<p class="wp-block-paragraph">I just made a custom function that just kind of helped me print.</p>



<p class="wp-block-paragraph">Don&#8217;t worry about that.</p>



<p class="wp-block-paragraph">The real meat of this video is that we&#8217;re going to loop through all arguments</p>



<p class="wp-block-paragraph">and just print every single argument that the user provided.</p>



<p class="wp-block-paragraph">So you can imagine this is maybe the top of a while loop here.</p>



<p class="wp-block-paragraph">Notice how, oh, I forgot to replace main with start with start.</p>



<p class="wp-block-paragraph">I had another version of this program that used main.</p>



<p class="wp-block-paragraph">pretend we have this is called the main loop instead of the the main functions</p>



<p class="wp-block-paragraph">loop anyway so main loop initialize first thing I&#8217;m going to do is I&#8217;m going</p>



<p class="wp-block-paragraph">to initialize the loop by saying we&#8217;re looking at index 0 okay no problem so</p>



<p class="wp-block-paragraph">we&#8217;re looking at index 0 we want to do that we want to look at all the</p>



<p class="wp-block-paragraph">arguments you know we want to look at index 0 and index 1 and index 2 and we</p>



<p class="wp-block-paragraph">just want to keep going until we&#8217;re out of arguments remember that we also have</p>



<p class="wp-block-paragraph">the number of arguments coming from argc now sitting in r12. So that means if we have a</p>



<p class="wp-block-paragraph">counter that starts at zero with r14 and then we know how many arguments there are in r12,</p>



<p class="wp-block-paragraph">we should be able to know when the loop stops. So just a reminder that, you know, the loops here,</p>



<p class="wp-block-paragraph">the arrays here are zero-based indexed or zero-index based, which means, for example,</p>



<p class="wp-block-paragraph">that&#8217;s three arguments but the array of arguments is going to have indexes zero and one and two</p>



<p class="wp-block-paragraph">which means the last valid index is going to be two or the size minus one think about that if you</p>



<p class="wp-block-paragraph">have five arguments the last index that is valid is going to be four size minus one because it&#8217;s</p>



<p class="wp-block-paragraph">zero based so we can use that logic to figure out if we&#8217;re done so we start off with an index of zero</p>



<p class="wp-block-paragraph">here and then at the top of the loop i&#8217;m just going to quickly ask are we done how do we know</p>



<p class="wp-block-paragraph">are we done how do we know if we&#8217;re done we compare the current index we&#8217;re</p>



<p class="wp-block-paragraph">looking at with the count and we say if the current index we&#8217;re looking at is</p>



<p class="wp-block-paragraph">greater than or equal to the count then we know we&#8217;re already done we don&#8217;t need</p>



<p class="wp-block-paragraph">to look at any more indexes why am I saying is is the index greater than or</p>



<p class="wp-block-paragraph">equal to the count because remember if we have five arguments then the last</p>



<p class="wp-block-paragraph">valid index is four therefore if we find ourselves looking at index five we know</p>



<p class="wp-block-paragraph">already done five is equal to or greater than five, but four is not equal to or greater</p>



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



<p class="wp-block-paragraph">So that&#8217;s why I&#8217;m using this logic here.</p>



<p class="wp-block-paragraph">I&#8217;m saying if we&#8217;re done, then jump to the done label.</p>



<p class="wp-block-paragraph">Basically what&#8217;s the done label?</p>



<p class="wp-block-paragraph">It&#8217;s main loop done.</p>



<p class="wp-block-paragraph">All it really does is it says goodbye and then it just exits the program with a system</p>



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



<p class="wp-block-paragraph">Again, I have other videos that explain system calls and all that stuff.</p>



<p class="wp-block-paragraph">So if we&#8217;re done, we, uh, we jumped down to the done area, but if not, then execute</p>



<p class="wp-block-paragraph">to the done area but if not then execution will fall through to this next loop or sorry this next</p>



<p class="wp-block-paragraph">label which is not necessarily we don&#8217;t really need a label there but i i like to put i like to</p>



<p class="wp-block-paragraph">put it there just to help myself remember this is what it looks like in terms of a while loop you</p>



<p class="wp-block-paragraph">know i have like here&#8217;s the top of the while loop here&#8217;s the little comparison part of the while loop</p>



<p class="wp-block-paragraph">here&#8217;s the body like the opening braces of the while loop and then here&#8217;s sort of like the</p>



<p class="wp-block-paragraph">closing braces i just like to do that but anyway after we decided that we are not done and we drop</p>



<p class="wp-block-paragraph">done and we drop through to the next actual instruction we&#8217;re just going to</p>



<p class="wp-block-paragraph">print the next argument so what&#8217;s the next argument we will dereference r13</p>



<p class="wp-block-paragraph">remember up here we took the second item sitting like you know one under the top</p>



<p class="wp-block-paragraph">of the stack and we just stuck it into r13 so this is r13 is now the address of</p>



<p class="wp-block-paragraph">the second item on the stack if we de-reference it then that&#8217;s going to give</p>



<p class="wp-block-paragraph">then that&#8217;s going to give us a pointer to our um sorry it&#8217;s going to give us a pointer to the first</p>



<p class="wp-block-paragraph">item to the first string i should say to the first string uh the f this the string of the first</p>



<p class="wp-block-paragraph">argument so if we dereference you know let me say this one more time just to make sure that i&#8217;m</p>



<p class="wp-block-paragraph">item, you know, the item right under the top of the stack, that&#8217;s going to be a pointer</p>



<p class="wp-block-paragraph">to the first argument string.</p>



<p class="wp-block-paragraph">So if we just simply dereference R13, then we&#8217;re basically telling RDI, here&#8217;s a pointer</p>



<p class="wp-block-paragraph">to the string that we want to print.</p>



<p class="wp-block-paragraph">Okay, so then I just call my helper function to print that string to standard output, no</p>



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



<p class="wp-block-paragraph">And then we have to figure out like, how do we increment to go to the next string?</p>



<p class="wp-block-paragraph">might have been unclear earlier because gcc does it in a different way but on the stack</p>



<p class="wp-block-paragraph">every item underneath the the top of the stack is a is another pointer it&#8217;s part of the original argv</p>



<p class="wp-block-paragraph">array it&#8217;s another pointer to a different string so basically if i increase r14 here then i&#8217;m</p>



<p class="wp-block-paragraph">increasing the index counter that&#8217;ll help us eventually terminate but notice how here i&#8217;m</p>



<p class="wp-block-paragraph">Remember R13 is the second item, you know, the item right under the top of the stack.</p>



<p class="wp-block-paragraph">And if I dereference that, then I now have a pointer to the first argument string.</p>



<p class="wp-block-paragraph">If I want to go one lower into the stack, then I just add eight to that register&#8217;s value.</p>



<p class="wp-block-paragraph">Because again, remember, the stack grows downward in memory.</p>



<p class="wp-block-paragraph">So if I increase the value, then I&#8217;m sort of like going through previous items that were put into the stack.</p>



<p class="wp-block-paragraph">So imagine the stack here, it&#8217;s got like,</p>



<p class="wp-block-paragraph">you know, argc sitting on top</p>



<p class="wp-block-paragraph">and then underneath argc,</p>



<p class="wp-block-paragraph">it&#8217;s got a pointer to the first argument.</p>



<p class="wp-block-paragraph">And then under that in the stack,</p>



<p class="wp-block-paragraph">it&#8217;s got a pointer to the second argument.</p>



<p class="wp-block-paragraph">And then under that in the stack,</p>



<p class="wp-block-paragraph">it&#8217;s got a pointer to the third argument.</p>



<p class="wp-block-paragraph">Then under that, it&#8217;s got a pointer</p>



<p class="wp-block-paragraph">to the next argument and so forth.</p>



<p class="wp-block-paragraph">So every time we wanna go to the next arguments pointer,</p>



<p class="wp-block-paragraph">the next arguments string pointer,</p>



<p class="wp-block-paragraph">we just add eight to that R13 register,</p>



<p class="wp-block-paragraph">which was originally just pointing at the first string.</p>



<p class="wp-block-paragraph">so again why eight because pointers are 64-bit integers therefore they are eight bytes so I&#8217;m</p>



<p class="wp-block-paragraph">just literally increasing the index by one and then I&#8217;m moving that register r13 to point to</p>



<p class="wp-block-paragraph">the next pointer that way next time I dereference it up here on line 70 I&#8217;ll be dereferencing the</p>



<p class="wp-block-paragraph">next string and these strings don&#8217;t need to be contiguous they could be located anywhere it&#8217;s</p>



<p class="wp-block-paragraph">that is contiguous but it&#8217;s just full of pointers to other strings or sorry it&#8217;s full of if we de</p>



<p class="wp-block-paragraph">reference the stack pointer at any point then we will get the address of a string so then we will</p>



<p class="wp-block-paragraph">get a pointer to a string this double pointer stuff sometimes i get tongue tongue tired okay so uh</p>



<p class="wp-block-paragraph">when we&#8217;re done printing and incrementing then we just jump to the top of the loop</p>



<p class="wp-block-paragraph">And then finally, when we&#8217;re done, well, we&#8217;re done.</p>



<p class="wp-block-paragraph">Let me draw this out for you, because I think the way I&#8217;m explaining it might be</p>



<p class="wp-block-paragraph">a little bit unclear, so I just want to make sure that I&#8217;m being totally clear on</p>



<p class="wp-block-paragraph">this, okay, so I&#8217;ve got my little annotator here and you can imagine here&#8217;s a stack</p>



<p class="wp-block-paragraph">and it visually grows up.</p>



<p class="wp-block-paragraph">We can imagine that every time we add an item to the stack, it grows up.</p>



<p class="wp-block-paragraph">Like if you wanted to take a five, stick it on top of the stack.</p>



<p class="wp-block-paragraph">Well, then it would end up on the top of the stack, right?</p>



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



<p class="wp-block-paragraph">Right? No problem.</p>



<p class="wp-block-paragraph">Oh, maybe this needs to be bigger because of my pen size.</p>



<p class="wp-block-paragraph">So let&#8217;s do it like that.</p>



<p class="wp-block-paragraph">What the heck happened?</p>



<p class="wp-block-paragraph">I lost the whole desktop.</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">So we have this and this and this and this.</p>



<p class="wp-block-paragraph">And so there&#8217;s probably some kind of a value sitting on top of the stack.</p>



<p class="wp-block-paragraph">When we started the program,</p>



<p class="wp-block-paragraph">RSP is a register that just has the memory location of the top of the stack,</p>



<p class="wp-block-paragraph">you know, the most recently added item.</p>



<p class="wp-block-paragraph">you know the most recently added item we know that this was actually arg c so if we dereferenced rsp</p>



<p class="wp-block-paragraph">that&#8217;ll go to wherever rx is and get it so we can basically say that rx is sitting on the top of</p>



<p class="wp-block-paragraph">the stack so you know we dereference our rsp which holds a memory location to this place in memory</p>



<p class="wp-block-paragraph">we just had an integer stored an eight byte integer okay cool so then the next lowest i guess</p>



<p class="wp-block-paragraph">the next highest item or the next lower item is arg v at index zero which is the same thing as</p>



<p class="wp-block-paragraph">just saying arg v remember a pointer to the array is really a pointer to the first item</p>



<p class="wp-block-paragraph">the next lower item is arg v at index one and so forth so we can just keep doing this we can keep</p>



<p class="wp-block-paragraph">keep doing this we can keep going lower and lower and lower on the stack by adding eight to r13</p>



<p class="wp-block-paragraph">because remember r13 originally pointed uh you know to this item right here i don&#8217;t know i&#8217;ll</p>



<p class="wp-block-paragraph">say like r13 maybe starts off pointing uh to the first argument because that&#8217;s the way we have it</p>



<p class="wp-block-paragraph">set up so every time the loop iterates if we dereference r13 then we&#8217;re getting a pointer to</p>



<p class="wp-block-paragraph">when we add eight bytes to r13 we&#8217;re really just moving it down to the next pointer that we can</p>



<p class="wp-block-paragraph">dereference hopefully that was a little bit more clear than what i said before or maybe you&#8217;re just</p>



<p class="wp-block-paragraph">a visual learner um you know it&#8217;s a good idea to try to explain things in many different ways</p>



<p class="wp-block-paragraph">but long story short we&#8217;re going down down down further in the stack to get more arguments and</p>



<p class="wp-block-paragraph">we&#8217;re just printing them and so now that we&#8217;ve explained it all we should be able to just run</p>



<p class="wp-block-paragraph">clear and make run and under the hood let me just show you real fast what I&#8217;ve got inside of my make</p>



<p class="wp-block-paragraph">file under the hood when we do make run you don&#8217;t need to know about make files I have a video that</p>



<p class="wp-block-paragraph">explains all of this don&#8217;t worry but well I mean you don&#8217;t need to know it to understand this video</p>



<p class="wp-block-paragraph">but you probably do need to know it notice how when I call the executable which in this case is</p>



<p class="wp-block-paragraph">I give it some arguments.</p>



<p class="wp-block-paragraph">I give it just some strings.</p>



<p class="wp-block-paragraph">First arg, second arg, third arg, fourth arg.</p>



<p class="wp-block-paragraph">So that&#8217;s the same thing as if I typed echo first arg,</p>



<p class="wp-block-paragraph">second arg, third arg, fourth arg, right?</p>



<p class="wp-block-paragraph">That&#8217;s what echo is doing.</p>



<p class="wp-block-paragraph">So in the make file, I&#8217;m just giving it those arguments.</p>



<p class="wp-block-paragraph">And then our program now is looping</p>



<p class="wp-block-paragraph">through all of the arguments.</p>



<p class="wp-block-paragraph">It knows when to stop because we grabbed argc</p>



<p class="wp-block-paragraph">and it knows where those strings are located</p>



<p class="wp-block-paragraph">are located because the pointers to those strings are just sitting on the stack so if we deref twice</p>



<p class="wp-block-paragraph">we&#8217;re derefing we&#8217;re doing a double dereference a pointer to a pointer</p>



<p class="wp-block-paragraph">at least we could say r13 is a pointer to a pointer but the actual values sitting inside</p>



<p class="wp-block-paragraph">the stack are just pointers to strings um so let&#8217;s just do this in a slightly different way</p>



<p class="wp-block-paragraph">clear and then I&#8217;ll say main because that&#8217;s the name of the program that I</p>



<p class="wp-block-paragraph">compiled you can imagine this is could be named something else and I&#8217;ll just put</p>



<p class="wp-block-paragraph">hello you are super cool now so I&#8217;m giving it one two three four five</p>



<p class="wp-block-paragraph">arguments in addition to main so it should print six things main hello you</p>



<p class="wp-block-paragraph">are super cool now so notice how it prints main hello you are super cool now</p>



<p class="wp-block-paragraph">Alright, that&#8217;s pretty much everything that I wanted to show you for the pure assembly</p>



<p class="wp-block-paragraph">version of Grappin Command Line Arguments.</p>



<p class="wp-block-paragraph">Thank you so much for listening.</p>



<p class="wp-block-paragraph">It&#8217;s a little late for me.</p>



<p class="wp-block-paragraph">The sun&#8217;s starting to come up.</p>



<p class="wp-block-paragraph">I&#8217;ve got to go and eat a bunch of cookies.</p>



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



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



<p class="wp-block-paragraph">I will see you in the next one.</p>



<p class="wp-block-paragraph">Happy studying and coding and all that stuff.</p>



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



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



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



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



<p class="wp-block-paragraph">If you could do me a please, a small little favor,</p>



<p class="wp-block-paragraph">could you please subscribe and follow this channel or these videos</p>



<p class="wp-block-paragraph">or whatever it is you do on the current social media website</p>



<p class="wp-block-paragraph">that you&#8217;re looking at right now.</p>



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



<p class="wp-block-paragraph">and grow this community.</p>



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just i&#8217;ll be able to keep making videos in general so please do do me a kindness and uh and</p>



<p class="wp-block-paragraph">subscribe you know sometimes i&#8217;m sleeping in the middle of the night and i just wake up because i</p>



<p class="wp-block-paragraph">know somebody subscribed or followed it just wakes me up and i get filled with joy that&#8217;s exactly what</p>



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



<p class="wp-block-paragraph">you want to just wake me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake</p>



<p class="wp-block-paragraph">up i promise that&#8217;s what will happen also uh if you look at the middle of the screen right now you</p>



<p class="wp-block-paragraph">of the screen right now you should see a qr code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which i think is also named somewhere at the bottom of this video and it&#8217;ll take you to my</p>



<p class="wp-block-paragraph">main website where you can just kind of like see all the videos i published and the services and</p>



<p class="wp-block-paragraph">tutorials and things that i offer and all that good stuff and uh if you have a suggestion for uh</p>



<p class="wp-block-paragraph">clarifications or errata or just future videos that you want to see please leave a comment or</p>



<p class="wp-block-paragraph">up what&#8217;s going on you know just send me a comment whatever i also wake up for those in the middle of</p>



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



<p class="wp-block-paragraph">me i would really appreciate it so again thank you so much for watching this video and um enjoy the</p>



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/">Master Command Line Arguments in x86-64 Assembly with YASM</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
