<?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>hybrid programming Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/hybrid-programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/hybrid-programming/</link>
	<description></description>
	<lastBuildDate>Sun, 09 Nov 2025 01:47:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>hybrid programming Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/hybrid-programming/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mix C++, C, and Assembly into One Program &#8211; Hybrid Program Full Build Tutorial</title>
		<link>https://www.NeuralLantern.com/mix-c-c-and-assembly-into-one-program-hybrid-program-full-build-tutorial/</link>
					<comments>https://www.NeuralLantern.com/mix-c-c-and-assembly-into-one-program-hybrid-program-full-build-tutorial/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 09 Nov 2025 01:47:40 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[build system]]></category>
		<category><![CDATA[C and assembly]]></category>
		<category><![CDATA[C++ assembly interop]]></category>
		<category><![CDATA[c++ tutorial]]></category>
		<category><![CDATA[extern C]]></category>
		<category><![CDATA[hybrid programming]]></category>
		<category><![CDATA[linking object files]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[Makefile tutorial]]></category>
		<category><![CDATA[mixed language programming]]></category>
		<category><![CDATA[name mangling]]></category>
		<category><![CDATA[object files]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=248</guid>

					<description><![CDATA[<p>Learn to build a hybrid program mixing C++, C, and x86-64 assembly. Covers object files, linking, extern "C", name mangling, and a full Makefile. Run one executable with modules calling each other.</p>
<p>The post <a href="https://www.NeuralLantern.com/mix-c-c-and-assembly-into-one-program-hybrid-program-full-build-tutorial/">Mix C++, C, and Assembly into One Program &#8211; Hybrid Program Full Build Tutorial</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="Mix C++, C, and Assembly into One Program - Hybrid Program Full Build Tutorial" width="1380" height="776" src="https://www.youtube.com/embed/Izu807v7NbU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Want to write a single program that uses C++ for high-level logic, C for portability, and assembly for speed? This video shows exactly how to do it.</p>



<p class="wp-block-paragraph">We build a complete hybrid program from scratch:</p>



<ul class="wp-block-list">
<li>driver.cpp &#8211; contains main(), prints intro, calls assembly</li>



<li>c.c &#8211; simple printf() function</li>



<li>cpp.cpp &#8211; C++ function (with extern &#8220;C&#8221; to disable name mangling)</li>



<li>hello.asm &#8211; assembly module that prints messages, calls C and C++ functions</li>
</ul>



<p class="wp-block-paragraph">You’ll see:</p>



<ul class="wp-block-list">
<li>Why hybrid programs matter</li>



<li>How source files → object files → final executable</li>



<li>The role of the driver and why main() lives once</li>



<li>Name mangling in C++ and how extern &#8220;C&#8221; fixes interop</li>



<li>Global / extern in assembly to expose and call functions</li>



<li>A clean Makefile that compiles each module separately</li>



<li>Live build and execution with output explained line-by-line</li>
</ul>



<p class="wp-block-paragraph">By the end you’ll know how to call across languages safely, pass basic args via registers, and structure projects for fast incremental builds.</p>



<p class="wp-block-paragraph">No prior assembly required &#8211; just basic C/C++ familiarity. Code is copy-paste ready.</p>



<p class="wp-block-paragraph">Timestamps in comments. Source files linked below.</p>



<p class="wp-block-paragraph">Like &amp; subscribe for more systems programming!</p>



<p class="wp-block-paragraph">What is a Hybrid Program 00:00:00<br>Why Use Hybrid Programs 00:00:21<br>Program Modules Overview 00:01:10<br>Compilation to Object Files 00:02:23<br>Makefile Introduction 00:04:26<br>Driver Module Setup 00:06:43<br>Name Mangling Explained 00:07:18<br>C++ Module with extern C 00:07:43<br>Driver Main Function 00:10:12<br>C Module Implementation 00:11:52<br>Assembly Module Setup 00:12:41<br>Assembly Data Section 00:13:03<br>Assembly Text Section 00:14:18<br>Global and External Functions 00:14:35<br>Assembly System Calls 00:16:20<br>Calling C from Assembly 00:18:58<br>Calling C++ from Assembly 00:20:32<br>Program Execution Flow 00:21:05<br>Running the Program 00:23:59<br>Passing Arguments Between Modules 00:26:23<br>Hybrid Program Summary 00:29:11</p>



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p class="wp-block-paragraph">Hello there. Let&#8217;s talk about hybrid programs.</p>



<p class="wp-block-paragraph">What&#8217;s a hybrid program?</p>



<p class="wp-block-paragraph">A hybrid program is basically a program where you have multiple modules,</p>



<p class="wp-block-paragraph">many written in different languages, all compiled into one executable program.</p>



<p class="wp-block-paragraph">Why would you want to make a hybrid program? Well, you know,</p>



<p class="wp-block-paragraph">maybe you have C++ as one of the modules that you&#8217;re creating and C++ is a high</p>



<p class="wp-block-paragraph">And C++ is a high level language, so it makes it easier to write big, robust programs with GUIs and like big design, big fancy design patterns and things.</p>



<p class="wp-block-paragraph">But maybe at some point you want to interface with the C program.</p>



<p class="wp-block-paragraph">So it might make sense to, you know, kind of jump into some C code.</p>



<p class="wp-block-paragraph">Maybe also you want to write a little module in assembly because maybe one part of your code needs to be really, really fast and efficient in some way.</p>



<p class="wp-block-paragraph">the code compiles down to machine code.</p>



<p class="wp-block-paragraph">Assembly is just, you know, a level up from machine code.</p>



<p class="wp-block-paragraph">So let&#8217;s see, I&#8217;m just gonna write a quick program</p>



<p class="wp-block-paragraph">to demonstrate that you can do this</p>



<p class="wp-block-paragraph">and you can have these modules call each other.</p>



<p class="wp-block-paragraph">First off, I should probably draw a little bit</p>



<p class="wp-block-paragraph">about what I&#8217;m even talking about with multiple modules.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna do my little annotator here</p>



<p class="wp-block-paragraph">and yeah, there we go.</p>



<p class="wp-block-paragraph">Basically imagine that you have a C++ module</p>



<p class="wp-block-paragraph">and we&#8217;ll call it the driver.</p>



<p class="wp-block-paragraph">and we&#8217;ll call it the driver and I&#8217;ll say like driver.cpp. Okay I think I&#8217;m</p>



<p class="wp-block-paragraph">drawing this backwards. I&#8217;m gonna draw this down here. Driver.cpp.</p>



<p class="wp-block-paragraph">Excuse my penmanship I don&#8217;t have a smoother setup on this thing. So we have</p>



<p class="wp-block-paragraph">driver.cpp that&#8217;s one source code. Maybe you have like another module, another</p>



<p class="wp-block-paragraph">just some C code. The driver, usually the way I like to refer to it, and one of my favorite,</p>



<p class="wp-block-paragraph">you know, assembly books refers to it is the driver is where the main function is so that</p>



<p class="wp-block-paragraph">it&#8217;s sort of like the entry point of your program. But then maybe we&#8217;ll have another module that has</p>



<p class="wp-block-paragraph">some other kind of CPP code in there. I&#8217;m just going to call this file cpp.cpp. And maybe we</p>



<p class="wp-block-paragraph">have another module that&#8217;s written in assembly. I&#8217;m going to call this hello.asm. Okay, so just</p>



<p class="wp-block-paragraph">Okay, so just several source code files.</p>



<p class="wp-block-paragraph">We will compile them each to an object file.</p>



<p class="wp-block-paragraph">Sometimes, I think, with new programmers,</p>



<p class="wp-block-paragraph">they think that you just compile a source code directly to the executable.</p>



<p class="wp-block-paragraph">We&#8217;re not going to do that in this case.</p>



<p class="wp-block-paragraph">We&#8217;re going to get a little bit fancier.</p>



<p class="wp-block-paragraph">Doing it this way, by the way, will increase your compiling efficiency</p>



<p class="wp-block-paragraph">when you start getting used to make files.</p>



<p class="wp-block-paragraph">I don&#8217;t know if you&#8217;re already using those, but it&#8217;s a good idea.</p>



<p class="wp-block-paragraph">So we&#8217;ll write a script to compile or make file to compile</p>



<p class="wp-block-paragraph">or some kind of a build system to compile.</p>



<p class="wp-block-paragraph">We&#8217;ll compile the CPP driver to just a file called</p>



<p class="wp-block-paragraph">driver.o, O for object file.</p>



<p class="wp-block-paragraph">So O for object file depends on driver.cpp.</p>



<p class="wp-block-paragraph">We&#8217;ll have another file called c.o,</p>



<p class="wp-block-paragraph">so the object file c.o depends on c.c and so forth.</p>



<p class="wp-block-paragraph">So I&#8217;m just gonna go cpp.o, circle it,</p>



<p class="wp-block-paragraph">and then down here we&#8217;ll do hello.o.</p>



<p class="wp-block-paragraph">Notice how all of these modules, regardless of the language they are written in, compile</p>



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



<p class="wp-block-paragraph">That&#8217;s really what it is.</p>



<p class="wp-block-paragraph">The higher level languages are just an illusion for us humans.</p>



<p class="wp-block-paragraph">So then at the very top, we want our actual executable file.</p>



<p class="wp-block-paragraph">We&#8217;ll call it main because that&#8217;s kind of a standard thing sometimes.</p>



<p class="wp-block-paragraph">So it&#8217;s like our main, we&#8217;ll have a file named main that we can execute.</p>



<p class="wp-block-paragraph">is going to be the main function.</p>



<p class="wp-block-paragraph">Spoiler, it&#8217;s going to be inside the driver.</p>



<p class="wp-block-paragraph">Remember, the main function, if you&#8217;re using GCC libraries,</p>



<p class="wp-block-paragraph">has to appear in exactly one place, one module in your program.</p>



<p class="wp-block-paragraph">It should appear one time and one time alone, not zero or more than one.</p>



<p class="wp-block-paragraph">So the main executable depends on the driver object file,</p>



<p class="wp-block-paragraph">the C object file, and the C++ object file,</p>



<p class="wp-block-paragraph">and the assembly hello object file.</p>



<p class="wp-block-paragraph">Looks complicated at first until you stare at it a while,</p>



<p class="wp-block-paragraph">complicated at first until you stare at it a while and then you just realize,</p>



<p class="wp-block-paragraph">oh, every source code is going to compile to its own object file.</p>



<p class="wp-block-paragraph">And then after we have all the object files,</p>



<p class="wp-block-paragraph">we&#8217;re going to have our executable just sort of linked together at the final</p>



<p class="wp-block-paragraph">linking stage. So with that in mind,</p>



<p class="wp-block-paragraph">I&#8217;m just going to copy paste a make file that I already wrote.</p>



<p class="wp-block-paragraph">It&#8217;s like my pre solution because this is not a make file video.</p>



<p class="wp-block-paragraph">And I just want you to know just real fast what it looks like.</p>



<p class="wp-block-paragraph">All I&#8217;m doing is I&#8217;m going to make some variables, uh,</p>



<p class="wp-block-paragraph">for my C++ compiler flags and my C compiler flags and my Yasm assembler flags.</p>



<p class="wp-block-paragraph">I&#8217;m really not doing anything fancy.</p>



<p class="wp-block-paragraph">I&#8217;m just sort of setting up some variables so I don&#8217;t have to type.</p>



<p class="wp-block-paragraph">The newer Ubuntu stuffs need a no executable stack flag and a no pi flag.</p>



<p class="wp-block-paragraph">So here we&#8217;re just like making variables for linking.</p>



<p class="wp-block-paragraph">My executable&#8217;s name is going to be main over here.</p>



<p class="wp-block-paragraph">I personally like to make make files that default to a cute help menu.</p>



<p class="wp-block-paragraph">help menu. I know most people just default to building, but, uh, you know, for educational</p>



<p class="wp-block-paragraph">purposes, I think this is a little more fun, a little easier. So this way later I can just type</p>



<p class="wp-block-paragraph">make menu or make build or make run or make clean or whatever I want to do. And, um,</p>



<p class="wp-block-paragraph">I&#8217;m going to make a target called run, which is what we&#8217;re going to be using. And then a target</p>



<p class="wp-block-paragraph">called build, which just only builds everything. The run target obviously depends on build so that</p>



<p class="wp-block-paragraph">to run it and and if you don&#8217;t know make files at this point it&#8217;s okay this is not a make file video</p>



<p class="wp-block-paragraph">i&#8217;m going to make some make file videos in the future</p>



<p class="wp-block-paragraph">then my binary the main program is just going to depend on all these object files notice how it</p>



<p class="wp-block-paragraph">depends on the driver the hello the c plus plus and the c object files so really uh at the linking</p>



<p class="wp-block-paragraph">stage we&#8217;re just going to use g plus plus to just sort of link all the object files together</p>



<p class="wp-block-paragraph">Then we have a little section to compile each source code file.</p>



<p class="wp-block-paragraph">So in order to make driver.o, I&#8217;m going to compile,</p>



<p class="wp-block-paragraph">I&#8217;m going to depend on the driver.cpp.</p>



<p class="wp-block-paragraph">And then when it comes to actually compiling, compiling it,</p>



<p class="wp-block-paragraph">I&#8217;m just going to type the commands to compile it here.</p>



<p class="wp-block-paragraph">Don&#8217;t worry about these crazy variables.</p>



<p class="wp-block-paragraph">I&#8217;m going to make more videos in the future.</p>



<p class="wp-block-paragraph">And then each module gets compiled in its own way.</p>



<p class="wp-block-paragraph">Then I just have a little target at the bottom called clean because I like to be</p>



<p class="wp-block-paragraph">able to just clean my build area of object files.</p>



<p class="wp-block-paragraph">I don&#8217;t know about you, but I like a clean build area.</p>



<p class="wp-block-paragraph">I&#8217;m a clean build area guy.</p>



<p class="wp-block-paragraph">I don&#8217;t like a dirty build area.</p>



<p class="wp-block-paragraph">So that was the make file.</p>



<p class="wp-block-paragraph">Again, this is not a make file video,</p>



<p class="wp-block-paragraph">so don&#8217;t worry too much about it right now.</p>



<p class="wp-block-paragraph">The next thing we should do is make a driver.</p>



<p class="wp-block-paragraph">Again, I&#8217;m gonna copy paste from my solution here</p>



<p class="wp-block-paragraph">because the driver should be easy.</p>



<p class="wp-block-paragraph">This is really, this video is mostly gonna be</p>



<p class="wp-block-paragraph">for people who have never done assembly before.</p>



<p class="wp-block-paragraph">So I&#8217;m just gonna assume you know a little bit</p>



<p class="wp-block-paragraph">about C++ and C already.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say touch, let&#8217;s see, driver.cpp so that I can get the driver file in there.</p>



<p class="wp-block-paragraph">And I&#8217;m going to go nano driver, probably put it down in the first place.</p>



<p class="wp-block-paragraph">Then I&#8217;m just going to paste my solution.</p>



<p class="wp-block-paragraph">Oops, you can tell I copy pasted this from my IDE because I have the extra tabs in there, which I love.</p>



<p class="wp-block-paragraph">One thing to keep in mind is that, I guess like one of the first rules that I want to tell you for hybrid programs</p>



<p class="wp-block-paragraph">is that assembly doesn&#8217;t understand something called name mangling.</p>



<p class="wp-block-paragraph">mangling. So what is name mangling? Name mangling is basically when you have a,</p>



<p class="wp-block-paragraph">oh, this is not going to get called. So this is maybe not a great idea to show you name</p>



<p class="wp-block-paragraph">mangling. Let me, let me start on one of the other ones real fast too. Let&#8217;s do</p>



<p class="wp-block-paragraph">the C++ module. Okay. So I&#8217;m going to go nano CPP dot CPP. I know it&#8217;s a silly name. I know it.</p>



<p class="wp-block-paragraph">So CPP dot CPP, this is just a simple C++ program, which is meant to be called by</p>



<p class="wp-block-paragraph">by the assembly module just to show you that we can.</p>



<p class="wp-block-paragraph">And so we just have a little function here,</p>



<p class="wp-block-paragraph">void, you know, the CPP function.</p>



<p class="wp-block-paragraph">So it&#8217;s just a function that doesn&#8217;t really return anything.</p>



<p class="wp-block-paragraph">Inside of it, I&#8217;m just going to print,</p>



<p class="wp-block-paragraph">hello, this is the C++ function, no problem.</p>



<p class="wp-block-paragraph">Notice at the top,</p>



<p class="wp-block-paragraph">this is the first important thing that you should understand.</p>



<p class="wp-block-paragraph">In C++, we have overloads, right?</p>



<p class="wp-block-paragraph">You can have the same function name,</p>



<p class="wp-block-paragraph">but with different argument lists.</p>



<p class="wp-block-paragraph">And so that gets resolved under the hood</p>



<p class="wp-block-paragraph">by the name actually kind of changing</p>



<p class="wp-block-paragraph">based on what the argument signature is,</p>



<p class="wp-block-paragraph">what the prototype signature is.</p>



<p class="wp-block-paragraph">So that&#8217;s great and all,</p>



<p class="wp-block-paragraph">but in assembly, at least at this level,</p>



<p class="wp-block-paragraph">there&#8217;s no way to really differentiate between overloads.</p>



<p class="wp-block-paragraph">In assembly, we&#8217;ll just call a name of some function.</p>



<p class="wp-block-paragraph">But if we try to call a name,</p>



<p class="wp-block-paragraph">let&#8217;s say of just the CPP function,</p>



<p class="wp-block-paragraph">if we say call the CPP function in assembly,</p>



<p class="wp-block-paragraph">it&#8217;s not going to work</p>



<p class="wp-block-paragraph">because the actual function has not been compiled to have that name.</p>



<p class="wp-block-paragraph">It&#8217;s been compiled to have the CPP function</p>



<p class="wp-block-paragraph">and a bunch of extra symbols indicating what the argument list is.</p>



<p class="wp-block-paragraph">This is great for C++ programs, but it&#8217;s poor.</p>



<p class="wp-block-paragraph">It&#8217;s bad for other modules to be able to call the C++ function</p>



<p class="wp-block-paragraph">because they won&#8217;t really know what the actual name is</p>



<p class="wp-block-paragraph">after the mangling has been done.</p>



<p class="wp-block-paragraph">So what you want to do is make a little block called Xtern C,</p>



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



<p class="wp-block-paragraph">You say extern and then C in quotes and then do a scope with braces.</p>



<p class="wp-block-paragraph">And inside of that, just put the prototypes of any function that you want to be available to other modules.</p>



<p class="wp-block-paragraph">So, for example, we want the CPP function to be available to assembly modules and C modules, not just other C++ modules.</p>



<p class="wp-block-paragraph">So, I&#8217;m just going to put the prototype of it right there.</p>



<p class="wp-block-paragraph">You can put as many prototypes as you want.</p>



<p class="wp-block-paragraph">I think they should come from the same source file.</p>



<p class="wp-block-paragraph">different source file where you want something to be available elsewhere,</p>



<p class="wp-block-paragraph">you would put an extern C block for its prototype.</p>



<p class="wp-block-paragraph">This disables name mangling,</p>



<p class="wp-block-paragraph">which means the compiled name of the CPP function will actually be the CPP</p>



<p class="wp-block-paragraph">function. So it&#8217;s pretty good. This will make it available to assembly.</p>



<p class="wp-block-paragraph">So now that I&#8217;ve kind of explained that I can maybe close this and go back to</p>



<p class="wp-block-paragraph">what I was doing before. So this is the main driver program.</p>



<p class="wp-block-paragraph">We don&#8217;t need to engage in a dis,</p>



<p class="wp-block-paragraph">we don&#8217;t need to disable name mangling for the main function because no one is going to call main</p>



<p class="wp-block-paragraph">except the GCC libraries or like the OS. But when the C++ module calls other modules, it needs to</p>



<p class="wp-block-paragraph">be able to call the right name. And remember in C++, there&#8217;s name mangling enabled by default.</p>



<p class="wp-block-paragraph">So if I tell it, let&#8217;s say on this line right here, or you can do alt N to get line numbers on nano.</p>



<p class="wp-block-paragraph">we want to call on the hello module will C++ by default will assume that hello has name</p>



<p class="wp-block-paragraph">mangling applied to it, which means it will actually try to call some name that is totally</p>



<p class="wp-block-paragraph">different based on the prototype signature, the incoming arguments and things like that.</p>



<p class="wp-block-paragraph">But so we want to disable that because we wanted to just call the actual name because</p>



<p class="wp-block-paragraph">hello is going to be a function that we make inside of assembly.</p>



<p class="wp-block-paragraph">So it&#8217;s not going to be name mangled.</p>



<p class="wp-block-paragraph">So that&#8217;s why up here on line seven, we enter its signature.</p>



<p class="wp-block-paragraph">Enter its signature. Oh, actually this is from a different version of something that I was doing. I&#8217;m not going to return anything from hello</p>



<p class="wp-block-paragraph">We&#8217;ll do name a demangling with our extern C block just void hello</p>



<p class="wp-block-paragraph">And now when we call hello, it&#8217;s actually going to call a function called hello without any other</p>



<p class="wp-block-paragraph">mangling same thing for the C S E A</p>



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



<p class="wp-block-paragraph">That was from a different version. I wrote we&#8217;re not going to be calling C in this module. Don&#8217;t worry</p>



<p class="wp-block-paragraph">We&#8217;re going to keep it simple</p>



<p class="wp-block-paragraph">So pretty much we&#8217;re going to print hello and then we&#8217;re going to print,</p>



<p class="wp-block-paragraph">then we&#8217;re going to call the hello and then we&#8217;re going to say goodbye.</p>



<p class="wp-block-paragraph">And then that&#8217;s going to be the end of the program.</p>



<p class="wp-block-paragraph">So let me close out of that and just double check what I have written right now.</p>



<p class="wp-block-paragraph">So we&#8217;ve got CPP and okay, we need to do C, nano C dot C.</p>



<p class="wp-block-paragraph">Okay, so let me get my solution real fast here.</p>



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



<p class="wp-block-paragraph">Literally, it&#8217;s just a C program that prints something.</p>



<p class="wp-block-paragraph">Remember in C++, we&#8217;ve got the IO stream, but we don&#8217;t have that in C.</p>



<p class="wp-block-paragraph">that in C. So I&#8217;m just going to use printf. Oh, by the way, this is a C function. Hi.</p>



<p class="wp-block-paragraph">So done with that. Pretty easy. Shoot. You know what? I need to start learning how to do</p>



<p class="wp-block-paragraph">clear and LSA. So I can just go up, up, up. So C++, C and the driver</p>



<p class="wp-block-paragraph">and the make file, which is huge. I just realized that. And now I guess we can start</p>



<p class="wp-block-paragraph">or hello function.</p>



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



<p class="wp-block-paragraph">So maybe I want to write this in the Genie program.</p>



<p class="wp-block-paragraph">So I&#8217;m going to, well, maybe I&#8217;ll first, I&#8217;ll say touch,</p>



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



<p class="wp-block-paragraph">And then now that it&#8217;s there, I can try to open it up.</p>



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



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



<p class="wp-block-paragraph">Okay, so now let&#8217;s write an assembly program.</p>



<p class="wp-block-paragraph">I&#8217;m not going to spend too much time talking about this,</p>



<p class="wp-block-paragraph">but I&#8217;ll say like data section here,</p>



<p class="wp-block-paragraph">and we&#8217;ll say section.data.</p>



<p class="wp-block-paragraph">We&#8217;ll say section.data and then we&#8217;ll say system calls.</p>



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



<p class="wp-block-paragraph">I&#8217;m just gonna do this very quickly without explaining.</p>



<p class="wp-block-paragraph">System write is gonna be code one, I guess.</p>



<p class="wp-block-paragraph">And then we&#8217;re gonna do file descriptors, one for stdout.</p>



<p class="wp-block-paragraph">Whoops, stdout, it&#8217;s gonna be equal to one.</p>



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



<p class="wp-block-paragraph">I&#8217;ll put FDs, I guess.</p>



<p class="wp-block-paragraph">And then we&#8217;ll make some C strings.</p>



<p class="wp-block-paragraph">C strings, you know, just character arrays, basically.</p>



<p class="wp-block-paragraph">I&#8217;ll say, well, you know what?</p>



<p class="wp-block-paragraph">I don&#8217;t want to type this all out</p>



<p class="wp-block-paragraph">because this is not a lesson on variables.</p>



<p class="wp-block-paragraph">I&#8217;m just going to copy paste my existing solution here.</p>



<p class="wp-block-paragraph">And, you know, long story short,</p>



<p class="wp-block-paragraph">I&#8217;m going to try to make this a pretty program</p>



<p class="wp-block-paragraph">that prints hello and goodbye and things.</p>



<p class="wp-block-paragraph">And so we just have like some variables</p>



<p class="wp-block-paragraph">that sort of just you know old strings and hold the strings length and we&#8217;re</p>



<p class="wp-block-paragraph">gonna do one that calls a new line and so forth actually that&#8217;ll be a different</p>



<p class="wp-block-paragraph">video but I&#8217;ll leave it in there for now so now let&#8217;s make the text section</p>



<p class="wp-block-paragraph">remember the text section in Yasm is just for the actual code of your program</p>



<p class="wp-block-paragraph">and then we need to set up some external symbols. So right now, at least for the purposes of this</p>



<p class="wp-block-paragraph">source code, this source code is inside of the hello module. So you can imagine we&#8217;re inside of</p>



<p class="wp-block-paragraph">hello.o. All the o&#8217;s get linked together in the executable, but between themselves, there&#8217;s kind</p>



<p class="wp-block-paragraph">of a little bit of like a border situation happening. There&#8217;s like some separation. So</p>



<p class="wp-block-paragraph">are going to be available to the other modules,</p>



<p class="wp-block-paragraph">even if they&#8217;re part of the same executable.</p>



<p class="wp-block-paragraph">It&#8217;s kind of convenient because you would like sometimes</p>



<p class="wp-block-paragraph">to be able to write tons and tons of functions</p>



<p class="wp-block-paragraph">that are only available inside of your assembly module,</p>



<p class="wp-block-paragraph">and they might not be available to other modules,</p>



<p class="wp-block-paragraph">and therefore you don&#8217;t want to pollute the namespace,</p>



<p class="wp-block-paragraph">I guess, of the global namespace of the executable.</p>



<p class="wp-block-paragraph">So by default, if I make a function called hello,</p>



<p class="wp-block-paragraph">how you make a function, just a quick recap here.</p>



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



<p class="wp-block-paragraph">make a symbol with the name of the function you want and then you just put a ret after it and then</p>



<p class="wp-block-paragraph">you hope that whoever got you there is going to use the call instruction but anyway for now</p>



<p class="wp-block-paragraph">we&#8217;re just going to say this is our hello function okay i cannot call the hello function now from</p>



<p class="wp-block-paragraph">another module i have to make it visible to the other modules with a special keyword called global</p>



<p class="wp-block-paragraph">our program the hello function will be available to the other modules but not anything else that</p>



<p class="wp-block-paragraph">I type without marking it as global so let&#8217;s go ahead and do let&#8217;s do a welcome message and this</p>



<p class="wp-block-paragraph">is not a system call a video maybe I should just copy paste this so just looking at it this is a</p>



<p class="wp-block-paragraph">going to quickly you know breeze through what we&#8217;re doing in case you&#8217;re interested but you</p>



<p class="wp-block-paragraph">don&#8217;t have to care too much about this right now we&#8217;re going to tell rax what system call we want</p>



<p class="wp-block-paragraph">to make the code for that is what i put up in system right which is just code one means let&#8217;s</p>



<p class="wp-block-paragraph">write to a file we&#8217;ll give it the file handle uh that&#8217;s going to be the variable we made called fd</p>



<p class="wp-block-paragraph">std out which means we&#8217;re going to be giving it the file handle of one which means we&#8217;re telling</p>



<p class="wp-block-paragraph">to print to standard output because file handle one is always standard output.</p>



<p class="wp-block-paragraph">And then we just give it the a pointer to the first character of the message</p>



<p class="wp-block-paragraph">string that we made and then tell it how long that message is. Then we do system call this should</p>



<p class="wp-block-paragraph">actually um this this should actually print a string. Okay so then uh let&#8217;s see down here I&#8217;m</p>



<p class="wp-block-paragraph">going to make a function called crlf because I&#8217;m lazy and I don&#8217;t like constantly adding extra stuff</p>



<p class="wp-block-paragraph">constantly adding extra stuff to the string so that there will be like a new line line feed</p>



<p class="wp-block-paragraph">situation so i usually like to make a little function somewhere called crlf carriage return</p>



<p class="wp-block-paragraph">line feed is what it stands for and it&#8217;s the same thing it&#8217;s just like load up the system call</p>



<p class="wp-block-paragraph">registers so that it knows i want to print the string which is just a line feed</p>



<p class="wp-block-paragraph">carriage return line feed and then actually call system call and then return to the caller so this</p>



<p class="wp-block-paragraph">back up here let&#8217;s see crlf i guess i am going to be doing it it&#8217;s just a string with the the</p>



<p class="wp-block-paragraph">slash r slash n or the carriage return line feed characters in ascii those are 13 comma 10 so i can</p>



<p class="wp-block-paragraph">put that there instead of a literal quoted string okay so we got that and then that means after the</p>



<p class="wp-block-paragraph">welcome message i can just like call crlf in order to have uh the cursor jump down to the next uh</p>



<p class="wp-block-paragraph">after that string is notice how I don&#8217;t have any line feeds after my strings that&#8217;s kind of why I</p>



<p class="wp-block-paragraph">like to do crlf and it lets me just call crlf a bunch of times if I want to just like space things</p>



<p class="wp-block-paragraph">out temporarily okay so we&#8217;ve got the hello function and now we&#8217;re going to print another</p>



<p class="wp-block-paragraph">message here I&#8217;ll just explain this real fast so I&#8217;m going to print a message about calling a c</p>



<p class="wp-block-paragraph">So same thing, we&#8217;re just going to tell the system call service that we want to print a string and it&#8217;s going to be our string here that says, you know, we&#8217;re about to print this.</p>



<p class="wp-block-paragraph">We&#8217;re about to, what do we say?</p>



<p class="wp-block-paragraph">We&#8217;re about to call the C function and then later we&#8217;re going to call the C++ function.</p>



<p class="wp-block-paragraph">So we&#8217;re just going to print a message announcing and do CRLF.</p>



<p class="wp-block-paragraph">So that&#8217;s really nothing new at all.</p>



<p class="wp-block-paragraph">And then down here we actually call the C function, which is not going to be in this module.</p>



<p class="wp-block-paragraph">It&#8217;s going to be in the C module, the other source code.</p>



<p class="wp-block-paragraph">Somewhere in this program, we need to let our assembly module know</p>



<p class="wp-block-paragraph">that the C function is available because it kind of goes both ways.</p>



<p class="wp-block-paragraph">In assembly, I have to mark a function as global if I want other modules to be able</p>



<p class="wp-block-paragraph">to call that function, but I also have to mark a function as external</p>



<p class="wp-block-paragraph">if I want to be able to call some other modules function.</p>



<p class="wp-block-paragraph">So we have to go back up to the top.</p>



<p class="wp-block-paragraph">I mean, somewhere in the text section, I think would be fine.</p>



<p class="wp-block-paragraph">But for me, I just like to put it at the top.</p>



<p class="wp-block-paragraph">put it at the top at the top so I&#8217;ll say externals and then I&#8217;ll go extern</p>



<p class="wp-block-paragraph">keyword and then just name the function that I intend to call this way when the</p>



<p class="wp-block-paragraph">linker is trying to link all the objects together it doesn&#8217;t get upset because</p>



<p class="wp-block-paragraph">you tried to call a C function which is not in the current module it&#8217;ll</p>



<p class="wp-block-paragraph">understand that it&#8217;s gonna happen you know like it&#8217;s gonna call other modules</p>



<p class="wp-block-paragraph">for that it usually gets upset right away and then while we&#8217;re at it let&#8217;s do</p>



<p class="wp-block-paragraph">Let&#8217;s turn the CPP function because that&#8217;s going to come from the C++ module.</p>



<p class="wp-block-paragraph">So now we have both of our external functions set up.</p>



<p class="wp-block-paragraph">We&#8217;ve marked our global hello function so other modules can call us.</p>



<p class="wp-block-paragraph">And then let&#8217;s see, oh, what did I do wrong?</p>



<p class="wp-block-paragraph">I put the C message in the wrong spot.</p>



<p class="wp-block-paragraph">I was inside of the CRLF function.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to copy paste that back up here.</p>



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



<p class="wp-block-paragraph">Then we&#8217;ll do the same thing for the C++ message,</p>



<p class="wp-block-paragraph">or for the C++ stuff.</p>



<p class="wp-block-paragraph">I will first print a C++ message</p>



<p class="wp-block-paragraph">with these lines up here.</p>



<p class="wp-block-paragraph">That&#8217;s just like a regular system call,</p>



<p class="wp-block-paragraph">and then I&#8217;ll do a CRLF, so nothing new,</p>



<p class="wp-block-paragraph">just printing something.</p>



<p class="wp-block-paragraph">And then I will actually call the C++ function</p>



<p class="wp-block-paragraph">called the CPP function.</p>



<p class="wp-block-paragraph">Then I&#8217;ll say goodbye with another block of text.</p>



<p class="wp-block-paragraph">Again, not super important or complicated,</p>



<p class="wp-block-paragraph">so I&#8217;m just gonna paste it.</p>



<p class="wp-block-paragraph">Just another string.</p>



<p class="wp-block-paragraph">string. And then when we&#8217;re done, I&#8217;ll just say, you know, return, we&#8217;re done. So that means if</p>



<p class="wp-block-paragraph">you notice how we don&#8217;t have like any symbols in here called underscore start, that means this is</p>



<p class="wp-block-paragraph">not a pure assembly program. And we don&#8217;t even have a symbol inside of here that is called main.</p>



<p class="wp-block-paragraph">So that means this hello ASM module is not going to be the entry point of our program. It&#8217;s just</p>



<p class="wp-block-paragraph">going to expose a function called hello, which does some stuff. The entry point of our program</p>



<p class="wp-block-paragraph">really, let&#8217;s see, where is it? Oh, gosh, I think I already closed it for some reason. It&#8217;s the</p>



<p class="wp-block-paragraph">driver program, which we talked about. So remember the driver program, it&#8217;s got a main here. So that</p>



<p class="wp-block-paragraph">means this is going to be what the GCC libraries or the operating system calls, however you want</p>



<p class="wp-block-paragraph">to think of it. So this is the entry point of our program, it&#8217;ll just print something quickly,</p>



<p class="wp-block-paragraph">then it&#8217;ll call the hello function, which means execution will jump in to the hello module. So</p>



<p class="wp-block-paragraph">module and and also it would be really easy to apply this logic to have a c module call on an</p>



<p class="wp-block-paragraph">assembly module and in fact you can use this logic to have every type of module call on any other i</p>



<p class="wp-block-paragraph">mean just if you have a c++ function either being defined in the current module or being referenced</p>



<p class="wp-block-paragraph">in another module just make sure that you have an extern c block and then if you&#8217;re inside of a c</p>



<p class="wp-block-paragraph">and you&#8217;re going to call a non-name mingled module like C or assembly,</p>



<p class="wp-block-paragraph">then just do this block here.</p>



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



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



<p class="wp-block-paragraph">The C module, we looked at that.</p>



<p class="wp-block-paragraph">The C++, we looked at that.</p>



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



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



<p class="wp-block-paragraph">I mean, I guess we&#8217;re kind of done already.</p>



<p class="wp-block-paragraph">So what we should see now is a little intro here.</p>



<p class="wp-block-paragraph">Hello, my name is whatever.</p>



<p class="wp-block-paragraph">And then when we jump into the hello module,</p>



<p class="wp-block-paragraph">we should see a little welcome message about being in the assembly module.</p>



<p class="wp-block-paragraph">And then we should see a message about calling the C function.</p>



<p class="wp-block-paragraph">And then the C function should print.</p>



<p class="wp-block-paragraph">Let me open that up for you.</p>



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



<p class="wp-block-paragraph">The C function should print.</p>



<p class="wp-block-paragraph">Just, oh, by the way, this is the C function.</p>



<p class="wp-block-paragraph">And then when it returns at the very end, remember, even in a void function, there is</p>



<p class="wp-block-paragraph">a return statement implicit at the end of scope.</p>



<p class="wp-block-paragraph">So when it returns, it&#8217;ll come back down here.</p>



<p class="wp-block-paragraph">And then the C++ message will get printed.</p>



<p class="wp-block-paragraph">printed and then the C++ function will get called which is going to end up being</p>



<p class="wp-block-paragraph">just it just prints you know another message this is the C++ function</p>



<p class="wp-block-paragraph">then when it returns implicitly at the end of the function</p>



<p class="wp-block-paragraph">then we get down to here where we just basically say goodbye and then return to the caller</p>



<p class="wp-block-paragraph">the caller in this case is going to be the driver program because this whole time we were just inside</p>



<p class="wp-block-paragraph">called. So then the driver will say goodbye and then it will return control to the GCC libraries</p>



<p class="wp-block-paragraph">or the operating system ending the program. Let&#8217;s see if that works. Okay, clear. And so,</p>



<p class="wp-block-paragraph">you know, the way I wreck my make files, I&#8217;d like to do a little menu. I type make and it&#8217;s like,</p>



<p class="wp-block-paragraph">oh, the menu, make menu, make build, just in case, just to see what&#8217;s up. Okay, clear.</p>



<p class="wp-block-paragraph">say, let&#8217;s do clear and make run because that&#8217;s really what we&#8217;re after.</p>



<p class="wp-block-paragraph">Again, run will implicitly call build.</p>



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



<p class="wp-block-paragraph">And it seems to have succeeded.</p>



<p class="wp-block-paragraph">It wasn&#8217;t actually very exciting.</p>



<p class="wp-block-paragraph">Let me do a make clean so you can see it compile real fast.</p>



<p class="wp-block-paragraph">We run it.</p>



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



<p class="wp-block-paragraph">That was still kind of fast.</p>



<p class="wp-block-paragraph">So up here is basically the make file, all these lines.</p>



<p class="wp-block-paragraph">They&#8217;re just calling your normal compiler and assembler tools and linker tools.</p>



<p class="wp-block-paragraph">linker tools and then here&#8217;s the driver like we said it prints the hello message</p>



<p class="wp-block-paragraph">you know my name is whatever I love that name I have a strange name generator</p>



<p class="wp-block-paragraph">that I found online that&#8217;s not my name you can call me that if you want to and</p>



<p class="wp-block-paragraph">then we have the message that we&#8217;re going to call the hello module so now</p>



<p class="wp-block-paragraph">we&#8217;ve called into the hello function inside of the assembly module assembly</p>



<p class="wp-block-paragraph">module prints hello you know I&#8217;m inside of here now and then the assembly module</p>



<p class="wp-block-paragraph">Now we&#8217;re going to call the C function and then the C function actually</p>



<p class="wp-block-paragraph">executes and it is now printing with its print F function call that it did,</p>



<p class="wp-block-paragraph">you know, by the way, this is a C function. Hi.</p>



<p class="wp-block-paragraph">And then it returns to the caller.</p>



<p class="wp-block-paragraph">Maybe I could have added another print statement if I felt like I wanted to</p>



<p class="wp-block-paragraph">spend more time, but it returns to the caller, which is the hello function.</p>



<p class="wp-block-paragraph">Then we get to the next part of the hello function where it&#8217;s like now calling</p>



<p class="wp-block-paragraph">the C function as a print statement.</p>



<p class="wp-block-paragraph">Then it actually does call the C function. The C function prints itself out.</p>



<p class="wp-block-paragraph">prints itself out hello this is the C function and then the assembly module</p>



<p class="wp-block-paragraph">says goodbye it says it&#8217;s finished and then it returns to the caller so finally</p>



<p class="wp-block-paragraph">at the end of this print statement the there&#8217;s like that little return statement</p>



<p class="wp-block-paragraph">at the bottom of the hello module that returns to the caller which was the</p>



<p class="wp-block-paragraph">driver dot CPP program so then the driver prints the driver is now back in</p>



<p class="wp-block-paragraph">the driver is now back in control. You can see that message behind the terminal here.</p>



<p class="wp-block-paragraph">The driver is now back in control. Then it says goodbye. Then it returns zero to the operating</p>



<p class="wp-block-paragraph">system and the whole program is done. So it&#8217;s important to understand that if you want to</p>



<p class="wp-block-paragraph">pass arguments, right now I&#8217;m just going to say, you know, I&#8217;m going to make another video that</p>



<p class="wp-block-paragraph">is more robust in the future about passing arguments back and forth between these. It&#8217;s</p>



<p class="wp-block-paragraph">important to understand for now that you can pass arguments between all these different</p>



<p class="wp-block-paragraph">between all these different module functions if you want.</p>



<p class="wp-block-paragraph">Like if I wanted to give the.</p>



<p class="wp-block-paragraph">If I wanted to give the hello function.</p>



<p class="wp-block-paragraph">An incoming argument, let&#8217;s say like an integer or a character value or a pointer</p>



<p class="wp-block-paragraph">or something like that, I could just load up appropriate registers.</p>



<p class="wp-block-paragraph">Remember, we have argument registers in assembly.</p>



<p class="wp-block-paragraph">I think I can never remember if RSI or RDI are the first one.</p>



<p class="wp-block-paragraph">I&#8217;m going to say RDI is the first argument just off the top of my head.</p>



<p class="wp-block-paragraph">I always look that up.</p>



<p class="wp-block-paragraph">So if I wanted to call, let&#8217;s say give an integer argument to hello when I originally</p>



<p class="wp-block-paragraph">called it, then from the driver, I literally would just have to type an integer argument</p>



<p class="wp-block-paragraph">in there and then under the hood, the RDI register, assuming that I&#8217;m right about RDI</p>



<p class="wp-block-paragraph">being the first argument, the RDI register would get loaded up with that value.</p>



<p class="wp-block-paragraph">your assembly program all you&#8217;d have to do is do something with the RDI register</p>



<p class="wp-block-paragraph">you know load it up save it do whatever it is that you think you&#8217;re gonna do so</p>



<p class="wp-block-paragraph">that&#8217;s how you pass an integer or like a character or a pointer from C++ to</p>



<p class="wp-block-paragraph">assembly it works the same exact way if you want to pass arguments when calling</p>



<p class="wp-block-paragraph">from C to assembly and when if you want to pass integers from assembly to C or</p>



<p class="wp-block-paragraph">or C++, it&#8217;s the same thing just backwards.</p>



<p class="wp-block-paragraph">First, you load up RDI as the first argument register with whatever value you want to pass</p>



<p class="wp-block-paragraph">to C or C++.</p>



<p class="wp-block-paragraph">And then in the signature of the C++ function, you just expect, you know, a long or, you</p>



<p class="wp-block-paragraph">know, whatever you were going to get and the register will already be loaded up.</p>



<p class="wp-block-paragraph">Remember, the C++ is not really happening on the machine.</p>



<p class="wp-block-paragraph">It gets compiled down to assembly.</p>



<p class="wp-block-paragraph">So this source code that we&#8217;re looking at, it&#8217;s another illusion for our benefit.</p>



<p class="wp-block-paragraph">benefit. It&#8217;s not happening. It&#8217;s getting assembled and then compiled down to machine code. And then</p>



<p class="wp-block-paragraph">that is what&#8217;s actually happening on the machine. So when you write that you have an argument in a</p>



<p class="wp-block-paragraph">C++ function signature prototype, you&#8217;re not really writing that at all. You&#8217;re just saying</p>



<p class="wp-block-paragraph">that the A variable should get loaded from whatever the RDI register had.</p>



<p class="wp-block-paragraph">Or if you previously loaded the RDI register and you want to call a C++ function, that&#8217;s</p>



<p class="wp-block-paragraph">a C++ function that&#8217;s what it would expect the RDI register so it can work pretty seamlessly</p>



<p class="wp-block-paragraph">just calling things back and forth um so yeah I guess that&#8217;s all I really had to say</p>



<p class="wp-block-paragraph">this is the basics of writing a hybrid program thank you for watching I hope you learned a</p>



<p class="wp-block-paragraph">little bit of stuff and had a little bit of fun see you in the next video</p>



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



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



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



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



<p class="wp-block-paragraph">website that you&#8217;re looking at right now it would really mean the world to me and</p>



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">good stuff and if you have a suggestion for 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 get</p>



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/mix-c-c-and-assembly-into-one-program-hybrid-program-full-build-tutorial/">Mix C++, C, and Assembly into One Program &#8211; Hybrid Program Full Build Tutorial</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/mix-c-c-and-assembly-into-one-program-hybrid-program-full-build-tutorial/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</title>
		<link>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/</link>
					<comments>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 14 Sep 2025 23:46:11 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[argv argc]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[command line args]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[GCC assembly]]></category>
		<category><![CDATA[GCC linking]]></category>
		<category><![CDATA[hybrid programming]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming guide]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[x86 assembly]]></category>
		<category><![CDATA[x86-64 programming]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=227</guid>

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



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



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



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



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/">Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
