<?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>software development Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/software-development/</link>
	<description></description>
	<lastBuildDate>Sun, 05 Oct 2025 11:22:41 +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>software development Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/software-development/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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 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>Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</title>
		<link>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/</link>
					<comments>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 14 Sep 2025 23:46:11 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[argv argc]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[command line args]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[GCC assembly]]></category>
		<category><![CDATA[GCC linking]]></category>
		<category><![CDATA[hybrid programming]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming guide]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[x86 assembly]]></category>
		<category><![CDATA[x86-64 programming]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=227</guid>

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



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



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



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">points to an array.</p>



<p class="wp-block-paragraph">So like if you go to that location in memory,</p>



<p class="wp-block-paragraph">then what you will see there for the first eight bytes</p>



<p class="wp-block-paragraph">is just the address of some other memory location where a string has been stored.</p>



<p class="wp-block-paragraph">Then if you advance that pointer another eight bytes for it,</p>



<p class="wp-block-paragraph">you know, in memory, because all pointers are eight bytes or 64 bits,</p>



<p class="wp-block-paragraph">then again, you&#8217;ll see that that value of that next eight bytes</p>



<p class="wp-block-paragraph">is actually a memory location that points to another string somewhere else.</p>



<p class="wp-block-paragraph">So these strings could be all over the place,</p>



<p class="wp-block-paragraph">But the pointers to those strings are contiguous in memory starting with what you were given in RSI.</p>



<p class="wp-block-paragraph">So it&#8217;s a character pointer pointer or an array of character pointers, however you want to imagine that.</p>



<p class="wp-block-paragraph">Anyway, so we&#8217;ll grab those and then I&#8217;ll just show you how to use them down further in the code.</p>



<p class="wp-block-paragraph">For starters, I&#8217;m calling on an intro function which just basically prints some stuff.</p>



<p class="wp-block-paragraph">I have a custom function that I wrote called print null terminated string.</p>



<p class="wp-block-paragraph">That&#8217;s not the point of this video.</p>



<p class="wp-block-paragraph">I have that explained in other videos a little bit.</p>



<p class="wp-block-paragraph">So it&#8217;s up to you if you want to even care.</p>



<p class="wp-block-paragraph">Right now I just want to be able to print something.</p>



<p class="wp-block-paragraph">And then let&#8217;s see.</p>



<p class="wp-block-paragraph">So after we print our welcome message in the intro, then we print another message basically</p>



<p class="wp-block-paragraph">saying okay now we&#8217;re about to start printing all the arguments.</p>



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



<p class="wp-block-paragraph">Nothing complicated at this point.</p>



<p class="wp-block-paragraph">Then I have another label here with my preferred style of adding a suffix after the function</p>



<p class="wp-block-paragraph">after the function that I&#8217;m currently inside of.</p>



<p class="wp-block-paragraph">And I&#8217;m going to say, all right, this is where I initialize my loop.</p>



<p class="wp-block-paragraph">This is not a looping video, so I&#8217;m going to skim through it kind of.</p>



<p class="wp-block-paragraph">But I&#8217;m basically going to say, let&#8217;s start the loop as basically saying</p>



<p class="wp-block-paragraph">the index of the argument that we&#8217;re currently looking at is zero</p>



<p class="wp-block-paragraph">because we&#8217;ll start with zero.</p>



<p class="wp-block-paragraph">So that means we&#8217;ll print like if we were going to, if our program was named Echo,</p>



<p class="wp-block-paragraph">we would also print Echo itself and not just all the incoming arguments</p>



<p class="wp-block-paragraph">that the user might have typed.</p>



<p class="wp-block-paragraph">index zero and then we&#8217;re going to use r15 as the current character pointer so r15 its current</p>



<p class="wp-block-paragraph">character pointer is going to be coming from r13 which was the argv argument so that means</p>



<p class="wp-block-paragraph">r15 is now going to hold a pointer uh let&#8217;s see it&#8217;s going to hold</p>



<p class="wp-block-paragraph">when you have an array and the array is contiguous in memory then the pointer itself that points to</p>



<p class="wp-block-paragraph">the array is also a pointer to the first item that&#8217;s just kind of the way it works like if we</p>



<p class="wp-block-paragraph">have 10 items and it&#8217;s an array then your pointer to that array is also a pointer to the first item</p>



<p class="wp-block-paragraph">in the array if that makes sense so if r13 was a pointer to an array it&#8217;s also a pointer to the</p>



<p class="wp-block-paragraph">go off to a null terminated string i know that sounds weird you got to get used to double dereferencing</p>



<p class="wp-block-paragraph">here so all we really need to do to access uh the first pointer to the actual string is take the</p>



<p class="wp-block-paragraph">array pointer that we have and dereference it one time so remember we&#8217;re receiving an argv</p>



<p class="wp-block-paragraph">a pointer to a pointer or like a you know a double pointer if we dereference it once then we should</p>



<p class="wp-block-paragraph">terminated string. Anyway, so that&#8217;s the initialization part. I&#8217;m going to start looking</p>



<p class="wp-block-paragraph">at the first string here and I&#8217;m going to say we&#8217;re at index zero. And then here&#8217;s the top of</p>



<p class="wp-block-paragraph">my loop. You can imagine this is a while loop. This is not a while video, but you know, there it is.</p>



<p class="wp-block-paragraph">And we&#8217;re just going to ask first, are we actually done? Do we need to break the loop? I like to do</p>



<p class="wp-block-paragraph">that at the top of my while loop. And how we&#8217;ll do that is we&#8217;ll say, all right, R14 is the index</p>



<p class="wp-block-paragraph">the number of arguments so notice how like right here we grabbed RDI right</p>



<p class="wp-block-paragraph">into R12 right away so basically I&#8217;m saying if the index we&#8217;re currently</p>



<p class="wp-block-paragraph">looking at is greater than or equal to the number of arguments then we&#8217;re</p>



<p class="wp-block-paragraph">actually already done remember if we&#8217;re using zero based indexing and you</p>



<p class="wp-block-paragraph">suppose that you have three items in your array their indexes would be zero</p>



<p class="wp-block-paragraph">So that means if the size of your array is three, like the count, like the RFC, that</p>



<p class="wp-block-paragraph">means the last valid index is two.</p>



<p class="wp-block-paragraph">It&#8217;s one less than the size.</p>



<p class="wp-block-paragraph">You know, it&#8217;s one less than the count.</p>



<p class="wp-block-paragraph">So I&#8217;m saying at this point that if we ever reach an index number that is equal to the</p>



<p class="wp-block-paragraph">size, then we&#8217;ve already finished.</p>



<p class="wp-block-paragraph">We do not need to look at the current item.</p>



<p class="wp-block-paragraph">So I&#8217;m comparing those two registers.</p>



<p class="wp-block-paragraph">You know, where are we looking at versus what is the count?</p>



<p class="wp-block-paragraph">You know, what is the index we&#8217;re looking at versus the count?</p>



<p class="wp-block-paragraph">If the index we&#8217;re looking at is greater than or equal to the count, then that means we&#8217;re done.</p>



<p class="wp-block-paragraph">I&#8217;m going to jump out of the loop to a label called main loop done.</p>



<p class="wp-block-paragraph">So then, you know, that&#8217;s down here.</p>



<p class="wp-block-paragraph">Basically, we just say goodbye and then we jump to our exit function.</p>



<p class="wp-block-paragraph">And all that does is it just returns from main with some kind of a success code.</p>



<p class="wp-block-paragraph">You know, so just you can imagine in C++, it&#8217;s just return zero.</p>



<p class="wp-block-paragraph">So, you know, breaking the loop doesn&#8217;t really do anything except end the program and say goodbye.</p>



<p class="wp-block-paragraph">However, if we did not jump, then the, let&#8217;s see if we did not jump, let&#8217;s, let&#8217;s see if</p>



<p class="wp-block-paragraph">we did jump, we compared it, we realized that we&#8217;re done.</p>



<p class="wp-block-paragraph">Then it&#8217;s going to jump down to the, to the done.</p>



<p class="wp-block-paragraph">But if we&#8217;re not done, execution is going to fall through to the next statement.</p>



<p class="wp-block-paragraph">So that means we&#8217;re going to end up doing something with the current item inside of</p>



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



<p class="wp-block-paragraph">So what are we going to do?</p>



<p class="wp-block-paragraph">We&#8217;re going to dereference R15.</p>



<p class="wp-block-paragraph">was your pointer to a pointer it was your double pointer there if we dereference it once then</p>



<p class="wp-block-paragraph">instead of being a pointer to an array of pointers it&#8217;s going to be a pointer to one string one one</p>



<p class="wp-block-paragraph">character that starts one string so dereferencing it once means you know i put brackets around the</p>



<p class="wp-block-paragraph">double pointer it&#8217;s now dereferenced once that means rdi is going to receive a pointer to one</p>



<p class="wp-block-paragraph">into my function my function takes two arguments it wants a pointer to a string and it wants</p>



<p class="wp-block-paragraph">the file descriptor to print to again other videos explain you know printing to standard</p>



<p class="wp-block-paragraph">output but i&#8217;m just going to print the string so this part right here should actually print</p>



<p class="wp-block-paragraph">the argument and then after we&#8217;re done with that uh well maybe i should change this</p>



<p class="wp-block-paragraph">so that it&#8217;s a little bit more clear i&#8217;m going to maybe push this down and say</p>



<p class="wp-block-paragraph">these lines up here actually do something they do the printing by</p>



<p class="wp-block-paragraph">dereferencing and then here we just sort of increment along the array of pointers</p>



<p class="wp-block-paragraph">and jump back to the top of the loop so what are we doing here with r14</p>



<p class="wp-block-paragraph">remember r14 was the index that we&#8217;re currently looking at so we we start</p>



<p class="wp-block-paragraph">looking at index 0 line 83 is going to say let&#8217;s next look at index 1 and then</p>



<p class="wp-block-paragraph">this part right here add 8 to r15 that just basically means remember r15 was</p>



<p class="wp-block-paragraph">remember r15 was the double pointer the double pointer like i said before it&#8217;s looking at an</p>



<p class="wp-block-paragraph">array of pointers so it&#8217;s actually a pointer to a pointer if i increase the memory location that</p>



<p class="wp-block-paragraph">r15 holds then it&#8217;s now looking at the next pointer it&#8217;s moving through the array r15 at</p>



<p class="wp-block-paragraph">that point would no longer be a valid pointer to the original array it&#8217;s sort of like a running</p>



<p class="wp-block-paragraph">pointer it&#8217;s kind of like scanning all of the pointers but a pointer is eight bytes so if we&#8217;re</p>



<p class="wp-block-paragraph">a pointer is eight bytes so if we&#8217;re just looking at the first pointer and we increase the memory</p>



<p class="wp-block-paragraph">location that we&#8217;re looking at by eight bytes now we&#8217;re looking at the second pointer so then on the</p>



<p class="wp-block-paragraph">next iteration of the loop if we dereference then we&#8217;re going to end up dereferencing to the second</p>



<p class="wp-block-paragraph">string then i just print a little new line here honestly probably should have put that up top</p>



<p class="wp-block-paragraph">sloppy code i was doing this quickly and then we jump to the top of the loop so then we just</p>



<p class="wp-block-paragraph">going up to the top of the loop and printing arguments and advancing to the</p>



<p class="wp-block-paragraph">next pointer. And we just keep going at it.</p>



<p class="wp-block-paragraph">Let me see if this works. Hopefully I didn&#8217;t mess this up while I was screwing</p>



<p class="wp-block-paragraph">around. All right. So I&#8217;m going to do this make run. Okay.</p>



<p class="wp-block-paragraph">So under the hood inside of my make file,</p>



<p class="wp-block-paragraph">maybe let&#8217;s open the make file real fast just so you can see.</p>



<p class="wp-block-paragraph">I&#8217;m just going to nano it real fast here under the hood.</p>



<p class="wp-block-paragraph">So when I call the program to run, notice how I&#8217;m giving it arguments.</p>



<p class="wp-block-paragraph">You can see right here on this line, or actually let me get the line numbers up.</p>



<p class="wp-block-paragraph">You can see on line 48, I am calling my executable, which is named main.</p>



<p class="wp-block-paragraph">In the make file, I&#8217;m using a variable, so don&#8217;t worry about that.</p>



<p class="wp-block-paragraph">But I&#8217;m giving it four arguments.</p>



<p class="wp-block-paragraph">And I&#8217;m just saying first arg, second arg, third arg, fourth arg.</p>



<p class="wp-block-paragraph">So that&#8217;s why you see that printed in the previous screen.</p>



<p class="wp-block-paragraph">screen it&#8217;s just going through all the arguments that I gave it it&#8217;s saying</p>



<p class="wp-block-paragraph">first arg second arg third arg fourth arg notice how it knows when to stop</p>



<p class="wp-block-paragraph">because of the argc that came in on RDI now that the program is built you know</p>



<p class="wp-block-paragraph">I&#8217;ve got my main executable which I named main which I said before was kind</p>



<p class="wp-block-paragraph">of confusing now that I&#8217;ve got it I can just execute it again and give it like</p>



<p class="wp-block-paragraph">one argument of like hello notice how it prints hello on a line by itself you do</p>



<p class="wp-block-paragraph">do it again dudes and notice how every argument I give it it just prints it no</p>



<p class="wp-block-paragraph">matter how many I do I can go a b c d e f g I could probably do this so many</p>



<p class="wp-block-paragraph">times that I exhaust you know a long integer which is would be a horrible</p>



<p class="wp-block-paragraph">endeavor but yeah everything that I put on there it just loops through it and</p>



<p class="wp-block-paragraph">prints it so when you are linking with GCC because you&#8217;re probably using a</p>



<p class="wp-block-paragraph">if you&#8217;re just linking with GCC.</p>



<p class="wp-block-paragraph">GCC makes it really, really easy</p>



<p class="wp-block-paragraph">to access the command line arguments.</p>



<p class="wp-block-paragraph">Imagine now instead of just printing these things,</p>



<p class="wp-block-paragraph">you used them to somehow decide</p>



<p class="wp-block-paragraph">what your program was gonna do.</p>



<p class="wp-block-paragraph">Maybe the user will give you a sub command.</p>



<p class="wp-block-paragraph">Like if you&#8217;re a Git user, we say Git status, right?</p>



<p class="wp-block-paragraph">So the Git says like, oh, you Git launches</p>



<p class="wp-block-paragraph">and it goes, you want the status of something?</p>



<p class="wp-block-paragraph">Yeah, sure.</p>



<p class="wp-block-paragraph">So in your program now,</p>



<p class="wp-block-paragraph">you could read what the user typed,</p>



<p class="wp-block-paragraph">figure out a way to parse it and interpret it</p>



<p class="wp-block-paragraph">have your program&#8217;s behavior adjust to whatever the user typed in okay that&#8217;s it for this video</p>



<p class="wp-block-paragraph">the next video I&#8217;m going to post is how to do basically exactly the same thing but using pure</p>



<p class="wp-block-paragraph">assembly without linking against GCC so like LD is going to be the linker just like pure assembly</p>



<p class="wp-block-paragraph">no extra libraries okay thank you so much for watching this video I hope you learned a little</p>



<p class="wp-block-paragraph">tell your friends and i&#8217;ll see you in the next video</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really appreciate it</p>



<p class="wp-block-paragraph">i do hope you did learn something and have some fun uh if you could do me a please a small little</p>



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



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



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



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



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



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



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



<p class="wp-block-paragraph">you want to just wake me up in the middle of the night, just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">just wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



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



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



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



<p class="wp-block-paragraph">offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me i would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/">Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &#038; Clean Code!</title>
		<link>https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/</link>
					<comments>https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 23 Jun 2025 02:41:27 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[automation debugging]]></category>
		<category><![CDATA[binary file inspection]]></category>
		<category><![CDATA[byte level debugging]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[coding tips]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[linux tools]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming errors]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[terminal commands]]></category>
		<category><![CDATA[text file debugging]]></category>
		<category><![CDATA[xxd]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=165</guid>

					<description><![CDATA[<p>Debug program output with xxd! Learn to inspect text/binary files at byte level, fix hidden issues, and ensure clean code. Perfect for automation &#038; assignments.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/">Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &amp; Clean 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 title="Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &amp; Clean Code!" width="1380" height="776" src="https://www.youtube.com/embed/UyE5t01Vnd0?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 wonder why your program’s acting funky? Join me to master debugging with xxd! This vid walks you through inspecting text or binary file output at the byte level, catching sneaky characters like null bytes that mess up automation or school assignments. From assembly to redirects, learn practical tips to ensure clean output. Perfect for beginners and pros alike! Hit subscribe for more coding tutorials, and check my site for extra goodies. Let’s debug smarter, not harder!</p>



<p class="wp-block-paragraph">Introduction to xxd 00:00:00<br>Purpose of debugging 00:00:12<br>Why debug output 00:00:23<br>Example assembly program 00:00:56<br>Running the program 00:01:26<br>Corrupting the message 00:01:45<br>Terminal vs automation 00:02:27<br>Installing xxd 00:03:16<br>Redirecting output 00:03:29<br>Using xxd to debug 00:04:33<br>Identifying newline issue 00:05:36<br>Finding zero in string 00:06:04<br>Debugging conclusion 00:06:32<br>Weird symbols warning 00:06:47<br>Debugging standard error 00:07:23<br>Closing remarks 00:07:40<br>Call to subscribe 00:07:56<br>QR code and website 00:08:45<br>Request for comments 00:09:09<br>Fade out 00:09:31</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey there, I&#8217;d like to talk to you about debugging your program&#8217;s output with xxd.</p>



<p class="wp-block-paragraph">What am I talking about? Well, there&#8217;s a program called xxd that can sort of inspect</p>



<p class="wp-block-paragraph">at the byte level the output of some text file or binary file. It&#8217;s really useful for</p>



<p class="wp-block-paragraph">inspecting things. Why would you want to debug the output of your program? Well, I don&#8217;t know.</p>



<p class="wp-block-paragraph">print a message from your program the program might be printing some extra characters somewhere</p>



<p class="wp-block-paragraph">or some garbage and maybe maybe you don&#8217;t notice because you&#8217;re sort of looking at your program&#8217;s</p>



<p class="wp-block-paragraph">output in the terminal but then maybe if your output is being sent to another program</p>



<p class="wp-block-paragraph">for the purposes of automation or like you&#8217;re getting a grade from a class or something like</p>



<p class="wp-block-paragraph">that then um well it can it can sort of it can sort of get you without you realizing what&#8217;s wrong</p>



<p class="wp-block-paragraph">you an example real fast of what i&#8217;m talking about i have a simple assembly program here this is not</p>



<p class="wp-block-paragraph">a video about how to write assembly code so just assume that you know if you want to know assembly</p>



<p class="wp-block-paragraph">see my other videos but um i&#8217;m just going to print a simple message i&#8217;m just going to print</p>



<p class="wp-block-paragraph">hello i feel awesome and then the length of the message i&#8217;m specifying here you don&#8217;t know you</p>



<p class="wp-block-paragraph">don&#8217;t need to know too much about this for this particular video i&#8217;m just printing a string in</p>



<p class="wp-block-paragraph">assembly that&#8217;s all i&#8217;m doing and then here you can see i&#8217;m just kind of like printing it and then</p>



<p class="wp-block-paragraph">I&#8217;m just kind of like printing it and then I&#8217;m like exiting.</p>



<p class="wp-block-paragraph">So if we go back to the terminal here, I can type make run.</p>



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



<p class="wp-block-paragraph">See my other videos.</p>



<p class="wp-block-paragraph">I want to type make run just to compile and run the program.</p>



<p class="wp-block-paragraph">And then here&#8217;s the message that it prints, right?</p>



<p class="wp-block-paragraph">Hello, I feel awesome.</p>



<p class="wp-block-paragraph">It looks good in the terminal.</p>



<p class="wp-block-paragraph">I can&#8217;t be 100% sure though, because think about this.</p>



<p class="wp-block-paragraph">What if I corrupted the message on purpose?</p>



<p class="wp-block-paragraph">This can happen in assembly all the time.</p>



<p class="wp-block-paragraph">Wrong or if you add extra characters at the end of it or even if you have you know a corrupted register somewhere</p>



<p class="wp-block-paragraph">That either reads from the wrong spot</p>



<p class="wp-block-paragraph">To get a string or maybe it it writes over the string for some reason. There&#8217;s a lot of things that can go wrong</p>



<p class="wp-block-paragraph">So for now just suppose that I&#8217;ve corrupted my message somehow by I don&#8217;t know. Let&#8217;s put a zero</p>



<p class="wp-block-paragraph">In between the string so I&#8217;m gonna say is that it&#8217;s gonna be like H E L</p>



<p class="wp-block-paragraph">0 L O and what that should do is</p>



<p class="wp-block-paragraph">lo and what that should do uh well it should look like just the word hello but if i&#8217;m automating</p>



<p class="wp-block-paragraph">this program or sending it in to get a grade at a school somewhere then this should you know not</p>



<p class="wp-block-paragraph">match what is expected if i&#8217;m automating with like another system in some way but it should look okay</p>



<p class="wp-block-paragraph">in the terminal let&#8217;s see i&#8217;m going to do clear and make run notice how the message looks the same</p>



<p class="wp-block-paragraph">I feel awesome. So if I was automating, you know, if I was sending this string to another program</p>



<p class="wp-block-paragraph">for automation, I might be convinced that I&#8217;m not doing anything wrong. And I&#8217;ll, I&#8217;ll think it&#8217;s</p>



<p class="wp-block-paragraph">the other side that is wrong or, or our computers are just buggy or something like that. But actually</p>



<p class="wp-block-paragraph">I&#8217;ve outputted a corrupted message for some reason. So how can I really be sure that my</p>



<p class="wp-block-paragraph">message is what I think I&#8217;m seeing in the terminal? That&#8217;s the XXD program. Pretty easy.</p>



<p class="wp-block-paragraph">apt install xxd let me see if I have it on this system oh it&#8217;s already installed</p>



<p class="wp-block-paragraph">okay good so I&#8217;m gonna do clear and make run again so there it is I would like to</p>



<p class="wp-block-paragraph">just redirect the standard output pipe to a file with a special command in the</p>



<p class="wp-block-paragraph">shell let me just show you real fast I am definitely printing to std out the</p>



<p class="wp-block-paragraph">standard pipe which is just a number one file descriptor if you don&#8217;t understand</p>



<p class="wp-block-paragraph">If you don&#8217;t understand that, I have other videos, but I&#8217;m going to run the program again,</p>



<p class="wp-block-paragraph">but then I&#8217;m going to redirect the output to a file and I&#8217;m going to call it stdout.txt.</p>



<p class="wp-block-paragraph">It&#8217;s probably a good idea to eliminate spaces.</p>



<p class="wp-block-paragraph">I think I&#8217;ve made mistakes in other videos where I didn&#8217;t put a space before or after</p>



<p class="wp-block-paragraph">this little redirector symbol and I ended up creating a file just called the number</p>



<p class="wp-block-paragraph">two or the number one.</p>



<p class="wp-block-paragraph">But pipe number one is standard output.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say anything that comes to pipe one, which is standard output, I&#8217;m just</p>



<p class="wp-block-paragraph">output I&#8217;m just going to redirect it to a text file. So when I hit enter notice</p>



<p class="wp-block-paragraph">how nothing prints to the screen but the standard output text file that I</p>



<p class="wp-block-paragraph">specified is now created. If I spill the contents of std out it still looks</p>



<p class="wp-block-paragraph">normal so don&#8217;t let that trick you but watch what happens if I use xxd.</p>



<p class="wp-block-paragraph">xxd std out basically xxd is going to read it as a binary file and tell me</p>



<p class="wp-block-paragraph">every single character in there while I oh I forgot to change the title of that</p>



<p class="wp-block-paragraph">that&#8217;s not this video but notice right here where it says H E L L O and then</p>



<p class="wp-block-paragraph">right before that there&#8217;s like a little dot if you look at the dot let&#8217;s see</p>



<p class="wp-block-paragraph">what is the dot it&#8217;s one two three four five six it&#8217;s the sixth thing one two</p>



<p class="wp-block-paragraph">one two three four five six seven eight nine ten twelve thirteen fourteen fifteen oh there&#8217;s</p>



<p class="wp-block-paragraph">fifteen characters but there&#8217;s not that many i think probably they&#8217;re packing them by two here</p>



<p class="wp-block-paragraph">let me see if that makes more sense now one two three four five six one two three four five six</p>



<p class="wp-block-paragraph">yeah that makes a lot more sense so the sixth uh byte not the sixth uh word uh is basically</p>



<p class="wp-block-paragraph">to this dot right here and if you recall oa is a decimal 10 which is uh the beginning of a new line</p>



<p class="wp-block-paragraph">you know like a carriage return line feed um 13 comma 10 so that&#8217;s what it is right there</p>



<p class="wp-block-paragraph">and then so now we know that there&#8217;s xxd is figuring out here or helping us understand</p>



<p class="wp-block-paragraph">that there&#8217;s a new line between slash main and then the message which if you recall that&#8217;s</p>



<p class="wp-block-paragraph">exactly what happened and then when we look into our hello string there&#8217;s a dot in the middle here</p>



<p class="wp-block-paragraph">string there&#8217;s a dot in the middle here what is that dot well we just have to figure out what</p>



<p class="wp-block-paragraph">number that corresponds to so the oa was that dot right there so we just got to go a couple more</p>



<p class="wp-block-paragraph">bytes forward one two three four bytes forward one two three four bytes forward it&#8217;s this zero right</p>



<p class="wp-block-paragraph">so xxd even though the terminal didn&#8217;t help us originally xxd has helped us realize that we&#8217;re</p>



<p class="wp-block-paragraph">that we&#8217;re actually printing a zero under the hood and we can&#8217;t see it in the terminal.</p>



<p class="wp-block-paragraph">So we have now debugged our output. You know, depending on where you print this,</p>



<p class="wp-block-paragraph">you might see nothing like in the terminal. It didn&#8217;t really show anything. But if you&#8217;re on a</p>



<p class="wp-block-paragraph">webpage somewhere or some other type of thing that&#8217;s going to print the data for you, you might</p>



<p class="wp-block-paragraph">see a weird symbol. I mean, it really depends. This is not something you&#8217;ll see everywhere, but</p>



<p class="wp-block-paragraph">you might see a weird symbol that kind of looks like a black diamond with a question mark inside</p>



<p class="wp-block-paragraph">mark inside of it or some other weird symbol.</p>



<p class="wp-block-paragraph">If you start seeing weird symbols all over the place or just in a place where you know</p>



<p class="wp-block-paragraph">there&#8217;s not supposed to be a weird symbol, that might be an indication to you that you</p>



<p class="wp-block-paragraph">have weird values sitting inside of your string.</p>



<p class="wp-block-paragraph">And then you should probably try to debug with XXD.</p>



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



<p class="wp-block-paragraph">That&#8217;s the basics for debugging with XXD.</p>



<p class="wp-block-paragraph">Just, you know, file output anyway, for your information.</p>



<p class="wp-block-paragraph">If you wanted to debug the standard error pipe, you could also do this.</p>



<p class="wp-block-paragraph">you know because the error pipe is just a two um and that&#8217;s basically it i&#8217;m not going to</p>



<p class="wp-block-paragraph">debug right now because that&#8217;s that&#8217;s too easy but i hope you 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 i&#8217;ll see you in the next video</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really</p>



<p class="wp-block-paragraph">appreciate it i do hope you did learn something and have some fun uh if you could do me a please</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media website that you&#8217;re looking at right now.</p>



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



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos, 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">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 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 could troll me if you want to just wake</p>



<p class="wp-block-paragraph">me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s</p>



<p class="wp-block-paragraph">what will happen also uh if you look at the middle of the screen right now you should see a qr code</p>



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



<p class="wp-block-paragraph">you to my main website where you can just kind of like see all the videos I published and the</p>



<p class="wp-block-paragraph">services and tutorials and things that I offer and all that good stuff and uh if you have a</p>



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



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



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



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



<p class="wp-block-paragraph">thank you so much for watching this video and enjoy the cool music as I fade</p>



<p class="wp-block-paragraph">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-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/">Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &amp; Clean Code!</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master CGDB: Boost Your Debugging with GDB’s Curses Interface in Terminal</title>
		<link>https://www.NeuralLantern.com/master-cgdb-boost-your-debugging-with-gdbs-curses-interface-in-terminal/</link>
					<comments>https://www.NeuralLantern.com/master-cgdb-boost-your-debugging-with-gdbs-curses-interface-in-terminal/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 15 Jun 2025 23:08:57 +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[C debugging]]></category>
		<category><![CDATA[c++ debugging]]></category>
		<category><![CDATA[CGDB]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[curses interface]]></category>
		<category><![CDATA[debugging tools]]></category>
		<category><![CDATA[GDB]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[terminal debugging]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=158</guid>

					<description><![CDATA[<p>Learn CGDB, a GDB curses layer for terminal debugging. View source code &#038; breakpoints in one window. Ideal for C++, C, &#038; assembly!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-cgdb-boost-your-debugging-with-gdbs-curses-interface-in-terminal/">Master CGDB: Boost Your Debugging with GDB’s Curses Interface in Terminal</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 CGDB: Boost Your Debugging with GDB&#039;s Curses Interface in Terminal" width="1380" height="776" src="https://www.youtube.com/embed/grU1mA3W8K4?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! In this video, I’m diving into CGDB, a powerful curses layer on top of GDB that makes terminal debugging a breeze. See your source code and breakpoints side-by-side in one clean interface. I’ll walk you through setup, breakpoints, and why CGDB rocks for C++, C, and assembly projects. Watch my GDB video first for the basics (link in comments)! If you dig this, subscribe and drop a comment for more coding tips. Let’s debug smarter! #CGDB #GDB #Debugging #Coding</p>



<p class="wp-block-paragraph">Introduction to CGDB 00:00:00<br>Recommendation to Watch GDB Video 00:00:05<br>Explanation of CGDB and Curses 00:00:23<br>Building and Running CGDB 00:01:03<br>CGDB Interface Overview 00:01:56<br>Setting Breakpoints in CGDB 00:02:18<br>Managing Breakpoints 00:02:53<br>Benefits of CGDB 00:03:47<br>Closing Remarks and Subscription Request 00:04:00<br>Call for Comments and Suggestions 00:05:30</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 CGDB which is just a debugging program.</p>



<p class="wp-block-paragraph">If you haven&#8217;t seen my other video on GDB please watch that first because</p>



<p class="wp-block-paragraph">I go over all the concepts of debugging an assembly program, a C++ program, a C program</p>



<p class="wp-block-paragraph">and it&#8217;ll be much more useful than this video.</p>



<p class="wp-block-paragraph">This video is just about CGDB which is really a curses layer on top of GDB.</p>



<p class="wp-block-paragraph">on top of GDB. Curses is a library that allows programmers to kind of make</p>



<p class="wp-block-paragraph">graphical interfaces in the terminal so the point of this video is just to show</p>



<p class="wp-block-paragraph">you a slightly different way to use GDB that&#8217;s why I&#8217;m saying go check out the</p>



<p class="wp-block-paragraph">previous GDB video first but you know I think you know sometimes people like CG</p>



<p class="wp-block-paragraph">to be so what am I talking about for starters pretend that I have a program</p>



<p class="wp-block-paragraph">I&#8217;ve got an assembly module a C++ module and a make file you don&#8217;t know</p>



<p class="wp-block-paragraph">or C++, see my other videos.</p>



<p class="wp-block-paragraph">This video is only about CGDB.</p>



<p class="wp-block-paragraph">But I can do, you know, make build,</p>



<p class="wp-block-paragraph">just to build my objects and my executable.</p>



<p class="wp-block-paragraph">And then normally, if you know GDB,</p>



<p class="wp-block-paragraph">you can go GDB main and just enter the GDB terminal, right?</p>



<p class="wp-block-paragraph">This is great, you can do a lot of commands from here,</p>



<p class="wp-block-paragraph">but it&#8217;s not very graphical.</p>



<p class="wp-block-paragraph">It does have a graphical mode, to be honest,</p>



<p class="wp-block-paragraph">but it seems to be kind of glitchy,</p>



<p class="wp-block-paragraph">so I&#8217;m not really gonna talk about it.</p>



<p class="wp-block-paragraph">going to talk about it anyway so instead of launching your program inside of gdb you can</p>



<p class="wp-block-paragraph">launch your program with c gdb c standing for curses i don&#8217;t think this is installed on the</p>



<p class="wp-block-paragraph">current system so i&#8217;ll probably have to install it right okay so you can go sudo apt install c gdb</p>



<p class="wp-block-paragraph">and then just enter your password</p>



<p class="wp-block-paragraph">Let me do clear and then we&#8217;ll do CGDB main.</p>



<p class="wp-block-paragraph">And I just want you to see that it&#8217;s got two windows.</p>



<p class="wp-block-paragraph">This is the whole point for me anyway.</p>



<p class="wp-block-paragraph">The bottom window is actually GDB.</p>



<p class="wp-block-paragraph">So anything you&#8217;ve learned there is going to apply here.</p>



<p class="wp-block-paragraph">But the difference is that there&#8217;s a top panel that shows your source code.</p>



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



<p class="wp-block-paragraph">Let&#8217;s suppose for the sake of argument, I&#8217;m going to hit escape so I can go up to the top panel and kind of scroll my source code.</p>



<p class="wp-block-paragraph">Let&#8217;s suppose for the sake of argument, I want to break every time I hit line 36.</p>



<p class="wp-block-paragraph">time I hit line 36 okay I&#8217;m kind of scrolling I just hit escape to get into the top panel</p>



<p class="wp-block-paragraph">I&#8217;m gonna hit I for interactive mode which lets me go back down to the bottom panel</p>



<p class="wp-block-paragraph">and then I&#8217;ll just say B for breakpoints main.cpp line 36 and then just double check that I entered</p>



<p class="wp-block-paragraph">my breakpoints correctly and then I&#8217;ll run the program again if you don&#8217;t know GDB see my other</p>



<p class="wp-block-paragraph">video but notice how I started to run the program and then it immediately hit a breakpoint and then</p>



<p class="wp-block-paragraph">the top pointed to that line where it broke if you don&#8217;t believe me i&#8217;ll do another breakpoint</p>



<p class="wp-block-paragraph">at line let&#8217;s see main.cpp line maybe uh 32 and then another one at uh 39 well maybe i should</p>



<p class="wp-block-paragraph">have done 40. yeah i should have done 40 and then 33 so that means i probably want to uh</p>



<p class="wp-block-paragraph">delete that one at 32 so i&#8217;m gonna delete whichever one shows up at 32 that&#8217;s number two</p>



<p class="wp-block-paragraph">and then info breakpoints again okay so now if i continue the program also by the way notice how</p>



<p class="wp-block-paragraph">the top panel is showing red line numbers for my breakpoints if i hit c for continue</p>



<p class="wp-block-paragraph">and it hits the same breakpoint again if i hit enter to continue one more time it&#8217;ll do that</p>



<p class="wp-block-paragraph">eventually it hits a different breakpoint and notice how the source code</p>



<p class="wp-block-paragraph">moves down to the appropriate breakpoint so for me personally i kind of like to just regularly you</p>



<p class="wp-block-paragraph">and then go back and forth between that and my code window.</p>



<p class="wp-block-paragraph">But some people really love having both their code and GDB in the same terminal</p>



<p class="wp-block-paragraph">so they don&#8217;t have to go back and forth between windows.</p>



<p class="wp-block-paragraph">So if that&#8217;s you, then maybe CGDB is for you.</p>



<p class="wp-block-paragraph">My little doggy wants to go pee.</p>



<p class="wp-block-paragraph">Okay, that&#8217;s all I have for this video.</p>



<p class="wp-block-paragraph">Thank you so much for watching,</p>



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">and grow this community.</p>



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



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



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



<p class="wp-block-paragraph">know somebody subscribed or followed it just wakes me up and i get filled with joy that&#8217;s exactly what</p>



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



<p class="wp-block-paragraph">you want to just wake me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake</p>



<p class="wp-block-paragraph">up i promise that&#8217;s what will happen also uh if you look at the middle of the screen right now you</p>



<p class="wp-block-paragraph">of the screen right now you should see a qr code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which i think is also named somewhere at the bottom of this video and it&#8217;ll take you to my</p>



<p class="wp-block-paragraph">main website where you can just kind of like see all the videos i published and the services and</p>



<p class="wp-block-paragraph">tutorials and things that i offer and all that good stuff and uh if you have a suggestion for uh</p>



<p class="wp-block-paragraph">clarifications or errata or just future videos that you want to see please leave a comment or</p>



<p class="wp-block-paragraph">up what&#8217;s going on you know just send me a comment whatever i also wake up for those in the middle of</p>



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



<p class="wp-block-paragraph">me i would really appreciate it so again thank you so much for watching this video and um enjoy the</p>



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-cgdb-boost-your-debugging-with-gdbs-curses-interface-in-terminal/">Master CGDB: Boost Your Debugging with GDB’s Curses Interface in Terminal</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-cgdb-boost-your-debugging-with-gdbs-curses-interface-in-terminal/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master GNU Debugger: Debug C++ &#038; Assembly Programs with GDB Like a Pro</title>
		<link>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/</link>
					<comments>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 14 Jun 2025 23:53:13 +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[assembly programming]]></category>
		<category><![CDATA[breakpoints]]></category>
		<category><![CDATA[c++ debugging]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[call stack]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[debug symbols]]></category>
		<category><![CDATA[debugging tools]]></category>
		<category><![CDATA[GDB]]></category>
		<category><![CDATA[GNU Debugger]]></category>
		<category><![CDATA[null pointer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=155</guid>

					<description><![CDATA[<p>Master GDB to debug C++ &#038; assembly! Learn breakpoints, call stacks, &#038; crash fixes in this fun guide for coders.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/">Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB 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="Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro" width="1380" height="776" src="https://www.youtube.com/embed/lPcwsvSWak0?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 everybody! Ready to crush those pesky bugs in your C++ and assembly programs? In this video, we’re diving deep into the GNU Debugger (GDB) – the ultimate tool for tracking down crashes, inspecting variables, and mastering your code. From setting up debug symbols to navigating call stacks, setting breakpoints, and even debugging assembly registers, this fun and relatable guide has you covered. Whether you’re a beginner coder or a seasoned dev, you’ll learn practical tips to level up your debugging game. We’ll also tackle null pointers, create GDB scripts, and explore why your program might be misbehaving. Stick around for a few laughs and some serious skills! Don’t forget to subscribe, hit that like button, and check out my website for more coding tutorials. Let’s debug like pros together!</p>



<p class="wp-block-paragraph">Introduction to GNU Debugger 00:00:00<br>What is a Debugger 00:00:20<br>Debug Symbols Explanation 00:02:08<br>Compiling with Debug Symbols 00:03:13<br>File Size Comparison 00:05:30<br>Installing and Launching GDB 00:06:21<br>GDB Console Basics 00:06:55<br>Attaching GDB to Program 00:08:12<br>Running Program in GDB 00:09:09<br>Handling Program Crash 00:13:02<br>Understanding Call Stack 00:14:05<br>Navigating Call Stack 00:18:13<br>Inspecting Variables 00:19:08<br>Null Pointer Issues 00:21:25<br>Using GDB Script 00:25:10<br>Setting Breakpoints 00:27:04<br>Managing Breakpoints 00:28:37<br>Continuing Execution 00:30:41<br>Debugging Assembly 00:33:24<br>Global Variables in Assembly 00:35:43<br>Advanced GDB Commands 00:38:31<br>Conclusion and Call to Action 00:40:22</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey everybody! In this video I&#8217;m going to show you how to use the GNU Debugger to</p>



<p class="wp-block-paragraph">debug your C++ and assembly programs.</p>



<p class="wp-block-paragraph">You can also use it for C and some other stuff but we&#8217;re just going to focus on</p>



<p class="wp-block-paragraph">C++ and assembly. What is the GNU Debugger and what is a debugger in the</p>



<p class="wp-block-paragraph">first place? So for starters the GNU Debugger it&#8217;s like it&#8217;s called GDB and</p>



<p class="wp-block-paragraph">the db you can imagine that stands for debugger something like that and the g stands for gnu i</p>



<p class="wp-block-paragraph">personally don&#8217;t know how to uh pronounce gnu so i just say gnu because it it feels more fun to do</p>



<p class="wp-block-paragraph">it that way it&#8217;s more interesting i think probably some people just say new but i don&#8217;t like that</p>



<p class="wp-block-paragraph">because the gdb debugger is really old and robust and powerful it&#8217;s not a new tool it&#8217;s it&#8217;s an old</p>



<p class="wp-block-paragraph">new debugger someone&#8217;s always going to ask what was the old debugger and then I say this is the</p>



<p class="wp-block-paragraph">old debugger the new debugger is the old debugger anyway so we&#8217;re going to use the GNU debugger</p>



<p class="wp-block-paragraph">if you haven&#8217;t yet watched my video on caveman debugging you probably want to watch that first</p>



<p class="wp-block-paragraph">just for like some basics of you know why you might want to look at information in your program</p>



<p class="wp-block-paragraph">but for now we&#8217;ll just assume that you already know what&#8217;s going on with just like why you would</p>



<p class="wp-block-paragraph">know how to make make files see my other videos but here i just have a basic make file all it&#8217;s</p>



<p class="wp-block-paragraph">really going to do is just sort of compile a very simple program and add debug symbols into it so</p>



<p class="wp-block-paragraph">let&#8217;s double check that i&#8217;m actually doing that here yeah there we go okay so the first thing</p>



<p class="wp-block-paragraph">that i should probably show you is uh we are compiling a c plus plus source module so i&#8217;ve</p>



<p class="wp-block-paragraph">actually using c but i i have that left over in there anyway and then we&#8217;re assembling something</p>



<p class="wp-block-paragraph">in yasm we&#8217;re linking with g plus plus because we want to have a hybrid program and we&#8217;ve got</p>



<p class="wp-block-paragraph">all these flags here those are just variables and so uh so now before i can debug with gdb</p>



<p class="wp-block-paragraph">i&#8217;ve got to talk about something called debug symbols what are debug symbols imagine just a</p>



<p class="wp-block-paragraph">bunch of extra information explaining all of the design and variables and everything inside of your</p>



<p class="wp-block-paragraph">about your code stuffed directly into the executable.</p>



<p class="wp-block-paragraph">So imagine, you know, when we compile a C++ source module</p>



<p class="wp-block-paragraph">into an object file, usually that&#8217;s just, you know,</p>



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



<p class="wp-block-paragraph">But when we add debug symbols, we&#8217;ll have a bunch of information</p>



<p class="wp-block-paragraph">that can help the debugger figure out where we are in the program,</p>



<p class="wp-block-paragraph">what the variables look like, you know,</p>



<p class="wp-block-paragraph">a bunch of extra information to help the debugger pretty much.</p>



<p class="wp-block-paragraph">The assembler will put debug symbols into the object code</p>



<p class="wp-block-paragraph">symbols into the object code that you generate the compilers will do that the linker will do that</p>



<p class="wp-block-paragraph">and so it&#8217;s important to understand if you don&#8217;t generate debug symbols when you&#8217;re compiling and</p>



<p class="wp-block-paragraph">linking your code then your debugger won&#8217;t actually be able to do anything it won&#8217;t understand what&#8217;s</p>



<p class="wp-block-paragraph">going on you can debug it but like you&#8217;re not going to see anything that&#8217;s very uh that&#8217;s useful</p>



<p class="wp-block-paragraph">so let me show you real fast i&#8217;m going to do make clean and then i&#8217;m going to say make build</p>



<p class="wp-block-paragraph">that I do not have debug symbols.</p>



<p class="wp-block-paragraph">All right, okay, if you don&#8217;t know how to compile and link from the command line, see</p>



<p class="wp-block-paragraph">my other videos, but for now it looks like we&#8217;re not generating debug symbols.</p>



<p class="wp-block-paragraph">So if I list the contents of my directory here, just note the size is real fast.</p>



<p class="wp-block-paragraph">I have an assembly module here that I&#8217;m calling ASI.asm, ASI for assembly, and then we&#8217;re</p>



<p class="wp-block-paragraph">assembling it down to an object file.</p>



<p class="wp-block-paragraph">Notice how it&#8217;s just 656 bytes, very small.</p>



<p class="wp-block-paragraph">plus plus module that I&#8217;m creating here is compiling to an object file that is</p>



<p class="wp-block-paragraph">about four and a half kilobytes so you know not too big the final executable is</p>



<p class="wp-block-paragraph">called main and it&#8217;s about 17 kilobytes so this is without debug symbols when</p>



<p class="wp-block-paragraph">you&#8217;re compiling something on your own you need to add extra switches to enable</p>



<p class="wp-block-paragraph">debug symbols so you can see here in this make file that I&#8217;ve made and again if</p>



<p class="wp-block-paragraph">you don&#8217;t know how to make a make file or compile or link or anything see my</p>



<p class="wp-block-paragraph">But for now, I&#8217;m just going to assume you kind of know your way around to makefile,</p>



<p class="wp-block-paragraph">or at least you can kind of infer what&#8217;s going on.</p>



<p class="wp-block-paragraph">So I&#8217;ve commented out a different version of this variable for the flags of my C++ compiler.</p>



<p class="wp-block-paragraph">If I uncomment this and then comment out the other one,</p>



<p class="wp-block-paragraph">you&#8217;ll notice the only real difference is this part right here, dash G dwarf 2.</p>



<p class="wp-block-paragraph">Usually in C++ compilation, it&#8217;ll just be dash G to generate debug symbols,</p>



<p class="wp-block-paragraph">and then the symbol format will default to a format called dwarf2 so I don&#8217;t know for these</p>



<p class="wp-block-paragraph">tutorials I like to just specify the full format but you can just say dash g in your c++ compiler</p>



<p class="wp-block-paragraph">and linker we do the same thing for the linker down here so I&#8217;m going to uncomment this</p>



<p class="wp-block-paragraph">and comment that and the only difference is just g dwarf2 so I&#8217;m just telling my linker that I also</p>



<p class="wp-block-paragraph">want debug symbols in there too then we do the same thing for the assembler so I&#8217;m going to</p>



<p class="wp-block-paragraph">So I&#8217;m going to uncomment that and comment this other one.</p>



<p class="wp-block-paragraph">And the only difference is that in the assembler,</p>



<p class="wp-block-paragraph">we kind of have to specify it a little bit differently.</p>



<p class="wp-block-paragraph">Instead of G dwarf dash two,</p>



<p class="wp-block-paragraph">it&#8217;s just G dwarf two as just one string.</p>



<p class="wp-block-paragraph">And I think with Yasm, you have to specify the debug symbol format.</p>



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



<p class="wp-block-paragraph">So now I&#8217;ve turned on all the debug symbols.</p>



<p class="wp-block-paragraph">I&#8217;m going to do real fast, make clean and make build one more time.</p>



<p class="wp-block-paragraph">And then if I list everything,</p>



<p class="wp-block-paragraph">list everything let me just double check that it&#8217;s building the symbols now right okay good</p>



<p class="wp-block-paragraph">notice that the files are bigger so this asio um file is now 1.8 kilobytes instead of you know</p>



<p class="wp-block-paragraph">half a kilobyte the main.o object file is now 36 kilobytes instead of only 4.5 and the executable</p>



<p class="wp-block-paragraph">main is 36 kilobytes instead of just 17. so you can feel it already right like there&#8217;s a bunch</p>



<p class="wp-block-paragraph">extra information sitting inside the object files and the binary which allows us to debug our program</p>



<p class="wp-block-paragraph">okay so now that we&#8217;ve generated debug symbols in our program we can actually think about starting</p>



<p class="wp-block-paragraph">to use gdb so gdb is a program just gdb by the command line if you don&#8217;t have it in your system</p>



<p class="wp-block-paragraph">already you can go sudo apt install gdb or depending on what system you&#8217;re on maybe a or</p>



<p class="wp-block-paragraph">or whatever your package management program is,</p>



<p class="wp-block-paragraph">but we just need to install GDB.</p>



<p class="wp-block-paragraph">On Ubuntu and Debian, I think,</p>



<p class="wp-block-paragraph">there is a meta package called build essential,</p>



<p class="wp-block-paragraph">which will give you a bunch of compilation tools</p>



<p class="wp-block-paragraph">and make file stuff and whatever.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to assume at this point</p>



<p class="wp-block-paragraph">you already have GDB on your system.</p>



<p class="wp-block-paragraph">To launch GDB and go into its console,</p>



<p class="wp-block-paragraph">just type GDB by itself.</p>



<p class="wp-block-paragraph">So now we&#8217;re inside of the GDB console or terminal.</p>



<p class="wp-block-paragraph">console or terminal. We&#8217;re no longer inside of a bash terminal. We can&#8217;t type normal commands.</p>



<p class="wp-block-paragraph">Let me show you real fast. Here&#8217;s the first command you want to learn on GDB. It&#8217;s called</p>



<p class="wp-block-paragraph">quit. Never quit. Never surrender. So, you know, normally if you&#8217;re at the command line,</p>



<p class="wp-block-paragraph">you can do something like cat, etc. OS release just to see what operating system you&#8217;re using.</p>



<p class="wp-block-paragraph">So you can see for this virtual machine that I&#8217;m using right now, I&#8217;ve got like Ubuntu 22 on there.</p>



<p class="wp-block-paragraph">If we go inside of GDB, we can&#8217;t use regular bash commands anymore or regular operating</p>



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



<p class="wp-block-paragraph">We can&#8217;t say cat, et cetera, OS release because we can now only use GDB commands.</p>



<p class="wp-block-paragraph">We&#8217;re inside of GDB already.</p>



<p class="wp-block-paragraph">Notice how it says undefined catch command.</p>



<p class="wp-block-paragraph">I don&#8217;t know what you&#8217;re talking about, dude.</p>



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



<p class="wp-block-paragraph">So remember we do a Q or quit to get out.</p>



<p class="wp-block-paragraph">You can actually just type Q.</p>



<p class="wp-block-paragraph">A lot of commands that I&#8217;m going to be talking about.</p>



<p class="wp-block-paragraph">going to be talking about you can abbreviate them with one or two or three letters and it totally</p>



<p class="wp-block-paragraph">works just for speed so now that we know how to enter gdb and now that we also know that we have</p>



<p class="wp-block-paragraph">already compiled our program with debug symbols we can attach gdb to our program i mean what&#8217;s the</p>



<p class="wp-block-paragraph">whole point of a debugger we most of the time we will just have our debugger attached to our program</p>



<p class="wp-block-paragraph">and launch it or i guess launch it while it&#8217;s attached you can also attach to a running program</p>



<p class="wp-block-paragraph">but we&#8217;re going to launch a program and stay attached to it.</p>



<p class="wp-block-paragraph">And then we can sort of catch crashes and see what&#8217;s going on.</p>



<p class="wp-block-paragraph">Or we could also tell the debugger to stop the program at certain points in time,</p>



<p class="wp-block-paragraph">like when we hit a certain line number or when a variable changes or something like that.</p>



<p class="wp-block-paragraph">And then we can look around.</p>



<p class="wp-block-paragraph">We can look at all the variables, look at the state of the program,</p>



<p class="wp-block-paragraph">even change things if we wanted to.</p>



<p class="wp-block-paragraph">We can look at all the registers if you&#8217;re coding in assembly.</p>



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



<p class="wp-block-paragraph">Anyway, I&#8217;m going to go gdb and the next command we&#8217;re going to learn is file, which just tells</p>



<p class="wp-block-paragraph">gdb to attach to a program so that we can run it.</p>



<p class="wp-block-paragraph">So, you know, the name of our program here that we compiled is just called main.</p>



<p class="wp-block-paragraph">And so if I type file main, then gdb should load up that file and try to parse its debug</p>



<p class="wp-block-paragraph">symbols so it can begin debugging for you.</p>



<p class="wp-block-paragraph">Notice how it says reading symbols from main.</p>



<p class="wp-block-paragraph">you know if we did a typo or we had something with no debug symbols it will give us some sort</p>



<p class="wp-block-paragraph">of an error message so for now i&#8217;m just going to quit and then go back in just to make sure that</p>



<p class="wp-block-paragraph">it&#8217;s all clean and we&#8217;re going to do file main now it attaches once it&#8217;s attached that&#8217;s not i guess</p>



<p class="wp-block-paragraph">it&#8217;s not technically attached because the program&#8217;s not running but once it has loaded the debug</p>



<p class="wp-block-paragraph">symbols for that program we can run the program with the run command in gdb also kind of interesting</p>



<p class="wp-block-paragraph">If you have debug symbols that are generated separately from your executable,</p>



<p class="wp-block-paragraph">you could tell GDB to load the symbols file and then run your program.</p>



<p class="wp-block-paragraph">That happens a lot in Linux where people release the non-debug friendly version of a program</p>



<p class="wp-block-paragraph">and then they&#8217;ll release the debug symbols separately if you&#8217;re interested.</p>



<p class="wp-block-paragraph">Anyway, so I&#8217;m going to type run and it&#8217;ll run the program.</p>



<p class="wp-block-paragraph">Notice how GDB kind of tells us that it&#8217;s starting up now.</p>



<p class="wp-block-paragraph">here&#8217;s like a thread debugger that&#8217;s being enabled and it says we&#8217;re using this library to do it and</p>



<p class="wp-block-paragraph">then it says hello you know here&#8217;s the hello message so the program is actually running that&#8217;s</p>



<p class="wp-block-paragraph">not my name i wish it was and then it prints the final result and then gdb says your program exited</p>



<p class="wp-block-paragraph">normally on newer versions of gdb there&#8217;s a setting i think by default where it&#8217;ll ask you</p>



<p class="wp-block-paragraph">if you want to start a debug daemon a debug info daemon or something yes or no you can usually just</p>



<p class="wp-block-paragraph">without actually having to type n.</p>



<p class="wp-block-paragraph">It&#8217;s a little bit faster.</p>



<p class="wp-block-paragraph">So the whole program ran and finished.</p>



<p class="wp-block-paragraph">If I type run again, it does the same thing.</p>



<p class="wp-block-paragraph">In GDB, if you hit enter without typing anything,</p>



<p class="wp-block-paragraph">it ends up repeating the previous command.</p>



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



<p class="wp-block-paragraph">If I just hit enter, are you serious?</p>



<p class="wp-block-paragraph">GDB made me into a liar.</p>



<p class="wp-block-paragraph">Well, most of the commands will repeat if you hit enter.</p>



<p class="wp-block-paragraph">I guess not the run command.</p>



<p class="wp-block-paragraph">So I&#8217;ll type run again.</p>



<p class="wp-block-paragraph">And okay, I mean, the program is pretty good, right?</p>



<p class="wp-block-paragraph">So if you watched my…</p>



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



<p class="wp-block-paragraph">watched my it&#8217;s not pretty good it&#8217;s a nonsense program I mean it it doesn&#8217;t crash is what I&#8217;m</p>



<p class="wp-block-paragraph">saying if you watched my previous video which you should on caveman debugging I had this uh you know</p>



<p class="wp-block-paragraph">nonsense portion of code that just sort of updated a variable and we pretended that we were confused</p>



<p class="wp-block-paragraph">and we didn&#8217;t understand what was happening and uh we used gdb to debug it so what I&#8217;m going to do</p>



<p class="wp-block-paragraph">either let&#8217;s say we&#8217;ll start off with throwing an exception and then we&#8217;ll try to use a no pointer</p>



<p class="wp-block-paragraph">and then we&#8217;ll see a crash and then after that I&#8217;m going to start using breakpoints where we can stop</p>



<p class="wp-block-paragraph">automatically inside of our program to print the state of the program print the variables</p>



<p class="wp-block-paragraph">and then I&#8217;m going to do that first in C++ and then hopefully I&#8217;ll remember to do that in</p>



<p class="wp-block-paragraph">assembly right after it&#8217;s basically the same thing only with assembly you don&#8217;t really have</p>



<p class="wp-block-paragraph">you know a bunch of variables everywhere you just kind of have registers and maybe some globals</p>



<p class="wp-block-paragraph">globals but it&#8217;s going to be the same deal okay so let&#8217;s pretend that uh we are gonna have a crash</p>



<p class="wp-block-paragraph">okay so this program just kind of runs later on we&#8217;ll figure out why the result is wrong we&#8217;ll</p>



<p class="wp-block-paragraph">just pretend that it&#8217;s wrong but for now we&#8217;ll just say how about we uncomment this line right</p>



<p class="wp-block-paragraph">here and what will happen is when we&#8217;re running the main loop at some point in the loop we get</p>



<p class="wp-block-paragraph">When F gets called, the input will be looked at here.</p>



<p class="wp-block-paragraph">And if the input is more than one,</p>



<p class="wp-block-paragraph">which is definitely gonna happen like right away,</p>



<p class="wp-block-paragraph">then we&#8217;ll call on the G function.</p>



<p class="wp-block-paragraph">Then the G function will just throw an exception.</p>



<p class="wp-block-paragraph">We&#8217;ll just pretend that something really bad happened.</p>



<p class="wp-block-paragraph">You crashed or you actually did throw</p>



<p class="wp-block-paragraph">and you didn&#8217;t catch your throw,</p>



<p class="wp-block-paragraph">or maybe the system threw something at you</p>



<p class="wp-block-paragraph">or another library threw something at you</p>



<p class="wp-block-paragraph">and you didn&#8217;t catch it.</p>



<p class="wp-block-paragraph">So just basically a program crash.</p>



<p class="wp-block-paragraph">Let me run this real fast.</p>



<p class="wp-block-paragraph">So make run just to show you that the program crashes.</p>



<p class="wp-block-paragraph">Make run at this point is the same thing as just kind of executing the program.</p>



<p class="wp-block-paragraph">But you can see that it says terminate called after throwing an instance of runtime error.</p>



<p class="wp-block-paragraph">And then there&#8217;s the message, oh my gosh, and then aborted core dumped.</p>



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



<p class="wp-block-paragraph">So now let&#8217;s try to understand why.</p>



<p class="wp-block-paragraph">Why did that crash?</p>



<p class="wp-block-paragraph">Pretend you don&#8217;t know that it happened in G. You know, you&#8217;re trying to investigate.</p>



<p class="wp-block-paragraph">So we could type GDB and then we could type a file to load the debug symbols, but it&#8217;s a little bit faster just to type GDB main and just sort of name the file that you want to load right away.</p>



<p class="wp-block-paragraph">So if I do that, notice how it automatically tries to load the debug symbols from main.</p>



<p class="wp-block-paragraph">Then I can just type run and then the program tries to run and notice how it actually catches the crash.</p>



<p class="wp-block-paragraph">If you look down here, terminate called after throwing an instance of runtime error.</p>



<p class="wp-block-paragraph">throwing an instance of runtime error so that&#8217;s what the program thinks is going on but then the</p>



<p class="wp-block-paragraph">program is trying to terminate but then down here gdb is like wait wait wait i just caught you know</p>



<p class="wp-block-paragraph">a termination uh getting invoked here and you can see this is sort of system code like we did not</p>



<p class="wp-block-paragraph">create this source file p thread kill we didn&#8217;t write that that&#8217;s the standard library and there&#8217;s</p>



<p class="wp-block-paragraph">a function here called p thread kill implementation with those you know fun c underscore prefixes</p>



<p class="wp-block-paragraph">prefixes everywhere and so this is like some sort of a c source file and we don&#8217;t have that file on</p>



<p class="wp-block-paragraph">the system so we can&#8217;t really debug that file lucky for you most of these standard libraries</p>



<p class="wp-block-paragraph">work all the time so you don&#8217;t really need to debug them you need to debug your code instead</p>



<p class="wp-block-paragraph">of the standard library code so the question really is how did i get here how did i get to</p>



<p class="wp-block-paragraph">this crash so the next command we&#8217;ll learn in gdb is just the where command the where command will</p>



<p class="wp-block-paragraph">I&#8217;m going to release a video in the future that kind of explains call stacks, but basically</p>



<p class="wp-block-paragraph">imagine a abstract data type, a data structure called a stack. And every time you want to add</p>



<p class="wp-block-paragraph">data to the stack, it just sort of stacks up on top of the last piece of data. So like if I add</p>



<p class="wp-block-paragraph">something, let&#8217;s say I want to add the number five, then I would just add the number five on top of</p>



<p class="wp-block-paragraph">the stack, right? If I wanted to add the number 11, then I would just add the number 11 onto the</p>



<p class="wp-block-paragraph">off of the stack and the stack is a really good data structure to uh sort of give you a trail of</p>



<p class="wp-block-paragraph">breadcrumbs to know where you got where did you come from so we call this the call stack because</p>



<p class="wp-block-paragraph">what&#8217;s happening is every single time you call a function then the new scope and then you know the</p>



<p class="wp-block-paragraph">new function that you&#8217;re invoking um it has something called a call frame full of information</p>



<p class="wp-block-paragraph">current address is and all that stuff.</p>



<p class="wp-block-paragraph">And we&#8217;ll just call that chunk of data that belongs to one instance of a function call.</p>



<p class="wp-block-paragraph">We&#8217;ll just call that a call frame.</p>



<p class="wp-block-paragraph">And so if you&#8217;re stacking call frames one on top of the other,</p>



<p class="wp-block-paragraph">then we call that whole entire thing the call stack.</p>



<p class="wp-block-paragraph">And this is what allows us to use recursion and all these complicated call graphs and everything.</p>



<p class="wp-block-paragraph">It&#8217;s really simple, but it&#8217;s really powerful.</p>



<p class="wp-block-paragraph">So you&#8217;re looking at the call stack.</p>



<p class="wp-block-paragraph">Each one of these lines is the call frame or is a call frame.</p>



<p class="wp-block-paragraph">And so for example, if you just look at number zero here, you&#8217;re looking at call frame zero,</p>



<p class="wp-block-paragraph">which is the closest frame to wherever the crash occurred, which is if you look at it,</p>



<p class="wp-block-paragraph">that&#8217;s exactly what we were looking at when we saw that original message, right? Call frame zero.</p>



<p class="wp-block-paragraph">So that&#8217;s not really useful. You want to go down to higher numbered call frames or I guess</p>



<p class="wp-block-paragraph">physically lowered number call frames and just kind of scan it until you find some code that</p>



<p class="wp-block-paragraph">raise no abort no none of this stuff is ours live standard c plus plus no the first frame that</p>



<p class="wp-block-paragraph">contains code that is ours is call frame number nine or i guess like nine away from our current</p>



<p class="wp-block-paragraph">position so i guess find the physically highest call frame that is your code or the lowest numbered</p>



<p class="wp-block-paragraph">call frame that is your code and it&#8217;s telling us right here all right we uh we actually seem to</p>



<p class="wp-block-paragraph">So if I go to 65, right there, it tells you exactly where the crash happened.</p>



<p class="wp-block-paragraph">If you&#8217;re still trying to figure out, well, how did I get to that crash?</p>



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



<p class="wp-block-paragraph">Just keep looking down further in the call frames.</p>



<p class="wp-block-paragraph">The next one, call frame 10, says, well, we were inside of function f with input equals</p>



<p class="wp-block-paragraph">three at main.cpb line 46.</p>



<p class="wp-block-paragraph">So if I just go to 46, I can get another clue.</p>



<p class="wp-block-paragraph">I can go, all right, so for some reason we called g.</p>



<p class="wp-block-paragraph">Imagine again, this program is much more complicated.</p>



<p class="wp-block-paragraph">And then if we&#8217;re still confused, we just look down at another one and it&#8217;s like, well, this all this whole mess started at CPP main dot CPP line 28.</p>



<p class="wp-block-paragraph">So if we look at line 28, it&#8217;s like, well, we were inside of this loop and we we called the F function and then the F function called the G function.</p>



<p class="wp-block-paragraph">And then G just kind of did a throw. So that gives us a lot of information.</p>



<p class="wp-block-paragraph">All right. Next thing we can do is we can sort of move up and down the call stack, because right now we&#8217;re sitting at call frame zero, which is just the system code.</p>



<p class="wp-block-paragraph">which is just the system code, but maybe we don&#8217;t understand why the throw actually happened at,</p>



<p class="wp-block-paragraph">let&#8217;s say, line 65, right? So we can use up to go up in the call stack to a different call frame.</p>



<p class="wp-block-paragraph">So if I hit up, notice how it mentions that we&#8217;re now in frame number one instead of zero.</p>



<p class="wp-block-paragraph">And if I do up again, we&#8217;re now in frame two, which is a little bit closer. We can use the</p>



<p class="wp-block-paragraph">trick finally where we hit the enter key instead of repeating the command. So I&#8217;m just going to</p>



<p class="wp-block-paragraph">and hit enter a couple times until we eventually get to our code,</p>



<p class="wp-block-paragraph">which I think was supposed to be at frame nine.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to hit it a bunch of times until we get to frame nine.</p>



<p class="wp-block-paragraph">Now we&#8217;re looking sort of back in time at that point</p>



<p class="wp-block-paragraph">because all these other frames actually did get invoked,</p>



<p class="wp-block-paragraph">but we don&#8217;t really care about what was going on inside of them</p>



<p class="wp-block-paragraph">because they probably did their job correctly.</p>



<p class="wp-block-paragraph">We&#8217;re looking at our code, so we&#8217;re going back in time</p>



<p class="wp-block-paragraph">right when we were doing this throw.</p>



<p class="wp-block-paragraph">Oh no, we threw. Why did we throw?</p>



<p class="wp-block-paragraph">well there&#8217;s another command in gdb called info locals</p>



<p class="wp-block-paragraph">okay the info locals uh there&#8217;s there&#8217;s really not much to this maybe maybe let me do this again</p>



<p class="wp-block-paragraph">a equals five and uh then i&#8217;ll just say a plus plus just so that we have a local variable</p>



<p class="wp-block-paragraph">i forgot that gdb doesn&#8217;t consider the incoming arguments as locals so there was nothing there</p>



<p class="wp-block-paragraph">real fast uh gdp oh let&#8217;s do make build and then gdp main and then run and then we have a throw</p>



<p class="wp-block-paragraph">and then i say where and then i go up up up up to a frame you can also use the keyword down if you</p>



<p class="wp-block-paragraph">go too far if you want to go you know back down in the call stack but i&#8217;m just going to use up</p>



<p class="wp-block-paragraph">okay so now we have it here now finally i think i can do info locals just to see the local variables</p>



<p class="wp-block-paragraph">notice how the a variable is there now because I just added a local variable a a moment ago</p>



<p class="wp-block-paragraph">you can also print things directly you can say print the input incoming variable if you&#8217;re in</p>



<p class="wp-block-paragraph">assembly you can also print registers you can say info registers like that and you&#8217;ll get a nice</p>



<p class="wp-block-paragraph">print out of all the registers you could print individual registers you can say let&#8217;s print</p>



<p class="wp-block-paragraph">register r12 you can print register r12 as binary by saying I think it&#8217;s p slash t</p>



<p class="wp-block-paragraph">or print slash t yeah we can probably just do print slash t also</p>



<p class="wp-block-paragraph">t stands for two because they&#8217;re it&#8217;s a base two number system</p>



<p class="wp-block-paragraph">does that mean there&#8217;s a p slash h or a p slash f for 15 or 16 s for 16 i don&#8217;t know i haven&#8217;t</p>



<p class="wp-block-paragraph">tried that is it going to work hang on p slash s bar 12 it&#8217;s not going to work nope didn&#8217;t work</p>



<p class="wp-block-paragraph">i think it thinks it&#8217;s a character point or something but anyway so we can print a lot of</p>



<p class="wp-block-paragraph">So we can print a lot of stuff.</p>



<p class="wp-block-paragraph">And like I said before, we can go up and down the call stack.</p>



<p class="wp-block-paragraph">So I can go down a couple times and then go back up again.</p>



<p class="wp-block-paragraph">And now we can assume that we&#8217;ve kind of debugged, you know, where the source of the error was.</p>



<p class="wp-block-paragraph">So I&#8217;m going to comment that call out to G and run the program again one more time with a different error.</p>



<p class="wp-block-paragraph">So I&#8217;ve commented this code out from before, but just imagine now that we&#8217;re going to use some pointers.</p>



<p class="wp-block-paragraph">We&#8217;re going to start off with a pointer called P.</p>



<p class="wp-block-paragraph">a pointer called p we&#8217;re going to set it to null at the beginning and then we&#8217;re going to just</p>



<p class="wp-block-paragraph">kind of allocate it and then we&#8217;re going to set you know a value and then we&#8217;re going to dereference</p>



<p class="wp-block-paragraph">it and dereferencing a pointer just kind of sets the first value in an array you can do that and</p>



<p class="wp-block-paragraph">then we&#8217;re going to deallocate the pointer and then how about right after that we do something</p>



<p class="wp-block-paragraph">really really naughty we say p at some index is equal to a five this should be this should be a</p>



<p class="wp-block-paragraph">a program crash because we deallocated p already at that point we would be dealing with junk data</p>



<p class="wp-block-paragraph">if we tried to dereference p but to make it even more clear that it&#8217;s naughty we&#8217;ll set it to a no</p>



<p class="wp-block-paragraph">pointer and then we&#8217;ll try to actually use it so let me let me just restart the program real fast</p>



<p class="wp-block-paragraph">i&#8217;m gonna do quit yes and then we&#8217;ll do make a debug just so you know my make debug is just a</p>



<p class="wp-block-paragraph">Let&#8217;s see, where&#8217;s that? Where&#8217;s that? Where&#8217;s that? Do I not have a debug shortcut yet?</p>



<p class="wp-block-paragraph">Oh dear. I need to add that before this video is over. You know what? I&#8217;ll add it right now.</p>



<p class="wp-block-paragraph">We&#8217;ll do this run and we&#8217;ll say debug, make debug, and it needs to build first. And then I&#8217;ll say</p>



<p class="wp-block-paragraph">debugging the program. And then we will do the GDB binary and give it an argument of</p>



<p class="wp-block-paragraph">the executable and then later we can we can upgrade this to take a little script of commands</p>



<p class="wp-block-paragraph">because the commands are going to start getting out of control so now if i do make debug if i</p>



<p class="wp-block-paragraph">didn&#8217;t screw it up now it at least goes in there and i&#8217;ll do run and then we have a seg fault and</p>



<p class="wp-block-paragraph">notice how it tells us right away hey you have a seg fault right here you&#8217;re accessing invalid</p>



<p class="wp-block-paragraph">memory let&#8217;s do info locals just to see what&#8217;s up oh the p is actually a zero that&#8217;s a null pointer</p>



<p class="wp-block-paragraph">explicitly oh whoops you know oh what have I done but it&#8217;s a really good idea to set your</p>



<p class="wp-block-paragraph">pointers to null after you deallocate because if you don&#8217;t you might end up with undefined</p>



<p class="wp-block-paragraph">behavior where sometimes the program doesn&#8217;t crash while you&#8217;re overriding junk data or reading junk</p>



<p class="wp-block-paragraph">data but sometimes it does and you&#8217;re not really sure like why does it work sometimes and why does</p>



<p class="wp-block-paragraph">it not work sometimes so let me comment this out and see if it&#8217;ll crash uh let&#8217;s just let&#8217;s just</p>



<p class="wp-block-paragraph">make debug and then i&#8217;ll do run and then if we do info locals oh yeah okay so this is uh</p>



<p class="wp-block-paragraph">it did seg fault so that&#8217;s good uh if we were unlucky then the program wouldn&#8217;t have crashed</p>



<p class="wp-block-paragraph">it would have just started behaving strangely and um when we print out the value of p notice how it</p>



<p class="wp-block-paragraph">looks like a pointer still like if we were to debug the program and print the pointer value</p>



<p class="wp-block-paragraph">then it doesn&#8217;t really it looks the same it looks the same after we deallocated it right so that</p>



<p class="wp-block-paragraph">this is called a dangling pointer meaning you deallocated the pointer but you forgot to set</p>



<p class="wp-block-paragraph">it to null afterwards so then later when you&#8217;re trying to debug the program it&#8217;s a little confusing</p>



<p class="wp-block-paragraph">because you&#8217;re like that looks like a regular pointer what did i do wrong so um it&#8217;s really</p>



<p class="wp-block-paragraph">good practice to set your pointers to null right after you deallocate them that way when you&#8217;re</p>



<p class="wp-block-paragraph">debugging later because something crashed instead of seeing a memory location on p you&#8217;ll see</p>



<p class="wp-block-paragraph">On P, you&#8217;ll see something that looks definitely like a null pointer and print P.</p>



<p class="wp-block-paragraph">Then it&#8217;s way easier to realize, oh, whoops, I was trying to use a dead pointer, a pointer that I deallocated.</p>



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



<p class="wp-block-paragraph">Next thing I want to do is a small upgrade.</p>



<p class="wp-block-paragraph">I can&#8217;t remember if it&#8217;s dash X or dash EX.</p>



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



<p class="wp-block-paragraph">But you can write a little script.</p>



<p class="wp-block-paragraph">I have a little script here called Good Doggo.</p>



<p class="wp-block-paragraph">called good doggo you can just make any file name it anything you want i&#8217;m so i&#8217;m just naming it</p>



<p class="wp-block-paragraph">good doggo.txt because my dog&#8217;s taking a little nap behind me as usual um but you could name this</p>



<p class="wp-block-paragraph">gdb.txt or whatever it is you want so you can put inside of this script file any command that you</p>



<p class="wp-block-paragraph">want gdb to execute when it launches so let&#8217;s just comment this stuff out real fast and i&#8217;ll do</p>



<p class="wp-block-paragraph">I&#8217;ll just do run maybe for starters.</p>



<p class="wp-block-paragraph">Because whenever I&#8217;ve been launching for debug,</p>



<p class="wp-block-paragraph">I launch with GDB and then I type run manually, right?</p>



<p class="wp-block-paragraph">So I want to save a little time.</p>



<p class="wp-block-paragraph">So good doggo is the name of the script.</p>



<p class="wp-block-paragraph">So when I invoke GDB, I am going to,</p>



<p class="wp-block-paragraph">where is it right there?</p>



<p class="wp-block-paragraph">Okay, it&#8217;s GDB.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to go dot, I think it&#8217;s X.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to say good doggo.txt.</p>



<p class="wp-block-paragraph">If it&#8217;s not dash x, then it&#8217;s dash ex.</p>



<p class="wp-block-paragraph">One of those executes the command that comes after,</p>



<p class="wp-block-paragraph">and one of those executes the command script that comes after.</p>



<p class="wp-block-paragraph">Let me just double check that this actually is going to work.</p>



<p class="wp-block-paragraph">So make debug.</p>



<p class="wp-block-paragraph">All right, okay, so it was dash x.</p>



<p class="wp-block-paragraph">Dash x specifies a script that will be run.</p>



<p class="wp-block-paragraph">Dash ex just specifies a command that you can put right in there.</p>



<p class="wp-block-paragraph">Like I could have said dash ex run, and it would have ran right away.</p>



<p class="wp-block-paragraph">But the script is more convenient, right?</p>



<p class="wp-block-paragraph">Because we can save typing.</p>



<p class="wp-block-paragraph">So notice how it ran right away and then there&#8217;s a seg fault.</p>



<p class="wp-block-paragraph">Okay, so now let&#8217;s go a little bit deeper.</p>



<p class="wp-block-paragraph">Let&#8217;s change this to false again now that we understand like null pointers and all that</p>



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



<p class="wp-block-paragraph">So we can just basically deal a little bit more with only what the main loop is doing.</p>



<p class="wp-block-paragraph">Suppose we just still don&#8217;t really understand what the loop is doing, why our answer is</p>



<p class="wp-block-paragraph">you know, good or bad.</p>



<p class="wp-block-paragraph">So maybe I want to do a breakpoint at the top of that for loop.</p>



<p class="wp-block-paragraph">loop gets to the top of its iteration, I want the program to pause so I can look around.</p>



<p class="wp-block-paragraph">So I&#8217;m going to set up a breakpoint on line 22. And here&#8217;s how you set up breakpoints</p>



<p class="wp-block-paragraph">in GDB. I&#8217;m going to go ahead and maybe do the terminal for now. And then I&#8217;ll stick that into</p>



<p class="wp-block-paragraph">the script next. I will not remember that it&#8217;s line 22. That&#8217;s okay. I&#8217;m going to do quit.</p>



<p class="wp-block-paragraph">And I&#8217;m going to do make build. Then I&#8217;m going to go GDB main just to jump in there.</p>



<p class="wp-block-paragraph">and then i&#8217;m going to say break or just the letter b just to make a break point you type the name of</p>



<p class="wp-block-paragraph">the source code file that you want to break in and then a colon and then the line number where</p>



<p class="wp-block-paragraph">you want it to break so i think i think it actually was line 22 oh i can see it and then</p>



<p class="wp-block-paragraph">maybe i want to have it break at line i don&#8217;t know maybe right here line 25 right before it increases</p>



<p class="wp-block-paragraph">And then so I&#8217;m going to do an up arrow to just repeat the command so I can edit it real fast.</p>



<p class="wp-block-paragraph">And then I&#8217;ll break again at line 28 and then maybe 30 and then 32.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go 28, 30 and 32.</p>



<p class="wp-block-paragraph">30 and I&#8217;m just making up break points.</p>



<p class="wp-block-paragraph">I just want to inspect the program and then maybe I&#8217;ll break at line 36 so I can see what the final answer is.</p>



<p class="wp-block-paragraph">So I just have a bunch of break points set up.</p>



<p class="wp-block-paragraph">Remember when the program is running now under GDB, every time it hits one of those lines,</p>



<p class="wp-block-paragraph">every time it hits one of those lines the program will pause and i&#8217;ll have a chance to look around</p>



<p class="wp-block-paragraph">at the variables and things so i&#8217;m not sure if i&#8217;ve set up the breakpoints correctly i can say</p>



<p class="wp-block-paragraph">info breakpoints and it&#8217;ll show me all of my breakpoints notice how you can enable them and</p>



<p class="wp-block-paragraph">disable them so let&#8217;s say for the sake of argument i want to disable the breakpoint at line 30 because</p>



<p class="wp-block-paragraph">maybe i don&#8217;t really need that right now but i kind of want to keep it in the system for later</p>



<p class="wp-block-paragraph">disable four because it&#8217;s number four.</p>



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



<p class="wp-block-paragraph">So I can say disable four.</p>



<p class="wp-block-paragraph">Then if I do info breakpoints again,</p>



<p class="wp-block-paragraph">notice how there&#8217;s a little N on there,</p>



<p class="wp-block-paragraph">meaning breakpoint four is disabled.</p>



<p class="wp-block-paragraph">So I could re-enable it with a four</p>



<p class="wp-block-paragraph">and then go info breakpoints again.</p>



<p class="wp-block-paragraph">So now they&#8217;re all enabled.</p>



<p class="wp-block-paragraph">I am going to maybe copy this into the script file real fast</p>



<p class="wp-block-paragraph">so I don&#8217;t have to keep typing this over and over and over again.</p>



<p class="wp-block-paragraph">Imagine if every single time you changed your program and recompiled it you had to type all of the breakpoints from scratch</p>



<p class="wp-block-paragraph">That&#8217;s why I want you to use this little breakpoint script</p>



<p class="wp-block-paragraph">So we&#8217;re going to do B to break at main.cpp line 22 and 25 and</p>



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



<p class="wp-block-paragraph">30 and 32. I should have copy pasted the three dang it 36</p>



<p class="wp-block-paragraph">And after we&#8217;re done setting up all the breakpoints</p>



<p class="wp-block-paragraph">show me the breakpoints just so I can have a visual reminder. Keep in mind if you change too</p>



<p class="wp-block-paragraph">much of your source code then you&#8217;re probably going to have to update these lines and that&#8217;s</p>



<p class="wp-block-paragraph">okay but it&#8217;s a good idea to just at least you know kind of look at them a little bit so that&#8217;s</p>



<p class="wp-block-paragraph">why I&#8217;m saying info breakpoints. And so then remember again the makefile all it&#8217;s doing when</p>



<p class="wp-block-paragraph">I type make debug is it&#8217;s just launching this command right here it&#8217;s just saying gdb with the</p>



<p class="wp-block-paragraph">with my gdb script so let me quit to get out of this and then i&#8217;m going to say clear and make</p>



<p class="wp-block-paragraph">debug and notice how it did all that stuff for me it added the breakpoints it showed me the break</p>



<p class="wp-block-paragraph">points and then it ran the program like i told it to and then it already broke on a breakpoint it</p>



<p class="wp-block-paragraph">already break it break breakened it&#8217;s broken i don&#8217;t know i don&#8217;t think it&#8217;s broken uh so we&#8217;re</p>



<p class="wp-block-paragraph">So we&#8217;re on breakpoint number one on line 22.</p>



<p class="wp-block-paragraph">And here&#8217;s the for loop.</p>



<p class="wp-block-paragraph">I can type all of my inspection stuff.</p>



<p class="wp-block-paragraph">I can say info locals.</p>



<p class="wp-block-paragraph">I can say print I, I can say print A, I can print whatever I want.</p>



<p class="wp-block-paragraph">And then when I&#8217;m done kind of looking around and inspecting things,</p>



<p class="wp-block-paragraph">I want to continue the program.</p>



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



<p class="wp-block-paragraph">So I&#8217;m just going to use the command continue.</p>



<p class="wp-block-paragraph">And it goes right to the next breakpoint.</p>



<p class="wp-block-paragraph">If I want to, you know, continue again, I can hit C.</p>



<p class="wp-block-paragraph">continue again i can hit c or i can just hit enter you know to just sort of keep continuing as i</p>



<p class="wp-block-paragraph">inspect and print things let&#8217;s see when can i get to break point number one is that what&#8217;s going on</p>



<p class="wp-block-paragraph">here hang on a second what is break point number one oh i know what to do info break points</p>



<p class="wp-block-paragraph">break point number one is that main.cpp line 22 is that actually going to get hit oh it&#8217;s</p>



<p class="wp-block-paragraph">having issues here with my GUI. Okay. Line 22. Okay. So it&#8217;s not really hitting that anymore.</p>



<p class="wp-block-paragraph">I guess it&#8217;s not going to think that it hits the top of the forelip. Okay. So I guess breakpoint</p>



<p class="wp-block-paragraph">two is where we&#8217;re always going to be hitting. So let&#8217;s just suppose that I&#8217;m continuing until</p>



<p class="wp-block-paragraph">I hit breakpoint number two. Suppose that the next 10 times I see breakpoint two, I don&#8217;t</p>



<p class="wp-block-paragraph">actually want to stop and break on it. I just want to skip the next 10 iterations for some reason.</p>



<p class="wp-block-paragraph">some reason you can say continue 10 and it&#8217;ll skip the next 10 times that it hits the number two</p>



<p class="wp-block-paragraph">notice how if i hit continue a bunch of times we&#8217;re not really seeing the break point number</p>



<p class="wp-block-paragraph">two anymore we&#8217;re seeing other break points and then eventually if i hit it enough times</p>



<p class="wp-block-paragraph">we&#8217;ll probably see two again oh my god oh my god are we seeing it yet no</p>



<p class="wp-block-paragraph">Okay, wait, are we seeing I&#8217;m freaking myself out.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s continue 10 times on breakpoint three, then we&#8217;ll only see</p>



<p class="wp-block-paragraph">breakpoint four, I guess.</p>



<p class="wp-block-paragraph">So we can do continue 10 times on breakpoint four.</p>



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



<p class="wp-block-paragraph">Did I write this program in a weird way?</p>



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



<p class="wp-block-paragraph">Well, trust me on this.</p>



<p class="wp-block-paragraph">Let&#8217;s continue 100 on breakpoint three and then continue 100 on breakpoint four.</p>



<p class="wp-block-paragraph">breakpoint 4. Okay, so now we&#8217;re just done with the whole entire program. I guess there must have</p>



<p class="wp-block-paragraph">been a 2 there that I missed. So now we&#8217;re finally on breakpoint 6, which is when everything is</p>



<p class="wp-block-paragraph">finished. Let me show you real fast that we can add more breakpoints in assembly just to prove</p>



<p class="wp-block-paragraph">that we can debug assembly real fast. So if I want to debug assembly, I just have to type the name of</p>



<p class="wp-block-paragraph">that source code file. If it was nested in a folder, like if you had like a complicated hierarchy of</p>



<p class="wp-block-paragraph">of source code files you would just need to type the relative path but for now I&#8217;m just going to</p>



<p class="wp-block-paragraph">be able to type the name of the file so assy.asm and let&#8217;s suppose that I want to break at line</p>



<p class="wp-block-paragraph">16 just so I can see the registers that I set up so I&#8217;m going to do 16 and then I&#8217;m going to break</p>



<p class="wp-block-paragraph">at assy.asm line 16 and then I&#8217;m going to run and that actually never gets called does it no no it</p>



<p class="wp-block-paragraph">called does it no no it gets called I think I have a call up here somewhere</p>



<p class="wp-block-paragraph">nope I don&#8217;t have a call okay let&#8217;s make a call this is gonna throw off all of my</p>



<p class="wp-block-paragraph">C++ breakpoints so I&#8217;ll just comment them all out right now comment them all</p>



<p class="wp-block-paragraph">out so I don&#8217;t have to redo them and this is a hybrid program so I&#8217;m gonna go</p>



<p class="wp-block-paragraph">extern what is it extern C make a block where I name the function the reason we</p>



<p class="wp-block-paragraph">name mangling so the AC symbol is going to show up as just its regular function</p>



<p class="wp-block-paragraph">name rather than a bunch of extra stuff indicating the prototype so that we can</p>



<p class="wp-block-paragraph">do overloading so we&#8217;re just going to disable that and then at the very top of</p>



<p class="wp-block-paragraph">the program I&#8217;m just going to call it this should hopefully work let me just</p>



<p class="wp-block-paragraph">do a regular make run just to make sure the whole program compiles okay now</p>



<p class="wp-block-paragraph">debug script we&#8217;re gonna break on line 16 which is going to be letting us see</p>



<p class="wp-block-paragraph">the registers okay so I&#8217;m gonna go make debug notice how it hit the breakpoint</p>



<p class="wp-block-paragraph">in the assembly just the same as the C++ and we can print whatever we want now so</p>



<p class="wp-block-paragraph">I&#8217;m just gonna say info registers and if we look carefully we can kind of see</p>



<p class="wp-block-paragraph">that we modified racks REX is 15 so that&#8217;s expected RDI is 20 which is</p>



<p class="wp-block-paragraph">R12 should be a giant number. Where&#8217;s R12? Right there. So you can see the state of your program at any point in time just by breaking on it.</p>



<p class="wp-block-paragraph">I&#8217;m breaking on a certain line. So this is tremendously useful for debugging not just for higher level languages but also assembly.</p>



<p class="wp-block-paragraph">What else can I do? Oh let&#8217;s put a global in the data section. So I&#8217;m gonna do, I don&#8217;t know, my thing or something like that and we&#8217;ll call it a byte array and I&#8217;ll just go hello.</p>



<p class="wp-block-paragraph">I&#8217;ll say we have a thing one and a thing two.</p>



<p class="wp-block-paragraph">Something like that.</p>



<p class="wp-block-paragraph">And maybe thing two is a null terminated string,</p>



<p class="wp-block-paragraph">whereas thing one is a regular thing.</p>



<p class="wp-block-paragraph">We should be able to print those symbols.</p>



<p class="wp-block-paragraph">If that&#8217;s not true, I&#8217;ll come back at a later time</p>



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



<p class="wp-block-paragraph">Anyway, so we&#8217;ll do make debug</p>



<p class="wp-block-paragraph">to just kind of assemble everything again.</p>



<p class="wp-block-paragraph">And we know how to do info registers.</p>



<p class="wp-block-paragraph">We can print, you know, one register in particular,</p>



<p class="wp-block-paragraph">print R12 if we wanted to.</p>



<p class="wp-block-paragraph">History has not reached.</p>



<p class="wp-block-paragraph">History has not reached 12.</p>



<p class="wp-block-paragraph">Oh, I got to put R12.</p>



<p class="wp-block-paragraph">Yeah, then we can get the, wait a minute, wait a minute.</p>



<p class="wp-block-paragraph">Oh, I threw off the line numbers because I added the variables up here.</p>



<p class="wp-block-paragraph">So now we&#8217;re going to break at 21.</p>



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



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



<p class="wp-block-paragraph">We&#8217;ll do a quit.</p>



<p class="wp-block-paragraph">Make debug again.</p>



<p class="wp-block-paragraph">And now we&#8217;re at 21.</p>



<p class="wp-block-paragraph">If I say info registers, we can see R12 is that big value.</p>



<p class="wp-block-paragraph">you, but we can also print R12 directly. And we should be able to print my thing one, hopefully,</p>



<p class="wp-block-paragraph">has an unknown type, oh, we have to cast it. So we can do like basic casting in GDB. So I&#8217;m going</p>



<p class="wp-block-paragraph">to say this is a character pointer. Remember, all of the assembly symbols are basically pointers,</p>



<p class="wp-block-paragraph">unless it&#8217;s an EQU, EQU variable. In that case, it&#8217;s more of a define. So I&#8217;m going to print</p>



<p class="wp-block-paragraph">and then it says error cannot access the memory add address</p>



<p class="wp-block-paragraph">what the heck did i do wrong how about that cannot access that all right i&#8217;ll come back in</p>



<p class="wp-block-paragraph">another video because this wasn&#8217;t something that i prepared for just to print strings in globals</p>



<p class="wp-block-paragraph">i&#8217;ll come back at some later date in the future like five years from now and i&#8217;ll just show you</p>



<p class="wp-block-paragraph">how to print globals but i hope if you&#8217;re in assembly you probably don&#8217;t need to worry about</p>



<p class="wp-block-paragraph">You just have globals, but the real problem for you is going to be what&#8217;s inside of your registers and so forth.</p>



<p class="wp-block-paragraph">You can also deref, I think.</p>



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



<p class="wp-block-paragraph">Okay, I&#8217;m going to move on from that.</p>



<p class="wp-block-paragraph">So anyway, we got a script and we got a lot of basic GDB commands.</p>



<p class="wp-block-paragraph">Is there anything else that I wanted to show you?</p>



<p class="wp-block-paragraph">Let me just look at my notes real fast here to make sure I&#8217;m not forgetting to say anything.</p>



<p class="wp-block-paragraph">make sure I&#8217;m not forgetting to say anything.</p>



<p class="wp-block-paragraph">So we&#8217;re going to do debug symbols, console, quit, attach to binary,</p>



<p class="wp-block-paragraph">launching the program, uncaught exception, breakpoints, info, delete,</p>



<p class="wp-block-paragraph">enable, disable, run, continue, end times, info registers, printing.</p>



<p class="wp-block-paragraph">Oh, we can print a register in binary.</p>



<p class="wp-block-paragraph">Forgot to show that.</p>



<p class="wp-block-paragraph">So we are at a breakpoint, I think.</p>



<p class="wp-block-paragraph">And if we printed R12 with the regular print, we can also do P slash T to just</p>



<p class="wp-block-paragraph">p slash t to just sort of print it in binary if you want to i think i might have said that already</p>



<p class="wp-block-paragraph">either that or i said that like a couple days ago to some and then we can do info locals and</p>



<p class="wp-block-paragraph">then print a variable and then we get the script file and then we can quit okay so i think this is</p>



<p class="wp-block-paragraph">pretty much everything that i wanted to show you you now have a basic idea of what we can do inside</p>



<p class="wp-block-paragraph">of gdb but keep in mind there is so much more you can do in gdb than i can fit in one video</p>



<p class="wp-block-paragraph">can type help and you can see a list of other major you know areas that gdb can handle um you</p>



<p class="wp-block-paragraph">can do uh let&#8217;s see i think it&#8217;s help and then like we&#8217;ve got information on aliases breakpoints</p>



<p class="wp-block-paragraph">data you know whatever we can do i think help breakpoints to see more information on breakpoint</p>



<p class="wp-block-paragraph">commands yeah so all of the things you can do with breakpoints is like all of these commands here</p>



<p class="wp-block-paragraph">one page we have to enter to see one more page or see to see all of the results without using</p>



<p class="wp-block-paragraph">paging anymore so i&#8217;m just hit c and so there&#8217;s like you know we can save trace points we can</p>



<p class="wp-block-paragraph">try to catch exceptions we can enable disable break points there&#8217;s like unwinders which i&#8217;ve</p>



<p class="wp-block-paragraph">never even used we can bookmark things we can you know start tracing memory we can rethrow</p>



<p class="wp-block-paragraph">variables so just keep in mind gdp is incredibly powerful this video barely scratches the surface</p>



<p class="wp-block-paragraph">but for a programmer who is new to debugging i think this will be very useful to you i hope it is</p>



<p class="wp-block-paragraph">anyway thanks for watching this video i hope you learned a little bit of stuff and had a</p>



<p class="wp-block-paragraph">little bit of fun um i will see you in the next video rest yourself and take a nap and have fun</p>



<p class="wp-block-paragraph">and hug your your loved ones okay I&#8217;m out see you later hey everybody thanks</p>



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



<p class="wp-block-paragraph">it I do hope you did learn something and have some fun if you could do me a</p>



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



<p class="wp-block-paragraph">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 it would really mean the world to me</p>



<p class="wp-block-paragraph">and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do</p>



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



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



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



<p class="wp-block-paragraph">know somebody subscribed or followed it just wakes me up and I get filled with</p>



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



<p class="wp-block-paragraph">So you could do it as a nice favor to me,</p>



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



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



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



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now,</p>



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



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



<p class="wp-block-paragraph">and all that good stuff.</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,</p>



<p class="wp-block-paragraph">clarifications or errata, or just future videos that you want to see, please leave a comment.</p>



<p class="wp-block-paragraph">Or if you just want to say, Hey, what&#8217;s up, what&#8217;s going on? You know, just send me a comment,</p>



<p class="wp-block-paragraph">whatever. I also wake up for those in the middle of the night. I get, I wake up in a cold sweat</p>



<p class="wp-block-paragraph">and I&#8217;m like, it would really, it really mean the world to me. I would really appreciate it. So</p>



<p class="wp-block-paragraph">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/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/">Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB 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/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/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>How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</title>
		<link>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/</link>
					<comments>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 02 Jun 2025 13:04:50 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[code linking]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[executable files]]></category>
		<category><![CDATA[jump instructions]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[module linking]]></category>
		<category><![CDATA[object files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming basics]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[virtual memory]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=139</guid>

					<description><![CDATA[<p>Learn how linkers connect code modules, manage virtual memory, and handle jumps in this beginner-friendly guide to programming! #Linker #Coding</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained" width="1380" height="776" src="https://www.youtube.com/embed/Q6B9FWCeaFs?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 everyone, let’s talk linkers! In this video, we unpack the general idea of linking in programming—taking your source code, turning it into object files, and stitching them into an executable. We dive into virtual memory, how programs use offsets, and why jump instructions matter across modules. Using simple assembly and C++ examples, we’ll show how linkers lay out modules, handle labels, and make function calls work. Whether you’re a beginner or a coder curious about what happens under the hood, this is for you! Hit subscribe, scan the QR code for more tutorials, and drop a comment with your thoughts or video ideas. Let’s keep learning and have some fun with code! #Programming #Linker #VirtualMemory #CodingExplained</p>



<p class="wp-block-paragraph">Introduction to Linking 00:00:00<br>Compilation and Object Files 00:00:05<br>Linker Overview 00:00:32<br>Virtual Memory Explanation 00:00:42<br>Program Memory Offsets 00:01:18<br>Jump Instructions in Modules 00:02:54<br>Module Address Space 00:03:38<br>Assembler and Label Jumps 00:04:02<br>Linker’s Role in Module Layout 00:07:15<br>Function Calls Across Modules 00:08:04<br>Marking Labels as Global 00:09:31<br>External Function Calls 00:10:23<br>Data in Executables 00:11:12<br>Conclusion and Call to Subscribe 00:12:08</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey there, I want to talk to you very quickly about the general idea of linking your programs.</p>



<p class="wp-block-paragraph">In previous videos I&#8217;ve described exactly how to perform the linking stage when you&#8217;re compiling</p>



<p class="wp-block-paragraph">a program. So you write some source code, you compile the source code into object files,</p>



<p class="wp-block-paragraph">you know each file becomes one individual object file, and then when we&#8217;re done we take all the</p>



<p class="wp-block-paragraph">object files and we link them up into an executable program. So I&#8217;ve talked about that</p>



<p class="wp-block-paragraph">I just wanted to talk to you about the general idea of the linking stage in general.</p>



<p class="wp-block-paragraph">Like what is the linker? What is its job? What is it actually doing?</p>



<p class="wp-block-paragraph">So try to keep in mind for starters, each program uses virtual memory.</p>



<p class="wp-block-paragraph">It uses a virtual memory space.</p>



<p class="wp-block-paragraph">So obviously on your computer you have real memory,</p>



<p class="wp-block-paragraph">but there&#8217;s lots of layers of abstraction between the physical hardware</p>



<p class="wp-block-paragraph">the physical hardware and the program that&#8217;s running for starters the operating system uses</p>



<p class="wp-block-paragraph">a paging system the memory stick the memory circuitry might be doing something else for</p>



<p class="wp-block-paragraph">error checking or just you know transport or whatever so so try and bear in mind that each</p>



<p class="wp-block-paragraph">program thinks that it&#8217;s it thinks that itself is kind of the beginning of memory you could imagine</p>



<p class="wp-block-paragraph">it as each program thinks that its first memory location that it has assigned to it is memory</p>



<p class="wp-block-paragraph">location zero but that wouldn&#8217;t necessarily be the case on the computer</p>



<p class="wp-block-paragraph">your operating system probably would have come up with an offset let&#8217;s say</p>



<p class="wp-block-paragraph">for example you know your computer decides to launch your program it</p>



<p class="wp-block-paragraph">creates a process it finds a chunk of memory that&#8217;s available across you know</p>



<p class="wp-block-paragraph">one or more pages of free memory and let&#8217;s say for the sake of argument that</p>



<p class="wp-block-paragraph">the starting offset for the for the quote-unquote real forgetting the other</p>



<p class="wp-block-paragraph">layers layers of abstraction the real memory location of your program is going</p>



<p class="wp-block-paragraph">of your program is going to be let&#8217;s just say like a thousand I know that&#8217;s</p>



<p class="wp-block-paragraph">real unrealistically too low but let&#8217;s just say a thousand and then let&#8217;s say</p>



<p class="wp-block-paragraph">that your program then thinks that it starts at memory location zero that</p>



<p class="wp-block-paragraph">means if your program wants to access memory location 100 then under the hood</p>



<p class="wp-block-paragraph">at the last moment right before you actually hit the RAM stick or hit the</p>



<p class="wp-block-paragraph">page file system a translation has to be performed so if your program is trying</p>



<p class="wp-block-paragraph">what actually happens is you know the general offset for the entire program</p>



<p class="wp-block-paragraph">gets added to memory location 100 and then that tells the computer or the</p>



<p class="wp-block-paragraph">operating system that what you&#8217;re actually trying to do in your program is</p>



<p class="wp-block-paragraph">access memory location 1100 so keep in mind all of this memory is virtual</p>



<p class="wp-block-paragraph">and the modules themselves also need to know where to jump when I say where to</p>



<p class="wp-block-paragraph">Well, suppose for the sake of argument, you have a program that has some jump instructions</p>



<p class="wp-block-paragraph">or go to instructions or like some conditional branching instructions, anything where execution</p>



<p class="wp-block-paragraph">is not just going to go to the very next statement.</p>



<p class="wp-block-paragraph">Execution is going to go somewhere else.</p>



<p class="wp-block-paragraph">Like maybe you have an if else block.</p>



<p class="wp-block-paragraph">It&#8217;s got to maybe jump sometimes down to the else part instead of the top if part.</p>



<p class="wp-block-paragraph">And then when it&#8217;s done executing, it&#8217;s going to jump until after the whole block, you know,</p>



<p class="wp-block-paragraph">There will be lots of times in all of your programs where execution kind of has to jump</p>



<p class="wp-block-paragraph">around somewhere if the program is even a little bit complicated.</p>



<p class="wp-block-paragraph">So that could be a jump instruction, go to in a higher level language, not assembly necessarily,</p>



<p class="wp-block-paragraph">jump if not equal and so forth.</p>



<p class="wp-block-paragraph">So if you imagine writing one module, you could also imagine that the module has its</p>



<p class="wp-block-paragraph">own virtual memory address space.</p>



<p class="wp-block-paragraph">Just imagine it for now.</p>



<p class="wp-block-paragraph">And maybe it starts at zero.</p>



<p class="wp-block-paragraph">at zero that&#8217;s that&#8217;s not what we&#8217;re going to say but just like imagine the module only really knows</p>



<p class="wp-block-paragraph">about itself and so sometimes when you&#8217;re jumping for example if we&#8217;re going to jump uh when</p>



<p class="wp-block-paragraph">something is not equal to something else we&#8217;ll jump to some label and in order to jump to that</p>



<p class="wp-block-paragraph">label the assembler needs to know you know where is that label inside of your source code so pretend</p>



<p class="wp-block-paragraph">just for a moment this is not like a real assembly program but just pretend for a moment that we have</p>



<p class="wp-block-paragraph">and maybe this is like I don&#8217;t know the main label that gets jumped into from GCC and</p>



<p class="wp-block-paragraph">so then we have like a label down here outside and we&#8217;ll do stuff and then jump back to the</p>



<p class="wp-block-paragraph">original point so we probably have to do a label here main finish this is this is bad form but I&#8217;m</p>



<p class="wp-block-paragraph">So if we jump, let&#8217;s compare, I don&#8217;t know, one with two or something.</p>



<p class="wp-block-paragraph">Let&#8217;s compare RAX to RDX and we&#8217;ll just move RAX the value one and move RDX the value two</p>



<p class="wp-block-paragraph">so they&#8217;re not actually equal.</p>



<p class="wp-block-paragraph">And then we compare them and then we say, all right, jump if they&#8217;re not equal to this label.</p>



<p class="wp-block-paragraph">So definitely now we know, oh, we are going to jump down to that label.</p>



<p class="wp-block-paragraph">So execution is going to go directly down to here.</p>



<p class="wp-block-paragraph">we&#8217;ll do something and then eventually maybe we want to jump back so we&#8217;ll say uh</p>



<p class="wp-block-paragraph">maybe let&#8217;s do it again let&#8217;s do let&#8217;s do like a whole set of statements again we&#8217;ll say jump</p>



<p class="wp-block-paragraph">if it is equal and we&#8217;ll just like load those two registers so one and one and then compare</p>



<p class="wp-block-paragraph">them and then say jump if it is equal to main finish this is not a video about conditional</p>



<p class="wp-block-paragraph">branching or jumping i&#8217;m trying to make this as simple as i can but i hope you understand the</p>



<p class="wp-block-paragraph">but i hope you understand the point is just basically we&#8217;re jumping around within the same</p>



<p class="wp-block-paragraph">module right so it&#8217;s easy for the program to understand where to jump if it&#8217;s in the same</p>



<p class="wp-block-paragraph">module or i guess the the object file when we&#8217;re assembling it it&#8217;s easy to understand where to jump</p>



<p class="wp-block-paragraph">because if we&#8217;re at line 8 here when we start to jump and then the actual label here has its first</p>



<p class="wp-block-paragraph">instruction at line 17 well then it you know the amount of instructions to move is just the</p>



<p class="wp-block-paragraph">the difference you know so it&#8217;s easy to say all right if our virtual address is you know this</p>



<p class="wp-block-paragraph">when we jump and we&#8217;re going to jump this much of a difference based on where the label is then now</p>



<p class="wp-block-paragraph">we can just compute the new virtual address to jump or the absolute address or whatever you want</p>



<p class="wp-block-paragraph">to whatever you want to do on that particular run but how does it know where to jump in another</p>



<p class="wp-block-paragraph">module because when we assemble this module as an object file the assembler is only running one pass</p>



<p class="wp-block-paragraph">one pass on just this object file it doesn&#8217;t really know the addresses in the other modules</p>



<p class="wp-block-paragraph">it doesn&#8217;t know their offsets of its labels even if it&#8217;s a c plus plus or a c module it doesn&#8217;t</p>



<p class="wp-block-paragraph">really know the offsets it doesn&#8217;t know where the functions start and end doesn&#8217;t know anything</p>



<p class="wp-block-paragraph">because right now if we assemble this one source code it&#8217;s only going to know about this one source</p>



<p class="wp-block-paragraph">code right and the same goes for the other modules if we compile a c plus plus program to an object</p>



<p class="wp-block-paragraph">a function or you know do a go to statement or something into one of these labels from this</p>



<p class="wp-block-paragraph">module the c plus plus program won&#8217;t really know where it is it won&#8217;t know what address it&#8217;s at it</p>



<p class="wp-block-paragraph">won&#8217;t know the offset right so that&#8217;s the job of the linker the linker looks at all of these labels</p>



<p class="wp-block-paragraph">and all of these uh conditional branching statements and jump statements and everything</p>



<p class="wp-block-paragraph">and it just decides for starters it decides where each module is going to start in memory so maybe</p>



<p class="wp-block-paragraph">I don&#8217;t know if your C++ module starts up here somewhere and then it&#8217;ll say this assembly module</p>



<p class="wp-block-paragraph">starts right after it and then another module right after that and it&#8217;ll just kind of decide</p>



<p class="wp-block-paragraph">where every module will start in the final executable that we&#8217;re actually linking together.</p>



<p class="wp-block-paragraph">Once it decides the layout then it knows the offset of all the different modules and therefore</p>



<p class="wp-block-paragraph">it can compute the additional offset that it would take to get to all the labels. So then at that</p>



<p class="wp-block-paragraph">Your C++ module will make a function call inside of, you know, some assembly module like the one we&#8217;re looking at, assuming it was written a little bit differently.</p>



<p class="wp-block-paragraph">Main finish return.</p>



<p class="wp-block-paragraph">I guess the way it&#8217;s written down here, it&#8217;s returning to main if we just kind of execute it as we&#8217;re looking at it.</p>



<p class="wp-block-paragraph">But another module could could call main finish as a function and still get a return statement.</p>



<p class="wp-block-paragraph">That would actually work, even though it&#8217;s probably bad design.</p>



<p class="wp-block-paragraph">that your assembly sorry your C++ program wants to call a function called</p>



<p class="wp-block-paragraph">main finish inside of this module the linker having already laid out the</p>



<p class="wp-block-paragraph">modules and and being aware of all their offsets it knows okay so you know this</p>



<p class="wp-block-paragraph">assembly module it was underneath the C++ module so it&#8217;ll just take that offset</p>



<p class="wp-block-paragraph">and add it to the offset of the label itself within the module and then also</p>



<p class="wp-block-paragraph">add that to the the virtual address or I guess the operating system will do the</p>



<p class="wp-block-paragraph">address. But you know, the point is the linker coordinates all the jumps and the conditional</p>



<p class="wp-block-paragraph">branches where the functions start, lays out all the modules, gets all the offsets,</p>



<p class="wp-block-paragraph">and then starts replacing all of the conditional branches and jumps and things with the real</p>



<p class="wp-block-paragraph">offsets that make it actually doable. Like let&#8217;s jump to exactly this memory location</p>



<p class="wp-block-paragraph">in code exactly in quotes, because we&#8217;re still using virtual addressing.</p>



<p class="wp-block-paragraph">idea of the linker it knows how to jump between modules um wants to link or discuss okay that&#8217;s</p>



<p class="wp-block-paragraph">all i really wanted to say don&#8217;t forget if you want a label to be available to jump into or to</p>



<p class="wp-block-paragraph">call as a function from outside the module you got to mark it as global so if i actually wanted</p>



<p class="wp-block-paragraph">somebody to be able to call main finish as a function i just have to mark it as global same</p>



<p class="wp-block-paragraph">thing for some label if i say global some label then now at this point another module could call</p>



<p class="wp-block-paragraph">call this as a function or jump into it probably bad form to not put a return a return statement</p>



<p class="wp-block-paragraph">at this point which means when i&#8217;m calling it up here instead of jump not equal to i probably have</p>



<p class="wp-block-paragraph">to add more complicated logic so i can use a function call that gets jumped around if it is</p>



<p class="wp-block-paragraph">equal but so i&#8217;m not going to go that far right now kind of complicated just for this video</p>



<p class="wp-block-paragraph">and then also of course if you intend to jump somewhere else remember that you have to mark</p>



<p class="wp-block-paragraph">So let&#8217;s say there&#8217;s a function in your other module, your C++ module or your C module or your assembly module.</p>



<p class="wp-block-paragraph">You just have to mark it as extern in the text section, in the text segment, like some other function somewhere else, something like that.</p>



<p class="wp-block-paragraph">And then once I do that, now I could actually call it, I could say, call, you know, this.</p>



<p class="wp-block-paragraph">Actually, that&#8217;ll never get reached because the jump equal thing is at the bottom.</p>



<p class="wp-block-paragraph">equal thing is at the bottom but I could do this I could say call it if it was actually a function</p>



<p class="wp-block-paragraph">or I could say jump if it was just a jump point or I could say you know jump not equal to</p>



<p class="wp-block-paragraph">the other function instead of some label something like that so lots of stuff you can do and now you</p>



<p class="wp-block-paragraph">kind of understand the idea of linking is taking all the modules stuffing them inside of the final</p>



<p class="wp-block-paragraph">executable and also putting data inside of the final executable you know like if you&#8217;re creating</p>



<p class="wp-block-paragraph">So, you know, like if you&#8217;re creating a string variable in your globals area of your assembly</p>



<p class="wp-block-paragraph">program or hard coding, any kind of string anywhere in your C++, then it&#8217;s got to be</p>



<p class="wp-block-paragraph">inside of the executable.</p>



<p class="wp-block-paragraph">Otherwise, it wouldn&#8217;t be anywhere when we ran the program.</p>



<p class="wp-block-paragraph">So, yeah, it sticks the data in there.</p>



<p class="wp-block-paragraph">It sticks the segments in there.</p>



<p class="wp-block-paragraph">It, you know, calculates the jumps and all that stuff.</p>



<p class="wp-block-paragraph">I just want to point out you could put strings in a configuration file.</p>



<p class="wp-block-paragraph">of a vanilla C++ or assembly program you probably are making strings directly in the program.</p>



<p class="wp-block-paragraph">Anyway, so I think that&#8217;s the gist of everything that I really wanted to say about what is the</p>



<p class="wp-block-paragraph">general idea of the linker. Thanks for watching this video I hope you learned a little bit and</p>



<p class="wp-block-paragraph">had some fun. I will see you in the next video. Hey everybody thanks for watching this video again</p>



<p class="wp-block-paragraph">it i do hope you did learn something and have some fun if you could do me a please a small little</p>



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



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p class="wp-block-paragraph">world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



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



<p class="wp-block-paragraph">and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time. So you could do it as a nice favor to me or you</p>



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



<p class="wp-block-paragraph">and then I&#8217;ll just wake up. I promise that&#8217;s what will happen. Also, if you look 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 to the website,</p>



<p class="wp-block-paragraph">is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where</p>



<p class="wp-block-paragraph">you 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, 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 and enjoy the cool music as I fade into</p>



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master GNU Makefiles: Streamline Coding Builds with C++, C &#038; Assembly</title>
		<link>https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/</link>
					<comments>https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 25 May 2025 07:53:49 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[beginner coding]]></category>
		<category><![CDATA[build automation]]></category>
		<category><![CDATA[build system]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[coding workflow]]></category>
		<category><![CDATA[compile code]]></category>
		<category><![CDATA[GNU Make]]></category>
		<category><![CDATA[Makefile tutorial]]></category>
		<category><![CDATA[programming tips]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[streamline coding]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=113</guid>

					<description><![CDATA[<p>Master GNU Make! Simplify coding with Makefiles, manage C++, C, assembly builds, and cut compile times. Beginner-friendly guide!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/">Master GNU Makefiles: Streamline Coding Builds with C++, C &amp; 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 GNU Makefiles: Streamline Coding Builds with C++, C &amp; Assembly" width="1380" height="776" src="https://www.youtube.com/embed/fvaoc5Ogp7Y?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">Tired of typing endless compile commands? Join me in this fun, hands-on guide to mastering GNU Make! We’ll walk through creating a Makefile to simplify your coding builds, covering C++, C, and assembly projects. Learn how to set up variables, define functions, manage dependencies, and organize build directories to cut compile times drastically. From practical tips like using clean targets to advanced tricks like dynamic variable assignments, this video has it all. Whether you’re a beginner or a seasoned coder, you’ll see how Makefiles can transform your workflow. Plus, I share a real story of turning a 1-hour build into 1 minute! Subscribe for more coding tutorials, and let me know how Makefiles change your game. Scan the QR code for more resources!</p>



<p class="wp-block-paragraph">Introduction to Make Files 00:00:00<br>What is a Build System 00:00:11<br>Problems with Manual Compilation 00:00:16<br>Using Scripts vs Build Systems 00:00:36<br>Benefits of Make Build System 00:00:56<br>Personal Experience with Build Times 00:01:15<br>Creating Sample Source Files 00:02:20<br>Installing Make Build System 00:04:56<br>Creating a Makefile 00:06:02<br>Defining Functions in Makefile 00:06:46<br>Calling Functions and Variables 00:07:13<br>Setting Up Compiler Variables 00:10:51<br>Dynamic vs Static Variable Assignment 00:11:56<br>Compiler and Linker Flags 00:12:44<br>Setting Up Build Paths 00:19:16<br>Printing Variables for Debugging 00:21:24<br>Understanding Targets in Make 00:25:10<br>Dependency Graph and Compilation 01:02:04<br>Managing Build Directory 01:03:11<br>Creating Binary Target 01:05:44<br>Handling Object Files 01:11:29<br>Running the Program 01:13:16<br>Clean Target for Cleanup 01:17:00<br>Advanced Build System Features 01:22:46<br>Git Ignore for Build Files 01:24:34<br>Conclusion and Call to Action 01:25:08</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey there, let&#8217;s talk about using make files and the make build system.</p>



<p class="wp-block-paragraph">So what&#8217;s a build system? It&#8217;s basically just a program that helps you compile your program.</p>



<p class="wp-block-paragraph">In a previous video, I talked about the idea that it&#8217;s really cumbersome</p>



<p class="wp-block-paragraph">to type out build commands, you know, compiling commands, linking commands and so forth for your</p>



<p class="wp-block-paragraph">cumbersome and you&#8217;ll forget everything that you&#8217;re supposed to be doing. So the next upgrade</p>



<p class="wp-block-paragraph">from that was in a previous video I talked about let&#8217;s take all the commands and put them into a</p>



<p class="wp-block-paragraph">script so that we don&#8217;t really have to remember all the commands. We can just, you know, create</p>



<p class="wp-block-paragraph">a build script and then just kind of run it when we want a program to compile and link and execute.</p>



<p class="wp-block-paragraph">But then the thing is about a script is if you have a very, very large program,</p>



<p class="wp-block-paragraph">it might take a very long time to compile. So a build system will take care of that for you.</p>



<p class="wp-block-paragraph">care of that for you the build system that i&#8217;m about to show you the make build system</p>



<p class="wp-block-paragraph">it can carefully calculate which source code files you&#8217;ve actually changed since the last</p>



<p class="wp-block-paragraph">time that you built your program and it will only rebuild the source code files</p>



<p class="wp-block-paragraph">that actually need to be rebuilt you know into their corresponding object files and such</p>



<p class="wp-block-paragraph">so for as a personal example long time ago before i learned how to use build systems i had a giant</p>



<p class="wp-block-paragraph">And every single little change that I made, I would just have to wait for like an hour.</p>



<p class="wp-block-paragraph">Like I&#8217;d have to go get a sandwich or go do something else or work on a different project for an hour.</p>



<p class="wp-block-paragraph">Then come back and see if my changes actually affected anything.</p>



<p class="wp-block-paragraph">Somewhat quickly, I got irritated enough that I looked into build systems.</p>



<p class="wp-block-paragraph">And I realized that make, the one that I&#8217;m showing you today, is pretty easy.</p>



<p class="wp-block-paragraph">It goes really, really far, but it&#8217;s pretty easy to get started.</p>



<p class="wp-block-paragraph">And it drastically reduced my compile times.</p>



<p class="wp-block-paragraph">set up, you know, the make file and everything so that I let the build system do the building.</p>



<p class="wp-block-paragraph">My build only took like a minute. So I could do like a quick change and then just wait one minute</p>



<p class="wp-block-paragraph">to see the results and then another quick change and so forth. Okay. So if you look at the screen</p>



<p class="wp-block-paragraph">here, I&#8217;m sitting here on a blank desktop. Hopefully I&#8217;m recording everything. Am I?</p>



<p class="wp-block-paragraph">I&#8217;m sitting on a blank page here. So let me just make a couple of source code files. This is not</p>



<p class="wp-block-paragraph">This is not a tutorial for C++ or assembly or anything.</p>



<p class="wp-block-paragraph">I&#8217;m just going to copy paste a couple of sample programs in here real fast.</p>



<p class="wp-block-paragraph">So I&#8217;m creating a C++ source code file.</p>



<p class="wp-block-paragraph">I&#8217;m calling it first.cpp and it&#8217;s going to call functions from other source code files.</p>



<p class="wp-block-paragraph">This is going to be a hybrid program.</p>



<p class="wp-block-paragraph">Again, don&#8217;t really worry about this.</p>



<p class="wp-block-paragraph">My other videos already explained hybrid programs and so forth.</p>



<p class="wp-block-paragraph">I&#8217;m just going to show you how to use the make build system.</p>



<p class="wp-block-paragraph">the make build system.</p>



<p class="wp-block-paragraph">So let&#8217;s make another source code file called second dot C.</p>



<p class="wp-block-paragraph">And then another one called third dot ASM.</p>



<p class="wp-block-paragraph">So I&#8217;m linking a I&#8217;m linking three source.</p>



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



<p class="wp-block-paragraph">I&#8217;m linking three source code files.</p>



<p class="wp-block-paragraph">And they&#8217;re all in different languages just to prove to you that this will work</p>



<p class="wp-block-paragraph">with a hybrid program.</p>



<p class="wp-block-paragraph">And so you can kind of see I&#8217;ve got first, second and third.</p>



<p class="wp-block-paragraph">The first one is C++.</p>



<p class="wp-block-paragraph">The second one is just C.</p>



<p class="wp-block-paragraph">Third one is assembly.</p>



<p class="wp-block-paragraph">If I look at it real fast, get ready to pause the video.</p>



<p class="wp-block-paragraph">real fast get ready to pause the video then you can see that it&#8217;s C++ and if we look at the second</p>



<p class="wp-block-paragraph">one it&#8217;s just C and if we look at the third one it&#8217;s just a very simple assembly program and they</p>



<p class="wp-block-paragraph">just sort of say hello and that&#8217;s it okay so you know at this point in my other video I would have</p>



<p class="wp-block-paragraph">made a compile script I&#8217;d say nano compile and then I&#8217;d stick a bunch of compile commands inside</p>



<p class="wp-block-paragraph">of it let&#8217;s see do I even have that from last time let me see if I got it if I have it I&#8217;ll</p>



<p class="wp-block-paragraph">I got it if I have it I&#8217;ll just paste it real fast just to show you compile I don&#8217;t think I&#8217;ve</p>



<p class="wp-block-paragraph">got it although I do okay I&#8217;m just gonna paste it in here and it&#8217;s not the point of this video check</p>



<p class="wp-block-paragraph">my other video if you want to kind of understand everything that&#8217;s going on in here but it&#8217;s just</p>



<p class="wp-block-paragraph">a script so I&#8217;m gonna go compile clear and then list and then in the last video I just said let&#8217;s</p>



<p class="wp-block-paragraph">and it compiles everything and it links the binary and then I can run main which is my binary and then</p>



<p class="wp-block-paragraph">it just runs this program so it&#8217;s no problem it seems okay but again imagine that your program is</p>



<p class="wp-block-paragraph">huge many many lines of source code in every single file and many many many source code files</p>



<p class="wp-block-paragraph">and perhaps you&#8217;re pulling in libraries and shared objects and just like you know a bunch of other</p>



<p class="wp-block-paragraph">stuff your your your building could slow down drastically so I&#8217;m going to remove the compiler</p>



<p class="wp-block-paragraph">the compiler script and then I&#8217;m going to manually remove all the compiled</p>



<p class="wp-block-paragraph">object files. Got to be careful with this. Remove the binary. Okay. So now I&#8217;ve got</p>



<p class="wp-block-paragraph">that one, two, three. Okay. Now I&#8217;m ready to set up a make file. So I guess first</p>



<p class="wp-block-paragraph">you probably should have the make build system installed. If you&#8217;re if you&#8217;re</p>



<p class="wp-block-paragraph">learning about C++ and assembly you probably already do but just just so you</p>



<p class="wp-block-paragraph">know it&#8217;s a it&#8217;s gonna show up in Ubuntu as the build essentials package so</p>



<p class="wp-block-paragraph">So sudo apt install build essentials.</p>



<p class="wp-block-paragraph">I can&#8217;t remember if this is plural or not.</p>



<p class="wp-block-paragraph">It&#8217;s either build essentials or build essential.</p>



<p class="wp-block-paragraph">You can do an apt search or a DNF search depending on your system.</p>



<p class="wp-block-paragraph">We can do build essential and see what shows up.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to go to the top build essential.</p>



<p class="wp-block-paragraph">Okay, so it was singular, not plural.</p>



<p class="wp-block-paragraph">I have it installed already.</p>



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



<p class="wp-block-paragraph">If you just want to install make by itself, you can probably do apt search.</p>



<p class="wp-block-paragraph">search, just make and go up to the Ms.</p>



<p class="wp-block-paragraph">You can see right here.</p>



<p class="wp-block-paragraph">It&#8217;s just pseudo apt install.</p>



<p class="wp-block-paragraph">Make is all you really have to do to get the whole make build system.</p>



<p class="wp-block-paragraph">They&#8217;ve got a website, you know, search for Gnu make.</p>



<p class="wp-block-paragraph">I&#8217;m going to type it on the screen here.</p>



<p class="wp-block-paragraph">Gnu make search for that.</p>



<p class="wp-block-paragraph">You&#8217;ll get a nice website with a bunch</p>



<p class="wp-block-paragraph">of documentation and examples that go way beyond this video.</p>



<p class="wp-block-paragraph">But I&#8217;m just going to show you the basics so you can get started.</p>



<p class="wp-block-paragraph">So the first thing you should do is create a file called make file.</p>



<p class="wp-block-paragraph">create a file called make file. I think under lowercase m is supported but I usually do uppercase</p>



<p class="wp-block-paragraph">m which is obviously supported because I always do it and what you&#8217;re really going to do is you&#8217;re</p>



<p class="wp-block-paragraph">just going to create an empty file call it make file and then inside of the make file you&#8217;re just</p>



<p class="wp-block-paragraph">going to give make a bunch of commands and things that you want it to do and then later when you&#8217;re</p>



<p class="wp-block-paragraph">actually ready to compile you&#8217;ll just type make as a command and then give make an instruction and</p>



<p class="wp-block-paragraph">have lots of instructions and targets available inside of the make file for</p>



<p class="wp-block-paragraph">make to grab onto. Okay, so moving on. The first thing I want to show you is how to</p>



<p class="wp-block-paragraph">define a function in make. You probably won&#8217;t do this a lot, but for me I kind of</p>



<p class="wp-block-paragraph">like to print, you know, pretty messages and sort of like do repetitive tasks in a</p>



<p class="wp-block-paragraph">function. So when you want to define a function you just use the keyword define</p>



<p class="wp-block-paragraph">and then you name the function. So I&#8217;m gonna make a function called say which I</p>



<p class="wp-block-paragraph">see what it&#8217;s for I know it&#8217;s silly define say and then I&#8217;m going to tab here and then I&#8217;m going to</p>



<p class="wp-block-paragraph">tell it to print some information I&#8217;ll just put test info for now the thing about calling functions</p>



<p class="wp-block-paragraph">is you usually put a dollar sign and then an open parenthesis and then the name of the function and</p>



<p class="wp-block-paragraph">then after that arguments to the function so here you can see actually let me get line numbers up</p>



<p class="wp-block-paragraph">here on nano you can see online too I am calling a function called info it&#8217;s a built-in system</p>



<p class="wp-block-paragraph">it&#8217;s a built-in system function you don&#8217;t have to define it yourself and I&#8217;m</p>



<p class="wp-block-paragraph">telling it I want you to print some info to the screen and I want you to print</p>



<p class="wp-block-paragraph">test info to the screen and that&#8217;s it so in my make file I can just call that</p>



<p class="wp-block-paragraph">right away with call you know dollar sign parentheses and then the keyword</p>



<p class="wp-block-paragraph">call and then name the function that I want to call closing parentheses and</p>



<p class="wp-block-paragraph">then if the function takes arguments I put a comma and then just start</p>



<p class="wp-block-paragraph">providing the argument so I&#8217;ll just say hello what&#8217;s up actually this shouldn&#8217;t</p>



<p class="wp-block-paragraph">up. Actually, this shouldn&#8217;t take my arguments right now. We&#8217;ll upgrade it in a second. But</p>



<p class="wp-block-paragraph">so this is a very simple makefile. It doesn&#8217;t actually have any targets. It will just simply</p>



<p class="wp-block-paragraph">do things. This kind of stuff is useful. At the very top of your makefile later, we&#8217;re going to</p>



<p class="wp-block-paragraph">define like a bunch of variables. And sometimes it&#8217;s nice to print them out. So I just want to</p>



<p class="wp-block-paragraph">show you how to start printing so that maybe if your makefile isn&#8217;t working, you&#8217;ll realize that,</p>



<p class="wp-block-paragraph">oh, that variable is wrong because you printed everything when it started up. You don&#8217;t have to</p>



<p class="wp-block-paragraph">You don&#8217;t have to do it that way.</p>



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



<p class="wp-block-paragraph">So how do you invoke the make file?</p>



<p class="wp-block-paragraph">We just literally type make.</p>



<p class="wp-block-paragraph">And because we named the make file, make file,</p>



<p class="wp-block-paragraph">the make program will automatically figure out</p>



<p class="wp-block-paragraph">where it is and go find it and load it.</p>



<p class="wp-block-paragraph">But you can specify the name of a make file</p>



<p class="wp-block-paragraph">if you really want to.</p>



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



<p class="wp-block-paragraph">Actually, let me look it up just to be sure.</p>



<p class="wp-block-paragraph">I&#8217;m gonna go man make and just go down a second here.</p>



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



<p class="wp-block-paragraph">So this switch right here,</p>



<p class="wp-block-paragraph">here dash f and then specify the file name or file path or dash dash file and then specify the name</p>



<p class="wp-block-paragraph">or path that&#8217;s how you could use a non-standard make file but almost no one does that everyone</p>



<p class="wp-block-paragraph">just likes to to name it this way and then just type make so if i type make notice how the first</p>



<p class="wp-block-paragraph">thing it does is it says test info which is what i told it to do in that function which i called</p>



<p class="wp-block-paragraph">and then it says no targets gotta stop because we didn&#8217;t add any targets yet okay by the way if</p>



<p class="wp-block-paragraph">about what I&#8217;m even doing this for like compiling and whatever go see my other</p>



<p class="wp-block-paragraph">videos where we talk about compiling and linking and all that stuff this is just</p>



<p class="wp-block-paragraph">to make things a lot more easy and powerful so let&#8217;s upgrade this save</p>



<p class="wp-block-paragraph">function and I&#8217;m just gonna put some brackets and I&#8217;m gonna say my super cool</p>



<p class="wp-block-paragraph">make how about like builder I guess and then instead of test info I&#8217;m gonna put</p>



<p class="wp-block-paragraph">dollar sign one which basically is gonna tell this function you know when I call</p>



<p class="wp-block-paragraph">say, then the dollar sign one variable is going to show up as the first argument that I provided.</p>



<p class="wp-block-paragraph">So now when I call say, it should have hello, what&#8217;s up as the first argument that goes into</p>



<p class="wp-block-paragraph">the function. So that means it should print my super cool builder and then the message that I</p>



<p class="wp-block-paragraph">had it print. One more time, notice how it says my super cool builder. Hello, what&#8217;s up, I just like</p>



<p class="wp-block-paragraph">to do it this way, because then it&#8217;s easier for me to differentiate messages that the build system</p>



<p class="wp-block-paragraph">itself from the actual make file and messages that maybe the tools I&#8217;m calling on are giving like GCC or whatever</p>



<p class="wp-block-paragraph">So let&#8217;s edit this a little bit more</p>



<p class="wp-block-paragraph">The second thing I would like to do is well, maybe I&#8217;ll change this to just you know now running or something</p>



<p class="wp-block-paragraph">Now let&#8217;s set up some variables. I&#8217;m gonna do like a little thing here. I&#8217;m gonna say variables</p>



<p class="wp-block-paragraph">Put a bunch of comments in make files comments are just hashes</p>



<p class="wp-block-paragraph">So, you know, this, these lines right here don&#8217;t really do anything, 9, 10, 11.</p>



<p class="wp-block-paragraph">And I&#8217;m going to start setting up some variables for my compilers.</p>



<p class="wp-block-paragraph">So again, actually compiling is in a different video.</p>



<p class="wp-block-paragraph">We assume right now that you already know how to do it.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say, let&#8217;s do some variables for compilers.</p>



<p class="wp-block-paragraph">You don&#8217;t have to do it this way, but the standard convention for naming a regular C</p>



<p class="wp-block-paragraph">compilers or GCC seems to be just CC as the variable name.</p>



<p class="wp-block-paragraph">So I&#8217;m saying a variable named CC is going to be equal to GCC.</p>



<p class="wp-block-paragraph">to be equal to GCC and then from this point forward every time I use the variable CC in my</p>



<p class="wp-block-paragraph">script in my makefile it&#8217;s actually going to be like typing GCC and you know if you don&#8217;t understand</p>



<p class="wp-block-paragraph">why you would use variables you probably need to learn how to code a little bit more but basically</p>



<p class="wp-block-paragraph">it makes everything more powerful instead of typing GCC everywhere and then maybe later if I</p>



<p class="wp-block-paragraph">want to change it I have to go change it in a million places now I can just change it in one</p>



<p class="wp-block-paragraph">place and so it&#8217;s more powerful let&#8217;s do the same thing for the C++ compiler I&#8217;m going to say G++</p>



<p class="wp-block-paragraph">compiler I&#8217;m gonna say G++ same thing for my Yasm assembler I&#8217;m gonna say</p>



<p class="wp-block-paragraph">we&#8217;re using Yasm also notice how when I assign variables I&#8217;m not just using an</p>



<p class="wp-block-paragraph">equality or an assignment operator I&#8217;m not just doing equals that is a little</p>



<p class="wp-block-paragraph">bit different of a way to assign you can do that but if you just put an</p>



<p class="wp-block-paragraph">assignment operator by itself just like the equal then if you later change</p>



<p class="wp-block-paragraph">depends on on the right side, like another variable, then it will update on the left</p>



<p class="wp-block-paragraph">side. So it&#8217;s like, it&#8217;s not really a permanent assignment. It&#8217;s more like a dynamic assignment.</p>



<p class="wp-block-paragraph">So, you know, if you want to make sure that the variable has a fixed value that doesn&#8217;t change,</p>



<p class="wp-block-paragraph">even if you start changing variables that it depends on, then use colon equal. I&#8217;ll just leave it at that for now.</p>



<p class="wp-block-paragraph">Not super important. You can also tab and, you know, kind of line things up and it&#8217;s no problem.</p>



<p class="wp-block-paragraph">just to make things look nicer.</p>



<p class="wp-block-paragraph">So now let&#8217;s set up some flags for C and C++ and YASM.</p>



<p class="wp-block-paragraph">So I&#8217;m going to create a variable called ccflags,</p>



<p class="wp-block-paragraph">do the same thing again where I do the colon assignment operator.</p>



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



<p class="wp-block-paragraph">I want it to show me all warnings,</p>



<p class="wp-block-paragraph">and I want it to be pedantic about its warnings,</p>



<p class="wp-block-paragraph">and I want it to generate debug symbols.</p>



<p class="wp-block-paragraph">build system we want to try to compile source code files into object files first</p>



<p class="wp-block-paragraph">and then at a different stage link the object files together we we don&#8217;t want</p>



<p class="wp-block-paragraph">to just compile everything in one fell swoop directly to a binary in one line</p>



<p class="wp-block-paragraph">because we wouldn&#8217;t really be leveraging the power of the build system in a</p>



<p class="wp-block-paragraph">moment I&#8217;m going to draw a diagram that tries to make this a little more clear</p>



<p class="wp-block-paragraph">for now I&#8217;m just typing up variables so just bear with me when I&#8217;m you know</p>



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



<p class="wp-block-paragraph">So for C++, I&#8217;m actually going to reuse a variable here.</p>



<p class="wp-block-paragraph">I&#8217;m going to reuse the CC flags because all the flags</p>



<p class="wp-block-paragraph">above are fine for C++ as well as C.</p>



<p class="wp-block-paragraph">So that means like in my C++ compilation,</p>



<p class="wp-block-paragraph">I want all warnings and I want it to be pedantic and I want to generate debug</p>



<p class="wp-block-paragraph">symbols, but in C++, we&#8217;ll specify the C++ standard.</p>



<p class="wp-block-paragraph">So C++ 23.</p>



<p class="wp-block-paragraph">kind of already leveraging variables against other variables to save typing and make things a little</p>



<p class="wp-block-paragraph">bit more module. If I decided that all my C was not going to show warnings or was going to convert</p>



<p class="wp-block-paragraph">all warnings into errors or, you know, use a different flag or something, all I&#8217;d have to do</p>



<p class="wp-block-paragraph">is change it in one spot, line 20 and line 21 would automatically get updated. Also keep in mind</p>



<p class="wp-block-paragraph">because like I said before, we have this colon assignment operator here going on the right side.</p>



<p class="wp-block-paragraph">value of cc flags then it would be reflected if i didn&#8217;t use um the assignment operator you know</p>



<p class="wp-block-paragraph">what let&#8217;s let&#8217;s just do it let&#8217;s just do it real fast i&#8217;m going to say call say i&#8217;m going to say</p>



<p class="wp-block-paragraph">let&#8217;s let&#8217;s see cpp flags is and then i&#8217;m just going to print cpp flags you print variables kind</p>



<p class="wp-block-paragraph">of the same way that you call functions you just put a dollar sign and then surround the variable</p>



<p class="wp-block-paragraph">name in a set of parentheses and that&#8217;s pretty much it so i&#8217;m going to copy this line a couple</p>



<p class="wp-block-paragraph">And in between CPP flags, actually let&#8217;s do CC flags.</p>



<p class="wp-block-paragraph">We&#8217;ll assign CC flags to something.</p>



<p class="wp-block-paragraph">I&#8217;ll say hello test.</p>



<p class="wp-block-paragraph">And right now the way CPP flags is written, the assignment kind of sticks.</p>



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



<p class="wp-block-paragraph">It doesn&#8217;t dynamically depend on CC flags.</p>



<p class="wp-block-paragraph">So we should see two instances of the exact same message.</p>



<p class="wp-block-paragraph">Let me open up another window here because I want to keep that editor open.</p>



<p class="wp-block-paragraph">because I don&#8217;t I want to keep that editor open so we&#8217;ll do a make and notice how when it prints</p>



<p class="wp-block-paragraph">the CPP flags they&#8217;re the same it&#8217;s the same both times even though I changed CC flags in between</p>



<p class="wp-block-paragraph">those two messages on the other hand if I don&#8217;t put that to colon if I just put a sign then now</p>



<p class="wp-block-paragraph">it is dynamic notice how the second message uses the modified version of cc flags so keep that in</p>



<p class="wp-block-paragraph">So keep that in mind if you want a variable to be able to change anytime you depend on</p>



<p class="wp-block-paragraph">anytime a dependent variable that it depends on changes you&#8217;ll assign one way and if you</p>



<p class="wp-block-paragraph">don&#8217;t want it to change you&#8217;ll assign it another way okay so that&#8217;s enough of that I&#8217;m going to</p>



<p class="wp-block-paragraph">take away that message and I&#8217;m going to change this back to non-dynamic okay then we&#8217;ll do the</p>



<p class="wp-block-paragraph">same thing for assembly assembly flags this is going to be the Yasm compiler I&#8217;m going to tell</p>



<p class="wp-block-paragraph">I&#8217;m going to tell it that I want ELF 64.</p>



<p class="wp-block-paragraph">I want a 64 bit executable.</p>



<p class="wp-block-paragraph">I want to dwarf to debug symbols.</p>



<p class="wp-block-paragraph">I think in Yasm you have to specify the type of symbol.</p>



<p class="wp-block-paragraph">I think I can&#8217;t remember if you actually need to.</p>



<p class="wp-block-paragraph">So you could try just, you know, dash G if you want.</p>



<p class="wp-block-paragraph">It may or may not work.</p>



<p class="wp-block-paragraph">But I always just like to specify at least for assembly.</p>



<p class="wp-block-paragraph">So then let&#8217;s do some linker flags.</p>



<p class="wp-block-paragraph">Okay, so link flags, you know, what is the linking stage?</p>



<p class="wp-block-paragraph">What&#8217;s going to happen in a hybrid program?</p>



<p class="wp-block-paragraph">You know, for me, it&#8217;s just going to be the G plus plus GCC linker.</p>



<p class="wp-block-paragraph">So that means I&#8217;m going to do all the CPP flags because I want wall and pedantic and</p>



<p class="wp-block-paragraph">debug symbols and I want the C plus plus standard set and all that stuff.</p>



<p class="wp-block-paragraph">Whatever you want to do is fine.</p>



<p class="wp-block-paragraph">And then I want to just specify.</p>



<p class="wp-block-paragraph">I don&#8217;t think you have to do this on modern systems, but I&#8217;m going to specify I want to link a 64-bit executable</p>



<p class="wp-block-paragraph">And then I have to specify no pi</p>



<p class="wp-block-paragraph">Which I think is kind of an Ubuntu thing your program probably won&#8217;t run if you don&#8217;t do this</p>



<p class="wp-block-paragraph">So just trust me for now put no pi in the linking stage and then we&#8217;ll do another flag called no exec stack</p>



<p class="wp-block-paragraph">Which is also a somewhat new thing which prevents</p>



<p class="wp-block-paragraph">stack which means you might be less hackable not sure if it&#8217;s how safe it really is but you know</p>



<p class="wp-block-paragraph">probably improves the safety a little bit uh let&#8217;s see at the last minute okay so now uh</p>



<p class="wp-block-paragraph">now that i&#8217;ve set up the link flags uh i need to like add on the dash c flag for the actual</p>



<p class="wp-block-paragraph">compiler flags because uh you know if if you know this from my previous videos if you&#8217;re going to</p>



<p class="wp-block-paragraph">compile to an object file and not directly link everything right away you need to add the dash c</p>



<p class="wp-block-paragraph">away you need to add the dash c flag to let the compiler know oh i just want to compile to an</p>



<p class="wp-block-paragraph">object file and then later i&#8217;ll come along and link so i&#8217;m going to go cpp flags is equal to</p>



<p class="wp-block-paragraph">and i&#8217;m going to say equal to itself and then just add a dash c at the end of it and then we&#8217;ll do</p>



<p class="wp-block-paragraph">cc flags and then it&#8217;s going to equal to itself with just a dash c at the end of it so</p>



<p class="wp-block-paragraph">I had CPP flags on line 21 equal to just this basic thing.</p>



<p class="wp-block-paragraph">And then I reused CPP flags for the link flags,</p>



<p class="wp-block-paragraph">which means if the link flags didn&#8217;t use that colon,</p>



<p class="wp-block-paragraph">I would basically have ruined the link flags variable by the time I went down</p>



<p class="wp-block-paragraph">here and changed it. So you don&#8217;t have to organize your make file this way.</p>



<p class="wp-block-paragraph">You can actually hard code a lot more stuff into the variables.</p>



<p class="wp-block-paragraph">I just like to try to be more dynamic. It&#8217;s more fun.</p>



<p class="wp-block-paragraph">up all the basic variables for the compiler let&#8217;s set up some variables for paths so i&#8217;m</p>



<p class="wp-block-paragraph">going to set up paths here so what do i mean by paths you know this is a build system it&#8217;s got to</p>



<p class="wp-block-paragraph">know where things are right so for starters you probably want to name your binary you know the</p>



<p class="wp-block-paragraph">executable file so i&#8217;m just going to make mine main you can make anything you want like my program or</p>



<p class="wp-block-paragraph">whatever but you know for mine it&#8217;s going to be main and then i&#8217;m going to set up another variable</p>



<p class="wp-block-paragraph">going to set up another variable that depends on it so I&#8217;m going to say the actual binary path is</p>



<p class="wp-block-paragraph">just going to be you know this main meaning the current directory and main also you know most it</p>



<p class="wp-block-paragraph">seems like most make files have it set up so that all of the intermediate files like the the object</p>



<p class="wp-block-paragraph">files and the binary they get built in the current source directory you know like the root of the</p>



<p class="wp-block-paragraph">Sometimes also I like to just make a build directory.</p>



<p class="wp-block-paragraph">So it&#8217;s really, really easy to just kind of clean everything out.</p>



<p class="wp-block-paragraph">You just delete the build directory and you don&#8217;t have to worry about the repository getting</p>



<p class="wp-block-paragraph">super cluttered with object files in the meantime.</p>



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



<p class="wp-block-paragraph">I&#8217;m going to say build directory name is build.</p>



<p class="wp-block-paragraph">And then so you can imagine there&#8217;s going to be a folder here now named build that shows</p>



<p class="wp-block-paragraph">up whenever, well, I&#8217;m going to add more targets later when I actually start building.</p>



<p class="wp-block-paragraph">when I actually start building, we&#8217;re still just naming things.</p>



<p class="wp-block-paragraph">So then I&#8217;m going to name the actual build directory as the current directory slash and then build dir name.</p>



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



<p class="wp-block-paragraph">So that means the bin shouldn&#8217;t just be in the current directory.</p>



<p class="wp-block-paragraph">It should be in the build dir and then a slash.</p>



<p class="wp-block-paragraph">And then instead of typing main, actually, I should probably reuse that variable.</p>



<p class="wp-block-paragraph">So let&#8217;s do bin name.</p>



<p class="wp-block-paragraph">And again, reusing variables is really, really good because it just saves you work.</p>



<p class="wp-block-paragraph">I can change things in less places when I leverage variables more.</p>



<p class="wp-block-paragraph">If I had the word main written down all over the program, I&#8217;d have to change that in every</p>



<p class="wp-block-paragraph">single spot of the make file if I wanted to change main to something else.</p>



<p class="wp-block-paragraph">But in this case, I only have to change it in one spot.</p>



<p class="wp-block-paragraph">Okay, so now maybe it&#8217;s probably a good idea at this point to start printing out what we&#8217;ve</p>



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



<p class="wp-block-paragraph">So I&#8217;m going to do a bunch of, you know, calls to print things.</p>



<p class="wp-block-paragraph">you know calls to print things print everything out just for double checking ourselves</p>



<p class="wp-block-paragraph">okay how can i do that i&#8217;m going to do that with a call uh the uh say you could also just do uh info</p>



<p class="wp-block-paragraph">and then you know something like that like we did up above in the save function if you want a less</p>



<p class="wp-block-paragraph">fancier build system but i like doing it this way so i&#8217;m going to say what um let&#8217;s do cc uh</p>



<p class="wp-block-paragraph">CC and I&#8217;ll just put maybe like a quality operator or something and then</p>



<p class="wp-block-paragraph">I&#8217;ll just print out what I put for CC and I&#8217;ll just start duplicating this</p>



<p class="wp-block-paragraph">line a few times and I&#8217;ll say I&#8217;ll just print out everything that I added as a</p>



<p class="wp-block-paragraph">variable CPP and then ASM type ASM and this just kind of you know it just kind</p>



<p class="wp-block-paragraph">typed something in incorrectly might take me a while to figure that out but if</p>



<p class="wp-block-paragraph">I print it all out at the beginning of the of the make file running that I can</p>



<p class="wp-block-paragraph">just visually inspect what the variables actually contain so let&#8217;s do CPP flags</p>



<p class="wp-block-paragraph">and then we&#8217;ll do CC flags</p>



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



<p class="wp-block-paragraph">And then we&#8217;ll do one more.</p>



<p class="wp-block-paragraph">It&#8217;s going to be probably, oh, link flags.</p>



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">So link flags.</p>



<p class="wp-block-paragraph">Bringing out a lot of stuff here.</p>



<p class="wp-block-paragraph">Then I can print the directories, I guess.</p>



<p class="wp-block-paragraph">So maybe I&#8217;ll duplicate this a few more times.</p>



<p class="wp-block-paragraph">I want to do builder.</p>



<p class="wp-block-paragraph">The build directory, just so I know where it is.</p>



<p class="wp-block-paragraph">and I can verify that it&#8217;s like a real path.</p>



<p class="wp-block-paragraph">Builder, maybe I&#8217;ll duplicate this one more time</p>



<p class="wp-block-paragraph">so that I can see the absolute path</p>



<p class="wp-block-paragraph">to the build directory.</p>



<p class="wp-block-paragraph">Just for my own information,</p>



<p class="wp-block-paragraph">because sometimes if you get it wrong,</p>



<p class="wp-block-paragraph">this is another way to kind of see what&#8217;s going on.</p>



<p class="wp-block-paragraph">So there&#8217;s a function in make that&#8217;s built in.</p>



<p class="wp-block-paragraph">You pretty much just say dollar</p>



<p class="wp-block-paragraph">and the name of the function is abspath.</p>



<p class="wp-block-paragraph">path and whatever you put inside of it it&#8217;ll try to give you the absolute path of that thing</p>



<p class="wp-block-paragraph">so i&#8217;m just telling it now that i want to print the absolute path of the build directory</p>



<p class="wp-block-paragraph">by the way um you probably don&#8217;t want to convert all of your variables to absolute paths because</p>



<p class="wp-block-paragraph">make has a huge problem with spaces in paths and file names so keep it relative unless you&#8217;re just</p>



<p class="wp-block-paragraph">going to print something um you&#8217;ll find out the hard way i mean feel free to try it and prove to</p>



<p class="wp-block-paragraph">yourself it&#8217;s not a good idea um but i found it the hard way many times because i kept forgetting</p>



<p class="wp-block-paragraph">I kept forgetting. So then we&#8217;ll just do the binary, I guess. Okay. Yeah. We&#8217;ll do one more</p>



<p class="wp-block-paragraph">for the binary. It&#8217;s going to go there and maybe I&#8217;ll duplicate this so that I can say</p>



<p class="wp-block-paragraph">what the absolute path is. Okay. Abs path. And then if I screw this up, I&#8217;ll just look up the</p>



<p class="wp-block-paragraph">I&#8217;m going to do clear and make so I can just see what it&#8217;s going to print.</p>



<p class="wp-block-paragraph">And let me just double check here.</p>



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



<p class="wp-block-paragraph">So everything looks good there.</p>



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



<p class="wp-block-paragraph">Looks pretty good.</p>



<p class="wp-block-paragraph">Absolute path to the builder is my stuff.</p>



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



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



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



<p class="wp-block-paragraph">I&#8217;m just going to leave that in there because it&#8217;ll be easy to double check it.</p>



<p class="wp-block-paragraph">And now we&#8217;re going to do targets.</p>



<p class="wp-block-paragraph">So what is the target in the make build system?</p>



<p class="wp-block-paragraph">in the make build system a target is just something that you might want to create or or</p>



<p class="wp-block-paragraph">or build or compile or something targets are not only for uh building uh executables or object</p>



<p class="wp-block-paragraph">files or you know something that you make targets sometimes can just be called they&#8217;re called phony</p>



<p class="wp-block-paragraph">targets but you can just call a target and it will execute a bunch of commands within that target</p>



<p class="wp-block-paragraph">even though it&#8217;s not building something specific that is needed so you can use make files to do a</p>



<p class="wp-block-paragraph">really powerful stuff. Let me show you first off, we&#8217;ll do a we&#8217;ll do a target. I&#8217;ve already</p>



<p class="wp-block-paragraph">prepared something up here. I&#8217;m just gonna I&#8217;m just gonna copy paste it here because it&#8217;s going</p>



<p class="wp-block-paragraph">to take a long time to type if I don&#8217;t. So here&#8217;s a target. An example of a target is okay, I&#8217;m going</p>



<p class="wp-block-paragraph">to name the target the target menu and I&#8217;m gonna put a colon. So now later I can type make menu</p>



<p class="wp-block-paragraph">and what will happen is it&#8217;ll execute all those commands that are listed below. Each command</p>



<p class="wp-block-paragraph">is really just going to be a shell command.</p>



<p class="wp-block-paragraph">You have to use tab to indent for the command itself.</p>



<p class="wp-block-paragraph">Notice how I have a bunch of echo statements</p>



<p class="wp-block-paragraph">and then I&#8217;m just like printing stuff, right?</p>



<p class="wp-block-paragraph">So this whole target, it doesn&#8217;t actually build anything,</p>



<p class="wp-block-paragraph">but it will print a menu to the screen for me,</p>



<p class="wp-block-paragraph">which is pretty convenient.</p>



<p class="wp-block-paragraph">When you&#8217;re not actually building something,</p>



<p class="wp-block-paragraph">like you&#8217;re not building the executable</p>



<p class="wp-block-paragraph">that the target doesn&#8217;t name an executable,</p>



<p class="wp-block-paragraph">then it&#8217;s called a phony target.</p>



<p class="wp-block-paragraph">And you want to name it as a phony target</p>



<p class="wp-block-paragraph">phony target with this line 67 down here because if you don&#8217;t the build system might actually</p>



<p class="wp-block-paragraph">eventually end up getting confused between a fake target and something that might be sitting on your</p>



<p class="wp-block-paragraph">file system like if i accidentally put a file named menu on my file system at the root of my</p>



<p class="wp-block-paragraph">repository then make might get confused and think well i see the file so therefore i don&#8217;t need to</p>



<p class="wp-block-paragraph">build it and then the menu will never show up again so this way i&#8217;m saying this is a phony target</p>



<p class="wp-block-paragraph">at the file system it&#8217;ll just always execute that target for me so this is the basics of a target</p>



<p class="wp-block-paragraph">you just name a target put a colon and then every line under that is a shell command that you wanted</p>



<p class="wp-block-paragraph">to execute so let me just show you that real fast we save to be sure so we&#8217;re going to do clear and</p>



<p class="wp-block-paragraph">actually the absolute paths are starting to bother me let me get rid of them right now</p>



<p class="wp-block-paragraph">head before I made this video. Okay, and we can just sort of trim the fat a little bit. So I&#8217;m</p>



<p class="wp-block-paragraph">going to do clear and make. And notice how the menu target just ran by itself already.</p>



<p class="wp-block-paragraph">The convenient thing about make files is the first target that shows up is going to be known</p>



<p class="wp-block-paragraph">as the default target and it will just get executed automatically if you don&#8217;t specify</p>



<p class="wp-block-paragraph">what to execute. So notice how I just typed make by itself and I didn&#8217;t actually specify a target.</p>



<p class="wp-block-paragraph">I could specify make menu and the same exact thing happens.</p>



<p class="wp-block-paragraph">Notice how I said make menu, the menu shows up again.</p>



<p class="wp-block-paragraph">But if you don&#8217;t specify anything,</p>



<p class="wp-block-paragraph">then it&#8217;ll always execute the first found target.</p>



<p class="wp-block-paragraph">And just to prove that to you right here,</p>



<p class="wp-block-paragraph">I&#8217;ll do maybe I&#8217;ll do like a different target</p>



<p class="wp-block-paragraph">and I&#8217;ll just call it hello.</p>



<p class="wp-block-paragraph">And I&#8217;ll just have it echo hello.</p>



<p class="wp-block-paragraph">So now if we just execute make with no arguments,</p>



<p class="wp-block-paragraph">notice how it just prints hello.</p>



<p class="wp-block-paragraph">if I want the menu again, I got to go make menu.</p>



<p class="wp-block-paragraph">Right? Okay. So I&#8217;m going to, I&#8217;m going to set the menu back to the default target.</p>



<p class="wp-block-paragraph">Another thing that sometimes people do is they&#8217;ll just make a target called default.</p>



<p class="wp-block-paragraph">I guess I&#8217;ll do that here, make a target called default. And they&#8217;ll say that the</p>



<p class="wp-block-paragraph">default target depends on whatever they want to actually run. And you don&#8217;t even need to</p>



<p class="wp-block-paragraph">call it default. You can call it hello or anything that you want. So, you know,</p>



<p class="wp-block-paragraph">put to lead default just so you know that this is not a standard system name that&#8217;s expected so</p>



<p class="wp-block-paragraph">the default target it&#8217;s just the name of the target then a colon and instead of putting shell</p>



<p class="wp-block-paragraph">commands underneath i could put dependencies on the right so now i&#8217;m saying that the default target</p>



<p class="wp-block-paragraph">depends on the menu target which means in the make build system first what it&#8217;s going to do is it&#8217;s</p>



<p class="wp-block-paragraph">going to go check to make sure that main or sorry menu is satisfied because menu is actually a fake</p>



<p class="wp-block-paragraph">Because menu is actually a fake, you know, a phony target, it&#8217;s always going to get executed.</p>



<p class="wp-block-paragraph">And then when it&#8217;s finished and laDefault realizes, okay, all of my dependencies are satisfied now,</p>



<p class="wp-block-paragraph">then laDefault is going to execute and it&#8217;s actually going to end up doing nothing.</p>



<p class="wp-block-paragraph">I mean, we could put some commands under here if we want.</p>



<p class="wp-block-paragraph">I&#8217;ll put the word nothing.</p>



<p class="wp-block-paragraph">And just to prove to you that menu will get executed first because it&#8217;s a dependency of laDefault.</p>



<p class="wp-block-paragraph">And then finally laDefault will execute its commands and print the word nothing.</p>



<p class="wp-block-paragraph">execute its commands and print the word nothing.</p>



<p class="wp-block-paragraph">Let&#8217;s do that and then I&#8217;ll erase the echo command there.</p>



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



<p class="wp-block-paragraph">Notice how the menu got printed first</p>



<p class="wp-block-paragraph">because it was a dependency of the default</p>



<p class="wp-block-paragraph">and the default is the default target.</p>



<p class="wp-block-paragraph">And then after the dependencies were satisfied,</p>



<p class="wp-block-paragraph">then the default did its thing and printed nothing.</p>



<p class="wp-block-paragraph">But so let&#8217;s get rid of that.</p>



<p class="wp-block-paragraph">And now it&#8217;s just like when you do make with no arguments,</p>



<p class="wp-block-paragraph">then the menu gets printed.</p>



<p class="wp-block-paragraph">printed. Okay, so what else can I talk about real fast here? Let&#8217;s talk about</p>



<p class="wp-block-paragraph">silent commands. I&#8217;ll put a little comment menu. Let&#8217;s talk about silent</p>



<p class="wp-block-paragraph">commands. You see all these at symbols here? There are a bunch of symbols that</p>



<p class="wp-block-paragraph">you can use throughout a make file. I&#8217;m going to show you just this and a couple</p>



<p class="wp-block-paragraph">other ones, but basically this means don&#8217;t print the command you&#8217;re about to</p>



<p class="wp-block-paragraph">execute, just execute it. So let me show you an example real fast of what I&#8217;m</p>



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



<p class="wp-block-paragraph">Targets to show silence and non-silent commands,</p>



<p class="wp-block-paragraph">or a suppressed command, whatever you wanna call it.</p>



<p class="wp-block-paragraph">Basically not printing the command,</p>



<p class="wp-block-paragraph">just executing the command.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna name a target silent commands,</p>



<p class="wp-block-paragraph">and it&#8217;s not gonna depend on anything.</p>



<p class="wp-block-paragraph">So that&#8217;s why I&#8217;m gonna hit enter here,</p>



<p class="wp-block-paragraph">just like with menu and unlike the default.</p>



<p class="wp-block-paragraph">So then I wanna do tab to enter a command</p>



<p class="wp-block-paragraph">to enter a command and the echo command is going to say hello this is a silent command or a</p>



<p class="wp-block-paragraph">suppressed command then i&#8217;m going to do basically the same thing again but i&#8217;m not going to put the</p>



<p class="wp-block-paragraph">at symbol in front i&#8217;m going to say hello this is a non-silent command so what we should see is that</p>



<p class="wp-block-paragraph">if we exit the silent commands target we should see first this message gets printed on line 75</p>



<p class="wp-block-paragraph">and then second we see the full command including the echo statement that shows up on line 76 and</p>



<p class="wp-block-paragraph">on line 76 and then third we should just see the message hello this is a non-silent command</p>



<p class="wp-block-paragraph">let me oh and then if it&#8217;s a phony target meaning it&#8217;s not an actual file on the file system</p>



<p class="wp-block-paragraph">that you expect to be built we have to do phony and phony is actually a target notice how i&#8217;m</p>



<p class="wp-block-paragraph">saying dot phony colon indicating that that it&#8217;s a target and we&#8217;ll just say that it depends on</p>



<p class="wp-block-paragraph">and we&#8217;ll just name the command that is also a phony or the target that&#8217;s also a phony</p>



<p class="wp-block-paragraph">you can specify all of the phony targets in one line if you really want to but for me that kind</p>



<p class="wp-block-paragraph">of feels messy and you&#8217;re allowed to like add add add dependencies so notice on line 70 i&#8217;m adding</p>



<p class="wp-block-paragraph">menu as a phony target and then on line 77 i&#8217;m adding silent commands as a phony target</p>



<p class="wp-block-paragraph">the way you do it is up to you but i like to do it this way so i&#8217;m going to do silent commands</p>



<p class="wp-block-paragraph">and then I&#8217;m going to do make silent commands.</p>



<p class="wp-block-paragraph">So now we&#8217;re actually going to execute the silent commands target</p>



<p class="wp-block-paragraph">so we wouldn&#8217;t see a menu.</p>



<p class="wp-block-paragraph">And then we&#8217;ll see an example of the silent commands.</p>



<p class="wp-block-paragraph">Notice how the first one that says,</p>



<p class="wp-block-paragraph">hello, this is a silent command.</p>



<p class="wp-block-paragraph">The actual echo command is nowhere to be found</p>



<p class="wp-block-paragraph">because that whole line was muted</p>



<p class="wp-block-paragraph">and only the output of executing the command gets shown to you.</p>



<p class="wp-block-paragraph">But for the second one,</p>



<p class="wp-block-paragraph">remember we did not put the at symbol on the second command.</p>



<p class="wp-block-paragraph">So the whole entire command gets printed.</p>



<p class="wp-block-paragraph">the whole entire command gets printed echo and then quote this is a non-silent command and then</p>



<p class="wp-block-paragraph">that command gets executed and here&#8217;s the result it&#8217;s the same string except just without the echo</p>



<p class="wp-block-paragraph">so you know this line right here is this is the command that we&#8217;re about to execute whoops</p>



<p class="wp-block-paragraph">this is the command we&#8217;re about to execute and then the last line is this is the result of</p>



<p class="wp-block-paragraph">executing that command why would you want to print your commands kind of useful sometimes to see the</p>



<p class="wp-block-paragraph">compiler statements that show up there have been a few times or more than a few times in my life</p>



<p class="wp-block-paragraph">times in my life where I was running a make file and just kind of watching it and it was printing</p>



<p class="wp-block-paragraph">out all the commands that it was executing and then I realized oh my god that&#8217;s wrong because</p>



<p class="wp-block-paragraph">it was printing and I was able to fix that so you know you don&#8217;t have to print your commands but</p>



<p class="wp-block-paragraph">you probably want to so let&#8217;s see what else can we do okay so here&#8217;s another thing that I want to</p>



<p class="wp-block-paragraph">show you how to ignore failures so sometimes if you&#8217;re compiling your source code won&#8217;t compile</p>



<p class="wp-block-paragraph">So then that means the compilation command failed.</p>



<p class="wp-block-paragraph">Or if you want to do any command in general,</p>



<p class="wp-block-paragraph">and for some reason it returns false or it fails,</p>



<p class="wp-block-paragraph">then that&#8217;s considered a failed command.</p>



<p class="wp-block-paragraph">The make build system will stop execution of any target</p>



<p class="wp-block-paragraph">as soon as it encounters a failure.</p>



<p class="wp-block-paragraph">It&#8217;s kind of a good thing.</p>



<p class="wp-block-paragraph">What if you had a huge complicated target,</p>



<p class="wp-block-paragraph">which you can do it this way.</p>



<p class="wp-block-paragraph">I&#8217;ve done it this way before.</p>



<p class="wp-block-paragraph">What if you had a huge complicated target,</p>



<p class="wp-block-paragraph">which not only builds everything,</p>



<p class="wp-block-paragraph">but then also tries to deploy it to your remote server?</p>



<p class="wp-block-paragraph">deploy it to your remote server.</p>



<p class="wp-block-paragraph">Well, if your program fails to build, you probably don&#8217;t want the deployment part to</p>



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



<p class="wp-block-paragraph">So you would hope that it would stop as soon as something failed to compile.</p>



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



<p class="wp-block-paragraph">So we should try to know the difference between failed commands stopping the make build system</p>



<p class="wp-block-paragraph">and failed commands being ignored by the build system and just continuing.</p>



<p class="wp-block-paragraph">So we can do it both ways.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to do a little comment here.</p>



<p class="wp-block-paragraph">or ignoring failures and then i&#8217;m going to do ignore failures so that&#8217;s a target no dependencies</p>



<p class="wp-block-paragraph">and i&#8217;m just going to do false false twice in bash if you just you know do a false</p>



<p class="wp-block-paragraph">then it will be interpreted as a failure um so you know if i put true here it will be interpreted</p>



<p class="wp-block-paragraph">as true and this is not necessarily a make file thing this is a bash thing just like the command</p>



<p class="wp-block-paragraph">just like the command line. Let me show you real fast just just to prove it. I&#8217;m gonna prove it to</p>



<p class="wp-block-paragraph">you. Okay, so hopefully you remember if you can do echo dollar sign question, it&#8217;ll tell you the</p>



<p class="wp-block-paragraph">return code of the last command that you executed. So if I type echo hello, and then as another</p>



<p class="wp-block-paragraph">command, I echo the return code of the previous command. Now it&#8217;s going to basically tell me</p>



<p class="wp-block-paragraph">echo and then it&#8217;s going to tell me whether or not echo succeeded. You see a zero indicating</p>



<p class="wp-block-paragraph">succeeded it would be really weird if it didn&#8217;t succeed but you know whatever now i can modify</p>



<p class="wp-block-paragraph">this command just to type in some random stuff like what if i type in this notice how the second</p>



<p class="wp-block-paragraph">part the echo return code part echoes a 127 anything but a zero is considered a failure</p>



<p class="wp-block-paragraph">usually so it&#8217;s telling me 127 and that&#8217;s sometimes a standard code meaning something</p>



<p class="wp-block-paragraph">wasn&#8217;t found i could also just do true and that should give me a zero because you know in bash it</p>



<p class="wp-block-paragraph">bash it understands boolean so it&#8217;s like true success that&#8217;s a return code of zero it&#8217;s weird</p>



<p class="wp-block-paragraph">but that&#8217;s what it is if i return if i execute false then the return code should at least not</p>



<p class="wp-block-paragraph">be zero it&#8217;s probably going to be a one yeah there we go so just letting you know if we just</p>



<p class="wp-block-paragraph">execute the statement false by itself or true by itself then that&#8217;s telling us</p>



<p class="wp-block-paragraph">um that&#8217;s sort of like simulating a failed compile command or something i guess we could put</p>



<p class="wp-block-paragraph">commands in there if we wanted to but i don&#8217;t really want to run the compiler just for this</p>



<p class="wp-block-paragraph">in the compiler just for this so then I&#8217;m gonna do echo this echo statement</p>



<p class="wp-block-paragraph">should be reached as previous errors which I&#8217;m using false to represent should</p>



<p class="wp-block-paragraph">be ignored so now why how do I know that we&#8217;re gonna ignore the errors because I</p>



<p class="wp-block-paragraph">put the little minus in front of the false notice how before it was either an</p>



<p class="wp-block-paragraph">at symbol or nothing at the beginning of a command remember the at symbol does</p>



<p class="wp-block-paragraph">Remember the at symbol does suppression.</p>



<p class="wp-block-paragraph">The minus symbol says try to run this command,</p>



<p class="wp-block-paragraph">but if it fails, ignore it,</p>



<p class="wp-block-paragraph">continue with the recipe for that build target.</p>



<p class="wp-block-paragraph">You know, recipe meaning all of the commands</p>



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



<p class="wp-block-paragraph">So that means the ignore failures target</p>



<p class="wp-block-paragraph">should actually fail twice and then make it to line 84</p>



<p class="wp-block-paragraph">where it just prints that message.</p>



<p class="wp-block-paragraph">Then we&#8217;ll do, well, we&#8217;ll mark this as a phony target.</p>



<p class="wp-block-paragraph">practice to try to mark your phony targets i&#8217;ve i&#8217;ve not done that in the past and eventually</p>



<p class="wp-block-paragraph">regretted it a few times so then i&#8217;m going to do stop on failures is another target and we&#8217;re going</p>



<p class="wp-block-paragraph">to do false whoops no minus because we actually want to stop on failure false and then we&#8217;ll do</p>



<p class="wp-block-paragraph">another echo and we&#8217;ll say this echo statement should never be reached as previous errors</p>



<p class="wp-block-paragraph">false should cause build build termination okay I&#8217;m kind of verbose but I hope this explains it</p>



<p class="wp-block-paragraph">we&#8217;ll name this as a phony target too phony you&#8217;re a phony failures okay so we can run both these</p>



<p class="wp-block-paragraph">maybe I&#8217;ll put a comment here just to show you it&#8217;s two separate things I kind of like doing that</p>



<p class="wp-block-paragraph">we can run ignore failures and then we can run stop on failures separately to see what happens</p>



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



<p class="wp-block-paragraph">Okay, so I&#8217;m going to do clear and, what was it?</p>



<p class="wp-block-paragraph">Ignore failures and then stop on failures.</p>



<p class="wp-block-paragraph">So ignore failures, notice how it prints false</p>



<p class="wp-block-paragraph">because I forgot to put an at symbol in front of it.</p>



<p class="wp-block-paragraph">And then the make system itself says,</p>



<p class="wp-block-paragraph">hey, error, that command failed, error one.</p>



<p class="wp-block-paragraph">Remember before we had the return code one</p>



<p class="wp-block-paragraph">when we just typed in false.</p>



<p class="wp-block-paragraph">me that it received return code one from trying to execute false inside of bash so it detected</p>



<p class="wp-block-paragraph">that a failure occurred so these two lines go together then the same thing again because i have</p>



<p class="wp-block-paragraph">two false statements in there and then the last statement says this echo statement should be</p>



<p class="wp-block-paragraph">reached as previous errors should be ignored because we use the minus symbol i&#8217;m having a</p>



<p class="wp-block-paragraph">hard time selecting text here i gotta i gotta go home and practice my text selection actually wait</p>



<p class="wp-block-paragraph">So notice how, you know, the minus symbol right there says, let&#8217;s ignore.</p>



<p class="wp-block-paragraph">So now let&#8217;s do stop on failures.</p>



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



<p class="wp-block-paragraph">Notice how the first false showed up as an error to the make build system.</p>



<p class="wp-block-paragraph">And then make just said, we&#8217;re done.</p>



<p class="wp-block-paragraph">We&#8217;re not ignoring this error.</p>



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



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



<p class="wp-block-paragraph">Anytime you have commands that need to stop the build, if they fail,</p>



<p class="wp-block-paragraph">build if they fail you should not put a minus in front but anytime you have commands where</p>



<p class="wp-block-paragraph">everything just needs to be executed even if some stuff fails you want to put a minus in front of</p>



<p class="wp-block-paragraph">there we&#8217;ll talk about a clean target a little bit later which usually you know just continues</p>



<p class="wp-block-paragraph">even if there&#8217;s a failure so we got silent commands ignored commands or ignored failures</p>



<p class="wp-block-paragraph">and failures that we&#8217;re actually going to stop so now we&#8217;re going to get into the the meat and</p>



<p class="wp-block-paragraph">make file it doesn&#8217;t really do anything it doesn&#8217;t build anything for us I&#8217;m just kind of showing you</p>



<p class="wp-block-paragraph">you know how to work with the make file like the very basics now let&#8217;s actually start to build</p>



<p class="wp-block-paragraph">things so the first thing I&#8217;d like to do is I&#8217;d like to make a target for the build directory</p>



<p class="wp-block-paragraph">if you you know again if you just kind of like look at my file system here I don&#8217;t actually have</p>



<p class="wp-block-paragraph">a build directory right so I want to make sure that a build directory exists I could of course</p>



<p class="wp-block-paragraph">dir and then type build but I want the build system to do this automatically for me and also</p>



<p class="wp-block-paragraph">as a lesson for what we&#8217;re doing so you know be sure the build directory exists so I&#8217;m going to</p>



<p class="wp-block-paragraph">name a target and this is not going to be a phony target I think this is our first non-phony target</p>



<p class="wp-block-paragraph">right yeah oh I forgot to put la default as a phony might regret that one day the defaults</p>



<p class="wp-block-paragraph">you is phony and everything&#8217;s funny. Okay. So now we have our first real build target. I&#8217;m just</p>



<p class="wp-block-paragraph">going to name the thing that I want to build. And I&#8217;m going to name it by typing the build directory</p>



<p class="wp-block-paragraph">variable. I could type, you know, underscore build or whatever it is that I put for that variable.</p>



<p class="wp-block-paragraph">What did I put there again? Underscore build. Yeah, I could put that if I wanted to. But again,</p>



<p class="wp-block-paragraph">try not to hard code things. It&#8217;s better to stick things in variables if you can.</p>



<p class="wp-block-paragraph">So since this is a target, I&#8217;m going to put a colon. It doesn&#8217;t really depend on anything,</p>



<p class="wp-block-paragraph">because if we&#8217;re just talking about building that folder all we really have to do is execute a command</p>



<p class="wp-block-paragraph">to just make sure that the folder is created right so i&#8217;m going to do no dependencies and</p>



<p class="wp-block-paragraph">then i&#8217;m going to like maybe do a little all say function call just to announce that we&#8217;re going</p>



<p class="wp-block-paragraph">to ensure the build directory a lot of people don&#8217;t do this but i&#8217;m going to do it ensuring</p>



<p class="wp-block-paragraph">the builder and now i could put you know what the builder is probably a pretty good idea so that i</p>



<p class="wp-block-paragraph">probably a pretty good idea so that I can see what I&#8217;m trying to ensure let&#8217;s</p>



<p class="wp-block-paragraph">just run that real fast if I say oh shoot I guess I would have to do make</p>



<p class="wp-block-paragraph">and then name build let&#8217;s see if that actually works yeah okay so I&#8217;m naming</p>



<p class="wp-block-paragraph">the build directory you wouldn&#8217;t normally actually name the build</p>



<p class="wp-block-paragraph">directory in the command line but I&#8217;m doing it so it says we&#8217;re ensuring the</p>



<p class="wp-block-paragraph">build directory and then now it says the build thing is up to date because the</p>



<p class="wp-block-paragraph">because the target finished executing,</p>



<p class="wp-block-paragraph">but nothing actually got created, right?</p>



<p class="wp-block-paragraph">So what I would like to do before we actually create it</p>



<p class="wp-block-paragraph">is replace this builder variable with a special variable</p>



<p class="wp-block-paragraph">that GNU make gives you called $at.</p>



<p class="wp-block-paragraph">The $at variable, and I&#8217;m quoting it,</p>



<p class="wp-block-paragraph">you don&#8217;t have to quote it,</p>



<p class="wp-block-paragraph">it always ends up being the name of the current build target.</p>



<p class="wp-block-paragraph">So again, it&#8217;s a bad idea to hard code</p>



<p class="wp-block-paragraph">It&#8217;s a bad idea to hard code lots of different values</p>



<p class="wp-block-paragraph">and it&#8217;s way better to put things into a variable.</p>



<p class="wp-block-paragraph">But at the same time, if you can get away with</p>



<p class="wp-block-paragraph">hard coding a variable name multiple times</p>



<p class="wp-block-paragraph">and you can use something more generic,</p>



<p class="wp-block-paragraph">well then that can also increase the power</p>



<p class="wp-block-paragraph">of what you&#8217;re doing, make things easier for you</p>



<p class="wp-block-paragraph">and easier for you to debug.</p>



<p class="wp-block-paragraph">Save yourself some time, right?</p>



<p class="wp-block-paragraph">Because coding is already hard enough.</p>



<p class="wp-block-paragraph">So if I do dollar sign at,</p>



<p class="wp-block-paragraph">it should show up as whatever the builder contains</p>



<p class="wp-block-paragraph">because that&#8217;s the current target.</p>



<p class="wp-block-paragraph">So let&#8217;s run that one more time.</p>



<p class="wp-block-paragraph">that one more time and we&#8217;ll say clear and make build notice how it says ensuring the builder and</p>



<p class="wp-block-paragraph">then it quoted the current target which is underscore built nice so we got that now let&#8217;s</p>



<p class="wp-block-paragraph">actually run a command to create the directory that&#8217;s just going to be you know in linux the</p>



<p class="wp-block-paragraph">command mkdir to make a directory and again i could put a builder here but it&#8217;s probably a</p>



<p class="wp-block-paragraph">special variable that will change because what if later on i want to change the name of that variable</p>



<p class="wp-block-paragraph">uh if i did then i&#8217;d have to change it in three places now but uh you know and possibly way more</p>



<p class="wp-block-paragraph">places later down the line but if i use that special you know dollar at symbol then i only</p>



<p class="wp-block-paragraph">have to change it in one spot okay so mkdir so that basically says it&#8217;s going to look to see if</p>



<p class="wp-block-paragraph">that folder is created if it&#8217;s not then it&#8217;s going to create it with that command so if i do that</p>



<p class="wp-block-paragraph">So if I do that, notice how it executed that command and also printed the command.</p>



<p class="wp-block-paragraph">So it&#8217;s like mkdir build.</p>



<p class="wp-block-paragraph">If we list the directory again, notice how there is a build directory.</p>



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



<p class="wp-block-paragraph">You go inside of there.</p>



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



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



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



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



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



<p class="wp-block-paragraph">our make file until it&#8217;s somewhat decent it&#8217;s not going to be amazing but it&#8217;s going to be somewhat</p>



<p class="wp-block-paragraph">decent okay so we have a target that will build the build directory now let&#8217;s make our first real</p>



<p class="wp-block-paragraph">target that is it&#8217;s going to be a phony target but it&#8217;s going to it&#8217;s going to do something for us</p>



<p class="wp-block-paragraph">so run the program we&#8217;re going to make a target called run and so if you type make run then it</p>



<p class="wp-block-paragraph">which in my opinion would be building the program first.</p>



<p class="wp-block-paragraph">Your opinion may vary, but you know, so I&#8217;m going to do it this way.</p>



<p class="wp-block-paragraph">I&#8217;m going to say run colon because that&#8217;s the name of the target.</p>



<p class="wp-block-paragraph">And I&#8217;m going to say that the run target depends on the build target.</p>



<p class="wp-block-paragraph">So remember this means that before run can actually execute its steps,</p>



<p class="wp-block-paragraph">it will go quickly to the build target and execute all the steps in its recipe.</p>



<p class="wp-block-paragraph">So essentially I&#8217;m saying before we try to run, let&#8217;s build.</p>



<p class="wp-block-paragraph">So it depends on build.</p>



<p class="wp-block-paragraph">By the way, build is not created yet.</p>



<p class="wp-block-paragraph">We&#8217;re going to do that in a second.</p>



<p class="wp-block-paragraph">not created yet we&#8217;re going to do that in a second the only line in this recipe that i&#8217;m going to put</p>



<p class="wp-block-paragraph">is just the name of the binary meaning after build is finished running i can assume that</p>



<p class="wp-block-paragraph">the entire executable is actually built and it&#8217;s ready to run so then i&#8217;m just going to run it so</p>



<p class="wp-block-paragraph">it&#8217;s just like first go build it somewhere else and then run it and again indirection and modular</p>



<p class="wp-block-paragraph">thinking is is a lot more powerful than just sticking all the build commands right inside of</p>



<p class="wp-block-paragraph">run target and duplicate all those commands for the build target so this is way better and then</p>



<p class="wp-block-paragraph">i&#8217;ll name run as a phony because this is not an actual file i&#8217;m trying to build the run the there&#8217;s</p>



<p class="wp-block-paragraph">no file named run then we&#8217;ll do the build target build and link the object files and executable</p>



<p class="wp-block-paragraph">okay and this is where it gets a little funny so we&#8217;re going to make a target called build</p>



<p class="wp-block-paragraph">actually build everything we shouldn&#8217;t hard code them here we should treat every source code file</p>



<p class="wp-block-paragraph">as as one separate thing that needs to be built every corresponding object file that comes from</p>



<p class="wp-block-paragraph">a source file should be one separate thing that that gets built from the source code that needs</p>



<p class="wp-block-paragraph">to be used to build i guess is what i should say so what should the build target depend on like</p>



<p class="wp-block-paragraph">before we can say that build is satisfied.</p>



<p class="wp-block-paragraph">How about just the executable file itself?</p>



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



<p class="wp-block-paragraph">So our main program,</p>



<p class="wp-block-paragraph">it should be totally built and finished</p>



<p class="wp-block-paragraph">and set up and created and everything</p>



<p class="wp-block-paragraph">before we can say build is satisfied.</p>



<p class="wp-block-paragraph">And then hilariously, once that&#8217;s satisfied,</p>



<p class="wp-block-paragraph">then the build target is totally satisfied too</p>



<p class="wp-block-paragraph">because it doesn&#8217;t really do anything.</p>



<p class="wp-block-paragraph">It just asks, you know, this is more of a shortcut.</p>



<p class="wp-block-paragraph">Okay, so now let&#8217;s,</p>



<p class="wp-block-paragraph">Let&#8217;s maybe first before we link let&#8217;s start writing commands to actually build the source code files. So I&#8217;m gonna do</p>



<p class="wp-block-paragraph">build the first object file</p>



<p class="wp-block-paragraph">So remember we have three source code files here. We&#8217;ve got first dot CPP and</p>



<p class="wp-block-paragraph">Second dot C and third dot ASM. So that&#8217;s just three source code files. They should map to three object files</p>



<p class="wp-block-paragraph">Let me let me draw this for you for a second before we talk about it further because I want to make sure</p>



<p class="wp-block-paragraph">that what I&#8217;m about to do is crystal clear when we&#8217;re talking about like the dependency graph.</p>



<p class="wp-block-paragraph">Okay. So my mouse is all over the place. I gotta execute a command real fast.</p>



<p class="wp-block-paragraph">I have many monitors going on right now and the pen just keeps forgetting that it&#8217;s only</p>



<p class="wp-block-paragraph">supposed to be on this one monitor. Okay. So I got that. Okay. So the first thing that we</p>



<p class="wp-block-paragraph">executable called main.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to draw that on the graph here for you Windows people.</p>



<p class="wp-block-paragraph">You can imagine there&#8217;s a dot exe on the end of it, but in, you know, in Linux and</p>



<p class="wp-block-paragraph">other link and other operating systems, we don&#8217;t really need that.</p>



<p class="wp-block-paragraph">So main, we want to build that.</p>



<p class="wp-block-paragraph">That&#8217;s the, that&#8217;s the primary thing we&#8217;re trying to build.</p>



<p class="wp-block-paragraph">What does it depend on though?</p>



<p class="wp-block-paragraph">What needs to be built before we can, we can create our executable?</p>



<p class="wp-block-paragraph">Well, we need to compile every piece of source code into a corresponding</p>



<p class="wp-block-paragraph">all the object files will be linked together into the executable so maybe i&#8217;ll i&#8217;ll write</p>



<p class="wp-block-paragraph">down first what the uh what the source code files are going to be so i&#8217;m going to do let&#8217;s see first</p>



<p class="wp-block-paragraph">sorry about my writing i don&#8217;t have a smoother right now first dot cpp and i got like a really</p>



<p class="wp-block-paragraph">small draw pad um i&#8217;m i&#8217;m making lots of excuses but i think probably my penmanship in real life is</p>



<p class="wp-block-paragraph">maybe even a little worse i don&#8217;t know i was at a job a long time ago and i was taking down</p>



<p class="wp-block-paragraph">names of customers it was like a tech support center and my boss after he saw the paper that</p>



<p class="wp-block-paragraph">i was writing down he just looked at me and he went chicken scratches and then he walked away</p>



<p class="wp-block-paragraph">okay so we have first dot cpp and then we have second this is why i like typing second dot c</p>



<p class="wp-block-paragraph">okay so we got that and then we&#8217;ll have third dot asm so third maybe i should go slower a</p>



<p class="wp-block-paragraph">At least I&#8217;m not making misspellings.</p>



<p class="wp-block-paragraph">I know these are simple file names, but it could happen.</p>



<p class="wp-block-paragraph">So we have three source code files.</p>



<p class="wp-block-paragraph">They don&#8217;t really depend on anything because they just are themselves.</p>



<p class="wp-block-paragraph">We don&#8217;t need to build these source code files.</p>



<p class="wp-block-paragraph">So we&#8217;re not going to draw any arrows indicating that these files depend on something else.</p>



<p class="wp-block-paragraph">They&#8217;re kind of like the primary source.</p>



<p class="wp-block-paragraph">Like these are the things that would actually go into your Git repository,</p>



<p class="wp-block-paragraph">whereas the object files that we&#8217;re going to generate and the executable that we generate,</p>



<p class="wp-block-paragraph">they would definitely not go into your repository.</p>



<p class="wp-block-paragraph">your git repository. Okay, so what&#8217;s going to happen? First.cpp is going to generate first.o.</p>



<p class="wp-block-paragraph">We&#8217;re going to type that out in a second, but basically first.o. That&#8217;s awful. That just looks</p>



<p class="wp-block-paragraph">disgusting. I&#8217;m going to keep it though. Okay, so in order to indicate dependency,</p>



<p class="wp-block-paragraph">we&#8217;re going to draw an arrow from first.o to first.cpp indicating, all right,</p>



<p class="wp-block-paragraph">if we&#8217;re trying to build first.o, then it will look at first.cpp and it&#8217;ll check.</p>



<p class="wp-block-paragraph">check does it exist if it doesn&#8217;t then there&#8217;s an error if it does exist then then the the the</p>



<p class="wp-block-paragraph">build system is actually going to check the modification dates of first.o and first.cpp</p>



<p class="wp-block-paragraph">assuming that a first.o already exists it&#8217;s just going to check it&#8217;s going to say</p>



<p class="wp-block-paragraph">does is first.cpp newer than first.o if yes then that means i have to recompile first.o if no i&#8217;m</p>



<p class="wp-block-paragraph">not going to recompile it and i&#8217;m going to save a bunch of time this is kind of the heart of why</p>



<p class="wp-block-paragraph">So same thing for 2nd.0.</p>



<p class="wp-block-paragraph">2nd.0, I&#8217;ll just circle it here, and we&#8217;ll say that it depends on 2nd.c.</p>



<p class="wp-block-paragraph">And then, of course, the 3rd.0 object file, it&#8217;s going to depend on 3rd.asm.</p>



<p class="wp-block-paragraph">So again, notice how they don&#8217;t really depend on each other.</p>



<p class="wp-block-paragraph">Maybe if you have a C++ file, maybe if you have a C++ program that&#8217;s really complicated,</p>



<p class="wp-block-paragraph">maybe your first.o, it would depend on the CPP file,</p>



<p class="wp-block-paragraph">and it might also depend on some other header files that you have set up somewhere.</p>



<p class="wp-block-paragraph">So then there would be more circles and more arrows that we draw.</p>



<p class="wp-block-paragraph">But for now, it&#8217;s just a simple program, so I&#8217;m just going to leave it this way.</p>



<p class="wp-block-paragraph">But just keep in mind that when we name dependencies in the make file,</p>



<p class="wp-block-paragraph">you want to name a dependency of everything that a source file depends on.</p>



<p class="wp-block-paragraph">So like first.o, it&#8217;s definitely going to depend on first.cpp,</p>



<p class="wp-block-paragraph">includes that are custom or from someone&#8217;s library and not the C++ standard libraries,</p>



<p class="wp-block-paragraph">then you would want to say that first.o depends on those as well. Because if you change</p>



<p class="wp-block-paragraph">a header that you made elsewhere in the program, then you probably want to recompile</p>



<p class="wp-block-paragraph">that corresponding object file, right? So just keep that in mind.</p>



<p class="wp-block-paragraph">Anyway, we&#8217;ll do first.o. Okay, so now the executable program main, that needs to be</p>



<p class="wp-block-paragraph">all the object files so I can just say that it depends on all three object files</p>



<p class="wp-block-paragraph">with just this right here and this is the basic idea of what we&#8217;re about to</p>



<p class="wp-block-paragraph">type up in the make file itself keep in mind that the make system will actually</p>



<p class="wp-block-paragraph">build this graph in memory under the hood to try and figure out which things</p>



<p class="wp-block-paragraph">actually need to be built or not you could even launch make with multiple</p>



<p class="wp-block-paragraph">threads I&#8217;ll probably forget to do it but it&#8217;s a things like dash J and then</p>



<p class="wp-block-paragraph">things like dash j and then the number of threads you want to launch in order to totally saturate</p>



<p class="wp-block-paragraph">your cpu and have as many things compiling as possibly can be compiled make will figure out</p>



<p class="wp-block-paragraph">which things don&#8217;t actually depend on each other and then build them in separate threads at the</p>



<p class="wp-block-paragraph">same time so your build system is just like so much faster so let&#8217;s see we got uh corresponding</p>



<p class="wp-block-paragraph">object dial for every source file and then we got the binary that depends on the object notice how</p>



<p class="wp-block-paragraph">source code file what would happen is when we wanted to build the let&#8217;s say we wanted to just</p>



<p class="wp-block-paragraph">you know this is the the target the binary target that is just named main what will happen is it&#8217;ll</p>



<p class="wp-block-paragraph">look at its dependencies and the way we&#8217;re going to write it it&#8217;ll say okay it depends on the three</p>



<p class="wp-block-paragraph">object files if they&#8217;re already there and they&#8217;re already satisfied then it it won&#8217;t actually</p>



<p class="wp-block-paragraph">if they&#8217;re already there and they are all newer than their corresponding source files then none</p>



<p class="wp-block-paragraph">corresponding source files, then none of them will get rebuilt. If main itself sees that it is newer,</p>



<p class="wp-block-paragraph">like the existing on disk version of main is newer than all the object files, then that tells the</p>



<p class="wp-block-paragraph">build system, oh, I don&#8217;t actually even need to relink the binary at all because the object files</p>



<p class="wp-block-paragraph">didn&#8217;t change, which means the source code didn&#8217;t change. And so you could actually like type make</p>



<p class="wp-block-paragraph">build and nothing happens because nothing needs to happen. It&#8217;s going to be pretty cool. I&#8217;ll show</p>



<p class="wp-block-paragraph">I&#8217;ll show you in a moment.</p>



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



<p class="wp-block-paragraph">So for now, I&#8217;m going to try not to erase this.</p>



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



<p class="wp-block-paragraph">Do I can, I don&#8217;t know if I remember, I think it&#8217;s like control.</p>



<p class="wp-block-paragraph">Let me do the menu here.</p>



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



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



<p class="wp-block-paragraph">It would have been control.</p>



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



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



<p class="wp-block-paragraph">Just get that off there.</p>



<p class="wp-block-paragraph">Just in case I want to show it to you again later.</p>



<p class="wp-block-paragraph">So now let&#8217;s make the first object file.</p>



<p class="wp-block-paragraph">So remember the first object file is first.o.</p>



<p class="wp-block-paragraph">to create a target that will build the object file based on the first source code file.</p>



<p class="wp-block-paragraph">I&#8217;m going to put a colon there to indicate that it&#8217;s a target.</p>



<p class="wp-block-paragraph">And then remember on the right side, we can do dependencies.</p>



<p class="wp-block-paragraph">Well, we have to say that this depends on the first CPP file.</p>



<p class="wp-block-paragraph">If we didn&#8217;t, then every single time we run the make system,</p>



<p class="wp-block-paragraph">then this object file is just going to get built over and over and over again,</p>



<p class="wp-block-paragraph">even if it doesn&#8217;t need to.</p>



<p class="wp-block-paragraph">So now with a dependency there, it&#8217;s going to look at first.cpp</p>



<p class="wp-block-paragraph">and then it&#8217;s going to look at first.o if one exists if one doesn&#8217;t exist it&#8217;ll</p>



<p class="wp-block-paragraph">definitely build it but if one does exist it&#8217;ll go is first.o newer than</p>



<p class="wp-block-paragraph">first.cpp if it is don&#8217;t do anything but if it&#8217;s not then rebuild it make sure</p>



<p class="wp-block-paragraph">it&#8217;s fresh here&#8217;s the other thing though I kind of wanted to build everything</p>



<p class="wp-block-paragraph">inside of the of the build folder so I&#8217;m gonna add the variable build in front of</p>



<p class="wp-block-paragraph">it let me do it first without doing that so that you can kind of see what will</p>



<p class="wp-block-paragraph">So it&#8217;s going to depend on first dot CPP.</p>



<p class="wp-block-paragraph">And then there&#8217;s another thing you can do in make files where you can,</p>



<p class="wp-block-paragraph">I forgot the proper name for this,</p>



<p class="wp-block-paragraph">but you can specify other types of dependencies where they only need to exist</p>



<p class="wp-block-paragraph">as a dependency.</p>



<p class="wp-block-paragraph">They don&#8217;t necessarily need to be freshly fully updated because,</p>



<p class="wp-block-paragraph">you know, the way files and folders work,</p>



<p class="wp-block-paragraph">if you start adding or removing files from a directory,</p>



<p class="wp-block-paragraph">then the directory thinks that it&#8217;s been updated.</p>



<p class="wp-block-paragraph">And so that can kind of throw off the build system&#8217;s thinking</p>



<p class="wp-block-paragraph">the build system&#8217;s thinking because your build directory will always think that it&#8217;s been updated</p>



<p class="wp-block-paragraph">if anything happens. But we don&#8217;t really care about the date of when the build directory was</p>



<p class="wp-block-paragraph">built. We just want to make sure that it exists, right? So we put a little or bar and we put those</p>



<p class="wp-block-paragraph">types of dependencies on the right side of the or bar. Okay, maybe I&#8217;ll leave a comment or something</p>



<p class="wp-block-paragraph">at a later date specifying the official name for that, but I mean, that&#8217;s how it works.</p>



<p class="wp-block-paragraph">So that&#8217;s the recipe.</p>



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



<p class="wp-block-paragraph">You know, in the past, I&#8217;ve said when you name a dependency,</p>



<p class="wp-block-paragraph">it goes off and make sure that that dependency is resolved.</p>



<p class="wp-block-paragraph">Well, that&#8217;s true for phony targets and targets that sort of do other things.</p>



<p class="wp-block-paragraph">But in this case, if we&#8217;re just naming a file, all it&#8217;s going to do is just look</p>



<p class="wp-block-paragraph">at the modification date of the file.</p>



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



<p class="wp-block-paragraph">I&#8217;m going to do CPP, which means that&#8217;s the C++ compiler.</p>



<p class="wp-block-paragraph">And I could write, you know, G++ and all the commands here directly</p>



<p class="wp-block-paragraph">directly if I want to, but it&#8217;s kind of a waste of time.</p>



<p class="wp-block-paragraph">And it&#8217;s not, it&#8217;s not very smart because we said before, what if you want to change</p>



<p class="wp-block-paragraph">the flags and you have a hundred objects that you&#8217;re building, you probably just want to</p>



<p class="wp-block-paragraph">be able to change one variable instead of a hundred different things.</p>



<p class="wp-block-paragraph">So we&#8217;ll do CPP flags and then we&#8217;ll, let&#8217;s see, we&#8217;ll take first.cpp as a source.</p>



<p class="wp-block-paragraph">You can imagine again, this is like, you know, G++ happening inside of here and then wall</p>



<p class="wp-block-paragraph">inside of here.</p>



<p class="wp-block-paragraph">and then at some point you specify the source.</p>



<p class="wp-block-paragraph">Okay, so just keep that in mind.</p>



<p class="wp-block-paragraph">And then after I specify the source,</p>



<p class="wp-block-paragraph">I want to specify the output</p>



<p class="wp-block-paragraph">and the output is going to be first.o.</p>



<p class="wp-block-paragraph">And now let&#8217;s use another trick</p>



<p class="wp-block-paragraph">which allows us to make slightly more powerful make files.</p>



<p class="wp-block-paragraph">So again, you want to avoid hard coding stuff if you can.</p>



<p class="wp-block-paragraph">There&#8217;s a special variable.</p>



<p class="wp-block-paragraph">Well, okay, let&#8217;s go back first to the other special variable.</p>



<p class="wp-block-paragraph">Remember $and, or sorry, $at.</p>



<p class="wp-block-paragraph">that always refers to the current target right so first.o is the is the current</p>



<p class="wp-block-paragraph">target so I don&#8217;t even have to type first.o here I can just do dollar sign</p>



<p class="wp-block-paragraph">at there&#8217;s another special variable which just basically means the first</p>



<p class="wp-block-paragraph">dependency that&#8217;s been named so if I just do quotes and then I say this it&#8217;s</p>



<p class="wp-block-paragraph">weird I know dollar sign and then angle bracket pointing to the left or like a</p>



<p class="wp-block-paragraph">typing first dot CPP. If you wanted to send a bunch more stuff, like if you wanted to</p>



<p class="wp-block-paragraph">send all of the names of all dependencies that you named into the command line, then</p>



<p class="wp-block-paragraph">you can use the carrot like dollar carrot. That&#8217;ll do all of the dependencies. But if</p>



<p class="wp-block-paragraph">we&#8217;re just compiling one source code file, you probably want to just do one dependency.</p>



<p class="wp-block-paragraph">Like for example, if I had other thing dot HPP as a dependency, I probably wouldn&#8217;t want</p>



<p class="wp-block-paragraph">because then that would be telling the compiler,</p>



<p class="wp-block-paragraph">here, I want you to compile first.cpp and also other thing.hpp,</p>



<p class="wp-block-paragraph">which probably wouldn&#8217;t work.</p>



<p class="wp-block-paragraph">It&#8217;s probably not what you want.</p>



<p class="wp-block-paragraph">So instead, if I do this like arrow to the left,</p>



<p class="wp-block-paragraph">then it will only give it first.cpp rather than both dependencies.</p>



<p class="wp-block-paragraph">But I guess we&#8217;re simple.</p>



<p class="wp-block-paragraph">We don&#8217;t really need all that right now.</p>



<p class="wp-block-paragraph">So we got that finished.</p>



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



<p class="wp-block-paragraph">We now have the binary.</p>



<p class="wp-block-paragraph">okay this is only going to run if i do make first dot oh maybe i should do that right now so that</p>



<p class="wp-block-paragraph">we can we can take more baby steps to making this more complicated so i&#8217;ll do here and make</p>



<p class="wp-block-paragraph">and then i&#8217;ll do make first dot o so notice how when i typed first dot o it went right to this</p>



<p class="wp-block-paragraph">target no problem and then it started to you know it looked at first dot cpp just to see you know</p>



<p class="wp-block-paragraph">built or not and it it also looked at the build directory as a dependency and</p>



<p class="wp-block-paragraph">then finally it actually compiled so what we should see right now is first</p>



<p class="wp-block-paragraph">dot o sitting in the directory and then also we should see the build directory</p>



<p class="wp-block-paragraph">again let&#8217;s just double check that so if I list everything notice how the build</p>



<p class="wp-block-paragraph">directory exists if I go remove and then remove the build directory and then</p>



<p class="wp-block-paragraph">clear it again notice how we also have first dot o so I can say remove first</p>



<p class="wp-block-paragraph">So if we go clear and list everything again, now I&#8217;m going to do one more time.</p>



<p class="wp-block-paragraph">Make first.o and then if I do list, then the first.o got built and the build directory got built.</p>



<p class="wp-block-paragraph">Notice also that as soon as I ran that command, it did make dir on build.</p>



<p class="wp-block-paragraph">So it built the build directory.</p>



<p class="wp-block-paragraph">So that was the build dir target.</p>



<p class="wp-block-paragraph">And then it went over to the first.o target and it executed that command to actually compile it.</p>



<p class="wp-block-paragraph">All my variables expanded, so it&#8217;s like G++, wall, pedantic, whatever.</p>



<p class="wp-block-paragraph">That special variable with the arrow pointing to the left was the first source code, or source code file.</p>



<p class="wp-block-paragraph">And then the $at variable expanded to the current target, which is just first.o.</p>



<p class="wp-block-paragraph">If we run this again, I&#8217;m not going to clear it, I&#8217;m just going to go make first.o.</p>



<p class="wp-block-paragraph">Notice how nothing actually happens.</p>



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



<p class="wp-block-paragraph">Up here we had two lines where we made the build directory</p>



<p class="wp-block-paragraph">and we also compiled the object file.</p>



<p class="wp-block-paragraph">But notice how here it just says the object file is up to date.</p>



<p class="wp-block-paragraph">It did not recompile it because it can tell that the source code was not changed.</p>



<p class="wp-block-paragraph">Let me go into another directory right here and I&#8217;ll just modify the source code file.</p>



<p class="wp-block-paragraph">I&#8217;ll just add an extra line to it and then I&#8217;ll go back here.</p>



<p class="wp-block-paragraph">and if I compile it now we should see that it chooses to compile it again</p>



<p class="wp-block-paragraph">because now the source code is newer than the object file so if I go make</p>



<p class="wp-block-paragraph">first notice how it did not build the build directory because it already</p>



<p class="wp-block-paragraph">existed but it did rebuild the object file because the source code was updated</p>



<p class="wp-block-paragraph">if I immediately try to build it again it does not need to rebuild it because</p>



<p class="wp-block-paragraph">the source code didn&#8217;t get updated since the last time I built and so it says</p>



<p class="wp-block-paragraph">it&#8217;s up to date up to date sometimes you might see a message that says something</p>



<p class="wp-block-paragraph">just says something like nothing to do, I think.</p>



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



<p class="wp-block-paragraph">We&#8217;re getting a little bit better now.</p>



<p class="wp-block-paragraph">But I&#8217;m also making a mistake here</p>



<p class="wp-block-paragraph">because we have a build directory</p>



<p class="wp-block-paragraph">but there&#8217;s nothing inside of it.</p>



<p class="wp-block-paragraph">I wanna put everything inside of my build directory</p>



<p class="wp-block-paragraph">just to show you how annoying this could be.</p>



<p class="wp-block-paragraph">Notice how we got a first.cpp and a first.o.</p>



<p class="wp-block-paragraph">Imagine if you had a million source code files,</p>



<p class="wp-block-paragraph">you&#8217;ll have a million object files</p>



<p class="wp-block-paragraph">sitting in your repository or your directory</p>



<p class="wp-block-paragraph">kinda cluttering the place up, right?</p>



<p class="wp-block-paragraph">cluttering the place up, right? I don&#8217;t like it. I&#8217;m not a fan. You probably want to edit your</p>



<p class="wp-block-paragraph">git ignore so that you don&#8217;t accidentally put object files into your repo. But for me, I think</p>



<p class="wp-block-paragraph">it&#8217;s better to just ignore, git ignore a build directory, and then just stick everything inside</p>



<p class="wp-block-paragraph">of the build directory. It&#8217;s up to you, but this is the way I&#8217;m going to do it. So how do we get</p>



<p class="wp-block-paragraph">it to be inside of the build directory? First, let me remove the object file. Okay, let&#8217;s see,</p>



<p class="wp-block-paragraph">I think I can get rid of that. That&#8217;s responsible for the swap file. We probably want to put</p>



<p class="wp-block-paragraph">star.swap inside of gitignore so that the temporary files from nano don&#8217;t go into our</p>



<p class="wp-block-paragraph">repository. So now I&#8217;m going to prefix this object file. And a lot of people don&#8217;t do this,</p>



<p class="wp-block-paragraph">but I think it&#8217;s pretty cool. I&#8217;m going to do build dir slash the object. And then now</p>



<p class="wp-block-paragraph">everything&#8217;s going to show up inside of the builder or at least that one. So if I remove</p>



<p class="wp-block-paragraph">directory just kind of list things again then I can do make first oh and then</p>



<p class="wp-block-paragraph">notice how it mmm what happened oh what did I do wrong well I did something wrong</p>



<p class="wp-block-paragraph">okay hang on let me see if I can fix that first oh what in the heck did I do</p>



<p class="wp-block-paragraph">second and third. Okay, so I didn&#8217;t break anything.</p>



<p class="wp-block-paragraph">First.o. Oh, because when I typed this on the command line, I was typing first.o and</p>



<p class="wp-block-paragraph">well, that&#8217;s not the target anymore. The real target now is underscore build first.o.</p>



<p class="wp-block-paragraph">So maybe this is a good time to stick our binary target inside of there.</p>



<p class="wp-block-paragraph">So we have the binary target. I kind of ignored it for a second because I wanted to show you an object file first.</p>



<p class="wp-block-paragraph">We want to make the main file that gets executed.</p>



<p class="wp-block-paragraph">We have to link everything together.</p>



<p class="wp-block-paragraph">So, well, maybe this is a better description down here for that.</p>



<p class="wp-block-paragraph">And then up here, I&#8217;ll say alias for just building the binary.</p>



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



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



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



<p class="wp-block-paragraph">There we go.</p>



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



<p class="wp-block-paragraph">So now we&#8217;re actually going to do it.</p>



<p class="wp-block-paragraph">So we&#8217;ll put bin.</p>



<p class="wp-block-paragraph">So now bin is its own target, meaning our main program that we want to create</p>



<p class="wp-block-paragraph">main program that we want to create is uh it&#8217;s going to happen somehow the uh dependencies that</p>



<p class="wp-block-paragraph">it needs though should be all of our object files that we intend to create so first you know one of</p>



<p class="wp-block-paragraph">its dependencies should be uh inside of the builder and i know this is annoying to type these variables</p>



<p class="wp-block-paragraph">all over the place but kind of the price you pay for having everything outside of the working</p>



<p class="wp-block-paragraph">directory but i guess that&#8217;s why a lot of people don&#8217;t do this we say builder first dot o so</p>



<p class="wp-block-paragraph">So basically saying before we can create the executable, we have to first build the first</p>



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



<p class="wp-block-paragraph">And then we&#8217;ll just name more dependencies.</p>



<p class="wp-block-paragraph">I&#8217;ll say the builder, we separate dependencies using spaces.</p>



<p class="wp-block-paragraph">That&#8217;s another reason that make has problems with spaces if you&#8217;re going to do like an</p>



<p class="wp-block-paragraph">absolute path or something.</p>



<p class="wp-block-paragraph">So then we&#8217;re going to grab the second object file as a dependency and then the third object</p>



<p class="wp-block-paragraph">file as a dependency.</p>



<p class="wp-block-paragraph">means we just need to set up targets for each one of those object files we only have first.o</p>



<p class="wp-block-paragraph">set up so far we&#8217;ll have to set up the second and the third one so aside from those dependencies we</p>



<p class="wp-block-paragraph">want to make sure that the builder is actually created so we&#8217;ll put builder as another uh you</p>



<p class="wp-block-paragraph">know non-time stamped uh dependency like we did with the object file then the command we&#8217;ll actually</p>



<p class="wp-block-paragraph">and remember CPP is just GCC and then the link flags is the stuff that we set up up above</p>



<p class="wp-block-paragraph">which is basically going to be you know wall pedantic G and then M64 no pi no you know all</p>



<p class="wp-block-paragraph">the stuff we don&#8217;t want to type manually at the very bottom so we&#8217;re going to do that link flags</p>



<p class="wp-block-paragraph">you know we want to give it every single object file as an input so we&#8217;ll name you know first.o</p>



<p class="wp-block-paragraph">and then we&#8217;ll name second.o second.o and you know i&#8217;m getting irritated i hope you can tell</p>



<p class="wp-block-paragraph">already i don&#8217;t want to type all these things so we can use a shell trick we can put a wild card</p>



<p class="wp-block-paragraph">there we can say how about i just give you every file asterisk that ends in.o so star.o basically</p>



<p class="wp-block-paragraph">on that command line it&#8217;s going to go look into the build directory and just</p>



<p class="wp-block-paragraph">give it every object file that it sees it&#8217;s not a great idea if you have</p>



<p class="wp-block-paragraph">multiple different executables that you want to make and they&#8217;ve all got their</p>



<p class="wp-block-paragraph">own main functions and they&#8217;re all in the same builder but in our case we only</p>



<p class="wp-block-paragraph">have one executable with one main function so we can just throw all of the</p>



<p class="wp-block-paragraph">object files we want at it if you had other types of object files you wanted</p>



<p class="wp-block-paragraph">to link into your executable like for example shared object files you could</p>



<p class="wp-block-paragraph">object files you could basically do the same thing but just go you know builder star star.so</p>



<p class="wp-block-paragraph">or maybe not even in the builder if i if let&#8217;s say if i gave you a shared object file</p>



<p class="wp-block-paragraph">and i wanted you to link that into your program you would just specify wherever it was</p>



<p class="wp-block-paragraph">you know maybe it&#8217;s in the root something.so maybe it&#8217;s in a different folder um and maybe</p>



<p class="wp-block-paragraph">you want to create a variable up top to just kind of like name where the shared object files are</p>



<p class="wp-block-paragraph">libraries are it&#8217;s up to you but I&#8217;m just letting you know this is how you</p>



<p class="wp-block-paragraph">would do it to get a shared object file in there as well for this program it&#8217;s</p>



<p class="wp-block-paragraph">very simple we just are gonna grab the object files and that&#8217;s it so now we&#8217;re</p>



<p class="wp-block-paragraph">just ready to specify the output file with a dash o and we&#8217;ll use that same</p>



<p class="wp-block-paragraph">trick again dollar sign and at so we don&#8217;t have to specify the the full</p>



<p class="wp-block-paragraph">target which is just going to be the bin variable so let&#8217;s see what do I got to</p>



<p class="wp-block-paragraph">If we run it right now, it should fail because it&#8217;ll complain that we don&#8217;t have second and third built.</p>



<p class="wp-block-paragraph">But at least I have enough now to use the make run target.</p>



<p class="wp-block-paragraph">So we can stop specifying the names of files and just say something like make run or make build and it&#8217;s just way easier to type.</p>



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



<p class="wp-block-paragraph">It&#8217;s going to depend on build.</p>



<p class="wp-block-paragraph">Build is going to execute before run even tries to run.</p>



<p class="wp-block-paragraph">Build is going to say, well, I depend on the binary, the executable.</p>



<p class="wp-block-paragraph">Then that means the binary&#8217;s target is going to run.</p>



<p class="wp-block-paragraph">run it&#8217;s going to depend on all these object files so before it even tries to do anything</p>



<p class="wp-block-paragraph">it&#8217;s going to go down here to the first dot o object file it&#8217;s actually going to build it</p>



<p class="wp-block-paragraph">then it&#8217;s going to come back and try to handle the next dependency which is second dot o</p>



<p class="wp-block-paragraph">but there&#8217;s no target for second dot o and it&#8217;s not on disk um so it&#8217;s just going to fail at that</p>



<p class="wp-block-paragraph">point so let&#8217;s see if let&#8217;s see if i&#8217;m right we&#8217;re going to do make run clear and whoops</p>



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



<p class="wp-block-paragraph">Okay, so ensuring the build directory. Oh, I forgot to mention that yet</p>



<p class="wp-block-paragraph">It&#8217;s gonna ensure the build directory then it actually builds the first object file so far so good</p>



<p class="wp-block-paragraph">Then it complains no rule to make the target second auto so we can&#8217;t continue Oh</p>



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



<p class="wp-block-paragraph">By the way just to show you I think it&#8217;s like a J</p>



<p class="wp-block-paragraph">Let&#8217;s say we wanted to launch this with eight threads. I think it might be low</p>



<p class="wp-block-paragraph">Is it lowercase or uppercase J? I can never remember. Let me try lowercase</p>



<p class="wp-block-paragraph">second how about uppercase nope okay so it&#8217;s lowercase well I guess it just fails right there</p>



<p class="wp-block-paragraph">I was kind of hoping it would try to spawn off two threads to look at second and also third</p>



<p class="wp-block-paragraph">at the same time and then fail twice maybe that&#8217;s why it didn&#8217;t do that because it automatically</p>



<p class="wp-block-paragraph">saw right away oh we can&#8217;t do anything so let&#8217;s just cut the whole build process so now I&#8217;m going</p>



<p class="wp-block-paragraph">Cut cut cut paste paste and then I&#8217;m going to say build the second object file</p>



<p class="wp-block-paragraph">So we&#8217;re going to depend on seconds</p>



<p class="wp-block-paragraph">There are actually advanced patterns you can use so that you don&#8217;t even have to specify the object files you can</p>



<p class="wp-block-paragraph">There&#8217;s there&#8217;s these things that people do I did it a couple times</p>



<p class="wp-block-paragraph">But I don&#8217;t really like it where you can have make sort of scan your source code directory for all CPP files and</p>



<p class="wp-block-paragraph">Automatically compile them in the exact same way and then the output file is like</p>



<p class="wp-block-paragraph">And then the output file is like the name of the source code file and then.o concatenated at the end of it.</p>



<p class="wp-block-paragraph">But this video is not like that advanced, so I&#8217;m not going to do that.</p>



<p class="wp-block-paragraph">So we&#8217;re going to compile second.c into second.o.</p>



<p class="wp-block-paragraph">And we need to make sure the build directory is created.</p>



<p class="wp-block-paragraph">And instead of using the CPP compiler, we&#8217;re going to use the regular C compiler.</p>



<p class="wp-block-paragraph">And then we&#8217;re going to do cc flags right there.</p>



<p class="wp-block-paragraph">and I think that&#8217;s all we need so then we&#8217;re gonna do the last object file by</p>



<p class="wp-block-paragraph">the way in nano I&#8217;m going control K to cut and control you to paste and it&#8217;s</p>



<p class="wp-block-paragraph">kind of convenient if you want to like duplicate you know a few lines we&#8217;re</p>



<p class="wp-block-paragraph">gonna use the ASM to assemble the assembly code so I&#8217;m gonna do third dot</p>



<p class="wp-block-paragraph">what it was and then we have to use a totally different command now we have to use the assembly</p>



<p class="wp-block-paragraph">assembler variable so that&#8217;s the name of the tool that assembles and then we&#8217;ll give it the assembly</p>



<p class="wp-block-paragraph">flags i mean i guess it&#8217;s not that different and then we&#8217;ll say give it the first dependency which</p>



<p class="wp-block-paragraph">is just the source code and then output to the at target so we should have like a lot of stuff</p>



<p class="wp-block-paragraph">ready to go let&#8217;s see if this works now if i say clear and make run then what is it going to do it</p>



<p class="wp-block-paragraph">then what is it going to do it the first thing it does is it compiles the second object file</p>



<p class="wp-block-paragraph">notice how it did not compile the first object file because remember we just compiled that</p>



<p class="wp-block-paragraph">and we didn&#8217;t change the source code so it just ignored it and we have a faster compile</p>



<p class="wp-block-paragraph">then it assembles aka compiles the assembly to its own object file and then</p>



<p class="wp-block-paragraph">now that all those object files are satisfied notice how like you know for the binary</p>



<p class="wp-block-paragraph">all of those object files first and make sure the build directory is there. Then finally it can</p>



<p class="wp-block-paragraph">execute its own recipe, which is just one command saying, you know, let&#8217;s link this stuff together</p>



<p class="wp-block-paragraph">by grabbing all the object files. So that&#8217;s this line right here, the linking flags and the linker.</p>



<p class="wp-block-paragraph">So it&#8217;s like GCC and all the linking flags, the no pie and all that stuff. And it&#8217;s expanded that</p>



<p class="wp-block-paragraph">variable. Remember we put builder slash star dot O. So that glob right there basically says grab</p>



<p class="wp-block-paragraph">glob right there basically says grab all the object files from the build directory and then</p>



<p class="wp-block-paragraph">output the main program in the build directory no no i think even if you&#8217;re using a build directory</p>



<p class="wp-block-paragraph">sometimes people will still put their executable in the root i don&#8217;t know it&#8217;s up to you i don&#8217;t</p>



<p class="wp-block-paragraph">really care finally after all that is done you&#8217;ll see let&#8217;s see what we actually did is we said let&#8217;s</p>



<p class="wp-block-paragraph">its recipe it goes down here for build and then build says first we need to build that binary</p>



<p class="wp-block-paragraph">and then binaries like first we got to build the object files and then you know all those</p>



<p class="wp-block-paragraph">get built finally when the object files are built then the binary gets to link itself</p>



<p class="wp-block-paragraph">when it&#8217;s done linking itself then we go back to this point because now finally the dependencies</p>



<p class="wp-block-paragraph">on line 108 are satisfied then that means the build target its dependencies are satisfied</p>



<p class="wp-block-paragraph">dependencies are satisfied. It would execute its recipe, but there&#8217;s no recipe there. So it just</p>



<p class="wp-block-paragraph">goes back to run because in the first place, run said, I need you to make sure that build is handled</p>



<p class="wp-block-paragraph">before I&#8217;ll execute my recipe or all of my statements. So finally, after all that stuff</p>



<p class="wp-block-paragraph">was done, then it&#8217;s just a command line that just names the executable, which is going to run it.</p>



<p class="wp-block-paragraph">And that&#8217;s this last part right here. So right there, it just names the executable using a</p>



<p class="wp-block-paragraph">using a whoops using a relative path to our main executable so now below that</p>



<p class="wp-block-paragraph">line the program is actually running it&#8217;s like hello from first hello from</p>



<p class="wp-block-paragraph">second hello from third and watch this if I do make run again nothing happens</p>



<p class="wp-block-paragraph">except executing the program notice how none of the object files are getting</p>



<p class="wp-block-paragraph">built the binary is not getting linked nothing is happening because it&#8217;s</p>



<p class="wp-block-paragraph">already done all it does for the run target now is just run the executable</p>



<p class="wp-block-paragraph">run the executable. It&#8217;s the same thing as if we did build main, just to run it. That&#8217;s it.</p>



<p class="wp-block-paragraph">You know, of course, it&#8217;s a little more proper to go dot slash, right? You don&#8217;t have to use the</p>



<p class="wp-block-paragraph">dot if the thing you&#8217;re naming is in a different directory, but you do if it&#8217;s in the same directory.</p>



<p class="wp-block-paragraph">Like if we just went into the build directory, by the way, here&#8217;s all our build files. They&#8217;re</p>



<p class="wp-block-paragraph">in one convenient place. You can do a git ignore on that, or you can just delete the folder if</p>



<p class="wp-block-paragraph">if you want to clean everything.</p>



<p class="wp-block-paragraph">But we can&#8217;t just type main here, it&#8217;s not going to work.</p>



<p class="wp-block-paragraph">We have to do a dot slash main because we&#8217;re in the same folder.</p>



<p class="wp-block-paragraph">But if we&#8217;re one level higher, then we can just name build main and it&#8217;ll work.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s do another thing real fast here.</p>



<p class="wp-block-paragraph">Let&#8217;s do another target that is kind of typical.</p>



<p class="wp-block-paragraph">It is the clean target.</p>



<p class="wp-block-paragraph">useful when people have object files just scattered around the root of their of their file system</p>



<p class="wp-block-paragraph">there their repository but i like to add it in anyway for mine even though mine&#8217;s a little bit</p>



<p class="wp-block-paragraph">cleaner right now so we&#8217;ll do another target called clean and we&#8217;ll just say clean the uh the</p>



<p class="wp-block-paragraph">build area system thing stuff and i&#8217;m just going to put the word clean with a colon no dependencies</p>



<p class="wp-block-paragraph">meaning it&#8217;ll always run right away and not depend on anything it&#8217;s obviously a phony target because</p>



<p class="wp-block-paragraph">It&#8217;s obviously a phony target because I&#8217;m not going to make a file called clean so I&#8217;m</p>



<p class="wp-block-paragraph">going to stick that as a dependency to phony.</p>



<p class="wp-block-paragraph">And then what is it going to do?</p>



<p class="wp-block-paragraph">Usually this is where you put something like let&#8217;s remove star dot o, let&#8217;s remove all</p>



<p class="wp-block-paragraph">of the object files and then let&#8217;s remove the binary file and let&#8217;s remove anything</p>



<p class="wp-block-paragraph">that we built so that we can just clean it.</p>



<p class="wp-block-paragraph">Maybe I could put that here, build dir slash o, I&#8217;m going to make it a little bit better</p>



<p class="wp-block-paragraph">in a second.</p>



<p class="wp-block-paragraph">inside of the builder and then we&#8217;ll also remove the binary.</p>



<p class="wp-block-paragraph">So when we go back into our file system,</p>



<p class="wp-block-paragraph">if we list the build directory,</p>



<p class="wp-block-paragraph">we should see that it&#8217;s empty after we run this.</p>



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



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



<p class="wp-block-paragraph">And then you can see that these two removal commands got executed.</p>



<p class="wp-block-paragraph">And then if I list the directory again, notice how it&#8217;s empty.</p>



<p class="wp-block-paragraph">But the remove command will fail</p>



<p class="wp-block-paragraph">if it tries to remove something that doesn&#8217;t exist.</p>



<p class="wp-block-paragraph">to remove something that doesn&#8217;t exist so we&#8217;ll actually get like a a nasty message from clean</p>



<p class="wp-block-paragraph">or from make if we try to clean again so we say make clean it says remove tried to remove object</p>



<p class="wp-block-paragraph">files but there was nothing inside of there no such file or directory so then it just stops the</p>



<p class="wp-block-paragraph">whole process well that seems okay for now but what if you uh what if you had gone in and removed or</p>



<p class="wp-block-paragraph">and that stopped other things from being cleaned you&#8217;d probably end up being</p>



<p class="wp-block-paragraph">pretty frustrated right so for the clean target I&#8217;m just gonna say remove is a</p>



<p class="wp-block-paragraph">command that won&#8217;t stop the build or the target so I&#8217;m gonna put a minus in</p>



<p class="wp-block-paragraph">front of there meaning don&#8217;t stop if something goes wrong just keep</p>



<p class="wp-block-paragraph">executing all these commands and so now if we do clear and make clean notice how</p>



<p class="wp-block-paragraph">it actually tries to remove both types of things it doesn&#8217;t just stop on the</p>



<p class="wp-block-paragraph">I guess this is the first problem.</p>



<p class="wp-block-paragraph">It&#8217;s trying to remove the object files.</p>



<p class="wp-block-paragraph">Then remove says, no, I can&#8217;t do that.</p>



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



<p class="wp-block-paragraph">And then make says, I&#8217;m ignoring you.</p>



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



<p class="wp-block-paragraph">There is no bathroom.</p>



<p class="wp-block-paragraph">And then the same thing happens for removing the executable main.</p>



<p class="wp-block-paragraph">But we can make this actually a little bit more efficient.</p>



<p class="wp-block-paragraph">I mean, this is kind of what you&#8217;ll do if everything is sitting at the root of your repo.</p>



<p class="wp-block-paragraph">But if we simply have a build directory and you&#8217;re absolutely sure that you already have</p>



<p class="wp-block-paragraph">you know set to the correct value then you could just remove i don&#8217;t know if i want to do it now</p>



<p class="wp-block-paragraph">because i&#8217;m getting scared you could just remove the entire build directory i&#8217;m going to do it but</p>



<p class="wp-block-paragraph">i&#8217;ll explain to you why i kind of don&#8217;t want to do it in a second we could remove the entire build</p>



<p class="wp-block-paragraph">directory so like with the remove command remove recursively the entire build directory</p>



<p class="wp-block-paragraph">just so you don&#8217;t see it if you feel like it&#8217;s an eyesore so i&#8217;m going to do make clean</p>



<p class="wp-block-paragraph">do it again do it again do it again and notice well why wasn&#8217;t it</p>



<p class="wp-block-paragraph">i feel like it should have failed but i guess remove felt like it wasn&#8217;t a failure if build</p>



<p class="wp-block-paragraph">didn&#8217;t exist but notice how the builder is gone so i didn&#8217;t really have to specify</p>



<p class="wp-block-paragraph">the object files but it&#8217;s a little bit safer i don&#8217;t know it depends on your philosophy</p>



<p class="wp-block-paragraph">this is way more compact and nicer that was my first feeling but it&#8217;s also a little more</p>



<p class="wp-block-paragraph">there into the variables area and i like change the builder somehow i change its name or i change</p>



<p class="wp-block-paragraph">its value and i accidentally now have this variable pointed to like a dangerous path</p>



<p class="wp-block-paragraph">and then if i type make clean it just erases everything not sure i really like that idea so</p>



<p class="wp-block-paragraph">i&#8217;m going to do i&#8217;m going to go back to the original way which takes more typing</p>



<p class="wp-block-paragraph">remove every object file and maybe before that let&#8217;s remove the binary so if we do</p>



<p class="wp-block-paragraph">if we do make build which by the way will only build things it won&#8217;t run anything remember</p>



<p class="wp-block-paragraph">the dependency graph that we looked at a little while ago or not the dependency graph that we</p>



<p class="wp-block-paragraph">explained the dependencies so it does everything required to build but it doesn&#8217;t actually run the</p>



<p class="wp-block-paragraph">program and that&#8217;s fine i just wanted to go look inside of the build directory</p>



<p class="wp-block-paragraph">and you can see it&#8217;s got all the stuff there so then if i just run make clean one more time</p>



<p class="wp-block-paragraph">by the way, if I try to run make clean from here,</p>



<p class="wp-block-paragraph">there&#8217;s no make file in this directory.</p>



<p class="wp-block-paragraph">So nothing&#8217;s going to happen.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go up one level, make clean.</p>



<p class="wp-block-paragraph">And then if I list the build directory,</p>



<p class="wp-block-paragraph">there&#8217;s just nothing inside of it.</p>



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



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



<p class="wp-block-paragraph">Let me just look at my notes right here.</p>



<p class="wp-block-paragraph">I just finished building this whole giant make file.</p>



<p class="wp-block-paragraph">It&#8217;s not even like that complicated,</p>



<p class="wp-block-paragraph">but I hope that you&#8217;ve learned a lot</p>



<p class="wp-block-paragraph">about making make files at this point.</p>



<p class="wp-block-paragraph">this point i hope you kind of like the idea let me just double check there&#8217;s nothing else i wanted</p>



<p class="wp-block-paragraph">to say for this video oh i should point out that gnu make is not the only build system available</p>



<p class="wp-block-paragraph">it&#8217;s just the one that i like the most um remember you can also put shortcuts in there like any</p>



<p class="wp-block-paragraph">command line that you could actually type could be part of the recipe of a target it doesn&#8217;t have</p>



<p class="wp-block-paragraph">to only build it doesn&#8217;t have to only be build targets so again you could make commands in there</p>



<p class="wp-block-paragraph">like deploy your executable somewhere or check something or like a long time ago I used to have</p>



<p class="wp-block-paragraph">a recipe actually it was that program I was talking about at the beginning where I converted</p>



<p class="wp-block-paragraph">an hour-long compilation to just like a minute I had another target in there called deploy so I&#8217;d</p>



<p class="wp-block-paragraph">say make deploy and what it would do is it would build and if it built then it would run unit tests</p>



<p class="wp-block-paragraph">on my code and if those succeeded then it would copy my source code to one of my other servers</p>



<p class="wp-block-paragraph">my other servers then remotely it would tell that other server to build and run tests and if all</p>



<p class="wp-block-paragraph">that succeeded you know if it didn&#8217;t succeed then it would just quit if all that succeeded then it</p>



<p class="wp-block-paragraph">would shut down the the server that I had written as a running service and then it would copy the</p>



<p class="wp-block-paragraph">freshly built executable to the right location and then it would restart the service so basically I</p>



<p class="wp-block-paragraph">just like do a bunch of coding and then I you know run my test if everything seems cool then I go make</p>



<p class="wp-block-paragraph">five minutes or whatever it took to run all the tests and do another compile and deploy everything</p>



<p class="wp-block-paragraph">and my server was just totally updated just by that so there&#8217;s a lot of stuff you can do but</p>



<p class="wp-block-paragraph">there are other great build systems out there there&#8217;s one called gradle there&#8217;s one called</p>



<p class="wp-block-paragraph">maven there&#8217;s other like node.js systems there&#8217;s a ton of build systems out there</p>



<p class="wp-block-paragraph">probably a slightly more popular popular c++ build system is called cmake it&#8217;s more tailored to c++</p>



<p class="wp-block-paragraph">um but you know you obviously don&#8217;t need to do it it&#8217;s just i think like a little bit easier</p>



<p class="wp-block-paragraph">depending on what you want to do so keep that in mind this is not the only system there&#8217;s a lot</p>



<p class="wp-block-paragraph">out there to explore but this is this is definitely a great first step um let&#8217;s see what else can i do</p>



<p class="wp-block-paragraph">oh we showed you the diagram showed you the info function and the targets and the dependencies</p>



<p class="wp-block-paragraph">and the run build well i guess i&#8217;m out of stuff to show you that&#8217;s that&#8217;s all i had written down</p>



<p class="wp-block-paragraph">that I wanted to show you maybe I could this is not a git video I&#8217;ll make you</p>



<p class="wp-block-paragraph">know I have other videos forget but you know if this is a git repository you</p>



<p class="wp-block-paragraph">would nano git ignore just because I kept mentioning this we&#8217;ll do nano git</p>



<p class="wp-block-paragraph">ignore and then I&#8217;ll just say ignore the build directory and ignore swap files so</p>



<p class="wp-block-paragraph">I&#8217;ll say like ignore the build directory and ignore anything that&#8217;s edited and</p>



<p class="wp-block-paragraph">your git status and git add and git commit and stuff then the build directory wouldn&#8217;t even show</p>



<p class="wp-block-paragraph">up so yeah kind of i guess it&#8217;s kind of unnecessary for this project okay i think that concludes this</p>



<p class="wp-block-paragraph">video assuming i was actually recording this entire time thank you so much for watching i</p>



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



<p class="wp-block-paragraph">practice practice practice and start making your own make file videos and let me know</p>



<p class="wp-block-paragraph">files in your own programs and let me know if you liked the content of this video and like if it</p>



<p class="wp-block-paragraph">helped you i love receiving emails way after the fact when people say hey i love make files now</p>



<p class="wp-block-paragraph">and it&#8217;s all because of you and i do it all the time because then i get to sit alone in my dark</p>



<p class="wp-block-paragraph">room and giggle to myself it&#8217;s all because of me um okay i think that&#8217;s probably a good note to</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 it</p>



<p class="wp-block-paragraph">is you do on the current social media website that you&#8217;re looking at right now it would really mean</p>



<p class="wp-block-paragraph">the world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do</p>



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



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



<p class="wp-block-paragraph">and I get filled with joy. That&#8217;s exactly what happens every single time. So you could do it as</p>



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">sweat and i&#8217;m like it would really it really mean the world to me i would really appreciate it so</p>



<p class="wp-block-paragraph">again thank you so much for watching this video and um enjoy the cool music</p>



<p class="wp-block-paragraph">as as i fade into the darkness which is coming for us all</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/">Master GNU Makefiles: Streamline Coding Builds with C++, C &amp; Assembly</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-gnu-makefiles-streamline-coding-builds-with-c-c-assembly/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Git Basics Tutorial: Learn Version Control, Commits &#038; Branches for Beginners</title>
		<link>https://www.NeuralLantern.com/git-basics-tutorial-learn-version-control-commits-branches-for-beginners/</link>
					<comments>https://www.NeuralLantern.com/git-basics-tutorial-learn-version-control-commits-branches-for-beginners/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 12 May 2025 09:07:04 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[avoid merge conflicts]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[Git basics]]></category>
		<category><![CDATA[Git branches]]></category>
		<category><![CDATA[Git clone]]></category>
		<category><![CDATA[Git collaboration]]></category>
		<category><![CDATA[Git commits]]></category>
		<category><![CDATA[Git for beginners]]></category>
		<category><![CDATA[Git pull]]></category>
		<category><![CDATA[Git push]]></category>
		<category><![CDATA[Git tutorial]]></category>
		<category><![CDATA[learn Git]]></category>
		<category><![CDATA[programming basics]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[version control]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=103</guid>

					<description><![CDATA[<p>Learn Git basics in this fun tutorial! Master version control, commits, branches &#038; collaboration for coding. #GitTutorial</p>
<p>The post <a href="https://www.NeuralLantern.com/git-basics-tutorial-learn-version-control-commits-branches-for-beginners/">Git Basics Tutorial: Learn Version Control, Commits &amp; Branches 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="Git Basics Tutorial: Learn Version Control, Commits &amp; Branches for Beginners" width="1380" height="776" src="https://www.youtube.com/embed/L-HDXipyEcM?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 there, coders! Want to master Git? This fun, beginner-friendly tutorial covers all the basics: what Git is, how to track changes, commit code, create branches, push to remotes, and collaborate with others. Whether you&#8217;re coding solo or with a team, Git&#8217;s got your back. Avoid losing code, recover old versions, and learn pro tips to dodge merge conflicts. Subscribe for more coding tutorials, and let’s make version control a breeze! #GitBasics #LearnToCode #ProgrammingTutorials</p>



<p class="wp-block-paragraph">Introduction to Git 00:00:00<br>What is Git 00:00:07<br>Git for tracking changes 00:00:18<br>Git for non-code documents 00:00:24<br>Why use Git 00:00:45<br>Code versioning benefits 00:00:50<br>Recovering deleted code 00:01:15<br>Collaboration with Git 00:02:35<br>Git repository basics 00:04:33<br>Installing Git 00:04:44<br>Creating a Git repository 00:05:08<br>Using git status 00:06:36<br>Adding files to Git 00:07:51<br>Committing changes 00:08:18<br>Checking Git log 00:11:21<br>Viewing changes with git diff 00:12:21<br>Pushing to remote 00:19:44<br>Cloning a repository 00:17:01<br>Branching in Git 00:23:27<br>Merging branches 00:25:21<br>Tagging releases 00:16:00<br>Pulling changes 00:26:55<br>Branching strategies 00:29:55<br>Avoiding merge conflicts 00:32:52<br>Backup and fresh clone tip 00:34:00<br>Conclusion and call to action 00:35: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">Hey there, I&#8217;d like to talk to you today about the basics of Git and what is Git.</p>



<p class="wp-block-paragraph">Git is an awesome system that you can use to track changes to all your code as you write</p>



<p class="wp-block-paragraph">programs and work on things. And in fact, you can use Git for tracking changes to a wide variety of</p>



<p class="wp-block-paragraph">documents, not just code only. There&#8217;s a special tool that I used a while back where I could track</p>



<p class="wp-block-paragraph">used a while back where I could track changes to just regular office documents.</p>



<p class="wp-block-paragraph">But if you&#8217;re writing text files of some sort or even like, I don&#8217;t know, making SVG graphics</p>



<p class="wp-block-paragraph">files or something like that, you can track changes to all sorts of stuff. Okay, so it&#8217;s</p>



<p class="wp-block-paragraph">mostly for coding. So what is Git and why would you want to use Git? Okay, so we talked about</p>



<p class="wp-block-paragraph">Git being a code versioning system. It will track your changes. Imagine this.</p>



<p class="wp-block-paragraph">Imagine you&#8217;re writing code and you spend all day, maybe like all month writing a really,</p>



<p class="wp-block-paragraph">really good algorithm or a really good function or something like that.</p>



<p class="wp-block-paragraph">And then maybe a year later, you haven&#8217;t been using it.</p>



<p class="wp-block-paragraph">And you kind of think to yourself, you know, whatever happened to that giant function that</p>



<p class="wp-block-paragraph">I wrote, that was really good.</p>



<p class="wp-block-paragraph">And then you realize, oh no, I accidentally, I think I deleted it like several months ago</p>



<p class="wp-block-paragraph">because I thought I didn&#8217;t need it anymore.</p>



<p class="wp-block-paragraph">I didn&#8217;t need it anymore.</p>



<p class="wp-block-paragraph">And now I&#8217;ve changed my mind.</p>



<p class="wp-block-paragraph">I wish I had that back.</p>



<p class="wp-block-paragraph">But then by then it&#8217;s too late because the code is gone and maybe you don&#8217;t have a backup</p>



<p class="wp-block-paragraph">or maybe your backup is just, you know, only a few snapshots deep or whatever.</p>



<p class="wp-block-paragraph">And so you&#8217;re kind of screwed, right?</p>



<p class="wp-block-paragraph">So one way that Git can help you is Git lets you look back in time to the state of your</p>



<p class="wp-block-paragraph">code at any other previous point.</p>



<p class="wp-block-paragraph">Like every time you make significant progress with your code, you log it in Gits database.</p>



<p class="wp-block-paragraph">You can just look back in time.</p>



<p class="wp-block-paragraph">You can look back to see what your code was three years ago.</p>



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



<p class="wp-block-paragraph">You can also, you know, revert changes.</p>



<p class="wp-block-paragraph">You can sort of like branch your code off in two different directions.</p>



<p class="wp-block-paragraph">Maybe here you&#8217;re just going to be working on bugs and on another branch, you&#8217;re adding</p>



<p class="wp-block-paragraph">one feature that you think might be a good idea.</p>



<p class="wp-block-paragraph">a really good idea you could merge that branch into the main branch or if you think that feature</p>



<p class="wp-block-paragraph">is and is going to be trash and it sucks and you wish you never did it you can just delete that</p>



<p class="wp-block-paragraph">branch and it doesn&#8217;t affect your main code branch it&#8217;s really cool it&#8217;s also a good tool</p>



<p class="wp-block-paragraph">for collaboration because multiple people can can push to the git database and they can get</p>



<p class="wp-block-paragraph">each other&#8217;s changes it&#8217;s kind of a way also to cloudify your code you know like if i&#8217;m writing</p>



<p class="wp-block-paragraph">writing a program, I can commit some changes and I can push some changes to the cloud.</p>



<p class="wp-block-paragraph">And then my colleague can pull my changes and they get everything that I just worked on.</p>



<p class="wp-block-paragraph">And then they can commit some more changes and push it back up to the cloud.</p>



<p class="wp-block-paragraph">Then I can pull it.</p>



<p class="wp-block-paragraph">And so we&#8217;re sort of like collaborating and in a way where every single change is logged,</p>



<p class="wp-block-paragraph">your boss can look at, or you, you know, you can look at all the logs in your commit,</p>



<p class="wp-block-paragraph">in your git commit database and see who changed what you can see what lines were changed when</p>



<p class="wp-block-paragraph">when they were changes you can see who introduced a bug there&#8217;s a function in</p>



<p class="wp-block-paragraph">git that is called git blame where you can look at a source code file and you</p>



<p class="wp-block-paragraph">can see who is responsible for every single line you can bookmark states of</p>



<p class="wp-block-paragraph">your code you can do so much it&#8217;s wonderful but anyway I just want to</p>



<p class="wp-block-paragraph">touch on the basics today I hope I&#8217;ve kind of convinced you that git is a</p>



<p class="wp-block-paragraph">little bit of a good idea I used to just sort of code and then you know do copy</p>



<p class="wp-block-paragraph">paste as my backup copy and it was okay but when I started using git even by</p>



<p class="wp-block-paragraph">started using git even by myself without collaborating um it was tremendously valuable</p>



<p class="wp-block-paragraph">there were many times when i wanted to look back at a previous state of code and git let me do it</p>



<p class="wp-block-paragraph">many times when i wanted to revert some mistake that i made and git let me do it</p>



<p class="wp-block-paragraph">okay so you see my terminal here maybe maybe i should reduce the transparency just a little bit</p>



<p class="wp-block-paragraph">to like maybe like 85 opacity.</p>



<p class="wp-block-paragraph">That&#8217;s a little bit better.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m gonna go into a documents folder.</p>



<p class="wp-block-paragraph">I&#8217;m gonna go into a temporary folder</p>



<p class="wp-block-paragraph">and I&#8217;m gonna remove everything that is, whoops.</p>



<p class="wp-block-paragraph">Okay, that was just something I was working on earlier.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m in a folder.</p>



<p class="wp-block-paragraph">So what is a Git repository?</p>



<p class="wp-block-paragraph">Actually a Git repository is just a folder</p>



<p class="wp-block-paragraph">with some extra information inside of it.</p>



<p class="wp-block-paragraph">Let me see, I don&#8217;t remember if I installed Git on this machine.</p>



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



<p class="wp-block-paragraph">Okay, if you don&#8217;t have Git, you can get it pretty easily with sudo apt install git.</p>



<p class="wp-block-paragraph">Or if you&#8217;re on Windows or some other operating system, you can just go to Git&#8217;s website.</p>



<p class="wp-block-paragraph">It&#8217;s git-sem.com or something like that.</p>



<p class="wp-block-paragraph">You can just find the installer and just get it in there.</p>



<p class="wp-block-paragraph">But, so let&#8217;s say, let&#8217;s say I want to make a repository.</p>



<p class="wp-block-paragraph">directory my repository okay so I&#8217;ve got like an empty folder I&#8217;m going to go inside of it</p>



<p class="wp-block-paragraph">and this is just a folder it&#8217;s not a repo yet I can convert this folder into a repository by</p>



<p class="wp-block-paragraph">just using the command git init oh gosh here&#8217;s like a message oh you got to choose what branch</p>



<p class="wp-block-paragraph">you want I think it&#8217;s actually okay at this point I think they&#8217;ll choose one for me when you see</p>



<p class="wp-block-paragraph">this you can read them and obey them but they&#8217;re not necessarily mission critical while we&#8217;re just</p>



<p class="wp-block-paragraph">learning so notice how when i list the directory it&#8217;s no longer empty there&#8217;s a there&#8217;s a git</p>



<p class="wp-block-paragraph">folder inside of there so if i go inside of the git folder i mean this is really not so much for</p>



<p class="wp-block-paragraph">humans you can kind of do configuration stuff in here but um this is really gets database of</p>



<p class="wp-block-paragraph">everything it knows about your code you know when you change stuff what&#8217;s the configuration</p>



<p class="wp-block-paragraph">So if you actually remove this folder, I&#8217;m going to remove the Git folder.</p>



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



<p class="wp-block-paragraph">Now this folder is just a regular folder.</p>



<p class="wp-block-paragraph">It&#8217;s no longer a Git repository.</p>



<p class="wp-block-paragraph">So you probably don&#8217;t want to do that once you&#8217;ve initialized it,</p>



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



<p class="wp-block-paragraph">If I had a bunch of history inside that folder,</p>



<p class="wp-block-paragraph">then it would have been gone already.</p>



<p class="wp-block-paragraph">But we&#8217;re just learning.</p>



<p class="wp-block-paragraph">This is just an empty repository.</p>



<p class="wp-block-paragraph">So I have a Git repository here.</p>



<p class="wp-block-paragraph">here. First thing I want to do is try to figure out what Git thinks about the repository. So I&#8217;m</p>



<p class="wp-block-paragraph">going to use the command git status. Whenever you&#8217;re not sure of what&#8217;s going on, if you think</p>



<p class="wp-block-paragraph">you need to commit something or push something or pull something or whatever, it&#8217;s probably a good</p>



<p class="wp-block-paragraph">idea to use git status. I use it all the time. Git status and then git will tell you what to do.</p>



<p class="wp-block-paragraph">It&#8217;s basically telling you that you haven&#8217;t done anything at this point. So that&#8217;s okay.</p>



<p class="wp-block-paragraph">a readme file in markdown, my, oops, my project.</p>



<p class="wp-block-paragraph">You don&#8217;t really need to know about markdown to use Git,</p>



<p class="wp-block-paragraph">although the two kind of go hand in hand on GitHub.</p>



<p class="wp-block-paragraph">But I&#8217;m just going to say, well, here&#8217;s my project.</p>



<p class="wp-block-paragraph">This is my super cool project.</p>



<p class="wp-block-paragraph">Okay, so pretend this is a program, a complicated program.</p>



<p class="wp-block-paragraph">So I&#8217;m saving it.</p>



<p class="wp-block-paragraph">We can verify that I actually like put something into that file.</p>



<p class="wp-block-paragraph">So now I&#8217;m going to ask Git, you know,</p>



<p class="wp-block-paragraph">you know, what do you think about the state of this repository?</p>



<p class="wp-block-paragraph">So I&#8217;m going to say git status.</p>



<p class="wp-block-paragraph">Git is telling me now that we&#8217;re on the master branch</p>



<p class="wp-block-paragraph">and there are no commits yet.</p>



<p class="wp-block-paragraph">And I have an untracked file.</p>



<p class="wp-block-paragraph">This means that the readme file is not considered part of the git repository.</p>



<p class="wp-block-paragraph">It&#8217;s just sitting in the directory tree.</p>



<p class="wp-block-paragraph">So I want to add that into my repository so I can start tracking changes.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say git add and then the name of the file.</p>



<p class="wp-block-paragraph">What have I done?</p>



<p class="wp-block-paragraph">Okay, here we go.</p>



<p class="wp-block-paragraph">What have I done? Okay, here we go.</p>



<p class="wp-block-paragraph">That&#8217;s not how you spell add.</p>



<p class="wp-block-paragraph">So now that I&#8217;ve done git add, I can say git status one more time to see what</p>



<p class="wp-block-paragraph">Git thinks about the state of my repository.</p>



<p class="wp-block-paragraph">Git says, well, you definitely use the add in order to put the changes on a stage.</p>



<p class="wp-block-paragraph">Git likes to bunch up changes on a stage before you actually commit things to the</p>



<p class="wp-block-paragraph">database. The reason for that is maybe</p>



<p class="wp-block-paragraph">maybe you spend an hour doing a bunch of work in a bunch of different areas of your</p>



<p class="wp-block-paragraph">different areas of your program, but maybe there&#8217;s only like a few files over here that</p>



<p class="wp-block-paragraph">are part of a logical change.</p>



<p class="wp-block-paragraph">Like this is feature a that I was fixing, but you also changed a bunch of other files</p>



<p class="wp-block-paragraph">that were related to something else like feature B that I was fixing.</p>



<p class="wp-block-paragraph">It doesn&#8217;t really make sense to take all of those changes and make them one commit because</p>



<p class="wp-block-paragraph">you want a nice clean commit log that shows exactly what you were working on.</p>



<p class="wp-block-paragraph">And it makes sense.</p>



<p class="wp-block-paragraph">you just worked on a bunch of different files,</p>



<p class="wp-block-paragraph">you can add all the feature A files to the stage first</p>



<p class="wp-block-paragraph">and then commit that as one change</p>



<p class="wp-block-paragraph">and then go over to the feature B files</p>



<p class="wp-block-paragraph">and add those to the stage</p>



<p class="wp-block-paragraph">and then commit that as a second change.</p>



<p class="wp-block-paragraph">So it&#8217;s kind of a way to get you out of the mess</p>



<p class="wp-block-paragraph">you&#8217;ve put yourself in</p>



<p class="wp-block-paragraph">if you&#8217;ve just been working too long without committing.</p>



<p class="wp-block-paragraph">You should really do a git commit</p>



<p class="wp-block-paragraph">every time you make significant progress.</p>



<p class="wp-block-paragraph">Like, I mean, it depends on where you&#8217;re working</p>



<p class="wp-block-paragraph">where you&#8217;re working or who you&#8217;re talking to. You definitely don&#8217;t want to commit every line</p>



<p class="wp-block-paragraph">that you change. You definitely don&#8217;t want to work for like a month and then do one commit at the end</p>



<p class="wp-block-paragraph">of the month. The sweet spot is somewhere in between. Your boss will probably tell you what</p>



<p class="wp-block-paragraph">to do. For me personally, every time I fix something, I&#8217;ll make a commit. One thing,</p>



<p class="wp-block-paragraph">you know, I made significant progress in my program by adding a new feature. One little</p>



<p class="wp-block-paragraph">feature, I&#8217;m going to commit it. Some people like to do commits at least once a day so that if</p>



<p class="wp-block-paragraph">to do commits at least once a day so that if they&#8217;re working on a huge new feature, then</p>



<p class="wp-block-paragraph">they&#8217;ll do like one commit a day. And then they&#8217;ll sort of like call those several commits</p>



<p class="wp-block-paragraph">part of like a new feature. It&#8217;s up to you. But at this point, we just have the one file</p>



<p class="wp-block-paragraph">that we made up on the stage. It&#8217;s ready to be committed. We used git status. So git</p>



<p class="wp-block-paragraph">is just telling us how to commit it. It&#8217;s like, oh no, it&#8217;s not telling us. It&#8217;s just</p>



<p class="wp-block-paragraph">saying we need to commit it. It&#8217;s not saying how. If you want to unstage it, then here&#8217;s</p>



<p class="wp-block-paragraph">commit command is just git commit now it&#8217;s going to ask me for a commit message this is what you</p>



<p class="wp-block-paragraph">will see in the log so don&#8217;t just put work don&#8217;t put change don&#8217;t put something that doesn&#8217;t</p>



<p class="wp-block-paragraph">describe what you did you should describe exactly what you did so so what i&#8217;m going to do is for</p>



<p class="wp-block-paragraph">the commit message i&#8217;m going to just sort of say what i did you can imagine writing something like</p>



<p class="wp-block-paragraph">i created the readme file it should always definitely describe exactly what you did</p>



<p class="wp-block-paragraph">um but it seems like a lot of people use uh i guess grammar and and and terseness</p>



<p class="wp-block-paragraph">just to make the commit message sound like they told somebody to do something so create the readme</p>



<p class="wp-block-paragraph">file instead of i created the readme file create the readme file so i&#8217;m just going to make that my</p>



<p class="wp-block-paragraph">commit message save the buffer and then uh now that i&#8217;ve committed the changes i have to ask</p>



<p class="wp-block-paragraph">you know git status what did i do you know what&#8217;s the state of the repository it is now saying that</p>



<p class="wp-block-paragraph">that the repo is clean, everything looks pretty good.</p>



<p class="wp-block-paragraph">So that means my changes are recorded in the Git database.</p>



<p class="wp-block-paragraph">I can now actually use a command called Git log to see what changes have been recorded.</p>



<p class="wp-block-paragraph">Notice how there&#8217;s only one change.</p>



<p class="wp-block-paragraph">It&#8217;s just, you know, my name here, when it was changed and then what I did.</p>



<p class="wp-block-paragraph">There&#8217;s a hash here.</p>



<p class="wp-block-paragraph">This little hexadecimal string is called a hash.</p>



<p class="wp-block-paragraph">to show me what happened in any specific commit by saying git show and then I give it a hash</p>



<p class="wp-block-paragraph">and it&#8217;ll tell me exactly what files were created or changed or deleted or whatever</p>



<p class="wp-block-paragraph">and there it is right there this will get more interesting in a second let&#8217;s make a change</p>



<p class="wp-block-paragraph">I&#8217;m going to say edit the readme file and we say this is my super cool project this is my first</p>



<p class="wp-block-paragraph">So I&#8217;m going to say git status to find out what&#8217;s going on.</p>



<p class="wp-block-paragraph">Git says, oh, you made a change there.</p>



<p class="wp-block-paragraph">It&#8217;s not saying that this file is not part of the database.</p>



<p class="wp-block-paragraph">It&#8217;s just saying that we made changes.</p>



<p class="wp-block-paragraph">I want to see the changes that it&#8217;s talking about.</p>



<p class="wp-block-paragraph">I could say git diff.</p>



<p class="wp-block-paragraph">And it&#8217;s telling me that I added this line.</p>



<p class="wp-block-paragraph">My dog is growling at me.</p>



<p class="wp-block-paragraph">about peeing oh my gosh hang on</p>



<p class="wp-block-paragraph">so i&#8217;ll let him back in he&#8217;ll try to lie to me and he&#8217;ll try to get free treats</p>



<p class="wp-block-paragraph">okay so uh we can use the command git diff to see what our changes are we can also say</p>



<p class="wp-block-paragraph">git diff whoops git diff and then name a file and it&#8217;ll tell us what&#8217;s changed in that one file</p>



<p class="wp-block-paragraph">second line so great back to get status it&#8217;s saying we need to stage that change</p>



<p class="wp-block-paragraph">so I&#8217;m just gonna say get add and then the name of the file get status again</p>



<p class="wp-block-paragraph">so that we know what&#8217;s up it&#8217;s saying all right well you just need to commit</p>



<p class="wp-block-paragraph">the changes on your stage if you&#8217;d like to so yeah sure I&#8217;m gonna say get commit</p>



<p class="wp-block-paragraph">and I&#8217;m gonna say you know changed the readme or something okay get status</p>



<p class="wp-block-paragraph">So now if we do git log, there&#8217;s two entries.</p>



<p class="wp-block-paragraph">Imagine that this happens every single time</p>



<p class="wp-block-paragraph">somebody makes a significant change.</p>



<p class="wp-block-paragraph">You know, it&#8217;s just like it goes in the log.</p>



<p class="wp-block-paragraph">You can figure out who changed what.</p>



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



<p class="wp-block-paragraph">Let&#8217;s do cat readme so we can see the readme.</p>



<p class="wp-block-paragraph">Notice how it&#8217;s got the second line at the end.</p>



<p class="wp-block-paragraph">I could also go back in time</p>



<p class="wp-block-paragraph">and see what the state of my project was</p>



<p class="wp-block-paragraph">was after that first commit so i could i&#8217;m going to copy paste that first commit and i&#8217;m going to</p>



<p class="wp-block-paragraph">say git checkout and the commit hash it&#8217;s now telling me something hey by the way now you&#8217;re</p>



<p class="wp-block-paragraph">looking back in time you should not change anything you&#8217;re on a detached head if you&#8217;re</p>



<p class="wp-block-paragraph">ever unsure of where you&#8217;re actually at in git you should do git branch all and it&#8217;ll just sort</p>



<p class="wp-block-paragraph">of show you where you&#8217;re at i was on the master branch now i&#8217;m on a detached head but notice if i</p>



<p class="wp-block-paragraph">But notice if I spill the contents of the README file.</p>



<p class="wp-block-paragraph">Hang on, what did I do wrong?</p>



<p class="wp-block-paragraph">Change the README.</p>



<p class="wp-block-paragraph">Oh, sorry, it&#8217;s in reverse order.</p>



<p class="wp-block-paragraph">I always forget that.</p>



<p class="wp-block-paragraph">I copied the wrong hash.</p>



<p class="wp-block-paragraph">So let me check out the first commit that I made.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say git checkout the first commit hash.</p>



<p class="wp-block-paragraph">Okay, now I&#8217;m going to concatenate the,</p>



<p class="wp-block-paragraph">or I&#8217;m going to spill the contents of the README.</p>



<p class="wp-block-paragraph">Notice how the readme looks like it did when we first made it.</p>



<p class="wp-block-paragraph">So we&#8217;ve gone back in time.</p>



<p class="wp-block-paragraph">Think of how useful this could be if this was a huge, big project with a bunch of files</p>



<p class="wp-block-paragraph">and a lot of lines per file.</p>



<p class="wp-block-paragraph">So once again, we&#8217;ll do git, actually let&#8217;s do git status.</p>



<p class="wp-block-paragraph">Status is reminding me that we&#8217;re on its attached head.</p>



<p class="wp-block-paragraph">and we can also use git branch to see that we&#8217;re still in the detached head you want to get back</p>



<p class="wp-block-paragraph">onto the master branch or whatever branch you&#8217;re working with before you continue working so we&#8217;ll</p>



<p class="wp-block-paragraph">status and you can see that we&#8217;re on the master branch.</p>



<p class="wp-block-paragraph">Then we can say get branch all.</p>



<p class="wp-block-paragraph">And there we go. Maybe we want to bookmark this.</p>



<p class="wp-block-paragraph">Maybe we want to remember, oh, this is a perfect state of our of our code.</p>



<p class="wp-block-paragraph">Maybe this is version one point.</p>



<p class="wp-block-paragraph">We can do get tag version one point.</p>



<p class="wp-block-paragraph">Oh, and now we have a bookmark forever.</p>



<p class="wp-block-paragraph">How can we find the bookmarks?</p>



<p class="wp-block-paragraph">Well, we can say get tag just by itself, and it&#8217;ll give us a list of our bookmarks.</p>



<p class="wp-block-paragraph">When we push this to a remote server, the server will be able to show it like</p>



<p class="wp-block-paragraph">remote server, their server will be able to show it like GitHub or GitLab or whatever.</p>



<p class="wp-block-paragraph">And then later we can do something like, you know, get checkout and then just check out the</p>



<p class="wp-block-paragraph">name of a tag. So it&#8217;s kind of the same thing as checking out a commit hash, but it&#8217;s like</p>



<p class="wp-block-paragraph">a bookmark that&#8217;s a little bit easier to remember. So let&#8217;s look at remotes for a second,</p>



<p class="wp-block-paragraph">because right now we&#8217;re not pushing code anymore. We&#8217;re just remembering what we changed in our</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m inside my repository.</p>



<p class="wp-block-paragraph">And now I&#8217;m going to go up a level on this right pane,</p>



<p class="wp-block-paragraph">and I&#8217;m going to make a new directory.</p>



<p class="wp-block-paragraph">But I&#8217;d like to clone the original repository.</p>



<p class="wp-block-paragraph">Imagine that this repository, it&#8217;s a folder to us,</p>



<p class="wp-block-paragraph">but it could be for all we know, sitting on a remote server</p>



<p class="wp-block-paragraph">and accessed with a special URL.</p>



<p class="wp-block-paragraph">So you can go to like GitHub or somebody&#8217;s server,</p>



<p class="wp-block-paragraph">and you can copy their get URL for their repository.</p>



<p class="wp-block-paragraph">repository. Over here in our local file system, we could clone the original repository.</p>



<p class="wp-block-paragraph">Usually you would have to copy paste like a big get URL, SSH URL or HTTPS URL or whatever.</p>



<p class="wp-block-paragraph">But you can even do this locally so I can tell get I would like to clone this local repository</p>



<p class="wp-block-paragraph">denoted by this folder name. And I would like to call it my clone or something. So I&#8217;m gonna say</p>



<p class="wp-block-paragraph">So I&#8217;m going to say get clone repository my clone.</p>



<p class="wp-block-paragraph">It says cloning and done.</p>



<p class="wp-block-paragraph">Now we have two folders.</p>



<p class="wp-block-paragraph">And if we go inside of the my clone repository,</p>



<p class="wp-block-paragraph">we should have the same state of code that we just cloned.</p>



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



<p class="wp-block-paragraph">Now think about collaboration.</p>



<p class="wp-block-paragraph">We can change our code from the clone.</p>



<p class="wp-block-paragraph">And as long as the clone has permission to push back up to the remote,</p>



<p class="wp-block-paragraph">back up to the remote then it actually would work.</p>



<p class="wp-block-paragraph">So let&#8217;s edit the README file real fast.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go nano README and I&#8217;m going to say this change was made by the clone.</p>



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



<p class="wp-block-paragraph">And actually just to make things interesting, I&#8217;m going to change my git identity only inside</p>



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



<p class="wp-block-paragraph">You can do that in git.</p>



<p class="wp-block-paragraph">config and you say something like user.name, you know, you can put your name here, your email,</p>



<p class="wp-block-paragraph">whatever, for like user.email. There&#8217;s this thing that you usually do where you say get config</p>



<p class="wp-block-paragraph">global. And that means you&#8217;re changing configuration that is account wide. So like</p>



<p class="wp-block-paragraph">your entire account on this machine is going to be changed when you use that global flag.</p>



<p class="wp-block-paragraph">But if I don&#8217;t use the global flag, it&#8217;s just changing my configuration for only this one</p>



<p class="wp-block-paragraph">this one repository so i&#8217;m going to make my name clone dude and make my email</p>



<p class="wp-block-paragraph">clone dude at laptop or whatever at server so now if i say git status over here it&#8217;s telling me hey</p>



<p class="wp-block-paragraph">i have like a change i say git diff and it tells me oh look i you know you changed that last line</p>



<p class="wp-block-paragraph">so i&#8217;m going to add that change to the stage and then i&#8217;m going to commit it and i&#8217;m going to say</p>



<p class="wp-block-paragraph">I added something to the readme.</p>



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



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



<p class="wp-block-paragraph">Notice how git status is saying something a little bit extra this time.</p>



<p class="wp-block-paragraph">Before, we were just in a local file system only.</p>



<p class="wp-block-paragraph">And now we&#8217;re working inside of a clone.</p>



<p class="wp-block-paragraph">So this is like, you know, you clone some code from GitHub</p>



<p class="wp-block-paragraph">or from your friend&#8217;s server or whatever.</p>



<p class="wp-block-paragraph">And when you do a clone,</p>



<p class="wp-block-paragraph">it actually automatically links your local repository</p>



<p class="wp-block-paragraph">repository to the remote repository. By the way, in Git, everything is considered a local copy. So</p>



<p class="wp-block-paragraph">it&#8217;s not like you&#8217;re working with something different than the server has. You actually</p>



<p class="wp-block-paragraph">have the entire Git history and all the code and everything that Git has on the remote,</p>



<p class="wp-block-paragraph">except for maybe some like configurations or something. But when you pull, you&#8217;re just making</p>



<p class="wp-block-paragraph">you&#8217;re making a copy later we can push our changes to the server and that just makes</p>



<p class="wp-block-paragraph">the two repositories talk to each other sort of and reconcile changes and make sure that both sides</p>



<p class="wp-block-paragraph">have the differences i guess so it&#8217;s telling us we need one more step it&#8217;s saying git status and</p>



<p class="wp-block-paragraph">it says you&#8217;re on the master branch your branch is ahead of origin master by one commit what&#8217;s</p>



<p class="wp-block-paragraph">origin master you can find out all of your remote connections and get by saying git remote v so when</p>



<p class="wp-block-paragraph">so when you clone it automatically makes an origin remote it calls it origin and</p>



<p class="wp-block-paragraph">then it has the URL or in this case just the file path of where the remote is so</p>



<p class="wp-block-paragraph">it&#8217;s telling you that our remote where we&#8217;re connected to is the my repository</p>



<p class="wp-block-paragraph">folder that we were at in the left pane so it&#8217;s telling us also if we go back to</p>



<p class="wp-block-paragraph">just status it&#8217;s telling us that we should use git push to publish my local</p>



<p class="wp-block-paragraph">my local commits to the remote because at this point we&#8217;re out of sync if uh if somebody else</p>



<p class="wp-block-paragraph">cloned the remote repository and then made a bunch of changes and then pushed then i would now be</p>



<p class="wp-block-paragraph">totally out of sync with that new person who cloned and also the remote server and it would</p>



<p class="wp-block-paragraph">create something called a merge conflict which is like a little bit more advanced than this video</p>



<p class="wp-block-paragraph">and we&#8217;d have to take steps to resolve it so the smartest thing to do is um well if you&#8217;re</p>



<p class="wp-block-paragraph">Make sure that everybody is designated a certain file or set of files to work on and you all talk to each other.</p>



<p class="wp-block-paragraph">Hey, I just pushed some code.</p>



<p class="wp-block-paragraph">You need to pull.</p>



<p class="wp-block-paragraph">Hey, I&#8217;m about to push.</p>



<p class="wp-block-paragraph">Hold off a second.</p>



<p class="wp-block-paragraph">Hey, I just pushed.</p>



<p class="wp-block-paragraph">If you&#8217;re working on something, you&#8217;ve got to pull my changes before you do a push.</p>



<p class="wp-block-paragraph">Always push after you commit so that everybody has the latest copy on the remote so you don&#8217;t cause conflicts with your teammates or whatever.</p>



<p class="wp-block-paragraph">and always try to do pulls regularly.</p>



<p class="wp-block-paragraph">Anyway, so I need to push my code.</p>



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



<p class="wp-block-paragraph">And it&#8217;s saying, oh gosh, what is it saying?</p>



<p class="wp-block-paragraph">Oh, okay, okay, okay, okay.</p>



<p class="wp-block-paragraph">This is going to be a special setup that I have to do.</p>



<p class="wp-block-paragraph">Let me just very quickly revert what I&#8217;m doing here.</p>



<p class="wp-block-paragraph">I think I have to…</p>



<p class="wp-block-paragraph">Oh, I know what to do. I can just make it a little trick.</p>



<p class="wp-block-paragraph">Usually the thing is they don&#8217;t want you to push onto a branch that the remote has currently checked out into the file tree.</p>



<p class="wp-block-paragraph">But usually remote servers, they don&#8217;t have a branch checked out.</p>



<p class="wp-block-paragraph">So you won&#8217;t even see the file system on the remote.</p>



<p class="wp-block-paragraph">It&#8217;ll actually all look like just this.</p>



<p class="wp-block-paragraph">There&#8217;s a flag called bear that you can use to make that happen.</p>



<p class="wp-block-paragraph">But I don&#8217;t really want to go through all the steps right now.</p>



<p class="wp-block-paragraph">So what I&#8217;m going to do is I&#8217;m just going to make another dummy branch and then just kind of sit on it for a while.</p>



<p class="wp-block-paragraph">dummy branch and then just kind of sit on it for a while.</p>



<p class="wp-block-paragraph">That way I&#8217;m allowed to push to the master branch.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say get branch.</p>



<p class="wp-block-paragraph">This is how you make a new branch.</p>



<p class="wp-block-paragraph">I&#8217;m going to say dummy or something.</p>



<p class="wp-block-paragraph">Whoops, got to spell branch, right?</p>



<p class="wp-block-paragraph">Then get checkout dummy and then get branch all and then get status just to make sure</p>



<p class="wp-block-paragraph">I&#8217;m now sitting on the dummy branch.</p>



<p class="wp-block-paragraph">And then this will cure the problem that we had a moment ago where we&#8217;re not</p>



<p class="wp-block-paragraph">allowed to push to a branch that the remote has checked out.</p>



<p class="wp-block-paragraph">branch that the remote has checked out so i&#8217;m gonna say git oh wait hang on gotta go back in there</p>



<p class="wp-block-paragraph">my clone git push okay so now it works uh so keep in mind if you&#8217;re pushing to you know a remote</p>



<p class="wp-block-paragraph">that has a branch that&#8217;s checked out like it&#8217;s another file system like it&#8217;s a friend&#8217;s computer</p>



<p class="wp-block-paragraph">you&#8217;re gonna have to worry about this sort of thing but if it&#8217;s a server like github or just</p>



<p class="wp-block-paragraph">someone who has set them set the repository up properly uh you won&#8217;t have to worry about it so</p>



<p class="wp-block-paragraph">Forget about that for now.</p>



<p class="wp-block-paragraph">So I pushed to the remote.</p>



<p class="wp-block-paragraph">If I do git log over here, there&#8217;s a mix.</p>



<p class="wp-block-paragraph">It shows, you know, Mike created it and then changed it.</p>



<p class="wp-block-paragraph">And then the clone dude added something too.</p>



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



<p class="wp-block-paragraph">So if I say git log, we should now see the history for only the dummy branch.</p>



<p class="wp-block-paragraph">So that&#8217;s just two things.</p>



<p class="wp-block-paragraph">And if I say git checkout master, and then I check out and then I look at the log for</p>



<p class="wp-block-paragraph">I can see all the changes that the other person made.</p>



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



<p class="wp-block-paragraph">I could also go back into the dummy branch if I wanted to.</p>



<p class="wp-block-paragraph">I actually used to do this a long time ago before I realized you should do bear repos.</p>



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



<p class="wp-block-paragraph">Check out dummy.</p>



<p class="wp-block-paragraph">And then I&#8217;ll say git log just to confirm that the changes aren&#8217;t in there.</p>



<p class="wp-block-paragraph">So now we have two branches that are kind of diverging a little bit.</p>



<p class="wp-block-paragraph">the master branch has one more commit than the dummy branch and if we let this go on for far too</p>



<p class="wp-block-paragraph">long it might be more of a hassle to make the branches merge again but i&#8217;m just going to merge</p>



<p class="wp-block-paragraph">them right now so i&#8217;m going to say git merge verify that you&#8217;re sitting on the correct branch</p>



<p class="wp-block-paragraph">that you want to be the destination branch so i&#8217;m sitting on the destination the dummy branch so i&#8217;m</p>



<p class="wp-block-paragraph">going to say git merge and i&#8217;m going to give it the name of the branch that i want to merge changes</p>



<p class="wp-block-paragraph">It&#8217;s telling me that something happened.</p>



<p class="wp-block-paragraph">So if I do get branch again one more time, I&#8217;m still on the dummy branch.</p>



<p class="wp-block-paragraph">But if I do get log, notice how I have that latest log entry.</p>



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



<p class="wp-block-paragraph">So now I&#8217;m going to go back onto the master branch because I want to do some work here.</p>



<p class="wp-block-paragraph">This is a little clumsy.</p>



<p class="wp-block-paragraph">If we&#8217;re talking about a server client paradigm, just bear with me.</p>



<p class="wp-block-paragraph">Now I&#8217;m going to make another change.</p>



<p class="wp-block-paragraph">Hi, Mr. Clone.</p>



<p class="wp-block-paragraph">clone. Can you read this? So I&#8217;m going to make a change that I want the clone person to see.</p>



<p class="wp-block-paragraph">Git status, git add, the readme. You could also do git commit dash a, but I kind of don&#8217;t like</p>



<p class="wp-block-paragraph">to because I&#8217;d like to remind myself that the stage is a good idea. Git commit new readme</p>



<p class="wp-block-paragraph">okay so I&#8217;m not I don&#8217;t have a remote I am the master so there&#8217;s nowhere to push</p>



<p class="wp-block-paragraph">but now in the clone I can say git status it doesn&#8217;t yet know that the that the</p>



<p class="wp-block-paragraph">remote has changes I could do git pull to actually pull all the changes or I</p>



<p class="wp-block-paragraph">can do git fetch fetch will sort of talk to the remote and pull the changes into</p>



<p class="wp-block-paragraph">this repository&#8217;s local copy of the remote.</p>



<p class="wp-block-paragraph">So if we do git branch all, you&#8217;ll notice that we have a master branch here.</p>



<p class="wp-block-paragraph">So the master branch is my master branch.</p>



<p class="wp-block-paragraph">And all these other branches here are local copies of the remotes branch.</p>



<p class="wp-block-paragraph">So we&#8217;re just making lots and lots of copies.</p>



<p class="wp-block-paragraph">That&#8217;s kind of how git works.</p>



<p class="wp-block-paragraph">But now that we did a fetch, that talked to the remote, it grabbed changes.</p>



<p class="wp-block-paragraph">Now Git understands that we&#8217;re actually behind the remote by one commit.</p>



<p class="wp-block-paragraph">And it&#8217;s telling us, well, you need to use Git pull to pull all the changes.</p>



<p class="wp-block-paragraph">Usually you kind of don&#8217;t need to do Git fetch.</p>



<p class="wp-block-paragraph">If you have a remote, you just say Git pull.</p>



<p class="wp-block-paragraph">You only do Git fetch if you want to kind of see what&#8217;s going on with the remote first before you</p>



<p class="wp-block-paragraph">actually try to pull all the changes into your branch.</p>



<p class="wp-block-paragraph">It&#8217;s a more complicated situation.</p>



<p class="wp-block-paragraph">So if I say Git pull, now inside of my Git log, I have that last change.</p>



<p class="wp-block-paragraph">that last change that the master gave us.</p>



<p class="wp-block-paragraph">So this is like a very, very basic workflow for Git</p>



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



<p class="wp-block-paragraph">committing the changes, checking out the log,</p>



<p class="wp-block-paragraph">checking out what was changed,</p>



<p class="wp-block-paragraph">pushing to a remote and so forth.</p>



<p class="wp-block-paragraph">The only difference, by the way,</p>



<p class="wp-block-paragraph">between using a remote that&#8217;s a file system</p>



<p class="wp-block-paragraph">and using a remote that&#8217;s GitHub</p>



<p class="wp-block-paragraph">is just what URL you put in clone.</p>



<p class="wp-block-paragraph">in clone like if i put if i said git clone i put a file path here originally but if i just</p>



<p class="wp-block-paragraph">put a clone url that github gave me or your friend&#8217;s server gave you right there then it</p>



<p class="wp-block-paragraph">would work basically the same way it&#8217;s pretty sweet um let&#8217;s see so those are the basics of git</p>



<p class="wp-block-paragraph">always make sure that you push to the remote so that the server has your changes and if you&#8217;re</p>



<p class="wp-block-paragraph">using github or another website uh it&#8217;s it&#8217;s usually a really good idea to push and then go</p>



<p class="wp-block-paragraph">to the website to double check that your changes actually made it.</p>



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



<p class="wp-block-paragraph">This video is not going to be for advanced branching strategies,</p>



<p class="wp-block-paragraph">but there are lots of cool resources you can check out.</p>



<p class="wp-block-paragraph">Actually, you know what? I&#8217;m going to pull one up. Let&#8217;s see.</p>



<p class="wp-block-paragraph">I&#8217;m going to edit this out if it ends up being like a really bad search result.</p>



<p class="wp-block-paragraph">Get branching strategy.</p>



<p class="wp-block-paragraph">big project with a big team let&#8217;s see there&#8217;s one that I used to love where the heck is it</p>



<p class="wp-block-paragraph">I think this month no that&#8217;s not the link I remember I should have bookmarked it but there</p>



<p class="wp-block-paragraph">are lots of different strategies for how and why you would want to use um branches let&#8217;s see one</p>



<p class="wp-block-paragraph">of these has a good diagram this is it this is not the same web page but I think this website</p>



<p class="wp-block-paragraph">diagram that I remember.</p>



<p class="wp-block-paragraph">So we&#8217;ve been on the master branch.</p>



<p class="wp-block-paragraph">That&#8217;s like the right side here.</p>



<p class="wp-block-paragraph">You know, this little, these little blue dots.</p>



<p class="wp-block-paragraph">Imagine that every single time you want to create a new feature,</p>



<p class="wp-block-paragraph">you just create a branch and you name it after the feature that you&#8217;re creating.</p>



<p class="wp-block-paragraph">I think I mentioned that before that allows you to sort of keep working on the</p>



<p class="wp-block-paragraph">master branch independently of the feature that you&#8217;re working on.</p>



<p class="wp-block-paragraph">And then later when you&#8217;re sure you want to merge the feature into the master</p>



<p class="wp-block-paragraph">branch, then you just use a get command to make the two branches merge.</p>



<p class="wp-block-paragraph">command to make the two branches merge.</p>



<p class="wp-block-paragraph">Or if the feature turns out to be a bad idea, you can just delete the branch.</p>



<p class="wp-block-paragraph">Usually, at minimum, most people will do something like this.</p>



<p class="wp-block-paragraph">They&#8217;ll have a development branch.</p>



<p class="wp-block-paragraph">So here you can see the yellow dots.</p>



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



<p class="wp-block-paragraph">And what they&#8217;ll do is they&#8217;ll make all of their commits to the development branch.</p>



<p class="wp-block-paragraph">And then only whenever the program is in a really good state, like it&#8217;s sort of presentable,</p>



<p class="wp-block-paragraph">you can actually release it.</p>



<p class="wp-block-paragraph">let your friend run the code or whatever, then you&#8217;ll merge the dev branch into the master branch</p>



<p class="wp-block-paragraph">without deleting the dev branch. So you&#8217;ll merge the dev into master every time the code is in a</p>



<p class="wp-block-paragraph">really good state. And then you&#8217;ll come back on to dev to continue developing. I think most people</p>



<p class="wp-block-paragraph">call it develop. Actually, I call it dev for mine. And that way, the master branch usually only ever</p>



<p class="wp-block-paragraph">is in a state that is good that people could clone from and just compile the program or use the</p>



<p class="wp-block-paragraph">or use the program or whatever.</p>



<p class="wp-block-paragraph">And that is in addition to adding tags</p>



<p class="wp-block-paragraph">whenever you think the master branch is in a state</p>



<p class="wp-block-paragraph">that you think is like a significant release.</p>



<p class="wp-block-paragraph">So like version 1.0 or 1.2 or whatever.</p>



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



<p class="wp-block-paragraph">where you&#8217;re always there most of the time.</p>



<p class="wp-block-paragraph">Branches for feature when you&#8217;re kind of experimenting</p>



<p class="wp-block-paragraph">and trying to figure out</p>



<p class="wp-block-paragraph">if you&#8217;re going to be able to add something.</p>



<p class="wp-block-paragraph">Branches for, there&#8217;s a branch for the master</p>



<p class="wp-block-paragraph">where it&#8217;s like this is the state</p>



<p class="wp-block-paragraph">that the public should see,</p>



<p class="wp-block-paragraph">the state that actually works.</p>



<p class="wp-block-paragraph">actually works. And then, you know, you might do a temporary branch for a hot fix.</p>



<p class="wp-block-paragraph">And sometimes people will do a new branch for a future release. Like if you&#8217;re going to release</p>



<p class="wp-block-paragraph">version 2.0, you might make a new branch and call it version 2.0 and then just work on that and</p>



<p class="wp-block-paragraph">kind of like merge changes from dev in that and just make sure that it&#8217;s all good and it&#8217;s great.</p>



<p class="wp-block-paragraph">And as soon as you think that the feature branch is perfect for your release, sorry, not</p>



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



<p class="wp-block-paragraph">Release branch is great for your release.</p>



<p class="wp-block-paragraph">Then all at once, you&#8217;ll merge that whole thing into master.</p>



<p class="wp-block-paragraph">You don&#8217;t have to do it that way.</p>



<p class="wp-block-paragraph">It doesn&#8217;t have to be that complicated,</p>



<p class="wp-block-paragraph">but sometimes it can be that complicated.</p>



<p class="wp-block-paragraph">For me personally, I usually just do a development branch</p>



<p class="wp-block-paragraph">and a master branch.</p>



<p class="wp-block-paragraph">And then sometimes when I&#8217;m taking a risk,</p>



<p class="wp-block-paragraph">I&#8217;ll make a feature branch for the new thing that I&#8217;m trying.</p>



<p class="wp-block-paragraph">So I just kind of wanted to show you that for branching.</p>



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



<p class="wp-block-paragraph">we talked about pulling and pushing and cloning</p>



<p class="wp-block-paragraph">yeah so just uh i guess one more warning to make sure that you don&#8217;t</p>



<p class="wp-block-paragraph">end up with merge conflicts when you&#8217;re collaborating with other people</p>



<p class="wp-block-paragraph">or even actually this happens to people who work by themselves and they just</p>



<p class="wp-block-paragraph">switch computers a lot make sure that when you first sit down</p>



<p class="wp-block-paragraph">and you&#8217;re about to start coding you always pull</p>



<p class="wp-block-paragraph">team of people communicate with them and tell them you&#8217;re about to pull tell them you&#8217;re about</p>



<p class="wp-block-paragraph">to start working on something tell them tell them what you&#8217;re about to start working on unless you</p>



<p class="wp-block-paragraph">have like a manager who&#8217;s telling you exactly what to work on then it&#8217;s their problem um</p>



<p class="wp-block-paragraph">and then do your get pull and then work and then every time you make significant progress</p>



<p class="wp-block-paragraph">do a commit and then tell everybody i&#8217;m about to push and then push and then make sure that you</p>



<p class="wp-block-paragraph">So if you go on your lunch break, make sure you push before you go on your lunch break.</p>



<p class="wp-block-paragraph">And when you come back from your lunch break, make sure you pull right away.</p>



<p class="wp-block-paragraph">Because if you don&#8217;t pull and push enough, you&#8217;re either going to get merge conflicts</p>



<p class="wp-block-paragraph">on your end or you&#8217;re going to cause other people to get merge conflicts.</p>



<p class="wp-block-paragraph">And sometimes it takes a lot of time to resolve the merge conflicts.</p>



<p class="wp-block-paragraph">So you really don&#8217;t want to deal with that.</p>



<p class="wp-block-paragraph">And then a beginner&#8217;s tip, or I guess like maybe like an easy tip.</p>



<p class="wp-block-paragraph">I do this actually sometimes.</p>



<p class="wp-block-paragraph">up totally forgetting to push and pull and you do a lot of code and you kind of like wreck everything</p>



<p class="wp-block-paragraph">and you don&#8217;t want to deal with a gigantic merge conflict resolution type of situation sometimes</p>



<p class="wp-block-paragraph">it&#8217;s easier to just copy paste your folder somewhere else rename it remember a git repository</p>



<p class="wp-block-paragraph">locally it&#8217;s just a folder so you can copy paste it or rename it or whatever you want to do</p>



<p class="wp-block-paragraph">you just kind of copy paste it somewhere and then perform a fresh clone from the remote</p>



<p class="wp-block-paragraph">then there&#8217;s not going to be a merge conflict because the fresh clone is going to be directly</p>



<p class="wp-block-paragraph">from the remote which is not conflicted on its own then you&#8217;ll have your fresh clone and then</p>



<p class="wp-block-paragraph">you&#8217;ll have your little backup copy of what you just screwed up then you can manually inspect the</p>



<p class="wp-block-paragraph">difference between the fresh clone and then the thing that you just screwed up or you can just</p>



<p class="wp-block-paragraph">start copy pasting some of your changes and then do like a commit and then do push and then it</p>



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



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



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



<p class="wp-block-paragraph">appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



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



<p class="wp-block-paragraph">whatever it is you do on the current social media website that you&#8217;re looking at right now.</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</p>



<p class="wp-block-paragraph">And subscribe you know sometimes</p>



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



<p class="wp-block-paragraph">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">me if you want 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 uh 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 which i think is also</p>



<p class="wp-block-paragraph">named somewhere at the bottom of this video and it&#8217;ll take you to my main website where you can</p>



<p class="wp-block-paragraph">just kind of like see all the videos i published and the services and tutorials and things that i</p>



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



<p class="wp-block-paragraph">up 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">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/git-basics-tutorial-learn-version-control-commits-branches-for-beginners/">Git Basics Tutorial: Learn Version Control, Commits &amp; Branches for Beginners</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/git-basics-tutorial-learn-version-control-commits-branches-for-beginners/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
