<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>programming basics Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/programming-basics/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/programming-basics/</link>
	<description></description>
	<lastBuildDate>Sun, 24 Aug 2025 05:33:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>programming basics Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/programming-basics/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mastering x86-64 YASM Assembly: Functions Made Simple</title>
		<link>https://www.NeuralLantern.com/mastering-x86-64-yasm-assembly-functions-made-simple/</link>
					<comments>https://www.NeuralLantern.com/mastering-x86-64-yasm-assembly-functions-made-simple/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 24 Aug 2025 05:33:36 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[ABI compliance]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[function calls]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming basics]]></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=214</guid>

					<description><![CDATA[<p>Master x86-64 YASM assembly functions! Learn to write, call, and manage arguments &#038; returns in this beginner-friendly tutorial. Avoid crashes &#038; respect the ABI.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-x86-64-yasm-assembly-functions-made-simple/">Mastering x86-64 YASM Assembly: Functions Made Simple</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="Mastering x86-64 YASM Assembly: Functions Made Simple" width="1380" height="776" src="https://www.youtube.com/embed/KUshn1VczCA?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>Get hands-on with x86-64 YASM assembly in this in-depth tutorial on writing functions! Perfect for beginners and seasoned coders, we cover the basics of function creation, calling conventions, argument handling, and return values. Learn to avoid crashes, respect the ABI, and use prologue/epilogue for clean code. From printing messages to returning integers, see practical examples and tips to simplify your assembly programs. Subscribe for more low-level programming tutorials and take your skills to the next level!</p>



<p>Introduction to Functions 00:00:00<br>Makefile Overview 00:00:19<br>Assembly Program Setup 00:02:01<br>Data Section Definitions 00:02:08<br>Text Section and Entry Point 00:03:02<br>Basic Assembly Program Demo 00:03:38<br>Return Codes Explained 00:04:30<br>Function Concepts Introduced 00:06:10<br>Creating a Simple Function 00:07:04<br>Function Call vs Jump 00:08:00<br>Adding Return Statement 00:09:06<br>Moving Print Logic to Function 00:09:48<br>Benefits of Functions 00:10:01<br>Calling Function Multiple Times 00:11:58<br>Creating Print Function with Arguments 00:14:00<br>Handling Function Arguments 00:15:45<br>Respecting the ABI 00:17:16<br>Prologue and Epilogue 00:23:15<br>Stack Operations 00:24:34<br>Calling Print Function 00:25:25<br>Avoiding Recursive Loop 00:34:17<br>Modifying Print Function to Print Line 00:35:21<br>Adding CRLF Function 00:30:13<br>Printing Multiple Messages 00:37:00<br>Returning Integer Values 00:37:48<br>Preserving Registers in Entry Point 00:41:50<br>Final Program Demo 00:43:24<br>Conclusion and Call to Subscribe 00:45:16</p>



<p>Thanks for watching!</p>



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



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



<p>Please help support us!</p>



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



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



<li>Subscribing to our Blog</li>



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



<p>Hey there! Let&#8217;s talk about functions in x8664 Yasm Assembly.</p>



<p>I&#8217;m just going to give you the basics of how to write a function.</p>



<p>So let&#8217;s get started here. First thing I want to show you is just a makefile.</p>



<p>This is not a makefile video, so you don&#8217;t have to worry about it too much.</p>



<p>I just have it up because I need it for this demo.</p>



<p>If you&#8217;re interested in makefiles, that would be a really, really good thing.</p>



<p>thing i&#8217;ll probably make videos in the future about them but for now we&#8217;ll just say you hopefully have</p>



<p>a script or method already set up that allows you to compile or assemble assembly programs</p>



<p>so i&#8217;m just going to skim through it real fast if you&#8217;re interested you can kind of study it</p>



<p>but basically i have like a little define here that allows me to print out a message that looks</p>



<p>nice and then i define the repo path as the current path and i take the absolute path of that</p>



<p>This is where the real work happens.</p>



<p>I have Yasm flags because I&#8217;m using the Yasm assembler.</p>



<p>I&#8217;m going to be assembling to x86 64.</p>



<p>I like to out.</p>



<p>I like to convert all of my warnings to errors to make sure that I don&#8217;t write sloppy code</p>



<p>export debug symbols and export debug symbols for the linking stage to the name of my executable</p>



<p>is going to be called a main.</p>



<p>have set up and well I can just do make run or make debug as a little shortcut</p>



<p>to run it in GDB if you don&#8217;t know GDB don&#8217;t worry that&#8217;s going to happen in a</p>



<p>future video and make clean which just cleans the build area I like a clean</p>



<p>build area and then this is the main command here we&#8217;re going to be using LD</p>



<p>to do our linking because this is going to be a pure assembly program instead of</p>



<p>a hybrid program which would require GCC or something else and then here&#8217;s my</p>



<p>And then here&#8217;s my program main ASM is going to get compiled down to main.o and</p>



<p>That&#8217;s it for the make pile</p>



<p>Okay, so for the main assembly program I have some stuff written up already here, but I think I&#8217;m going to modify it for this video</p>



<p>For starters, we have our data section which hopefully you understand already</p>



<p>I&#8217;m just going to define a bunch of stuff in the data section like I&#8217;m going to define</p>



<p>The system call code to write a string so I can print a message pretty easily</p>



<p>so I can print a message pretty easily the system call code to actually exit the program</p>



<p>remember when you&#8217;re writing a pure assembly program that has start as an entry point</p>



<p>you need to be you know you&#8217;re responsible for exiting the program so the system call code is</p>



<p>60 there and then I&#8217;m going to say exiting for success is a zero that&#8217;s kind of a standard thing</p>



<p>and then I&#8217;m going to make two file descriptors for the standard input it&#8217;s going to be zero and</p>



<p>the standard output it&#8217;s going to be one actually I don&#8217;t think we need that for this video we just</p>



<p>We just need standard output, but not standard input.</p>



<p>And then I&#8217;m just going to make two strings.</p>



<p>That&#8217;s not my name, but I like those names.</p>



<p>And then the BSS section.</p>



<p>Actually, I&#8217;m going to get rid of that</p>



<p>because we don&#8217;t really need that for this video.</p>



<p>And then I have a text section, which is where all the code is.</p>



<p>We&#8217;re going to begin our entry point.</p>



<p>If you are writing a pure assembly program</p>



<p>and this is your entry point module,</p>



<p>make a function called underscore start.</p>



<p>It&#8217;s not actually technically going to be a function because it won&#8217;t return anywhere.</p>



<p>It&#8217;ll actually just call the system exit service.</p>



<p>And then I mark start as global so that the operating system can go into it,</p>



<p>can call it from the outside.</p>



<p>And then all I&#8217;m doing right now is I&#8217;m printing a hello.</p>



<p>So far, this is not really a demo of functions.</p>



<p>This is just like a very basic pure assembly program.</p>



<p>All it&#8217;s going to do is it&#8217;s going to enter.</p>



<p>going to print the hello message and then down here it&#8217;s going to do a system call to exit the</p>



<p>program with zero for success so let&#8217;s just see what that looks like real fast I&#8217;m going to do</p>



<p>make run and then make run you can see the first line it just kind of prints and then the second</p>



<p>line that&#8217;s make sort of echoing the command that I&#8217;m issuing it&#8217;s just going to assemble the main</p>



<p>dot asm into a main dot o and then it&#8217;s letting me know that if there are any warnings it will</p>



<p>It will refuse to compile.</p>



<p>And then I use the LD linker to link the main executable.</p>



<p>And then I actually run the executable.</p>



<p>So only below this line that I have highlighted right now</p>



<p>is gonna be the actual program.</p>



<p>So you can see all it really did was just,</p>



<p>you know, print the message and then exit.</p>



<p>Just, you know, a little note here.</p>



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



<p>but the return code zero is kind of a standard</p>



<p>to indicate success for programs,</p>



<p>which is very useful if you want programs to automate other programs.</p>



<p>If I change the system, let&#8217;s see what is it, exit success.</p>



<p>If I just change that variable to a 3 so that I will exit with a return code of 3 instead of 0,</p>



<p>then the operating system, or actually bash, since we&#8217;re in a terminal emulator,</p>



<p>should consider the program to have exited in error.</p>



<p>So you can see now it&#8217;s like, hey, hey, hey, the makefile system,</p>



<p>oh not bash, the makefile system is like that program exited with code 3,</p>



<p>three something went wrong and normally if you don&#8217;t add any extra stuff into your make file it&#8217;ll</p>



<p>just refuse to continue at that point well so i&#8217;m just going to change it back to a zero and make</p>



<p>sure that it still works and then we&#8217;ll get on to actually writing functions so i&#8217;m going to go clear</p>



<p>and make run so it&#8217;s a little bit faster for me to run this repeatedly you can see actually the</p>



<p>first time that i did that um the make file recompiled notice how it recompiled um and</p>



<p>and relinked because I changed that source code.</p>



<p>This is not a make file video, but I just want you to be aware.</p>



<p>One of the great reasons to use make or a build system in general</p>



<p>is because it makes it really easy to compile your code faster.</p>



<p>Notice how if I didn&#8217;t actually change, let&#8217;s see.</p>



<p>So I recompiled it because I just changed it again,</p>



<p>but now I haven&#8217;t changed it since I&#8217;m going to recompile or rerun.</p>



<p>Make just kind of like skips reassembling that file because it hasn&#8217;t changed.</p>



<p>it can make your compilations and assemblies much, much faster.</p>



<p>So anyway, functions. Functions in assembly are kind of simple and you&#8217;ll realize that</p>



<p>some of the stuff that we take for granted in higher level languages is being done for us</p>



<p>automatically by the compiler. But in assembly, we have labels. So for example, this start entry</p>



<p>some valid symbols like characters underscore numbers I don&#8217;t think you can start a label with</p>



<p>a number correct me if I&#8217;m wrong but I don&#8217;t think you can so we have like a label which is just like</p>



<p>this collection of characters and then we have a colon after it and so you can jump into a label</p>



<p>which I&#8217;ll talk about in a different video but you can jump into a label you can call a label as a</p>



<p>function and so a label isn&#8217;t actually a function by itself you have to treat it in a certain way</p>



<p>the abstract so notice how there&#8217;s no return statement at the bottom here let me write a</p>



<p>function real fast and maybe i will have it so that i have a function that just says hello for</p>



<p>me so i&#8217;ll make a label down here function that says hello and i&#8217;ll give it a label and i&#8217;ll say</p>



<p>maybe like say hello and i&#8217;ll do a little label there first thing that you should do when you are</p>



<p>trying to create a function is just put a return statement at the very end of it.</p>



<p>That way it will return to the caller because if you don&#8217;t then it&#8217;s just going to continue</p>



<p>to execute downward until it reaches no code and then the program will probably crash. In fact</p>



<p>maybe I should do that. I&#8217;m going to do say hello as a label with no return so it&#8217;s not really a</p>



<p>function now. It&#8217;s more of just like a label that you can jump to but there&#8217;s no code under it so</p>



<p>I&#8217;m not even sure this will assemble, but it&#8217;ll definitely crash if we can call into this.</p>



<p>So let me do, at the very start of our program, I&#8217;m going to type call say hello.</p>



<p>Or actually, you know what, maybe first I&#8217;ll jump to hello.</p>



<p>Jumping is going to be for a different video, but jumping just means go to that place.</p>



<p>It&#8217;s a go-to statement, essentially.</p>



<p>You&#8217;re not supposed to be able to return from a jump.</p>



<p>but it doesn&#8217;t really follow the same design pattern logic as a function.</p>



<p>So I&#8217;m going to immediately jump to the say hello logic and see what happens.</p>



<p>I think that it&#8217;ll crash.</p>



<p>Here we go.</p>



<p>SegFault, core dumped, oh no.</p>



<p>So, hey, it crashed.</p>



<p>So instead of jumping there, let&#8217;s do a call.</p>



<p>Now we&#8217;re treating it a little bit more like a function.</p>



<p>We still don&#8217;t have the return statement down here.</p>



<p>So it should still crash, I think.</p>



<p>Let&#8217;s try that again.</p>



<p>Yep, it crashed again.</p>



<p>Because you&#8217;re supposed to exit from the operator, or you&#8217;re supposed to exit from the program</p>



<p>properly to the operating system.</p>



<p>So now I&#8217;m going to do a return statement here.</p>



<p>There&#8217;s never an argument for the return statement.</p>



<p>You just simply return to the caller.</p>



<p>This uses the stack.</p>



<p>If you don&#8217;t know what the stack is, I&#8217;ll probably make another video about that in</p>



<p>the future.</p>



<p>But the stack, you know, it helps your program understand where it just called to and how</p>



<p>to get back from it.</p>



<p>to get back from it it also stores local variables and things but so if i have a call it should jump</p>



<p>down to the hello function and then return meaning it&#8217;ll just return to the caller immediately without</p>



<p>actually doing anything but the program should be able to continue without crashing notice how</p>



<p>there&#8217;s no crash here all it does is print out the welcome message and then no problem all right</p>



<p>printing stuff and I&#8217;m just going to cut it and stick it inside of the say hello</p>



<p>function that way when I call that function it should still print hello but</p>



<p>now notice how we have less code to deal with in this primary function you know</p>



<p>one of the first things that that programmers learn is that you know we&#8217;re</p>



<p>human beings we&#8217;re not computers it&#8217;s really hard for us to write complex</p>



<p>logic in a program without tools to help us and design patterns to help us to</p>



<p>help us stay on track to help us you know make sure that we&#8217;re not going to</p>



<p>we&#8217;re not going to be forgetting anything or screwing something up or you know to debug so</p>



<p>you know one awesome design pattern is to write functions because you you you realize in your</p>



<p>program you might be calling the same logic several times so you&#8217;re sort of like repeating a bunch of</p>



<p>code that already is bad it&#8217;s really hard to debug repeating code and it&#8217;s really hard to make updates</p>



<p>to it and it becomes unwieldy right so as soon as you realize you&#8217;re repeating the same logic</p>



<p>places you should think about taking it and putting that logic into a function</p>



<p>and then just simply calling that function many times it makes your coding</p>



<p>a lot easier and then once you put all the work into getting a function to</p>



<p>work you&#8217;re just you can just be done with it as soon as you&#8217;re sure that</p>



<p>this function actually works you can just put it to the side and just forget</p>



<p>about it you can stick it at the bottom of the source or just ignore it put it</p>



<p>into a different module whatever you want to do and then the other parts of</p>



<p>of the program that you&#8217;re still working on they become a lot more simple and so you know because</p>



<p>we&#8217;re human beings we need all the advantages we can get to write powerful code so i am now just</p>



<p>i&#8217;m not i don&#8217;t have to think anymore about all the system call things that&#8217;s happening</p>



<p>to print the hello message all i have to do is think about calling the say hello function</p>



<p>and of course this is simple but you can imagine using this for more complicated</p>



<p>concepts in the future so let&#8217;s see if this still works if i didn&#8217;t screw this up</p>



<p>It printed the same exact message.</p>



<p>And if I keep running it, you know, the make file doesn&#8217;t compile as much, but it still</p>



<p>runs the program.</p>



<p>If you don&#8217;t believe me that this is inside of a function now, let&#8217;s actually just call</p>



<p>that same function many times.</p>



<p>We&#8217;ll call say hello.</p>



<p>Let&#8217;s say we call it five times.</p>



<p>This should work.</p>



<p>I&#8217;m going to run the program again.</p>



<p>Notice how it printed that message five times.</p>



<p>Just to reemphasize my earlier point, wouldn&#8217;t it be a huge pain in the butt if you wrote</p>



<p>all the code for the system call and the message printing five duplicate times?</p>



<p>Wouldn&#8217;t that be hard to update? What if you had a hundred of those in there?</p>



<p>What if you had something that was really complicated and you called on it like</p>



<p>50 times,</p>



<p>wouldn&#8217;t that be so much better than maintaining 50 different versions of the</p>



<p>exact same idea of code and, and, you know,</p>



<p>making sure that if you needed to upgrade it or change it in some way,</p>



<p>you actually got it right for all 50 copies. So this is way better.</p>



<p>All right. So that&#8217;s the basic idea for a function.</p>



<p>for a function let&#8217;s see what else can i do um let&#8217;s let&#8217;s make a function that just prints</p>



<p>anything because that would be kind of a good little practice in the uh in the arguments that</p>



<p>we can use remember in c plus plus and other languages you have function signatures that</p>



<p>you can use so for example say hello we know for sure that say hello is not actually doing anything</p>



<p>it&#8217;s not receiving any arguments and it&#8217;s also not returning anything so if we know it&#8217;s not</p>



<p>returning anything. So if we know it&#8217;s not returning anything, we can say that it&#8217;s a</p>



<p>void function if we&#8217;re talking C++. We&#8217;ll do the name here. We&#8217;ll say say hello. And in the</p>



<p>argument list, we know that it doesn&#8217;t take any arguments. So it&#8217;s just say hello with nothing,</p>



<p>right? Okay. So let&#8217;s make another function that just prints something. And this function will</p>



<p>kind of be a little redundant because if you just sort of look at the system call here,</p>



<p>we have to load up the system call with the standard output and the system write code.</p>



<p>So that&#8217;s going to be repeated.</p>



<p>So we could move that into the print something function, but then, you know, giving an argument</p>



<p>of like, here&#8217;s the string I want to print.</p>



<p>And here&#8217;s the length of the string that I want to print that, that is something that</p>



<p>we can pass as arguments every time.</p>



<p>So we&#8217;ll be saving like a little bit of work, but it&#8217;s still, I think, I hope illustrates</p>



<p>the idea.</p>



<p>Maybe we will, oh, print something.</p>



<p>Okay.</p>



<p>So print something.</p>



<p>Maybe we&#8217;ll do the signature here.</p>



<p>Print something will not return any value.</p>



<p>So we&#8217;ll just give it a void return type.</p>



<p>And I&#8217;ll do a description up here.</p>



<p>Print a message given by a character pointer.</p>



<p>A pointer to a string.</p>



<p>character is also a pointer to a C string, not a regular string class, but a C string.</p>



<p>So I don&#8217;t know how to describe it. I think I&#8217;ll just say a pointer to a C string</p>



<p>and length and integer length maybe. So that means the print something function should take</p>



<p>two arguments. We want to be able to call that function and tell it, here&#8217;s a pointer to the</p>



<p>string I want you to print. And here&#8217;s how long the string is. So still talking about C++, I&#8217;m</p>



<p>character pointer p and maybe i&#8217;ll put like string just to remind myself when i look at this later</p>



<p>it&#8217;s a pointer to the string or like p char for the pointer to like the first character in the</p>



<p>string something like that and then length so the length is going to be a long because we&#8217;re using</p>



<p>64-bit integers in this video long and i&#8217;ll just say maybe size or length or something so now we</p>



<p>I want to use the same symbol that I&#8217;m describing in this little prototype here.</p>



<p>So I&#8217;m just going to copy paste it and use a colon.</p>



<p>And then because it&#8217;s a function, I immediately want to put a return statement at the very end.</p>



<p>Okay.</p>



<p>So then what I need to do is grab the incoming arguments.</p>



<p>Okay.</p>



<p>So, well, the first thing that every system call that prints a string should do,</p>



<p>at least if it&#8217;s going to print it to standard output,</p>



<p>to print it to standard output is it should start setting up the system call code registers or the</p>



<p>system call registers to say all right the system call wants rax to describe what the system call</p>



<p>is going to do we already have system write set up so that just means we&#8217;re telling syscall that</p>



<p>we want to print something where do we want to print it we want to print to the standard output</p>



<p>which if you look at earlier in the video that was just a file descriptor of one so that&#8217;s fine</p>



<p>up the system call and then the next two things can be kind of variable uh you know we can we</p>



<p>can grab that from incoming arguments so rsi wants a pointer to the string we&#8217;re not going to load</p>



<p>hello string but we&#8217;re going to load whatever character pointer we were given in the incoming</p>



<p>RDI is the first incoming integer argument.</p>



<p>We&#8217;re not going to talk about mixed arguments with floats.</p>



<p>If we just assume that we&#8217;re only going to use integer arguments or pointer arguments,</p>



<p>then the first one is going to be RDI.</p>



<p>So that means by the time print something gets called,</p>



<p>by the time we come into this code right here,</p>



<p>RDI should be loaded with the pointer to the character to the C string that we want to print.</p>



<p>Again, this follows something called the ABI, which you should absolutely respect,</p>



<p>which you should absolutely respect even if you&#8217;re the only one writing any of the code that you</p>



<p>interact with your code will be bad and considered not good if you don&#8217;t respect the abi on this type</p>



<p>of architecture so we definitely still need to load rsi with the string pointer but art whoops</p>



<p>but rdi is what&#8217;s going to have the string pointer so we actually already just ruined rdi when we</p>



<p>probably either load it up backwards or i think probably a better way to explain functions is</p>



<p>let&#8217;s just use another register so i&#8217;m going to use another register to sort of store our incoming</p>



<p>arguments i personally like to do this i admit that this will cost you cpu cycles to sort of</p>



<p>like move things around in registers but it&#8217;s still way faster than sticking something into</p>



<p>a global variable because then you&#8217;ll be hitting memory so first i&#8217;m going to say let&#8217;s move</p>



<p>to r12 and I want to store the incoming argument so I&#8217;m just going to write here save the</p>



<p>the p care you know c string character pointer or something like that so we&#8217;re going to save it</p>



<p>and then the next thing we need to do is save the size because as soon as we load up rsi we&#8217;re also</p>



<p>going to be destroying the second integer argument which should come to us in rsi</p>



<p>Okay, so I&#8217;m going to save that too, I guess, with R13.</p>



<p>So I&#8217;m going to move something into R13, RSI, and then save the size of the C string.</p>



<p>Okay, so we saved both of those.</p>



<p>Now, when we load RSI, we can just sort of say, RDI is saved.</p>



<p>And then when we load RSI…</p>



<p>Oh, that&#8217;ll be when we hit RDX.</p>



<p>Oh, that&#8217;ll be when we hit RDX. Okay, I got confused. So we stored R12 was the character</p>



<p>pointer. And then for the length of the string, we stored that as R13. Also for me personally,</p>



<p>I feel like it&#8217;s a pretty good idea to kind of make a comment at the very top, because this is</p>



<p>assembly. It&#8217;s really, really hard, right? Make a little comment at the top, just kind of reminding</p>



<p>yourselves what you use all of the registers for. I know sometimes you&#8217;ll use the same register for</p>



<p>sometimes you&#8217;ll use the same register for multiple purposes.</p>



<p>You could either write that down</p>



<p>or you could consider breaking up your function</p>



<p>into multiple functions.</p>



<p>That&#8217;s totally valid</p>



<p>and it probably will make your life a lot easier.</p>



<p>Anyway, so I&#8217;m gonna say register usage</p>



<p>and then I&#8217;m gonna say R12 pointer to string, C string.</p>



<p>And then I&#8217;m gonna say R13 is gonna be</p>



<p>size of the string. And that seems simple but remember assembly especially when you&#8217;re new</p>



<p>it&#8217;s really confusing and for me when I was first learning and even sometimes now I&#8217;ll be staring</p>



<p>at a big blob of assembly code and I&#8217;ll just be like what register was I using you know or I&#8217;ll</p>



<p>look at a register and I&#8217;ll be like what was that thing even for? So just make yourself a little</p>



<p>comment up here to help you understand and then you&#8217;ll thank yourself later when you get a little</p>



<p>a little bit too overloaded or maybe even if you come back to your code a month from</p>



<p>now probably having totally forgotten what you even wrote then you&#8217;ll just have a nice</p>



<p>little reminder here.</p>



<p>It&#8217;s good to document and this is one of the ways that I recommend.</p>



<p>Okay, so we&#8217;re saying that R12 and R13 are going to be used.</p>



<p>We&#8217;re loading them up here from the incoming arguments.</p>



<p>Now RDI and RSI are free to be destroyed if we want and of course we have to destroy them</p>



<p>because RDI and RSI were incoming arguments when this function first came in but now that</p>



<p>first came in but now that we&#8217;re going to be doing a system call we have to use</p>



<p>them for incoming arguments to the sys call so they&#8217;re just they&#8217;re just meant</p>



<p>to be constantly destroyed so we&#8217;re gonna do call code there and then the</p>



<p>standard output is gonna be the first argument and then the string that we did</p>



<p>which is an r12 is going to be the second argument and then rdx is going to</p>



<p>be the next argument which is r13 which came into us through the second argument</p>



<p>wait wait wait the string to write came into us through the first argument the</p>



<p>came into us through the second argument but if you just kind of look at what we&#8217;re doing to the</p>



<p>system call it&#8217;s actually the second and the third so I mean just forget about it okay so we set all</p>



<p>that up let me make sure I&#8217;m not forgetting something by scrolling up real fast yeah so now</p>



<p>we can do a system call one other thing that&#8217;s very very important about functions is you have</p>



<p>to respect the ABI and that doesn&#8217;t just include using the right registers for incoming arguments</p>



<p>out a call but you also have to keep in mind which registers are denoted as callee saved</p>



<p>if something is callee saved then that means you know if i&#8217;m inside of print something</p>



<p>i&#8217;m being called that means i&#8217;m the callee so that means if i&#8217;m going to use r12 and r13 which</p>



<p>are designated as callee saved maybe i&#8217;ll pull up that my favorite assembly book after this</p>



<p>but if i&#8217;m using registers which are designated as callee saved then i have to preserve those</p>



<p>then I have to preserve those registers, meaning those registers,</p>



<p>they should have their same values from when they first came in on the call</p>



<p>when I exit the function. So when I exit the function, those registers,</p>



<p>register values should appear to be untouched to the caller.</p>



<p>Remember these registers are not local variables.</p>



<p>They&#8217;re global to the entire system. There&#8217;s only one R12 on the whole CPU.</p>



<p>So every program that runs every function that gets called,</p>



<p>see the same exact R12 register. So if we&#8217;re not careful about preserving when we have to,</p>



<p>we could end up crashing other programs or our own program. So anyway, let&#8217;s do something that</p>



<p>I like to call the prologue and the epilogue. That&#8217;s another nod to my favorite assembly book,</p>



<p>which I&#8217;ll probably show at the end of this video. So prologue is just, hey, let&#8217;s preserve</p>



<p>the stuff that we need to preserve. We will preserve the R12 with a push and we will preserve</p>



<p>and we will preserve the R13 with another push.</p>



<p>We then have to restore them.</p>



<p>So right now when we do this push,</p>



<p>that just means that whatever value R12 and R13 had</p>



<p>is going to go to the stack.</p>



<p>So we&#8217;re going to hit memory.</p>



<p>That&#8217;s not great, but like we have to in this case.</p>



<p>We&#8217;re going to push it onto memory</p>



<p>in order to preserve the value.</p>



<p>And now we&#8217;re free to destroy the value if we want.</p>



<p>And then right before we return,</p>



<p>we&#8217;ll just pop those values.</p>



<p>So that means we&#8217;re going to go to memory.</p>



<p>We&#8217;re going to go to the stack.</p>



<p>to go to the stack we&#8217;re going to grab the values that we just pushed and put them back onto the</p>



<p>registers oops forgot to do 13 and 12 and I&#8217;ll call this the epilogue just meaning like we&#8217;re</p>



<p>done we&#8217;re cleaning up and of course look very carefully at the fact that the push and the pop</p>



<p>sequence are in reverse order notice how we push 12 first and we push our 13 second then at the end</p>



<p>Then at the end, we pop R13 first, so it&#8217;s backwards.</p>



<p>It&#8217;s like a little shell, you know, the R13s are on the inside</p>



<p>and the R12s are on the outside.</p>



<p>That logic would persist if we pushed,</p>



<p>or if we had to preserve more Kali saved registers,</p>



<p>if we were using more stuff.</p>



<p>The reason we do that is because the stack as a data structure</p>



<p>will return data to you backwards in the reverse order</p>



<p>that you returned it or that you sent it into the stack.</p>



<p>it into the stack so if i send a 12 and a 13 let&#8217;s just say the number 12 and the number 13</p>



<p>into the stack then if i start popping stuff out of the stack it&#8217;s first going to give me the most</p>



<p>recent item which is going to be the 13 so it&#8217;s going to give me backwards data and then it&#8217;ll</p>



<p>give me the art the 12 seconds so um the type of data structure a stack is is first in last out</p>



<p>last out no that&#8217;s a that&#8217;s a queue anyway so we&#8217;re preserving the registers we&#8217;re doing the</p>



<p>system call we&#8217;re probably okay to call this function now so let me see if i can do this</p>



<p>i&#8217;m going to comment out all of these things that the the say hello function does and i&#8217;m just going</p>



<p>to call on print something in order to call that function but i have to load up my arguments i have</p>



<p>pass arguments remember in the print something function it&#8217;s got a signature</p>



<p>it wants a character pointer and a size we can&#8217;t just call it without giving it</p>



<p>those things or it&#8217;s going to look at the registers anyway and just grab</p>



<p>whatever junk data happened to be in there so that would be bad so first we</p>



<p>have to load up the registers load up argument registers and call print</p>



<p>load up the argument registers and call print something.</p>



<p>So the first thing is going to be RDI, so we have to move something into RDI</p>



<p>and then the second register for the second integer argument is going to be RSI.</p>



<p>As far as I recall, if I&#8217;m wrong this is going to go horribly wrong.</p>



<p>I&#8217;ll double check the book after this.</p>



<p>And what do we want to do?</p>



<p>We want to basically, inside of say hello,</p>



<p>we could assume for now that say hello hardcodes the pointer and the length.</p>



<p>So we&#8217;ll just say it&#8217;s going to grab the string from global and it&#8217;s going to grab the string</p>



<p>length from the global variables.</p>



<p>So it&#8217;s going to load up those two arguments and then call on print something.</p>



<p>This still ends up being three lines.</p>



<p>That&#8217;s why I was saying before, we&#8217;re not going to save too much, but we did save, you</p>



<p>know, these two lines right here, you know, and the system call line.</p>



<p>So it&#8217;s like slightly faster to do.</p>



<p>You just load up two pointers and then you make a call.</p>



<p>in this video so I can&#8217;t really make the function better but in the future when</p>



<p>you learn how to loop and and learn about null terminated strings you could</p>



<p>basically just pass a pointer to just the string only and then call on a</p>



<p>function if the function was smart enough to scan through the string and</p>



<p>figure out how long it was based on where the null terminator was but that&#8217;s</p>



<p>gonna happen in another video anyway so if we call print something it should</p>



<p>Notice also that we&#8217;re having a function call another function, which is pretty cool.</p>



<p>So we have our entry point, it&#8217;s going to call on say hello, and then once we&#8217;re inside</p>



<p>of say hello, we&#8217;re just going to load up some arguments and then call on the print</p>



<p>something function.</p>



<p>The print something function then does most of the work for the printing, and I think</p>



<p>we&#8217;re ready to go.</p>



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



<p>All right, so we&#8217;re going to clear and then just run the program.</p>



<p>Oh, that was so fast.</p>



<p>That was so fast I don&#8217;t even feel like I&#8217;ve proved anything.</p>



<p>Let&#8217;s comment out the system call so that all we really do is just load up some registers</p>



<p>and then don&#8217;t do anything.</p>



<p>And then you should see here that the print something function no longer actually does</p>



<p>anything because it was too fast.</p>



<p>Now if I uncomment the system call, you know that the print something function is actually</p>



<p>doing something and it&#8217;s printing the message five times.</p>



<p>We can also make some more messages if we wanted to,</p>



<p>just as a way to make this video slightly more interesting.</p>



<p>I&#8217;ll say msg1 is going to be a string of bytes,</p>



<p>and I&#8217;m going to say this is message number one.</p>



<p>Boring, sorry.</p>



<p>And we&#8217;ll do a crlf there.</p>



<p>Actually you know what, let&#8217;s make a function that does a crlf.</p>



<p>Okay, let me just finish message one length,</p>



<p>and we&#8217;ll do it equals that special string that you can do in yasm am i doing this right yeah okay</p>



<p>so this is message number one so now we&#8217;ll call again with message we&#8217;ll call say hello just once</p>



<p>and then we&#8217;ll call on print something loading it up first move something with rdi and then move</p>



<p>message one is that what I had message underscore one and then RSI is going to</p>



<p>get message underscore one length so basically we&#8217;re just you know print the</p>



<p>first message it&#8217;s always a good idea to put comments on each line when you&#8217;re</p>



<p>learning so that you don&#8217;t forget what&#8217;s happening in addition to like a comment</p>



<p>for the whole block but I&#8217;m not going to do that here let&#8217;s just make sure that</p>



<p>make sure that this actually works so it should print two different messages now</p>



<p>one okay nice let&#8217;s enhance this a little bit more later i think i&#8217;m going to have us print like a i</p>



<p>don&#8217;t know a character or maybe we&#8217;ll do a return value from something so we can just show you how</p>



<p>to do the return values but i&#8217;m just going to enhance this a little bit more we&#8217;re going to say</p>



<p>let&#8217;s make another function we&#8217;ll call it crlf the crlf function i don&#8217;t want it to do all the</p>



<p>system call stuff because print something already does that for us i&#8217;m instead just going to make</p>



<p>message so now that means i&#8217;m going to go crlf and that&#8217;s just going to be a 13 and a 10. remember</p>



<p>you can define a c string with quotes but you can also separate quoted strings by commas and also</p>



<p>integers just to sort of tack it on so you know this variable right here it&#8217;s going to be a</p>



<p>sequence of characters representing the string that you see and then at the very end of the</p>



<p>string it&#8217;s going to have a crlf carriage return line feed so that the cursor goes to the next line</p>



<p>goes to the next line so I&#8217;m actually gonna take that off of message one</p>



<p>because it&#8217;s gonna be here just on CRLF and then I&#8217;ll say CRLF length is gonna</p>



<p>be two I could also do that special thing probably a little smarter CRLF</p>



<p>yeah I mean it&#8217;s it&#8217;s better to avoid hard coding things if you can avoid</p>



<p>hard coding the number two or any number just do it I guess I have to hard code</p>



<p>So, so CRLF and then length.</p>



<p>And so that means in my CRLF function, let&#8217;s see, let&#8217;s do CRLF, CRLF immediately return</p>



<p>because it&#8217;s going to be a function.</p>



<p>I&#8217;ll just say void CRLF with no arguments and prints a carriage return new line, also</p>



<p>known as CRLF.</p>



<p>and so that just kind of describes it and I don&#8217;t need to preserve RSI and RDI</p>



<p>because those are not callie saved registers so respecting the ABI kind of</p>



<p>helps you in this case I&#8217;m just gonna copy paste here and maybe I&#8217;ll copy</p>



<p>paste that comment real fast too so I don&#8217;t have to like type that whole thing</p>



<p>out and instead of doing hello string we&#8217;ll just say CRLF and then for here</p>



<p>And now when I call CRLF, it should just make the cursor go down a little bit.</p>



<p>So let&#8217;s test that out.</p>



<p>I took the CRLF off of message one.</p>



<p>So if we actually run this right now on modified, it should have the cursor.</p>



<p>Now, what did I just do wrong?</p>



<p>On number 28 and 29, instructions expected after label.</p>



<p>I guess I forgot to complete something.</p>



<p>Oh, I forgot to put, it&#8217;s a byte sequence right there.</p>



<p>there and I forgot to put that this is basically a defined sequence you know</p>



<p>that EQU okay my bad okay so now it prints notice how the message line it no</p>



<p>longer does a new line and no longer jumps to the next line CRLF so that</p>



<p>means when the program exits the terminal prompt is on the same line as</p>



<p>the program just printed that&#8217;s ugly and awful so let&#8217;s call</p>



<p>We could either say, let&#8217;s call CRLF after printing the first message,</p>



<p>or we could just assume that print something is like print a line.</p>



<p>I don&#8217;t know how you feel,</p>



<p>but I think if we always called CRLF after every time we printed a message,</p>



<p>I would probably be a little irritated.</p>



<p>So maybe let&#8217;s change this to print line and then make it call CRLF.</p>



<p>You can just keep adding this like 1013 at the end of every string, but I think I want</p>



<p>to try to make this as compact as possible.</p>



<p>So let&#8217;s add the CRLF for now and then we&#8217;ll change print something later.</p>



<p>So we print the message.</p>



<p>Now the prompt should be, you know, a line further down.</p>



<p>So great works.</p>



<p>I am now going to take the CRLF off and I&#8217;m going to put it inside of print something</p>



<p>so that right after we do the system call to print the string in question, we&#8217;ll print</p>



<p>we&#8217;ll print a new line this should now accomplish the same thing that we just saw</p>



<p>oh no what did i do i think i did uh i think i have a infinite loop of recursive calls in there</p>



<p>somewhere i had a stack overflow probably so let&#8217;s see what did i just do say hello is call</p>



<p>print something and then crlf is call print something oh whoops print something calls crlf</p>



<p>at the end so i should do one or the other and not have them call both so maybe just because crlf is</p>



<p>special maybe i&#8217;ll just use a direct system call inside of crlf i thought i was so clever</p>



<p>but i was wrong so we&#8217;re going to repeat a little code for the crlf and we&#8217;re going to load it up</p>



<p>with um crlf dang how embarrassing i like to say this is the most public of my many humiliations</p>



<p>of my many humiliations. But anyway, so now we don&#8217;t need to rely on print something. So this</p>



<p>won&#8217;t be an infinite loop and it should work if print something calls on crlf now. Do it again.</p>



<p>Okay, it works. So now let&#8217;s modify print something so that it is just print</p>



<p>a line. Print a line. And then that, in my eyes, you don&#8217;t have to do it this way. It sort of</p>



<p>to do it this way it sort of justifies printing a crlf at the end every single time so this is</p>



<p>just my personal thinking and then maybe i&#8217;ll add a comment after prints a crlf</p>



<p>so now when we call print line we no longer have to call crlf</p>



<p>and then when we print that message should be pretty good oh we got to update that to print line</p>



<p>Then for say hello, let&#8217;s just double check.</p>



<p>We can get rid of this system call code here.</p>



<p>Probably a good idea at this point.</p>



<p>And then we just say print hello string.</p>



<p>And then from the hello string, we can get rid of this CRLF at the end of it.</p>



<p>So I&#8217;m just going to get rid of that.</p>



<p>Actually, let&#8217;s do it first without getting rid of it.</p>



<p>Just so you see, oh, what did I do wrong?</p>



<p>Lion 61, forgot to update the symbol name.</p>



<p>Oh, there we go.</p>



<p>call print line because we don&#8217;t have print something anymore and try it again notice how</p>



<p>the first message hello my name is it has two line feeds after it because it is calling print line</p>



<p>which will do a crlf but then also in the string itself there&#8217;s a crlf so again the point is i&#8217;m</p>



<p>to my advantage.</p>



<p>Okay, so we got that working now.</p>



<p>I&#8217;m just going to print like five different kinds of messages.</p>



<p>How about three?</p>



<p>So we don&#8217;t have to sit here and watch me typing for too long.</p>



<p>So I&#8217;m going to say message two and then I&#8217;m going to do message three.</p>



<p>Message three.</p>



<p>This is message three unless I got that wrong.</p>



<p>One, two, three, one, two, three, one, two, three.</p>



<p>Now we can just call a print string on three different messages.</p>



<p>And I&#8217;ll just change this to say, you know, print the second message, print the third</p>



<p>message.</p>



<p>And then I&#8217;m going to change that to message two and then message three.</p>



<p>All right.</p>



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



<p>And then all three messages get printed.</p>



<p>Nice.</p>



<p>So now one more thing.</p>



<p>I just want to show you how to return an integer to the caller in a basic YASM x86 assembly function.</p>



<p>Again, this will not cover floats.</p>



<p>This does not show you how to return floats.</p>



<p>With floats, you have to use a different register called xmm0.</p>



<p>That&#8217;s going to be a different video.</p>



<p>But for now, I&#8217;m going to say all integer or pointer return values, like longs is going to be what we&#8217;re using,</p>



<p>that is the register that is designated for return values.</p>



<p>So what about this?</p>



<p>Instead of just returning the exit success code</p>



<p>that I&#8217;ve defined up above,</p>



<p>we&#8217;ll return whatever some function call gives us.</p>



<p>Maybe I&#8217;ll make another function down here</p>



<p>and then I&#8217;ll say a function</p>



<p>that just returns a simple long value.</p>



<p>And we&#8217;ll call this function gimme long.</p>



<p>We&#8217;ll call this function gimme long.</p>



<p>It&#8217;ll take no arguments because we&#8217;re just keeping this simple for now.</p>



<p>And instead of having a void return type, it&#8217;ll have a long return type because we expect</p>



<p>RAX to be loaded up.</p>



<p>So then I&#8217;m going to say gimme long and immediately do a return because it is a function.</p>



<p>And then I&#8217;m just going to load up a value from somewhere.</p>



<p>Obviously, it&#8217;s better if you&#8217;re doing something complicated to stick with registers as much</p>



<p>or defines and hit memory only if you need to.</p>



<p>And try not to hard code immediate into your code</p>



<p>if you can possibly avoid it.</p>



<p>It&#8217;s probably a lot better to define a value up at the top</p>



<p>in the data area than to just hard code it here.</p>



<p>But I&#8217;m gonna just hard code something here.</p>



<p>No, I always second guess myself.</p>



<p>I&#8217;m gonna say exit gimme.</p>



<p>I&#8217;m gonna define something up here.</p>



<p>So it&#8217;s easy to find what value I&#8217;m gonna return</p>



<p>for the gimme.</p>



<p>I&#8217;m just going to say 88, 89, 90, I don&#8217;t even know.</p>



<p>About 33, I don&#8217;t even know.</p>



<p>So we&#8217;re defining exitGimme as a symbol</p>



<p>to just be a replacement of just the number 33.</p>



<p>So down here, I&#8217;m going to say,</p>



<p>let&#8217;s have gimme long simply return exitGimme into RAX.</p>



<p>Nice, okay.</p>



<p>And so that means it&#8217;s the official return value</p>



<p>once you call gimme long.</p>



<p>call gimme long so that means up here get our whoops get out it&#8217;s coming from inside the house</p>



<p>get our return value from gimme long and again imagine gimme long might be a big complicated</p>



<p>function that decides what a return value is going to be or does something so i&#8217;ll start with saying</p>



<p>call gimme long because gimme long does not take any arguments i don&#8217;t have to load up any registers</p>



<p>load up any registers nor do i have to worry about preserving them or setting them up or doing</p>



<p>anything i just call but then let&#8217;s see inside of this function we&#8217;ll use rax in order to you know</p>



<p>load up the system call to let it know what function or sorry what function we want from</p>



<p>the system call so we got to give rax system exit so that means down here we can&#8217;t actually use rax</p>



<p>those other registers again I&#8217;m going to use I&#8217;m going to use the r12 register</p>



<p>I&#8217;m going to do like a little comment here that says register usage and I&#8217;ll say r12</p>



<p>maybe I&#8217;ll do a tab r12 is going to be old return value</p>



<p>or the syscall to exit you know whatever and that&#8217;s all we&#8217;re going to do so in the prologue</p>



<p>I&#8217;m going to push R12.</p>



<p>You should probably even preserve registers in the start function</p>



<p>because something might, or in your entry point,</p>



<p>because something that called you might be counting on those registers.</p>



<p>This is going to be probably especially true if you&#8217;re using GCC</p>



<p>to have a main entry point within a hybrid program.</p>



<p>So I&#8217;m just going to go prolog, push R12,</p>



<p>and then pop R12 at the very end.</p>



<p>Pop R12.</p>



<p>That&#8217;s not going to work because by the time we get there,</p>



<p>because by the time we get there,</p>



<p>it&#8217;s gonna exit the program.</p>



<p>I&#8217;ll do this here.</p>



<p>I&#8217;ll just try to be a good citizen.</p>



<p>I&#8217;m not actually sure if we need this</p>



<p>for a pure assembly function,</p>



<p>but it&#8217;s just a really good habit to get into.</p>



<p>And what is it gonna cost you?</p>



<p>Just a touch memory,</p>



<p>just one time right before the program exits.</p>



<p>It&#8217;s not gonna be a giant for loop or anything.</p>



<p>Okay, so epilog,</p>



<p>probably I might be showing you bad practice</p>



<p>by preserving things in the underscore start function.</p>



<p>But again, you will definitely wanna do this</p>



<p>Again, you will definitely want to do this for the main when you return from main.</p>



<p>So we do prolog R12, epilog R12.</p>



<p>I made a comment there.</p>



<p>And then we&#8217;re going to store the return value in R12.</p>



<p>So that means here we&#8217;re going to move something into R12.</p>



<p>It&#8217;s getting precarious because we restored it right before the system call,</p>



<p>but I think it&#8217;ll be okay.</p>



<p>system call but i think it&#8217;ll be okay we&#8217;re going to grab rax because rax is supposed to be the</p>



<p>return value register so when we called gimme long it loaded up rax with our return value</p>



<p>we then send rax into r12 so we can use r12 uh even though our rax has been you know destroyed</p>



<p>we&#8217;ll still have the return value that we wanted to use so i&#8217;m just going to load r12 up into the</p>



<p>first argument of the sys exit call let&#8217;s see if i if i got this to work or if i totally ruin this</p>



<p>work or if i totally ruin this okay all right so let&#8217;s see here what was</p>



<p>why is it not erroring gimme 33 exit gimme should i did i load the wrong value exit gimme what is</p>



<p>it doing exit gimme it&#8217;s moving rex into exit gimme so you call gimme long and then you move</p>



<p>r a x into r 12 and r 12 i wonder if that destroyed it</p>



<p>hmm let me get rid of this push pop pair because it&#8217;s supposed to be giving me</p>



<p>an ever message that the function or that the program did not exit maybe this is proof that</p>



<p>you don&#8217;t need to preserve inside of the underscore start function let&#8217;s see here</p>



<p>yeah okay i guess that proves it hey don&#8217;t take my word for it i&#8217;m wrong all the time</p>



<p>For yourself, be a scientist, be a computer scientist.</p>



<p>Try it out.</p>



<p>Try to do something different.</p>



<p>Okay, so I guess this is proof we don&#8217;t really need a prolog and epilog in just a pure assembly,</p>



<p>at least the entry point for start.</p>



<p>But if you were calling any other functions, then they definitely need to preserve.</p>



<p>And again, if you&#8217;re using GCC, so you can have a main for your entry point, then you</p>



<p>still have to preserve.</p>



<p>you know print the message and then print our other three messages and then the return code</p>



<p>is going to be 33 that was the gimme code that we did so now we know how to return a value from a</p>



<p>function and um let me set this back to just zero so the make system thinks that we succeeded</p>



<p>run it again succeeded all right i guess this concludes the video i hope you had a little bit</p>



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



<p>Hey everybody, thanks for watching this video again from the bottom of my heart.</p>



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



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



<p>If you could do me a please, a small little favor, could you please subscribe and follow</p>



<p>this channel or these videos or whatever it is you do on the current social media website</p>



<p>that you&#8217;re looking at right now.</p>



<p>world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll</p>



<p>be able to do more videos longer videos better videos or just I&#8217;ll be able to</p>



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



<p>you know sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p>because I know somebody subscribed or followed it just wakes me up and I get</p>



<p>filled with joy that&#8217;s exactly what happens every single time so you could</p>



<p>do it as a nice favor to me or you could you control me if you want to just wake</p>



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



<p>Also, if you look at the middle of the screen right now, you should see a QR code, which you</p>



<p>can scan in order to go to the website, which I think is also named somewhere at the bottom of</p>



<p>this video. And it&#8217;ll take you to my main website where you can just kind of like see</p>



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



<p>clarifications or errata or just future videos that you want to see please leave a comment or</p>



<p>if you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever</p>



<p>i also wake up for those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like</p>



<p>it would really it really mean the world to me i would really appreciate it so</p>



<p>again thank you so much for watching this video and um enjoy the cool music as as i fade into the</p>



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



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-x86-64-yasm-assembly-functions-made-simple/">Mastering x86-64 YASM Assembly: Functions Made Simple</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/mastering-x86-64-yasm-assembly-functions-made-simple/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 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>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>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>Thanks for watching!</p>



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



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



<p>Please help support us!</p>



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



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



<li>Subscribing to our Blog</li>



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



<p>Hey there, I want to talk to you very quickly about the general idea of linking your programs.</p>



<p>In previous videos I&#8217;ve described exactly how to perform the linking stage when you&#8217;re compiling</p>



<p>a program. So you write some source code, you compile the source code into object files,</p>



<p>you know each file becomes one individual object file, and then when we&#8217;re done we take all the</p>



<p>object files and we link them up into an executable program. So I&#8217;ve talked about that</p>



<p>I just wanted to talk to you about the general idea of the linking stage in general.</p>



<p>Like what is the linker? What is its job? What is it actually doing?</p>



<p>So try to keep in mind for starters, each program uses virtual memory.</p>



<p>It uses a virtual memory space.</p>



<p>So obviously on your computer you have real memory,</p>



<p>but there&#8217;s lots of layers of abstraction between the physical hardware</p>



<p>the physical hardware and the program that&#8217;s running for starters the operating system uses</p>



<p>a paging system the memory stick the memory circuitry might be doing something else for</p>



<p>error checking or just you know transport or whatever so so try and bear in mind that each</p>



<p>program thinks that it&#8217;s it thinks that itself is kind of the beginning of memory you could imagine</p>



<p>it as each program thinks that its first memory location that it has assigned to it is memory</p>



<p>location zero but that wouldn&#8217;t necessarily be the case on the computer</p>



<p>your operating system probably would have come up with an offset let&#8217;s say</p>



<p>for example you know your computer decides to launch your program it</p>



<p>creates a process it finds a chunk of memory that&#8217;s available across you know</p>



<p>one or more pages of free memory and let&#8217;s say for the sake of argument that</p>



<p>the starting offset for the for the quote-unquote real forgetting the other</p>



<p>layers layers of abstraction the real memory location of your program is going</p>



<p>of your program is going to be let&#8217;s just say like a thousand I know that&#8217;s</p>



<p>real unrealistically too low but let&#8217;s just say a thousand and then let&#8217;s say</p>



<p>that your program then thinks that it starts at memory location zero that</p>



<p>means if your program wants to access memory location 100 then under the hood</p>



<p>at the last moment right before you actually hit the RAM stick or hit the</p>



<p>page file system a translation has to be performed so if your program is trying</p>



<p>what actually happens is you know the general offset for the entire program</p>



<p>gets added to memory location 100 and then that tells the computer or the</p>



<p>operating system that what you&#8217;re actually trying to do in your program is</p>



<p>access memory location 1100 so keep in mind all of this memory is virtual</p>



<p>and the modules themselves also need to know where to jump when I say where to</p>



<p>Well, suppose for the sake of argument, you have a program that has some jump instructions</p>



<p>or go to instructions or like some conditional branching instructions, anything where execution</p>



<p>is not just going to go to the very next statement.</p>



<p>Execution is going to go somewhere else.</p>



<p>Like maybe you have an if else block.</p>



<p>It&#8217;s got to maybe jump sometimes down to the else part instead of the top if part.</p>



<p>And then when it&#8217;s done executing, it&#8217;s going to jump until after the whole block, you know,</p>



<p>There will be lots of times in all of your programs where execution kind of has to jump</p>



<p>around somewhere if the program is even a little bit complicated.</p>



<p>So that could be a jump instruction, go to in a higher level language, not assembly necessarily,</p>



<p>jump if not equal and so forth.</p>



<p>So if you imagine writing one module, you could also imagine that the module has its</p>



<p>own virtual memory address space.</p>



<p>Just imagine it for now.</p>



<p>And maybe it starts at zero.</p>



<p>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>about itself and so sometimes when you&#8217;re jumping for example if we&#8217;re going to jump uh when</p>



<p>something is not equal to something else we&#8217;ll jump to some label and in order to jump to that</p>



<p>label the assembler needs to know you know where is that label inside of your source code so pretend</p>



<p>just for a moment this is not like a real assembly program but just pretend for a moment that we have</p>



<p>and maybe this is like I don&#8217;t know the main label that gets jumped into from GCC and</p>



<p>so then we have like a label down here outside and we&#8217;ll do stuff and then jump back to the</p>



<p>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>So if we jump, let&#8217;s compare, I don&#8217;t know, one with two or something.</p>



<p>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>so they&#8217;re not actually equal.</p>



<p>And then we compare them and then we say, all right, jump if they&#8217;re not equal to this label.</p>



<p>So definitely now we know, oh, we are going to jump down to that label.</p>



<p>So execution is going to go directly down to here.</p>



<p>we&#8217;ll do something and then eventually maybe we want to jump back so we&#8217;ll say uh</p>



<p>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>if it is equal and we&#8217;ll just like load those two registers so one and one and then compare</p>



<p>them and then say jump if it is equal to main finish this is not a video about conditional</p>



<p>branching or jumping i&#8217;m trying to make this as simple as i can but i hope you understand the</p>



<p>but i hope you understand the point is just basically we&#8217;re jumping around within the same</p>



<p>module right so it&#8217;s easy for the program to understand where to jump if it&#8217;s in the same</p>



<p>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>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>instruction at line 17 well then it you know the amount of instructions to move is just the</p>



<p>the difference you know so it&#8217;s easy to say all right if our virtual address is you know this</p>



<p>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>we can just compute the new virtual address to jump or the absolute address or whatever you want</p>



<p>to whatever you want to do on that particular run but how does it know where to jump in another</p>



<p>module because when we assemble this module as an object file the assembler is only running one pass</p>



<p>one pass on just this object file it doesn&#8217;t really know the addresses in the other modules</p>



<p>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>really know the offsets it doesn&#8217;t know where the functions start and end doesn&#8217;t know anything</p>



<p>because right now if we assemble this one source code it&#8217;s only going to know about this one source</p>



<p>code right and the same goes for the other modules if we compile a c plus plus program to an object</p>



<p>a function or you know do a go to statement or something into one of these labels from this</p>



<p>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>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>and all of these uh conditional branching statements and jump statements and everything</p>



<p>and it just decides for starters it decides where each module is going to start in memory so maybe</p>



<p>I don&#8217;t know if your C++ module starts up here somewhere and then it&#8217;ll say this assembly module</p>



<p>starts right after it and then another module right after that and it&#8217;ll just kind of decide</p>



<p>where every module will start in the final executable that we&#8217;re actually linking together.</p>



<p>Once it decides the layout then it knows the offset of all the different modules and therefore</p>



<p>it can compute the additional offset that it would take to get to all the labels. So then at that</p>



<p>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>Main finish return.</p>



<p>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>But another module could could call main finish as a function and still get a return statement.</p>



<p>That would actually work, even though it&#8217;s probably bad design.</p>



<p>that your assembly sorry your C++ program wants to call a function called</p>



<p>main finish inside of this module the linker having already laid out the</p>



<p>modules and and being aware of all their offsets it knows okay so you know this</p>



<p>assembly module it was underneath the C++ module so it&#8217;ll just take that offset</p>



<p>and add it to the offset of the label itself within the module and then also</p>



<p>add that to the the virtual address or I guess the operating system will do the</p>



<p>address. But you know, the point is the linker coordinates all the jumps and the conditional</p>



<p>branches where the functions start, lays out all the modules, gets all the offsets,</p>



<p>and then starts replacing all of the conditional branches and jumps and things with the real</p>



<p>offsets that make it actually doable. Like let&#8217;s jump to exactly this memory location</p>



<p>in code exactly in quotes, because we&#8217;re still using virtual addressing.</p>



<p>idea of the linker it knows how to jump between modules um wants to link or discuss okay that&#8217;s</p>



<p>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>call as a function from outside the module you got to mark it as global so if i actually wanted</p>



<p>somebody to be able to call main finish as a function i just have to mark it as global same</p>



<p>thing for some label if i say global some label then now at this point another module could call</p>



<p>call this as a function or jump into it probably bad form to not put a return a return statement</p>



<p>at this point which means when i&#8217;m calling it up here instead of jump not equal to i probably have</p>



<p>to add more complicated logic so i can use a function call that gets jumped around if it is</p>



<p>equal but so i&#8217;m not going to go that far right now kind of complicated just for this video</p>



<p>and then also of course if you intend to jump somewhere else remember that you have to mark</p>



<p>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>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>And then once I do that, now I could actually call it, I could say, call, you know, this.</p>



<p>Actually, that&#8217;ll never get reached because the jump equal thing is at the bottom.</p>



<p>equal thing is at the bottom but I could do this I could say call it if it was actually a function</p>



<p>or I could say jump if it was just a jump point or I could say you know jump not equal to</p>



<p>the other function instead of some label something like that so lots of stuff you can do and now you</p>



<p>kind of understand the idea of linking is taking all the modules stuffing them inside of the final</p>



<p>executable and also putting data inside of the final executable you know like if you&#8217;re creating</p>



<p>So, you know, like if you&#8217;re creating a string variable in your globals area of your assembly</p>



<p>program or hard coding, any kind of string anywhere in your C++, then it&#8217;s got to be</p>



<p>inside of the executable.</p>



<p>Otherwise, it wouldn&#8217;t be anywhere when we ran the program.</p>



<p>So, yeah, it sticks the data in there.</p>



<p>It sticks the segments in there.</p>



<p>It, you know, calculates the jumps and all that stuff.</p>



<p>I just want to point out you could put strings in a configuration file.</p>



<p>of a vanilla C++ or assembly program you probably are making strings directly in the program.</p>



<p>Anyway, so I think that&#8217;s the gist of everything that I really wanted to say about what is the</p>



<p>general idea of the linker. Thanks for watching this video I hope you learned a little bit and</p>



<p>had some fun. I will see you in the next video. Hey everybody thanks for watching this video again</p>



<p>it i do hope you did learn something and have some fun if you could do me a please a small little</p>



<p>favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p>on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p>world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



<p>videos longer videos better videos or just i&#8217;ll be able to keep making videos in general so please</p>



<p>and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p>because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



<p>That&#8217;s exactly what happens every single time. So you could do it as a nice favor to me or you</p>



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



<p>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>the screen right now, you should see a QR code, which you can scan in order to go to the website,</p>



<p>is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where</p>



<p>you can just kind of like see all the videos I published and the services and tutorials and</p>



<p>things that I offer and all that good stuff and uh if you have a suggestion for uh uh clarifications</p>



<p>or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p>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>I wake up in a cold sweat and I&#8217;m like, it would really mean the world to me.</p>



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



<p>So again, thank you so much for watching this video and enjoy the cool music as I fade into</p>



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



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/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>Compile, Link, Execute: A Beginner’s Guide to Linux Programming with C++, C, and Assembly</title>
		<link>https://www.NeuralLantern.com/compile-link-execute-a-beginners-guide-to-linux-programming-with-c-c-and-assembly/</link>
					<comments>https://www.NeuralLantern.com/compile-link-execute-a-beginners-guide-to-linux-programming-with-c-c-and-assembly/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Wed, 28 May 2025 03:37:23 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[beginner coding]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[compile C++]]></category>
		<category><![CDATA[execute Linux]]></category>
		<category><![CDATA[G++ tutorial]]></category>
		<category><![CDATA[link object files]]></category>
		<category><![CDATA[Linux compile script]]></category>
		<category><![CDATA[Linux development]]></category>
		<category><![CDATA[Linux programming]]></category>
		<category><![CDATA[name mangling]]></category>
		<category><![CDATA[object files]]></category>
		<category><![CDATA[programming basics]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=135</guid>

					<description><![CDATA[<p>Learn to compile, link &#038; execute C++, C, and assembly on Linux! Beginner-friendly guide with bash scripting tips. #Linux #Programming</p>
<p>The post <a href="https://www.NeuralLantern.com/compile-link-execute-a-beginners-guide-to-linux-programming-with-c-c-and-assembly/">Compile, Link, Execute: A Beginner’s Guide to Linux Programming with C++, C, and 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="Compile, Link, Execute: A Beginner&#039;s Guide to Linux Programming with C++, C, and Assembly" width="1380" height="776" src="https://www.youtube.com/embed/z9iuTrptPM0?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>Hey there, coding enthusiasts! Ready to master compiling, linking, and executing programs on Linux? In this fun and approachable video, we dive into the nuts and bolts of turning your code into runnable programs. We’ll create a simple C++ program, compile it with G++, and explore object files, linking, and execute permissions. Plus, we’ll mix in C and assembly code, tackle name mangling, and build a bash script to automate it all! Perfect for beginners or anyone curious about Linux programming, this guide is packed with practical tips and real-world examples. Don’t miss out—subscribe for more coding adventures, leave a comment with your thoughts, and let’s geek out together! Scan the QR code to visit my site for more tutorials. #LinuxProgramming #CodingForBeginners #CPlusPlus</p>



<p>Introduction to Compiling, Linking, and Executing 00:00:00<br>Overview of the Process 00:00:05<br>Writing a Simple C++ Program 00:00:28<br>Compiling with G++ 00:02:01<br>Understanding Executable Files 00:03:04<br>Executing a Program 00:04:21<br>Handling Execute Permissions 00:05:13<br>Creating a Compile Script 00:07:00<br>Using Shebang for Scripts 00:08:43<br>Specifying Output Files 00:10:53<br>Breaking Down Compilation Steps 00:12:26<br>Compiling to Object Files 00:13:17<br>Linking Object Files 00:15:24<br>Handling Multiple Source Files 00:18:39<br>Mixing C and C++ with Name Mangling 00:22:52<br>Enhancing Script with Error Handling 00:24:29<br>Adding Assembly Source File 00:31:16<br>Using Bash Variables for Flags 00:41:53<br>Organizing Compiler Flags 00:44:41<br>Final Script Enhancements 00:46:36<br>Conclusion and Call to Action 00:47:35</p>



<p>Thanks for watching!</p>



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



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



<p>Please help support us!</p>



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



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



<li>Subscribing to our Blog</li>



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



<p>Hey there! Let&#8217;s talk about compiling, linking and executing.</p>



<p>This video is going to focus on Linux, but I think it&#8217;ll be useful for all other operating systems that you might be working with at home.</p>



<p>I&#8217;m just going to basically explain like what does it mean to compile?</p>



<p>What does it mean to link a program?</p>



<p>What does it mean to execute a program?</p>



<p>If you don&#8217;t know that, then I think this video might be for you.</p>



<p>Okay, so for starters, imagine you have written a program.</p>



<p>I&#8217;m going to write the program here real fast.</p>



<p>I&#8217;m going to say, let&#8217;s do an empty file.</p>



<p>We&#8217;ll call it, let&#8217;s see, I got my answer key up here.</p>



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



<p>First.cpp.</p>



<p>So I&#8217;m just like making a first piece of source code and I&#8217;m editing it in my little editor.</p>



<p>Notice how I&#8217;m not calling this the main.cpp program because a lot of beginners, they always</p>



<p>do main.</p>



<p>I want you to know that you don&#8217;t actually need a source code file called main.cpp.</p>



<p>Even if you&#8217;re writing a C++ program, all you really need is just one instance of the function main.</p>



<p>Beyond that also, you only need an instance of main if you&#8217;re writing a hybrid program</p>



<p>or some kind of program that is in pure C++ or that has the GCC libraries.</p>



<p>GCC libraries call on the main function as your entry point.</p>



<p>But if you&#8217;re writing pure assembly, the entry point is actually underscore start as a label.</p>



<p>We&#8217;re not really going to do this is not an assembly tutorial.</p>



<p>I just wanted you to know real fast.</p>



<p>Okay.</p>



<p>So I&#8217;m going to do like IO stream and then I&#8217;m going to say</p>



<p>STDC out and I&#8217;m just going to print, you know, hello from first.</p>



<p>Cpp.</p>



<p>STD.</p>



<p>And L.</p>



<p>Okay.</p>



<p>So we kind of have like a hello world program that&#8217;ll just</p>



<p>that&#8217;ll just basically print a message and do nothing else how do we compile</p>



<p>this program and execute it you know what does that actually even mean okay</p>



<p>so for starters the first thing that you probably do when you&#8217;re compiling a</p>



<p>program you&#8217;ve probably been told to do something like this let me get my little</p>



<p>command line open here you&#8217;ve probably been told to do something like this</p>



<p>let&#8217;s compile with GCC or G++ and we&#8217;ll say the standard for C++ that we&#8217;re</p>



<p>There are a bunch of other standards you can use.</p>



<p>We can turn on all warnings.</p>



<p>We can have the compiler be pedantic in terms of the warnings that it gives us.</p>



<p>You know, these two things at the end don&#8217;t really matter that much.</p>



<p>It&#8217;s really all about G++ and then STD C++ 23 to get it compiled.</p>



<p>And then we&#8217;ll give an input file.</p>



<p>We&#8217;ll say burst.cpp.</p>



<p>And then I think probably usually this is where most of you stop.</p>



<p>you stop we just kind of like specify a couple flags specify the input file then</p>



<p>hit enter and it compiles if we list the contents of the directory now this might</p>



<p>be familiar you&#8217;ll probably see something called a.out a.out notice how</p>



<p>the permissions look a little bit different for that for that file it&#8217;s</p>



<p>kind of printed in green in Ubuntu and if you look at the left side right here</p>



<p>you can see that it&#8217;s got a bunch of X&#8217;s in the permissions area that just means</p>



<p>That just means it has execute permission.</p>



<p>The compiler does that automatically for you,</p>



<p>but essentially this is like just, you know,</p>



<p>an executable binary file.</p>



<p>It&#8217;s not a text file.</p>



<p>It&#8217;s just something that the computer is meant to run.</p>



<p>We can look inside of it real fast.</p>



<p>There&#8217;s a program called XXD on Linux,</p>



<p>and it&#8217;ll sort of spill the contents of that file.</p>



<p>So if I say XXD and then I go a.out,</p>



<p>it just spills like a whole lot of like binary nonsense,</p>



<p>right?</p>



<p>you can see at the very beginning elf that&#8217;s uh i think that&#8217;s executable linking format</p>



<p>for linux and then there&#8217;s like a bunch of stuff and it just doesn&#8217;t make sense this is not text</p>



<p>that you can read here&#8217;s like some sort of a shared argument that it&#8217;s using and then some</p>



<p>register information i don&#8217;t even know what most of this is somewhere in here if you look</p>



<p>carefully you&#8217;ll probably see that message where is that oh yeah hello from c first.cpp so it&#8217;s</p>



<p>saying that the message we typed in the program is actually embedded in the executable.</p>



<p>That makes sense.</p>



<p>So hopefully I&#8217;ve proved to you that this is just an executable program.</p>



<p>How do you execute the program?</p>



<p>Well, usually you&#8217;ll have to type, you know, the full path to the program that you want to execute</p>



<p>because your custom program is not in the system library paths.</p>



<p>So your system&#8217;s not going to know where to find it automatically,</p>



<p>even if it&#8217;s in the current folder.</p>



<p>So you would usually do something like, you know, the full path to your executable,</p>



<p>path to your executable like a.out. But there&#8217;s a shortcut we can use in Linux. The dot directory</p>



<p>usually just means or it always means the current directory. So if we say dot and then a slash,</p>



<p>that&#8217;s the same thing as typing out the full path to the current directory. Then it&#8217;s really easy to</p>



<p>just type the name of the file that we compiled. Okay, so a.out. We executed it now. So that&#8217;s what</p>



<p>it means to execute. We just compiled without a lot of options. We&#8217;re going to try to do that better</p>



<p>We&#8217;re going to try to do that better in a second.</p>



<p>And we know that you need execute permissions.</p>



<p>Let me show you what happens if we take away execute permissions.</p>



<p>I&#8217;m going to use a command called chamad, like change the mode.</p>



<p>I&#8217;m going to say take away execute permissions from the a.out program.</p>



<p>Then if I list the directory again, notice how there are a bunch of X&#8217;s missing now</p>



<p>on the left side of that a.out permissions area.</p>



<p>Notice how it&#8217;s not in green anymore.</p>



<p>Depending on your system, it might not be green or gray or whatever.</p>



<p>be green or gray or whatever but just look at the permissions so now if i do a dot out</p>



<p>it&#8217;ll say permission denied maybe you&#8217;ve seen this before especially if you&#8217;re syncing with</p>



<p>the cloud that doesn&#8217;t carry execute permissions from one machine to another which happens to me</p>



<p>all the time we can reverse this with just the chamad you know plus x execute permissions</p>



<p>and then we can just execute it again the funny thing about execute permissions is</p>



<p>you can actually execute a bash program which is basically a text file without</p>



<p>without needing to execute a binary program so this is not a bash video I&#8217;ll</p>



<p>make other videos in the future on my channels for for bash but for now just</p>



<p>know that something you compile is not the only type of thing that you can</p>



<p>actually execute in fact in Linux under the hood a lot of system tools are just</p>



<p>written in bash or Python or something else that looks like a human readable</p>



<p>like a human readable language and they are not necessarily all compiled languages, you</p>



<p>know, like C++.</p>



<p>Okay, so now that we kind of know that we&#8217;re compiling a program, let&#8217;s be a little bit</p>



<p>better about specifying the name of the output file.</p>



<p>So I just want you to see one more flag here and while I&#8217;m doing that, I&#8217;m going to create</p>



<p>a script that will compile our program for us.</p>



<p>nano and I&#8217;ll just name a file I&#8217;ll name it compile and it&#8217;ll be our compiler program okay</p>



<p>so what we did before is it was I think G++ and then we named the standard is C++ 23 and then we</p>



<p>said wall wall just means give me all warnings which is good to help your you know to help you</p>



<p>write better code same thing for pedantic just helps you write better code it gives you more</p>



<p>but you know it&#8217;s pretty good. Okay so this is where we stopped last time so</p>



<p>I&#8217;m going to say now let me remove a dot out now instead of typing the command by</p>



<p>ourselves we can run the compile script. The language I&#8217;ve just written was was</p>



<p>well I haven&#8217;t really written in any particular language but if we use a</p>



<p>shell interpreter called bash which is actually what&#8217;s running in the terminal</p>



<p>right now it&#8217;ll interpret any command line that we give it as just something</p>



<p>line that we give it as just something that we want it to execute to the system. So if I type</p>



<p>bash to run the bash interpreter and I just specify the name of the script, it should compile the</p>



<p>program automatically by executing that one line that I put inside of it. See now I&#8217;ve got the a.out</p>



<p>again. If you rewind the video you&#8217;ll see the a.out wasn&#8217;t there when I originally ran it.</p>



<p>One more time just to prove it to you. bash compile. Now you can see that it&#8217;s back. Okay</p>



<p>Okay, so let&#8217;s make this compile program a little bit better instead of typing bash every single time</p>



<p>I think I just want to try to execute the compile program directly. I</p>



<p>Can do that pretty easily. There&#8217;s something in</p>



<p>In our script that we can put that will designate what interpreter we should use to run the program</p>



<p>So right now it&#8217;s just like some text and it doesn&#8217;t really mean anything</p>



<p>there&#8217;s something called the shebang which just means hash bang and</p>



<p>just provide the path to some interpreter. I&#8217;m going to type shebang and then a path</p>



<p>to the bash interpreter. If you don&#8217;t know where bash is on your system, you can go which bash.</p>



<p>And I guess mine is a user bin bash. I think I can get away with bin bash. Let me see.</p>



<p>Let me just type it out to make sure bin bash. Yeah. Okay. So if I type exit, I&#8217;m actually in</p>



<p>another version of bash, which is inside of bash. If I do exit, I should just kind of stay where I</p>



<p>Okay, so bin bash will work, user bin bash will also work.</p>



<p>I&#8217;m going to go back to editing this compiler program.</p>



<p>And now all I have to do, because the system is going to know what interpreter to use to execute my little script program here,</p>



<p>all I have to do is add execute permissions on it, and it should work.</p>



<p>So let me first remove a dot out.</p>



<p>And then let me try first to execute compile.</p>



<p>It should not work because I don&#8217;t have execute permissions.</p>



<p>Remember we talked about that before.</p>



<p>permissions. Remember we talked about that before? So if I do that it says</p>



<p>permission denied. Oh no! So I&#8217;m going to give it permission to execute. I&#8217;m going</p>



<p>to say change the mode plus X on compile. If I list the directory again notice how</p>



<p>it&#8217;s green notice how there&#8217;s a bunch of X&#8217;s everywhere. So now I should be able</p>



<p>to just say compile and then it seems to have worked and notice how it has an</p>



<p>because it&#8217;s a pain in the butt to type out all the compile commands every single time,</p>



<p>especially if you have a complicated compile command or many files that you want to compile</p>



<p>in the same shot. So, you know, of course, in another video, I&#8217;m going to talk about make files,</p>



<p>build systems, proper build systems are a lot better than just making a script. But for now,</p>



<p>let&#8217;s just make a script because I just want you to understand, you know, compiling, linking,</p>



<p>some of the surrounding ideas. Okay, so I&#8217;m going to, let&#8217;s see, I&#8217;m going to go nano compile.</p>



<p>And the next upgrade that I want to make is I want to specify the output file because it&#8217;s</p>



<p>kind of a bad idea to not specify the output file and just hope that the compiler gives you</p>



<p>the file that you wanted. I don&#8217;t know. So I&#8217;m going to do dash O main, and that&#8217;s going to give</p>



<p>So if I remove a.out just to keep my area clean, I can now do compile.</p>



<p>And if I list again, notice how I&#8217;ve got main.</p>



<p>So I can execute main and it&#8217;s the same program that we already had.</p>



<p>In fact, maybe sometimes just as a shortcut since this is a script,</p>



<p>what if I&#8217;m always hitting ls-la, I always want to list the folder after I compile.</p>



<p>I could just put that into the script.</p>



<p>The more commands you put into the script, the more convenient things can get, unless</p>



<p>I guess it gets too messy.</p>



<p>So I&#8217;m going to do, I&#8217;m going to list first, and I&#8217;m going to remove main, just to prove</p>



<p>to you that we&#8217;re doing this from scratch, and then I&#8217;ll do compile.</p>



<p>Notice how it compiles and then lists everything for me.</p>



<p>Seems like it didn&#8217;t actually turn the compile green.</p>



<p>That&#8217;s probably another flag that we have to stick in there.</p>



<p>Let me see if I can do that real fast.</p>



<p>If not, I won&#8217;t waste time.</p>



<p>This is not an LS video.</p>



<p>probably color or colors is what I got to do. Let me just do that one more time. Yeah, okay. So</p>



<p>that&#8217;s just a flag on LS. That&#8217;s not what this video is about. So now we&#8217;re compiling directly</p>



<p>to main, but here&#8217;s the problem though. We&#8217;re actually kind of sort of skipping over some</p>



<p>steps that we could be aware of. When we compile our program, we&#8217;re actually taking our source code</p>



<p>and we&#8217;re assembling it down to assembly code under the hood, and then we&#8217;re compiling it to</p>



<p>And then we&#8217;re compiling it to an object file, which is sort of just machine code.</p>



<p>It&#8217;s like a level lower than assembly.</p>



<p>And then as a last step, it&#8217;s getting linked into an executable named main.</p>



<p>So we&#8217;re skipping a ton of steps.</p>



<p>Really what&#8217;s supposed to be happening is every single source file.</p>



<p>Oh, whoops.</p>



<p>I&#8217;m on the wrong machine right now.</p>



<p>Okay.</p>



<p>Where&#8217;s that?</p>



<p>Oh, the machine that I&#8217;m recording on.</p>



<p>There we go.</p>



<p>CPP and we&#8217;re thinking that it just goes directly to main you know that works if you only have one source file or if you don&#8217;t want to have</p>



<p>fine-tuned control over your compiling</p>



<p>But I would like to do something a little bit more detailed. Let&#8217;s compile our</p>



<p>CPP source file into an object file. I&#8217;ll name it first.o and then we&#8217;ll link that into main</p>



<p>Why is that useful because later when we have multiple source files?</p>



<p>We might we might want to compile them all to object files first and then link them all together in one step into main</p>



<p>all together in one step into main this will be even more useful when you later realize that you</p>



<p>can use a build system that does kind of the same thing to save compilation time i won&#8217;t talk too</p>



<p>much about make files here but let me just tell you when you start using a build system</p>



<p>your compile time can be drastically reduced uh story i used to have a program a long time ago</p>



<p>that i wrote myself took like an hour to compile i would literally every little change i made i&#8217;d</p>



<p>have to get up and leave and go make a sandwich or something and then come back by the time it</p>



<p>back by the time it was finished compiling when i started using object files as intermediate steps</p>



<p>and upgraded to a build system i was using gnu make then my compile time went down to like a</p>



<p>minute each time so it was like so much more efficient anyway let&#8217;s do that let&#8217;s do that now</p>



<p>let&#8217;s let&#8217;s uh let&#8217;s nano our compile script and you just need another flag in here for the gcc</p>



<p>an object file and not actually produce a fully linked executable that you can execute that means</p>



<p>i should probably rename main to something else because main is supposed to be my executable at</p>



<p>least that&#8217;s what i&#8217;ve chosen i would like to have every object file be named similarly to the source</p>



<p>file it belongs to so i&#8217;m going to type the output now is going to be first.o and then the c flag</p>



<p>just says only compile don&#8217;t link this means of course that i&#8217;m not going to produce a program</p>



<p>a program that I can run. Let&#8217;s see, I&#8217;m gonna end up accidentally deleting the</p>



<p>compiler. Okay, but we can see what we&#8217;re doing. Okay, so compile and CPP for first.</p>



<p>So I&#8217;m gonna compile it and now notice how we have an object file and no main</p>



<p>and just the source file and its corresponding object file. So I can&#8217;t run</p>



<p>this program. I have to do the additional linking step now. So I&#8217;m gonna do</p>



<p>step now so I&#8217;m going to do compile and in my editor here let&#8217;s see where is my</p>



<p>command that I wanted to do for linking okay so I&#8217;m going to link with the the</p>



<p>GCC libraries I&#8217;m gonna use the G++ command I&#8217;m just gonna put a couple of</p>



<p>flags I&#8217;ll explain them real fast I&#8217;m gonna say that I want a 64-bit</p>



<p>executable which you probably actually don&#8217;t have to specify I&#8217;m going to</p>



<p>anyway and then I&#8217;m gonna tell it again that I want it to link up against the</p>



<p>23 libraries. This is important if multiple modules reference the C++ libraries. I&#8217;m not</p>



<p>even sure. I think I need it in both the compiling command and the linking command. I&#8217;m going to</p>



<p>leave it in both because it should work. Usually if you want to embed debugging symbols into your</p>



<p>program, you want to put a dash G there, which is a great idea. But we&#8217;re not going to talk about</p>



<p>debugging in this video. You can also specify the type of debugging symbols that you want.</p>



<p>symbols that you want I&#8217;m just gonna put that in here right now G dwarf 2 and</p>



<p>then there&#8217;s some new flags that you kind of need there&#8217;s one here called no</p>



<p>PI which I think is just an Ubuntu thing your program probably won&#8217;t execute if</p>



<p>you don&#8217;t do that just just put it in there and trust me there&#8217;s another one</p>



<p>that we have to put in now called no exec stack which basically prevents your</p>



<p>program from executing code sitting inside of the stack which is just sort</p>



<p>not get hacked hopefully it&#8217;s not bulletproof but you know it might help</p>



<p>and then i&#8217;m going to give it input files the input files for the linking</p>



<p>stage maybe i should do a comment linking stage</p>



<p>compile the c++ program or source or something</p>



<p>for the linking stage uh you want to you want to provide all of the object files</p>



<p>that you&#8217;re going to link together in this case we just have you know</p>



<p>file named first and then we can specify the output file as main if we didn&#8217;t</p>



<p>specify it would probably be a dot out like we saw before so if I got this</p>



<p>right let&#8217;s see if I did now this should compile the C++ source code file into</p>



<p>its corresponding object file and then scoop up the object file turn it into an</p>



<p>executable okay so my clear and then list and then I&#8217;m gonna remove the object</p>



<p>put star dot o which is a shell trick to basically say that that star dot o is</p>



<p>going to expand to really mean every file that ends in dot o so you know in</p>



<p>this case it&#8217;s actually just gonna end up being first dot o but it&#8217;s a trick you</p>



<p>can use to grab multiple object files or files of a certain type all in one</p>



<p>command so I&#8217;m gonna do that and then I&#8217;m gonna list again and then I&#8217;m gonna</p>



<p>compile and you can see that the compile command it created first dot o the</p>



<p>the object file, and it also created the executable main.</p>



<p>So if I execute main, the same thing should happen.</p>



<p>So great. We&#8217;re ready to move on to another step.</p>



<p>Let me remove star dot O.</p>



<p>I got to be so careful because I&#8217;m going to totally ruin this video by erasing the wrong thing.</p>



<p>Okay. Because this is, I should be in a Git repository, but I&#8217;m trying to be fast here.</p>



<p>Okay. So let&#8217;s nano compile.</p>



<p>Let&#8217;s create a second source file actually.</p>



<p>Okay. So let me get out of this.</p>



<p>Let me get out of this.</p>



<p>I want to create a second source file.</p>



<p>I&#8217;m going to call it second.c.</p>



<p>It&#8217;s going to be a pure C program.</p>



<p>And because we don&#8217;t have C++ libraries in C source files,</p>



<p>I&#8217;m just going to say, you know,</p>



<p>standard input output dot O for the header.</p>



<p>I&#8217;m going to make a function called void second probably.</p>



<p>And it doesn&#8217;t do anything except just sort of print</p>



<p>a little message.</p>



<p>So I&#8217;m going to say hello from second.</p>



<p>And then do a new line.</p>



<p>because we don&#8217;t have endels in c all right i think that&#8217;s probably going to work so then</p>



<p>let&#8217;s uh edit our compiling script and we&#8217;ll just add another line here to compile the c source</p>



<p>okay so i&#8217;m going to go gcc because it&#8217;s not c plus plus anymore and um i&#8217;m going to do all</p>



<p>warnings and pedantic again uh you don&#8217;t really need even need to worry about that and i&#8217;m going</p>



<p>need even need to worry about that and i&#8217;m going to give it an input of second.c because that&#8217;s the</p>



<p>file we just worked on and i&#8217;m going to tell it i only want you to compile with the dash c flag if i</p>



<p>forgot that on this one then i&#8217;ll probably end up with an object file a main and then an a.out that&#8217;s</p>



<p>only based on the c source code and that probably wouldn&#8217;t work because the second source code</p>



<p>doesn&#8217;t have a main function inside of it so um let&#8217;s see we&#8217;ll do output and it&#8217;s going to be</p>



<p>and then I think that should be okay you know something that I just realized I</p>



<p>should mention too is when you&#8217;re making hybrid programs like this or or</p>



<p>programs where there are just many many source files like I said before you</p>



<p>don&#8217;t need to have a source code named main.cpp you can name all your source</p>



<p>codes anything that you want the one thing that you really do need is a piece</p>



<p>of source code oh I&#8217;m editing inside the terminal suddenly sorry I got</p>



<p>Sorry, I got sidetracked.</p>



<p>I wanted to edit all this stuff inside of Genie because it&#8217;s a little bit better.</p>



<p>Maybe it doesn&#8217;t matter.</p>



<p>So notice how we have the main function inside of our first.cpp program,</p>



<p>and then there&#8217;s no main function inside of our other source codes.</p>



<p>For your program that uses the GCC libraries, you need exactly one instance of main.</p>



<p>so that means um you know you have to have at least one and if you have more than one it&#8217;s</p>



<p>probably not going to link so if i put a main inside of here probably not going to work</p>



<p>this also kind of means you can arrange your source code in a funny way you could</p>



<p>have a bunch of different pieces of source code that you could consider maybe libraries maybe</p>



<p>there are a bunch of classes or something that will help your program and you can release multiple</p>



<p>different executable files by just having different source code files each with their own</p>



<p>mains and linked separately against the object files that contain your library or classes or</p>



<p>whatever that&#8217;s just a little side tip but um anyway let&#8217;s see if i actually did this right</p>



<p>we&#8217;re linking this and i&#8217;m going to see if it works i get stuck inside of the terminal i start</p>



<p>thinking i&#8217;m going to edit everything inside there okay so it compiled well let me let me</p>



<p>remove the main and then just clear it again in the list okay so now I&#8217;m gonna</p>



<p>run the compiler and after the compiler ran everything seemed to be okay it</p>



<p>compiled first into its object file and it also compiled second into its object</p>



<p>file if I run the main executable notice how it only prints hello from first dot</p>



<p>CPP well what about the second one that we just added well what we need to do is</p>



<p>improve our linking stage notice how in the linking stage right here we just</p>



<p>stage right here we just only link first.o so we should also include the other object file that we</p>



<p>want i&#8217;m going to glob that in a second but uh let me show you compile now if we run main</p>



<p>what did i do wrong hold on let&#8217;s see here second.c oh i forgot to actually call the second</p>



<p>function so that&#8217;s cool just uh wrote a bunch of stuff for no reason at all let me uh let me have</p>



<p>have the main function call on the second function we&#8217;re going to encounter an issue here too the</p>



<p>second function is written in c and the first function uh its its source code is in c plus plus</p>



<p>and the thing is c plus plus uses something called name mangling i won&#8217;t go over it too much in this</p>



<p>video but it uses name mangling so you can overload functions you can have functions with the same</p>



<p>name but like different signatures right so it&#8217;ll go in there and it&#8217;ll mangle the name of a function</p>



<p>the name of a function according to its overload prototype so that we can actually call overloaded</p>



<p>functions but we don&#8217;t really have that in C so that means if we try to call a C function</p>



<p>from C++ we&#8217;re probably going to end up calling the wrong name because there&#8217;s the expectation</p>



<p>that the other module has name mangling enabled but it&#8217;s not because it&#8217;s C so I just have</p>



<p>to do this little block extern C and just name all the stuff that is not going to be</p>



<p>name mangled i&#8217;ll just provide the prototypes of all the functions that i want to be able to call</p>



<p>so just void second if you look here again we just have void second and now when um when the c plus</p>



<p>plus module calls on second it won&#8217;t expect name mangling so it should work so we&#8217;re calling it</p>



<p>and then we linked it now everything i think should be okay i&#8217;m going to compile one more time</p>



<p>and then i&#8217;m going to run the main program and now you see that we have both calls in there</p>



<p>Awesome. Let&#8217;s give this script a little bit more output though. This is kind of</p>



<p>precarious. What if something failed inside of there? Maybe you don&#8217;t want the script to continue</p>



<p>if something fails and maybe you kind of want to know where the script is at while it&#8217;s compiling.</p>



<p>So I&#8217;m going to upgrade it just a little bit. So compile the source. I&#8217;m just going to say echo</p>



<p>compiling the, you know, compiling burst.cbp. And then here I&#8217;ll just do another echo and I&#8217;ll say</p>



<p>and then here I&#8217;ll say echo linking the executable or the binary aka the binary</p>



<p>I don&#8217;t even know if that&#8217;s the proper term I just like to call these things binaries because</p>



<p>they&#8217;re not in text anyway so if we do another I&#8217;m going to do I&#8217;m going to do a compound</p>



<p>command line here I&#8217;m going to go clear and compile so that I don&#8217;t have to continue to</p>



<p>continue to clear every single time. Now notice how it prints what it&#8217;s doing. So if it kind of</p>



<p>failed somewhere along the way, or if it took a long time, you&#8217;d kind of know what&#8217;s going on.</p>



<p>Now let&#8217;s use a little bash trick, because remember this is a bash script. It&#8217;s not just</p>



<p>going to only execute actual commands. I&#8217;m going to say or exit with the return code of the previous</p>



<p>We&#8217;re going to try to execute G++.</p>



<p>If G++ fails for some reason, then the whole program or the whole script is going to exit</p>



<p>and it&#8217;s going to exit with the return code mentioned here.</p>



<p>I think it&#8217;s not going to print it.</p>



<p>I&#8217;ll show you how to print it in a second, but we can actually make a function called</p>



<p>die up here in a second, which might be better.</p>



<p>So I&#8217;m going to do the same thing over here.</p>



<p>I&#8217;m going to say or exit with the return code of the GCC command and then here or exit with</p>



<p>And then here or exit with the return code of the linking command.</p>



<p>We&#8217;ll do it one more time here.</p>



<p>Notice how it seems to work.</p>



<p>So now let&#8217;s make the first C++ program not actually compile.</p>



<p>I&#8217;ll put a bunch of Zs there.</p>



<p>And so if we try to compile it again, it should just quit right after it tries to compile the C++ program.</p>



<p>So that saves you some time and helps draw your attention to what went wrong.</p>



<p>The C++ compiler is saying hey, there&#8217;s like a type there. It doesn&#8217;t show the exit code though. So let&#8217;s make a function in bash</p>



<p>That will die and print an exit code. So I&#8217;m going to say do die or maybe just die by itself something like that</p>



<p>Functions whoops. I&#8217;m in the wrong language</p>



<p>Let me go back to the compiler</p>



<p>make a function in bash</p>



<p>Called die and it&#8217;ll take one argument and the argument will just be the exit code</p>



<p>that we want it to alert us of.</p>



<p>So I&#8217;m going to say echo,</p>



<p>I&#8217;m going to say we are dying now.</p>



<p>Previous exits code was,</p>



<p>maybe I&#8217;ll do a little variable here,</p>



<p>I&#8217;ll do a local variable.</p>



<p>Exit code is going to be the first incoming argument.</p>



<p>This is a bash program, not C++.</p>



<p>And then here I can just say exit code.</p>



<p>Okay.</p>



<p>So then after writing all that,</p>



<p>then after writing all that I can say or die and then just you know so I&#8217;m calling</p>



<p>a function and the first argument I&#8217;m giving it is the actual exit code of the</p>



<p>thing that died so we&#8217;re just kind of like using indirection to print a pretty</p>



<p>pretty message to get a little bit more information so we&#8217;ll try that one more</p>



<p>time notice how it says we are dying now previous exit code was one so that just</p>



<p>that just tells us that gcc exited with the exit code of one not super useful but it&#8217;s nice to see</p>



<p>could be something else entirely like i don&#8217;t know maybe uh maybe we misname the first source</p>



<p>code file let&#8217;s see if the code changes i think it probably will nope maybe this exit code was one</p>



<p>no such file or directory all right exit code am i doing something wrong i guess i&#8217;m all right</p>



<p>Alright, okay, so let&#8217;s just move on.</p>



<p>I wanted it to be fancier.</p>



<p>We could also upgrade a little bit if we wanted to.</p>



<p>Instead of echoing, I could make a function called log here,</p>



<p>and I could just say that the log command just echoes,</p>



<p>and maybe we&#8217;ll put a cute label, and we&#8217;ll say, you know,</p>



<p>my super cool program compiler, or how about super cool compiler?</p>



<p>And then just do the $1, because that&#8217;s the first incoming argument that you get.</p>



<p>the first incoming argument that you get now I can type log instead of echo so</p>



<p>that&#8217;s nice and why would you want to do this well now it&#8217;s gonna go inside of a</p>



<p>function which means later on you can start adding extra commands like logger</p>



<p>a log to the system daemon oh no so this would write to your system log in</p>



<p>addition to printing something you could do anything you want you know it&#8217;s just</p>



<p>like a regular program adding more power by sticking everything inside of</p>



<p>functions I&#8217;m gonna put log here and let&#8217;s see if it works</p>



<p>let&#8217;s see if it works pile okay nice notice how we have a little message with a little header which</p>



<p>seems pretty cool maybe instead of echoing here let&#8217;s make a complaint function let&#8217;s do a</p>



<p>complain and same thing as the echo function but maybe I think there&#8217;s a flag where you can tell</p>



<p>echo to print to standard error instead of standard output but I&#8217;m just going to do it the easy way</p>



<p>it the easy way I&#8217;m going to say one goes to two so that the the first pipe standard output is going</p>



<p>to be redirected into the second pipe standard error so now I can use complain instead of um</p>



<p>echo down here complain before I die oh I forgot to actually</p>



<p>or die I forgot to actually exit so that means it was oh yeah it&#8217;s still compiling everything</p>



<p>Let me fix that.</p>



<p>So in the actual die function, hopefully you were at home cringing along with me.</p>



<p>Let&#8217;s see, let&#8217;s exit with the actual exit code that was specified just to make things</p>



<p>a little bit more automatable.</p>



<p>Yeah, now it stops right away.</p>



<p>And the complainer is like, you know, pretty cool.</p>



<p>Let me fix the first source code real fast.</p>



<p>And we&#8217;ll say that the second source code is broken.</p>



<p>We&#8217;ll put a bunch of Z&#8217;s there.</p>



<p>So now the first one compiles, the second one, it breaks.</p>



<p>And we&#8217;re starting to, you know, get a hang for a compiler script that&#8217;s a lot more sophisticated</p>



<p>than just typing things on the command line, right?</p>



<p>You can take this as far as you want.</p>



<p>The next step above this is using a proper build engine.</p>



<p>So let&#8217;s see.</p>



<p>Well, let&#8217;s do another source code.</p>



<p>an assembly source code. So we&#8217;ll say third dot ASM and it&#8217;s just going to be Yasm. This is not</p>



<p>a Yasm or assembly tutorial. I&#8217;m just showing you how to, you know, build a, you know, compile,</p>



<p>link and execute. We&#8217;ll make a data section so I can just stick some defines in here real fast.</p>



<p>I&#8217;ll say system write is going to be equal to a one and then the file descriptor for std out</p>



<p>Do you ever feel like red jumps out at you on the screen?</p>



<p>Does that mean I have eye problems?</p>



<p>I am kind of old now.</p>



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



<p>Hello from third dot ASM and I&#8217;ll just put a little new line there.</p>



<p>So I don&#8217;t have to do it elsewhere.</p>



<p>And then I&#8217;ll have to specify the magic message length because this is not a sophisticated program that can loop through the message looking for a null terminator.</p>



<p>And then I&#8217;ll do a text section, which is where your code goes.</p>



<p>which is where your code goes and you know in hybrid programs if I have this</p>



<p>third function which is marked as a which is marked using a label and then</p>



<p>in return statement I still have to mark a third as being accessible outside</p>



<p>this module so I&#8217;m going to do the global statement and then I&#8217;m just going</p>



<p>to do really quickly I&#8217;m going to move something into RAX it&#8217;s going to be</p>



<p>system right so basically I would like to write something somewhere to some</p>



<p>some file descriptor its first argument wants where I want to write it so I&#8217;m</p>



<p>gonna write it to the standard output instead of an actual file and then I&#8217;m</p>



<p>gonna move RSI the next argument is going to be the actual message or a</p>



<p>pointer to the message that I defined above and you know check out my other</p>



<p>videos if you want to learn assembly that&#8217;s this is not this is not an</p>



<p>assembly learning video I&#8217;m just kind of doing it real fast in case you&#8217;re</p>



<p>probably unless I ruined it somehow let&#8217;s start compiling or assembling the</p>



<p>assembly program so just one more we&#8217;ll say assemble the assembly source or</p>



<p>module or whatever you want to call it we&#8217;re going to use the ASM to do that</p>



<p>G dwarf 2 is the debugging symbols not necessary in this video the format is I</p>



<p>want a 64-bit executable that&#8217;s how you do it in Yasm and I&#8217;m going to give it</p>



<p>and I&#8217;m going to give it an input of just the third assembly source file.</p>



<p>And I want it to output the third object file.</p>



<p>I got to remind myself to glob line 36 after this or die with the exit code.</p>



<p>Okay. So now this might work.</p>



<p>Oh, I got to put, I got to put third dot O in the linking stage.</p>



<p>I&#8217;m going to do clear and I&#8217;m going to go here and compile.</p>



<p>and compile.</p>



<p>Unrecognized debug format, dward.</p>



<p>Why didn&#8217;t you stop me?</p>



<p>It&#8217;s g dwarf.</p>



<p>Let&#8217;s see, what did I do wrong?</p>



<p>g dwarf, oh, dwarf dash two.</p>



<p>Oh, it&#8217;s not even g, it&#8217;s just dwarf two.</p>



<p>Sorry.</p>



<p>And I got to put a dash, I think, for EASM.</p>



<p>Yeah, okay.</p>



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



<p>What did I do wrong?</p>



<p>Oh no no, Yasm doesn&#8217;t need the dash, but GCC wants the dash.</p>



<p>Okay, I had it right the first time.</p>



<p>Doop doop doop, okay, so it probably linked.</p>



<p>Let me run it and see what happened.</p>



<p>Hello from the second, oh, we still have to actually call it from the C++ module.</p>



<p>So now we&#8217;ll do the same thing.</p>



<p>We&#8217;ll say that the assembly module, it&#8217;s not going to use name mangling.</p>



<p>use name mangling there&#8217;s no overloads so we&#8217;re going to put it into the extern C</p>



<p>block and we&#8217;ll just say you know void third how do we know that&#8217;s that it&#8217;s a</p>



<p>void function with no arguments well you know that&#8217;s just a convenience that</p>



<p>happens under the hood with C and C++ in assembly it&#8217;s just a label that you&#8217;re</p>



<p>jumping to and returning from void means return type all that means is I&#8217;m</p>



<p>trying my best not to make this a C++ or an assembly tutorial but all that</p>



<p>All that means is there is no return value getting returned.</p>



<p>That would be the RAX register if I wanted to move something in there.</p>



<p>And then similarly, if I wanted to catch arguments, I&#8217;d be grabbing from other registers.</p>



<p>So I&#8217;m not grabbing any register, any arguments from registers, and I&#8217;m not sending a value back with RAX or XMM0 or anything.</p>



<p>So that just means it&#8217;s void and no arguments.</p>



<p>So let&#8217;s do it again.</p>



<p>Compile it and then run main.</p>



<p>then run main hello from second oh i sure put in the name mingling thing but i forgot to call it</p>



<p>let me do that third so now one more time compile and then run it</p>



<p>what&#8217;s happening in here</p>



<p>third i guess i should probably open this up now third asm so global third and then third oh</p>



<p>important part of a system call you got to put the keyword or the instruction system call in there</p>



<p>one more time i hope you&#8217;re laughing and cringing at home trying to make this more fun maybe i don&#8217;t</p>



<p>know okay so now it&#8217;s all it&#8217;s all working notice how we have a bunch of different modules in</p>



<p>different languages we&#8217;re compiling them all to object files first and we&#8217;re uh we&#8217;re linking</p>



<p>them all into one executable and we&#8217;re doing this in a really really easy way by using a script</p>



<p>script instead of typing all the commands out manually. Pretty convenient, right? Let me give</p>



<p>you another upgrade real fast here. So this is kind of irritating. I have like all of these object</p>



<p>files that I have to specify. What if I forget to specify some? Since this line 36 is just going to</p>



<p>be something that goes directly, you know, to the shell as a command line. This is not like bash</p>



<p>wildcards I can say star dot o meaning I&#8217;m going to give every object file to</p>



<p>the linker as an input file and that should just work automatically keep in</p>



<p>mind if you want to use an advanced strategy like I mentioned earlier where</p>



<p>you have multiple different object files and they&#8217;ve each got their own main</p>



<p>functions because they&#8217;re each going to be their own separate executables then</p>



<p>globbing all object files probably not going to work you might want to organize</p>



<p>files or stick the object files for executables in like their own folders or</p>



<p>something like that we&#8217;re not going to go that far but I just want you to know</p>



<p>so let&#8217;s do that again real fast here we&#8217;ll say clear and compile and I&#8217;ll</p>



<p>just try to like run main assuming that the compiler works yes so it worked</p>



<p>everything compiled by the way this and end that means only execute the next</p>



<p>So if I, you know, clear is obviously going to succeed and then compile, it might succeed</p>



<p>or not.</p>



<p>Then I&#8217;m going to try to run main.</p>



<p>Let me actually, let me actually do that real fast.</p>



<p>Let me show you what I&#8217;m talking about.</p>



<p>I&#8217;m going to remove main.</p>



<p>You&#8217;re okay.</p>



<p>So then I&#8217;m going to do clear and compile and main.</p>



<p>So obviously if everything works, then everything works.</p>



<p>But if I do that again, where something is not actually going to compile, like maybe</p>



<p>the second the c source program is not going to compile by putting some z&#8217;s in there then the</p>



<p>dot main or yeah that part shouldn&#8217;t get executed so it won&#8217;t try to execute our program</p>



<p>notice how it just stops so that&#8217;s convenient if i do it again though with a different command</p>



<p>if i chain instead of between the commands instead of putting and end to say one must execute before</p>



<p>semicolon then they will all execute no matter whether whether they succeeded or not maybe in</p>



<p>certain things you&#8217;re doing you actually want that behavior but in this case it&#8217;s going to be bad</p>



<p>watch what happens it fails to compile and then at the end it also tries to run a program that</p>



<p>doesn&#8217;t exist because it never got linked because the script stopped so i&#8217;m just letting you know</p>



<p>you have lots of different options when you&#8217;re writing these scripts we do it again and then let</p>



<p>And I think, well, maybe there&#8217;s one other thing I want you to know.</p>



<p>Sometimes these lines get really, really long, right?</p>



<p>And it&#8217;s messy and irritating.</p>



<p>At least for me.</p>



<p>Maybe if it goes off the side of the screen for you, it&#8217;s like, oh, that&#8217;s awful.</p>



<p>You can actually just separate a command across multiple lines with a backslash.</p>



<p>Or sorry, I think that is called a forward slash.</p>



<p>It&#8217;s the drive slash.</p>



<p>I don&#8217;t remember forward slash backslash.</p>



<p>I just say web slash and drive slash.</p>



<p>So I&#8217;m going to do G++ and do a little slash.</p>



<p>Then I can put the whole rest of the thing on the next line.</p>



<p>If I wanted to, I could start separating these out by category.</p>



<p>So maybe I&#8217;m like, oh, I don&#8217;t know.</p>



<p>Maybe M64 on its own line.</p>



<p>And then I&#8217;ll keep these other two on their own line.</p>



<p>And maybe these two on their own line.</p>



<p>You know, it&#8217;s up to you how you organize this.</p>



<p>And then I&#8217;ll say, give me all the input files on its own line.</p>



<p>And then the output file on another line.</p>



<p>on another line you could even put the or bars for the die part on its own line I</p>



<p>guess I&#8217;ll just try that and now let&#8217;s just make sure that this still compiles</p>



<p>let me remove star dot o and remove main it&#8217;s not there okay so clear and then</p>



<p>list and then two showed up somewhere oh my mistake I probably should have caught</p>



<p>some file got saved as a two I should have noticed okay so let&#8217;s do clear and</p>



<p>compile and I just run main okay so now everything works notice how even though</p>



<p>everything was on a different line it all just seemed to work cool what about</p>



<p>something here on line 38 we&#8217;re using the C++23 standard but we&#8217;re also doing</p>



<p>that up here and we&#8217;re also using the all warnings flag up here and down here</p>



<p>and pedantic also and even the linker like what if I want to put all warnings</p>



<p>into the linker we could make variables in bash and by the way this is totally</p>



<p>starting to become a job for for mark for make files but for now we&#8217;re just</p>



<p>stay in bash so I can make a variable in bash I can say maybe GCC flags name it something and I&#8217;ll</p>



<p>just put equals whatever and I&#8217;ll just type the stuff that I know is going to appear in every</p>



<p>single invocation of G++ or GCC so I&#8217;m going to go wall because I want to put that everywhere</p>



<p>and I&#8217;m going to say C++23 because I&#8217;m going to put that everywhere and probably pedantic I&#8217;m</p>



<p>I&#8217;m not going to put the dash C flag everywhere because notice how I&#8217;m only putting that on the compiler commands when I just want to make an object file.</p>



<p>But when I&#8217;m linking, there&#8217;s no dash C because that means you got to actually link.</p>



<p>So let&#8217;s see.</p>



<p>We got G dwarf two, G dwarf two.</p>



<p>Maybe I could put G dwarf two there and see if it still works.</p>



<p>So I want debugging symbols and I want them to be in dwarf dash two format, which honestly is the default format.</p>



<p>which honestly is the default format if you just put dash G.</p>



<p>Let&#8217;s see if I can get away with that for now.</p>



<p>So I&#8217;m going to go GCC flags.</p>



<p>And here I can get rid of C++23 and wall and pedantic.</p>



<p>And I&#8217;ll just insert instead GCC flags.</p>



<p>And if you want to be extra careful,</p>



<p>you can put these little braces around the variable name of that.</p>



<p>Probably should be fine.</p>



<p>But because I don&#8217;t want to type that again,</p>



<p>I&#8217;m just going to copy paste it into the other command.</p>



<p>So wall pedantic, just paste that.</p>



<p>Just paste that and then I&#8217;m going to leave it alone for Yasm because Yasm is different than GCC.</p>



<p>And then here I&#8217;m going to do another line where I just kind of put the flags.</p>



<p>That means I can get rid of those two flags.</p>



<p>And then wall and pedantic are going to show up.</p>



<p>No pi is kind of a linker only thing.</p>



<p>So is the no exec stack.</p>



<p>I think probably that will be okay.</p>



<p>Let&#8217;s see if I got that right or wrong.</p>



<p>Oh no.</p>



<p>Unrecognized command line option.</p>



<p>Wall pedantic GCC.</p>



<p>Oh, I guess because I quoted it.</p>



<p>I shouldn&#8217;t have done that.</p>



<p>Because I quoted it, the command line thought that that was all one argument.</p>



<p>I should have remembered.</p>



<p>So I&#8217;m going to unquote it right now.</p>



<p>This should help the command line understand that all of the things inside of that variable,</p>



<p>the GCC flags, are separate arguments instead of just one argument.</p>



<p>Let me try one more time.</p>



<p>Yay, it seems to work.</p>



<p>Okay, we got a warning here.</p>



<p>Command line option C++23 is valid for object,</p>



<p>but not for C.</p>



<p>Okay, so basically I made the mistake</p>



<p>of trying to send a C++ object,</p>



<p>which is this right here, or sorry,</p>



<p>a C++ argument, which is this right here,</p>



<p>into a C compiling command.</p>



<p>Not great.</p>



<p>So what if I did this?</p>



<p>I&#8217;ll do C flags, and it will contain only flags for C,</p>



<p>for C and then I&#8217;ll have another one for C++ flags</p>



<p>which will only contain things that are for C++ compiling so the regular C compiling can take</p>



<p>wall and pedantic okay and then it can take the G dwarf 2 okay the C++ flags it can take everything</p>



<p>except for um sorry the C++ flags can actually take all of the C flags and then additionally the</p>



<p>and then additionally the the c++ 23 flag so i could embed a variable inside of itself i could</p>



<p>say c flags or sorry i could embed a variable inside of another variable so that i can just</p>



<p>steal all of the flags from the c flags variable stick them also in the c++ flags variable and</p>



<p>then just add one more at the end of that hopefully that works i think it probably will</p>



<p>here and then use the C flags here just for compiling I could probably name the</p>



<p>variable better put the word compile in there or something but I don&#8217;t really</p>



<p>want to I think some people put CC to mean like C compiling but I don&#8217;t know I</p>



<p>just want to do it this way so we have that and then we&#8217;re gonna do CPP flags</p>



<p>like this we could also organize the variables differently so that the we</p>



<p>We could have some linker flags, which basically would probably have all of this stuff minus dash C.</p>



<p>And then we could have linking flags.</p>



<p>No, we can have linking flags that has all that stuff minus the C.</p>



<p>And then we&#8217;ll have like some compiler flags that has the linking flags plus the dash C.</p>



<p>But I don&#8217;t really want to spend a bunch of time on this now.</p>



<p>For now, we&#8217;ll just say we have C flags and CPP flags.</p>



<p>And we&#8217;ll just manually add that dash C.</p>



<p>But of course, keep in mind, you can organize these things any way you want.</p>



<p>and organize these things any way you want.</p>



<p>So I&#8217;m gonna do,</p>



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



<p>I&#8217;m getting distracted.</p>



<p>I think it works.</p>



<p>Okay.</p>



<p>Let me just double check by removing all the object files.</p>



<p>There&#8217;s a two in there still.</p>



<p>Let&#8217;s debug that if it happens again,</p>



<p>then I&#8217;m gonna remove main.</p>



<p>Okay, then I&#8217;m just gonna list everything real fast.</p>



<p>Okay, let&#8217;s see.</p>



<p>Is there gonna be a two in there now?</p>



<p>Is there going to be a two in there now?</p>



<p>No, is that only when it fails?</p>



<p>Only when something fails to compile?</p>



<p>I mean, it&#8217;s working, so that&#8217;s good news.</p>



<p>You know what?</p>



<p>Leave a comment somewhere letting me know</p>



<p>where you think I went wrong with this two,</p>



<p>and maybe I&#8217;ll release another video</p>



<p>or something in the future,</p>



<p>at some distant point in the future.</p>



<p>But yeah, anyway, I hope you learned a lot of stuff</p>



<p>in this video and you had a little bit of fun too.</p>



<p>had a little bit of fun too. This has been, you know, a little intro for compiling, linking</p>



<p>and executing in Linux, but also probably on a bunch of other systems if you have these</p>



<p>same tools, and you&#8217;re working inside of bash. Thank you so much for watching this video.</p>



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



<p>of my heart i really appreciate it i do hope you did learn something and have some fun if you could</p>



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



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



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



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



<p>Do me a kindness and and subscribe. You know sometimes I&#8217;m sleeping in the middle of the night</p>



<p>And I just wake up because I know somebody subscribed or followed it just wakes me up and I get filled with joy</p>



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



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



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



<p>Also, uh, if you look at the middle of the screen right now</p>



<p>You should see a QR code which you can scan in order to go to the website</p>



<p>go to the website which i think is also named somewhere at the bottom of this video and it&#8217;ll</p>



<p>take you to my main website where you can just kind of like see all the videos i published and</p>



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



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



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



<p>wake up for those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like</p>



<p>it would really it really mean the world to me i would really appreciate it so again thank you so</p>



<p>much for watching this video and um enjoy the cool music as as i fade into the darkness which is</p>



<p>coming for us all</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/compile-link-execute-a-beginners-guide-to-linux-programming-with-c-c-and-assembly/">Compile, Link, Execute: A Beginner’s Guide to Linux Programming with C++, C, and Assembly</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/compile-link-execute-a-beginners-guide-to-linux-programming-with-c-c-and-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>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>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>Thanks for watching!</p>



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



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



<p>Please help support us!</p>



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



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



<li>Subscribing to our Blog</li>



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



<p>Hey there, I&#8217;d like to talk to you today about the basics of Git and what is Git.</p>



<p>Git is an awesome system that you can use to track changes to all your code as you write</p>



<p>programs and work on things. And in fact, you can use Git for tracking changes to a wide variety of</p>



<p>documents, not just code only. There&#8217;s a special tool that I used a while back where I could track</p>



<p>used a while back where I could track changes to just regular office documents.</p>



<p>But if you&#8217;re writing text files of some sort or even like, I don&#8217;t know, making SVG graphics</p>



<p>files or something like that, you can track changes to all sorts of stuff. Okay, so it&#8217;s</p>



<p>mostly for coding. So what is Git and why would you want to use Git? Okay, so we talked about</p>



<p>Git being a code versioning system. It will track your changes. Imagine this.</p>



<p>Imagine you&#8217;re writing code and you spend all day, maybe like all month writing a really,</p>



<p>really good algorithm or a really good function or something like that.</p>



<p>And then maybe a year later, you haven&#8217;t been using it.</p>



<p>And you kind of think to yourself, you know, whatever happened to that giant function that</p>



<p>I wrote, that was really good.</p>



<p>And then you realize, oh no, I accidentally, I think I deleted it like several months ago</p>



<p>because I thought I didn&#8217;t need it anymore.</p>



<p>I didn&#8217;t need it anymore.</p>



<p>And now I&#8217;ve changed my mind.</p>



<p>I wish I had that back.</p>



<p>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>or maybe your backup is just, you know, only a few snapshots deep or whatever.</p>



<p>And so you&#8217;re kind of screwed, right?</p>



<p>So one way that Git can help you is Git lets you look back in time to the state of your</p>



<p>code at any other previous point.</p>



<p>Like every time you make significant progress with your code, you log it in Gits database.</p>



<p>You can just look back in time.</p>



<p>You can look back to see what your code was three years ago.</p>



<p>It&#8217;s awesome.</p>



<p>You can also, you know, revert changes.</p>



<p>You can sort of like branch your code off in two different directions.</p>



<p>Maybe here you&#8217;re just going to be working on bugs and on another branch, you&#8217;re adding</p>



<p>one feature that you think might be a good idea.</p>



<p>a really good idea you could merge that branch into the main branch or if you think that feature</p>



<p>is and is going to be trash and it sucks and you wish you never did it you can just delete that</p>



<p>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>for collaboration because multiple people can can push to the git database and they can get</p>



<p>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>writing a program, I can commit some changes and I can push some changes to the cloud.</p>



<p>And then my colleague can pull my changes and they get everything that I just worked on.</p>



<p>And then they can commit some more changes and push it back up to the cloud.</p>



<p>Then I can pull it.</p>



<p>And so we&#8217;re sort of like collaborating and in a way where every single change is logged,</p>



<p>your boss can look at, or you, you know, you can look at all the logs in your commit,</p>



<p>in your git commit database and see who changed what you can see what lines were changed when</p>



<p>when they were changes you can see who introduced a bug there&#8217;s a function in</p>



<p>git that is called git blame where you can look at a source code file and you</p>



<p>can see who is responsible for every single line you can bookmark states of</p>



<p>your code you can do so much it&#8217;s wonderful but anyway I just want to</p>



<p>touch on the basics today I hope I&#8217;ve kind of convinced you that git is a</p>



<p>little bit of a good idea I used to just sort of code and then you know do copy</p>



<p>paste as my backup copy and it was okay but when I started using git even by</p>



<p>started using git even by myself without collaborating um it was tremendously valuable</p>



<p>there were many times when i wanted to look back at a previous state of code and git let me do it</p>



<p>many times when i wanted to revert some mistake that i made and git let me do it</p>



<p>okay so you see my terminal here maybe maybe i should reduce the transparency just a little bit</p>



<p>to like maybe like 85 opacity.</p>



<p>That&#8217;s a little bit better.</p>



<p>Okay, so I&#8217;m gonna go into a documents folder.</p>



<p>I&#8217;m gonna go into a temporary folder</p>



<p>and I&#8217;m gonna remove everything that is, whoops.</p>



<p>Okay, that was just something I was working on earlier.</p>



<p>Okay, so I&#8217;m in a folder.</p>



<p>So what is a Git repository?</p>



<p>Actually a Git repository is just a folder</p>



<p>with some extra information inside of it.</p>



<p>Let me see, I don&#8217;t remember if I installed Git on this machine.</p>



<p>I did.</p>



<p>Okay, if you don&#8217;t have Git, you can get it pretty easily with sudo apt install git.</p>



<p>Or if you&#8217;re on Windows or some other operating system, you can just go to Git&#8217;s website.</p>



<p>It&#8217;s git-sem.com or something like that.</p>



<p>You can just find the installer and just get it in there.</p>



<p>But, so let&#8217;s say, let&#8217;s say I want to make a repository.</p>



<p>directory my repository okay so I&#8217;ve got like an empty folder I&#8217;m going to go inside of it</p>



<p>and this is just a folder it&#8217;s not a repo yet I can convert this folder into a repository by</p>



<p>just using the command git init oh gosh here&#8217;s like a message oh you got to choose what branch</p>



<p>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>this you can read them and obey them but they&#8217;re not necessarily mission critical while we&#8217;re just</p>



<p>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>folder inside of there so if i go inside of the git folder i mean this is really not so much for</p>



<p>humans you can kind of do configuration stuff in here but um this is really gets database of</p>



<p>everything it knows about your code you know when you change stuff what&#8217;s the configuration</p>



<p>So if you actually remove this folder, I&#8217;m going to remove the Git folder.</p>



<p>That&#8217;s all it takes.</p>



<p>Now this folder is just a regular folder.</p>



<p>It&#8217;s no longer a Git repository.</p>



<p>So you probably don&#8217;t want to do that once you&#8217;ve initialized it,</p>



<p>but I&#8217;m going to reinitialize this again.</p>



<p>If I had a bunch of history inside that folder,</p>



<p>then it would have been gone already.</p>



<p>But we&#8217;re just learning.</p>



<p>This is just an empty repository.</p>



<p>So I have a Git repository here.</p>



<p>here. First thing I want to do is try to figure out what Git thinks about the repository. So I&#8217;m</p>



<p>going to use the command git status. Whenever you&#8217;re not sure of what&#8217;s going on, if you think</p>



<p>you need to commit something or push something or pull something or whatever, it&#8217;s probably a good</p>



<p>idea to use git status. I use it all the time. Git status and then git will tell you what to do.</p>



<p>It&#8217;s basically telling you that you haven&#8217;t done anything at this point. So that&#8217;s okay.</p>



<p>a readme file in markdown, my, oops, my project.</p>



<p>You don&#8217;t really need to know about markdown to use Git,</p>



<p>although the two kind of go hand in hand on GitHub.</p>



<p>But I&#8217;m just going to say, well, here&#8217;s my project.</p>



<p>This is my super cool project.</p>



<p>Okay, so pretend this is a program, a complicated program.</p>



<p>So I&#8217;m saving it.</p>



<p>We can verify that I actually like put something into that file.</p>



<p>So now I&#8217;m going to ask Git, you know,</p>



<p>you know, what do you think about the state of this repository?</p>



<p>So I&#8217;m going to say git status.</p>



<p>Git is telling me now that we&#8217;re on the master branch</p>



<p>and there are no commits yet.</p>



<p>And I have an untracked file.</p>



<p>This means that the readme file is not considered part of the git repository.</p>



<p>It&#8217;s just sitting in the directory tree.</p>



<p>So I want to add that into my repository so I can start tracking changes.</p>



<p>So I&#8217;m going to say git add and then the name of the file.</p>



<p>What have I done?</p>



<p>Okay, here we go.</p>



<p>What have I done? Okay, here we go.</p>



<p>That&#8217;s not how you spell add.</p>



<p>So now that I&#8217;ve done git add, I can say git status one more time to see what</p>



<p>Git thinks about the state of my repository.</p>



<p>Git says, well, you definitely use the add in order to put the changes on a stage.</p>



<p>Git likes to bunch up changes on a stage before you actually commit things to the</p>



<p>database. The reason for that is maybe</p>



<p>maybe you spend an hour doing a bunch of work in a bunch of different areas of your</p>



<p>different areas of your program, but maybe there&#8217;s only like a few files over here that</p>



<p>are part of a logical change.</p>



<p>Like this is feature a that I was fixing, but you also changed a bunch of other files</p>



<p>that were related to something else like feature B that I was fixing.</p>



<p>It doesn&#8217;t really make sense to take all of those changes and make them one commit because</p>



<p>you want a nice clean commit log that shows exactly what you were working on.</p>



<p>And it makes sense.</p>



<p>you just worked on a bunch of different files,</p>



<p>you can add all the feature A files to the stage first</p>



<p>and then commit that as one change</p>



<p>and then go over to the feature B files</p>



<p>and add those to the stage</p>



<p>and then commit that as a second change.</p>



<p>So it&#8217;s kind of a way to get you out of the mess</p>



<p>you&#8217;ve put yourself in</p>



<p>if you&#8217;ve just been working too long without committing.</p>



<p>You should really do a git commit</p>



<p>every time you make significant progress.</p>



<p>Like, I mean, it depends on where you&#8217;re working</p>



<p>where you&#8217;re working or who you&#8217;re talking to. You definitely don&#8217;t want to commit every line</p>



<p>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>of the month. The sweet spot is somewhere in between. Your boss will probably tell you what</p>



<p>to do. For me personally, every time I fix something, I&#8217;ll make a commit. One thing,</p>



<p>you know, I made significant progress in my program by adding a new feature. One little</p>



<p>feature, I&#8217;m going to commit it. Some people like to do commits at least once a day so that if</p>



<p>to do commits at least once a day so that if they&#8217;re working on a huge new feature, then</p>



<p>they&#8217;ll do like one commit a day. And then they&#8217;ll sort of like call those several commits</p>



<p>part of like a new feature. It&#8217;s up to you. But at this point, we just have the one file</p>



<p>that we made up on the stage. It&#8217;s ready to be committed. We used git status. So git</p>



<p>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>saying we need to commit it. It&#8217;s not saying how. If you want to unstage it, then here&#8217;s</p>



<p>commit command is just git commit now it&#8217;s going to ask me for a commit message this is what you</p>



<p>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>describe what you did you should describe exactly what you did so so what i&#8217;m going to do is for</p>



<p>the commit message i&#8217;m going to just sort of say what i did you can imagine writing something like</p>



<p>i created the readme file it should always definitely describe exactly what you did</p>



<p>um but it seems like a lot of people use uh i guess grammar and and and terseness</p>



<p>just to make the commit message sound like they told somebody to do something so create the readme</p>



<p>file instead of i created the readme file create the readme file so i&#8217;m just going to make that my</p>



<p>commit message save the buffer and then uh now that i&#8217;ve committed the changes i have to ask</p>



<p>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>that the repo is clean, everything looks pretty good.</p>



<p>So that means my changes are recorded in the Git database.</p>



<p>I can now actually use a command called Git log to see what changes have been recorded.</p>



<p>Notice how there&#8217;s only one change.</p>



<p>It&#8217;s just, you know, my name here, when it was changed and then what I did.</p>



<p>There&#8217;s a hash here.</p>



<p>This little hexadecimal string is called a hash.</p>



<p>to show me what happened in any specific commit by saying git show and then I give it a hash</p>



<p>and it&#8217;ll tell me exactly what files were created or changed or deleted or whatever</p>



<p>and there it is right there this will get more interesting in a second let&#8217;s make a change</p>



<p>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>So I&#8217;m going to say git status to find out what&#8217;s going on.</p>



<p>Git says, oh, you made a change there.</p>



<p>It&#8217;s not saying that this file is not part of the database.</p>



<p>It&#8217;s just saying that we made changes.</p>



<p>I want to see the changes that it&#8217;s talking about.</p>



<p>I could say git diff.</p>



<p>And it&#8217;s telling me that I added this line.</p>



<p>My dog is growling at me.</p>



<p>about peeing oh my gosh hang on</p>



<p>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>okay so uh we can use the command git diff to see what our changes are we can also say</p>



<p>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>second line so great back to get status it&#8217;s saying we need to stage that change</p>



<p>so I&#8217;m just gonna say get add and then the name of the file get status again</p>



<p>so that we know what&#8217;s up it&#8217;s saying all right well you just need to commit</p>



<p>the changes on your stage if you&#8217;d like to so yeah sure I&#8217;m gonna say get commit</p>



<p>and I&#8217;m gonna say you know changed the readme or something okay get status</p>



<p>So now if we do git log, there&#8217;s two entries.</p>



<p>Imagine that this happens every single time</p>



<p>somebody makes a significant change.</p>



<p>You know, it&#8217;s just like it goes in the log.</p>



<p>You can figure out who changed what.</p>



<p>Watch this.</p>



<p>Let&#8217;s do cat readme so we can see the readme.</p>



<p>Notice how it&#8217;s got the second line at the end.</p>



<p>I could also go back in time</p>



<p>and see what the state of my project was</p>



<p>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>say git checkout and the commit hash it&#8217;s now telling me something hey by the way now you&#8217;re</p>



<p>looking back in time you should not change anything you&#8217;re on a detached head if you&#8217;re</p>



<p>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>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>But notice if I spill the contents of the README file.</p>



<p>Hang on, what did I do wrong?</p>



<p>Change the README.</p>



<p>Oh, sorry, it&#8217;s in reverse order.</p>



<p>I always forget that.</p>



<p>I copied the wrong hash.</p>



<p>So let me check out the first commit that I made.</p>



<p>So I&#8217;m going to say git checkout the first commit hash.</p>



<p>Okay, now I&#8217;m going to concatenate the,</p>



<p>or I&#8217;m going to spill the contents of the README.</p>



<p>Notice how the readme looks like it did when we first made it.</p>



<p>So we&#8217;ve gone back in time.</p>



<p>Think of how useful this could be if this was a huge, big project with a bunch of files</p>



<p>and a lot of lines per file.</p>



<p>So once again, we&#8217;ll do git, actually let&#8217;s do git status.</p>



<p>Status is reminding me that we&#8217;re on its attached head.</p>



<p>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>onto the master branch or whatever branch you&#8217;re working with before you continue working so we&#8217;ll</p>



<p>status and you can see that we&#8217;re on the master branch.</p>



<p>Then we can say get branch all.</p>



<p>And there we go. Maybe we want to bookmark this.</p>



<p>Maybe we want to remember, oh, this is a perfect state of our of our code.</p>



<p>Maybe this is version one point.</p>



<p>We can do get tag version one point.</p>



<p>Oh, and now we have a bookmark forever.</p>



<p>How can we find the bookmarks?</p>



<p>Well, we can say get tag just by itself, and it&#8217;ll give us a list of our bookmarks.</p>



<p>When we push this to a remote server, the server will be able to show it like</p>



<p>remote server, their server will be able to show it like GitHub or GitLab or whatever.</p>



<p>And then later we can do something like, you know, get checkout and then just check out the</p>



<p>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>a bookmark that&#8217;s a little bit easier to remember. So let&#8217;s look at remotes for a second,</p>



<p>because right now we&#8217;re not pushing code anymore. We&#8217;re just remembering what we changed in our</p>



<p>Okay, so I&#8217;m inside my repository.</p>



<p>And now I&#8217;m going to go up a level on this right pane,</p>



<p>and I&#8217;m going to make a new directory.</p>



<p>But I&#8217;d like to clone the original repository.</p>



<p>Imagine that this repository, it&#8217;s a folder to us,</p>



<p>but it could be for all we know, sitting on a remote server</p>



<p>and accessed with a special URL.</p>



<p>So you can go to like GitHub or somebody&#8217;s server,</p>



<p>and you can copy their get URL for their repository.</p>



<p>repository. Over here in our local file system, we could clone the original repository.</p>



<p>Usually you would have to copy paste like a big get URL, SSH URL or HTTPS URL or whatever.</p>



<p>But you can even do this locally so I can tell get I would like to clone this local repository</p>



<p>denoted by this folder name. And I would like to call it my clone or something. So I&#8217;m gonna say</p>



<p>So I&#8217;m going to say get clone repository my clone.</p>



<p>It says cloning and done.</p>



<p>Now we have two folders.</p>



<p>And if we go inside of the my clone repository,</p>



<p>we should have the same state of code that we just cloned.</p>



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



<p>Now think about collaboration.</p>



<p>We can change our code from the clone.</p>



<p>And as long as the clone has permission to push back up to the remote,</p>



<p>back up to the remote then it actually would work.</p>



<p>So let&#8217;s edit the README file real fast.</p>



<p>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>Okay, so I did that.</p>



<p>And actually just to make things interesting, I&#8217;m going to change my git identity only inside</p>



<p>of this clone.</p>



<p>You can do that in git.</p>



<p>config and you say something like user.name, you know, you can put your name here, your email,</p>



<p>whatever, for like user.email. There&#8217;s this thing that you usually do where you say get config</p>



<p>global. And that means you&#8217;re changing configuration that is account wide. So like</p>



<p>your entire account on this machine is going to be changed when you use that global flag.</p>



<p>But if I don&#8217;t use the global flag, it&#8217;s just changing my configuration for only this one</p>



<p>this one repository so i&#8217;m going to make my name clone dude and make my email</p>



<p>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>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>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>I added something to the readme.</p>



<p>Okay.</p>



<p>Git status.</p>



<p>Notice how git status is saying something a little bit extra this time.</p>



<p>Before, we were just in a local file system only.</p>



<p>And now we&#8217;re working inside of a clone.</p>



<p>So this is like, you know, you clone some code from GitHub</p>



<p>or from your friend&#8217;s server or whatever.</p>



<p>And when you do a clone,</p>



<p>it actually automatically links your local repository</p>



<p>repository to the remote repository. By the way, in Git, everything is considered a local copy. So</p>



<p>it&#8217;s not like you&#8217;re working with something different than the server has. You actually</p>



<p>have the entire Git history and all the code and everything that Git has on the remote,</p>



<p>except for maybe some like configurations or something. But when you pull, you&#8217;re just making</p>



<p>you&#8217;re making a copy later we can push our changes to the server and that just makes</p>



<p>the two repositories talk to each other sort of and reconcile changes and make sure that both sides</p>



<p>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>it says you&#8217;re on the master branch your branch is ahead of origin master by one commit what&#8217;s</p>



<p>origin master you can find out all of your remote connections and get by saying git remote v so when</p>



<p>so when you clone it automatically makes an origin remote it calls it origin and</p>



<p>then it has the URL or in this case just the file path of where the remote is so</p>



<p>it&#8217;s telling you that our remote where we&#8217;re connected to is the my repository</p>



<p>folder that we were at in the left pane so it&#8217;s telling us also if we go back to</p>



<p>just status it&#8217;s telling us that we should use git push to publish my local</p>



<p>my local commits to the remote because at this point we&#8217;re out of sync if uh if somebody else</p>



<p>cloned the remote repository and then made a bunch of changes and then pushed then i would now be</p>



<p>totally out of sync with that new person who cloned and also the remote server and it would</p>



<p>create something called a merge conflict which is like a little bit more advanced than this video</p>



<p>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>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>Hey, I just pushed some code.</p>



<p>You need to pull.</p>



<p>Hey, I&#8217;m about to push.</p>



<p>Hold off a second.</p>



<p>Hey, I just pushed.</p>



<p>If you&#8217;re working on something, you&#8217;ve got to pull my changes before you do a push.</p>



<p>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>and always try to do pulls regularly.</p>



<p>Anyway, so I need to push my code.</p>



<p>I&#8217;m going to say git push.</p>



<p>And it&#8217;s saying, oh gosh, what is it saying?</p>



<p>Oh, okay, okay, okay, okay.</p>



<p>This is going to be a special setup that I have to do.</p>



<p>Let me just very quickly revert what I&#8217;m doing here.</p>



<p>I think I have to…</p>



<p>Oh, I know what to do. I can just make it a little trick.</p>



<p>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>But usually remote servers, they don&#8217;t have a branch checked out.</p>



<p>So you won&#8217;t even see the file system on the remote.</p>



<p>It&#8217;ll actually all look like just this.</p>



<p>There&#8217;s a flag called bear that you can use to make that happen.</p>



<p>But I don&#8217;t really want to go through all the steps right now.</p>



<p>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>dummy branch and then just kind of sit on it for a while.</p>



<p>That way I&#8217;m allowed to push to the master branch.</p>



<p>So I&#8217;m going to say get branch.</p>



<p>This is how you make a new branch.</p>



<p>I&#8217;m going to say dummy or something.</p>



<p>Whoops, got to spell branch, right?</p>



<p>Then get checkout dummy and then get branch all and then get status just to make sure</p>



<p>I&#8217;m now sitting on the dummy branch.</p>



<p>And then this will cure the problem that we had a moment ago where we&#8217;re not</p>



<p>allowed to push to a branch that the remote has checked out.</p>



<p>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>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>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>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>someone who has set them set the repository up properly uh you won&#8217;t have to worry about it so</p>



<p>Forget about that for now.</p>



<p>So I pushed to the remote.</p>



<p>If I do git log over here, there&#8217;s a mix.</p>



<p>It shows, you know, Mike created it and then changed it.</p>



<p>And then the clone dude added something too.</p>



<p>Okay.</p>



<p>So if I say git log, we should now see the history for only the dummy branch.</p>



<p>So that&#8217;s just two things.</p>



<p>And if I say git checkout master, and then I check out and then I look at the log for</p>



<p>I can see all the changes that the other person made.</p>



<p>Pretty cool.</p>



<p>I could also go back into the dummy branch if I wanted to.</p>



<p>I actually used to do this a long time ago before I realized you should do bear repos.</p>



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



<p>Check out dummy.</p>



<p>And then I&#8217;ll say git log just to confirm that the changes aren&#8217;t in there.</p>



<p>So now we have two branches that are kind of diverging a little bit.</p>



<p>the master branch has one more commit than the dummy branch and if we let this go on for far too</p>



<p>long it might be more of a hassle to make the branches merge again but i&#8217;m just going to merge</p>



<p>them right now so i&#8217;m going to say git merge verify that you&#8217;re sitting on the correct branch</p>



<p>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>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>It&#8217;s telling me that something happened.</p>



<p>So if I do get branch again one more time, I&#8217;m still on the dummy branch.</p>



<p>But if I do get log, notice how I have that latest log entry.</p>



<p>Pretty cool.</p>



<p>So now I&#8217;m going to go back onto the master branch because I want to do some work here.</p>



<p>This is a little clumsy.</p>



<p>If we&#8217;re talking about a server client paradigm, just bear with me.</p>



<p>Now I&#8217;m going to make another change.</p>



<p>Hi, Mr. Clone.</p>



<p>clone. Can you read this? So I&#8217;m going to make a change that I want the clone person to see.</p>



<p>Git status, git add, the readme. You could also do git commit dash a, but I kind of don&#8217;t like</p>



<p>to because I&#8217;d like to remind myself that the stage is a good idea. Git commit new readme</p>



<p>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>but now in the clone I can say git status it doesn&#8217;t yet know that the that the</p>



<p>remote has changes I could do git pull to actually pull all the changes or I</p>



<p>can do git fetch fetch will sort of talk to the remote and pull the changes into</p>



<p>this repository&#8217;s local copy of the remote.</p>



<p>So if we do git branch all, you&#8217;ll notice that we have a master branch here.</p>



<p>So the master branch is my master branch.</p>



<p>And all these other branches here are local copies of the remotes branch.</p>



<p>So we&#8217;re just making lots and lots of copies.</p>



<p>That&#8217;s kind of how git works.</p>



<p>But now that we did a fetch, that talked to the remote, it grabbed changes.</p>



<p>Now Git understands that we&#8217;re actually behind the remote by one commit.</p>



<p>And it&#8217;s telling us, well, you need to use Git pull to pull all the changes.</p>



<p>Usually you kind of don&#8217;t need to do Git fetch.</p>



<p>If you have a remote, you just say Git pull.</p>



<p>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>actually try to pull all the changes into your branch.</p>



<p>It&#8217;s a more complicated situation.</p>



<p>So if I say Git pull, now inside of my Git log, I have that last change.</p>



<p>that last change that the master gave us.</p>



<p>So this is like a very, very basic workflow for Git</p>



<p>in terms of making changes to your program,</p>



<p>committing the changes, checking out the log,</p>



<p>checking out what was changed,</p>



<p>pushing to a remote and so forth.</p>



<p>The only difference, by the way,</p>



<p>between using a remote that&#8217;s a file system</p>



<p>and using a remote that&#8217;s GitHub</p>



<p>is just what URL you put in clone.</p>



<p>in clone like if i put if i said git clone i put a file path here originally but if i just</p>



<p>put a clone url that github gave me or your friend&#8217;s server gave you right there then it</p>



<p>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>always make sure that you push to the remote so that the server has your changes and if you&#8217;re</p>



<p>using github or another website uh it&#8217;s it&#8217;s usually a really good idea to push and then go</p>



<p>to the website to double check that your changes actually made it.</p>



<p>So we talked about tags and branches.</p>



<p>This video is not going to be for advanced branching strategies,</p>



<p>but there are lots of cool resources you can check out.</p>



<p>Actually, you know what? I&#8217;m going to pull one up. Let&#8217;s see.</p>



<p>I&#8217;m going to edit this out if it ends up being like a really bad search result.</p>



<p>Get branching strategy.</p>



<p>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>I think this month no that&#8217;s not the link I remember I should have bookmarked it but there</p>



<p>are lots of different strategies for how and why you would want to use um branches let&#8217;s see one</p>



<p>of these has a good diagram this is it this is not the same web page but I think this website</p>



<p>diagram that I remember.</p>



<p>So we&#8217;ve been on the master branch.</p>



<p>That&#8217;s like the right side here.</p>



<p>You know, this little, these little blue dots.</p>



<p>Imagine that every single time you want to create a new feature,</p>



<p>you just create a branch and you name it after the feature that you&#8217;re creating.</p>



<p>I think I mentioned that before that allows you to sort of keep working on the</p>



<p>master branch independently of the feature that you&#8217;re working on.</p>



<p>And then later when you&#8217;re sure you want to merge the feature into the master</p>



<p>branch, then you just use a get command to make the two branches merge.</p>



<p>command to make the two branches merge.</p>



<p>Or if the feature turns out to be a bad idea, you can just delete the branch.</p>



<p>Usually, at minimum, most people will do something like this.</p>



<p>They&#8217;ll have a development branch.</p>



<p>So here you can see the yellow dots.</p>



<p>That&#8217;s development.</p>



<p>And what they&#8217;ll do is they&#8217;ll make all of their commits to the development branch.</p>



<p>And then only whenever the program is in a really good state, like it&#8217;s sort of presentable,</p>



<p>you can actually release it.</p>



<p>let your friend run the code or whatever, then you&#8217;ll merge the dev branch into the master branch</p>



<p>without deleting the dev branch. So you&#8217;ll merge the dev into master every time the code is in a</p>



<p>really good state. And then you&#8217;ll come back on to dev to continue developing. I think most people</p>



<p>call it develop. Actually, I call it dev for mine. And that way, the master branch usually only ever</p>



<p>is in a state that is good that people could clone from and just compile the program or use the</p>



<p>or use the program or whatever.</p>



<p>And that is in addition to adding tags</p>



<p>whenever you think the master branch is in a state</p>



<p>that you think is like a significant release.</p>



<p>So like version 1.0 or 1.2 or whatever.</p>



<p>So branches for development</p>



<p>where you&#8217;re always there most of the time.</p>



<p>Branches for feature when you&#8217;re kind of experimenting</p>



<p>and trying to figure out</p>



<p>if you&#8217;re going to be able to add something.</p>



<p>Branches for, there&#8217;s a branch for the master</p>



<p>where it&#8217;s like this is the state</p>



<p>that the public should see,</p>



<p>the state that actually works.</p>



<p>actually works. And then, you know, you might do a temporary branch for a hot fix.</p>



<p>And sometimes people will do a new branch for a future release. Like if you&#8217;re going to release</p>



<p>version 2.0, you might make a new branch and call it version 2.0 and then just work on that and</p>



<p>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>And as soon as you think that the feature branch is perfect for your release, sorry, not</p>



<p>Sorry, not feature branch.</p>



<p>Release branch is great for your release.</p>



<p>Then all at once, you&#8217;ll merge that whole thing into master.</p>



<p>You don&#8217;t have to do it that way.</p>



<p>It doesn&#8217;t have to be that complicated,</p>



<p>but sometimes it can be that complicated.</p>



<p>For me personally, I usually just do a development branch</p>



<p>and a master branch.</p>



<p>And then sometimes when I&#8217;m taking a risk,</p>



<p>I&#8217;ll make a feature branch for the new thing that I&#8217;m trying.</p>



<p>So I just kind of wanted to show you that for branching.</p>



<p>for branching and</p>



<p>we talked about pulling and pushing and cloning</p>



<p>yeah so just uh i guess one more warning to make sure that you don&#8217;t</p>



<p>end up with merge conflicts when you&#8217;re collaborating with other people</p>



<p>or even actually this happens to people who work by themselves and they just</p>



<p>switch computers a lot make sure that when you first sit down</p>



<p>and you&#8217;re about to start coding you always pull</p>



<p>team of people communicate with them and tell them you&#8217;re about to pull tell them you&#8217;re about</p>



<p>to start working on something tell them tell them what you&#8217;re about to start working on unless you</p>



<p>have like a manager who&#8217;s telling you exactly what to work on then it&#8217;s their problem um</p>



<p>and then do your get pull and then work and then every time you make significant progress</p>



<p>do a commit and then tell everybody i&#8217;m about to push and then push and then make sure that you</p>



<p>So if you go on your lunch break, make sure you push before you go on your lunch break.</p>



<p>And when you come back from your lunch break, make sure you pull right away.</p>



<p>Because if you don&#8217;t pull and push enough, you&#8217;re either going to get merge conflicts</p>



<p>on your end or you&#8217;re going to cause other people to get merge conflicts.</p>



<p>And sometimes it takes a lot of time to resolve the merge conflicts.</p>



<p>So you really don&#8217;t want to deal with that.</p>



<p>And then a beginner&#8217;s tip, or I guess like maybe like an easy tip.</p>



<p>I do this actually sometimes.</p>



<p>up totally forgetting to push and pull and you do a lot of code and you kind of like wreck everything</p>



<p>and you don&#8217;t want to deal with a gigantic merge conflict resolution type of situation sometimes</p>



<p>it&#8217;s easier to just copy paste your folder somewhere else rename it remember a git repository</p>



<p>locally it&#8217;s just a folder so you can copy paste it or rename it or whatever you want to do</p>



<p>you just kind of copy paste it somewhere and then perform a fresh clone from the remote</p>



<p>then there&#8217;s not going to be a merge conflict because the fresh clone is going to be directly</p>



<p>from the remote which is not conflicted on its own then you&#8217;ll have your fresh clone and then</p>



<p>you&#8217;ll have your little backup copy of what you just screwed up then you can manually inspect the</p>



<p>difference between the fresh clone and then the thing that you just screwed up or you can just</p>



<p>start copy pasting some of your changes and then do like a commit and then do push and then it</p>



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



<p>I will see you in the next video.</p>



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



<p>appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p>a small little favor, could you please subscribe and follow this channel or these videos or</p>



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



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



<p>So we&#8217;ll be able to do more videos longer videos better videos or just I&#8217;ll be able to keep making videos in general</p>



<p>so please do do me a kindness and</p>



<p>And subscribe you know sometimes</p>



<p>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>And I get filled with joy. That&#8217;s exactly what happens every single time</p>



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



<p>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>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>you should see a qr code which you can scan in order to go to the website which i think is also</p>



<p>named somewhere at the bottom of this video and it&#8217;ll take you to my main website where you can</p>



<p>just kind of like see all the videos i published and the services and tutorials and things that i</p>



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



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



<p>send me a comment whatever i also wake up for those in the middle of the night i get i wake</p>



<p>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>appreciate it so again thank you so much for watching this video and um enjoy the cool music</p>



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



<p>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>
		<item>
		<title>How to Convert Decimal to Hexadecimal: Fun &#038; Easy Guide for Beginners</title>
		<link>https://www.NeuralLantern.com/how-to-convert-decimal-to-hexadecimal-fun-easy-guide-for-beginners/</link>
					<comments>https://www.NeuralLantern.com/how-to-convert-decimal-to-hexadecimal-fun-easy-guide-for-beginners/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 13 Apr 2025 00:54:33 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Conversions]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[beginner programming]]></category>
		<category><![CDATA[binary to hex]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding tips]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[decimal to hexadecimal]]></category>
		<category><![CDATA[hex explained]]></category>
		<category><![CDATA[hexadecimal conversion]]></category>
		<category><![CDATA[learn to code]]></category>
		<category><![CDATA[math for coding]]></category>
		<category><![CDATA[number systems]]></category>
		<category><![CDATA[programming basics]]></category>
		<category><![CDATA[tech tutorials]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=88</guid>

					<description><![CDATA[<p>"Hexadecimal uses 0-9 and A-F to represent 16 values, making it shorter than binary. Learn to convert decimal to hex with this fun, step-by-step guide!</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-convert-decimal-to-hexadecimal-fun-easy-guide-for-beginners/">How to Convert Decimal to Hexadecimal: Fun &amp; Easy Guide 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-wp-embed is-provider-rumble-com wp-block-embed-rumble-com"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="How to Convert Decimal to Hexadecimal: Fun &amp; Easy Guide for Beginners" src="https://rumble.com/embed/v6ptsuf/#?secret=pWTtkdDlLf" data-secret="pWTtkdDlLf" width="1000" height="563" frameborder="0"></iframe>
</div></figure>



<p>Want to master decimal-to-hexadecimal conversion? Join me in this fun, beginner-friendly tutorial where we break it down with clear examples?like turning 223 into 0xDF! From number systems to handy calculator tricks, I?ll guide you step-by-step, no stress. Bonus: my dog makes a cameo! Perfect for coding newbies or anyone curious about hex. Subscribe for more easy tech tutorials, and let me know what you want to learn next! #DecimalToHex #CodingBasics #LearnToCode</p>



<p>Introduction 00:00:00<br>Number Systems Overview 00:00:12<br>Decimal vs. Hexadecimal 00:00:39<br>Hexadecimal Digits Explained 00:01:06<br>Conversion Process Introduction 00:01:40<br>First Conversion Example Start 00:02:10<br>Handling Remainders 00:02:38<br>Dog Interruption 00:03:16<br>Continuing First Conversion 00:03:43<br>Finalizing First Conversion 00:06:04<br>Reversing Digits Order 00:06:24<br>Mapping Numbers to Hex Letters 00:07:34<br>Verifying First Conversion 00:08:48<br>Hexadecimal Prefix Importance 00:10:57<br>Second Conversion Example (223) 00:11:34<br>Third Conversion Example (2816) 00:13:32<br>Hex and Binary Relationship 00:14:56<br>Padding Zeros in Hex 00:16:07<br>Video Conclusion 00:16:58</p>



<p>Thanks for watching!</p>



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



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



<p>Please help support us!</p>



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



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



<li>Subscribing to our Blog</li>



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



<p>Hello there.</p>



<p>Let&#8217;s talk about converting decimal to hexadecimal.</p>



<p>Hopefully you&#8217;ve watched my other videos by now, but basically we have different number</p>



<p>systems, number bases that we can use.</p>



<p>We have decimal, which is a base 10.</p>



<p>which is base 10 or sorry base 16.</p>



<p>We can basically convert back and forth between all of these systems.</p>



<p>We can represent the exact same number just in different ways.</p>



<p>Just as a quick refresher.</p>



<p>Decimal, we can have characters that are 0 through 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.</p>



<p>That&#8217;s 10 total characters.</p>



<p>That&#8217;s why it&#8217;s base 10.</p>



<p>In binary, we have, you know, just characters 0 and 1.</p>



<p>characters 0 and 1 and in hexadecimal it&#8217;s meant to compact the representation a little bit it has</p>



<p>more characters or more possible characters per digit than decimal so the number is going to be</p>



<p>a little bit shorter usually unless it&#8217;s like very very small than decimal and it&#8217;ll be a lot shorter</p>



<p>than the same number in binary so in hexadecimal we start off with 0 1 2 3 4 5 6 7 8 9</p>



<p>three, four, five, six, seven, eight, nine.</p>



<p>And then to get the remaining digits, we just go A, B, C, D, E, F.</p>



<p>So we have this many characters.</p>



<p>It&#8217;s 16 total characters.</p>



<p>We can represent a number between 0 and 15.</p>



<p>So that&#8217;s a difference between, you know, hexadecimal and decimal.</p>



<p>Now let&#8217;s learn how to actually convert.</p>



<p>So I&#8217;m going to start off with a number.</p>



<p>I&#8217;m just going to type like a random number here.</p>



<p>Hopefully this doesn&#8217;t go on for too long, the conversion.</p>



<p>decimal number is just that. How do we convert? If you watch my other videos, it&#8217;s basically the</p>



<p>same thing as converting from decimal to binary, except instead of dividing by two, because binary</p>



<p>is base two, we&#8217;ll divide by 16 because hex is base 16. So I&#8217;m going to start off by saying,</p>



<p>let&#8217;s take the original number and we&#8217;ll divide it by not two, 16. What does that equal? There&#8217;s</p>



<p>no way I&#8217;m doing this in my head. So I&#8217;m just going to use a calculator for every single step,</p>



<p>going to use a calculator for every single step not even going to try I&#8217;m</p>



<p>going to say this number divided by 16 is 5 1 1 7 5 7 with some sort of a</p>



<p>remainder so I&#8217;m gonna go 5 1 1 7 5 7 remainder something so in most</p>



<p>calculators you can just punch up the modulo operator which is like the</p>



<p>percent symbol before I do that I just want to point out 0.75 is 3 4ths of</p>



<p>of whatever it is that is one you know that one character can represent we know</p>



<p>we can represent 16 different values what&#8217;s 16 divided by 4 that&#8217;s 4 so three</p>



<p>of those should be like 12 I hope unless I&#8217;m saying something totally wrong so</p>



<p>I&#8217;m gonna do modulo so that&#8217;s 12 okay remainder 12 my dog is growling at me</p>



<p>He likes to lie about peeing.</p>



<p>He doesn&#8217;t actually pee.</p>



<p>He already did a huge pee and then three times after that at 20 minute intervals, he went</p>



<p>out there and lifted his leg and just like three squirts came out and he expected a giant</p>



<p>treat for it.</p>



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



<p>You&#8217;re not getting that treat.</p>



<p>I expect a big pee pee if you want a treat.</p>



<p>You dog?</p>



<p>Dang little dog.</p>



<p>Okay.</p>



<p>So, here we are still dividing.</p>



<p>here we are still dividing. I got the remainder. So then we just need to take, you know, the</p>



<p>quotient result, you know, what is the result of actually dividing, just carry it over to</p>



<p>the next line. I&#8217;m going to do some spaces to make it look all even and continue to divide.</p>



<p>So divided by 16 equals something. Don&#8217;t forget that if you have the modulo operator over there,</p>



<p>you got to take it out, go back to division. It&#8217;s going to be 31984 remainder something.</p>



<p>what&#8217;s the remainder i&#8217;m just going to get the modulo i don&#8217;t want i don&#8217;t want to recall what</p>



<p>0.8125 is i&#8217;m sure some of you out there can already do that but it is 13 remainder 13.</p>



<p>um so i&#8217;m gonna go 319 divided by 16 31984 divided by 16 so it&#8217;s going to be 1 999 okay so carry that</p>



<p>over real fast though divided by 16 equals 1 9 9 remainder something there&#8217;s no decimal point at the</p>



<p>There&#8217;s no decimal point at the end of that so I can just assume the remainder is going to be zero.</p>



<p>If you want to double check to be sure, which is a good idea, use the modulo operator.</p>



<p>If your calculator doesn&#8217;t have modulo, find another calculator or jump into Python or something.</p>



<p>So I&#8217;m going to carry over 199 to the next line there.</p>



<p>1, 2, 4, remainder, whatever modulo says, 15.</p>



<p>That&#8217;s pretty cool.</p>



<p>All right, then I&#8217;m gonna carry it over,</p>



<p>just 1, 2, 4, divided by 16 again.</p>



<p>If you were hoping I&#8217;d be able to do it in my head by now,</p>



<p>you were wrong.</p>



<p>1, 2, 4, divided by 16, it&#8217;s gonna be 7.75,</p>



<p>so just like seven, remainder something.</p>



<p>What did I say last time for the 3 4ths?</p>



<p>Was that 12?</p>



<p>whoops, I can&#8217;t remember anymore.</p>



<p>12, yeah, okay, so remainder 12.</p>



<p>And then we&#8217;ll carry it over and we&#8217;ll say 7 divided by 16.</p>



<p>So we know that, you know, 16 doesn&#8217;t really fit into 7 at all.</p>



<p>So it&#8217;s going to be 0 remainder, whatever the number is.</p>



<p>Let&#8217;s punch it here just to double check.</p>



<p>We&#8217;ll say 7 divided by 16.</p>



<p>You can see that it&#8217;s 0.</p>



<p>And then the remainder is going to be 7, just, you know, what the original number was.</p>



<p>number was. So now at this point when the actual you know carry down quotient is</p>



<p>going to be zero then we just have zero divided by 16 equals just zero remainder</p>



<p>zero and it&#8217;ll just continue like this forever and ever and ever and ever and</p>



<p>ever. So this is how you know you&#8217;re done. Another thing that I mentioned in</p>



<p>other videos is how do we actually know where the zeros belong? I mean if you</p>



<p>read this intuitively from the top to the bottom you might think that you know</p>



<p>you know the top number is going to be like the first digit but it&#8217;s actually</p>



<p>backwards it goes from the bottom up the reason you can know that is again based</p>



<p>on my other videos if we just type a random decimal number here if I add</p>



<p>zeros to the right side I&#8217;m actually changing the value of the number I&#8217;m</p>



<p>making it bigger but if I add zeros to the left side I&#8217;m not changing the value</p>



<p>at all so that means those zeros here which could go on for infinity based on</p>



<p>how much tenacity you have they should be on the left side because you don&#8217;t</p>



<p>side because you don&#8217;t want any amount of these zeros to change the value of your number because</p>



<p>they you know it&#8217;s an arbitrary number of zeros based on how how fast you get tired of doing zeros</p>



<p>so that means if i go from top to bottom i have to reverse it if i go from bottom to top it&#8217;s</p>



<p>already going to be in the right order or sorry if i if i correlate or if i map bottom to top to mean</p>



<p>left to right then it&#8217;s fine already if i map top to bottom for left to right then i&#8217;ll have to</p>



<p>For left to right, then I&#8217;ll have to reverse it when I&#8217;m done.</p>



<p>So I&#8217;ll do it both ways just to show you.</p>



<p>But there&#8217;s one more step we need to do because in hexadecimal,</p>



<p>we have more characters than decimal.</p>



<p>We have to translate what does this 12 and 13 and these other numbers mean.</p>



<p>Luckily, we had some of them in there.</p>



<p>It could have been too easy.</p>



<p>So remember in hex, we have 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.</p>



<p>And then we have A, B, C, D, E, right?</p>



<p>So we know that the value of 0 is 0 and 1 is 1 and 2 and 2 and so forth, right?</p>



<p>Like 9 is 9.</p>



<p>But what&#8217;s the value of A?</p>



<p>For each increasing digit, the value just goes up by 1.</p>



<p>So that means that A is worth 10.</p>



<p>I&#8217;m going to write this vertically just so that you understand that this means the strength</p>



<p>of the A is 10.</p>



<p>And then the strength of the B is going to be 11 because it just increases by 1.</p>



<p>The strength of the C is 12.</p>



<p>The strength of the D is 13.</p>



<p>Oops, I forgot the F.</p>



<p>Oops, I forgot the F. Hit F in the chat if you forgot the F too.</p>



<p>So the strength of the E is 14. The strength of the F is 15.</p>



<p>And then we&#8217;re done. And remember, there&#8217;s 16 digits total.</p>



<p>So the highest value is 15 because it includes the zero.</p>



<p>So, you know, 16 total possible values you could represent, but the highest value, 15.</p>



<p>So that means every time we see a 12 here,</p>



<p>say that that&#8217;s really a C and every time we see actually let me let me put</p>



<p>the other C in there real fast every time we see a 13 that means it&#8217;s a D</p>



<p>every time we see a zero zero through nine it just it means the original</p>



<p>number oh wow we only had two digits that are gonna mean the original number</p>



<p>so mark my words you know the 15 is gonna be an F every time you see zero</p>



<p>one two three four five six seven eight nine it maps to the same number so seven</p>



<p>maps to seven it&#8217;s totally fine the only time it maps to a letter is of course when you exceed nine</p>



<p>so 10 and above are going to map to letters so now i have these mappings i just need to sort of scan</p>



<p>uh my my work to come up with the correct hexadecimal number so i&#8217;ll start from top to</p>



<p>bottom because it&#8217;s a little bit harder that way and it&#8217;ll be more brain practice i&#8217;m going to go</p>



<p>and then you know as many zeros as you decided to calculate and hopefully this</p>



<p>reminds you oh no I&#8217;m increasing the value by adding the zeros that means I</p>



<p>have to reverse everything so I&#8217;m gonna get rid of these zeros though and I&#8217;m</p>



<p>gonna reverse it 7cf0dc okay great now let&#8217;s double check because it&#8217;s always</p>



<p>a great idea to check your work in different ways with different methods to</p>



<p>decrease the possibility that you&#8217;re accidentally wrong so now I&#8217;m gonna go</p>



<p>So now I&#8217;m going to go from bottom to top and see if it&#8217;s the same thing.</p>



<p>7 C F 0 D C. Does it match? Yes.</p>



<p>So now I&#8217;m pretty confident that I have the right answer.</p>



<p>Let me punch this up in my personal calculator real fast.</p>



<p>I&#8217;m going to do just to double check the work before we cut the camera,</p>



<p>because if I&#8217;m wrong, I want to be able to correct myself right away.</p>



<p>Instead of coming back with another video later,</p>



<p>which sometimes I guess I&#8217;ll have to do.</p>



<p>f0 dc is the correct answer all right so we now have converted our first number from decimal to</p>



<p>hexadecimal nice and by the way if you didn&#8217;t already know this you&#8217;re supposed to put a</p>



<p>prefix in front of hexadecimal numbers not necessarily in every program that asks for</p>



<p>hex input some of them are not programmed that way but in general when you expect someone to</p>



<p>read your numbers if it&#8217;s hex you want to put ox in front of it because you don&#8217;t want them to</p>



<p>confuse, let&#8217;s say we have this number and this number and this number. All three of those could</p>



<p>be a different number depending on whether they&#8217;re binary or decimal or hex. But if you put the</p>



<p>symbols in front, this is binary, this is hex, then now the reader knows that these are three</p>



<p>different numbers and they can infer what the numbers mean. Okay, so let me, let&#8217;s just do like</p>



<p>another number. We&#8217;ll make it a little bit smaller so it&#8217;s easier. We&#8217;ll say decimal and we&#8217;ll go two,</p>



<p>and we&#8217;ll go 2 2 3.</p>



<p>So it&#8217;s faster.</p>



<p>So we start off with 2 2 3,</p>



<p>we divide it by 16,</p>



<p>and that&#8217;s going to be something.</p>



<p>So 2 2 3 divided by 16</p>



<p>is going to be 13 remainder something.</p>



<p>I&#8217;m going to do the modulo operator.</p>



<p>And by the way,</p>



<p>if you don&#8217;t have a modulo operator</p>



<p>and you can&#8217;t figure out a better way to do this,</p>



<p>a good trick is to just say,</p>



<p>let&#8217;s take 13,</p>



<p>because that was the answer, right?</p>



<p>13 point something.</p>



<p>We&#8217;ll take 13 and multiply that by 16 again,</p>



<p>that by 16 again so it goes higher then take the difference between that and the original number</p>



<p>so we can say 223 minus uh the number multiplied back up and it&#8217;ll tell us that our remainder is 15.</p>



<p>let&#8217;s see was that actually the remainder let me just double check here oh gosh what am i doing</p>



<p>223 modulo 16 15 yeah there it is if you&#8217;re lazy like me you could also do something like this i</p>



<p>and I don&#8217;t have a modulo.</p>



<p>I&#8217;ll do 13 times 16 and it&#8217;s 208.</p>



<p>And then I&#8217;ll just subtract the original number</p>



<p>and then we get negative 15,</p>



<p>but then I know it&#8217;s not negative, I know it&#8217;s 15.</p>



<p>So it&#8217;s just like, it makes you a little bit faster</p>



<p>in the calculator.</p>



<p>So this number I think was too small</p>



<p>because we just do 13 and then divide that by 16.</p>



<p>Obviously the answer is gonna be zero remainder 13.</p>



<p>And we just have a two digit hexadecimal number.</p>



<p>digit hexadecimal number. Let&#8217;s do that real fast. What is 15 going to be? It&#8217;s A and no, no,</p>



<p>no, not A. Sorry. That&#8217;s F. Subtract two from that. D E F. So it&#8217;s going to be D, I think.</p>



<p>So then if we go from bottom to top, it&#8217;s going to be O X D F. Let me double check that I&#8217;m</p>



<p>telling you the right thing. 223 D F. Okay. So we got it right. Let&#8217;s do something just like a</p>



<p>not as difficult as the first one so I&#8217;ll try four digits maybe two two two two</p>



<p>how about that four digital four digital digits how about that we&#8217;ll do</p>



<p>two eight one six divided by 13 equals something two eight one six divided by</p>



<p>16 that&#8217;s 176 remainder something there&#8217;s no decimal point so I can just</p>



<p>16 is 176 divided by 16 is 11.</p>



<p>Another zero remainder.</p>



<p>Getting kind of boring though, isn&#8217;t it?</p>



<p>Remainder zero.</p>



<p>And then we&#8217;ll do 11 divided by 16.</p>



<p>That&#8217;s going to be zero remainder 11.</p>



<p>That&#8217;s too easy.</p>



<p>Okay.</p>



<p>So what is zero?</p>



<p>Zero is zero.</p>



<p>You&#8217;re welcome.</p>



<p>And then what is zero?</p>



<p>It&#8217;s also zero.</p>



<p>0, it&#8217;s also 0 and then what is 11? That&#8217;s B.</p>



<p>So we should have a number now of 0xB00 if we&#8217;re going from the bottom to the top.</p>



<p>If you go from the top to the bottom of course it&#8217;ll be 00B and then you reverse it B00</p>



<p>but I just wanted to skip that step for now.</p>



<p>Let me punch this up into my personal calculator to make sure I don&#8217;t need to make a correction.</p>



<p>B00, there we go.</p>



<p>Also, you know, here&#8217;s another thing to keep in mind.</p>



<p>it&#8217;s to read you know sets of bytes which typically go in patterns of one byte or two</p>



<p>bytes or four bytes or eight bytes or whatever so the cool thing about hex is one character</p>



<p>can represent a number from zero uh to 15 or 16 combinations and if you think about that in binary</p>



<p>that&#8217;s four bits right it&#8217;s like one two three four one two four eight multiply eight by two</p>



<p>16 subtract 1 is 15.</p>



<p>So you can go from 0 to 15.</p>



<p>So that means for every character in hex,</p>



<p>you get four characters of binary.</p>



<p>So it&#8217;s like a huge savings, right?</p>



<p>But the point is, if you wanted to represent one byte,</p>



<p>that&#8217;s not going to be four bits.</p>



<p>That&#8217;s going to be, you know,</p>



<p>four bits followed by four bits for a total of eight bits.</p>



<p>Even if there are zeros in the beginning,</p>



<p>in binary, if you&#8217;re representing a byte,</p>



<p>But in binary, if you&#8217;re representing a byte, you typically want to pad the zeros to the</p>



<p>left so that it looks like it&#8217;s aligned to nice blocks of eight or 16 or 32 or 64 in</p>



<p>terms of bits.</p>



<p>So we should do the same thing with hex.</p>



<p>We should always have two hex digits together.</p>



<p>We should try not to have like an odd number of hex digits.</p>



<p>And if you want to get more strict than that and say like, oh, only, you know, two or four</p>



<p>eight you can do that but i just will say pad it with a zero to the left remember when you pad a</p>



<p>number with zeros to the left it doesn&#8217;t change the value like if i just put a bunch of zeros in</p>



<p>front of this decimal number it wouldn&#8217;t change the value so we can do that with hex and it looks</p>



<p>nicer and neater and people can quickly see okay so there&#8217;s like a byte right there it&#8217;s ob</p>



<p>they can imagine oh that byte is probably um 11. so there&#8217;s like a like an 11 byte it&#8217;s like got</p>



<p>a sequence of zeros and ones and then there&#8217;s another byte right after it which is smaller</p>



<p>which is smaller, which just has zeros.</p>



<p>So it just helps the reader visualize what&#8217;s going on.</p>



<p>Okay, I&#8217;m going to cut the video here.</p>



<p>I hope you enjoyed this video.</p>



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



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



<p>Hey, everybody.</p>



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



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



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



<p>If you could do me a please, a small little favor,</p>



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



<p>or these videos or whatever it is you do on the current social media website</p>



<p>that you&#8217;re looking at right now it would really mean the world to me and</p>



<p>it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do</p>



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



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



<p>sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I</p>



<p>And I just wake up because I know somebody subscribed or followed.</p>



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



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



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



<p>Just subscribe and then I&#8217;ll just wake up.</p>



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



<p>Also, if you look at the middle of the screen right now, you should see a QR code,</p>



<p>which you can scan in order to go to the website, which I think is also named somewhere at the bottom of this video.</p>



<p>where you can just kind of like see all the videos I published and the services</p>



<p>and tutorials and things that I offer and all that good stuff and if you have</p>



<p>a suggestion for clarifications or errata or just future videos that you</p>



<p>want to see please leave a comment or if you just want to say hey what&#8217;s up</p>



<p>what&#8217;s going on you know just send me a comment whatever I also wake up for</p>



<p>those in the middle of the night I get I wake up in a cold sweat I&#8217;m like this</p>



<p>really it really mean the world to me I would really appreciate it so again thank you so much</p>



<p>for watching this video and enjoy the cool music as as I fade into the darkness which is coming for</p>



<p>us all</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-convert-decimal-to-hexadecimal-fun-easy-guide-for-beginners/">How to Convert Decimal to Hexadecimal: Fun &amp; Easy Guide for Beginners</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-to-convert-decimal-to-hexadecimal-fun-easy-guide-for-beginners/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
