<?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>programming tutorial Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/programming-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/programming-tutorial/</link>
	<description></description>
	<lastBuildDate>Sat, 27 Jun 2026 21:17:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>programming tutorial Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/programming-tutorial/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>AVL Trees: Adding Linear Data and Performing Rotations</title>
		<link>https://www.NeuralLantern.com/avl-trees-adding-linear-data-and-performing-rotations/</link>
					<comments>https://www.NeuralLantern.com/avl-trees-adding-linear-data-and-performing-rotations/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 27 Jun 2026 21:16:58 +0000</pubDate>
				<category><![CDATA[AVL Trees]]></category>
		<category><![CDATA[Binary Search Trees]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[AVL rotation example]]></category>
		<category><![CDATA[AVL tree]]></category>
		<category><![CDATA[AVL trees]]></category>
		<category><![CDATA[balance factor]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[binary search tree insertion]]></category>
		<category><![CDATA[bst]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[data structures tutorial]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[self balancing tree]]></category>
		<category><![CDATA[tree rotations]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=396</guid>

					<description><![CDATA[<p>In this AVL tree example we add linear data starting with 12 then 21 30 38 42 and 55. After each insertion we update balance factors and when we hit imbalance we select the XYZ trinode and perform rotations to restore the AVL property. The tree stays balanced despite the bad input data.</p>
<p>The post <a href="https://www.NeuralLantern.com/avl-trees-adding-linear-data-and-performing-rotations/">AVL Trees: Adding Linear Data and Performing Rotations</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="AVL Trees: Adding Linear Data and Performing Rotations" width="1380" height="776" src="https://www.youtube.com/embed/6kasiB918fE?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">Watch me build an AVL tree step by step with linear data that would normally create a terrible unbalanced BST. See insertions, balance factor calculations, and rotations in action.</p>



<p class="wp-block-paragraph">Perfect follow-up to my BST and AVL intro videos.</p>



<p class="wp-block-paragraph">00:00 Introduction to AVL Tree with Bad Data<br>00:14 Previous Videos on BST and AVL Trees<br>00:28 Practice Example Building Step by Step<br>00:50 Adding First Node 12<br>01:11 Adding Node 21<br>02:10 Adding Node 30 and First Rotation<br>04:03 Recomputing Balance Factors<br>05:08 Adding Node 38<br>08:03 Adding Node 42 and Second Rotation<br>12:51 Recomputing Balance After Rotation<br>14:09 Adding Node 55 and Third Rotation<br>18:55 Placing Unaccounted Nodes<br>19:21 Final Tree and Balance Factors<br>20:07 Conclusion and Thanks</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 the Blog: https://www.NeuralLantern.com</li>



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



<p class="wp-block-paragraph">Hey there! Let&#8217;s build an AVL self-balancing binary search tree with some really bad data.</p>



<p class="wp-block-paragraph">It&#8217;s all going to work out, trust me.</p>



<p class="wp-block-paragraph">Okay, so hopefully by now you&#8217;ve seen my other videos where we talked about how to define binary</p>



<p class="wp-block-paragraph">search trees, how to build them, search through them, add, delete, all that stuff. And also AVL</p>



<p class="wp-block-paragraph">trees. What are rotations? Why do we rotate? How does the AVL tree maintain itself? And so forth.</p>



<p class="wp-block-paragraph">just going to be a practice example. In the previous video that I that I</p>



<p class="wp-block-paragraph">recorded regarding AVL trees, I started off with a really long and gnarly linear</p>



<p class="wp-block-paragraph">tree and then I suddenly turned on AVLness and we rotated the crap out of</p>



<p class="wp-block-paragraph">it for about 30 minutes until it was really really good. So now I&#8217;m just</p>



<p class="wp-block-paragraph">going to build a tree one step at a time. Suppose for the sake of argument that</p>



<p class="wp-block-paragraph">you have some really bad data. You know a long time ago, I love telling this story.</p>



<p class="wp-block-paragraph">time ago you know my grandma before she passed on she was kind of bitter and she had some enemies in</p>



<p class="wp-block-paragraph">the neighborhood she used to call the cops on her neighbors for gossip um she had a neighbor who</p>



<p class="wp-block-paragraph">kind of feuded with her and at one point according to my grandma anyway uh my neighbor like didn&#8217;t</p>



<p class="wp-block-paragraph">like my grandma&#8217;s tree and so one day when my grandma was looking out into the backyard</p>



<p class="wp-block-paragraph">through the back window because she likes to yell at ducks who are swimming in her pool</p>



<p class="wp-block-paragraph">notice that the other little old lady&#8217;s arm just kind of went over my grandma&#8217;s fence</p>



<p class="wp-block-paragraph">with a spray bottle and then sprayed her tree. And then my grandma&#8217;s tree died. So this kind of</p>



<p class="wp-block-paragraph">thing I like to call, you know, tree poisoning or data poisoning or bad data, it can affect a binary</p>



<p class="wp-block-paragraph">search tree and make it really, really, really slow. But in AVL trees, if we have bad data,</p>



<p class="wp-block-paragraph">it should actually end up being fine. So I&#8217;m just going to say we&#8217;re poisoning our grandma&#8217;s tree</p>



<p class="wp-block-paragraph">grandma&#8217;s tree with some bad data. I&#8217;ll just do maybe maybe five pieces of data. We could go</p>



<p class="wp-block-paragraph">further than that but it&#8217;s it&#8217;s going to be a super long video if we do. So we&#8217;re going to add</p>



<p class="wp-block-paragraph">these pieces of data one by one. So that means the first thing I&#8217;m going to do remember we are kind</p>



<p class="wp-block-paragraph">of just regularly you know building a regular binary search tree. It&#8217;s just that the differences</p>



<p class="wp-block-paragraph">after we modify the topology in some way we&#8217;ll just check to see that it satisfies the rules of</p>



<p class="wp-block-paragraph">then we&#8217;re going to start performing rotations to make sure that it&#8217;s self-balancing.</p>



<p class="wp-block-paragraph">So we&#8217;ll add the 12 first.</p>



<p class="wp-block-paragraph">So let me see if I can draw a little arrow just indicating,</p>



<p class="wp-block-paragraph">yeah, we&#8217;re going to add this number right now.</p>



<p class="wp-block-paragraph">I&#8217;m going to do an ellipse for a node.</p>



<p class="wp-block-paragraph">And you know, like for binary, what is that?</p>



<p class="wp-block-paragraph">Flying saucer for binary search trees.</p>



<p class="wp-block-paragraph">It&#8217;s like, well, if there is no data already, if the tree is empty,</p>



<p class="wp-block-paragraph">first piece of data you add is going to end up being the root node. So that&#8217;s it. We have our</p>



<p class="wp-block-paragraph">root node here. See my other videos if you want more practice on building trees. So we&#8217;re just</p>



<p class="wp-block-paragraph">going to call that the root node. And then we&#8217;re going to compute its balance factor, which is</p>



<p class="wp-block-paragraph">obviously just going to be a zero. So that was super easy. Now we&#8217;re going to move on to adding</p>



<p class="wp-block-paragraph">the next piece of data. Things are getting a little bit worse. This is going to be a linear tree.</p>



<p class="wp-block-paragraph">tree if it weren&#8217;t for our trusty I guess AVL functionality so the 21 I&#8217;m</p>



<p class="wp-block-paragraph">gonna maybe just duplicate this node right now and set that to a 21 and then</p>



<p class="wp-block-paragraph">we&#8217;ll figure out where does the 21 go well it can&#8217;t be the root because the</p>



<p class="wp-block-paragraph">root is already occupied 21 is larger than 12 so it&#8217;s got to be on the right</p>



<p class="wp-block-paragraph">side so the 21 is going to be the right child of the root node so I&#8217;m just going</p>



<p class="wp-block-paragraph">Connecting line right here.</p>



<p class="wp-block-paragraph">And then we have to recompute balance factors.</p>



<p class="wp-block-paragraph">So the 21 is the thing we just added.</p>



<p class="wp-block-paragraph">We have to compute that.</p>



<p class="wp-block-paragraph">Then we have to work our way up the tree until we hit root.</p>



<p class="wp-block-paragraph">So we see the root node.</p>



<p class="wp-block-paragraph">It now has a balance factor of 1.</p>



<p class="wp-block-paragraph">So it got a little bit worse.</p>



<p class="wp-block-paragraph">But we don&#8217;t see 2 or worse.</p>



<p class="wp-block-paragraph">So that means this is currently a valid AVL tree.</p>



<p class="wp-block-paragraph">And we don&#8217;t have to do any rotations.</p>



<p class="wp-block-paragraph">So now it&#8217;s time to add the 30.</p>



<p class="wp-block-paragraph">just realized I could just upload like a hundred videos like this and I think you&#8217;d all be pretty</p>



<p class="wp-block-paragraph">happy or some people would be pretty happy um I don&#8217;t know if I want to do that to myself maybe</p>



<p class="wp-block-paragraph">I will so we&#8217;re going to add the 30 node uh so first I&#8217;m just going to duplicate some node</p>



<p class="wp-block-paragraph">and I&#8217;m going to call it 30 then we have to figure out where the 30 node belongs uh it&#8217;s not going</p>



<p class="wp-block-paragraph">to be the root node that&#8217;s already occupied 30 belongs on the right side of 12 but we can&#8217;t use</p>



<p class="wp-block-paragraph">of 12 but we can&#8217;t use that right child it&#8217;s occupied 30 belongs on the right side of 21</p>



<p class="wp-block-paragraph">so you know it makes sense we called this linear data that would make a linear tree so everything</p>



<p class="wp-block-paragraph">ended up being on the right side so far it&#8217;s just getting worse and worse but now the ablness is</p>



<p class="wp-block-paragraph">going to kind of come to the rescue we have to recompute the balance factors so the 30 has a 0</p>



<p class="wp-block-paragraph">the 21 ends up having a 1 again if you want practice computing balance factors see my other</p>



<p class="wp-block-paragraph">The 12 has a balance factor of 2 and now we know right away this is not a valid ABL tree anymore</p>



<p class="wp-block-paragraph">because we have a balance factor that is bad. It&#8217;s too bad.</p>



<p class="wp-block-paragraph">So we have to now select an XYZ trinode subtree so we can perform a rotation.</p>



<p class="wp-block-paragraph">I&#8217;m sure you can imagine it&#8217;s just going to end up being three nodes that are perfectly balanced like that.</p>



<p class="wp-block-paragraph">But let&#8217;s do it one step at a time.</p>



<p class="wp-block-paragraph">So the Z node is going to be the 12.</p>



<p class="wp-block-paragraph">That was the first node that we noticed that was out of whack or like I guess the highest node.</p>



<p class="wp-block-paragraph">or like I guess the highest node of the lowest nodes.</p>



<p class="wp-block-paragraph">And then we have to find Y by taking a child of Z.</p>



<p class="wp-block-paragraph">There&#8217;s only one possible child we could choose, so that&#8217;s going to be Y.</p>



<p class="wp-block-paragraph">And then we find X by taking a child of Y.</p>



<p class="wp-block-paragraph">There&#8217;s only one choice again, so it&#8217;s just going to be there.</p>



<p class="wp-block-paragraph">Now we have X, Y, and Z, and I&#8217;m going to write it down real fast.</p>



<p class="wp-block-paragraph">Let me just put this in black ink.</p>



<p class="wp-block-paragraph">So X is 30, and Y is 21, and Z is 12.</p>



<ol start="12" class="wp-block-list">
<li>Then we&#8217;re going to do A and B and C, which are going to be just in order representations of</li>
</ol>



<p class="wp-block-paragraph">XYZ. So again, think in your code, you would be doing pointers, you&#8217;d probably want to make three</p>



<p class="wp-block-paragraph">more pointers, call them ABC. If you had a rotation function, the rotation function,</p>



<p class="wp-block-paragraph">after you selected three nodes to rotate, it would receive XYZ. And then you say, let&#8217;s reorder,</p>



<p class="wp-block-paragraph">you know, XYZ and call them ABC. So A is going to be 12, and B is going to be 21,</p>



<p class="wp-block-paragraph">it should you know ascend from left to right if we&#8217;re not supporting duplicates in our tree</p>



<p class="wp-block-paragraph">and then i&#8217;m going to um just you know make some make some nodes for our target pattern here</p>



<p class="wp-block-paragraph">our output pattern so i&#8217;m going to like make some nodes here kind of place them uh in the perfect</p>



<p class="wp-block-paragraph">avl tree output pattern a perfectly balanced trinode subtree i&#8217;m just going to reconnect this</p>



<p class="wp-block-paragraph">The output pattern is always the same.</p>



<p class="wp-block-paragraph">You know, it always starts this way because this is better</p>



<p class="wp-block-paragraph">than the linear pattern that we have above.</p>



<p class="wp-block-paragraph">And then I just have to update the numbers.</p>



<p class="wp-block-paragraph">So the left child is going to be 12.</p>



<p class="wp-block-paragraph">The right child is going to be 21.</p>



<p class="wp-block-paragraph">Sorry, the center is going to be 21, the new parent.</p>



<p class="wp-block-paragraph">And the right child is going to be 30.</p>



<p class="wp-block-paragraph">Okay, now we look for any nodes that are children of the input nodes</p>



<p class="wp-block-paragraph">that have been unaccounted for.</p>



<p class="wp-block-paragraph">You can tell easily that all nodes are being used.</p>



<p class="wp-block-paragraph">So we don&#8217;t even have to worry about that step.</p>



<p class="wp-block-paragraph">So now that we have our trinode subtree which is perfectly balanced, we are ready to just sort of override it into the diagram.</p>



<p class="wp-block-paragraph">And since the diagram only has the three nodes to begin with, I could pretty much just like erase everything, call it a day, and say this is the new tree, the new rotated tree.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to maybe put this in the middle I guess.</p>



<p class="wp-block-paragraph">I&#8217;m going to delete this over here and recompute the balance factors.</p>



<p class="wp-block-paragraph">a zero, get zeros, and this 21 also gets a zero because it&#8217;s perfectly balanced.</p>



<p class="wp-block-paragraph">Next thing is let&#8217;s move on to adding the number 38. So we&#8217;ll add the 38 here and</p>



<p class="wp-block-paragraph">same thing that we do before. Let&#8217;s make a copy of one of the nodes for our diagram.</p>



<p class="wp-block-paragraph">Let&#8217;s call it the 38 and then let&#8217;s figure out where it belongs. It&#8217;s not going to be the new</p>



<p class="wp-block-paragraph">root node because that&#8217;s occupied. It belongs on the right side. It&#8217;s not going to be the right</p>



<p class="wp-block-paragraph">It&#8217;s not going to be the right child because that&#8217;s occupied.</p>



<p class="wp-block-paragraph">It belongs on the right side of the 30.</p>



<p class="wp-block-paragraph">It couldn&#8217;t go on the left.</p>



<p class="wp-block-paragraph">That would be an invalid binary search tree.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to stick it right there and do a connection.</p>



<p class="wp-block-paragraph">And then we&#8217;re going to update the balance factors.</p>



<p class="wp-block-paragraph">So the 38 is a leaf.</p>



<p class="wp-block-paragraph">It gets 0.</p>



<p class="wp-block-paragraph">The 30 gets a 1.</p>



<p class="wp-block-paragraph">And the 21 also gets a 1 because its left subtree is a 1 and its right subtree is 2,</p>



<p class="wp-block-paragraph">or height, and the difference is just 1.</p>



<p class="wp-block-paragraph">is just one. Remember we don&#8217;t really need to update the 12 or any nodes that are not</p>



<p class="wp-block-paragraph">directly above the node that we just added or removed. So if you look at this tree there&#8217;s</p>



<p class="wp-block-paragraph">a little bit of imbalance but nothing is two or worse so we don&#8217;t actually need to perform a</p>



<p class="wp-block-paragraph">rotation. This is already a valid AVL tree. So I&#8217;m going to move on to adding the next number.</p>



<p class="wp-block-paragraph">Let&#8217;s add a 42. Same thing we&#8217;re going to duplicate a node for our diagram and we&#8217;re going to call it</p>



<p class="wp-block-paragraph">going to call it the 42 where does it belong well we start by looking at root that&#8217;s occupied 42</p>



<p class="wp-block-paragraph">belongs on the right side of 21 the right child is occupied 42 belongs on the right side belongs on</p>



<p class="wp-block-paragraph">the right side i mean it&#8217;s always going to be on the very right of the of the diagram because that&#8217;s</p>



<p class="wp-block-paragraph">the poison data that we received uh so i&#8217;m going to put it over there and then connect um the child</p>



<p class="wp-block-paragraph">child relationship and then let&#8217;s update the the balance factor so 42 gets a 0</p>



<p class="wp-block-paragraph">38 gets a 1 and 30 gets a 2 now because it&#8217;s got 2 height of subtree on its</p>



<p class="wp-block-paragraph">right side and no subtree on its left side the 21 we should update left subtree</p>



<p class="wp-block-paragraph">is a 1 right subtree is a 3 oh it&#8217;s still gonna it&#8217;s actually gonna be 2 so</p>



<p class="wp-block-paragraph">we have two instances of the number 2 and again which one do we actually want</p>



<p class="wp-block-paragraph">by the way here&#8217;s here&#8217;s how I like to eyeball it you can kind of see oh there&#8217;s two levels of</p>



<p class="wp-block-paragraph">difference in terms of the root node which one do we rotate first well as low as possible because</p>



<p class="wp-block-paragraph">if we rotate the 30 it might end up fixing the 21 so we don&#8217;t want to do any more more work than we</p>



<p class="wp-block-paragraph">have to so I&#8217;m just going to maybe move this over here a little bit and select our xyz um hang on</p>



<p class="wp-block-paragraph">a second I think I just like didn&#8217;t do a snap to grid when I was doing that okay hang on</p>



<p class="wp-block-paragraph">doing that okay hang on okay so we got to choose our x y and z uh we&#8217;re going to say that the 30</p>



<p class="wp-block-paragraph">is z the lowest node possible that is out of whack and then we hop down to a child of z to find y</p>



<p class="wp-block-paragraph">we hop down to a child of y to find x and so now we have our xyz i&#8217;m just going to write them down</p>



<p class="wp-block-paragraph">I&#8217;m going to change the ink real fast and then we have to get ABC so A is the least value B is the</p>



<p class="wp-block-paragraph">one that belongs in the middle and C is 42 now we have our ABC we&#8217;re ready to draw our output pattern</p>



<p class="wp-block-paragraph">or target pattern so I&#8217;m just going to put like some nodes up here duplicate that a couple times</p>



<p class="wp-block-paragraph">all right not the prettiest but I&#8217;ll take it I&#8217;m gonna do my connecting lines</p>



<p class="wp-block-paragraph">and then I have to update the numbers so a is 30 and then b is 38 and c is 42 still so we&#8217;ll just</p>



<p class="wp-block-paragraph">leave that as is now we have to look for children of any of the output pattern nodes that are</p>



<p class="wp-block-paragraph">for so we&#8217;ll first look at the z node here the 30 it had a right child of 38 that&#8217;s already handled</p>



<p class="wp-block-paragraph">as the y node so we don&#8217;t need to worry about the 38 okay next we look at the uh y node it had a</p>



<p class="wp-block-paragraph">right child of 42 that&#8217;s also handled in the output pattern so we don&#8217;t have to worry about that uh</p>



<p class="wp-block-paragraph">then the 42 had no children so we don&#8217;t need to really do anything this is going to be super easy</p>



<p class="wp-block-paragraph">Just as a reminder, the Z could have had a left child, the Y could have had a left child,</p>



<p class="wp-block-paragraph">and the X could have had two children, at least in this particular pattern.</p>



<p class="wp-block-paragraph">Oh, I think in my previous video, I didn&#8217;t name off all the rotation types.</p>



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



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



<p class="wp-block-paragraph">So now I&#8217;m ready to just kind of like move this into the diagram.</p>



<p class="wp-block-paragraph">So the 30 and 38 and 42, we can just kind of get rid of that</p>



<p class="wp-block-paragraph">move the rotated output pattern into the diagram like this.</p>



<p class="wp-block-paragraph">We&#8217;ll make the 38 the right child of 21.</p>



<p class="wp-block-paragraph">I want to make it go a little bit more to the right</p>



<p class="wp-block-paragraph">so that we have a nicely drawn diagram</p>



<p class="wp-block-paragraph">so that all the nodes have space so it&#8217;s easy to debug visually.</p>



<p class="wp-block-paragraph">It&#8217;s easy to just kind of eyeball it.</p>



<p class="wp-block-paragraph">Then I&#8217;m going to update the balance factors.</p>



<p class="wp-block-paragraph">So the 42 has 0, the 30 has 0, the 38 has 0.</p>



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



<p class="wp-block-paragraph">The 21, hopefully that improved.</p>



<p class="wp-block-paragraph">The left subtree has a height of 1, the right subtree has a height of 2.</p>



<p class="wp-block-paragraph">of one the right subtree has a height of two so actually the balance factor of the 21 node improved</p>



<p class="wp-block-paragraph">to one we are now done uh rotating and we have a valid avl tree and uh we could have had you know</p>



<p class="wp-block-paragraph">a tree that was just totally linear all the way down to the right it could have worked out that</p>



<p class="wp-block-paragraph">way if we weren&#8217;t using avl trees uh and we would have had a really slow binary search tree but with</p>



<p class="wp-block-paragraph">avl trees this is like you know a lot a lot faster reasonably and you can imagine if i added some</p>



<p class="wp-block-paragraph">And you can imagine if I added some more data, let&#8217;s see, how long is this video?</p>



<p class="wp-block-paragraph">Oh, it&#8217;s this video.</p>



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



<p class="wp-block-paragraph">Let&#8217;s add one more piece of data just for fun, Zars.</p>



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



<p class="wp-block-paragraph">Anybody remember that old song, I Can&#8217;t Drive, 55?</p>



<p class="wp-block-paragraph">So we&#8217;re going to add the 55.</p>



<p class="wp-block-paragraph">I&#8217;m going to say, here it is.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to do just like a new node duplicate.</p>



<p class="wp-block-paragraph">node duplicate. I&#8217;m going to stick a 55 in there. And then where does the 55 belong? Well,</p>



<p class="wp-block-paragraph">it&#8217;s not going to go with the root node belongs on the right side. Not going to go there belongs</p>



<p class="wp-block-paragraph">on the right side, not going to go there belongs on the right side, we just end up going all the</p>



<p class="wp-block-paragraph">way to the right. Pretty much. Okay, so I&#8217;m going to say it belongs there. And I&#8217;m going to connect</p>



<p class="wp-block-paragraph">it. And then we update the balance factors. So zero here, and then the 42 becomes a one and the</p>



<p class="wp-block-paragraph">42 becomes a 1 and the 38 becomes a 1 and the 21 becomes a 1 on the left and 3 on the right</p>



<p class="wp-block-paragraph">which means we have a balance factor of 2 so now the 21 node is imbalanced this is no longer a</p>



<p class="wp-block-paragraph">valid abl tree we got to rotate to make it better so once again we look at the first node that&#8217;s out</p>



<p class="wp-block-paragraph">of whack or the lowest node that&#8217;s out of whack it&#8217;s going to be the 21 we call it our z and then</p>



<p class="wp-block-paragraph">we find a child of z with the tallest subtree so it you know is it going to be the 12 or the 38</p>



<p class="wp-block-paragraph">the 12 or the 38 it&#8217;s definitely going to be the 38 because 38 is the taller subtree same thing to</p>



<p class="wp-block-paragraph">find x it&#8217;s got to be a child of y should we go left or should we go right we have to go right</p>



<p class="wp-block-paragraph">because that&#8217;s the taller subtree so now we have our x y and z um i think i&#8217;ve been forgetting to</p>



<p class="wp-block-paragraph">is 38, Z is 21, X, Y, and Z, and then we do A and B and C. So A is the least value, 21, B is the one</p>



<p class="wp-block-paragraph">that belongs in the middle, C is the one that belongs on the right side. Now we&#8217;re ready to</p>



<p class="wp-block-paragraph">draw our target output pattern. So I&#8217;m going to do this, a little duplication.</p>



<p class="wp-block-paragraph">Do you like when I say, oh, we&#8217;re going to do this, we&#8217;re going to do this, we&#8217;re going to do this?</p>



<p class="wp-block-paragraph">Because sometimes I just go, I don&#8217;t like it.</p>



<p class="wp-block-paragraph">And I don&#8217;t think people like it when I say that.</p>



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



<p class="wp-block-paragraph">I&#8217;m going to connect these real fast and then change the numbers to match.</p>



<p class="wp-block-paragraph">I think I made that one.</p>



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



<p class="wp-block-paragraph">I can never tell if it&#8217;s perfectly symmetrical.</p>



<p class="wp-block-paragraph">I can&#8217;t do it.</p>



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



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



<p class="wp-block-paragraph">So A is going to be on the left.</p>



<p class="wp-block-paragraph">Alright, so A is going to be on the left, that&#8217;s 21.</p>



<p class="wp-block-paragraph">B is in the middle, that&#8217;s 38.</p>



<p class="wp-block-paragraph">C is on the right, that&#8217;s 42.</p>



<p class="wp-block-paragraph">Then we have to look for children of the output pattern that are unaccounted for.</p>



<p class="wp-block-paragraph">So we&#8217;re going to do, look at the Z node.</p>



<p class="wp-block-paragraph">The Z node had 12, which is unaccounted for as a left child.</p>



<p class="wp-block-paragraph">So I&#8217;m going to copy the 12 somewhere.</p>



<p class="wp-block-paragraph">We&#8217;ll deal with it in a second.</p>



<p class="wp-block-paragraph">Then we look for the right child of 21, that&#8217;s a 38.</p>



<p class="wp-block-paragraph">that&#8217;s a 38 that&#8217;s already in the output pattern so we don&#8217;t have to worry about that anymore</p>



<p class="wp-block-paragraph">and then we look at the y node so y had left child was 30 that&#8217;s not accounted for so i&#8217;m</p>



<p class="wp-block-paragraph">going to copy that put it somewhere else and then its right child was 42 that&#8217;s already</p>



<p class="wp-block-paragraph">handled in the output pattern so we&#8217;re done there i&#8217;m going to duplicate this and then we look at</p>



<p class="wp-block-paragraph">the uh we look at the x node the 42 it had a right child of 55 that also was not accounted for so i&#8217;m</p>



<p class="wp-block-paragraph">for so I&#8217;m gonna just copy it over here and we&#8217;ll do something with it okay we&#8217;re done looking for</p>



<p class="wp-block-paragraph">unaccounted for children again if you are just rearranging pointers you don&#8217;t really have to</p>



<p class="wp-block-paragraph">worry about this in your code but since we&#8217;re doing a diagram we have to double check that</p>



<p class="wp-block-paragraph">none of these nodes at the bottom here the unaccounted for children have children of their</p>



<p class="wp-block-paragraph">own if they did the children would have to come with them so 55 uh no children 12 no children 30</p>



<p class="wp-block-paragraph">So those are fine. If there were any children underneath, they would just stay on those nodes.</p>



<p class="wp-block-paragraph">So now we have to figure out who goes where. So the 12 is the least value. That means it&#8217;s going</p>



<p class="wp-block-paragraph">to go probably in the leftmost position compared to the other ones. But if we figure out like,</p>



<p class="wp-block-paragraph">where does this belong in the binary search tree? It belongs right here as the left child of 21.</p>



<p class="wp-block-paragraph">The 30 node, same thing. Where does it belong? It belongs between the 21 and 38. That&#8217;s the only</p>



<p class="wp-block-paragraph">And then the 55, it belongs on the right side of 42 for the same reason.</p>



<p class="wp-block-paragraph">Okay, I&#8217;m going to do my connecting lines real fast.</p>



<p class="wp-block-paragraph">If I don&#8217;t do my connecting lines, then I don&#8217;t like it.</p>



<p class="wp-block-paragraph">So now we have how many nodes in the output pattern?</p>



<p class="wp-block-paragraph">We have one, two, three, four, five, six.</p>



<p class="wp-block-paragraph">there&#8217;s also just six which means the final tree after rotation is just everything that we&#8217;ve</p>



<p class="wp-block-paragraph">written on the right side so i&#8217;m just going to erase all of this stuff get rid of that too</p>



<p class="wp-block-paragraph">and then move all these nodes over to the left call that the tree this is now the tree and then</p>



<p class="wp-block-paragraph">i just have to recompute the balance factors to make sure that everything is okay so the leaves</p>



<p class="wp-block-paragraph">0, 0, the 42 gets a 1, the 21 is perfectly balanced so that gets a 0.</p>



<p class="wp-block-paragraph">The 38 is also perfectly balanced.</p>



<p class="wp-block-paragraph">Again, it&#8217;s not about weight or mass even though there are more nodes on the left subtree,</p>



<p class="wp-block-paragraph">it&#8217;s all about the height.</p>



<p class="wp-block-paragraph">The height of the left subtree is 2, the height of the right subtree is 2, so 38 is actually</p>



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



<p class="wp-block-paragraph">Because there are no nodes that have a balance factor of 2 or worse, we are done rotating</p>



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



<p class="wp-block-paragraph">This is a valid AVL tree and it&#8217;s pretty fast.</p>



<p class="wp-block-paragraph">So I think that&#8217;s pretty much it.</p>



<p class="wp-block-paragraph">That&#8217;s all I wanted to go through today for this video.</p>



<p class="wp-block-paragraph">Thank you so much for following along.</p>



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



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



<p class="wp-block-paragraph">Have a great night and or day and or week and or weekend.</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">of my heart I really appreciate it I do hope you did learn something and have</p>



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



<p class="wp-block-paragraph">subscribe and follow this channel or these videos or whatever it is you do on</p>



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



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



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



<p class="wp-block-paragraph">do me a kindness and uh and subscribe 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 it just wakes me up and</p>



<p class="wp-block-paragraph">i get filled with joy that&#8217;s exactly what happens every single time so you could do it as a nice</p>



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



<p class="wp-block-paragraph">night just subscribe and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s what will happen also uh if</p>



<p class="wp-block-paragraph">you look at the middle of the screen right now you should see a qr code which you can scan</p>



<p class="wp-block-paragraph">to go to the website which i think is also named somewhere at the bottom of this video</p>



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



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



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



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



<p class="wp-block-paragraph">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 um enjoy the cool music as as i fade into the darkness which is</p>



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



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



<p class="wp-block-paragraph">It should all work out according to plan, trust me.</p>



<p class="wp-block-paragraph">Anyway, um, so…</p>
<p>The post <a href="https://www.NeuralLantern.com/avl-trees-adding-linear-data-and-performing-rotations/">AVL Trees: Adding Linear Data and Performing Rotations</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/avl-trees-adding-linear-data-and-performing-rotations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AVL Tree Tutorial: Balance Factors and Why They Fix Slow BSTs</title>
		<link>https://www.NeuralLantern.com/avl-tree-tutorial-balance-factors-and-why-they-fix-slow-bsts/</link>
					<comments>https://www.NeuralLantern.com/avl-tree-tutorial-balance-factors-and-why-they-fix-slow-bsts/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 18 May 2026 06:09:32 +0000</pubDate>
				<category><![CDATA[AVL Trees]]></category>
		<category><![CDATA[Binary Search Trees]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[AVL tree]]></category>
		<category><![CDATA[AVL tree rotation]]></category>
		<category><![CDATA[AVL trees]]></category>
		<category><![CDATA[balance factor]]></category>
		<category><![CDATA[balanced binary tree]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[bst]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[self balancing binary search tree]]></category>
		<category><![CDATA[tree rotation]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=371</guid>

					<description><![CDATA[<p>AVL trees are self-balancing binary search trees that prevent the tree from becoming unbalanced. We compute balance factors as the absolute value of left subtree height minus right subtree height. If any node has a balance factor of 2 or worse, we rebalance using rotations on trinode subtrees. This keeps search, insert, and other operations efficient at logarithmic time.</p>
<p>The post <a href="https://www.NeuralLantern.com/avl-tree-tutorial-balance-factors-and-why-they-fix-slow-bsts/">AVL Tree Tutorial: Balance Factors and Why They Fix Slow BSTs</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="AVL Tree Tutorial: Balance Factors and Why They Fix Slow BSTs" width="1380" height="776" src="https://www.youtube.com/embed/xfMFNMpGVz0?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 AVL trees in this beginner-friendly introduction. We cover balance factors, why regular BSTs get slow, and how AVL trees stay balanced with rotations. Great for coding interviews and data structure understanding.</p>



<p class="wp-block-paragraph">00:00 AVL Trees Introduction<br>00:00:28 Problems with Regular BSTs<br>00:00:56 AVL Tree Balance Rule<br>00:02:10 Balance Factor Explained<br>00:02:48 Computing Balance Factors<br>00:03:11 Example Tree Analysis<br>00:04:40 Imbalance at 65 Node<br>00:05:08 Invalid AVL Tree<br>00:06:18 Linear Tree Problem<br>00:06:50 Trinode Subtree<br>00:07:40 Selecting Z Y X Nodes<br>00:09:20 Rotation Overview<br>00:10:03 Next Videos Preview<br>00:11:09 Thank You and 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 the Blog: https://www.NeuralLantern.com</li>



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



<p class="wp-block-paragraph">Hello there. Let&#8217;s talk about a type of self-balancing binary search tree called an AVL tree.</p>



<p class="wp-block-paragraph">Okay, so by now I hope you&#8217;ve seen my other videos that I&#8217;ve posted</p>



<p class="wp-block-paragraph">previously where we talked about binary search trees, how to define them,</p>



<p class="wp-block-paragraph">terminology, how to know you&#8217;re actually looking at one, how to build them, insert,</p>



<p class="wp-block-paragraph">If you finish those videos already with me, then you know that binary search trees can actually get slow sometimes because if we have bad data, regular binary search trees don&#8217;t really know how to rearrange themselves.</p>



<p class="wp-block-paragraph">They just might become slow depending on how good or bad the data is.</p>



<p class="wp-block-paragraph">The data is totally random.</p>



<p class="wp-block-paragraph">Then on average, it&#8217;ll, you know, the trees will be log time, but that&#8217;s not always the case.</p>



<p class="wp-block-paragraph">Maybe sometimes you have bad data, sorted data, poison data, whatever kind of data.</p>



<p class="wp-block-paragraph">The secret to AVL trees is we&#8217;re going to start with the binary search tree.</p>



<p class="wp-block-paragraph">And so first it has to satisfy all the rules of the binary search tree.</p>



<p class="wp-block-paragraph">And then we add on another rule.</p>



<p class="wp-block-paragraph">The rule is going to be that we don&#8217;t have a valid AVL tree.</p>



<p class="wp-block-paragraph">If the balance factor for any of the nodes, we&#8217;ll talk about balance factors in a second.</p>



<p class="wp-block-paragraph">If the balance factor for any node is two or worse.</p>



<p class="wp-block-paragraph">Meaning if we think the tree is too imbalanced at any node, it&#8217;s not a valid AVL tree.</p>



<p class="wp-block-paragraph">and therefore we must rebalance the tree with something called a rotation.</p>



<p class="wp-block-paragraph">After we do enough rotations and we see that the tree is balanced again, then it&#8217;ll be valid.</p>



<p class="wp-block-paragraph">And so AVL trees sometimes are invalid in some intermediate state.</p>



<p class="wp-block-paragraph">Like if you have an AVL tree and you add some data into it,</p>



<p class="wp-block-paragraph">for a moment it might be an invalid AVL tree and then internally it&#8217;s sort of just like rotating itself and rebalancing itself.</p>



<p class="wp-block-paragraph">Then when the tree is done, you&#8217;ll have a valid AVL tree again, if that makes sense.</p>



<p class="wp-block-paragraph">AVL tree again if that makes sense. So suppose this tree here we can tell this is a valid binary</p>



<p class="wp-block-paragraph">search tree because it follows all the rules that we talked about before. So let&#8217;s start implementing</p>



<p class="wp-block-paragraph">the first rule of an AVL tree which is let&#8217;s compute the balance factors for every single node.</p>



<p class="wp-block-paragraph">How do we compute balance factors? The basic idea is I want to say BF for balance factor</p>



<p class="wp-block-paragraph">the left subtree height minus the right subtree height.</p>



<p class="wp-block-paragraph">If you don&#8217;t know what a subtree or height is,</p>



<p class="wp-block-paragraph">you should probably check out my other videos right now.</p>



<p class="wp-block-paragraph">But basically, we&#8217;re just going to take the absolute value</p>



<p class="wp-block-paragraph">just to get the difference in the height of the left</p>



<p class="wp-block-paragraph">and the height of the right.</p>



<p class="wp-block-paragraph">So if you know binary search trees already,</p>



<p class="wp-block-paragraph">then you know that the leaves, they don&#8217;t have any subtrees.</p>



<p class="wp-block-paragraph">So their balance factor is going to be pretty easy to compute.</p>



<p class="wp-block-paragraph">It&#8217;s just going to be a zero.</p>



<p class="wp-block-paragraph">I should also point out that some other tutorials out there use positive and negative numbers</p>



<p class="wp-block-paragraph">for the balance factor.</p>



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



<p class="wp-block-paragraph">I&#8217;m just going to use absolute values here because it&#8217;s a little bit more simple.</p>



<p class="wp-block-paragraph">So all the leaves get a balance factor of zero, which is fine.</p>



<p class="wp-block-paragraph">We&#8217;re looking to see if we can find a balance factor of two or worse to indicate to us that</p>



<p class="wp-block-paragraph">we have an invalid AVL tree.</p>



<p class="wp-block-paragraph">So far, so good.</p>



<p class="wp-block-paragraph">Let&#8217;s look at the 22 node.</p>



<p class="wp-block-paragraph">we&#8217;ll compute the height of the left subtree versus the height of the right subtree.</p>



<p class="wp-block-paragraph">So, you know, I&#8217;m going to highlight its left subtree.</p>



<p class="wp-block-paragraph">That&#8217;s just the 14 node that has a height of 1.</p>



<p class="wp-block-paragraph">And then its right subtree is just the 36 node that also has a height of 1,</p>



<p class="wp-block-paragraph">which means the balance factor for the 22 node is the absolute value of 1 minus 1 is 0.</p>



<p class="wp-block-paragraph">So actually the 22 node is perfectly balanced.</p>



<p class="wp-block-paragraph">If you think about it, that makes sense.</p>



<p class="wp-block-paragraph">Left and right subtrees have the same height.</p>



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



<p class="wp-block-paragraph">have the same height no problem so I&#8217;m going to move on let&#8217;s compute the balance factor for the</p>



<p class="wp-block-paragraph">48 node this is a little trickier notice how the right subtree has a height of one and there is no</p>



<p class="wp-block-paragraph">left subtree which means its height is zero so for the 48 node it&#8217;s actually going to be</p>



<p class="wp-block-paragraph">the absolute value of zero minus one or just one so we find our first node that&#8217;s a little bit out</p>



<p class="wp-block-paragraph">imbalance here but avl trees tolerate imbalances of one they don&#8217;t really care we sort of try to</p>



<p class="wp-block-paragraph">make a trade-off between constantly always rotating every single time anything happens</p>



<p class="wp-block-paragraph">which would perhaps burn a little too much cpu versus letting the tree just be imbalanced to a</p>



<p class="wp-block-paragraph">reasonable amount so we could still call this a log tree in the end so we consider this to be okay</p>



<p class="wp-block-paragraph">65 node and compute the balance factor so 65 node has no right subtree so the height is zero there</p>



<p class="wp-block-paragraph">and its left subtree is those two nodes on the left so that has a height of two which means the</p>



<p class="wp-block-paragraph">balance factor for the 65 node is going to be the absolute value of two minus zero is two at this</p>



<p class="wp-block-paragraph">point we are already certain that this is not a valid avl tree and it would need to be rebalanced</p>



<p class="wp-block-paragraph">you know, consider it a valid AVL tree in the future.</p>



<p class="wp-block-paragraph">So invalid AVL tree, still a valid binary search tree.</p>



<p class="wp-block-paragraph">Something has to be done.</p>



<p class="wp-block-paragraph">Normally what I would say is if you find some nodes</p>



<p class="wp-block-paragraph">way down lower in the tree that are imbalanced,</p>



<p class="wp-block-paragraph">then just go ahead and perform a rebalancing</p>



<p class="wp-block-paragraph">or a rotation immediately,</p>



<p class="wp-block-paragraph">because sometimes when you rotate lower in the tree,</p>



<p class="wp-block-paragraph">you&#8217;ll end up fixing nodes that are a little higher.</p>



<p class="wp-block-paragraph">But since we started with this tree</p>



<p class="wp-block-paragraph">and we&#8217;re not kind of, you know,</p>



<p class="wp-block-paragraph">building a tree step-by-step,</p>



<p class="wp-block-paragraph">I just want to compute the balance factor for all of the nodes at the same time.</p>



<p class="wp-block-paragraph">So we&#8217;ll do the same thing for the 41 node, the root node.</p>



<p class="wp-block-paragraph">Its left subtree has a height of two and its right subtree has a height of three.</p>



<p class="wp-block-paragraph">So its balance factor is the absolute value of two minus three is one.</p>



<p class="wp-block-paragraph">So actually the root node is okay.</p>



<p class="wp-block-paragraph">If it was only up to the root node, we would say this is a valid AVL tree</p>



<p class="wp-block-paragraph">and we don&#8217;t really need to do anything.</p>



<p class="wp-block-paragraph">need to do anything however we&#8217;ve already seen that the 65 node is invalid so again uh we we</p>



<p class="wp-block-paragraph">need to do something here&#8217;s another quick example before we move on to actually identifying which</p>



<p class="wp-block-paragraph">nodes to to modify and rotate just real fast i want to show you you know that a binary search</p>



<p class="wp-block-paragraph">tree could actually end up being a linear tree if you had really really really bad data the binary</p>



<p class="wp-block-paragraph">This is slow because this is a linear tree.</p>



<p class="wp-block-paragraph">The time complexity of searching through this tree is linear time.</p>



<p class="wp-block-paragraph">It scales linearly with the number of nodes in your data set.</p>



<p class="wp-block-paragraph">That&#8217;s really far away from log time, which is supposed to be lightning fast.</p>



<p class="wp-block-paragraph">So an AVL tree will fix this kind of bad data.</p>



<p class="wp-block-paragraph">Let&#8217;s take a step back here and focus your attention for a second on these three nodes.</p>



<p class="wp-block-paragraph">We noticed that there is one node that&#8217;s actually out of whack.</p>



<p class="wp-block-paragraph">It&#8217;s the 65 node, right?</p>



<p class="wp-block-paragraph">What we&#8217;re going to do is we&#8217;re going to find a trinode subtree that starts with the first node or the lowest node we can find that&#8217;s out of whack.</p>



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



<p class="wp-block-paragraph">And you can tell that if we just kind of go down a level and down another level to select the other two nodes,</p>



<p class="wp-block-paragraph">it&#8217;s just going to be this little, you know, subtree of three nodes or otherwise known as a trinode subtree.</p>



<p class="wp-block-paragraph">So here&#8217;s kind of a diagram for that.</p>



<p class="wp-block-paragraph">Whoops, forgot to delete that earlier.</p>



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



<p class="wp-block-paragraph">So this is the trinode subtree that we selected, right?</p>



<p class="wp-block-paragraph">So we&#8217;ve got the 65 and the 48 and the 55.</p>



<p class="wp-block-paragraph">How did we actually select this?</p>



<p class="wp-block-paragraph">So what you kind of want to do is the first node that is out of whack,</p>



<p class="wp-block-paragraph">you want to call that Z.</p>



<p class="wp-block-paragraph">So I&#8217;m going to write a Z here.</p>



<p class="wp-block-paragraph">What we&#8217;re looking for is a trinode subtree,</p>



<p class="wp-block-paragraph">which we&#8217;ll first call X and Y and Z.</p>



<p class="wp-block-paragraph">And then we&#8217;ll end up reordering the nodes</p>



<p class="wp-block-paragraph">and then rearranging all the pointers to the nodes</p>



<p class="wp-block-paragraph">so that the trinode subtree is a little bit more in balance.</p>



<p class="wp-block-paragraph">more in balance. So we see the Z node. We have to find the Y node next. To find the Y node,</p>



<p class="wp-block-paragraph">what&#8217;s going on with my computer? Oh, there we go. We have the Z node. To find the Y node,</p>



<p class="wp-block-paragraph">really, we&#8217;re just going to take the child of the 65 node that has the taller subtree. So</p>



<p class="wp-block-paragraph">there&#8217;s only one subtree, you know, on the left, there&#8217;s no subtree on the right of the 65 node.</p>



<p class="wp-block-paragraph">So the choice is obvious. But just so you know, if there was, you know, another, you know, child</p>



<p class="wp-block-paragraph">another you know child hanging off of the right for some reason we would still choose the number</p>



<p class="wp-block-paragraph">48 node as the y node because it has the taller subtree notice how the subtree on the left is two</p>



<p class="wp-block-paragraph">and the subtree on the right has a height of one so always take the taller subtree when you&#8217;re</p>



<p class="wp-block-paragraph">looking for uh y and then x so then we do the same thing we go down to the grandchild of the z node</p>



<p class="wp-block-paragraph">and if we had a choice to go left or right again we would always choose the taller subtree in this</p>



<p class="wp-block-paragraph">taller subtree in this case there&#8217;s only one choice so that x node is going to be the 55</p>



<p class="wp-block-paragraph">now in this next slide i&#8217;ve kind of redrawn this in a little bit different of a way</p>



<p class="wp-block-paragraph">notice the trinode subtree that we just selected here the 65 48 55 subtree it has a height of three</p>



<p class="wp-block-paragraph">i mean that should be obvious right it&#8217;s just got a height of three</p>



<p class="wp-block-paragraph">or height. Notice on the left, these are the same three nodes. Exactly. 48, 55, and 65. That&#8217;s the</p>



<p class="wp-block-paragraph">same three nodes that we originally had. But notice how the height is too. So the basic idea for ABL</p>



<p class="wp-block-paragraph">trees is, you know, compute the balance factors. And as soon as you identify a node that&#8217;s out of</p>



<p class="wp-block-paragraph">whack, you grab a tri-node sub-tree starting at the node that&#8217;s out of whack, the Z node.</p>



<p class="wp-block-paragraph">And then we&#8217;ll perform, quote unquote, a rotation where we just kind of smoosh it to be a little</p>



<p class="wp-block-paragraph">be a little bit more balanced and a little bit more a little bit shorter so the height goes from</p>



<p class="wp-block-paragraph">three to two once we do that the rest of the tree it&#8217;s going to get a little bit better you&#8217;ll notice</p>



<p class="wp-block-paragraph">that this will end up sometimes completely but sometimes partially fixing bad balance factors</p>



<p class="wp-block-paragraph">in the tree so um this is the end of the intro i only wanted to spend a little time just kind of</p>



<p class="wp-block-paragraph">like warming you up to the idea in the next videos uh we&#8217;re going to actually look at performing</p>



<p class="wp-block-paragraph">identifying the four different types of rotations that you could see and like how to do them.</p>



<p class="wp-block-paragraph">We&#8217;ll talk more about the idea that we&#8217;re really just rearranging pointers here.</p>



<p class="wp-block-paragraph">If you&#8217;re thinking about code, you&#8217;re thinking about, oh, I&#8217;ve got some pointers between these</p>



<p class="wp-block-paragraph">nodes. We&#8217;re not going to delete any nodes or add any nodes. We&#8217;re just going to like</p>



<p class="wp-block-paragraph">rearrange who is a parent of who, who is a child of who. And then eventually we&#8217;ll deal with some</p>



<p class="wp-block-paragraph">really bad trees and we&#8217;ll become experts at just like maintaining ABL trees.</p>



<p class="wp-block-paragraph">talk about ways to visualize the rotations, which makes it a little bit easier to remember these</p>



<p class="wp-block-paragraph">patterns and stuff. Okay, so thank you for watching this video. I hope you learned a little bit of</p>



<p class="wp-block-paragraph">stuff and had a little bit of fun. In the next one, we&#8217;re going to get started. We&#8217;re going to</p>



<p class="wp-block-paragraph">go deep. I&#8217;m going to get my gear. Sorry.</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">from the bottom of my heart. I really appreciate it. I do hope you did learn something and have</p>



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



<p class="wp-block-paragraph">follow 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? It would really mean the world to me and it&#8217;ll help make more</p>



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



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



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



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



<p class="wp-block-paragraph">in order to go to the website which i think is also named somewhere at the bottom of this video</p>



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



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



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



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



<p class="wp-block-paragraph">I also wake up for those in the middle of the night. I get I wake up in a cold sweat and I&#8217;m like</p>



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



<p class="wp-block-paragraph">so much for watching this video 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/avl-tree-tutorial-balance-factors-and-why-they-fix-slow-bsts/">AVL Tree Tutorial: Balance Factors and Why They Fix Slow BSTs</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/avl-tree-tutorial-balance-factors-and-why-they-fix-slow-bsts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Search in a Binary Search Tree (BST) &#8211; Step by Step Explanation with Examples</title>
		<link>https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/</link>
					<comments>https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 02 May 2026 23:54:59 +0000</pubDate>
				<category><![CDATA[Binary Search Trees]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[binary search tree tutorial]]></category>
		<category><![CDATA[binary tree search]]></category>
		<category><![CDATA[BST explained]]></category>
		<category><![CDATA[BST search]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[data structures and algorithms]]></category>
		<category><![CDATA[log n time]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[search in BST]]></category>
		<category><![CDATA[tree traversal]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=336</guid>

					<description><![CDATA[<p>Learn how to search in a Binary Search Tree. We demonstrate searching for existing and non-existing values, explain why BST search is O(log n) on average, and show how poor data ordering can turn your tree into a slow linear structure similar to a linked list. Includes discussion of tree height and balanced vs unbalanced BSTs.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/">How to Search in a Binary Search Tree (BST) &#8211; Step by Step Explanation with 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="How to Search in a Binary Search Tree (BST) - Step by Step Explanation with Examples" width="1380" height="776" src="https://www.youtube.com/embed/FCz9IbLywI4?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 we walk through how to perform searches in a Binary Search Tree. Starting with a perfectly balanced BST, we cover the search process step by step, including finding existing nodes like 73 and determining that numbers like 44 do not exist in the tree.</p>



<p class="wp-block-paragraph">We discuss time complexity for searches in BSTs &#8211; O(log n) on average for balanced trees and O(n) in the worst case when the tree becomes skewed like a linked list due to sorted or bad data. Learn why each comparison eliminates half the remaining data and how height affects performance.</p>



<p class="wp-block-paragraph">Perfect for students learning data structures and algorithms. If you&#8217;re studying BSTs, this clear explanation will help you understand searching, insertion paths, and why self-balancing trees matter.</p>



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



<p class="wp-block-paragraph">00:00 Introduction to BST Search<br>00:31 BST Not Self-Balancing<br>00:40 Average Case Log Time<br>00:53 Linear Time in Worst Case<br>01:13 How BST Search Works<br>01:18 Search Path Example<br>02:08 Searching for Existing Node<br>02:35 Searching for Non-Existent Node<br>03:19 Tree Size and Height<br>03:30 Time Complexity O(h)<br>05:40 Bad Data Example<br>08:23 Skewed Tree Like Linked List<br>09:53 Linear Time in Worst Case<br>11:58 Why Log Time<br>12:36 Halving the Search Space<br>14:14 O(log n) Summary<br>14:28 Conclusion</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 the Blog: https://www.NeuralLantern.com</li>



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



<p class="wp-block-paragraph">hey there let&#8217;s perform searches in a binary search tree</p>



<p class="wp-block-paragraph">okay if you watch my previous videos you know how to define a binary search tree by now</p>



<p class="wp-block-paragraph">you know some terminology you know how to construct a tree and so now let&#8217;s just take</p>



<p class="wp-block-paragraph">a tree that&#8217;s already been constructed and let&#8217;s search through it first thing i want to say is</p>



<p class="wp-block-paragraph">first thing I want to say is this is a binary search tree this is not a self</p>



<p class="wp-block-paragraph">balancing tree so in the future this tree could get lopsided and messed up</p>



<p class="wp-block-paragraph">depending on what kind of data we add we can always expect that binary search</p>



<p class="wp-block-paragraph">trees have a search time or an insert time or removal time of log log base 2</p>



<p class="wp-block-paragraph">of n on average assuming that the data is random or in the worst possible case</p>



<p class="wp-block-paragraph">scenario linear time so these could get slower right now you can see this tree</p>



<p class="wp-block-paragraph">Right now you can see this tree is perfectly balanced.</p>



<p class="wp-block-paragraph">So if we say that our tree is currently perfectly balanced and it&#8217;s always going to be perfectly balanced,</p>



<p class="wp-block-paragraph">which is a fantasy, but let&#8217;s just say that it is,</p>



<p class="wp-block-paragraph">then we could just say it&#8217;s a log tree.</p>



<p class="wp-block-paragraph">It&#8217;s going to take log time to search through.</p>



<p class="wp-block-paragraph">So how do we perform searches?</p>



<p class="wp-block-paragraph">Again, if you saw my previous videos, you should know that it&#8217;s really easy to find out where a node belongs.</p>



<p class="wp-block-paragraph">Like for example, if I was going to add the number 14,</p>



<p class="wp-block-paragraph">I would first look at the root node and I&#8217;d say, okay, the root node is occupied.</p>



<p class="wp-block-paragraph">and I&#8217;d say, okay, the root node is occupied.</p>



<p class="wp-block-paragraph">And so where would 14 belong?</p>



<p class="wp-block-paragraph">Well, it would belong on the left of 37</p>



<p class="wp-block-paragraph">because it&#8217;s less than 37.</p>



<p class="wp-block-paragraph">It would belong on the left of 16</p>



<p class="wp-block-paragraph">because it&#8217;s less than 16.</p>



<p class="wp-block-paragraph">It would belong on the right of 9</p>



<p class="wp-block-paragraph">because it&#8217;s greater than 9.</p>



<p class="wp-block-paragraph">It would belong on the right of 11</p>



<p class="wp-block-paragraph">because it&#8217;s greater than 11.</p>



<p class="wp-block-paragraph">And so the 14 node that we just wanted to add,</p>



<p class="wp-block-paragraph">is that what I just said, 14?</p>



<p class="wp-block-paragraph">Would end up going there.</p>



<p class="wp-block-paragraph">So when you&#8217;re searching through a binary search tree,</p>



<p class="wp-block-paragraph">you really just have to go find</p>



<p class="wp-block-paragraph">have to go find where the node would belong as if you&#8217;re performing insert or you could think of it</p>



<p class="wp-block-paragraph">the other way around like insert is really thinking of a search first but basically we&#8217;re just going</p>



<p class="wp-block-paragraph">to start by saying you know pick a number and we&#8217;ll see if it exists so uh let&#8217;s pick the number</p>



<p class="wp-block-paragraph">67 or actually let&#8217;s pick the number 73 just to see if it exists in the tree so 73 i&#8217;m going to</p>



<p class="wp-block-paragraph">do like you know seven three with like a question mark we check the root node 73 belongs on the</p>



<p class="wp-block-paragraph">side we look at the 59 it belongs on the right side and we found our 73 so 73 exists in the tree</p>



<p class="wp-block-paragraph">and it only took us three examinations only three examinations let&#8217;s look for a number that doesn&#8217;t</p>



<p class="wp-block-paragraph">actually exist in the tree so maybe oh my thing is freezing what&#8217;s going on okay so maybe uh let&#8217;s</p>



<p class="wp-block-paragraph">The 37 here, 44 belongs on the right of 37.</p>



<p class="wp-block-paragraph">We look at the 59, it belongs on the left.</p>



<p class="wp-block-paragraph">We look at the 48, it belongs on the left.</p>



<p class="wp-block-paragraph">We look at the 43, it belongs on the right.</p>



<p class="wp-block-paragraph">The 44 would have been there, but it&#8217;s not because that right child pointer off the 43</p>



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



<p class="wp-block-paragraph">So we only had to really examine one, two, three, four nodes in order to determine that</p>



<p class="wp-block-paragraph">our number 44 didn&#8217;t exist in the tree.</p>



<p class="wp-block-paragraph">Notice how we&#8217;re not doing a lot of examinations compared to the total size of the tree.</p>



<p class="wp-block-paragraph">compared to the total size of the tree.</p>



<p class="wp-block-paragraph">So let me just write this up here.</p>



<p class="wp-block-paragraph">How many nodes do we have?</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15.</p>



<p class="wp-block-paragraph">We got 15 nodes up here.</p>



<p class="wp-block-paragraph">Someone say N is equal to 15.</p>



<p class="wp-block-paragraph">And what&#8217;s the height of the tree?</p>



<p class="wp-block-paragraph">Remember, the height of the tree is the number of nodes you must touch</p>



<p class="wp-block-paragraph">as you make your way down towards the deepest node.</p>



<p class="wp-block-paragraph">Or if you&#8217;ve already found the deepest node,</p>



<p class="wp-block-paragraph">you take its depth and you just add 1, assuming that depths start at 0.</p>



<p class="wp-block-paragraph">start at zero. So I&#8217;ll just say that the depth of the root node is zero and the 59 and the 16 are</p>



<p class="wp-block-paragraph">one. And then that third row is two. And that last row is three. And then I just add one to the</p>



<p class="wp-block-paragraph">deepest node that I can find, which is just going to have a depth of three. All of these on the</p>



<p class="wp-block-paragraph">bottom row have a depth of three. So the height of this tree is actually four, because we would</p>



<p class="wp-block-paragraph">so like 37 59 48 43 that&#8217;s four touches um or the or the depth of the deepest node plus one okay um</p>



<p class="wp-block-paragraph">all trees all binary search trees whether they&#8217;re actually avl trees or regular binary search trees</p>



<p class="wp-block-paragraph">or whether they&#8217;re balanced or imbalanced they&#8217;re always going to have a time complexity to search</p>



<p class="wp-block-paragraph">through of o of h meaning in the worst case scenario you&#8217;ll have to touch h number of nodes</p>



<p class="wp-block-paragraph">order to find a node by search query or to add a new node or even to delete a new node.</p>



<p class="wp-block-paragraph">So how does that compare to this tree in reality?</p>



<p class="wp-block-paragraph">Let me just open up a little calculator real fast.</p>



<p class="wp-block-paragraph">I just want to show you.</p>



<p class="wp-block-paragraph">So if we do log base two, because we have a binary search tree, not a trinary search</p>



<p class="wp-block-paragraph">nodes 15 it tells us that it should take us no more than four examinations to find the node that</p>



<p class="wp-block-paragraph">we&#8217;re looking for if the tree was perfectly balanced and if you if you if you notice that&#8217;s</p>



<p class="wp-block-paragraph">exactly what the height is telling us here if the tree was more imbalanced the height would get</p>



<p class="wp-block-paragraph">really bad compared to the number of nodes and it would no longer be considered a log tree it would</p>



<p class="wp-block-paragraph">just be you know somewhere in between linear time and log time um let&#8217;s see what else can i show you</p>



<p class="wp-block-paragraph">let&#8217;s do well we did that computation let&#8217;s do a search through the tree that</p>



<p class="wp-block-paragraph">through a tree that&#8217;s actually really really bad let&#8217;s pretend that we have a</p>



<p class="wp-block-paragraph">bunch of nodes here and you know I&#8217;ve got an old story that I love to tell</p>



<p class="wp-block-paragraph">about this when like when my grandma was alive she was kind of bitter towards the</p>



<p class="wp-block-paragraph">end you know I loved her but she used to call the cops on her neighbors for</p>



<p class="wp-block-paragraph">gossip and at some point in time she got into a feud with her neighbor who was</p>



<p class="wp-block-paragraph">with her neighbor who was also a bitter old lady.</p>



<p class="wp-block-paragraph">You know, towards the end, it kind of happens sometimes.</p>



<p class="wp-block-paragraph">It sucks, but it happened.</p>



<p class="wp-block-paragraph">And I guess the neighbor didn&#8217;t like my grandma&#8217;s tree</p>



<p class="wp-block-paragraph">that she had in her backyard.</p>



<p class="wp-block-paragraph">So they fought over it, they argued over it,</p>



<p class="wp-block-paragraph">and then one day my grandma said</p>



<p class="wp-block-paragraph">she was looking out the backyard window</p>



<p class="wp-block-paragraph">to yell at ducks who were jumping into her pool</p>



<p class="wp-block-paragraph">because she just hated when the ducks went into her pool.</p>



<p class="wp-block-paragraph">She was waiting for them to show up.</p>



<p class="wp-block-paragraph">She wasn&#8217;t even looking at ducks.</p>



<p class="wp-block-paragraph">even looking at ducks she was just waiting and she saw the other little old lady reach her arm over</p>



<p class="wp-block-paragraph">the fence and spray my grandma&#8217;s tree with some sort of poison then my grandma&#8217;s tree died and uh</p>



<p class="wp-block-paragraph">i guess you know my grandma never never got over it i always thought it was like a funny story it</p>



<p class="wp-block-paragraph">was a little sad but um she poisoned my grandma&#8217;s tree so we can kind of do the same thing with the</p>



<p class="wp-block-paragraph">binary search tree we can give bad data let me show you what happens here if i use this data set</p>



<p class="wp-block-paragraph">search tree. So we&#8217;re going to add this node right here. It&#8217;s going to be the 14.</p>



<p class="wp-block-paragraph">And then when we add the 19 node, I&#8217;m just going to duplicate it. The 19 is supposed to be on the</p>



<p class="wp-block-paragraph">right side of 14 because it&#8217;s greater than 14. So I&#8217;m just going to like, you know, draw a 19 right</p>



<p class="wp-block-paragraph">here and a little connecting line. Okay. Then when we add the 24, I&#8217;m going to duplicate this node</p>



<p class="wp-block-paragraph">the 24 go belongs on the right side of the 14 and also belongs on the right side of the 19</p>



<p class="wp-block-paragraph">because it&#8217;s greater than 19 so again we have a node that shows up on the right side let me</p>



<p class="wp-block-paragraph">remember to actually fix the 19 so it looks like 24. then when we add the uh 29 it&#8217;s gonna end up</p>



<p class="wp-block-paragraph">being the same thing right the 29 is gonna end up showing on the right the right the right it&#8217;s</p>



<p class="wp-block-paragraph">If we have bad data, we can end up with a tree that kind of looks like a straight line.</p>



<p class="wp-block-paragraph">And if you are watching this video from the future,</p>



<p class="wp-block-paragraph">after I&#8217;ve posted all of my data structures videos that I have,</p>



<p class="wp-block-paragraph">you might notice that this looks like another data structure.</p>



<p class="wp-block-paragraph">If you&#8217;re watching this right away, I haven&#8217;t posted those videos just yet.</p>



<p class="wp-block-paragraph">But just tilt your head to the right a little bit</p>



<p class="wp-block-paragraph">and tell me if that looks like something that you recognize.</p>



<p class="wp-block-paragraph">It looks like a linked list.</p>



<p class="wp-block-paragraph">looks like a linked list just like a straight line or even i guess you could kind of say maybe an array</p>



<p class="wp-block-paragraph">um just like a straight line of data there&#8217;s no uh you know there&#8217;s no splitting of the data</p>



<p class="wp-block-paragraph">so we have the 29 and then the 35 and then uh maybe i&#8217;ll just do one more node only and i&#8217;ll</p>



<p class="wp-block-paragraph">get rid of that 54 because that&#8217;s too many nodes so what happens is if you have you know bad data</p>



<p class="wp-block-paragraph">tree doesn&#8217;t actually search or add insert or remove or anything like that in log time anymore</p>



<p class="wp-block-paragraph">instead it operates in linear time just like a linked list would meaning we would have to scan</p>



<p class="wp-block-paragraph">through every single node in the entire tree to be sure that some value did not exist well</p>



<p class="wp-block-paragraph">not exactly but in the worst case scenario we&#8217;d have to scan through the whole entire tree</p>



<p class="wp-block-paragraph">for example let&#8217;s just look at the the number of nodes real fast we&#8217;ll say the</p>



<p class="wp-block-paragraph">number of nodes here is one two three four oh I put two 24s in there oh dearie</p>



<p class="wp-block-paragraph">let me get that says 14 19 24 29 and then I guess I got to make that a 35 oh</p>



<p class="wp-block-paragraph">okay and then there&#8217;s a 49 I guess I did add every single node okay so we added</p>



<p class="wp-block-paragraph">so there&#8217;s like seven uh items in the tree so i&#8217;m going to say n is equal to seven the height also</p>



<p class="wp-block-paragraph">is seven though so the height is seven notice how if we say that it&#8217;s always true that a binary</p>



<p class="wp-block-paragraph">search tree has a time complexity in the worst case of o of h meaning you&#8217;d have to go down</p>



<p class="wp-block-paragraph">in the worst case the number of levels that is equal to the whole entire height of the entire</p>



<p class="wp-block-paragraph">tree that&#8217;s also the number of nodes in the tree which means uh if i wanted to add let&#8217;s say the</p>



<p class="wp-block-paragraph">I don&#8217;t know, if you wanted to add the number 60,</p>



<p class="wp-block-paragraph">60 would end up going down here.</p>



<p class="wp-block-paragraph">And in order to find where 60 would go,</p>



<p class="wp-block-paragraph">we&#8217;d have to look at the 14, that&#8217;s 1, 19, 24.</p>



<p class="wp-block-paragraph">We&#8217;d have to look at all these nodes.</p>



<p class="wp-block-paragraph">That is seven nodes.</p>



<p class="wp-block-paragraph">We&#8217;d have to examine seven nodes</p>



<p class="wp-block-paragraph">just to figure out where the 60 would go.</p>



<p class="wp-block-paragraph">Or if we were searching for 60,</p>



<p class="wp-block-paragraph">then we&#8217;d have to go down that far</p>



<p class="wp-block-paragraph">to find out that 60 didn&#8217;t exist.</p>



<p class="wp-block-paragraph">So this is nowhere near a log tree.</p>



<p class="wp-block-paragraph">This is a linear tree, a linear time tree.</p>



<p class="wp-block-paragraph">year time tree and just to drive the point further if we did log base two of the number of nodes in</p>



<p class="wp-block-paragraph">this case seven notice how it&#8217;s telling us that we should if it was a log tree if it was perfectly</p>



<p class="wp-block-paragraph">balanced or a self-balancing tree we should have to touch no more than three nodes in order to find</p>



<p class="wp-block-paragraph">what we&#8217;re looking for to search through the tree or to insert a new node or even to delete a node</p>



<p class="wp-block-paragraph">but that&#8217;s not the case here because the tree is really really slow compared to a perfectly balanced</p>



<p class="wp-block-paragraph">slow compared to a perfectly balanced tree.</p>



<p class="wp-block-paragraph">So we call this a linear tree.</p>



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



<p class="wp-block-paragraph">You want to try to avoid that.</p>



<p class="wp-block-paragraph">You don&#8217;t want your data to be poisoned.</p>



<p class="wp-block-paragraph">On average, your trees won&#8217;t really look like this if you just have totally</p>



<p class="wp-block-paragraph">random data, but if you think there&#8217;s a chance that your data might be skewed</p>



<p class="wp-block-paragraph">in some way, it&#8217;s probably a good idea to upgrade to a self-balancing tree,</p>



<p class="wp-block-paragraph">which we&#8217;re going to talk about later.</p>



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



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



<p class="wp-block-paragraph">So we talked about searching.</p>



<p class="wp-block-paragraph">why are these trees considered log time? I mean, they&#8217;re really, really fast, but why?</p>



<p class="wp-block-paragraph">Let&#8217;s just duplicate this slide here and I&#8217;ll move it down one level. I just want to kind of</p>



<p class="wp-block-paragraph">show you why this ends up being a log time tree. Okay. So why, why is this a log time tree?</p>



<p class="wp-block-paragraph">Suppose for the sake of argument, we&#8217;re searching for the number 52. So if we&#8217;re searching for the</p>



<p class="wp-block-paragraph">node the root node and decide where would the 52 belong let me actually write that down so i don&#8217;t</p>



<p class="wp-block-paragraph">forget 52 question mark where would the 52 belong it would belong on the right side of the 37 because</p>



<p class="wp-block-paragraph">it&#8217;s greater than 37 right which means it&#8217;s actually impossible that the 52 would be in any</p>



<p class="wp-block-paragraph">of these other nodes on the left side there&#8217;s no need to check them we&#8217;re not going to scan the</p>



<p class="wp-block-paragraph">whole tree we&#8217;re just going to go left or right and ignore the whole other side of the tree</p>



<p class="wp-block-paragraph">we just did is with one examination we eliminated half of the remaining data set or i guess of the</p>



<p class="wp-block-paragraph">initial data set if we&#8217;re looking at the root node so then the next thing that we do is we just kind</p>



<p class="wp-block-paragraph">of say okay it belongs on the right side so we look at the 59 node and we do the same thing we</p>



<p class="wp-block-paragraph">say where would 52 be would it be on the left side or the right side of the 59 node it would be on</p>



<p class="wp-block-paragraph">the left side which means we&#8217;re going to eliminate from consideration the entire right subtree of the</p>



<p class="wp-block-paragraph">So again, we&#8217;re eliminating half of the remaining data set.</p>



<p class="wp-block-paragraph">Then we kind of go down here and we look at the 48.</p>



<p class="wp-block-paragraph">We do the same thing.</p>



<p class="wp-block-paragraph">52 belongs on the right side.</p>



<p class="wp-block-paragraph">So we eliminate half of the remaining data set, you know, and then eventually we do find</p>



<p class="wp-block-paragraph">the 52 and then that&#8217;s it.</p>



<p class="wp-block-paragraph">So if we&#8217;re eliminating half of the data set with every single, just one examination at</p>



<p class="wp-block-paragraph">a time, that&#8217;s why it ends up being log base two.</p>



<p class="wp-block-paragraph">getting twice as close to your destination at every step you took if you&#8217;re like in a car like</p>



<p class="wp-block-paragraph">running maybe you&#8217;re on the moon or something then it would be a log time you know uh progress</p>



<p class="wp-block-paragraph">towards your goal or eliminating half of the data set at every single step sometimes people see</p>



<p class="wp-block-paragraph">for loops on exams and stuff when we talk about this um like for i equals zero uh i is less than</p>



<p class="wp-block-paragraph">it would be like i times equals two.</p>



<p class="wp-block-paragraph">So i&#8217;s jumping twice as far each time.</p>



<p class="wp-block-paragraph">That&#8217;s the sort of thing that makes it log.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to write down log here real fast</p>



<p class="wp-block-paragraph">to drive the point home a little bit more.</p>



<p class="wp-block-paragraph">O of log base two of n.</p>



<p class="wp-block-paragraph">Yeah, so I guess that&#8217;s all I wanted to tell you in this video.</p>



<p class="wp-block-paragraph">Hopefully you feel like an expert in searching now.</p>



<p class="wp-block-paragraph">If you want to see more searching videos,</p>



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



<p class="wp-block-paragraph">leave a comment or something like that. But yeah, thank you for watching. And I hope you</p>



<p class="wp-block-paragraph">learned a little bit of stuff and had a little bit of fun. I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">I&#8217;m going to go find a blueberry muffin.</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">subscribe 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 do me a kindness</p>



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



<p class="wp-block-paragraph">It just wakes me 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 to just wake me up in the middle</p>



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



<p class="wp-block-paragraph">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 main website where you can just kind of like</p>



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



<p class="wp-block-paragraph">So 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/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/">How to Search in a Binary Search Tree (BST) &#8211; Step by Step Explanation with Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-to-search-in-a-binary-search-tree-bst-step-by-step-explanation-with-examples/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 x86-64 Assembly: A Beginner&#8217;s Guide to CPU Registers</title>
		<link>https://www.NeuralLantern.com/mastering-x86-64-assembly-a-beginners-guide-to-cpu-registers/</link>
					<comments>https://www.NeuralLantern.com/mastering-x86-64-assembly-a-beginners-guide-to-cpu-registers/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 27 Jul 2025 00:12:09 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[ABI]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[callee saved registers]]></category>
		<category><![CDATA[coding optimization]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[CPU registers]]></category>
		<category><![CDATA[general purpose registers]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[RAX register]]></category>
		<category><![CDATA[RBX register]]></category>
		<category><![CDATA[stack pointer]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=190</guid>

					<description><![CDATA[<p>Learn x86-64 assembly with this beginner’s guide to CPU registers. Master RAX, RBX, ABI rules, and optimize code. Perfect for low-level programming enthusiasts.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-x86-64-assembly-a-beginners-guide-to-cpu-registers/">Mastering x86-64 Assembly: A Beginner&#8217;s Guide to CPU Registers</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 x86-64 Assembly: A Beginner&#039;s Guide to CPU Registers" width="1380" height="776" src="https://www.youtube.com/embed/jPysL_y4rRA?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">Ready to dive into x86-64 assembly? This beginner-friendly video breaks down CPU registers like RAX, RBX, and more in Yasm assembly. Learn how to use general-purpose registers, respect the ABI to avoid debugging nightmares, and optimize code by minimizing RAM hits. We’ll cover callee-saved registers, function arguments, and why you shouldn’t mess with the stack pointer. Perfect for coders looking to master low-level programming. Grab the free book mentioned and subscribe for more assembly tips! #AssemblyProgramming #x86</p>



<p class="wp-block-paragraph">Introduction to Registers 00:00:00<br>x86-64 Yasm Assembly 00:00:04<br>Recommended Book 00:00:09<br>Move Instruction Example 00:01:04<br>64-bit Registers Overview 00:01:52<br>General Purpose Registers 00:02:24<br>Two&#8217;s Complement for Integers 00:03:37<br>Floating Point Registers Introduction 00:03:54<br>ABI Importance 00:04:55<br>Function Return Values 00:08:01<br>C++ to Assembly Translation 00:08:43<br>Avoiding System RAM 00:11:45<br>Optimizing with Registers 00:13:04<br>Callee Saved Registers 00:14:16<br>Preserving Registers with Push/Pop 00:16:40<br>Stack and Local Variables 00:22:00<br>Function Arguments in Registers 00:25:12<br>Stack Pointer and Base Pointer 00:31:29<br>Instruction Pointer (RIP) 00:36:30<br>Temporary Registers (R10, R11) 00:36:49<br>Accessing 32-bit Register Portions 00:38:29<br>Floating Point Registers Details 00:42:53<br>Conclusion and Call to Subscribe 00:45:35</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">Let&#8217;s talk about registers in assembly.</p>



<p class="wp-block-paragraph">More specifically, x8664 Yasm assembly.</p>



<p class="wp-block-paragraph">Okay, so first off, check out this book.</p>



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



<p class="wp-block-paragraph">The author is a genius.</p>



<p class="wp-block-paragraph">It&#8217;s called x8664 assembly language programming with Ubuntu.</p>



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



<p class="wp-block-paragraph">website and you know grab your copy it&#8217;s wonderful it&#8217;s released under a copy left license</p>



<p class="wp-block-paragraph">author&#8217;s a genius whenever i&#8217;m trying to remember things about cpu registers for assembly</p>



<p class="wp-block-paragraph">i always go to this section i say callie saved i search for callie saved i already had it there</p>



<p class="wp-block-paragraph">callie saved and it ends up being section 12.8.2 register usage so before we do that let me just</p>



<p class="wp-block-paragraph">that let me just give you a little quick example so you kind of know what I&#8217;m</p>



<p class="wp-block-paragraph">talking about here hopefully everybody&#8217;s seen this instruction by now this is a</p>



<p class="wp-block-paragraph">move instruction in Yasm x86 64 assembly it just moves data from one place to</p>



<p class="wp-block-paragraph">another it takes two operands so you know we have like operand one and</p>



<p class="wp-block-paragraph">operand two basically operand one is the destination operand so we could put</p>



<p class="wp-block-paragraph">destination there if we wanted to operand two is the source we could put</p>



<p class="wp-block-paragraph">that actually won&#8217;t, you know, compile or assemble,</p>



<p class="wp-block-paragraph">but I&#8217;m just saying that&#8217;s what those positions are for.</p>



<p class="wp-block-paragraph">So here&#8217;s an example of a register receiving the value 10.</p>



<p class="wp-block-paragraph">We use the move instruction and we say,</p>



<p class="wp-block-paragraph">we would like to move something into the REX register.</p>



<p class="wp-block-paragraph">We would like to move the value 10 into the REX register.</p>



<p class="wp-block-paragraph">And there you have it. There&#8217;s a move instruction. Okay.</p>



<p class="wp-block-paragraph">So REX is a register.</p>



<p class="wp-block-paragraph">that it is a 64-bit register in our 64-bit CPUs every single register or</p>



<p class="wp-block-paragraph">sorry every single general purpose register and the plot registers they</p>



<p class="wp-block-paragraph">have 64 bits available for us to use 64 bits like you know ones and zeros it&#8217;s</p>



<p class="wp-block-paragraph">like a very very very big number a long time ago we had 32 bit registers and so</p>



<p class="wp-block-paragraph">these are like you know twice as mathematically robust or whatever you</p>



<p class="wp-block-paragraph">allows the registers to address, you know, the 64 bit memory addressing space,</p>



<p class="wp-block-paragraph">which helps us go beyond four gigabytes of RAM in our modern computers,</p>



<p class="wp-block-paragraph">helps us go far beyond what we can even achieve right now.</p>



<p class="wp-block-paragraph">So we have a register called RAX and there&#8217;s a list of other registers on this</p>



<p class="wp-block-paragraph">page here. So basically, you know,</p>



<p class="wp-block-paragraph">we have the RAX register and the RBX register and the RCX register and so</p>



<p class="wp-block-paragraph">forth. I have a hard time remembering all these names,</p>



<p class="wp-block-paragraph">remembering all these names so I go to this book when I forget but otherwise</p>



<p class="wp-block-paragraph">you know you can kind of think of like ABCD and then just surround them with</p>



<p class="wp-block-paragraph">RNX you know our kind of for register and X for extra big maybe so we&#8217;ve got</p>



<p class="wp-block-paragraph">the RAX RBX RCX and RDX registers and then we have a bunch of other ones</p>



<p class="wp-block-paragraph">through R15 but first before we do that let me just emphasize that these are</p>



<p class="wp-block-paragraph">general purpose registers to be used for integers or data you can put</p>



<p class="wp-block-paragraph">characters in there for strings you can put just like you know whatever data you</p>



<p class="wp-block-paragraph">want inside the machine we use twos complement to represent integers so it&#8217;s</p>



<p class="wp-block-paragraph">it&#8217;s fine the instructions that you will do for addition and other mathematical</p>



<p class="wp-block-paragraph">but don&#8217;t put floating point numbers in these registers because the computer the</p>



<p class="wp-block-paragraph">system the machine won&#8217;t know how to operate on that data the thing is</p>



<p class="wp-block-paragraph">integers are stored as twos complement I&#8217;m going to talk about that more in</p>



<p class="wp-block-paragraph">another video and floats are stored in something called I triple E seven five</p>



<p class="wp-block-paragraph">four standard which is just like a crazy different way of storing floating point</p>



<p class="wp-block-paragraph">numbers that makes more sense for floating point numbers but because the</p>



<p class="wp-block-paragraph">differently in the machine you can&#8217;t really use normal instructions like you</p>



<p class="wp-block-paragraph">can&#8217;t add two floats together the same with the same instruction that you would</p>



<p class="wp-block-paragraph">add two integers together you would have to use special floating point registers</p>



<p class="wp-block-paragraph">and special floating point instructions I&#8217;ll talk about floats at the end of</p>



<p class="wp-block-paragraph">this video I hope but basically just keep in mind these are general purpose</p>



<p class="wp-block-paragraph">registers to be used for integers in data only okay so what am I talking</p>



<p class="wp-block-paragraph">Okay, so what am I talking about?</p>



<p class="wp-block-paragraph">What are we seeing here on the side here?</p>



<p class="wp-block-paragraph">Why does it say return value?</p>



<p class="wp-block-paragraph">What is going on with Kali saved and fourth argument and third argument and so forth?</p>



<p class="wp-block-paragraph">So there&#8217;s a standard that you&#8217;re supposed to use when you program.</p>



<p class="wp-block-paragraph">You can get yourself into a lot of hot water or you can dramatically increase your debugging</p>



<p class="wp-block-paragraph">time if you don&#8217;t do this.</p>



<p class="wp-block-paragraph">standard called the ABI which I think is short for application binary interface but basically I just</p>



<p class="wp-block-paragraph">like to say the ABI respect the ABI there&#8217;s a plan that people came up with that says this is how you</p>



<p class="wp-block-paragraph">should use these registers don&#8217;t use them in a different way and that way if everybody is writing</p>



<p class="wp-block-paragraph">you know modules and they&#8217;re all going to interact together like I write a module you write a module</p>



<p class="wp-block-paragraph">the abi then it&#8217;s it&#8217;s pretty much guaranteed that we can we can expect certain things like</p>



<p class="wp-block-paragraph">our registers won&#8217;t become corrupted after a function call or that we&#8217;re not going to corrupt</p>



<p class="wp-block-paragraph">someone else&#8217;s uh function or you know whatever right so you can also use this to benefit yourself</p>



<p class="wp-block-paragraph">even if you&#8217;re the only person who is writing your code and you&#8217;re not calling on anyone else&#8217;s</p>



<p class="wp-block-paragraph">function um then you know like how are you going to remember like what was i using this register</p>



<p class="wp-block-paragraph">Was I supposed to save that one?</p>



<p class="wp-block-paragraph">Was I supposed to preserve it?</p>



<p class="wp-block-paragraph">How was I going to return data from that function?</p>



<p class="wp-block-paragraph">Was I going to use this register or the other register?</p>



<p class="wp-block-paragraph">It&#8217;s hard to remember what you,</p>



<p class="wp-block-paragraph">what you yourself even did like a month ago.</p>



<p class="wp-block-paragraph">So if you respect this plan,</p>



<p class="wp-block-paragraph">then your functions will work not only</p>



<p class="wp-block-paragraph">with other people&#8217;s functions,</p>



<p class="wp-block-paragraph">but with your own functions from a month ago.</p>



<p class="wp-block-paragraph">The other thing too, is we have system calls, right?</p>



<p class="wp-block-paragraph">So you have like a system call.</p>



<p class="wp-block-paragraph">Let&#8217;s say we want to move something into REX.</p>



<p class="wp-block-paragraph">something into REX, maybe I want to exit the system or something.</p>



<p class="wp-block-paragraph">Just forget about this.</p>



<p class="wp-block-paragraph">This is not a system call video.</p>



<p class="wp-block-paragraph">Suppose I want to do a system call, right?</p>



<p class="wp-block-paragraph">The system call itself is also going to respect the ABI.</p>



<p class="wp-block-paragraph">So if you start calling other</p>



<p class="wp-block-paragraph">services in the system call instruction, like if you want to open a file,</p>



<p class="wp-block-paragraph">close a file, read a file, write a file, whatever.</p>



<p class="wp-block-paragraph">If you don&#8217;t respect the ABI and the system call is respecting the ABI,</p>



<p class="wp-block-paragraph">might have some of your data corrupted so it&#8217;s a really really good idea to respect the abi</p>



<p class="wp-block-paragraph">in fact think about it this way what if uh what if you wrote a bunch of functions for a long long</p>



<p class="wp-block-paragraph">time and then like a year later you couldn&#8217;t you couldn&#8217;t remember what you were doing you know</p>



<p class="wp-block-paragraph">last year oh what was the return register uh and it costs you a bunch of extra time debugging</p>



<p class="wp-block-paragraph">eventually you&#8217;ll probably decide to write your write your own standard okay from now on i&#8217;m always</p>



<p class="wp-block-paragraph">going to use this register for return values and i&#8217;m going to use this register for the first</p>



<p class="wp-block-paragraph">and i&#8217;m going to use this register for the first argument and i&#8217;m going to write you probably</p>



<p class="wp-block-paragraph">come up with a plan right that&#8217;s basically the abi the abi covers more than just how to use</p>



<p class="wp-block-paragraph">registers but um register usage is covered in the abi so why would you put yourself through</p>



<p class="wp-block-paragraph">a bunch of heartache and then eventually come up with your own plan when you could have just</p>



<p class="wp-block-paragraph">been following the correct plan in the first place right so everybody should respect the abi</p>



<p class="wp-block-paragraph">I wanted to talk next about the return value.</p>



<p class="wp-block-paragraph">Okay, so let me write up a little function here.</p>



<p class="wp-block-paragraph">Let me just say that we have a C++ function.</p>



<p class="wp-block-paragraph">And we&#8217;ll just say it&#8217;s like void f.</p>



<p class="wp-block-paragraph">And we&#8217;ll say it calls on g.</p>



<p class="wp-block-paragraph">And then we&#8217;ll have another function called g.</p>



<p class="wp-block-paragraph">And actually, maybe it&#8217;s not void.</p>



<p class="wp-block-paragraph">Maybe it actually does return a long.</p>



<p class="wp-block-paragraph">returns the number five or something. Okay.</p>



<p class="wp-block-paragraph">Hopefully you&#8217;ve seen some kind of a higher level language before like C++</p>



<p class="wp-block-paragraph">so that you can understand what&#8217;s going on here.</p>



<p class="wp-block-paragraph">We&#8217;re just making two functions and one is calling the other.</p>



<p class="wp-block-paragraph">And the second one is just returning a value to the first one.</p>



<p class="wp-block-paragraph">So in assembly, the equivalent of this would be,</p>



<p class="wp-block-paragraph">let&#8217;s make a label with the name of the function and then a little colon,</p>



<p class="wp-block-paragraph">and then just put a return instruction at the end of it. Wham,</p>



<p class="wp-block-paragraph">it, wham, you&#8217;ve got a function. It&#8217;s not going to work very well, but you do have a function at</p>



<p class="wp-block-paragraph">this point. So F, uh, I&#8217;m going to try to copy the C++, uh, function. So it&#8217;s a really good idea.</p>



<p class="wp-block-paragraph">Whenever you&#8217;re writing a function in assembly, try to imagine what the prototype would be for</p>



<p class="wp-block-paragraph">C++ and just put it as a comment at the top. So I know how the F function is going to behave in</p>



<p class="wp-block-paragraph">my assembly module because I put a comment up there just kind of reminding me what the prototype</p>



<p class="wp-block-paragraph">for C++. It doesn&#8217;t really do anything. It just sort of runs. So that&#8217;s okay. And then I&#8217;ll make</p>



<p class="wp-block-paragraph">another function down here. I&#8217;ll do the long G again in a comment, and then I&#8217;ll do the actual</p>



<p class="wp-block-paragraph">assembly version. I&#8217;ll say G colon, and then I&#8217;ll return. So just by putting that comment up,</p>



<p class="wp-block-paragraph">I kind of can remind myself now that the G function is supposed to return some kind of a value.</p>



<p class="wp-block-paragraph">up here, you know, do how about let&#8217;s say, I don&#8217;t want to start adding a bunch of local</p>



<p class="wp-block-paragraph">variables right now.</p>



<p class="wp-block-paragraph">Pretend that we&#8217;re going to print the return value of the call to G somehow we&#8217;re going</p>



<p class="wp-block-paragraph">to use C out or whatever.</p>



<p class="wp-block-paragraph">We&#8217;re going to send it to a variable, whatever.</p>



<p class="wp-block-paragraph">I&#8217;m just going to try to keep the assembly as simple as possible.</p>



<p class="wp-block-paragraph">But anyway, the point is G returns something.</p>



<p class="wp-block-paragraph">you know, a value in your assembly function.</p>



<p class="wp-block-paragraph">Well, remember that higher level languages,</p>



<p class="wp-block-paragraph">part of why they&#8217;re so awesome</p>



<p class="wp-block-paragraph">is they do a lot of extra work for us under the hood</p>



<p class="wp-block-paragraph">and they actually provide illusions to us</p>



<p class="wp-block-paragraph">that make programming easier.</p>



<p class="wp-block-paragraph">For example, there are no functions</p>



<p class="wp-block-paragraph">going on inside the actual machine.</p>



<p class="wp-block-paragraph">I mean, I guess from a certain point of view there are,</p>



<p class="wp-block-paragraph">but basically the machine is just sort of like moving data</p>



<p class="wp-block-paragraph">and jumping to instructions</p>



<p class="wp-block-paragraph">and jumping back from somewhere.</p>



<p class="wp-block-paragraph">And, you know, it&#8217;s just sort of like jumping around</p>



<p class="wp-block-paragraph">and executing instructions.</p>



<p class="wp-block-paragraph">and executing instructions there&#8217;s no actual function it&#8217;s so it&#8217;s like if you want to pretend</p>



<p class="wp-block-paragraph">that you have a function in assembly well there is a return instruction that will help you jump</p>



<p class="wp-block-paragraph">back to wherever you came from most recently but we have to we have to implement more is what i&#8217;m</p>



<p class="wp-block-paragraph">saying so how do we return a value in an assembly function we just have to load up the return value</p>



<p class="wp-block-paragraph">it as return value that just means we have to load rax up with something so for example we wanted to</p>



<p class="wp-block-paragraph">return the number five so i&#8217;m just going to load it up with the number five and then return</p>



<p class="wp-block-paragraph">now we&#8217;ve pretty much translated a c plus plus function into uh an assembly function i mean</p>



<p class="wp-block-paragraph">that&#8217;s really what&#8217;s happening under the hood when you compile your c plus plus program</p>



<p class="wp-block-paragraph">it&#8217;s um it&#8217;s just you know translating all the c plus plus into assembly</p>



<p class="wp-block-paragraph">Another thing that I should probably point out is that you should use registers as often as possible</p>



<p class="wp-block-paragraph">and you should try your best not to touch memory.</p>



<p class="wp-block-paragraph">Of course at some point you have to touch memory when you want to save your final result or send</p>



<p class="wp-block-paragraph">it off somewhere or whatever but you know imagine that you have an assembly function and you&#8217;re</p>



<p class="wp-block-paragraph">doing lots and lots of calculations you&#8217;re performing an algorithm or something your</p>



<p class="wp-block-paragraph">program will be so much more efficient by like a factor of a hundred or probably more if you don&#8217;t</p>



<p class="wp-block-paragraph">if you don&#8217;t hit system ram because every time you hit system ram like a global variable or the</p>



<p class="wp-block-paragraph">stack or something then um your cpu you know typically in the uncashed uh scenario your cpu</p>



<p class="wp-block-paragraph">has to go talk to the system bus on your motherboard and then you know send a message</p>



<p class="wp-block-paragraph">to system ram and then wait for the system ram to figure out what it&#8217;s doing and then get a response</p>



<p class="wp-block-paragraph">back so when your program is executing on the cpu you can encounter a stall which is like your</p>



<p class="wp-block-paragraph">like a hundred clock cycles or more like it&#8217;s a long time at least in the most basic case</p>



<p class="wp-block-paragraph">and how do you avoid that just use registers only when you&#8217;re doing lots of calculations the</p>



<p class="wp-block-paragraph">registers are built into the cpu they&#8217;re part of the cpu&#8217;s hardware so they are lightning fast</p>



<p class="wp-block-paragraph">compared to system ram or your disk or whatever</p>



<p class="wp-block-paragraph">i probably say this a lot but you know part of the reason you would even want to code an assembly</p>



<p class="wp-block-paragraph">Maybe you have a big program that does a lot of stuff and eventually you profile the program</p>



<p class="wp-block-paragraph">and you realize, Hey, this one part of the program is really slow because it gets called</p>



<p class="wp-block-paragraph">constantly and it&#8217;s not super efficient.</p>



<p class="wp-block-paragraph">That might be a good use case for writing a hybrid program where you have multiple modules.</p>



<p class="wp-block-paragraph">Some of your modules are in a higher level language and some of your modules are in assembly.</p>



<p class="wp-block-paragraph">So you take your most important function that slows down your program that gets called all</p>



<p class="wp-block-paragraph">like a big loop or something and you rewrite it to assembly so that you can</p>



<p class="wp-block-paragraph">have more control over how often you touch system RAM to try to make the</p>



<p class="wp-block-paragraph">whole thing more efficient and you know reduce the number of instructions and</p>



<p class="wp-block-paragraph">just like whatever and you can improve the product of the efficiency of your</p>



<p class="wp-block-paragraph">program so anyway you want to try to avoid hitting system RAM your registers</p>



<p class="wp-block-paragraph">are built in the CPU there&#8217;s 64 bits that gives us 64 bits of address space</p>



<p class="wp-block-paragraph">can reach you know back in the day we had 32 bit systems that means you could only have a memory</p>



<p class="wp-block-paragraph">stick that was about four gigabytes so now we can go much further so um yeah that&#8217;s what&#8217;s going on</p>



<p class="wp-block-paragraph">with our registers on the cpu back to the return value okay so we have return value here goes into</p>



<p class="wp-block-paragraph">the rax register and then the next thing here is it&#8217;s saying that the rbx register is something</p>



<p class="wp-block-paragraph">remember we said that uh we have to respect the abi right like you have to respect this convention</p>



<p class="wp-block-paragraph">uh because if you don&#8217;t you&#8217;re going to cost yourself debug time and your</p>



<p class="wp-block-paragraph">functions probably won&#8217;t be interoperable interoperable with other people&#8217;s functions</p>



<p class="wp-block-paragraph">or the system call uh instruction well so one of the things about the abi is some of the registers</p>



<p class="wp-block-paragraph">are designated as the function that is being called has to be the thing that saves the register&#8217;s</p>



<p class="wp-block-paragraph">registers value so that it doesn&#8217;t corrupt for the caller. Imagine this if I had a function</p>



<p class="wp-block-paragraph">called f I&#8217;m going to do like f and g here suppose the function f is going to move something into</p>



<p class="wp-block-paragraph">let&#8217;s say r12 or actually let&#8217;s do rbx move the value 10 into rbx and then it&#8217;ll call g for some</p>



<p class="wp-block-paragraph">reason maybe g doesn&#8217;t take any arguments maybe g is just kind of doing stuff let&#8217;s just say that</p>



<p class="wp-block-paragraph">g just moves a different value into rbx so the thing is when the call comes back like after we</p>



<p class="wp-block-paragraph">get to this next line let&#8217;s say we&#8217;re going to do something with do something do something with</p>



<p class="wp-block-paragraph">rbx by the time we get to this line dude can i get the line numbers on this oh yeah i forgot okay</p>



<p class="wp-block-paragraph">so by the time we get to line seven uh the register rbx is ruined these registers are not</p>



<p class="wp-block-paragraph">local variables they&#8217;re not like uh you know tied to any scope or function call these registers are</p>



<p class="wp-block-paragraph">just basically global variables that are sitting on the cpu for lightning fast performance but that</p>



<p class="wp-block-paragraph">means the rbx i use inside of f is the same rbx i use inside of g so that means if g messes up the</p>



<p class="wp-block-paragraph">value of rbx and then if f calls g then f now has a bad value for rbx this is a broken program</p>



<p class="wp-block-paragraph">broken program because we did not respect the ABI.</p>



<p class="wp-block-paragraph">The ABI says that RBX is callee saved,</p>



<p class="wp-block-paragraph">which means if I use RBX in the G,</p>



<p class="wp-block-paragraph">then I have to preserve the value so that by the time I return,</p>



<p class="wp-block-paragraph">the value is the same as it was when the call first came in.</p>



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



<p class="wp-block-paragraph">We&#8217;ll do that with a push pop pair.</p>



<p class="wp-block-paragraph">I&#8217;ll probably make more videos in the future about pushing and popping,</p>



<p class="wp-block-paragraph">but I&#8217;m going to try to keep it simple for now.</p>



<p class="wp-block-paragraph">We just say, let&#8217;s push RBX onto the stack.</p>



<p class="wp-block-paragraph">at the beginning and then we&#8217;ll pop it off the stack at the very end.</p>



<p class="wp-block-paragraph">This basically means we&#8217;re going to take the value of RBX.</p>



<p class="wp-block-paragraph">We&#8217;re going to send it onto the stack.</p>



<p class="wp-block-paragraph">So, so yeah, we are hitting system RAM.</p>



<p class="wp-block-paragraph">It&#8217;s a little slower at that point.</p>



<p class="wp-block-paragraph">The ABI will save us a little time for the other registers.</p>



<p class="wp-block-paragraph">I&#8217;ll try to explain that in a second, but basically we&#8217;re preserving the value here</p>



<p class="wp-block-paragraph">with push and then we&#8217;re popping it back off.</p>



<p class="wp-block-paragraph">So we&#8217;re restoring it.</p>



<p class="wp-block-paragraph">So that means even though we ruined the value at line 14, when F does its line</p>



<p class="wp-block-paragraph">When F does its line 7, it&#8217;s going to have the correct value of RBX.</p>



<p class="wp-block-paragraph">It&#8217;s going to have the value 10.</p>



<p class="wp-block-paragraph">The book and I like to call this the prologue, just meaning this is a little section of code</p>



<p class="wp-block-paragraph">where we&#8217;re going to set things up.</p>



<p class="wp-block-paragraph">We&#8217;re going to start getting ready to do more instructions.</p>



<p class="wp-block-paragraph">And then this at the bottom is going to be called the epilogue.</p>



<p class="wp-block-paragraph">This is just like the finale.</p>



<p class="wp-block-paragraph">We&#8217;re like, we&#8217;re kind of cleaning up.</p>



<p class="wp-block-paragraph">We&#8217;re finishing up right before we return.</p>



<p class="wp-block-paragraph">If you wanted to return a value from G, then you could put, you know, the move inside of</p>



<p class="wp-block-paragraph">RAX somewhere else.</p>



<p class="wp-block-paragraph">Like you could put it like below the epilogue or just above the epilogue.</p>



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



<p class="wp-block-paragraph">As long as you&#8217;re sure that RAX is not getting trampled upon.</p>



<p class="wp-block-paragraph">So it&#8217;s important to note also that if I do a, let&#8217;s say a system call right after that,</p>



<p class="wp-block-paragraph">let&#8217;s say I call G and then I do a system call with, you know, like, you know, some</p>



<p class="wp-block-paragraph">you know some other number as the call code i want to open a file i want to close a file</p>



<p class="wp-block-paragraph">i want to read or write a file whatever i want to ask the system to do something for me the</p>



<p class="wp-block-paragraph">system is also going to respect the abi which means i&#8217;m guaranteed that rbx is not modified</p>



<p class="wp-block-paragraph">when the system call comes back if if the system call you know if the syscall instruction didn&#8217;t</p>



<p class="wp-block-paragraph">respect the abi then my rbx could be ruined i&#8217;d have to do a bunch of stuff to preserve it so this</p>



<p class="wp-block-paragraph">some of these registers let me go down a little bit here like this R10 the</p>



<p class="wp-block-paragraph">temporary register and also the RDI if you decided to use that in the body of</p>



<p class="wp-block-paragraph">your program which you&#8217;re allowed to these are not designated as callee saved</p>



<p class="wp-block-paragraph">which means system call could actually ruin the value of those registers so</p>



<p class="wp-block-paragraph">suppose for the sake of argument I really decided that I needed to use I</p>



<p class="wp-block-paragraph">10 because that&#8217;s marked as a temporary I&#8217;ll put a value in our 10 and then I&#8217;ll say you know</p>



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



<p class="wp-block-paragraph">With our 10 I&#8217;m sorry our 10</p>



<p class="wp-block-paragraph">Then that means by the time I&#8217;m done with my call to G</p>



<p class="wp-block-paragraph">I should assume that our 10 is ruined because even though you&#8217;re you can see right here that that G doesn&#8217;t actually do anything</p>



<p class="wp-block-paragraph">To our 10 we should assume that we have to respect the ABI which means the other function could have ruined it</p>



<p class="wp-block-paragraph">Ruined it. This is especially true if you call someone else&#8217;s module or system call or whatever same thing for the system call</p>



<p class="wp-block-paragraph">so if I call system call</p>



<p class="wp-block-paragraph">and I use</p>



<p class="wp-block-paragraph">R10 at some point before and then after then I have to assume R10 is destroyed by the time I get back in system call</p>



<p class="wp-block-paragraph">So that&#8217;s no good</p>



<p class="wp-block-paragraph">The cure to that when we&#8217;re talking about a temporary or something that is not designated as callee saved is that the caller has to save</p>



<p class="wp-block-paragraph">hit a system RAM just to make a call.</p>



<p class="wp-block-paragraph">Anything that we think we need when we&#8217;re finished.</p>



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



<p class="wp-block-paragraph">This is not the only way to do it, but I&#8217;m going to do a push R10 here.</p>



<p class="wp-block-paragraph">And then afterwards, I&#8217;m going to do pop R10.</p>



<p class="wp-block-paragraph">So that sucks.</p>



<p class="wp-block-paragraph">And then I have to do the same thing for the system call.</p>



<p class="wp-block-paragraph">I can go push R10 and then pop R10.</p>



<p class="wp-block-paragraph">And of course, if you were clever, you probably would, you know, put the call to G inside</p>



<p class="wp-block-paragraph">of that system call push pop pair.</p>



<p class="wp-block-paragraph">So you could have one less push pop pair.</p>



<p class="wp-block-paragraph">push pop pair but I&#8217;m just saying there&#8217;s no guarantee r10 is going to survive so you always</p>



<p class="wp-block-paragraph">have to preserve it if you ever want to use it again so this is like another way that the abi</p>



<p class="wp-block-paragraph">kind of can help you save time notice how here in the uh in the g function which I probably should</p>



<p class="wp-block-paragraph">have prototyped let me just say it looks like to me it&#8217;s a void and it doesn&#8217;t take any arguments</p>



<p class="wp-block-paragraph">to prototype your functions in comments.</p>



<p class="wp-block-paragraph">Maybe let me do the same thing to F up here.</p>



<p class="wp-block-paragraph">So F looks like it&#8217;s not returning anything and it&#8217;s not taking anything.</p>



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



<p class="wp-block-paragraph">Those are C++ comments that would not compile.</p>



<p class="wp-block-paragraph">All right. So notice how I&#8217;m using RBX.</p>



<p class="wp-block-paragraph">So I decided to preserve RBX, but there&#8217;s also other registers that are marked as</p>



<p class="wp-block-paragraph">marked as Kali saved like R12 through 15 and RBP and whatever,</p>



<p class="wp-block-paragraph">but I&#8217;m not preserving those.</p>



<p class="wp-block-paragraph">The reason I don&#8217;t have to preserve those is because I&#8217;m not using them.</p>



<p class="wp-block-paragraph">So the, uh, the, uh, the ABI can save you a little time here.</p>



<p class="wp-block-paragraph">Like for example, I&#8217;m preserving R10 because I&#8217;m supposed to assume that I,</p>



<p class="wp-block-paragraph">that I, that they could be destroyed by the time the function comes back.</p>



<p class="wp-block-paragraph">What if instead of using R10, I used R12.</p>



<p class="wp-block-paragraph">have to surround any calls with a push pop pair because I can trust that whoever is going to</p>



<p class="wp-block-paragraph">modify R12 will preserve it for me. But then notice down here G is not actually using R12.</p>



<p class="wp-block-paragraph">So G doesn&#8217;t even do push pop on R12. So we save hits to memory. We don&#8217;t even have to touch memory</p>



<p class="wp-block-paragraph">to preserve R12 because the ABI is helping us sort of stay a little bit more efficient.</p>



<p class="wp-block-paragraph">So this is great, right? F is a broken function at this point though, because I&#8217;m using</p>



<p class="wp-block-paragraph">at this point though because I&#8217;m using two registers that are callee saved I</p>



<p class="wp-block-paragraph">can&#8217;t assume that whoever called F is gonna know that I&#8217;m modifying RBX and</p>



<p class="wp-block-paragraph">R12 so I should do a prolog and an epilog up here I&#8217;m gonna say push RBX</p>



<p class="wp-block-paragraph">and then I&#8217;m gonna push R12 and then down here at the bottom I&#8217;m gonna do an</p>



<p class="wp-block-paragraph">epilog epilog and I&#8217;m gonna pop RBX and I&#8217;m gonna pop R12</p>



<p class="wp-block-paragraph">but I&#8217;ve done something wrong.</p>



<p class="wp-block-paragraph">The thing is, I&#8217;m not going to talk about the stack too much in this video,</p>



<p class="wp-block-paragraph">but the stack is a particular type of data structure</p>



<p class="wp-block-paragraph">that will return to you data in a reverse order than you sent into it.</p>



<p class="wp-block-paragraph">This is great for helping us keep track of function calls and return addresses,</p>



<p class="wp-block-paragraph">as I&#8217;ll probably try to explain in this video.</p>



<p class="wp-block-paragraph">But basically, the data comes out backwards.</p>



<p class="wp-block-paragraph">The data comes out backwards. So if I do it like this</p>



<p class="wp-block-paragraph">Then actually by the time the return statement instruction gets executed</p>



<p class="wp-block-paragraph">RBX will have the value that was intended for R12 and R12 will have the value that was intended for RBX</p>



<p class="wp-block-paragraph">It&#8217;ll be backwards. So you have to do your push pops in the reverse order to notice how</p>



<p class="wp-block-paragraph">It&#8217;s kind of like a shell that goes outwards. It&#8217;s like R12 is first on the inside and then RBX is next on the outside</p>



<p class="wp-block-paragraph">That&#8217;s just what you have to do to preserve everything.</p>



<p class="wp-block-paragraph">So the F function works now.</p>



<p class="wp-block-paragraph">The G function, I think it works now.</p>



<p class="wp-block-paragraph">We have a prologue and epilogue.</p>



<p class="wp-block-paragraph">Okay, so we talked about the ABI.</p>



<p class="wp-block-paragraph">We talked about calls.</p>



<p class="wp-block-paragraph">We talked about the registers.</p>



<p class="wp-block-paragraph">Talked about callee saved.</p>



<p class="wp-block-paragraph">We talked about the fact that we don&#8217;t have to save the other ones.</p>



<p class="wp-block-paragraph">I think I can talk about…</p>



<p class="wp-block-paragraph">um so uh one thing that i should make sure to mention is that these are general purpose registers</p>



<p class="wp-block-paragraph">they&#8217;re to be used for integers integer data or like characters or just like regular data</p>



<p class="wp-block-paragraph">they use certain instructions that are not to be used with floating point data so you actually</p>



<p class="wp-block-paragraph">should not store floating point numbers inside of your general purpose registers you should only</p>



<p class="wp-block-paragraph">store floating points in special registers which i&#8217;ll talk about at the end of this video</p>



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



<p class="wp-block-paragraph">Floating point numbers are stored differently in the system.</p>



<p class="wp-block-paragraph">They&#8217;re stored with a scheme called IEEE 754 floating point.</p>



<p class="wp-block-paragraph">So like the numbers wouldn&#8217;t make sense.</p>



<p class="wp-block-paragraph">Integers and floats are stored differently.</p>



<p class="wp-block-paragraph">So the hardware is wired differently to operate on two different types of data.</p>



<p class="wp-block-paragraph">So anyway, I just want to say that this is only for integers and general purpose data.</p>



<p class="wp-block-paragraph">So now let&#8217;s look at the other types of registers.</p>



<p class="wp-block-paragraph">rc x and rd x and rsi and rdi are designated as arguments first second third and fourth</p>



<p class="wp-block-paragraph">okay so let me uh let me write like a quick c plus function here and this is going to be uh let&#8217;s</p>



<p class="wp-block-paragraph">say we have like a function that returns some value we&#8217;ll call it uh we&#8217;ll call it f and we&#8217;ll</p>



<p class="wp-block-paragraph">say that f takes in some arguments let&#8217;s say that it takes in three arguments um again uh</p>



<p class="wp-block-paragraph">integers right now because we&#8217;re only using integer registers.</p>



<p class="wp-block-paragraph">We can&#8217;t use floating point arguments or return values.</p>



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



<p class="wp-block-paragraph">So I&#8217;m just going to do like three arguments long A and B and C.</p>



<p class="wp-block-paragraph">OK, so we can take in three arguments and maybe we&#8217;re just going to return,</p>



<p class="wp-block-paragraph">you know, a plus B plus C.</p>



<p class="wp-block-paragraph">OK, simple C++ function.</p>



<p class="wp-block-paragraph">Let&#8217;s do this in assembly.</p>



<p class="wp-block-paragraph">We&#8217;ll make a label and we&#8217;ll do a little comment that just reminds us.</p>



<p class="wp-block-paragraph">of sorry of the</p>



<p class="wp-block-paragraph">Function that we&#8217;re trying to implement we stick a little return instruction at the end of it so that</p>



<p class="wp-block-paragraph">it will jump back to the caller and</p>



<p class="wp-block-paragraph">then we&#8217;ll say</p>



<p class="wp-block-paragraph">Well when the caller of this function</p>



<p class="wp-block-paragraph">Called us and gave us a and B and C. How do we get a and B and C?</p>



<p class="wp-block-paragraph">Well a is the first integer argument, so it&#8217;s just going to be the RDI register</p>



<p class="wp-block-paragraph">So we&#8217;ll literally just use a move instruction</p>



<p class="wp-block-paragraph">just use a move instruction.</p>



<p class="wp-block-paragraph">Let&#8217;s say we want to, for whatever reason, use the R12 register</p>



<p class="wp-block-paragraph">and we&#8217;ll do something with it later.</p>



<p class="wp-block-paragraph">We&#8217;ll print it, we&#8217;ll save it, we&#8217;ll do whatever.</p>



<p class="wp-block-paragraph">Let&#8217;s just grab the incoming argument.</p>



<p class="wp-block-paragraph">So we&#8217;ll just grab RDI.</p>



<p class="wp-block-paragraph">So I&#8217;m going to put a little comment up above here, you know, grab</p>



<p class="wp-block-paragraph">a and do something</p>



<p class="wp-block-paragraph">with it and I&#8217;ll just write down here more instructions just to just to denote</p>



<p class="wp-block-paragraph">Just to denote that we&#8217;re doing something with the a value, but I&#8217;m not going to write it down here because I don&#8217;t want this to get huge.</p>



<p class="wp-block-paragraph">So we&#8217;ll do the same thing with the b.</p>



<p class="wp-block-paragraph">Maybe I should remember that programming is case sensitive.</p>



<p class="wp-block-paragraph">We&#8217;ll do something with the b.</p>



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



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



<p class="wp-block-paragraph">So that&#8217;s actually RSI.</p>



<p class="wp-block-paragraph">And then we&#8217;ll do something else.</p>



<p class="wp-block-paragraph">We could have used R13 or other registers if we wanted to.</p>



<p class="wp-block-paragraph">I&#8217;m just showing you how to grab incoming arguments.</p>



<p class="wp-block-paragraph">So then we&#8217;ll grab the c and do something with it also.</p>



<p class="wp-block-paragraph">C and do something with it also it&#8217;s not going to be RDI it&#8217;s going to be RDX and you can do this</p>



<p class="wp-block-paragraph">up to like I think six arguments let me just double check here yeah so like R9 ends up being</p>



<p class="wp-block-paragraph">the sixth argument and if you want more than that then the caller will have to put stuff on the stack</p>



<p class="wp-block-paragraph">and in fact if you if you kind of like understand what&#8217;s happening here let me just do like a main</p>



<p class="wp-block-paragraph">Let&#8217;s say we do cout whatever f returns.</p>



<p class="wp-block-paragraph">You know, this is like a typical function call, right?</p>



<p class="wp-block-paragraph">So we&#8217;ll call f.</p>



<p class="wp-block-paragraph">f will jump in there.</p>



<p class="wp-block-paragraph">It&#8217;ll jump into its body.</p>



<p class="wp-block-paragraph">It&#8217;ll do some sort of a manipulation with the incoming arguments.</p>



<p class="wp-block-paragraph">It&#8217;ll return a final value.</p>



<p class="wp-block-paragraph">Then that final value gets printed out.</p>



<p class="wp-block-paragraph">So what&#8217;s 5 plus 6 plus 7?</p>



<p class="wp-block-paragraph">That&#8217;s 11 plus 7.</p>



<p class="wp-block-paragraph">What is that, like 18?</p>



<p class="wp-block-paragraph">I&#8217;m bad at math.</p>



<p class="wp-block-paragraph">So let&#8217;s just say that&#8217;s 18 gets printed.</p>



<p class="wp-block-paragraph">So what happens is, um, we return, Oh, I forgot to return.</p>



<p class="wp-block-paragraph">I&#8217;m going to say compute the, uh,</p>



<p class="wp-block-paragraph">compute the sum of the things.</p>



<p class="wp-block-paragraph">Uh, and I&#8217;ll just say like block cause I don&#8217;t want to put a bunch of addition</p>



<p class="wp-block-paragraph">instructions here. Uh, and we&#8217;ll just like store in, uh,</p>



<p class="wp-block-paragraph">in R13, let&#8217;s say. So then when we have finally computed our result, I&#8217;ll just move R13 into the</p>



<p class="wp-block-paragraph">return value. And what I&#8217;m really trying to say here is if you imagine a function that behaves</p>



<p class="wp-block-paragraph">this way in C++, then what I&#8217;ve written down below is really what&#8217;s actually happening in</p>



<p class="wp-block-paragraph">assembly. Your compiler compiles the code down to assembly language first, and then it assembles it</p>



<p class="wp-block-paragraph">down to machine code. So really this is what&#8217;s happening under the hood. It&#8217;s not like a special</p>



<p class="wp-block-paragraph">under the hood it&#8217;s not like a special trick when you call a function in C++</p>



<p class="wp-block-paragraph">literally the A B and C have been loaded up just before the the jump</p>



<p class="wp-block-paragraph">instruction to go to that you know line 9 they&#8217;ve been loaded up with the</p>



<p class="wp-block-paragraph">appropriate values so that&#8217;s part of like you know the magic of what higher</p>



<p class="wp-block-paragraph">level languages give us it&#8217;s just makes things a little bit easier okay so I&#8217;ve</p>



<p class="wp-block-paragraph">If I had only used RDI and RSI and RDX, those are not designated as callee saved.</p>



<p class="wp-block-paragraph">So I wouldn&#8217;t have had to preserve those, but because I chose to use R12 and R13, I</p>



<p class="wp-block-paragraph">have to preserve those for the caller, even if the caller is not going to use them.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do, I&#8217;m going to do push R12 and I&#8217;m going to do push R13.</p>



<p class="wp-block-paragraph">And then at the bottom, let me do like a prologue here.</p>



<p class="wp-block-paragraph">is kind of helpful because it kind of helps you remember like, oh, did I forget the prologue?</p>



<p class="wp-block-paragraph">Did I forget the epilogue? They got a match. And then I guess the fact that you can see the words</p>



<p class="wp-block-paragraph">prologue and epilogue also helps remind you that everything is supposed to be in reverse order</p>



<p class="wp-block-paragraph">in the epilogue. So again, notice how R13 is on the inside and R12 is on the outside</p>



<p class="wp-block-paragraph">of the push pop pair. So now my program is good. And we&#8217;ve, you know, successfully translated</p>



<p class="wp-block-paragraph">We&#8217;ve, you know, successfully translated a nice function call there.</p>



<p class="wp-block-paragraph">And we&#8217;ve done a bunch of nonsense in the middle that I&#8217;m not writing down at this point.</p>



<p class="wp-block-paragraph">We are respecting the ABI.</p>



<p class="wp-block-paragraph">So if somebody else uses our function in their module, then they can be pretty confident</p>



<p class="wp-block-paragraph">that we&#8217;re not going to ruin their registers and so forth.</p>



<p class="wp-block-paragraph">We talked about the return value.</p>



<p class="wp-block-paragraph">We talked about that these general purpose registers are not for floats.</p>



<p class="wp-block-paragraph">We talked about pushes and pops.</p>



<p class="wp-block-paragraph">and pops. We&#8217;ve talked about function arguments,</p>



<p class="wp-block-paragraph">which right now we can only do integer arguments and return values.</p>



<p class="wp-block-paragraph">We&#8217;ve talked about, uh, well, he talked about the stack a little bit.</p>



<p class="wp-block-paragraph">So let me, let me just point out that, um,</p>



<p class="wp-block-paragraph">suppose you have a function. I just want to mention this briefly.</p>



<p class="wp-block-paragraph">Suppose you have a function F let&#8217;s say it&#8217;s, it&#8217;s void.</p>



<p class="wp-block-paragraph">So it doesn&#8217;t return anything and it has an integer a equals five.</p>



<p class="wp-block-paragraph">I think the reason that I wanted to do this is to show you how dangerous it is to mess</p>



<p class="wp-block-paragraph">with the wrong register like the stack register.</p>



<p class="wp-block-paragraph">So suppose we have two variables and then we&#8217;ll do something with a and b.</p>



<p class="wp-block-paragraph">So now suppose we have two threads.</p>



<p class="wp-block-paragraph">We have an execution thread one and an execution thread two.</p>



<p class="wp-block-paragraph">If you&#8217;re not familiar with threads, that just basically means your computer is literally</p>



<p class="wp-block-paragraph">executing your function or sorry, it&#8217;s executing twice at the exact same time.</p>



<p class="wp-block-paragraph">Maybe not the exact same time if you only have a single core on your CPU, but you could</p>



<p class="wp-block-paragraph">imagine that that&#8217;s possible, especially if you have many cores, that&#8217;s an operating systems</p>



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



<p class="wp-block-paragraph">But basically pretend that we have an execution thread.</p>



<p class="wp-block-paragraph">So it&#8217;s like going through your program, executing one instruction at a time.</p>



<p class="wp-block-paragraph">Then you launch another execution thread that also executes your program one instruction</p>



<p class="wp-block-paragraph">at a time.</p>



<p class="wp-block-paragraph">at a time so at some point it&#8217;s possible that um thread one and thread two could be executing f</p>



<p class="wp-block-paragraph">at the exact same time right so i&#8217;m not going to talk too much about this because this is not an</p>



<p class="wp-block-paragraph">os video but basically this could create a race condition where thread one and thread two kind</p>



<p class="wp-block-paragraph">of step on each other&#8217;s toes and they both try to modify the value of a uh at the wrong time and</p>



<p class="wp-block-paragraph">because the other thread modified it.</p>



<p class="wp-block-paragraph">So this is why local variables in a function actually live on the stack.</p>



<p class="wp-block-paragraph">A and B are not global variables.</p>



<p class="wp-block-paragraph">They&#8217;re actually temporary local variables that are sitting on the stack.</p>



<p class="wp-block-paragraph">And the way the stack works, I&#8217;m not going to talk about it too much in this video,</p>



<p class="wp-block-paragraph">is that, well, every function kind of has its own area of the stack.</p>



<p class="wp-block-paragraph">So when the function comes in, on the stack sits the return address</p>



<p class="wp-block-paragraph">return address so that the function knows where to jump back to when it returns and any local</p>



<p class="wp-block-paragraph">variable that the function makes. So if you think about it, when thread one calls F, we actually</p>



<p class="wp-block-paragraph">end up with a different version of A and a different version of B. We could imagine them</p>



<p class="wp-block-paragraph">as being, you know, A sub one and B sub one. But when thread two comes in and, you know,</p>



<p class="wp-block-paragraph">creates those local variables, we can imagine that we get two different versions of A and B also.</p>



<p class="wp-block-paragraph">of a and b also so this is how the computer prevents multiple threads from stepping on each</p>



<p class="wp-block-paragraph">other&#8217;s toes if you&#8217;re using local variables local variables are just local to the function</p>



<p class="wp-block-paragraph">this also helps if a function calls itself a bunch of times maybe one call or another might want to</p>



<p class="wp-block-paragraph">see a different version of a or b and it would be just incredibly difficult to keep track of that</p>



<p class="wp-block-paragraph">if you were using globals but when you use locals well they&#8217;re just basically different variables</p>



<p class="wp-block-paragraph">trying to lead up to is the stack is pretty important if you corrupt the</p>



<p class="wp-block-paragraph">stack then you probably are going to crash the entire program you might make</p>



<p class="wp-block-paragraph">it so that a function doesn&#8217;t know where to return from like when you do the</p>



<p class="wp-block-paragraph">return statement it might jump to some other part of the code that doesn&#8217;t even</p>



<p class="wp-block-paragraph">make sense and then everything crashes or you might mess up some data in a local</p>



<p class="wp-block-paragraph">variable like if you mess up if you mess up the stack you might be messing up the</p>



<p class="wp-block-paragraph">that the caller is depending on and so then the caller continues to execute and</p>



<p class="wp-block-paragraph">it sees the wrong value and it just crashes or you might even mess up your</p>



<p class="wp-block-paragraph">own local variables so don&#8217;t miss with the stack the reason I&#8217;m saying that now</p>



<p class="wp-block-paragraph">is because this very this register right here the RBP sorry that&#8217;s not it the</p>



<p class="wp-block-paragraph">RSP register that&#8217;s the stack pointer eventually you can learn how to</p>



<p class="wp-block-paragraph">manipulate the stack pointer in order to create your own local variables that&#8217;s</p>



<p class="wp-block-paragraph">variables that&#8217;s okay once you know what you&#8217;re doing but unless you know exactly what you&#8217;re</p>



<p class="wp-block-paragraph">doing you probably shouldn&#8217;t touch the stack pointer especially you shouldn&#8217;t mess with it</p>



<p class="wp-block-paragraph">right before you call a function or right before you return from your own function be very careful</p>



<p class="wp-block-paragraph">with that the rbp uh register is similarly dangerous uh it won&#8217;t like automatically destroy</p>



<p class="wp-block-paragraph">your program but it is uh it&#8217;s usually i mean it&#8217;s quite often used as sort of like a bookmark for</p>



<p class="wp-block-paragraph">mark for where the stack pointer was pointing in other modules and other</p>



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



<p class="wp-block-paragraph">So if you fail to preserve the base pointer,</p>



<p class="wp-block-paragraph">the RBP and then you returned from your function,</p>



<p class="wp-block-paragraph">then you might have actually messed up the stack pointer for the caller or some</p>



<p class="wp-block-paragraph">other caller somewhere in like the ancestry of your call graph.</p>



<p class="wp-block-paragraph">So be very careful. I mean,</p>



<p class="wp-block-paragraph">I guess all callee preserved variables or registers you should be very careful,</p>



<p class="wp-block-paragraph">careful about, but these are like kind of the two worst ones to forget about.</p>



<p class="wp-block-paragraph">first ones to forget about.</p>



<p class="wp-block-paragraph">There&#8217;s also another register that is not listed on this page called the</p>



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



<p class="wp-block-paragraph">It basically is a register that holds</p>



<p class="wp-block-paragraph">the memory location of the next instruction to be executed.</p>



<p class="wp-block-paragraph">So if you modify that, then you just told your program to go execute</p>



<p class="wp-block-paragraph">in some random crazy place and probably everything is going to crash.</p>



<p class="wp-block-paragraph">R10 and R11.</p>



<p class="wp-block-paragraph">I can&#8217;t remember already if I explain this, but I&#8217;ll just say it again.</p>



<p class="wp-block-paragraph">But I&#8217;ll just say it again, R10 and R11 are just temporary registers.</p>



<p class="wp-block-paragraph">You don&#8217;t have to preserve them.</p>



<p class="wp-block-paragraph">But the callee, if you call another function, they don&#8217;t have to preserve the registers either,</p>



<p class="wp-block-paragraph">which means it can be really fast to use R10 and R12 if you&#8217;re kind of like already running out of registers.</p>



<p class="wp-block-paragraph">If you don&#8217;t have to make a function call anywhere, so you know no one is going to ruin your R10 and R11,</p>



<p class="wp-block-paragraph">then you can also use R10 and R11 to sort of like, you know,</p>



<p class="wp-block-paragraph">reduce your hits to system RAM to speed up your program.</p>



<p class="wp-block-paragraph">So R10 and R11, they should probably be used last.</p>



<p class="wp-block-paragraph">R12, 13, 14, 15, I usually use those first.</p>



<p class="wp-block-paragraph">Once I start running out of those, Kali saved.</p>



<p class="wp-block-paragraph">Then I&#8217;ll start eating into the arguments.</p>



<p class="wp-block-paragraph">I&#8217;ll say, you know, I&#8217;m going to start using RBX</p>



<p class="wp-block-paragraph">and then I&#8217;m going to use RDI and RSI and whatever.</p>



<p class="wp-block-paragraph">It&#8217;s okay if you use, you know, the argument registers.</p>



<p class="wp-block-paragraph">as long as you&#8217;ve already done something with your incoming arguments or you don&#8217;t have any.</p>



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



<p class="wp-block-paragraph">You&#8217;re allowed to use them.</p>



<p class="wp-block-paragraph">I mean, this is all just a standard.</p>



<p class="wp-block-paragraph">As long as you obey what the rule is, then you&#8217;ll be all right.</p>



<p class="wp-block-paragraph">The rule is you got to callee save those.</p>



<p class="wp-block-paragraph">The rule is that one&#8217;s just temporary.</p>



<p class="wp-block-paragraph">The rule is this one&#8217;s an argument and so forth.</p>



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



<p class="wp-block-paragraph">locals and how we use these registers. Let me try to just show you one more</p>



<p class="wp-block-paragraph">thing real fast. So I said before that the size of the REX register is 64 bits</p>



<p class="wp-block-paragraph">because it takes up the whole available register bits in the CPU but there are</p>



<p class="wp-block-paragraph">other versions of this register that we could use. What if you only wanted to use</p>



<p class="wp-block-paragraph">32 bits in your register? What if you wanted to pack like two different 32</p>



<p class="wp-block-paragraph">32-bit numbers in the same 64-bit register.</p>



<p class="wp-block-paragraph">You could do that.</p>



<p class="wp-block-paragraph">There are also older modules and instructions</p>



<p class="wp-block-paragraph">that will operate only on 32-bits.</p>



<p class="wp-block-paragraph">So how do you reference only 32-bits of a register?</p>



<p class="wp-block-paragraph">Well, if I search for, oh shoot, what was it?</p>



<p class="wp-block-paragraph">Is it EDI?</p>



<p class="wp-block-paragraph">No, no.</p>



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



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



<p class="wp-block-paragraph">This is like a good lesson in actually preparing before you record a video.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do architecture overview, CPU registers.</p>



<p class="wp-block-paragraph">Oh, it was at the beginning of this section.</p>



<p class="wp-block-paragraph">I always skip down to 2.4, 12 point something, and I should have gone to 2.3.1.1.</p>



<p class="wp-block-paragraph">So obviously I&#8217;m not going to remember all of this, but basically notice at the top,</p>



<p class="wp-block-paragraph">we have the REX register, all 64 bits of it.</p>



<p class="wp-block-paragraph">But if you wanted to access the lowest six, sorry, the lowest 32 bits, then in your code,</p>



<p class="wp-block-paragraph">instead of putting REX, you put EAX.</p>



<p class="wp-block-paragraph">So for example, you know, move REX, whoops, REX, let&#8217;s say the number five, but over</p>



<p class="wp-block-paragraph">here we&#8217;re going to move EAX, the number five.</p>



<p class="wp-block-paragraph">five uh here it&#8217;s going to set the whole 64 bits to just like a bunch of zeros and then there&#8217;s</p>



<p class="wp-block-paragraph">going to be a few bits that help represent five the lowest bits so it&#8217;s going to erase like the</p>



<p class="wp-block-paragraph">whole thing all 64 bits but if you use the eax instruction then only the lowest 32 bits will</p>



<p class="wp-block-paragraph">actually be modified which means whatever data you had in the higher 60 the higher 32 bits of the</p>



<p class="wp-block-paragraph">of the register itself they&#8217;re just going to stay there it&#8217;s going to be considered</p>



<p class="wp-block-paragraph">point so sometimes if you&#8217;re going to work with something that&#8217;s going to be using only 32 bits</p>



<p class="wp-block-paragraph">of your register you better make sure that the other bits are uh are cleared out if you intend</p>



<p class="wp-block-paragraph">to use rax right after that and and vice versa so keep in mind that we have other forms of the same</p>



<p class="wp-block-paragraph">register a designation but just to let the cpu know that we only want to touch 32 bits worth we</p>



<p class="wp-block-paragraph">And this, this kind of table covers all of the registers,</p>



<p class="wp-block-paragraph">REX, RBX, RCX, and so forth.</p>



<p class="wp-block-paragraph">I think it doesn&#8217;t cover the instruction pointer</p>



<p class="wp-block-paragraph">and something else in there, but you know, most of them.</p>



<p class="wp-block-paragraph">However, you know, for my purposes,</p>



<p class="wp-block-paragraph">I usually just use 64 bits</p>



<p class="wp-block-paragraph">because I&#8217;m not like super advanced</p>



<p class="wp-block-paragraph">unless I have to divide or do something.</p>



<p class="wp-block-paragraph">Okay, so that&#8217;s the last thing I wanted to mention</p>



<p class="wp-block-paragraph">about the general purpose registers.</p>



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



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



<p class="wp-block-paragraph">So the not sure if I said this before already, but basically the.</p>



<p class="wp-block-paragraph">So just to emphasize the, uh, the RBP register is the base pointer register.</p>



<p class="wp-block-paragraph">You&#8217;re probably going to mess up, uh, the caller because the caller often uses RBP as</p>



<p class="wp-block-paragraph">a bookmark for the stack pointer.</p>



<p class="wp-block-paragraph">mark for the stack pointer you definitely don&#8217;t want to mess with a stack pointer unless you</p>



<p class="wp-block-paragraph">actually know what you&#8217;re doing in order to create local variables um there&#8217;s another variable</p>



<p class="wp-block-paragraph">another register in here called rip which is the instruction pointer register so if you</p>



<p class="wp-block-paragraph">if you mess that one up then the program is going to start executing in some crazy place that doesn&#8217;t</p>



<p class="wp-block-paragraph">even make sense okay so now that we&#8217;ve talked about general purpose registers by the way i</p>



<p class="wp-block-paragraph">called special purpose registers, not general purpose.</p>



<p class="wp-block-paragraph">General purpose is like RAX, RBX, all these ones that you can just randomly use as long</p>



<p class="wp-block-paragraph">as you respect the ABI.</p>



<p class="wp-block-paragraph">But the base pointer and the stack pointer, those are kind of special.</p>



<p class="wp-block-paragraph">And the RIP, the instruction pointer, that&#8217;s a special register.</p>



<p class="wp-block-paragraph">You shouldn&#8217;t mess with those unless you really know what you&#8217;re doing or you&#8217;ll get yourself</p>



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



<p class="wp-block-paragraph">But now that we&#8217;ve talked about those, let&#8217;s talk about the floating point registers just</p>



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



<p class="wp-block-paragraph">about using floats until a lot later but basically</p>



<p class="wp-block-paragraph">i at least want to mention that we do have registers that will work with floating point</p>



<p class="wp-block-paragraph">operations let me see there we go okay so it&#8217;s 18.2 floating point registers um essentially</p>



<p class="wp-block-paragraph">we use xmm0 through xmm13 for floating point numbers there&#8217;s not going to be any</p>



<p class="wp-block-paragraph">not going to be any crazy letters like RDI, RSI that you have to memorize. You can just use zero</p>



<p class="wp-block-paragraph">through 15 and it&#8217;s totally fine. When you want to return a floating point number from a function,</p>



<p class="wp-block-paragraph">you will load up XMM0 as the return value. You won&#8217;t even touch RAX. The arguments are the same.</p>



<p class="wp-block-paragraph">They&#8217;re just kind of ordered. It&#8217;s like the first argument is going to be XMM0. The second argument</p>



<p class="wp-block-paragraph">is going to be XMM1 and so forth all the way up to XMM15. If you need more than 15 arguments,</p>



<p class="wp-block-paragraph">some sorcery with the stack or with some kind of system like the global variable or something</p>



<p class="wp-block-paragraph">and also for floating point registers we use different instructions so what I really want</p>



<p class="wp-block-paragraph">you to know because this is mostly about the regular registers is that if you have floating</p>



<p class="wp-block-paragraph">point numbers and you want to multiply them or do some other operation on them the normal</p>



<p class="wp-block-paragraph">instructions for regular registers won&#8217;t actually work you&#8217;ll have to look up a different set of</p>



<p class="wp-block-paragraph">and i&#8217;m going to do this in another video some other time uh if you want to move uh data with</p>



<p class="wp-block-paragraph">a floating point register you can&#8217;t just use the regular move instruction you got to use either</p>



<p class="wp-block-paragraph">move ss or move sd um and and both operands have to be floats or actually i think the one on the</p>



<p class="wp-block-paragraph">right can be memory but um move ss basically means a single piece of data single precision</p>



<p class="wp-block-paragraph">So you can move like multiple pieces of data at a time.</p>



<p class="wp-block-paragraph">I&#8217;m not going to really cover that.</p>



<p class="wp-block-paragraph">Um, but you can move single precision floating points, which means there are 32 bit floating</p>



<p class="wp-block-paragraph">points or you can move double precision floating points, which means they&#8217;re a full 64 bit</p>



<p class="wp-block-paragraph">floating point number.</p>



<p class="wp-block-paragraph">There&#8217;s also bigger registers, but I&#8217;m not going to talk about that.</p>



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



<p class="wp-block-paragraph">Well, yeah.</p>



<p class="wp-block-paragraph">Later processors 256.</p>



<p class="wp-block-paragraph">I think mine has that, but I&#8217;m not going to talk about that.</p>



<p class="wp-block-paragraph">I think mine are like YMM or something.</p>



<p class="wp-block-paragraph">So yeah, with that, those are the basics of registers and some stuff to keep in mind.</p>



<p class="wp-block-paragraph">In future videos, I&#8217;m going to talk more in depth about making functions and calling functions</p>



<p class="wp-block-paragraph">and all that stuff, respecting the ABI.</p>



<p class="wp-block-paragraph">But for now, here is your primer.</p>



<p class="wp-block-paragraph">I hope it was useful on CPU registers.</p>



<p class="wp-block-paragraph">Thank you for watching this video.</p>



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



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



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



<p class="wp-block-paragraph">mean the world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able</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</p>



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



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



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



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



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



<p class="wp-block-paragraph">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/mastering-x86-64-assembly-a-beginners-guide-to-cpu-registers/">Mastering x86-64 Assembly: A Beginner&#8217;s Guide to CPU Registers</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/mastering-x86-64-assembly-a-beginners-guide-to-cpu-registers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners</title>
		<link>https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/</link>
					<comments>https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 30 Jun 2025 06:15:25 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[AND operator]]></category>
		<category><![CDATA[binary logic]]></category>
		<category><![CDATA[binary operations]]></category>
		<category><![CDATA[bit manipulation]]></category>
		<category><![CDATA[bitwise operators]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding tips]]></category>
		<category><![CDATA[computer science basics]]></category>
		<category><![CDATA[NOR operator]]></category>
		<category><![CDATA[NOT operator]]></category>
		<category><![CDATA[OR operator]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[tech tutorials]]></category>
		<category><![CDATA[XOR operator]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=173</guid>

					<description><![CDATA[<p>Learn bitwise operators (OR, AND, NOT, XOR, NOR) with clear examples. Perfect for beginners mastering binary logic in programming.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/">Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners</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 Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners" width="1380" height="776" src="https://www.youtube.com/embed/mL_wTRllqtc?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 understand bitwise operators? This video dives into OR, AND, NOT, XOR, and NOR with easy-to-follow examples. Learn how to use these operators for flags, masks, and more in programming. Perfect for beginners or anyone wanting to master binary logic in C or other languages. I break it down with real examples, a touch of humor, and no fluff. Subscribe for more coding tutorials, and check out my site for extra resources. Drop a comment with your questions or video ideas!</p>



<p class="wp-block-paragraph">Introduction to Logical Operators 00:00:00<br>Explanation of Bitwise OR 00:00:35<br>OR Operation Examples 00:01:01<br>Bitwise OR with Multiple Bits 00:02:12<br>Using OR for Flags 00:03:52<br>Introduction to Logical AND 00:08:06<br>AND Operation Examples 00:08:29<br>Using AND as a Mask 00:10:00<br>Checking Specific Bits with AND 00:11:17<br>Introduction to NOT Operation 00:13:36<br>Introduction to NOR Operation 00:14:38<br>Introduction to XOR Operation 00:16:37<br>XOR and Neural Networks 00:16:53<br>Conclusion and Call to Action 00:18:38</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 talk about basic logical operators such as OR and AND.</p>



<p class="wp-block-paragraph">Uh so let&#8217;s let&#8217;s dive right into it. What am I talking about with the OR and AND?</p>



<p class="wp-block-paragraph">Suppose for the sake of argument that this notepad is totally dark and I wanted it to be really light</p>



<p class="wp-block-paragraph">and then I have to go into the system settings to fix it. Sorry let me change my theme.</p>



<p class="wp-block-paragraph">How about that?</p>



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



<p class="wp-block-paragraph">So suppose for the sake of argument, we&#8217;ve got, you know, a couple of bits.</p>



<p class="wp-block-paragraph">These are going to be a bitwise operations for the most part.</p>



<p class="wp-block-paragraph">In other languages, sometimes we will say logical operator, but actually we&#8217;re just</p>



<p class="wp-block-paragraph">talking about values rather than bits individually.</p>



<p class="wp-block-paragraph">So these are bitwise operators.</p>



<p class="wp-block-paragraph">Imagine we have like a couple of bits.</p>



<p class="wp-block-paragraph">Remember the possible values for bits are just, you know, a zero and a one binary.</p>



<p class="wp-block-paragraph">So suppose we have a couple of values.</p>



<p class="wp-block-paragraph">values, let&#8217;s say we have a zero here and a one.</p>



<p class="wp-block-paragraph">So if I apply a logical or to the zero and the one,</p>



<p class="wp-block-paragraph">the result is going to be a one because either the first bit or the second bit are a one.</p>



<p class="wp-block-paragraph">You could also expand these operators to have multiple sets of bits,</p>



<p class="wp-block-paragraph">but we&#8217;re just going to do, you know, one set against another set.</p>



<p class="wp-block-paragraph">In this case, each set is just one bit long, but we&#8217;ll do, we&#8217;ll do a more complicated stuff in a minute.</p>



<p class="wp-block-paragraph">If I have a zero and a one, then the answer there is, well, let me just put or maybe.</p>



<p class="wp-block-paragraph">The answer is a one.</p>



<p class="wp-block-paragraph">I&#8217;ll put or maybe at the top, just like or to let you know that we&#8217;re doing ors here</p>



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



<p class="wp-block-paragraph">So if we have a zero and a one, the answer is going to be a one.</p>



<p class="wp-block-paragraph">If we have a one and a zero, the answer is going to be a one.</p>



<p class="wp-block-paragraph">Also, if we have two ones, which looks like an L over there, I got to work on my penmanship.</p>



<p class="wp-block-paragraph">Then the answer is also going to be a one.</p>



<p class="wp-block-paragraph">if either of the bits in question are a one then the answer should be a one. The only case with an</p>



<p class="wp-block-paragraph">OR that results in a zero is if both of the bits are zero because neither the first or the second</p>



<p class="wp-block-paragraph">are actually a one right so this is the basic idea of using an OR operator and you can also do this</p>



<p class="wp-block-paragraph">with multiple bits at the same time like for example we could say let&#8217;s take a bunch of random</p>



<p class="wp-block-paragraph">work on the it&#8217;s the pressure dude the l&#8217;s are driving me crazy okay oh my god okay so i do that</p>



<p class="wp-block-paragraph">and i let go okay i&#8217;m just going to put some random bits uh underneath the the first set of</p>



<p class="wp-block-paragraph">random bits put like a zero here and then like a one here maybe and we&#8217;ll say that we&#8217;re going to</p>



<p class="wp-block-paragraph">do a logical or just like you might think of doing a you know addition or subtraction we&#8217;ll just say</p>



<p class="wp-block-paragraph">you know, addition or subtraction. We&#8217;ll just say we&#8217;re going to or these two sets of bits.</p>



<p class="wp-block-paragraph">Actually, these are six on the top and six on the bottom. If I add two more, then it&#8217;ll be a nice</p>



<p class="wp-block-paragraph">little bite for the top and the bottom. So I&#8217;m just going to do that, you know, to have eight</p>



<p class="wp-block-paragraph">bits on the top and eight bits on the bottom. Okay. So if I just want to logically or two sets</p>



<p class="wp-block-paragraph">of bits, literally, I just have to do one pair of bits at a time. So a one or zero is just a one.</p>



<p class="wp-block-paragraph">One or zero is just a one, a zero or one is a one, a one or zero is a one, a zero or one</p>



<p class="wp-block-paragraph">is a one.</p>



<p class="wp-block-paragraph">And then these ones, everything is just a one.</p>



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



<p class="wp-block-paragraph">So that was too easy.</p>



<p class="wp-block-paragraph">Maybe if I, I don&#8217;t know, maybe if I change one of these ones to a zero, then we would</p>



<p class="wp-block-paragraph">actually be able to have a zero somewhere in here.</p>



<p class="wp-block-paragraph">So that&#8217;s a logical or a bitwise or operator or operation.</p>



<p class="wp-block-paragraph">So you can, you can kind of use this in various ways.</p>



<p class="wp-block-paragraph">can kind of use this in various ways i mean obviously if you want to manipulate some bits</p>



<p class="wp-block-paragraph">this can be pretty useful inside of the machine but there was kind of an old school way that</p>



<p class="wp-block-paragraph">people did flags with arguments they would basically say something like this they would go</p>



<p class="wp-block-paragraph">in their computer program they would say you know flag a name it something like turn on the display</p>



<p class="wp-block-paragraph">or enable caching or just like whatever right so we&#8217;ll just have a flag we&#8217;ll call it flag a</p>



<p class="wp-block-paragraph">that value is equal to a one and then maybe flag b its value is equal to a two and then flag c</p>



<p class="wp-block-paragraph">its value would be a four and then we basically just double the value of the flag and the reason</p>



<p class="wp-block-paragraph">for that c d e f i&#8217;ll just stop with f maybe oh wait that was supposed to be 16 and that&#8217;s 32.</p>



<p class="wp-block-paragraph">the reason for that is if you double the value of each flag so that uh</p>



<p class="wp-block-paragraph">and then you can do a bitwise or against all of these flags and sort of combine multiple flags.</p>



<p class="wp-block-paragraph">Because if you think about it, if we&#8217;re talking about binary,</p>



<p class="wp-block-paragraph">if we suppose this is just a regular eight bit number, then, you know, the first bit has a</p>



<p class="wp-block-paragraph">strength of one. If you&#8217;ve seen my other videos for converting between binary and hex,</p>



<p class="wp-block-paragraph">the second bit has a strength of two. The next bit has a strength of four and then eight and</p>



<p class="wp-block-paragraph">and then 32 and 64 and then 128.</p>



<p class="wp-block-paragraph">And so if you look at the flags,</p>



<p class="wp-block-paragraph">1, 2, 4, 8, 16, 32,</p>



<p class="wp-block-paragraph">they map to only one bit.</p>



<p class="wp-block-paragraph">It&#8217;s not going to be some kind of random pattern for these numbers.</p>



<p class="wp-block-paragraph">It&#8217;s literally going to be flag A is going to look like this.</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8.</p>



<p class="wp-block-paragraph">And then flag B is going to look like this.</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8.</p>



<p class="wp-block-paragraph">five, six, seven, eight. And flag D is going to look like this. Whoops. Let me make that green.</p>



<p class="wp-block-paragraph">Still getting used to this. Oh, sorry. C is the next one. One, two, three, four, five,</p>



<p class="wp-block-paragraph">six, seven, eight. Can you see the pattern here? Let me just do D and be done with it at this</p>



<p class="wp-block-paragraph">point. One, two, three, four, five, six, seven, eight. So because we&#8217;re increasing the value of</p>



<p class="wp-block-paragraph">the flags by a power of two, or by a power of two, they&#8217;ll always correspond to just one bit.</p>



<p class="wp-block-paragraph">they&#8217;ll always correspond to just one bit, which means if you apply a logical or operation,</p>



<p class="wp-block-paragraph">you can represent a bunch of different flags with just one number.</p>



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



<p class="wp-block-paragraph">What if I wanted to have, oh, I don&#8217;t know.</p>



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



<p class="wp-block-paragraph">What if I wanted to have some, let&#8217;s say I wanted flag A and flag D and flag F just for</p>



<p class="wp-block-paragraph">the sake of argument.</p>



<p class="wp-block-paragraph">Dang, this pen.</p>



<p class="wp-block-paragraph">It&#8217;s actually my fault completely, but I need to practice.</p>



<p class="wp-block-paragraph">but I need to practice F okay and DNF so that would basically be you know 1 2 3 4 5 6 7 8</p>



<p class="wp-block-paragraph">and then D would be the 8 so a 1 0 0 0 there and then a bunch of zeros elsewhere and then the F</p>



<p class="wp-block-paragraph">So if we did an OR between all of those, then the OR is just basically 00101001.</p>



<p class="wp-block-paragraph">And if you convert that from binary to decimal, what is that?</p>



<p class="wp-block-paragraph">That&#8217;s a 1248 plus 8 plus 1248 and then a 32.</p>



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



<p class="wp-block-paragraph">just write down the number 41 and if the programmer is smart enough to you know parse all the bits</p>



<p class="wp-block-paragraph">and everything then they&#8217;ll know that you have flags a and d and f set that&#8217;s not necessarily</p>



<p class="wp-block-paragraph">something that all the modern programs do anymore it was much more popular in the olden days but i</p>



<p class="wp-block-paragraph">think some people still kind of do it especially if they&#8217;re programming in c and other languages</p>



<p class="wp-block-paragraph">where they want speed it&#8217;s pretty fast to look at bits inside of the machine so keep that in mind</p>



<p class="wp-block-paragraph">Keep that in mind now we know how to do an OR operation and we know one reason that it might be useful and</p>



<p class="wp-block-paragraph">Yeah, okay. I&#8217;m gonna move on to the next operation</p>



<p class="wp-block-paragraph">So clearing the screen now</p>



<p class="wp-block-paragraph">Hello little doggy he barked and now he&#8217;s in the room</p>



<p class="wp-block-paragraph">Let&#8217;s do</p>



<p class="wp-block-paragraph">The logical AND operation okay, so suppose we have two bits here</p>



<p class="wp-block-paragraph">in a one only if both of the input bits are a one i&#8217;m gonna whoops i accidentally cleared the whole</p>



<p class="wp-block-paragraph">entire thing let me forget where my red pen is okay and okay so if we have a zero and a zero</p>



<p class="wp-block-paragraph">the result is zero because neither of those are a one if we have a zero and a one the result is</p>



<p class="wp-block-paragraph">still going to be zero because we need both bits to be a one to result in a one so then that means</p>



<p class="wp-block-paragraph">would also result in a zero. So you get a bunch of zeros until finally you have an input pattern</p>



<p class="wp-block-paragraph">that is just two ones. And then finally the result is one. So that&#8217;s a logical and.</p>



<p class="wp-block-paragraph">Let me do a quick example so we can and a bunch of bits together. I&#8217;m just going to do more</p>



<p class="wp-block-paragraph">random bit patterns. So there&#8217;s another L there. I&#8217;m cringing. I&#8217;m self-cringing. One, two, three,</p>



<p class="wp-block-paragraph">okay so then i&#8217;ll do like another one there and like a zero there and a zero maybe a couple of</p>



<p class="wp-block-paragraph">ones maybe three ones and then a zero and then one i guess and we&#8217;ll just say that we&#8217;re going</p>



<p class="wp-block-paragraph">to end those together so and oh man i&#8217;m mixing uppercase and lowercase like crazy</p>



<p class="wp-block-paragraph">so uh to end them together you know that bit position right here that&#8217;s going to be a one</p>



<p class="wp-block-paragraph">and then we have a zero because they don&#8217;t match they&#8217;re not both one and then we have another zero</p>



<p class="wp-block-paragraph">a one and then we have a zero and a zero and a zero and a one so this is a logical and you can</p>



<p class="wp-block-paragraph">use logical ands for a wide variety of things but one thing you can kind of do somewhat easily is to</p>



<p class="wp-block-paragraph">use one number as a mask against another number for example notice how uh suppose this was the</p>



<p class="wp-block-paragraph">input number let&#8217;s just say we have the input number up top and maybe you wanted to make sure</p>



<p class="wp-block-paragraph">because you&#8217;re you&#8217;re checking for those bits individually or maybe you want to just prevent</p>



<p class="wp-block-paragraph">the input from having certain bits on for some other reason well you can you can apply the mask</p>



<p class="wp-block-paragraph">as the second bit and use a logical and i&#8217;ll say mask here sorry you can apply a mask as the second</p>



<p class="wp-block-paragraph">bit pattern and notice how in the answer there are only ones where both you know the input and</p>



<p class="wp-block-paragraph">means if I wanted to just control only which ones are allowed I can use the mask notice how the mask</p>



<p class="wp-block-paragraph">has ones in these positions and there are definitely no zeros sorry there are definitely</p>



<p class="wp-block-paragraph">no ones in any position where a mask had a zero so the mask can kind of like you know mute or mask</p>



<p class="wp-block-paragraph">or control the input pattern if that makes sense hopefully another thing we could do if we wanted</p>



<p class="wp-block-paragraph">if one bit exists. Let me go ahead and clear this real fast. I&#8217;m going to just do maybe four</p>



<p class="wp-block-paragraph">bits this time. So we could obviously do an and against four zeros, and this would result in just,</p>



<p class="wp-block-paragraph">you know, a resulting pattern of zero. So this is not super useful. The result would just</p>



<p class="wp-block-paragraph">definitely be four zeros. But notice again how the second pattern is sort of controlling what&#8217;s</p>



<p class="wp-block-paragraph">allowed to go through from the first pattern. Suppose I wanted to check to see if that particular</p>



<p class="wp-block-paragraph">particular bit was on or off.</p>



<p class="wp-block-paragraph">All I have to do is mask it with a one in the correct pattern.</p>



<p class="wp-block-paragraph">So, you know, the second bit that I just wrote down on the bottom row,</p>



<p class="wp-block-paragraph">I just want to see if that second bit is on or off in the input pattern.</p>



<p class="wp-block-paragraph">I don&#8217;t care about any of the other bits.</p>



<p class="wp-block-paragraph">That means the result will be this.</p>



<p class="wp-block-paragraph">So now it&#8217;s much more easy for me to see if that bit is on.</p>



<p class="wp-block-paragraph">I could just compare the value of those bits to a regular integer.</p>



<p class="wp-block-paragraph">Like, for example, if we consider that this was the one and this was the two</p>



<p class="wp-block-paragraph">considered that this was the one and this was the two and this was the four or sorry four and then</p>



<p class="wp-block-paragraph">the eight I could just ask now if the final value equals two and then I would know if that bit was</p>



<p class="wp-block-paragraph">on or not in the original pattern and so if I wanted to check to see if this other you know</p>



<p class="wp-block-paragraph">bit was on I can move this over here and set that back to a zero so the resulting pattern would be</p>



<p class="wp-block-paragraph">zeros then I&#8217;d ask myself is the resulting value equal to four no it&#8217;s equal to zero and so then</p>



<p class="wp-block-paragraph">Another thing you can do that I&#8217;m going to talk about in a future video is just sort of shift the bits over.</p>



<p class="wp-block-paragraph">You could, instead of checking to see if the value was a 4 or like a direct integer,</p>



<p class="wp-block-paragraph">you could just sort of shift over a certain number of spots and then check to see if it was equal to 1 or 0.</p>



<p class="wp-block-paragraph">Let me put this 1 back over into its original position just so that we&#8217;ll have something that had a 1.</p>



<p class="wp-block-paragraph">is one from uh you know the right side if it&#8217;s one to the left from the right side</p>



<p class="wp-block-paragraph">then i could just shift all the bits one to the right and end up with a pattern that is zero zero</p>



<p class="wp-block-paragraph">zero one i&#8217;m not going to talk about bit shifting operations in this video but just know that you can</p>



<p class="wp-block-paragraph">and you&#8217;ll see more of it in a future video so then you know this is another way to check to</p>



<p class="wp-block-paragraph">see if a bit was on first you do a mask for that bit and then you shift bits and then you just</p>



<p class="wp-block-paragraph">check to see if the final value is a zero or one which may or may not feel easier than checking for</p>



<p class="wp-block-paragraph">or may not feel easier than checking for an actual integer in your program.</p>



<p class="wp-block-paragraph">Okay, so we&#8217;ve done OR and also AND. The next bit pattern is called a NOT, which is really easy.</p>



<p class="wp-block-paragraph">It&#8217;s literally just an inversion of the original bit pattern. So for the NOT, we don&#8217;t really take</p>



<p class="wp-block-paragraph">two bits against each other. We just take an input bit and we just invert it. We&#8217;ll just say</p>



<p class="wp-block-paragraph">So that&#8217;s a knot. Pretty easy. We could also knot, you know, a random bit pattern with Ls.</p>



<p class="wp-block-paragraph">So I swear, somebody&#8217;s going to show up and this is their first computer science video.</p>



<p class="wp-block-paragraph">They&#8217;re going to go tell their parents, hey, there&#8217;s Ls in computer science.</p>



<p class="wp-block-paragraph">So sorry. I&#8217;m so sorry. Okay. So I got four there. So if I knot those, then that&#8217;s pretty easy.</p>



<p class="wp-block-paragraph">It&#8217;s just going to be the opposite, you know, an inversion.</p>



<p class="wp-block-paragraph">you know, an inversion.</p>



<p class="wp-block-paragraph">One, zero, one, zero.</p>



<p class="wp-block-paragraph">Let me just double check that I did that correctly.</p>



<p class="wp-block-paragraph">Yeah, so that&#8217;s the knot pattern.</p>



<p class="wp-block-paragraph">No big deal.</p>



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



<p class="wp-block-paragraph">So then maybe the next thing that we can talk about is the nor,</p>



<p class="wp-block-paragraph">which just means not or.</p>



<p class="wp-block-paragraph">So let me draw that out real fast just to show you what I&#8217;m talking about.</p>



<p class="wp-block-paragraph">So if we do nor, pretty much you can imagine first taking the or and then knotting it.</p>



<p class="wp-block-paragraph">So inverting the or.</p>



<p class="wp-block-paragraph">the OR. So for example, if we have two bits here, actually, let me, let me do, let me do a</p>



<p class="wp-block-paragraph">sequential counter. Cause I think that&#8217;s more fun. I&#8217;m counting right now from one to a three</p>



<p class="wp-block-paragraph">or a actually, I do that in the last one. I started with zero. I hope let&#8217;s count from zero</p>



<p class="wp-block-paragraph">to three. So zero and then one and then two and then three. So I&#8217;m counting in binary.</p>



<p class="wp-block-paragraph">two input bits and we&#8217;re going to do a nor then the first thing we probably want to do is take</p>



<p class="wp-block-paragraph">the or operator so that would be a zero here i&#8217;ll just put or in parentheses just to let you know</p>



<p class="wp-block-paragraph">that this is kind of a nice first step you could memorize nor if you wanted to but i don&#8217;t i don&#8217;t</p>



<p class="wp-block-paragraph">really remember how to do it without doing these steps so uh it&#8217;s going to be ones for everything</p>



<p class="wp-block-paragraph">else because in the or you get a one if either of those is a one and then uh the next step is you</p>



<p class="wp-block-paragraph">the or i&#8217;ll just put nor here just to let you well just to let you know that you&#8217;re uh well i</p>



<p class="wp-block-paragraph">don&#8217;t know if i put nor then it kind of sounds like i&#8217;m norring that one bit doesn&#8217;t it so maybe</p>



<p class="wp-block-paragraph">here i&#8217;ll say uh not just to let you know that this is just one step against the previous bit</p>



<p class="wp-block-paragraph">so the knot is uh just going to be an inversion and so the nor of zero zero is one the nor of zero</p>



<p class="wp-block-paragraph">nor of 1 1 is 0 and that&#8217;s how you do a nor and all of these logical or bitwise</p>



<p class="wp-block-paragraph">operators can be used in circuits and circuit design and just you know other</p>



<p class="wp-block-paragraph">types of logical operations I&#8217;m gonna move on let&#8217;s see the next one is gonna</p>



<p class="wp-block-paragraph">be XOR that I wanted to talk about in this video so what is XOR it just means</p>



<p class="wp-block-paragraph">exclusive or so it&#8217;s a little bit more complicated than or this is actually a</p>



<p class="wp-block-paragraph">one because it has a history with neural networks. When you have a neural network that does not have</p>



<p class="wp-block-paragraph">more than one, or sorry, if you have a neural network that does not have any hidden layers,</p>



<p class="wp-block-paragraph">like if you just have an input layer and an output layer, then the neural network should</p>



<p class="wp-block-paragraph">actually not be able to solve XOR. It should not be able to learn it. You have to increase the</p>



<p class="wp-block-paragraph">topology of the neural network in some way, make it a little bit more complicated. For example,</p>



<p class="wp-block-paragraph">one or more middle layers between the input and the output layers. If you understand neural</p>



<p class="wp-block-paragraph">networks, it&#8217;s just kind of fun to know, oh, XOR stumps a shallow network and kind of starts to</p>



<p class="wp-block-paragraph">prove that deep networks might be a little bit smarter or deepish at least. Okay. So XOR,</p>



<p class="wp-block-paragraph">let&#8217;s start off by counting here. I&#8217;m going to do zero and zero, and then this is the number one,</p>



<p class="wp-block-paragraph">and this is the number two, and this is the number three. And exclusive OR just basically means</p>



<p class="wp-block-paragraph">just basically means an or but if both of the bits are one then it&#8217;s a zero so that means</p>



<p class="wp-block-paragraph">either of the bits can be a one to produce a one but it must be exclusive the bit that is a one</p>



<p class="wp-block-paragraph">can&#8217;t also be next to another bit that&#8217;s a one so let me show you so in is in a double zero</p>



<p class="wp-block-paragraph">the answer is just going to be a zero in a zero and one the answer is going to be a one in a one</p>



<p class="wp-block-paragraph">exclusive, the one is it has a, it has a buddy or a partner.</p>



<p class="wp-block-paragraph">It&#8217;s not an exclusive one.</p>



<p class="wp-block-paragraph">So we&#8217;ll say that that&#8217;s a zero.</p>



<p class="wp-block-paragraph">So that&#8217;s the XOR.</p>



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



<p class="wp-block-paragraph">You could put like a, a, a not on top of that or an and on top of that or whatever</p>



<p class="wp-block-paragraph">you wanted to do.</p>



<p class="wp-block-paragraph">And we can make stuff that&#8217;s a lot more complicated, but these are the basics of</p>



<p class="wp-block-paragraph">or and not XOR and NOR as bitwise operators.</p>



<p class="wp-block-paragraph">So thank you for watching this video.</p>



<p class="wp-block-paragraph">That&#8217;s all I have to say for now.</p>



<p class="wp-block-paragraph">See you in the next one.</p>



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



<p class="wp-block-paragraph">I&#8217;m out.</p>



<p class="wp-block-paragraph">social 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 do me a kindness</p>



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



<p class="wp-block-paragraph">wake up because i know somebody subscribed or followed it just wakes me up and i get filled</p>



<p class="wp-block-paragraph">with joy that&#8217;s exactly what happens every single time so you could do it as a nice favor to me or</p>



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



<p class="wp-block-paragraph">middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s what will</p>



<p class="wp-block-paragraph">happen also uh 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">if you have a suggestion for uh uh clarifications or errata or just future videos that you want to</p>



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



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



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



<p class="wp-block-paragraph">appreciate it so again thank you so much for watching this video and um enjoy the cool music</p>



<p class="wp-block-paragraph">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/master-bitwise-operators-or-and-not-xor-nor-for-beginners/">Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>DDD Debugger Tutorial: Fast Guide to Debugging C++ &#038; C Code</title>
		<link>https://www.NeuralLantern.com/ddd-debugger-tutorial-fast-guide-to-debugging-c-c-code/</link>
					<comments>https://www.NeuralLantern.com/ddd-debugger-tutorial-fast-guide-to-debugging-c-c-code/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 22 Jun 2025 13:42:41 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[C debugging]]></category>
		<category><![CDATA[c++ debugging]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[Data Display Debugger]]></category>
		<category><![CDATA[DDD debugger]]></category>
		<category><![CDATA[debugger GUI]]></category>
		<category><![CDATA[debugging tutorial]]></category>
		<category><![CDATA[GDB debugger]]></category>
		<category><![CDATA[learn to code]]></category>
		<category><![CDATA[programming tips]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[set breakpoints]]></category>
		<category><![CDATA[software debugging]]></category>
		<category><![CDATA[source code debugging]]></category>
		<category><![CDATA[Ubuntu debugging]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=161</guid>

					<description><![CDATA[<p>Learn DDD debugging fast! This tutorial covers breakpoints, source code, and GDB console for C++ &#038; C. Watch our GDB video first for better skills!</p>
<p>The post <a href="https://www.NeuralLantern.com/ddd-debugger-tutorial-fast-guide-to-debugging-c-c-code/">DDD Debugger Tutorial: Fast Guide to Debugging C++ &amp; C Code</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="DDD Debugger Tutorial: Fast Guide to Debugging C++ &amp; C Code" width="1380" height="776" src="https://www.youtube.com/embed/jRsoOosxWuc?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">Hey coders! Dive into this quick DDD tutorial to learn the Data Display Debugger for C++ and C programs. See how to launch DDD, set breakpoints, view source code, and use the GDB console. I’ll walk you through the basics, but check my GDB video first for a better debugging foundation. If you’re new to GUI debuggers or just curious, this is for you! Subscribe for more programming tips, and let me know in the comments if you want advanced DDD content. Scan the QR code for more tutorials!</p>



<p class="wp-block-paragraph">Introduction to DDD 00:00:00<br>DDD vs GDB Comparison 00:00:04<br>Installation Instructions 00:00:56<br>Launching DDD 00:01:20<br>Source Code Window 00:01:57<br>Setting Breakpoints 00:03:16<br>Running and Debugging 00:04:08<br>GDB Console Commands 00:04:21<br>Modifying Breakpoints 00:05:20<br>Closing DDD 00:05:36<br>Recommendation to Learn GDB 00:05:48<br>Call to Subscribe 00:06:32<br>Website and Comments 00:07:17</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">DDD debugger, Data Display Debugger, debugging tutorial, C++ debugging, C debugging, GDB debugger, programming tutorial, software debugging, coding for beginners, debugger GUI, set breakpoints, source code debugging, Ubuntu debugging, learn to code, programming tips</p>



<p class="wp-block-paragraph">hey there in this video i&#8217;m going to give you a very very quick overview</p>



<p class="wp-block-paragraph">of a program called ddd which you can use to debug your programs</p>



<p class="wp-block-paragraph">disclaimer you should see my gdb video first before you watch this one because it&#8217;s much more</p>



<p class="wp-block-paragraph">useful and in my personal opinion gdb is a much better debugger than ddd ddd ddd is actually</p>



<p class="wp-block-paragraph">over GDB so it doesn&#8217;t really add any more functionality it&#8217;s sort of for</p>



<p class="wp-block-paragraph">people who like to use GUI&#8217;s but the GUI is not it&#8217;s not very good but it&#8217;s</p>



<p class="wp-block-paragraph">there if you&#8217;re still struggling with the command line anyway so yeah see my</p>



<p class="wp-block-paragraph">other video if you want to learn about make files if you want to learn about</p>



<p class="wp-block-paragraph">C++ C assembly GDB debugging all that stuff are in other videos but assuming</p>



<p class="wp-block-paragraph">that you know how to use GDB we can start on DDD now DDD anyway if you don&#8217;t</p>



<p class="wp-block-paragraph">Anyway, if you don&#8217;t have DDD on your system, you can go sudo apt install DDD.</p>



<p class="wp-block-paragraph">I&#8217;m on Ubuntu.</p>



<p class="wp-block-paragraph">You could use whatever package manage you have on your system like DNF or whatever.</p>



<p class="wp-block-paragraph">So sudo apt install DDD.</p>



<p class="wp-block-paragraph">I don&#8217;t have to do that because I already have it on my system, unfortunately.</p>



<p class="wp-block-paragraph">Anyway, so the first thing that you can do is you can sort of launch it with DDD up here.</p>



<p class="wp-block-paragraph">It&#8217;s called the data display debugger.</p>



<p class="wp-block-paragraph">You can launch it and then you can attach it to your program for me.</p>



<p class="wp-block-paragraph">attach it to your program for me i like to just launch it uh from the command line i&#8217;ll type ddd</p>



<p class="wp-block-paragraph">and then the name of my executable i&#8217;ll build my executable real fast again this all this stuff is</p>



<p class="wp-block-paragraph">in another video how to build and you know what so forth so i&#8217;m going to build my uh executable</p>



<p class="wp-block-paragraph">and there it is main so i&#8217;m going to go ddd main and this is the uh i can&#8217;t remember the name of</p>



<p class="wp-block-paragraph">display debugger yeah I don&#8217;t really like to use this anyway you can see that</p>



<p class="wp-block-paragraph">right away there is a source code window visible which sort of looks at your</p>



<p class="wp-block-paragraph">program&#8217;s source code if that&#8217;s not visible you can click on the view menu</p>



<p class="wp-block-paragraph">item up here and start you know enabling and disabling windows there&#8217;s a data</p>



<p class="wp-block-paragraph">window to let you look at data there&#8217;s a machine code window I&#8217;m just gonna</p>



<p class="wp-block-paragraph">basically make sure that the GDB console is up and that the source window is up</p>



<p class="wp-block-paragraph">when I closed both windows hoping that I could show you that I opened both of them it just shut</p>



<p class="wp-block-paragraph">down the whole program okay anyway so yeah click view and make sure that the source windows open</p>



<p class="wp-block-paragraph">so we can see our source code and then also make sure that the gdb console window is open so we can</p>



<p class="wp-block-paragraph">type gdb commands and then um well you know probably if you know gdb you&#8217;ll you&#8217;ll you&#8217;ll</p>



<p class="wp-block-paragraph">want to start typing commands here you know enter a breakpoint at main.cpp line you know</p>



<p class="wp-block-paragraph">dot cpp line you know whatever but once you start doing that a lot you&#8217;ll realize maybe you don&#8217;t</p>



<p class="wp-block-paragraph">need to be inside of ddd with ddd you can right click on a line and add a breakpoint manually so</p>



<p class="wp-block-paragraph">that&#8217;s a little convenient i think we can do can we do control mouse no there&#8217;s a lot of obscure</p>



<p class="wp-block-paragraph">areas here well you can go to the preferences and change the font size i think i&#8217;m not going to deal</p>



<p class="wp-block-paragraph">with that in this video but so suppose for the sake of argument i wanted to break at this line</p>



<p class="wp-block-paragraph">line right here I could just right click on it and I have to hold down the right</p>



<p class="wp-block-paragraph">mouse and say set breakpoint and then I could do the same thing for this set</p>



<p class="wp-block-paragraph">breakpoint and then for this set breakpoint so it&#8217;s a little more</p>



<p class="wp-block-paragraph">convenient a little bit faster if you like looking at the text in this way to</p>



<p class="wp-block-paragraph">set breakpoints and then you can disable breakpoints and you can delete breakpoints</p>



<p class="wp-block-paragraph">and you can reset the execution position if you&#8217;re absolutely sure you know what</p>



<p class="wp-block-paragraph">know what you&#8217;re doing you can have your program skip an area and jump somewhere and then once</p>



<p class="wp-block-paragraph">i&#8217;ve kind of set up my break points i can go up here at the top this is the uh i forgot what</p>



<p class="wp-block-paragraph">window this is called but i can basically hit run which i accidentally already clicked when i was</p>



<p class="wp-block-paragraph">trying to resize the window there we go oh i can&#8217;t resize it okay so we&#8217;ll go run and uh</p>



<p class="wp-block-paragraph">well now we&#8217;ve already hit a breakpoint right away notice how at the bottom in the gdb uh</p>



<p class="wp-block-paragraph">GDB console area it says breakpoint 2 at line 36 and then there&#8217;s a green arrow here letting</p>



<p class="wp-block-paragraph">us know that we hit one of our breakpoints already so then we can do normal GDB stuff</p>



<p class="wp-block-paragraph">we can go info breakpoints just to kind of see what&#8217;s in there and you can resize with this</p>



<p class="wp-block-paragraph">handle on the very right side I don&#8217;t think it works in the middle here I&#8217;ve tried it many times</p>



<p class="wp-block-paragraph">but so you can kind of resize with this handle on the right side to get more real estate for</p>



<p class="wp-block-paragraph">panel and so it&#8217;s telling me all right I did info breakpoints just to see the</p>



<p class="wp-block-paragraph">breakpoints I can go info locals to see my local variables like a print a</p>



<p class="wp-block-paragraph">variable you know all that all the normal GDB commands I&#8217;m gonna hit</p>



<p class="wp-block-paragraph">continue and five to skip the next five times this breakpoints get hit this</p>



<p class="wp-block-paragraph">breakpoint gets hit now the next breakpoint that gets hit is this other</p>



<p class="wp-block-paragraph">one over here I can do the same thing info locals I can see the state of all</p>



<p class="wp-block-paragraph">what is b you know what is i what is a what is whatever and when i&#8217;m finished i can say continue</p>



<p class="wp-block-paragraph">and i can also modify my breakpoints by just sort of like deleting them enabling them disabling them</p>



<p class="wp-block-paragraph">but that&#8217;s me trying to type everything in the terminal of course with ddd you can right click</p>



<p class="wp-block-paragraph">on a breakpoint and disable it or delete it and so forth when you&#8217;re eventually done let&#8217;s see</p>



<p class="wp-block-paragraph">kill the process and then you can just kind of exit DDD at this point or you can exit</p>



<p class="wp-block-paragraph">the GDB console with Q and that&#8217;s it that&#8217;s the basics for DDD.</p>



<p class="wp-block-paragraph">However again I strongly encourage you to learn GDB first and by the time you do that</p>



<p class="wp-block-paragraph">you will probably not want to use DDD.</p>



<p class="wp-block-paragraph">But I have to put up this video regardless.</p>



<p class="wp-block-paragraph">Let me know if you&#8217;re interested in very advanced stuff covering DDD.</p>



<p class="wp-block-paragraph">20 years, I might upload another DDD video. You never know.</p>



<p class="wp-block-paragraph">Okay, thanks for watching this video.</p>



<p class="wp-block-paragraph">I hope you learned a little bit, and I hope you go directly to the GDB video after this.</p>



<p class="wp-block-paragraph">See you in the next one.</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">Could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media</p>



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



<p class="wp-block-paragraph">every single time. So you could do it as a nice favor to me or you could 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">I promise that&#8217;s what will happen. Also 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">all the videos i published and the services and tutorials and things that i offer and all that</p>



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



<p class="wp-block-paragraph">that you want to see 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 i</p>



<p class="wp-block-paragraph">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">really appreciate it. So again, thank you so much for watching this video and enjoy the cool music</p>



<p class="wp-block-paragraph">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/ddd-debugger-tutorial-fast-guide-to-debugging-c-c-code/">DDD Debugger Tutorial: Fast Guide to Debugging C++ &amp; C Code</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/ddd-debugger-tutorial-fast-guide-to-debugging-c-c-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Caveman Debugging: Simple Trick to Debug C++ Code Like a Pro!</title>
		<link>https://www.NeuralLantern.com/caveman-debugging-simple-trick-to-debug-c-code-like-a-pro/</link>
					<comments>https://www.NeuralLantern.com/caveman-debugging-simple-trick-to-debug-c-code-like-a-pro/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Wed, 11 Jun 2025 19:56:00 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly debugging]]></category>
		<category><![CDATA[beginner coding]]></category>
		<category><![CDATA[c++ debugging]]></category>
		<category><![CDATA[c++ tutorial]]></category>
		<category><![CDATA[caveman debugging]]></category>
		<category><![CDATA[code troubleshooting]]></category>
		<category><![CDATA[coding hacks]]></category>
		<category><![CDATA[coding tips]]></category>
		<category><![CDATA[debug c++]]></category>
		<category><![CDATA[debug code fast]]></category>
		<category><![CDATA[fix code bugs]]></category>
		<category><![CDATA[print statement debugging]]></category>
		<category><![CDATA[programming for beginners]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[software development]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=151</guid>

					<description><![CDATA[<p>Master caveman debugging! Easy C++ trick to fix code fast with print statements. Clear tips for beginners &#038; pros. Watch now to squash bugs!</p>
<p>The post <a href="https://www.NeuralLantern.com/caveman-debugging-simple-trick-to-debug-c-code-like-a-pro/">Caveman Debugging: Simple Trick to Debug C++ Code Like a Pro!</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="Caveman Debugging: Simple Trick to Debug C++ Code Like a Pro!" width="1380" height="776" src="https://www.youtube.com/embed/hsGaRukvpF8?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">Hey coders! Ever hit a wall with a program that just won’t work? In this video, I’m spilling the beans on caveman debugging—a super simple, no-fuss way to hunt down bugs in your C++ code (or any language, from assembly to Python)! No need to wrestle with complex debuggers; this method is all about using print statements to trace what your code is doing, step by step.</p>



<p class="wp-block-paragraph">I’ll show you a real C++ program where things go wrong (think integer overflows and mystery crashes) and walk you through how to sprinkle in cout statements to spot the problem fast. You’ll learn how to label decision points like loops and if-statements, break down complex expressions with temporary variables, and format your debug output so it’s easy to read. Plus, I share a neat trick called short circuiting to toggle your debug prints on or off without deleting them—saving you tons of time!</p>



<p class="wp-block-paragraph">Whether you’re a beginner just starting out or a pro debugging a massive codebase, caveman debugging is a lifesaver. It’s quick, it’s intuitive, and it fits my “let’s figure this out” vibe perfectly. Stick around to see how I catch a sneaky bug in a for-loop and fix it in minutes.</p>



<p class="wp-block-paragraph">Why watch?</p>



<ul class="wp-block-list">
<li>Learn a beginner-friendly debugging technique that works in any language.</li>



<li>See real code examples with clear, relatable explanations.</li>



<li>Get tips to make your debug output readable and avoid hours of frustration.</li>



<li>Discover how to short circuit print statements for reusable debugging.</li>
</ul>



<p class="wp-block-paragraph">If you’re ready to level up your coding game and squash bugs like a champ, smash that play button! Don’t forget to subscribe and hit the bell for more coding tutorials, from beginner hacks to advanced tricks. Drop a comment if you’ve ever used caveman debugging or have a bug you need help with—I read every one! Check out my next video on using a proper debugger for even more debugging goodness.</p>



<p class="wp-block-paragraph">Scan the QR code on-screen or visit my website (linked below) for more tutorials, services, and coding resources. Let’s keep the coding community growing—your support means the world! #CavemanDebugging #CodingTips #DebuggingHacks</p>



<p class="wp-block-paragraph">Hey everybody! In this video I&#8217;m gonna try to familiarize you with a concept</p>



<p class="wp-block-paragraph">called caveman debugging. It&#8217;s just as bad as it sounds but it&#8217;s really really</p>



<p class="wp-block-paragraph">really useful. So suppose for the sake of argument you&#8217;re writing a program I&#8217;m</p>



<p class="wp-block-paragraph">gonna show a C++ program here but this this concept is not just for C++</p>



<p class="wp-block-paragraph">debugging it&#8217;s also for assembly and any other kind of language that you can come</p>



<p class="wp-block-paragraph">other kind of language that you can come up with but suppose I have a program and I&#8217;m trying to</p>



<p class="wp-block-paragraph">figure out why it&#8217;s not working so if you look at this program right here that I&#8217;ve kind of written</p>



<p class="wp-block-paragraph">up already we have a main function here and we have like a little hello message that&#8217;s not my</p>



<p class="wp-block-paragraph">name I love that name though and we have a variable a and then we just sort of do some nonsense to it</p>



<p class="wp-block-paragraph">to try and compute a value for a when I say nonsense I mean literally I&#8217;m just I just made</p>



<p class="wp-block-paragraph">I&#8217;m just I just made up instructions the point of this video is not to show you some advanced program</p>



<p class="wp-block-paragraph">It&#8217;s just to show you that you know</p>



<p class="wp-block-paragraph">This is how you can possibly debug a program that has gone awry</p>



<p class="wp-block-paragraph">So you can imagine at home that this code you&#8217;re seeing right here might be your larger project your larger</p>



<p class="wp-block-paragraph">Code base whatever it is that you&#8217;re doing that is not working for some reason and you&#8217;re not sure why</p>



<p class="wp-block-paragraph">So, um, let me run the program real fast</p>



<p class="wp-block-paragraph">It basically is just like a little for loop and then it just sort of</p>



<p class="wp-block-paragraph">of you know not randomly but it just kind of increases the value of a for no reason</p>



<p class="wp-block-paragraph">a bunch of times and then it calls a function that will crash later</p>



<p class="wp-block-paragraph">so let me show you what happens when we try to run this program okay do do do</p>



<p class="wp-block-paragraph">okay i want to go clear and make run if you don&#8217;t know how to do a make file or compile</p>



<p class="wp-block-paragraph">or link or anything like that uh then go see my other videos so clear and make run</p>



<p class="wp-block-paragraph">What did I do wrong?</p>



<p class="wp-block-paragraph">TempResult was not declared in this scope.</p>



<p class="wp-block-paragraph">Okay, well, this is now a video on reading compiler errors.</p>



<p class="wp-block-paragraph">Line 59, I probably left something out.</p>



<p class="wp-block-paragraph">Oh, because I just changed it.</p>



<p class="wp-block-paragraph">I forgot to put it back in there.</p>



<p class="wp-block-paragraph">Return tempResult, we should just return input times two.</p>



<p class="wp-block-paragraph">And I&#8217;m just making this up.</p>



<p class="wp-block-paragraph">It&#8217;s not really like a valid algorithm.</p>



<p class="wp-block-paragraph">Okay, so we run our program.</p>



<p class="wp-block-paragraph">We print the final result and we realize for some reason the final result is wrong.</p>



<p class="wp-block-paragraph">result is wrong. So I don&#8217;t, I mean, I just made this up. So I don&#8217;t really know what the right</p>



<p class="wp-block-paragraph">answer is. But just imagine that you are looking at some sort of an output, some sort of a final</p>



<p class="wp-block-paragraph">state, maybe a crash. And you realize, oh, my program doesn&#8217;t work, but it&#8217;s too complicated</p>



<p class="wp-block-paragraph">to figure out. Caveman debugging to the rescue. Caveman debugging kind of is as bad as it sounds.</p>



<p class="wp-block-paragraph">It&#8217;s just really, really simple. But it&#8217;s also really useful, especially if you just want to do</p>



<p class="wp-block-paragraph">on you don&#8217;t want to dive deep into a full-on debugger or do something more advanced it literally</p>



<p class="wp-block-paragraph">is just printing a lot of things while your program is running i do it all the time i usually</p>



<p class="wp-block-paragraph">don&#8217;t even go to a debugger unless i really get in trouble with like some huge mess um okay so</p>



<p class="wp-block-paragraph">the first thing i&#8217;m going to say is in this for loop we uh you know we&#8217;re kind of like iterating</p>



<p class="wp-block-paragraph">And so probably this is a good idea to announce that we&#8217;re iterating in the for loop.</p>



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



<p class="wp-block-paragraph">In C++, you know, we have the Cout object that we can use to stream texts to standard output,</p>



<p class="wp-block-paragraph">which usually goes to the terminal.</p>



<p class="wp-block-paragraph">So use whatever construct you&#8217;re using for your particular language.</p>



<p class="wp-block-paragraph">So we&#8217;re going to do Cout.</p>



<p class="wp-block-paragraph">And I should say also, if you&#8217;re programming in assembly,</p>



<p class="wp-block-paragraph">if you are programming in assembly,</p>



<p class="wp-block-paragraph">it&#8217;s a little bit more complicated than just writing a Cout.</p>



<p class="wp-block-paragraph">little bit more complicated than just writing a C out you probably have to have some pre-computed</p>



<p class="wp-block-paragraph">messages and then you can use a library to print a number to the screen or use printf to print stuff</p>



<p class="wp-block-paragraph">to the screen but you can do it just takes a little bit longer so anyway conceptually I&#8217;m</p>



<p class="wp-block-paragraph">just going to say this is the first iteration of my loop so I&#8217;m going to sort of announce it I&#8217;m</p>



<p class="wp-block-paragraph">going to say main and then I&#8217;m going to call it main four or how about primary four or first four</p>



<p class="wp-block-paragraph">but I want to try to label the for loop.</p>



<p class="wp-block-paragraph">And maybe instead of leaving those parentheses blank,</p>



<p class="wp-block-paragraph">I could say iteration number i right there,</p>



<p class="wp-block-paragraph">or maybe I could do iteration i.</p>



<p class="wp-block-paragraph">That would be pretty good.</p>



<p class="wp-block-paragraph">Then I just have to replace the i with the actual variable i</p>



<p class="wp-block-paragraph">so that the i keeps increasing.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to like do another stream operator here</p>



<p class="wp-block-paragraph">and I&#8217;m going to say i.</p>



<p class="wp-block-paragraph">Then I&#8217;ll print a new line.</p>



<p class="wp-block-paragraph">we&#8217;ve got, you know, one iteration of our loop.</p>



<p class="wp-block-paragraph">Maybe I should also print what is the current value of A</p>



<p class="wp-block-paragraph">because the point of this, you know, weird nonsense code</p>



<p class="wp-block-paragraph">is we&#8217;re coming up with a value for A, right?</p>



<p class="wp-block-paragraph">So I should just print what A is at the top of each iteration of the for loop.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say A is equal to, and then do another A at the end of it.</p>



<p class="wp-block-paragraph">And then maybe at the bottom of the for loop,</p>



<p class="wp-block-paragraph">when the for loop is actually ending one of its iterations,</p>



<p class="wp-block-paragraph">I can just say we&#8217;re at the bottom of the iteration so maybe I&#8217;ll put to end</p>



<p class="wp-block-paragraph">iteration and then print the final value of a and then at the top I&#8217;ll say begin</p>



<p class="wp-block-paragraph">iteration at this point you might start to feel like hey aren&#8217;t you using too</p>



<p class="wp-block-paragraph">many words here like why can&#8217;t I just print a bunch of numbers I mean you</p>



<p class="wp-block-paragraph">could but when you&#8217;re coding you need all the brainpower you can get to not</p>



<p class="wp-block-paragraph">just code but to debug coding is already hard enough without making it harder</p>



<p class="wp-block-paragraph">harder for yourself than you need it to be. So, you know, I see people all the time, they&#8217;re</p>



<p class="wp-block-paragraph">trying to debug their code and they just like start printing numbers. And after not very long</p>



<p class="wp-block-paragraph">at all, they&#8217;re looking at the debug output and they&#8217;re just like, what did that number mean?</p>



<p class="wp-block-paragraph">Where is the number I&#8217;m looking for? It&#8217;s just a bunch of numbers. It&#8217;s harder to debug when you</p>



<p class="wp-block-paragraph">do it that way. Do it the nice and pretty way. It just costs you a couple of extra keystrokes to do,</p>



<p class="wp-block-paragraph">you know, nice letters and new lines and things, nice words, labels. Isn&#8217;t that still a lot better</p>



<p class="wp-block-paragraph">Isn&#8217;t that still a lot better than debugging for an extra six hours?</p>



<p class="wp-block-paragraph">Because you can&#8217;t really understand what you&#8217;re seeing.</p>



<p class="wp-block-paragraph">Anyway, let me show you what this looks like so far with just those two lines added.</p>



<p class="wp-block-paragraph">Now we can kind of see, alright, alright, on iteration number 61, where I was 61, then</p>



<p class="wp-block-paragraph">this was the first value of A and then after that this was the second value of A, you know,</p>



<p class="wp-block-paragraph">when we were finished with the iteration.</p>



<p class="wp-block-paragraph">It seems to have gone up by a certain amount.</p>



<p class="wp-block-paragraph">you know it was like a negative blah blah blah 836 and then negative blah blah blah 708 so it</p>



<p class="wp-block-paragraph">kind of increased in value all right that&#8217;s a little bit helpful now it&#8217;s a really good uh</p>



<p class="wp-block-paragraph">place to uh print our decision points so anytime in your code where you have an if or an else or</p>



<p class="wp-block-paragraph">a function call or anything where you are kind of like you know making a decision or processing your</p>



<p class="wp-block-paragraph">data in some way it&#8217;s probably a good idea to announce your decisions so i could say up here i</p>



<p class="wp-block-paragraph">say up here i can go maybe i&#8217;ll say uh main first four and then i&#8217;ll call it uh maybe i&#8217;ll do a</p>



<p class="wp-block-paragraph">double colon there and i&#8217;ll say top if just to make it easy to read that i&#8217;m kind of like at</p>



<p class="wp-block-paragraph">the first if statement um maybe i&#8217;ll even put parentheses i&#8217;ll say a is more than 20 just to</p>



<p class="wp-block-paragraph">kind of like name what i&#8217;m actually doing and then i could replace the a with the actual value of a</p>



<p class="wp-block-paragraph">actual value of a so i could say a like that and maybe uh when i&#8217;m reading this later i might want</p>



<p class="wp-block-paragraph">to kind of actually see the variable name so i could say uh you could just like put a as a string</p>



<p class="wp-block-paragraph">and then maybe its value in parentheses or something like that do a new line um and then</p>



<p class="wp-block-paragraph">maybe after that top thing i&#8217;ll say uh true to indicate that we&#8217;re inside of the the if statement</p>



<p class="wp-block-paragraph">the if statement and then maybe at the bottom of that if statement we&#8217;ll just say</p>



<p class="wp-block-paragraph">a is now true and we&#8217;ll say like a is now you know whatever the new value of a was so just</p>



<p class="wp-block-paragraph">basically we&#8217;re announcing that we decided to go into this if block and then we announce what we</p>



<p class="wp-block-paragraph">ended up changing a to and also you probably anytime you see a compound expression like this</p>



<p class="wp-block-paragraph">You know B time something or a plus something or just you know a big part of multiple parts of the expression any expression</p>



<p class="wp-block-paragraph">That&#8217;s more than just like one variable or one number. It&#8217;s probably a good idea if you break that up into temporary variables, too</p>



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



<p class="wp-block-paragraph">Print out each variable and I know that&#8217;s a lot of stuff to read but again it beats debugging for an extra six hours</p>



<p class="wp-block-paragraph">I&#8217;m gonna leave that be for now though</p>



<p class="wp-block-paragraph">leave that be and</p>



<p class="wp-block-paragraph">I&#8217;m just gonna continue adding comments into the rest of the code. So I&#8217;m gonna do the second if block here</p>



<p class="wp-block-paragraph">So I&#8217;m going to do the second if block here.</p>



<p class="wp-block-paragraph">I&#8217;m going to say we&#8217;re in the first floor.</p>



<p class="wp-block-paragraph">We&#8217;re in the bottom if more than 20 true.</p>



<p class="wp-block-paragraph">And then we&#8217;ll print out what is the value of a after we&#8217;re finished.</p>



<p class="wp-block-paragraph">We&#8217;ll say a is now is now whatever value for a.</p>



<p class="wp-block-paragraph">And then I&#8217;ll do the same thing for this function call.</p>



<p class="wp-block-paragraph">Because, you know, when I call this function, it&#8217;s going to change the value somehow.</p>



<p class="wp-block-paragraph">So we&#8217;re going to do cout about to a plus equals f, you know, call to f.</p>



<p class="wp-block-paragraph">And then inside the arguments, I&#8217;m obviously putting i plus 3.</p>



<p class="wp-block-paragraph">But because i is a variable, we could just print that.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do quote, quote, and then just stick the actual i in there.</p>



<p class="wp-block-paragraph">And then another new line.</p>



<p class="wp-block-paragraph">a finished a plus equals f and then I&#8217;ll just say you know a is now you know a you know print the</p>



<p class="wp-block-paragraph">new value of a you could also say a equal equal a and then print the value whatever you want but</p>



<p class="wp-block-paragraph">the point is I&#8217;m just printing everything here so now let&#8217;s go down a little bit more because</p>



<p class="wp-block-paragraph">there is a function call if you look at this function call down here here&#8217;s like some nonsense</p>



<p class="wp-block-paragraph">being used here&#8217;s some other like you know disabled code really what i&#8217;m doing at the</p>



<p class="wp-block-paragraph">very end is i&#8217;m just taking the input that the function received and i&#8217;m just multiplying it by</p>



<p class="wp-block-paragraph">two and returning it so again imagine that your code is a lot more complicated than this</p>



<p class="wp-block-paragraph">maybe input times two is actually input times two divided by three and then some other function</p>



<p class="wp-block-paragraph">call and then some other this and some other that and whatever so a lot of people will just kind of</p>



<p class="wp-block-paragraph">stuff like a really complicated expression in one line or one assignment or one return statement</p>



<p class="wp-block-paragraph">And that&#8217;s super confusing because you can&#8217;t really be sure that every part of the expression is as you thought.</p>



<p class="wp-block-paragraph">So it&#8217;s a really good idea to break it all up into parts and print each part.</p>



<p class="wp-block-paragraph">So you could imagine that we have like a C out here and we&#8217;ll say C out, you know, begin F.</p>



<p class="wp-block-paragraph">I&#8217;ll say like begin for F and then F receives an input of input.</p>



<p class="wp-block-paragraph">Do an end L.</p>



<p class="wp-block-paragraph">And then I&#8217;ll make a temporary variable here.</p>



<p class="wp-block-paragraph">variable here I&#8217;ll say int temp results equals input times two and then I&#8217;ll</p>



<p class="wp-block-paragraph">print that f and maybe I&#8217;ll do the input again</p>



<p class="wp-block-paragraph">temp result is now and then say temp result so I&#8217;m just gonna print what the</p>



<p class="wp-block-paragraph">temp result actually was and I could print something about I just multiplied</p>



<p class="wp-block-paragraph">thing about I just multiplied the input by two and then you know the more</p>



<p class="wp-block-paragraph">complicated your expression is the more temporary variables you want to use and</p>



<p class="wp-block-paragraph">just kind of print every single one of them and print you know this new</p>



<p class="wp-block-paragraph">variable is the result of dividing by two this new variable is the result of</p>



<p class="wp-block-paragraph">calling some other function and so forth</p>



<p class="wp-block-paragraph">so then we have like a basically you know basically a pretty good idea maybe</p>



<p class="wp-block-paragraph">at the end though instead of multiplying by two again you want to make it more</p>



<p class="wp-block-paragraph">want to make it more consistent with your debug output so like here temp result is obviously going</p>



<p class="wp-block-paragraph">to be the result that i return why would you do the expression all over again for the return part</p>



<p class="wp-block-paragraph">when you could easily get it wrong why not instead just return the temp result that you made right so</p>



<p class="wp-block-paragraph">then that way your output completely matches what you&#8217;re actually returning and for now i think</p>



<p class="wp-block-paragraph">that&#8217;s all we need to do let me run it one more time and then you&#8217;ll see a bunch of stuff now uh</p>



<p class="wp-block-paragraph">Now, we have a lot of information that we can use to trace how our program was thinking and hopefully find the problem.</p>



<p class="wp-block-paragraph">But isn&#8217;t this like a little bit starting to get a little bit hard to read, right?</p>



<p class="wp-block-paragraph">You can see that there are kind of blocks happening whenever we iterate.</p>



<p class="wp-block-paragraph">So, you know, for me, I always try to keep in mind you need all the brainpower you can get.</p>



<p class="wp-block-paragraph">Why not just format it a little bit better so it&#8217;s really easy to just quickly look at one block and see, you know,</p>



<p class="wp-block-paragraph">the couts kind of like belong together so i&#8217;m just going to add one more cout in the main for loop</p>



<p class="wp-block-paragraph">here just at the very bottom i&#8217;m going to go couts and l just so that i get a new line and if i run</p>



<p class="wp-block-paragraph">the program again notice how it&#8217;s easier to see the blocks like oh that&#8217;s clearly one iteration</p>



<p class="wp-block-paragraph">right here you know your mind just grabs onto it faster and that increases your brain power and</p>



<p class="wp-block-paragraph">makes it easier to debug and read the debug output so i can go all right all right okay so</p>



<p class="wp-block-paragraph">all right okay so we&#8217;re right up here oh around uh iteration um number 83 uh a was this number</p>



<p class="wp-block-paragraph">and then it got increased by uh this other number and the reason that that happened is because the</p>



<p class="wp-block-paragraph">function returned 172 so it basically increased it by 172 and then it ended up being that number</p>



<p class="wp-block-paragraph">oh okay i think i see what went wrong oh no right in this particular program if we scroll up just a</p>



<p class="wp-block-paragraph">little bit we can probably see that the integer is overflowing right the integer was getting bigger</p>



<p class="wp-block-paragraph">right the integer was getting bigger and bigger and bigger here and then eventually</p>



<p class="wp-block-paragraph">it jumped into the negative at some point so right here we can see oh okay when did this</p>



<p class="wp-block-paragraph">number become negative suppose we didn&#8217;t want it to be negative um what was this this is like</p>



<p class="wp-block-paragraph">a million this is a billion no wait wait wait this is uh no that&#8217;s a million right there so it&#8217;s like</p>



<p class="wp-block-paragraph">299 million and then it overflowed oh no no it didn&#8217;t it didn&#8217;t overflow it started at 299</p>



<p class="wp-block-paragraph">it started at 299 then at the bottom it was sitting at 899 million that&#8217;s kind of close to a billion</p>



<p class="wp-block-paragraph">and it did jump up from 300 million to 900 million so that&#8217;s a jump up of like 600 million</p>



<p class="wp-block-paragraph">oh you know it&#8217;s like kind of jumping up faster with each iteration oh and i&#8217;m using a 32-bit</p>



<p class="wp-block-paragraph">signed integer which has a maximum value of around 2 billion so now i could possibly realize at this</p>



<p class="wp-block-paragraph">the number is just like it became too big and I need to change my data type or I need to change</p>



<p class="wp-block-paragraph">my algorithm for some reason right so you can kind of get to the bottom of things pretty quickly</p>



<p class="wp-block-paragraph">so here&#8217;s another problem that people encounter when they&#8217;re using caveman debugging</p>



<p class="wp-block-paragraph">basically you you add all these cout statements or print statements or whatever you&#8217;re doing in</p>



<p class="wp-block-paragraph">whatever language you have and then when you&#8217;re finished you&#8217;re kind of like well I guess uh</p>



<p class="wp-block-paragraph">I need to delete all of these Couts because I don&#8217;t want all this you know</p>



<p class="wp-block-paragraph">Junk being printed in my program after I fix the problem or maybe you&#8217;re trying to debug a different part of your program</p>



<p class="wp-block-paragraph">So then you start commenting out all the print statements or you start</p>



<p class="wp-block-paragraph">You know deleting them or whatever and then whoops later on you realize maybe that part of my program</p>



<p class="wp-block-paragraph">Was not actually fixed and I have to add all the Couts all over again from scratch that costs time</p>



<p class="wp-block-paragraph">So that&#8217;s not fun. So here&#8217;s a trick that I like to use. It&#8217;s called a short circuit</p>



<p class="wp-block-paragraph">it&#8217;s called a short circuit it&#8217;s a sort of like a beginning C++ thing or just</p>



<p class="wp-block-paragraph">when you&#8217;re first learning how to use logical operators for boolean</p>



<p class="wp-block-paragraph">expressions so I&#8217;m gonna do a boolean and I&#8217;m just gonna name it after what</p>



<p class="wp-block-paragraph">problem I&#8217;m trying to solve so we could just call this you know main C outs or</p>



<p class="wp-block-paragraph">something like that let&#8217;s I don&#8217;t know primary problem I&#8217;ll call it primary</p>



<p class="wp-block-paragraph">the boolean as true because then what will happen is uh we can then short circuit all of the cout</p>



<p class="wp-block-paragraph">statements we can say primary problem couts and cout like that and the way the short circuit works</p>



<p class="wp-block-paragraph">works is if you have a logical and expression you can see right here we have two sides</p>



<p class="wp-block-paragraph">of that statement now one&#8217;s on the left which is just the boolean and one&#8217;s on the right which is</p>



<p class="wp-block-paragraph">have a logical and then you know one and zero is equal to zero true and false is equal to false so</p>



<p class="wp-block-paragraph">both things have to be true for the expression to evaluate to true which means if the first thing</p>



<p class="wp-block-paragraph">is false there&#8217;s no point in even looking at the second thing at all because if i if i set that to</p>



<p class="wp-block-paragraph">false then the second part the c out is it doesn&#8217;t matter the whole expression is going to evaluate</p>



<p class="wp-block-paragraph">to false anyway so uh the logical operator itself will just you know block out the rest of the</p>



<p class="wp-block-paragraph">you know, block out the rest of the statement.</p>



<p class="wp-block-paragraph">That&#8217;s called a short circuit.</p>



<p class="wp-block-paragraph">So I&#8217;m going to copy the short circuiting to all of my C out statements like this.</p>



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



<p class="wp-block-paragraph">And do that.</p>



<p class="wp-block-paragraph">And then the C out there.</p>



<p class="wp-block-paragraph">And I guess I&#8217;ll leave the final result there.</p>



<p class="wp-block-paragraph">And for the moment, you know, this is just a regular function.</p>



<p class="wp-block-paragraph">apply the short circuiting to this other f unless I do a separate boolean but</p>



<p class="wp-block-paragraph">keep in mind if this was a class and you had two different methods that you</p>



<p class="wp-block-paragraph">wanted to short circuit see outs inside of at the same time you could just use a</p>



<p class="wp-block-paragraph">member variable and name it after the problem you&#8217;re currently trying to solve</p>



<p class="wp-block-paragraph">and then just short circuit each see out in the appropriate method with that</p>



<p class="wp-block-paragraph">boolean so I guess in this regular program that doesn&#8217;t have a class I</p>



<p class="wp-block-paragraph">could move the boolean into the global if I wanted to but I&#8217;m not going to right</p>



<p class="wp-block-paragraph">if I wanted to, but I&#8217;m not going to right now.</p>



<p class="wp-block-paragraph">And if you&#8217;re writing assembly or some simpler language</p>



<p class="wp-block-paragraph">and you&#8217;re thinking, hey, I can&#8217;t short circuit an assembly</p>



<p class="wp-block-paragraph">or some other language, well, you could write a function</p>



<p class="wp-block-paragraph">that just takes a couple arguments.</p>



<p class="wp-block-paragraph">You could write a function that takes a string to print</p>



<p class="wp-block-paragraph">and maybe a number to print or just, you know,</p>



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



<p class="wp-block-paragraph">And then in the function itself that prints,</p>



<p class="wp-block-paragraph">you could call it debug print if you want.</p>



<p class="wp-block-paragraph">Have it look at a global variable or define</p>



<p class="wp-block-paragraph">that you&#8217;ve set up at the top of the assembly module.</p>



<p class="wp-block-paragraph">set up at the top of the assembly module, which you can just turn on and off,</p>



<p class="wp-block-paragraph">like just do a data byte and set it to a zero or set it to a one.</p>



<p class="wp-block-paragraph">And then the function debug print will just look at that variable to decide</p>



<p class="wp-block-paragraph">whether or not it&#8217;s going to actually print or not.</p>



<p class="wp-block-paragraph">So, you know, it&#8217;s a little more complicated in assembly,</p>



<p class="wp-block-paragraph">but you can do it basically the same concept.</p>



<p class="wp-block-paragraph">Let&#8217;s run this again just to make sure it still works.</p>



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



<p class="wp-block-paragraph">So now suppose I want to turn off all the Cout statements.</p>



<p class="wp-block-paragraph">If I just change the true to false,</p>



<p class="wp-block-paragraph">the true to false notice how it&#8217;s all gone except for the stuff inside of f which i told you i</p>



<p class="wp-block-paragraph">wasn&#8217;t going to touch but notice how easy it was to mute it and then if i want to bring it back</p>



<p class="wp-block-paragraph">later i just go true to unmute it of course if you want to do a little bit more typing you can</p>



<p class="wp-block-paragraph">also do if statements like if this condition is true and that condition is true then print the</p>



<p class="wp-block-paragraph">debug statement so then you can have a more complicated way of muting and not muting but</p>



<p class="wp-block-paragraph">I&#8217;m going to leave it as is right now.</p>



<p class="wp-block-paragraph">Let&#8217;s see, what else do we got here?</p>



<p class="wp-block-paragraph">I think actually at this point, this is the basic idea of caveman debugging.</p>



<p class="wp-block-paragraph">Just basically print everything.</p>



<p class="wp-block-paragraph">Print all of your decision points.</p>



<p class="wp-block-paragraph">Use pretty labels that are really, really easy for you to understand.</p>



<p class="wp-block-paragraph">Use formatting so that your brain doesn&#8217;t have to struggle to understand what you&#8217;re seeing.</p>



<p class="wp-block-paragraph">If you just print a bunch of numbers, you&#8217;re going to be shooting yourself in the foot.</p>



<p class="wp-block-paragraph">you&#8217;re going to be shooting yourself in the foot and use short circuiting or if statements to</p>



<p class="wp-block-paragraph">selectively mute them so you can do less typing and and debugging the debugging and so forth but</p>



<p class="wp-block-paragraph">yeah i think i think this is all i really wanted to show you in this particular video</p>



<p class="wp-block-paragraph">i hope you feel like an expert in caveman debugging i certainly am and it you know it</p>



<p class="wp-block-paragraph">kind of fits my personality a little bit i&#8217;m like what&#8217;s going on um and like i said before</p>



<p class="wp-block-paragraph">debugger it&#8217;s probably a better idea but I usually don&#8217;t unless I&#8217;m in big trouble</p>



<p class="wp-block-paragraph">and I have a huge mess on my hands I usually just go directly to caveman</p>



<p class="wp-block-paragraph">debugging we&#8217;ll look at the same piece of code in my next video that I&#8217;m going</p>



<p class="wp-block-paragraph">to publish which is going to talk about using a proper debugger so watch the</p>



<p class="wp-block-paragraph">next one also but for now I hope you&#8217;ve enjoyed this video thank you for</p>



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



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



<p class="wp-block-paragraph">whoops what the heck</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 i do hope you did learn something and have</p>



<p class="wp-block-paragraph">some fun uh if you could do me a please a small little favor could you please</p>



<p class="wp-block-paragraph">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 that you&#8217;re looking</p>



<p class="wp-block-paragraph">at right now it would really mean the world to me and</p>



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



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



<p class="wp-block-paragraph">please do do me a kindness and and subscribe you know sometimes I&#8217;m</p>



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



<p class="wp-block-paragraph">subscribed or followed it just wakes me up and I get filled with joy that&#8217;s</p>



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



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



<p class="wp-block-paragraph">and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s what will happen also uh if you look at the middle</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</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">if you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also</p>



<p class="wp-block-paragraph">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 um enjoy the cool music as as i fade into the darkness which is</p>



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/caveman-debugging-simple-trick-to-debug-c-code-like-a-pro/">Caveman Debugging: Simple Trick to Debug C++ Code Like a Pro!</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/caveman-debugging-simple-trick-to-debug-c-code-like-a-pro/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Hex to Decimal Made Easy: Fun &#038; Simple Conversion Guide!</title>
		<link>https://www.NeuralLantern.com/hex-to-decimal-made-easy-fun-simple-conversion-guide/</link>
					<comments>https://www.NeuralLantern.com/hex-to-decimal-made-easy-fun-simple-conversion-guide/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Fri, 02 May 2025 09:23:46 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Conversions]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[beginner coding]]></category>
		<category><![CDATA[binary to decimal]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding guide]]></category>
		<category><![CDATA[computer science basics]]></category>
		<category><![CDATA[computer science tutorial]]></category>
		<category><![CDATA[hex to decimal]]></category>
		<category><![CDATA[hexadecimal to decimal]]></category>
		<category><![CDATA[hexadecimal tutorial]]></category>
		<category><![CDATA[learn to code]]></category>
		<category><![CDATA[number conversion]]></category>
		<category><![CDATA[number systems]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[tech education]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=95</guid>

					<description><![CDATA[<p>Learn to convert hexadecimal to decimal with this fun, easy guide! Perfect for beginners in coding and computer science. #HexToDecimal #LearnToCode</p>
<p>The post <a href="https://www.NeuralLantern.com/hex-to-decimal-made-easy-fun-simple-conversion-guide/">Hex to Decimal Made Easy: Fun &amp; Simple Conversion 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="Hex to Decimal Made Easy: Fun &amp; Simple Conversion Guide!" width="1380" height="776" src="https://www.youtube.com/embed/yDk-fB52i0A?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">Confused by hexadecimal numbers? Don’t worry! This fun, step-by-step guide makes converting hex to decimal super easy, even for beginners. With clear examples and a chill vibe, you’ll master this computer science skill in no time. Perfect for students, coders, or anyone curious about number systems. Hit subscribe for more coding tutorials, and check out our site for extra resources! #HexToDecimal #CodingForBeginners #ComputerScience #LearnToCode</p>



<p class="wp-block-paragraph">Introduction to Hexadecimal Conversion 00:00:00<br>Purpose of Conversion 00:00:11<br>Number System Basics 00:00:39<br>Hexadecimal Explanation 00:01:12<br>Converting Hex to Decimal 00:01:59<br>First Example Setup 00:02:35<br>Decimal Place Value Recap 00:03:02<br>Hexadecimal Place Value 00:05:14<br>Formula for Conversion 00:05:43<br>Translating Hex Letters 00:08:17<br>First Example Calculation 00:09:51<br>Second Example Introduction 00:11:14<br>Second Example Conversion 00:11:58<br>Second Example Result 00:13:11<br>Conclusion and Call to Action 00:14:00</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. Let&#8217;s talk about converting hexadecimal to decimal.</p>



<p class="wp-block-paragraph">So why would you do this? Of course, sometimes in computer science and other realms, you may be</p>



<p class="wp-block-paragraph">faced with a number that looks like this, and it&#8217;s got some letters in there, and it&#8217;s weird,</p>



<p class="wp-block-paragraph">and you&#8217;re thinking, oops, not a V. That wouldn&#8217;t work. Not a G. And you&#8217;re thinking like, what does</p>



<p class="wp-block-paragraph">what does this number mean in decimal well this is a number that is real and we can just change</p>



<p class="wp-block-paragraph">the way it&#8217;s represented uh to decimal so that we can understand what it is so just like a quick</p>



<p class="wp-block-paragraph">recap if you haven&#8217;t watched my other videos yet uh in decimal we have a base 10 system which just</p>



<p class="wp-block-paragraph">basically means we have these characters zero one two three four five six seven eight nine there</p>



<p class="wp-block-paragraph">base is 10. In binary, of course, we have base two, which is just, you know, we have a zero and a one</p>



<p class="wp-block-paragraph">because in the computer, which is why we learn binary, we just have on and off basically for</p>



<p class="wp-block-paragraph">every single, you know, part of the computer. There&#8217;s just like a certain voltage or there&#8217;s</p>



<p class="wp-block-paragraph">not a certain voltage and that&#8217;s it. And then for hexadecimal, which is a way to represent the same</p>



<p class="wp-block-paragraph">numbers, but just in a more compact way. It&#8217;s a little bit more compact than decimal. It&#8217;s a lot</p>



<p class="wp-block-paragraph">than binary we can say that this is base 16 which means we have 16 total characters that we can work</p>



<p class="wp-block-paragraph">with zero one two three four five six seven eight nine and once we run out of numbers we just start</p>



<p class="wp-block-paragraph">using letters so a b c d e f so there are 16 total characters if we include the zero which means we</p>



<p class="wp-block-paragraph">So that&#8217;s the basics of you know the number basis let&#8217;s uh let&#8217;s work out how to convert a hex</p>



<p class="wp-block-paragraph">number to decimal. So I&#8217;m going to say ox because in hex when you write down a hex number you should</p>



<p class="wp-block-paragraph">usually put ox in front of it unless the program you&#8217;re working with doesn&#8217;t understand that but</p>



<p class="wp-block-paragraph">usually especially for a human reader you should do it this way. So I&#8217;m going to just type like a</p>



<p class="wp-block-paragraph">few random maybe I have to I have to keep the number small because hex will explode it&#8217;ll be</p>



<p class="wp-block-paragraph">not careful. So I&#8217;m going to put like a I don&#8217;t know, maybe a few decimal numbers there or a few</p>



<p class="wp-block-paragraph">like digits that are zero to nine, then I&#8217;ll just to make it more interesting, I&#8217;ll put some letters</p>



<p class="wp-block-paragraph">in there. How about like an E there? And then I don&#8217;t know, like, we&#8217;ll do a B there. Okay, so</p>



<p class="wp-block-paragraph">how many do I have? 12341234? How about we get rid of? Now, let&#8217;s go for it. This is going to be an</p>



<p class="wp-block-paragraph">So this is our starting number hexadecimal. What we need to do is understand that, well,</p>



<p class="wp-block-paragraph">a recap if you haven&#8217;t watched my other videos yet. In decimal we have, let&#8217;s say, 0, 1, 2, 3,</p>



<p class="wp-block-paragraph">4, 5, 6. You know that the first digit has a strength of 1. You multiply 6 by 1 to understand</p>



<p class="wp-block-paragraph">the real power of that 6. For the 5, you know that it has a power of 10 or a strength of 10</p>



<p class="wp-block-paragraph">10 because it&#8217;s the next digit over you know to the left same thing for the four it&#8217;s like got a</p>



<p class="wp-block-paragraph">strength of 100 and so every time you move to the left the strength of the digit increases by a</p>



<p class="wp-block-paragraph">factor of 10. why does it increase by a factor of 10 because decimal is base 10 because we have 10</p>



<p class="wp-block-paragraph">possible digits we can represent for each character okay so by the time we get to that</p>



<p class="wp-block-paragraph">left, we have a strength of 100,000. So, you know, if you wanted to really understand 100,000,</p>



<p class="wp-block-paragraph">if you really wanted to understand, you know, how powerful, let me, let me give some spacing here.</p>



<p class="wp-block-paragraph">So this feels better. Okay. If you really wanted to understand like, you know, what is the strength?</p>



<p class="wp-block-paragraph">What is like the actual value of this digit right here? You&#8217;re imagining this is like 100,000.</p>



<p class="wp-block-paragraph">this digit here you&#8217;re imagining that this is two of ten thousand you know two times ten thousand</p>



<p class="wp-block-paragraph">and so forth so uh uh just like another recap the first digit is really 10 to the zero power</p>



<p class="wp-block-paragraph">like in terms of the strength because if you multiply um let me pin this to the top</p>



<p class="wp-block-paragraph">if you multiply you know 10 to the something power and you start at zero with the most</p>



<p class="wp-block-paragraph">the weakest digit 10 to the zero power gives a strength of one and then every time you move over</p>



<p class="wp-block-paragraph">to the left you just increase the exponent there by one so 10 to the first power is going to be 10</p>



<p class="wp-block-paragraph">that&#8217;s what that five has got so it&#8217;ll be five times 10 to give us an understanding of how you</p>



<p class="wp-block-paragraph">know powerful that digit is move one over to the left it&#8217;s 10 to the second power so that&#8217;s 100</p>



<p class="wp-block-paragraph">move one over to the left it&#8217;s 10 to the third power and so forth until we get to 10 to the fifth</p>



<p class="wp-block-paragraph">1 times 10 to the fifth power to understand how powerful that is so we can do the same exact thing</p>



<p class="wp-block-paragraph">with hexadecimal except instead of raising 10 to a power we raise 16 to a power because hexadecimal</p>



<p class="wp-block-paragraph">is base 16 whereas decimal is base 10. so that means this e is is uh you know 10 to the or sorry</p>



<p class="wp-block-paragraph">16 to the zero power and then that 3 is 16 to the 1 power and that f is 16 to the 2 power and so</p>



<p class="wp-block-paragraph">16 to the 2 power and so forth so first what we should do is let&#8217;s write out a</p>



<p class="wp-block-paragraph">formula which won&#8217;t work in a calculator because we&#8217;re going to put some letters</p>



<p class="wp-block-paragraph">in there and then later we&#8217;ll translate the letters to actual values so we&#8217;ll</p>



<p class="wp-block-paragraph">start off with the e we&#8217;ll say e times 16 to the something power it&#8217;s going to be</p>



<p class="wp-block-paragraph">16 to the zero power okay so then the next digit is 3 so 3 times 16 to the</p>



<p class="wp-block-paragraph">And then the next thing is going to be F times 16 to the second power.</p>



<p class="wp-block-paragraph">And just as a reminder here, I&#8217;m starting with zero with the smallest digit.</p>



<p class="wp-block-paragraph">And I&#8217;m just working my way up in steps of one.</p>



<p class="wp-block-paragraph">So it&#8217;s zero power or raised to zero and raised to one and raised to two and just so forth all the way to the left.</p>



<p class="wp-block-paragraph">That number will just keep increasing by one.</p>



<p class="wp-block-paragraph">The exponent will increase by one.</p>



<p class="wp-block-paragraph">times 16 to the third power do it again um one times 16 to the fourth power do it again</p>



<p class="wp-block-paragraph">um d times 16 to the fourth power oh what did i do did i erase something</p>



<p class="wp-block-paragraph">0, 1, 2, 3, 4, 5.</p>



<p class="wp-block-paragraph">Oh, that was supposed to be a 5.</p>



<p class="wp-block-paragraph">Okay, maybe it&#8217;s good that I thought I made a mistake</p>



<p class="wp-block-paragraph">because that drew my attention to the bad exponent.</p>



<p class="wp-block-paragraph">Okay, so after the D is a B.</p>



<p class="wp-block-paragraph">B times 16 to the 6th power.</p>



<p class="wp-block-paragraph">And then one more.</p>



<p class="wp-block-paragraph">We&#8217;ll say 6 times 16 to the 7th power.</p>



<p class="wp-block-paragraph">And then another one.</p>



<p class="wp-block-paragraph">A times 16 to the, whoops, to the eighth power.</p>



<p class="wp-block-paragraph">And another one.</p>



<p class="wp-block-paragraph">One times 16 to the ninth power.</p>



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



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



<p class="wp-block-paragraph">So just double check your work real fast.</p>



<p class="wp-block-paragraph">You know, because I make typos all the time and I get things wrong all the time.</p>



<p class="wp-block-paragraph">So just double check.</p>



<p class="wp-block-paragraph">Zero, one, two, three, four, five, six, seven, eight, nine.</p>



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



<p class="wp-block-paragraph">Double check the digits.</p>



<p class="wp-block-paragraph">6 b d 1 3 f 3 e okay so i got that right i&#8217;m not going to erase my work because if i end up screwing</p>



<p class="wp-block-paragraph">up the next part oh man is it going to be a hassle to correct so i&#8217;m just going to copy paste it here</p>



<p class="wp-block-paragraph">and then i&#8217;m going to start translating the letters to numbers anytime you see a number here like one</p>



<p class="wp-block-paragraph">time something it&#8217;s just one but every time you see a letter you have to translate that into</p>



<p class="wp-block-paragraph">in decimal. Remember in hex, we&#8217;ll say, what can I do?</p>



<p class="wp-block-paragraph">I can say A, B, C, D, E, F.</p>



<p class="wp-block-paragraph">And I can say that the A is worth 10.</p>



<p class="wp-block-paragraph">The B is worth 11.</p>



<p class="wp-block-paragraph">The C is worth 12.</p>



<p class="wp-block-paragraph">And the D is worth 13.</p>



<p class="wp-block-paragraph">The E is worth 14 and the F is worth 15.</p>



<p class="wp-block-paragraph">Well, maybe I should do the other numbers too.</p>



<p class="wp-block-paragraph">five, six, seven, eight, nine,</p>



<p class="wp-block-paragraph">just so we have a visual reminder</p>



<p class="wp-block-paragraph">of like what we&#8217;re even looking at.</p>



<p class="wp-block-paragraph">And I won&#8217;t write down what the digits are worth</p>



<p class="wp-block-paragraph">because they&#8217;re worth themselves, right?</p>



<p class="wp-block-paragraph">So like zero through nine, it&#8217;s just worth zero through nine.</p>



<p class="wp-block-paragraph">So now that we have this little translation table up here,</p>



<p class="wp-block-paragraph">anytime we see a letter,</p>



<p class="wp-block-paragraph">we can just translate it very quickly to the decimal value.</p>



<p class="wp-block-paragraph">So A is worth 10, we&#8217;ll put a 10 there.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll add some spacing so that this continues to line up.</p>



<p class="wp-block-paragraph">I see a B here, so the B is gonna be worth 11,</p>



<p class="wp-block-paragraph">11 add another space so it lines up i&#8217;m running out of room but i&#8217;ll try the d is worth 13 add</p>



<p class="wp-block-paragraph">another space so it lines up and then the f is worth 15 add another space so it lines up the e</p>



<p class="wp-block-paragraph">is worth 14 so i&#8217;ll add another space so it lines up okay let me just double check my work here a b d</p>



<p class="wp-block-paragraph">So now I&#8217;ve got like a big formula that I wrote out.</p>



<p class="wp-block-paragraph">I can literally now, I mean, you can do this in your head if you&#8217;re like a crazy genius,</p>



<p class="wp-block-paragraph">but I&#8217;m just going to paste this into a calculator and hit enter.</p>



<p class="wp-block-paragraph">And this is the number that we had originally in hex.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll put commas here to make things more fun.</p>



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



<p class="wp-block-paragraph">You don&#8217;t really need to do that, but I&#8217;m going to.</p>



<p class="wp-block-paragraph">So for me, it&#8217;s easier to read.</p>



<p class="wp-block-paragraph">this is uh like 113 trillion 478 no wait that&#8217;s a million and that&#8217;s a bill okay so 113 mil a</p>



<p class="wp-block-paragraph">billion 478 million 25 022. let me punch up my personal calculator here to make sure that i&#8217;m</p>



<p class="wp-block-paragraph">getting this right i&#8217;m not going to show this on the screen because i&#8217;ve just got this up</p>



<p class="wp-block-paragraph">on my host machine bet you didn&#8217;t know i&#8217;m inside of vm right now surprised you didn&#8217;t know that</p>



<p class="wp-block-paragraph">decimal and the number is supposed to be 113478025022 okay so we did this right we now know how</p>



<p class="wp-block-paragraph">to convert from hexadecimal to decimal and it&#8217;s pretty awesome right okay let&#8217;s do another number</p>



<p class="wp-block-paragraph">one that is not quite as hard let&#8217;s see how many digits do we have here one two three i think we</p>



<p class="wp-block-paragraph">5, 6, 7, 8, 9, 10.</p>



<p class="wp-block-paragraph">Yeah, okay, we had 10.</p>



<p class="wp-block-paragraph">Let&#8217;s do a five-digit hex number.</p>



<p class="wp-block-paragraph">Okay, maybe I&#8217;ll copy…</p>



<p class="wp-block-paragraph">I&#8217;ll copy just this table at the top</p>



<p class="wp-block-paragraph">since you don&#8217;t need it anymore,</p>



<p class="wp-block-paragraph">but I&#8217;m going to need it to do my calculations.</p>



<p class="wp-block-paragraph">So we&#8217;ll do 1, 2, 3, 4, 5,</p>



<p class="wp-block-paragraph">and I&#8217;ll just start randomly changing</p>



<p class="wp-block-paragraph">some of these numbers.</p>



<p class="wp-block-paragraph">Like an 8 over here, and how about like a 2?</p>



<p class="wp-block-paragraph">So I&#8217;ve got five numbers.</p>



<p class="wp-block-paragraph">This is OX.</p>



<p class="wp-block-paragraph">I&#8217;m going to say this is a hexadecimal number.</p>



<p class="wp-block-paragraph">Kind of ambiguous if we tell the reader this is a hex number,</p>



<p class="wp-block-paragraph">but then we put OX.</p>



<p class="wp-block-paragraph">Kind of don&#8217;t really need to tell them that it&#8217;s hex</p>



<p class="wp-block-paragraph">because OX tells you it&#8217;s hex.</p>



<p class="wp-block-paragraph">It&#8217;s not even part of the value.</p>



<p class="wp-block-paragraph">So let&#8217;s get on with it.</p>



<p class="wp-block-paragraph">I&#8217;ll start by just doing 8 times 16 to the something power,</p>



<p class="wp-block-paragraph">which is going to be 0 for that first position.</p>



<p class="wp-block-paragraph">the power as we go to the left so it&#8217;s going to be 1 times 16 to the first power and then it&#8217;s</p>



<p class="wp-block-paragraph">going to be f times 16 to the second power and then it&#8217;s going to be 2 times 16 to the third</p>



<p class="wp-block-paragraph">power oh no my thoughts are wandering i think i&#8217;m getting bored of recording this video i&#8217;m starting</p>



<p class="wp-block-paragraph">to the fourth power but honestly why couldn&#8217;t they end up together so and</p>



<p class="wp-block-paragraph">then I think one two three four five okay so that&#8217;s five digits a to f one</p>



<p class="wp-block-paragraph">eight a to f one eight all right zero one two three four just to make sure</p>



<p class="wp-block-paragraph">that I got my exponents right copy paste it so I don&#8217;t have to repeat my work if</p>



<p class="wp-block-paragraph">I get something wrong I&#8217;m gonna translate the letters into numbers so a</p>



<p class="wp-block-paragraph">becomes 10 f becomes 15 and the other numbers are fine as is I can just copy</p>



<p class="wp-block-paragraph">fine as is I can just copy paste this whole thing stick it into a calculator and now I know that</p>



<p class="wp-block-paragraph">this number is actually 667 416 with a little comma in there don&#8217;t put commas if you are taking an</p>



<p class="wp-block-paragraph">exam somewhere if you&#8217;re watching my video to help with your exam because most most likely the exam</p>



<p class="wp-block-paragraph">that you&#8217;re taking will not accept a comma it&#8217;s not been pre-programmed for a comma I don&#8217;t know</p>



<p class="wp-block-paragraph">If you start typing numbers and a comma just shows up, then it probably was programmed for a comma.</p>



<p class="wp-block-paragraph">But don&#8217;t assume it might be a string match and not a numeric match.</p>



<p class="wp-block-paragraph">So be careful out there.</p>



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



<p class="wp-block-paragraph">So 667-416.</p>



<p class="wp-block-paragraph">Let me punch this into my personal calculator just to make sure I got this right and I don&#8217;t have to issue an errata.</p>



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



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



<p class="wp-block-paragraph">We&#8217;ve done it.</p>



<p class="wp-block-paragraph">We know how to convert hexadecimal numbers into decimal numbers.</p>



<p class="wp-block-paragraph">Thank you so much for watching this video. I hope you enjoyed it and had a little bit of fun and</p>



<p class="wp-block-paragraph">learned a little bit of stuff. I&#8217;ll see you in the next video. Hey everybody, thanks for watching</p>



<p class="wp-block-paragraph">this video again from the bottom of my heart. I really appreciate it. I do hope you did learn</p>



<p class="wp-block-paragraph">something and have some fun. If you could do me a please, a small little favor, could you please</p>



<p class="wp-block-paragraph">subscribe and follow this channel or these videos or whatever it is you do on the current social</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 subscribe.</p>



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



<p class="wp-block-paragraph">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/hex-to-decimal-made-easy-fun-simple-conversion-guide/">Hex to Decimal Made Easy: Fun &amp; Simple Conversion Guide!</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/hex-to-decimal-made-easy-fun-simple-conversion-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
