<?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>virtual memory Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/virtual-memory/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/virtual-memory/</link>
	<description></description>
	<lastBuildDate>Mon, 04 Aug 2025 01:16:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>virtual memory Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/virtual-memory/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Demystifying x86-64 Program Segments: Stack, Heap, and More</title>
		<link>https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/</link>
					<comments>https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 04 Aug 2025 01:16:47 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[BSS section]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[data section]]></category>
		<category><![CDATA[heap memory]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[memory management]]></category>
		<category><![CDATA[program segments]]></category>
		<category><![CDATA[segmentation fault]]></category>
		<category><![CDATA[stack overflow]]></category>
		<category><![CDATA[virtual memory]]></category>
		<category><![CDATA[x86-64]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=195</guid>

					<description><![CDATA[<p>Understand x86-64 program segments like stack, heap, data, and BSS. Learn to avoid segmentation faults and stack overflows in this beginner-friendly coding tutorial.</p>
<p>The post <a href="https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/">Demystifying x86-64 Program Segments: Stack, Heap, and More</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="Demystifying x86-64 Program Segments: Stack, Heap, and More" width="1380" height="776" src="https://www.youtube.com/embed/GUicAuRPgPA?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Join us for a clear, engaging look at x86-64 program segments! We break down the text, data, and BSS sections, explore stack vs. heap memory, and show a real stack overflow in C++. Learn why segmentation faults happen, how virtual memory works, and tips to avoid crashes. Whether you&#8217;re new to assembly or leveling up your coding skills, this video is packed with insights to boost your understanding of low-level programming. Subscribe for more coding deep dives!</p>



<p class="wp-block-paragraph">Introduction to x86-64 program segments 00:00:01<br>Understanding segmentation faults 00:00:12<br>Importance of segments in assembly 00:00:32<br>Overview of assembly program structure 00:01:09<br>Defining segments in Yasm assembly 00:01:49<br>Data section: Initialized global variables 00:02:20<br>BSS section: Uninitialized variables 00:03:23<br>Text section: Code and functions 00:03:59<br>Global and extern function declarations 00:04:41<br>Stack: Local variables and return addresses 00:07:11<br>Stack overflow example in C++ 00:08:48<br>Heap: Dynamic memory allocation 00:11:31<br>Stack vs heap memory growth 00:11:56<br>Virtual memory and memory allocation 00:14:00<br>Demonstrating memory overflow with heap allocation 00:16:59<br>Summary of segments and their purposes 00:17:59<br>Closing remarks and call to subscribe 00:18:47</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hi there!</p>



<p class="wp-block-paragraph">Let&#8217;s talk about x86-64 programs and their segments and the purpose of the segments.</p>



<p class="wp-block-paragraph">Probably when you&#8217;ve been programming in the past you&#8217;ve seen segmentation fault errors.</p>



<p class="wp-block-paragraph">If you&#8217;ve accidentally crossed the bounds of some appropriate memory location, if you</p>



<p class="wp-block-paragraph">have an array and you try to index it way outside of bounds or something, you might</p>



<p class="wp-block-paragraph">have seen a segfault.</p>



<p class="wp-block-paragraph">SegFaults basically come from the idea that you have crossed a segment boundary.</p>



<p class="wp-block-paragraph">Segments used to be really, really important.</p>



<p class="wp-block-paragraph">They&#8217;re a little bit less important now that we have virtual memory.</p>



<p class="wp-block-paragraph">I&#8217;ll just talk a little bit about them.</p>



<p class="wp-block-paragraph">I&#8217;m going to be discussing this from the perspective of an assembly program,</p>



<p class="wp-block-paragraph">just because even in higher level languages,</p>



<p class="wp-block-paragraph">your languages will typically be compiled down to assembly</p>



<p class="wp-block-paragraph">first before they actually hit machine code and your actual executable binary.</p>



<p class="wp-block-paragraph">So if you&#8217;re not interested in Yasm Assembly,</p>



<p class="wp-block-paragraph">Yasm assembly I think this could still be worth it for you to watch because</p>



<p class="wp-block-paragraph">you&#8217;ll be able to see the different segments and just kind of get a better</p>



<p class="wp-block-paragraph">understanding of what they are okay so I&#8217;m gonna actually write a very very</p>



<p class="wp-block-paragraph">very quick program in assembly it&#8217;s not gonna really do anything I just want you</p>



<p class="wp-block-paragraph">to show I just want you to see the segments that are involved so for</p>



<p class="wp-block-paragraph">starters let&#8217;s just pretend that I&#8217;m writing a an assembly program here we&#8217;ll</p>



<p class="wp-block-paragraph">This is a comment just so you know what I&#8217;m about to type.</p>



<p class="wp-block-paragraph">Perhaps actually this is not the best editor.</p>



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



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



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



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



<p class="wp-block-paragraph">There we go.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll save it somewhere.</p>



<p class="wp-block-paragraph">I&#8217;ll say segments assembly.</p>



<p class="wp-block-paragraph">And then now the comment gets highlighted.</p>



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



<p class="wp-block-paragraph">So in assembly in the ASM assembly,</p>



<p class="wp-block-paragraph">we denote various segments by using the section keywords.</p>



<p class="wp-block-paragraph">keywords so we&#8217;ll say section and then dot something indicating the type of segment that we&#8217;re</p>



<p class="wp-block-paragraph">defining so section text and then up here we&#8217;ll have another one section dot bss and you know if</p>



<p class="wp-block-paragraph">you already program assembly you know that somewhere in here is where the code goes right</p>



<p class="wp-block-paragraph">between these sections so just a quick recap of what the data section is it just is where you</p>



<p class="wp-block-paragraph">can name and initialize at the same time at the very top.</p>



<p class="wp-block-paragraph">Globals are not great, but sometimes you want to do that in assembly, depending.</p>



<p class="wp-block-paragraph">It&#8217;s better if you stick all your variables on the stack.</p>



<p class="wp-block-paragraph">Like if they&#8217;re a local variable, it&#8217;s a little bit better.</p>



<p class="wp-block-paragraph">Think of higher level languages.</p>



<p class="wp-block-paragraph">You typically want to avoid global variables if you can possibly avoid them and make</p>



<p class="wp-block-paragraph">everything else a local variable or a member variable.</p>



<p class="wp-block-paragraph">So that means somewhere else other than data, probably the stack, but or the heap.</p>



<p class="wp-block-paragraph">Anyway, you know, this is like the basic pattern.</p>



<p class="wp-block-paragraph">We&#8217;ll say, you know, my variable and then we&#8217;ll decide to say what data size it is.</p>



<p class="wp-block-paragraph">In this case, it&#8217;s DB for one byte of data.</p>



<p class="wp-block-paragraph">You could put a, I think DD in there or a DW for a word.</p>



<p class="wp-block-paragraph">Sorry, sorry, DW would be for a word.</p>



<p class="wp-block-paragraph">And then I think DD would be a double and then DQ would definitely be a quad word.</p>



<p class="wp-block-paragraph">So here quad word is eight bytes.</p>



<p class="wp-block-paragraph">And then I can sort of initialize it to some number.</p>



<p class="wp-block-paragraph">some number and now I have a global variable so not like a huge deal the BSS section is basically</p>



<p class="wp-block-paragraph">where you have uninitialized variables but there you can make huge amounts of variables you can</p>



<p class="wp-block-paragraph">make an array of variables so if I say my array something like that I could put resource queue</p>



<p class="wp-block-paragraph">to say I want the type of one item to be a quad word so you know eight bytes per item and then I</p>



<p class="wp-block-paragraph">could just say I want you know a hundred thousand items or something and I&#8217;ll</p>



<p class="wp-block-paragraph">double check that after I stop recording this video and correct it if I&#8217;m wrong</p>



<p class="wp-block-paragraph">it&#8217;s been a while since I actually typed BSS here and then in the text section</p>



<p class="wp-block-paragraph">this is where you put code and functions and things you typically want to have at</p>



<p class="wp-block-paragraph">least one entry point somewhere you know if you want to make like if you want to</p>



<p class="wp-block-paragraph">make this the entry point of your entire program you&#8217;ll probably do global main</p>



<p class="wp-block-paragraph">main and then this assumes that you use the GCC libraries and just sort of return from the label</p>



<p class="wp-block-paragraph">sort of makes it a function assuming you didn&#8217;t ruin any of the other data.</p>



<p class="wp-block-paragraph">So those are the three sections that we can start off looking at the data section,</p>



<p class="wp-block-paragraph">the BSS section, and the tech section. It&#8217;s important to note that besides marking functions</p>



<p class="wp-block-paragraph">as global so that they&#8217;re accessible to other segments or other modules, we also mark</p>



<p class="wp-block-paragraph">We also mark functions and labels that we would like to access that are in other modules.</p>



<p class="wp-block-paragraph">So if we&#8217;re using the GCC libraries, we could say something like global printf,</p>



<p class="wp-block-paragraph">and then right away we&#8217;re able to call the printf function.</p>



<p class="wp-block-paragraph">Or say if you have another function in another module,</p>



<p class="wp-block-paragraph">like a different source code file that&#8217;s compiled somewhere else,</p>



<p class="wp-block-paragraph">we could say, you know, my other function.</p>



<p class="wp-block-paragraph">Something like that.</p>



<p class="wp-block-paragraph">Just mark it as global.</p>



<p class="wp-block-paragraph">Or sorry, not global.</p>



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



<p class="wp-block-paragraph">Xtern. Global is when you have the function in the current module and you want it to be available to other modules.</p>



<p class="wp-block-paragraph">Xtern is when the function or label is in another module and it&#8217;s already been made available to you,</p>



<p class="wp-block-paragraph">but you want your current module to know that it can access it for the purposes of assembling the program.</p>



<p class="wp-block-paragraph">So that means inside of here we could do something like call.</p>



<p class="wp-block-paragraph">We could say, let&#8217;s call my other function.</p>



<p class="wp-block-paragraph">my other function that will work if the other function is actually a function</p>



<p class="wp-block-paragraph">with a return statement and it respects the ABI you know it pushes registers that</p>



<p class="wp-block-paragraph">it&#8217;s going to modify if they&#8217;re callie saved if it&#8217;s not another function maybe</p>



<p class="wp-block-paragraph">we&#8217;ll say extern my other jump point so like not a proper function but just</p>



<p class="wp-block-paragraph">something that you might want to jump to then instead of using call we would use</p>



<p class="wp-block-paragraph">jump, you know, and so forth. So those are the basic sections. Let&#8217;s see, for the BSS,</p>



<p class="wp-block-paragraph">I definitely talked about token size and count. And then there&#8217;s resource B, resource W, resource</p>



<p class="wp-block-paragraph">D, resource Q for the different sizes. So basically just take all the different sizes you could put</p>



<p class="wp-block-paragraph">in the regular data section and assume that that could be popped on to the end of RES inside of</p>



<p class="wp-block-paragraph">the BSS section. If you&#8217;re interested, this is a segments video, not an assembly video.</p>



<p class="wp-block-paragraph">assembly video um another segment uh another segment that we&#8217;re not showing here in this</p>



<p class="wp-block-paragraph">source code is the actual stack probably i guess the best way that i could show it is</p>



<p class="wp-block-paragraph">i don&#8217;t know by messing around with the stack pointer increase uh</p>



<p class="wp-block-paragraph">oh rsp why did i think it was the instruction pointer we could increase the stack pointer and</p>



<p class="wp-block-paragraph">stack pointer and then decrease the stack pointer.</p>



<p class="wp-block-paragraph">It doesn&#8217;t really help a whole lot.</p>



<p class="wp-block-paragraph">But in another video, I&#8217;m gonna talk more in depth</p>



<p class="wp-block-paragraph">about what the stack is and how to use it and such.</p>



<p class="wp-block-paragraph">But just keep in mind that the stack</p>



<p class="wp-block-paragraph">is where local variables are stored</p>



<p class="wp-block-paragraph">and you can use it in assembly and C++</p>



<p class="wp-block-paragraph">and other higher level languages.</p>



<p class="wp-block-paragraph">You can even make virtual stacks</p>



<p class="wp-block-paragraph">in any type of program almost</p>



<p class="wp-block-paragraph">to just sort of have a stack like structure.</p>



<p class="wp-block-paragraph">But in C++, if you make any local variable,</p>



<p class="wp-block-paragraph">any local variable, then it&#8217;s usually going on the stack.</p>



<p class="wp-block-paragraph">And the stack tends to have a fixed size.</p>



<p class="wp-block-paragraph">And so if you sort of put too much data on the stack,</p>



<p class="wp-block-paragraph">you risk a stack overflow, which will crash your program.</p>



<p class="wp-block-paragraph">Besides local variables, the stack will hold other information that the current scope needs,</p>



<p class="wp-block-paragraph">like its return address.</p>



<p class="wp-block-paragraph">So when we make a function and then let&#8217;s say we call another function inside of it,</p>



<p class="wp-block-paragraph">actually just up here even when we call another function on line 22 the stack will receive the</p>



<p class="wp-block-paragraph">return address of where we currently are so that later when we return from the other function you</p>



<p class="wp-block-paragraph">know the program knows where to jump back and forth it&#8217;s actually under the hood just jump</p>



<p class="wp-block-paragraph">instructions when you do call it&#8217;s it&#8217;s not it&#8217;s not like a special thing it&#8217;s just jumping to</p>



<p class="wp-block-paragraph">another location and then pushing the return address on the call stack so that&#8217;s other stuff</p>



<p class="wp-block-paragraph">other stuff that the stack holds, which means if you have like an endless or like a infinite</p>



<p class="wp-block-paragraph">recursion happening in your function where just a function calls itself over and over</p>



<p class="wp-block-paragraph">and over again, or you have some complicated call graph and you end up calling too many</p>



<p class="wp-block-paragraph">functions without ever returning, you could overflow the stack.</p>



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



<p class="wp-block-paragraph">Let me show you a quick example that I&#8217;m going to make for you real fast.</p>



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



<p class="wp-block-paragraph">Did I actually make this?</p>



<p class="wp-block-paragraph">Where is the, it&#8217;s on the desktop.</p>



<p class="wp-block-paragraph">Okay, I guess I&#8217;m going to make more on the desktop.</p>



<p class="wp-block-paragraph">Let&#8217;s do a stack overflow.</p>



<p class="wp-block-paragraph">Let me do desktop here.</p>



<p class="wp-block-paragraph">Let&#8217;s do stack overflow.</p>



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



<p class="wp-block-paragraph">I&#8217;m just going to make a quick program.</p>



<p class="wp-block-paragraph">In C++, that doesn&#8217;t really do anything except overflow the stack.</p>



<p class="wp-block-paragraph">So I just want you to know the stack can overflow.</p>



<p class="wp-block-paragraph">I&#8217;ll make a function called F.</p>



<p class="wp-block-paragraph">And F just calls itself.</p>



<p class="wp-block-paragraph">calls itself. So that&#8217;s going to be an infinite recursion.</p>



<p class="wp-block-paragraph">And that means, you know, every single time F calls itself,</p>



<p class="wp-block-paragraph">the return address of like line five is going to get pushed onto the stack again.</p>



<p class="wp-block-paragraph">So it&#8217;s just going to get pushed and pushed and pushed and pushed.</p>



<p class="wp-block-paragraph">The stack will overflow faster if I had local variables because every scope that</p>



<p class="wp-block-paragraph">gets called, even if it&#8217;s the same function name, it&#8217;ll have its own allocation on</p>



<p class="wp-block-paragraph">the stack. So if I just sort of like call this from main and then I&#8217;ll just need</p>



<p class="wp-block-paragraph">and then I&#8217;ll just need to make a little uh a little make file that just kind of compiles</p>



<p class="wp-block-paragraph">I don&#8217;t really even need to make a make file I could do a build script but I&#8217;m going to do it</p>



<p class="wp-block-paragraph">anyway we&#8217;ll say g plus plus standard equals c plus plus 23 show all warnings show pedantic</p>



<p class="wp-block-paragraph">the input file will be stack overflow cpp and then the output file will be main</p>



<p class="wp-block-paragraph">main and then assuming that succeeds I&#8217;ll just run main so this is like not a make</p>



<p class="wp-block-paragraph">file video I have other videos for make files let&#8217;s see let me get to the</p>



<p class="wp-block-paragraph">desktop if I run the make file with just the word make you should see a stack</p>



<p class="wp-block-paragraph">overflow we should also see a warning about the fact that there&#8217;s infinite</p>



<p class="wp-block-paragraph">That&#8217;s funny, I must have done something wrong or different because on a different computer</p>



<p class="wp-block-paragraph">not too long ago I did the same thing and I saw a warning.</p>



<p class="wp-block-paragraph">Okay, well thanks for not warning me.</p>



<p class="wp-block-paragraph">But anyway, you can see that we have a segmentation fault here because the stack overflowed.</p>



<p class="wp-block-paragraph">We just made a stack that was too huge.</p>



<p class="wp-block-paragraph">This is a reminder that the stack is not necessarily as dynamic as the heap.</p>



<p class="wp-block-paragraph">You can definitely overflow it.</p>



<p class="wp-block-paragraph">It&#8217;s not really meant to store gigantic amounts of data.</p>



<p class="wp-block-paragraph">What am I talking about when I say the heap though?</p>



<p class="wp-block-paragraph">So just keep in mind that whenever you allocate dynamic data,</p>



<p class="wp-block-paragraph">well, maybe, well, what do you think?</p>



<p class="wp-block-paragraph">Maybe, maybe inside of, instead of calling F, let&#8217;s call G.</p>



<p class="wp-block-paragraph">The heap is where you allocate dynamic data.</p>



<p class="wp-block-paragraph">So anytime you use the malloc operator in C or the new allocator in C++,</p>



<p class="wp-block-paragraph">you&#8217;re creating like a dynamic allocation of data.</p>



<p class="wp-block-paragraph">I&#8217;ll do a new integer and then I&#8217;ll do like a thousand integers so this is</p>



<p class="wp-block-paragraph">basically going to allocate a thousand new integers in the heap which is a</p>



<p class="wp-block-paragraph">segment that is right up against the stack I should mention also that the</p>



<p class="wp-block-paragraph">stack it&#8217;s important the stack its memory locations go down as the stack</p>



<p class="wp-block-paragraph">grows keep that in mind because typically when you when you imagine a</p>



<p class="wp-block-paragraph">stack I&#8217;ll make more videos in the future so you can visualize the stack better but most of you who</p>



<p class="wp-block-paragraph">know what a stack is already you imagine that the stack grows upward visually right but in your</p>



<p class="wp-block-paragraph">computer the memory locations of the stack grow downward so if I add something to the stack then</p>



<p class="wp-block-paragraph">the new stack head pointer is actually going to be a lesser address and the reason for that is the</p>



<p class="wp-block-paragraph">stack and the heap they grow in the same direction towards the same unallocated space we&#8217;ll call that</p>



<p class="wp-block-paragraph">We&#8217;ll call that space the unallocated memory space or the unmapped memory space.</p>



<p class="wp-block-paragraph">And it&#8217;s just, you know, a segment stack in the heap.</p>



<p class="wp-block-paragraph">And then there&#8217;s the unallocated space that they grow towards each other.</p>



<p class="wp-block-paragraph">If they ever meet, then your program is out of memory and it&#8217;ll crash.</p>



<p class="wp-block-paragraph">But the heap actually can be dynamically allocated to store tons of RAM.</p>



<p class="wp-block-paragraph">I&#8217;m probably about to crash this computer.</p>



<p class="wp-block-paragraph">So maybe this video won&#8217;t finish recording.</p>



<p class="wp-block-paragraph">recording so maybe I&#8217;ll try to crash this at the very end I just wanted you to</p>



<p class="wp-block-paragraph">see let me let me do this I&#8217;ll say while true we&#8217;ll just allocate a new integer</p>



<p class="wp-block-paragraph">this is kind of bad form because when you allocate you know a new variable</p>



<p class="wp-block-paragraph">somewhere you want to have access to it after the allocation you would usually</p>



<p class="wp-block-paragraph">send that into a pointer you&#8217;d say like you know integer pointer P equals new</p>



<p class="wp-block-paragraph">in something like that right but in this case I don&#8217;t really care I&#8217;m not gonna</p>



<p class="wp-block-paragraph">that memory i just want you to see how fast the memory can grow when we did the stack overflow</p>



<p class="wp-block-paragraph">seemed like the program died pretty quickly but here we&#8217;re going to be able to see the memory</p>



<p class="wp-block-paragraph">boom pretty pretty big before the whole computer just starts to you know fall to its knees</p>



<p class="wp-block-paragraph">so i&#8217;m going to do a call to g here and then i won&#8217;t actually run this until</p>



<p class="wp-block-paragraph">i&#8217;m ready to crash this whole video let&#8217;s see what else can i say</p>



<p class="wp-block-paragraph">Oh, the reason that the heap can grow so much larger than the stack is our programs now in the modern era, they use virtual memory.</p>



<p class="wp-block-paragraph">So it&#8217;s not like when we allocate, let&#8217;s say we&#8217;re accessing a memory location via a pointer inside of our program.</p>



<p class="wp-block-paragraph">It&#8217;s not that the pointer has the absolute memory location through the whole system.</p>



<p class="wp-block-paragraph">Like it doesn&#8217;t, it&#8217;s not able to name locations outside of the current program.</p>



<p class="wp-block-paragraph">Every program sees its own start memory location as just zero.</p>



<p class="wp-block-paragraph">And then under the hood, there are some extra tricks so that when you try to access a memory location,</p>



<p class="wp-block-paragraph">let&#8217;s say memory location 100, because you&#8217;ve made, I don&#8217;t know, this many integers or whatever.</p>



<p class="wp-block-paragraph">Then under the hood, the computer will know what is the start offset of the program&#8217;s memory.</p>



<p class="wp-block-paragraph">So maybe the start offset is 1000.</p>



<p class="wp-block-paragraph">It&#8217;s like totally unrealistic, but just pretend.</p>



<p class="wp-block-paragraph">The start offset is 1000.</p>



<p class="wp-block-paragraph">1000 then that means if it&#8217;s trying to access a pointer with memory location 100 it just gets added to the offset the virtual offset</p>



<p class="wp-block-paragraph">So it&#8217;ll be a thousand and 100 is the real you know physical memory location or at least at that point</p>



<p class="wp-block-paragraph">It&#8217;ll probably go to the paging system, but that&#8217;s that&#8217;s another video</p>



<p class="wp-block-paragraph">So just know that it&#8217;s virtual which means the program thinks it has the full range of of the 64 bit memory address space</p>



<p class="wp-block-paragraph">Even if you don&#8217;t even have that much memory on your computer, which there&#8217;s no way there&#8217;s no way you have so much memory</p>



<p class="wp-block-paragraph">there&#8217;s no way you have so much memory that it&#8217;s going to overflow or even meet</p>



<p class="wp-block-paragraph">64 bits at all but the program thinks it can so it&#8217;s just going to grow and grow</p>



<p class="wp-block-paragraph">and grow until you actually run out of physical memory and then eventually</p>



<p class="wp-block-paragraph">probably your program is going to start going to the page file or to the swap</p>



<p class="wp-block-paragraph">file and then when you run out of that then your whole computer probably is</p>



<p class="wp-block-paragraph">going to start crashing to be honest it&#8217;ll probably start crashing as soon as</p>



<p class="wp-block-paragraph">it hits the swap file because at that point none of the other programs really</p>



<p class="wp-block-paragraph">None of the other programs really have enough leftover memory to to breathe to do extra</p>



<p class="wp-block-paragraph">allocations and things so everything&#8217;s going to start slowing down it&#8217;s going to be pretty bad</p>



<p class="wp-block-paragraph">and well i think that&#8217;s all i really need to say this is not supposed to be a really long video</p>



<p class="wp-block-paragraph">let me uh let me show you this crasher i&#8217;m going to say goodbye now thank you so much for watching</p>



<p class="wp-block-paragraph">the video i hope you learned a little bit and had some fun too and and that way i&#8217;ve already said</p>



<p class="wp-block-paragraph">if it actually crashes the computer. So I&#8217;m going to open up this and then I&#8217;m going to do maybe</p>



<p class="wp-block-paragraph">HTOP so that I can see memory. So if you kind of like look at HTOP real fast,</p>



<p class="wp-block-paragraph">this is just a Linux command line tool that you can install. It&#8217;s pretty cool.</p>



<p class="wp-block-paragraph">What the heck&#8217;s going on here? Oh, that&#8217;s my recorder. You can see here&#8217;s the memory allocation.</p>



<p class="wp-block-paragraph">So I&#8217;m using two gigs of eight gigs on this virtual machine and then I&#8217;m not using any swap</p>



<p class="wp-block-paragraph">space which means I have not exhausted all my memory and and I have not been forced to go to</p>



<p class="wp-block-paragraph">the disk for like additional memory but in a second we&#8217;ll see that will probably change</p>



<p class="wp-block-paragraph">so I&#8217;m going to do make just to run that it looks like it&#8217;s stuck but if you keep looking at the</p>



<p class="wp-block-paragraph">memory allocation oh it already hit eight gigs now it&#8217;s into the swap already probably</p>



<p class="wp-block-paragraph">The out of memory killer, the OOM, successfully killed the program.</p>



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



<p class="wp-block-paragraph">Or the whole computer would have been down.</p>



<p class="wp-block-paragraph">I always forget that that&#8217;s going to happen lately.</p>



<p class="wp-block-paragraph">But you can see it spiked, right?</p>



<p class="wp-block-paragraph">It went right up to the full physical memory allocation of 7.75 gigs.</p>



<p class="wp-block-paragraph">And then the swap file went all the way up to 2 gigs.</p>



<p class="wp-block-paragraph">You can see that the swap file still has about 700 megs inside of it.</p>



<p class="wp-block-paragraph">That just means that there&#8217;s memory that isn&#8217;t really being accessed.</p>



<p class="wp-block-paragraph">the operating system doesn&#8217;t feel like it&#8217;s necessary to pull it back out of swap and put</p>



<p class="wp-block-paragraph">it into RAM but I wonder if the video skipped when I did that or stuttered or anything I&#8217;m</p>



<p class="wp-block-paragraph">interested to find out now okay so that&#8217;s the end of this video I hope you have a decent basic</p>



<p class="wp-block-paragraph">understanding of segments and then you know like the segments and their purpose you know the heap</p>



<p class="wp-block-paragraph">and the stack they grow together the heap can dynamically allocate to grow bigger notice how it</p>



<p class="wp-block-paragraph">Whereas the stack will crash a lot faster.</p>



<p class="wp-block-paragraph">If the stack and the heap meet, then you&#8217;ve ran out of memory.</p>



<p class="wp-block-paragraph">At that point, you know, you probably want to like resize the heap or the stack just crashes.</p>



<p class="wp-block-paragraph">And then we got the text section of the program and the data section and the BSS section of the program.</p>



<p class="wp-block-paragraph">And these sections are a little bit less relevant in the modern era because we have, you know, virtual memory and stuff.</p>



<p class="wp-block-paragraph">That definitely means you have tried to access outside of your segment and it&#8217;s a no go.</p>



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



<p class="wp-block-paragraph">Thank you for watching this video.</p>



<p class="wp-block-paragraph">I will see you at a later date and time.</p>



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



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



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



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



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



<p class="wp-block-paragraph">as you do on the current social media website</p>



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



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



<p class="wp-block-paragraph">and it&#8217;ll help make more videos</p>



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



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



<p class="wp-block-paragraph">longer videos, better videos,</p>



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



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping</p>



<p class="wp-block-paragraph">in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed.</p>



<p class="wp-block-paragraph">It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could you could troll me if you want to just wake me up in the middle</p>



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



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



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



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



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



<p class="wp-block-paragraph">and all that good stuff and</p>



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



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/">Demystifying x86-64 Program Segments: Stack, Heap, and More</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/demystifying-x86-64-program-segments-stack-heap-and-more/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How the Loader Module Works: Launching Programs in Your Operating System Explained!</title>
		<link>https://www.NeuralLantern.com/how-the-loader-module-works-launching-programs-in-your-operating-system-explained/</link>
					<comments>https://www.NeuralLantern.com/how-the-loader-module-works-launching-programs-in-your-operating-system-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 08 Jun 2025 23:06:41 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[computer basics]]></category>
		<category><![CDATA[CPU scheduling]]></category>
		<category><![CDATA[ELF format]]></category>
		<category><![CDATA[executable files]]></category>
		<category><![CDATA[Linux 64 bit]]></category>
		<category><![CDATA[loader module]]></category>
		<category><![CDATA[memory allocation]]></category>
		<category><![CDATA[multitasking]]></category>
		<category><![CDATA[operating system]]></category>
		<category><![CDATA[OS explained]]></category>
		<category><![CDATA[process creation]]></category>
		<category><![CDATA[program execution]]></category>
		<category><![CDATA[tech education]]></category>
		<category><![CDATA[tech tutorial]]></category>
		<category><![CDATA[virtual memory]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=144</guid>

					<description><![CDATA[<p>Discover the Loader Module’s role in your OS! Learn how it loads programs from disk to RAM in this fun, clear guide. Perfect for tech fans!</p>
<p>The post <a href="https://www.NeuralLantern.com/how-the-loader-module-works-launching-programs-in-your-operating-system-explained/">How the Loader Module Works: Launching Programs in Your Operating System 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 the Loader Module Works: Launching Programs in Your Operating System Explained!" width="1380" height="776" src="https://www.youtube.com/embed/mfsYCiGDg8A?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Ever clicked an icon and wondered how your program starts? Meet the Loader Module, the unsung hero in your operating system! This video breaks down how it loads programs from your disk to RAM, sets up processes, and gets your apps ready to roll. Perfect for tech newbies or curious coders! Join us for a fun, easy-to-follow explanation, and stick around for more OS secrets. Subscribe, comment your thoughts, and scan the QR code to explore more tutorials on our site! Let’s geek out together!</p>



<p class="wp-block-paragraph">Introduction to Loader Module 00:00:00<br>What is the Loader Module 00:00:10<br>Role in Operating Systems 00:00:14<br>Loading Process Overview 00:00:21<br>Program Execution Trigger 00:00:44<br>Signal to Operating System 00:01:00<br>Executable Validation 00:01:43<br>Memory Allocation 00:02:31<br>Process Creation 00:03:05<br>Process Setup Completion 00:04:22<br>Operating System Scheduling 00:04:54<br>Multitasking Illusion 00:05:24<br>Process Termination 00:05:59<br>Loader Module Limitations 00:06:11<br>Conclusion and Summary 00:06:28<br>Call to Subscribe 00:07:00<br>Website and Community 00:07:56</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey there! Let&#8217;s talk about the Loader Module for just a second.</p>



<p class="wp-block-paragraph">What is the Loader Module? For starters, you probably have one on your computer at home.</p>



<p class="wp-block-paragraph">Almost, I mean, as far as I understand, every major operating system has a Loader Module.</p>



<p class="wp-block-paragraph">I would be surprised if an operating system did not have one.</p>



<p class="wp-block-paragraph">The Loader Module is basically responsible for getting your program loaded from your hard disk,</p>



<p class="wp-block-paragraph">your hard disk your ssd or whatever into ram and sort of setting it up setting up an empty process</p>



<p class="wp-block-paragraph">and getting it all prepared so that the operating system can begin executing your process doesn&#8217;t</p>



<p class="wp-block-paragraph">actually execute it it just gets it set up so i mean think about it what if i click on my desktop</p>



<p class="wp-block-paragraph">here and i click on this little mouse icon this little text editor icon the mouse pad</p>



<p class="wp-block-paragraph">it launched what happened it wasn&#8217;t running before and now it is running something had to do that</p>



<p class="wp-block-paragraph">It wasn&#8217;t the desktop environment actually the desktop environment when I click this little button</p>



<p class="wp-block-paragraph">It just sent a signal to the operating system letting it know that I wanted to start executing a program</p>



<p class="wp-block-paragraph">But it didn&#8217;t actually load it up for me. That&#8217;s the loader module. The loader module is part of the operating system</p>



<p class="wp-block-paragraph">and imagine that as soon as I</p>



<p class="wp-block-paragraph">You know click this button right here a signal gets sent to the operating system or maybe even if I just execute a command like echo</p>



<p class="wp-block-paragraph">You know test or something or run get get status. Let&#8217;s say</p>



<p class="wp-block-paragraph">status let&#8217;s say or even I could run this terminal again terminator and it</p>



<p class="wp-block-paragraph">shows up in another window something like that let me exit from that you know</p>



<p class="wp-block-paragraph">anything that I exit whatever the loader module is involved so I click this and</p>



<p class="wp-block-paragraph">the first thing that will happen is the loader module will inspect the</p>



<p class="wp-block-paragraph">executable which is just kind of sitting on disk somewhere and it&#8217;ll make sure</p>



<p class="wp-block-paragraph">that it&#8217;s actually executable it&#8217;ll make sure not just in terms of you know</p>



<p class="wp-block-paragraph">That&#8217;s sort of an operating system thing, a different part of the operating system.</p>



<p class="wp-block-paragraph">But it&#8217;ll check to make sure, let&#8217;s say that it&#8217;s a binary program that needs to be executed.</p>



<p class="wp-block-paragraph">It&#8217;ll make sure that the data inside of the binary, the actual executable is correct for</p>



<p class="wp-block-paragraph">the current system that you&#8217;re on.</p>



<p class="wp-block-paragraph">Like right now I&#8217;m on Linux 64 bit.</p>



<p class="wp-block-paragraph">So it&#8217;ll make sure that the executable is in a ELF 64 format or a format that can be</p>



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



<p class="wp-block-paragraph">It&#8217;ll check that it&#8217;ll make sure everything&#8217;s okay to make sure it&#8217;s got some data. It&#8217;s got like a you know an entry point whatever</p>



<p class="wp-block-paragraph">If everything looks good, then it will go through system RAM and try to find a little place in RAM that&#8217;s unoccupied</p>



<p class="wp-block-paragraph">I&#8217;m not going to talk too much about operating system concepts beyond the loader module, but just so you know</p>



<p class="wp-block-paragraph">There is a paging system that it would go through which sort of lets you have fragmented memory without too much of a penalty</p>



<p class="wp-block-paragraph">the ram stick directly but for our purposes we&#8217;ll just say it&#8217;s looking for a free spot in memory</p>



<p class="wp-block-paragraph">anyway once it finds out that there&#8217;s a free spot in memory that&#8217;s big enough to accommodate</p>



<p class="wp-block-paragraph">the program then it actually loads the program from disk from ssd from whatever into that spot</p>



<p class="wp-block-paragraph">in memory and creates a process in the operating system remember everything that&#8217;s actually running</p>



<p class="wp-block-paragraph">in your operating system is a process there&#8217;s a process for this notepad there&#8217;s a process</p>



<p class="wp-block-paragraph">for the mouse stuff there&#8217;s a process for this little widget down here there&#8217;s a</p>



<p class="wp-block-paragraph">process for the entire desktop there&#8217;s a process for probably every tab in your</p>



<p class="wp-block-paragraph">browser you know a process just means here&#8217;s a little spot in memory on the</p>



<p class="wp-block-paragraph">computer and it&#8217;s got a program inside of it and it wants to be run by the CPU</p>



<p class="wp-block-paragraph">whenever the CPU thinks that it has some time to run that process so that&#8217;s like</p>



<p class="wp-block-paragraph">a process anyway so it you know it finds a spot in memory it loads the program in</p>



<p class="wp-block-paragraph">you know checks everything it sets it up as a process which means it has to set up some data</p>



<p class="wp-block-paragraph">structures in the operating system indicating hey there&#8217;s a new process in town and here&#8217;s where the</p>



<p class="wp-block-paragraph">memory is and here&#8217;s the first instruction that you should execute and it just kind of sets</p>



<p class="wp-block-paragraph">everything up so that it&#8217;s like a like a ready process a process in the ready state that hasn&#8217;t</p>



<p class="wp-block-paragraph">been actually executed yet but it&#8217;s ready to get executed so once it does all of that</p>



<p class="wp-block-paragraph">new process you know setting everything up maybe figuring out what is the virtual memory address</p>



<p class="wp-block-paragraph">that the process is going to see and so forth then finally it lets the operating system know</p>



<p class="wp-block-paragraph">that the process is ready to run so before it was just kind of like loading it and setting it up</p>



<p class="wp-block-paragraph">marking little flags figuring out the virtual memory offset all that stuff then once that&#8217;s</p>



<p class="wp-block-paragraph">all finished it just tells the operating system now this process is ready to run the process</p>



<p class="wp-block-paragraph">I&#8217;m going to try my best not to talk too much about operating systems concepts beyond the loader module, but</p>



<p class="wp-block-paragraph">the loader module&#8217;s job is not to run the process. It&#8217;s just to load it, just to set it up.</p>



<p class="wp-block-paragraph">At some later point in time, maybe some amount of microseconds or milliseconds in the future,</p>



<p class="wp-block-paragraph">the operating system will decide, okay, now I&#8217;m ready to let that program run for a little while.</p>



<p class="wp-block-paragraph">Since the process has already been set up by the loader module, the operating system knows where</p>



<p class="wp-block-paragraph">it is in memory and it knows the next instruction address or offset address to execute. It&#8217;ll just</p>



<p class="wp-block-paragraph">set address to execute it&#8217;ll just start bringing those instructions onto the CPU and just execute</p>



<p class="wp-block-paragraph">them for some amount of time and then the operating system will decide to stop and take it off the CPU</p>



<p class="wp-block-paragraph">again you know put it back just into a into a ready state and then it just keeps switching back</p>



<p class="wp-block-paragraph">and forth between that by the way have you ever wondered how it is that maybe your CPU only has</p>



<p class="wp-block-paragraph">one core or only eight cores but there are hundreds of browser tabs that you have open</p>



<p class="wp-block-paragraph">hundreds and hundreds of processes that you have open that&#8217;s how the operating system does it it</p>



<p class="wp-block-paragraph">it simulates it provides the illusion that all these programs are running at the same time so</p>



<p class="wp-block-paragraph">this notepad process right here it&#8217;s not actually running at all times it just runs in tiny little</p>



<p class="wp-block-paragraph">slices again i&#8217;ll try to stay away from explaining that too much because i&#8217;m really here to talk</p>



<p class="wp-block-paragraph">about the loader module another thing to keep in mind is that eventually when your process terminates</p>



<p class="wp-block-paragraph">like the the program terminates itself or the operating system kills it for some reason or just</p>



<p class="wp-block-paragraph">or just, you know, something happens to where it&#8217;s just not going to be running anymore.</p>



<p class="wp-block-paragraph">It&#8217;s not the loader module that has anything to do with that.</p>



<p class="wp-block-paragraph">And there is no unloader module.</p>



<p class="wp-block-paragraph">It will just mark itself as, you know, I&#8217;m done, I&#8217;m terminated, whatever,</p>



<p class="wp-block-paragraph">or it&#8217;ll get marked.</p>



<p class="wp-block-paragraph">Then the operating system will come along and clean it up.</p>



<p class="wp-block-paragraph">So loader module is not involved in that step.</p>



<p class="wp-block-paragraph">It&#8217;s just involved in getting everything set up so that it can start to execute.</p>



<p class="wp-block-paragraph">And that&#8217;s the basic idea.</p>



<p class="wp-block-paragraph">detailed but that&#8217;s what the loader module does in general and you probably</p>



<p class="wp-block-paragraph">have a loader module on your operating system right now unless you&#8217;re running</p>



<p class="wp-block-paragraph">some bizarre operating system that has some other strange method of doing</p>



<p class="wp-block-paragraph">things okay that&#8217;s all I really wanted to say in this video thank you so much</p>



<p class="wp-block-paragraph">for watching I hope you learned a little bit of stuff and had some fun I&#8217;ll see</p>



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



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



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



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



<p class="wp-block-paragraph">Could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media?</p>



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



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



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



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



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



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



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could troll me if you want to just wake me up in</p>



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



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



<p class="wp-block-paragraph">QR code which you can scan in order to go to the website which I think is also</p>



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-the-loader-module-works-launching-programs-in-your-operating-system-explained/">How the Loader Module Works: Launching Programs in Your Operating System Explained!</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-the-loader-module-works-launching-programs-in-your-operating-system-explained/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 class="wp-block-paragraph">Hey everyone, let’s talk linkers! In this video, we unpack the general idea of linking in programming—taking your source code, turning it into object files, and stitching them into an executable. We dive into virtual memory, how programs use offsets, and why jump instructions matter across modules. Using simple assembly and C++ examples, we’ll show how linkers lay out modules, handle labels, and make function calls work. Whether you’re a beginner or a coder curious about what happens under the hood, this is for you! Hit subscribe, scan the QR code for more tutorials, and drop a comment with your thoughts or video ideas. Let’s keep learning and have some fun with code! #Programming #Linker #VirtualMemory #CodingExplained</p>



<p class="wp-block-paragraph">Introduction to Linking 00:00:00<br>Compilation and Object Files 00:00:05<br>Linker Overview 00:00:32<br>Virtual Memory Explanation 00:00:42<br>Program Memory Offsets 00:01:18<br>Jump Instructions in Modules 00:02:54<br>Module Address Space 00:03:38<br>Assembler and Label Jumps 00:04:02<br>Linker’s Role in Module Layout 00:07:15<br>Function Calls Across Modules 00:08:04<br>Marking Labels as Global 00:09:31<br>External Function Calls 00:10:23<br>Data in Executables 00:11:12<br>Conclusion and Call to Subscribe 00:12:08</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hey there, I want to talk to you very quickly about the general idea of linking your programs.</p>



<p class="wp-block-paragraph">In previous videos I&#8217;ve described exactly how to perform the linking stage when you&#8217;re compiling</p>



<p class="wp-block-paragraph">a program. So you write some source code, you compile the source code into object files,</p>



<p class="wp-block-paragraph">you know each file becomes one individual object file, and then when we&#8217;re done we take all the</p>



<p class="wp-block-paragraph">object files and we link them up into an executable program. So I&#8217;ve talked about that</p>



<p class="wp-block-paragraph">I just wanted to talk to you about the general idea of the linking stage in general.</p>



<p class="wp-block-paragraph">Like what is the linker? What is its job? What is it actually doing?</p>



<p class="wp-block-paragraph">So try to keep in mind for starters, each program uses virtual memory.</p>



<p class="wp-block-paragraph">It uses a virtual memory space.</p>



<p class="wp-block-paragraph">So obviously on your computer you have real memory,</p>



<p class="wp-block-paragraph">but there&#8217;s lots of layers of abstraction between the physical hardware</p>



<p class="wp-block-paragraph">the physical hardware and the program that&#8217;s running for starters the operating system uses</p>



<p class="wp-block-paragraph">a paging system the memory stick the memory circuitry might be doing something else for</p>



<p class="wp-block-paragraph">error checking or just you know transport or whatever so so try and bear in mind that each</p>



<p class="wp-block-paragraph">program thinks that it&#8217;s it thinks that itself is kind of the beginning of memory you could imagine</p>



<p class="wp-block-paragraph">it as each program thinks that its first memory location that it has assigned to it is memory</p>



<p class="wp-block-paragraph">location zero but that wouldn&#8217;t necessarily be the case on the computer</p>



<p class="wp-block-paragraph">your operating system probably would have come up with an offset let&#8217;s say</p>



<p class="wp-block-paragraph">for example you know your computer decides to launch your program it</p>



<p class="wp-block-paragraph">creates a process it finds a chunk of memory that&#8217;s available across you know</p>



<p class="wp-block-paragraph">one or more pages of free memory and let&#8217;s say for the sake of argument that</p>



<p class="wp-block-paragraph">the starting offset for the for the quote-unquote real forgetting the other</p>



<p class="wp-block-paragraph">layers layers of abstraction the real memory location of your program is going</p>



<p class="wp-block-paragraph">of your program is going to be let&#8217;s just say like a thousand I know that&#8217;s</p>



<p class="wp-block-paragraph">real unrealistically too low but let&#8217;s just say a thousand and then let&#8217;s say</p>



<p class="wp-block-paragraph">that your program then thinks that it starts at memory location zero that</p>



<p class="wp-block-paragraph">means if your program wants to access memory location 100 then under the hood</p>



<p class="wp-block-paragraph">at the last moment right before you actually hit the RAM stick or hit the</p>



<p class="wp-block-paragraph">page file system a translation has to be performed so if your program is trying</p>



<p class="wp-block-paragraph">what actually happens is you know the general offset for the entire program</p>



<p class="wp-block-paragraph">gets added to memory location 100 and then that tells the computer or the</p>



<p class="wp-block-paragraph">operating system that what you&#8217;re actually trying to do in your program is</p>



<p class="wp-block-paragraph">access memory location 1100 so keep in mind all of this memory is virtual</p>



<p class="wp-block-paragraph">and the modules themselves also need to know where to jump when I say where to</p>



<p class="wp-block-paragraph">Well, suppose for the sake of argument, you have a program that has some jump instructions</p>



<p class="wp-block-paragraph">or go to instructions or like some conditional branching instructions, anything where execution</p>



<p class="wp-block-paragraph">is not just going to go to the very next statement.</p>



<p class="wp-block-paragraph">Execution is going to go somewhere else.</p>



<p class="wp-block-paragraph">Like maybe you have an if else block.</p>



<p class="wp-block-paragraph">It&#8217;s got to maybe jump sometimes down to the else part instead of the top if part.</p>



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



<p class="wp-block-paragraph">There will be lots of times in all of your programs where execution kind of has to jump</p>



<p class="wp-block-paragraph">around somewhere if the program is even a little bit complicated.</p>



<p class="wp-block-paragraph">So that could be a jump instruction, go to in a higher level language, not assembly necessarily,</p>



<p class="wp-block-paragraph">jump if not equal and so forth.</p>



<p class="wp-block-paragraph">So if you imagine writing one module, you could also imagine that the module has its</p>



<p class="wp-block-paragraph">own virtual memory address space.</p>



<p class="wp-block-paragraph">Just imagine it for now.</p>



<p class="wp-block-paragraph">And maybe it starts at zero.</p>



<p class="wp-block-paragraph">at zero that&#8217;s that&#8217;s not what we&#8217;re going to say but just like imagine the module only really knows</p>



<p class="wp-block-paragraph">about itself and so sometimes when you&#8217;re jumping for example if we&#8217;re going to jump uh when</p>



<p class="wp-block-paragraph">something is not equal to something else we&#8217;ll jump to some label and in order to jump to that</p>



<p class="wp-block-paragraph">label the assembler needs to know you know where is that label inside of your source code so pretend</p>



<p class="wp-block-paragraph">just for a moment this is not like a real assembly program but just pretend for a moment that we have</p>



<p class="wp-block-paragraph">and maybe this is like I don&#8217;t know the main label that gets jumped into from GCC and</p>



<p class="wp-block-paragraph">so then we have like a label down here outside and we&#8217;ll do stuff and then jump back to the</p>



<p class="wp-block-paragraph">original point so we probably have to do a label here main finish this is this is bad form but I&#8217;m</p>



<p class="wp-block-paragraph">So if we jump, let&#8217;s compare, I don&#8217;t know, one with two or something.</p>



<p class="wp-block-paragraph">Let&#8217;s compare RAX to RDX and we&#8217;ll just move RAX the value one and move RDX the value two</p>



<p class="wp-block-paragraph">so they&#8217;re not actually equal.</p>



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



<p class="wp-block-paragraph">So definitely now we know, oh, we are going to jump down to that label.</p>



<p class="wp-block-paragraph">So execution is going to go directly down to here.</p>



<p class="wp-block-paragraph">we&#8217;ll do something and then eventually maybe we want to jump back so we&#8217;ll say uh</p>



<p class="wp-block-paragraph">maybe let&#8217;s do it again let&#8217;s do let&#8217;s do like a whole set of statements again we&#8217;ll say jump</p>



<p class="wp-block-paragraph">if it is equal and we&#8217;ll just like load those two registers so one and one and then compare</p>



<p class="wp-block-paragraph">them and then say jump if it is equal to main finish this is not a video about conditional</p>



<p class="wp-block-paragraph">branching or jumping i&#8217;m trying to make this as simple as i can but i hope you understand the</p>



<p class="wp-block-paragraph">but i hope you understand the point is just basically we&#8217;re jumping around within the same</p>



<p class="wp-block-paragraph">module right so it&#8217;s easy for the program to understand where to jump if it&#8217;s in the same</p>



<p class="wp-block-paragraph">module or i guess the the object file when we&#8217;re assembling it it&#8217;s easy to understand where to jump</p>



<p class="wp-block-paragraph">because if we&#8217;re at line 8 here when we start to jump and then the actual label here has its first</p>



<p class="wp-block-paragraph">instruction at line 17 well then it you know the amount of instructions to move is just the</p>



<p class="wp-block-paragraph">the difference you know so it&#8217;s easy to say all right if our virtual address is you know this</p>



<p class="wp-block-paragraph">when we jump and we&#8217;re going to jump this much of a difference based on where the label is then now</p>



<p class="wp-block-paragraph">we can just compute the new virtual address to jump or the absolute address or whatever you want</p>



<p class="wp-block-paragraph">to whatever you want to do on that particular run but how does it know where to jump in another</p>



<p class="wp-block-paragraph">module because when we assemble this module as an object file the assembler is only running one pass</p>



<p class="wp-block-paragraph">one pass on just this object file it doesn&#8217;t really know the addresses in the other modules</p>



<p class="wp-block-paragraph">it doesn&#8217;t know their offsets of its labels even if it&#8217;s a c plus plus or a c module it doesn&#8217;t</p>



<p class="wp-block-paragraph">really know the offsets it doesn&#8217;t know where the functions start and end doesn&#8217;t know anything</p>



<p class="wp-block-paragraph">because right now if we assemble this one source code it&#8217;s only going to know about this one source</p>



<p class="wp-block-paragraph">code right and the same goes for the other modules if we compile a c plus plus program to an object</p>



<p class="wp-block-paragraph">a function or you know do a go to statement or something into one of these labels from this</p>



<p class="wp-block-paragraph">module the c plus plus program won&#8217;t really know where it is it won&#8217;t know what address it&#8217;s at it</p>



<p class="wp-block-paragraph">won&#8217;t know the offset right so that&#8217;s the job of the linker the linker looks at all of these labels</p>



<p class="wp-block-paragraph">and all of these uh conditional branching statements and jump statements and everything</p>



<p class="wp-block-paragraph">and it just decides for starters it decides where each module is going to start in memory so maybe</p>



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



<p class="wp-block-paragraph">starts right after it and then another module right after that and it&#8217;ll just kind of decide</p>



<p class="wp-block-paragraph">where every module will start in the final executable that we&#8217;re actually linking together.</p>



<p class="wp-block-paragraph">Once it decides the layout then it knows the offset of all the different modules and therefore</p>



<p class="wp-block-paragraph">it can compute the additional offset that it would take to get to all the labels. So then at that</p>



<p class="wp-block-paragraph">Your C++ module will make a function call inside of, you know, some assembly module like the one we&#8217;re looking at, assuming it was written a little bit differently.</p>



<p class="wp-block-paragraph">Main finish return.</p>



<p class="wp-block-paragraph">I guess the way it&#8217;s written down here, it&#8217;s returning to main if we just kind of execute it as we&#8217;re looking at it.</p>



<p class="wp-block-paragraph">But another module could could call main finish as a function and still get a return statement.</p>



<p class="wp-block-paragraph">That would actually work, even though it&#8217;s probably bad design.</p>



<p class="wp-block-paragraph">that your assembly sorry your C++ program wants to call a function called</p>



<p class="wp-block-paragraph">main finish inside of this module the linker having already laid out the</p>



<p class="wp-block-paragraph">modules and and being aware of all their offsets it knows okay so you know this</p>



<p class="wp-block-paragraph">assembly module it was underneath the C++ module so it&#8217;ll just take that offset</p>



<p class="wp-block-paragraph">and add it to the offset of the label itself within the module and then also</p>



<p class="wp-block-paragraph">add that to the the virtual address or I guess the operating system will do the</p>



<p class="wp-block-paragraph">address. But you know, the point is the linker coordinates all the jumps and the conditional</p>



<p class="wp-block-paragraph">branches where the functions start, lays out all the modules, gets all the offsets,</p>



<p class="wp-block-paragraph">and then starts replacing all of the conditional branches and jumps and things with the real</p>



<p class="wp-block-paragraph">offsets that make it actually doable. Like let&#8217;s jump to exactly this memory location</p>



<p class="wp-block-paragraph">in code exactly in quotes, because we&#8217;re still using virtual addressing.</p>



<p class="wp-block-paragraph">idea of the linker it knows how to jump between modules um wants to link or discuss okay that&#8217;s</p>



<p class="wp-block-paragraph">all i really wanted to say don&#8217;t forget if you want a label to be available to jump into or to</p>



<p class="wp-block-paragraph">call as a function from outside the module you got to mark it as global so if i actually wanted</p>



<p class="wp-block-paragraph">somebody to be able to call main finish as a function i just have to mark it as global same</p>



<p class="wp-block-paragraph">thing for some label if i say global some label then now at this point another module could call</p>



<p class="wp-block-paragraph">call this as a function or jump into it probably bad form to not put a return a return statement</p>



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



<p class="wp-block-paragraph">to add more complicated logic so i can use a function call that gets jumped around if it is</p>



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



<p class="wp-block-paragraph">and then also of course if you intend to jump somewhere else remember that you have to mark</p>



<p class="wp-block-paragraph">So let&#8217;s say there&#8217;s a function in your other module, your C++ module or your C module or your assembly module.</p>



<p class="wp-block-paragraph">You just have to mark it as extern in the text section, in the text segment, like some other function somewhere else, something like that.</p>



<p class="wp-block-paragraph">And then once I do that, now I could actually call it, I could say, call, you know, this.</p>



<p class="wp-block-paragraph">Actually, that&#8217;ll never get reached because the jump equal thing is at the bottom.</p>



<p class="wp-block-paragraph">equal thing is at the bottom but I could do this I could say call it if it was actually a function</p>



<p class="wp-block-paragraph">or I could say jump if it was just a jump point or I could say you know jump not equal to</p>



<p class="wp-block-paragraph">the other function instead of some label something like that so lots of stuff you can do and now you</p>



<p class="wp-block-paragraph">kind of understand the idea of linking is taking all the modules stuffing them inside of the final</p>



<p class="wp-block-paragraph">executable and also putting data inside of the final executable you know like if you&#8217;re creating</p>



<p class="wp-block-paragraph">So, you know, like if you&#8217;re creating a string variable in your globals area of your assembly</p>



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



<p class="wp-block-paragraph">inside of the executable.</p>



<p class="wp-block-paragraph">Otherwise, it wouldn&#8217;t be anywhere when we ran the program.</p>



<p class="wp-block-paragraph">So, yeah, it sticks the data in there.</p>



<p class="wp-block-paragraph">It sticks the segments in there.</p>



<p class="wp-block-paragraph">It, you know, calculates the jumps and all that stuff.</p>



<p class="wp-block-paragraph">I just want to point out you could put strings in a configuration file.</p>



<p class="wp-block-paragraph">of a vanilla C++ or assembly program you probably are making strings directly in the program.</p>



<p class="wp-block-paragraph">Anyway, so I think that&#8217;s the gist of everything that I really wanted to say about what is the</p>



<p class="wp-block-paragraph">general idea of the linker. Thanks for watching this video I hope you learned a little bit and</p>



<p class="wp-block-paragraph">had some fun. I will see you in the next video. Hey everybody thanks for watching this video again</p>



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



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



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



<p class="wp-block-paragraph">world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



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



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



<p class="wp-block-paragraph">because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
