<?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>x86-64 Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/x86-64/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/x86-64/</link>
	<description></description>
	<lastBuildDate>Sun, 22 Mar 2026 01:28:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>x86-64 Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/x86-64/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>YASM x86-64 Assembly Functions Tutorial &#8211; Integers, Floats, Pointers, ABI, C++ Interoperability</title>
		<link>https://www.NeuralLantern.com/yasm-x86-64-assembly-functions-tutorial-integers-floats-pointers-abi-c-interoperability/</link>
					<comments>https://www.NeuralLantern.com/yasm-x86-64-assembly-functions-tutorial-integers-floats-pointers-abi-c-interoperability/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 22 Mar 2026 01:28:30 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[abi x86-64]]></category>
		<category><![CDATA[amd64]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[C++ assembly interop]]></category>
		<category><![CDATA[call ret assembly]]></category>
		<category><![CDATA[extern C]]></category>
		<category><![CDATA[floating point assembly]]></category>
		<category><![CDATA[hybrid C++ assembly]]></category>
		<category><![CDATA[linux assembly]]></category>
		<category><![CDATA[passing arguments assembly]]></category>
		<category><![CDATA[rax return]]></category>
		<category><![CDATA[system v abi]]></category>
		<category><![CDATA[ubuntu assembly]]></category>
		<category><![CDATA[writing functions assembly]]></category>
		<category><![CDATA[x64 assembly]]></category>
		<category><![CDATA[x86-64]]></category>
		<category><![CDATA[xmm registers]]></category>
		<category><![CDATA[xmm0 return]]></category>
		<category><![CDATA[yasm]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=321</guid>

					<description><![CDATA[<p>Learn how to write callable functions in YASM x86-64 assembly on Ubuntu. Covers passing integers, pointers, and floating-point values, using the correct registers (RDI, RSI, XMM0, etc.), returning values in RAX/XMM0, extern \"C\" for C++ interop, and building a hybrid C++/Assembly program.</p>
<p>The post <a href="https://www.NeuralLantern.com/yasm-x86-64-assembly-functions-tutorial-integers-floats-pointers-abi-c-interoperability/">YASM x86-64 Assembly Functions Tutorial &#8211; Integers, Floats, Pointers, ABI, C++ Interoperability</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="YASM x86-64 Assembly Functions Tutorial - Integers, Floats, Pointers, ABI, C++ Interoperability" width="1380" height="776" src="https://www.youtube.com/embed/fXf3Gpf-fyM?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">Quick but complete guide to writing proper functions in YASM x86-64 assembly on Linux. See how to pass integers, pointers &amp; floats, return values, follow the ABI, disable C++ name mangling with extern &#8220;C&#8221;, and call back and forth between C++ and assembly in a real working example.</p>



<p class="wp-block-paragraph">Great for people moving from NASM/GAS or trying to mix assembly with higher-level code.</p>



<p class="wp-block-paragraph">00:00 Introduction and Video Overview<br>00:28 What Are Functions in Programming<br>00:56 Why Functions Are Harder in Assembly<br>01:24 Topics Covered in This Video<br>01:59 About the Makefile and Prerequisites<br>02:28 Hybrid C++ and Assembly Program Plan<br>03:01 Using extern &#8220;C&#8221; to Disable Name Mangling<br>04:03 Main Driver Function in C++<br>05:00 Adding a Callable C++ Function for Assembly<br>05:42 Explaining extern &#8220;C&#8221; Placement<br>06:16 Assembly File Skeleton and Data Section<br>06:41 Creating Null-Terminated Strings<br>07:49 Section .text and External Symbols<br>08:52 Declaring my_cpp_function as extern<br>09:20 Defining my_assembly_function<br>09:40 Labels vs Real Functions<br>10:31 The call Instruction and Return Address<br>11:16 Why Jumping Instead of Calling Crashes<br>11:47 Global Directive for Exporting Functions<br>12:32 Basic Function Structure<br>13:20 Implementing my_assembly_function Prologue<br>14:50 Receiving Arguments in ABI Registers<br>16:30 Printing Received Integer Arguments<br>18:10 Handling Pointer Arguments (C Strings)<br>19:40 Passing Floating-Point Arguments in XMM<br>21:15 Printing Floats from Assembly<br>23:00 Calling Back to C++ Function<br>25:40 Preparing Arguments for my_cpp_function<br>27:20 Loading XMM0 and XMM1 for Floats<br>29:10 Making the Call to C++ Function<br>30:50 Receiving Double Return Value in XMM0<br>32:30 Saving Returned Float to Memory<br>34:10 Printing the Returned Value<br>36:00 Final Messages and Program Flow<br>38:20 Fixing String Pointer Crash Issue<br>40:00 Correcting Argument Loading<br>42:10 Passing String Owned by Assembly<br>44:00 Observing Successful Output<br>45:47 Saving and Restoring XMM0 Safely<br>47:14 Printing Final Returned Float<br>48:32 Importance of Following the ABI<br>50:29 Summary of Covered Topics<br>51:03 Closing Remarks and Call to Subscribe</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">In this video I&#8217;m going to teach you how to write functions in YASM x86-64 assembly inside</p>



<p class="wp-block-paragraph">of Ubuntu, although probably any YASM assembler will be fine.</p>



<p class="wp-block-paragraph">I&#8217;ve covered these topics before in other videos, but I thought it would be nice to</p>



<p class="wp-block-paragraph">put them all here in one single video to make it a little bit easier to understand.</p>



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



<p class="wp-block-paragraph">Well, you know, when you have a program, let&#8217;s say we have a higher level language program</p>



<p class="wp-block-paragraph">and we have like, you know, void or actually probably not void main, let&#8217;s say int main</p>



<p class="wp-block-paragraph">and we&#8217;ll forget about the arguments and inside of main, it just sort of calls f and then</p>



<p class="wp-block-paragraph">we have an f function over here and it, you know, does stuff, right?</p>



<p class="wp-block-paragraph">So that&#8217;s the basic idea of having a function that you can call and calling it.</p>



<p class="wp-block-paragraph">We sort of take the whole process for granted in higher level languages, but in assembly,</p>



<p class="wp-block-paragraph">in assembly we have to do a lot more from scratch so I&#8217;m going to show you about how to pass</p>



<p class="wp-block-paragraph">arguments how to pass integer arguments pointer arguments floating point arguments return types</p>



<p class="wp-block-paragraph">you know double like floating return types integer return types pointer return types</p>



<p class="wp-block-paragraph">how to use special registers to actually pass the arguments into the functions how to write a</p>



<p class="wp-block-paragraph">so that&#8217;s basically what we&#8217;re going to do before before i get any further here i just want to point</p>



<p class="wp-block-paragraph">out that um this video is not about the basics of assembly nor is it about the basics of um</p>



<p class="wp-block-paragraph">make files or some of the other related technologies that i&#8217;m going to show</p>



<p class="wp-block-paragraph">i&#8217;ve covered everything in this video in a previous video um so if you if you find yourself</p>



<p class="wp-block-paragraph">getting lost and you don&#8217;t understand what i&#8217;m saying or what i&#8217;m doing you probably want to</p>



<p class="wp-block-paragraph">look at my previous videos because this is sort of a summary video to kind of help you</p>



<p class="wp-block-paragraph">of help you help you really lock down on the concepts of writing functions okay so for starters</p>



<p class="wp-block-paragraph">this right here that you&#8217;re looking at is a make file this is not a make file video if you want to</p>



<p class="wp-block-paragraph">learn how to make make files or why they&#8217;re awesome see my other videos but i&#8217;m just going to assume</p>



<p class="wp-block-paragraph">at this point you&#8217;re either willing to research my other video or you already know or you don&#8217;t care</p>



<p class="wp-block-paragraph">how to make a make file so you know we&#8217;re just going to skip this i&#8217;m going to close it</p>



<p class="wp-block-paragraph">function or sorry a driver module and what I&#8217;m going to do is I&#8217;m going to write this program</p>



<p class="wp-block-paragraph">that I&#8217;m showing you now as a as a hybrid program a program with modules of different languages so</p>



<p class="wp-block-paragraph">this module right here is going to be c++ and then we&#8217;re going to have an assembly module and</p>



<p class="wp-block-paragraph">then they&#8217;re going to be able to call each other so the first thing that I&#8217;m going to do is I&#8217;m</p>



<p class="wp-block-paragraph">going to name some functions that are going to be inside of my assembly module and also name some</p>



<p class="wp-block-paragraph">module and also name some functions that are going to well name a function that&#8217;s</p>



<p class="wp-block-paragraph">going to be just inside of the C++ module but it should be callable by the</p>



<p class="wp-block-paragraph">assembly module so for that we use a little block called extern C and long</p>



<p class="wp-block-paragraph">story short that disables name mangling which C++ does in order to provide</p>



<p class="wp-block-paragraph">overloading functionality so we&#8217;re basically going to disable overload</p>



<p class="wp-block-paragraph">functionality in order to have simple function names that way assembly can</p>



<p class="wp-block-paragraph">and also when we attempt to call a function inside of assembly we&#8217;ll just call it by its</p>



<p class="wp-block-paragraph">simple name rather than try to mangle the name based on the the arguments and return type and</p>



<p class="wp-block-paragraph">such so that that&#8217;s something we have to do for compatibility at least for this video and I&#8217;m just</p>



<p class="wp-block-paragraph">going to move on so basically you just take you just take the keyword extern and you put a c in</p>



<p class="wp-block-paragraph">a quote and then you make a block right a little braces scope and then you just list prototypes of</p>



<p class="wp-block-paragraph">types of either the functions inside of the current module which you would like to demangle</p>



<p class="wp-block-paragraph">or other modules functions that you would like to be able to call in a demangled or</p>



<p class="wp-block-paragraph">I guess a non-mangled way.</p>



<p class="wp-block-paragraph">Mangled meaning name mangling.</p>



<p class="wp-block-paragraph">Okay, so then I&#8217;m going to copy paste the main function that I&#8217;m going to do.</p>



<p class="wp-block-paragraph">So this is a hybrid program, which means you know there are several different modules of</p>



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



<p class="wp-block-paragraph">driver which just launches the program and it contains like the entry point</p>



<p class="wp-block-paragraph">like see how there&#8217;s like the the main entry point which if you know how to do</p>



<p class="wp-block-paragraph">other languages this is usually where you start in C++ or like the GCC</p>



<p class="wp-block-paragraph">libraries so this is the entry point for our whole program and then once we&#8217;re</p>



<p class="wp-block-paragraph">inside of here we&#8217;re just kind of print out a message to the user we&#8217;re gonna</p>



<p class="wp-block-paragraph">make a C string and then we&#8217;re gonna call on the assembly function we&#8217;re</p>



<p class="wp-block-paragraph">gonna give it you know some numbers some integers and some floats and we&#8217;re</p>



<p class="wp-block-paragraph">gonna give it our C string and then when we&#8217;re inside of the assembly</p>



<p class="wp-block-paragraph">and then when we&#8217;re inside of the assembly function we&#8217;re just going to print those things to prove</p>



<p class="wp-block-paragraph">that we know how to call and we know how to receive data from c or c plus plus into assembly</p>



<p class="wp-block-paragraph">and then we&#8217;re just going to print you know goodbye basically okay so uh i&#8217;m going to make</p>



<p class="wp-block-paragraph">another uh let&#8217;s see another function in the driver so that assembly has something to call</p>



<p class="wp-block-paragraph">because i don&#8217;t just want to be able to call assembly from c i also want to be able to call</p>



<p class="wp-block-paragraph">put in something that we can call on from assembly here.</p>



<p class="wp-block-paragraph">I&#8217;m going to call it my CPP function.</p>



<p class="wp-block-paragraph">And it&#8217;s just going to have like some arguments,</p>



<p class="wp-block-paragraph">just some nonsense arguments.</p>



<p class="wp-block-paragraph">And all it&#8217;s going to do is just print out that it&#8217;s entering,</p>



<p class="wp-block-paragraph">print out the arguments and then just sort of say goodbye.</p>



<p class="wp-block-paragraph">And then just return a value to the caller.</p>



<p class="wp-block-paragraph">We&#8217;re going to return a floating point value to the call.</p>



<p class="wp-block-paragraph">And we&#8217;re going to return a floating point value to the caller.</p>



<p class="wp-block-paragraph">floating point value to the color okay so notice how at the top here i have uh in the extern c my</p>



<p class="wp-block-paragraph">cpp function it&#8217;s the same thing that we see at the top is now at the bottom and that just means</p>



<p class="wp-block-paragraph">uh this normally would be compiled and linked with name mangling and so because it&#8217;s in the</p>



<p class="wp-block-paragraph">extern c block there&#8217;s no name mangling and the reason that works with an extern c block is</p>



<p class="wp-block-paragraph">because there&#8217;s no name mangling in c that&#8217;s sort of like a c plus plus thing with overloads and like</p>



<p class="wp-block-paragraph">whatever okay so we have like the basics for our driver it&#8217;s a simple module the hard work is going</p>



<p class="wp-block-paragraph">to be inside of assembly so uh maybe before we write assembly oh you know what let&#8217;s write the</p>



<p class="wp-block-paragraph">skeleton of the assembly and then i&#8217;ll start explaining uh what it means to call back and</p>



<p class="wp-block-paragraph">forth and to make functions and things like that okay so for starters i&#8217;m just going to make a data</p>



<p class="wp-block-paragraph">section with a bunch of stuff inside of it and i&#8217;ll explain it just very briefly again this video is</p>



<p class="wp-block-paragraph">basics of assembly in Yasm. If you want to learn the basics, go see my other videos.</p>



<p class="wp-block-paragraph">But for now, I&#8217;ll just assume that you understand why we&#8217;re making variables in the data section</p>



<p class="wp-block-paragraph">and kind of how to do it. So I&#8217;m just, you can see here, I&#8217;m making a bunch of null terminated</p>



<p class="wp-block-paragraph">strings. They&#8217;re null because they have a zero at the end. And I&#8217;m just saying, well, here&#8217;s a</p>



<p class="wp-block-paragraph">message when we begin the program. Here&#8217;s a message to announce we&#8217;re about to print some integers,</p>



<p class="wp-block-paragraph">to print a C string, to print some floats. Here&#8217;s another message for this, another message for</p>



<p class="wp-block-paragraph">messages right then a crlf that&#8217;s just you know taking the cursor down to the</p>



<p class="wp-block-paragraph">next line and then back to the very beginning so it&#8217;s like a basically a new</p>



<p class="wp-block-paragraph">line and then I&#8217;m gonna have some floating point numbers and I&#8217;m gonna</p>



<p class="wp-block-paragraph">have an a and a B number and then I&#8217;m gonna have a B and a D that I&#8217;ll send</p>



<p class="wp-block-paragraph">somewhere else and so I&#8217;m gonna populate them with numbers from the start the B</p>



<p class="wp-block-paragraph">and the D that just are not being sent they start at zero because we&#8217;re gonna</p>



<p class="wp-block-paragraph">we&#8217;re going to receive those numbers from C and then we&#8217;re going to get a return value as a</p>



<p class="wp-block-paragraph">floating point from the C function that we call so we&#8217;re just going to store it there so I&#8217;m just</p>



<p class="wp-block-paragraph">like making a bunch of room to store some from some variables and then here we&#8217;re just going</p>



<p class="wp-block-paragraph">to do system right and we&#8217;re going to send to standard output that&#8217;s covered in other videos</p>



<p class="wp-block-paragraph">but basically we&#8217;re just going to be printing stuff okay so section text now this is where</p>



<p class="wp-block-paragraph">actually starts. Well, sort of. This is where the program contains instructions to execute.</p>



<p class="wp-block-paragraph">So section text. And the first thing I&#8217;m going to do is I&#8217;m going to name some external symbols</p>



<p class="wp-block-paragraph">that I have for myself just to help me print integers and floats. So, you know, if you&#8217;ve</p>



<p class="wp-block-paragraph">seen my other videos, you know that you can do a wide variety of things to sort of print characters</p>



<p class="wp-block-paragraph">and numbers if you were clever. And you can also call on C library functions like printf.</p>



<p class="wp-block-paragraph">functions like printf if you really wanted to print floating point numbers</p>



<p class="wp-block-paragraph">and signed integers and stuff so you don&#8217;t have access to this library so</p>



<p class="wp-block-paragraph">don&#8217;t worry about putting this part in your code if you&#8217;re working at this from</p>



<p class="wp-block-paragraph">home unless you&#8217;re someone that has taken a class that I&#8217;ve taught somewhere</p>



<p class="wp-block-paragraph">and for now just just assume that this just lets me print very easily no</p>



<p class="wp-block-paragraph">problem you don&#8217;t really need that if you&#8217;re just kind of experimenting with</p>



<p class="wp-block-paragraph">function this is the name of the function that we made in the driver my cpp function notice how it&#8217;s</p>



<p class="wp-block-paragraph">over here my cpp function we&#8217;re just letting our assembly module know that there&#8217;s a function in</p>



<p class="wp-block-paragraph">another module that we should be able to call on even though all these modules are going to be</p>



<p class="wp-block-paragraph">linked into the same program we still have to do this just to let the assembly module know</p>



<p class="wp-block-paragraph">okay so now we need to make a function called my assembly function if you look at the top right here</p>



<p class="wp-block-paragraph">We had this other D name mingled prototype, my assembly function.</p>



<p class="wp-block-paragraph">So we have to actually write that somewhere.</p>



<p class="wp-block-paragraph">It&#8217;s not in the driver.</p>



<p class="wp-block-paragraph">Let&#8217;s write it inside of assembly.</p>



<p class="wp-block-paragraph">So my assembly function is going to start right here.</p>



<p class="wp-block-paragraph">Boom, right there.</p>



<p class="wp-block-paragraph">So this is when we kind of start on the basics of writing a function.</p>



<p class="wp-block-paragraph">So for starters, hopefully you understand labels.</p>



<p class="wp-block-paragraph">If you don&#8217;t understand labels by now, you might want to see my other videos.</p>



<p class="wp-block-paragraph">just some sort of an alphanumeric symbol that you just kind of write as sort of</p>



<p class="wp-block-paragraph">sort of like a variable name.</p>



<p class="wp-block-paragraph">You can&#8217;t use every symbol available.</p>



<p class="wp-block-paragraph">I would just start with using letters and numbers in the underscore.</p>



<p class="wp-block-paragraph">Of course, you can always experiment if you want to see what&#8217;s allowed and what&#8217;s</p>



<p class="wp-block-paragraph">not just type something and see if it compiles.</p>



<p class="wp-block-paragraph">So the label starts with just, you know, this name and then a colon, right?</p>



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



<p class="wp-block-paragraph">You can jump into labels.</p>



<p class="wp-block-paragraph">Like if we were somewhere else in the program right now, we could like, if we</p>



<p class="wp-block-paragraph">we could like if we wanted to do an infinite loop we could say jump and then the name of the label</p>



<p class="wp-block-paragraph">and what would happen is execution would go back up to this label and then it would jump again</p>



<p class="wp-block-paragraph">it would go back up it would be an infinite loop but we wouldn&#8217;t technically be calling a function</p>



<p class="wp-block-paragraph">we&#8217;re just sort of jumping so labels are sort of the first step we have to do a little bit more to</p>



<p class="wp-block-paragraph">actually make a function so we have an assembly function which right now is just a label and in</p>



<p class="wp-block-paragraph">side we have to mark it as global so remember when we marked my CPP function</p>



<p class="wp-block-paragraph">as extern that means we can call a function that lives somewhere else now</p>



<p class="wp-block-paragraph">we&#8217;re marking this function as global which means it lives here but we want</p>



<p class="wp-block-paragraph">other modules to be able to call on our function or our label okay so how do we</p>



<p class="wp-block-paragraph">actually make a function let&#8217;s see the first thing that you should do is try to</p>



<p class="wp-block-paragraph">understand that if that all functions return even if they don&#8217;t return any any</p>



<p class="wp-block-paragraph">Under the hood, what this is actually going to do is crash the program if you just jumped</p>



<p class="wp-block-paragraph">into this label and didn&#8217;t call it like a function, because the return instruction will</p>



<p class="wp-block-paragraph">look onto the call stack and try to find a return address for wherever this function</p>



<p class="wp-block-paragraph">was called from and then go jump, do a jump instruction to return there.</p>



<p class="wp-block-paragraph">And so if you just jumped into this label and then there&#8217;s a return, it&#8217;s going to pop</p>



<p class="wp-block-paragraph">something up the stack that&#8217;s not actually a return address and probably crash the program.</p>



<p class="wp-block-paragraph">So that means now that we have a return statement, we definitely have to call this like a function.</p>



<p class="wp-block-paragraph">And I guess that&#8217;s pretty easy because, well, if we were inside of assembly and we wanted to call another function,</p>



<p class="wp-block-paragraph">let me just show you real fast.</p>



<p class="wp-block-paragraph">I&#8217;ll say some other function.</p>



<p class="wp-block-paragraph">If we were inside of this label, for some reason, we could call the above function by just saying call.</p>



<p class="wp-block-paragraph">And then the label.</p>



<p class="wp-block-paragraph">So now it&#8217;s being treated like a function.</p>



<p class="wp-block-paragraph">it&#8217;s being treated like a function.</p>



<p class="wp-block-paragraph">What the call instruction really does is it just looks at the address of the next instruction</p>



<p class="wp-block-paragraph">that would have been executed.</p>



<p class="wp-block-paragraph">So, you know, whatever, let&#8217;s say we have like a nope on the next line, whatever the</p>



<p class="wp-block-paragraph">memory location or the relative memory location is of that nope instruction, it&#8217;s going to</p>



<p class="wp-block-paragraph">push that onto the call stack.</p>



<p class="wp-block-paragraph">And then it&#8217;s going to just do a jump instruction to this label.</p>



<p class="wp-block-paragraph">So then later when we hit this return statement, then it&#8217;s going to look onto the call stack</p>



<p class="wp-block-paragraph">and it&#8217;s going to find that return address, which is going to correspond with the nope</p>



<p class="wp-block-paragraph">instruction and the return instruction is going to do a jump back to that address.</p>



<p class="wp-block-paragraph">So basically you have to use the call instruction to get there and then use a return instruction</p>



<p class="wp-block-paragraph">to return from there.</p>



<p class="wp-block-paragraph">And then now we can actually call it a function.</p>



<p class="wp-block-paragraph">But then there&#8217;s other things that functions have to do to behave themselves without crashing</p>



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



<p class="wp-block-paragraph">So for example, notice up here that I have copy pasted the let&#8217;s see call on assembly.</p>



<p class="wp-block-paragraph">Oh, I think I forgot to update that.</p>



<p class="wp-block-paragraph">I forgot to update that. Let&#8217;s see. Call on this. Yeah. It&#8217;s supposed to be called my assembly</p>



<p class="wp-block-paragraph">function now. Hold on. Let me update my, uh, my solution. Whoops. Hold on. Call on.</p>



<p class="wp-block-paragraph">There we go. My assembly. Okay. So I&#8217;ve got my solution up above on another monitor.</p>



<p class="wp-block-paragraph">So I have the prototype of the function here. Uh, it&#8217;s just going to return nothing. And it&#8217;s</p>



<p class="wp-block-paragraph">going to like take in a long and a double and a long and a double and a character pointer.</p>



<p class="wp-block-paragraph">And then my intention here is to save these arguments with some registers.</p>



<p class="wp-block-paragraph">So notice how I&#8217;m saying we&#8217;re going to use R12, 13, and 14 to save the arguments A, C, and E.</p>



<p class="wp-block-paragraph">And we&#8217;ll talk about why we&#8217;re not saving the other ones with those registers in a second.</p>



<p class="wp-block-paragraph">But basically we&#8217;re going to use those registers.</p>



<p class="wp-block-paragraph">So the thing about the registers is we have to do something called respecting the ABI.</p>



<p class="wp-block-paragraph">Respect the ABI.</p>



<p class="wp-block-paragraph">The ABI stands for the Application Binary Interface.</p>



<p class="wp-block-paragraph">interface and it&#8217;s just sort of like a standard that governs all of the things that you can do</p>



<p class="wp-block-paragraph">and you&#8217;re supposed to do when you&#8217;re working with x86 64 assembly so the abi is pretty cool</p>



<p class="wp-block-paragraph">hang on a second the abi is pretty cool because it actually standardizes things</p>



<p class="wp-block-paragraph">for instance if we didn&#8217;t have the abi and we didn&#8217;t respect it then we couldn&#8217;t actually call</p>



<p class="wp-block-paragraph">plus or vice versa because c plus plus the higher level languages they&#8217;re going to use the abi so if</p>



<p class="wp-block-paragraph">you try to do things your own way then all you&#8217;re going to end up doing is wasting time and energy</p>



<p class="wp-block-paragraph">coming up with two different ways of doing things when you could have just done it the abi way</p>



<p class="wp-block-paragraph">right so and one of those and one of those ways your way wouldn&#8217;t even work uh for cross you know</p>



<p class="wp-block-paragraph">module calling it would only work internally to your own program so we&#8217;re going to respect the abi</p>



<p class="wp-block-paragraph">does the abi say about these registers and again i&#8217;ve talked about this extensively in other videos</p>



<p class="wp-block-paragraph">but let me pull up a fun book that i love to uh to talk about uh so this book right here i did not</p>



<p class="wp-block-paragraph">write it uh the book here is written by a really wonderful uh professor dr ed jorgensen phd and um</p>



<p class="wp-block-paragraph">this book is totally free it&#8217;s not i&#8217;m not selling you anything uh this is literally you can just go</p>



<p class="wp-block-paragraph">to this this professor&#8217;s website and download his book for free and he&#8217;s already given me permission</p>



<p class="wp-block-paragraph">and he&#8217;s already given me permission to just tell everybody to just share it with everybody if you</p>



<p class="wp-block-paragraph">if you look in the license area it&#8217;s a copyleft license so it&#8217;s sort of like the spirit of open</p>



<p class="wp-block-paragraph">source just sort of like sharing knowledge and stuff so it&#8217;s awesome so I suggest everybody you</p>



<p class="wp-block-paragraph">know follow the link that I hopefully put in the video and and grab a copy of this book but</p>



<p class="wp-block-paragraph">basically what I&#8217;m going to do is I&#8217;m going to go to a special area and I&#8217;m going to search for</p>



<p class="wp-block-paragraph">here and so that would be I guess section 12.8.2 and it&#8217;s called register usage subsection 12.8.2</p>



<p class="wp-block-paragraph">notice how it lists all of the registers and kind of how they are typically used</p>



<p class="wp-block-paragraph">this falls under the scope of the abi so this is not all the abi is but this is one of the</p>



<p class="wp-block-paragraph">things you&#8217;re supposed to do when you&#8217;re respecting the abi is you&#8217;re supposed to sort of like</p>



<p class="wp-block-paragraph">are supposed to be used. Notice R12, which is one of the registers that we&#8217;re going to use,</p>



<p class="wp-block-paragraph">is designated as callee saved. So that means whoever is being called has to preserve that</p>



<p class="wp-block-paragraph">register if they intend to mess it up. So for example, if I just had this function here,</p>



<p class="wp-block-paragraph">move some value into, you know, R12, I have now basically broken the program. If any, you know,</p>



<p class="wp-block-paragraph">C function or other library that you didn&#8217;t write, just any anywhere else calls on this function,</p>



<p class="wp-block-paragraph">anywhere else calls on this function then their version of r12 is going to get destroyed by what</p>



<p class="wp-block-paragraph">i just did and so i&#8217;m not respecting the abi when this function returns to the caller they&#8217;re going</p>



<p class="wp-block-paragraph">to expect that their original data was intact and if it&#8217;s not program is not going to work it&#8217;s going</p>



<p class="wp-block-paragraph">to screw up so respecting the ai means you have to preserve any registered mark as callee saved or</p>



<p class="wp-block-paragraph">that&#8217;s one of the things that it means so notice how r12 through r15 are callee saved so we have</p>



<p class="wp-block-paragraph">the abi now and sort of preserve 12 13 and 14. we can do that pretty easily with some push and pop</p>



<p class="wp-block-paragraph">statements so i&#8217;m going to do push r12 push r13 push r14 and now what happens is those values</p>



<p class="wp-block-paragraph">are actually on the stack now and i can retrieve them later at the end of the function even if i</p>



<p class="wp-block-paragraph">destroy them while i&#8217;m inside of the function i&#8217;ll just restore them right before i return so</p>



<p class="wp-block-paragraph">because it happens before the function does anything.</p>



<p class="wp-block-paragraph">And then we have to make sure that we pop those values</p>



<p class="wp-block-paragraph">because you have to be careful with the stack.</p>



<p class="wp-block-paragraph">If you just start pushing values</p>



<p class="wp-block-paragraph">and you don&#8217;t restore the stack to its original state</p>



<p class="wp-block-paragraph">by the time you return,</p>



<p class="wp-block-paragraph">you&#8217;ve basically broken the program.</p>



<p class="wp-block-paragraph">It&#8217;s either going to crash right away</p>



<p class="wp-block-paragraph">or whoever called it is not going to function correctly anymore.</p>



<p class="wp-block-paragraph">So let&#8217;s do some pops.</p>



<p class="wp-block-paragraph">We&#8217;re going to do three pops</p>



<p class="wp-block-paragraph">and we&#8217;ll call this the epilogue,</p>



<p class="wp-block-paragraph">which means uh you know something we do right before we exit the function and keep in mind</p>



<p class="wp-block-paragraph">that the order of the pops should be reverse of the order of the pushes notice how we&#8217;re popping</p>



<p class="wp-block-paragraph">in reverse order from what i did before so we&#8217;re going to pop uh 14 13 and 12 where as we pushed</p>



<p class="wp-block-paragraph">12 13 and 14 before if you pop in the wrong order like if you try to do it in in the same order as</p>



<p class="wp-block-paragraph">the pushes then uh you&#8217;re still going to end up destroying data for the caller because you&#8217;re</p>



<p class="wp-block-paragraph">because you&#8217;re going to be restoring data to the wrong registers.</p>



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



<p class="wp-block-paragraph">OK, so now the ABI is being respected.</p>



<p class="wp-block-paragraph">Let me see, by the way, do we have enough to actually even run the driver right now?</p>



<p class="wp-block-paragraph">We&#8217;re just calling it and then it didn&#8217;t really do anything.</p>



<p class="wp-block-paragraph">Yeah, I think we could probably this might compile.</p>



<p class="wp-block-paragraph">OK, let me let me just check this out.</p>



<p class="wp-block-paragraph">I want to say clear and make run.</p>



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



<p class="wp-block-paragraph">OK, so the driver printed its hello message.</p>



<p class="wp-block-paragraph">again it&#8217;s just sort of saying like hello from the driver and then when the driver comes</p>



<p class="wp-block-paragraph">back it says the driver regained control and nothing really happened because well we didn&#8217;t</p>



<p class="wp-block-paragraph">do anything in our assembly function yet but at least we&#8217;re calling multiple modules and again</p>



<p class="wp-block-paragraph">if you want to know how to do hybrid programs and linking and compiling and all that stuff</p>



<p class="wp-block-paragraph">see my other videos for now I&#8217;m just going to move on so the next thing we have to do is we have to</p>



<p class="wp-block-paragraph">have to try to understand like how are we going to receive these arguments so this is one of the</p>



<p class="wp-block-paragraph">other you know building blocks to making functions notice how the assembly function i&#8217;m sending in an</p>



<p class="wp-block-paragraph">integer and then a float and then another integer and then another floats i&#8217;m kind of mixing the</p>



<p class="wp-block-paragraph">arguments then at the very end i&#8217;m sending in a pointer if i look back up at the prototype here</p>



<p class="wp-block-paragraph">which matches what i&#8217;ve what how i&#8217;ve used it it&#8217;s a long a double a long a double and a character</p>



<p class="wp-block-paragraph">longs and doubles, they actually, they&#8217;re called mixed arguments and they don&#8217;t actually count</p>



<p class="wp-block-paragraph">against each other when you&#8217;re looking at the order of the registers to stuff them into.</p>



<p class="wp-block-paragraph">So for example, let me show you here. We have, what did I just do? I clicked on the wrong</p>



<p class="wp-block-paragraph">computer. Okay. I&#8217;m on the wrong computer. Okay. Let me close this real fast. So</p>



<p class="wp-block-paragraph">When you think about registers for incoming arguments, you basically start to think about this.</p>



<p class="wp-block-paragraph">RDI and RSI, those registers represent the first and the second integer arguments.</p>



<p class="wp-block-paragraph">If we look back to the book real fast, we can see in that same section, RDI is the first argument,</p>



<p class="wp-block-paragraph">and then RSI is the second argument, and then RDX is the third, and then the fourth.</p>



<p class="wp-block-paragraph">We can do up to six arguments with R9, and then after that, we have to start pushing arguments to the stack.</p>



<p class="wp-block-paragraph">stack i&#8217;m not going to go that far in this video i&#8217;ve actually done that already in a previous video</p>



<p class="wp-block-paragraph">but basically we for for now we can just use six registers to push arguments but if you think</p>



<p class="wp-block-paragraph">about it these registers these are not floating point registers these are general purpose registers</p>



<p class="wp-block-paragraph">they&#8217;re meant for integers and pointers the reason they&#8217;re used for in it for pointers also is because</p>



<p class="wp-block-paragraph">a pointer is just an integer a pointer is just a 64-bit integer unsigned which represents a memory</p>



<p class="wp-block-paragraph">can use these registers only for integers and pointers but we can&#8217;t use them for floats so that</p>



<p class="wp-block-paragraph">means the first integer argument is going to be RDI and the second integer argument is going to be</p>



<p class="wp-block-paragraph">RSI but if there was a float argument in between then RSI would still be the second integer argument</p>



<p class="wp-block-paragraph">the floats don&#8217;t count against the integers and vice versa so for example if we&#8217;re talking about</p>



<p class="wp-block-paragraph">float registers you know the first one available is XMM0 and then we have XMM1 and then we have</p>



<p class="wp-block-paragraph">we have XMM1 and we have XMM2 and it goes all the way up to I think XMM15 so we have 16 floating</p>



<p class="wp-block-paragraph">point registers. So we could pass in 16 floating point arguments just using these registers if we</p>



<p class="wp-block-paragraph">wanted to and then if we want to do even more than that we probably have to get you know funky with</p>



<p class="wp-block-paragraph">the stack or something or maybe hopefully you just have an array somewhere and you&#8217;re just going to</p>



<p class="wp-block-paragraph">pass in a pointer. But the way you have to think of these arguments is that even though they might</p>



<p class="wp-block-paragraph">they might be mixed in the prototype of the function that you&#8217;re calling from a higher level</p>



<p class="wp-block-paragraph">language you shouldn&#8217;t think of them as being mixed when you&#8217;re actually loading up registers so</p>



<p class="wp-block-paragraph">again if we just kind of like go back here to this prototype</p>



<p class="wp-block-paragraph">notice how that a variable we&#8217;re going to say that the a is rdi because a is along it&#8217;s an integer</p>



<p class="wp-block-paragraph">but then right after that there&#8217;s a double b we would not skip rsi or assign b to rsi</p>



<p class="wp-block-paragraph">b would just be the first float argument and then when we go back to long c long c is actually the</p>



<p class="wp-block-paragraph">second integer argument because that double doesn&#8217;t count against the integer so it&#8217;s going to be c</p>



<p class="wp-block-paragraph">is going to be rsi and then uh for double d uh same thing uh we&#8217;re not going to skip xmm1 just</p>



<p class="wp-block-paragraph">because there was a an integer we&#8217;re going to go straight to saying that xmm1 is the second float</p>



<p class="wp-block-paragraph">so it&#8217;s the d then for the last argument that we have i&#8217;m just going to erase this stuff down here</p>



<p class="wp-block-paragraph">it was going to be e and remember pointers are integers they&#8217;re just unsigned uh 64-bit integers</p>



<p class="wp-block-paragraph">we have to go on to the next one which i think i recall is like rdx let me just double check</p>



<p class="wp-block-paragraph">i don&#8217;t want to say this wrong rdx yeah the third argument so i&#8217;m going to do rdx and now</p>



<p class="wp-block-paragraph">that we&#8217;ve kind of like mapped this out we we know now what what registers we should be looking for</p>



<p class="wp-block-paragraph">we should be looking for when the function comes in in order to receive</p>



<p class="wp-block-paragraph">our data we should look at those registers for those variables another</p>



<p class="wp-block-paragraph">thing to keep in mind by the way is that usually when we return something in</p>



<p class="wp-block-paragraph">assembly we will move a value into RAX right like some value if you&#8217;ve been</p>



<p class="wp-block-paragraph">following my assembly videos so far but that only counts if you want to return</p>



<p class="wp-block-paragraph">an integer or a pointer if you instead wanted to return a floating point number</p>



<p class="wp-block-paragraph">use XMM zero and I&#8217;ll just you&#8217;re not allowed to you&#8217;re not allowed to hard code a floating</p>



<p class="wp-block-paragraph">point number in assembly like this or at least in the ASM so we&#8217;ll just pretend that there&#8217;s</p>



<p class="wp-block-paragraph">like a float somewhere and I&#8217;ll just load it from memory and I&#8217;ll say like the float</p>



<p class="wp-block-paragraph">something like that so notice how we&#8217;re using a different instruction we&#8217;re not using the regular</p>



<p class="wp-block-paragraph">move instruction that works with integers we&#8217;re instead using the floating point version we&#8217;re</p>



<p class="wp-block-paragraph">saying let&#8217;s move a single piece of data and let&#8217;s move a double precision floating point number</p>



<p class="wp-block-paragraph">xmm zero and then we&#8217;ll just grab from memory whatever whatever that variable has we&#8217;ll just</p>



<p class="wp-block-paragraph">take that floating point number and stick it into xmm zero so uh if you want to return an integer</p>



<p class="wp-block-paragraph">or float you use rax if you want to re sorry if you want to return an integer or a pointer</p>



<p class="wp-block-paragraph">you use rax if you want to return a float you use xmm zero you shouldn&#8217;t do that at the same time</p>



<p class="wp-block-paragraph">if you have like two assembly functions calling each other you might be tempted to do that and i</p>



<p class="wp-block-paragraph">you know very standard and it wouldn&#8217;t work very well with other people&#8217;s code or library code or</p>



<p class="wp-block-paragraph">higher level language code so only one or the other and it just has to match your prototype</p>



<p class="wp-block-paragraph">so notice how here inside of my cpp function notice how it&#8217;s going to return a double</p>



<p class="wp-block-paragraph">right so when the assembly module is done calling on this function it should expect xmm0 to be</p>



<p class="wp-block-paragraph">loaded up with that double precision loading point number okay so that&#8217;s the basic idea</p>



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



<p class="wp-block-paragraph">So now let&#8217;s maybe let me pin this.</p>



<p class="wp-block-paragraph">Let&#8217;s kind of fill this out a little bit more.</p>



<p class="wp-block-paragraph">So the first thing that we should do</p>



<p class="wp-block-paragraph">is we should save our integer or pointer arguments.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna leave the respect ABI thing there.</p>



<p class="wp-block-paragraph">And notice how I&#8217;m just looking at RDI and RSI and RDX.</p>



<p class="wp-block-paragraph">And well, I guess, you know,</p>



<p class="wp-block-paragraph">we have it in a comment up here, A, C and E,</p>



<p class="wp-block-paragraph">but I&#8217;ll just make another comment here.</p>



<p class="wp-block-paragraph">here I&#8217;ll say like a and a or sorry a C and E and maybe we&#8217;ll specify the data types for fun</p>



<p class="wp-block-paragraph">it&#8217;s going to be long a and then long C and then the character pointer C even if this was a float</p>



<p class="wp-block-paragraph">pointer it would still be an integer because all pointers are integers no matter what they&#8217;re</p>



<p class="wp-block-paragraph">pointing to so just keep that in mind anyway so we&#8217;re going to save r12 r13 and 14 with the</p>



<p class="wp-block-paragraph">14 with the incoming arguments and the reason we want to save those right away is because rdi rsi</p>



<p class="wp-block-paragraph">and rdx those are not callee saved which means the moment we call in another function they&#8217;ll</p>



<p class="wp-block-paragraph">possibly be destroyed because we don&#8217;t really know what&#8217;s going on in other functions that we might</p>



<p class="wp-block-paragraph">call so it&#8217;s a good idea to just kind of save right away either to a global or the stack or</p>



<p class="wp-block-paragraph">in this case just registers being faster okay so we have that now we have to save our float arguments</p>



<p class="wp-block-paragraph">b and d were xmm0 and xmm1 so I&#8217;m just going to save both of those</p>



<p class="wp-block-paragraph">and if you&#8217;re wondering what this float b and float d are that&#8217;s just</p>



<p class="wp-block-paragraph">you know up here I just have a global variable so I can save them to memory</p>



<p class="wp-block-paragraph">easily and not worry about the stack this is not a stack video so much</p>



<p class="wp-block-paragraph">but yeah okay so I&#8217;m just saving all of the incoming arguments that&#8217;s all I&#8217;ve</p>



<p class="wp-block-paragraph">done so far and let&#8217;s see it should probably still</p>



<p class="wp-block-paragraph">Let me see if this works.</p>



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



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



<p class="wp-block-paragraph">So nothing happens, but it at least worked.</p>



<p class="wp-block-paragraph">So I&#8217;m going to same as other windows for that so that we don&#8217;t have to look at it anymore.</p>



<p class="wp-block-paragraph">And now that we&#8217;re done saving our float arguments, let&#8217;s, let&#8217;s print a welcome message.</p>



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



<p class="wp-block-paragraph">And I&#8217;m going to use a special function that I&#8217;ve made in previous videos called print</p>



<p class="wp-block-paragraph">null terminated string, which means I should probably copy paste that into this program</p>



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



<p class="wp-block-paragraph">What is print null terminated string?</p>



<p class="wp-block-paragraph">It&#8217;s just another convenience function that I wrote.</p>



<p class="wp-block-paragraph">I&#8217;m not going to explain it too much because it&#8217;s in other videos and</p>



<p class="wp-block-paragraph">I&#8217;m already here trying to explain functions to you in general.</p>



<p class="wp-block-paragraph">So long story short, it takes in a C string and a file handle, you know, to like where</p>



<p class="wp-block-paragraph">you want to write, like if you want to write to a file or you want to write to standard</p>



<p class="wp-block-paragraph">output or standard error.</p>



<p class="wp-block-paragraph">And it just takes those arguments and then it sort of says, all right, how long is the</p>



<p class="wp-block-paragraph">string?</p>



<p class="wp-block-paragraph">And it uses another function called string length to figure out how long the string is.</p>



<p class="wp-block-paragraph">how long the string is and then it just uses a system call to actually print the</p>



<p class="wp-block-paragraph">string and again system calls are covered in other videos this one looks</p>



<p class="wp-block-paragraph">really convoluted because it&#8217;s like you know customized for this function but</p>



<p class="wp-block-paragraph">just trust me on this this prints a string next function I got a paste in</p>



<p class="wp-block-paragraph">real fast again explained in other videos is the string length function so</p>



<p class="wp-block-paragraph">all this does is it just takes a pointer to a string and it sort of scans the</p>



<p class="wp-block-paragraph">string is and as soon as it sees a zero like a null terminator then it just says all right that&#8217;s</p>



<p class="wp-block-paragraph">that&#8217;s the end of the string and it&#8217;ll just return the length to the caller so that&#8217;s all you need to</p>



<p class="wp-block-paragraph">know about this covered in other videos then i&#8217;m going to make a convenience function here called</p>



<p class="wp-block-paragraph">crlf and all that&#8217;s going to do is just print the new line that we talked about earlier so just</p>



<p class="wp-block-paragraph">just a bunch of convenience functions on top of the real part of the program so now that we have</p>



<p class="wp-block-paragraph">the convenience functions in there we should be able to see the welcome message let me just double</p>



<p class="wp-block-paragraph">yeah now inside assembly entry point oh what did I do wrong now inside I keep forgetting to change</p>



<p class="wp-block-paragraph">the strings on this now inside where&#8217;s that now inside my assembly function okay let me change</p>



<p class="wp-block-paragraph">that in my solution to you know I&#8217;m just kind of like writing these things and I&#8217;m having fun and</p>



<p class="wp-block-paragraph">I keep changing my mind about what they should be named and then I I get some inconsistencies okay</p>



<p class="wp-block-paragraph">all right so then uh we printed the welcome message and now let&#8217;s print the integer arguments</p>



<p class="wp-block-paragraph">but first let&#8217;s print a little introduction uh to the integers let&#8217;s just say hey we&#8217;re about</p>



<p class="wp-block-paragraph">to print the integer so that&#8217;s just this other string a message saying we&#8217;re about to print the</p>



<p class="wp-block-paragraph">integers nothing really that complicated so far it says now we&#8217;re printing all the integer arguments</p>



<p class="wp-block-paragraph">so now we can actually print the integer arguments so we have two integer arguments</p>



<p class="wp-block-paragraph">if you recall let&#8217;s see yeah we had like a and c those were integers I&#8217;m not going to talk about</p>



<p class="wp-block-paragraph">e right now because that was a pointer but you know right now we&#8217;re just saying a and c so that</p>



<p class="wp-block-paragraph">was r12 and r13 so I&#8217;m just going to paste some code here to actually print those and</p>



<p class="wp-block-paragraph">talk about this library in other videos but basically I&#8217;m moving r12 which is the first</p>



<p class="wp-block-paragraph">integer argument that functions typically receive and once that&#8217;s loaded up i&#8217;m just going to call</p>



<p class="wp-block-paragraph">on my special function to just print the integer and again you could use printf from the c libraries</p>



<p class="wp-block-paragraph">if you actually wanted to print it and not just experiment and stuff like that so i&#8217;m going to use</p>



<p class="wp-block-paragraph">r12 and r13 and i&#8217;m just going to print both of those integer arguments and then after each one</p>



<p class="wp-block-paragraph">is printed notice i&#8217;m calling the crlf function which is just the convenience function of just</p>



<p class="wp-block-paragraph">which is just the convenience function of just like doing a new line.</p>



<p class="wp-block-paragraph">So now we should see two numbers. Yeah.</p>



<p class="wp-block-paragraph">Now printing all integer arguments,</p>



<p class="wp-block-paragraph">we&#8217;ve got an 88 there and then that other giant number there.</p>



<p class="wp-block-paragraph">Let&#8217;s just double check that that&#8217;s actually what we&#8217;re supposed to be seeing.</p>



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



<p class="wp-block-paragraph">the driver called the assembly module with these numbers.</p>



<p class="wp-block-paragraph">It gave it an 88 and then for the next integer,</p>



<p class="wp-block-paragraph">it gave it the 287 giant number. So great.</p>



<p class="wp-block-paragraph">so great we&#8217;re printing the integers now let&#8217;s print the floats so we should see</p>



<p class="wp-block-paragraph">like a 99 point something in a 32 point something next okay so let&#8217;s continue</p>



<p class="wp-block-paragraph">with printing oh sorry actually let&#8217;s print the the C string because that&#8217;s a</p>



<p class="wp-block-paragraph">pointer that&#8217;s still more closely related than the floats so the first</p>



<p class="wp-block-paragraph">thing I&#8217;m going to do is I&#8217;m going to</p>



<p class="wp-block-paragraph">print the received c string how about like announce that we will print the c string because</p>



<p class="wp-block-paragraph">that&#8217;s what we&#8217;re doing right here let me change my solution to match and then we&#8217;ll uh we&#8217;ll</p>



<p class="wp-block-paragraph">actually print the received c string next so same stuff as before first we call print null terminated</p>



<p class="wp-block-paragraph">string to print out a little welcome message or just like an intro message like we are going to</p>



<p class="wp-block-paragraph">print the c string and then we&#8217;ll use that print function again but we&#8217;ll give it the c string so</p>



<p class="wp-block-paragraph">it the c string so it just prints the whole c string out and this should prove to you that we</p>



<p class="wp-block-paragraph">are indeed receiving a pointer to some data owned by the c plus plus module so if we run this real</p>



<p class="wp-block-paragraph">fast it should just tell us two more things it&#8217;ll give us the announcement now printing the received</p>



<p class="wp-block-paragraph">c string and then on that same line it says hello this is the c string owned by main and if we just</p>



<p class="wp-block-paragraph">that&#8217;s exactly what string is inside of that variable so hello this is a c string owned by</p>



<p class="wp-block-paragraph">main and we gave it to the function by just kind of passing it in and we know that character arrays</p>



<p class="wp-block-paragraph">are basically character pointers or any array is just a pointer to the first item in the array so</p>



<p class="wp-block-paragraph">my c string is really a pointer to that h character so if we pass that in then a pointer</p>



<p class="wp-block-paragraph">based print function should be able to work and that&#8217;s what happened okay so we&#8217;ve done that</p>



<p class="wp-block-paragraph">So we&#8217;ve done that.</p>



<p class="wp-block-paragraph">And then the next thing we should do is let&#8217;s print the floats.</p>



<p class="wp-block-paragraph">So first let&#8217;s announce that we&#8217;re going to print the floats.</p>



<p class="wp-block-paragraph">Same thing we&#8217;d before we&#8217;re just printing like an announcement message.</p>



<p class="wp-block-paragraph">If we run the program again, it&#8217;s just like now printing the floats, but it doesn&#8217;t actually</p>



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



<p class="wp-block-paragraph">So then the next step is let&#8217;s, let&#8217;s grab the first float into XMM zero.</p>



<p class="wp-block-paragraph">And then let&#8217;s call a function to print it.</p>



<p class="wp-block-paragraph">so right here we have like that 99 number that we expected from before by</p>



<p class="wp-block-paragraph">the way so why am I doing it this way why am I not just keeping XMM zero</p>



<p class="wp-block-paragraph">because you remember before we had XMM zero had that had the float that we</p>



<p class="wp-block-paragraph">received and then we&#8217;re using it again down here but remember XMM zero and all</p>



<p class="wp-block-paragraph">the other float registers they&#8217;re not designated as callee saved which means</p>



<p class="wp-block-paragraph">the moment we call any other function we should expect that that data has been</p>



<p class="wp-block-paragraph">so I can&#8217;t actually count on XMM 0 surviving just this little simple function instead I have to save</p>



<p class="wp-block-paragraph">it somewhere to the stack to memory you know whatever so I&#8217;m just that&#8217;s why I put that into</p>



<p class="wp-block-paragraph">a global variable so it&#8217;s sitting in float underscore B right now and then we saved it at</p>



<p class="wp-block-paragraph">the beginning to float underscore B and if you just kind of look up to the data area well it was</p>



<p class="wp-block-paragraph">just float underscore B was just a little quad word you know eight bytes of memory that can hold</p>



<p class="wp-block-paragraph">hold our float. So we have like float allocations for B and D, the first and second float arguments.</p>



<p class="wp-block-paragraph">So we&#8217;re saving it there. And then we&#8217;re recalling it here. And remember, the first function argument</p>



<p class="wp-block-paragraph">is going to be XMM0, regardless of where that data originally came from. So if we look at the next</p>



<p class="wp-block-paragraph">one here, if we kind of like, let&#8217;s see, copy paste this, and we want to grab like the D float,</p>



<p class="wp-block-paragraph">still going to load it into XMM zero because right now it&#8217;s not about what we originally</p>



<p class="wp-block-paragraph">received as an argument.</p>



<p class="wp-block-paragraph">It&#8217;s what this function expects as an argument.</p>



<p class="wp-block-paragraph">This function only takes one argument.</p>



<p class="wp-block-paragraph">It just wants a float so that it can print it and that&#8217;s it.</p>



<p class="wp-block-paragraph">So both times we&#8217;re going to load it up into XMM zero and then we&#8217;re going to print a new</p>



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



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



<p class="wp-block-paragraph">So let me just run the program one more time and we should now see we&#8217;ve got two floats</p>



<p class="wp-block-paragraph">and they should match what the driver tried to send in.</p>



<p class="wp-block-paragraph">Right?</p>



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



<p class="wp-block-paragraph">And then 32 point something, that&#8217;s the second one.</p>



<p class="wp-block-paragraph">So cool, we have received integers and pointers and floats.</p>



<p class="wp-block-paragraph">We&#8217;ve recalled them and then we&#8217;ve printed them.</p>



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



<p class="wp-block-paragraph">Anyway, so we&#8217;ve done that.</p>



<p class="wp-block-paragraph">And the next thing that we should probably do is…</p>



<p class="wp-block-paragraph">Well, at this point, we just maybe have to mess with return types.</p>



<p class="wp-block-paragraph">Even though I&#8217;ve told you about it, we&#8217;ll just mess with it a little bit.</p>



<p class="wp-block-paragraph">mess with it a little bit. But let&#8217;s call the C++ module. So what I&#8217;d like to do first is just sort</p>



<p class="wp-block-paragraph">of announce that we&#8217;re going to call on the C++ module. Again, typical design pattern, let&#8217;s just</p>



<p class="wp-block-paragraph">print a message saying what we&#8217;re about to do. And if we run this now, it&#8217;s going to say assembly</p>



<p class="wp-block-paragraph">module will now call on the C++ module. So nothing really too complicated. So now we&#8217;re going to call</p>



<p class="wp-block-paragraph">on that function. Let me let me paste the name of it here. Actually, I&#8217;m going to put this one right</p>



<p class="wp-block-paragraph">I want to put this one right here.</p>



<p class="wp-block-paragraph">It&#8217;s the my CPP function function.</p>



<p class="wp-block-paragraph">So if we look back at the driver</p>



<p class="wp-block-paragraph">and look at the signature for my CPP function,</p>



<p class="wp-block-paragraph">whoops, it has this signature.</p>



<p class="wp-block-paragraph">And if you wanted to look up higher,</p>



<p class="wp-block-paragraph">you totally can just look into the name mangling section.</p>



<p class="wp-block-paragraph">Whoops, the my CPP function, it returns a double.</p>



<p class="wp-block-paragraph">It takes in a long, a double, a long, a double,</p>



<p class="wp-block-paragraph">and a character pointer.</p>



<p class="wp-block-paragraph">Basically the same thing as the other one,</p>



<p class="wp-block-paragraph">as the other one except it returns a double so what&#8217;s going to happen is when it takes all of</p>



<p class="wp-block-paragraph">these in it&#8217;s just going to print all of them and then i&#8217;m just going to have it return just kind of</p>



<p class="wp-block-paragraph">like some random double that i decided to type because this is not an arithmetic video okay so</p>



<p class="wp-block-paragraph">cpp function and then um now how do we interpret that so if we uh let&#8217;s see let me maybe just for</p>



<p class="wp-block-paragraph">help this usually helps me when i&#8217;m trying to do this i&#8217;m going to take the prototype and just sort</p>



<p class="wp-block-paragraph">and just sort of like paste it right where I&#8217;m about to call the function.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do this just to remind myself of what I&#8217;m actually calling.</p>



<p class="wp-block-paragraph">Let me add that to my solution, by the way.</p>



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



<p class="wp-block-paragraph">So we&#8217;re going to call myCPP function,</p>



<p class="wp-block-paragraph">which means it&#8217;s expecting some registers to be loaded up with arguments.</p>



<p class="wp-block-paragraph">If we don&#8217;t actually load up anything right now,</p>



<p class="wp-block-paragraph">it&#8217;ll probably do some sort of nonsense.</p>



<p class="wp-block-paragraph">Let&#8217;s actually see what happens right now.</p>



<p class="wp-block-paragraph">If we don&#8217;t load up the appropriate registers,</p>



<p class="wp-block-paragraph">then C++ will still look at those registers expecting to see valid data.</p>



<p class="wp-block-paragraph">Let&#8217;s see what happens.</p>



<p class="wp-block-paragraph">I don&#8217;t know if it&#8217;s going to be good or bad.</p>



<p class="wp-block-paragraph">This would probably be something called undefined behavior,</p>



<p class="wp-block-paragraph">meaning you did something wrong,</p>



<p class="wp-block-paragraph">and probably sometimes your program will work,</p>



<p class="wp-block-paragraph">and sometimes it won&#8217;t.</p>



<p class="wp-block-paragraph">Sometimes you won&#8217;t understand what&#8217;s going on.</p>



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



<p class="wp-block-paragraph">and it&#8217;s saying, oh, it&#8217;s segfaulted.</p>



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



<p class="wp-block-paragraph">Why did it segfault?</p>



<p class="wp-block-paragraph">all right well I guess maybe because I did something naughty I don&#8217;t know</p>



<p class="wp-block-paragraph">if this say faults by the end we&#8217;re going to be in trouble I&#8217;ll have to debug on camera</p>



<p class="wp-block-paragraph">so uh we&#8217;re going to enter into my cpp function and then it says we got a variable a</p>



<p class="wp-block-paragraph">which was a long we didn&#8217;t give it a one a one was just probably sitting in there</p>



<p class="wp-block-paragraph">before we even called that function so like one is definitely not it and then b was like some</p>



<p class="wp-block-paragraph">floating point number and then C was just like another seemingly random value</p>



<p class="wp-block-paragraph">that kind of looks a little bit more like a pointer I&#8217;m not really sure it&#8217;s</p>



<p class="wp-block-paragraph">probably not but it&#8217;s just some junk data coming from somewhere and then D</p>



<p class="wp-block-paragraph">which I think D was supposed to be a character pointer it says not a number</p>



<p class="wp-block-paragraph">so we just got like a a really bad value for D let me upgrade this real fast</p>



<p class="wp-block-paragraph">because maybe we should be printing what printing it as a memory location so E is</p>



<p class="wp-block-paragraph">So E is, let me bring this down real fast.</p>



<p class="wp-block-paragraph">So E is supposed to be a character pointer.</p>



<p class="wp-block-paragraph">Let me, instead of printing the C string as just like itself, let&#8217;s first print the memory location.</p>



<p class="wp-block-paragraph">And I&#8217;ll just say memory.</p>



<p class="wp-block-paragraph">And then we&#8217;ll do a static cast.</p>



<p class="wp-block-paragraph">Oh, I wonder if this will actually change anything.</p>



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



<p class="wp-block-paragraph">Let&#8217;s static cast both of them just to see what happens.</p>



<p class="wp-block-paragraph">print e and uh c string here and then it&#8217;s going to be um</p>



<p class="wp-block-paragraph">hmm no i don&#8217;t think that&#8217;s actually going to change anything</p>



<p class="wp-block-paragraph">because if i cast it as a point as a character that&#8217;s definitely wrong</p>



<p class="wp-block-paragraph">and if i don&#8217;t cast it then it&#8217;s going to show up as its original data type how do i get the memory</p>



<p class="wp-block-paragraph">location hmm oh i know what to do i can static cast it maybe as a as an unsigned long okay</p>



<p class="wp-block-paragraph">and unsigned long. Okay, so a character pointer, we&#8217;ll leave that for the C string. Unsigned long,</p>



<p class="wp-block-paragraph">long, just in case. And I think I should see the memory location first and then the actual C</p>



<p class="wp-block-paragraph">string later. If not, then whatever. Let&#8217;s try one more time. Oh dear. Invalid static cast from</p>



<p class="wp-block-paragraph">a character pointer to a type long, long unsigned integer. What have I done? How about unsigned long?</p>



<p class="wp-block-paragraph">long see if that works character pointer long int i guess i forgot how to cast pointers to longs</p>



<p class="wp-block-paragraph">i&#8217;ll look that up and post another video in the future but i guess for now we&#8217;ll just</p>



<p class="wp-block-paragraph">we&#8217;ll deal with this humiliation and i&#8217;ll just print e by itself</p>



<p class="wp-block-paragraph">all right so i&#8217;m just going to run it one more time it should say fault again</p>



<p class="wp-block-paragraph">is wrong let&#8217;s uh let&#8217;s just fix the arguments so before we make that call we should load up some</p>



<p class="wp-block-paragraph">stuff right so i&#8217;m going to do maybe like a semicolon comment here and then i&#8217;m going to do</p>



<p class="wp-block-paragraph">what else do i have i&#8217;ve got three move instructions so the first argument is going to get</p>



<p class="wp-block-paragraph">77118 the second argument is going to get 1111 and the third argument looks like it&#8217;s going to</p>



<p class="wp-block-paragraph">get a pointer that i&#8217;ve defined inside of the assembly module so if you look back up at the</p>



<p class="wp-block-paragraph">look back up at the top let&#8217;s see message string inside asm message string inside asm so basically</p>



<p class="wp-block-paragraph">i&#8217;m going to be sending a character pointer to this t right here which is just this string says</p>



<p class="wp-block-paragraph">this string is owned by the assembly module and it&#8217;s a null terminated string which uh c definitely</p>



<p class="wp-block-paragraph">needs in order to print correctly if we took that zero off we&#8217;d probably get a bunch of junk data</p>



<p class="wp-block-paragraph">we might crash the program i don&#8217;t know so anyway basically we&#8217;re just going to be saying you know</p>



<p class="wp-block-paragraph">we&#8217;re just going to be saying, you know, here you go. Here&#8217;s a pointer. Where the heck am I?</p>



<p class="wp-block-paragraph">Okay. Here&#8217;s a pointer to a C string. And so we&#8217;re giving it one, two, three arguments. We&#8217;re giving</p>



<p class="wp-block-paragraph">it the A and the C and the E. Now we just have to load it up with the other two floats. So</p>



<p class="wp-block-paragraph">I&#8217;m going to do this real fast. Remember the first float argument is going to be XMM zero.</p>



<p class="wp-block-paragraph">And the second one is going to be XMM one. And you can see that send B corresponds to the first</p>



<p class="wp-block-paragraph">corresponds to the first float argument.</p>



<p class="wp-block-paragraph">That&#8217;s why it&#8217;s XMM zero.</p>



<p class="wp-block-paragraph">And then the float send D corresponds</p>



<p class="wp-block-paragraph">to the second argument.</p>



<p class="wp-block-paragraph">That&#8217;s why it&#8217;s XMM one.</p>



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



<p class="wp-block-paragraph">And there&#8217;s no other floats.</p>



<p class="wp-block-paragraph">And if we just kind of look back up real fast,</p>



<p class="wp-block-paragraph">the float send B and D,</p>



<p class="wp-block-paragraph">I just defined those arbitrarily</p>



<p class="wp-block-paragraph">to just these two random numbers.</p>



<p class="wp-block-paragraph">So we should see like a two one nine</p>



<p class="wp-block-paragraph">and then a nine nine eight eight seven seven six</p>



<p class="wp-block-paragraph">sort of, you know, weird number.</p>



<p class="wp-block-paragraph">number then when we&#8217;re done loading all those things you know all of these registers up now</p>



<p class="wp-block-paragraph">the function should be able to receive something i bet you the reason it crashes because we</p>



<p class="wp-block-paragraph">we had like a bad address for the the string previously because we didn&#8217;t load it</p>



<p class="wp-block-paragraph">so let me go up here and now it doesn&#8217;t crash so if you just kind of like look we have hard-coded a</p>



<p class="wp-block-paragraph">and b sorry not not a and b a and also c so that&#8217;s the seven seven one and then the bunch of ones</p>



<p class="wp-block-paragraph">of ones and then the string which was rdx which was the e so this string is owned by the assembly</p>



<p class="wp-block-paragraph">module nice we&#8217;re now able to print a string that&#8217;s owned by assembly in another module in</p>



<p class="wp-block-paragraph">the c plus plus module and then xmm0 and xmm1 those are the two floats so if we look back up</p>



<p class="wp-block-paragraph">again that&#8217;s uh we should expect to see these two numbers right here whoops um bloat send b and d</p>



<p class="wp-block-paragraph">and then D. So the printing kind of turned it into scientific notation. That&#8217;s okay. You know,</p>



<p class="wp-block-paragraph">there&#8217;s other stuff you can do in C++ to just not print in scientific notation, but for now,</p>



<p class="wp-block-paragraph">I don&#8217;t really care. It&#8217;s basically the same value. So it&#8217;s fine. I just want to show you</p>



<p class="wp-block-paragraph">how to transport data. This is not a C++ video. Anyway, if we go back down to the end of that,</p>



<p class="wp-block-paragraph">so we called the function, but then this function, if you notice, it returns a double,</p>



<p class="wp-block-paragraph">we should expect to see something loaded into the XMM zero register.</p>



<p class="wp-block-paragraph">So I&#8217;m going to move a single piece of data and it&#8217;s going to be a double precision floating</p>



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



<p class="wp-block-paragraph">And I&#8217;m just going to store it into my float got return value global variable,</p>



<p class="wp-block-paragraph">which I defined up above.</p>



<p class="wp-block-paragraph">So let me scroll up real fast.</p>



<p class="wp-block-paragraph">So where is that?</p>



<p class="wp-block-paragraph">Where is that?</p>



<p class="wp-block-paragraph">Float got return value.</p>



<p class="wp-block-paragraph">I initialized it with a zero just because we&#8217;re going to receive something in there.</p>



<p class="wp-block-paragraph">I could have used the BSS section if I wanted to, probably would have been a little bit</p>



<p class="wp-block-paragraph">bit smarter and more performant but i don&#8217;t know i personally don&#8217;t like using the bss section in</p>



<p class="wp-block-paragraph">yasm unless uh i want to allocate an array if i&#8217;m just doing one variable here and there then i&#8217;m</p>



<p class="wp-block-paragraph">just going to put it in the globals or or the data section so float got return value i&#8217;m saving it in</p>



<p class="wp-block-paragraph">there and then uh i want to grab it from xmm zero so that&#8217;s where it comes from when uh my cpp</p>



<p class="wp-block-paragraph">return the double to us inside of XMM0.</p>



<p class="wp-block-paragraph">So I&#8217;m just moving that into my data section into the global variable.</p>



<p class="wp-block-paragraph">And then now that we have finally returned from the C++ module,</p>



<p class="wp-block-paragraph">I&#8217;m just going to announce that we have indeed returned from the C++ module.</p>



<p class="wp-block-paragraph">Let&#8217;s get that far real fast.</p>



<p class="wp-block-paragraph">So this string is owned and then my CPP function exiting.</p>



<p class="wp-block-paragraph">exiting and then now it says the assembly module received this return value from the</p>



<p class="wp-block-paragraph">C++ module and then it says the driver has regained control because we were supposed</p>



<p class="wp-block-paragraph">to print the float and do a line feed after that and we didn&#8217;t so basically assembly just</p>



<p class="wp-block-paragraph">printed this string that was the last part we just added and then it returned right away</p>



<p class="wp-block-paragraph">to the driver so let&#8217;s finish this up so next thing we&#8217;re going to do is we&#8217;re going to</p>



<p class="wp-block-paragraph">move the float value back into XMM0.</p>



<p class="wp-block-paragraph">Remember, anytime you call a function, all your float registers could be destroyed.</p>



<p class="wp-block-paragraph">So it makes sense that we saved XMM0 and then we loaded it only several instructions later</p>



<p class="wp-block-paragraph">because you don&#8217;t know what&#8217;s happening under the hood inside of print null terminated string</p>



<p class="wp-block-paragraph">or any of the system calls that it uses.</p>



<p class="wp-block-paragraph">Your XMM0 is likely destroyed, but you don&#8217;t know for sure, right?</p>



<p class="wp-block-paragraph">If you count on it not being destroyed, you might be introducing undefined behavior to your program.</p>



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



<p class="wp-block-paragraph">Anyway, so we&#8217;re just loading back up from that global into XMM zero.</p>



<p class="wp-block-paragraph">And then we&#8217;re calling that function again to just sort of print the float.</p>



<p class="wp-block-paragraph">And it wants the float as argument zero.</p>



<p class="wp-block-paragraph">So we&#8217;re just sticking into XMM zero.</p>



<p class="wp-block-paragraph">And then we&#8217;re printing a new line.</p>



<p class="wp-block-paragraph">So then when we&#8217;re done here, run it.</p>



<p class="wp-block-paragraph">and now it says the assembly module received this value from the C++ module and notice how it&#8217;s that</p>



<p class="wp-block-paragraph">special value that I hard-coded 112222 whatever so that&#8217;s this value right here</p>



<p class="wp-block-paragraph">and again if we had this cpp function returning along then all we would have to do is look at</p>



<p class="wp-block-paragraph">the RAX register and if we had let&#8217;s let&#8217;s say for some reason that this assembly function we</p>



<p class="wp-block-paragraph">function we wanted to get something from it we could say you know double temp</p>



<p class="wp-block-paragraph">equals that then all we&#8217;d have to do is make sure that we returned sorry we</p>



<p class="wp-block-paragraph">loaded XMM zero with our return value in the assembly module because XMM zero is</p>



<p class="wp-block-paragraph">the return register for floats or if we wanted to do like a long then just load</p>



<p class="wp-block-paragraph">RAX with something at the end of my assembly function and that&#8217;s how C would</p>



<p class="wp-block-paragraph">C and C++ they&#8217;re following the ABI so if you personally don&#8217;t follow the ABI</p>



<p class="wp-block-paragraph">you&#8217;re just going to end up memorizing two different ways of doing things and</p>



<p class="wp-block-paragraph">your way is not going to be compatible with all the other modules written in</p>



<p class="wp-block-paragraph">higher level languages so it&#8217;s kind of a waste of time and your modules won&#8217;t be</p>



<p class="wp-block-paragraph">compatible with other people&#8217;s libraries and functions it&#8217;s just a huge waste of</p>



<p class="wp-block-paragraph">time so just follow the ABI in the first place I&#8217;ve literally known people who</p>



<p class="wp-block-paragraph">said you know what I don&#8217;t want to learn the ABI that&#8217;s dumb then as they wrote</p>



<p class="wp-block-paragraph">they wrote a bunch of assembly they just started thinking like oh this is too confusing because i</p>



<p class="wp-block-paragraph">keep forgetting what registers i was going to pass back and forth between my functions</p>



<p class="wp-block-paragraph">and like a month goes by i come back to an old program i can&#8217;t remember i have to like look</p>



<p class="wp-block-paragraph">through all my code again so then they started accidentally inventing their own little scheme</p>



<p class="wp-block-paragraph">like oh i know what to do i&#8217;ll put the first argument in this register and i&#8217;ll put the</p>



<p class="wp-block-paragraph">second argument in this all they were doing is just reinventing the abi from scratch and then</p>



<p class="wp-block-paragraph">got to that point and then later wasting more time when they realized they just needed to learn the</p>



<p class="wp-block-paragraph">ABI and forget about their way so don&#8217;t let that happen to you and you should probably just try to</p>



<p class="wp-block-paragraph">do it the right way the first time right um a lot of things in coding and computer science in general</p>



<p class="wp-block-paragraph">are just time savers that feel like wastes of time at first okay what else we have anything</p>



<p class="wp-block-paragraph">that I wanted to show you that was actually I think the entirety of that program let&#8217;s run it</p>



<p class="wp-block-paragraph">while I check to see if there&#8217;s any other stuff that I was supposed to show you.</p>



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



<p class="wp-block-paragraph">Everything seems to be working.</p>



<p class="wp-block-paragraph">Let&#8217;s see, I wanted to tell you about labels, return, call,</p>



<p class="wp-block-paragraph">the stack, the return address, prologue and epilog,</p>



<p class="wp-block-paragraph">pushing and popping, respecting the ABI.</p>



<p class="wp-block-paragraph">I wanted to show you that textbook function arguments, mixed arguments,</p>



<p class="wp-block-paragraph">int or pointer return types and float return types.</p>



<p class="wp-block-paragraph">I guess I got through everything without forgetting something huge, which, hey,</p>



<p class="wp-block-paragraph">that&#8217;s probably a first not that i recall at the moment but it probably is</p>



<p class="wp-block-paragraph">anyway so uh i guess that&#8217;s it i hope you feel like function experts now in yasm x86-64 assembly</p>



<p class="wp-block-paragraph">also known as a amd64 assembly in ubuntu okay thank you so much for watching this video i</p>



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



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



<p class="wp-block-paragraph">appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p class="wp-block-paragraph">a small little favor, could you please subscribe and follow this channel or these videos or whatever</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/yasm-x86-64-assembly-functions-tutorial-integers-floats-pointers-abi-c-interoperability/">YASM x86-64 Assembly Functions Tutorial &#8211; Integers, Floats, Pointers, ABI, C++ Interoperability</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/yasm-x86-64-assembly-functions-tutorial-integers-floats-pointers-abi-c-interoperability/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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>Master Data Sizes in x86-64 CPUs: Bytes, Words, D Words, and Quad Words Explained</title>
		<link>https://www.NeuralLantern.com/master-data-sizes-in-x86-64-cpus-bytes-words-d-words-and-quad-words-explained/</link>
					<comments>https://www.NeuralLantern.com/master-data-sizes-in-x86-64-cpus-bytes-words-d-words-and-quad-words-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 09 Jun 2025 00:07:07 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[64-bit computing]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[bytes]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[CPU basics]]></category>
		<category><![CDATA[CPU registers]]></category>
		<category><![CDATA[D word]]></category>
		<category><![CDATA[data sizes]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming for beginners]]></category>
		<category><![CDATA[quad word]]></category>
		<category><![CDATA[tech education]]></category>
		<category><![CDATA[words]]></category>
		<category><![CDATA[x86-64]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=148</guid>

					<description><![CDATA[<p>Learn data sizes in x86-64 CPUs: bytes, words, D words, quad words. Clear guide for coders on assembly &#038; registers. Subscribe for more!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-data-sizes-in-x86-64-cpus-bytes-words-d-words-and-quad-words-explained/">Master Data Sizes in x86-64 CPUs: Bytes, Words, D Words, and Quad Words 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="Master Data Sizes in x86-64 CPUs: Bytes, Words, D Words, and Quad Words Explained" width="1380" height="776" src="https://www.youtube.com/embed/v3fMANsXIwU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Get a clear, fun breakdown of data sizes in x86-64 CPUs! This video covers bytes (8 bits), words (16 bits), D words (32 bits), and quad words (64 bits), plus how they fit into assembly and CPU registers. Perfect for programmers, students, or anyone curious about low-level computing. I’ll walk you through the basics with relatable examples, no jargon overload. Subscribe for more coding &amp; tech videos, and scan the QR code to visit my site for extra tutorials! Leave a comment with your thoughts!</p>



<p class="wp-block-paragraph">Introduction 00:00:00<br>Data Sizes Overview 00:00:01<br>Byte Definition 00:00:44<br>Bits to Bytes Conversion 00:01:27<br>Word Size Explanation 00:02:20<br>Double Word (D Word) 00:04:03<br>Quad Word Definition 00:04:44<br>CPU Registers and Memory 00:05:21<br>Conclusion and Outro 00:06:07<br>Call to Action 00:06:32</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



<p class="wp-block-paragraph">I&#8217;d like to talk to you about data sizes within the context of x86,</p>



<p class="wp-block-paragraph">64 CPUs,</p>



<p class="wp-block-paragraph">just like 64 bit CPUs for assembly and just whatever.</p>



<p class="wp-block-paragraph">So what&#8217;s going on inside of the machine and how do we describe the sizes of</p>



<p class="wp-block-paragraph">various clumps of data? So for starters, you know,</p>



<p class="wp-block-paragraph">of your computer, there&#8217;s just a bunch of ones and zeros represented in all the wires,</p>



<p class="wp-block-paragraph">in all the circuitry.</p>



<p class="wp-block-paragraph">The human beings with feelings decide, oh, you know, I&#8217;m going to take a group of this</p>



<p class="wp-block-paragraph">many bits, this many ones and zeros, and I&#8217;m going to say that it is something else.</p>



<p class="wp-block-paragraph">I&#8217;m going to call it an abstract unit.</p>



<p class="wp-block-paragraph">So the first thing that we do is we have something called a byte.</p>



<p class="wp-block-paragraph">That just means eight bits.</p>



<p class="wp-block-paragraph">So we can say one byte equals eight bits.</p>



<p class="wp-block-paragraph">equals eight bits. I don&#8217;t know why I hit the shift key there. That&#8217;s probably going to mess</p>



<p class="wp-block-paragraph">up my annotator. Nope. Okay. So what is eight bits? Just as a little reminder, you know, we&#8217;ll</p>



<p class="wp-block-paragraph">just say one, two, three, four, five, six, seven, eight, or it could be, you know, something more</p>



<p class="wp-block-paragraph">random looking one, two, three, four, five, six, seven, eight, you know, so like inside of the</p>



<p class="wp-block-paragraph">machine, we have eight ones and zeros for eight bits. And when we group them together, we&#8217;ll just</p>



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



<p class="wp-block-paragraph">So that means by the way, if somebody says,</p>



<p class="wp-block-paragraph">oh, my internet connection is this many megabits a second.</p>



<p class="wp-block-paragraph">If you wanna know how many bytes a second,</p>



<p class="wp-block-paragraph">try dividing by eight.</p>



<p class="wp-block-paragraph">Or if somebody says I have this many megabytes a second</p>



<p class="wp-block-paragraph">of transfer speed, try dividing that by eight.</p>



<p class="wp-block-paragraph">You know, so multiply or divide by eight</p>



<p class="wp-block-paragraph">to get the right number.</p>



<p class="wp-block-paragraph">Okay, so if we had two bytes together,</p>



<p class="wp-block-paragraph">that&#8217;s just gonna be 16 bits.</p>



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



<p class="wp-block-paragraph">I&#8217;m just going to copy paste these bits and you don&#8217;t have to do this.</p>



<p class="wp-block-paragraph">But for me personally, I like to put a little space in between bite groupings just to help</p>



<p class="wp-block-paragraph">my human brain kind of see, oh, I&#8217;m looking at two bites right here when I&#8217;m referring</p>



<p class="wp-block-paragraph">to different data sizes.</p>



<p class="wp-block-paragraph">So then eventually we kind of need an idea of, you know, let&#8217;s come up with a different</p>



<p class="wp-block-paragraph">word that means more than one bite.</p>



<p class="wp-block-paragraph">ironically based on what I just said the the term we&#8217;re going to use is word a word</p>



<p class="wp-block-paragraph">the size of a word just kind of depends on the system that you&#8217;re on on my system</p>



<p class="wp-block-paragraph">the size of a word is two bytes so I&#8217;m going to say one word equals two bytes</p>



<p class="wp-block-paragraph">and you can imagine that&#8217;s 16 bits maybe I should start doing the double equal sign here just to be</p>



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



<p class="wp-block-paragraph">It also equals 16 bits.</p>



<p class="wp-block-paragraph">And you can imagine it&#8217;s basically the same thing</p>



<p class="wp-block-paragraph">that we just wrote up above.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna erase this actually, 16.</p>



<p class="wp-block-paragraph">Oh, I put an E there, embarrassing.</p>



<p class="wp-block-paragraph">Okay, so one word is two bytes.</p>



<p class="wp-block-paragraph">Again, the size of a word depends on your system.</p>



<p class="wp-block-paragraph">If you&#8217;re not sure, you should probably look it up.</p>



<p class="wp-block-paragraph">What&#8217;s the word size on my system?</p>



<p class="wp-block-paragraph">But again, the typical system here in 2024</p>



<p class="wp-block-paragraph">6664 machines running Ubuntu, um, or just like Linux is going to be like, you know,</p>



<p class="wp-block-paragraph">two bytes. Okay. So now, uh, we have like words that we can do. So if I had, uh,</p>



<p class="wp-block-paragraph">let&#8217;s say I had two words, uh, two words is going to be double of what we just wrote. Right. So</p>



<p class="wp-block-paragraph">that means we&#8217;re going to have this many, whoops, I blew it. We&#8217;re going to have this many bits.</p>



<p class="wp-block-paragraph">So two words, two words is going to be equal to, um, 32 bits.</p>



<p class="wp-block-paragraph">And it&#8217;s also going to be equal to four bytes because, you know, we multiplied everything</p>



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



<p class="wp-block-paragraph">So this is like four bytes.</p>



<p class="wp-block-paragraph">So now we need another term to represent this two words, which is four bytes, which</p>



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



<p class="wp-block-paragraph">We can also call that a D word.</p>



<p class="wp-block-paragraph">Actually, I&#8217;ll say D word like that.</p>



<p class="wp-block-paragraph">And what does D word mean?</p>



<p class="wp-block-paragraph">is twice the size of the word length on your system.</p>



<p class="wp-block-paragraph">So like if we decided our word length is two bytes,</p>



<p class="wp-block-paragraph">then a D word is four bytes and that&#8217;s it.</p>



<p class="wp-block-paragraph">Four bytes is 32 bits.</p>



<p class="wp-block-paragraph">You might notice this is similar to like old school CPUs</p>



<p class="wp-block-paragraph">that ran in 32 bits and maxed out their RAM</p>



<p class="wp-block-paragraph">at about four gigabytes.</p>



<p class="wp-block-paragraph">So let&#8217;s come up with one more term here.</p>



<p class="wp-block-paragraph">Let&#8217;s come up with the term quad word.</p>



<p class="wp-block-paragraph">Actually, we&#8217;re not coming up with the term.</p>



<p class="wp-block-paragraph">We&#8217;re just using it.</p>



<p class="wp-block-paragraph">What is a quad word?</p>



<p class="wp-block-paragraph">A quad word is two D words.</p>



<p class="wp-block-paragraph">So we&#8217;re just kind of doubling it again.</p>



<p class="wp-block-paragraph">I forgot that extra equal sign there.</p>



<p class="wp-block-paragraph">Quad word is two D words, which means it&#8217;s also four words.</p>



<p class="wp-block-paragraph">And it also means it&#8217;s eight bytes.</p>



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



<p class="wp-block-paragraph">And then I guess if I want to represent this to you,</p>



<p class="wp-block-paragraph">I can just kind of like copy paste that twice.</p>



<p class="wp-block-paragraph">And this is the size of the memory address space that we have on modern CPUs.</p>



<p class="wp-block-paragraph">This is also the size of your general purpose registers in modern 64-bit CPUs.</p>



<p class="wp-block-paragraph">So if somebody says, hey, I got a quad word.</p>



<p class="wp-block-paragraph">I want you to store it somewhere.</p>



<p class="wp-block-paragraph">You can instantly think to yourself, well, obviously I could put it in memory.</p>



<p class="wp-block-paragraph">I could put it in memory.</p>



<p class="wp-block-paragraph">You could also just put it directly into a CPU register.</p>



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



<p class="wp-block-paragraph">This also means that you could put two D words into one CPU register if you were very clever.</p>



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



<p class="wp-block-paragraph">You could put like four words inside of one CPU register.</p>



<p class="wp-block-paragraph">Because the CPU registers, they&#8217;re always the same size no matter how you use them.</p>



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



<p class="wp-block-paragraph">So I hope this has been, you know, kind of helpful.</p>



<p class="wp-block-paragraph">These are the basics of different data type sizes that we have in CPUs and</p>



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



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



<p class="wp-block-paragraph">I really appreciate it. 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">Follow this channel or these videos or whatever it is you do on the current social media website that you&#8217;re looking at right now</p>



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



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



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



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



<p class="wp-block-paragraph">and I get filled with joy. That&#8217;s exactly what happens every single time. So you could do it as</p>



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-data-sizes-in-x86-64-cpus-bytes-words-d-words-and-quad-words-explained/">Master Data Sizes in x86-64 CPUs: Bytes, Words, D Words, and Quad Words Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-data-sizes-in-x86-64-cpus-bytes-words-d-words-and-quad-words-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
